Skip to contentSkip to conversation

domain: followup for phys address mapping series

PATCH In review Roger Pau Monne 5 participants 17 messages Oct 6, 2023 – Oct 16, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover domain: followup for phys address mapping series

Hello,

First patch fixes a bug reported by osstest, second patch is an addition requested by Andrew, I think this should remove the blocker raised against the series.

Roger Pau Monne (2):
domain: fix misaligned unmap address in {,un}map_guest_area()
domain: expose newly introduced hypercalls as XENFEAT

 CHANGELOG.md                  | 2 ++
 xen/arch/x86/domain.c         | 4 ++++
 xen/common/domain.c           | 8 ++++++--
 xen/common/kernel.c           | 6 +++++-
 xen/include/public/features.h | 9 +++++++++
 xen/include/public/vcpu.h     | 3 +++
 6 files changed, 29 insertions(+), 3 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH v2 1/2 domain: fix misaligned unmap address in {,un}map_guest_area()

unmap_domain_page_global() expects the provided address to be page aligned, or else some of the called functions will trigger assertions, like modify_xen_mappings() on x86 or destroy_xen_mappings() on Arm.

The following assert has been reported by osstest arm 32bit tests:

(XEN) Assertion 'IS_ALIGNED(s, PAGE_SIZE)' failed at arch/arm/mm.c:1243 (XEN) ----[ Xen-4.18-rc arm32 debug=y Not tainted ]----
(XEN) CPU: 0
(XEN) PC: 00271a38 destroy_xen_mappings+0x50/0x5c
[...]
(XEN) Xen call trace:

(XEN)    [<00271a38>] destroy_xen_mappings+0x50/0x5c (PC)
(XEN)    [<00235aa8>] vunmap+0x30/0x1a0 (LR)
(XEN)    [<0026ad88>] unmap_domain_page_global+0x10/0x20
(XEN)    [<00208e38>] unmap_guest_area+0x90/0xec
(XEN)    [<00208f98>] domain_kill+0x104/0x180
(XEN)    [<00239e3c>] do_domctl+0x8ac/0x14fc
(XEN)    [<0027ae34>] do_trap_guest_sync+0x570/0x66c
(XEN)    [<002019f0>] arch/arm/arm32/entry.o#return_from_trap+0/0x4
Fixes eadc288cbb0d ('domain: map/unmap GADDR based shared guest areas')

---
Changes since v1:
- Also page-align the address in map_guest_area().

---
 xen/common/domain.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/domain.c +2 -2
index b8281d7cff9d..1468638ade8b 100644
@@ -1601,7 +1601,7 @@ int map_guest_area(struct vcpu *v, paddr_t gaddr, unsigned int size,
  unmap:
     if ( pg )
     {
-        unmap_domain_page_global(map);
+        unmap_domain_page_global((void *)((unsigned long)map & PAGE_MASK));
         put_page_and_type(pg);
     }
 
@@ -1634,7 +1634,7 @@ void unmap_guest_area(struct vcpu *v, struct guest_area *area)
 
     if ( pg )
     {
-        unmap_domain_page_global(map);
+        unmap_domain_page_global((void *)((unsigned long)map & PAGE_MASK));
         put_page_and_type(pg);
     }
 }
Signature · 1 line
2.42.0
#2 lore raw

Re: [PATCH v2 1/2] domain: fix misaligned unmap address in {,un}map_guest_area()

Hi Roger,

Quoted 23 lines · Roger Pau Monne

unmap_domain_page_global() expects the provided address to be page aligned, or else some of the called functions will trigger assertions, like modify_xen_mappings() on x86 or destroy_xen_mappings() on Arm.

The following assert has been reported by osstest arm 32bit tests:

(XEN) Assertion 'IS_ALIGNED(s, PAGE_SIZE)' failed at arch/arm/mm.c:1243 (XEN) ----[ Xen-4.18-rc arm32 debug=y Not tainted ]----
(XEN) CPU: 0
(XEN) PC: 00271a38 destroy_xen_mappings+0x50/0x5c
[...]
(XEN) Xen call trace:

