Skip to contentSkip to conversation

getpageframeinfo3: replace hardcoded batchsize with constant

PATCH In review Olaf Hering 4 participants 8 messages Mar 9, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 getpageframeinfo3: replace hardcoded batchsize with constant

While looking for the cause of errors returnd by XEN_DOMCTL_getpageframeinfo3 I came across this hardcoded value. Replace it with a constant and use that constant also in libxc.

---
 tools/libxc/xc_domain.c     | 9 +++++----
 xen/arch/x86/domctl.c       | 2 +-
 xen/include/public/domctl.h | 2 ++
 3 files changed, 8 insertions(+), 5 deletions(-)
tools/libxc/xc_domain.c +5 -4
index ea3df1ef31..20dc4e2bf5 100644
@@ -2035,14 +2035,15 @@ int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid,
                                            minfo->guest_width);
 
     /* Retrieve PFN types in batches */
-    for ( i = 0; i < minfo->p2m_size ; i+=1024 )
+    for ( i = 0; i < minfo->p2m_size ; i+=XEN_GETPAGEFRAMEINFO3_MAX_SIZE )
     {
-        int count = ((minfo->p2m_size - i ) > 1024 ) ?
-                        1024: (minfo->p2m_size - i);
+        int count = ((minfo->p2m_size - i ) > XEN_GETPAGEFRAMEINFO3_MAX_SIZE ) ?
+                        XEN_GETPAGEFRAMEINFO3_MAX_SIZE: (minfo->p2m_size - i);
 
         if ( xc_get_pfn_type_batch(xch, domid, count, minfo->pfn_type + i) )
         {
-            PERROR("Could not get %d-eth batch of PFN types", (i+1)/1024);
+            PERROR("Could not get %d-eth batch of PFN types",
+                  (i+1)/XEN_GETPAGEFRAMEINFO3_MAX_SIZE);
             goto failed;
         }
     }
xen/arch/x86/domctl.c +1 -1
index 8fbbf3aeb3..daf733de4f 100644
@@ -421,7 +421,7 @@ long arch_do_domctl(
         /* Games to allow this code block to handle a compat guest. */
         void __user *guest_handle = domctl->u.getpageframeinfo3.array.p;
 
-        if ( unlikely(num > 1024) ||
+        if ( unlikely(num > XEN_GETPAGEFRAMEINFO3_MAX_SIZE) ||
              unlikely(num != domctl->u.getpageframeinfo3.num) )
         {
             ret = -E2BIG;
xen/include/public/domctl.h +2 -0
index ec7a860afc..8d39cc8f74 100644
@@ -137,6 +137,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t);
 #define XEN_DOMCTL_PFINFO_BROKEN  (0xdU<<28) /* broken page */
 #define XEN_DOMCTL_PFINFO_LTAB_MASK (0xfU<<28)
 
+#define XEN_GETPAGEFRAMEINFO3_MAX_SIZE 1024U
+
 /* XEN_DOMCTL_getpageframeinfo3 */
 struct xen_domctl_getpageframeinfo3 {
     /* IN variables. */

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw

xen/include/public/domctl.h DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t); · line 140

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 17:17, <[email protected]> wrote:
xen/include/public/domctl.h +1 -0
@@ -137,6 +137,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t);
 #define XEN_DOMCTL_PFINFO_BROKEN  (0xdU<<28) /* broken page */
 #define XEN_DOMCTL_PFINFO_LTAB_MASK (0xfU<<28)
 
+#define XEN_GETPAGEFRAMEINFO3_MAX_SIZE 1024U

This is an implementation detail; it shouldn't be made part of the public interface. If there's a need for user land to know the value, and if there's currently no way to query it, that's what you would want to add.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 17:17, <[email protected]> wrote:
xen/include/public/domctl.h +0 -0
@@ -137,6 +137,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t);
 #define XEN_DOMCTL_PFINFO_BROKEN  (0xdU<<28) /* broken page */
 #define XEN_DOMCTL_PFINFO_LTAB_MASK (0xfU<<28)
 
Quoted 6 lines

xen/include/public/domctl.h DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t); · line 140

Quoted 1 line
xen/include/public/domctl.h +1 -0
+#define XEN_GETPAGEFRAMEINFO3_MAX_SIZE 1024U

This is an implementation detail; it shouldn't be made part of the public interface. If there's a need for user land to know the value, and if there's currently no way to query it, that's what you would want to add.

