Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1AD4C433F5 for ; Thu, 23 Dec 2021 22:24:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350509AbhLWWX6 (ORCPT ); Thu, 23 Dec 2021 17:23:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350452AbhLWWXx (ORCPT ); Thu, 23 Dec 2021 17:23:53 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 847ADC061784 for ; Thu, 23 Dec 2021 14:23:50 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id b8-20020a17090a10c800b001a61dff6c9dso4031104pje.5 for ; Thu, 23 Dec 2021 14:23:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=fpIDrpWZwmj6BNONuDX3BQPSQp/TrPoIB2oyQBfGSwo=; b=GRcaaHwNTlE7NbCGNV/wpojHO94gvVAt5hXaCqZRlKal8bVZDb3AR7GVeWbPVCBIp3 JylcRrzpPNy4j7rzIblndCS2J2VE68MPO0n1sfCMr0Snbg06HoeuO8+GnBfNtMljOxvQ rjLPLHtz/rbxAA/maMsbXxnkiXxNQ/1D2UPVOJowJrFNEVjrLljnelDNEvtmMqcKH9h/ iDERCmRJOGePmwwt6T+JwDLSqX8CFOqZ2n6mILxbTJ2mao/zYUoKYGTo/nZYbgQTbRgX 6w9HzzMk/m/xRaxtf+jplH3oB6AfmUi6TgqUVA9fcdhQHIsvOZIyUFBPw5j6mk4OppQV +baQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=fpIDrpWZwmj6BNONuDX3BQPSQp/TrPoIB2oyQBfGSwo=; b=gg7s3Tb/9lQ4IMCz/CQkUKduPdqL3Tc5uwon0e1K2kHDf04wnLsDVV5ucsseta/0TW O9DrW+2PL4ZAUZqMSmUJCXUIhfG3zHHBvs242dgkYahqnWWppV4ZfxVMokj5XtbuJQFO h44UFxuDy6Zg1rPfRL1S61hxk1J2jBy6F9KyfSLPSvNu/S9mZKTjk9HJqRoyqCWacy8I bQwgWenqueZJcGoFCP+ZxOWPSmgJGNf7a0cvUGj5LgFAU1YsdWlDzn/nJiEzZWmt0zTU mgAzEX4kqFcN4zXIoZ0VyXTSVLrDHwYWANGasSxSsUnwoIT50AB/6GxzxCOx0ejeuUF7 UX1g== X-Gm-Message-State: AOAM532bE43TxK/YM1zk07GimD8k5VQVp1xfRsQJ2paVgaMYXWJ7B334 3USH+fjeMrgxG6TbRH9MeeiOjA/jFNA= X-Google-Smtp-Source: ABdhPJyclXLRTwW6GJeCEWsyo4Kj1bo3ZQ/06TQEYE++AKaw4dOta3j54//LgcIFPrdnUSZzHL2DS03/7L0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:7797:b0:143:88c3:7ff1 with SMTP id o23-20020a170902779700b0014388c37ff1mr3972429pll.22.1640298230048; Thu, 23 Dec 2021 14:23:50 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 23 Dec 2021 22:22:53 +0000 In-Reply-To: <20211223222318.1039223-1-seanjc@google.com> Message-Id: <20211223222318.1039223-6-seanjc@google.com> Mime-Version: 1.0 References: <20211223222318.1039223-1-seanjc@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v2 05/30] KVM: x86/mmu: Check for present SPTE when clearing dirty bit in TDP MMU From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon , David Matlack , Mingwei Zhang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Explicitly check for present SPTEs when clearing dirty bits in the TDP MMU. This isn't strictly required for correctness, as setting the dirty bit in a defunct SPTE will not change the SPTE from !PRESENT to PRESENT. However, the guarded MMU_WARN_ON() in spte_ad_need_write_protect() would complain if anyone actually turned on KVM's MMU debugging. Fixes: a6a0b05da9f3 ("kvm: x86/mmu: Support dirty logging for the TDP MMU") Cc: Ben Gardon Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- arch/x86/kvm/mmu/tdp_mmu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 41e975841ea6..fcbae282af6f 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1239,6 +1239,9 @@ static bool clear_dirty_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root, if (tdp_mmu_iter_cond_resched(kvm, &iter, false, true)) continue; + if (!is_shadow_present_pte(iter.old_spte)) + continue; + if (spte_ad_need_write_protect(iter.old_spte)) { if (is_writable_pte(iter.old_spte)) new_spte = iter.old_spte & ~PT_WRITABLE_MASK; -- 2.34.1.448.ga2b2bfdf31-goog