2023-09-04 08:27:31

by Li zeming

[permalink] [raw]
Subject: [v2 PATCH] x86/kvm/mmu: Remove unnecessary ‘NULL’ values from sptep

Remove spte and sptep initialization assignments, add sptep assignment
check and processing.

Signed-off-by: Li zeming <[email protected]>
---
v2:
1. Remove spte initialization assignment.
2. Add sptep assignment check.

arch/x86/kvm/mmu/mmu.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index ec169f5c7dce..0d11bfeae2f8 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3456,8 +3456,8 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
{
struct kvm_mmu_page *sp;
int ret = RET_PF_INVALID;
- u64 spte = 0ull;
- u64 *sptep = NULL;
+ u64 spte;
+ u64 *sptep;
uint retry_count = 0;

if (!page_fault_can_be_fast(fault))
@@ -3473,6 +3473,14 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
else
sptep = fast_pf_get_last_sptep(vcpu, fault->addr, &spte);

+ /*
+ * It's entirely possible for the mapping to have been zapped
+ * by a different task, but the root page is should always be
+ * available as the vCPU holds a reference to its root(s).
+ */
+ if (WARN_ON_ONCE(!sptep))
+ spte = REMOVED_SPTE;
+
if (!is_shadow_present_pte(spte))
break;

--
2.18.2


2023-10-20 22:58:30

by Sean Christopherson

[permalink] [raw]
Subject: Re: [v2 PATCH] x86/kvm/mmu: Remove unnecessary ‘NULL’ values from sptep

On Wed, 06 Sep 2023 02:20:06 +0800, Li zeming wrote:
> Remove spte and sptep initialization assignments, add sptep assignment
> check and processing.

Applied to kvm-x86 mmu, with a beefed up changelog. Thanks!

[1/1] x86/kvm/mmu: Remove unnecessary ‘NULL’ values from sptep
https://github.com/kvm-x86/linux/commit/1de9992f9de0

--
https://github.com/kvm-x86/linux/tree/next