Skip to contentSkip to conversation

passthrough/pci: properly qualify the mem_sharing_enabled check...

PATCH In review Paul Durrant 2 participants 5 messages Jul 1, 2019 – Jul 3, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 passthrough/pci: properly qualify the mem_sharing_enabled check...

...in assign_device().

The check of arch.hvm.mem_sharing_enabled flag at the top of drivers/passthrough/pci.c:assign_device() does not make sure that the domain is actually an HVM domain.

This patch fixes the issue by moving the definition of the mem_sharing_enabled() macro from mem_sharing.c into asm-86/hvm/domain.h and then using that instead.

---
Cc: Tamas K Lengyel <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/mm/mem_sharing.c    | 3 ---
 xen/drivers/passthrough/pci.c    | 2 +-
 xen/include/asm-x86/hvm/domain.h | 3 +++
 3 files changed, 4 insertions(+), 4 deletions(-)
xen/arch/x86/mm/mem_sharing.c +0 -3
index f16a3f5324..db02f4dfd5 100644
@@ -149,9 +149,6 @@ static inline shr_handle_t get_next_handle(void)
     return x + 1;
 }
 
-#define mem_sharing_enabled(d) \
-    (is_hvm_domain(d) && (d)->arch.hvm.mem_sharing_enabled)
-
 static atomic_t nr_saved_mfns   = ATOMIC_INIT(0); 
 static atomic_t nr_shared_mfns  = ATOMIC_INIT(0);
 
xen/drivers/passthrough/pci.c +1 -1
index e88689425d..7697ec440d 100644
@@ -1450,7 +1450,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag)
 
     /* Prevent device assign if mem paging or mem sharing have been 
      * enabled for this domain */
