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 6FAC7C02181 for ; Fri, 24 Jan 2025 12:39:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA1B5280049; Fri, 24 Jan 2025 07:39:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D521F6B0127; Fri, 24 Jan 2025 07:39:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C196F280049; Fri, 24 Jan 2025 07:39:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A2E7A6B0126 for ; Fri, 24 Jan 2025 07:39:14 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 20045C033E for ; Fri, 24 Jan 2025 12:39:14 +0000 (UTC) X-FDA: 83042300628.07.23DDB66 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 560AD40007 for ; Fri, 24 Jan 2025 12:39:12 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.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=1737722352; 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; bh=NtxCifFL1KhPlXI6TEsIMYiI8AZohAUAMLxCMAQIMGI=; b=XsjT7BQ1UaYQNThon06S8q3sN07zTkcfQeAxFFLFxXXANssLa9V5ntAVDJop1/twp/JEal 2Ya/2L4L960BG7r+TE38gcyMtqP2oRXlRjwX8lvXevTtl+McDlSrstJrA0H/6Xor1WSwhr RomEP6VF3RLC1iyRvDB7gDraMRtzBmw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.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; s=arc-20220608; d=hostedemail.com; t=1737722352; a=rsa-sha256; cv=none; b=ePbkhEFKLzzZL3Jyb0SBjhMsVeAg3kGCOgF3sCJZXomu4xgMraRJpe/0FU2S2C2oR27PAb 2oa5cMDUA3dUTHTHqqAJvA7T3D8juhkp5uBI9aI5riA2Fv39vN9Zf8ABcRUIWkecW87dF/ DcSIS8wRUCOfZ1NIvWf5VGo9UzQlFTA= 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 68A39497; Fri, 24 Jan 2025 04:39:39 -0800 (PST) Received: from [10.57.95.170] (unknown [10.57.95.170]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 49F5E3F5A1; Fri, 24 Jan 2025 04:39:09 -0800 (PST) Message-ID: <426c1487-2bc4-4aa4-8da7-7559c7109ab8@arm.com> Date: Fri, 24 Jan 2025 13:39:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] s390/mm: Add missing ctor/dtor on page table upgrade To: Heiko Carstens Cc: Alexander Gordeev , Qi Zheng , Gerald Schaefer , linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Morton References: <20250123160349.200154-1-agordeev@linux.ibm.com> <20250124092917.19507-A-hca@linux.ibm.com> Content-Language: en-GB From: Kevin Brodsky In-Reply-To: <20250124092917.19507-A-hca@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 560AD40007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: e7tbmpom946ehbrzk5i1y515xm3qfaz3 X-HE-Tag: 1737722352-688759 X-HE-Meta: U2FsdGVkX18QQa3vQv4QduQgEAb0l5Hf75SlZ7oUHGTBSkYeMLTJCtMFhibjzv0inKwjBwcF1jFfIFCYdsPge7cPbDupa2Y5ccATAwZctxKn7HcsjP0MNGfiihMb3wUBzhiXNhm3kCUDWkIV7cH28B9TkcD6YZ5Z2kkHOBSP6oGJ4L5EuKXgYxldy+G371xSMUmHRDT7VvFwySwT8idp4P7MzfuhPuWbd9TLBxev553Uew8HREOJzaOrUnyRAABY9B7g60u3/0cw3ErtDlsDgrFLjYXmpcyxgz8sw4QOI4qsFiOlgYOzfEkWHOqsWQej9U2VDUSXTm3Ebopbo+eKky8Ek2ay7EWfG2wbZ4jypu6gmOM6dCHvGaTWh8NGr9XSDu5H4eLYOQA5+bLRsbTRO5vMA4Wpg/ginQAAPYLd1IWGJ84iJfuLxMZ2GtDvFFGosHjY1YvFnfopHICn09xZrYhYDX2LyUNxP7oQXkujlq1jOW1fO+eFchtmkC9DWE0n7ancZWhQsLZDeMab84eoumcJeQ0dsKsTnasYfsx5gaEhLBiZRr/UUYT8ctAF17UtQNCUMQfSU1cFy/OA8GEE9I1l+8Kr/8rL95ZpSwv1HDXmVeZjXQrQEbs1Fgb99yFXGhCdG2DgxWKGYnMU6OF/IrgSKui5GSWEBEQRlr8ZvLwAER5GnNS+39cskgzqUcbO/pew3Ck/sflJ6KDqI+VNla7rGcQSNncM6nHPJ04pJT5n2zl3vQ2RtFrO65sriOkmvpn53GqaMxMMvEwzzRVyp8F/i//NKKP0ZQ1gdkPxIVjX7mtrMLcucNPwl4anunhCHenVvYJ/2MndN8TpyGZm4vx+yaLVhj8GUAgNKbe+mrzqo3GNC1x5wGoImte/+vjTscvrG0FJH9Bg24wyEIOfWSM4yrVZ2xrrtp6CCkmcskwTHOzz9i2HHm5Czq3cQx+UX8OdFGo2iK9oc5et81p Rt+mKHca Ola2BFov6mtaSZLBt37PvLi6yBLH1c3YTIjgUQdnk6zH6oURtLnltI6qZ48mZ1A1HcjLUck84CpRNGVQN+yPoF516uYjeaW6CCib+m6oLCpOURxxfz2+8UBJ6gDMPOpX3+cx1Y+NRewiTc2iAYyH0KzZkpHwwcnnRKd6Qq0qy2af5IL+1AD/mXGpHEODBlIjhUCBKwBUdWehq8J3a0nGhCOYNYg9GhWsI6SkbvTNlJLxdF8c4N2utKgfpPQ== 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: On 24/01/2025 10:29, Heiko Carstens wrote: > On Fri, Jan 24, 2025 at 08:58:07AM +0100, Kevin Brodsky wrote: >> On 23/01/2025 17:03, Alexander Gordeev wrote: >>> Commit 78966b550289 ("s390: pgtable: add statistics for PUD and P4D >>> level page table") misses the call to pagetable_p4d_ctor() against >>> a newly allocated P4D table in crst_table_upgrade(); >>> >>> Commit 68c601de75d8 ("mm: introduce ctor/dtor at PGD level") misses >>> the call to pagetable_pgd_ctor() against a newly allocated PGD and >>> the call to pagetable_dtor() against a newly allocated P4D that is >>> about to be freed on crst_table_upgrade() PGD upgrade fail path. >>> >>> The missed constructors and destructor break (at least) the page >>> table accounting when a process memory space is upgraded. >>> >>> Reported-by: Heiko Carstens >>> Closes: https://lore.kernel.org/all/20250122074954.8685-A-hca@linux.ibm.com/ >>> Suggested-by: Heiko Carstens >>> Fixes: 78966b550289 ("s390: pgtable: add statistics for PUD and P4D level page table") >>> Fixes: 68c601de75d8 ("mm: introduce ctor/dtor at PGD level") >>> Signed-off-by: Alexander Gordeev >>> --- >>> The patch is against: >>> >>> git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git next-20250123 >>> git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm mm-stable >> Thank you for putting together this patch! I was completely unaware of >> this "upgrade" path on s390. > This whole thing is even worse than it looks after this patch. With page > table upgrade taken into account we still have the oddity that e.g. a > previous pgd becomes a pud or p4d, which means that ctor and dtor functions > might be called for different levels for the same page table. As of now > this is ok, since they do all the same. > > As a quick fix this patch is ok, and most likely it will be ok for a long > time, but it doesn't give me good feeling :) This could clearly cause trouble if the pud/p4d/pgd constructors start to diverge. In principle this could be addressed when upgrading by calling the dtor on the old pgd and then the ctor on the new pud/p4d. That said since there is now only one dtor, and the ctor are all the same, it's probably good enough. I'll mention in passing that my own series (that introduced PGD-level ctor/dtor) really aimed at supporting the kpkeys page table protection RFC [1], where hooks are inserted into the ctor/dtor to modify the pkey page tables are mapped with. No idea if that would work with this sort of upgrade path, but since s390 does not support pkeys this is just a theoretical issue :) - Kevin [1] https://lore.kernel.org/linux-hardening/20250108103250.3188419-1-kevin.brodsky@arm.com/