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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9CCE7C79F82 for ; Tue, 8 Sep 2026 10:12:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9611A6B008A; Tue, 8 Sep 2026 06:12:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 939A06B008C; Tue, 8 Sep 2026 06:12:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 875446B0092; Tue, 8 Sep 2026 06:12:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 681526B008A for ; Tue, 8 Sep 2026 06:12:16 -0400 (EDT) Received: from smtpin28.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E77F01A04EE for ; Tue, 8 Sep 2026 10:12:15 +0000 (UTC) X-FDA: 85190179830.28.EB9D069 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id E0223180003 for ; Tue, 8 Sep 2026 10:12:13 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=arm.com header.s=foss header.b=bq3wzFSn; spf=pass (imf16.hostedemail.com: domain of kevin.brodsky@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=kevin.brodsky@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1788862334; b=6BM5nxDkT/NH35DldTVXhYPA567E6x5ktiWnmVryxoqxazzntizMj4e/KjwSLQ6v+VG3jM VoH5ks4WqPg8+bPiqZP7aQMo3h2k/WPgkMXJ4aUhdODvxzDmCgBs9k1APJOL813u3OYnQ5 0ydzeEmBChIwsMcI50ruSw7DMNHBsR4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=arm.com header.s=foss header.b=bq3wzFSn; spf=pass (imf16.hostedemail.com: domain of kevin.brodsky@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=kevin.brodsky@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1788862334; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/ayOQBPJP38Is6vE11/duZwA3mrGAIUY0/EIe7FHOUQ=; b=qjdn2VQZvQ0vFuHhRsENRYcGjppKsgeHvcz8pcHGoHVpnTbIT0Z9/Ebj0ZO+ds3M/ZgzYH ELmEnnAWvB+v7Gt2eh9qV7otenh8/hcedpNMFvO/eAlyuroIxTMvanN7dypCtK9hGtjtwf KPwx2drxdVmhU6WxaU+bzrZMTDme50c= 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 37FA41476; Tue, 8 Sep 2026 03:12:09 -0700 (PDT) Received: from [10.57.7.202] (unknown [10.57.7.202]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 34DD83F528; Tue, 8 Sep 2026 03:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1788862332; bh=xlZC3OEZMV0/coWQyGMwBENJjfaFGyqN0Zg0ccer2wI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=bq3wzFSnLt2zEXdSnnz8U9DC9OXdPlrslLiXfJfZ/k46iOwSa29UVewNF2oShj0Vu /1YVazJsXb5vhqKLpsEUmyltbNMJhQZLlZtXH0OjNqzlNMIy0OoZofVpqolFOC9O0z RpncI49u7gtPHlIbJmwbnR1eaq8VLcUU9Xix7Sik= Message-ID: <00e97c75-eef1-4587-b299-ab07591a07bc@arm.com> Date: Tue, 8 Sep 2026 12:11:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC v9 12/25] mm: kpkeys: Protect regular page tables To: Mike Rapoport Cc: linux-hardening@vger.kernel.org, Andrew Morton , Andy Lutomirski , Catalin Marinas , Dave Hansen , "David Hildenbrand (Arm)" , Jann Horn , Jeff Xu , Joey Gouly , Kees Cook , Linu Cherian , Linus Walleij , Marc Zyngier , Mark Brown , Matthew Wilcox , Maxwell Bland , Peter Zijlstra , Pierre Langlois , =?UTF-8?Q?Pierre-Cl=C3=A9ment_Tosi?= , Quentin Perret , Rick Edgecombe , Ryan Roberts , Vlastimil Babka , Will Deacon , Yang Shi , Yeoreum Yun , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, x86@kernel.org, Ira Weiny , Lorenzo Stoakes , Thomas Gleixner References: <20260818-kpkeys-v9-0-743ad31b2c8f@arm.com> <20260818-kpkeys-v9-12-743ad31b2c8f@arm.com> <178877845406.3691569.12554855722197968629.b4-review@b4> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E0223180003 X-Stat-Signature: ono7b4i9mdkaqyt9bkhpxod6un4mpkob X-Rspam-User: X-HE-Tag: 1788862333-442901 X-HE-Meta: U2FsdGVkX1+p35wiMbNC7+GHIdL8fqfgxBmqcC/rSy/6Bq4aON5L1rLwOlbXxOBp+fvNiWOBL4I1KbE3Kb9EOYDlXx1FzitftxWsPePZPaiJqoLsSBGChhCC6RAtk4XBLDvG099jk/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WvqG98mGRyvfuEfPj8= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 08/09/2026 09:33, Mike Rapoport wrote: > On Mon, Sep 07, 2026 at 05:52:32PM +0200, Kevin Brodsky wrote: >> On 07/09/2026 12:54, Mike Rapoport wrote: >>>> [...] >>>> >>>> static inline struct ptdesc *pagetable_alloc_noprof(gfp_t gfp, unsigned int order) >>>> { >>>> - struct page *page = alloc_pages_noprof(gfp | __GFP_COMP, order); >>>> + struct page *page; >>>> + >>>> + if (kpkeys_hardened_pgtables_enabled()) >>>> + page = kpkeys_pgtable_alloc(gfp | __GFP_COMP, order); >>>> + else >>>> + page = alloc_pages_noprof(gfp | __GFP_COMP, order); >>> Can we make it a sequence rahter than a branch? >>> >>> kpkeys_pgtable_alloc() does alloc_pages and then sets their pkeys, so I >>> think something like this should work: >>> >>> page = alloc_pages_noprof(gfp | __GFP_COMP, order); >>> if (!page) >>> return NULL; >>> err = kpkeys_pgtable_alloc(page); >>> if (err) { >>> __free_pages(page, order); >>> return NULL; >>> >>> with if (kpkeys_hardened_pgtables_enabled()) folded into >>> kpkeys_pgtable_alloc(). >> I agree this would be less ugly. In fact this is pretty much what this >> series did up to RFC v5 (albeit in the ctor/dtor instead of alloc/free). >> We could go back to this API, *but* the big issue is that it makes it >> impossible to use a smarter allocation strategy for protected pages. >> Patch 14 in RFC v6 [1] will give you an idea of what such an allocator >> (with support for large blocks and splitting) would look like. >> >> As discussed with David H we're first trying to land this feature >> without large block support (fully PTE-mapped direct map), but we do >> want to support large blocks eventually [2] and I would prefer the core >> API to be already compatible with that objective. Very happy to hear >> about suggestions as to how to avoid the explicit condition in >> pagetable_alloc() though! > We could unconditionally replace alloc_pages_noprof() with > kpkeys_pgtable_alloc() and make the latter choose the right allocator, but > that's not very nice either :/ Yep I also thought of that but the naming would be really misleading... Maybe, maybe, introduce __pagetable_alloc() that is a simple static inline calling alloc_pages_noprof() if !CONFIG_KPKEYS_HARDENED_PGTABLES, and otherwise checks kpkeys_hardened_pgtables_enabled()? Less ugliness in pagetable_alloc() but even more further down, not sure this helps. - Kevin