Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp781702rwb; Fri, 23 Sep 2022 04:12:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4XbCrf0cs/O1iGMFeZHPSKI7T+93aXJSVMpLIoPHeybgZXgQidf89uAq4h/WsfFq+cLua6 X-Received: by 2002:a17:907:7632:b0:76f:f6e7:36cf with SMTP id jy18-20020a170907763200b0076ff6e736cfmr6758668ejc.442.1663931578698; Fri, 23 Sep 2022 04:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663931578; cv=none; d=google.com; s=arc-20160816; b=EhrbdojxBllnhFh4M+sPG6Oy8GW6anrr4dRDcJm+9J3sfrPSSB7NwJoohYv9oKB4jm llLxgeDSsnalSfwg4ohxrJYLdme4ys7q8OLt09rHBcETWgM0Hd9ZrAlPw9gW47tAOCok P7iTXf50GSxV8k6oGQU9zXMIFZ8Eq2pu3x2vWgaK4855r0b/86vlnsDyV4RbGgxOuZaJ 7krcMwvfFTSYCFBDsVEE2wIA5/DsrQ6Yhj43Aal0UWxgbE/c2knk+4MTGBVUMuFezgcK NVmdAwV7XdnkG23vSxWJR7TUUyFe5uWKPQVnFqp9vecwTf3XtD2ZK/X6MbWXMyKo/Jk5 7qCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LXmRt6KivLwXygqIeIEif1J7BDUorTfV54FhLb40cik=; b=o0qYz/F+RhsJ3LEJX2RTXNRaCgWkXUp/ivoRuKzPTD+aj+Ei+E9kMauHcRPBfWtJTX s0zHupcTM8ydhgV5Qovk3pSnAA+Eq2EdVDjP5N/DrrYrANtlJFheblQBIHp6naCVkphp wn8NcB6FDCt/GPTEp9OsoXWdFOCCer6hFxRohZcz5nk2UzQeQe/a0L2q8vSkaBLnfzdV 8J02oK9bfSX8RH1OTJ1HUD4w0hTIDS7GrhzTScd9SoPg02ZuhOl+MkqWErZMhnbjrDwF NkHEOssNQbNXoU/rJR8Lxb2r/0b6U+4jmfewgGl0EAAOTvJS/DSHOfWaEx16dJQFBVDz iLeQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i23-20020aa7c717000000b00448a3d713ffsi5747387edq.292.2022.09.23.04.12.33; Fri, 23 Sep 2022 04:12:58 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232042AbiIWKw4 (ORCPT + 99 others); Fri, 23 Sep 2022 06:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231805AbiIWKwb (ORCPT ); Fri, 23 Sep 2022 06:52:31 -0400 Received: from out0-157.mail.aliyun.com (out0-157.mail.aliyun.com [140.205.0.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44258E6DD3; Fri, 23 Sep 2022 03:52:29 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R531e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047190;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---.PMZwGQI_1663930346; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.PMZwGQI_1663930346) by smtp.aliyun-inc.com; Fri, 23 Sep 2022 18:52:26 +0800 From: "Hou Wenlong" To: kvm@vger.kernel.org Cc: David Matlack , 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: [PATCH v3 3/6] KVM: x86/mmu: Fix wrong gfn range of tlb flushing in kvm_set_pte_rmapp() Date: Fri, 23 Sep 2022 18:52:19 +0800 Message-Id: <478926d56e8f574cb95686c19bf0910eaba19fd5.1663929851.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY 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 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 70c57ed166c7..ec5b3b9880de 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1437,7 +1437,9 @@ 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); + gfn_t base = gfn_round_for_level(gfn, level); + + kvm_flush_remote_tlbs_gfn(kvm, base, level); return false; } -- 2.31.1