Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1179514pxj; Fri, 18 Jun 2021 01:04:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlTB8ZgnFovrHUusj2IaneYQYCVJNnpCXve7VSXpQ5Cz2rVIS0kQJxozUUZ0ZYOo8uCkmg X-Received: by 2002:a5d:96c6:: with SMTP id r6mr2498112iol.25.1624003448137; Fri, 18 Jun 2021 01:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624003448; cv=none; d=google.com; s=arc-20160816; b=xJeLc1R79ArU3cXDqhIpRv8Fm9SpfhvQbC6uchABVfy0vAATrrBpE/VBlgPGvZWmCu n+mggqCgBdof/0WemKNUaQ6nMLnnR4/CcTK8kn8qZ5DgnYXRcJqS8k3mc1LwgfB2GaUC y5Af/fucijFpgJM/S4CMTBC2ufnIxhOiyrGe38XmLNGBY4SNHb51yq822wsVTDgInjRo napSv6/Z25C7j63EULfO3QyYuCh5zDXP4dAyHxLkBcV+QH5nSfxjsHtXFxKt0ta0rQR9 yK/bBQCXJrke4Nf39Bi1tzkI5Hl1NkRxzNeh21L1KYNjkgTuM+PGdZy6tLmur6aFfpzP KWRg== 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=Etb+e8FSSeXWZbq2Xf9BFn2ebx78s4yb03Of9slw210=; b=zc25Uhc9zGVKgHz/oXtMy78kPADn6drXULJlHFZrh1L5Y5hL+0o2/ZSgfHscc7X32E R0G/qq+LaguOEyNz2I19epPZYuQI23LMk2xyz8tTCfQeO6l1jQq6ULVDfMP259uuQAA6 wcBYniRaNp5DM/5Ol0Eo4BUOaX0knSfhyTdY+7O43IOpmBiaX02mp1DhMLAnGiyy0yvI XKU6/LL5E5Y7ZhYV3pNkqrAfs4pYHuX7E9FduxPqOiazOYvruGAwmMZMLi0JYQYzDlgc WsVDw+uNL9GFVCa4Hd5DTEsS97gwUsR8d4gJEwlfxfcn1KWA8es/9z55MZ9mw7LTni4A jvUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=qgX66veJ; 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 r4si1542691ilb.18.2021.06.18.01.03.55; Fri, 18 Jun 2021 01:04:08 -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=qgX66veJ; 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 S232707AbhFRGCM (ORCPT + 99 others); Fri, 18 Jun 2021 02:02:12 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:56900 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232250AbhFRGCL (ORCPT ); Fri, 18 Jun 2021 02:02:11 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 2C57621AB1; Fri, 18 Jun 2021 06:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1623996002; 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=Etb+e8FSSeXWZbq2Xf9BFn2ebx78s4yb03Of9slw210=; b=qgX66veJVOAz8w/h06hvEAy8tj7LJjm5kroBTguRv6+yqaHR+HF86BS5Q3nBuTgu9TT3bm iCeVwMkvKakAibJlJv4QHp0BYt++KCebhnO7eyG1NVL/0wEgZwsd9lnHm0IghQ42F2uc9m sFwT1ETlMcSACt+8efwjXONSPFB6AUs= 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 E0E8AA3B9D; Fri, 18 Jun 2021 06:00:01 +0000 (UTC) Date: Fri, 18 Jun 2021 08:00:01 +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 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. -- Michal Hocko SUSE Labs