Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3296401pxm; Mon, 28 Feb 2022 16:46:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgDaOvPieIbjF+H9RFv+UpWakH0k+OLTBbgiph7U7jVYwKD2IBV7opmbslzO7PhzuyyZz9 X-Received: by 2002:a17:902:f707:b0:14a:fd51:3b5f with SMTP id h7-20020a170902f70700b0014afd513b5fmr23595481plo.98.1646095598613; Mon, 28 Feb 2022 16:46:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646095598; cv=none; d=google.com; s=arc-20160816; b=YRAy3IujezNo7HYiefVcxwQ9JMNgPxXy6hR4yeORLU0CYgRmy49XygeLFTWF4kWvnr j2nD1DEGKEi1Ktg1vjtkbal/jBE4Vxfsmu1/SUcfnfAIORm4JEvozvtiESIyR9H0EcKt uOziOYvQS2DFlDOg9FJqnVtozIgZJobc4YnZwQexx3DA9uwjaDqqU32mCGm1Xi75DovA PXofnQCEf4a1Ly2TxqkQbmqItjWM3328k6JrEBwHp4HHIIhj2esIGZyVYRWAMT4Bt1hW eMCDwAEd933zvBcR0IoEOa9uxUCr/LsA2EsJbThbsUHh4G2A+cNV3m2MC7haabgRlPEk o4Ow== 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=7Jq5c+6vhvuF7Ybk2lRX6RTPY/8mW01cAvWtc5ooEkc=; b=O1rhTTnRkDXiYyw0U352KbXjm7BnEKkf8RjEvtDprGEaKPJgKYVVWx40WJg40y6OGe SkwIqIXAZ/NZvu648fhgi4DYRXLSIe3B/TmCUIutx9wCwreB5re5HzUMH43QE2fGpYUv jHYHGfNaMVsFp6bCbiNya/Klvtb7IYcPfpsWMbjKmNNPzt71dNPpMyp5EBIJJUx2uurr zDar6DaMqKOLp9qkK1BNVIxOo+yKA9gXySKxu0x6fRUELaaFyPtYEZBSoswvbZljgetX 1nQLdzYwCHNrQ8D/CSRKQTx4wduDqZeOrVHRwK46sc1573aWsAWG254bj5EKRGbkF0s3 z0qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qVLdh0ag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a170902dad000b0015011e142f5si13137258plx.55.2022.02.28.16.46.22; Mon, 28 Feb 2022 16:46:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qVLdh0ag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231292AbiCAAMx (ORCPT + 99 others); Mon, 28 Feb 2022 19:12:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbiCAAMw (ORCPT ); Mon, 28 Feb 2022 19:12:52 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E8D8D4C98 for ; Mon, 28 Feb 2022 16:12:12 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id i11so19830348eda.9 for ; Mon, 28 Feb 2022 16:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7Jq5c+6vhvuF7Ybk2lRX6RTPY/8mW01cAvWtc5ooEkc=; b=qVLdh0ag0EcbKeamPlw5IhI6fH/Fdz2yENO78FGpjCRZFakmIC4oBvnX0wwDF45o+P aSjhAttFyjLqWMxdbNe6wWCiauI9b2PSCgqzXyczs+t3TdTaWoZccUA4uBj0ODw1Al0a q58QYElr/+kt//TTsmFbwKtF3IiHzE5i7GTQ398Fb4M1NIwqhrSQrErgy7TACNDCguPn wyeXcF9VbYuTuJ6A/OXXhn9eYVHJdaJZ7NJiWRMy/jUtFf858qKKVzCKPzuOVtwfM6TQ kcpbaW1TdnsLucM6eUa5v6THR++M6r98Qt47iga1pN1HrxNEG+lvjszYOV9XYDAwhNmI w7YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7Jq5c+6vhvuF7Ybk2lRX6RTPY/8mW01cAvWtc5ooEkc=; b=GwpW8KgxMkR8JQumAeogUtvFvzAklBo8FcIaTMzo7A6wYYBClv/7kCH0zAd9GxJlm0 dcKH8RwB1SN9Uul25NLScKYQoq/vsxo4dQ1uGSAhfg1L/ogKN1QGgjhX6EMG10gN2Zc2 f06IgAZ1poGyXxqYzUurhiLjSysrDcYaMzk2SWv3yLJMGgVfy/H+8YxKFLzkAedA8OeZ 4WK85ET3VG5ufNrex4b9knsvZIXCJp5TqS4S5jTrEnCD54sNozNssNjrfVVIXNXzRIJ7 DNc3fv8iTMPzW3bRGOfoiGjwNl8MgM+nErVw2AdA6BIwFKgGC18x8nGl0I+Zr5YicLWD jFQQ== X-Gm-Message-State: AOAM533877PisIJ0nkpi+h2aR41M1xyy/9m6ZvpulaIjNGb2hT2p+IBY ymF2nGY5+fQfi2lqSpKqiM7oPkIcPTYrnyc7/6IsXw== X-Received: by 2002:aa7:c612:0:b0:40f:2a41:bddb with SMTP id h18-20020aa7c612000000b0040f2a41bddbmr21772637edq.291.1646093530737; Mon, 28 Feb 2022 16:12:10 -0800 (PST) MIME-Version: 1.0 References: <20220226001546.360188-1-seanjc@google.com> <20220226001546.360188-8-seanjc@google.com> In-Reply-To: <20220226001546.360188-8-seanjc@google.com> From: Ben Gardon Date: Mon, 28 Feb 2022 16:11:59 -0800 Message-ID: Subject: Re: [PATCH v3 07/28] KVM: x86/mmu: Check for !leaf=>leaf, not PFN change, in TDP MMU SP removal To: Sean Christopherson Cc: Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , David Hildenbrand , kvm , LKML , David Matlack , Mingwei Zhang Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-18.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 On Fri, Feb 25, 2022 at 4:16 PM Sean Christopherson wrote: > > Look for a !leaf=>leaf conversion instead of a PFN change when checking > if a SPTE change removed a TDP MMU shadow page. Convert the PFN check > into a WARN, as KVM should never change the PFN of a shadow page (except > when its being zapped or replaced). > > From a purely theoretical perspective, it's not illegal to replace a SP > with a hugepage pointing at the same PFN. In practice, it's impossible > as that would require mapping guest memory overtop a kernel-allocated SP. > Either way, the check is odd. > > Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon > --- > arch/x86/kvm/mmu/tdp_mmu.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 189f21e71c36..848448b65703 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -505,9 +505,12 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, > > /* > * Recursively handle child PTs if the change removed a subtree from > - * the paging structure. > + * the paging structure. Note the WARN on the PFN changing without the > + * SPTE being converted to a hugepage (leaf) or being zapped. Shadow > + * pages are kernel allocations and should never be migrated. > */ > - if (was_present && !was_leaf && (pfn_changed || !is_present)) > + if (was_present && !was_leaf && > + (is_leaf || !is_present || WARN_ON_ONCE(pfn_changed))) > handle_removed_pt(kvm, spte_to_child_pt(old_spte, level), shared); > } > > -- > 2.35.1.574.g5d30c73bfb-goog >