(XEN)    [<00271a38>] destroy_xen_mappings+0x50/0x5c (PC)
(XEN)    [<00235aa8>] vunmap+0x30/0x1a0 (LR)
(XEN)    [<0026ad88>] unmap_domain_page_global+0x10/0x20
(XEN)    [<00208e38>] unmap_guest_area+0x90/0xec
(XEN)    [<00208f98>] domain_kill+0x104/0x180
(XEN)    [<00239e3c>] do_domctl+0x8ac/0x14fc
(XEN)    [<0027ae34>] do_trap_guest_sync+0x570/0x66c
(XEN)    [<002019f0>] arch/arm/arm32/entry.o#return_from_trap+0/0x4
Quoted 2 lines
Fixes eadc288cbb0d ('domain: map/unmap GADDR based shared guest areas')

Kind regards,
Henry

Quoted 32 lines

---
Changes since v1:
- Also page-align the address in map_guest_area().
---
xen/common/domain.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/domain.c +2 -2
index b8281d7cff9d..1468638ade8b 100644
@@ -1601,7 +1601,7 @@ int map_guest_area(struct vcpu *v, paddr_t gaddr, unsigned int size,
 unmap:
    if ( pg )
    {
-        unmap_domain_page_global(map);
+        unmap_domain_page_global((void *)((unsigned long)map & PAGE_MASK));
        put_page_and_type(pg);
    }
 
@@ -1634,7 +1634,7 @@ void unmap_guest_area(struct vcpu *v, struct guest_area *area)
 
    if ( pg )
    {
-        unmap_domain_page_global(map);
+        unmap_domain_page_global((void *)((unsigned long)map & PAGE_MASK));
        put_page_and_type(pg);
    }
 }
Signature · 1 line
2.42.0
Reviewed-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] domain: fix misaligned unmap address in {,un}map_guest_area()

In reply to Roger Pau Monne

Hi Roger,

Quoted 21 lines · Roger Pau Monne

unmap_domain_page_global() expects the provided address to be page aligned, or else some of the called functions will trigger assertions, like modify_xen_mappings() on x86 or destroy_xen_mappings() on Arm.

The following assert has been reported by osstest arm 32bit tests:

(XEN) Assertion 'IS_ALIGNED(s, PAGE_SIZE)' failed at arch/arm/mm.c:1243 (XEN) ----[ Xen-4.18-rc arm32 debug=y Not tainted ]----
(XEN) CPU: 0
(XEN) PC: 00271a38 destroy_xen_mappings+0x50/0x5c
[...]
(XEN) Xen call trace:

(XEN)    [<00271a38>] destroy_xen_mappings+0x50/0x5c (PC)
(XEN)    [<00235aa8>] vunmap+0x30/0x1a0 (LR)
(XEN)    [<0026ad88>] unmap_domain_page_global+0x10/0x20
(XEN)    [<00208e38>] unmap_guest_area+0x90/0xec
(XEN)    [<00208f98>] domain_kill+0x104/0x180
(XEN)    [<00239e3c>] do_domctl+0x8ac/0x14fc
(XEN)    [<0027ae34>] do_trap_guest_sync+0x570/0x66c
(XEN)    [<002019f0>] arch/arm/arm32/entry.o#return_from_trap+0/0x4
Quoted 2 lines
Fixes eadc288cbb0d ('domain: map/unmap GADDR based shared guest areas')

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw

Re: [PATCH v2 1/2] domain: fix misaligned unmap address in {,un}map_guest_area()

In reply to Roger Pau Monne

On 06.10.2023 15:00, Roger Pau Monne wrote:> --- a/xen/common/domain.c

Quoted 11 lines

+++ b/xen/common/domain.c

xen/common/domain.c +1 -1
@@ -1601,7 +1601,7 @@ int map_guest_area(struct vcpu *v, paddr_t gaddr, unsigned int size,
  unmap:
     if ( pg )
     {
-        unmap_domain_page_global(map);
+        unmap_domain_page_global((void *)((unsigned long)map & PAGE_MASK));
         put_page_and_type(pg);
     }
 

xen/common/domain.c void unmap_guest_area(struct vcpu *v, struct guest_area *area) · line 1640

Quoted 8 lines
xen/common/domain.c +1 -1
@@ -1634,7 +1634,7 @@ void unmap_guest_area(struct vcpu *v, struct guest_area *area)
 
     if ( pg )
     {
-        unmap_domain_page_global(map);
+        unmap_domain_page_global((void *)((unsigned long)map & PAGE_MASK));
         put_page_and_type(pg);
     }
 }

