Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3833695pxv; Mon, 26 Jul 2021 13:25:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbZOdlysx6HoOqf6/xRE4MDfD6Yd8W7jPG01rfCVQ+DL8w5nhp2hpHeAeBx2rQNqUWSK2Y X-Received: by 2002:a05:6402:1d86:: with SMTP id dk6mr24016657edb.136.1627331153705; Mon, 26 Jul 2021 13:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627331153; cv=none; d=google.com; s=arc-20160816; b=tJYCYlrQu6nzxZtS72UwwSi+7nN8wxq+AYVM0uppbJan4r7SODUv9hol2m5VjikMWj escjMG/BWYAVel+L13TDVdDeTYKtTFIsr27DIebEbqsClsEWcECW4elcTA4ezo56RqUC GdCKm5Q4mj4uqvTfA/0/Yi5yt5UJH6j93vcjKMfot2v46gPH/yLc9bGAEnBORYYLSCwf 2v0wVG9UzEDWmqf0Heg83r1TJFZ6p/+U8ZRhg1E6MkpRoZ759ymhIjC2Mng05c6d6hMM hCgySdXu/wxxz5y0pepoEN5zhcNgKYCbSRJiwx6qVc4spAfQo/lELdgQNOEtAOObZcyH x9Fg== 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=DkoqzghGXkp4JTswxtHKmjuCRqg+mzIS/snExybiSds=; b=avTew18X5AxN6yW+kRcIxl0oQjN2Fe5o8LYSfx33AbFPI12jZ+cEBki5bVrPTA8Tmr /eVJDYZxG1XEj4aDnAOc9HFpEXYWe/tforZKptTq6JYFKOPxkc+KLqYCppJdwwKMhYk8 k4HXHwyPi88f9TJ8ircpjEZBeJXurQOW/1kmUIfzJ8NBDvJ5t+4+EGxuQZR+vwdZsPw1 JUKFnxqYqbGrxOb3Br/SiQAVxNuwcVpKFxAW3Z7MkH3lJRHGRpJVTcTX3LZzKOryAq5K 2N6yyzRxqNvawIPxKtv0wyjp1nVZawAJj4o6dZ/83kuI4NGxueZ+cJrL61O0wJ3M1nFY m/1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=t91gofma; 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 mp29si885343ejc.290.2021.07.26.13.25.30; Mon, 26 Jul 2021 13:25:53 -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=t91gofma; 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 S232146AbhGZTnR (ORCPT + 99 others); Mon, 26 Jul 2021 15:43:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbhGZTnR (ORCPT ); Mon, 26 Jul 2021 15:43:17 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0E6EC061757 for ; Mon, 26 Jul 2021 13:23:45 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id n19so13627756ioz.0 for ; Mon, 26 Jul 2021 13:23:45 -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=DkoqzghGXkp4JTswxtHKmjuCRqg+mzIS/snExybiSds=; b=t91gofmau6rt/+T6FpafvvaxtDSRVb+jfJovRyDuaj9pHLjbE/Tn8gcKSf0oaOebtA W/tHTQQzX6nKQQ2S7JVijuZtmfQFewf4QQ2qarA3P+UU9l61Te5Vw1bhZOkoeiYE0KAw b7ukqOb8SwJ22Cci0PyvTQnqzO7Neak85q4y/kAc6yXz75ea2qqNHjzCXIqNUhk5xWZU lWxhZG33JXMKvovCf6tkoG74jvRC3CzISSPci2CstAbt7DPGEoLGazCqY4Q03IWIKia8 1DxsDnvmK789LzUHZMSh5X2qUVkR38ZdgUJJbMbjydSK4EXU9E5QhE70W0Yh9SRGkA+o agSA== 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=DkoqzghGXkp4JTswxtHKmjuCRqg+mzIS/snExybiSds=; b=GDAsqTGQ7YkUELCu5ewLbqoJ+pUT97DEpJec9O1ZkFke/ds2fTiZ/dXlhZpajn4+NZ scGNB1ypwN256l3lBumYeK/v0KQObm/TYK52iBQEdgK+VTRcAw6x3ou5UrAFmb4Zrop5 VGkmv2/Rtut1qHAz7p7+JTo04EbxaHTiNapmb/YdNdhya4NCQiJSr0J+q6w0RENWMe5I tS5or/rLfg0KN89GrXm3wW0nDt/4IGNisYEbS5v2vRzpOT1uiP66levcZhUcV3vCvvxz p0/sk893XijD0p3E7XsU1g8ET5CYS0gn6HyrDT8GKn1NJftWxTqZLKaALc1H9cFKB6gR Nuag== X-Gm-Message-State: AOAM531krQXkjjl1MrwYhne+IDWf+NcCRuRWahaMzTo/8i8xP84fkdoN woOfrZ/J3sDoVhmP1/jnNU4nimY+hqqOWnQP7EB4Vg== X-Received: by 2002:a02:cab9:: with SMTP id e25mr17930118jap.25.1627331025078; Mon, 26 Jul 2021 13:23:45 -0700 (PDT) MIME-Version: 1.0 References: <20210726175357.1572951-1-mizhang@google.com> <20210726175357.1572951-2-mizhang@google.com> In-Reply-To: <20210726175357.1572951-2-mizhang@google.com> From: Ben Gardon Date: Mon, 26 Jul 2021 13:23:34 -0700 Message-ID: Subject: Re: [PATCH v2 1/3] KVM: x86/mmu: Remove redundant spte present check in mmu_set_spte To: Mingwei Zhang Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm , LKML , Jing Zhang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 26, 2021 at 10:54 AM 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 > Signed-off-by: Mingwei Zhang Reviewed-by: Ben Gardon > --- > 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.432.gabb21c7263-goog >