-    if ( unlikely(d->arch.hvm.mem_sharing_enabled ||
+    if ( unlikely(mem_sharing_enabled(d) ||
                   vm_event_check_ring(d->vm_event_paging) ||
                   p2m_get_hostp2m(d)->global_logdirty) )
         return -EXDEV;
xen/include/asm-x86/hvm/domain.h +3 -0
index 6c7c4f5aa6..1e6e3ce078 100644
@@ -197,8 +197,11 @@ struct hvm_domain {
 
 #ifdef CONFIG_HVM
 #define hap_enabled(d)  (is_hvm_domain(d) && (d)->arch.hvm.hap_enabled)
+#define mem_sharing_enabled(d) \
+    (is_hvm_domain(d) && (d)->arch.hvm.mem_sharing_enabled)
 #else
 #define hap_enabled(d)  ({(void)(d); false;})
+#define mem_sharing_enabled(d)  ({(void)(d); false;})
 #endif
 
 #endif /* __ASM_X86_HVM_DOMAIN_H__ */
Signature · 7 lines
2.20.1.2.gb21ebb671


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

xen/drivers/passthrough/pci.c static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) · line 1456

Quoted 11 lines · Paul Durrant
xen/drivers/passthrough/pci.c +1 -1
@@ -1450,7 +1450,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag)
 
      /* Prevent device assign if mem paging or mem sharing have been
       * enabled for this domain */
-    if ( unlikely(d->arch.hvm.mem_sharing_enabled ||
+    if ( unlikely(mem_sharing_enabled(d) ||
                    vm_event_check_ring(d->vm_event_paging) ||
                    p2m_get_hostp2m(d)->global_logdirty) )
          return -EXDEV;

This change is redundant with the more extensive one by "x86/HVM: p2m_ram_ro is incompatible with device pass-through", of which I've sent v2 earlier today, and v1 of which has been pending for quite some time without having heard back from other than you.

Jan

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

#2 lore raw
Quoted 22 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 July 2019 14:20
To: Paul Durrant <[email protected]>; [email protected]
Cc: Andrew Cooper <[email protected]>; Roger Pau Monne <[email protected]>; George Dunlap <[email protected]>; Tamas K Lengyel <[email protected]>; WeiLiu <[email protected]>
Subject: Re: [PATCH] passthrough/pci: properly qualify the mem_sharing_enabled check...

xen/drivers/passthrough/pci.c static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32

Quoted 3 lines · Paul Durrant
xen/drivers/passthrough/pci.c +0 -0
@@ -1450,7 +1450,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32

flag)

xen/drivers/passthrough/pci.c static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) · line 1456

Quoted 8 lines
xen/drivers/passthrough/pci.c +1 -1
      /* Prevent device assign if mem paging or mem sharing have been
       * enabled for this domain */
-    if ( unlikely(d->arch.hvm.mem_sharing_enabled ||
+    if ( unlikely(mem_sharing_enabled(d) ||
                    vm_event_check_ring(d->vm_event_paging) ||
                    p2m_get_hostp2m(d)->global_logdirty) )
          return -EXDEV;
Quoted 5 lines

This change is redundant with the more extensive one by "x86/HVM: p2m_ram_ro is incompatible with device pass-through", of which I've sent v2 earlier today, and v1 of which has been pending for quite some time without having heard back from other than you.

Agreed, but I still think it's a good idea to move the mem_sharing_enabled() macro into domain.h, so maybe incorporate that into your patch? I'll take a look at v2 as soon as I can.

Paul

Quoted 2 lines

Jan

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

#3 lore raw
Quoted 28 lines · Paul Durrant
Quoted 22 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 July 2019 14:20
To: Paul Durrant <[email protected]>; [email protected]
Cc: Andrew Cooper <[email protected]>; Roger Pau Monne <[email protected]>; George Dunlap <[email protected]>; Tamas K Lengyel <[email protected]>; WeiLiu <[email protected]>
Subject: Re: [PATCH] passthrough/pci: properly qualify the mem_sharing_enabled check...

xen/drivers/passthrough/pci.c static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32

Quoted 3 lines · Paul Durrant
xen/drivers/passthrough/pci.c +0 -0
@@ -1450,7 +1450,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32

flag)

xen/drivers/passthrough/pci.c static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) · line 1456

Quoted 8 lines
xen/drivers/passthrough/pci.c +1 -1
       /* Prevent device assign if mem paging or mem sharing have been
        * enabled for this domain */
-    if ( unlikely(d->arch.hvm.mem_sharing_enabled ||
+    if ( unlikely(mem_sharing_enabled(d) ||
                     vm_event_check_ring(d->vm_event_paging) ||
                     p2m_get_hostp2m(d)->global_logdirty) )
           return -EXDEV;
Quoted 5 lines

This change is redundant with the more extensive one by "x86/HVM: p2m_ram_ro is incompatible with device pass-through", of which I've sent v2 earlier today, and v1 of which has been pending for quite some time without having heard back from other than you.

Quoted 3 lines

Agreed, but I still think it's a good idea to move the mem_sharing_enabled() macro into domain.h, so maybe incorporate that into your patch?

Hmm, that would actually have been a question of mine if I hadn't recognized the redundancy: Why domain.h rather than mem_sharing.h? Furthermore I'd rather not use it here anyway, to avoid two consecutive is_hvm_*() checks (which have become slightly more expensive with the LFENCE addition).

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

#4 lore raw
Quoted 42 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 July 2019 14:30
To: Paul Durrant <[email protected]>; [email protected]
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Roger Pau Monne <[email protected]>; Tamas KLengyel <[email protected]>; WeiLiu <[email protected]>
Subject: Re: [PATCH] passthrough/pci: properly qualify the mem_sharing_enabled check...

Quoted 5 lines · Paul Durrant
Quoted 5 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 July 2019 14:20
To: Paul Durrant <[email protected]>; [email protected]
Cc: Andrew Cooper <[email protected]>; Roger Pau Monne <[email protected]>; George

Dunlap

Quoted 23 lines
Quoted 17 lines

<[email protected]>; Tamas K Lengyel <[email protected]>; WeiLiu <[email protected]>
Subject: Re: [PATCH] passthrough/pci: properly qualify the mem_sharing_enabled check...

xen/drivers/passthrough/pci.c static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32

Quoted 3 lines · Paul Durrant
xen/drivers/passthrough/pci.c +0 -0
@@ -1450,7 +1450,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32

flag)

xen/drivers/passthrough/pci.c static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) · line 1456

Quoted 8 lines
xen/drivers/passthrough/pci.c +1 -1
       /* Prevent device assign if mem paging or mem sharing have been
        * enabled for this domain */
-    if ( unlikely(d->arch.hvm.mem_sharing_enabled ||
+    if ( unlikely(mem_sharing_enabled(d) ||
                     vm_event_check_ring(d->vm_event_paging) ||
                     p2m_get_hostp2m(d)->global_logdirty) )
           return -EXDEV;
Quoted 5 lines

This change is redundant with the more extensive one by "x86/HVM: p2m_ram_ro is incompatible with device pass-through", of which I've sent v2 earlier today, and v1 of which has been pending for quite some time without having heard back from other than you.

Quoted 3 lines

Agreed, but I still think it's a good idea to move the mem_sharing_enabled() macro into domain.h, so maybe incorporate that into your patch?

Quoted 5 lines

Hmm, that would actually have been a question of mine if I hadn't recognized the redundancy: Why domain.h rather than mem_sharing.h? Furthermore I'd rather not use it here anyway, to avoid two consecutive is_hvm_*() checks (which have become slightly more expensive with the LFENCE addition).

Maybe mem_sharing.h is a more logical location, but I think providing a macro to make sure the is_hvm_domain() protection is there is a good thing. As for using it here, yes I guess the addition of the speculation barrier makes it more expensive but then is not really performance critical code so I'd go for tidiness.

Paul

Quoted 2 lines

Jan

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