[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] x86/pv: Use DIV_ROUND_UP() when converting between GDT entries and frames



commit ffc4a3cf4fe6945a4998075e2c4435d1da281909
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Tue Oct 3 15:30:54 2017 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri Dec 1 19:03:27 2017 +0000

    x86/pv: Use DIV_ROUND_UP() when converting between GDT entries and frames
    
    Also consistently use use nr_frames, rather than mixing nr_pages with a
    frames[] array.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/domain.c               |  8 +++++---
 xen/arch/x86/pv/descriptor-tables.c | 17 ++++++++---------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index b49a9c4..e1bf2d9 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1017,12 +1017,14 @@ int arch_set_info_guest(
     else
     {
         unsigned long gdt_frames[ARRAY_SIZE(v->arch.pv_vcpu.gdt_frames)];
-        unsigned int n = (c.cmp->gdt_ents + 511) / 512;
+        unsigned int nr_frames = DIV_ROUND_UP(c.cmp->gdt_ents, 512);
 
-        if ( n > ARRAY_SIZE(v->arch.pv_vcpu.gdt_frames) )
+        if ( nr_frames > ARRAY_SIZE(v->arch.pv_vcpu.gdt_frames) )
             return -EINVAL;
-        for ( i = 0; i < n; ++i )
+
+        for ( i = 0; i < nr_frames; ++i )
             gdt_frames[i] = c.cmp->gdt_frames[i];
+
         rc = (int)pv_set_gdt(v, gdt_frames, c.cmp->gdt_ents);
     }
     if ( rc != 0 )
diff --git a/xen/arch/x86/pv/descriptor-tables.c 
b/xen/arch/x86/pv/descriptor-tables.c
index 9c8de1d..e31c97e 100644
--- a/xen/arch/x86/pv/descriptor-tables.c
+++ b/xen/arch/x86/pv/descriptor-tables.c
@@ -57,14 +57,13 @@ long pv_set_gdt(struct vcpu *v, unsigned long *frames, 
unsigned int entries)
 {
     struct domain *d = v->domain;
     l1_pgentry_t *pl1e;
-    /* NB. There are 512 8-byte entries per GDT page. */
-    unsigned int i, nr_pages = (entries + 511) / 512;
+    unsigned int i, nr_frames = DIV_ROUND_UP(entries, 512);
 
     if ( entries > FIRST_RESERVED_GDT_ENTRY )
         return -EINVAL;
 
     /* Check the pages in the new GDT. */
-    for ( i = 0; i < nr_pages; i++ )
+    for ( i = 0; i < nr_frames; i++ )
     {
         struct page_info *page;
 
@@ -85,7 +84,7 @@ long pv_set_gdt(struct vcpu *v, unsigned long *frames, 
unsigned int entries)
     /* Install the new GDT. */
     v->arch.pv_vcpu.gdt_ents = entries;
     pl1e = pv_gdt_ptes(v);
-    for ( i = 0; i < nr_pages; i++ )
+    for ( i = 0; i < nr_frames; i++ )
     {
         v->arch.pv_vcpu.gdt_frames[i] = frames[i];
         l1e_write(&pl1e[i], l1e_from_pfn(frames[i], __PAGE_HYPERVISOR_RW));
@@ -104,7 +103,7 @@ long pv_set_gdt(struct vcpu *v, unsigned long *frames, 
unsigned int entries)
 long do_set_gdt(XEN_GUEST_HANDLE_PARAM(xen_ulong_t) frame_list,
                 unsigned int entries)
 {
-    int nr_pages = (entries + 511) / 512;
+    unsigned int nr_frames = DIV_ROUND_UP(entries, 512);
     unsigned long frames[16];
     struct vcpu *curr = current;
     long ret;
@@ -113,7 +112,7 @@ long do_set_gdt(XEN_GUEST_HANDLE_PARAM(xen_ulong_t) 
frame_list,
     if ( entries > FIRST_RESERVED_GDT_ENTRY )
         return -EINVAL;
 
-    if ( copy_from_guest(frames, frame_list, nr_pages) )
+    if ( copy_from_guest(frames, frame_list, nr_frames) )
         return -EFAULT;
 
     domain_lock(curr->domain);
@@ -130,7 +129,7 @@ int compat_set_gdt(XEN_GUEST_HANDLE_PARAM(uint) frame_list,
                    unsigned int entries)
 {
     struct vcpu *curr = current;
-    unsigned int i, nr_pages = (entries + 511) / 512;
+    unsigned int i, nr_frames = DIV_ROUND_UP(entries, 512);
     unsigned long frames[16];
     int ret;
 
@@ -138,10 +137,10 @@ int compat_set_gdt(XEN_GUEST_HANDLE_PARAM(uint) 
frame_list,
     if ( entries > FIRST_RESERVED_GDT_ENTRY )
         return -EINVAL;
 
-    if ( !guest_handle_okay(frame_list, nr_pages) )
+    if ( !guest_handle_okay(frame_list, nr_frames) )
         return -EFAULT;
 
-    for ( i = 0; i < nr_pages; ++i )
+    for ( i = 0; i < nr_frames; ++i )
     {
         unsigned int frame;
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.