Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1973141pxy; Mon, 2 Aug 2021 15:33:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4kXqIpDzUgw0BQBuAchOlU/HsOxjHQXtPJkV9V9m0+nrlYeJEfg49CCuC2Yxtm8tsXodn X-Received: by 2002:a50:f615:: with SMTP id c21mr22636121edn.146.1627943636503; Mon, 02 Aug 2021 15:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627943636; cv=none; d=google.com; s=arc-20160816; b=ybkrIp3bCUcolM7yY3gqqlWEygfzkaz3Rnjdvj/GyWO/dkDRBLe9vb6bQ8EWOYxKDz 3+Ki5ehZYsuf1hl/rxiUFRke7SoSePC97i8s5yE/BHqUCDbpKi4Z27DpgYfou2P2zKvL DoqSFDkaHL5J6VmWMQqa+LnSdbFG0wboa7f8O3QWVbnyG64fBxnxFJD2k/H20CTnExX0 xJWH8KgQ7YHjY12h2t3gBC/JQM+KmCloy1driM+dXvNhfXHpXkRDItb3c6sSyKmnov89 utLjRHH0NSCglx+bXUXDoWtnfhLEacqRF9yxQXM6WPlouqK6p3JL9woJQIuZz4i5nQn7 qBlg== 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=9qmivmphespvuvyQ3MoQcp3D+LF94WdyvdfL2S659tE=; b=EWt5oFVbrrWjlzz0l9wW+2eJdSX6nySJxXZrkCnG1EmujhJ54koSe3YZFsnx5Bd7q/ D5+2Dzvl7dTXOgWjluVFM1MbC/F4M3tO1XCj60jHuoN/iG1Ef8PMElWXxaDVJw60ja9z fBlO5RsDVYg8oj0p7DR0NO7mgtBmlFLvT1hEX/Xgs/IX3/sgzs1tDh5HckRuMd88IqVF UEOAeFux+r2+8+SJYV0ULdWL8ccY4f8e36vMBm7sL6n8pqq9Pjg59i/mrZ3K33Jh92rh XQENacviLoevcGjd5gLwumu1tPo6UrciG6+en5ZYNrWdfszE1j6NTaKlm3hlm9ncAnR/ 78Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="QTS5XBU/"; 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 jg31si14757147ejc.10.2021.08.02.15.33.33; Mon, 02 Aug 2021 15:33:56 -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="QTS5XBU/"; 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 S232042AbhHBW3h (ORCPT + 99 others); Mon, 2 Aug 2021 18:29:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbhHBW3f (ORCPT ); Mon, 2 Aug 2021 18:29:35 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0442C061764 for ; Mon, 2 Aug 2021 15:29:24 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id z3so20048598plg.8 for ; Mon, 02 Aug 2021 15:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9qmivmphespvuvyQ3MoQcp3D+LF94WdyvdfL2S659tE=; b=QTS5XBU/761TpN4U96Dh5MQybzFkqH146ItHsrUeAN+GIDp5GJqcYZ0UdTUXckdlFd cNSiuSkRgJEEX5Cd7UjrDqOBtgocNdFU/I3PUQFcfpmoYw/KaVpLDuPdZr/VKm/OJ+pd ssqtwWpblWCQsqftXO6LkljYpm3Ir+w0gPQG0sPn1mwWg+hVtYa2e47I/lHmQkuAwu2G V7YVQSgIMfDZ+58cTIu+g8+w7bdyKjVD38Om0pgPRF5wxFKJhnEycam6tDsVGpRSZ+rN xq5v/xOaU8NoAjmveoqSmYC+m6VmCUZ76IQxE1CLBrKsaZYOEg5yM5aqtpRbSO1LsWc6 Vfag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9qmivmphespvuvyQ3MoQcp3D+LF94WdyvdfL2S659tE=; b=eNKBg8FdJwZW3WP4GFIxJfFHjkgD2s0rFtg63BGPBHPkuqLFW4JgsC2ogx+haiOpig WTCfZWocB1Iuerot7Kk36NW7x7GZGUWrdSQfVUDp+aCHNZiHP+0YLc+Zuf8yO5g3C6nM flOt4YuzsGO2VRGA5NlZaK7EcKukhhM4gVBMhpZQaxlFPX675+RoLUuPs0JIF0SnnBYX 6gqE//wx/3sL5c5A7FYKQVBCxSu6wdZ5fGLjP2UvMlfAXw9HyJpNNLFxRjBnS11Lqh8O wV+oZNfkNt+aLO3IUyDdUElHV9fzVNA3tgLROml/FV1wlpwL0YpybkVOuzT/Rc6JIWfu k1RA== X-Gm-Message-State: AOAM5300otsRIU3vEeIU2E+Zd6uEHNGXN4ZCDnW8wV6Ry1z8qVCOZmea /347YqecuccJ4YEZ4yQJpYy+sA== X-Received: by 2002:aa7:854a:0:b029:332:330e:1387 with SMTP id y10-20020aa7854a0000b0290332330e1387mr18564513pfn.67.1627943364007; Mon, 02 Aug 2021 15:29:24 -0700 (PDT) Received: from google.com (254.80.82.34.bc.googleusercontent.com. [34.82.80.254]) by smtp.gmail.com with ESMTPSA id y7sm12164953pfi.204.2021.08.02.15.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 15:29:23 -0700 (PDT) Date: Mon, 2 Aug 2021 22:29:19 +0000 From: David Matlack To: Mingwei Zhang Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon , Jing Zhang Subject: Re: [PATCH v3 1/3] KVM: x86/mmu: Remove redundant spte present check in mmu_set_spte Message-ID: References: <20210730225939.3852712-1-mizhang@google.com> <20210730225939.3852712-2-mizhang@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210730225939.3852712-2-mizhang@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 30, 2021 at 03:59:37PM -0700, Mingwei Zhang wrote: > Drop an unnecessary is_shadow_present_pte() check when updating the rmaps > after installing a non-MMIO SPTE. set_spte() is used only to create > shadow-present SPTEs, e.g. MMIO SPTEs are handled early on, mmu_set_spte() > runs with mmu_lock held for write, i.e. the SPTE can't be zapped between > writing the SPTE and updating the rmaps. > > Opportunistically combine the "new SPTE" logic for large pages and rmaps. > > No functional change intended. > > Suggested-by: Ben Gardon > > Reviewed-by: Ben Gardon > Reviewed-by: Sean Christopherson > Signed-off-by: Mingwei Zhang > --- Reviewed-by: David Matlack > arch/x86/kvm/mmu/mmu.c | 14 ++++++-------- > 1 file changed, 6 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index b888385d1933..442cc554ebd6 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -2690,15 +2690,13 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, > > pgprintk("%s: setting spte %llx\n", __func__, *sptep); > trace_kvm_mmu_set_spte(level, gfn, sptep); > - if (!was_rmapped && is_large_pte(*sptep)) > - ++vcpu->kvm->stat.lpages; > > - if (is_shadow_present_pte(*sptep)) { > - if (!was_rmapped) { > - rmap_count = rmap_add(vcpu, sptep, gfn); > - if (rmap_count > RMAP_RECYCLE_THRESHOLD) > - rmap_recycle(vcpu, sptep, gfn); > - } > + if (!was_rmapped) { > + if (is_large_pte(*sptep)) > + ++vcpu->kvm->stat.lpages; > + rmap_count = rmap_add(vcpu, sptep, gfn); > + if (rmap_count > RMAP_RECYCLE_THRESHOLD) > + rmap_recycle(vcpu, sptep, gfn); > } > > return ret; > -- > 2.32.0.554.ge1b32706d8-goog >