Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp855282iog; Fri, 24 Jun 2022 16:13:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sS+9f4iihUUMo2l/C9PTqCJD2p/BS+9sbN+faITB2gaTCkNIFtEp8aLdiEpYcllSHfMn0S X-Received: by 2002:a05:6402:3227:b0:435:8e00:62b4 with SMTP id g39-20020a056402322700b004358e0062b4mr1735114eda.325.1656112431019; Fri, 24 Jun 2022 16:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656112431; cv=none; d=google.com; s=arc-20160816; b=rEkDGzIjbTph/gzc1b1WRzfbuFreDG00eHbT6hZ+4zVAQ4QNl8S2zgteag71F9U8BO 3lnB0K5oLt1Rx24xwzA7ZUwM1x0xAC4YCDYsGdLQHAr3QosQhl8GAH3nCTPILjBeTQ3j CoTTh8ZKgu/yDO+k6ZZ1KJC0/BvB3zFvlBOX210pMfdwvnoIjGmrFbcq7uuNP4y0TIKl NcpwDfAY8W/mYnHHhdnsRQujXbFCS4+qNSEWOYvoN62N4JQWnIemuf8l/5LzeELS4pTt 5CTf6ty73/s/t5OdKTKu4vqIQCGBgEEztZE7avEU2A+Oe0prPLETfNHpPdWFvuWurnXU Vcng== 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=tVvmPFlVYh1eywyk8X/ZOhSRyJAUFIuskvR1LEIJ1vQ=; b=qzDJwEHGpQVQbG06Q3bl8EFoZd5U1UjwAbP751dSVA7SCInD96lHg0ei3j+PRZCdYW WE5bFsK135dp8MMYFmVwIVCyWozXIjlM+anLTdDyrciqCTB5II9uBTTBcU43cEPnX9XD h4CawntV95ukbQWAdeTX92NC3ur2lVCUrgrRe2LTX/KLO4rQ0xx5DUbvSgk2uD1mrv/A honiQUY4eMXRwAr6UXMYibO+SC8EzFuUpNupfLAmgo8lDvj5JC63pSApmvJG+kh/IRW7 OGBAlr/Al+g50vZuVUS/ecKn4xwAkNB1ngyYbaWrgSFpkkV491s2TJtTb902d4kDoxBo GFmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=s8He2MsJ; 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 v7-20020a50c407000000b00435670c03cbsi2486770edf.187.2022.06.24.16.13.24; Fri, 24 Jun 2022 16:13:51 -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=s8He2MsJ; 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 S231328AbiFXWxd (ORCPT + 99 others); Fri, 24 Jun 2022 18:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbiFXWxb (ORCPT ); Fri, 24 Jun 2022 18:53:31 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 597B443EF7 for ; Fri, 24 Jun 2022 15:53:30 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id o18so3294250plg.2 for ; Fri, 24 Jun 2022 15:53:30 -0700 (PDT) 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=tVvmPFlVYh1eywyk8X/ZOhSRyJAUFIuskvR1LEIJ1vQ=; b=s8He2MsJOXCaycrGX1mG1fxPyK0GY+qid/53Ua4JIpGXeMfcDd0DpeNADBbGJb0dxX bZiMS/Li4XNAF466IkSip2+IKEZTgaafJ+UhHRLp9YCj3k4Z0YIhNKjTOvtbFoHbC67d 1KaAr6lnZjWTHOIswYWgxW4Ibmcarfa9HMDP8CMW76N6YEQ1Kd0EEaTAmM4o2iYvoWN6 YiE1gTDSV6xkD8QitprAPGpVCBl4M09SZw/7BBlD/Pvzih4JcxGNFxOH6/CCA8GJ/Dvt Xsi8/LCcIKXN6IXFT4qthznVMO5+ArrnlP8cojvRXovuos9l7X0++8XfeJXVZqr0+vG8 tLiw== 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=tVvmPFlVYh1eywyk8X/ZOhSRyJAUFIuskvR1LEIJ1vQ=; b=h3lJeZXUqz2ErIOxs5sxcaFUzNaP/Rk0DYfp7i3z8QXSy4KXJ+n6Ify/8wr6A1D2kj A7AawAFYPsDlSYKs/OkjMdz5MIv1HHwTkrXHgpj480Y9gb6P17wsnc7ocTdjcq9ZmL53 yIgqK77DUNJgoXNzPvo7qhSrBpw7E85jaL+ruJHmJtdrZMKUmLm4lkaTPk9Myt3jkhY8 CHyQv38XoKyD08TTEPowkg28g1ZtmNuCKStbjWCxCb7CHTEk5XS6Q+SWY/cWlPFM3Akg H8PDgknUdG8isefZ/QJ6DgFKZCyz9XjvPcPvz2Gvujxi072OzHgdux8AOTReZfk5aghF Bu4Q== X-Gm-Message-State: AJIora+4PrFAdZe4QSvp+T2C1tAxxQYjdTCSRrG3GCAg7qiGWx/vQCq/ BKKGfMII3HZ4WkOxQJtsgNVZLg== X-Received: by 2002:a17:902:6b8c:b0:168:fee5:884 with SMTP id p12-20020a1709026b8c00b00168fee50884mr1348279plk.105.1656111209721; Fri, 24 Jun 2022 15:53:29 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id bj23-20020a056a00319700b0052584b69a50sm218842pfb.66.2022.06.24.15.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jun 2022 15:53:29 -0700 (PDT) Date: Fri, 24 Jun 2022 22:53:25 +0000 From: Sean Christopherson To: Hou Wenlong Cc: kvm@vger.kernel.org, Paolo Bonzini , 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: Re: [PATCH 2/5] KVM: x86/mmu: Fix wrong gfn range of tlb flushing in kvm_set_pte_rmapp() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Fri, Jun 24, 2022, 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. 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(). It's also worth noting that kvm_set_pte_rmapp() is the other user of the rmap iterators that consumes @gfn, i.e. modifying iterator->gfn is safe-ish. > 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); Hrm, arguably this be done on start_gfn in slot_rmap_walk_init(). Having iter->gfn be less than iter->start_gfn will be odd. > 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 >