On v1 in a reply to Julien you talk of "limiting misuse" by not relaxing expecations in Arm's backing code, but I wonder what kind of misuse you think about. Aiui there's no strong need to insist on page aligned input, and relaxing things there may simplify code elsewhere as well.

Jan

#5 lore raw

Re: [PATCH v2 1/2] domain: fix misaligned unmap address in {,un}map_guest_area()

Quoted 13 lines · Jan Beulich

On 06.10.2023 15:00, Roger Pau Monne wrote:> --- a/xen/common/domain.c

Quoted 12 lines

+++ b/xen/common/domain.c

xen/common/domain.c +1 -1
@@ -1601,7 +1601,7 @@ int map_guest_area(struct vcpu *v, paddr_t gaddr, unsigned int size,
  unmap:
     if ( pg )
     {
-        unmap_domain_page_global(map);
+        unmap_domain_page_global((void *)((unsigned long)map & PAGE_MASK));
         put_page_and_type(pg);
     }
 
@@ -1634,7 +1634,7 @@ void unmap_guest_area(struct vcpu *v, struct guest_area *area)
 
Quoted 12 lines

xen/common/domain.c void unmap_guest_area(struct vcpu *v, struct guest_area *area) · line 1640

Quoted 7 lines
xen/common/domain.c +1 -1
     if ( pg )
     {
-        unmap_domain_page_global(map);
+        unmap_domain_page_global((void *)((unsigned long)map & PAGE_MASK));
         put_page_and_type(pg);
     }
 }

On v1 in a reply to Julien you talk of "limiting misuse" by not relaxing expecations in Arm's backing code, but I wonder what kind of misuse you think about. Aiui there's no strong need to insist on page aligned input, and relaxing things there may simplify code elsewhere as well.

destroy_xen_mappings() both on Arm and x86 will trigger asserts if the passed address is not page aligned. I do think it makes sense to call unmap_domain_page_global() with page-aligned addresses, as that could help detect bogus callers or corrupted data passed as input.

IMO an assert for page aligned input address should be placed at vunmap() in order to not get differing expectations on input address being page aligned or not whether destroy_xen_mappings() or map_pages_to_xen() is used. map_pages_to_xen() doesn't require page-aligned virtual addresses as input.

Roger.

#6 lore raw

PATCH v2 2/2 domain: expose newly introduced hypercalls as XENFEAT

In reply to Roger Pau Monne

XENFEAT_runstate_phys_area is exposed to all architectures, while XENFEAT_vcpu_time_phys_area is currently only implemented for x86, and hence the feature flag is also only exposed on x86.

Additionally add dummy guards with TODOs in the respective hypercall implementations, to signal the intention to control the availability of those hypercalls on a guest-by-guest basis from the toolstack.

---
Changes since v1:
- Adjust comments, and add new one in vcpu.h
- Add dummy guard with TDOD in hypercall implementations.

---
 CHANGELOG.md                  | 2 ++
 xen/arch/x86/domain.c         | 4 ++++
 xen/common/domain.c           | 4 ++++
 xen/common/kernel.c           | 6 +++++-
 xen/include/public/features.h | 9 +++++++++
 xen/include/public/vcpu.h     | 3 +++
 6 files changed, 27 insertions(+), 1 deletion(-)
CHANGELOG.md +2 -0
index e33cf4e1b113..47ea9e275462 100644
@@ -31,6 +31,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
  - Add Intel Hardware P-States (HWP) cpufreq driver.
  - On Arm, experimental support for dynamic addition/removal of Xen device tree
    nodes using a device tree overlay binary (.dtbo).
+ - Introduce two new hypercalls to map the vCPU runstate and time areas by
+   physical rather than linear/virtual addresses.
 
 ### Removed
  - On x86, the "pku" command line option has been removed.  It has never
