Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1764372rdb; Tue, 20 Feb 2024 06:26:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW7HMXMESetHaxnkzGdker3G1Mz2pqKmkqSEv3U/Gx8uLg8aSLS4dsTMVzP2vf+qSWXjDmWnIwfrYAXCvHlj0DMCSI0Ht+asY/bWgseuA== X-Google-Smtp-Source: AGHT+IFyGFrWzd3FvSNbpYUj7tgEley+n8j6X0grjyUM3N34yc/jhKkvyi5E2wnp+g50DZ3kOp0n X-Received: by 2002:a05:6358:d383:b0:176:a5c2:8f19 with SMTP id mp3-20020a056358d38300b00176a5c28f19mr15201990rwb.30.1708439219177; Tue, 20 Feb 2024 06:26:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708439219; cv=pass; d=google.com; s=arc-20160816; b=BXGq8RbPFIs+LbDDK8iTPmN4wUK9Eqrp9WecKLx8bylasz8hBJtzSMj90itFu6bxbp H3uqa0EKqUX/JLZ6vyH9PAqbtXdVxt8vZ+qerUK2+V60khL1lKQHrZ0t8r1ymN1pyzPf I4znN5NYHwSOGMtV8NvU3S17ehRQh5ZCKM36UdK0V/K7f0fU2cOFWz1ZNcV/WgUxNywE rVXIfxXoy/NFL7uAyTv865avdTq4b37Gh5Z5hf1e1RUU56PERI9Wi5z/W/pyVZn8rhL0 JfwsaQWY2PSCEGZlWyeoAxjMrzfNitbiIn9k3Q75xhHT8zV9tBEibuevslv2ZPBSrgz9 8UKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=TfSiB4xU3Pf2ASAqrc35eYDgyfR8LdcSqcXXHY4DB94=; fh=lxUydpWRk179MTuWoHLClNlsE07TkdX2c6ltdLFH380=; b=B4I6gMCS+8CDpvUscGR3hHbsbPsbvUVYTNd+fCCWNCwetk7Mgp3cuWuSynnmZylC/f r04gTA0K4Jm2eFkSz8ftTeN+Ekrt1EvRdNtRA9AhMaSVyeYZsxgEn7EQo3xdgat6fdv4 n1xiQ563WZhJp8/cORf47sZ/B3WO5VfMOm4187OmBcw+nJw1BjQlAjjTtqFZ1oxXJAYA t+Jo0+0uw6tKvmypj2DxFiN8QALyiuElrdlBV+knkdDnxBsDN9BdfpBgj2ddHlc15T4J HYGr4FOiRPUW14w8IIS9wfC9GSfz6TTjIHEbYMx6ne48uNPhimhcuQxEoOqVHySJ+4bK XW+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ez1E/1Gj"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-73150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w23-20020a639357000000b005dbedf04f68si6560300pgm.10.2024.02.20.06.26.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 06:26:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ez1E/1Gj"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-73150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C0FCEB2355B for ; Tue, 20 Feb 2024 14:09:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6E926BFB2; Tue, 20 Feb 2024 14:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ez1E/1Gj" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EB176BB48 for ; Tue, 20 Feb 2024 14:07:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708438050; cv=none; b=hSVQ49UIGKJYyUsMQLCIn/htohd1jummJJzfxIWG8Z0BfWj4IWo2DwojfRjTgdMfI2Xl7onwWOoCJtRkqvc0UI5eF8+kGp1XpIo17+woJhn67kqyRTi9hY/r5k3ZuUZT22jFJpPial/kLT75mRQxlqtT2w/kIQ96Nht2XJLQ4AY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708438050; c=relaxed/simple; bh=E/1SUYF3tv2F1OGwxNLmQh08FWlc1Ijdbb/2R+O4kIs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fFXakuugxMEQ3ObLB2Fl6MbTYUmN+yo1k4f3Rbmm2NQ2nC0g8h5tr2HOv+nz9ig8Ph5BijZB46kgf1DNAIL9akypxwc2jqm8ONWT3B5K+3hQ5+RRjTYD86BLTMlnmiFSvdgugB2eIzgWbcBMKF8rfWUao/kxkRxqQoj7DZXQQh0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ez1E/1Gj; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708438047; 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=TfSiB4xU3Pf2ASAqrc35eYDgyfR8LdcSqcXXHY4DB94=; b=ez1E/1Gju9rzyoj5NYPFTypNLH1jtrgMesZ2yo6KZxD1wpvWxWqanxk8i1NVQTh7mEwUmF O6VHgIzJRkMgYrP8nvfrx0HoP6E19OrS2EAuhZKqhqA9H6X6TKPtDwIr6eDLJfpXEsj31I 5+eqyJMwU++3J3zWk8po/mQVsWS9664= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-OYBXdJclP2WePdi5BQlCTw-1; Tue, 20 Feb 2024 09:07:25 -0500 X-MC-Unique: OYBXdJclP2WePdi5BQlCTw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4125670e7d1so14165595e9.1 for ; Tue, 20 Feb 2024 06:07:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708438045; x=1709042845; 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=TfSiB4xU3Pf2ASAqrc35eYDgyfR8LdcSqcXXHY4DB94=; b=ms1YhRWYGkB8ub4bHYvxo2moqlnH6PXWPhOtsBq121aZuYEDgKLW1V9NXmsQRucRgV 9lYnK55fclG0pxwpaTUyiYzqzcH1A6FT9opcCIqETq1pXItWOiuT1PPiRwtOF3lq+ssz FYfPH5fX1Ea8c6atzPC+OvZxObxQrDEOyI1Ol37luCKdaGMnDz0PsvOHaktRx4SAfumV o/QDx+l/CHri1Ze9Ag+9XLz7N4KviyrIqt8aBLGmBp1oKiQM3RjoxPG0Du00NUur5OQS vUc4kmvoERCTkCpfxtyCt8/fr4ou9KDwwjbzuZ7iHKZXicHGLkTI8titLQXmvxkrFT/J XPjg== X-Forwarded-Encrypted: i=1; AJvYcCXjg/q+GDRUNzPDaXk8gDPGeKfZspEqL1tGm17gp/bxWDzM7DkhXWnPaIrAiH6V4JIWY5/BikLIGxSZq/B2IjI+a0G4zt1sWe0MApOh X-Gm-Message-State: AOJu0Yyb6CSP2FQI4D6PPYl20MbUudYZcqXzm6eXQteCYWiJ9ARg+PZs vM2K5itCTwPcCi9io2fFq1GZX3SiB6KZFkeCKMJRy1vbm9jMOz54lyovmMerk0Wojg94zHuJ/9D YbUCo4ik1oPAfEgGColvvW3OEE9chsaGO7kBVXi6q20pwICtexxW2YZsiPd/gdQ== X-Received: by 2002:a05:600c:1d1a:b0:411:db41:687c with SMTP id l26-20020a05600c1d1a00b00411db41687cmr15038516wms.13.1708438044725; Tue, 20 Feb 2024 06:07:24 -0800 (PST) X-Received: by 2002:a05:600c:1d1a:b0:411:db41:687c with SMTP id l26-20020a05600c1d1a00b00411db41687cmr15038492wms.13.1708438044298; Tue, 20 Feb 2024 06:07:24 -0800 (PST) Received: from ?IPV6:2003:cb:c72a:bc00:9a2d:8a48:ef51:96fb? (p200300cbc72abc009a2d8a48ef5196fb.dip0.t-ipconnect.de. [2003:cb:c72a:bc00:9a2d:8a48:ef51:96fb]) by smtp.gmail.com with ESMTPSA id js21-20020a05600c565500b0040fdb244485sm14558144wmb.40.2024.02.20.06.07.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 06:07:23 -0800 (PST) Message-ID: Date: Tue, 20 Feb 2024 15:07:22 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: arm64 MTE tag storage reuse - alternatives to MIGRATE_CMA 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, pcc@google.com, steven.price@arm.com, anshuman.khandual@arm.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, rppt@kernel.org, akpm@linux-foundation.org, peterz@infradead.org, konrad.wilk@oracle.com, willy@infradead.org, jgross@suse.com, hch@lst.de, geert@linux-m68k.org, vitaly.wool@konsulko.com, ddstreet@ieee.org, sjenning@redhat.com, hughd@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org References: <70d77490-9036-48ac-afc9-4b976433070d@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou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gb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+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 >> >> With large folios in place, we'd likely want to investigate not working on >> individual pages, but on (possibly large) folios instead. > > Yes, that would be interesting. Since the backend has no way of controlling > what tag storage page will be needed for tags, and subsequently dropped > from the cache, we would have to figure out what to do if one of the pages > that is part of a large folio is dropped. The easiest solution that I can > see is to remove the entire folio from the cleancache, but that would mean > also dropping the rest of the pages from the folio unnecessarily. Right, but likely that won't be an issue. Things get interesting when thinking about an efficient allocation approach. > >> >>> >>> I believe this is a very good fit for tag storage reuse, because it allows >>> tag storage to be allocated even in atomic contexts, which enables MTE in >>> the kernel. As a bonus, all of the changes to MM from the current approach >>> wouldn't be needed, as tag storage allocation can be handled entirely in >>> set_ptes_at(), copy_*highpage() or arch_swap_restore(). >>> >>> Is this a viable approach that would be upstreamable? Are there other >>> solutions that I haven't considered? I'm very much open to any alternatives >>> that would make tag storage reuse viable. >> >> As raised recently, I had similar ideas with something like virtio-mem in >> the past (wanted to call it virtio-tmem back then), but didn't have time to >> look into it yet. >> >> I considered both, using special device memory as "cleancache" backend, and >> using it as backend storage for something similar to zswap. We would not >> need a memmap/"struct page" for that special device memory, which reduces >> memory overhead and makes "adding more memory" a more reliable operation. > > Hm... this might not work with tag storage memory, the kernel needs to > perform cache maintenance on the memory when it transitions to and from > storing tags and storing data, so the memory must be mapped by the kernel. The direct map will definitely be required I think (copy in/out data). But memmap for tag memory will likely not be required. Of course, it depends how to manage tag storage. Likely we have to store some metadata, hopefully we can avoid the full memmap and just use something else. [...] >> Similar to virtio-mem, there are ways for the hypervisor to request changes >> to the memory consumption of a device (setting the requested size). So when >> requested to consume less, clean pagecache pages can be dropped and the >> memory can be handed back to the hypervisor. >> >> Of course, likely we would want to consider using "slower" memory in the >> hypervisor to back such a device. > > I'm not sure how useful that will be with tag storage reuse. KVM must > assume that **all** the memory that the guest uses is tagged and it needs > tag storage allocated (it's a known architectural limitation), so that will > leave even less tag storage memory to distribute between the host and the > guest(s). Yes, I don't think this applies to tag storage. > > Adding to that, at the moment Android is going to be the major (only?) user > of tag storage reuse, and as far as I know pKVM is more restrictive with > regards to the emulated devices and the memory that is shared between > guests and the host. Right, what I described here does not have overlap with tag storage besides requiring similar (cleancache) hooks. -- Cheers, David / dhildenb