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 722C1C4167B for ; Wed, 29 Nov 2023 13:41:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1E4D6B0396; Wed, 29 Nov 2023 08:41:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECDDE6B039E; Wed, 29 Nov 2023 08:41:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBF706B039F; Wed, 29 Nov 2023 08:41:43 -0500 (EST) 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 CFC326B0396 for ; Wed, 29 Nov 2023 08:41:43 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8BB9680240 for ; Wed, 29 Nov 2023 13:41:43 +0000 (UTC) X-FDA: 81511104486.07.AD36D97 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 87ED680007 for ; Wed, 29 Nov 2023 13:41:41 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf02.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701265301; 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=hxtdTDV8oVb2euQnQH5ksv8TBsTbWgLO9P6Qz/yBJOg=; b=I12vZ2gnyAhhFCEAiQ4zs/g585WDppJLlaBkeulF5qveT5o7B8wVIF/XcB8BC2M84pqPI+ qShb0bm02s1G1jl3y/ft2QBriD6bSsORGtpchD9hQaShhKFotjGY7zBiIC393u0F3lbbgR p8BZczPgswg5EHdUdHalodtE+PKJUs0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf02.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701265301; a=rsa-sha256; cv=none; b=p7SbEAke8tMVRU4y83d4cFEzsDfDekMAu47nO+RhwtCRpF2QcOVcWZGxNFR/8w+R98JvM+ ThhUzCxuwz1dBrlv4IDfjH+HDRH7GDYvK6eEC5HJQ1oAT+SRjtlg2lAQs/Uug7txSZZc1P iPEQtVy40SdYeKYNOYfJXifA6hH+Wr8= 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 8EDEE2F4; Wed, 29 Nov 2023 05:42:27 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3CA6E3F5A1; Wed, 29 Nov 2023 05:41:35 -0800 (PST) Date: Wed, 29 Nov 2023 13:41:32 +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, 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 v2 18/27] arm64: mte: Reserve tag block for the zero page Message-ID: References: <20231119165721.9849-1-alexandru.elisei@arm.com> <20231119165721.9849-19-alexandru.elisei@arm.com> <930b6fba-43bf-4784-9bc9-1c83c1adc30c@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <930b6fba-43bf-4784-9bc9-1c83c1adc30c@redhat.com> X-Rspamd-Queue-Id: 87ED680007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: sm9nrfw61ex8doderrcqpazzoiref6kj X-HE-Tag: 1701265301-143760 X-HE-Meta: U2FsdGVkX1/yZ06H2oZP3C7QCzxhz5H2+QocHPPJ7QzTxK3xsYyvTmA39u5BhVrZp2ykidD1kFaZ9mYNNsOwb68t4jVx/hqhmRjKbgKicJVD5qvPcj2rwyGFygDGJAooa8ml1HrdhdJDUvRP5v8/CASY30PtmBAl6zI821XO4zeGjeg4Imb9bpL+LR6Z1h7LYkN/LxuUZbMZLGO8MoWlccDbyqvb7vtILa35V7DVD8Ko71V7k3D82AiDH6Zx4P5k2ympeuDD9DNWYNSS2HlNmC2EpjowvrDSMW6i+wPIdaDj+oYFpR+siwYcKeJEUYKrA2FywMfW0R4ooZNrw3gsYVS3W2Y0XmliLQXNOhCyPHtUTAYiFuQdKVZHZV3/CI0RkpruX5WWAwaCoTUh332MKkWs/cIwEnPTeskSoxTSSHRipZjHQpTk2hHEomEZ4DlG8VU5r3/Vt2hhZHtXfb7cFPlgt4ndBwL/7nIHucX7GN6TzQH2LNH4w6vdY1KViY4xPmgDJepAsggZYcoB2VP6ldGvyOXllPPDPZGpfxn2voohx3U5P+FksPpJhIywY4k3ULy54TQqmim3OeL5mXjIz4wwH2FsUeXcD2lJub7RtfwF5m3+n+nNH+BOxzmVIub8wzTsXOZYhVwsWxUutLojMhrfoz2W9NgQF1vdKUdwS4bAtNlP4jYj/FrranpIqKO0p4Js/81iZODRlOwHRhBB7wQ+EG4C7joCFFpzUdWPJHSXdU2uhhalQEonhXHICovG+sOXzV0Ln/u2eR8dXRsr/BFriuengiuvxF68XgYaRAdumFV+pdm48H66CmsYXosfGFeXA8mvZvf7KUnkZ3sZXe1ox387oMdD1LjBkpxv3FNyyE3B8ccc4+xgXW/4scORvfZ09CQF/kfOcOAo7hzrIxtADnIWPycq+vLtp2VMklmztQu8BP9Ntvfmj3scEap77aJQts5SQCHQlO1MCz0 ZK+uGl54 iDA2+s4fdN7Tp8HPFc7xAoHkLjWso8+IkfYlXNEKe4pYx8+cL2AR1EezKPxyggqn6EHEwnDb9KK0WFJnOB3oQWCpWu7yasLoTkNTjgIeqgXih1Dk= 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: List-Subscribe: List-Unsubscribe: Hi, On Wed, Nov 29, 2023 at 02:13:50PM +0100, David Hildenbrand wrote: > On 29.11.23 12:30, Alexandru Elisei wrote: > > On Tue, Nov 28, 2023 at 06:06:54PM +0100, David Hildenbrand wrote: > > > On 19.11.23 17:57, Alexandru Elisei wrote: > > > > On arm64, the zero page receives special treatment by having the tagged > > > > flag set on MTE initialization, not when the page is mapped in a process > > > > address space. Reserve the corresponding tag block when tag storage > > > > management is being activated. > > > > > > Out of curiosity: why does the shared zeropage require tagged storage? What > > > about the huge zeropage? > > > > There are two different tags that are used for tag checking: the logical > > tag, the tag embedded in bits 59:56 of an address, and the physical tag > > corresponding to the address. This tag is stored in a separate memory > > location, called tag storage. When an access is performed, hardware > > compares the logical tag (from the address) with the physical tag (from the > > tag storage). If they match, the access is permitted. > > Ack, matches my understanding. > > > > > The physical tag is set with special instructions. > > > > Userspace pointers have bits 59:56 zero. If the pointer is in a VMA with > > MTE enabled, then for userspace to be able to access this address, the > > physical tag must also be 0b0000. > > > > To make it easier on userspace, when a page is first mapped as tagged, its > > tags are cleared by the kernel; this way, userspace can access the address > > immediately, without clearing the physical tags beforehand. Another reason > > for clearing the physical tags when a page is mapped as tagged would be to > > avoid leaking uninitialized tags to userspace. > > Make sense. Zero it just like we zero page content. > > > > > The zero page is special, because the physical tags are not zeroed every > > time the page is mapped in a process; instead, the zero page is marked as > > tagged (by setting a page flag) and the physical tags are zeroed only once, > > when MTE is enabled at boot. > > Makes sense. > > > > > All of this means that when tag storage is enabled, which happens after MTE > > is enabled, the tag storage corresponding to the zero page is already in > > use and must be rezerved, and it can never be used for data allocations. > > > > I hope all of the above makes sense. I can also put it in the commit > > message :) > > Yes, makes sense! > > > > > As for the zero huge page, the MTE code in the kernel treats it like a > > regular page, and it zeroes the tags when it is mapped as tagged in a > > process. I agree that this might not be the best solution from a > > performance perspective, but it has worked so far. > > What if user space were to change the tag of that shared resource? > > Having a tag != 0 doesn't make sense for such a shared resource, so I > suspect modifying the tag is like a write event: trigger write-fault -> COW. Yes, modifying the tag is a write event. > > > > > With tag storage management enabled, set_pte_at()->mte_sync_tags() will > > discover that the huge zero page doesn't have tag storage reserved, the > > table entry will be mapped as invalid to use the page fault-on-access > > mechanism that I introduce later in the series [1] to reserve tag storage, > > I assume (without looking at the code) that you took proper care of possible > races. > > Thanks for goind into detail! No problem. Alex > > > -- > Cheers, > > David / dhildenb >