xen/arch/x86/domain.c +4 -0
index 8e0af2278104..8d3d52034a6d 100644
@@ -1580,6 +1580,10 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_time_memory_area area;
 
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_vcpu_time_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;
xen/common/domain.c +4 -0
index 1468638ade8b..8f9ab01c0cb7 100644
@@ -1998,6 +1998,10 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_runstate_memory_area area;
 
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_runstate_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;
xen/common/kernel.c +5 -1
index 52aa28762782..b6302e44b34e 100644
@@ -607,7 +607,11 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         switch ( fi.submap_idx )
         {
         case 0:
-            fi.submap = (1U << XENFEAT_memory_op_vnode_supported);
+            fi.submap = (1U << XENFEAT_memory_op_vnode_supported) |
+#ifdef CONFIG_X86
+                        (1U << XENFEAT_vcpu_time_phys_area) |
+#endif
+                        (1U << XENFEAT_runstate_phys_area);
             if ( VM_ASSIST(d, pae_extended_cr3) )
                 fi.submap |= (1U << XENFEAT_pae_pgdir_above_4gb);
             if ( paging_mode_translate(d) )
xen/include/public/features.h +9 -0
index d2a9175aae67..22713a51b520 100644
@@ -111,6 +111,15 @@
 #define XENFEAT_not_direct_mapped         16
 #define XENFEAT_direct_mapped             17
 
+/*
+ * Signal whether the domain is permitted to use the following hypercalls:
+ *
+ * VCPUOP_register_runstate_phys_area
+ * VCPUOP_register_vcpu_time_phys_area
+ */
+#define XENFEAT_runstate_phys_area	  18
+#define XENFEAT_vcpu_time_phys_area	  19
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
xen/include/public/vcpu.h +3 -0
index 8fb0bd1b6c03..03b031a3e557 100644
@@ -236,6 +236,9 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
  * Note that the area registered via VCPUOP_register_runstate_memory_area will
  * be updated in the same manner as the one registered via virtual address PLUS
  * VMASST_TYPE_runstate_update_flag engaged by the domain.
+ *
+ * XENFEAT_{runstate,vcpu_time}_phys_area feature bits signal if the domain is
+ * permitted the usage of the hypercalls.
  */
 #define VCPUOP_register_runstate_phys_area      14
 #define VCPUOP_register_vcpu_time_phys_area     15
Signature · 1 line
2.42.0
#7 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

Quoted 25 lines · Roger Pau Monne
xen/include/public/features.h +9 -0
index d2a9175aae67..22713a51b520 100644
@@ -111,6 +111,15 @@
 #define XENFEAT_not_direct_mapped         16
 #define XENFEAT_direct_mapped             17
 
+/*
+ * Signal whether the domain is permitted to use the following hypercalls:
+ *
+ * VCPUOP_register_runstate_phys_area
+ * VCPUOP_register_vcpu_time_phys_area
+ */
+#define XENFEAT_runstate_phys_area	  18
+#define XENFEAT_vcpu_time_phys_area	  19
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
xen/include/public/vcpu.h +0 -0
index 8fb0bd1b6c03..03b031a3e557 100644

xen/include/public/vcpu.h DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t); · line 244

Quoted 9 lines
xen/include/public/vcpu.h +3 -0
@@ -236,6 +236,9 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
  * Note that the area registered via VCPUOP_register_runstate_memory_area will
  * be updated in the same manner as the one registered via virtual address PLUS
  * VMASST_TYPE_runstate_update_flag engaged by the domain.
+ *
+ * XENFEAT_{runstate,vcpu_time}_phys_area feature bits signal if the domain is
+ * permitted the usage of the hypercalls.
  */
 #define VCPUOP_register_runstate_phys_area      14
 #define VCPUOP_register_vcpu_time_phys_area     15

For both of these, I'd suggest s/permitted/able/.  For older versions of Xen which don't advertise the XENFEAT, it's a matter of capability, not permission.

Otherwise, Reviewed-by: Andrew Cooper <[email protected]> and I'm happy to adjust on commit to save sending out a v3.

Thanks,

~Andrew

#8 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

Quoted 40 lines · Andrew Cooper
Quoted 25 lines · Roger Pau Monne
xen/include/public/features.h +9 -0
index d2a9175aae67..22713a51b520 100644
@@ -111,6 +111,15 @@
 #define XENFEAT_not_direct_mapped         16
 #define XENFEAT_direct_mapped             17
 
+/*
+ * Signal whether the domain is permitted to use the following hypercalls:
+ *
+ * VCPUOP_register_runstate_phys_area
+ * VCPUOP_register_vcpu_time_phys_area
+ */
+#define XENFEAT_runstate_phys_area	  18
+#define XENFEAT_vcpu_time_phys_area	  19
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
xen/include/public/vcpu.h +0 -0
index 8fb0bd1b6c03..03b031a3e557 100644

xen/include/public/vcpu.h DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t); · line 244

