Skip to contentSkip to conversation

KVM: X86: Remove unnecessary GFP_KERNEL_ACCOUNT for temporary variables

PATCH Applied [email protected] 3 participants 5 messages Jun 24, 2024 – Jul 30, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: X86: Remove unnecessary GFP_KERNEL_ACCOUNT for temporary variables

From: Peng Hao <[email protected]>

Some variables allocated in kvm_arch_vcpu_ioctl are released when the function exits, so there is no need to set GFP_KERNEL_ACCOUNT.

---
 arch/x86/kvm/x86.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kvm/x86.c +4 -4
index 0763a0f72a06..bfddc04eae40 100644
@@ -5880,7 +5880,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 		if (!lapic_in_kernel(vcpu))
 			goto out;
 		u.lapic = kzalloc(sizeof(struct kvm_lapic_state),
-				GFP_KERNEL_ACCOUNT);
+				GFP_KERNEL);
 
 		r = -ENOMEM;
 		if (!u.lapic)
@@ -6073,7 +6073,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 		if (vcpu->arch.guest_fpu.uabi_size > sizeof(struct kvm_xsave))
 			break;
 
-		u.xsave = kzalloc(sizeof(struct kvm_xsave), GFP_KERNEL_ACCOUNT);
+		u.xsave = kzalloc(sizeof(struct kvm_xsave), GFP_KERNEL);
 		r = -ENOMEM;
 		if (!u.xsave)
 			break;
@@ -6104,7 +6104,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 	case KVM_GET_XSAVE2: {
 		int size = vcpu->arch.guest_fpu.uabi_size;
 
-		u.xsave = kzalloc(size, GFP_KERNEL_ACCOUNT);
+		u.xsave = kzalloc(size, GFP_KERNEL);
 		r = -ENOMEM;
 		if (!u.xsave)
 			break;
@@ -6122,7 +6122,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 	}
 
 	case KVM_GET_XCRS: {
-		u.xcrs = kzalloc(sizeof(struct kvm_xcrs), GFP_KERNEL_ACCOUNT);
+		u.xcrs = kzalloc(sizeof(struct kvm_xcrs), GFP_KERNEL);
 		r = -ENOMEM;
 		if (!u.xcrs)
 			break;
Signature · 1 line
2.27.0
#2 lore raw
Quoted 4 lines · Sean Christopherson
Quoted 2 lines · On Mon, 24 Jun 2024 09:20:16 +0800, [email protected] wrote:

Some variables allocated in kvm_arch_vcpu_ioctl are released when the function exits, so there is no need to set GFP_KERNEL_ACCOUNT.

Quoted 8 lines

Applied to kvm-x86 misc, thanks!

[1/1] KVM: X86: Remove unnecessary GFP_KERNEL_ACCOUNT for temporary variables

      https://github.com/kvm-x86/linux/commit/dd103407ca31

--
https://github.com/kvm-x86/linux/tree/next

Hi Sean,

I thought we should use _ACCOUNT even for temporary variables.

Should I send a patch to do below? :-)

arch/x86/kvm/vmx/sgx.c +1 -1
@@ -274,7 +274,7 @@ static int handle_encls_ecreate(struct kvm_vcpu *vcpu)
         * simultaneously set SGX_ATTR_PROVISIONKEY to bypass the check to
         * enforce restriction of access to the PROVISIONKEY.
         */
-       contents = (struct sgx_secs *)__get_free_page(GFP_KERNEL_ACCOUNT);
+       contents = (struct sgx_secs *)__get_free_page(GFP_KERNEL);
        if (!contents)
                return -ENOMEM;
 
#3 lore raw
Quoted 7 lines · Kai Huang
Quoted 6 lines · Sean Christopherson
Quoted 2 lines · On Mon, 24 Jun 2024 09:20:16 +0800, [email protected] wrote:

Some variables allocated in kvm_arch_vcpu_ioctl are released when the function exits, so there is no need to set GFP_KERNEL_ACCOUNT.

Applied to kvm-x86 misc, thanks!

Quoted 8 lines
Quoted 6 lines

[1/1] KVM: X86: Remove unnecessary GFP_KERNEL_ACCOUNT for temporary variables

      https://github.com/kvm-x86/linux/commit/dd103407ca31

--
https://github.com/kvm-x86/linux/tree/next

Hi Sean,

Sorry, lost this at the bottom of my inbox.

Quoted 1 line

I thought we should use _ACCOUNT even for temporary variables.

Heh, that's what I thought too.

[*] https://lore.kernel.org/all/c0122f66-f428-417e-a360-b25fc0f154a0@p183

#4 lore raw
Quoted 11 lines · Sean Christopherson
Quoted 10 lines · Kai Huang
Quoted 9 lines · Sean Christopherson
Quoted 2 lines · On Mon, 24 Jun 2024 09:20:16 +0800, [email protected] wrote:

Some variables allocated in kvm_arch_vcpu_ioctl are released when the function exits, so there is no need to set GFP_KERNEL_ACCOUNT.

Applied to kvm-x86 misc, thanks!

[1/1] KVM: X86: Remove unnecessary GFP_KERNEL_ACCOUNT for temporary variables

       https://github.com/kvm-x86/linux/commit/dd103407ca31
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

--
https://github.com/kvm-x86/linux/tree/next

Hi Sean,

Sorry, lost this at the bottom of my inbox.

Thanks for getting back to this. :-)

Quoted 7 lines
Quoted 2 lines

I thought we should use _ACCOUNT even for temporary variables.

Heh, that's what I thought too.

[*] https://lore.kernel.org/all/c0122f66-f428-417e-a360-b25fc0f154a0@p183

Thanks for the info.

Looking at Paolo's reply and by applying this patch, it seems we agreed we can just use GFP_KERNEL (e.g., GFP_USER isn't needed too)?

Anyway I've sent a patch to change handle_encls_ecreate():

https://lore.kernel.org/kvm/[email protected]/T/