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 E7F89C48BC3 for ; Tue, 20 Feb 2024 16:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To: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=/UwU1P2u4SG1ywseyqUOKBdA/plQJbtTALVCQ6SAgXE=; b=Rjl/X6ArGLdY/9 13AHYELfm6CljlQ6kBjpjq8yb5JE1ldwMMhNIw2+TmeeOtzz2H6J7Qon38Zac81q+/FZHEuXusSbh ZdLa1zJ9hpLpNa3cru5PaNyOyPwkENDTMiW1/2j77RHG92UKtPlE+7f8UEPI8MB9L/GD3rp/SzORz eEIdi42ZhZpdAdtt/gv3bvEcT6hXbXk3JH/Xe+jGzh4a3kThd4M/dlbmMWGzYaG8xrudOs9/oSJyD X0RVD1DxiVGXhX6oAatgk8uF/abzN/mwFdB1a5mZh9p3T67ozFqOehJB0iN6afNUswqzXrK+gjwjj ekrqBeWcnu1Sfum7pj2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcT6O-0000000FVbx-1cXR; Tue, 20 Feb 2024 16:36:16 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcT6M-0000000FVb1-2Ieu for linux-arm-kernel@lists.infradead.org; Tue, 20 Feb 2024 16:36:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F848FEC; Tue, 20 Feb 2024 08:36:49 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 20E3A3F762; Tue, 20 Feb 2024 08:36:06 -0800 (PST) Date: Tue, 20 Feb 2024 16:36:03 +0000 From: Alexandru Elisei To: David Hildenbrand Cc: catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, pcc@google.com, steven.price@arm.com, anshuman.khandual@arm.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, rppt@kernel.org, akpm@linux-foundation.org, peterz@infradead.org, konrad.wilk@oracle.com, willy@infradead.org, jgross@suse.com, hch@lst.de, geert@linux-m68k.org, vitaly.wool@konsulko.com, ddstreet@ieee.org, sjenning@redhat.com, hughd@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, alexandru.elisei@arm.com Subject: Re: arm64 MTE tag storage reuse - alternatives to MIGRATE_CMA Message-ID: References: <70d77490-9036-48ac-afc9-4b976433070d@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240220_083614_714218_99FF7B2B X-CRM114-Status: GOOD ( 40.12 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On Tue, Feb 20, 2024 at 05:16:26PM +0100, David Hildenbrand wrote: > > > > > > I believe this is a very good fit for tag storage reuse, because it allows > > > > > > tag storage to be allocated even in atomic contexts, which enables MTE in > > > > > > the kernel. As a bonus, all of the changes to MM from the current approach > > > > > > wouldn't be needed, as tag storage allocation can be handled entirely in > > > > > > set_ptes_at(), copy_*highpage() or arch_swap_restore(). > > > > > > > > > > > > Is this a viable approach that would be upstreamable? Are there other > > > > > > solutions that I haven't considered? I'm very much open to any alternatives > > > > > > that would make tag storage reuse viable. > > > > > > > > > > As raised recently, I had similar ideas with something like virtio-mem in > > > > > the past (wanted to call it virtio-tmem back then), but didn't have time to > > > > > look into it yet. > > > > > > > > > > I considered both, using special device memory as "cleancache" backend, and > > > > > using it as backend storage for something similar to zswap. We would not > > > > > need a memmap/"struct page" for that special device memory, which reduces > > > > > memory overhead and makes "adding more memory" a more reliable operation. > > > > > > > > Hm... this might not work with tag storage memory, the kernel needs to > > > > perform cache maintenance on the memory when it transitions to and from > > > > storing tags and storing data, so the memory must be mapped by the kernel. > > > > > > The direct map will definitely be required I think (copy in/out data). But > > > memmap for tag memory will likely not be required. Of course, it depends how > > > to manage tag storage. Likely we have to store some metadata, hopefully we > > > can avoid the full memmap and just use something else. > > > > So I guess instead of ZONE_DEVICE I should try to use arch_add_memory() > > directly? That has the limitation that it cannot be used by a driver > > (symbol not exported to modules). > You can certainly start with something simple, and we can work on removing > that memmap allocation later. > > Maybe we have to expose new primitives in the context of such drivers. > arch_add_memory() likely also doesn't do what you need. > > I recall that we had a way of only messing with the direct map. > > Last time I worked with that was in the context of memtrace > (arch/powerpc/platforms/powernv/memtrace.c) > > There, we call arch_create_linear_mapping()/arch_remove_linear_mapping(). > > ... and now my memory comes back: we never finished factoring out > arch_create_linear_mapping/arch_remove_linear_mapping so they would be > available on all architectures. > > > Your driver will be very arm64 specific, so doing it in an arm64-special way > might be good enough initially. For example, the arm64-core could detect > that special memory region and just statically prepare the direct map and > not expose the memory to the buddy/allocate a memmap. Similar to how we > handle the crashkernel/kexec IIRC (we likely do not have a direct map for > that, though; ). > > [I was also wondering if we could simply dynamically map/unmap when required > so you can just avoid creating the entire direct map; might bot be the best > approach performance-wise, though] > > There are a bunch of details to be sorted out, but I don't consider the > directmap/memmap side of things a big problem. Sounds reasonable, thank you for the feedback! Thanks, Alex > > -- > Cheers, > > David / dhildenb > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel