Skip to contentSkip to conversation

gnttab: fallout/improvements from max version

PATCH In review Roger Pau Monne 7 participants 22 messages Nov 15, 2021 – Nov 17, 2021 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

cover gnttab: fallout/improvements from max version

Hello,

The first patch introduces some syntactic sugar for setting the max grant version on the domctl, while the later 3 patches fix missing occurrences of xen_domctl_createdomain that didn't set the max grant version. It's likely patches 2 and 3 could be squashed.

All should be considered for the release, or else we need to revert the grant table version per domain change.

Thanks, Roger.

Roger Pau Monne (4):
domctl: introduce a macro to set the grant table max version tests/resource: set grant version for created domains test/tsx: set grant version for created domains tools/python: fix python libxc bindings to pass a max grant version

 tools/helpers/init-xenstore-domain.c |  2 +-
 tools/libs/light/libxl_create.c      |  2 +-
 tools/ocaml/libs/xc/xenctrl_stubs.c  |  3 ++-
 tools/python/xen/lowlevel/xc/xc.c    | 10 ++++++----
 tools/tests/resource/test-resource.c |  3 +++
 tools/tests/tsx/test-tsx.c           |  4 ++++
 xen/arch/arm/domain_build.c          |  4 ++--
 xen/arch/x86/setup.c                 |  2 +-
 xen/include/public/domctl.h          |  1 +
 9 files changed, 21 insertions(+), 10 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/4 domctl: introduce a macro to set the grant table max version

Such macro just clamps the passed version to fit in the designated bits of the domctl field. The main purpose is to make it clearer in the code when max grant version is being set in the grant_opts field.

Existing users that where setting the version in the grant_opts field are switched to use the macro.

No functional change intended.

---
Cc: Ian Jackson <[email protected]>

Given it's a non functional change (or at least that's the intention) it shouldn't have any impact on the release, it's just syntactic sugar.

---
 tools/helpers/init-xenstore-domain.c | 2 +-
 tools/libs/light/libxl_create.c      | 2 +-
 tools/ocaml/libs/xc/xenctrl_stubs.c  | 3 ++-
 xen/arch/arm/domain_build.c          | 4 ++--
 xen/arch/x86/setup.c                 | 2 +-
 xen/include/public/domctl.h          | 1 +
 6 files changed, 8 insertions(+), 6 deletions(-)
tools/helpers/init-xenstore-domain.c +1 -1
index 60469161bd..b205a79ee6 100644
@@ -89,7 +89,7 @@ static int build(xc_interface *xch)
          */
         .max_grant_frames = 4,
         .max_maptrack_frames = 128,
-        .grant_opts = 1,
+        .grant_opts = XEN_DOMCTL_GRANT_version(1),
     };
 
     xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
tools/libs/light/libxl_create.c +1 -1
index b6855c7b46..dcd09d32ba 100644
@@ -629,7 +629,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
             .max_evtchn_port = b_info->event_channels,
             .max_grant_frames = b_info->max_grant_frames,
             .max_maptrack_frames = b_info->max_maptrack_frames,
-            .grant_opts = b_info->max_grant_version,
+            .grant_opts = XEN_DOMCTL_GRANT_version(b_info->max_grant_version),
             .vmtrace_size = ROUNDUP(b_info->vmtrace_buf_kb << 10, XC_PAGE_SHIFT),
         };
 
tools/ocaml/libs/xc/xenctrl_stubs.c +2 -1
index eca0b8b334..5b4fe72c8d 100644
@@ -199,7 +199,8 @@ CAMLprim value stub_xc_domain_create(value xch, value wanted_domid, value config
 		.max_evtchn_port = Int_val(VAL_MAX_EVTCHN_PORT),
 		.max_grant_frames = Int_val(VAL_MAX_GRANT_FRAMES),
 		.max_maptrack_frames = Int_val(VAL_MAX_MAPTRACK_FRAMES),
-		.grant_opts = Int_val(VAL_MAX_GRANT_VERSION),
+		.grant_opts =
+		    XEN_DOMCTL_GRANT_version(Int_val(VAL_MAX_GRANT_VERSION)),
 	};
 
 	domain_handle_of_uuid_string(cfg.handle, String_val(VAL_HANDLE));
