Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7634464rdb; Thu, 4 Jan 2024 02:56:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+aWRmAvPpfVeP1th05+j9dvmCmDPIwJ8bdYg+PulSROChec/2crsy7rzlnQvU4z814aHF X-Received: by 2002:a50:d659:0:b0:556:d08d:aef8 with SMTP id c25-20020a50d659000000b00556d08daef8mr377945edj.12.1704365762176; Thu, 04 Jan 2024 02:56:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704365762; cv=none; d=google.com; s=arc-20160816; b=ZZi3Z1kjZ6uqLuOJUn958s2oQ/CizUobPoUx+3JAmolbJDknYUUPRye3xizFWd9+8A fKTm2TR3Cte/O60TLnr6Sp0ayExV1cRBAKNyv03WCYr0QkbsX1h2VweE3y19FXQAdayG LHZxxH3AihW+oRczceby6WiUFEijlQq1Hw4X/8EeLB8RsAh36Z+MdDCb29aQ/VDX71RD CuKLXVFXUqUbTHPpRI9pnjoVUDSc7xbw+NelhmiZVYdt9x1CVjzUqO6INYmZJmVHtvO9 1XPCLXYN+y58LRURPpaYCwNugfzYgfP3unfDJenRSY3c3KjLJxko0CPdJTll6wzllebu TxGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=diabq4qd4Kt1vJAgcVi3NYsIIq3v5mEq/My81edjZAk=; fh=9bU2fKyHjkjFJAnePEHuf/oKADDYZgMMGP3lut0sQoQ=; b=ZcdVr35UZ8gWxDODrLGHexkgY8iUdqdCoRDbhqDDjZbg5HOC+zuElcXHFax44bMc5Z wHwmFbDyjGtIhji5wNYuAG6NY6+lIJ5Z97Wut2pgAorLstq6w0r8trRKx0wlRKDPOKzB P/TTH8GRAgk2YTi6Af6IgMZ9rWQKjsUdZS2ky3BMElG19bLT7H8+4pBdy2YbfZUJFkOZ w7Bi41O+Fpk6qGrG/dAder6ChnSxthE3vkF76UXz+t2zcogNW7BMDxlgYbh7WRdutPYZ sFVhgcarDQuGw8pl8LIYIwlKv/RkDjcDwZnPHayBw5cDjj4H/GT5VPOdOit0N3gH2K5v +cOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16544-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16544-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r14-20020a056402234e00b00552fd4f41b3si13470538eda.44.2024.01.04.02.56.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 02:56:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16544-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16544-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16544-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AEFD31F23B6A for ; Thu, 4 Jan 2024 10:56:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D702F20DFF; Thu, 4 Jan 2024 10:55:53 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C800020DE5; Thu, 4 Jan 2024 10:55:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id 6766EE0005; Thu, 4 Jan 2024 10:55:40 +0000 (UTC) Message-ID: <36166acf-aa32-40b6-806a-ade59bc645ad@ghiti.fr> Date: Thu, 4 Jan 2024 11:55:40 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/4] riscv: tlb: fix __p*d_free_tlb() Content-Language: en-US To: Jisheng Zhang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Will Deacon , "Aneesh Kumar K . V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Conor Dooley Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org References: <20231219175046.2496-1-jszhang@kernel.org> <20231219175046.2496-2-jszhang@kernel.org> From: Alexandre Ghiti In-Reply-To: <20231219175046.2496-2-jszhang@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-Sasl: alex@ghiti.fr On 19/12/2023 18:50, Jisheng Zhang wrote: > If non-leaf PTEs I.E pmd, pud or p4d is modified, a sfence.vma is > a must for safe, imagine if an implementation caches the non-leaf > translation in TLB, although I didn't meet this HW so far, but it's > possible in theory. And since this is a fix, it would be worth trying to add a Fixes tag here. Not easy I agree because it fixes several commits (I have 07037db5d479f,  e8a62cc26ddf5, d10efa21a9374 and c5e9b2c2ae822 if you implement tlb_flush() as I suggested). So I would add the latest commit as the Fixes commit (which would be c5e9b2c2ae822), and then I'd send a patch to stable for each commit with the right Fixes tag...@Conor: let me know if you have a simpler idea or if this is wrong. Thanks, Alex > Signed-off-by: Jisheng Zhang > --- > arch/riscv/include/asm/pgalloc.h | 20 +++++++++++++++++--- > 1 file changed, 17 insertions(+), 3 deletions(-) > > diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h > index d169a4f41a2e..a12fb83fa1f5 100644 > --- a/arch/riscv/include/asm/pgalloc.h > +++ b/arch/riscv/include/asm/pgalloc.h > @@ -95,7 +95,13 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud) > __pud_free(mm, pud); > } > > -#define __pud_free_tlb(tlb, pud, addr) pud_free((tlb)->mm, pud) > +#define __pud_free_tlb(tlb, pud, addr) \ > +do { \ > + if (pgtable_l4_enabled) { \ > + pagetable_pud_dtor(virt_to_ptdesc(pud)); \ > + tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pud)); \ > + } \ > +} while (0) > > #define p4d_alloc_one p4d_alloc_one > static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) > @@ -124,7 +130,11 @@ static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d) > __p4d_free(mm, p4d); > } > > -#define __p4d_free_tlb(tlb, p4d, addr) p4d_free((tlb)->mm, p4d) > +#define __p4d_free_tlb(tlb, p4d, addr) \ > +do { \ > + if (pgtable_l5_enabled) \ > + tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(p4d)); \ > +} while (0) > #endif /* __PAGETABLE_PMD_FOLDED */ > > static inline void sync_kernel_mappings(pgd_t *pgd) > @@ -149,7 +159,11 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm) > > #ifndef __PAGETABLE_PMD_FOLDED > > -#define __pmd_free_tlb(tlb, pmd, addr) pmd_free((tlb)->mm, pmd) > +#define __pmd_free_tlb(tlb, pmd, addr) \ > +do { \ > + pagetable_pmd_dtor(virt_to_ptdesc(pmd)); \ > + tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pmd)); \ > +} while (0) > > #endif /* __PAGETABLE_PMD_FOLDED */ >