Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp706877pxu; Wed, 14 Oct 2020 11:32:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHuCHKYTy6jnrgGg5lWsx4znmmTfqeENy49kBdWfinS+1F50CJLGGBJ+YelG38bMQLlxNc X-Received: by 2002:a17:906:53d7:: with SMTP id p23mr409140ejo.232.1602700332532; Wed, 14 Oct 2020 11:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602700332; cv=none; d=google.com; s=arc-20160816; b=CBTnWAeRFdtLIH/pHflzxpj6ZncRkiE7heNVPKdZK4Evygk0TFn687PUfp4ivHAazC VWdmkKPF3ObnFXViSy/SnoZA7/jVCbxeWjGnztckTu1AWj82l+k+9K4dugCu2WUjRX1W EjqcTypoeiQGK+CGgerToH5xEsFN81R4Ye2pvpP4MFfJ4XcbwMiD2sxTbjn1QkzbQd0C huuYBB0/K74Ibg5mCkTmA9PSiZCZ4RQsuxK7ecjq5tcBN1p1aspdYTJwCGa8l5M6AeZe yQPwVhc0NJhm027gUAZG0HSh1DERZF+Sraa93e9ms56bkwcR/yZhfio+wlRKtl4KbIVe JyMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=89LrHzVsLlwPBCGn84hGo/p+FJBhRaw2texxmtA4jtA=; b=sCH4FG2lSu6qj6/jumOf+y3owWg8lB9zBoS973pb3SGQvGL/8R4IsvfxSEkxMJU55e YUTfmGog27aoPRH8E0jyzYAIzBJLDblKlfPSpm0NooR+a4iqyIAh8nUkKCpAunsv5NbH 8RbRbA/xWM2RD/WUiyYk6Bm8xFqoLAPAwi23V2cm/5xT/GkkzmeaUaSbLajKzCN9mDUU lta13vy7ABExk88mXIy5OUoP+vC7Y8Ua+zP0xW4cmULUuEFNiC3ZwibIEtCVuNp5Taco hfwtm4gOKqOiB2+7VAyq0oG9oqUXVxNppumB3jzB2jyGI36zCcUbbHI9cO0PK61R0AU9 mbqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G0CBA16R; 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 dk1si357787ejb.556.2020.10.14.11.31.50; Wed, 14 Oct 2020 11:32:12 -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=G0CBA16R; 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 S1730011AbgJNS2J (ORCPT + 99 others); Wed, 14 Oct 2020 14:28:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389175AbgJNS1q (ORCPT ); Wed, 14 Oct 2020 14:27:46 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC5BBC0613E3 for ; Wed, 14 Oct 2020 11:27:39 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id y77so354049qkb.8 for ; Wed, 14 Oct 2020 11:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=89LrHzVsLlwPBCGn84hGo/p+FJBhRaw2texxmtA4jtA=; b=G0CBA16RiGAumu6zAemSqyOdhCK2t0J6mY2WbIOvQp14LFcD7co9CLm/gSj3d7ou9G XtE2cAaxSEe5Ua17Si2vIdYX7lVuMAei6cqwgXO6puYzYxn3e81DiB8pen/ANenriYWS MQ8HAiCMx2x+8+Ge7jbI98vKWUhOXzsfhAORKXZP76rjJ+BQNRXGXa4/exCXtxqUCxI+ MBcrDurIBPgrBVhTz3yzlEWtcNu1/fqxh+9osjW3AmiiPEO+J8wWZM7eZtPR65BaBhyB 0FOqWx9w2DrlrYhNfql9GH7DSU2FjrjKgWSmGLnPNMSAQPk6s+ePGXMmClf3tubOYaTl kndA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=89LrHzVsLlwPBCGn84hGo/p+FJBhRaw2texxmtA4jtA=; b=AX1MCX/GcXNXThXx6wNM61qtbxeUz+eKuoHO5/42a+F5dkrEQvLaIYUk60URtOg2HD TqKQ92muydIvwXoQ1hCN5w3RF6PV2ttMXOWJEYEpM3jNRUzhcGp2qwDCyFGLzH9JQ7AD ivol71yGKUM3GAVYsh2b6W3Bx3TWFWBeuUIJnsLtOsdDtIubPfzo9l+7HC4+MWIF7Lic CdyJARwmk48+XkOt1M3Y/sOc+8FWT7EJmtlSOt5793DtISmlq56eTVb9Wxi7MbAzj0qS xdi3i6sYUldbN9IJWfXhW4V0kVGuyhHuGPC+fydwf1ked95Uo/skr1mMTE4E8W7IXpaU F8JA== X-Gm-Message-State: AOAM532AoBmQmT8dOlCBxKRsl9Z9o8g/i4ESpcI+umqrwLC8uiVzcNPe 068RCKETQ2YB49pqVgor+19kk+IIBBQmEKdV8C6N2iLsRTpBLpMLqfEY9LOcj8YMEiR7ZcMy0cN WsY8sgVwgm5dJ0C5E4o0AZBubogYcCNTmWNJKT79DPfOJrRu/EN+lb/S4Rk9n7PkyKPmM0fna Sender: "bgardon via sendgmr" X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:f693:9fff:fef4:a293]) (user=bgardon job=sendgmr) by 2002:a05:6214:2ed:: with SMTP id h13mr593520qvu.26.1602700058739; Wed, 14 Oct 2020 11:27:38 -0700 (PDT) Date: Wed, 14 Oct 2020 11:26:59 -0700 In-Reply-To: <20201014182700.2888246-1-bgardon@google.com> Message-Id: <20201014182700.2888246-20-bgardon@google.com> Mime-Version: 1.0 References: <20201014182700.2888246-1-bgardon@google.com> X-Mailer: git-send-email 2.28.0.1011.ga647a8990f-goog Subject: [PATCH v2 19/20] kvm: x86/mmu: Don't clear write flooding count for direct roots From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Cannon Matthews , Paolo Bonzini , Peter Xu , Sean Christopherson , Peter Shier , Peter Feiner , Junaid Shahid , Jim Mattson , Yulei Zhang , Wanpeng Li , Vitaly Kuznetsov , Xiao Guangrong , Ben Gardon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Direct roots don't have a write flooding count because the guest can't affect that paging structure. Thus there's no need to clear the write flooding count on a fast CR3 switch for direct roots. Tested by running kvm-unit-tests and KVM selftests on an Intel Haswell machine. This series introduced no new failures. This series can be viewed in Gerrit at: https://linux-review.googlesource.com/c/virt/kvm/kvm/+/2538 Signed-off-by: Ben Gardon --- arch/x86/kvm/mmu/mmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 2e8bf8d19c35a..3935c10278736 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4266,7 +4266,13 @@ static void __kvm_mmu_new_pgd(struct kvm_vcpu *vcpu, gpa_t new_pgd, */ vcpu_clear_mmio_info(vcpu, MMIO_GVA_ANY); - __clear_sp_write_flooding_count(to_shadow_page(vcpu->arch.mmu->root_hpa)); + /* + * If this is a direct root page, it doesn't have a write flooding + * count. Otherwise, clear the write flooding count. + */ + if (!new_role.direct) + __clear_sp_write_flooding_count( + to_shadow_page(vcpu->arch.mmu->root_hpa)); } void kvm_mmu_new_pgd(struct kvm_vcpu *vcpu, gpa_t new_pgd, bool skip_tlb_flush, -- 2.28.0.1011.ga647a8990f-goog