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 C0E4DC2BD09 for ; Wed, 3 Jul 2024 15:01:16 +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-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EWSsJZlTvGsOFFc+izAIsjnWUcuio0kOQrT3E6ouaNQ=; b=r/gogGlBWvLLKHyXyZx8uRNNV2 76w81mOv1yngkoVNDB3ynrbbaE5Tco2LWb8V7vElxpm2ug1ITcMICaSAdJy2z40ZgCI9brbEfpE1L +WQaEMivTVj7yJenzQLFxGIQRaJCkjiYtsh36xfW8hv+b8ErxadfO+lENMD3sQHBRTQd3pExq0s5y k6MAglyNNJlJnIqbGbsY0qV/haoBwonk6MyjY66cahR4Sqv050qA9cJcRihVZM73hG/2wcFpNqLyp WkKpdaOIKW9kzPHMaAcH9GuA1WoqUuD5O/0H5vFZ/fGjFwCz1IN++c8Bmwb12njIbN77esbz689UF 8nQ8j9JQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sP1Tf-0000000Aakx-3dDT; Wed, 03 Jul 2024 15:00:59 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sP0UQ-0000000ANdq-0DlM for linux-arm-kernel@bombadil.infradead.org; Wed, 03 Jul 2024 13:57:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=EWSsJZlTvGsOFFc+izAIsjnWUcuio0kOQrT3E6ouaNQ=; b=GSTVS5cE5YxJ3IqYm3LJfWx/PU x+TioVl3rUHu3bsgCGXzKQESSKQP+GoRv4jxwR5qU8TzpHifb2AXplXn030w7o6plJotnFtmsuhAf gyWnD5/GPVMQ5Oym5NVz3a0mM+v4/hQjJnvlYWryGWTwQDTcybEj2GiN1WJINnHXD2k2WTJ3jhSOO tt1uJdZu6F7hWb3S35zCwXtRyIznpLAKro2L3+to+zig2JIWm2N4zF4hll4xAn/rhCnCEqSbrHA1E NRVLrGgKAequaEOV0SD/9ypaBcs/y9/6QOgJsgSzlezqAzaWPa/l2E3iuLvdPYqRlt+DPN2oo3rLi dVbUF6Mg==; Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sP0UM-0000000A2MB-1rji for linux-arm-kernel@lists.infradead.org; Wed, 03 Jul 2024 13:57:40 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id AB614CE12DD; Wed, 3 Jul 2024 13:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FEC0C3277B; Wed, 3 Jul 2024 13:57:31 +0000 (UTC) Date: Wed, 3 Jul 2024 14:57:29 +0100 From: Catalin Marinas To: David Hildenbrand Cc: Yang Shi , 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> <9dd065aa-f377-4b4c-893a-df69c9f67360@os.amperecomputing.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240703_145739_193058_9EAA8AFD X-CRM114-Status: GOOD ( 41.93 ) 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 Wed, Jul 03, 2024 at 12:24:40PM +0200, David Hildenbrand wrote: > On 03.07.24 02:20, Yang Shi wrote: > > On 7/2/24 6:09 AM, David Hildenbrand wrote: > > > On 02.07.24 14:34, Catalin Marinas wrote: > > > > 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. > > > > > > This would likely also add a blocker for > > > ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP on arm64 (no idea if there are now > > > ways to move forward with that now, or if we are still not sure if we > > > can actually add support), correct? > > > > IIUC, it is not. We just need to guarantee each subpage has > > PG_mte_tagged flag and allocated tags. The HVO just maps the 7 vmemmap > > pages for sub pages to the first page, they still see the flag and the > > space for tag is not impacted, right? Did I miss something? > > In the R/O vmemmap optimization we won't be able to modify the flags of the > double-mapped vmemmap pages via the double mappings. > > Of course, we could find HVO-specific ways to only modify the flags of the > first vmemmap page, but it does sound wrong ... > > Really, the question is if we can have a per-folio flag for hugetlb instead > and avoid all that? I think it is possible and I have some half-baked changes but got distracted and never completed. The only issue I came across was folio_copy() calling copy_highpage() on individual pages that did not have the original PG_mte_tagged (PG_arch_2) flag. To avoid some races, we also use PG_mte_lock (PG_arch_3) as some form of locking but for optimisation we don't clear this flag after copying the tags and setting PG_mte_tagged. So doing the checks on the head page only confuses the tail page copying. Even if we use PG_arch_3 as a proper lock bit and clear it after tag copying, I'll need to check whether this can race with any mprotect(PROT_MTE) that could cause losing tags or leaking tags (not initialising the pages). set_pte_at() relies on the PG_mte_tagged flag to decide whether to initialise the tags. The arm64 hugetlbfs supports contiguous ptes, so we'd get multiple set_pte_at() calls. Anyway, I think with some care it is doable, I just did not have the time, nor did I see anyone asking for such feature until now. -- Catalin