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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94DAFC7113B for ; Thu, 24 Aug 2023 10:44:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2F4728006D; Thu, 24 Aug 2023 06:44:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDF13280063; Thu, 24 Aug 2023 06:44:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACE1A28006D; Thu, 24 Aug 2023 06:44:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9D8DD280063 for ; Thu, 24 Aug 2023 06:44:49 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 69852402CF for ; Thu, 24 Aug 2023 10:44:49 +0000 (UTC) X-FDA: 81158665098.04.C873905 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id B558A16001E for ; Thu, 24 Aug 2023 10:44:47 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf08.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692873887; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3q6SsUTEV58DV8cM/ZP/VT00n2/KnRX6QLTzxY/stIk=; b=Zh0yWXPMFT8zodEgu/TEg9G6dsBQ+Ey8M7Hn4/843stTQA9HkpPCvf0VXwzYhkZDH3rJRp g0EUZEPgop3tDaq1D5fyEeKUCn5/ZhRdDlLpI1DHEHgopSXZCNg1gVoGP7WWWVvI2s126J qCGLcWzUN7dIPvefBFdq83Sqpr6UcZU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf08.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692873887; a=rsa-sha256; cv=none; b=NNmsLxzZ+ap4+O6GSAIdUcM13hZnm/MeEGl3Oq3i4WPeXmlrGXyu0gVjVq2Bw7ISrb25QA xdTO1/UcHVy0iA7pLAR3GucU0gg3roKR+Gydc1IUGfpDwe0O3dHKO8BFW7DYMEEmuBLQJn J+gz4D7U6ieN4my8GEQzeouqGRGw400= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D471B6698B; Thu, 24 Aug 2023 10:44:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34910C433C8; Thu, 24 Aug 2023 10:44:17 +0000 (UTC) Date: Thu, 24 Aug 2023 11:44:13 +0100 From: Catalin Marinas To: David Hildenbrand Cc: Alexandru Elisei , will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, arnd@arndb.de, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, mhiramat@kernel.org, rppt@kernel.org, hughd@google.com, pcc@google.com, steven.price@arm.com, anshuman.khandual@arm.com, vincenzo.frascino@arm.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH RFC 00/37] Add support for arm64 MTE dynamic tag storage reuse Message-ID: References: <20230823131350.114942-1-alexandru.elisei@arm.com> <33def4fe-fdb8-6388-1151-fabd2adc8220@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33def4fe-fdb8-6388-1151-fabd2adc8220@redhat.com> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B558A16001E X-Stat-Signature: xf6ubeu33demg7yeafigc1q6oxi3fnsq X-Rspam-User: X-HE-Tag: 1692873887-914255 X-HE-Meta: U2FsdGVkX18Hu7mgV5VeA2aEBPGRZPyqkh1lQhI3iabYF/tvgWcOvike1GTENJoea/nftehdBuY6vnHwmS/RIMKZxOACMxajwEAjpcm6R+NPrF8t8ZlVeSs9A2UZ+53zsBYZb3hZvcQzM7qpzJ6jnTxrLcnRBmuy2/KWvrFlP6yN1vjPtxEhU1Y4WuD9ArH0DUmbeaaI9Bucczu9Feo099guAi2UKHGndSTZVJOxOhZSgvpzsNiyTsQ7KBdiPC5mmbf8Z1oUyhxPTkuESV0JIxcywRHFFcqRQcq7C61Mme4BJPE1Tloff/+UyFOVdC94dVvas8wro+QnKsw2OlM4K1gcbNr44cupgkt+PL+LGr24AREnr+fKwaEBg1+9qDOLcKWx7+exiH7XvE/9vowU0ykZE0e0Gnc40uoBawBMLUliIgSG0SpQUtdYcgF+fw7yaOD54Dl8j1XCVPWTZ3s3SHP41S6//Ve1UmiMr8wZ1h7833bLSxjgXn7a8eGLS4NTvYzH8YQBla47d0E4QpNqG5oTXwo+T/C3U740ZPxPuYyYfzjrW7vAD5WZp+0cbYnnAsFwwncxOuDfprh3RXiuIVd4JaGjyuhN10MB4UxODKxpl7CmxThZgEKFL7LPYAu52WLvS11OKpk0sY/rZgvEu4s/yogcuZchxBgZB1b7S0FpvLnWGYvfM9SqRG4ODMM8C5WaFct4ym0KlUXJwIneAqY6xFqHJ7hMwNkNmvIROoeCvbLPBbbEAyc+L4GPitR504Gk4vo+FTuxTdsf3ChxzFwAZUrqVPW62ckvO/XzqyWhD3KHEe/LplxyFLH7jJ5gYfQeVxPSP1j35cWExuPGWIpdS7gEI4XK1Fst7BDgTn2o0CqP+wXSC6YAoTDX0Z2CUhRNhSOb1kcenlTcKmFSbRqsOGxlIVYw3cCB0OL75BSEftV9FUsDUIhpW6Mv8K9iZEsU+XAhwHkD/NSQegx 4bFqBFno xXg2xw8NxGEweSj2BIET8lAgiN+llPyaQrvbSspSZBYaCY/172fxEoE2d/dClDGHQwONubswsnPHHr9FfUQSJrYk27LBzm9W4X2K3RslTLW1o5t1/NmWX0J55NxuF4njhzagxkY6OxjSMzBC3epzKmKGMs/CxOD+i4C4eL+HUTqNUQclIMtoKCUjB2VrDMLkq+f+6AXtM9UfCdmHXB+QjxALUtfOCtntC6WzlgLWAnESr6k9F5E6zQ+NmGrF/9+oNCHBIrMnuj9Qazoegs0BkSwm/SyMgrW0silR57rGhjcczbE2do24uEiKHWs7TwBOEE5Z2Pp/QpYAcUHadDXbHRuuk5VLOm4LwDep1PgugEMq3MJCh3vS7wu9ZpVwukA5aJCEguuNr3Si86+S2dTMMPncqVRXS7ukmNBOKJtRILwZp8XU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Aug 24, 2023 at 09:50:32AM +0200, David Hildenbrand wrote: > after re-reading it 2 times, I still have no clue what your patch set is > actually trying to achieve. Probably there is a way to describe how user > space intents to interact with this feature, so to see which value this > actually has for user space -- and if we are using the right APIs and > allocators. I'll try with an alternative summary, hopefully it becomes clearer (I think Alex is away until the end of the week, may not reply immediately). If this still doesn't work, maybe we should try a different implementation ;). The way MTE is implemented currently is to have a static carve-out of the DRAM to store the allocation tags (a.k.a. memory colour). This is what we call the tag storage. Each 16 bytes have 4 bits of tags, so this means 1/32 of the DRAM, roughly 3% used for the tag storage. This is done transparently by the hardware/interconnect (with firmware setup) and normally hidden from the OS. So a checked memory access to location X generates a tag fetch from location Y in the carve-out and this tag is compared with the bits 59:56 in the pointer. The correspondence from X to Y is linear (subject to a minimum block size to deal with some address interleaving). The software doesn't need to know about this correspondence as we have specific instructions like STG/LDG to location X that lead to a tag store/load to Y. Now, not all memory used by applications is tagged (mmap(PROT_MTE)). For example, some large allocations may not use PROT_MTE at all or only for the first and last page since initialising the tags takes time. The side-effect is that of these 3% DRAM, only part, say 1% is effectively used. Some people want the unused tag storage to be released for normal data usage (i.e. give it to the kernel page allocator). So the first complication is that a PROT_MTE page allocation at address X will need to reserve the tag storage at location Y (and migrate any data in that page if it is in use). To make things worse, pages in the tag storage/carve-out range cannot use PROT_MTE themselves on current hardware, so this adds the second complication - a heterogeneous memory layout. The kernel needs to know where to allocate a PROT_MTE page from or migrate a current page if it becomes PROT_MTE (mprotect()) and the range it is in does not support tagging. Some other complications are arm64-specific like cache coherency between tags and data accesses. There is a draft architecture spec which will be released soon, detailing how the hardware behaves. To your question about user APIs/ABIs, that's entirely transparent. As with the current kernel (without this dynamic tag storage), a user only needs to ask for PROT_MTE mappings to get tagged pages. > So some dummy questions / statements > > 1) Is this about re-propusing the memory used to hold tags for different > purpose? Yes. To allow part of this 3% to be used for data. It could even be the whole 3% if no application is enabling MTE. > Or what exactly is user space going to do with the PROT_MTE memory? > The whole mprotect(PROT_MTE) approach might not eb the right thing to do. As I mentioned above, there's no difference to the user ABI. PROT_MTE works as before with the kernel moving pages around as needed. > 2) Why do we even have to involve the page allocator if this is some > special-purpose memory? Re-porpusing the buddy when later using > alloc_contig_range() either way feels wrong. The aim here is to rebrand this special-purpose memory as a nearly general-purpose one (bar the PROT_MTE restriction). > The core-mm changes don't look particularly appealing :) OTOH, it's a fun project to learn about the mm ;). Our aim for now is to get some feedback from the mm community on whether this special -> nearly general rebranding is acceptable together with the introduction of a heterogeneous memory concept for the general purpose page allocator. There are some alternatives we looked at with a smaller mm impact but we haven't prototyped them yet: (a) use the available tag storage as a frontswap accelerator or (b) use it as a (compressed) ramdisk that can be mounted as swap. The latter has the advantage of showing up in the available total memory, keeps customers happy ;). Both options would need some mm hooks when a PROT_MTE page gets allocated to release the corresponding page in the tag storage range. -- Catalin