Skip to content

Commit 1229cbe

Browse files
committed
Merge tag 'kvm-x86-svm-6.11' of https://github.com/kvm-x86/linux into HEAD
KVM SVM changes for 6.11 - Make per-CPU save_area allocations NUMA-aware. - Force sev_es_host_save_area() to be inlined to avoid calling into an instrumentable function from noinstr code.
2 parents dbfd50c + 704ec48 commit 1229cbe

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ int svm_allocate_nested(struct vcpu_svm *svm)
11811181
if (svm->nested.initialized)
11821182
return 0;
11831183

1184-
vmcb02_page = snp_safe_alloc_page(&svm->vcpu);
1184+
vmcb02_page = snp_safe_alloc_page();
11851185
if (!vmcb02_page)
11861186
return -ENOMEM;
11871187
svm->nested.vmcb02.ptr = page_address(vmcb02_page);

arch/x86/kvm/svm/sev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4459,13 +4459,13 @@ void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector)
44594459
}
44604460
}
44614461

4462-
struct page *snp_safe_alloc_page(struct kvm_vcpu *vcpu)
4462+
struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)
44634463
{
44644464
unsigned long pfn;
44654465
struct page *p;
44664466

44674467
if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
4468-
return alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
4468+
return alloc_pages_node(node, gfp | __GFP_ZERO, 0);
44694469

44704470
/*
44714471
* Allocate an SNP-safe page to workaround the SNP erratum where
@@ -4476,7 +4476,7 @@ struct page *snp_safe_alloc_page(struct kvm_vcpu *vcpu)
44764476
* Allocate one extra page, choose a page which is not
44774477
* 2MB-aligned, and free the other.
44784478
*/
4479-
p = alloc_pages(GFP_KERNEL_ACCOUNT | __GFP_ZERO, 1);
4479+
p = alloc_pages_node(node, gfp | __GFP_ZERO, 1);
44804480
if (!p)
44814481
return NULL;
44824482

arch/x86/kvm/svm/svm.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ static void __svm_write_tsc_multiplier(u64 multiplier)
571571
__this_cpu_write(current_tsc_ratio, multiplier);
572572
}
573573

574+
static __always_inline struct sev_es_save_area *sev_es_host_save_area(struct svm_cpu_data *sd)
575+
{
576+
return page_address(sd->save_area) + 0x400;
577+
}
578+
574579
static inline void kvm_cpu_svm_disable(void)
575580
{
576581
uint64_t efer;
@@ -675,12 +680,9 @@ static int svm_hardware_enable(void)
675680
* TSC_AUX field now to avoid a RDMSR on every vCPU run.
676681
*/
677682
if (boot_cpu_has(X86_FEATURE_V_TSC_AUX)) {
678-
struct sev_es_save_area *hostsa;
679683
u32 __maybe_unused msr_hi;
680684

681-
hostsa = (struct sev_es_save_area *)(page_address(sd->save_area) + 0x400);
682-
683-
rdmsr(MSR_TSC_AUX, hostsa->tsc_aux, msr_hi);
685+
rdmsr(MSR_TSC_AUX, sev_es_host_save_area(sd)->tsc_aux, msr_hi);
684686
}
685687

686688
return 0;
@@ -705,7 +707,7 @@ static int svm_cpu_init(int cpu)
705707
int ret = -ENOMEM;
706708

707709
memset(sd, 0, sizeof(struct svm_cpu_data));
708-
sd->save_area = snp_safe_alloc_page(NULL);
710+
sd->save_area = snp_safe_alloc_page_node(cpu_to_node(cpu), GFP_KERNEL);
709711
if (!sd->save_area)
710712
return ret;
711713

@@ -1431,7 +1433,7 @@ static int svm_vcpu_create(struct kvm_vcpu *vcpu)
14311433
svm = to_svm(vcpu);
14321434

14331435
err = -ENOMEM;
1434-
vmcb01_page = snp_safe_alloc_page(vcpu);
1436+
vmcb01_page = snp_safe_alloc_page();
14351437
if (!vmcb01_page)
14361438
goto out;
14371439

@@ -1440,7 +1442,7 @@ static int svm_vcpu_create(struct kvm_vcpu *vcpu)
14401442
* SEV-ES guests require a separate VMSA page used to contain
14411443
* the encrypted register state of the guest.
14421444
*/
1443-
vmsa_page = snp_safe_alloc_page(vcpu);
1445+
vmsa_page = snp_safe_alloc_page();
14441446
if (!vmsa_page)
14451447
goto error_free_vmcb_page;
14461448
}
@@ -1505,11 +1507,6 @@ static void svm_vcpu_free(struct kvm_vcpu *vcpu)
15051507
__free_pages(virt_to_page(svm->msrpm), get_order(MSRPM_SIZE));
15061508
}
15071509

1508-
static struct sev_es_save_area *sev_es_host_save_area(struct svm_cpu_data *sd)
1509-
{
1510-
return page_address(sd->save_area) + 0x400;
1511-
}
1512-
15131510
static void svm_prepare_switch_to_guest(struct kvm_vcpu *vcpu)
15141511
{
15151512
struct vcpu_svm *svm = to_svm(vcpu);
@@ -4968,7 +4965,7 @@ static int svm_vm_init(struct kvm *kvm)
49684965

49694966
static void *svm_alloc_apic_backing_page(struct kvm_vcpu *vcpu)
49704967
{
4971-
struct page *page = snp_safe_alloc_page(vcpu);
4968+
struct page *page = snp_safe_alloc_page();
49724969

49734970
if (!page)
49744971
return NULL;

arch/x86/kvm/svm/svm.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,13 @@ void sev_guest_memory_reclaimed(struct kvm *kvm);
726726
int sev_handle_vmgexit(struct kvm_vcpu *vcpu);
727727

728728
/* These symbols are used in common code and are stubbed below. */
729-
struct page *snp_safe_alloc_page(struct kvm_vcpu *vcpu);
729+
730+
struct page *snp_safe_alloc_page_node(int node, gfp_t gfp);
731+
static inline struct page *snp_safe_alloc_page(void)
732+
{
733+
return snp_safe_alloc_page_node(numa_node_id(), GFP_KERNEL_ACCOUNT);
734+
}
735+
730736
void sev_free_vcpu(struct kvm_vcpu *vcpu);
731737
void sev_vm_destroy(struct kvm *kvm);
732738
void __init sev_set_cpu_caps(void);
@@ -741,8 +747,14 @@ int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);
741747
void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end);
742748
int sev_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn);
743749
#else
744-
static inline struct page *snp_safe_alloc_page(struct kvm_vcpu *vcpu) {
745-
return alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
750+
static inline struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)
751+
{
752+
return alloc_pages_node(node, gfp | __GFP_ZERO, 0);
753+
}
754+
755+
static inline struct page *snp_safe_alloc_page(void)
756+
{
757+
return snp_safe_alloc_page_node(numa_node_id(), GFP_KERNEL_ACCOUNT);
746758
}
747759

748760
static inline void sev_free_vcpu(struct kvm_vcpu *vcpu) {}

0 commit comments

Comments
 (0)