Skip to contentSkip to conversation

gnttab: simplify (really: drop) gnttab_set_frame_gfn()

PATCH In review Jan Beulich 4 participants 5 messages May 12 – May 19

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gnttab: simplify (really: drop) gnttab_set_frame_gfn()

It's not really doing anything for valid GFNs, which renders its one use site pretty pointless. The other isn't so much about setting anything, but rather about clearing.

The main point here, however, is about Rafal spotting the double fetching of the GFN (first in gnttab_unpopulate_status_frames(), then again in gnttab_set_frame_gfn()). Re-purpose the macro parameter to pass in the already fetched GFN, while dropping the no longer used parameters.

As the result is a mere wrapper around guest_physmap_remove_page(), drop the hook altogether.

---
v2: Drop hook altogether.

xen/arch/arm/include/asm/grant_table.h +0 -7
@@ -50,13 +50,6 @@ int replace_grant_host_mapping(uint64_t
 #define gnttab_dom0_frames()                                             \
     min_t(unsigned int, opt_max_grant_frames, PFN_DOWN(_etext - _stext))
 
-#define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn)                      \
-    (gfn_eq(gfn, INVALID_GFN)                                            \
-     ? guest_physmap_remove_page((gt)->domain,                           \
-                                 gnttab_get_frame_gfn(gt, st, idx),      \
-                                 mfn, 0)                                 \
-     : 0)
-
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
    (st) ? gnttab_status_gfn(NULL, gt, idx)                               \
         : gnttab_shared_gfn(NULL, gt, idx);                              \
xen/arch/x86/include/asm/grant_table.h +0 -6
@@ -32,12 +32,6 @@ static inline int replace_grant_host_map
     return replace_grant_pv_mapping(addr, frame, new_addr, flags);
 }
 
-#define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn)                      \
-    (gfn_eq(gfn, INVALID_GFN)                                            \
-     ? guest_physmap_remove_page((gt)->domain,                           \
-                                 gnttab_get_frame_gfn(gt, st, idx),      \
-                                 mfn, 0)                                 \
-     : 0 /* Handled in add_to_physmap_one(). */)
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
     mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx)                       \
                       : gnttab_shared_mfn(gt, idx);                      \
