Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1168518pxm; Thu, 3 Mar 2022 11:40:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxO4JPFEx/BP8JRhi0nVaOAxHQaMI/WdjzQKqoOvVMM1ZeNewWWNkrK0lLsFKl6Rezb7Int X-Received: by 2002:a17:907:6e23:b0:6d7:713a:9747 with SMTP id sd35-20020a1709076e2300b006d7713a9747mr9233331ejc.411.1646336435297; Thu, 03 Mar 2022 11:40:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646336435; cv=none; d=google.com; s=arc-20160816; b=e1i3Jz0qZ931G1BJQeSgAxU0RxXW7U7HnAhNzh33LDkyw3HfwMbMlUVgTtRfhKQxfh 769mGNXZhHH7GczR+voaK9c3JnSMFk8eIfkNKpPK6NUvywmvQqsOqBP62w71oLqHIXXo 52fbTQbYn6TUlvckr8KS1anygOGeMdZfxFA3mTgjkwtbRFlCm8I7m6aL0zIn1PX+WPdn BNU+HHtSen2L6KfmBnHiHQWeEd6qsWone0A0YVv0nq4B+PbElgQMVF0MinIEdQjJVQ0x wQbjl6yOtd028BUdpDsW/XSSrusczyJ6wiZQSCWffzLSxSSedO2A2VOVPPYGdRp72788 gk/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wXD0lhGUV6Vx3hh95xkovDLgtCU6APmz+b2GdNRK/RE=; b=zDPfpe9dLbR93NeQCL8KPtYXbMdP7r06/zU5IcFd+eT/TGYtnl7aad/sop3WlO3Hpm ecvBdcX7WaYJuMHfyJzILpT4RsynJ8xHal5blhznRzIMyGkUUqMDiHd15jcVwzwa1CiX r1Om1PggpklVJoWvxC+d0kAj/Xes96AsZawvHtafKLILFKUPsP0dwIWeEDnKh9PAGBYi lZdyOZvdXyg83t3k170WJ8pjq+1tN7KJTctm/3H/okDGG/UEKX8AwdUC9BRxFnByezsa RZOpRJhIglT/y8QcMLv4BdHJkiJdzzgbgUOeGLnkdPt1EIAQ4wFVK0O0WHmFiCTzE6AF fJMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FJGxFbCw; 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 h17-20020a05640250d100b00415ed5193d3si965086edb.498.2022.03.03.11.40.12; Thu, 03 Mar 2022 11:40:35 -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=FJGxFbCw; 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 S235607AbiCCSDr (ORCPT + 99 others); Thu, 3 Mar 2022 13:03:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235595AbiCCSDq (ORCPT ); Thu, 3 Mar 2022 13:03:46 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5373155C00 for ; Thu, 3 Mar 2022 10:03:00 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id t5so5357754pfg.4 for ; Thu, 03 Mar 2022 10:03:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wXD0lhGUV6Vx3hh95xkovDLgtCU6APmz+b2GdNRK/RE=; b=FJGxFbCw7rR/LPeZm/NArRHGbcHesjph3Kn69m3nm4Ldw+bkSYNkB9UDLmP2cLig+3 0Cas7VySBXv/Qia8DpH6SN4hcCxp1d9oUaSqjwH7Bcpw/9WfqrQTMpJIlS8ay8nejHQI aNvsrbWJzHi5lYbNkVPet7DtSxiWXOKRNNnEyEWmVz7H1eqXV5CR4TvD4rD6yg3V+2Q1 vaMxCup0T74m95+9RcrL3WxXlgtPKg/k+OqiNJ28BmNC7/3udEXINC60cK6h87hY6wdO HmhLodYFKRjUokEQOLdujdsdQOBI7sVAEM26SmVbRejKhcUrDeBdpbZyRXJrel+Q+Iqm Gm9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wXD0lhGUV6Vx3hh95xkovDLgtCU6APmz+b2GdNRK/RE=; b=KuNPig0KZ7YGMiXmhsPEN+MZaNdrK3a2h6BJXT969npG2mQga8Z3MfeYfvvEBg0yv7 I7tYH6YVL7ovIcYIRe65B3nKBAbQqpNbMLcp0MxgUJvdyF8fT5CGEtCMr+soMfXhK32n ZF6fbGLiBK2LKaL90SxUEwuAvWO8p/mgz2oKIynSrhypwCMsZPHf5pXre71uCmLa91fF 4CqyijX2ocNUfO6nFIooehvpEfClFVc4dV0WHMcuUZY6kXDwAf8HYXAHoAZoH39Du0yo QRn0+AcEl7C7cSSVJwZpHbJMn58UqJfIazGt+Lq94cqWsNjVplcGWXl7wSEzmALT8sRH fYgg== X-Gm-Message-State: AOAM532yNClDi/NyUIs3X0eLKN6NftrAmLb8sHV6jes+sspwAX09LnCx B9EO8bRDzs1BjpmTSbdD5wwkbA== X-Received: by 2002:a63:5124:0:b0:375:9f87:f881 with SMTP id f36-20020a635124000000b003759f87f881mr28381432pgb.578.1646330579563; Thu, 03 Mar 2022 10:02:59 -0800 (PST) Received: from google.com (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with ESMTPSA id h22-20020a056a001a5600b004f41a2a6cf9sm3060866pfv.134.2022.03.03.10.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 10:02:59 -0800 (PST) Date: Thu, 3 Mar 2022 18:02:55 +0000 From: Mingwei Zhang To: Sean Christopherson Cc: Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , David Hildenbrand , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Ben Gardon Subject: Re: [PATCH v3 07/28] KVM: x86/mmu: Check for !leaf=>leaf, not PFN change, in TDP MMU SP removal Message-ID: References: <20220226001546.360188-1-seanjc@google.com> <20220226001546.360188-8-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220226001546.360188-8-seanjc@google.com> 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 Sat, Feb 26, 2022, 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: Mingwei Zhang > --- > 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 >