xen/arch/arm/domain_build.c +2 -2
index 19487c79da..d02bacbcd1 100644
@@ -2986,7 +2986,7 @@ void __init create_domUs(void)
             .max_evtchn_port = -1,
             .max_grant_frames = -1,
             .max_maptrack_frames = -1,
-            .grant_opts = opt_gnttab_max_version,
+            .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version),
         };
 
         if ( !dt_device_is_compatible(node, "xen,domain") )
@@ -3094,7 +3094,7 @@ void __init create_dom0(void)
         .max_evtchn_port = -1,
         .max_grant_frames = gnttab_dom0_frames(),
         .max_maptrack_frames = -1,
-        .grant_opts = opt_gnttab_max_version,
+        .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version),
     };
 
     /* The vGIC for DOM0 is exactly emulating the hardware GIC */
xen/arch/x86/setup.c +1 -1
index ec6e686fac..da47cdea14 100644
@@ -755,7 +755,7 @@ static struct domain *__init create_dom0(const module_t *image,
         .max_evtchn_port = -1,
         .max_grant_frames = -1,
         .max_maptrack_frames = -1,
-        .grant_opts = opt_gnttab_max_version,
+        .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version),
         .max_vcpus = dom0_max_vcpus(),
         .arch = {
             .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0,
xen/include/public/domctl.h +1 -0
index 1c21d4dc75..b85e6170b0 100644
@@ -99,6 +99,7 @@ struct xen_domctl_createdomain {
 
 /* Grant version, use low 4 bits. */
 #define XEN_DOMCTL_GRANT_version_mask    0xf
+#define XEN_DOMCTL_GRANT_version(v)      ((v) & XEN_DOMCTL_GRANT_version_mask)
 
     uint32_t grant_opts;
 
Signature · 1 line
2.33.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH for-4.16 1/4] domctl: introduce a macro to set the grant table max version

Quoted 11 lines · Roger Pau Monne

Such macro just clamps the passed version to fit in the designated bits of the domctl field. The main purpose is to make it clearer in the code when max grant version is being set in the grant_opts field.

Existing users that where setting the version in the grant_opts field are switched to use the macro.

No functional change intended.

Acked-by on v1 1/4
#3 lore raw

Re: [PATCH for-4.16 1/4] domctl: introduce a macro to set the grant table max version

In reply to Roger Pau Monne
Quoted 11 lines · Roger Pau Monne

Such macro just clamps the passed version to fit in the designated bits of the domctl field. The main purpose is to make it clearer in the code when max grant version is being set in the grant_opts field.

Existing users that where setting the version in the grant_opts field are switched to use the macro.

No functional change intended.

Reviewed-by on v1 1/4
#4 lore raw

Re: [PATCH for-4.16 1/4] domctl: introduce a macro to set the grant table max version

In reply to Roger Pau Monne

Hi Roger,

Quoted 6 lines · Roger Pau Monne

Such macro just clamps the passed version to fit in the designated bits of the domctl field. The main purpose is to make it clearer in the code when max grant version is being set in the grant_opts field.

Quoted 7 lines

Existing users that where setting the version in the grant_opts field are switched to use the macro.

No functional change intended.

Cheers
Bertrand

Quoted 105 lines

---
Cc: Ian Jackson <[email protected]>

Given it's a non functional change (or at least that's the intention) it shouldn't have any impact on the release, it's just syntactic sugar.
---

tools/helpers/init-xenstore-domain.c | 2 +-
tools/libs/light/libxl_create.c      | 2 +-
tools/ocaml/libs/xc/xenctrl_stubs.c  | 3 ++-
xen/arch/arm/domain_build.c          | 4 ++--
xen/arch/x86/setup.c                 | 2 +-
xen/include/public/domctl.h          | 1 +
6 files changed, 8 insertions(+), 6 deletions(-)
tools/helpers/init-xenstore-domain.c +1 -1
index 60469161bd..b205a79ee6 100644
@@ -89,7 +89,7 @@ static int build(xc_interface *xch)
         */
        .max_grant_frames = 4,
        .max_maptrack_frames = 128,
