Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp408245rwe; Wed, 24 Aug 2022 03:10:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR7nUSVpRFx1X2bUSEYKXGMPAoPJqY8oKs1rvnDcb1pfiG/OmhvRxexrNlORnkRqiLYsHgJy X-Received: by 2002:a50:9f4f:0:b0:447:8aff:d312 with SMTP id b73-20020a509f4f000000b004478affd312mr1109844edf.110.1661335831566; Wed, 24 Aug 2022 03:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661335831; cv=none; d=google.com; s=arc-20160816; b=dComaEKcGetDqXZZFyZ2gndF7yh6wcdyr972kGfwS7x+WSgIZMnswiuOplJTBKKoLq d+QLY/oe2D3cYHaAdoLvG6yuoQueCsifSzkrCffrLu4hztQtlufzOGUIFdPYcc7n6EA3 kwBFlbIulv+2J0DXr63I7R6W25pmsZWV5TE8Llsy1ewApntDDtgDf61SnnS0gqP8J8Q/ dGc4nDci5VneztNuX7JWg6zV1H7jaqPOlxsluURc1+FIP+1y1mO7G4DimXydIoKzHNhX /Hll14ZnseesWxoOWULrGMn7qwXVhnpiPRZ83SJj9C7TbFc+dimEjTl9HojjM1tmtokO kFPw== 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=sXm22BqvhJDlOuWcdmoC2qbHYhhIb2lKzvuW6VPYbQQ=; b=kJyrvyujJPYK1GSKYBjUo3Tky+KHG0wVk1B8SOouJfDINxzA6cIcskG18oa3hLhpAr DmdTAmmyI2E9ep2oDvIYPtHJNA0se3SfL4D3CZaxko69LD0NafI0jL7UxnOCyOt4nXrJ IE8T5xesle6ZaMCMBEEOM/9oeLI8k307pzOqG6nuy5ts2kjf3o7hRxAUxOpxdp0RXuAN M7OyOJQhpbnM3L+UZU+d/MReXCd2gacE42Am9l3QY7BF9JCQJl65d1pacCgkP0QQNDup 7m7any70+/hFj5i7u9Ll2PjYE+Y3RKNLuC5sPknDu0vUAVsKkz9gQbovdxw9u1eLymeR S6UQ== 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 s3-20020a056402520300b0044202417985si3209582edd.108.2022.08.24.03.10.03; Wed, 24 Aug 2022 03:10:31 -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 S235466AbiHXJ3t (ORCPT + 99 others); Wed, 24 Aug 2022 05:29:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235982AbiHXJ3a (ORCPT ); Wed, 24 Aug 2022 05:29:30 -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 1884D84EC1; Wed, 24 Aug 2022 02:29:28 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047198;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---.P-jvWt-_1661333365; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.P-jvWt-_1661333365) by smtp.aliyun-inc.com; Wed, 24 Aug 2022 17:29:25 +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 v2 2/6] KVM: x86/mmu: Fix wrong gfn range of tlb flushing in kvm_set_pte_rmapp() Date: Wed, 24 Aug 2022 17:29:19 +0800 Message-Id: <4b6f39b9617ee9be9fcddeaa0afd754f21cf2e24.1661331396.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,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. 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), + KVM_PAGES_PER_HPAGE(level)); return false; } -- 2.31.1