* [PATCH -next] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state()
@ 2024-08-21 11:27 Yongqiang Liu
2024-08-23 0:03 ` Huang, Kai
2024-08-23 23:47 ` Sean Christopherson
0 siblings, 2 replies; 5+ messages in thread
From: Yongqiang Liu @ 2024-08-21 11:27 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, zhangxiaoxu5, hpa, x86, dave.hansen, bp, mingo,
tglx, pbonzini, seanjc, liuyongqiang13
The fixed size temporary variables vmcb_control_area and vmcb_save_area
allocated in svm_set_nested_state() are released when the function exits.
Meanwhile, svm_set_nested_state() also have vcpu mutex held to avoid
massive concurrency allocation, so we don't need to set GFP_KERNEL_ACCOUNT.
Signed-off-by: Yongqiang Liu <liuyongqiang13@huawei.com>
---
arch/x86/kvm/svm/nested.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 6f704c1037e5..d5314cb7dff4 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1693,8 +1693,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
return -EINVAL;
ret = -ENOMEM;
- ctl = kzalloc(sizeof(*ctl), GFP_KERNEL_ACCOUNT);
- save = kzalloc(sizeof(*save), GFP_KERNEL_ACCOUNT);
+ ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
+ save = kzalloc(sizeof(*save), GFP_KERNEL);
if (!ctl || !save)
goto out_free;
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state()
2024-08-21 11:27 [PATCH -next] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state() Yongqiang Liu
@ 2024-08-23 0:03 ` Huang, Kai
2024-08-24 0:00 ` Sean Christopherson
2024-08-23 23:47 ` Sean Christopherson
1 sibling, 1 reply; 5+ messages in thread
From: Huang, Kai @ 2024-08-23 0:03 UTC (permalink / raw)
To: Yongqiang Liu, kvm
Cc: linux-kernel, zhangxiaoxu5, hpa, x86, dave.hansen, bp, mingo,
tglx, pbonzini, seanjc
On 21/08/2024 11:27 pm, Yongqiang Liu wrote:
> The fixed size temporary variables vmcb_control_area and vmcb_save_area
> allocated in svm_set_nested_state() are released when the function exits.
> Meanwhile, svm_set_nested_state() also have vcpu mutex held to avoid
> massive concurrency allocation, so we don't need to set GFP_KERNEL_ACCOUNT.
Hi Sean/Paolo,
Seems more patches are popping up regarding to whether to use _ACCOUNT
for temporary memory allocation. Could we have a definitive guide on this?
As you know, one similar patch was merged and now is in upstream:
dd103407ca315 ("KVM: X86: Remove unnecessary GFP_KERNEL_ACCOUNT for
temporary variables")
Also see:
https://lore.kernel.org/kvm/20240715101224.90958-1-kai.huang@intel.com/T/
>
> Signed-off-by: Yongqiang Liu <liuyongqiang13@huawei.com>
> ---
> arch/x86/kvm/svm/nested.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 6f704c1037e5..d5314cb7dff4 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -1693,8 +1693,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
> return -EINVAL;
>
> ret = -ENOMEM;
> - ctl = kzalloc(sizeof(*ctl), GFP_KERNEL_ACCOUNT);
> - save = kzalloc(sizeof(*save), GFP_KERNEL_ACCOUNT);
> + ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
> + save = kzalloc(sizeof(*save), GFP_KERNEL);
> if (!ctl || !save)
> goto out_free;
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH -next] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state()
2024-08-23 0:03 ` Huang, Kai
@ 2024-08-24 0:00 ` Sean Christopherson
2024-08-24 9:33 ` Huang, Kai
0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2024-08-24 0:00 UTC (permalink / raw)
To: Kai Huang
Cc: Yongqiang Liu, kvm, linux-kernel, zhangxiaoxu5, hpa, x86,
dave.hansen, bp, mingo, tglx, pbonzini
On Fri, Aug 23, 2024, Kai Huang wrote:
>
>
> On 21/08/2024 11:27 pm, Yongqiang Liu wrote:
> > The fixed size temporary variables vmcb_control_area and vmcb_save_area
> > allocated in svm_set_nested_state() are released when the function exits.
> > Meanwhile, svm_set_nested_state() also have vcpu mutex held to avoid
> > massive concurrency allocation, so we don't need to set GFP_KERNEL_ACCOUNT.
>
> Hi Sean/Paolo,
>
> Seems more patches are popping up regarding to whether to use _ACCOUNT for
> temporary memory allocation. Could we have a definitive guide on this?
If the allocations are temporary, e.g. scoped to exactly one function, not massive
(use best judgment), and can't be used in any kind of novel DDoS attack, e.g. are
limited to one per vCPU or so, then they don't need to be accounted.
At least, that's my take on things.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state()
2024-08-24 0:00 ` Sean Christopherson
@ 2024-08-24 9:33 ` Huang, Kai
0 siblings, 0 replies; 5+ messages in thread
From: Huang, Kai @ 2024-08-24 9:33 UTC (permalink / raw)
To: seanjc
Cc: x86, dave.hansen, hpa, linux-kernel, mingo, bp, kvm,
zhangxiaoxu5, liuyongqiang13, pbonzini, tglx
On Fri, 2024-08-23 at 17:00 -0700, Sean Christopherson wrote:
> On Fri, Aug 23, 2024, Kai Huang wrote:
> >
> >
> > On 21/08/2024 11:27 pm, Yongqiang Liu wrote:
> > > The fixed size temporary variables vmcb_control_area and vmcb_save_area
> > > allocated in svm_set_nested_state() are released when the function exits.
> > > Meanwhile, svm_set_nested_state() also have vcpu mutex held to avoid
> > > massive concurrency allocation, so we don't need to set GFP_KERNEL_ACCOUNT.
> >
> > Hi Sean/Paolo,
> >
> > Seems more patches are popping up regarding to whether to use _ACCOUNT for
> > temporary memory allocation. Could we have a definitive guide on this?
>
> If the allocations are temporary, e.g. scoped to exactly one function, not massive
> (use best judgment), and can't be used in any kind of novel DDoS attack, e.g. are
> limited to one per vCPU or so, then they don't need to be accounted.
>
> At least, that's my take on things.
That makes sense. Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state()
2024-08-21 11:27 [PATCH -next] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state() Yongqiang Liu
2024-08-23 0:03 ` Huang, Kai
@ 2024-08-23 23:47 ` Sean Christopherson
1 sibling, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2024-08-23 23:47 UTC (permalink / raw)
To: Sean Christopherson, kvm, Yongqiang Liu
Cc: linux-kernel, zhangxiaoxu5, hpa, x86, dave.hansen, bp, mingo,
tglx, pbonzini
On Wed, 21 Aug 2024 19:27:37 +0800, Yongqiang Liu wrote:
> The fixed size temporary variables vmcb_control_area and vmcb_save_area
> allocated in svm_set_nested_state() are released when the function exits.
> Meanwhile, svm_set_nested_state() also have vcpu mutex held to avoid
> massive concurrency allocation, so we don't need to set GFP_KERNEL_ACCOUNT.
>
>
Applied to kvm-x86 svm, thanks!
[1/1] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state()
https://github.com/kvm-x86/linux/commit/c501062bb22b
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-24 9:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-21 11:27 [PATCH -next] KVM: SVM: Remove unnecessary GFP_KERNEL_ACCOUNT in svm_set_nested_state() Yongqiang Liu
2024-08-23 0:03 ` Huang, Kai
2024-08-24 0:00 ` Sean Christopherson
2024-08-24 9:33 ` Huang, Kai
2024-08-23 23:47 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®