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 54217C48BC3 for ; Tue, 20 Feb 2024 11:26:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD4B56B006E; Tue, 20 Feb 2024 06:26:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B85286B0071; Tue, 20 Feb 2024 06:26:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9A686B0072; Tue, 20 Feb 2024 06:26:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9B8166B006E for ; Tue, 20 Feb 2024 06:26:50 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 65BF41405B7 for ; Tue, 20 Feb 2024 11:26:50 +0000 (UTC) X-FDA: 81811954980.26.641516B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf28.hostedemail.com (Postfix) with ESMTP id D436FC0004 for ; Tue, 20 Feb 2024 11:26:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf28.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=1708428408; a=rsa-sha256; cv=none; b=B3hx3nTQrIJgFiLyUCYtM5kUlwFV1VCqlzes0gH817aD6JDTfAvFJEDjHGAWkKtkgbWZKx Ovnxnr7PKyGm1z8FvM39H8sqc/PUwyDq5XfaXtAW+yibfN1lwzUw8lbOxfJRFT7otYGSld OnwijyOu/4oY2uLq/PmonWEWa+4O5m8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf28.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=1708428408; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=J1wZ4Cd4IxkrhRskemFKQnfSBNPUac3MHa/xVG5/wIM=; b=vaPLSYAeDFi0lKopccqZwitNK9ccSixrREHddNfk5K70U4DvQMVEOnr+hZyjX66Oh+OuLq GuAJxZ99ZRSQMG6FsfGqrFO8eTPPrm4z2JHx4T4K+2dJsb8qh+tHMa0DEfW9a8eqiiOVQy bpzCECK1O1Humo7E7PNwxe237E/Nik8= 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 C4F9BFEC; Tue, 20 Feb 2024 03:27:25 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE4513F762; Tue, 20 Feb 2024 03:26:41 -0800 (PST) Date: Tue, 20 Feb 2024 11:26:38 +0000 From: Alexandru Elisei To: 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, david@redhat.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 Subject: arm64 MTE tag storage reuse - alternatives to MIGRATE_CMA Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D436FC0004 X-Stat-Signature: p5agtnboyhsowsgumqdod6toy83gg9h3 X-Rspam-User: X-HE-Tag: 1708428407-198922 X-HE-Meta: U2FsdGVkX1/JBI/leFYsVQV2KvVSbI75IhOFsDYZGFZIAbF0e+fQTtf3g/ObGOL3uUyOI84ZbiEzNzfsaCa1d7NOrBJjdhVrSAdIgwghKB/dK92zVkDWb/USSFxWxNVf00ccOX1XgvnWgh02Ahp2hkVIecX86EUOI/806LwdZbbAgPv4V8j3iLx8NgLtdA9JVkuKPoG4H+QlOkqMq2JghPLS0TVn8T19IXL+cX4+R28pPvQIn9Ab79AhrhMsTPyPYA7/1wCinc28dU2pqw6PovohYajB28/xKu5n4WAGYxCaaKaR6ebfl/74eK7uybUmQsbXvtIziO5FMMK170dXr1d9rR/BJfBCemyQvuHyhTKmxDZVlMz+dS5Td2yhrjMxQzLyL8prtRrH2tXLWTrjW3y3FQxE2r16hclM2PJBfOPVvtYO6Il4MQB1gta8Nzq+yZnNOUd6T+7nsyf8jLKJbmK2Npo+Dr1AuEDw1JSJdP48rYic6+4+r5eYOJcwb/WQIDeC5EmGz3cT9zzETaQjhh7eCKMkSXR6jB9NZrnlBA80UkAPG1aJu97XykeP5zKfv8z2kqqCUNS4mtFj5Y7eyc5pETwnLON9JnU1P4QZiyQzguwVo7BLeWBoeuDFMDwLVZkHop30Q0f6ykzvb9SD92II58HVvnT1HjWwxr+0E7OsmnG0pz1Jb/WKm3IvV72wrRXoH45R7Nb2BpIlI4cUtv19NErVWT0EwPRTUmzLyYn0v+yZwKdYAm+CyOmVbWmJUuWy8mzb+bByoYkCqQHcpWn8sp2fSnbpLfCecMfYTWqJCrjDfTq1qoLGP6Ag0Zr/Oa46OJRqMqyTjlPL9tqe25kSizsmIpWKpMou96JJtd/woX/1cBseuaqYwGvKLSnJc0sF0iEhCGxt866jY2cWJPULtJqXvrjPiP9a9l9Yz+LL6Toux/5TFIxJtxwqraf/BicZai5p6vHZNuaG4iP 59oQD3Wu ckD5mGCJ5r9XQFWH6Z7LkfvQHKRZMeslEbNP2J+F4pqrE2OXBp8oODEYtGpGZo/jSWYy/vhdvGpVKIQAJAvf4PyJOhZN9MvwQeOrCpX7MoaxzSnRXGHpFLr2ydDOxSUetKTZULP9bdqaMleg55KCAWPYpGhP8EQjWnumYe018FE63f7Eoo/IKisxznvlAKMgcKJDOo6DINoYfPSMHdpstIhwTKZRq8e0cDggjJRn/oa3cRF7Zkg+e2jejPMhYQ1ey5luBVwKzdgcfNIyqBofDLBieSZrQto3C/kBH/LF5h9wIlcnCbmeJf5IsvptT8YQ2cTuf 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: Hello, This is a request to discuss alternatives to the current approach for reusing the MTE tag storage memory for data allocations [1]. Each iteration of the series uncovered new issues, the latest being that memory allocation is being performed in atomic contexts [2]; I would like to start a discussion regarding possible alternative, which would integrate better with the memory management code. This is a high level overview of the current approach: * Tag storage pages are put on the MIGRATE_CMA lists, meaning they can be used for data allocations like (almost) any other page in the system. * When a page is allocated as tagged, the corresponding tag storage is also allocated. * There's a static relationship between a page and the location in memory where its tags are stored. Because of this, if the corresponding tag storage is used for data, the tag storage page is migrated. Although this is the most generic approach because tag storage pages are treated like normal pages, it has some disadvantages: * HW KASAN (MTE in the kernel) cannot be used. The kernel allocates memory in atomic context, where migration is not possible. * Tag storage pages cannot be themselves tagged, and this means that all CMA pages, even those which aren't tag storage, cannot be used for tagged allocations. * Page migration is costly, and a process that uses MTE can experience measurable slowdowns if the tag storage it requires is in use for data. There might be ways to reduce this cost (by reducing the likelihood that tag storage pages are allocated), but it cannot be completely eliminated. * Worse yet, a userspace process can use a tag storage page in such a way that migration is effectively impossible [3],[4]. A malicious process can make use of this to prevent the allocation of tag storage for other processes in the system, leading to a degraded experience for the affected processes. Worst case scenario, progress becomes impossible for those processes. One alternative approach I'm looking at right now is cleancache. Cleancache was removed in v5.17 (commit 0a4ee518185e) because the only backend, the tmem driver, had been removed earlier (in v5.3, commit 814bbf49dcd0). With this approach, MTE tag storage would be implemented as a driver backend for cleancache. When a tag storage page is needed for storing tags, the page would simply be dropped from the cache (cleancache_get_page() returns -1). 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. [1] https://lore.kernel.org/all/20240125164256.4147-1-alexandru.elisei@arm.com/ [2] https://lore.kernel.org/all/CAMn1gO7M51QtxPxkRO3ogH1zasd2-vErWqoPTqGoPiEvr8Pvcw@mail.gmail.com/ [3] https://lore.kernel.org/linux-trace-kernel/4e7a4054-092c-4e34-ae00-0105d7c9343c@redhat.com/ [4] https://lore.kernel.org/linux-trace-kernel/92833873-cd70-44b0-9f34-f4ac11b9e498@redhat.com/ Thanks, Alex