Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1675892pxj; Fri, 18 Jun 2021 12:21:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzerD2c3KYxq1NooZhKPJx9lXymv1RT5Gjcn88Z0XZp6JT9aZhmBQSS+5FbupCC+UCLpjFp X-Received: by 2002:a17:906:6d16:: with SMTP id m22mr2904740ejr.333.1624044093987; Fri, 18 Jun 2021 12:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624044093; cv=none; d=google.com; s=arc-20160816; b=M2ywzYYXoC/Y/O6VawMadvkPanAhhqBd5LHdDFEJVV/xXgcEEyyY56v7lv/aOcmHx8 2XQ5+xQdtBteTNoztyi3yW2ueCTy64wPmpm+gIMtak9mTH6lV87ZLfJjBgh6kqmsW36J I+4xZhK2hfqN0oat+ayypCjiKKUvgFuLqO+KSd/h3q0Y9sSAXfTKjApuDCSeUK5eBhpZ qOhE2XGTuERh+hY9cn1V0naEha36z6cXfOH9Ly84rGh8aPZXRlz6IxlYk4NrLzZF/IX1 SfDidHl0SWtnhUqrqw4gpJXYfyZq3WEUd/cFziwTils8iIJz/w0OfT2KEt7ZBAtytTzI 7MKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AtSqJOQGfjKv3UOcjj+P/M/U0KAJcbotecQbdXLeGdE=; b=dStsgcdwlEu5istpz74p9N2FfmkfEo9WNkM4Q2nFlNgk54ZDjf2eXt4Az+Bo5pwdpk 8E102OFPlpe3VzsF4ykQQLVvHVyDm9maCgD6QuRp6lJR+rjfUniqp58x9omyUQVJ7gFx nXA5E9eQU7HcZV4hi33BC92MOfQ9RO637QVse0C5NLu/Y7bkT7VpT3vPwGBj1S3ejX/E YmcfjvwQ8gr2KcHBC6nUte+Uu+sP0pyqR4a5mGwmYtm/QF2lOFTS9gRt1Uci7vRGT9G5 RzxyKXiwZ2f4o4OfOEZ7FULOZLdm8vtB4FjWsSDYNyDDNEdzWe8wW+mAKJmR7IM4mqCg L6LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S6H4mLso; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si6203911eds.175.2021.06.18.12.21.11; Fri, 18 Jun 2021 12:21:33 -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=@google.com header.s=20161025 header.b=S6H4mLso; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235984AbhFRQ4O (ORCPT + 99 others); Fri, 18 Jun 2021 12:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233369AbhFRQ4O (ORCPT ); Fri, 18 Jun 2021 12:56:14 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02CFAC061574 for ; Fri, 18 Jun 2021 09:54:05 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id x196so11196048oif.10 for ; Fri, 18 Jun 2021 09:54:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AtSqJOQGfjKv3UOcjj+P/M/U0KAJcbotecQbdXLeGdE=; b=S6H4mLsocQZXJTWCCi58vEGYojWSPpW0UBu5oyIqTluZ1mhtIhmr8gi/WkMNeemx9V ZVVxgzztTTFLcKcB7Fl9a6JjekIFLAD7GK8aco+Ed9UvOgWLWmhtPKxbFX7Mrii+GK36 +vCHyWa+xfsZbl8w9tKOmCXqnyHgWTsCGYhiqctrFdiWgo6mBo6503RS8pHiIA+1kgNy Lo0e8EpTtukNP0M0cubZstkmwYWHaCIzJx7hIwLb3IcYuXpfOlay3MIWYwWYDIbyqQ9y 3OccBtAaOIJQ4IxlAb4Zyp8/H3I0oUeZLf6vCuoF7iakCwbd7Fv9Z/dTSnxhl9Nlqvdn UeZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AtSqJOQGfjKv3UOcjj+P/M/U0KAJcbotecQbdXLeGdE=; b=UsMAxjhgnlND6W2BUDYyeDicvpLas1RqsyQoiBq83R+YQi9Qr3pRTQldIapMmtsKtJ YeG+jsTc/6f6FlhdOky2gDBQJzKWdPFKMZNbudjefpmBkkwHndTxtK6SRiiz+xQLkzyZ d8sibcrngd6JR4I/A0e3KzTb4fyTrONxOttO9NpdWVT4Qm0PHC7F6V5JXRXCUQ5DI186 S/8WtAyohZhURibgc/mvSYm8acsuMhfySDFLkZ7gQsHf3ONCOcG18Ic72gjMV/+6m3JM 2Av5ON54ixtFQBch7Q8JqrMYoK768E7XcnjwTCE9dwt2LDnXcx4BZ9imOKJTW0xRkulw FYaw== X-Gm-Message-State: AOAM530Vo13ctWcci9QoY43k0mObxn8/CyGz7PK+UnG9GJ/urNvR6r1Q zqV/xR3WmK1+HlRAh3PuHY6Ik161WOVGlmfwRLtnBA== X-Received: by 2002:aca:1e07:: with SMTP id m7mr7727189oic.28.1624035244083; Fri, 18 Jun 2021 09:54:04 -0700 (PDT) MIME-Version: 1.0 References: <0c00d96c46d34d69f5f459baebf3c89a507730fc.camel@perches.com> <20200603101131.2107303-1-efremov@linux.com> In-Reply-To: From: Jim Mattson Date: Fri, 18 Jun 2021 09:53:53 -0700 Message-ID: Subject: Re: [PATCH] KVM: Use vmemdup_user() To: Michal Hocko Cc: Denis Efremov , Paolo Bonzini , joe@perches.com, kvm list , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?