-        .grant_opts = 1,
+        .grant_opts = XEN_DOMCTL_GRANT_version(1),
    };
 
    xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
tools/libs/light/libxl_create.c +1 -1
index b6855c7b46..dcd09d32ba 100644
@@ -629,7 +629,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
            .max_evtchn_port = b_info->event_channels,
            .max_grant_frames = b_info->max_grant_frames,
            .max_maptrack_frames = b_info->max_maptrack_frames,
-            .grant_opts = b_info->max_grant_version,
+            .grant_opts = XEN_DOMCTL_GRANT_version(b_info->max_grant_version),
            .vmtrace_size = ROUNDUP(b_info->vmtrace_buf_kb << 10, XC_PAGE_SHIFT),
        };
 
tools/ocaml/libs/xc/xenctrl_stubs.c +2 -1
index eca0b8b334..5b4fe72c8d 100644
@@ -199,7 +199,8 @@ CAMLprim value stub_xc_domain_create(value xch, value wanted_domid, value config
 		.max_evtchn_port = Int_val(VAL_MAX_EVTCHN_PORT),
 		.max_grant_frames = Int_val(VAL_MAX_GRANT_FRAMES),
 		.max_maptrack_frames = Int_val(VAL_MAX_MAPTRACK_FRAMES),
-		.grant_opts = Int_val(VAL_MAX_GRANT_VERSION),
+		.grant_opts =
+		    XEN_DOMCTL_GRANT_version(Int_val(VAL_MAX_GRANT_VERSION)),
 	};
 
 	domain_handle_of_uuid_string(cfg.handle, String_val(VAL_HANDLE));
xen/arch/arm/domain_build.c +2 -2
index 19487c79da..d02bacbcd1 100644
@@ -2986,7 +2986,7 @@ void __init create_domUs(void)
            .max_evtchn_port = -1,
            .max_grant_frames = -1,
            .max_maptrack_frames = -1,
-            .grant_opts = opt_gnttab_max_version,
+            .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version),
        };
 
        if ( !dt_device_is_compatible(node, "xen,domain") )
@@ -3094,7 +3094,7 @@ void __init create_dom0(void)
        .max_evtchn_port = -1,
        .max_grant_frames = gnttab_dom0_frames(),
        .max_maptrack_frames = -1,
-        .grant_opts = opt_gnttab_max_version,
+        .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version),
    };
 
    /* The vGIC for DOM0 is exactly emulating the hardware GIC */
