Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4566077rdh; Wed, 29 Nov 2023 05:14:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1LRcZ/58+Kbeg0tSOpnd0P+sJx0Ub1PVOgxm0huFh/PsonTy6wz2Mu3aNS5cqL58ev6u/ X-Received: by 2002:a05:6808:150a:b0:3b8:5c54:fe0a with SMTP id u10-20020a056808150a00b003b85c54fe0amr18415599oiw.2.1701263654531; Wed, 29 Nov 2023 05:14:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701263654; cv=none; d=google.com; s=arc-20160816; b=dIyaWGb2BW8H9ht++TkAheCZAcl6I+9RZ40Wu5o6foajCI+BE0fpDzxG8PSRjbbc0X 7F7jfEyTtr4khKIUoK9RdyolofsqymsILd4jmGbJZEdfppXJMwHrHEAU4L4a8BkcWtbf UDu/HVVsfUi/ddvWuHaefXkj03LPm8+Sw8HCADOVshZPn1iDHh6ZtLa9vCzIPpJevw/6 YiuiURJhh377xy5sfpncTLqxwH1ZPKEDJJClX09VGgJEbdboSMzwrUgmBu5W6QDEFBMw zdcfyvc0FBSjywkxXpq3kONZQNuZCBQIiQtl+hbRRsoUqFwXSVs2CPEy5b0nryDihSAm BdzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:autocrypt:from:references:cc:to:content-language :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=3TayWcGEHdK+3ZI0qKU3Neqs2Q8oviWSNuzQtqoO+JM=; fh=XeoyJYZu6cpr3FtC9fPQMNAL10w6OL9aWVxlLXrVK24=; b=h7WrrrdL8eiHwLL8bW0G7/YD9ANFJwVa4fvROrLxC/wJIdA4OPuLxHNRvUYKyT117X 7Zatz5nwH5GJHLk3HkYgqswwg9gFbY91/WQxxMkwRioviLlmvyruaWHl0QLCHNupo8FR Idt+wPtx0HJrRgMBXgky6Gsx+XxULk0iW5siclmCtJ8ptTXRzXNX0vu3r8puNbU+fkgK 2pPI01GSEmJICuPNI4GgOHEWF/+/7WRjhoPOpvyIRIwUGSINFRdbOh0BUopcFxGB+PGe hVMsraS/Vd2Me9MvJEzO68wm7yi6dpwNrAZZEWqdKG5Ju7H0Ggg/a83JcWqsJnMu8DDe tTKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="GitpA5J/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id r14-20020a63514e000000b005b909e93e2dsi14545826pgl.522.2023.11.29.05.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 05:14:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="GitpA5J/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 72F36833965F; Wed, 29 Nov 2023 05:14:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233871AbjK2NNw (ORCPT + 99 others); Wed, 29 Nov 2023 08:13:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233354AbjK2NNv (ORCPT ); Wed, 29 Nov 2023 08:13:51 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D494FD68 for ; Wed, 29 Nov 2023 05:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701263636; 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:autocrypt:autocrypt; bh=3TayWcGEHdK+3ZI0qKU3Neqs2Q8oviWSNuzQtqoO+JM=; b=GitpA5J/Okuaasvo32p4mVfVtguvlY12iyKleyg5uRpCuegIRH9N0o0LlWgyOf0LVNqDgO ntlYChaM22jnLRj18XD72tpEK1daMznq7p9zl05IuXHONAQa2XR1VXUQ4tZfL6aM7gkQ84 eJ9kA8GuGggbVsf5DYqvJkaIEMYkxoA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-gaipZENeOrW55ZN26BUeSA-1; Wed, 29 Nov 2023 08:13:54 -0500 X-MC-Unique: gaipZENeOrW55ZN26BUeSA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40b3dbe99d9so31415985e9.1 for ; Wed, 29 Nov 2023 05:13:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701263633; x=1701868433; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3TayWcGEHdK+3ZI0qKU3Neqs2Q8oviWSNuzQtqoO+JM=; b=oqQvX4dDg1dc3HR5aQiBgei4ALwKVYLooM3rRNg91Zrz+X+f7H5KAQRGXP3oadoVJn nC5NmD4HqiSHS7HXefJbAXzaeDB1crRlNWelOxHA2611DJAgkfoU4scc7iMRn+kb1ebS kbr27UOtnUzmVK3bbDfDvOFUQG6bpndZGG2tBV/ch79OKppLcQoAnegFh+65ysojgVGd x0zAPyw07kHTG5ZZkBBpm3MrUeekSfOQBKnrdX+7IWYIoslmAal88941BfaUNS+2hY18 gnLOZxIO9tiDHstZZ3fA5kOz667lvxPtz9b4EiFkWKt28cUhduFPEKUkUq5yEyM1XJDi SFCQ== X-Gm-Message-State: AOJu0YxreDp2/6Yy6ieTtzptr9ZN1wSidg8WcSBtc19IR41BDM+TEAXb ddOotAsudrnDc+rDDO4n3D8mbnvYWBsy1mj154nTJthf8D3Q7Op5j7QnV6ac8do6ojCt+d6tX4U z88kbOw84iVq9KfjkmjC7kJqy X-Received: by 2002:a05:600c:3505:b0:40b:3863:3ae7 with SMTP id h5-20020a05600c350500b0040b38633ae7mr12727466wmq.29.1701263633142; Wed, 29 Nov 2023 05:13:53 -0800 (PST) X-Received: by 2002:a05:600c:3505:b0:40b:3863:3ae7 with SMTP id h5-20020a05600c350500b0040b38633ae7mr12727431wmq.29.1701263632730; Wed, 29 Nov 2023 05:13:52 -0800 (PST) Received: from ?IPV6:2003:cb:c710:f600:634b:35f:ffa8:475b? (p200300cbc710f600634b035fffa8475b.dip0.t-ipconnect.de. [2003:cb:c710:f600:634b:35f:ffa8:475b]) by smtp.gmail.com with ESMTPSA id t2-20020a5d4602000000b0032da4c98ab2sm18135574wrq.35.2023.11.29.05.13.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Nov 2023 05:13:52 -0800 (PST) Message-ID: <930b6fba-43bf-4784-9bc9-1c83c1adc30c@redhat.com> Date: Wed, 29 Nov 2023 14:13:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC v2 18/27] arm64: mte: Reserve tag block for the zero page Content-Language: en-US To: Alexandru Elisei 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 References: <20231119165721.9849-1-alexandru.elisei@arm.com> <20231119165721.9849-19-alexandru.elisei@arm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBE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ZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 29 Nov 2023 05:14:11 -0800 (PST) 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. > > 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! -- Cheers, David / dhildenb