Skip to content

Commit 9f44286

Browse files
lrq-maxsean-jc
authored andcommitted
KVM: SVM: not account memory allocation for per-CPU svm_data
The allocation for the per-CPU save area in svm_cpu_init shouldn't be accounted, So introduce __snp_safe_alloc_page helper, which has gfp flag as input, svm_cpu_init calls __snp_safe_alloc_page with GFP_KERNEL, snp_safe_alloc_page calls __snp_safe_alloc_page with GFP_KERNEL_ACCOUNT as input Suggested-by: Sean Christopherson <[email protected]> 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 f51af34 commit 9f44286

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
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(void)
3383+
struct page *__snp_safe_alloc_page(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_KERNEL_ACCOUNT | __GFP_ZERO);
3389+
return alloc_page(gfp | __GFP_ZERO);
33903390

33913391
/*
33923392
* Allocate an SNP-safe page to workaround the SNP erratum where
@@ -3397,7 +3397,7 @@ struct page *snp_safe_alloc_page(void)
33973397
* Allocate one extra page, choose a page which is not
33983398
* 2MB-aligned, and free the other.
33993399
*/
3400-
p = alloc_pages(GFP_KERNEL_ACCOUNT | __GFP_ZERO, 1);
3400+
p = alloc_pages(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();
706+
sd->save_area = __snp_safe_alloc_page(GFP_KERNEL);
707707
if (!sd->save_area)
708708
return ret;
709709

arch/x86/kvm/svm/svm.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,13 @@ 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(void);
697+
struct page *__snp_safe_alloc_page(gfp_t gfp);
698+
699+
static inline struct page *snp_safe_alloc_page(void)
700+
{
701+
return __snp_safe_alloc_page(GFP_KERNEL_ACCOUNT);
702+
}
703+
698704
void sev_free_vcpu(struct kvm_vcpu *vcpu);
699705
void sev_vm_destroy(struct kvm *kvm);
700706
void __init sev_set_cpu_caps(void);
@@ -704,9 +710,14 @@ int sev_cpu_init(struct svm_cpu_data *sd);
704710
int sev_dev_get_attr(u32 group, u64 attr, u64 *val);
705711
extern unsigned int max_sev_asid;
706712
#else
713+
static inline struct page *__snp_safe_alloc_page(gfp_t gfp)
714+
{
715+
return alloc_page(gfp | __GFP_ZERO);
716+
}
717+
707718
static inline struct page *snp_safe_alloc_page(void)
708719
{
709-
return alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
720+
return __snp_safe_alloc_page(GFP_KERNEL_ACCOUNT);
710721
}
711722

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

0 commit comments

Comments
 (0)