xen/arch/x86/setup.c +1 -1
index ec6e686fac..da47cdea14 100644
@@ -755,7 +755,7 @@ static struct domain *__init create_dom0(const module_t *image,
        .max_evtchn_port = -1,
        .max_grant_frames = -1,
        .max_maptrack_frames = -1,
-        .grant_opts = opt_gnttab_max_version,
+        .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version),
        .max_vcpus = dom0_max_vcpus(),
        .arch = {
            .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0,
xen/include/public/domctl.h +1 -0
index 1c21d4dc75..b85e6170b0 100644
@@ -99,6 +99,7 @@ struct xen_domctl_createdomain {
 
 /* Grant version, use low 4 bits. */
 #define XEN_DOMCTL_GRANT_version_mask    0xf
+#define XEN_DOMCTL_GRANT_version(v)      ((v) & XEN_DOMCTL_GRANT_version_mask)
 
    uint32_t grant_opts;
 
Signature · 1 line
2.33.0
Acked-by on v1 1/4
#5 lore raw

Re: [PATCH for-4.16 1/4] domctl: introduce a macro to set the grant table max version

In reply to Roger Pau Monne

Hi Roger,

Quoted 11 lines · Roger Pau Monne

Such macro just clamps the passed version to fit in the designated bits of the domctl field. The main purpose is to make it clearer in the code when max grant version is being set in the grant_opts field.

Existing users that where setting the version in the grant_opts field are switched to use the macro.

No functional change intended.

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by
#6 lore raw

Re: [PATCH for-4.16 1/4] domctl: introduce a macro to set the grant table max version

Julien Grall writes ("Re: [PATCH for-4.16 1/4] domctl: introduce a macro to set the grant table max version"):

Quoted 8 lines · Roger Pau Monne
Quoted 7 lines

Such macro just clamps the passed version to fit in the designated bits of the domctl field. The main purpose is to make it clearer in the code when max grant version is being set in the grant_opts field.

Existing users that where setting the version in the grant_opts field are switched to use the macro.

Quoted 6 lines
Quoted 4 lines

No functional change intended.

#7 lore raw

PATCH 2/4 tests/resource: set grant version for created domains

In reply to Roger Pau Monne

Set the grant table version for the created domains to use version 1, as that's the used by the test cases. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')

---
Cc: Ian Jackson <[email protected]>

This patch only modifies a test, so it should be safe to commit as it's not going to cause any changes to the hypervisor or the tools. Worse that could happen is it makes the test even more broken, but it's already unusable.

---
 tools/tests/resource/test-resource.c | 3 +++
 1 file changed, 3 insertions(+)
tools/tests/resource/test-resource.c +3 -0
index 988f96f7c1..0557f8a1b5 100644
@@ -120,6 +120,7 @@ static void test_domain_configurations(void)
             .create = {
                 .max_vcpus = 2,
                 .max_grant_frames = 40,
+                .grant_opts = XEN_DOMCTL_GRANT_version(1),
             },
         },
         {
@@ -128,6 +129,7 @@ static void test_domain_configurations(void)
                 .flags = XEN_DOMCTL_CDF_hvm,
                 .max_vcpus = 2,
                 .max_grant_frames = 40,
+                .grant_opts = XEN_DOMCTL_GRANT_version(1),
                 .arch = {
                     .emulation_flags = XEN_X86_EMU_LAPIC,
                 },
@@ -140,6 +142,7 @@ static void test_domain_configurations(void)
                 .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap,
                 .max_vcpus = 2,
                 .max_grant_frames = 40,
+                .grant_opts = XEN_DOMCTL_GRANT_version(1),
             },
         },
 #endif
Signature · 1 line
2.33.0
Reviewed-by on v1 2/4
#8 lore raw

Re: [PATCH for-4.16 2/4] tests/resource: set grant version for created domains

Quoted 7 lines · Roger Pau Monne

Set the grant table version for the created domains to use version 1, as that's the used by the test cases. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')
Acked-by on v1 2/4
#9 lore raw

Re: [PATCH for-4.16 2/4] tests/resource: set grant version for created domains

In reply to Roger Pau Monne
Quoted 7 lines · Roger Pau Monne

Set the grant table version for the created domains to use version 1, as that's the used by the test cases. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')
#10 lore raw

PATCH 3/4 test/tsx: set grant version for created domains

In reply to Roger Pau Monne

Set the grant table version for the created domains to use version 1, as such tests domains don't require the usage of the grant table at all. A TODO note is added to switch those dummy domains to not have a grant table at all when possible. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')

---
Cc: Ian Jackson <[email protected]>

This patch only modifies a test, so it should be safe to commit as it's not going to cause any changes to the hypervisor or the tools. Worse that could happen is it makes the test even more broken, but it's already unusable.

---
 tools/tests/tsx/test-tsx.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/tests/tsx/test-tsx.c +4 -0
index fab99c135e..f1dcff4c30 100644
@@ -444,6 +444,8 @@ static void test_guests(void)
         struct xen_domctl_createdomain c = {
             .max_vcpus = 1,
             .max_grant_frames = 1,
+            /* TODO: switch to 0 once support for no grant table is added. */
+            .grant_opts = XEN_DOMCTL_GRANT_version(1),
         };
 
         printf("Testing PV guest\n");
@@ -456,6 +458,8 @@ static void test_guests(void)
             .flags = XEN_DOMCTL_CDF_hvm,
             .max_vcpus = 1,
             .max_grant_frames = 1,
+            /* TODO: switch to 0 once support for no grant table is added. */
+            .grant_opts = XEN_DOMCTL_GRANT_version(1),
             .arch = {
                 .emulation_flags = XEN_X86_EMU_LAPIC,
             },
Signature · 1 line
2.33.0
Reviewed-by on v1 3/4
#11 lore raw

