Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp722246pxm; Fri, 25 Feb 2022 18:19:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3FFTT/bHV3zxP3g5iudcAQEAbUHHyAz0ee/RkK5ItnnECz3FrBgttq9g2r4Qer9+V2A3r X-Received: by 2002:a63:ad49:0:b0:374:916e:46e1 with SMTP id y9-20020a63ad49000000b00374916e46e1mr8485392pgo.18.1645841970433; Fri, 25 Feb 2022 18:19:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645841970; cv=none; d=google.com; s=arc-20160816; b=LSrsvrax/CJWBQdcYkQ8Wer/L8RBGySyP+lqcnNtIPMnYh7y/sMSnYn0SaEqQwCkLj LvpbgHaR5D9PUgBJV/8jK8KRK7gWUlwTyPjsxUy1ve+g7HV0qRmwjjGnbBxzvIdK26et q7lnON+UvmgRydA0udbwkufHoU10KIGzYox/bIQudiS45VtVOMUgEPHc7UTfd/lB57lG 5Y/RKFU9JKVBKDrdR1B6TJLDUM/WoMUdNZEMx3Hici/aPyO+1IOzrH1m7fAeTzH3bNb3 c1uzrEWQ/d+4AMioS8oNHmIxTIs7CMbpZbBJKFONENQYifiUQIwxfzduvkazY7WTUy4V yXTg== 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:reply-to:dkim-signature; bh=EjwrK4ZJChvc6iOJgG1AWxHnLn4z532gyWXr0rVG/jQ=; b=Nap6O3eYpRTp07Niw5z9yUTHiGvn5XsPb3I4R3tqs43/U0J9isRocoeg60Whttf/BT 8sBZuKTGD3wmNkHjWpsGqOQq3moDZw2uKyEGbTfXH5JgjVhL/0eFUz/p/yxYcN+B2x6D tQy2X/FvA7n7EVwMbpCpL9wIATV9yryYXofARlbQllMX6EbGFFdfoGNlkXw+lZNQ4/Ny L3FYkB5PfMS+9ffMKiOzD2mNfC2Sf1WPq/3teEL9Iw8yH/gm3PIH8IeI3AyD/tBQgImf rdFhwj6BjL1UxbA9orwkGFNKckSvxqMC0LuBSoc3gQ5xzToP0ZRZfNa+untQ8Vmo/G6C A+Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lDvo9S5D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k1-20020a17090a590100b001b84ec5495fsi3320670pji.97.2022.02.25.18.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 18:19:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lDvo9S5D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F1AF12C94F1; Fri, 25 Feb 2022 17:51:55 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241062AbiBZASd (ORCPT + 99 others); Fri, 25 Feb 2022 19:18:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241354AbiBZARy (ORCPT ); Fri, 25 Feb 2022 19:17:54 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B594A22559E for ; Fri, 25 Feb 2022 16:16:50 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id bm16-20020a656e90000000b00372932b1d83so3474383pgb.10 for ; Fri, 25 Feb 2022 16:16: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=EjwrK4ZJChvc6iOJgG1AWxHnLn4z532gyWXr0rVG/jQ=; b=lDvo9S5DXUSc+JKq46AkxVaccqJHq5C6rWdkLNnSG8RB7M0LjPk1aSTbjzHeUBF2SK LdC8PARFCyh+yPqzV5tav9taOV6Oxa+HPg0xnKCj8GKro1Ihjk0vStC60ejtziH7Kp22 hHSwQoe7biVA931GQdyCO+VJFwkH8jxSdWXJcPS3F3/jgFHejbPhBKfjtliBSkBeeDe1 XTSXxP4elMA42o+QiK1nVBNWnT11jiKN3/lT6obqM9bkRm5JT9VYMLqruY0A9EvvX79K jiQkAs77DMMXN1I5PgcKZxVhI/ZWz5mf4sza4V1Bg3oo9vG+KmZ3q66uyPOB4qwbxkLG bxfw== 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=EjwrK4ZJChvc6iOJgG1AWxHnLn4z532gyWXr0rVG/jQ=; b=fathtZhHX+Mt1Ln0EMBagdDMVDymsXglmUPPv9oPs15obD/vq90yiXUCIfcQcEA1ec Z2yWQ5UT+GSvGj2WF4q2E96Iwi2MIsIw4HM6xifbEEHmIULndGljH+MGBgOBaFZXJLRr eyBe04Z18NwBeuPw6Cr6xL6tYJCqzsIbw8y3aa5h47NXOJ5lSEebHrNpKO31Pxgb54hT 1IxZCbAz7Tiny3Y63PeshjuaWRXb5omlcby8iUD6ZXhOHUY66nmFo2aLFMwbX+uSqVP7 oQa0L6cG/djDWOWBuWIA9DvNJgH4wMudq5DQY9dQBosTjKeZtrKUSaDIrBA7Q2VgBIJK Pr6Q== X-Gm-Message-State: AOAM533c8sH58gvQsJ+DoSlm0sfplHXNzpCXsW1vJbzG0yvJfzA9jeN5 9xwodpGmLt/rb1W0PY+yKS8Fh16hDr4= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:7f81:b0:1b9:4485:3f01 with SMTP id m1-20020a17090a7f8100b001b944853f01mr5573009pjl.120.1645834599991; Fri, 25 Feb 2022 16:16:39 -0800 (PST) Reply-To: Sean Christopherson Date: Sat, 26 Feb 2022 00:15:41 +0000 In-Reply-To: <20220226001546.360188-1-seanjc@google.com> Message-Id: <20220226001546.360188-24-seanjc@google.com> Mime-Version: 1.0 References: <20220226001546.360188-1-seanjc@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 23/28] KVM: x86/mmu: Check for a REMOVED leaf SPTE before making the SPTE From: Sean Christopherson To: Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , David Hildenbrand , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Ben Gardon , Mingwei Zhang Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Explicitly check for a REMOVED leaf SPTE prior to attempting to map the final SPTE when handling a TDP MMU fault. Functionally, this is a nop as tdp_mmu_set_spte_atomic() will eventually detect the frozen SPTE. Pre-checking for a REMOVED SPTE is a minor optmization, but the real goal is to allow tdp_mmu_set_spte_atomic() to have an invariant that the "old" SPTE is never a REMOVED SPTE. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 4151e61245a7..1acd12bf309f 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1250,7 +1250,11 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) } } - if (iter.level != fault->goal_level) { + /* + * Force the guest to retry the access if the upper level SPTEs aren't + * in place, or if the target leaf SPTE is frozen by another CPU. + */ + if (iter.level != fault->goal_level || is_removed_spte(iter.old_spte)) { rcu_read_unlock(); return RET_PF_RETRY; } -- 2.35.1.574.g5d30c73bfb-goog