Skip to content

Commit 6961ab0

Browse files
yamahatabonzini
authored andcommitted
KVM: x86/mmu: Add an is_mirror member for union kvm_mmu_page_role
Introduce a "is_mirror" member to the kvm_mmu_page_role union to identify SPTEs associated with the mirrored EPT. The TDX module maintains the private half of the EPT mapped in the TD in its protected memory. KVM keeps a copy of the private GPAs in a mirrored EPT tree within host memory. This "is_mirror" attribute enables vCPUs to find and get the root page of mirrored EPT from the MMU root list for a guest TD. This also allows KVM MMU code to detect changes in mirrored EPT according to the "is_mirror" mmu page role and propagate the changes to the private EPT managed by TDX module. Signed-off-by: Isaku Yamahata <[email protected]> Signed-off-by: Rick Edgecombe <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 3a4eb36 commit 6961ab0

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@ struct kvm_kernel_irq_routing_entry;
313313
* the number of unique SPs that can theoretically be created is 2^n, where n
314314
* is the number of bits that are used to compute the role.
315315
*
316-
* But, even though there are 19 bits in the mask below, not all combinations
316+
* But, even though there are 20 bits in the mask below, not all combinations
317317
* of modes and flags are possible:
318318
*
319-
* - invalid shadow pages are not accounted, so the bits are effectively 18
319+
* - invalid shadow pages are not accounted, mirror pages are not shadowed,
320+
* so the bits are effectively 18.
320321
*
321322
* - quadrant will only be used if has_4_byte_gpte=1 (non-PAE paging);
322323
* execonly and ad_disabled are only used for nested EPT which has
@@ -349,7 +350,8 @@ union kvm_mmu_page_role {
349350
unsigned ad_disabled:1;
350351
unsigned guest_mode:1;
351352
unsigned passthrough:1;
352-
unsigned :5;
353+
unsigned is_mirror:1;
354+
unsigned :4;
353355

354356
/*
355357
* This is left at the top of the word so that

arch/x86/kvm/mmu/mmu_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ static inline int kvm_mmu_page_as_id(struct kvm_mmu_page *sp)
157157
return kvm_mmu_role_as_id(sp->role);
158158
}
159159

160+
static inline bool is_mirror_sp(const struct kvm_mmu_page *sp)
161+
{
162+
return sp->role.is_mirror;
163+
}
164+
160165
static inline void kvm_mmu_alloc_external_spt(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
161166
{
162167
/*

arch/x86/kvm/mmu/spte.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ static inline struct kvm_mmu_page *root_to_sp(hpa_t root)
276276
return spte_to_child_sp(root);
277277
}
278278

279+
static inline bool is_mirror_sptep(tdp_ptep_t sptep)
280+
{
281+
return is_mirror_sp(sptep_to_sp(rcu_dereference(sptep)));
282+
}
283+
279284
static inline bool is_mmio_spte(struct kvm *kvm, u64 spte)
280285
{
281286
return (spte & shadow_mmio_mask) == kvm->arch.shadow_mmio_value &&

0 commit comments

Comments
 (0)