Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5573748pxj; Wed, 23 Jun 2021 04:29:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyenweE4GdzaWxVyvVdv5UOAkhTRAKYA8F42ND6m4dcvTnXSRS7LQH+SR4wJ/itAsTd+ZpO X-Received: by 2002:a02:628b:: with SMTP id d133mr8526279jac.27.1624447747776; Wed, 23 Jun 2021 04:29:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624447747; cv=none; d=google.com; s=arc-20160816; b=Oz5m1YwVYThXNpXanLL+Z9tcZv2wBo7eQNR5mXn4R7t72rYAi/zUz6yP42S05hetlc zgqdybM4NHBSykDyPrHXiQexDurwRZILkqjNa00NUznuFfKG0QvogYGenPlUBYJt8Ubo BjTD/+Qo47Ql1B5SRZaQyzKZQ2ZrWnOHgiQLt6B67qlua4M3k7Ht8C3uqO7EYhfkTCJG wLLDvgOnlJbrb8zvRaZPe27rOEz6MfJp7VAbxQVmYXQYAmOtLYpfGCw8Jrpeje2WpNlm Ay9r3OM+JYX2V+/z2jvIDZ/teq9N99TsbYcE5q4DMD03sfW5/VaIQfSNEkprRqaPnlyu /BqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=SWvvfh382FhSLiWxV4FGC+mbrS37Fc8Q94jsnPO0/I8=; b=LsHR1AkfK6CiXH8j3OMKxFFuukGsM25i/6QZ3JKyYgsElWGQR9yrjOIzIRfTTPUlt+ R2cAKO9/17BlDSq/rqQ32EG0grzDZUd24OHw5QtS4CpnKt3W+KVJudCFnSo8QciqZ5MD 1n5qbUaFpt6g9B5/p4ErMP8HcTc/9+AewPnoESI7+Vw1+kmH3hVzYgrM2rtj/+QxTmIr r3I+d4yeL5yiGb3E6IxhA2a/gE/ABg032Dt+1cLU7Gf8pi3VhEtlmhq5BI6hts9bPJqg cv91iJTZblnc5AYaiRbbQmWwUd2dPJazmTIQFhdggV+V3/JwimM0AG2/SxnijsufyNRm Cmsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h9si16863117ilq.47.2021.06.23.04.28.55; Wed, 23 Jun 2021 04:29:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbhFWLan (ORCPT + 99 others); Wed, 23 Jun 2021 07:30:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:38552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230205AbhFWLan (ORCPT ); Wed, 23 Jun 2021 07:30:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DF9926102A; Wed, 23 Jun 2021 11:28:23 +0000 (UTC) Date: Wed, 23 Jun 2021 12:28:21 +0100 From: Catalin Marinas To: Will Deacon Cc: Zhenyu Ye , aneesh.kumar@linux.ibm.com, Marc Zyngier , steven.price@arm.com, Peter Zijlstra , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Xiexiangyou , liushixin2@huawei.com, huyaqin , zhurui3@huawei.com Subject: Re: [PATCH v1] arm64: tlb: fix the TTL value of tlb_get_level Message-ID: <20210623112819.GB3718@arm.com> References: <20210623110412.GA32177@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210623110412.GA32177@willie-the-truck> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 23, 2021 at 12:04:12PM +0100, Will Deacon wrote: > On Wed, Jun 23, 2021 at 03:05:22PM +0800, Zhenyu Ye wrote: > > The TTL field indicates the level of page table walk holding the *leaf* > > entry for the address being invalidated. But currently, the TTL field > > may be set to an incorrent value in the following stack: > > > > pte_free_tlb > > __pte_free_tlb > > tlb_remove_table > > tlb_table_invalidate > > tlb_flush_mmu_tlbonly > > tlb_flush > > > > In this case, we just want to flush a PTE page, but the tlb->cleared_pmds > > is set and we get tlb_level = 2 in the tlb_get_level() function. This may > > cause some unexpected problems. > > > > This patch set the TTL field to 0 if tlb->freed_tables is set. The > > tlb->freed_tables indicates page table pages are freed, not the leaf > > entry. > > > > Fixes: c4ab2cbc1d87 ("arm64: tlb: Set the TTL field in flush_tlb_range") > > Reported-by: ZhuRui > > Signed-off-by: Zhenyu Ye > > --- > > arch/arm64/include/asm/tlb.h | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h > > index 61c97d3b58c7..c995d1f4594f 100644 > > --- a/arch/arm64/include/asm/tlb.h > > +++ b/arch/arm64/include/asm/tlb.h > > @@ -28,6 +28,10 @@ static void tlb_flush(struct mmu_gather *tlb); > > */ > > static inline int tlb_get_level(struct mmu_gather *tlb) > > { > > + /* The TTL field is only valid for the leaf entry. */ > > + if (tlb->freed_tables) > > + return 0; > > + > > if (tlb->cleared_ptes && !(tlb->cleared_pmds || > > tlb->cleared_puds || > > tlb->cleared_p4ds)) > > Thanks. I can't see a better way around this, so I'll queue the patch. If you haven't queued it already, feel free to add: Acked-by: Catalin Marinas I'd also add: Cc: # 5.9.x -- Catalin