Quoted 9 lines
xen/include/public/vcpu.h +3 -0
@@ -236,6 +236,9 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
  * Note that the area registered via VCPUOP_register_runstate_memory_area will
  * be updated in the same manner as the one registered via virtual address PLUS
  * VMASST_TYPE_runstate_update_flag engaged by the domain.
+ *
+ * XENFEAT_{runstate,vcpu_time}_phys_area feature bits signal if the domain is
+ * permitted the usage of the hypercalls.
  */
 #define VCPUOP_register_runstate_phys_area      14
 #define VCPUOP_register_vcpu_time_phys_area     15

For both of these, I'd suggest s/permitted/able/.  For older versions of Xen which don't advertise the XENFEAT, it's a matter of capability, not permission.

Quoted 2 lines

Otherwise, Reviewed-by: Andrew Cooper <[email protected]> and I'm happy to adjust on commit to save sending out a v3.

TBH I've used permitted because that's the wording you used in your reply to v1, I'm perfectly fine with switching to able.

https://lore.kernel.org/xen-devel/[email protected]/

Thanks, Roger.

#9 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

Quoted 40 lines · Roger Pau Monné
Quoted 39 lines · Andrew Cooper
Quoted 25 lines · Roger Pau Monne
xen/include/public/features.h +9 -0
index d2a9175aae67..22713a51b520 100644
@@ -111,6 +111,15 @@
 #define XENFEAT_not_direct_mapped         16
 #define XENFEAT_direct_mapped             17
 
+/*
+ * Signal whether the domain is permitted to use the following hypercalls:
+ *
+ * VCPUOP_register_runstate_phys_area
+ * VCPUOP_register_vcpu_time_phys_area
+ */
+#define XENFEAT_runstate_phys_area	  18
+#define XENFEAT_vcpu_time_phys_area	  19
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
xen/include/public/vcpu.h +0 -0
index 8fb0bd1b6c03..03b031a3e557 100644

xen/include/public/vcpu.h DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t); · line 244

Quoted 9 lines
xen/include/public/vcpu.h +3 -0
@@ -236,6 +236,9 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
  * Note that the area registered via VCPUOP_register_runstate_memory_area will
  * be updated in the same manner as the one registered via virtual address PLUS
  * VMASST_TYPE_runstate_update_flag engaged by the domain.
+ *
+ * XENFEAT_{runstate,vcpu_time}_phys_area feature bits signal if the domain is
+ * permitted the usage of the hypercalls.
  */
 #define VCPUOP_register_runstate_phys_area      14
 #define VCPUOP_register_vcpu_time_phys_area     15

For both of these, I'd suggest s/permitted/able/.  For older versions of Xen which don't advertise the XENFEAT, it's a matter of capability, not permission.

Quoted 6 lines
Quoted 2 lines

Otherwise, Reviewed-by: Andrew Cooper <[email protected]> and I'm happy to adjust on commit to save sending out a v3.

TBH I've used permitted because that's the wording you used in your reply to v1, I'm perfectly fine with switching to able.

https://lore.kernel.org/xen-devel/[email protected]/

Yeah, sorry.  I didn't think fully before making the suggestion.

I was mainly looking to avoid saying "what the hypervisor is capable of" :)

~Andrew

#10 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

In reply to Andrew Cooper

Hi,

Quoted 42 lines · Andrew Cooper
Quoted 25 lines · Roger Pau Monne
xen/include/public/features.h +9 -0
index d2a9175aae67..22713a51b520 100644
@@ -111,6 +111,15 @@
 #define XENFEAT_not_direct_mapped         16
 #define XENFEAT_direct_mapped             17
 
+/*
+ * Signal whether the domain is permitted to use the following hypercalls:
+ *
+ * VCPUOP_register_runstate_phys_area
+ * VCPUOP_register_vcpu_time_phys_area
+ */
+#define XENFEAT_runstate_phys_area  18
+#define XENFEAT_vcpu_time_phys_area  19
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
xen/include/public/vcpu.h +0 -0
index 8fb0bd1b6c03..03b031a3e557 100644

xen/include/public/vcpu.h DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t); · line 244

Quoted 9 lines
xen/include/public/vcpu.h +3 -0
@@ -236,6 +236,9 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
 * Note that the area registered via VCPUOP_register_runstate_memory_area will
 * be updated in the same manner as the one registered via virtual address PLUS
 * VMASST_TYPE_runstate_update_flag engaged by the domain.