Re: [PATCH for-4.16 3/4] test/tsx: set grant version for created domains

Quoted 10 lines · Roger Pau Monne

Set the grant table version for the created domains to use version 1, as such tests domains don't require the usage of the grant table at all. A TODO note is added to switch those dummy domains to not have a grant table at all when possible. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')
#12 lore raw

Re: [PATCH for-4.16 3/4] test/tsx: set grant version for created domains

In reply to Roger Pau Monne
Quoted 10 lines · Roger Pau Monne

Set the grant table version for the created domains to use version 1, as such tests domains don't require the usage of the grant table at all. A TODO note is added to switch those dummy domains to not have a grant table at all when possible. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')
Quoted 7 lines

---
Cc: Ian Jackson <[email protected]>

This patch only modifies a test, so it should be safe to commit as it's not going to cause any changes to the hypervisor or the tools. Worse that could happen is it makes the test even more broken, but it's already unusable.

What do you mean unusable?  Other than this, the test works.

tools/tests/tsx/test-tsx.c static void test_guests(void) · line 447

Quoted 13 lines
---
 tools/tests/tsx/test-tsx.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/tests/tsx/test-tsx.c +1 -0
index fab99c135e..f1dcff4c30 100644
@@ -444,6 +444,8 @@ static void test_guests(void)
         struct xen_domctl_createdomain c = {
             .max_vcpus = 1,
             .max_grant_frames = 1,
+            /* TODO: switch to 0 once support for no grant table is added. */

I'd avoid these TODOs.  It's test code, so really doesn't matter too much.

However, there is a further task for this test to actually boot enough of a guest to dump CPUID as visible inside the guest, and cross-check with the toolstack's view of the data.

How exactly to get that data out of the VM is an open question, but it might involve xenconsoled.

~Andrew

#13 lore raw

Re: [PATCH for-4.16 3/4] test/tsx: set grant version for created domains

Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Roger Pau Monne

Set the grant table version for the created domains to use version 1, as such tests domains don't require the usage of the grant table at all. A TODO note is added to switch those dummy domains to not have a grant table at all when possible. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')

---
Cc: Ian Jackson <[email protected]>

Quoted 6 lines
Quoted 4 lines

This patch only modifies a test, so it should be safe to commit as it's not going to cause any changes to the hypervisor or the tools. Worse that could happen is it makes the test even more broken, but it's already unusable.

What do you mean unusable?  Other than this, the test works.

I mean, it's unusable because I broke it with the gnttab change, and that's it's current status unless this patch is applied.

Quoted 4 lines
Quoted 4 lines
---
 tools/tests/tsx/test-tsx.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 11 lines

tools/tests/tsx/test-tsx.c static void test_guests(void) · line 447

Quoted 9 lines
tools/tests/tsx/test-tsx.c +1 -0
index fab99c135e..f1dcff4c30 100644
@@ -444,6 +444,8 @@ static void test_guests(void)
         struct xen_domctl_createdomain c = {
             .max_vcpus = 1,
             .max_grant_frames = 1,
+            /* TODO: switch to 0 once support for no grant table is added. */

I'd avoid these TODOs.  It's test code, so really doesn't matter too much.

I'm fine with this, when looking at the test code I didn't see any reason why gnttab was needed, so I thought it would be a fine use-case for opting out to grant table. As you say it's a test case, so it doesn't matter much.

Do you want me to repost with the comments removed?

Thanks, Roger.

#14 lore raw

Re: [PATCH for-4.16 3/4] test/tsx: set grant version for created domains

Quoted 37 lines · Roger Pau Monné
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Roger Pau Monne

Set the grant table version for the created domains to use version 1, as such tests domains don't require the usage of the grant table at all. A TODO note is added to switch those dummy domains to not have a grant table at all when possible. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')

---
Cc: Ian Jackson <[email protected]>

Quoted 5 lines
Quoted 4 lines

This patch only modifies a test, so it should be safe to commit as it's not going to cause any changes to the hypervisor or the tools. Worse that could happen is it makes the test even more broken, but it's already unusable.

What do you mean unusable?  Other than this, the test works.

