From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17779C30658 for ; Tue, 2 Jul 2024 12:35:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9hoVH0GyGia0LlAGw7P5aswQr5Cr9o3mvlInZZEILV8=; b=TA3euEN5i/85yxX83kB5i1UQj/ CYpBPa04HPRWZnCjQy7bwf92VYYUydUdzQfuyCzAl84lvMEUywUtdSfisFB93dk1W8u7IJmGhbO1L DpSaZLuF07IUtC4AR/cKK/AdKQhEIL2Td9EBpYipPzkIGnUUdPGdDaF4OXla0iSP9N4riaeioCg8C rz8oe1uuAwKTMUKMaV7YU1WAPPlTtziX5vNRYkeAjXrKUrAUKWFwF11Y7HqRm0bsq9iKW0wKd5ARg q3uXuAdWfTJaXOfUtZXiRWu/CLvDrfQv++H0VRFI1a9EFqfy0L2knHiJKTPXY/AzX+uDTULTx0Sz7 JWCGK+4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOcih-00000006hst-2Eo7; Tue, 02 Jul 2024 12:34:51 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOciU-00000006hnG-0Uoj for linux-arm-kernel@lists.infradead.org; Tue, 02 Jul 2024 12:34:40 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 420B3CE1D43; Tue, 2 Jul 2024 12:34:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 218CCC116B1; Tue, 2 Jul 2024 12:34:33 +0000 (UTC) Date: Tue, 2 Jul 2024 13:34:31 +0100 From: Catalin Marinas To: Yang Shi Cc: muchun.song@linux.dev, will@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] hugetlbfs: add MTE support Message-ID: References: <20240625233717.2769975-1-yang@os.amperecomputing.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240625233717.2769975-1-yang@os.amperecomputing.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240702_053438_364343_29D249C7 X-CRM114-Status: GOOD ( 28.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jun 25, 2024 at 04:37:17PM -0700, Yang Shi wrote: > MTE can be supported on ram based filesystem. It is supported on tmpfs. > There is use case to use MTE on hugetlbfs as well, adding MTE support. > > Signed-off-by: Yang Shi > --- > fs/hugetlbfs/inode.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index ecad73a4f713..c34faef62daf 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -110,7 +110,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) > * way when do_mmap unwinds (may be important on powerpc > * and ia64). > */ > - vm_flags_set(vma, VM_HUGETLB | VM_DONTEXPAND); > + vm_flags_set(vma, VM_HUGETLB | VM_DONTEXPAND | VM_MTE_ALLOWED); > vma->vm_ops = &hugetlb_vm_ops; Last time I checked, about a year ago, this was not sufficient. One issue is that there's no arch_clear_hugetlb_flags() implemented by your patch, leaving PG_arch_{2,3} set on a page. The other issue was that I initially tried to do this only on the head page but this did not go well with the folio_copy() -> copy_highpage() which expects the PG_arch_* flags on each individual page. The alternative was for arch_clear_hugetlb_flags() to iterate over all the pages in a folio. I'd also like to see some tests added to tools/testing/selftest/arm64/mte to exercise MAP_HUGETLB with PROT_MTE: write/read tags, a series of mman+munmap (mostly to check if old page flags are still around), force some copy on write. I don't think we should merge the patch without proper tests. An untested hunk on top of your changes: diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h index 3954cbd2ff56..5357b00b9087 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -20,7 +20,19 @@ extern bool arch_hugetlb_migration_supported(struct hstate *h); static inline void arch_clear_hugetlb_flags(struct folio *folio) { - clear_bit(PG_dcache_clean, &folio->flags); + unsigned long i, nr_pages = folio_nr_pages(folio); + const unsigned long clear_flags = BIT(PG_dcache_clean) | + BIT(PG_arch_2) | BIT(PG_arch_3); + + if (!system_supports_mte()) { + clear_bit(PG_dcache_clean, &folio->flags); + return; + } + + for (i = 0; i < nr_pages; i++) { + struct page *page = folio_page(folio, i); + page->flags &= ~clear_flags; + } } #define arch_clear_hugetlb_flags arch_clear_hugetlb_flags diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h index 5966ee4a6154..304dfc499e68 100644 --- a/arch/arm64/include/asm/mman.h +++ b/arch/arm64/include/asm/mman.h @@ -28,7 +28,8 @@ static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags) * backed by tags-capable memory. The vm_flags may be overridden by a * filesystem supporting MTE (RAM-based). */ - if (system_supports_mte() && (flags & MAP_ANONYMOUS)) + if (system_supports_mte() && + (flags & (MAP_ANONYMOUS | MAP_HUGETLB))) return VM_MTE_ALLOWED; return 0; -- Catalin