Received: by 2002:a05:6512:e85:0:0:0:0 with SMTP id bi5csp129014lfb; Thu, 23 Jun 2022 20:40:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKcw5nW06Oq07KLUpsIOqM7BCV4gQbz93m+eQqZXzG5uFW8S+zNIcYVK+eBv0YryzRkT2F X-Received: by 2002:a05:6402:40f:b0:436:a6ba:360d with SMTP id q15-20020a056402040f00b00436a6ba360dmr1744305edv.371.1656042013978; Thu, 23 Jun 2022 20:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656042013; cv=none; d=google.com; s=arc-20160816; b=MGgiDLQ6oPc59Np5BnKB41iyYaf9c/QixfjiYbT9WB1a7QI/GjEyqw1fud3bleP35m BekUtoFrdt70gWT3/hs+5I4eg3LwxZcFznMKsGXKAylk6XOtsDx1tfHgHjNVWjd/PECY fadLqS8KiDCOjRPdXs5iWmg5mp9YA/l6OyYROCdWCbWuOsWxIbHir0ziquDntyxHFNuI iC2Ov9QCTQw8hFQrWtkcRdCyimJXYFRAIilm0/DDVbDl7/1Hy+VWXzK+hJpT6eHnaauc u35JeFTgYiDIy4i4rosZGiEXbjcWEduTybYgJY8sdjTI16ifNv78FQiEooKd4SAuKXy9 c+JA== 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=phNRyOMzL40wGuvdCxx3O05ov/6iRdCweUdQS4hzOSY=; b=k7fjkz1xvT4FQ4CYXl3C8X7peX/b31IDf+p0XwZB3foXBQ63KR1EwHQ8lXBsm37egf 9ld/vRpc6acxDcMlICH68dfoiMXDDpNBLo/3Lrf6J+IckFr65UbEo/etwXvdZJhZovWO R3aCvghBFSR7LtrodyJg2ii/tskW/PPjsIzGLboweIIMfb2RQHhsH1iLQXJwhC2HzNwU gaP2XREQGJET4WLQxcrP9NgUt7KitJOLuGSuFVpC2vQpUlL6sBxjlnyDwdhp4BSx2uDv gyBCbGhKIahOE5wucG7LPlgQ9i/zCzASKJWWZNSALvghb7lyGY39ru4GcvU5J/6Atuj4 fGLw== 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 a100-20020a509eed000000b0042df64a5b1csi1673336edf.332.2022.06.23.20.39.41; Thu, 23 Jun 2022 20:40:13 -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 S230224AbiFXDhO (ORCPT + 99 others); Thu, 23 Jun 2022 23:37:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbiFXDhM (ORCPT ); Thu, 23 Jun 2022 23:37:12 -0400 Received: from out0-139.mail.aliyun.com (out0-139.mail.aliyun.com [140.205.0.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3BD153A71; Thu, 23 Jun 2022 20:37:08 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047194;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---.OBfZx2H_1656041824; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.OBfZx2H_1656041824) by smtp.aliyun-inc.com; Fri, 24 Jun 2022 11:37:04 +0800 From: "Hou Wenlong" To: kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Lan Tianyu , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] KVM: x86/mmu: Fix wrong gfn range of tlb flushing in kvm_set_pte_rmapp() Date: Fri, 24 Jun 2022 11:36:58 +0800 Message-Id: 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,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,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. Since the base gfn of huge page is more meaningful during the rmap walking, so align down the gfn for new level and use the correct size of huge page for tlb flushing in kvm_set_pte_rmapp(). 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, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index b8a1f5b46b9d..37bfc88ea212 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1427,7 +1427,7 @@ static bool kvm_set_pte_rmapp(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)); return false; } @@ -1455,7 +1455,7 @@ static void rmap_walk_init_level(struct slot_rmap_walk_iterator *iterator, int level) { iterator->level = level; - iterator->gfn = iterator->start_gfn; + iterator->gfn = iterator->start_gfn & -KVM_PAGES_PER_HPAGE(level); iterator->rmap = gfn_to_rmap(iterator->gfn, level, iterator->slot); iterator->end_rmap = gfn_to_rmap(iterator->end_gfn, level, iterator->slot); } -- 2.31.1