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 6260CC3DA6F for ; Thu, 24 Aug 2023 11:25:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1693280094; Thu, 24 Aug 2023 07:25:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC5D1280083; Thu, 24 Aug 2023 07:25:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98EAB280094; Thu, 24 Aug 2023 07:25:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8ADF3280083 for ; Thu, 24 Aug 2023 07:25:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 59515140276 for ; Thu, 24 Aug 2023 11:25:51 +0000 (UTC) X-FDA: 81158768502.25.D68E7E6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 08BF1C0007 for ; Thu, 24 Aug 2023 11:25:48 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gLqop03n; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692876349; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Pf8km5Wwirj+Pp5xkmndF+gQtFmnTLNzQCBzwGFpVXg=; b=XiOzodCiCJ4FCe26Zl+ibx2MtoYecilDG8zPXtoA60mUoHQeZVbiY1uLWEmyGbuU4ivnXL 9/fHKU/wpJSoD9YcSZZFJc1Z6ikkUSMY/TV6xt3NuPvCIVHOeCq54HxYrDTX7k9Ixm4eOu ZSRcOOOYizQurcIJw0mkq1BcDe5kJUE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gLqop03n; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692876349; a=rsa-sha256; cv=none; b=YP1VMzeu15QxBkIDD3B5Rf0ltvfDxySAozf4dheixpFBVqdb3pTiYY2nPaNHX0SfDYwgTy bieZNotpLCd7O4bXuYXm9BTHGA4lgj2EQPHYvC8V+ol4QRlOrEs3FN5vtvsqjGHXBlqL3l UVA0ap9i0gw4nhb+RHQH+O0nfMMe1xw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692876348; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pf8km5Wwirj+Pp5xkmndF+gQtFmnTLNzQCBzwGFpVXg=; b=gLqop03nRTfGeMA4ikYfQCRjkLKGhlKrL/J/wL3/msJZMKcr4i18j8jMFAd1m/TkKxicXm Rx/QtllIbOzmBdUuP0j7nYot+prk9Jvnj/TJ9MUirUi8LrlbhrTiXWYv8+aNNpsSbOwBwP 1zxZ3H7m+xELD3lKmBurDtcf2C4VRZM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-KmE1aIJGMOmmCqvGWdFc6w-1; Thu, 24 Aug 2023 07:25:45 -0400 X-MC-Unique: KmE1aIJGMOmmCqvGWdFc6w-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-2f2981b8364so4237960f8f.1 for ; Thu, 24 Aug 2023 04:25:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692876344; x=1693481144; h=content-transfer-encoding:in-reply-to:subject:organization :references:cc:to:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Pf8km5Wwirj+Pp5xkmndF+gQtFmnTLNzQCBzwGFpVXg=; b=C+7jDODDPRTNmKuMQy90b08dyJTALViS1wKv4DAe44f4qQJX0J65rifuH/m/mOsu/j k3O20I98bzThQMWkZoggOBftoaKzEMAU/bI8MtJi67+sB29T4rfS5b4zukBa2AUusdGG J+lnWcZFGYhEQMrXJU9mcaWWn9fYfmZEjVhHmtCGuxyD/51HSM+98sy49vCHimRBNB/M 69oLX1/wteFlkczG7up6UAzR3uRqpsPgg9vhjOGn3rwAsAAn30iFPmjSmncqvmadaQIc AxNdTiJdI8jZRqQCqSngSI+8fiW0F4S0QJ1nkT77MgiajbixNsY5Hm1Rv9raw0PBdgQ+ C1Mg== X-Gm-Message-State: AOJu0Yzea1n0kEeeW1jfn4n4fu0OkqgAZiNEZdPKx451ZjLJvbyY3A7V EP3E/OXqD4bPxhqUc1K1V+nCru3e5918KrpEHS2uS8iRDHfJ/PDS6S3WUaVdYZfzYNMd6rhrVfl CmViTDxEvT2o= X-Received: by 2002:adf:f291:0:b0:319:8333:9052 with SMTP id k17-20020adff291000000b0031983339052mr12256608wro.26.1692876343998; Thu, 24 Aug 2023 04:25:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjgoZLvCXmRzs+SoRsWPKHZfVBXeQL7A57Cia6xx3CKAJ6M8J1WZ44nBdXmrWG3mqys2wyvg== X-Received: by 2002:adf:f291:0:b0:319:8333:9052 with SMTP id k17-20020adff291000000b0031983339052mr12256571wro.26.1692876343532; Thu, 24 Aug 2023 04:25:43 -0700 (PDT) Received: from ?IPV6:2003:cb:c709:6200:16ba:af70:999d:6a1a? (p200300cbc709620016baaf70999d6a1a.dip0.t-ipconnect.de. [2003:cb:c709:6200:16ba:af70:999d:6a1a]) by smtp.gmail.com with ESMTPSA id c3-20020adfe703000000b0031773a8e5c4sm21950229wrm.37.2023.08.24.04.25.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Aug 2023 04:25:43 -0700 (PDT) Message-ID: <0b9c122a-c05a-b3df-c69f-85f520294adc@redhat.com> Date: Thu, 24 Aug 2023 13:25:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: David Hildenbrand To: Catalin Marinas 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 References: <20230823131350.114942-1-alexandru.elisei@arm.com> <33def4fe-fdb8-6388-1151-fabd2adc8220@redhat.com> Organization: Red Hat Subject: Re: [PATCH RFC 00/37] Add support for arm64 MTE dynamic tag storage reuse In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 08BF1C0007 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: fzenxizc6g3zn56fcejhhs3stgh1yp76 X-HE-Tag: 1692876348-119793 X-HE-Meta: U2FsdGVkX18Zo5grYhEtpXEgkMe9AngZS/t95RSx/ZWBvu4dp1lUbonqqQ9s7ylICvydJqPnuaHZaRwBKHc3gmeBSYpy61hOyueqyWC1kGkix6qxqw6pxhvsYoD1Q2nhNNWlQjprQc+wCZs7q8kEPiH2uchHVOmy3pQez939jVpqKpiLSgrLlnP0xgaU8l1x4x8TCkA+4IYez9dchBZcrSVHakmyvzhE+g1uETjawK2Rb8N5AuL8bLdHdz9vGWncGV5M1s8H+t2YPO62HQas/ABX/WG4oWzfR6Zf8ii5ZRHuGrYCv80hB4LEa3NovtbyRidfxbQUmOThdDa9tsZmGAf7OZobHL7kK92J0gvUh+eIS0atbtdo4bzE5Y7A1f0qSSa8lh03JHYKqX6Z/eTID9+DwVqJatHCtr/ElBYS/AuSPiD+hslXTZx2+2c5yub6wG/+haKY1qW8JjEWutJkGtMXrsb5Ue/83qNA/c/rGFcK0PI4cHfbYS3/WyrWj8khXmH/kMOQIMgrf77+cOCNmKTOyKbt+Tyu4XkbBqAUC9Qr33zq1k18WghzbISmHVDuhPB/OEpDuwLGQAO4Fky9caYgIBBqKk/bfd4OUESqy8sj95MGvdOSr/JcKkczA6lmhFfO0cEftCVgE4cqzGkHJfjbELGMgT7yEQknXPGUS+wYRHx5Bh0PluN4yfIZdM09Z3lZhyIY4cQVtsMaQv6zj4Q3ye+rz8DoVMk+RvgdhZraAfz9YtRPLu9s2AkGTR/ae5EDXQFGrHZvu/7nJdBTYaiDGtcM44ETvSg427NjsV9R7177cQ+dYrjJWCZCkiSAnA23t7LKvV4JbPJVc42/hflf34YqHArJ+O7Mzol3nfyopMceQ+9eTrC+GJtNCkyPr3yrBNAdr4bsnSBXjmgeRfD5nA9rEPD7TPV+/ois4J10it0BU34VeDBzRpWO//ih5WFxYuq40vczVbV/uRn SpHHrXIN rKt6hWR0fxnkrDHamLlMASJ1tGUTRCTjcAD1NRPKnSubLdR1K9JlJcV2DQ/Bt/K/DsL4DWFWXkbjiivwrolv1jFvTmMnmRfzu7KNXqSyskutXKnuGYrg0l/c1Ag5IROPTNPQHg9tZ6yADZYOgI1pwT69lEp+3Pz7HtQecugqnlFkro8FDpByUvcuzy2dQdLz9TJ9cpOIcdUkmEAnIMkuLnCPV8n2qMBA0nc08RhsQVBlPVz2CC6k3ndh7Ryzguf+ttchFiNM0n6XGInv5J16iohhk7P274ZG9NX49VZS9tYNQ7y89tqz7esDHDusJmXbXO5Qi5nzG23j4Kw1dvleEB9Lm6oZLnOQkuXJ6XN1ejuUHu/Tq7w2cuouhYKd+NUpNOQzZ 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 24.08.23 13:06, David Hildenbrand wrote: > On 24.08.23 12:44, Catalin Marinas wrote: >> 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. > > Thanks, that clarifies things a lot. > > So it sounds like you might want to provide that tag memory using CMA. > > That way, only movable allocations can end up on that CMA memory area, > and you can allocate selected tag pages on demand (similar to the > alloc_contig_range() use case). > > That also solves the issue that such tag memory must not be longterm-pinned. > > Regarding one complication: "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.", > simplified handling would be if it's in a MIGRATE_CMA pageblock, it > doesn't support tagging. You have to migrate to a !CMA page (for > example, not specifying GFP_MOVABLE as a quick way to achieve that). > Okay, I now realize that this patch set effectively duplicates some CMA behavior using a new migrate-type. Yeah, that's probably not what we want just to identify if memory is taggable or not. Maybe there is a way to just keep reusing most of CMA instead. Another simpler idea to get started would be to just intercept the first PROT_MTE, and allocate all CMA memory. In that case, systems that don't ever use PROT_MTE can have that additional 3% of memory. You probably know better how frequent it is that only a handful of applications use PROT_MTE, such that there is still a significant portion of tag memory to be reused (and if it's really worth optimizing for that scenario). -- Cheers, David / dhildenb