+ *
+ * XENFEAT_{runstate,vcpu_time}_phys_area feature bits signal if the domain is
+ * permitted the usage of the hypercalls.
 */
 #define VCPUOP_register_runstate_phys_area      14
 #define VCPUOP_register_vcpu_time_phys_area     15

For both of these, I'd suggest s/permitted/able/. For older versions of Xen which don't advertise the XENFEAT, it's a matter of capability, not permission.

Quoted 2 lines

Otherwise, Reviewed-by: Andrew Cooper <[email protected]> and I'm happy to adjust on commit to save sending out a v3.

Kind regards,
Henry

Quoted 4 lines

Thanks,

~Andrew

#11 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

In reply to Roger Pau Monne
Quoted 16 lines · Roger Pau Monne
xen/arch/x86/domain.c +4 -0
@@ -1580,6 +1580,10 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_time_memory_area area;
 
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_vcpu_time_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;

xen/common/domain.c long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) · line 2007

Quoted 10 lines
xen/common/domain.c +4 -0
@@ -1998,6 +1998,10 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_runstate_memory_area area;
 
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_runstate_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;

ENOSYS is not correct here. EPERM, EACCES, or EOPNOTSUPP would all be more correct.

xen/common/kernel.c long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 614

Quoted 12 lines
xen/common/kernel.c +5 -1
@@ -607,7 +607,11 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         switch ( fi.submap_idx )
         {
         case 0:
-            fi.submap = (1U << XENFEAT_memory_op_vnode_supported);
+            fi.submap = (1U << XENFEAT_memory_op_vnode_supported) |
+#ifdef CONFIG_X86
+                        (1U << XENFEAT_vcpu_time_phys_area) |
+#endif
+                        (1U << XENFEAT_runstate_phys_area);

No provisions here for the "disabled for this domain" case?

Jan

#12 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

Quoted 20 lines · Jan Beulich
Quoted 19 lines · Roger Pau Monne
xen/arch/x86/domain.c +4 -0
@@ -1580,6 +1580,10 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_time_memory_area area;
 
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_vcpu_time_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;
xen/common/domain.c +0 -0
@@ -1998,6 +1998,10 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_runstate_memory_area area;
 
Quoted 10 lines

xen/common/domain.c long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) · line 2007

Quoted 7 lines
xen/common/domain.c +4 -0
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_runstate_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;

ENOSYS is not correct here. EPERM, EACCES, or EOPNOTSUPP would all be more correct.

I don't think so, common_vcpu_op() default case does return -ENOSYS, and the point of this path is to mimic the behavior of an hypervisor that doesn't have the hypercalls implemented, hence -ENOSYS is the correct behavior.

Quoted 15 lines

xen/common/kernel.c long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 614

Quoted 13 lines
xen/common/kernel.c +5 -1
@@ -607,7 +607,11 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         switch ( fi.submap_idx )
         {
         case 0:
-            fi.submap = (1U << XENFEAT_memory_op_vnode_supported);
+            fi.submap = (1U << XENFEAT_memory_op_vnode_supported) |
+#ifdef CONFIG_X86
+                        (1U << XENFEAT_vcpu_time_phys_area) |
+#endif
+                        (1U << XENFEAT_runstate_phys_area);

No provisions here for the "disabled for this domain" case?

TBH I'm not sure the if ( 0 above are of much help, if we ever want to provide toolstack overwrites for those it's fairly easy to spot the paths that need to be patched anyway.

Thanks, Roger.

#13 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

Quoted 19 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
xen/common/domain.c +0 -0
@@ -1998,6 +1998,10 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_runstate_memory_area area;
 
Quoted 10 lines

xen/common/domain.c long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) · line 2007

Quoted 7 lines
xen/common/domain.c +4 -0
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_runstate_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;

ENOSYS is not correct here. EPERM, EACCES, or EOPNOTSUPP would all be more correct.

Quoted 4 lines

I don't think so, common_vcpu_op() default case does return -ENOSYS, and the point of this path is to mimic the behavior of an hypervisor that doesn't have the hypercalls implemented, hence -ENOSYS is the correct behavior.

Besides that other ENOSYS being wrong too, I question such "mimic-ing". Imo error codes should be the best representation of the real reason, not be arbitrarily "made up".

Jan

#14 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

