From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D959C48BE8 for ; Fri, 18 Jun 2021 16:54:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3225B61260 for ; Fri, 18 Jun 2021 16:54:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235990AbhFRQ4P (ORCPT ); Fri, 18 Jun 2021 12:56:15 -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-Google-Smtp-Source: ABdhPJyHzNg1FTlnP0ojeJkXrYeJkXPTb5H3tCQJjlx70G2MdTVcBObUsy/Yte/q9+CooW6Ir2VvuD/lJo1v/CAIyYs= 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?