I mean, it's unusable because I broke it with the gnttab change, and that's it's current status unless this patch is applied.

Quoted 4 lines
Quoted 4 lines
---
 tools/tests/tsx/test-tsx.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 10 lines

tools/tests/tsx/test-tsx.c static void test_guests(void) · line 447

Quoted 9 lines
tools/tests/tsx/test-tsx.c +1 -0
index fab99c135e..f1dcff4c30 100644
@@ -444,6 +444,8 @@ static void test_guests(void)
         struct xen_domctl_createdomain c = {
             .max_vcpus = 1,
             .max_grant_frames = 1,
+            /* TODO: switch to 0 once support for no grant table is added. */

I'd avoid these TODOs.  It's test code, so really doesn't matter too much.

Quoted 6 lines

I'm fine with this, when looking at the test code I didn't see any reason why gnttab was needed, so I thought it would be a fine use-case for opting out to grant table. As you say it's a test case, so it doesn't matter much.

Do you want me to repost with the comments removed?

I'm happy to fix on commit, if nothing else needs reposting.

~Andrew

#15 lore raw

Re: [PATCH for-4.16 3/4] test/tsx: set grant version for created domains

In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH for-4.16 3/4] test/tsx: set grant version for created domains"):

Quoted 10 lines

Set the grant table version for the created domains to use version 1, as such tests domains don't require the usage of the grant table at all. A TODO note is added to switch those dummy domains to not have a grant table at all when possible. Without setting the grant version the domains for the tests cannot be created.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')
#16 lore raw

PATCH 4/4 tools/python: fix python libxc bindings to pass a max grant version

In reply to Roger Pau Monne

Such max version should be provided by the caller, otherwise the bindings will default to specifying a max version of 2, which is inline with the current defaults in the hypervisor.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')

---
Cc: Ian Jackson <[email protected]>

Without this fix the python bindings won't be usable, as they will attempt to pass a max version of 0 which will be refused by the hypervisor. The main risk would be breaking the bindings, but given the current state it's unlikely to result in a worse outcome.

---
 tools/python/xen/lowlevel/xc/xc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tools/python/xen/lowlevel/xc/xc.c +6 -4