Quoted 20 lines · Jan Beulich
Quoted 19 lines · Roger Pau Monné
Quoted 17 lines · Jan Beulich

xen/common/domain.c long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) · line 2007

Quoted 13 lines · Roger Pau Monne
xen/common/domain.c +4 -0
@@ -1998,6 +1998,10 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_runstate_memory_area area;
 
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_runstate_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;

ENOSYS is not correct here. EPERM, EACCES, or EOPNOTSUPP would all be more correct.

Quoted 8 lines
Quoted 4 lines

I don't think so, common_vcpu_op() default case does return -ENOSYS, and the point of this path is to mimic the behavior of an hypervisor that doesn't have the hypercalls implemented, hence -ENOSYS is the correct behavior.

Besides that other ENOSYS being wrong too, I question such "mimic-ing". Imo error codes should be the best representation of the real reason, not be arbitrarily "made up".

The point is for the guest to not take any action that it won't take on an hypervisor that doesn't have the hypercalls implemented, and the only way to be sure about that is to return the same exact error code.

Thanks, Roger.

#15 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

Quoted 26 lines · Roger Pau Monné
Quoted 25 lines · Jan Beulich
Quoted 23 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
xen/common/domain.c +0 -0
@@ -1998,6 +1998,10 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_runstate_memory_area area;
 
Quoted 10 lines

xen/common/domain.c long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) · line 2007

Quoted 7 lines
xen/common/domain.c +4 -0
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_runstate_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;

ENOSYS is not correct here. EPERM, EACCES, or EOPNOTSUPP would all be more correct.

I don't think so, common_vcpu_op() default case does return -ENOSYS, and the point of this path is to mimic the behavior of an hypervisor that doesn't have the hypercalls implemented, hence -ENOSYS is the correct behavior.

Quoted 7 lines
Quoted 3 lines

Besides that other ENOSYS being wrong too, I question such "mimic-ing". Imo error codes should be the best representation of the real reason, not be arbitrarily "made up".

The point is for the guest to not take any action that it won't take on an hypervisor that doesn't have the hypercalls implemented, and the only way to be sure about that is to return the same exact error code.

I don't follow this kind of reasoning. Why would a guest, whose code to use the new sub-functions has to be newly written, key its decision to the specific error code it gets, when at the same time you expose feature bits that it can use to decide whether to invoke the hypercall in the first place.

Jan

#16 lore raw

Re: [PATCH v2 2/2] domain: expose newly introduced hypercalls as XENFEAT

Quoted 35 lines · Jan Beulich
Quoted 26 lines · Roger Pau Monné
Quoted 25 lines · Jan Beulich
Quoted 23 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
xen/common/domain.c +0 -0
@@ -1998,6 +1998,10 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct vcpu_register_runstate_memory_area area;
 
Quoted 10 lines

xen/common/domain.c long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) · line 2007

Quoted 7 lines
xen/common/domain.c +4 -0
+        rc = -ENOSYS;
+        if ( 0 /* TODO: Dom's XENFEAT_runstate_phys_area setting */ )
+            break;
+
         rc = -EFAULT;
         if ( copy_from_guest(&area.addr.p, arg, 1) )
             break;

ENOSYS is not correct here. EPERM, EACCES, or EOPNOTSUPP would all be more correct.

I don't think so, common_vcpu_op() default case does return -ENOSYS, and the point of this path is to mimic the behavior of an hypervisor that doesn't have the hypercalls implemented, hence -ENOSYS is the correct behavior.

Quoted 7 lines
Quoted 3 lines

Besides that other ENOSYS being wrong too, I question such "mimic-ing". Imo error codes should be the best representation of the real reason, not be arbitrarily "made up".

The point is for the guest to not take any action that it won't take on an hypervisor that doesn't have the hypercalls implemented, and the only way to be sure about that is to return the same exact error code.

Quoted 5 lines

I don't follow this kind of reasoning. Why would a guest, whose code to use the new sub-functions has to be newly written, key its decision to the specific error code it gets, when at the same time you expose feature bits that it can use to decide whether to invoke the hypercall in the first place.

Because we don't control all possible guest implementations out there.

AIUI the point of introducing a way to disable the newly added hypercalls is to make the interface between a Xen previous to the introduction of the hypercalls vs a Xen that has the hypercalls disabled equal, and that requires returning the same error code IMO, or else interfaces are not equal.

Thanks, Roger.