Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5559337pxj; Wed, 23 Jun 2021 04:07:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8YL9rNBGDHITJYjtPrNkkYA2rC2SkeryIzDDSkI8Gh7u1s0uk10Y2kenPlGxM6q+xDaNK X-Received: by 2002:a17:906:f285:: with SMTP id gu5mr9434853ejb.226.1624446474977; Wed, 23 Jun 2021 04:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624446474; cv=none; d=google.com; s=arc-20160816; b=a3zB7Umd5OXyB3UR+mlqbuovOQvpVAI3kAwrg9hV0LWA1rNF0rKpVxQXpWtJdQ3tB1 hmyghchNoGMrX+FznUyp3zDGd0Roevoprv93G4P7UioU2h/jw5CZOESQWpQQwuOO++R5 CAX3U/GF2Xb+Omu6ZJsy/P3ds0ys6LsMZHcofU05MXVxEQMle7cqrOHNlu3lSiBuM0zH 3ImkhNSVU+EQ+Wyd5I9UeSK3R9q9XGqePk4+egVapXXSAOI1Oxi+ks4PXMGRA558Pgye RIHDKrcKiuWWzcY882I0YAekxCjsbhJIiD7LsR++Cs9Fl8eXm9ng3KG6YU/wkvBNDnfi GObQ== 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 :dkim-signature; bh=/ouZS1+E7hFHMuWHDBabrSj+fIlItQ8BKKdPQuyfZPs=; b=s4X8MOrZ5Szh7UVhcwpyBYznL6DfkT80jIw/oI3JqxwzwapqC9ieAy9Q5vT4vny8l/ INdCabijHTeSM/6goGP7+PykHjsmi79TAVG2IDsGnhCLHYJZ84RvsF8HIK54G9oE418f 9b7kocCKiro6g50XD1zvE/83stiLokXq+sHLgsuuHiiHTUTYlTw5QniiYpjmmYcYdORU VJOGfhxHaGEqHteosUII0Tq9qWbhhJXt0jPM4D8KREvHfIWAJQbxLFDLMVAAdAcjOohr uRxTX7DKQ5mwAl/k1tbPxPwJFzoYz3CWOzdjeN4/WVmmb5oaEmqzcQhm1M7RXHpOE2iA LuOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nFel0oGO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l4si4654982edr.272.2021.06.23.04.07.32; Wed, 23 Jun 2021 04:07:54 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nFel0oGO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbhFWLGg (ORCPT + 99 others); Wed, 23 Jun 2021 07:06:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:58764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230028AbhFWLGf (ORCPT ); Wed, 23 Jun 2021 07:06:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E85E61003; Wed, 23 Jun 2021 11:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624446258; bh=SQLZ3jEqT4yhyhpj0Bb9UFclPy9A7MyuqA/xQ21E19o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nFel0oGOMMRKsUQpOzA8E0CCodJoyPdxcszRZjPwq2EF6srqWdV01nWToiHko05qr z4OoIBK2qzIUUUqLi/+1Gvaeq1z/zXhEREhS7P6V+BZdsMAMzIgeofMC0LMKzq5y+n 1csrxIqsmn/WulaMO7Mbf9WQjRdjHAJawSFsK2Y0e6dY6WVzN2K/wPJVVzwSvUO86F mW72uxO54TkbohQpB88ly/TTkjX7bt7ioUcsI+SbQ3wM1fv11Tz40VtNvJ94aR1DB1 OC7Rqt8S2FO3m8tUJGaII25RYFNWSq8XxR5rNaJ/nNUETYfy/n4Fvz8eabCU7nHi8c SIOV/J/fx2MjQ== Date: Wed, 23 Jun 2021 12:04:12 +0100 From: Will Deacon To: Zhenyu Ye Cc: Catalin Marinas , 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: <20210623110412.GA32177@willie-the-truck> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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. The stage-2 page-table code looks ok afaict, but please can you check it too? Cheers, Will