index 6293d205a3..fd00861032 100644
@@ -116,7 +116,7 @@ static PyObject *pyxc_domain_create(XcObject *self,
                                     PyObject *args,
                                     PyObject *kwds)
 {
-    uint32_t dom = 0, target = 0;
+    uint32_t dom = 0, target = 0, max_grant_version = 2;
     int      ret;
     size_t   i;
     PyObject *pyhandle = NULL;
@@ -132,12 +132,13 @@ static PyObject *pyxc_domain_create(XcObject *self,
     };
 
     static char *kwd_list[] = { "domid", "ssidref", "handle", "flags",
-                                "target", "max_vcpus", NULL };
+                                "target", "max_vcpus", "max_grant_version",
+                                NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOiii", kwd_list,
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOiiii", kwd_list,
                                       &dom, &config.ssidref, &pyhandle,
                                       &config.flags, &target,
-                                      &config.max_vcpus) )
+                                      &config.max_vcpus, &max_grant_version) )
         return NULL;
     if ( pyhandle != NULL )
     {
@@ -162,6 +163,7 @@ static PyObject *pyxc_domain_create(XcObject *self,
 #else
 #error Architecture not supported
 #endif
+    config.grant_opts = XEN_DOMCTL_GRANT_version(max_grant_version);
 
     if ( (ret = xc_domain_create(self->xc_handle, &dom, &config)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
Signature · 1 line
2.33.0
Acked-by on v1 4/4
#17 lore raw

Re: [PATCH for-4.16 4/4] tools/python: fix python libxc bindings to pass a max grant version

Quoted 6 lines · Roger Pau Monne

Such max version should be provided by the caller, otherwise the bindings will default to specifying a max version of 2, which is inline with the current defaults in the hypervisor.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')
Acked-by
#18 lore raw

Re: [PATCH for-4.16 4/4] tools/python: fix python libxc bindings to pass a max grant version

Andrew Cooper writes ("Re: [PATCH for-4.16 4/4] tools/python: fix python libxc bindings to pass a max grant version"):

Quoted 9 lines · Roger Pau Monne
Quoted 6 lines

Such max version should be provided by the caller, otherwise the bindings will default to specifying a max version of 2, which is inline with the current defaults in the hypervisor.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')

FTR

#19 lore raw

Re: [PATCH for-4.16 4/4] tools/python: fix python libxc bindings to pass a max grant version

In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH for-4.16 4/4] tools/python: fix python libxc bindings to pass a max grant version"):

Quoted 6 lines

Such max version should be provided by the caller, otherwise the bindings will default to specifying a max version of 2, which is inline with the current defaults in the hypervisor.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')
Quoted 7 lines

---
Cc: Ian Jackson <[email protected]>

Without this fix the python bindings won't be usable, as they will attempt to pass a max version of 0 which will be refused by the hypervisor. The main risk would be breaking the bindings, but given the current state it's unlikely to result in a worse outcome.

Acked-by on v1 4/4
#20 lore raw

Re: [PATCH for-4.16 4/4] tools/python: fix python libxc bindings to pass a max grant version

In reply to Roger Pau Monne
Quoted 6 lines · Roger Pau Monne

Such max version should be provided by the caller, otherwise the bindings will default to specifying a max version of 2, which is inline with the current defaults in the hypervisor.

Fixes 7379f9e10a ('gnttab: allow setting max version per-domain')
Quoted 52 lines

---
Cc: Ian Jackson <[email protected]>

Without this fix the python bindings won't be usable, as they will attempt to pass a max version of 0 which will be refused by the hypervisor. The main risk would be breaking the bindings, but given the current state it's unlikely to result in a worse outcome.

---
 tools/python/xen/lowlevel/xc/xc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tools/python/xen/lowlevel/xc/xc.c +6 -4
index 6293d205a3..fd00861032 100644
@@ -116,7 +116,7 @@ static PyObject *pyxc_domain_create(XcObject *self,
                                     PyObject *args,
                                     PyObject *kwds)
 {
-    uint32_t dom = 0, target = 0;
+    uint32_t dom = 0, target = 0, max_grant_version = 2;
     int      ret;
     size_t   i;
     PyObject *pyhandle = NULL;
@@ -132,12 +132,13 @@ static PyObject *pyxc_domain_create(XcObject *self,
     };
 
     static char *kwd_list[] = { "domid", "ssidref", "handle", "flags",
-                                "target", "max_vcpus", NULL };
+                                "target", "max_vcpus", "max_grant_version",
+                                NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOiii", kwd_list,
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOiiii", kwd_list,
                                       &dom, &config.ssidref, &pyhandle,
                                       &config.flags, &target,
-                                      &config.max_vcpus) )
+                                      &config.max_vcpus, &max_grant_version) )
         return NULL;
     if ( pyhandle != NULL )
     {
@@ -162,6 +163,7 @@ static PyObject *pyxc_domain_create(XcObject *self,
 #else
 #error Architecture not supported
 #endif
+    config.grant_opts = XEN_DOMCTL_GRANT_version(max_grant_version);
 
     if ( (ret = xc_domain_create(self->xc_handle, &dom, &config)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
Signature · 1 line
2.33.0
Signature · 3 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
#21 lore raw
In reply to Roger Pau Monne
Quoted 10 lines · Roger Pau Monne

Hello,

The first patch introduces some syntactic sugar for setting the max grant version on the domctl, while the later 3 patches fix missing occurrences of xen_domctl_createdomain that didn't set the max grant version. It's likely patches 2 and 3 could be squashed.

All should be considered for the release, or else we need to revert the grant table version per domain change.

Quoted 6 lines

Thanks, Roger.

Roger Pau Monne (4):
domctl: introduce a macro to set the grant table max version tests/resource: set grant version for created domains test/tsx: set grant version for created domains

I've committed these, but ...

Quoted 1 line

tools/python: fix python libxc bindings to pass a max grant version

... this one still lacks a maintainer ack (ignoring the slightly malformed shape of the ./MAINTAINERS entry, which imo ought to refer to tools/python/ to designate that's a directory).

Jan