xen/common/grant_table.c +1 -4
@@ -1844,8 +1844,7 @@ gnttab_unpopulate_status_frames(struct d
         {
             int rc = gfn_eq(gfn, INVALID_GFN)
                      ? 0
-                     : gnttab_set_frame_gfn(gt, true, i, INVALID_GFN,
-                                            page_to_mfn(pg));
+                     : guest_physmap_remove_page(d, gfn, page_to_mfn(pg), 0);
 
             if ( rc )
             {
@@ -4285,8 +4284,6 @@ int gnttab_map_frame_begin(
          */
         if ( !get_page(pg, d) )
             rc = -EBUSY;
-        else if ( (rc = gnttab_set_frame_gfn(gt, status, idx, gfn, *mfn)) )
-            put_page(pg);
     }
 
     if ( rc )
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Jan Beulich

It's not really doing anything for valid GFNs, which renders its one use site pretty pointless. The other isn't so much about setting anything, but rather about clearing.

The main point here, however, is about Rafal spotting the double fetching of the GFN (first in gnttab_unpopulate_status_frames(), then again in gnttab_set_frame_gfn()). Re-purpose the macro parameter to pass in the already fetched GFN, while dropping the no longer used parameters.

Quoted 5 lines

As the result is a mere wrapper around guest_physmap_remove_page(), drop the hook altogether.

#2 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich

It's not really doing anything for valid GFNs, which renders its one use site pretty pointless. The other isn't so much about setting anything, but rather about clearing.

The main point here, however, is about Rafal spotting the double fetching of the GFN (first in gnttab_unpopulate_status_frames(), then again in gnttab_set_frame_gfn()). Re-purpose the macro parameter to pass in the already fetched GFN, while dropping the no longer used parameters.

Quoted 5 lines

As the result is a mere wrapper around guest_physmap_remove_page(), drop the hook altogether.

Thanks.

~ Oleksii

Reviewed-by on v2 1/1
#3 lore raw
In reply to Jan Beulich
Quoted 61 lines · Jan Beulich

It's not really doing anything for valid GFNs, which renders its one use site pretty pointless. The other isn't so much about setting anything, but rather about clearing.

The main point here, however, is about Rafal spotting the double fetching of the GFN (first in gnttab_unpopulate_status_frames(), then again in gnttab_set_frame_gfn()). Re-purpose the macro parameter to pass in the already fetched GFN, while dropping the no longer used parameters.

As the result is a mere wrapper around guest_physmap_remove_page(), drop the hook altogether.

---
v2: Drop hook altogether.

xen/arch/arm/include/asm/grant_table.h +0 -7
@@ -50,13 +50,6 @@ int replace_grant_host_mapping(uint64_t
 #define gnttab_dom0_frames()                                             \
     min_t(unsigned int, opt_max_grant_frames, PFN_DOWN(_etext - _stext))
 
-#define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn)                      \
-    (gfn_eq(gfn, INVALID_GFN)                                            \
-     ? guest_physmap_remove_page((gt)->domain,                           \
-                                 gnttab_get_frame_gfn(gt, st, idx),      \
-                                 mfn, 0)                                 \
-     : 0)
-
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
    (st) ? gnttab_status_gfn(NULL, gt, idx)                               \
         : gnttab_shared_gfn(NULL, gt, idx);                              \
xen/arch/x86/include/asm/grant_table.h +0 -6
@@ -32,12 +32,6 @@ static inline int replace_grant_host_map
     return replace_grant_pv_mapping(addr, frame, new_addr, flags);
 }
 
-#define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn)                      \
-    (gfn_eq(gfn, INVALID_GFN)                                            \
-     ? guest_physmap_remove_page((gt)->domain,                           \
-                                 gnttab_get_frame_gfn(gt, st, idx),      \
-                                 mfn, 0)                                 \
-     : 0 /* Handled in add_to_physmap_one(). */)
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
     mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx)                       \
                       : gnttab_shared_mfn(gt, idx);                      \
xen/common/grant_table.c +1 -2
@@ -1844,8 +1844,7 @@ gnttab_unpopulate_status_frames(struct d
         {
             int rc = gfn_eq(gfn, INVALID_GFN)
                      ? 0
-                     : gnttab_set_frame_gfn(gt, true, i, INVALID_GFN,
-                                            page_to_mfn(pg));
+                     : guest_physmap_remove_page(d, gfn, page_to_mfn(pg), 0);
 
             if ( rc )
             {

xen/common/grant_table.c int gnttab_map_frame_begin( · line 4288

Quoted 4 lines
xen/common/grant_table.c +0 -1
@@ -4285,8 +4284,6 @@ int gnttab_map_frame_begin(
          */
         if ( !get_page(pg, d) )
             rc = -EBUSY;
-        else if ( (rc = gnttab_set_frame_gfn(gt, status, idx, gfn, *mfn)) )

status is now a variable that is set but never read. Remove it. With that:

~Michal

#4 lore raw
Quoted 11 lines · Michal
Quoted 10 lines · Jan Beulich
xen/common/grant_table.c +1 -2
@@ -1844,8 +1844,7 @@ gnttab_unpopulate_status_frames(struct d
         {
             int rc = gfn_eq(gfn, INVALID_GFN)
                      ? 0
-                     : gnttab_set_frame_gfn(gt, true, i, INVALID_GFN,
-                                            page_to_mfn(pg));
+                     : guest_physmap_remove_page(d, gfn, page_to_mfn(pg), 0);
 
Quoted 8 lines

xen/common/grant_table.c int gnttab_map_frame_begin( · line 4288

Quoted 7 lines
xen/common/grant_table.c +0 -1
             if ( rc )
             {
@@ -4285,8 +4284,6 @@ int gnttab_map_frame_begin(
          */
         if ( !get_page(pg, d) )
             rc = -EBUSY;
-        else if ( (rc = gnttab_set_frame_gfn(gt, status, idx, gfn, *mfn)) )

status is now a variable that is set but never read. Remove it.

Oh, good point. Thanks for spotting.

Quoted 2 lines

With that:

Thanks.

Jan