From mboxrd@z Thu Jan 1 00:00:00 1970 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 9D48EC433EF for ; Thu, 3 Mar 2022 18:03:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235606AbiCCSDs (ORCPT ); Thu, 3 Mar 2022 13:03:48 -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-Google-Smtp-Source: ABdhPJwyyVoqEon5C25c9UJr9TiVongdLYU8rJ02W4Fdis8eick2r/9zAfe+AM1teTuAyCKBFX08lA== 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> 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 >