x86/svm: retry after unhandled NPT fault if gfn was marked for recalculation
PATCH 1/1 x86/svm: retry after unhandled NPT fault if gfn was marked for recalculation
If a recalculation NPT fault hasn't been handled explicitly in hvm_hap_nested_page_fault() then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.
This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly in hvm_hap_nested_page_fault (this isn't called on EPT misconfig exit on Intel) which results in domain crash.
--- xen/arch/x86/hvm/svm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)
xen/arch/x86/hvm/svm/svm.c +4 -0
@@ -1726,6 +1726,10 @@ static void svm_do_nested_pgfault(struct vcpu *v,/* inject #VMEXIT(NPF) into guest. */ nestedsvm_vmexit_defer (v,VMEXIT_NPF , pfec, gpa);return ; +case 0 : +/* If a recalculation page fault hasn't been handled - just retry. */ +if ( pfec & PFEC_user_mode ) +return ; }/* Everything else is an error. */
Signature · 1 line
2.7.4
Quoted 5 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.
Quoted 8 lines
This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Signed-off-by Igor Druzhinin <[email protected]>---
Alternatively, I can re-raise the fault immediately after recalculation is done which is less efficient (will take one more VMEXIT) but safer IMO - hvm_hap_nested_page_fault might potentially leave VM in inconsistent state in case of a real failure and cause second page fault to conceal it.
Another alternative is to inject fall_through bool into hvm_hap_nested_page_fault to give it the idea of expected behavior in that case and avoid guessing in SVM code. I think that's an improvement over suggestion in v1 and a candidate for v2.
Igor
Quoted 21 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Signed-off-by Igor Druzhinin <[email protected]>--- xen/arch/x86/hvm/svm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/hvm/svm/svm.c +0
-0
xen/arch/x86/hvm/svm/svm.c static void svm_do_nested_pgfault(struct vcpu *v, · line 1732
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -1726,6 +1726,10 @@ static void svm_do_nested_pgfault(struct vcpu *v,/* inject #VMEXIT(NPF) into guest. */ nestedsvm_vmexit_defer (v,VMEXIT_NPF , pfec, gpa);return ; +case 0 : +/* If a recalculation page fault hasn't been handled - just retry. */ +if ( pfec & PFEC_user_mode ) +return ;
This smells like it is a recipe for livelocks.
Everything should have been handled properly by the call to p2m_pt_handle_deferred_changes() which precedes svm_do_nested_pgfault().
It is legitimate for the MMIO mapping to end up being transiently recalculated, but the fact that p2m_pt_handle_deferred_changes() doesn't fix it up suggests that the bug is there.
Do you have the complete NPT walk to the bad mapping? Do we have _PAGE_USER in the leaf mapping, or is this perhaps a spurious fault?
~Andrew
Quoted 35 lines · Andrew Cooper
Quoted 21 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Signed-off-by Igor Druzhinin <[email protected]>--- xen/arch/x86/hvm/svm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/hvm/svm/svm.c +0
-0xen/arch/x86/hvm/svm/svm.c static void svm_do_nested_pgfault(struct vcpu *v, · line 1732
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -1726,6 +1726,10 @@ static void svm_do_nested_pgfault(struct vcpu *v,/* inject #VMEXIT(NPF) into guest. */ nestedsvm_vmexit_defer (v,VMEXIT_NPF , pfec, gpa);return ; +case 0 : +/* If a recalculation page fault hasn't been handled - just retry. */ +if ( pfec & PFEC_user_mode ) +return ;This smells like it is a recipe for livelocks.
Everything should have been handled properly by the call to
p2m_pt_handle_deferred_changes()which precedessvm_do_nested_pgfault().
Quoted 6 lines
It is legitimate for the MMIO mapping to end up being transiently recalculated, but the fact that
p2m_pt_handle_deferred_changes()doesn't fix it up suggests that the bug is there.Do you have the complete NPT walk to the bad mapping? Do we have
_PAGE_USERin the leaf mapping, or is this perhaps a spurious fault?
It does fix it up. The problem is that currently in SVM we enter svm_do_nested_pgfault immediately after p2m_pt_handle_deferred_changes is finished finished.
Yes, we don't have _PAGE_USER initially and, yes, it's fixed up correctly in p2m_pt_handle_deferred_changes but svm_do_nested_pgfault doesn't know about it.
Please read my second email about alternatives that suggest to resolve the issue you're worrying about.
Igor
Quoted 39 lines · Igor Druzhinin
Quoted 38 lines · Andrew Cooper
Quoted 21 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Signed-off-by Igor Druzhinin <[email protected]>--- xen/arch/x86/hvm/svm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/hvm/svm/svm.c +0
-0xen/arch/x86/hvm/svm/svm.c static void svm_do_nested_pgfault(struct vcpu *v, · line 1732
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -1726,6 +1726,10 @@ static void svm_do_nested_pgfault(struct vcpu *v,/* inject #VMEXIT(NPF) into guest. */ nestedsvm_vmexit_defer (v,VMEXIT_NPF , pfec, gpa);return ; +case 0 : +/* If a recalculation page fault hasn't been handled - just retry. */ +if ( pfec & PFEC_user_mode ) +return ;This smells like it is a recipe for livelocks.
Everything should have been handled properly by the call to
p2m_pt_handle_deferred_changes()which precedessvm_do_nested_pgfault().It is legitimate for the MMIO mapping to end up being transiently recalculated, but the fact that
p2m_pt_handle_deferred_changes()doesn't fix it up suggests that the bug is there.
Quoted 5 lines
Quoted 2 lines
Do you have the complete NPT walk to the bad mapping? Do we have
_PAGE_USERin the leaf mapping, or is this perhaps a spurious fault?It does fix it up. The problem is that currently in SVM we enter
svm_do_nested_pgfaultimmediately afterp2m_pt_handle_deferred_changesis finished finished.
Oh - so we do. I'd read the entry condition for svm_do_nested_pgfault() incorrectly.
Jan - why did you chose to do it this way? If p2m_pt_handle_deferred_changes() has made a modification, there is surely nothing relevant to do in svm_do_nested_pgfault().
~Andrew
Quoted 46 lines · Andrew Cooper
Quoted 39 lines · Igor Druzhinin
Quoted 38 lines · Andrew Cooper
Quoted 21 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Signed-off-by Igor Druzhinin <[email protected]>--- xen/arch/x86/hvm/svm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/hvm/svm/svm.c +0
-0xen/arch/x86/hvm/svm/svm.c static void svm_do_nested_pgfault(struct vcpu *v, · line 1732
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -1726,6 +1726,10 @@ static void svm_do_nested_pgfault(struct vcpu *v,/* inject #VMEXIT(NPF) into guest. */ nestedsvm_vmexit_defer (v,VMEXIT_NPF , pfec, gpa);return ; +case 0 : +/* If a recalculation page fault hasn't been handled - just retry. */ +if ( pfec & PFEC_user_mode ) +return ;This smells like it is a recipe for livelocks.
Everything should have been handled properly by the call to
p2m_pt_handle_deferred_changes()which precedessvm_do_nested_pgfault().It is legitimate for the MMIO mapping to end up being transiently recalculated, but the fact that
p2m_pt_handle_deferred_changes()doesn't fix it up suggests that the bug is there.Quoted 5 lines
Quoted 2 lines
Do you have the complete NPT walk to the bad mapping? Do we have
_PAGE_USERin the leaf mapping, or is this perhaps a spurious fault?It does fix it up. The problem is that currently in SVM we enter
svm_do_nested_pgfaultimmediately afterp2m_pt_handle_deferred_changesis finished finished.
Quoted 6 lines
Oh - so we do. I'd read the entry condition for
svm_do_nested_pgfault()incorrectly.Jan - why did you chose to do it this way? If
p2m_pt_handle_deferred_changes()has made a modification, there is surely nothing relevant to do insvm_do_nested_pgfault().
In Jan's defense that saves one additional VMEXIT in rare cases if the fault had other implications (write to RO page in log-dirty) in addition to recalculation.
Igor
other
Quoted 46 lines · Andrew Cooper
Quoted 39 lines · Igor Druzhinin
Quoted 38 lines · Andrew Cooper
Quoted 21 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Signed-off-by Igor Druzhinin <[email protected]>--- xen/arch/x86/hvm/svm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/hvm/svm/svm.c +0
-0xen/arch/x86/hvm/svm/svm.c static void svm_do_nested_pgfault(struct vcpu *v, · line 1732
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -1726,6 +1726,10 @@ static void svm_do_nested_pgfault(struct vcpu *v,/* inject #VMEXIT(NPF) into guest. */ nestedsvm_vmexit_defer (v,VMEXIT_NPF , pfec, gpa);return ; +case 0 : +/* If a recalculation page fault hasn't been handled - just retry. */ +if ( pfec & PFEC_user_mode ) +return ;This smells like it is a recipe for livelocks.
Everything should have been handled properly by the call to
p2m_pt_handle_deferred_changes()which precedessvm_do_nested_pgfault().It is legitimate for the MMIO mapping to end up being transiently recalculated, but the fact that
p2m_pt_handle_deferred_changes()doesn't fix it up suggests that the bug is there.Quoted 5 lines
Quoted 2 lines
Do you have the complete NPT walk to the bad mapping? Do we have
_PAGE_USERin the leaf mapping, or is this perhaps a spurious fault?It does fix it up. The problem is that currently in SVM we enter
svm_do_nested_pgfaultimmediately afterp2m_pt_handle_deferred_changesis finished finished.
Quoted 6 lines
Oh - so we do. I'd read the entry condition for
svm_do_nested_pgfault()incorrectly.Jan - why did you chose to do it this way? If
p2m_pt_handle_deferred_changes()has made a modification, there is surely nothing relevant to do insvm_do_nested_pgfault().
Why? There can very well be multiple reasons for a single exit to occur, and hence it did seem to make sense to allow processing of such possible further reasons right away, instead of re- entering the guest just to deal with another VM exit. What I can accept is that the error code may not correctly represent the "remaining" fault reason anymore at this point.
Jan
Quoted 10 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.
Couldn't direct MMIO regions be handled like other types of memory for the purposes of logdiry mode?
I assume there's already a path here used for other memory types when logdirty is turned on, and hence would seem better to just make direct MMIO regions also use that path?
Quoted 10 lines
Signed-off-by Igor Druzhinin <[email protected]>--- xen/arch/x86/hvm/svm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/hvm/svm/svm.c +0
-0
xen/arch/x86/hvm/svm/svm.c static void svm_do_nested_pgfault(struct vcpu *v, · line 1732
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -1726,6 +1726,10 @@ static void svm_do_nested_pgfault(struct vcpu *v,/* inject #VMEXIT(NPF) into guest. */ nestedsvm_vmexit_defer (v,VMEXIT_NPF , pfec, gpa);return ; +case 0 : +/* If a recalculation page fault hasn't been handled - just retry. */ +if ( pfec & PFEC_user_mode ) +return ;
I'm slightly worried that this diverges from the EPT implementation now, in the sense that returning 0 from hvm_hap_nested_page_fault will no longer trigger a guest crash.
Thanks, Roger.
Quoted 12 lines · Roger Pau Monné
Quoted 10 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.
Quoted 6 lines
Couldn't direct MMIO regions be handled like other types of memory for the purposes of logdiry mode?
I assume there's already a path here used for other memory types when logdirty is turned on, and hence would seem better to just make direct MMIO regions also use that path?
The proble of handling only MMIO case is that the issue still stays. It will be hit with some other memory type since it's not MMIO specific. The issue is that if global recalculation is called, the next hit to this type will cause a transient fault which will not be handled correctly after a due fixup by neither of our handlers.
Quoted 5 lines
Quoted 5 lines
Signed-off-by Igor Druzhinin <[email protected]>--- xen/arch/x86/hvm/svm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)
Quoted 16 lines
xen/arch/x86/hvm/svm/svm.c static void svm_do_nested_pgfault(struct vcpu *v, · line 1732
Quoted 12 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -1726,6 +1726,10 @@ static void svm_do_nested_pgfault(struct vcpu *v,/* inject #VMEXIT(NPF) into guest. */ nestedsvm_vmexit_defer (v,VMEXIT_NPF , pfec, gpa);return ; +case 0 : +/* If a recalculation page fault hasn't been handled - just retry. */ +if ( pfec & PFEC_user_mode ) +return ;I'm slightly worried that this diverges from the EPT implementation now, in the sense that returning 0 from
hvm_hap_nested_page_faultwill no longer trigger a guest crash.
My second alternative from my follow up email addresses this. I also didn't like this aspect.
Igor
Quoted 20 lines · Igor Druzhinin
Quoted 12 lines · Roger Pau Monné
Quoted 10 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Quoted 6 lines
Couldn't direct MMIO regions be handled like other types of memory for the purposes of logdiry mode?
I assume there's already a path here used for other memory types when logdirty is turned on, and hence would seem better to just make direct MMIO regions also use that path?
Quoted 5 lines
The proble of handling only MMIO case is that the issue still stays. It will be hit with some other memory type since it's not MMIO specific. The issue is that if global recalculation is called, the next hit to this type will cause a transient fault which will not be handled correctly after a due fixup by neither of our handlers.
I admit I should go look at the code, but for example RAM p2m types don't require this fix, so I assume there's some different path taken in that case that avoids all this?
Ie: when global logdirty is enabled you will start to get nested page faults for every access, yet only direct MMIO types require this fix?
Thanks, Roger
Quoted 27 lines · Roger Pau Monné
Quoted 20 lines · Igor Druzhinin
Quoted 12 lines · Roger Pau Monné
Quoted 10 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Quoted 6 lines
Couldn't direct MMIO regions be handled like other types of memory for the purposes of logdiry mode?
I assume there's already a path here used for other memory types when logdirty is turned on, and hence would seem better to just make direct MMIO regions also use that path?
Quoted 5 lines
The proble of handling only MMIO case is that the issue still stays. It will be hit with some other memory type since it's not MMIO specific. The issue is that if global recalculation is called, the next hit to this type will cause a transient fault which will not be handled correctly after a due fixup by neither of our handlers.
Quoted 6 lines
I admit I should go look at the code, but for example RAM p2m types don't require this fix, so I assume there's some different path taken in that case that avoids all this?
Ie: when global logdirty is enabled you will start to get nested page faults for every access, yet only direct MMIO types require this fix?
It's not "only MMIO" - it's just MMIO area is hit in my particular case. I'd prefer this fix to address the general issue otherwise for SVM we would have to write handlers in hvm_hap_nested_page_fault() for every case as soon as we hit it.
Igor
Quoted 32 lines · Igor Druzhinin
Quoted 31 lines · Roger Pau Monné
Quoted 20 lines · Igor Druzhinin
Quoted 12 lines · Roger Pau Monné
Quoted 10 lines · Igor Druzhinin
If a recalculation NPT fault hasn't been handled explicitly in
hvm_hap_nested_page_fault()then it's potentially safe to retry - US bit has been re-instated in PTE and any real fault would be correctly re-raised next time.This covers a specific case of migration with vGPU assigned on AMD:
global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. This type of fault isn't described explicitly inhvm_hap_nested_page_fault(this isn't called on EPT misconfig exit on Intel) which results in domain crash.Quoted 6 lines
Couldn't direct MMIO regions be handled like other types of memory for the purposes of logdiry mode?
I assume there's already a path here used for other memory types when logdirty is turned on, and hence would seem better to just make direct MMIO regions also use that path?
Quoted 5 lines
The proble of handling only MMIO case is that the issue still stays. It will be hit with some other memory type since it's not MMIO specific. The issue is that if global recalculation is called, the next hit to this type will cause a transient fault which will not be handled correctly after a due fixup by neither of our handlers.
I admit I should go look at the code, but for example RAM p2m types don't require this fix, so I assume there's some different path taken in that case that avoids all this?
Quoted 7 lines
Quoted 2 lines
Ie: when global logdirty is enabled you will start to get nested page faults for every access, yet only direct MMIO types require this fix?
It's not "only MMIO" - it's just MMIO area is hit in my particular case. I'd prefer this fix to address the general issue otherwise for SVM we would have to write handlers in
hvm_hap_nested_page_fault()for every case as soon as we hit it.
Hm, I'm not sure I agree. p2m memory types are limited, and IMO we want to have strict control about how they are handled. hvm_hap_nested_page_fault is already full of special casing for each memory type for that reason.
That being said, I also don't like the fact that logdity is handled differently between EPT and NPT, as on EPT it's handled as a misconfig while on NPT it's handled as a violation.
Thanks, Roger.
Quoted 3 lines · Roger Pau Monné
That being said, I also don't like the fact that logdity is handled differently between EPT and NPT, as on EPT it's handled as a misconfig while on NPT it's handled as a violation.
Because, well, there is no concept of misconfig in NPT.
Jan
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Roger Pau Monné
That being said, I also don't like the fact that logdity is handled differently between EPT and NPT, as on EPT it's handled as a misconfig while on NPT it's handled as a violation.
Because, well, there is no concept of misconfig in NPT.
Indeed. Intel chose to split EPT errors into two - MISCONFIG for structural errors (not present, or reserved bits set) and VIOLATION for permissions errors.
AMD reused the same silicon pagewalker design, so have a single NPT_FAULT vmexit which behaves much more like a regular pagefault, encoding structural vs permission errors in the error code.
~Andrew
Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Roger Pau Monné
That being said, I also don't like the fact that logdity is handled differently between EPT and NPT, as on EPT it's handled as a misconfig while on NPT it's handled as a violation.
Because, well, there is no concept of misconfig in NPT.
Quoted 7 lines
Indeed. Intel chose to split EPT errors into two - MISCONFIG for structural errors (not present, or reserved bits set) and VIOLATION for permissions errors.
AMD reused the same silicon pagewalker design, so have a single
NPT_FAULTvmexit which behaves much more like a regular pagefault, encoding structural vs permission errors in the error code.
Maybe I should clarify, I understand that NPT doesn't have such differentiation regarding nested page table faults vs EPT, but I feel like it would be clearer if part of the code could be shared, ie:
unify EPT resolve_misconfig and NPT do_recalc into a single function for example that uses the necessary p2m-> helpers for the differing implementations. I think we should be able to tell apart when a NPT page fault is a recalc one by looking at the bits in the EXITINFO1 error field?
Anyway, this was just a rant, and it's tangential to the issue at hand, sorry for distracting.
Roger.
Quoted 14 lines · Roger Pau Monné
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Roger Pau Monné
That being said, I also don't like the fact that logdity is handled differently between EPT and NPT, as on EPT it's handled as a misconfig while on NPT it's handled as a violation.
Quoted 8 lines
Quoted 1 line
Because, well, there is no concept of misconfig in NPT.
Indeed. Intel chose to split EPT errors into two - MISCONFIG for structural errors (not present, or reserved bits set) and VIOLATION for permissions errors.
AMD reused the same silicon pagewalker design, so have a single
NPT_FAULTvmexit which behaves much more like a regular pagefault, encoding structural vs permission errors in the error code.
Quoted 8 lines
Maybe I should clarify, I understand that NPT doesn't have such differentiation regarding nested page table faults vs EPT, but I feel like it would be clearer if part of the code could be shared, ie:
unify EPTresolve_misconfigand NPTdo_recalcinto a single function for example that uses the necessary p2m-> helpers for the differing implementations. I think we should be able to tell apart when a NPT page fault is a recalc one by looking at the bits in the EXITINFO1 error field?
But they use fundamentally different mechanisms.
EPT uses an invalid caching type, while NPT sets the User bit (and even this is going to have to change when we want to support GMET for Windows VBS in the long term).
You could abstract a few things out into common logic, but none of the bit positions match (not even the recalc software bit), and the result would be more complicated than its current form.
~Andrew