From: Michal Hocko <mhocko@suse.com>
To: Jim Mattson <jmattson@google.com>
Cc: Denis Efremov <efremov@linux.com>,
Paolo Bonzini <pbonzini@redhat.com>,
joe@perches.com, kvm list <kvm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] KVM: Use vmemdup_user()
Date: Fri, 18 Jun 2021 08:00:01 +0200 [thread overview]
Message-ID: <YMw2YeWHFsn+AFmN@dhcp22.suse.cz> (raw)
In-Reply-To: <CALMp9eSFkRrWLjegJ5OC7kZ4oWtZypKRDjXFQD5=tFX4YLpUgw@mail.gmail.com>
On Thu 17-06-21 17:25:04, Jim Mattson wrote:
> On Wed, Jun 3, 2020 at 3:10 AM Denis Efremov <efremov@linux.com> wrote:
> >
> > Replace opencoded alloc and copy with vmemdup_user().
> >
> > Signed-off-by: Denis Efremov <efremov@linux.com>
> > ---
> > Looks like these are the only places in KVM that are suitable for
> > vmemdup_user().
> >
> > arch/x86/kvm/cpuid.c | 17 +++++++----------
> > virt/kvm/kvm_main.c | 19 ++++++++-----------
> > 2 files changed, 15 insertions(+), 21 deletions(-)
> >
> > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> > index 901cd1fdecd9..27438a2bdb62 100644
> > --- a/arch/x86/kvm/cpuid.c
> > +++ b/arch/x86/kvm/cpuid.c
> > @@ -182,17 +182,14 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
> > r = -E2BIG;
> > if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
> > goto out;
> > - r = -ENOMEM;
> > if (cpuid->nent) {
> > - cpuid_entries =
> > - vmalloc(array_size(sizeof(struct kvm_cpuid_entry),
> > - cpuid->nent));
> > - if (!cpuid_entries)
> > - goto out;
> > - r = -EFAULT;
> > - if (copy_from_user(cpuid_entries, entries,
> > - cpuid->nent * sizeof(struct kvm_cpuid_entry)))
> > + cpuid_entries = vmemdup_user(entries,
> > + array_size(sizeof(struct kvm_cpuid_entry),
> > + cpuid->nent));
>
> Does this break memcg accounting? I ask, because I'm really not sure.
What do you mean by that? The original code uses plain vmalloc so the
allocation is not memcg accounted (please note that __GFP_ACCOUNT needs
to be specified explicitly). vmemdup_user is the same in that regards.
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2021-06-18 6:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-30 14:35 [PATCH] KVM: Use previously computed array_size() Denis Efremov
2020-05-30 15:58 ` Joe Perches
2020-05-30 17:28 ` Denis Efremov
2020-06-01 8:46 ` Paolo Bonzini
2020-06-03 10:11 ` [PATCH] KVM: Use vmemdup_user() Denis Efremov
2020-06-04 18:41 ` Paolo Bonzini
2021-06-18 0:25 ` Jim Mattson
2021-06-18 6:00 ` Michal Hocko [this message]
2021-06-18 16:53 ` Jim Mattson
2021-06-18 17:04 ` Michal Hocko
2021-06-18 17:32 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YMw2YeWHFsn+AFmN@dhcp22.suse.cz \
--to=mhocko@suse.com \
--cc=efremov@linux.com \
--cc=jmattson@google.com \
--cc=joe@perches.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox