Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4583633rdh; Wed, 29 Nov 2023 05:41:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHe3RyFkxFgyifPm8k6qNB9N0NScTJB0LL6VPHt4ULmO/EgXPdJ9R4zr5csvsZWFNMURMJZ X-Received: by 2002:a17:903:1108:b0:1cc:5dd4:7ce5 with SMTP id n8-20020a170903110800b001cc5dd47ce5mr20779083plh.19.1701265312857; Wed, 29 Nov 2023 05:41:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701265312; cv=none; d=google.com; s=arc-20160816; b=uUaSIaeTULgOzrodGTFWXyPM27qjvzGoyjkb8rLvgPjdkdl1qFDTYZiOjutyIaLMFF zop9BsOE55qXBNj2/ahOtUX28wSWAdMGqzBR/GBEd2Z0CEVWEBzEzEDysmYLW9XVfks9 6hYSb11aTojbr6tNQjJhDnJWa02SXKcAFHOdJ/snqjd60+Hu79Jt+yS4Hgq4QPl5kQMe wCmNh1VyPRIbGg+JnhHy+VGoMBNMB/vrQIFlDt5W/lUvwqh/1DeHDNF3Vwd8JZzOLPyb 5kcBhTLsl0lMCU0oYkd2ATP80lw31/9ton7dHMWtEds6Uyb14DfzNTh3KHhN+kDvXLSv KdlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=hxtdTDV8oVb2euQnQH5ksv8TBsTbWgLO9P6Qz/yBJOg=; fh=oVyZPWtm6mpH3d4qDAoXsAeagaN2dloHFHPyagpC8cc=; b=gX8NMc23FKdcnrQjpQHnDAPC3ScNTwPiXXj/O5t5OQ8VpcEg5Q3a8VXuTagTiWcTXD 84sViTz1I90yp6b7tkqgEBgmb4nCwX/IprllkARqyY7fYGEuSVNZ9ChjZpNndG5rGdoV OyYdlR6xMxzuVtrHMMasZco9Q69Tkg/FrGRXJ9G2k5XKcvu6Lji+K3oo1PjKNmhHX9s2 cQUaokts6ZGTx6u4oPikdeEF/4ebR4i4v7tJ1XMd8IID84UwgJn09crty6PZ911WEW7J sIruERndp4+20GbdvcWllxUOjRF6U671kY6QlWx/K/In2BHb5aO4eTGHoceMGRqZjFiE D41g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id z8-20020a1709027e8800b001cfdd2fe63csi5316624pla.312.2023.11.29.05.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 05:41:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id F01F88041EBD; Wed, 29 Nov 2023 05:41:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232577AbjK2Nlg (ORCPT + 99 others); Wed, 29 Nov 2023 08:41:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbjK2Nlf (ORCPT ); Wed, 29 Nov 2023 08:41:35 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C262BB2; Wed, 29 Nov 2023 05:41:40 -0800 (PST) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 29 Nov 2023 05:41:50 -0800 (PST) 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 >