nested EPT: fixing wrong handling for L2 guest's direct mmio access
PATCH 1/1 nested EPT: fixing wrong handling for L2 guest's direct mmio access
From: Yang Zhang <[email protected]>
L2 guest will access the physical device directly(nested VT-d). For such access, Shadow EPT table should point to device's MMIO. But in current logic, L0 doesn't distinguish the MMIO whether from qemu or physical device when building shadow EPT table. This is wrong. This patch will setup the correct shadow EPT table for such MMIO ranges.
--- xen/arch/x86/mm/hap/nested_hap.c | 10 ++++++++-- xen/include/asm-x86/hvm/nestedhvm.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-)
xen/arch/x86/mm/hap/nested_hap.c +8 -2
@@ -170,8 +170,11 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa, mfn =get_gfn_type_access (p2m, L1_gpa >>PAGE_SHIFT , p2mt, p2ma,0 , page_order); + rc =NESTEDHVM_PAGEFAULT_DIRECT_MMIO ; +if ( *p2mt == p2m_mmio_direct ) + goto direct_mmio_out; rc =NESTEDHVM_PAGEFAULT_MMIO ; -if (p2m_is_mmio (*p2mt) ) +if ( *p2mt == p2m_mmio_dm ) goto out; rc =NESTEDHVM_PAGEFAULT_L0_ERROR ;
@@ -184,8 +187,9 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa,if ( !mfn_valid (mfn) ) goto out; - *L0_gpa = (mfn_x (mfn) <<PAGE_SHIFT ) + (L1_gpa & ~PAGE_MASK ); rc =NESTEDHVM_PAGEFAULT_DONE ; +direct_mmio_out: + *L0_gpa = (mfn_x (mfn) <<PAGE_SHIFT ) + (L1_gpa & ~PAGE_MASK ); out:__put_gfn (p2m, L1_gpa >>PAGE_SHIFT );return rc;
@@ -245,6 +249,8 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t *L2_gpa,break ;case NESTEDHVM_PAGEFAULT_MMIO :return rv; +case NESTEDHVM_PAGEFAULT_DIRECT_MMIO : +break ;default :BUG ();break ;
xen/include/asm-x86/hvm/nestedhvm.h +1 -0
@@ -53,6 +53,7 @@ bool_t nestedhvm_vcpu_in_guestmode(struct vcpu *v);#define NESTEDHVM_PAGEFAULT_L0_ERROR 3#define NESTEDHVM_PAGEFAULT_MMIO 4#define NESTEDHVM_PAGEFAULT_RETRY 5 +#define NESTEDHVM_PAGEFAULT_DIRECT_MMIO 6int nestedhvm_hap_nested_page_fault (struct vcpu *v,paddr_t *L2_gpa,bool_t access_r,bool_t access_w,bool_t access_x);
Signature · 1 line
1.7.1
Quoted 18 lines · Yang Zhang
From: Yang Zhang <[email protected]>
L2 guest will access the physical device directly(nested VT-d). For such access, Shadow EPT table should point to device's MMIO. But in current logic, L0 doesn't distinguish the MMIO whether from qemu or physical device when building shadow EPT table. This is wrong. This patch will setup the correct shadow EPT table for such MMIO ranges.
Signed-off-by Yang Zhang <[email protected]>--- xen/arch/x86/mm/hap/nested_hap.c | 10 ++++++++-- xen/include/asm-x86/hvm/nestedhvm.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-)xen/arch/x86/mm/hap/nested_hap.c +0
-0
xen/arch/x86/mm/hap/nested_hap.c nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa, · line 178
Quoted 10 lines
xen/arch/x86/mm/hap/nested_hap.c +4
-1@@ -170,8 +170,11 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa, mfn =get_gfn_type_access (p2m, L1_gpa >>PAGE_SHIFT , p2mt, p2ma,0 , page_order); + rc =NESTEDHVM_PAGEFAULT_DIRECT_MMIO ; +if ( *p2mt == p2m_mmio_direct ) + goto direct_mmio_out; rc =NESTEDHVM_PAGEFAULT_MMIO ; -if (p2m_is_mmio (*p2mt) ) +if ( *p2mt == p2m_mmio_dm ) goto out;
Why does p2m_is_mmio() not cover p2m_mmio_direct ?
Christoph
Quoted 34 lines
xen/arch/x86/mm/hap/nested_hap.c +4
-1rc =NESTEDHVM_PAGEFAULT_L0_ERROR ;@@ -184,8 +187,9 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa,if ( !mfn_valid (mfn) ) goto out; - *L0_gpa = (mfn_x (mfn) <<PAGE_SHIFT ) + (L1_gpa & ~PAGE_MASK ); rc =NESTEDHVM_PAGEFAULT_DONE ; +direct_mmio_out: + *L0_gpa = (mfn_x (mfn) <<PAGE_SHIFT ) + (L1_gpa & ~PAGE_MASK ); out:__put_gfn (p2m, L1_gpa >>PAGE_SHIFT );return rc;@@ -245,6 +249,8 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t *L2_gpa,break ;case NESTEDHVM_PAGEFAULT_MMIO :return rv; +case NESTEDHVM_PAGEFAULT_DIRECT_MMIO : +break ;default :BUG ();break ;xen/include/asm-x86/hvm/nestedhvm.h +1
-0@@ -53,6 +53,7 @@ bool_t nestedhvm_vcpu_in_guestmode(struct vcpu *v);#define NESTEDHVM_PAGEFAULT_L0_ERROR 3#define NESTEDHVM_PAGEFAULT_MMIO 4#define NESTEDHVM_PAGEFAULT_RETRY 5 +#define NESTEDHVM_PAGEFAULT_DIRECT_MMIO 6int nestedhvm_hap_nested_page_fault (struct vcpu *v,paddr_t *L2_gpa,bool_t access_r,bool_t access_w,bool_t access_x);
Quoted 22 lines · Christoph
Quoted 21 lines · Yang Zhang
From: Yang Zhang <[email protected]>
L2 guest will access the physical device directly(nested VT-d). For such access, Shadow EPT table should point to device's MMIO. But in current logic, L0 doesn't distinguish the MMIO whether from qemu or physical device when building shadow EPT table. This is wrong. This patch will setup the correct shadow EPT table for such MMIO ranges.
Signed-off-by Yang Zhang <[email protected]>--- xen/arch/x86/mm/hap/nested_hap.c | 10 ++++++++-- xen/include/asm-x86/hvm/nestedhvm.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-)xen/arch/x86/mm/hap/nested_hap.c +0
-0@@ -170,8 +170,11 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa, mfn =get_gfn_type_access (p2m, L1_gpa >>PAGE_SHIFT , p2mt, p2ma,0 , page_order);
Quoted 9 lines
xen/arch/x86/mm/hap/nested_hap.c nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa, · line 178
Quoted 7 lines
xen/arch/x86/mm/hap/nested_hap.c +4
-1+ rc =NESTEDHVM_PAGEFAULT_DIRECT_MMIO ; +if ( *p2mt == p2m_mmio_direct ) + goto direct_mmio_out; rc =NESTEDHVM_PAGEFAULT_MMIO ; -if (p2m_is_mmio (*p2mt) ) +if ( *p2mt == p2m_mmio_dm ) goto out;Why does
p2m_is_mmio()not coverp2m_mmio_direct?
It does. This code is changing to cover the two kinds of mmio separately.
Tim.
Quoted 8 lines · Yang Zhang
From: Yang Zhang <[email protected]>
L2 guest will access the physical device directly(nested VT-d). For such access, Shadow EPT table should point to device's MMIO. But in current logic, L0 doesn't distinguish the MMIO whether from qemu or physical device when building shadow EPT table. This is wrong. This patch will setup the correct shadow EPT table for such MMIO ranges.
Signed-off-by Yang Zhang <[email protected]>