Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5996730rwb; Wed, 7 Sep 2022 11:01:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR4xCPk3Cz54wdhmSXuNlLLryvBRwcZSrvzUx3PWDJDqwX0WGfXTubCkl5bVaQ6ZNb9OJAhy X-Received: by 2002:a17:902:aa42:b0:173:b84:ccf9 with SMTP id c2-20020a170902aa4200b001730b84ccf9mr5103940plr.83.1662573710992; Wed, 07 Sep 2022 11:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662573710; cv=none; d=google.com; s=arc-20160816; b=YArBUob/LEPx7kQ/clVHOwiLB7zst61z8nAOg6UNYQYdRsihUor85ucQrKpD0js+nA vRV8+yjbQ5dHQ2BrD5DgSXer1rLiii5iGqzzpxXlSdJaEJ0BKR5Aac5aqIszgpE3vXgl ZA+uJrxoYH4qQwN6oLaPD7FNNXXaWbziPRq8Q46V1hRKZ+56dyQeRUUdtjJTv9EeHlVP 3jC93ziRcfupV10vWaX42xjKefCPAxA4aov8R8ivmLVusvrNrfjvDcEQXdVM8dbjUfSr D5y34Ne7QaByAwR3yw1K556z8/Y0u/zPihOUmu/37+G2cOdwHzNzVysDyoGgoAZWT14g zZ+A== 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=t2UVCZIkN3IwB0SpdzJMa+gH2wnhttedu9ICdE2/3xw=; b=CzeJ0u2Z7Nv6CDMVJXfn29Wb0rz3bSUTHa57QRbw6rF5UX53+Q69wDrE82D9Qmlsom Djy9LHr6fQf4C1k2mwdjOJ+wIdFWvMrls8g6Pe0xP+2ReeZLFj3MX1YkD2xHyyZ4AhAe ao9JizEK5vSogB1BFQogXtTWVPzGNfY2GH9sJIfjJfSJiZn/NeBuN+UDjwZOh0S/uWNI 8TOGZNscdO/Z3RAYBgLRGQSUqsWP8pQxqqWI5QyVyST3ht3t5HTboJBZq/Hf8xn2BnEv uVXRWp6Y4885ehJ0YhA/dMN66QzBTS9hPQnf9TyfhbA+x+Zfr6qPYdhbCMZcsPw0qJIN sivw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MuuvkJV6; 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 k73-20020a633d4c000000b0043541f027aasi283580pga.157.2022.09.07.11.01.37; Wed, 07 Sep 2022 11:01:50 -0700 (PDT) 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=MuuvkJV6; 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 S229705AbiIGRvN (ORCPT + 99 others); Wed, 7 Sep 2022 13:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbiIGRvD (ORCPT ); Wed, 7 Sep 2022 13:51:03 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91946D561 for ; Wed, 7 Sep 2022 10:51:02 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id 73so14327318pga.1 for ; Wed, 07 Sep 2022 10:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=t2UVCZIkN3IwB0SpdzJMa+gH2wnhttedu9ICdE2/3xw=; b=MuuvkJV6NkTdL1mw5xuXvCfauzApb4WfEGbK5Z7oVaafwQ9jOSXF6E3GFCkj74JctM glDB56Cmk6wFnxwZCOBhLPDVzQBGbYt36bIE3lmVvBRdVri8zffZxDPflnAq/NeDgYgi P1ryPHN3fMojqSbtIb9PhOsDWo/wwfqIsL8DTkW1+vQ1kpUs8k/r9kmNKyrCjXecn4Px pjsKG9ykttwZwk94MmoFtdD+7hliw0ZzSr5gtuyx6n5l9/v8HERrQfZ6D3r5a0nisD6J vMdU49let3CQH1baMikzD8QBa+Gatl7+nMO67TbDDEKuJDNxJZT7aQTjK+yGUl7rDr3F dnUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=t2UVCZIkN3IwB0SpdzJMa+gH2wnhttedu9ICdE2/3xw=; b=vf6ODmUa9UBPEg/2wULn3roVxxPVwCPrErsBBjlp6x4IPc9rZ6lTOdsL0IeVS5ECCV iHLYWCMU1c24ox3XOnNvPxmNXaPQo1BIgsPZdi8h6J1T+FXUWqBDnMRJsQ0w+3OEf591 DIvGJE4mWjz3gpAeUgE93W+yqTRRi4nnaYO76JNbCho7RvcoSlpia7eWNBfU2zZIId4L M9nm61B7zD7XDggKYxKbe7b3+ca+5JW8troJ0LtcAvpwr3GtFwZpNiClR8YtEVuDZA8D yllPLPuLJynAQBlmFYvqJ2/IEYWcytXDvHYhpRbId7tNVOrh3h0t3nHOIALD0k0lZTEj MFPA== X-Gm-Message-State: ACgBeo3XfaKcaFIKF877G5K3P9UNJjVYlL6TR40+PrpC+w55JTCunR/j /5Cpcgm0eCE0UkfhG2Qp909rFw== X-Received: by 2002:a63:6909:0:b0:41c:9f4f:a63c with SMTP id e9-20020a636909000000b0041c9f4fa63cmr4561551pgc.76.1662573062060; Wed, 07 Sep 2022 10:51:02 -0700 (PDT) Received: from google.com (223.103.125.34.bc.googleusercontent.com. [34.125.103.223]) by smtp.gmail.com with ESMTPSA id g123-20020a625281000000b0053e483de200sm3677708pfb.73.2022.09.07.10.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 10:51:01 -0700 (PDT) Date: Wed, 7 Sep 2022 10:50:56 -0700 From: David Matlack To: Hou Wenlong Cc: kvm@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Lan Tianyu , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/6] KVM: x86/mmu: Fix wrong gfn range of tlb flushing in kvm_set_pte_rmapp() Message-ID: References: <4b6f39b9617ee9be9fcddeaa0afd754f21cf2e24.1661331396.git.houwenlong.hwl@antgroup.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4b6f39b9617ee9be9fcddeaa0afd754f21cf2e24.1661331396.git.houwenlong.hwl@antgroup.com> X-Spam-Status: No, score=-17.6 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 Wed, Aug 24, 2022 at 05:29:19PM +0800, Hou Wenlong wrote: > When the spte of hupe page is dropped in kvm_set_pte_rmapp(), > the whole gfn range covered by the spte should be flushed. > However, rmap_walk_init_level() doesn't align down the gfn > for new level like tdp iterator does, then the gfn used in > kvm_set_pte_rmapp() is not the base gfn of huge page. And > the size of gfn range is wrong too for huge page. Use the > base gfn of huge page and the size of huge page for > flushing tlbs for huge page. > > Fixes: c3134ce240eed ("KVM: Replace old tlb flush function with new one to flush a specified range.") > Signed-off-by: Hou Wenlong > --- > arch/x86/kvm/mmu/mmu.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index a3578abd8bbc..3bcff56df109 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -1438,7 +1438,8 @@ static bool kvm_set_pte_rmap(struct kvm *kvm, struct kvm_rmap_head *rmap_head, > } > > if (need_flush && kvm_available_flush_tlb_with_range()) { > - kvm_flush_remote_tlbs_with_address(kvm, gfn, 1); > + kvm_flush_remote_tlbs_with_address(kvm, gfn & -KVM_PAGES_PER_HPAGE(level), Rounding down the GFN to a huge page size is a common pattern throughout KVM. Can you introduce a common way of doing this and clean up the other call sites? > + KVM_PAGES_PER_HPAGE(level)); This eventually gets converted to kvm_flush_remote_tlbs_gfn() in a later patch; which is even more reason to introduce kvm_flush_remote_tlbs_gfn() in the previous patch. > return false; > } > > -- > 2.31.1 >