Skip to content

Commit 99a4909

Browse files
lrq-maxsean-jc
authored andcommitted
KVM: SVM: Consider NUMA affinity when allocating per-CPU save_area
save_area of per-CPU svm_data are dominantly accessed from their own local CPUs, so allocate them node-local for performance reason so rename __snp_safe_alloc_page as snp_safe_alloc_page_node which accepts numa node id as input parameter, svm_cpu_init call it with node id switched from cpu id Signed-off-by: Li RongQing <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 9f44286 commit 99a4909

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,13 +3380,13 @@ void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector)
33803380
}
33813381
}
33823382

3383-
struct page *__snp_safe_alloc_page(gfp_t gfp)
3383+
struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)
33843384
{
33853385
unsigned long pfn;
33863386
struct page *p;
33873387

33883388
if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
3389-
return alloc_page(gfp | __GFP_ZERO);
3389+
return alloc_pages_node(node, gfp | __GFP_ZERO, 0);
33903390

33913391
/*
33923392
* Allocate an SNP-safe page to workaround the SNP erratum where
@@ -3397,7 +3397,7 @@ struct page *__snp_safe_alloc_page(gfp_t gfp)
33973397
* Allocate one extra page, choose a page which is not
33983398
* 2MB-aligned, and free the other.
33993399
*/
3400-
p = alloc_pages(gfp | __GFP_ZERO, 1);
3400+
p = alloc_pages_node(node, gfp | __GFP_ZERO, 1);
34013401
if (!p)
34023402
return NULL;
34033403

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static int svm_cpu_init(int cpu)
703703
int ret = -ENOMEM;
704704

705705
memset(sd, 0, sizeof(struct svm_cpu_data));
706-
sd->save_area = __snp_safe_alloc_page(GFP_KERNEL);
706+
sd->save_area = snp_safe_alloc_page_node(cpu_to_node(cpu), GFP_KERNEL);
707707
if (!sd->save_area)
708708
return ret;
709709

arch/x86/kvm/svm/svm.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,11 +694,11 @@ void sev_guest_memory_reclaimed(struct kvm *kvm);
694694
int sev_handle_vmgexit(struct kvm_vcpu *vcpu);
695695

696696
/* These symbols are used in common code and are stubbed below. */
697-
struct page *__snp_safe_alloc_page(gfp_t gfp);
698697

698+
struct page *snp_safe_alloc_page_node(int node, gfp_t gfp);
699699
static inline struct page *snp_safe_alloc_page(void)
700700
{
701-
return __snp_safe_alloc_page(GFP_KERNEL_ACCOUNT);
701+
return snp_safe_alloc_page_node(numa_node_id(), GFP_KERNEL_ACCOUNT);
702702
}
703703

704704
void sev_free_vcpu(struct kvm_vcpu *vcpu);
@@ -710,14 +710,14 @@ int sev_cpu_init(struct svm_cpu_data *sd);
710710
int sev_dev_get_attr(u32 group, u64 attr, u64 *val);
711711
extern unsigned int max_sev_asid;
712712
#else
713-
static inline struct page *__snp_safe_alloc_page(gfp_t gfp)
713+
static inline struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)
714714
{
715-
return alloc_page(gfp | __GFP_ZERO);
715+
return alloc_pages_node(node, gfp | __GFP_ZERO, 0);
716716
}
717717

718718
static inline struct page *snp_safe_alloc_page(void)
719719
{
720-
return __snp_safe_alloc_page(GFP_KERNEL_ACCOUNT);
720+
return snp_safe_alloc_page_node(numa_node_id(), GFP_KERNEL_ACCOUNT);
721721
}
722722

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

0 commit comments

Comments
 (0)