x86/svm: do not try to handle recalc NPT faults immediately
PATCH v2 1/1 x86/svm: do not try to handle recalc NPT faults immediately
A recalculation NPT fault doesn't always require additional handling in hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal.
This covers a specific case of migration with vGPU assigned on AMD:
at a moment log-dirty is enabled globally, recalculation is requested for the whole guest memory including directly mapped MMIO regions of vGPU which causes a page fault being raised at the first access to those; but due to MMIO P2M type not having any explicit handling in hvm_hap_nested_page_fault() a domain is erroneously crashed with unhandled SVM violation.
Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in hvm_hap_nested_page_fault(). Do it by also unifying do_recalc return code with Intel implementation where returning 1 means P2M was actually changed.
Since there was no case previously where p2m_pt_handle_deferred_changes() could return a positive value - it's safe to replace ">= 0" with just "== 0" in VMEXIT_NPF handler. finish_type_change() is also not affected by the change as being able to deal with >0 return value of p2m->recalc from EPT implementation.
---
Changes in v2:
- replace rc with recalc_done bool
- updated comment in finish_type_change()
- significantly extended commit description
--- xen/arch/x86/hvm/svm/svm.c | 5 +++-- xen/arch/x86/mm/p2m-pt.c | 7 ++++++- xen/arch/x86/mm/p2m.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/svm/svm.c +3 -2
@@ -2923,9 +2923,10 @@ void svm_vmexit_handler(struct cpu_user_regs *regs) v->arch.hvm.svm.cached_insn_len = vmcb->guest_ins_len &0xf ; rc = vmcb->exitinfo1 & PFEC_page_present ?p2m_pt_handle_deferred_changes (vmcb->exitinfo2) :0 ; -if ( rc >=0 ) +if ( rc ==0 ) +/* If no recal adjustments were being made - handle this fault */ svm_do_nested_pgfault (v, regs, vmcb->exitinfo1, vmcb->exitinfo2); -else +else if ( rc <0 ) { printk(XENLOG_G_ERR "%pv: Error %d handling NPF (gpa=%08lx ec=%04lx)\n",
xen/arch/x86/mm/p2m-pt.c +6 -1
@@ -341,6 +341,7 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)unsigned int level =4 ;l1_pgentry_t *pent;int err =0 ; +bool recalc_done = false; table =map_domain_page (pagetable_get_mfn (p2m_get_pagetable (p2m)));while ( --level )
@@ -402,6 +403,8 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)clear_recalc (l1, e); err = p2m->write_p2m_entry (p2m, gfn, pent, e, level +1 );ASSERT (!err); + + recalc_done = true; } }unmap_domain_page ((void *)((unsigned long )pent &PAGE_MASK ));
@@ -448,12 +451,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)clear_recalc (l1, e); err = p2m->write_p2m_entry (p2m, gfn, pent, e, level +1 );ASSERT (!err); + + recalc_done = true; } out:unmap_domain_page (table); -return err; +return err ?: (recalc_done ?1 :0 ); }int p2m_pt_handle_deferred_changes (uint64_t gpa)
xen/arch/x86/mm/p2m.c +1 -1
@@ -1197,7 +1197,7 @@ static int finish_type_change(struct p2m_domain *p2m, rc = p2m->recalc (p2m, gfn);/* * ept->recalc could return 0/1/-ENOMEM. pt->recalc could return -* 0/-ENOMEM/-ENOENT, -ENOENT isn't an error as we are looping +* 0/1/-ENOMEM/-ENOENT, -ENOENT isn't an error as we are looping * gfn here. If rc is 1 we need to have it 0 for success. */ if ( rc == -ENOENT || rc >0 )
Signature · 1 line
2.7.4
Quoted 20 lines · Igor Druzhinin
A recalculation NPT fault doesn't always require additional handling in
hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal.This covers a specific case of migration with vGPU assigned on AMD:
at a moment log-dirty is enabled globally, recalculation is requested for the whole guest memory including directly mapped MMIO regions of vGPU which causes a page fault being raised at the first access to those; but due to MMIO P2M type not having any explicit handling inhvm_hap_nested_page_fault()a domain is erroneously crashed with unhandled SVM violation.Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in
hvm_hap_nested_page_fault(). Do it by also unifyingdo_recalcreturn code with Intel implementation where returning 1 means P2M was actually changed.
Quoted 8 lines
Since there was no case previously where
p2m_pt_handle_deferred_changes()could return a positive value - it's safe to replace ">= 0" with just "== 0" inVMEXIT_NPFhandler.finish_type_change()is also not affected by the change as being able to deal with >0 return value ofp2m->recalcfrom EPT implementation.Reviewed-by Roger Pau Monné <[email protected]>Signed-off-by Igor Druzhinin <[email protected]>
albeit preferably with ...
xen/arch/x86/mm/p2m-pt.c static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) · line 461
Quoted 13 lines
xen/arch/x86/mm/p2m-pt.c +3
-1@@ -448,12 +451,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)clear_recalc (l1, e); err = p2m->write_p2m_entry (p2m, gfn, pent, e, level +1 );ASSERT (!err); + + recalc_done = true; } out:unmap_domain_page (table); -return err; +return err ?: (recalc_done ?1 :0 );
... this shrunk to
return err ?: recalc_done;
(easily doable while committing).
Also Cc Paul.
Jan
Quoted 57 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 11:03
To: Igor Druzhinin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Paul Durrant <[email protected]>
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 20 lines · Igor Druzhinin
A recalculation NPT fault doesn't always require additional handling in
hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal.This covers a specific case of migration with vGPU assigned on AMD:
at a moment log-dirty is enabled globally, recalculation is requested for the whole guest memory including directly mapped MMIO regions of vGPU which causes a page fault being raised at the first access to those; but due to MMIO P2M type not having any explicit handling inhvm_hap_nested_page_fault()a domain is erroneously crashed with unhandled SVM violation.Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in
hvm_hap_nested_page_fault(). Do it by also unifyingdo_recalcreturn code with Intel implementation where returning 1 means P2M was actually changed.Quoted 8 lines
Since there was no case previously where
p2m_pt_handle_deferred_changes()could return a positive value - it's safe to replace ">= 0" with just "== 0" inVMEXIT_NPFhandler.finish_type_change()is also not affected by the change as being able to deal with >0 return value ofp2m->recalcfrom EPT implementation.Reviewed-by Roger Pau Monné <[email protected]>Signed-off-by Igor Druzhinin <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit preferably with ...
xen/arch/x86/mm/p2m-pt.c static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) · line 461
Quoted 13 lines
xen/arch/x86/mm/p2m-pt.c +3
-1@@ -448,12 +451,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)clear_recalc (l1, e); err = p2m->write_p2m_entry (p2m, gfn, pent, e, level +1 );ASSERT (!err); + + recalc_done = true; } out:unmap_domain_page (table); -return err; +return err ?: (recalc_done ?1 :0 );... this shrunk to
Quoted 6 lines
return err ?: recalc_done;(easily doable while committing).
Also Cc Paul.
paging_log_dirty_enable() still fails global enable if has_arch_pdevs() is true, so presumably there's no desperate need for this to go in 4.14?
Paul
Quoted 1 line
Jan
Quoted 59 lines · Paul Durrant
Quoted 59 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 11:03
To: Igor Druzhinin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Paul Durrant <[email protected]>
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 20 lines · Igor Druzhinin
A recalculation NPT fault doesn't always require additional handling in
hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal.This covers a specific case of migration with vGPU assigned on AMD:
at a moment log-dirty is enabled globally, recalculation is requested for the whole guest memory including directly mapped MMIO regions of vGPU which causes a page fault being raised at the first access to those; but due to MMIO P2M type not having any explicit handling inhvm_hap_nested_page_fault()a domain is erroneously crashed with unhandled SVM violation.Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in
hvm_hap_nested_page_fault(). Do it by also unifyingdo_recalcreturn code with Intel implementation where returning 1 means P2M was actually changed.Quoted 8 lines
Since there was no case previously where
p2m_pt_handle_deferred_changes()could return a positive value - it's safe to replace ">= 0" with just "== 0" inVMEXIT_NPFhandler.finish_type_change()is also not affected by the change as being able to deal with >0 return value ofp2m->recalcfrom EPT implementation.Reviewed-by Roger Pau Monné <[email protected]>Signed-off-by Igor Druzhinin <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit preferably with ...
xen/arch/x86/mm/p2m-pt.c static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) · line 461
Quoted 13 lines
xen/arch/x86/mm/p2m-pt.c +3
-1@@ -448,12 +451,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)clear_recalc (l1, e); err = p2m->write_p2m_entry (p2m, gfn, pent, e, level +1 );ASSERT (!err); + + recalc_done = true; } out:unmap_domain_page (table); -return err; +return err ?: (recalc_done ?1 :0 );... this shrunk to
return err ?: recalc_done;
Quoted 7 lines
Quoted 4 lines
(easily doable while committing).
Also Cc Paul.
paging_log_dirty_enable()still fails global enable ifhas_arch_pdevs()is true, so presumably there's no desperate need for this to go in 4.14?
The MMIO case is just the particular situation here. Aiui the same issue could potentially surface with other p2m types. Also given I'd consider this a backporting candidate, while it may not be desperately needed for the release, I think it deserves considering beyond the specific aspect you mention.
Jan
Quoted 73 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 12:22
To: [email protected]
Cc: 'Igor Druzhinin' <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 64 lines · Paul Durrant
Quoted 63 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 11:03
To: Igor Druzhinin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Paul Durrant <[email protected]>
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 20 lines · Igor Druzhinin
A recalculation NPT fault doesn't always require additional handling in
hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal.This covers a specific case of migration with vGPU assigned on AMD:
at a moment log-dirty is enabled globally, recalculation is requested for the whole guest memory including directly mapped MMIO regions of vGPU which causes a page fault being raised at the first access to those; but due to MMIO P2M type not having any explicit handling inhvm_hap_nested_page_fault()a domain is erroneously crashed with unhandled SVM violation.Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in
hvm_hap_nested_page_fault(). Do it by also unifyingdo_recalcreturn code with Intel implementation where returning 1 means P2M was actually changed.Quoted 8 lines
Since there was no case previously where
p2m_pt_handle_deferred_changes()could return a positive value - it's safe to replace ">= 0" with just "== 0" inVMEXIT_NPFhandler.finish_type_change()is also not affected by the change as being able to deal with >0 return value ofp2m->recalcfrom EPT implementation.Reviewed-by Roger Pau Monné <[email protected]>Signed-off-by Igor Druzhinin <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit preferably with ...
xen/arch/x86/mm/p2m-pt.c static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) · line 461
Quoted 13 lines
xen/arch/x86/mm/p2m-pt.c +3
-1@@ -448,12 +451,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)clear_recalc (l1, e); err = p2m->write_p2m_entry (p2m, gfn, pent, e, level +1 );ASSERT (!err); + + recalc_done = true; } out:unmap_domain_page (table); -return err; +return err ?: (recalc_done ?1 :0 );... this shrunk to
return err ?: recalc_done;(easily doable while committing).
Also Cc Paul.
Quoted 9 lines
Quoted 2 lines
paging_log_dirty_enable()still fails global enable ifhas_arch_pdevs()is true, so presumably there's no desperate need for this to go in 4.14?The MMIO case is just the particular situation here. Aiui the same issue could potentially surface with other p2m types. Also given I'd consider this a backporting candidate, while it may not be desperately needed for the release, I think it deserves considering beyond the specific aspect you mention.
In which case I think the commit message probably ought to be rephrased, since it appears to focus on a case that cannot currently happen.
Paul
Quoted 76 lines · Paul Durrant
Quoted 76 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 12:22
To: [email protected]
Cc: 'Igor Druzhinin' <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 66 lines · Paul Durrant
Quoted 57 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 11:03
To: Igor Druzhinin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Paul Durrant <[email protected]>
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 20 lines · Igor Druzhinin
A recalculation NPT fault doesn't always require additional handling in
hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal.This covers a specific case of migration with vGPU assigned on AMD:
at a moment log-dirty is enabled globally, recalculation is requested for the whole guest memory including directly mapped MMIO regions of vGPU which causes a page fault being raised at the first access to those; but due to MMIO P2M type not having any explicit handling inhvm_hap_nested_page_fault()a domain is erroneously crashed with unhandled SVM violation.Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in
hvm_hap_nested_page_fault(). Do it by also unifyingdo_recalcreturn code with Intel implementation where returning 1 means P2M was actually changed.Quoted 8 lines
Since there was no case previously where
p2m_pt_handle_deferred_changes()could return a positive value - it's safe to replace ">= 0" with just "== 0" inVMEXIT_NPFhandler.finish_type_change()is also not affected by the change as being able to deal with >0 return value ofp2m->recalcfrom EPT implementation.Reviewed-by Roger Pau Monné <[email protected]>Signed-off-by Igor Druzhinin <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit preferably with ...
xen/arch/x86/mm/p2m-pt.c static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) · line 461
Quoted 13 lines
xen/arch/x86/mm/p2m-pt.c +3
-1@@ -448,12 +451,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)clear_recalc (l1, e); err = p2m->write_p2m_entry (p2m, gfn, pent, e, level +1 );ASSERT (!err); + + recalc_done = true; } out:unmap_domain_page (table); -return err; +return err ?: (recalc_done ?1 :0 );... this shrunk to
Quoted 6 lines
return err ?: recalc_done;(easily doable while committing).
Also Cc Paul.
paging_log_dirty_enable()still fails global enable ifhas_arch_pdevs()is true, so presumably there's no desperate need for this to go in 4.14?
Quoted 8 lines
Quoted 6 lines
The MMIO case is just the particular situation here. Aiui the same issue could potentially surface with other p2m types. Also given I'd consider this a backporting candidate, while it may not be desperately needed for the release, I think it deserves considering beyond the specific aspect you mention.
In which case I think the commit message probably ought to be rephrased, since it appears to focus on a case that cannot currently happen.
This can happen without has_arch_pdevs() being true. It's enough to just directly map some physical memory into a guest to get p2m_direct_mmio type present in the page tables.
Igor
Quoted 92 lines
-----Original Message-----
From: Igor Druzhinin <[email protected]>
Sent: 03 June 2020 12:45
To: [email protected]; 'Jan Beulich' <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 83 lines · Paul Durrant
Quoted 82 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 12:22
To: [email protected]
Cc: 'Igor Druzhinin' <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 59 lines · Paul Durrant
Quoted 59 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 11:03
To: Igor Druzhinin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Paul Durrant <[email protected]>
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 20 lines · Igor Druzhinin
A recalculation NPT fault doesn't always require additional handling in
hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal.This covers a specific case of migration with vGPU assigned on AMD:
at a moment log-dirty is enabled globally, recalculation is requested for the whole guest memory including directly mapped MMIO regions of vGPU which causes a page fault being raised at the first access to those; but due to MMIO P2M type not having any explicit handling inhvm_hap_nested_page_fault()a domain is erroneously crashed with unhandled SVM violation.Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in
hvm_hap_nested_page_fault(). Do it by also unifyingdo_recalcreturn code with Intel implementation where returning 1 means P2M was actually changed.Quoted 8 lines
Since there was no case previously where
p2m_pt_handle_deferred_changes()could return a positive value - it's safe to replace ">= 0" with just "== 0" inVMEXIT_NPFhandler.finish_type_change()is also not affected by the change as being able to deal with >0 return value ofp2m->recalcfrom EPT implementation.Reviewed-by Roger Pau Monné <[email protected]>Signed-off-by Igor Druzhinin <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit preferably with ...
xen/arch/x86/mm/p2m-pt.c static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) · line 461
Quoted 13 lines
xen/arch/x86/mm/p2m-pt.c +3
-1@@ -448,12 +451,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)clear_recalc (l1, e); err = p2m->write_p2m_entry (p2m, gfn, pent, e, level +1 );ASSERT (!err); + + recalc_done = true; } out:unmap_domain_page (table); -return err; +return err ?: (recalc_done ?1 :0 );... this shrunk to
return err ?: recalc_done;Quoted 7 lines
Quoted 4 lines
(easily doable while committing).
Also Cc Paul.
paging_log_dirty_enable()still fails global enable ifhas_arch_pdevs()is true, so presumably there's no desperate need for this to go in 4.14?The MMIO case is just the particular situation here. Aiui the same issue could potentially surface with other p2m types. Also given I'd consider this a backporting candidate, while it may not be desperately needed for the release, I think it deserves considering beyond the specific aspect you mention.
Quoted 6 lines
Quoted 1 line
In which case I think the commit message probably ought to be rephrased, since it appears to focus
on a case that cannot currently happen.
This can happen without
has_arch_pdevs()being true. It's enough to just directly map some physical memory into a guest to getp2m_direct_mmiotype present in the page tables.
OK, that's fine, but when will that happen without pass-through? If we can have a commit message justifying the change based on what can actually happen now, then I would not be opposed to it going in 4.14.
Paul
Quoted 2 lines
Igor
Quoted 92 lines · Paul Durrant
Quoted 92 lines
-----Original Message-----
From: Igor Druzhinin <[email protected]>
Sent: 03 June 2020 12:45
To: [email protected]; 'Jan Beulich' <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 83 lines · Paul Durrant
Quoted 82 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 12:22
To: [email protected]
Cc: 'Igor Druzhinin' <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 59 lines · Paul Durrant
Quoted 59 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 03 June 2020 11:03
To: Igor Druzhinin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Paul Durrant <[email protected]>
Subject: Re: [PATCH v2] x86/svm: do not try to handle recalc NPT faults immediatelyQuoted 20 lines · Igor Druzhinin
A recalculation NPT fault doesn't always require additional handling in
hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal.This covers a specific case of migration with vGPU assigned on AMD:
at a moment log-dirty is enabled globally, recalculation is requested for the whole guest memory including directly mapped MMIO regions of vGPU which causes a page fault being raised at the first access to those; but due to MMIO P2M type not having any explicit handling inhvm_hap_nested_page_fault()a domain is erroneously crashed with unhandled SVM violation.Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in
hvm_hap_nested_page_fault(). Do it by also unifyingdo_recalcreturn code with Intel implementation where returning 1 means P2M was actually changed.Quoted 8 lines
Since there was no case previously where
p2m_pt_handle_deferred_changes()could return a positive value - it's safe to replace ">= 0" with just "== 0" inVMEXIT_NPFhandler.finish_type_change()is also not affected by the change as being able to deal with >0 return value ofp2m->recalcfrom EPT implementation.Reviewed-by Roger Pau Monné <[email protected]>Signed-off-by Igor Druzhinin <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit preferably with ...
Review static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) · line 461
Quoted 13 lines
(quoted diff) +3
-1@@ -448,12 +451,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn) clear_recalc(l1, e); err = p2m->write_p2m_entry(p2m, gfn, pent, e, level + 1); ASSERT(!err); + + recalc_done = true; } out: unmap_domain_page(table); - return err; + return err ?: (recalc_done ? 1 : 0);... this shrunk to
return err ?: recalc_done;Quoted 7 lines
Quoted 4 lines
(easily doable while committing).
Also Cc Paul.
paging_log_dirty_enable()still fails global enable ifhas_arch_pdevs()is true, so presumably there's no desperate need for this to go in 4.14?The MMIO case is just the particular situation here. Aiui the same issue could potentially surface with other p2m types. Also given I'd consider this a backporting candidate, while it may not be desperately needed for the release, I think it deserves considering beyond the specific aspect you mention.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
In which case I think the commit message probably ought to be rephrased, since it appears to focus
on a case that cannot currently happen.
This can happen without
has_arch_pdevs()being true. It's enough to just directly map some physical memory into a guest to getp2m_direct_mmiotype present in the page tables.OK, that's fine, but when will that happen without pass-through? If we can have a commit message justifying the change based on what can actually happen now, then I would not be opposed to it going in 4.14.
Yes, it can happen now - we had regular (not SR-IOV) vGPU migration totally broken because of this on AMD - never got tested before at all. You don't need special patches on top of Xen or anything.
To get p2m_mmio_direct you just need to call XEN_DOMCTL_memory_mapping on a domain.
All
Igor