File tree Expand file tree Collapse file tree 4 files changed +20
-16
lines changed Expand file tree Collapse file tree 4 files changed +20
-16
lines changed Original file line number Diff line number Diff line change @@ -3357,7 +3357,7 @@ static bool page_fault_can_be_fast(struct kvm *kvm, struct kvm_page_fault *fault
3357
3357
* by setting the Writable bit, which can be done out of mmu_lock.
3358
3358
*/
3359
3359
if (!fault -> present )
3360
- return !kvm_ad_enabled () ;
3360
+ return !kvm_ad_enabled ;
3361
3361
3362
3362
/*
3363
3363
* Note, instruction fetches and writes are mutually exclusive, ignore
@@ -3492,7 +3492,7 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
3492
3492
* uses A/D bits for non-nested MMUs. Thus, if A/D bits are
3493
3493
* enabled, the SPTE can't be an access-tracked SPTE.
3494
3494
*/
3495
- if (unlikely (!kvm_ad_enabled () ) && is_access_track_spte (spte ))
3495
+ if (unlikely (!kvm_ad_enabled ) && is_access_track_spte (spte ))
3496
3496
new_spte = restore_acc_track_spte (new_spte );
3497
3497
3498
3498
/*
@@ -5469,7 +5469,7 @@ kvm_calc_tdp_mmu_root_page_role(struct kvm_vcpu *vcpu,
5469
5469
role .efer_nx = true;
5470
5470
role .smm = cpu_role .base .smm ;
5471
5471
role .guest_mode = cpu_role .base .guest_mode ;
5472
- role .ad_disabled = !kvm_ad_enabled () ;
5472
+ role .ad_disabled = !kvm_ad_enabled ;
5473
5473
role .level = kvm_mmu_get_tdp_level (vcpu );
5474
5474
role .direct = true;
5475
5475
role .has_4_byte_gpte = false;
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ static bool __ro_after_init allow_mmio_caching;
24
24
module_param_named (mmio_caching , enable_mmio_caching , bool , 0444 );
25
25
EXPORT_SYMBOL_GPL (enable_mmio_caching );
26
26
27
+ bool __read_mostly kvm_ad_enabled ;
28
+
27
29
u64 __read_mostly shadow_host_writable_mask ;
28
30
u64 __read_mostly shadow_mmu_writable_mask ;
29
31
u64 __read_mostly shadow_nx_mask ;
@@ -414,6 +416,8 @@ EXPORT_SYMBOL_GPL(kvm_mmu_set_me_spte_mask);
414
416
415
417
void kvm_mmu_set_ept_masks (bool has_ad_bits , bool has_exec_only )
416
418
{
419
+ kvm_ad_enabled = has_ad_bits ;
420
+
417
421
shadow_user_mask = VMX_EPT_READABLE_MASK ;
418
422
shadow_accessed_mask = has_ad_bits ? VMX_EPT_ACCESS_BIT : 0ull ;
419
423
shadow_dirty_mask = has_ad_bits ? VMX_EPT_DIRTY_BIT : 0ull ;
@@ -447,6 +451,8 @@ void kvm_mmu_reset_all_pte_masks(void)
447
451
u8 low_phys_bits ;
448
452
u64 mask ;
449
453
454
+ kvm_ad_enabled = true;
455
+
450
456
/*
451
457
* If the CPU has 46 or less physical address bits, then set an
452
458
* appropriate mask to guard against L1TF attacks. Otherwise, it is
Original file line number Diff line number Diff line change @@ -167,6 +167,15 @@ static_assert(!(SHADOW_NONPRESENT_VALUE & SPTE_MMU_PRESENT_MASK));
167
167
#define SHADOW_NONPRESENT_VALUE 0ULL
168
168
#endif
169
169
170
+
171
+ /*
172
+ * True if A/D bits are supported in hardware and are enabled by KVM. When
173
+ * enabled, KVM uses A/D bits for all non-nested MMUs. Because L1 can disable
174
+ * A/D bits in EPTP12, SP and SPTE variants are needed to handle the scenario
175
+ * where KVM is using A/D bits for L1, but not L2.
176
+ */
177
+ extern bool __read_mostly kvm_ad_enabled ;
178
+
170
179
extern u64 __read_mostly shadow_host_writable_mask ;
171
180
extern u64 __read_mostly shadow_mmu_writable_mask ;
172
181
extern u64 __read_mostly shadow_nx_mask ;
@@ -285,17 +294,6 @@ static inline bool is_ept_ve_possible(u64 spte)
285
294
(spte & VMX_EPT_RWX_MASK ) != VMX_EPT_MISCONFIG_WX_VALUE ;
286
295
}
287
296
288
- /*
289
- * Returns true if A/D bits are supported in hardware and are enabled by KVM.
290
- * When enabled, KVM uses A/D bits for all non-nested MMUs. Because L1 can
291
- * disable A/D bits in EPTP12, SP and SPTE variants are needed to handle the
292
- * scenario where KVM is using A/D bits for L1, but not L2.
293
- */
294
- static inline bool kvm_ad_enabled (void )
295
- {
296
- return !!shadow_accessed_mask ;
297
- }
298
-
299
297
static inline bool sp_ad_disabled (struct kvm_mmu_page * sp )
300
298
{
301
299
return sp -> role .ad_disabled ;
Original file line number Diff line number Diff line change @@ -1075,7 +1075,7 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu,
1075
1075
static int tdp_mmu_link_sp (struct kvm * kvm , struct tdp_iter * iter ,
1076
1076
struct kvm_mmu_page * sp , bool shared )
1077
1077
{
1078
- u64 spte = make_nonleaf_spte (sp -> spt , !kvm_ad_enabled () );
1078
+ u64 spte = make_nonleaf_spte (sp -> spt , !kvm_ad_enabled );
1079
1079
int ret = 0 ;
1080
1080
1081
1081
if (shared ) {
@@ -1491,7 +1491,7 @@ static bool tdp_mmu_need_write_protect(struct kvm_mmu_page *sp)
1491
1491
* from level, so it is valid to key off any shadow page to determine if
1492
1492
* write protection is needed for an entire tree.
1493
1493
*/
1494
- return kvm_mmu_page_ad_need_write_protect (sp ) || !kvm_ad_enabled () ;
1494
+ return kvm_mmu_page_ad_need_write_protect (sp ) || !kvm_ad_enabled ;
1495
1495
}
1496
1496
1497
1497
static void clear_dirty_gfn_range (struct kvm * kvm , struct kvm_mmu_page * root ,
You can’t perform that action at this time.
0 commit comments