Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1678094pxj; Fri, 18 Jun 2021 12:25:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmLiqXkNt9l1rIPczrxXxcRi2Pk6bEuM9yASARCEXQZNXA0ksp2F8PHB85bdFZh4Kyeadj X-Received: by 2002:a17:906:b190:: with SMTP id w16mr12954344ejy.332.1624044314920; Fri, 18 Jun 2021 12:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624044314; cv=none; d=google.com; s=arc-20160816; b=tVhKmgp++Zb8uQI9nftk0p5awa4/GP/ifjuKilrIti6aMOtDdswm4UpVGrOvi2yjZ4 DK6KIexGLLfS5KGbXJcg+Aq+teF1F4b7hUdHugKrJyOz+mwVWiGEdj7V6IRz5MHbGAU2 eG3LZAi3mwOLEni37z9T4H+dL4n/FRM/NgFWuyXbWFKFYoVVtzLjwpB+fG2R8E4vgZmr YLP5Swx7nkgfNTblBePYA9CfrCXoEsLy8zclDGU18Xvy56+/MhY0d+4Yz0CB1iJjsb3O J0x43CxJjSGorjQ338mnsEryfk0IXkOtf2dKlEgb6IJz4CITB+PXAKhEsmO5muxPYxE6 wCJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RRj7fgDRtAehPcgrufisp/9Ya/S7fBGeH0Q99DKFBUg=; b=DgEZQ2ll/LAXTLKei3ja2Odu6LAftDUniYWMGWGzph8RQ0Zf5lzgR7oYunweECWk4R zXFdPBeX6BMvCzRScdMzf+rwcGAAQ9/wfolZYz7Q2hdD/AHsPn/Sk/ZefN5Rx0qfFsHJ /sjcTsBLCp6jbv+KvJtmXO6TWeJo5VXgL0y7duOfHNEvAI+8aQcXwZzXvSegpiaTm1zN Cc287YlXCBuWzaeMal4geCYcPYIaPgiNUtMdDsJvePsxvvUh2aTtFR5OWPVBkHHD6Q0i gEbOiRKDF6LAxSTYuLF4BENHAmWT79V5EaB6TgUjAzcbE7xqGTO7nehTPSwcjaCrizog BXTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=D8rrZRYD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dz21si9576654edb.281.2021.06.18.12.24.52; Fri, 18 Jun 2021 12:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=D8rrZRYD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236013AbhFRRHC (ORCPT + 99 others); Fri, 18 Jun 2021 13:07:02 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:53628 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233454AbhFRRHC (ORCPT ); Fri, 18 Jun 2021 13:07:02 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id CAFF21FDAE; Fri, 18 Jun 2021 17:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1624035891; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RRj7fgDRtAehPcgrufisp/9Ya/S7fBGeH0Q99DKFBUg=; b=D8rrZRYDsoVVhrdfz7W0QCUuphU0nV+ZkITBeWFLnMVGmIdAmqnZmTMjI/Uf6/ALA7pWxk QMamWOBwp2urL3ZtNaTOJUXk/1aDFrH8FdTwN6Kx7ShotJM4yvfOg7JlBmWhA/UtGSjmTZ 9xuvppuraIZt2cTxhVYd1VbmVqvTvK4= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 884E3A3BCA; Fri, 18 Jun 2021 17:04:51 +0000 (UTC) Date: Fri, 18 Jun 2021 19:04:51 +0200 From: Michal Hocko To: Jim Mattson Cc: Denis Efremov , Paolo Bonzini , joe@perches.com, kvm list , LKML Subject: Re: [PATCH] KVM: Use vmemdup_user() Message-ID: References: <0c00d96c46d34d69f5f459baebf3c89a507730fc.camel@perches.com> <20200603101131.2107303-1-efremov@linux.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 18-06-21 09:53:53, Jim Mattson wrote: > On Thu, Jun 17, 2021 at 11:00 PM Michal Hocko wrote: > > > > On Thu 17-06-21 17:25:04, Jim Mattson wrote: > > > On Wed, Jun 3, 2020 at 3:10 AM Denis Efremov wrote: > > > > > > > > Replace opencoded alloc and copy with vmemdup_user(). > > > > > > > > Signed-off-by: Denis Efremov > > > > --- > > > > 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. > > I asked, because I wasn't sure if plain vmalloc was accounted or not. > > In any case, these allocations *should* be accounted, shouldn't they? This is more of a question to maintainers. Are these objects easy to request by userspace without any bounds? -- Michal Hocko SUSE Labs