But the domctl interface isn't stable, right? There's no need to make a flexible backwards-compatible interface between libxc and Xen; sharing a #define should be fine, as long as there's only one place to change it.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 17:30, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 17:17, <[email protected]> wrote:
xen/include/public/domctl.h +0 -0
@@ -137,6 +137,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t);
 #define XEN_DOMCTL_PFINFO_BROKEN  (0xdU<<28) /* broken page */
 #define XEN_DOMCTL_PFINFO_LTAB_MASK (0xfU<<28)
 
Quoted 6 lines

xen/include/public/domctl.h DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t); · line 140

Quoted 1 line
xen/include/public/domctl.h +1 -0
+#define XEN_GETPAGEFRAMEINFO3_MAX_SIZE 1024U

This is an implementation detail; it shouldn't be made part of the public interface. If there's a need for user land to know the value, and if there's currently no way to query it, that's what you would want to add.

Quoted 3 lines

But the domctl interface isn't stable, right? There's no need to make a flexible backwards-compatible interface between libxc and Xen; sharing a #define should be fine, as long as there's only one place to change it.

Well, strictly speaking this is an option. But I would prefer if we didn't abuse the "is not a stable interface" property, which this changes feels like it would.

Furthermore it hasn't become clear to me why, if this hard coded number is deemed a problem, we don't get rid of it altogether. Domctl-s have long gained the ability to be preemptible - there various examples.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 20 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 17:30, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 17:17, <[email protected]> wrote:
xen/include/public/domctl.h +0 -0
@@ -137,6 +137,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t);
 #define XEN_DOMCTL_PFINFO_BROKEN  (0xdU<<28) /* broken page */
 #define XEN_DOMCTL_PFINFO_LTAB_MASK (0xfU<<28)
 
Quoted 6 lines

xen/include/public/domctl.h DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t); · line 140

Quoted 1 line
xen/include/public/domctl.h +1 -0
+#define XEN_GETPAGEFRAMEINFO3_MAX_SIZE 1024U

This is an implementation detail; it shouldn't be made part of the public interface. If there's a need for user land to know the value, and if there's currently no way to query it, that's what you would want to add.

Quoted 3 lines

But the domctl interface isn't stable, right? There's no need to make a flexible backwards-compatible interface between libxc and Xen; sharing a #define should be fine, as long as there's only one place to change it.

Quoted 8 lines

Well, strictly speaking this is an option. But I would prefer if we didn't abuse the "is not a stable interface" property, which this changes feels like it would.

Furthermore it hasn't become clear to me why, if this hard coded number is deemed a problem, we don't get rid of it altogether. Domctl-s have long gained the ability to be preemptible - there various examples.

Yes, making it preemptible and removing the limit is probably a better option.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
In reply to George Dunlap
Quoted 22 lines · George Dunlap
Quoted 21 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 17:30, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 17:17, <[email protected]> wrote:
xen/include/public/domctl.h +0 -0
@@ -137,6 +137,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t);
 #define XEN_DOMCTL_PFINFO_BROKEN  (0xdU<<28) /* broken page */
 #define XEN_DOMCTL_PFINFO_LTAB_MASK (0xfU<<28)
 
Quoted 8 lines
Quoted 5 lines

xen/include/public/domctl.h DEFINE_XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t); · line 140

Quoted 1 line
xen/include/public/domctl.h +1 -0
+#define XEN_GETPAGEFRAMEINFO3_MAX_SIZE 1024U

This is an implementation detail; it shouldn't be made part of the public interface. If there's a need for user land to know the value, and if there's currently no way to query it, that's what you would want to add.

But the domctl interface isn't stable, right? There's no need to make a flexible backwards-compatible interface between libxc and Xen; sharing a #define should be fine, as long as there's only one place to change it.

Well, strictly speaking this is an option. But I would prefer if we didn't abuse the "is not a stable interface" property, which this changes feels like it would.

Quoted 6 lines
Quoted 4 lines

Furthermore it hasn't become clear to me why, if this hard coded number is deemed a problem, we don't get rid of it altogether. Domctl-s have long gained the ability to be preemptible - there various examples.

Yes, making it preemptible and removing the limit is probably a better option.

The 1024 limit was from the 32bit days, where there was a single domheap page allocated as a bounce buffer.

The logic nowadays is trivial to make continuable, and would remove the fixed arbitrary upper limit.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
In reply to Olaf Hering
Quoted 1 line · Olaf Hering

The point was to document the counter part. Grep -w 1024 is not helpful.

Of course -- your patch certainly makes the codebase better by making this number set in only one place, and in making it easier to find who else is depending on this number with grep.

Jan is saying, however, it's not clear why we have such an arbitrary limit in the first place. Andy claims it's a remnant from the days when we were passing a single page rather than an arbitrary array; it also serves to make sure the hypercall doesn't run too long. But if we use normal hypercall preemption, we don't need to have this limit at all.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel