From patchwork Thu Aug 22 15:10:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773671 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 3A933C52D7C for ; Thu, 22 Aug 2024 15:11:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C54B180031; Thu, 22 Aug 2024 11:11:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C03FC8001E; Thu, 22 Aug 2024 11:11:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA5C580031; Thu, 22 Aug 2024 11:11:32 -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 8A4C38001E for ; Thu, 22 Aug 2024 11:11:32 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 33523A8DC6 for ; Thu, 22 Aug 2024 15:11:32 +0000 (UTC) X-FDA: 82480220424.13.3D6A361 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 89E2420022 for ; Thu, 22 Aug 2024 15:11:29 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339472; a=rsa-sha256; cv=none; b=cja5DG+plWNTyqV629g/E3buPgS0p8q6T7vLU707CcRwWr2SoMfR45jSZH1vm6RH24CwAu 08KyIyVg7uHfb8EgUp7UYXL1l9kJYWXhwAuBLhm0K2DQG7MtIR/kmb1493btWB4vIwlN3J Fum/815PEebCTgjCNWVrYr8RjJCzZwk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339472; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EkzhGaH1vpd9S+OVn0bTPh0Beh0aCRj5TChd371GEgM=; b=fTq4jG54VT8FsoL9mKnfkvVAPjb0R3jAol2Jd4TrGocQgd35fJfwXvo0mYZSplpAjzLn5I XcOgl4pTCUKRXuAcXrRc/tOYoG4H7T5caolWZ0jxciMKnB4tO3gAbQA92o4nXKaSaYOzPk 9mU07dgbprE4zBPkYtYh1gKw/iYTo58= 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 A8DFFFEC; Thu, 22 Aug 2024 08:11:54 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A4E13F58B; Thu, 22 Aug 2024 08:11:24 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 01/30] powerpc/mm: add ARCH_PKEY_BITS to Kconfig Date: Thu, 22 Aug 2024 16:10:44 +0100 Message-Id: <20240822151113.1479789-2-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 89E2420022 X-Rspamd-Server: rspam01 X-Stat-Signature: 4soufozsurab6t9zfg3eo65oxwaqgpmo X-HE-Tag: 1724339489-955756 X-HE-Meta: U2FsdGVkX1+6vhkF9fr7Ou4yssgN26+98kJTnvIlQg5pSoCrIKDDjnGeE8vvrHKjrbW/NisvCUWq+uWEiVgIwbnhGzntSDlsbPTyswk1V8+K/z//qTStUQaCRZT+3g6YVKWda4dUrkzUtRuVCk7zgiJtcxNr4RnRninPdt3uDX8uokmt1ZGuqGpDNemWMBXVvdnzDt16yrUBBOHueCHdDefi4hTMJcYyY2LnEwILAdxm1uccaJOASL731eBSGnMXyS6gORP0ru9r7WID7CkL7JOwo7kVJuY7Tqh+GG3VwOTsGZg4l5UOnBqBlONwePgjQeI8/7G9avS/HEUK8tHCWM8urh41NO2hROTlsRF/RhIgWOUnT72YVJLATi5DF6MDMfDu6Yi96W/MRS+EP61lO+2mQKf9cx8pJRn/6FTgAtOctyBW/xla9PiPVEfq/hX95ItfWH8HdOBYFGXymhXWFbc4TMQ7t4AuUhqlfz1JsVSnyuWraqL99vYI/dENogOYMsBfFEhhptPL+mmSjix4qHhcrQD2VC4Ok2A5mSHBE4U7SGAEz7sDZ/fLCxr/Ri2nifH5kc3UKuJ8iPAC5sZdzg08qyngMKcJ4LUN5p1+CvdoSGiylrJlVPVr0tjLUWFIzMLirkIz7J6oTsPTVay0u1gzwN5c6NCEKyPwDm8VlWYCqm6Y3rq/lx0e9ezxrBg98TJ3UJcw2lAJENQMZPxrTBCNhP3PIrOECH6Q2jlkOwE2Cq3p9MuB8Mi1GmBVnzMQpqaUINLoGBNoMOgeG388VtWxK+VgtvGNIT0K16Dgt0CA68ItJBme5ZLKQPiObVQJBbstomulOakbCcX2zPT4GM8beKsx/vunQJFgSKOUXNQJikUn+qLlRKdpOCjDPjeug8SBQ19ku9wWE221zxoSR+3bVFQFk/sE1uRBvfrRg4uCDxjfYQWElyKm5xsF9kzDTmwcBbZzp0QBrnJMOhR /EgGBqx1 RFBPZbckl3vKj2E2gNVdqr6ds+8oR4UayQKft5s5FTLvdA7kE8OWy44/qvfinSJY/8/RpsJosvTW3SPQ744P4Pmid0z4AhbCCw5yTvRwV4JXq9RWBq+E5uy54uoUkO5G9mmzs/BEswznamqfSzMgrfMRLnQbt1G+64610K5UfmvJjfASfpTDEJO6flvlj/uyJhPbtitHUJWQuRpZeJ3oY4hJucbNJe6dHA1V4WdTe0tGDzeAEDygUX8PMxigX9c4FlC+YsnbTxkTa+tQHlP+CJNt/rk2/89ZtYjv6MWiG6oWDhjXkXio0Y0/nKlS2QaZPomjom7M5JzZyR6kWWUARLIfPNK/F4/Z5TUJRR0RdKZgrJjS0JTGyWhyeMmRsIPVdkBvKsyiRqsbXcAbt9AtQQ/UcwL3rYqhkbEQv99e1G4RY+wE= 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: The new config option specifies how many bits are in each PKEY. Signed-off-by: Joey Gouly Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: "Aneesh Kumar K.V" Cc: "Naveen N. Rao" Cc: linuxppc-dev@lists.ozlabs.org Acked-by: Michael Ellerman --- arch/powerpc/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git arch/powerpc/Kconfig arch/powerpc/Kconfig index d7b09b064a8a..8a4ee57cd4ef 100644 --- arch/powerpc/Kconfig +++ arch/powerpc/Kconfig @@ -1026,6 +1026,10 @@ config PPC_MEM_KEYS If unsure, say y. +config ARCH_PKEY_BITS + int + default 5 + config PPC_SECURE_BOOT prompt "Enable secure boot support" bool From patchwork Thu Aug 22 15:10:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773672 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 6B637C5321D for ; Thu, 22 Aug 2024 15:11:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3DAA6B0156; Thu, 22 Aug 2024 11:11:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEB1680032; Thu, 22 Aug 2024 11:11:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF0AB8001E; Thu, 22 Aug 2024 11:11:37 -0400 (EDT) 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 AB0D56B0156 for ; Thu, 22 Aug 2024 11:11:37 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1F7EFC178D for ; Thu, 22 Aug 2024 15:11:37 +0000 (UTC) X-FDA: 82480220634.10.633DC19 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP id F007C40009 for ; Thu, 22 Aug 2024 15:11:33 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339412; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g7IaXVZdBs5xv39RK9QztWdWeQqbVpdYum+vkYswvwk=; b=LHOzmH0L3MBNuM1RKIGWhsJTGHBgZjTLixs4I7R74bmW6UzVNEcx5Pru7RlBBnwPob7y8o rg5B4pRmE8oD68DKkidmOTuGfMuIMKIZfin3tcOaRR1sm9eM2sKHprJFJCenQe0eofYm+T De+V0r9PSAR7w6+Pjt+EbmDihqGFQJY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339412; a=rsa-sha256; cv=none; b=JLXK1oQKjMAi6pTiQ73AGLd9EOSv7EFzGeI8DlNraWOAhOW2td1UQSJZXYXz0Pip05UYAU ngDLBrTbnSl9ENUE6PuvTRkZ4IvEBZlWvYpdOdu4qyHPmTA0XPnx4AS2xrGa9Yy76UV86h UC4Rz8yqCu633m1FsbsTjxiZdURl6sU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 037931576; Thu, 22 Aug 2024 08:11:59 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D92D73F58B; Thu, 22 Aug 2024 08:11:28 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 02/30] x86/mm: add ARCH_PKEY_BITS to Kconfig Date: Thu, 22 Aug 2024 16:10:45 +0100 Message-Id: <20240822151113.1479789-3-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Stat-Signature: 4m5e3ts7k3kkkcqe19y6gn8ux8m5xr88 X-Rspamd-Queue-Id: F007C40009 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724339493-175717 X-HE-Meta: U2FsdGVkX18hbjSNQ1IIsXljTWQKskXauAmIQ1NzavPZizVne9MEKG4wmjs5fvHT+lflgkqjXw7XBKSfuMmtJz5e6eMBngevYWq2vuhCVOct+KXsGjKEzxyzmjJRf3VAKQaUA290EmnlYERKPXJaa7q2jgW7ZnWotTR/pYWtiz9jLjg0WO3UBWCJYadZIVYck4gcWC9tvnpb0xNSJdeovpePGuY8KBLmbL/bOnaiKUqP/dAC5ZIs/KZxSi2PzPg8Cdb1GiW+sWtYsoYVz+jBZlVFIoz42UqnaZBKJsQL/6Ez5DuvxFRRYuytshvM1sc3qCl3c23mODsFelmJ5HcDTH7wz+yBOnSQ9jCFZjBL7kEzqbCazRrqMYgsP3REmny53FcfTxHo81rvHsXghVOHXraOMfpYo4Bax0xhPEIYGBojTDu4Od1FsQmX2kmsf9tgH/sKd3fCfX32A+UH2V7MIhnPZHmFN8XjYOWJJCXj9XcsbjnOyKnusqaB40zbZVVMN0t2LK0IA1Uf7V7kLv9/jdJUdTW0mg+NmvqYP7/4LuNyL1tftOTJp1MT4V7V0OuI/nEka/iPQ03jbVx4vQtCejg1LsKF+fCgZCQgszgW3nULJ9CzVKbnHNkO6br4/NKPA2MFvsz7CJs9vptl99WzR1uMWm5C47ndN4+GnsFCfkyQQP8jM3csIWGYElRy/BtLCfYzaRM3603W6dyKZg0As1UrM59e33tO+CT8BoIqTJ+eEa+XICcdyac6nyKkQ8pnLA49YE7MT3j9y1x2pLjzsQUVhQaobLzsd5bLJKd5AS7C3hBI4iNNTxixevWYXZZB7cZ1Ds/5/H+mYHO4BCqXHYP27Sn2YGKNE/Be1kVPxbRKDhT7O6ScKTJ6aIWoBWzcQ8xQs3k8MKJZki4qik15ZABY2c0IAUfCY/UD0mdrRd+iW8dhd8pzpQdygblCHOpq0zisopCvJlEZi03QxLT cK4qemDX OQ8i6imklCDypMBKQl8NL+dnkQB02QmZNd0pOCPwVfP2CYBbAWryCqzH+INi5MJPoX7cUi4rXaFckmSchkTVzacgSN61xcA/pbctNI4cCuSR2t8vnwVfTtbu6kyKSpVR65DzRbJB1sMXv29kds6WhuMXFdfXHHgGj6EvijIoOih4BlK0gTs9zeOJDEMNezOt+5OT42u/ThtjPKJE8pgk+cBX5OvVa4BUBseHEI5wcip5ifQaXfs2DpGkk3vIBJ05hrOHr70YemYhbnQ9tJS1ACdvc3b65r+P/QfLPJjYBcnwLVDpZY1IlZ89EWgy5yuqhLPgqI43HFaIBddXciWei5wN+Aty8P/reo1m3AkMK8j/8E/FYu2IX/xbBAw== 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: The new config option specifies how many bits are in each PKEY. Signed-off-by: Joey Gouly Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: H. Peter Anvin Cc: x86@kernel.org Acked-by: Dave Hansen --- arch/x86/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git arch/x86/Kconfig arch/x86/Kconfig index 007bab9f2a0e..683c0a64efe2 100644 --- arch/x86/Kconfig +++ arch/x86/Kconfig @@ -1889,6 +1889,10 @@ config X86_INTEL_MEMORY_PROTECTION_KEYS If unsure, say y. +config ARCH_PKEY_BITS + int + default 4 + choice prompt "TSX enable mode" depends on CPU_SUP_INTEL From patchwork Thu Aug 22 15:10:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773673 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 E01C0C54722 for ; Thu, 22 Aug 2024 15:11:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B16380032; Thu, 22 Aug 2024 11:11:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 65F198001E; Thu, 22 Aug 2024 11:11:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B2F780032; Thu, 22 Aug 2024 11:11:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 25F548001E for ; Thu, 22 Aug 2024 11:11:40 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C6E711A0685 for ; Thu, 22 Aug 2024 15:11:39 +0000 (UTC) X-FDA: 82480220718.05.45A5D6D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id 05BFB1A0022 for ; Thu, 22 Aug 2024 15:11:37 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339407; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AN5yxhdKyzfZdHqEo2A34b5U0fOr4xo1lXLMZ11v71Q=; b=7QoZiVQpIRbSmxrbMREh9uIV9ZipHZUxGvOM3GYiLlmL0CgSFr/b68jTjN5bxJ9baEaBcK Xok1UcrdXSSDMdGpRjVEtmMJoT2pu3RPJKaYKrOkVzMNe3vLQQ03By8l38DWTybSQJYxD2 6jKqSbDtOrdXZjETRfsakdXZP3QVonI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339407; a=rsa-sha256; cv=none; b=72f3+Yjn95oozo9+3n6Aq/Te/2VqhTMwiXVvS8ikhuw6wber54k6vpO6aWXSbkrtXQ3+cy oqRhWG6TyBPoS3lW3kyury0sVTPczSDVB5jGGdUGHU06I2GR2n2pwN0LuljTNS0wzaYDbA FIbvRS3rX8YdDzwzzMU7qTtzvwEtcWc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com 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 6108A1595; Thu, 22 Aug 2024 08:12:03 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 336263F58B; Thu, 22 Aug 2024 08:11:33 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 03/30] mm: use ARCH_PKEY_BITS to define VM_PKEY_BITN Date: Thu, 22 Aug 2024 16:10:46 +0100 Message-Id: <20240822151113.1479789-4-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 05BFB1A0022 X-Stat-Signature: 9epo865scq7igcr6dkx53iywuqe5dr8b X-Rspam-User: X-HE-Tag: 1724339497-258551 X-HE-Meta: U2FsdGVkX1+Jithx83lrt/EztyotQNFPLDIFoGAXsT9VMD0kVCx8w+o0P7cfsRCltkWpjU3LPDZ2gHdAke88TNFgoJlWOI8pgeQscOrVbN1UwLIOv3ejVv63scOZUVC9so9EO/b8nJ9s/m6JRaRGuPBDC2r3LDfyvI1wdILJIJnd4xCZs3Nzb2x7FeN6pPFmuZeClaLWiF4J1s1ziy9MHlnRwp6EdjPdv5cNB9iskqXsrGw1yyLjUr9+przEcs0LXjmdwFuMJjxNvBSFA/eA9CnQvu1+X4jLJOHfBAxwyx5iU5WVu1XeBxLCrg0UVZ3oMv0nkFGDRCwrw301oHcR23LJuaJmXQoSOmeua+zCQ2iIVs3j7EYyCRshShElcxd72iHrToiIG+6uXEkhbbcAuD/IBIQzfB3fmNw/dQtqw0RFuNTQw82FZH+iYB28wiYmgg9lrRtGYFt5SOrECaaRZjIVGaTpIDvfig/71KBnXsPiDXynezfUZswarkZaNkGXewEeaeSl5H5mr8BTuoTGSW7eOwANL88xMMm7Gij7aJshItNRZZrAo5qiuzWYihWdAaes29Za/SI15ORgj9HNn5uM+hTyNciy8c7IgUM2CBV41ISLeMBalqyI9zZIOPOeOL/k/5wTiw2M6vm33f6LNdT1GTU5Phlx/7YmH+3LIVc+9x60Av0z9GTZlFq6U8eGAJ2UDPkiRQ4+2bxw+oqibfBmyYbI7LLwiBqUmPv/I1wyf9t/HWyd7HigRf6VzfxAatoasVeq2CLrcq54vOdDAtF1+0VROARVqFmM4e286HFYlhdxLZ+Hub1UsxJzcep4cs1mPCAuHinfRrq/syXf6qfQQArwphC8A07ipmf78iq+cbEy2KeEbMOvhv+edvrO+5VhQY1z+1k+6ACvClZYtjmKFiQKZpqE4zmo05TF71BonVOIHs4qWWlv6QwHNisXjqVlsvSlrlrb2HbZzLN E5MeqA5k 5dvdccJElaWCPJX3GXYrBlCOFmRN7im10vg8C7n4wSR9pJy1vpWGEjc1Lfu8T0MVFi05pmBm5JOixTjAnbff0BwXoLWf7gCvRDQqlM5S5V6YOUZm3ZRmZ03JcSsZqsFapxfLCXD1mNzdkgEfdJ2DW8L/SUdo0ZLl+LlL92OGOr8lEfNvhS4WJrvuUALI+uSsIZMim8DqUJPKZnmqMdMFCbfCOBdqC1vUZYpJ87fg7M1PPqBITlBglnheJnRVvXpyzVrVn3jMfiUNtJG0mEU8bbvWoKCNL2rg1j73WoRxc4mIYRxp/vzQjwTBDEPugqWhD9B6ovUEbEzD6TyNGFHImdfMNEEfsA9FR461yXDdN5ARdbQk76GGS0jgKzPnY/kiSfrC4bfL7WSJaoqfqAxPXrEnYWA== 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: Use the new CONFIG_ARCH_PKEY_BITS to simplify setting these bits for different architectures. Signed-off-by: Joey Gouly Cc: Andrew Morton Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Acked-by: Dave Hansen Reviewed-by: Anshuman Khandual --- fs/proc/task_mmu.c | 2 ++ include/linux/mm.h | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git fs/proc/task_mmu.c fs/proc/task_mmu.c index 5f171ad7b436..2c5f4814aef9 100644 --- fs/proc/task_mmu.c +++ fs/proc/task_mmu.c @@ -976,7 +976,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) [ilog2(VM_PKEY_BIT0)] = "", [ilog2(VM_PKEY_BIT1)] = "", [ilog2(VM_PKEY_BIT2)] = "", +#if VM_PKEY_BIT3 [ilog2(VM_PKEY_BIT3)] = "", +#endif #if VM_PKEY_BIT4 [ilog2(VM_PKEY_BIT4)] = "", #endif diff --git include/linux/mm.h include/linux/mm.h index 6549d0979b28..56dc2481cc0f 100644 --- include/linux/mm.h +++ include/linux/mm.h @@ -330,12 +330,16 @@ extern unsigned int kobjsize(const void *objp); #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ #ifdef CONFIG_ARCH_HAS_PKEYS -# define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0 -# define VM_PKEY_BIT0 VM_HIGH_ARCH_0 /* A protection key is a 4-bit value */ -# define VM_PKEY_BIT1 VM_HIGH_ARCH_1 /* on x86 and 5-bit value on ppc64 */ -# define VM_PKEY_BIT2 VM_HIGH_ARCH_2 -# define VM_PKEY_BIT3 VM_HIGH_ARCH_3 -#ifdef CONFIG_PPC +# define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0 +# define VM_PKEY_BIT0 VM_HIGH_ARCH_0 +# define VM_PKEY_BIT1 VM_HIGH_ARCH_1 +# define VM_PKEY_BIT2 VM_HIGH_ARCH_2 +#if CONFIG_ARCH_PKEY_BITS > 3 +# define VM_PKEY_BIT3 VM_HIGH_ARCH_3 +#else +# define VM_PKEY_BIT3 0 +#endif +#if CONFIG_ARCH_PKEY_BITS > 4 # define VM_PKEY_BIT4 VM_HIGH_ARCH_4 #else # define VM_PKEY_BIT4 0 From patchwork Thu Aug 22 15:10:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773674 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 E3D3CC3DA4A for ; Thu, 22 Aug 2024 15:11:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B8A26B00E4; Thu, 22 Aug 2024 11:11:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 268066B0246; Thu, 22 Aug 2024 11:11:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E2B46B024B; Thu, 22 Aug 2024 11:11:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DFC166B00E4 for ; Thu, 22 Aug 2024 11:11:44 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5B17141800 for ; Thu, 22 Aug 2024 15:11:44 +0000 (UTC) X-FDA: 82480220928.26.549D041 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 570C818001F for ; Thu, 22 Aug 2024 15:11:42 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339421; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BEcWZioiXtHX8rackaBoYWZiwxpHMb6CvKiSOd8uBKQ=; b=odf8EBTpMBUd8J2w7ULI959SBA4WHneJwVWd4zgdtL75BJh8s4MMKgGH9xU5aWj0YjqXDy ZYfeObkwHQVBOiUS9SoWFH1SIQcv8J3Tq0zgmLps+WLD/JNWgo3jW7E3c9CXrqixIjyIp7 eu55WuIYXuXCsWBKlapIMJz6koV4JA8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339421; a=rsa-sha256; cv=none; b=BR1UHww8ZHzXAH+HTBVM2xKv9qg8lx3FzN8j0VV5t8HcQxvbuzdX/Pq/j4z3iWbEyjfr4e W9j7p/OCbGQIjMyHxEBYAga3Q9iuaH5NSz1TPH6izhUJOqrrDnWVFfL10N2SkqDerhHZgb Nbn/an/LyntYd5nCBQ4AEdPOrBMDAA4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 9FA9F1596; Thu, 22 Aug 2024 08:12:07 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 819CA3F58B; Thu, 22 Aug 2024 08:11:37 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 04/30] arm64: disable trapping of POR_EL0 to EL2 Date: Thu, 22 Aug 2024 16:10:47 +0100 Message-Id: <20240822151113.1479789-5-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 570C818001F X-Stat-Signature: zojn1scmwj5zs7kfdixhfm6p8i6yynts X-HE-Tag: 1724339502-956714 X-HE-Meta: U2FsdGVkX1/MYAEx0fY1JqTbRqzS1unSvqYhWIevd/QO7L3ywER9qH8tGwkos0StzyGfZRf26mEvX4l/SFPWyt/lw46Od+P8ggwi7kEa8ZKx8nrSLi7DB6fT1sVggHG3ohp//NJqfEhE0bbR1w3F4vHerO3QtAV6Zrv0Szf2lNiK1hoB24nUpzHOmViTjkvNH9jbKzcXkItX5wJ/zH9BQx8TxCKYStbhm1HPIYwaVZQHsVutCgSXQtqVGq5PmY67vxY7mCZ2oIXNTPpTtMAauEtj34JcCUF5Q5tKg15usje/B3Y8hW9x+AlRo1y/XHEuXljPyIHvY/iU5n9lzNLYmmr4t0YClQEIQdMTiUXGBroDouEbMFl5WO9Zqyac7hJDg2eqlR0Eqq3C9v2+jC4KPM/igzNCIp1g4DKp8qJJLqDhQOuHg99wdscdNXrn4q/QjE4vbbk+Ye3NoJI1utAnGXiyvBD1FAethPmY1csD8Y9rJqwh/Z5Lnxe1DQWLzwXy9nwzBpFT7dAXPg/dZtdJvtBiMQ6uPwEwZVDAV29S4THYFp8LwlgpBQ2lzUPWTQXtFVgE8q9nEE6UqGepMy8iOYQLz+rBfWfpysn6t2COnyH1zOkVFGaGjSLra96AvE4eBUZbVDZ53VxogolvlLvQ62yVVkOkdlHVfrDtvlxYb7oJm+nXznGQQ4jqKWcRGpzlBA3kWYhh2fk+2G1lMRTtnQgGrR3Vjon1TPJ+BhOMaW52C01l2MYNJlSQCO+r8uM1d/CrJLhfiMgXKIbY9x33ypPKaQGqb/Fi7Ln1xqNP1SYrjXQz2A/6inUhmR4/BbWsUfwtu8WUdKz/gst7gV3cmVYXFDBvz7ytnDuqDQnZ4COnkTCU0ImchRF0E3jju27JxcShmnmUbI2nH+bVHXEuyDf2s6RsgFFJ1zfHuqyQ59yaoZZufkZH+kxzItMqDeZMKES52p0aAyKsKBMsFDh guekrWhZ USpl08peMVCERJq85i2/oawCLPCgdEDgfoNMgWCSAmxl/LiMC/Mzgg0kFvUgLByEhTcUF4+EWzPn3oWs5KMlNbsBa4wFg738O1JBZtO/vOaaPe8YnGF0Ub0SGeI0p52WENjV9S520JbsbpTAbEUN7tnW8SKFxZVhp7Mf701/8T+W41FKhrGPvF0R/LbQqdINGh3M50iYYZvtBulv9eSbivI8dezXByCo/7f25ZEIGpG1qr8R/tIl84IK5zhZk51xbDzuhOQV/ESndm0w= 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: Allow EL0 or EL1 to access POR_EL0 without being trapped to EL2. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Acked-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- arch/arm64/include/asm/el2_setup.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git arch/arm64/include/asm/el2_setup.h arch/arm64/include/asm/el2_setup.h index fd87c4b8f984..212191ecad40 100644 --- arch/arm64/include/asm/el2_setup.h +++ arch/arm64/include/asm/el2_setup.h @@ -185,12 +185,20 @@ .Lset_pie_fgt_\@: mrs_s x1, SYS_ID_AA64MMFR3_EL1 ubfx x1, x1, #ID_AA64MMFR3_EL1_S1PIE_SHIFT, #4 - cbz x1, .Lset_fgt_\@ + cbz x1, .Lset_poe_fgt_\@ /* Disable trapping of PIR_EL1 / PIRE0_EL1 */ orr x0, x0, #HFGxTR_EL2_nPIR_EL1 orr x0, x0, #HFGxTR_EL2_nPIRE0_EL1 +.Lset_poe_fgt_\@: + mrs_s x1, SYS_ID_AA64MMFR3_EL1 + ubfx x1, x1, #ID_AA64MMFR3_EL1_S1POE_SHIFT, #4 + cbz x1, .Lset_fgt_\@ + + /* Disable trapping of POR_EL0 */ + orr x0, x0, #HFGxTR_EL2_nPOR_EL0 + .Lset_fgt_\@: msr_s SYS_HFGRTR_EL2, x0 msr_s SYS_HFGWTR_EL2, x0 From patchwork Thu Aug 22 15:10:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773675 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 9AE97C52D7C for ; Thu, 22 Aug 2024 15:11:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2439880033; Thu, 22 Aug 2024 11:11:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F4D08001E; Thu, 22 Aug 2024 11:11:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F38A880033; Thu, 22 Aug 2024 11:11:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D37F08001E for ; Thu, 22 Aug 2024 11:11:48 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 788CF1C12FF for ; Thu, 22 Aug 2024 15:11:48 +0000 (UTC) X-FDA: 82480221096.16.C25F5E1 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf28.hostedemail.com (Postfix) with ESMTP id 9E0CCC0017 for ; Thu, 22 Aug 2024 15:11:46 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf28.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339440; a=rsa-sha256; cv=none; b=zRnvy5+G4an/4O/zuQroJ23xkZCvbgGn3r/Df/16e2ALu+IYcLbbD12Hh9ymUqscETHE0b L9gUzM7b5IPzS2972vx/iDs9j3TYUKNFdmvi21dYBFXv80msc+ZpXw7/e0T1JAS4aVpITy vSGRaLeinN6HBurr/Rw0zIeznFJAbbg= 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 joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339440; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MNrTMGsD5+rmAx8lQBjnHgQzdbxN8x//itlGnFpXYu0=; b=TgfNO/RWR/zvuKCrDmrIbiiIplJgKkJJmGFMEYZhkVC0XeuoQBoPeb6He3UTJ3fZjUlMDw IfkTrSZi5Z+UVSXEvIsjupfBKywkRpqHAdTZH9XL1ddGE0Ad7SD0NC5YcTgUelflYxynq7 ZoFbnZ8Fi7penUGONzuhrsTiNbUfQ4w= 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 EE16915A1; Thu, 22 Aug 2024 08:12:11 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CF9E83F58B; Thu, 22 Aug 2024 08:11:41 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 05/30] arm64: cpufeature: add Permission Overlay Extension cpucap Date: Thu, 22 Aug 2024 16:10:48 +0100 Message-Id: <20240822151113.1479789-6-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9E0CCC0017 X-Stat-Signature: eaj8msedmikizfd3q5b9nw1koc5tgwtj X-Rspam-User: X-HE-Tag: 1724339506-947761 X-HE-Meta: U2FsdGVkX18diIodbpd50zlT0au3pawe23Nd/aPMzPVnishW9JRrrIznEfFaliwoGeRHyTHVJrEjOP1x5XyNmqZ8oCxfrfDwPb/v/eU7EcELb/iIKkffdpj3/H3bcGWyHGKDaTWIEzdjQ9SDdo/2vMgB+DVDcTEkTlpoATaceN++3IXflmka8cWlfR4yGngaE6oPu3GhyFXcYAj90jhXC3sM9W/DUusocwKa8RDH7jbEEZkyL8gKusX4PmqoVToulL/uCsbIsp7D9Pm2ET3gHNSaejqWeyARum6zhqGtuBvoVsr4/YZ9FxOqAobNqrIZTQtCi98l+S0KNFNbXj8WrJ3Eh9rhrb0396COaG8DTixWKUj2N3uHZ6P1K/KSD2uzeJg9/d9s4V2VChQxX3WAFnO3+DKl2+ly9zbkEBP90Id4d+QxY164vpapHyk46gdyMcyXJGGG7eDvSfODbcis36R7s8pT1axH5dUO5/P60VVo23o0jMxpuyyYSlLIbLzNyBeV2HcKabUu3B1PVpcr4Br5pY3K8I4y4MEjSCOVoPxnzxcflXLlDS0GxEHTblvmgz4Q7qQ4JmDV0f1OiSScDtajORSroMsQpbu3LmNgoZ4ZuwwVnbUUdEwlfTKwrrGyOiFNhV/LoThrl3Tf0DS0k/nW8P5wof8BU0eTZjxPZ33p8OkruifGNTz2L2vdXnbws3jAh0lUaP8DBwMNZFGD72Tt1OIiZXQv3/y0r5xatya17cusIyOQ6Udq+jF5LnSZN+Jc0/yIBbmPvX0vLf9Zlfn98MMjlaWAKAfs3Uk1vSZtHohamRmk7aypxmqBYLsMz8a9ssY/anssvmT96vXNAxqZc28JRyraXh/c3ubBQMt+q5WmL0198nw5j2dyEt104M6Tr7n1/SLP9i7PVo6LhVFZ+wjJkIZ1k9ZodjEzM6T498JxHWnDFBArWzv+5GM9LnT9xHzPNiz5q5CTwXW /Ltj+FdD HC/JFqy0R2Q+3kbUX8fYdOUP4wuvmryZezOouXWI9QAPcL2e9/naES+z/aLpCR823dEjUemNQGqtUNOuhthyrEFwaoaI2OEc3UPKNAxtiVTxry4e+Ej52cmqfg3NJM5I4ojnczmTpSX8h+RiuLJcza0SNIGuixqtpzzqBncFWChG/7U76rCDh0ECHYE9Id7YMyLmC4dNrxaqHghEMZApr3aFieA== 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: This indicates if the system supports POE. This is a CPUCAP_BOOT_CPU_FEATURE as the boot CPU will enable POE if it has it, so secondary CPUs must also have this feature. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Acked-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- arch/arm64/kernel/cpufeature.c | 9 +++++++++ arch/arm64/tools/cpucaps | 1 + 2 files changed, 10 insertions(+) diff --git arch/arm64/kernel/cpufeature.c arch/arm64/kernel/cpufeature.c index 646ecd3069fd..2daf5597cd65 100644 --- arch/arm64/kernel/cpufeature.c +++ arch/arm64/kernel/cpufeature.c @@ -2870,6 +2870,15 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .matches = has_nv1, ARM64_CPUID_FIELDS_NEG(ID_AA64MMFR4_EL1, E2H0, NI_NV1) }, +#ifdef CONFIG_ARM64_POE + { + .desc = "Stage-1 Permission Overlay Extension (S1POE)", + .capability = ARM64_HAS_S1POE, + .type = ARM64_CPUCAP_BOOT_CPU_FEATURE, + .matches = has_cpuid_feature, + ARM64_CPUID_FIELDS(ID_AA64MMFR3_EL1, S1POE, IMP) + }, +#endif {}, }; diff --git arch/arm64/tools/cpucaps arch/arm64/tools/cpucaps index ac3429d892b9..eedb5acc21ed 100644 --- arch/arm64/tools/cpucaps +++ arch/arm64/tools/cpucaps @@ -45,6 +45,7 @@ HAS_MOPS HAS_NESTED_VIRT HAS_PAN HAS_S1PIE +HAS_S1POE HAS_RAS_EXTN HAS_RNG HAS_SB From patchwork Thu Aug 22 15:10:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773676 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 9BA41C52D7C for ; Thu, 22 Aug 2024 15:11:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 269F080034; Thu, 22 Aug 2024 11:11:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 21CB48001E; Thu, 22 Aug 2024 11:11:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 095D580034; Thu, 22 Aug 2024 11:11:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D6D4C8001E for ; Thu, 22 Aug 2024 11:11:52 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 88DDC141597 for ; Thu, 22 Aug 2024 15:11:52 +0000 (UTC) X-FDA: 82480221264.26.21C6889 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id DE361180006 for ; Thu, 22 Aug 2024 15:11:50 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf16.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339420; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OpQ2k58t6nEQbtkgVhwz3rLdStOXjxbUhiBjdUnicRA=; b=0YAlJGFdgjEUG1/xGFDVfKFNCSELfCo6HnnMB6wgYQp+N1awzVWI3TzldkTFCwTrmisjDJ 2bJ3r9RenaOck4Y867keGZN3dh7EJTssHKvsulOUfRDK8EZpB6ekaZVTOZnJlY8TsnIkWx Fm6ia4Wy+D8KhhXmLZjufOoXkhfrStE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339420; a=rsa-sha256; cv=none; b=PLgnpIJFE0WcofprQPuwIRPET1RPOwgnUVO1ijzt8r8lQPq3KtAD1z7tyqlenRm6VIK5Px VmKFt1kS7MCWhY7xYRwK5ti7LxTNeeP3IRv2K9CK0rbNTuWg/WHvCpupAzshNFuXkDDhvO xe64qysfhPE9nohxEZSH2pTZo8tNjE0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf16.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com 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 4605B15BF; Thu, 22 Aug 2024 08:12:16 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 275E73F58B; Thu, 22 Aug 2024 08:11:46 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 06/30] arm64: context switch POR_EL0 register Date: Thu, 22 Aug 2024 16:10:49 +0100 Message-Id: <20240822151113.1479789-7-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DE361180006 X-Stat-Signature: f8ujd1e6dxs79y9qgi4a1uekbzje64yr X-Rspam-User: X-HE-Tag: 1724339510-528824 X-HE-Meta: U2FsdGVkX1+3lUHLPhZSPjrqZ3fPOCb8xXg6T89+tFGbJ6LokyMuOQLsWy/QvVPp8QtwNMDOaGPQpBs0lv8nSi2aT9+HQB6wFvDdXa2BxQRYY3VvavzozFOpYZyW3gqUVY3zYgLnvxs9ZSig8WdOkKcHKZXKxSIOHkKkois+rFj4GI4gs9l3IsNm1TNdAZ+jppKR7PoYh8+b4fnZ6Nj3kRnyRxaDYVixBU5Y7bWMBk8xEHnUfmVzv1Eg/02gxIBCwocgbXUSZ9gfa0T+DSM5ko56XJ3Nx0aLY0tZDvzo4cJf8VVyGdscFAxk1EyUOY6J7GW2jGeKNk+nfcZ1+UzL4ijOEvOdLa7pdnu9aakwTLxBaKK6z2521Wk05ayRZ5P624Tn+cd4jf8TOVZjZVI3mspSyg3JtLyG/61LO3axIUtHZDWgOQ6J8WJLwYuAp4xBxFg6PkNjxsRks4pWdw2WEbj6q6TZbF4tfgScGoFT1dz1Mem9nNWaB0xcxlt6c1DAF5MT4qMY6Kur8yRkhxayRwd8jC+VCtlmnGAUEG03ztVDA4fSt3ASNR8FPo/dInY5oqa4JJ4UdkBPvzuujdX8i/IPmSPw7tNFQ0oL3YOchf7g+WjEK4ys3JZo1630i2lSTpjkFlYqlXo3EE7dwzZVLtU58nn2Z2Yl4GBk1yF7qHYEcjMUKz4ERpTBtLQBiHidFCTeZ4gtc7Caz82uepuICk12AQMYUU+aytr3WwP0sUB7fnxjBxBayKdVyh9ifw+66DFep048yRXkhhNvw8+9kknVBqxVQFzquWxZMptinVUMLSoAYNNVNdeVqHbjbHwgZ0D8Dw7LCP1inEAlDv2T+c3b/7HQkGdrPo8n+dlqN+2z+aZ5GvudDF/CSrnu7sT7i2n/IvI/b0ZPG36n5Ra9zggG+Uedx28njUla9Jx5tiSs3ANsksd+4X4VMCK5z79s/iJyWWXGle2b2mQ2ztj yVRsxw/D qTUZ8OsOZAwKYy6yZ3uOHSDbOTaFOQ86tZDl674X86/GIEeF9xk02jLt8zAV5Lk9coEeMzJjafj2yZIJW3Gp5ifdoD/Trcs+r+bVIu/sfmvblEx8obDQtnZErPfKNjUxB0raCOKJwde8/KD61RJ9DQgBh290yffRvC22EmSooVE6/J+VQR7MH4Vo045MHIkpggYIHNVqCXwDC5neKoJ7bxiFLQ8Ydg1dWV+66tDk6/CqvPeFJixt+Iyye0fY0njk8yZNs38BX8JjHwMM= 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: POR_EL0 is a register that can be modified by userspace directly, so it must be context switched. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/cpufeature.h | 6 ++++++ arch/arm64/include/asm/processor.h | 1 + arch/arm64/include/asm/sysreg.h | 3 +++ arch/arm64/kernel/process.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git arch/arm64/include/asm/cpufeature.h arch/arm64/include/asm/cpufeature.h index 558434267271..3d261cc123c1 100644 --- arch/arm64/include/asm/cpufeature.h +++ arch/arm64/include/asm/cpufeature.h @@ -832,6 +832,12 @@ static inline bool system_supports_lpa2(void) return cpus_have_final_cap(ARM64_HAS_LPA2); } +static inline bool system_supports_poe(void) +{ + return IS_ENABLED(CONFIG_ARM64_POE) && + alternative_has_cap_unlikely(ARM64_HAS_S1POE); +} + int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt); bool try_emulate_mrs(struct pt_regs *regs, u32 isn); diff --git arch/arm64/include/asm/processor.h arch/arm64/include/asm/processor.h index f77371232d8c..e6376f979273 100644 --- arch/arm64/include/asm/processor.h +++ arch/arm64/include/asm/processor.h @@ -184,6 +184,7 @@ struct thread_struct { u64 sctlr_user; u64 svcr; u64 tpidr2_el0; + u64 por_el0; }; static inline unsigned int thread_get_vl(struct thread_struct *thread, diff --git arch/arm64/include/asm/sysreg.h arch/arm64/include/asm/sysreg.h index 4a9ea103817e..494e9efd856f 100644 --- arch/arm64/include/asm/sysreg.h +++ arch/arm64/include/asm/sysreg.h @@ -1077,6 +1077,9 @@ #define POE_RXW UL(0x7) #define POE_MASK UL(0xf) +/* Initial value for Permission Overlay Extension for EL0 */ +#define POR_EL0_INIT POE_RXW + #define ARM64_FEATURE_FIELD_BITS 4 /* Defined for compatibility only, do not add new users. */ diff --git arch/arm64/kernel/process.c arch/arm64/kernel/process.c index 4ae31b7af6c3..a3a61ecdb165 100644 --- arch/arm64/kernel/process.c +++ arch/arm64/kernel/process.c @@ -271,12 +271,23 @@ static void flush_tagged_addr_state(void) clear_thread_flag(TIF_TAGGED_ADDR); } +static void flush_poe(void) +{ + if (!system_supports_poe()) + return; + + write_sysreg_s(POR_EL0_INIT, SYS_POR_EL0); + /* ISB required for kernel uaccess routines when changing POR_EL0 */ + isb(); +} + void flush_thread(void) { fpsimd_flush_thread(); tls_thread_flush(); flush_ptrace_hw_breakpoint(current); flush_tagged_addr_state(); + flush_poe(); } void arch_release_task_struct(struct task_struct *tsk) @@ -371,6 +382,9 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) if (system_supports_tpidr2()) p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0); + if (system_supports_poe()) + p->thread.por_el0 = read_sysreg_s(SYS_POR_EL0); + if (stack_start) { if (is_compat_thread(task_thread_info(p))) childregs->compat_sp = stack_start; @@ -495,6 +509,19 @@ static void erratum_1418040_new_exec(void) preempt_enable(); } +static void permission_overlay_switch(struct task_struct *next) +{ + if (!system_supports_poe()) + return; + + current->thread.por_el0 = read_sysreg_s(SYS_POR_EL0); + if (current->thread.por_el0 != next->thread.por_el0) { + write_sysreg_s(next->thread.por_el0, SYS_POR_EL0); + /* ISB required for kernel uaccess routines when chaning POR_EL0 */ + isb(); + } +} + /* * __switch_to() checks current->thread.sctlr_user as an optimisation. Therefore * this function must be called with preemption disabled and the update to @@ -530,6 +557,7 @@ struct task_struct *__switch_to(struct task_struct *prev, ssbs_thread_switch(next); erratum_1418040_thread_switch(next); ptrauth_thread_switch_user(next); + permission_overlay_switch(next); /* * Complete any pending TLB or cache maintenance on this CPU in case From patchwork Thu Aug 22 15:10:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773677 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 21986C531DF for ; Thu, 22 Aug 2024 15:11:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85D1D80035; Thu, 22 Aug 2024 11:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80CE38001E; Thu, 22 Aug 2024 11:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AE9680035; Thu, 22 Aug 2024 11:11:57 -0400 (EDT) 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 4D2DE8001E for ; Thu, 22 Aug 2024 11:11:57 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CF743A1747 for ; Thu, 22 Aug 2024 15:11:56 +0000 (UTC) X-FDA: 82480221432.22.44C94BC Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id 2CC548000B for ; Thu, 22 Aug 2024 15:11:54 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339433; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t/GyyKQjhnvuOt3BOc8RNJrfkkM+4199Rp4lYae/2nQ=; b=IYI07wjPdbycC6rBNMHolk9uqBmtotsDT2DGuzKm61/hRvMEJfSTP87E4kACEro+ujKE4T NvHVzNnCJhy3KAHTB81oFBmXw6+RVOfxKLPxGlG0VUpsmRulwpPQ7tBzzkHYoPEEr/aDVu qBuwYk44JUoKvZsO+Qw9pF+nagiXhKA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339433; a=rsa-sha256; cv=none; b=5zsLL32ZYBRfrAGRbsEBpI+8e2iaa35bkZz0z0+HIWVmyJkgxYB+wNrdtCqmITCk9Z2Wal 7JERFXSnFnzq2Ww3IwbT1AUFwKpBaBQZebgqzoYzatZYvCg+6Ird9ZT38DFh/7YCqA0rLr oEr/u+a6db6d7xQhixsjncC7NE0wQsY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 955EA15DB; Thu, 22 Aug 2024 08:12:20 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 76AB93F58B; Thu, 22 Aug 2024 08:11:50 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 07/30] KVM: arm64: Save/restore POE registers Date: Thu, 22 Aug 2024 16:10:50 +0100 Message-Id: <20240822151113.1479789-8-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Stat-Signature: szhf1xnoihpqizyx5sowag7ocjp3f53z X-Rspamd-Queue-Id: 2CC548000B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724339514-789244 X-HE-Meta: U2FsdGVkX1/bnF39IQO17ukBRBnBw9rdJv3Ut/61/Bdle/A8p3Bz60eEl+zJ6HL+U8A6CBgHwTz13OU/ra+lXK3yWVXGDa58oY/BOPLosAgRJ0RPoA6u8s6S0M9COCj/JFGcfA86LCh10Oxd3MTTQKhYkxMua1RUVBhaoEk2aeihewRLj1dL7ezgTqWY8gjVXr0YQgNbVp7yACs7mVMRqfaat3kvPJfvJD2obZnBsAWbbi3/k88D+j1Lv9IBnzkZ37acrXbGc9uiwR+iysvf8HfxWbJl6GL615i5hZN58XRuB5yPWccmFip6O7lfzNEuvylWA0bzeRCqivZBFOg0Y9hJQLPQ+op44AaaVqH9WppUfPJugSqJwMNCA8rA7K3l+Ti+YGTsQchUyKXAh6BDI1/HS+Fy9hk8Bjfm6iRMjWem9lPh8Bfdvk7ObdoCkwEwn9Swtw6mNkUrTDiiIJDB2f2kmVFvIuue5fbTwGnpOqMn/r68hf3Q+bjb4zzGduLOeRvx+Zo/u95PNoRU29KtEGZSLYxuXv+FRlme4sGDeNUri0zke+YS3tbv+D977Knf7hLaVZVe/A6o0FVt7MZQ7W5gcPgeNHAlMUwzRBqtPF6J9tKoAKIUwulVN0BiIWlOKHBfw+9TFFuU3fPQHzbk58aDFqbKc2envGp0d/V1yRw1ncs1DwpqHTyKgwgO8Ye2mW8wq+18b3q7+xyx1qC3KHh5V/heX7uskxDGie7eCq8qPEJzEQuV130Rkd/cvkA5CvV0+TBuA7ECp7ruR/p/DDYNlg1cuptee4HzFcMW+9L0lSek0zxki2h+P4v1wJGWbEqExqk3BB2VrKnl+Mb0sYhNVuKVRO1FkNVGjDMbvW6tDzvrv2oK+g93crSqxZUhdDItbQ6bVExWZ6hvRQXRHqeqZ7jEKwEro0pSyODiw3JxhdKv9puSrT2xjAzj1B9VKeliYgNvcFGuE6fGNXj +kBFSQUz AIaq7EUpIEMlilSLN5BfwurbTpg5E+F2hXKvrOaOJ+TLNpX7EX/JbN+CfsPlKDRc++mctv2tbKMKdTgp0mo0PFW+D5wDbuSSWcsjxB/0U/T4sZvvIrrtuTPr8qxuUodwB9w3YRerysazdrQ8DA6ikveHgIrJZ9CUfqiis8velx00HmvonhUsMbKilWferLzyoSJ31PvrS4IvV9cQhRLz7eoB4uQ== 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: Define the new system registers that POE introduces and context switch them. Signed-off-by: Joey Gouly Cc: Marc Zyngier Cc: Oliver Upton Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 4 ++++ arch/arm64/include/asm/vncr_mapping.h | 1 + arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 27 ++++++++++++++++++++++ arch/arm64/kvm/sys_regs.c | 19 +++++++++++++-- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git arch/arm64/include/asm/kvm_host.h arch/arm64/include/asm/kvm_host.h index a33f5996ca9f..5c9de7692201 100644 --- arch/arm64/include/asm/kvm_host.h +++ arch/arm64/include/asm/kvm_host.h @@ -446,6 +446,8 @@ enum vcpu_sysreg { GCR_EL1, /* Tag Control Register */ TFSRE0_EL1, /* Tag Fault Status Register (EL0) */ + POR_EL0, /* Permission Overlay Register 0 (EL0) */ + /* 32bit specific registers. */ DACR32_EL2, /* Domain Access Control Register */ IFSR32_EL2, /* Instruction Fault Status Register */ @@ -517,6 +519,8 @@ enum vcpu_sysreg { VNCR(PIR_EL1), /* Permission Indirection Register 1 (EL1) */ VNCR(PIRE0_EL1), /* Permission Indirection Register 0 (EL1) */ + VNCR(POR_EL1), /* Permission Overlay Register 1 (EL1) */ + VNCR(HFGRTR_EL2), VNCR(HFGWTR_EL2), VNCR(HFGITR_EL2), diff --git arch/arm64/include/asm/vncr_mapping.h arch/arm64/include/asm/vncr_mapping.h index df2c47c55972..06f8ec0906a6 100644 --- arch/arm64/include/asm/vncr_mapping.h +++ arch/arm64/include/asm/vncr_mapping.h @@ -52,6 +52,7 @@ #define VNCR_PIRE0_EL1 0x290 #define VNCR_PIRE0_EL2 0x298 #define VNCR_PIR_EL1 0x2A0 +#define VNCR_POR_EL1 0x2A8 #define VNCR_ICH_LR0_EL2 0x400 #define VNCR_ICH_LR1_EL2 0x408 #define VNCR_ICH_LR2_EL2 0x410 diff --git arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h index 4c0fdabaf8ae..1579a3c08a36 100644 --- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +++ arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h @@ -16,9 +16,15 @@ #include #include +static inline bool ctxt_has_s1poe(struct kvm_cpu_context *ctxt); + static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, MDSCR_EL1) = read_sysreg(mdscr_el1); + + // POR_EL0 can affect uaccess, so must be saved/restored early. + if (ctxt_has_s1poe(ctxt)) + ctxt_sys_reg(ctxt, POR_EL0) = read_sysreg_s(SYS_POR_EL0); } static inline void __sysreg_save_user_state(struct kvm_cpu_context *ctxt) @@ -66,6 +72,17 @@ static inline bool ctxt_has_tcrx(struct kvm_cpu_context *ctxt) return kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64MMFR3_EL1, TCRX, IMP); } +static inline bool ctxt_has_s1poe(struct kvm_cpu_context *ctxt) +{ + struct kvm_vcpu *vcpu; + + if (!system_supports_poe()) + return false; + + vcpu = ctxt_to_vcpu(ctxt); + return kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64MMFR3_EL1, S1POE, IMP); +} + static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, SCTLR_EL1) = read_sysreg_el1(SYS_SCTLR); @@ -80,6 +97,9 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt) ctxt_sys_reg(ctxt, PIR_EL1) = read_sysreg_el1(SYS_PIR); ctxt_sys_reg(ctxt, PIRE0_EL1) = read_sysreg_el1(SYS_PIRE0); } + + if (ctxt_has_s1poe(ctxt)) + ctxt_sys_reg(ctxt, POR_EL1) = read_sysreg_el1(SYS_POR); } ctxt_sys_reg(ctxt, ESR_EL1) = read_sysreg_el1(SYS_ESR); ctxt_sys_reg(ctxt, AFSR0_EL1) = read_sysreg_el1(SYS_AFSR0); @@ -120,6 +140,10 @@ static inline void __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt) static inline void __sysreg_restore_common_state(struct kvm_cpu_context *ctxt) { write_sysreg(ctxt_sys_reg(ctxt, MDSCR_EL1), mdscr_el1); + + // POR_EL0 can affect uaccess, so must be saved/restored early. + if (ctxt_has_s1poe(ctxt)) + write_sysreg_s(ctxt_sys_reg(ctxt, POR_EL0), SYS_POR_EL0); } static inline void __sysreg_restore_user_state(struct kvm_cpu_context *ctxt) @@ -158,6 +182,9 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt) write_sysreg_el1(ctxt_sys_reg(ctxt, PIR_EL1), SYS_PIR); write_sysreg_el1(ctxt_sys_reg(ctxt, PIRE0_EL1), SYS_PIRE0); } + + if (ctxt_has_s1poe(ctxt)) + write_sysreg_el1(ctxt_sys_reg(ctxt, POR_EL1), SYS_POR); } write_sysreg_el1(ctxt_sys_reg(ctxt, ESR_EL1), SYS_ESR); write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR0_EL1), SYS_AFSR0); diff --git arch/arm64/kvm/sys_regs.c arch/arm64/kvm/sys_regs.c index c90324060436..e7208b59ea12 100644 --- arch/arm64/kvm/sys_regs.c +++ arch/arm64/kvm/sys_regs.c @@ -2255,6 +2255,15 @@ static bool access_zcr_el2(struct kvm_vcpu *vcpu, return true; } +static unsigned int s1poe_visibility(const struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd) +{ + if (kvm_has_feat(vcpu->kvm, ID_AA64MMFR3_EL1, S1POE, IMP)) + return 0; + + return REG_HIDDEN; +} + /* * Architected system registers. * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 @@ -2492,6 +2501,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_MAIR_EL1), access_vm_reg, reset_unknown, MAIR_EL1 }, { SYS_DESC(SYS_PIRE0_EL1), NULL, reset_unknown, PIRE0_EL1 }, { SYS_DESC(SYS_PIR_EL1), NULL, reset_unknown, PIR_EL1 }, + { SYS_DESC(SYS_POR_EL1), NULL, reset_unknown, POR_EL1, + .visibility = s1poe_visibility }, { SYS_DESC(SYS_AMAIR_EL1), access_vm_reg, reset_amair_el1, AMAIR_EL1 }, { SYS_DESC(SYS_LORSA_EL1), trap_loregion }, @@ -2578,6 +2589,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { .access = access_pmovs, .reg = PMOVSSET_EL0, .get_user = get_pmreg, .set_user = set_pmreg }, + { SYS_DESC(SYS_POR_EL0), NULL, reset_unknown, POR_EL0, + .visibility = s1poe_visibility }, { SYS_DESC(SYS_TPIDR_EL0), NULL, reset_unknown, TPIDR_EL0 }, { SYS_DESC(SYS_TPIDRRO_EL0), NULL, reset_unknown, TPIDRRO_EL0 }, { SYS_DESC(SYS_TPIDR2_EL0), undef_access }, @@ -4568,8 +4581,6 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu) kvm->arch.fgu[HFGxTR_GROUP] = (HFGxTR_EL2_nAMAIR2_EL1 | HFGxTR_EL2_nMAIR2_EL1 | HFGxTR_EL2_nS2POR_EL1 | - HFGxTR_EL2_nPOR_EL1 | - HFGxTR_EL2_nPOR_EL0 | HFGxTR_EL2_nACCDATA_EL1 | HFGxTR_EL2_nSMPRI_EL1_MASK | HFGxTR_EL2_nTPIDR2_EL0_MASK); @@ -4604,6 +4615,10 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu) kvm->arch.fgu[HFGxTR_GROUP] |= (HFGxTR_EL2_nPIRE0_EL1 | HFGxTR_EL2_nPIR_EL1); + if (!kvm_has_feat(kvm, ID_AA64MMFR3_EL1, S1POE, IMP)) + kvm->arch.fgu[HFGxTR_GROUP] |= (HFGxTR_EL2_nPOR_EL1 | + HFGxTR_EL2_nPOR_EL0); + if (!kvm_has_feat(kvm, ID_AA64PFR0_EL1, AMU, IMP)) kvm->arch.fgu[HAFGRTR_GROUP] |= ~(HAFGRTR_EL2_RES0 | HAFGRTR_EL2_RES1); From patchwork Thu Aug 22 15:10:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773678 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 73589C531DF for ; Thu, 22 Aug 2024 15:12:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 095DA80036; Thu, 22 Aug 2024 11:12:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 045608001E; Thu, 22 Aug 2024 11:12:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E016B80036; Thu, 22 Aug 2024 11:12:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C0AC08001E for ; Thu, 22 Aug 2024 11:12:01 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 692D34064D for ; Thu, 22 Aug 2024 15:12:01 +0000 (UTC) X-FDA: 82480221642.21.2E88DF5 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 9B4232000C for ; Thu, 22 Aug 2024 15:11:59 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339412; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LhhrQ4+z6yOEiKUoxQMrbV+q630Q9+dPEjR6MmHWyIE=; b=EZjlvYliDl3VXTEX78irKqKi7numQFJIAlz/DoIhW4FtbZRi7XKGdAIxn0SvIeYRBxqiZ6 k5+d9S3prBJaEoD4OhlWIRBx5MASfnLM6tYcYr22O+luGWSLFL/Z5cOolGufnZm7uN1Gj3 Uu6rRwvLgZfwEe9Sem3gcOHKBFioNRI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339412; a=rsa-sha256; cv=none; b=IIfeGM5D/rXsxGHshhc0ms8X4Ce6cPIsU+PC1WSrQIXuZkN00Grnhoo6noVbwfqEN0NJdV 2wUBYdY9FFLcO6H3fyS2Q3Z7U+pLiz4cH+nQgQ3sA+EYXiVVevgGTaz8IkJjMSrSwEnvR2 4LDudSeOIjClnrr/LHO78fdO7Yn4UIo= 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 E3E751650; Thu, 22 Aug 2024 08:12:24 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C53D43F58B; Thu, 22 Aug 2024 08:11:54 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 08/30] KVM: arm64: make kvm_at() take an OP_AT_* Date: Thu, 22 Aug 2024 16:10:51 +0100 Message-Id: <20240822151113.1479789-9-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9B4232000C X-Stat-Signature: 8ujp3uw18t8dewwpadeni6ndadxppn83 X-Rspam-User: X-HE-Tag: 1724339519-380954 X-HE-Meta: U2FsdGVkX18Dly3DRGLHgVR7XKVWUDztOTNcPglPPqcOedjpVp25ES9A80aVivGoRuWbtMzGeFz+JAYOCuL8h8v0uVNtkJW+XCUNidQSwFFx2SxYvG1MaqkNas8iRyVhQ/WN1oiH3L8h0EHgjlBPk2vYq2yAP9xgeGpC1l8ImQNlVxrr6wOcRZD9GwnEz8j2SqzwnPjcYIHlcYwxJYbPOhu33F9IF5ILsAx8gtLP6ALyPZrudo0WDA4Iy0BXkW1yRFvC2NTmGDDcRfvpb1tZuqsKACA8gxXPrpwa/54nmphe7mkgWUMZHBDGe2Hbh7bVHUq2BqgX8jiyd9rPjAYYcN4IfNqpnQXWG2QKPUOj2kSqXgBSz3s8SwoiMqgfGyT/JnlGcA9qvhooYh+sSRU785A377h5oVIlu3jVy/+OBlZ5WceTgxOSnL0EP5qjVN3LU2jMTQja8H5MNTxxVXcNh8YEWrjwXoLamLOx/bPmDVhV/GvmKWcfARpppsNGUsUXNq8sIm/pcrtwBPAKg0PWKWE6/BZnKGMnRBtFJThr6YKtAMyyQOgpWRd36z/y2ptbVfUaaCQ5X7TjftJsk/ofFR0tlOYfuJjWyVMNLOktx0EpjBiQ+3izkKDVJ/fbWaP1MQk8GTTNrtDpmGCW6TC0kEjcD8Ia0Jw+bLiB/BYD1M30p/zvRnccWNdOJn0BltUc26A7pk+0P3hFzey3VT+HewHiWDFEyvSVRlZDgPR7UIITVB2x1O2gOZztXneZtHGkOLkJ/yATdsmKVjdjdNKJUyZtIO7rVlv2ZB5XDbHfNR7HiVo4vsrwQU6TZ1bnrtMkx4G3lbPNR4gPEBvc6wjUzelm05l15cn5IcItWapR1OSnGbvjM1wAsRTVI7XkvuAzRbg3l3m9e67PnOSWvkwneMjM3OuCY7ZjJMLSBGgaA/2x1UiYHDb061gps3GOn/wFz/ERS/rwZoh68gOHO/P Nx/Vxu6A 4pisOAwNEDNEKMAnxvsPFJDR0m/6XU5YcB4iecgpeiDK6hs25uW+8lw1862QTdQPPPTUFQV+k9FyvHxHJJyi4W2F9wM/MuC3UVXV5OaptqIVHJI4rphsvZeWO8crnabM3cs94R6ZRpVbblkQQ7gimbYCaxTMeO4qYlZSjyP3TKmwh5lpml7+GxVYr573UsigNTOm0Ev6Xd3DTlvNn7XGC92VSmjHeAr6r9kq3ljGQVV9G2Zc6keUUNWDwqW8MnzeGn0Sh/Hvj/dnYO1A= 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: To allow using newer instructions that current assemblers don't know about, replace the `at` instruction with the underlying SYS instruction. Signed-off-by: Joey Gouly Cc: Marc Zyngier Cc: Oliver Upton Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Marc Zyngier Acked-by: Will Deacon --- arch/arm64/include/asm/kvm_asm.h | 3 ++- arch/arm64/kvm/hyp/include/hyp/fault.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git arch/arm64/include/asm/kvm_asm.h arch/arm64/include/asm/kvm_asm.h index 2181a11b9d92..38d7bfa3966a 100644 --- arch/arm64/include/asm/kvm_asm.h +++ arch/arm64/include/asm/kvm_asm.h @@ -9,6 +9,7 @@ #include #include +#include #include #define ARM_EXIT_WITH_SERROR_BIT 31 @@ -259,7 +260,7 @@ extern u64 __kvm_get_mdcr_el2(void); asm volatile( \ " mrs %1, spsr_el2\n" \ " mrs %2, elr_el2\n" \ - "1: at "at_op", %3\n" \ + "1: " __msr_s(at_op, "%3") "\n" \ " isb\n" \ " b 9f\n" \ "2: msr spsr_el2, %1\n" \ diff --git arch/arm64/kvm/hyp/include/hyp/fault.h arch/arm64/kvm/hyp/include/hyp/fault.h index 9e13c1bc2ad5..487c06099d6f 100644 --- arch/arm64/kvm/hyp/include/hyp/fault.h +++ arch/arm64/kvm/hyp/include/hyp/fault.h @@ -27,7 +27,7 @@ static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar) * saved the guest context yet, and we may return early... */ par = read_sysreg_par(); - if (!__kvm_at("s1e1r", far)) + if (!__kvm_at(OP_AT_S1E1R, far)) tmp = read_sysreg_par(); else tmp = SYS_PAR_EL1_F; /* back to the guest */ From patchwork Thu Aug 22 15:10:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773679 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 04DF8C52D7C for ; Thu, 22 Aug 2024 15:12:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63C2780037; Thu, 22 Aug 2024 11:12:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EBB48001E; Thu, 22 Aug 2024 11:12:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4655E80037; Thu, 22 Aug 2024 11:12:06 -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 1711A8001E for ; Thu, 22 Aug 2024 11:12:06 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B0B22C1730 for ; Thu, 22 Aug 2024 15:12:05 +0000 (UTC) X-FDA: 82480221810.02.4143CCD Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf14.hostedemail.com (Postfix) with ESMTP id F41D1100027 for ; Thu, 22 Aug 2024 15:12:03 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf14.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339464; a=rsa-sha256; cv=none; b=nW09kYfm8k+ssY7ijdDi4Ahy6G5qSZRH68Y3pcARwvQt2kSu9m8yNO9HAPVqWDsBRhQ/jq cJ61E6kAjdX5EH9XSEt6iTcWvHBaBBzFoRF4jJuR2jc9Kdfx19elNaNTBSnlp1DTDGKtfM kdgIF3Y4d6Xc4AocOKHURF8Lsc1bGQE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf14.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339464; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tGPcTPPfKkSGaPcxenC1uehrGC+VQwOEc7ex5Jc/eTc=; b=iMt4goT1av6NNap8PqW05C4m4Zw45mV0Pv5VGMG2SuizfKBpnxGF9jrNLrSsJJrB4S7j3H m35E6FbrWXeI2+JzHBaIAKaFLL4QDN9KyqQ+Ekjg+0pAshBJzKv3mc7UPzL6Urfvv27Hro N0C4DPeLyrw9Yt/0X3BbXov8SJkUCSk= 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 5A265DA7; Thu, 22 Aug 2024 08:12:29 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1F69E3F58B; Thu, 22 Aug 2024 08:11:59 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 09/30] KVM: arm64: use `at s1e1a` for POE Date: Thu, 22 Aug 2024 16:10:52 +0100 Message-Id: <20240822151113.1479789-10-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F41D1100027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ksjpb7nphidipmyi3g53m97mua661ycs X-HE-Tag: 1724339523-162882 X-HE-Meta: U2FsdGVkX188p3ubN8aeUXYXoPWhtB8orswhw6FZcB59GZ4kVW1fkfjRNxqtuZFz5zQD3zPywqVs2p6HEPhSco2vJYROPk+CK5mc052SmvqWTN4aPJA9vkEdDBDUHMBVhCwCi3Kq+Z4kZSGKH2rDC52wzKQAYD0hkOuTmP0A9kyXfApnhFuECiehK+ydljaGZYn775Pp24Rzh1OyRaCmGdawZYJER1/JjRxoBbgNhYZHGey9rNjD4NeDJZwOcfCpzvuqp6rnkG7XHjSgTBbYW1/AyqWFc1Rm5LgxbP+M3rJRBH42pWVR0g+E07gOGncgylpYDZIAWq7z0PSS6n9k8A5L2oAQK3HTa6kGi23KV8YzYgHiVihSP27IV4sJfXgDfQ+Y5tYS2408gLmcA5nA+8GJ9+yAC7iS9Pbmh9KqpmLHW+FIu0qlqF5NoNOmxMz8fZdD2wWqIiySTkNGreoJ4l+y3tpiWV8tnA07zfGvuxEYLFnzWqeBXFw0jUk4f9bgul9rvMAsfmQszwHhlA9kYw20GN+e8vdy45PVu1/7+8nJUzDdkQpvSuGua+wKv9Yc/nAGt3XYQfaRrV9Kgj0cbScAPckc0vBsWwJf9gEkVhDfUvynEkmw2m6i7Py0QZOXOnYwF/p6ZU+tIXn2ea6u/er6QUMTWEKJd5UqLp2AMi3DnDLtDw4hz77hI0X3jf4tuA0x/RPhplC98SggFPJ34y3OfAvdZhEi7ET4I7AebpIsrUX2eEoS6Xe0JvKJ8UiB/crHh4yzXVJyKjlpXM/xdgufcz/+i8VUzm78CYFkHUmbfKB/S8oWTZN9SGa+rQ+F434ZKIAKNZQ153JuLFmhbuRRODAwOfzi2DjZS/6jfYJEWRNVYbDf5YGymQPXOfU1gmHO7SGCPLQOidNdvV3Q8ZtUOWcsy9wLPm3ckoNjUjUvBDiP5XGI8vzPpa4xFSG5/fNKhqH3EVhR3TzpA4+ peeD/lEs E5/ffeOPGUktfh5fpca5TRnrDfH4BMBlGp/J1gkByLduPV4gXPv9tbJ3S4jxtEiCxFW+4xV0RncdjLWnMpYy1LGJrIxuBXaY1AD96Izv3HvOTUQ9wCksmi7q65XC7oJbgbvwBQ49+at87wUaeqSlVwKqDMe6mMvxynn1TX0slf0yrdglRg/rv9YJD6EggnaPnd5ahAZdO9Qzi/VMtBUD4uO8zoA== 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: FEAT_ATS1E1A introduces a new instruction: `at s1e1a`. This is an address translation, without permission checks. POE allows read permissions to be removed from S1 by the guest. This means that an `at` instruction could fail, and not get the IPA. Switch to using `at s1e1a` so that KVM can get the IPA regardless of S1 permissions. Signed-off-by: Joey Gouly Cc: Marc Zyngier Cc: Oliver Upton Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Marc Zyngier --- arch/arm64/kvm/hyp/include/hyp/fault.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git arch/arm64/kvm/hyp/include/hyp/fault.h arch/arm64/kvm/hyp/include/hyp/fault.h index 487c06099d6f..17df94570f03 100644 --- arch/arm64/kvm/hyp/include/hyp/fault.h +++ arch/arm64/kvm/hyp/include/hyp/fault.h @@ -14,6 +14,7 @@ static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar) { + int ret; u64 par, tmp; /* @@ -27,7 +28,9 @@ static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar) * saved the guest context yet, and we may return early... */ par = read_sysreg_par(); - if (!__kvm_at(OP_AT_S1E1R, far)) + ret = system_supports_poe() ? __kvm_at(OP_AT_S1E1A, far) : + __kvm_at(OP_AT_S1E1R, far); + if (!ret) tmp = read_sysreg_par(); else tmp = SYS_PAR_EL1_F; /* back to the guest */ From patchwork Thu Aug 22 15:10:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773680 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 2322FC52D7C for ; Thu, 22 Aug 2024 15:12:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA8A580038; Thu, 22 Aug 2024 11:12:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A32098001E; Thu, 22 Aug 2024 11:12:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8854D80038; Thu, 22 Aug 2024 11:12:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5927E8001E for ; Thu, 22 Aug 2024 11:12:10 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C924EA88BC for ; Thu, 22 Aug 2024 15:12:09 +0000 (UTC) X-FDA: 82480221978.02.2BC1413 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id 2330480024 for ; Thu, 22 Aug 2024 15:12:07 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339462; a=rsa-sha256; cv=none; b=eme8nVBDi16XmW8sE+O2IxSoFMy+fjkU8fhaHM/lIEJJSbe89puCjvAfJ9oGqSvZHg+Tbs IrflTDzpT268dYVw2QtVmxaKcms+MLYykLmnKsYzf1XmF/ld3cj4H0p3KHbewIRgW5Giyu Ee1XuSoYJxWS4R5JGUg8xBLbH88ye9s= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339462; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lhYPnmIy9QUOshqY63sjGUWSg8MXgpvHQMLfdS0GHX8=; b=j6NDX7UisNC6A4O+5AQeLzkvi2G504+XOVA2lO/0J9YUFucIZlUR94K7O9/JmkkACfkYLz UqrgoOTw2//m+YqS6wP2ExOt6TosHUx8/q9xdZ10LGuzuh3MgwyqxY6UjLYrH8//GUGMBs 8SfuAl4VQseenJPxBtr1/9mTHVuksNk= 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 8BA89FEC; Thu, 22 Aug 2024 08:12:33 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6CF9D3F58B; Thu, 22 Aug 2024 08:12:03 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 10/30] KVM: arm64: Sanitise ID_AA64MMFR3_EL1 Date: Thu, 22 Aug 2024 16:10:53 +0100 Message-Id: <20240822151113.1479789-11-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2330480024 X-Stat-Signature: k557duntggfx4ge35zbewjejhr3dgci7 X-Rspam-User: X-HE-Tag: 1724339527-947463 X-HE-Meta: U2FsdGVkX1+zltUU1VR8Drrd/Xt85XuUrqpL9cSfzzj1cAqvCcnGNS2lntaYcmcr7dySB8I1Yv2bjlEo7nHvlHaImhskM9U9GVUM/hed8gzmxk6K0zsBtXuxZhN5D0RENkZEQVU7aIBYcFwx8sT1b7PJnTYVtOGeYJPI0mP9ICMtwS6/IM2MQFzRi+uepGgyeTMG6DlfeCs/Ts9XBGDpODlwBeY3vZ/ahdfmVuIFZeO9Yf9qi20FnzOpPOox5J4IJPqnh2EAtioOPkzsH+ZzBbkrhbFU1SLBiInWsVQWZWv3gzgqO4nIbqtX2omyqZr4fm0KJTbullrD7s7pyq2cHiPEmJ3TLHdTDdxKKi2e9zHUPBo0pFqE/noKasAiSEkB8t16huCLaK+pADo5MI2GdXjuMQiVJ3TyVinm8ihzW7tda3tu2O0yN7K0iq+6JnKvDw6xWRcBMz4Q2Du2pokAWOz82H71FosIQmOHq7e8DFXCeK7LLN/e7wdq1lnLgJoPsGJf9tOap8zP/bcXb3FvaNQJwsiKxJaimZyq+hgqblpPOyRE3iP+2AufTPX7T+4fQ8JljgkgrsMMV3NinfhnQeBETAQ8DToY43b09TftDeQqkxdu0dF520zt7NkwYsvuyxxx2yj4kIzhql5gecTI63C6pzest871wJ4QjjxWfYG0E5o+DxnDHudMf05dC32C5YnY5uJdAmseIcjpPb21N7uBr66tplK+56IgHxwUwRbsddGeThW5u5UfqFyZtTLK/iQj2AmD0xljtA87Mv6BAdChMDYyDgP9IsDzrNPgdZlwgi96un5SynqIM9ivS7Oh8/n6DpNcyFPaemKTYOFtZOrdyFLeJE6ldPePctx1OPlBRTcgOzza+DRdyEHEFARq03MNoJrB0uodH9jePE8CUd3Rebe/wY5oYy5ty0JD8Rc6O0cdLggoHqGL39cu2KKxizQWs8/Wpnhx9vG5fUN eJNXt26q puNIqpOkVQk/H35rEG+tdgrAoiCQXm4l/Lxg0yCarigTMUf3GHGwNtPfha8Iu8umOcvRhjmyiyLvzLtyas4jW/j5tkvegomMetYAnVWs7IA5YvthBKLXmqEtWPXqWjoZS3auxC4nFvdaF4Wb9IN41Yk0ini6Ok8xayurWHx/rWTFY1w6Fs1hWB604KdCnqutB3vqLTq2nlNcFAxYn6uepC43Aq24kOZRgOGARid/92RdcwjuTSDm72zxyw7m6ATKo75Wc5dNAtLek9cM= 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: Add the missing sanitisation of ID_AA64MMFR3_EL1, making sure we solely expose S1POE and TCRX (we currently don't support anything else). [joey: Took Marc's patch for S1PIE, and changed it for S1POE] Signed-off-by: Marc Zyngier Signed-off-by: Joey Gouly --- arch/arm64/kvm/sys_regs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git arch/arm64/kvm/sys_regs.c arch/arm64/kvm/sys_regs.c index e7208b59ea12..0f13378e761c 100644 --- arch/arm64/kvm/sys_regs.c +++ arch/arm64/kvm/sys_regs.c @@ -1556,6 +1556,9 @@ static u64 __kvm_read_sanitised_id_reg(const struct kvm_vcpu *vcpu, case SYS_ID_AA64MMFR2_EL1: val &= ~ID_AA64MMFR2_EL1_CCIDX_MASK; break; + case SYS_ID_AA64MMFR3_EL1: + val &= ID_AA64MMFR3_EL1_TCRX | ID_AA64MMFR3_EL1_S1POE; + break; case SYS_ID_MMFR4_EL1: val &= ~ARM64_FEATURE_MASK(ID_MMFR4_EL1_CCIDX); break; @@ -2427,7 +2430,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { ID_AA64MMFR2_EL1_IDS | ID_AA64MMFR2_EL1_NV | ID_AA64MMFR2_EL1_CCIDX)), - ID_SANITISED(ID_AA64MMFR3_EL1), + ID_WRITABLE(ID_AA64MMFR3_EL1, (ID_AA64MMFR3_EL1_TCRX | + ID_AA64MMFR3_EL1_S1POE)), ID_SANITISED(ID_AA64MMFR4_EL1), ID_UNALLOCATED(7,5), ID_UNALLOCATED(7,6), From patchwork Thu Aug 22 15:10:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773681 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 4984AC3DA4A for ; Thu, 22 Aug 2024 15:12:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D40EF6B0154; Thu, 22 Aug 2024 11:12:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF0198001E; Thu, 22 Aug 2024 11:12:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6AD36B02F2; Thu, 22 Aug 2024 11:12:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 986D56B0154 for ; Thu, 22 Aug 2024 11:12:14 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5575641837 for ; Thu, 22 Aug 2024 15:12:14 +0000 (UTC) X-FDA: 82480222188.06.DD959BC Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id B1D671C0008 for ; Thu, 22 Aug 2024 15:12:12 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339473; a=rsa-sha256; cv=none; b=jrHCwrue6JCXYT/HC2I5VAO3ewGURcLls8nLTkI/5cU6pkvqMZfVKmWgpLmBkgQUYkdlFr vnhgUfQhHzyrcwr+EzTyvceGPlhuYmoYTJ51PHd9pvyKVRzmQ99EBTY6j3khjdoPqasJdY 51ohqytorxHh2LZ7ndHxMRbDjE5o2FI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339473; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uaX6trArFeDfzKeMq11RpmT+ufgxQad5zCSBp11VlPc=; b=zR2fJstxdCMIw5tjaJBS0egMJL9UZalB9Ss1/tvToqYudiCQ10pxQPnyDFfvOx9BorUVkQ 6MaR8X66lGv3dztnq2H286oQsYjaziRhUKq+e/ylm6Qa8eRVUbpc0Apv0fogxgpvWKC++A epXhOFM28cBtoXoIsowxYQZab5j7nwM= 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 DAB8B1576; Thu, 22 Aug 2024 08:12:37 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BC5FA3F58B; Thu, 22 Aug 2024 08:12:07 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 11/30] arm64: enable the Permission Overlay Extension for EL0 Date: Thu, 22 Aug 2024 16:10:54 +0100 Message-Id: <20240822151113.1479789-12-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B1D671C0008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: s9awuhptgzitazg7kd8wn1hhwmzxawj3 X-HE-Tag: 1724339532-925052 X-HE-Meta: U2FsdGVkX182IPv0kvF2/oRcVsLkElBVWjPdzFyqU0/ELAnwEeLoiCNwc23jdTYq/FJC7odjRZXxI092aE55v9030i7WDe6eBb713eXuKtwGg1AQnZuYZgg5fveTLNKwSc06e/nxXf9PJQiWZ6qYtWOI7zsY3+8SVkFYfi4ZHVROlIJfUuQ7z4843oo/6yNo8jld90SzOMl2uWjvdJS3mmEsaAq3VwN1mE+1PT81bf31KH9vSNOJFp7z2va2bHmsB/oUURNlHYCJoBEehL/CdCMKVFeSv6OOO38v+ddKTGfcSSQ+lGMIheU9Rkln2cbMnh2OPzrH6PIeteoxFrdHtQGI8qwNS7t67Z86gfpLDI2HYrnYzjmE31pr5k1wcWp+byhwokekf4TOyt0w/kPUOsefDcVyLNnUmL8R2CjUotSzUraxAmvgDFYrdnS8HdticBDrfb6c5RPSX7L6RkI7wFxKRRzCg2cdxtOSadB2NzfinvLyYvzxD1QczbelL6aYQZLIIjO5An1ISiqlPhMIT0Iw0gKjOGI5z8ffJ0zO2mPU10HslcI+JTQHY+vfN+mceY57vsPSST+suz16KJBRX3AIRj87kWI6Vxix7yzxF29AvFpU0+6CAEAKkylByJzX2LZE1joC/wozF/QB3v2dlFgqH9dlCHVVHfBs2DzxhB24dkjzSN7hyNo3ltp5di4WD+cfeoFbhiPiFghGsnpoYpBiYuaS9Z/nUbXvCeEeVXMivt0p941jgWESCjhGryHhBaqaxFDQ4B+kblcoYhE4FIyq07EScz8nkPq8J1iokZ3Z+qe1wDQ1wdCEV5uYhE6BC1HKn5tBAayjiXkPQKKDjyPdCfKX3iOXTdNW1+/DT9wxO/30COsATgQh40wYiPouPieDSt9qsR9gcBemDwSNrQldWyZ/+ODcjySuAkb43qd4xRjwdg4IiuzXWHShSC7ZH3qpkWXsD/SI+7adlkW d1SyT2hq iw6OOi6nHRmBVjxBmlDGR+ALiJow9S6pzXAyjYacjHb1yE4AHbAREX5CUYSqARySyd9M/++j0wqCG6vNIvIacoBwz3FtK0od5K9cnr8ZpQlMQZ2FYYeRiAxE9Gx6HM6qsiAByT7lD09CWzMlxsId8ZJhtq5hTFrE5ItqOtpHgkGDfXKUynWdSrXq0ykAhnrHI+qpugUb0IF2JRhNqadNVuo+Sog== 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: Expose a HWCAP and ID_AA64MMFR3_EL1_S1POE to userspace, so they can be used to check if the CPU supports the feature. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- Documentation/arch/arm64/elf_hwcaps.rst | 2 ++ arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/kernel/cpufeature.c | 14 ++++++++++++++ arch/arm64/kernel/cpuinfo.c | 1 + 5 files changed, 19 insertions(+) diff --git Documentation/arch/arm64/elf_hwcaps.rst Documentation/arch/arm64/elf_hwcaps.rst index 448c1664879b..694f67fa07d1 100644 --- Documentation/arch/arm64/elf_hwcaps.rst +++ Documentation/arch/arm64/elf_hwcaps.rst @@ -365,6 +365,8 @@ HWCAP2_SME_SF8DP2 HWCAP2_SME_SF8DP4 Functionality implied by ID_AA64SMFR0_EL1.SF8DP4 == 0b1. +HWCAP2_POE + Functionality implied by ID_AA64MMFR3_EL1.S1POE == 0b0001. 4. Unused AT_HWCAP bits ----------------------- diff --git arch/arm64/include/asm/hwcap.h arch/arm64/include/asm/hwcap.h index 4edd3b61df11..a775adddecf2 100644 --- arch/arm64/include/asm/hwcap.h +++ arch/arm64/include/asm/hwcap.h @@ -157,6 +157,7 @@ #define KERNEL_HWCAP_SME_SF8FMA __khwcap2_feature(SME_SF8FMA) #define KERNEL_HWCAP_SME_SF8DP4 __khwcap2_feature(SME_SF8DP4) #define KERNEL_HWCAP_SME_SF8DP2 __khwcap2_feature(SME_SF8DP2) +#define KERNEL_HWCAP_POE __khwcap2_feature(POE) /* * This yields a mask that user programs can use to figure out what diff --git arch/arm64/include/uapi/asm/hwcap.h arch/arm64/include/uapi/asm/hwcap.h index 285610e626f5..055381b2c615 100644 --- arch/arm64/include/uapi/asm/hwcap.h +++ arch/arm64/include/uapi/asm/hwcap.h @@ -122,5 +122,6 @@ #define HWCAP2_SME_SF8FMA (1UL << 60) #define HWCAP2_SME_SF8DP4 (1UL << 61) #define HWCAP2_SME_SF8DP2 (1UL << 62) +#define HWCAP2_POE (1UL << 63) #endif /* _UAPI__ASM_HWCAP_H */ diff --git arch/arm64/kernel/cpufeature.c arch/arm64/kernel/cpufeature.c index 2daf5597cd65..718728a85430 100644 --- arch/arm64/kernel/cpufeature.c +++ arch/arm64/kernel/cpufeature.c @@ -466,6 +466,8 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = { }; static const struct arm64_ftr_bits ftr_id_aa64mmfr3[] = { + ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_POE), + FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_S1POE_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_S1PIE_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_TCRX_SHIFT, 4, 0), ARM64_FTR_END, @@ -2348,6 +2350,14 @@ static void cpu_enable_mops(const struct arm64_cpu_capabilities *__unused) sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_MSCEn); } +#ifdef CONFIG_ARM64_POE +static void cpu_enable_poe(const struct arm64_cpu_capabilities *__unused) +{ + sysreg_clear_set(REG_TCR2_EL1, 0, TCR2_EL1x_E0POE); + sysreg_clear_set(CPACR_EL1, 0, CPACR_ELx_E0POE); +} +#endif + /* Internal helper functions to match cpu capability type */ static bool cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap) @@ -2876,6 +2886,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .capability = ARM64_HAS_S1POE, .type = ARM64_CPUCAP_BOOT_CPU_FEATURE, .matches = has_cpuid_feature, + .cpu_enable = cpu_enable_poe, ARM64_CPUID_FIELDS(ID_AA64MMFR3_EL1, S1POE, IMP) }, #endif @@ -3043,6 +3054,9 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { HWCAP_CAP(ID_AA64FPFR0_EL1, F8DP2, IMP, CAP_HWCAP, KERNEL_HWCAP_F8DP2), HWCAP_CAP(ID_AA64FPFR0_EL1, F8E4M3, IMP, CAP_HWCAP, KERNEL_HWCAP_F8E4M3), HWCAP_CAP(ID_AA64FPFR0_EL1, F8E5M2, IMP, CAP_HWCAP, KERNEL_HWCAP_F8E5M2), +#ifdef CONFIG_ARM64_POE + HWCAP_CAP(ID_AA64MMFR3_EL1, S1POE, IMP, CAP_HWCAP, KERNEL_HWCAP_POE), +#endif {}, }; diff --git arch/arm64/kernel/cpuinfo.c arch/arm64/kernel/cpuinfo.c index 09eeaa24d456..b9db812082b3 100644 --- arch/arm64/kernel/cpuinfo.c +++ arch/arm64/kernel/cpuinfo.c @@ -143,6 +143,7 @@ static const char *const hwcap_str[] = { [KERNEL_HWCAP_SME_SF8FMA] = "smesf8fma", [KERNEL_HWCAP_SME_SF8DP4] = "smesf8dp4", [KERNEL_HWCAP_SME_SF8DP2] = "smesf8dp2", + [KERNEL_HWCAP_POE] = "poe", }; #ifdef CONFIG_COMPAT From patchwork Thu Aug 22 15:10:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773682 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 BF69BC52D7C for ; Thu, 22 Aug 2024 15:12:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DDAD6B010B; Thu, 22 Aug 2024 11:12:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 48DEF8001E; Thu, 22 Aug 2024 11:12:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3053F6B0158; Thu, 22 Aug 2024 11:12:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0E41B6B010B for ; Thu, 22 Aug 2024 11:12:19 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B35F81216CE for ; Thu, 22 Aug 2024 15:12:18 +0000 (UTC) X-FDA: 82480222356.18.C537D22 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf09.hostedemail.com (Postfix) with ESMTP id EFCF614001C for ; Thu, 22 Aug 2024 15:12:16 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339520; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ypJJJaKGYD4Ov7M2/l/WjUT/Qty4LPf9GxDEXpk7WH8=; b=nOyLoxzcBhsgiRP3BqSGYQkgLIDcm/RjWftsGzxEEKkYUHFhy5T14pDUvv+YZ7cVztYBd0 BjSUELWy3T6acBq7h4Hw7qmxLUawCKbtMmkeUTgzQKs4WAeiqunlPIzh+IaBXZE+3o5nmb RjY2azp9g2XRC5yLDXJBUj3fTEnNz4I= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339520; a=rsa-sha256; cv=none; b=sVUrH3g7PL6FasYnv6WfWylMHseULiGk8ixyBGRbeMe0T+vR5nf4O9KBYsPUHEaig3ExuK W7RxpQjm1zuDP1HMJ1OpH3XiX48brDQ8AFO1+COHb9uH98nRdYgoCpMN7dsYin8o13aUXz m5IMGQHxtsLmbFhXZBo0HiRXLefBIcc= 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 4CCD31595; Thu, 22 Aug 2024 08:12:42 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 167F53F58B; Thu, 22 Aug 2024 08:12:11 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 12/30] arm64: re-order MTE VM_ flags Date: Thu, 22 Aug 2024 16:10:55 +0100 Message-Id: <20240822151113.1479789-13-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: dbb6pthzy49hsrfz1k7cun4yan54d3ja X-Rspamd-Queue-Id: EFCF614001C X-Rspamd-Server: rspam11 X-HE-Tag: 1724339536-719056 X-HE-Meta: U2FsdGVkX19qKFtAtnVDR+3d8EituPpNE7f4esiauZ3SCtQqiwOB0Y4GAm53Vim7Przyuw50Dbdeqhb1XdbFQEoqfOJ/tPFA/ao1gU65KMselpnng8L696nY5NbGZbPjnzNA0hz7lPq5M5JP+sS2oy1hsyeVEDZ9SRLqfJ5StEIn4tLBYXs+njRmz8CCJI+2CpdW7WdeuOecMAc4yaERUJGP/nYTUW6UdyOFGv91IdgjEb+/cYJa1Icrub9BtqOpE1UXmlxfHL/uM44qp5ahdaYy/n84LsdKe9KypWOQ1Z58q48ITf79hg2lwF3obvq7uvXFLA59ie9l24X20TvXQUOeiI53cttFZZXthsv1kzgOfLzD2rcBUGdbQYLQMIW7q72Uvaj4pKW48F7KypX+KK4eqBRJYPfQlW2fy0Np9RHzF08FMqMg0uoA+A2w3UX2nJ5oSHkFyPRmPGVKMBVRvKpH/kQdDSbZAGYIL+jLzYjBZr+F6j+TJgjR0yYmVr2FHZa18MrI3tCt/bXjuyFbrdYwLtVO+sUIHLVGcI4mvtoKlXrZ6GqGCgqdiHNSXBCE5YT9GonnphnBjIqffdBbknU8EcJ8i1BFaB0FNneW1NEiIezd6KrrIFppRrqk7Ku6JUOQiWO2Gs9cNcZrr5edsH24yj4keywPGu+hrWHDH95Uo7qQ//seYbhxRwkJLMe8fClOAT0ldhTPvp0pOVcMQm9K8GP7fVMQviKVN/ARAMvUJN3v+dlcxZ2cuBhok27iruT0vw6f29+u0HzLFbna6yj0Mw2oS4ASEu7CpqEhZZ5qQuyMIY46Pc+Dx+ycARVZvljjWsMe5wVaxTwgNGUeplJeEWFq38m/xS+mIetscca9vS+H46eERHAdGou4qnIm3A4xPUt984ZHkdInsF5rgc1JA+kSVMixEu5oI9TUqz5zsqNfEbrjjFndphwULkfu10rQbKkKJhaU2whUA+t oiShBxgM M3Re0GioVWMWULAqif8SzOae4MQDwEWmK5MV0zXUxpJh1ZXjx2S5rDnSy60D+P1HK8JendFNyT/qvD1b6PGXb3cbzF4DSg/8YyGczobl+UF7guJM2u0YwHkYglTJt2hy5cbVxZ+x7DYuyvxDvRVclDMlZ3ttOywAv0GBFT5OSCuNyiONU3jyrBIxsWKhcP42SatVmDhJJauo992jBrdVENGT7P7d5wRgOd26xqrKWa4qyHulka2kJuANUFeiDRn1KMJumNU7xRwF8Q1bXiz7OG5zYvktVvPKEwQlM 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: VM_PKEY_BIT[012] will use VM_HIGH_ARCH_[012], move the MTE VM flags to accommodate this. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Acked-by: Catalin Marinas --- include/linux/mm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git include/linux/mm.h include/linux/mm.h index 56dc2481cc0f..39e6234e2365 100644 --- include/linux/mm.h +++ include/linux/mm.h @@ -378,8 +378,8 @@ extern unsigned int kobjsize(const void *objp); #endif #if defined(CONFIG_ARM64_MTE) -# define VM_MTE VM_HIGH_ARCH_0 /* Use Tagged memory for access control */ -# define VM_MTE_ALLOWED VM_HIGH_ARCH_1 /* Tagged memory permitted */ +# define VM_MTE VM_HIGH_ARCH_4 /* Use Tagged memory for access control */ +# define VM_MTE_ALLOWED VM_HIGH_ARCH_5 /* Tagged memory permitted */ #else # define VM_MTE VM_NONE # define VM_MTE_ALLOWED VM_NONE From patchwork Thu Aug 22 15:10:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773683 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 E4184C3DA4A for ; Thu, 22 Aug 2024 15:12:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 774BD6B02FA; Thu, 22 Aug 2024 11:12:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 723296B02FC; Thu, 22 Aug 2024 11:12:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59D586B02FA; Thu, 22 Aug 2024 11:12:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 35EF66B0199 for ; Thu, 22 Aug 2024 11:12:23 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E39CBC1712 for ; Thu, 22 Aug 2024 15:12:22 +0000 (UTC) X-FDA: 82480222524.19.699E6E4 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 2D8568001F for ; Thu, 22 Aug 2024 15:12:20 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339477; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R8bZ0HCDMB4Ng+fG0OFOyHWUGs8nbmuYuMVfMre2cG4=; b=ZLkTK/gWj5W7ya/yFn1Q6LaVNA+eXcWwR820Jm7xGjWF8lNESaUPdBLa49v/edsv9g822p Ee1NYQ6exsPhr4cQJvwNzBGT3ibt2Juwi6Aak3/XfNDFQySWo0i/sCFDQGfktGTA3l9Tuz pnqsBMu8ichnduUxgbwhS8rQJpQH/F8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339477; a=rsa-sha256; cv=none; b=bw+ILkHTtbimv9terS3M/A442hfBxXWfazHtnBXUNx8zvkXiqiEOTnNlcBQUbJzYJfOZV/ yxwIfNGIA9IX8S07ZHF7BAgioH8ZEQTBgfqU5Hnz50OCTEgEbsgM5G5FC7KGcw6raohnB5 Kibxymm5tm5NjosbtY1EsJrZBtD4mQQ= 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 830E21596; Thu, 22 Aug 2024 08:12:46 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 64D793F58B; Thu, 22 Aug 2024 08:12:16 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 13/30] arm64: add POIndex defines Date: Thu, 22 Aug 2024 16:10:56 +0100 Message-Id: <20240822151113.1479789-14-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Stat-Signature: cokyyxe5db3f34dfmfa8uace5kre6e3m X-Rspam-User: X-Rspamd-Queue-Id: 2D8568001F X-Rspamd-Server: rspam02 X-HE-Tag: 1724339540-198329 X-HE-Meta: U2FsdGVkX1+Q9UL9HV3oZO2WDfEQLaNk2lDHQU9lf2uSpBYjKcsN58/hz2v2j9RaGtD65wPVPnOiJjun0QPQWBCL+XbBvEbRki4fVe17Igw4uT8gDHxG/V4xUuU889mWeOkl3nZp9US+e1HD86d/cVutcGni4aj4pGlIWea/a3+g4rRHSE63dMKmoISUDRXKIFlSu/rKphBSibbFSiBcK9l4kwbxtM1hnVxg7BeJMx0jCIbVva829QBtoqv9aTfTv4KuTr79ECzSaXopF93T5rv9wzRl85EXXpNTCnrOyk9bdjV6L/y9Z0+GSxkK1OyuFe6JDjSXiD6TNAFEzQtlRhF1mpn3juYB5/WtKjxbHh2rQcN/bpH5d2ORn+1dV1Sh9NPzDggt2NswHok3P+ymJCABXmsTiYtzB1+C0ulLHPmV87XZ6dWBHF/Vw1uep5ZDtuhYKTjfOczEEbih9nI9mOKpku26iE1wO+qbffhoGF7dT+kB1RpGyMDF5frDl6bzC3c/scWmHdnBUQQsl8N28M5gtRKPw3giEW4KbD0fed+f9bh33/xu+fqd7tuLcti+sN66D/4DOHaSpHKu9AuvY7XS0De0dWPOOC0j7GA8TkH5S9XzEEfuTYeFqv6MGNnrrvRs0cFzlbPWkaLE8ikFgIb2eDlyRE4wShZBNqxIVT/WLw9j7XeyuvkT/pISfkgt3/+LSGJTqK55JLDbKezM1xBR+9SWxusXO8uWc49NsxlSHeRtbJNn8B8cMaHBdT4qQlZMfDTsSIMI3jHox4MzxjB+bYh0MMoc1CnFc8FmwCnj7U/cCs+T+uM42ocivH9FXudMni6ooQB/prt1yVS+lv4h2aW/xA+MXflXlgqAdBsvFkzhPMK0znX97vwVmC+1rIV/XvdkbviI4t1uzFl7BgOk0Dr9wzf5X16j6WclSB07hyWs6s0C5ZfL0mbh//+GmiAqtYnZpyjrpshmd+M Q6UY7b49 +8aU5bMigwecC4aLUly8NeNF1d3Vz9VuGEmMjf54+pxMmqrUQryfXhvTwHZVU79fwFaNvoH8/EirWgeXIFFRGXuSgxTtSVV9+5xNWHUKp3Bz4fn4mFbmAlqe/Ah/CXgqt33fAYf+M45wqTUjh67UpSAKlr7D5FNfP70lUJZkq40v/yZhXuSHzMauKZXbznB0PdiJuI0MnNIHhvFXjf2GDRcj6bQ== 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: The 3-bit POIndex is stored in the PTE at bits 60..62. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Acked-by: Catalin Marinas --- arch/arm64/include/asm/pgtable-hwdef.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git arch/arm64/include/asm/pgtable-hwdef.h arch/arm64/include/asm/pgtable-hwdef.h index 1f60aa1bc750..3f0c3f5c5cef 100644 --- arch/arm64/include/asm/pgtable-hwdef.h +++ arch/arm64/include/asm/pgtable-hwdef.h @@ -199,6 +199,16 @@ #define PTE_PI_IDX_2 53 /* PXN */ #define PTE_PI_IDX_3 54 /* UXN */ +/* + * POIndex[2:0] encoding (Permission Overlay Extension) + */ +#define PTE_PO_IDX_0 (_AT(pteval_t, 1) << 60) +#define PTE_PO_IDX_1 (_AT(pteval_t, 1) << 61) +#define PTE_PO_IDX_2 (_AT(pteval_t, 1) << 62) + +#define PTE_PO_IDX_MASK GENMASK_ULL(62, 60) + + /* * Memory Attribute override for Stage-2 (MemAttr[3:0]) */ From patchwork Thu Aug 22 15:10:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773684 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 A2257C531DF for ; Thu, 22 Aug 2024 15:12:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DF8D6B0304; Thu, 22 Aug 2024 11:12:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2914A6B0306; Thu, 22 Aug 2024 11:12:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 130AB6B0305; Thu, 22 Aug 2024 11:12:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E5ABD6B0303 for ; Thu, 22 Aug 2024 11:12:27 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A89471216BB for ; Thu, 22 Aug 2024 15:12:27 +0000 (UTC) X-FDA: 82480222734.23.E8A3574 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id C1DA512000C for ; Thu, 22 Aug 2024 15:12:25 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339529; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rtB0cFu4yhRz/z4tCR4fwR+sWZaGlGCX641JW7j6vJM=; b=4AGPyzxwfdUM7W7XcDJlX/aZ8D0mDx75vMqsiI1InI1sBrfuLJjJuuZUAC3ziapDEiEpSQ TIeErAf8KkIpmq43Er6jpveeQ6ftkHAxCMYFcGkVd0ICWs/+gSaJMXtjxqXyaSNTyp5lBI PypTIjqM5GeuWjLg8qjMWiAdiSQ46w8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339529; a=rsa-sha256; cv=none; b=IPmbZMk00UqMwGE3N33W/WEn/U1AxOO/Sku6fl9JY34pebXplPYZy+mBke17KBSxgy/Xf0 B0miP0AveXPhFr72rVTxiOPrmHgyJEIOVNx9XfCgoaqplCfl3PSaITIigxcrMl7NyrHKR5 505ity3o91KX51050RGfbOgZ0GA9EmQ= 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 D16131655; Thu, 22 Aug 2024 08:12:50 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B2D423F58B; Thu, 22 Aug 2024 08:12:20 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 14/30] arm64: convert protection key into vm_flags and pgprot values Date: Thu, 22 Aug 2024 16:10:57 +0100 Message-Id: <20240822151113.1479789-15-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: k54hi6bpeubourqzc6fcy7uehohrbgx3 X-Rspamd-Queue-Id: C1DA512000C X-Rspamd-Server: rspam11 X-HE-Tag: 1724339545-371403 X-HE-Meta: U2FsdGVkX19H5nwpAvjl30e9OPaz/48LJN1SlGrG5xi6NwOHI1+JghVnENHSZE5LSWRrodn/orGOX1LEyAJkjh/mt9/sFvJvJpfAbg43f6c9W/0r6zkV7clp2A8oT5Vr6RRyL2wMdPfEz33Wf1Wwn9LIFeLh776Y2fYcH4V1LYi5fKpNcMg9KIUt8LrPJTxt5+yy4XTivcHpxxp0Qkeq+tNYzsvDnlO2st9QRTjNwqEvtXLw/0dvAi412QpY8MhuZveGFjwlrtWlHKFEzOPG63NeNnB0Ga7+/Dl0nvYkyRwLf299rGd1cGzLRRBkOQ642pCMgxpmNU4rVS0Q5gDje2rT1GCKhV0aa+CEwd2ws1zcyNC3G5R9izc5IFzQrcgAUohApyHNbeAJFbCe+bZDKdpYJKmhYna9O6dMtygzY6QwV+v2l7+5ev4lZXZwkwocyVzLy/TeJAVqRQ3KnPRiGasVQrF8b7+E6QxCCyV9NqeP6Bc5ISyP281N/b8UsRfldHKT21sp7kBJuccXWERrswBpF8zN2jNSS1v/MpWClx04gybkaiqZHuU2s4BTv95BP6CJqAyK9fyFBF/OZxU+3o3XDbh5v9yfpLZPVOsm+fLdqUh5+Dt6iGG6NxD8uvLjlDhv2lyVpi5BRDmeYjwbr5/XBsAITbdYEfjm4GXfFWBrQrja9Uaa2l5KeryGVpqE0KCbXOKGxtnghQyQBpkI3y53wLAu/Fy9NVTpFkOmgabUXY9KFVBnnFjIcgi91/GrgpGywluhCQ84lbRBr5CMXEpHRUO52xOovu0yVZ1qhm10J44BgzJdeiLqcX3bLiBNtYZCE5RvSNkGDjcZgZWMd20qP09QSDNXXottBZOZzZQRMUd425LdLUkB98s3NPLF1nqCIoEky3g4k6dvdtLfDn1akY4ZcNicKRWSr6TqZXrUUsrokQTexJZLURDpFjAPe5tHpTdHLTsv8Qbh5Ao xf/KH3ap 8tPA0/xUG92X6FX3MHbrgsK7p6SJFuga7u4jOmlUsv12zwWflRmMQa1m2YISLPvQVNAgz2nDv7+7NFSTVOYJGd8oXyQcJ0KZTD/Lc8vsUZCT6aN5i3qqQkwd2Hc8tK/KMn3D467yy0+yXayh4U8tpAvvgPMQvbjHvJfEa8TnIvnXqykMckAe+Brr8NU+LCBjFfKcTXJP6hFnNzwKDSqgcPFpk8SFTmbAcznthig153wRKLYQFA5cZYF3ue7JhA1GmuZcjHA6waLR3PFg= 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: Modify arch_calc_vm_prot_bits() and vm_get_page_prot() such that the pkey value is set in the vm_flags and then into the pgprot value. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/mman.h | 10 +++++++++- arch/arm64/mm/mmap.c | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git arch/arm64/include/asm/mman.h arch/arm64/include/asm/mman.h index 5966ee4a6154..52791715f6e6 100644 --- arch/arm64/include/asm/mman.h +++ arch/arm64/include/asm/mman.h @@ -7,7 +7,7 @@ #include static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, - unsigned long pkey __always_unused) + unsigned long pkey) { unsigned long ret = 0; @@ -17,6 +17,14 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, if (system_supports_mte() && (prot & PROT_MTE)) ret |= VM_MTE; +#ifdef CONFIG_ARCH_HAS_PKEYS + if (system_supports_poe()) { + ret |= pkey & BIT(0) ? VM_PKEY_BIT0 : 0; + ret |= pkey & BIT(1) ? VM_PKEY_BIT1 : 0; + ret |= pkey & BIT(2) ? VM_PKEY_BIT2 : 0; + } +#endif + return ret; } #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) diff --git arch/arm64/mm/mmap.c arch/arm64/mm/mmap.c index 642bdf908b22..7e3ad97e27d8 100644 --- arch/arm64/mm/mmap.c +++ arch/arm64/mm/mmap.c @@ -102,6 +102,17 @@ pgprot_t vm_get_page_prot(unsigned long vm_flags) if (vm_flags & VM_MTE) prot |= PTE_ATTRINDX(MT_NORMAL_TAGGED); +#ifdef CONFIG_ARCH_HAS_PKEYS + if (system_supports_poe()) { + if (vm_flags & VM_PKEY_BIT0) + prot |= PTE_PO_IDX_0; + if (vm_flags & VM_PKEY_BIT1) + prot |= PTE_PO_IDX_1; + if (vm_flags & VM_PKEY_BIT2) + prot |= PTE_PO_IDX_2; + } +#endif + return __pgprot(prot); } EXPORT_SYMBOL(vm_get_page_prot); From patchwork Thu Aug 22 15:10:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773685 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 AD3CBC3DA4A for ; Thu, 22 Aug 2024 15:12:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A3BF6B0306; Thu, 22 Aug 2024 11:12:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 354096B0307; Thu, 22 Aug 2024 11:12:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D0556B0308; Thu, 22 Aug 2024 11:12:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F12566B0306 for ; Thu, 22 Aug 2024 11:12:31 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id ADEAA1C583D for ; Thu, 22 Aug 2024 15:12:31 +0000 (UTC) X-FDA: 82480222902.17.70B3F0B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf20.hostedemail.com (Postfix) with ESMTP id F25BF1C0025 for ; Thu, 22 Aug 2024 15:12:29 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339509; a=rsa-sha256; cv=none; b=0WGUCW+7j1qF6mj2rJml5pAmDEFNg4gKL0L3K+4v0A8E691TuoQ3s0YFtU8M3GqgwTOct/ m6Le39K9lyrgex2ZL1EN0GNL5+ql0H3uhZ/EPl4HzWv+ZOV4jvHTTSgXoOw5mwH208cVuw rdFQ76WFbT0rKifP88DqM7vTZSth4m8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339509; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XWloCsKInlghkQxh/mo59nFfEBaFhJ6JRXZEr40jxF0=; b=LRaAPvH6KW94RYJUrZsyDzPYRJzmh6OD67AT16TRHxT0bFxskr0KkRgvy627l2rmdBSbbt xvf/4HeOOjMhI/zMh+X/CuPe9+U6WYI1M4qQKpyYK5k2QoCGCr/PmR38kLLMcaF6dhYnsR x0PQEU3c9c6TBzBQehutmRUqLY5gQ08= 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 2BF8D165C; Thu, 22 Aug 2024 08:12:55 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0D3BE3F58B; Thu, 22 Aug 2024 08:12:24 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 15/30] arm64: mask out POIndex when modifying a PTE Date: Thu, 22 Aug 2024 16:10:58 +0100 Message-Id: <20240822151113.1479789-16-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Stat-Signature: cwxptjyeccjz45zbqjkqp99ix4h5r4yd X-Rspamd-Queue-Id: F25BF1C0025 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724339549-443739 X-HE-Meta: U2FsdGVkX191eC+q3doTsLeUydo7Cbm9b1/6DUM//YyvDSCpjyyKlNfGA+Rwas0JHeexYzYRgXxLnWuumqI4gPESTiI1JEjYIPiI9kCvaLK4fM+4mIFXRYe31bu6ETtt8k52PxiNu0SpxmWpWNFzPKlW0RCRpizWsxkcCK4R53TN5UNdAxLYHIfilez3Hlq2bsfykSHegb4cI/Zh0O0Au6gE+Fp8LqHGGZ/vBHo4KHFewwUURO3FIpv9rOwE7srOdhuO25hIGUEk+pIYry2FwKqbnAofqSODfoVpTrFT8oKscoiJDroLV68GeAbLOfUy5Inez/XCO1nqV2LXWKVM6x9D0fnMUcIgAPx2zFU0svtiZGicTxJt0tRZYBU9UFlgUbTIR6BnKjHTNMR6voexD7bzABK5SH/veydSNN6/uVg4BAEG/0wHOE+yFRjXOQKkGQ4lWopwO6DsLdfRDI3o0vNHymF3moQRIZFPh697CZ71jP2twPmapGLB8NyuCEzLI8UOU4j5pwcb650ZzVDoBqsQ3H0mf+EkREfJfBUl526wmKzNXfXCwlLZVFW1i4jkforVZJhfm7D65KLi0L5YYzJJxmYs1n6cudbcgWvmU/z3Ca3DBEPj6XdZBP16CA1OUfvJkC5S2c8Jjc07NydjJ0HApy3P1O3Ss7dC3NXbWU++ELS8fUPK5Itm0rT8IdN7hWscbk69z8jzVSy9z9EVUDamw0enJD+3QyXqS/vL3g5emhQjiWDaVSPbtMx3IUToKm1Mnamkup3GlQr3FOcLsRua8wfjiPPY9c+DHoKRA4pHyxixutTtI9N9p72Vn/KS8CfZYRfzJ1LyEvCO0sCJs7YiKr6JjFZWhCtg+AFeEZVqhdgt1BgwLPguo8G2eJTqf29oItBl3V+Ui6LwY65h+id2cu6uAuKTy/vvIi1BJMRiuRWQSWlQPqRSeqLlsKSxLiVi1z9Wf63/msPuQs3 GmLnIaor PllNkQwDeUTYopkqDkOLUbTGQsD1KXPtOiWv652k8v6I6uL4eHVupSBsz3b8/c68iUaQ/8kgA5Hi+6INt0j69zgMhg3XOOOgGEV1K01UaZYhg5zokQ/h1aKCgx9cr8gyPiTB5bssBVYJCqGBbf0aWqbY6K5uOQYqsZqP7/gf4KUo/0FPkIVjZ1LgkjLiOLn1/+STwcJaSwiOUW3rzSefzAiWGYQ== 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: When a PTE is modified, the POIndex must be masked off so that it can be modified. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git arch/arm64/include/asm/pgtable.h arch/arm64/include/asm/pgtable.h index 7a4f5604be3f..1d0f18d30e1e 100644 --- arch/arm64/include/asm/pgtable.h +++ arch/arm64/include/asm/pgtable.h @@ -1103,7 +1103,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) */ const pteval_t mask = PTE_USER | PTE_PXN | PTE_UXN | PTE_RDONLY | PTE_PRESENT_INVALID | PTE_VALID | PTE_WRITE | - PTE_GP | PTE_ATTRINDX_MASK; + PTE_GP | PTE_ATTRINDX_MASK | PTE_PO_IDX_MASK; + /* preserve the hardware dirty information */ if (pte_hw_dirty(pte)) pte = set_pte_bit(pte, __pgprot(PTE_DIRTY)); From patchwork Thu Aug 22 15:10:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773686 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 14283C5321D for ; Thu, 22 Aug 2024 15:12:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 996FF6B01A4; Thu, 22 Aug 2024 11:12:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 946626B01A5; Thu, 22 Aug 2024 11:12:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79D276B01A6; Thu, 22 Aug 2024 11:12:36 -0400 (EDT) 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 2DB366B01A4 for ; Thu, 22 Aug 2024 11:12:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CBBECC0DF6 for ; Thu, 22 Aug 2024 15:12:35 +0000 (UTC) X-FDA: 82480223070.29.E6C3334 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id 2D32914002B for ; Thu, 22 Aug 2024 15:12:33 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf26.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339537; a=rsa-sha256; cv=none; b=59ALeJIk6UKgVSO62exiusxs65oOkWUfjHe7bKb2LgvZqFXm2Kk2LXtpzAWC4UxVz3aSZT bWnM+YHlohWONU6Ouz3LD1+ZNVpJ3ZYQS5EV6E5OhM4QjaU1bgwubowMtkwPmybE19S7gU ixodCTOIzs8ckCTpfor7s1afHPHyru4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf26.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339537; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PmUc9IZ3QQaMGDGB6yp3qr7QaJz6BkaXbPPESjB5bJ4=; b=q5NQXwizoyR05LPpfukbQZ1LzC/NNq8oXGhmoD//KEyvIgpBhqxYrf2LxRIhEyBwUwOwpU VbVefV4HMfSND8jt5sHMx9cPxDGjMxUjAs/7gA1U+dCdCmDja6O1f9Hnzc3mm5mZQ3z3jH sXBGxWbXuYThpFwc7i3r0PuJOYQUGUg= 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 8D58515A1; Thu, 22 Aug 2024 08:12:59 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5BB9A3F58B; Thu, 22 Aug 2024 08:12:29 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 16/30] arm64: handle PKEY/POE faults Date: Thu, 22 Aug 2024 16:10:59 +0100 Message-Id: <20240822151113.1479789-17-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 2D32914002B X-Rspamd-Server: rspam01 X-Stat-Signature: fbcog1qio6d18jwbfsxcxgirt7k4gbj7 X-HE-Tag: 1724339553-910136 X-HE-Meta: U2FsdGVkX18BDcL/Duz0v8qbr2eohmvzrvP/1w76kEtjY9hMR8JQrZWCmFEam/XY/NqJ1jDyzqGQM52dBkvU5C6dp84OjNEDyzIPgVYC9G9ed82GhyXfyQm3CQ5HzIr+oHBhYcrHIZyqPo19ZBfeO54LBn/+fnNhm2wOFweJp71NaCkFKb64321zs3z9RUa7luxusG7CUpIDMNKAMDTnNFK9YlhT4MBE8EyJc5znUcJhgQQDxAieCZxtdkAOE49Oi1qjzC46UrgSOX7Vki/dsY4PpOujPChqwkIH68Pcy5a81WQSQcAJlewuUMF0IjifvBSvgs0K/hjlWtzMmwDA910gvAzDlp1gyeC6h8wdl+3WR2MVR35nowKBYD91VWCp2P5NHJg9pAeJifQDajxQ/Kw6yHZpJXxXWYrUWm5oUrAE3io8Pn9M+FyU5SnC8motOlCsan3ooXurm5svYH2xw4NOmeoJ+2pD998wZs9lD4xwTdl5iy1Lbh80kn9WkT+WqyG1I6+vAOvZXhl55TgfkRTFUNkdj0FJ06Yx1GqALoIU1jDtjn5R3BAtkdrJY0qeCdXRg0lYP1GNh+yq9dCsKTa5dwAkKYBSe8EdGvZFsD9PAR0A20+1LFoTnb7lmvQleht0dF6IocHaBvbLwABls9DWs/GTR0JNeZ/b7OLu9MFRlbfZ6Ts51KLmeZZYfv4KtyoIDfjqtJa3JC/N+Vog+aH2Zszbcu+j+lUXRONWZ3P84RWkf0fUiVMCJA8Q4XmR3aWQoEWVtdPXam+7z+/h01oWQIXMiPaj4qxMTPhnQUdt0Ma+cLqoVxrNb4Rf/1Y/dSn6cn9Hfnhk1GkVKKEBw2wD0P/FUyfHFrf9guQT6C4uD0Pv3n/Xv7g+gtKX6EPz/Qlz2yP0t9UNrvMjQV6ToMj3IQzi7sW6uVOrGmMkFruHvIIzB9sOGvX2ft62KXcIzbl2MyV0aUCiCGm5Cm0 1zMtErmR Y/F1ujm7jp+RQ1TRyNvZ4HpiqODs1jPbdf5IKzfm4rm5N/xZjzXS4f7dj7Mlr8Z5SuTvjLLZJ5+cjyPO1+htdw447mCoLY4NUzE0LPy0uvhf1wp2jBKT+eQqNZVRCFmGH+0XNuwhFYYGX/BKkcWhC0erJgfXCQqQZAL88N4//PYstuAKi5DKvLoj/HIvako2j2kmB/7lfl3wdFdWgCtA82YzZwA== 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: If a memory fault occurs that is due to an overlay/pkey fault, report that to userspace with a SEGV_PKUERR. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/traps.h | 1 + arch/arm64/kernel/traps.c | 6 ++++ arch/arm64/mm/fault.c | 55 +++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git arch/arm64/include/asm/traps.h arch/arm64/include/asm/traps.h index eefe766d6161..d780d1bd2eac 100644 --- arch/arm64/include/asm/traps.h +++ arch/arm64/include/asm/traps.h @@ -25,6 +25,7 @@ try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn) void force_signal_inject(int signal, int code, unsigned long address, unsigned long err); void arm64_notify_segfault(unsigned long addr); void arm64_force_sig_fault(int signo, int code, unsigned long far, const char *str); +void arm64_force_sig_fault_pkey(unsigned long far, const char *str, int pkey); void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, const char *str); void arm64_force_sig_ptrace_errno_trap(int errno, unsigned long far, const char *str); diff --git arch/arm64/kernel/traps.c arch/arm64/kernel/traps.c index 9e22683aa921..9a11bb0db284 100644 --- arch/arm64/kernel/traps.c +++ arch/arm64/kernel/traps.c @@ -273,6 +273,12 @@ void arm64_force_sig_fault(int signo, int code, unsigned long far, force_sig_fault(signo, code, (void __user *)far); } +void arm64_force_sig_fault_pkey(unsigned long far, const char *str, int pkey) +{ + arm64_show_signal(SIGSEGV, str); + force_sig_pkuerr((void __user *)far, pkey); +} + void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, const char *str) { diff --git arch/arm64/mm/fault.c arch/arm64/mm/fault.c index 451ba7cbd5ad..a68055150950 100644 --- arch/arm64/mm/fault.c +++ arch/arm64/mm/fault.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -486,6 +487,23 @@ static void do_bad_area(unsigned long far, unsigned long esr, } } +static bool fault_from_pkey(unsigned long esr, struct vm_area_struct *vma, + unsigned int mm_flags) +{ + unsigned long iss2 = ESR_ELx_ISS2(esr); + + if (!system_supports_poe()) + return false; + + if (iss2 & ESR_ELx_Overlay) + return true; + + return !arch_vma_access_permitted(vma, + mm_flags & FAULT_FLAG_WRITE, + mm_flags & FAULT_FLAG_INSTRUCTION, + false); +} + static bool is_el0_instruction_abort(unsigned long esr) { return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_LOW; @@ -511,6 +529,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, unsigned long addr = untagged_addr(far); struct vm_area_struct *vma; int si_code; + int pkey = -1; if (kprobe_page_fault(regs, esr)) return 0; @@ -575,6 +594,16 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto bad_area; } + + if (fault_from_pkey(esr, vma, mm_flags)) { + pkey = vma_pkey(vma); + vma_end_read(vma); + fault = 0; + si_code = SEGV_PKUERR; + count_vm_vma_lock_event(VMA_LOCK_SUCCESS); + goto bad_area; + } + fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs); if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) vma_end_read(vma); @@ -610,7 +639,16 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, goto bad_area; } + if (fault_from_pkey(esr, vma, mm_flags)) { + pkey = vma_pkey(vma); + mmap_read_unlock(mm); + fault = 0; + si_code = SEGV_PKUERR; + goto bad_area; + } + fault = handle_mm_fault(vma, addr, mm_flags, regs); + /* Quick path to respond to signals */ if (fault_signal_pending(fault, regs)) { if (!user_mode(regs)) @@ -669,8 +707,23 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, arm64_force_sig_mceerr(BUS_MCEERR_AR, far, lsb, inf->name); } else { + /* + * The pkey value that we return to userspace can be different + * from the pkey that caused the fault. + * + * 1. T1 : mprotect_key(foo, PAGE_SIZE, pkey=4); + * 2. T1 : set POR_EL0 to deny access to pkey=4, touches, page + * 3. T1 : faults... + * 4. T2: mprotect_key(foo, PAGE_SIZE, pkey=5); + * 5. T1 : enters fault handler, takes mmap_lock, etc... + * 6. T1 : reaches here, sees vma_pkey(vma)=5, when we really + * faulted on a pte with its pkey=4. + */ /* Something tried to access memory that out of memory map */ - arm64_force_sig_fault(SIGSEGV, si_code, far, inf->name); + if (si_code == SEGV_PKUERR) + arm64_force_sig_fault_pkey(far, inf->name, pkey); + else + arm64_force_sig_fault(SIGSEGV, si_code, far, inf->name); } return 0; From patchwork Thu Aug 22 15:11:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773687 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 1B95DC3DA4A for ; Thu, 22 Aug 2024 15:12:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E4BD6B0255; Thu, 22 Aug 2024 11:12:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 995496B025C; Thu, 22 Aug 2024 11:12:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80EA56B0255; Thu, 22 Aug 2024 11:12:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5BCF46B0250 for ; Thu, 22 Aug 2024 11:12:40 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 08B1C8177C for ; Thu, 22 Aug 2024 15:12:39 +0000 (UTC) X-FDA: 82480223280.26.FE41AB9 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf09.hostedemail.com (Postfix) with ESMTP id 5DD9A140021 for ; Thu, 22 Aug 2024 15:12:38 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339518; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hcli0Td5f2QXcIZuDvn/8dKsjYNziEJ78ahe7tKTuic=; b=yFIX5oLA6mKGdCC1MNsP+iFFIh62w3XYeU+SYG/ZtBQSLApN2wecDXUN8kfK2I6A4xsUN/ fNFAnmToBh75eM+oYKE8dErvYmtg1prfu7fSU3phMD85tTZ+Kwy6nL1k4ln8P3WbaeDxlF a4O+4dDZZo3q3ZcVSa8RQK8gKNpmMM4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339518; a=rsa-sha256; cv=none; b=lkmVutmp1EgcJ1P8uW4ziu3WvLEwS+Rfo3Rxo/c7pobRxRWBDSSynFqpknn2km+J0EBscy qMPTcTzMcwskxYKZpBFW/2MmLDxmjBf73+QDlQr3/QPJ265YB2hiHiCqvQ2oqZ1eSsmKbY ET5sVCMhbdUf8QEQ2sL/zfujS7qtZHQ= 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 C8794DA7; Thu, 22 Aug 2024 08:13:03 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A9C703F58B; Thu, 22 Aug 2024 08:12:33 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 17/30] arm64: add pte_access_permitted_no_overlay() Date: Thu, 22 Aug 2024 16:11:00 +0100 Message-Id: <20240822151113.1479789-18-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5DD9A140021 X-Stat-Signature: zjo51wa9g5s3g9wowx8jkhuxe6oy3ex3 X-HE-Tag: 1724339558-964828 X-HE-Meta: U2FsdGVkX1+1zXuSLnSogBXCPZI3rmG7+k21ccR6BvKX2ZOeOS9aokzmEsdoL2faCHeuraL8+SNVgNOFb2Kj6VxypFdGPgEA5tWJ0gdC8SRVmcHhLCZw2AeLEFJD/2m5OKdOPluuObDM/4K+N96NYOnj8CyPIXSk5f2OsKawXfOQmzkLny6wZQxuLFLf3IprdfFbtIu5OLYs//6J6mTAb3LPO4fAnyZecOD/x9tuGOjvAa2dw69tQHykd9c4X/5fjenXN7iwx/G2/WZEaRj1d4eUsZ+URD+yZW1QN0n0sF5OWVgsS25DX38ng8zsdxtH11BJffrrMt123bJPYiXCYOYzhWRr7RR1XfFhNW8W2PN2+PJA++h2a75u7sybFp4JpQoch5W/Cws7xWRoZH9J3+1JjZiqMeDfYW0aZn0bFUlU8M1lpZjrl/tZYtp38Y4zdVsloaD14tiCe/lJ9y1PjkiztZo/dGjkd7XiCKe62Hh/lRfQEjWTvKNZUXD1YmLUJ+Ors3nqhChzHoX1Xbk90xcvnvzkgT1xKzO53kyGwLqSIWZe5k9s/EOAFvsD9R7ZhTFidtTGPfj5UG8NXCSAteKcbjRy2sHl7sNXFnqc805a9/W0D5Sle6GBmOQhZLd7Yt1Uu77RizHntCwM8NGFP+5OeMNq+aEC5M8T0prhQcVF2+gJPTwLo951zWqsSxCNswTs5dmw1j9EtircQTikzhXE9jXEF6i8jRs7W4iYpeK9TgzzDNKvPxUGmUpG65QPGlH6ru8XVA54nrCMORJ0iBBiXsyzqYe/cH8KC/5bpootDByfstc3OAs6JbF2QMzpAnGo3+Tc+LG+O4tDk+UAxic9eGNxESnYhstJRe5aP9FSQfU2/pX/ucVPyPOGD8st9NKXOxtF2R8I5m4hbBVRVhKpEWHpsa4R5J6ndocQDy2I8HiuKXOFdfp7Uv80O5jLdw0/FsXlQHKzuIE/zTK Zg9iZ+3Y Bx5t7COOXtpt5mzLOWkgGN+ieJPtAi1A6HH/FDoefd/Thr4gRh0p1dTTSlTmWXCiO5gzr9P+EzhUqD2TeXSXTwk3iFCW5fFfmx8Vbn0yYEUWNoP0vSwZp/9UgTN6qa4nSNcNu2KKt0UPEeYM12FPPv5GJkcz55avzzZ6gaYMVqRTEyaMvRFFyTa4bh2mW/j5lRCfzj0ntlBrmFcPogetxrSgfsPTlPok6CwjGtoHvTub2LDhvl5Ztt5utUoXhGH/KUnxKlCihTw7Jqzg= 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: We do not want take POE into account when clearing the MTE tags. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git arch/arm64/include/asm/pgtable.h arch/arm64/include/asm/pgtable.h index 1d0f18d30e1e..61a674942a6b 100644 --- arch/arm64/include/asm/pgtable.h +++ arch/arm64/include/asm/pgtable.h @@ -156,8 +156,10 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys) * not set) must return false. PROT_NONE mappings do not have the * PTE_VALID bit set. */ -#define pte_access_permitted(pte, write) \ +#define pte_access_permitted_no_overlay(pte, write) \ (((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER)) && (!(write) || pte_write(pte))) +#define pte_access_permitted(pte, write) \ + pte_access_permitted_no_overlay(pte, write) #define pmd_access_permitted(pmd, write) \ (pte_access_permitted(pmd_pte(pmd), (write))) #define pud_access_permitted(pud, write) \ @@ -373,10 +375,11 @@ static inline void __sync_cache_and_tags(pte_t pte, unsigned int nr_pages) /* * If the PTE would provide user space access to the tags associated * with it then ensure that the MTE tags are synchronised. Although - * pte_access_permitted() returns false for exec only mappings, they - * don't expose tags (instruction fetches don't check tags). + * pte_access_permitted_no_overlay() returns false for exec only + * mappings, they don't expose tags (instruction fetches don't check + * tags). */ - if (system_supports_mte() && pte_access_permitted(pte, false) && + if (system_supports_mte() && pte_access_permitted_no_overlay(pte, false) && !pte_special(pte) && pte_tagged(pte)) mte_sync_tags(pte, nr_pages); } From patchwork Thu Aug 22 15:11:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773688 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 96EB8C52D7C for ; Thu, 22 Aug 2024 15:12:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2452B6B0316; Thu, 22 Aug 2024 11:12:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F6498001E; Thu, 22 Aug 2024 11:12:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06EA86B0318; Thu, 22 Aug 2024 11:12:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D94916B0316 for ; Thu, 22 Aug 2024 11:12:44 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 94B1DA7896 for ; Thu, 22 Aug 2024 15:12:44 +0000 (UTC) X-FDA: 82480223448.10.14E32D1 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf14.hostedemail.com (Postfix) with ESMTP id E2023100013 for ; Thu, 22 Aug 2024 15:12:42 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339482; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ap/bHfgEG3vNR51GHX5ENZKqoWQhC/IEBUtgZWRXOl0=; b=eoGmvP36niUlpHCVOlLKwVIyy76pQSDGdSa4mHZOX4wVQwtbPbyMJl7CaflI9kr2343BIj x9bjgF/zySShSJWb9qr8cNiW1+uUD0UhW2Gy1ikTSE2exq2G1600PNuZ1UabXZohq5sbfX newijYnbX6ONN4WsD1Bpc7yPDY+vHME= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339482; a=rsa-sha256; cv=none; b=GFLPT6zVjg25rKGFsH3fn0PuXz+DCNvgXdvsVjcOh03tRAoeidAQuIDA9onHusMwAhwrpl L06R8p159RcgwuJXE2/C7SeE7Z9xXGwcnxwUvXgtLSxiJY2ab50IZhNYbM4/++JSck8M42 Hq6Zlr6Gxr2UzUYowYK2km6Ulij7s04= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 41D7F15DB; Thu, 22 Aug 2024 08:13:08 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 04AF63F58B; Thu, 22 Aug 2024 08:12:37 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 18/30] arm64: implement PKEYS support Date: Thu, 22 Aug 2024 16:11:01 +0100 Message-Id: <20240822151113.1479789-19-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E2023100013 X-Stat-Signature: ck7kxem375n3n6e3czmnydadm9za6fan X-HE-Tag: 1724339562-44555 X-HE-Meta: U2FsdGVkX1+L0BPp8zGNC/tmVJiBOEPoNqpBGuW548jJk4YLDuZGsasaM0OQLB1S2YIcTD0MDe94pBlWOCiDG3RdTRx131GkvM4v4WXTJE6VtRj7KmQtfPlcB7doCBm3MZykc/R1l/YL8UI5X6G/iLYYU3RB3sg25PtivtQ1Eu34mDJ/tCNY/DlzpasMWIbCev58I2nr8s3NBx+s6XrrKaUreWaG16yYL+hEnHiThvfKsVK7i+jwaWuKZvdnt4GSYB5soo5AP1zYcgj7O66crW8qfdrRd4YcyzA6J8BNvfgRcQmqkN72PbCyG37pWtUq+wQjiTqGeER51jieXhlrWigt6LXmi+3QQC/920Mq3uYu/zOmJY7td1sxaAcL5Shlh9Yn+E6+7QPt5ZZMn7TdCb4lNxyQlYoVEQpDCJbtRo1fJlmaISMzKBDDCD5dQ9NtB9lgmDmwn8gssg/U48fu9E4j3PuRh0US5epkXCKdTFMtE6Rkjhc4np4U5k+pduMq3e4XEgaszH8v6ZPBPSry4CuZpSCaQjK/Yk1Fqqqiw/nOfPnuHS2SXRGE6nuoBH8FBX2UHH/Xln3gmmAnhotNSljU3NT+pBp1yAAxqexjxvD+v923Lpj8cMzWwPer3jg8Lh9QKDBbJLvFi64ZmNVqBMLdaJ8+00+619gMq7FKltnIwHG/POU/Bv2SY4cg7AL91OXurKPEM9BkhbcfCujtgDhs7ZlJueQdNs0yD97CeyyGuauCS3enqn9tDks22aVKloStsV/OjszidQa7oqjUsYm1h1XRYB9Bn23B9oVG4FRGJ1hW8iyt3Jo8aIaWBPQ3bKrcQ491BU0j/LCMsasGH/JH+dElNkLLu/vN4GOjo+ls29sWxxhBjTBaEBAoXQfJ6+LDrGD5oBRFaw6WxbYN3o7+iJw6vrN05+bo+5IvRG4BAW4RFQpmj1tHKn+LWfD0oEQ4femDjDe8Y84/GJh WDdocX0r FNeTUZ0vJ9c7khgzV6DDOObXt1Bpi6wO+HpkQmSpg/Kwyn+zm74mxjwyLo3Q3bUYIB1xXO3EZmZD/c0QJRw2OcW8+7EWeCLALTmS/6AiDWxJCXH6/4HHFJmP54Buhd1wwXiipnWUkMpzVwAyFMKSpN5p5wI485lOfZweF6fFg/wqeNd43qoO/1X9GVi9siW7tX5erP8sBeWTsKNvickv23bkwNQ== 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: Implement the PKEYS interface, using the Permission Overlay Extension. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/mmu.h | 1 + arch/arm64/include/asm/mmu_context.h | 46 +++++++++++- arch/arm64/include/asm/pgtable.h | 22 +++++- arch/arm64/include/asm/pkeys.h | 108 +++++++++++++++++++++++++++ arch/arm64/include/asm/por.h | 33 ++++++++ arch/arm64/include/uapi/asm/mman.h | 9 +++ arch/arm64/mm/mmu.c | 45 +++++++++++ 7 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/include/asm/pkeys.h create mode 100644 arch/arm64/include/asm/por.h diff --git arch/arm64/include/asm/mmu.h arch/arm64/include/asm/mmu.h index 65977c7783c5..983afeb4eba5 100644 --- arch/arm64/include/asm/mmu.h +++ arch/arm64/include/asm/mmu.h @@ -25,6 +25,7 @@ typedef struct { refcount_t pinned; void *vdso; unsigned long flags; + u8 pkey_allocation_map; } mm_context_t; /* diff --git arch/arm64/include/asm/mmu_context.h arch/arm64/include/asm/mmu_context.h index bd19f4c758b7..7c09d47e09cb 100644 --- arch/arm64/include/asm/mmu_context.h +++ arch/arm64/include/asm/mmu_context.h @@ -15,12 +15,12 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -175,9 +175,36 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm) { atomic64_set(&mm->context.id, 0); refcount_set(&mm->context.pinned, 0); + + /* pkey 0 is the default, so always reserve it. */ + mm->context.pkey_allocation_map = BIT(0); + + return 0; +} + +static inline void arch_dup_pkeys(struct mm_struct *oldmm, + struct mm_struct *mm) +{ + /* Duplicate the oldmm pkey state in mm: */ + mm->context.pkey_allocation_map = oldmm->context.pkey_allocation_map; +} + +static inline int arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm) +{ + arch_dup_pkeys(oldmm, mm); + return 0; } +static inline void arch_exit_mmap(struct mm_struct *mm) +{ +} + +static inline void arch_unmap(struct mm_struct *mm, + unsigned long start, unsigned long end) +{ +} + #ifdef CONFIG_ARM64_SW_TTBR0_PAN static inline void update_saved_ttbr0(struct task_struct *tsk, struct mm_struct *mm) @@ -267,6 +294,23 @@ static inline unsigned long mm_untag_mask(struct mm_struct *mm) return -1UL >> 8; } +/* + * Only enforce protection keys on the current process, because there is no + * user context to access POR_EL0 for another address space. + */ +static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, + bool write, bool execute, bool foreign) +{ + if (!system_supports_poe()) + return true; + + /* allow access if the VMA is not one from this process */ + if (foreign || vma_is_foreign(vma)) + return true; + + return por_el0_allows_pkey(vma_pkey(vma), write, execute); +} + #include #endif /* !__ASSEMBLY__ */ diff --git arch/arm64/include/asm/pgtable.h arch/arm64/include/asm/pgtable.h index 61a674942a6b..96c2b0b07c4c 100644 --- arch/arm64/include/asm/pgtable.h +++ arch/arm64/include/asm/pgtable.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -149,6 +150,24 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys) #define pte_accessible(mm, pte) \ (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid(pte)) +static inline bool por_el0_allows_pkey(u8 pkey, bool write, bool execute) +{ + u64 por; + + if (!system_supports_poe()) + return true; + + por = read_sysreg_s(SYS_POR_EL0); + + if (write) + return por_elx_allows_write(por, pkey); + + if (execute) + return por_elx_allows_exec(por, pkey); + + return por_elx_allows_read(por, pkey); +} + /* * p??_access_permitted() is true for valid user mappings (PTE_USER * bit set, subject to the write permission check). For execute-only @@ -159,7 +178,8 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys) #define pte_access_permitted_no_overlay(pte, write) \ (((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER)) && (!(write) || pte_write(pte))) #define pte_access_permitted(pte, write) \ - pte_access_permitted_no_overlay(pte, write) + (pte_access_permitted_no_overlay(pte, write) && \ + por_el0_allows_pkey(FIELD_GET(PTE_PO_IDX_MASK, pte_val(pte)), write, false)) #define pmd_access_permitted(pmd, write) \ (pte_access_permitted(pmd_pte(pmd), (write))) #define pud_access_permitted(pud, write) \ diff --git arch/arm64/include/asm/pkeys.h arch/arm64/include/asm/pkeys.h new file mode 100644 index 000000000000..32c352bb36b9 --- /dev/null +++ arch/arm64/include/asm/pkeys.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2023 Arm Ltd. + * + * Based on arch/x86/include/asm/pkeys.h + */ + +#ifndef _ASM_ARM64_PKEYS_H +#define _ASM_ARM64_PKEYS_H + +#define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2) + +#define arch_max_pkey() 8 + +int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, + unsigned long init_val); + +static inline bool arch_pkeys_enabled(void) +{ + return false; +} + +static inline int vma_pkey(struct vm_area_struct *vma) +{ + return (vma->vm_flags & ARCH_VM_PKEY_FLAGS) >> VM_PKEY_SHIFT; +} + +static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma, + int prot, int pkey) +{ + if (pkey != -1) + return pkey; + + return vma_pkey(vma); +} + +static inline int execute_only_pkey(struct mm_struct *mm) +{ + // Execute-only mappings are handled by EPAN/FEAT_PAN3. + WARN_ON_ONCE(!cpus_have_final_cap(ARM64_HAS_EPAN)); + + return -1; +} + +#define mm_pkey_allocation_map(mm) (mm)->context.pkey_allocation_map +#define mm_set_pkey_allocated(mm, pkey) do { \ + mm_pkey_allocation_map(mm) |= (1U << pkey); \ +} while (0) +#define mm_set_pkey_free(mm, pkey) do { \ + mm_pkey_allocation_map(mm) &= ~(1U << pkey); \ +} while (0) + +static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) +{ + /* + * "Allocated" pkeys are those that have been returned + * from pkey_alloc() or pkey 0 which is allocated + * implicitly when the mm is created. + */ + if (pkey < 0 || pkey >= arch_max_pkey()) + return false; + + return mm_pkey_allocation_map(mm) & (1U << pkey); +} + +/* + * Returns a positive, 3-bit key on success, or -1 on failure. + */ +static inline int mm_pkey_alloc(struct mm_struct *mm) +{ + /* + * Note: this is the one and only place we make sure + * that the pkey is valid as far as the hardware is + * concerned. The rest of the kernel trusts that + * only good, valid pkeys come out of here. + */ + u8 all_pkeys_mask = GENMASK(arch_max_pkey() - 1, 0); + int ret; + + if (!arch_pkeys_enabled()) + return -1; + + /* + * Are we out of pkeys? We must handle this specially + * because ffz() behavior is undefined if there are no + * zeros. + */ + if (mm_pkey_allocation_map(mm) == all_pkeys_mask) + return -1; + + ret = ffz(mm_pkey_allocation_map(mm)); + + mm_set_pkey_allocated(mm, ret); + + return ret; +} + +static inline int mm_pkey_free(struct mm_struct *mm, int pkey) +{ + if (!mm_pkey_is_allocated(mm, pkey)) + return -EINVAL; + + mm_set_pkey_free(mm, pkey); + + return 0; +} + +#endif /* _ASM_ARM64_PKEYS_H */ diff --git arch/arm64/include/asm/por.h arch/arm64/include/asm/por.h new file mode 100644 index 000000000000..e06e9f473675 --- /dev/null +++ arch/arm64/include/asm/por.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2023 Arm Ltd. + */ + +#ifndef _ASM_ARM64_POR_H +#define _ASM_ARM64_POR_H + +#define POR_BITS_PER_PKEY 4 +#define POR_ELx_IDX(por_elx, idx) (((por_elx) >> ((idx) * POR_BITS_PER_PKEY)) & 0xf) + +static inline bool por_elx_allows_read(u64 por, u8 pkey) +{ + u8 perm = POR_ELx_IDX(por, pkey); + + return perm & POE_R; +} + +static inline bool por_elx_allows_write(u64 por, u8 pkey) +{ + u8 perm = POR_ELx_IDX(por, pkey); + + return perm & POE_W; +} + +static inline bool por_elx_allows_exec(u64 por, u8 pkey) +{ + u8 perm = POR_ELx_IDX(por, pkey); + + return perm & POE_X; +} + +#endif /* _ASM_ARM64_POR_H */ diff --git arch/arm64/include/uapi/asm/mman.h arch/arm64/include/uapi/asm/mman.h index 1e6482a838e1..e7e0c8216243 100644 --- arch/arm64/include/uapi/asm/mman.h +++ arch/arm64/include/uapi/asm/mman.h @@ -7,4 +7,13 @@ #define PROT_BTI 0x10 /* BTI guarded page */ #define PROT_MTE 0x20 /* Normal Tagged mapping */ +/* Override any generic PKEY permission defines */ +#define PKEY_DISABLE_EXECUTE 0x4 +#define PKEY_DISABLE_READ 0x8 +#undef PKEY_ACCESS_MASK +#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ + PKEY_DISABLE_WRITE |\ + PKEY_DISABLE_READ |\ + PKEY_DISABLE_EXECUTE) + #endif /* ! _UAPI__ASM_MMAN_H */ diff --git arch/arm64/mm/mmu.c arch/arm64/mm/mmu.c index 353ea5dc32b8..e55b02fbddc8 100644 --- arch/arm64/mm/mmu.c +++ arch/arm64/mm/mmu.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -1549,3 +1550,47 @@ void __cpu_replace_ttbr1(pgd_t *pgdp, bool cnp) cpu_uninstall_idmap(); } + +#ifdef CONFIG_ARCH_HAS_PKEYS +int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long init_val) +{ + u64 new_por = POE_RXW; + u64 old_por; + u64 pkey_shift; + + if (!system_supports_poe()) + return -ENOSPC; + + /* + * This code should only be called with valid 'pkey' + * values originating from in-kernel users. Complain + * if a bad value is observed. + */ + if (WARN_ON_ONCE(pkey >= arch_max_pkey())) + return -EINVAL; + + /* Set the bits we need in POR: */ + new_por = POE_RXW; + if (init_val & PKEY_DISABLE_WRITE) + new_por &= ~POE_W; + if (init_val & PKEY_DISABLE_ACCESS) + new_por &= ~POE_RW; + if (init_val & PKEY_DISABLE_READ) + new_por &= ~POE_R; + if (init_val & PKEY_DISABLE_EXECUTE) + new_por &= ~POE_X; + + /* Shift the bits in to the correct place in POR for pkey: */ + pkey_shift = pkey * POR_BITS_PER_PKEY; + new_por <<= pkey_shift; + + /* Get old POR and mask off any old bits in place: */ + old_por = read_sysreg_s(SYS_POR_EL0); + old_por &= ~(POE_MASK << pkey_shift); + + /* Write old part along with new part: */ + write_sysreg_s(old_por | new_por, SYS_POR_EL0); + + return 0; +} +#endif From patchwork Thu Aug 22 15:11:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773689 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 2AA9CC3DA4A for ; Thu, 22 Aug 2024 15:12:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0C1B6B031A; Thu, 22 Aug 2024 11:12:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BB8E6B031B; Thu, 22 Aug 2024 11:12:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80E586B031C; Thu, 22 Aug 2024 11:12:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5C1C26B031A for ; Thu, 22 Aug 2024 11:12:49 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 178A881474 for ; Thu, 22 Aug 2024 15:12:49 +0000 (UTC) X-FDA: 82480223658.21.D8C9F14 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 49FE040015 for ; Thu, 22 Aug 2024 15:12:47 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339486; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yS/wr3Kaj/+ao73MTWL/k678y347e9kidUJfkehZp8w=; b=XZRu+GsJSkxnzXyAPYKujmWQirhHM4FKC303GlmnUYVI4rJ/aHoURR7wZSAnIw5zU/wU1/ uUD4bAEGsJRnB97uTDaah55kMhJiWg40+5s+4+hlDBPo1Neqi6TcuHJeVTQgJrb/LeBhgt Txc9ex1X6pD2MX6ox38YKEjfECFAlYw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339486; a=rsa-sha256; cv=none; b=qIIn2ujPRMd3G0cGqHBdqG4w8DYULfgJ0Ew3sV2xpuqnpC5pYKJknFV0TbL50/8Rd05ViG yWy+zmIJI1no+XREmthS2QRF3cbeNZL1ybkyT/BS2vo8u6oydl/F4bgjfNkcqMdo5VkBBj yTvQwwH5hLa2sj0mXAmJ0oAWVX+As3Q= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 915F41576; Thu, 22 Aug 2024 08:13:12 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 722AE3F58B; Thu, 22 Aug 2024 08:12:42 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 19/30] arm64: add POE signal support Date: Thu, 22 Aug 2024 16:11:02 +0100 Message-Id: <20240822151113.1479789-20-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Stat-Signature: 43f7qn1c5em8qzpew91n5cmymihjzejg X-Rspamd-Queue-Id: 49FE040015 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724339567-687306 X-HE-Meta: U2FsdGVkX19nKNe1JEBBAYgTef6VjbgqTd6VRY58OqTKM7cH4vTlEG7G3hMj3EClM1XmAcuQJce2eLoYzFN5rJYHGWb8N745wWSgZZxUsKAUIouhFAWMkCdHHgI160Fxjrp6s1wmNsqd3LasEXOh/3YvqrBrPQMCtGc43X7Kyh72HOZKliA0VdSGIstlP3T8lAvsWiNWaM4RvTxm+y1TLbJtPjbg96imIryw3W681MLVsIogl9n9BF0KWRIVgU/NMku4vQTlWynmn2obf2on8jdNKDfGQkm/VbBBOPULpBtxyPbnhZXCWc3mEGueq30eejsNU9/mYDLmgtevVme29Ow1w4fCwiLmmhjrQzTri9FlXlOSW8h8w/Ri47/0I2IuLgnZ98QtBzGbQ5djS9tJ+mTLN2ttfjds15WC/zgTMHO2Ub4IPnCtHeINgB+PmXmwDzwugNps07j+djSQNLdWMYV0QuSkQFUZvN/geVoX4714EOy46pOBEu8CcS1Rbf+gQIQijWgzcB5xirbvok3c1sQVe5RAOmfFYWvLX0ktJTvFhIVvZ+kIJn+uwAS9BDc99NUZmXCMBmAPJiAfXqY7Xasjeg7+R+3mlRB96BWdmnlPoeTP8KFW+7gnSkONqp6Ug4vbiKcGfCD4GkuQahA8YS9MdPOGcCGWwflXhQNGTX0X6GJcA8ypyPMxYdvDZw4+Vjpb3MLQccwxElp+ExXybjUNfJrrvRCans9o4ePTpFjfJz9sdN6Z+ufxID+yZRD9Z3G1c7SJ5H9G2hg3Ovljznb0K5IYdfAH32mKbfTVZKNa0b4kQD71TgnBPszVHqLjmDoiw2aKSZrPamCDur919AFZltugJDW++KoTNBHCwcO4Xyg7e2TVlr9XyNu3OBRYreX6jWjfYdQoNCmYWRF4pgp657CoRMlGTUIry6wzJuhghX7iTxhbNjtNTYEje7secHJGho//SEIDqasp5Xz pLKskDPu lF8mZA7/tyQnovCMdZCpkce8uI0FpUiw5umX9K7Ljw5WafRvgJrsvaIuVy4OUy945OmI85gK4esgIn9YwC1fb6hL6CuVCEKvUBpNgP5b7Y5IqdSCOO9Jmq9ubuLdKWUMLhJpY7J2YJpZvDU+UPnwpoPBczPl1wYUedAyPfG3t9ram8gSzGHMIbwNtr1kNVRgNAvjNzzLb5EOebMpqLjClFYi6nw== 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: Add PKEY support to signals, by saving and restoring POR_EL0 from the stackframe. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Mark Brown Acked-by: Szabolcs Nagy Reviewed-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- arch/arm64/include/uapi/asm/sigcontext.h | 7 +++ arch/arm64/kernel/signal.c | 62 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git arch/arm64/include/uapi/asm/sigcontext.h arch/arm64/include/uapi/asm/sigcontext.h index 8a45b7a411e0..e4cba8a6c9a2 100644 --- arch/arm64/include/uapi/asm/sigcontext.h +++ arch/arm64/include/uapi/asm/sigcontext.h @@ -98,6 +98,13 @@ struct esr_context { __u64 esr; }; +#define POE_MAGIC 0x504f4530 + +struct poe_context { + struct _aarch64_ctx head; + __u64 por_el0; +}; + /* * extra_context: describes extra space in the signal frame for * additional structures that don't fit in sigcontext.__reserved[]. diff --git arch/arm64/kernel/signal.c arch/arm64/kernel/signal.c index 4a77f4976e11..561986947530 100644 --- arch/arm64/kernel/signal.c +++ arch/arm64/kernel/signal.c @@ -61,6 +61,7 @@ struct rt_sigframe_user_layout { unsigned long za_offset; unsigned long zt_offset; unsigned long fpmr_offset; + unsigned long poe_offset; unsigned long extra_offset; unsigned long end_offset; }; @@ -185,6 +186,8 @@ struct user_ctxs { u32 zt_size; struct fpmr_context __user *fpmr; u32 fpmr_size; + struct poe_context __user *poe; + u32 poe_size; }; static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) @@ -258,6 +261,32 @@ static int restore_fpmr_context(struct user_ctxs *user) return err; } +static int preserve_poe_context(struct poe_context __user *ctx) +{ + int err = 0; + + __put_user_error(POE_MAGIC, &ctx->head.magic, err); + __put_user_error(sizeof(*ctx), &ctx->head.size, err); + __put_user_error(read_sysreg_s(SYS_POR_EL0), &ctx->por_el0, err); + + return err; +} + +static int restore_poe_context(struct user_ctxs *user) +{ + u64 por_el0; + int err = 0; + + if (user->poe_size != sizeof(*user->poe)) + return -EINVAL; + + __get_user_error(por_el0, &(user->poe->por_el0), err); + if (!err) + write_sysreg_s(por_el0, SYS_POR_EL0); + + return err; +} + #ifdef CONFIG_ARM64_SVE static int preserve_sve_context(struct sve_context __user *ctx) @@ -621,6 +650,7 @@ static int parse_user_sigframe(struct user_ctxs *user, user->za = NULL; user->zt = NULL; user->fpmr = NULL; + user->poe = NULL; if (!IS_ALIGNED((unsigned long)base, 16)) goto invalid; @@ -671,6 +701,17 @@ static int parse_user_sigframe(struct user_ctxs *user, /* ignore */ break; + case POE_MAGIC: + if (!system_supports_poe()) + goto invalid; + + if (user->poe) + goto invalid; + + user->poe = (struct poe_context __user *)head; + user->poe_size = size; + break; + case SVE_MAGIC: if (!system_supports_sve() && !system_supports_sme()) goto invalid; @@ -857,6 +898,9 @@ static int restore_sigframe(struct pt_regs *regs, if (err == 0 && system_supports_sme2() && user.zt) err = restore_zt_context(&user); + if (err == 0 && system_supports_poe() && user.poe) + err = restore_poe_context(&user); + return err; } @@ -980,6 +1024,13 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user, return err; } + if (system_supports_poe()) { + err = sigframe_alloc(user, &user->poe_offset, + sizeof(struct poe_context)); + if (err) + return err; + } + return sigframe_alloc_end(user); } @@ -1042,6 +1093,14 @@ static int setup_sigframe(struct rt_sigframe_user_layout *user, err |= preserve_fpmr_context(fpmr_ctx); } + if (system_supports_poe() && err == 0 && user->poe_offset) { + struct poe_context __user *poe_ctx = + apply_user_offset(user, user->poe_offset); + + err |= preserve_poe_context(poe_ctx); + } + + /* ZA state if present */ if (system_supports_sme() && err == 0 && user->za_offset) { struct za_context __user *za_ctx = @@ -1178,6 +1237,9 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, sme_smstop(); } + if (system_supports_poe()) + write_sysreg_s(POR_EL0_INIT, SYS_POR_EL0); + if (ka->sa.sa_flags & SA_RESTORER) sigtramp = ka->sa.sa_restorer; else From patchwork Thu Aug 22 15:11:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773690 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 5AF21C3DA4A for ; Thu, 22 Aug 2024 15:12:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D412D6B0327; Thu, 22 Aug 2024 11:12:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF0556B0328; Thu, 22 Aug 2024 11:12:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B42E56B0329; Thu, 22 Aug 2024 11:12:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 947EA6B0327 for ; Thu, 22 Aug 2024 11:12:53 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4DCC214161D for ; Thu, 22 Aug 2024 15:12:53 +0000 (UTC) X-FDA: 82480223826.21.C09AD16 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf08.hostedemail.com (Postfix) with ESMTP id 885D3160025 for ; Thu, 22 Aug 2024 15:12:51 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339490; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q2RRx8rLkC5P4E8tx9Rk6lKwVPDwmtzasYWwFlURekc=; b=QZluXv6GRHc+EGU+ack24AzTIlp7mUfUStddBnOy/WgrmcleWec8/BD1eFjOAaxSblmo2+ FwiKrwJCGxCqPp/UVZWTTPcwPLYriVTc/N6SkNgh2xgRSHOEqxElWEpVZXkiXXkbzyAFAo OWi4ANmMTZ90Dr1d6SOqWiirYoMvIYw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339490; a=rsa-sha256; cv=none; b=y+m0GYSgGcM36JAolNcaOHkBPzc9sNxyfOMlGvwFuh7vuwZKS5TX7igBj1Sm/sO2c37w86 1KUK2Fz2adtvKJMqaXyQmJjcsDGYvrP5rdxZwXmxzpccZxQBdxdef2wYWon79zjhX/YvXd D1nOFoQaUsShxU1O1S8v3rg20XlRZBc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 E136A1595; Thu, 22 Aug 2024 08:13:16 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C28523F58B; Thu, 22 Aug 2024 08:12:46 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 20/30] arm64/ptrace: add support for FEAT_POE Date: Thu, 22 Aug 2024 16:11:03 +0100 Message-Id: <20240822151113.1479789-21-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Stat-Signature: h4nirgr18jmjqr8is465pcoftou98mhx X-Rspamd-Queue-Id: 885D3160025 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724339571-286971 X-HE-Meta: U2FsdGVkX18azekxLq7TcfXhmPqENdChPoXM60sPm1TmnQTmCx6jqZ6gOxQNgOdT9cAgvTQwVQg5WZmxDJAEzXrGbF6SOX4Ymgrl4hzbVAI5SvdvTFZwmeMDsPJJs+KAErCKI2lD4ZIH+1iRwH+FH8qMcdyHIMnCel337TsjEuEV14CNtOEJpdpdYzyX1Crp6szDfrBmYLxw3nop5g7sEwO6ytD4mG1OJUVBvV7A1FAgFJ2qyfDjnWWrNTpmlnq1JHs/0W/TwhtIcmUCoy/GXK5r9L5tk0GIpTP1l3vNZqKXJU3U2HXp8Spht5jWHLSKkIlJLZWvOkmGnHpvMPrnWN5uy0EVvESKgdxfzixq5/By5SHldEaG5GEu00oaQp9mbEaNJ7BJCBkgHpnOKbJ92jObI6dfXR+lkSoG3XYiX7Gs5KOGOZcBWcwElbvA3gfMk4oaf2P2U4NLBC6HJZk+DelbWUmgcbYnYcM99cgHZk7s2vDuzJHmX5n4sDPGzzEov4d3YJLlu7MOWMMY1wAA/mzv+E+godIAjjsnLDoljoDz5RfgsLbMgDGtuXrLnaMbti7AEz35uN3fOnpAAnVoBllX723WqsV8tm3gmO3Dd4MVvhGGgC2xe0rsLECuD88vi6+cjAZHmHI3Dv7kyDQePoSdyWcVzRcWc/G9+wnHpV72utHKZZPinDhNOk43sL7IBwNH7wrZ7fBPQiGcOQ4WI9ZX4/PIUbA6/86RhdOFCoCRimn8akYTMCH9mpjEaZPuto4wvueLsAhhsNR7urhBtzQg03mMMnlNvn3CuSueLQjqArZ/0pH6weiluDM7tt/BmJz3780d4eK4jfl6pgNa+ciyZG5e9RUGRSxPGzNygFvQtRFwd/LVduxT1Q9agWq5xRLtFYZXrQAj2RWHB7QioVSupGhrmETRGABywtubUGo69WduMWej3zFmEchupmHxLKS99AHvTWNAVZHjgZA iR2/MxpO dqduHslUx8wPPN5IBWLblZxspHh9I0m1m1tcRXTjRT570uBJWFM9LB8isGzvOhMi1h8Z3/EtwAjrrlnbVKL/YIdVNJlb1M0EfHh4fAUfsbtKJUXaNW7YOBJP0mry+wXOgk2C++7RNEfGJJiOSOPAHhbmWAfeIvoW4oJaZiotEK5JN77Z/TuBipkGudqt6pgJWfaZHeb9iXbbSzq67PPu3S0rjMM0VqPQhZdt1PfG/6qdoga2bpFp/+RFXJnRXMzVOexo9cZq5CuGEIXg= 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: Add a regset for POE containing POR_EL0. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Mark Brown Reviewed-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- arch/arm64/kernel/ptrace.c | 46 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/elf.h | 1 + 2 files changed, 47 insertions(+) diff --git arch/arm64/kernel/ptrace.c arch/arm64/kernel/ptrace.c index 0d022599eb61..b756578aeaee 100644 --- arch/arm64/kernel/ptrace.c +++ arch/arm64/kernel/ptrace.c @@ -1440,6 +1440,39 @@ static int tagged_addr_ctrl_set(struct task_struct *target, const struct } #endif +#ifdef CONFIG_ARM64_POE +static int poe_get(struct task_struct *target, + const struct user_regset *regset, + struct membuf to) +{ + if (!system_supports_poe()) + return -EINVAL; + + return membuf_write(&to, &target->thread.por_el0, + sizeof(target->thread.por_el0)); +} + +static int poe_set(struct task_struct *target, const struct + user_regset *regset, unsigned int pos, + unsigned int count, const void *kbuf, const + void __user *ubuf) +{ + int ret; + long ctrl; + + if (!system_supports_poe()) + return -EINVAL; + + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ctrl, 0, -1); + if (ret) + return ret; + + target->thread.por_el0 = ctrl; + + return 0; +} +#endif + enum aarch64_regset { REGSET_GPR, REGSET_FPR, @@ -1469,6 +1502,9 @@ enum aarch64_regset { #ifdef CONFIG_ARM64_TAGGED_ADDR_ABI REGSET_TAGGED_ADDR_CTRL, #endif +#ifdef CONFIG_ARM64_POE + REGSET_POE +#endif }; static const struct user_regset aarch64_regsets[] = { @@ -1628,6 +1664,16 @@ static const struct user_regset aarch64_regsets[] = { .set = tagged_addr_ctrl_set, }, #endif +#ifdef CONFIG_ARM64_POE + [REGSET_POE] = { + .core_note_type = NT_ARM_POE, + .n = 1, + .size = sizeof(long), + .align = sizeof(long), + .regset_get = poe_get, + .set = poe_set, + }, +#endif }; static const struct user_regset_view user_aarch64_view = { diff --git include/uapi/linux/elf.h include/uapi/linux/elf.h index b54b313bcf07..81762ff3c99e 100644 --- include/uapi/linux/elf.h +++ include/uapi/linux/elf.h @@ -441,6 +441,7 @@ typedef struct elf64_shdr { #define NT_ARM_ZA 0x40c /* ARM SME ZA registers */ #define NT_ARM_ZT 0x40d /* ARM SME ZT registers */ #define NT_ARM_FPMR 0x40e /* ARM floating point mode register */ +#define NT_ARM_POE 0x40f /* ARM POE registers */ #define NT_ARC_V2 0x600 /* ARCv2 accumulator/extra registers */ #define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note */ #define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */ From patchwork Thu Aug 22 15:11:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773691 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 39B22C3DA4A for ; Thu, 22 Aug 2024 15:12:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2FB36B0328; Thu, 22 Aug 2024 11:12:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDEC06B032A; Thu, 22 Aug 2024 11:12:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA7406B032C; Thu, 22 Aug 2024 11:12:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8B70F6B0328 for ; Thu, 22 Aug 2024 11:12:58 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3A77C14053F for ; Thu, 22 Aug 2024 15:12:58 +0000 (UTC) X-FDA: 82480224036.02.ABE5502 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id 0A5EC140004 for ; Thu, 22 Aug 2024 15:12:55 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339495; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YpUVqN2yD82ZzjqMsW13TV0m9gqSc3sr7jdaCm+yJjE=; b=xwTo4jc9UbhBl1FTJCYfuAzc72yQ7ksaMO1qRoMtQRI//8yHC1xRXJpPA/L9UjojWtycf/ 3YZLXU4S5kP4D4BB1cxwezZiLWx/5JugA4H3JBc4ucGQjHER61pyyGyEzcWUsBbGXEt5ME 52B5aVxaiEIshx+K4tU6G7I6+onPNSs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339495; a=rsa-sha256; cv=none; b=22IfhS6oI6yZckWSD/h1qbaIn0JzpBv9ONsSzHcHgQpaen+uM3aQbxMqeFykHvGB8VZxzw aIC3sln+7Wh3a814WTYyhQElDli1nxdMAkrdIbZJh1ie0K9wcffgsY285AUWn7i94m8lzH OMy+//Yf7S//GGUm6UhUyDNUgE9TPgc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 3AF6E1596; Thu, 22 Aug 2024 08:13:21 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1CD163F58B; Thu, 22 Aug 2024 08:12:50 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 21/30] arm64: enable POE and PIE to coexist Date: Thu, 22 Aug 2024 16:11:04 +0100 Message-Id: <20240822151113.1479789-22-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0A5EC140004 X-Stat-Signature: ciwnmfukwnpxu7qqccb7quq73wh1ncer X-HE-Tag: 1724339575-854841 X-HE-Meta: U2FsdGVkX1/oHE/WzS28YUht+HTMwH6fGHGrzvtBLwhh5vfz315q2ZyUU1kPjVg7yz2qjE8tSikGpqUzr3SqY8f4l63ClPbUaK8cseVUDWKm/NtvD9WUGFxwH2xvhlhLVEXR/i3exPgbp6JwtY5Rn0sBjM2gqQ51N6exGaMzJsDKblGp4QaDistcvz5KUzlUIgyKMOwRoP1rZ+A7OjUosclkBcGo04yuXDOogFogknt6v2nxjYSRfoyYKfegrNi19fb7mHys6JVJqzHxOOgOff/yDxVXKjyTsBmUNYTCQEXGYu9rG+AEW3d6kTmqn4AGF7UWOjvB+7RIvkhgNAnyVT5kgbJ6rmn9l7I++9+UBD/c9qE6ISVjX00mQvQfMnRlN6o+7q1LinkGWCT9N7ZSD1n7M6Uf4KZw4jrpBNe9qPmo0oCzEBzeO0WUt1ClX1Z/I+m9AplfCE885OzjKbi0bZvif0N3kujk3LStjNnmbu0MrU8AclfCMDNKTcDUVP67KK9hVRLncck+L52fir7uTJSkjDegT+BkUdolA61jjc3yE8PwMDmi2g6gcCexcZ3vSemGYcgTfNB5fcdEm8t8VFxqvbQqXfcG3LcJel/mQjSeigqAEB2KOUuN35d0xH+GDEYgk1KGRosqOOsNnFjjP9sdL6nG3rbz5eRN2ZWxDaCxKXHCBWaGDLNwXbH5QuLhr3m+31YJ143ljyhLLsGpN/XWvrzwnPzAe5xX+aPonrFsbHi0YxnmP4WENHrptrtMCscFXMavmjLs/NQJC6aQfZr2xmMHp2Yi3IP2FXcoz/PungUsy7NhYxtd6F6Lh2SHh3O9rAlaxPs56okhD2IPqcyFjY8tQXMyveuu2a5IaIFr6WktMjvl9/2sZwiL+wmrtgOzIQI96gNgU1l0XS8t5E50oYXSUpZDgRYkS2j/egD5cQLpsbYNgEl/KZpecRvugAl40XAB/DcUbdmjVkx 4X4GkLXe f+LaDjdY8Ct52FEHO/RWyTbBp4k+5p7MXe2oH/fMuHKFK/sO3p2cYRUlu4gJJgBcPp/G2ZpzE5t5rRnSyySi5v01+iYggdsASLos+epp76GLvGdFO8oqPb0DpISXe7PUaZ0ZWwCrI9zQJqzV5yFDYFs0j3wSUbejYjBCNH7w3595bYI74vvf5x4UEg/BHko2l18hJvYue0OXzwMCHXFe7d0+Jzw== 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: Permission Indirection Extension and Permission Overlay Extension can be enabled independently. When PIE is disabled and POE is enabled, the permissions set by POR_EL0 will be applied on top of the permissions set in the PTE. When both PIE and POE are enabled, the permissions set by POR_EL0 will be applied on top of the permissions set by the PIRE0_EL1 register. However PIRE0_EL1 has encodings that specifically enable and disable the overlay from applying. For example: 0001 Read, Overlay applied. 1000 Read, Overlay not applied. Switch to using the 'Overlay applied' encodings in PIRE0_EL1, so that PIE and POE can coexist. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/pgtable-prot.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git arch/arm64/include/asm/pgtable-prot.h arch/arm64/include/asm/pgtable-prot.h index b11cfb9fdd37..2a11d0c10760 100644 --- arch/arm64/include/asm/pgtable-prot.h +++ arch/arm64/include/asm/pgtable-prot.h @@ -154,10 +154,10 @@ static inline bool __pure lpa2_is_enabled(void) #define PIE_E0 ( \ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_X_O) | \ - PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX) | \ - PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RWX) | \ - PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY), PIE_R) | \ - PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW)) + PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX_O) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RWX_O) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY), PIE_R_O) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW_O)) #define PIE_E1 ( \ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_NONE_O) | \ From patchwork Thu Aug 22 15:11:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773692 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 D6EDDC52D7C for ; Thu, 22 Aug 2024 15:13:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59FB56B025F; Thu, 22 Aug 2024 11:13:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 527CD6B0260; Thu, 22 Aug 2024 11:13:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CA5C6B026A; Thu, 22 Aug 2024 11:13:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1CAA96B025F for ; Thu, 22 Aug 2024 11:13:02 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C00A8C16BD for ; Thu, 22 Aug 2024 15:13:01 +0000 (UTC) X-FDA: 82480224162.30.878BB30 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id 2BB7F80009 for ; Thu, 22 Aug 2024 15:12:59 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339563; a=rsa-sha256; cv=none; b=O98JAfTUYZNmDAiuteqVaug2dbSfsNvY30iNkeIhxHFRbo1WEvtiq/aoIZc66Su+iSZES4 Vt1A/X2sch2R6HvbmfWP+vuyHPGsORKN8jS+brmYbZ7a0/GR7CAoiKuL8fXtrd8M8Kc10T 0xR3KZKb+SdKtxdjda7ZSjY+4oKPRoE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339563; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bb7ZCtifyjmJorc1ZP8+hQKeVmZklK/Lz7jM+D30Hqo=; b=UsfNTMD8v6qtVqAGnpsmCnQjAzGw0i6U/sKQ+654zWCKQyvKukUznQXzhuzqtu3I9cSgvh r4NxSwAeFtV0lH60UNs3nCfwVUfToLfll4W57Q6boDScxFVdeYYADzTygYfxDK+/GcjOrX 4j6ppHxwArkSy1w0T3SPL5b61hmLHCQ= 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 893C615BF; Thu, 22 Aug 2024 08:13:25 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6ADCB3F58B; Thu, 22 Aug 2024 08:12:55 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 22/30] arm64: enable PKEY support for CPUs with S1POE Date: Thu, 22 Aug 2024 16:11:05 +0100 Message-Id: <20240822151113.1479789-23-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 2BB7F80009 X-Rspamd-Server: rspam01 X-Stat-Signature: i5uetkph955useiwrhm3n8933dacziso X-HE-Tag: 1724339579-511052 X-HE-Meta: U2FsdGVkX18y9K8wIBUTmj3d5K162ZAzGh5KaNKZ68qcL0nKo73SLsJHfKhXGITflv7Bn+yN/KRZ8Ffy56OnIVbFmrVjDnRpNbrjfVHjZGKcbjvIrknhX5l8IazGSNdooLCesZK36MRitcD7t12gH9GZIrOTn+9uCdr922qWVP9kO5JnGJz4cB1tfa0FsuX+BquqNJAZjylAwPh3M7nzpuO4Vw5CwoFcP98qlKavv12YNXpk3G4AIAQ/0lfIGAUhao+6JTlxyHUBrpU1PpdNgXkWIee3u3RiB0znfWPPjZkHDlfYHxbcPaEGMrwrgVgUgVVnQfRoEDR+G+BRmhFijTt0P9g2cyIMUZ8aCH8Oi25//qAbfE1D9Ykm09mRhcLnHfSY5pt+uqPP4RTv7x2Dg/b7AJF6muNISte+b1wPJ4tcoapTmrKZYAbMj0NFu4T4RsyUFZa9PI8KJl9v5UOFchq6JkfKFQfIflffSjOdcuFFmfYc1WIPViTj+/gnkZiL6R2uaDUkZvGHofTItZ1qK0fkdN2WIf1RpD33E9jd2TELWL4luE7+b7O40SdrPBn4z9zNqiCbQND2zKimONvNNGa+nkmfI9I7rtjB/7+VnvXM/akka5gj4nDZJfgZE3nvskuMG2UioQ7DgehNoChWLhtnzvjYBHzS1K6azUu154+dLlOsozib7c2VbfDD5H8iG+2TcLlwblJa5F269LZon3+Q1k2IFd5iTL7UIG7Ml26/QrU27k3AXc64+eA5mbxOLb5cTFJwGmyNEEZ+QzL0NJ5qQ3EyjVC8kVLFOcB/JPB4x816nDCwxqOxPx9f774h4Se8VQ5G/WB836Knx8rBpljCHTC70UCurK+CnBqUokcUFu8BJdG1+bo064r+NcFTRUAExWUaQnF9dPJlx3gzurJskQThLDJue/147Mm1MLvlBywnzJ2lDjx8wB1oYgNsgi554TTmJXOG/s3AvIm mxHOsfxQ Woslx6uUnnP8wNEb0IK0pHfaRWeS7xK+PpOlgwN1ojHWLVLnsMbthxfep2T1y8b7K/qevXkdwR3PvP93Iow1D6FqfPJr/5XdjIK4w1W0O/sitUfw4F4ObO4TFv5etjbpvZZXk1JLl5jBULZ3IIfrbGfFruCynrWCjddSa/LZ/4Yztvv/nKRPGQXKbJabQys7CLZ0jKKWyDt/vsnFmdc6sFd+djQ== 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: Now that PKEYs support has been implemented, enable it for CPUs that support S1POE. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Acked-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- arch/arm64/include/asm/pkeys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git arch/arm64/include/asm/pkeys.h arch/arm64/include/asm/pkeys.h index 32c352bb36b9..19eb1b12b7fc 100644 --- arch/arm64/include/asm/pkeys.h +++ arch/arm64/include/asm/pkeys.h @@ -17,7 +17,7 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, static inline bool arch_pkeys_enabled(void) { - return false; + return system_supports_poe(); } static inline int vma_pkey(struct vm_area_struct *vma) From patchwork Thu Aug 22 15:11:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773693 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 521B3C52D7C for ; Thu, 22 Aug 2024 15:13:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB78580039; Thu, 22 Aug 2024 11:13:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D67598001E; Thu, 22 Aug 2024 11:13:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE12B80039; Thu, 22 Aug 2024 11:13:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9D04D8001E for ; Thu, 22 Aug 2024 11:13:06 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1DE041610D5 for ; Thu, 22 Aug 2024 15:13:06 +0000 (UTC) X-FDA: 82480224372.05.6821A6E Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id 802341A001A for ; Thu, 22 Aug 2024 15:13:04 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339504; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UpfNylgfxY4txd7ztue1Ar+iWBvQcIDs522zyFJSfc4=; b=rm2HdfZbd/W/SQVDxSbKFxpfVscQYb6klY8pZ8Yx//t60jBu9QJXWvgNIv5ao9xc5G/9j4 7H6mv3HhZrNO3Uj/V80cSAPKX6B0JFoV3g88DWE+0ibrwn5rkvswki5dTaKUzu/hHVEyV9 zsPwLXJBXHW9baZAl9d9N6y81KEIkdw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339504; a=rsa-sha256; cv=none; b=a2SNuQzOJtUoBGl2C6rZrREQbkgfJYjK/HTthH8Pqije75fO9jM62ITYz4JdUKOVh4IU+P GUfoJUPsF8COvIKIMoHJjVo8zSo7lpsVfVHf3mYxJMtmWB+Ek8RVJGHsJyWNa4Iqik32ji tLbU302l+F9jiGk63hiPE821O0JI2XI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com 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 D6BB01650; Thu, 22 Aug 2024 08:13:29 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B8D833F58B; Thu, 22 Aug 2024 08:12:59 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 23/30] arm64: add Permission Overlay Extension Kconfig Date: Thu, 22 Aug 2024 16:11:06 +0100 Message-Id: <20240822151113.1479789-24-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 802341A001A X-Stat-Signature: zsfy1xgmcrt1zqtxa7ra595chz4wy6w7 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724339584-130846 X-HE-Meta: U2FsdGVkX1//jWVGpLDhKGrapRgvg+tJxOhPEuN2g74zZdyoLmkN179Y56OO/ozoLhHw7rOt8vWnwt3DO/XbrqCKesocqwIVQAeUS4yjkYHy9JfAOsXtpKVVrNFom81mx13RspdtljCs0vQfK0W3RYqq9rKWWfGQrDa43rNqxCeQPq0rf+7bfMFNRCmqmH72TPfwOoJqo86YMryzZiijZNrq6e07+3K/kt63JystWLPT3uVhV7YmW72qaDAqD+HyO/a6YManZrlkE10c2vfFiwcTbAe7/g8UuVitV0fJQiKRmFD10fh7o85JA0/Ab4oujQN5eEVTYoMmBpEoHziqzVTpnVzS305BUw5Gd3GUkh3lDSsGr365m2C9tezTDDs2WpfJA7Hz8mlisHCrtOzvkVlIje6tRmBEcWodRLsg5E2NN1wznCDG2mPOSWe1k4s1pSnXQ0Oa4D4Z10V5HjLJwGfJWiBkPokrWp6sFGlsD8c6a6bLCGtEG+8kHxxgA94EPhUW2HLiZhFK1ASfyKwfYzGVzse/z1b32LS8mO5KuX4HnX7CXhQkGYdecQ+6/ezxsA1Fr8rdR5Dz1H2iIdJOg8H5RLBQBKaB5EQmx56/j+E4sXOaOG7jWbQKM/KuTR1Yxy8IBOdroWCG7Sdo8TcRvem+pcQU3eW56zsdHHZzRBq9D/JvkXviMQ+NnqBy7zLKqNcfwZwR7F815ohpDFjrEpwVeGYAsdwIHdYrqG2/3VeN0GvmuVoQDt2tZaSl4vi3R6Eh/btYsOXLY9vFca1/HOnpwhx5yVw7+3/suR+IcI0CtdVWZSijNDVz4ZQPV71xD3u+GNU8NLfo7On/z+SEcsPLldvPGDiAPx42zv8DKn7SwOS5PR1hYICS+XiCVFPlIGIt0hxYD5A7qgOVpq+cGotQCFomneqj2e56DY3KA24KZIEgIi3bqJCMV3ZA8Qdi+5tPz1SITMB6d+9o6fk boESBo27 mcU9UhJdJdJZotnmp9S1URFM7t0fHhZdnoZpqUGB/YD+h+07/LjQD8BO0NJ+HHLOlYsi3c9G5bQG84f9UcunKyZO2aoD1fkTMQGRQuy+Yzh3r1WJH0GB+vcJ6pP2A3JhJztTAiHeruHA0wT25WFNf1DmphA0l5Ob35eDkz+ejcWAFbCc7AWCb5WL4X2InF/EqIzEtiAPmkSCiYwQahAIzYDjboQ== 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: Now that support for POE and Protection Keys has been implemented, add a config to allow users to actually enable it. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Anshuman Khandual Acked-by: Catalin Marinas --- arch/arm64/Kconfig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git arch/arm64/Kconfig arch/arm64/Kconfig index a2f8ff354ca6..35dfc6275328 100644 --- arch/arm64/Kconfig +++ arch/arm64/Kconfig @@ -2137,6 +2137,29 @@ config ARM64_EPAN if the cpu does not implement the feature. endmenu # "ARMv8.7 architectural features" +menu "ARMv8.9 architectural features" + +config ARM64_POE + prompt "Permission Overlay Extension" + def_bool y + select ARCH_USES_HIGH_VMA_FLAGS + select ARCH_HAS_PKEYS + help + The Permission Overlay Extension is used to implement Memory + Protection Keys. Memory Protection Keys provides a mechanism for + enforcing page-based protections, but without requiring modification + of the page tables when an application changes protection domains. + + For details, see Documentation/core-api/protection-keys.rst + + If unsure, say y. + +config ARCH_PKEY_BITS + int + default 3 + +endmenu # "ARMv8.9 architectural features" + config ARM64_SVE bool "ARM Scalable Vector Extension support" default y From patchwork Thu Aug 22 15:11:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773694 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 BD726C54722 for ; Thu, 22 Aug 2024 15:13:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DD2B8003A; Thu, 22 Aug 2024 11:13:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 464EA8001E; Thu, 22 Aug 2024 11:13:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D69E8003A; Thu, 22 Aug 2024 11:13:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0C00A8001E for ; Thu, 22 Aug 2024 11:13:11 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BA5021416D9 for ; Thu, 22 Aug 2024 15:13:10 +0000 (UTC) X-FDA: 82480224540.09.FB2E909 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf07.hostedemail.com (Postfix) with ESMTP id E867040026 for ; Thu, 22 Aug 2024 15:13:08 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339508; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dop1jxi1q30aR2qs1XTEluVvJyGHRlKot6WbNZEb224=; b=V0J99CKhOsqzttv5WXhuCKUY0xkNV0hTCvltSCuULHtUt31vnqW0U5Wf3NcR1jyV+GVUJN mJKidztASaLyWo8uplixuksiRKUJY1nzb/xUbaBjUOJJ0Q3Y52ycwIxgO3VYQq18TDamog HopClddibLqF2dO6fgzsoIXbio8y/Fo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339508; a=rsa-sha256; cv=none; b=ynGBrF+Xp92kLCMz0QFYq+Mp260yM6OpNen4XKMVKD7IniKY6sWgwPjWNY3UR28cdD7gxV 5KrFuDMCivKUXoYZY3lnY1q5NTu7kajUybnUq0sNo/LvkVSd/++Vh4N39/btDONUxLsMuI Bv3PcF7bI2OxtgohzTvl59Y34MLgvus= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 35721165C; Thu, 22 Aug 2024 08:13:34 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1275A3F58B; Thu, 22 Aug 2024 08:13:03 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 24/30] kselftest/arm64: move get_header() Date: Thu, 22 Aug 2024 16:11:07 +0100 Message-Id: <20240822151113.1479789-25-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E867040026 X-Stat-Signature: 7tudpa4u37nub357rtmpzhzf19xget5u X-HE-Tag: 1724339588-205874 X-HE-Meta: U2FsdGVkX1+ToSQom6it2JveMHO2zaveuM53u3GfGSi/CRYs0OyyNJ/cHG6VCU7mmay6oCGEZal6Go6rLTnwCz4olkPkVWnibydU66pzKIUCWX+4ByZOh/y6/wTqANLp97Fx5/25pOB/ITC9SE4fit+KbuV5J6lEGtLXrL5E6xxlfR3CcROmw3jGYhTagPu3bbw/MScvkPL4FmEhN+cKFWddLX9KCjrsLr0+Dk0qioXqUS2m01XYm4kHYc2BYeAENs4ZdZw5YwFX1JuRl6Ew2Sc/r3+xdg5d254SOzP/WWxa4tMxZBo8twZH61JZvOfBpRKG/fmeDdlSJWSRl6EC5RdlOVbvSP+5selyXaEMzW0uZguhEmDvXJuLB66aR8lhQ0DNrHFQ7yfP0oUY2h604Tsrc1g56ZJvPthCO4bKhuIDGvERRarNHArN2gHNov2yDZNk77MNdQ4xexmBm4OZJ08sJ317YWw2pE9besCXHzkNmqHuaSiXGP95MIYJmttfGz7L+C8T2Mbq0RFvkVnYA1ihXOviBXuHmXF6w0WdKzYToeoqtU06pMghGZz0EMxYgnvh+auyqeW0yRGwk1c2Vw0AY3Se7ZrfPKA+zCryylpI96NKx5GHnzD/rOljYBWb8LtcKDSX9rVHbTc2NNAMyQtZkBc/GE3PnU0Yk7hA1P2JchRc3j74fbPF0HAzmrmH2+JLxIbOSjX2vFn43QlXFacxcPaJbO5CmwEpQaQDsoEOKNDgLw5AjiEt9ozDGRHIl8Hve1H2UrL4g7TvK/88S+JjXmN8HT3+CYMI4KoutmuDpOme8MdGGEOFEG4CmEsEs+rW0ITI0mcE4j1z5q456gRHiIy2l1tVMNSRO+lFsUUnouSyaViRbmC/fgDWkoIdjwFdZUUEBSBv2nTmPDjLGa8VFKNe6yL9P7X9H5Ri8Mj53msPMHD+OGuV0Ui7zS3BXfYDuOHS+ofAtTi8nGe +g1VUQKt HR35EEwYZUzF2Mw9lgU2nMtEwo2uhJRjgt6upaH8ePsTgRMJo4eU2roVAVzC/3xrKLNn4bK/4ev0zubsnxMsX/EGd0zxH405RPrd8ff1F8odAYw8hHJS/6giVol+U6plLjmkFwyyD75nMst6zCX1XWrZZnWu9taciwxeOTMlCzF3IoSHbyMztITjMKXBWqigCazMVvKEX4QTJrDxoCTeOz0a9x4VK/66T8GNV5tfEeY7/z5ZjNKd9RKMH5Q8uu3oQ0s3xHajQlj9rVSlus8XzrFi/6+eC8NfzcnMirVF6+YOugkS8vBiL6cbNZA6Y6SBTWMWV87996VAD00GHJ/6g0yLoDIh3UQDeWtPJHm+N4LxxM1nEaidF2smuTA== 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: Put this function in the header so that it can be used by other tests, without needing to link to testcases.c. This will be used by selftest/mm/protection_keys.c Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Andrew Morton Cc: Shuah Khan Cc: Dave Hansen Cc: Aneesh Kumar K.V Reviewed-by: Mark Brown --- .../arm64/signal/testcases/testcases.c | 23 ----------------- .../arm64/signal/testcases/testcases.h | 25 +++++++++++++++++-- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git tools/testing/selftests/arm64/signal/testcases/testcases.c tools/testing/selftests/arm64/signal/testcases/testcases.c index 674b88cc8c39..e4331440fed0 100644 --- tools/testing/selftests/arm64/signal/testcases/testcases.c +++ tools/testing/selftests/arm64/signal/testcases/testcases.c @@ -6,29 +6,6 @@ #include "testcases.h" -struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic, - size_t resv_sz, size_t *offset) -{ - size_t offs = 0; - struct _aarch64_ctx *found = NULL; - - if (!head || resv_sz < HDR_SZ) - return found; - - while (offs <= resv_sz - HDR_SZ && - head->magic != magic && head->magic) { - offs += head->size; - head = GET_RESV_NEXT_HEAD(head); - } - if (head->magic == magic) { - found = head; - if (offset) - *offset = offs; - } - - return found; -} - bool validate_extra_context(struct extra_context *extra, char **err, void **extra_data, size_t *extra_size) { diff --git tools/testing/selftests/arm64/signal/testcases/testcases.h tools/testing/selftests/arm64/signal/testcases/testcases.h index 7727126347e0..3185e6875694 100644 --- tools/testing/selftests/arm64/signal/testcases/testcases.h +++ tools/testing/selftests/arm64/signal/testcases/testcases.h @@ -88,8 +88,29 @@ struct fake_sigframe { bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err); -struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic, - size_t resv_sz, size_t *offset); +static inline struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic, + size_t resv_sz, size_t *offset) +{ + size_t offs = 0; + struct _aarch64_ctx *found = NULL; + + if (!head || resv_sz < HDR_SZ) + return found; + + while (offs <= resv_sz - HDR_SZ && + head->magic != magic && head->magic) { + offs += head->size; + head = GET_RESV_NEXT_HEAD(head); + } + if (head->magic == magic) { + found = head; + if (offset) + *offset = offs; + } + + return found; +} + static inline struct _aarch64_ctx *get_terminator(struct _aarch64_ctx *head, size_t resv_sz, From patchwork Thu Aug 22 15:11:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773695 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 D7542C3DA4A for ; Thu, 22 Aug 2024 15:13:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6153A6B00DC; Thu, 22 Aug 2024 11:13:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C53F6B012B; Thu, 22 Aug 2024 11:13:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43D806B026F; Thu, 22 Aug 2024 11:13:15 -0400 (EDT) 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 26A166B00DC for ; Thu, 22 Aug 2024 11:13:15 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D97A812180F for ; Thu, 22 Aug 2024 15:13:14 +0000 (UTC) X-FDA: 82480224708.22.EA4873F Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf13.hostedemail.com (Postfix) with ESMTP id 2403B20018 for ; Thu, 22 Aug 2024 15:13:12 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf13.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339502; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JsKeRVCeIw9Bgaagj+6EgsxIap0Jm8Cb3TcgpNGDGbw=; b=MlBcv8AqWe5ySjFZQbyofhXW3hNXR4vIqYDsJ73hzgi+TU0AiMCpSTVGXRMna1qXOiA+dG N9HXSpP0um9OOCkzY1B2Y+9GB3c7HYV9xHMOe4/QmmpYWOPklR4iCr34VIwAXY03UXme3+ wjpCs+M034padQN2AqbvNBVGMsz6ZnY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339502; a=rsa-sha256; cv=none; b=6X700hUQdnrK+aLaqFmYDVDEGW30FrCNwHyKRUJYNLRUixHP5+2mnUCe6IKLDukcAUzFLV 1XvVQhrsDMLhec7OjkA6r4098HfZjOVqcUMSaCulCD1Bl7ejcncR8/PclEBuivSTL9NhjH dpTPSrR5z97TcwwRvKA/RuwfF08dYNU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf13.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com 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 7ED1F1682; Thu, 22 Aug 2024 08:13:38 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 60AA93F58B; Thu, 22 Aug 2024 08:13:08 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 25/30] selftests: mm: move fpregs printing Date: Thu, 22 Aug 2024 16:11:08 +0100 Message-Id: <20240822151113.1479789-26-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2403B20018 X-Stat-Signature: n5pkfcqipyoxgjyjzbb1ekrs6w3nhb9f X-Rspam-User: X-HE-Tag: 1724339592-637627 X-HE-Meta: U2FsdGVkX1+tPPOuFtk+BatITmH7eAaxX+ODxXZiSg1qFG+HO3LAo96coMzSAC024JM52+boj3IgAz9w2CdKhOz/j3GNXLgn9ED0tUqDv5vSToyJ2j1N4xWN8aLZ60yyd1ysx9kFh37ENGT3rWTH6/Bg7vCWoa5WFhw1vBofEw73IkOxsGsuka9rhgsUbeFRNPchN8mHQfkufWwlGL5X6JCcGh0ESJR8Alw7+qi9z5GdJ0hsBL1cQCFyMMrnSMFz3ebULSZclJUkdvSvmy+aAl7GaO9VCjZciBQNmStptUbCJjowCRjeLds0sFQywuYr53IRvhBLCxKXlc3MU8jKPi/lDb3PHl+iNPDIwQDZPXlCTqFpNq4prQ+L4LkzbcjxKJbqEeCcjYbzPVwlP6oh66dqbSv6eCjYjeCTnmc+OGYYnG3/rXMgiV4NXEbqL+51y8JUT1UFyTX0fdD45f+MCSTNngMWK2f8TeNywr3AadQopQiMfCuO8oAuEXm05C3E9z64vvPn2aiXYrDHJuc2Bm3DPuN3TN1t1Yf97ST8peUIPggcCNBgesueP6SY2jhle6G2rnEtDb0CEoZn6QRrmbjajmr24aQZ0mJ2JLIxKeAdwqcAO9VjneG19s04T8c+ZTYaJ101lmlqALr1s+S3Bxmadravgb+Wgu33MQs+dcJNLMsbQJ9LFsSlqXQeCbNHWRRp1i9TaqE1BePcT/NQtRksDMD1vpXxMNE/oJ3XKn0UXVtr3zDbUc4IC0OBddhWCXD1JxTmwfNtADNNaSlHMN96pDGG6w/SQNrQoO0MB1M1q+v28Gn7goWNucDubvAQBk5b+3froW7DPE6qGMpabAhoAEyAa1+8q6pkOBoiL5N1Wsha33J3MqeEgYvdCHz53wDTSGqsCG86zmJoQRXmXLJ4tJhtpZBwjtkMkW1QYSsydk9A/sG8i2CyMh4DRpFXYbPyCam0ia5q3Qt6Vq7 wj/Mz4td ZC6iM066Hh4nOB0nViWaW1rC2Qdy4nEFathIArRCI4ZKLxbXZ88BDmZznay7lTBME6BYqJF9Fy2vFdE68ceMXZzWlf18TUK64srvB8YRCJJOdYTkvZGvlFi9U6GBrMkDqU09FI2Wu/cP+gFk1EGNPbg1FAokLDhdwef7cjaMHmuT4I8zVqiJD9gOHCG4jVsqA38xVKqr+a/9MakucP0erofuSR7QFStOsX7d2gMO0fMu8Kys+c+W56+0xh/er5fEp1wUJjB1vbkkrxtHs+ouCq6RcItXcmUuy+Tu8mcqy0RHoLTqgM+NcDWUpjiH8L4LSC3+t 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: arm64's fpregs are not at a constant offset from sigcontext. Since this is not an important part of the test, don't print the fpregs pointer on arm64. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Andrew Morton Cc: Shuah Khan Cc: Dave Hansen Cc: Aneesh Kumar K.V Acked-by: Dave Hansen --- tools/testing/selftests/mm/pkey-powerpc.h | 1 + tools/testing/selftests/mm/pkey-x86.h | 2 ++ tools/testing/selftests/mm/protection_keys.c | 6 ++++++ 3 files changed, 9 insertions(+) diff --git tools/testing/selftests/mm/pkey-powerpc.h tools/testing/selftests/mm/pkey-powerpc.h index ae5df26104e5..6275d0f474b3 100644 --- tools/testing/selftests/mm/pkey-powerpc.h +++ tools/testing/selftests/mm/pkey-powerpc.h @@ -9,6 +9,7 @@ #endif #define REG_IP_IDX PT_NIP #define REG_TRAPNO PT_TRAP +#define MCONTEXT_FPREGS #define gregs gp_regs #define fpregs fp_regs #define si_pkey_offset 0x20 diff --git tools/testing/selftests/mm/pkey-x86.h tools/testing/selftests/mm/pkey-x86.h index 814758e109c0..b9170a26bfcb 100644 --- tools/testing/selftests/mm/pkey-x86.h +++ tools/testing/selftests/mm/pkey-x86.h @@ -15,6 +15,8 @@ #endif +#define MCONTEXT_FPREGS + #ifndef PKEY_DISABLE_ACCESS # define PKEY_DISABLE_ACCESS 0x1 #endif diff --git tools/testing/selftests/mm/protection_keys.c tools/testing/selftests/mm/protection_keys.c index eaa6d1fc5328..4337106a985e 100644 --- tools/testing/selftests/mm/protection_keys.c +++ tools/testing/selftests/mm/protection_keys.c @@ -314,7 +314,9 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext) ucontext_t *uctxt = vucontext; int trapno; unsigned long ip; +#ifdef MCONTEXT_FPREGS char *fpregs; +#endif #if defined(__i386__) || defined(__x86_64__) /* arch */ u32 *pkey_reg_ptr; int pkey_reg_offset; @@ -330,7 +332,9 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext) trapno = uctxt->uc_mcontext.gregs[REG_TRAPNO]; ip = uctxt->uc_mcontext.gregs[REG_IP_IDX]; +#ifdef MCONTEXT_FPREGS fpregs = (char *) uctxt->uc_mcontext.fpregs; +#endif dprintf2("%s() trapno: %d ip: 0x%016lx info->si_code: %s/%d\n", __func__, trapno, ip, si_code_str(si->si_code), @@ -359,7 +363,9 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext) #endif /* arch */ dprintf1("siginfo: %p\n", si); +#ifdef MCONTEXT_FPREGS dprintf1(" fpregs: %p\n", fpregs); +#endif if ((si->si_code == SEGV_MAPERR) || (si->si_code == SEGV_ACCERR) || From patchwork Thu Aug 22 15:11:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773696 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 741BBC52D7C for ; Thu, 22 Aug 2024 15:13:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3CF18003B; Thu, 22 Aug 2024 11:13:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EECD78001E; Thu, 22 Aug 2024 11:13:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D65638003B; Thu, 22 Aug 2024 11:13:19 -0400 (EDT) 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 B1B778001E for ; Thu, 22 Aug 2024 11:13:19 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6C571160786 for ; Thu, 22 Aug 2024 15:13:19 +0000 (UTC) X-FDA: 82480224918.01.7CB8A72 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 8482C80005 for ; Thu, 22 Aug 2024 15:13:17 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf02.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339537; a=rsa-sha256; cv=none; b=K5gs2hROEkpLRG+CivMUy6fc/A+CO10JUNCfz8c9uhSMIghTE5uOTNUZKO+J49rBItCKvq P65uvKs7qtR1WTjypOsxb4rpGqdSvAuDv3EDMJIkpJD7fbiN5V26AfLO/wROcgwLIMcOEG i81VL+LLYggkmfHoGMBGPi9lj2l8UJM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf02.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339537; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=unZjIO5N+sZCldykGsllM3Jx7NufijtBj+c5S3YcB88=; b=j8CXt3W8fyPAid2hHmmoPUPBm/YeXE5UkIsx2yU8qt9d+adlJCDNNcllImRude/9oz0Lt4 XQi9pTVEB7yNRDhFe3HmpZO7N5LXBiqnGxk8eY99IJ/KBg99DkUD7nRaNSnKFoXFvFJRgX 2sFm3AsLFGfxVWYig8hlYNiZK05pouI= 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 CDD7215DB; Thu, 22 Aug 2024 08:13:42 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AFB313F58B; Thu, 22 Aug 2024 08:13:12 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 26/30] selftests: mm: make protection_keys test work on arm64 Date: Thu, 22 Aug 2024 16:11:09 +0100 Message-Id: <20240822151113.1479789-27-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8482C80005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: eh5cqmewxmkja51akktbwt4idys3bsk8 X-HE-Tag: 1724339597-659839 X-HE-Meta: U2FsdGVkX1+RZ+LEuCSk2J24njEF7dNvWUrCsxs+ychr7ZNyKB2aSa4BfKzakOuiL/m0GHtDWjd681CCwGY3UGI0McGX1gny4Q1WV7WsaRFgGGOfPH7+mvEhkMsEVxkQY6IuSxBoMAuUxoHHjDV4/OqUzzxYOr+1/ysrY2kr/4KTxXFcRSdZp6O3DsysU4fm9peo0Wcb6bDzn0ghlcLmBuEBEmtwvwH/FY9HfRK+Xrsz2BKkAe4Gvs0StZ5HG1tDeiXWx/b11rFK9cH18QyVjh7ammfOwhZVjZoRazk+6xvtc9trYEvpuFG6qOFvz4XHvTSBRcC8RwdtK6/RkxkBuXwJPfwhZZFo/YcUfMl75jbZixSTNHXuhVj+nNMDeQiGGESt+j30alGpFnVoz1fgTAwwrqYAOucfPb2k4l0hHPqz4sI3q3JPE8ZhHFypDy4ZCn6U63D/mlN18+k8O7LdRbnxdXUbh9Uo1pbvr3sNTKU7V0Kr7gaS5EHn2v3hf/pLIQdyWE3PfM/xzmA3UCcLY7hTEICcTW4mMuGyB3kWjwO7bxxVO1C0ThrbkShspa5DuVXuGRpIuJfTGLEGhmEeEjKPpDUDQG8xtN5h1+eNOPTt1MOXWvKCo6jsdaU7aXY93ZgP/vIJjfjYt5Z+3AizYUCHPZC2Cb9LzocbgBngE3BCAvNUsrzWGF9gmRk9HwmwUoPjYquFs/+lZqKm41Aj8WDRz2iANZpXziGvsZNqjXl109X6oU3hOCr2sIEH1D9m35+/nmw8GpWYQ4ZZHPfZ0XtuOTwfz/SzbGb968HGF8i8JA0mFnD9sR2QYZNodym2+GErUkMlqruc3+n28GNWnu9d5kjdTqYBVMJnhI3ynwMHA6cnLe0NEamP3JOM0Pn1PW0XghJLzcGay1EsZsAesxyN5OmP8lrtiR8GwwpvMi9XrSDZhqvuAjUC49YKYQYV3dJ+GnSQ+7G49JEQweO m1d1tdzx 0CjkV90D2z0PWaGzOg2gsGx0QkmhnDeLuLHUFM1JO4urjd2nFm1wUT/hlP1KzN2rfno1R9t0PPadV9K6BWBJZnKci/I/MAR7X2lfpnpa4AnMa0e1bHHTrQcg3Y6jwoycIhB15pWhsTosD6rn0P3fXG2B1+c9pJ+P8KzcrK+FDaa8gvD2fqk448ZkoWQu75dNvEXolLq2KduwfmSbSRFlGoSdV031WnjlbQ+K5yermzjZx335rCHoYJRuQAF2mcE9fOYhcR031ZZRxuang/uiA1gDPvgLm/mWaAn9F+KuieS9yVnfedqkylxXKO6jx8eAGxEc9SOkx/6n3Pqw8Vdo0OMxk3o1meAqkhOAu88ESna53/bnBOeNg+1/ZvQ== 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: The encoding of the pkey register differs on arm64, than on x86/ppc. On those platforms, a bit in the register is used to disable permissions, for arm64, a bit enabled in the register indicates that the permission is allowed. This drops two asserts of the form: assert(read_pkey_reg() <= orig_pkey_reg); Because on arm64 this doesn't hold, due to the encoding. The pkey must be reset to both access allow and write allow in the signal handler. pkey_access_allow() works currently for PowerPC as the PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE have overlapping bits set. Access to the uc_mcontext is abstracted, as arm64 has a different structure. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Andrew Morton Cc: Shuah Khan Cc: Dave Hansen Cc: Aneesh Kumar K.V Acked-by: Dave Hansen --- .../arm64/signal/testcases/testcases.h | 3 + tools/testing/selftests/mm/Makefile | 2 +- tools/testing/selftests/mm/pkey-arm64.h | 139 ++++++++++++++++++ tools/testing/selftests/mm/pkey-helpers.h | 8 + tools/testing/selftests/mm/pkey-powerpc.h | 2 + tools/testing/selftests/mm/pkey-x86.h | 2 + tools/testing/selftests/mm/protection_keys.c | 103 +++++++++++-- 7 files changed, 247 insertions(+), 12 deletions(-) create mode 100644 tools/testing/selftests/mm/pkey-arm64.h diff --git tools/testing/selftests/arm64/signal/testcases/testcases.h tools/testing/selftests/arm64/signal/testcases/testcases.h index 3185e6875694..9872b8912714 100644 --- tools/testing/selftests/arm64/signal/testcases/testcases.h +++ tools/testing/selftests/arm64/signal/testcases/testcases.h @@ -26,6 +26,9 @@ #define HDR_SZ \ sizeof(struct _aarch64_ctx) +#define GET_UC_RESV_HEAD(uc) \ + (struct _aarch64_ctx *)(&(uc->uc_mcontext.__reserved)) + #define GET_SF_RESV_HEAD(sf) \ (struct _aarch64_ctx *)(&(sf).uc.uc_mcontext.__reserved) diff --git tools/testing/selftests/mm/Makefile tools/testing/selftests/mm/Makefile index cfad627e8d94..5f2ca591c956 100644 --- tools/testing/selftests/mm/Makefile +++ tools/testing/selftests/mm/Makefile @@ -106,7 +106,7 @@ TEST_GEN_FILES += $(BINARIES_64) endif else -ifneq (,$(findstring $(ARCH),powerpc)) +ifneq (,$(filter $(ARCH),arm64 powerpc)) TEST_GEN_FILES += protection_keys endif diff --git tools/testing/selftests/mm/pkey-arm64.h tools/testing/selftests/mm/pkey-arm64.h new file mode 100644 index 000000000000..580e1b0bb38e --- /dev/null +++ tools/testing/selftests/mm/pkey-arm64.h @@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2023 Arm Ltd. + */ + +#ifndef _PKEYS_ARM64_H +#define _PKEYS_ARM64_H + +#include "vm_util.h" +/* for signal frame parsing */ +#include "../arm64/signal/testcases/testcases.h" + +#ifndef SYS_mprotect_key +# define SYS_mprotect_key 288 +#endif +#ifndef SYS_pkey_alloc +# define SYS_pkey_alloc 289 +# define SYS_pkey_free 290 +#endif +#define MCONTEXT_IP(mc) mc.pc +#define MCONTEXT_TRAPNO(mc) -1 + +#define PKEY_MASK 0xf + +#define POE_NONE 0x0 +#define POE_X 0x2 +#define POE_RX 0x3 +#define POE_RWX 0x7 + +#define NR_PKEYS 8 +#define NR_RESERVED_PKEYS 1 /* pkey-0 */ + +#define PKEY_ALLOW_ALL 0x77777777 + +#define PKEY_BITS_PER_PKEY 4 +#define PAGE_SIZE sysconf(_SC_PAGESIZE) +#undef HPAGE_SIZE +#define HPAGE_SIZE default_huge_page_size() + +/* 4-byte instructions * 16384 = 64K page */ +#define __page_o_noops() asm(".rept 16384 ; nop; .endr") + +static inline u64 __read_pkey_reg(void) +{ + u64 pkey_reg = 0; + + // POR_EL0 + asm volatile("mrs %0, S3_3_c10_c2_4" : "=r" (pkey_reg)); + + return pkey_reg; +} + +static inline void __write_pkey_reg(u64 pkey_reg) +{ + u64 por = pkey_reg; + + dprintf4("%s() changing %016llx to %016llx\n", + __func__, __read_pkey_reg(), pkey_reg); + + // POR_EL0 + asm volatile("msr S3_3_c10_c2_4, %0\nisb" :: "r" (por) :); + + dprintf4("%s() pkey register after changing %016llx to %016llx\n", + __func__, __read_pkey_reg(), pkey_reg); +} + +static inline int cpu_has_pkeys(void) +{ + /* No simple way to determine this */ + return 1; +} + +static inline u32 pkey_bit_position(int pkey) +{ + return pkey * PKEY_BITS_PER_PKEY; +} + +static inline int get_arch_reserved_keys(void) +{ + return NR_RESERVED_PKEYS; +} + +void expect_fault_on_read_execonly_key(void *p1, int pkey) +{ +} + +void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) +{ + return PTR_ERR_ENOTSUP; +} + +#define set_pkey_bits set_pkey_bits +static inline u64 set_pkey_bits(u64 reg, int pkey, u64 flags) +{ + u32 shift = pkey_bit_position(pkey); + u64 new_val = POE_RWX; + + /* mask out bits from pkey in old value */ + reg &= ~((u64)PKEY_MASK << shift); + + if (flags & PKEY_DISABLE_ACCESS) + new_val = POE_X; + else if (flags & PKEY_DISABLE_WRITE) + new_val = POE_RX; + + /* OR in new bits for pkey */ + reg |= new_val << shift; + + return reg; +} + +#define get_pkey_bits get_pkey_bits +static inline u64 get_pkey_bits(u64 reg, int pkey) +{ + u32 shift = pkey_bit_position(pkey); + /* + * shift down the relevant bits to the lowest four, then + * mask off all the other higher bits + */ + u32 perm = (reg >> shift) & PKEY_MASK; + + if (perm == POE_X) + return PKEY_DISABLE_ACCESS; + if (perm == POE_RX) + return PKEY_DISABLE_WRITE; + return 0; +} + +static void aarch64_write_signal_pkey(ucontext_t *uctxt, u64 pkey) +{ + struct _aarch64_ctx *ctx = GET_UC_RESV_HEAD(uctxt); + struct poe_context *poe_ctx = + (struct poe_context *) get_header(ctx, POE_MAGIC, + sizeof(uctxt->uc_mcontext), NULL); + if (poe_ctx) + poe_ctx->por_el0 = pkey; +} + +#endif /* _PKEYS_ARM64_H */ diff --git tools/testing/selftests/mm/pkey-helpers.h tools/testing/selftests/mm/pkey-helpers.h index 1af3156a9db8..15608350fc01 100644 --- tools/testing/selftests/mm/pkey-helpers.h +++ tools/testing/selftests/mm/pkey-helpers.h @@ -91,12 +91,17 @@ void record_pkey_malloc(void *ptr, long size, int prot); #include "pkey-x86.h" #elif defined(__powerpc64__) /* arch */ #include "pkey-powerpc.h" +#elif defined(__aarch64__) /* arch */ +#include "pkey-arm64.h" #else /* arch */ #error Architecture not supported #endif /* arch */ +#ifndef PKEY_MASK #define PKEY_MASK (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE) +#endif +#ifndef set_pkey_bits static inline u64 set_pkey_bits(u64 reg, int pkey, u64 flags) { u32 shift = pkey_bit_position(pkey); @@ -106,7 +111,9 @@ static inline u64 set_pkey_bits(u64 reg, int pkey, u64 flags) reg |= (flags & PKEY_MASK) << shift; return reg; } +#endif +#ifndef get_pkey_bits static inline u64 get_pkey_bits(u64 reg, int pkey) { u32 shift = pkey_bit_position(pkey); @@ -116,6 +123,7 @@ static inline u64 get_pkey_bits(u64 reg, int pkey) */ return ((reg >> shift) & PKEY_MASK); } +#endif extern u64 shadow_pkey_reg; diff --git tools/testing/selftests/mm/pkey-powerpc.h tools/testing/selftests/mm/pkey-powerpc.h index 6275d0f474b3..3d0c0bdae5bc 100644 --- tools/testing/selftests/mm/pkey-powerpc.h +++ tools/testing/selftests/mm/pkey-powerpc.h @@ -8,6 +8,8 @@ # define SYS_pkey_free 385 #endif #define REG_IP_IDX PT_NIP +#define MCONTEXT_IP(mc) mc.gp_regs[REG_IP_IDX] +#define MCONTEXT_TRAPNO(mc) mc.gp_regs[REG_TRAPNO] #define REG_TRAPNO PT_TRAP #define MCONTEXT_FPREGS #define gregs gp_regs diff --git tools/testing/selftests/mm/pkey-x86.h tools/testing/selftests/mm/pkey-x86.h index b9170a26bfcb..5f28e26a2511 100644 --- tools/testing/selftests/mm/pkey-x86.h +++ tools/testing/selftests/mm/pkey-x86.h @@ -15,6 +15,8 @@ #endif +#define MCONTEXT_IP(mc) mc.gregs[REG_IP_IDX] +#define MCONTEXT_TRAPNO(mc) mc.gregs[REG_TRAPNO] #define MCONTEXT_FPREGS #ifndef PKEY_DISABLE_ACCESS diff --git tools/testing/selftests/mm/protection_keys.c tools/testing/selftests/mm/protection_keys.c index 4337106a985e..0789981b72b9 100644 --- tools/testing/selftests/mm/protection_keys.c +++ tools/testing/selftests/mm/protection_keys.c @@ -147,7 +147,7 @@ void abort_hooks(void) * will then fault, which makes sure that the fault code handles * execute-only memory properly. */ -#ifdef __powerpc64__ +#if defined(__powerpc64__) || defined(__aarch64__) /* This way, both 4K and 64K alignment are maintained */ __attribute__((__aligned__(65536))) #else @@ -212,7 +212,6 @@ void pkey_disable_set(int pkey, int flags) unsigned long syscall_flags = 0; int ret; int pkey_rights; - u64 orig_pkey_reg = read_pkey_reg(); dprintf1("START->%s(%d, 0x%x)\n", __func__, pkey, flags); @@ -242,8 +241,6 @@ void pkey_disable_set(int pkey, int flags) dprintf1("%s(%d) pkey_reg: 0x%016llx\n", __func__, pkey, read_pkey_reg()); - if (flags) - pkey_assert(read_pkey_reg() >= orig_pkey_reg); dprintf1("END<---%s(%d, 0x%x)\n", __func__, pkey, flags); } @@ -253,7 +250,6 @@ void pkey_disable_clear(int pkey, int flags) unsigned long syscall_flags = 0; int ret; int pkey_rights = hw_pkey_get(pkey, syscall_flags); - u64 orig_pkey_reg = read_pkey_reg(); pkey_assert(flags & (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE)); @@ -273,8 +269,6 @@ void pkey_disable_clear(int pkey, int flags) dprintf1("%s(%d) pkey_reg: 0x%016llx\n", __func__, pkey, read_pkey_reg()); - if (flags) - assert(read_pkey_reg() <= orig_pkey_reg); } void pkey_write_allow(int pkey) @@ -330,8 +324,8 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext) __func__, __LINE__, __read_pkey_reg(), shadow_pkey_reg); - trapno = uctxt->uc_mcontext.gregs[REG_TRAPNO]; - ip = uctxt->uc_mcontext.gregs[REG_IP_IDX]; + trapno = MCONTEXT_TRAPNO(uctxt->uc_mcontext); + ip = MCONTEXT_IP(uctxt->uc_mcontext); #ifdef MCONTEXT_FPREGS fpregs = (char *) uctxt->uc_mcontext.fpregs; #endif @@ -395,6 +389,8 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext) #elif defined(__powerpc64__) /* arch */ /* restore access and let the faulting instruction continue */ pkey_access_allow(siginfo_pkey); +#elif defined(__aarch64__) + aarch64_write_signal_pkey(uctxt, PKEY_ALLOW_ALL); #endif /* arch */ pkey_faults++; dprintf1("<<<<==================================================\n"); @@ -908,7 +904,9 @@ void expected_pkey_fault(int pkey) * test program continue. We now have to restore it. */ if (__read_pkey_reg() != 0) -#else /* arch */ +#elif defined(__aarch64__) + if (__read_pkey_reg() != PKEY_ALLOW_ALL) +#else if (__read_pkey_reg() != shadow_pkey_reg) #endif /* arch */ pkey_assert(0); @@ -1498,6 +1496,11 @@ void test_executing_on_unreadable_memory(int *ptr, u16 pkey) lots_o_noops_around_write(&scratch); do_not_expect_pkey_fault("executing on PROT_EXEC memory"); expect_fault_on_read_execonly_key(p1, pkey); + + // Reset back to PROT_EXEC | PROT_READ for architectures that support + // non-PKEY execute-only permissions. + ret = mprotect_pkey(p1, PAGE_SIZE, PROT_EXEC | PROT_READ, (u64)pkey); + pkey_assert(!ret); } void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) @@ -1671,6 +1674,84 @@ void test_ptrace_modifies_pkru(int *ptr, u16 pkey) } #endif +#if defined(__aarch64__) +void test_ptrace_modifies_pkru(int *ptr, u16 pkey) +{ + pid_t child; + int status, ret; + struct iovec iov; + u64 trace_pkey; + /* Just a random pkey value.. */ + u64 new_pkey = (POE_X << PKEY_BITS_PER_PKEY * 2) | + (POE_NONE << PKEY_BITS_PER_PKEY) | + POE_RWX; + + child = fork(); + pkey_assert(child >= 0); + dprintf3("[%d] fork() ret: %d\n", getpid(), child); + if (!child) { + ptrace(PTRACE_TRACEME, 0, 0, 0); + + /* Stop and allow the tracer to modify PKRU directly */ + raise(SIGSTOP); + + /* + * need __read_pkey_reg() version so we do not do shadow_pkey_reg + * checking + */ + if (__read_pkey_reg() != new_pkey) + exit(1); + + raise(SIGSTOP); + + exit(0); + } + + pkey_assert(child == waitpid(child, &status, 0)); + dprintf3("[%d] waitpid(%d) status: %x\n", getpid(), child, status); + pkey_assert(WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP); + + iov.iov_base = &trace_pkey; + iov.iov_len = 8; + ret = ptrace(PTRACE_GETREGSET, child, (void *)NT_ARM_POE, &iov); + pkey_assert(ret == 0); + pkey_assert(trace_pkey == read_pkey_reg()); + + trace_pkey = new_pkey; + + ret = ptrace(PTRACE_SETREGSET, child, (void *)NT_ARM_POE, &iov); + pkey_assert(ret == 0); + + /* Test that the modification is visible in ptrace before any execution */ + memset(&trace_pkey, 0, sizeof(trace_pkey)); + ret = ptrace(PTRACE_GETREGSET, child, (void *)NT_ARM_POE, &iov); + pkey_assert(ret == 0); + pkey_assert(trace_pkey == new_pkey); + + /* Execute the tracee */ + ret = ptrace(PTRACE_CONT, child, 0, 0); + pkey_assert(ret == 0); + + /* Test that the tracee saw the PKRU value change */ + pkey_assert(child == waitpid(child, &status, 0)); + dprintf3("[%d] waitpid(%d) status: %x\n", getpid(), child, status); + pkey_assert(WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP); + + /* Test that the modification is visible in ptrace after execution */ + memset(&trace_pkey, 0, sizeof(trace_pkey)); + ret = ptrace(PTRACE_GETREGSET, child, (void *)NT_ARM_POE, &iov); + pkey_assert(ret == 0); + pkey_assert(trace_pkey == new_pkey); + + ret = ptrace(PTRACE_CONT, child, 0, 0); + pkey_assert(ret == 0); + pkey_assert(child == waitpid(child, &status, 0)); + dprintf3("[%d] waitpid(%d) status: %x\n", getpid(), child, status); + pkey_assert(WIFEXITED(status)); + pkey_assert(WEXITSTATUS(status) == 0); +} +#endif + void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) { int size = PAGE_SIZE; @@ -1706,7 +1787,7 @@ void (*pkey_tests[])(int *ptr, u16 pkey) = { test_pkey_syscalls_bad_args, test_pkey_alloc_exhaust, test_pkey_alloc_free_attach_pkey0, -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) test_ptrace_modifies_pkru, #endif }; From patchwork Thu Aug 22 15:11:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773697 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 60C40C52D7C for ; Thu, 22 Aug 2024 15:13:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC9FA8003C; Thu, 22 Aug 2024 11:13:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E50FB8001E; Thu, 22 Aug 2024 11:13:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD59B8003C; Thu, 22 Aug 2024 11:13:23 -0400 (EDT) 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 A97CE8001E for ; Thu, 22 Aug 2024 11:13:23 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5DA2514053F for ; Thu, 22 Aug 2024 15:13:23 +0000 (UTC) X-FDA: 82480225086.10.78660C6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf25.hostedemail.com (Postfix) with ESMTP id B5A5AA0005 for ; Thu, 22 Aug 2024 15:13:21 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf25.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339535; a=rsa-sha256; cv=none; b=6cEQCGh8f7LTa3CInua1mLthJc65iA+ko53g/Z/alpIXt2ETDMx0f0h2HzpQsHvKvQzru5 /xtt9lUcfLAtsHt0PmQ/rvrrn684WGdiAQgn6Hfqnc1ENr1BxMDzTb9J8dChJwVtacRrOS JWNf37o9WDybDyWbwTMI6QV/55RUa1o= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf25.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339535; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MXCzl33CgYPuUp71NFeHGj+bfZwTzvm57ZuQHOtN0OI=; b=wC5mbFnDfyJSZokvldB7dkFyOi2V8gmiDZs1HkelLSWfwb4v8AOsykAR5Z0LCRkfGz30pt 2MsR4bxjHv6xDNnuV6nrlo8HT22H1wDd0329YGANWVAShF+G2/G1r+a/AQR7pQW4UadtLZ E1jK/5bhVE7x84gwn58rr0WcthCZN2w= 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 2889E1688; Thu, 22 Aug 2024 08:13:47 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0A2683F58B; Thu, 22 Aug 2024 08:13:16 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 27/30] kselftest/arm64: add HWCAP test for FEAT_S1POE Date: Thu, 22 Aug 2024 16:11:10 +0100 Message-Id: <20240822151113.1479789-28-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B5A5AA0005 X-Stat-Signature: ym6opicck3wtix9rjtwrk9pmqn6mg7x1 X-Rspam-User: X-HE-Tag: 1724339601-153711 X-HE-Meta: U2FsdGVkX193Hg/OuBHI/LncU1LlHHUHJBz6r63eoFM6qE0g9k1qJ9StzyY9Kol9+HWmj/z+2x9udk+41PkeKohbUW6fiquMMsA94+HejTtLdKMSZPveFImkHDNswQalB5zWp26ry1RDpFXNt5Q1jBOHGQZ8r+lm2f2/J8w0Z2CdKrTb+6B0Hogc159q//IAbIhHFgBkUO/k3t9IDj1Ppr2Axs2APrPgwcXno8VKI4+jjo+vtg+6Nn1Rz8jyr/tBfFCe0AsSYuNTM8v9CH3lpm7DYSknR+MuRKLPKJwaW7/3Pur/E7Tys8NnzQHNOOCVew+Qn+imWH9AZlxDN8amzYmSau0MPJe5dz9grSpUHTZ/2Op+oPrg3yoHX5cVh5PlcpeoHPifdc4rKAUAhQXLAhwK6T+eRSAbUTzNNFxUzJUw0ndBLKs02f8i1Nic54JRoluRIszqDjCXRdwUmfBxiokWPCak3yjp2eujwlou2OZAeJIkROVhsc+9yAtx8CumqPgDSwcZ+8MApZT2bxu5UPIoq3/D1azX0907xSBl6wSCzXfQYa3/ZLjK2YwtqInHyDxJOJv8eueEOeRWnnpbYObXBoeNUoQ3uS0DoSl1idbO8uRkaV7KL2O9M8A3MAkKDwyJ4mbb54UZ25OBzu5SJHX2EqejlH2M2WAVHrahPiTYZxejCGnHOUl32hgzaMO46FIJ8CiTRFVGZymza/KSfJjmXKNCN9uJRrwCDU0yTk91HjApYPraw6vswzT2iNNoSg/DVRFBiCe8X4zzr/1HzJvv74xOdwOesWwcUGGr2YEpqNAIPFeb5wvB0BNHl0JUS8goMGAf3UKjkcGaNZvFt0gwAvb+G2dx5FadQHuKWromJ0pQghdWcYHf5OW7+DwIydhHfBGlvbULGIJQmSofhXr+4JdovJ6MqHGodhZzTGteEhgIXvgMd/q9c3+oUUD2A5E/WwszzyEcBYvAncO z+pXb5Bl CH7WzVGcUIiCy64FA2dm8ZpYHuvXnpoonZztUkEpRvDawiLvbafm/Jpn440FjzFAdRVHRJCAl9ymzF6qJ1vuUbutR/VbWkK4iUDPHFltfNU83GzU03jvcNNv9wswPZHNzdxr0CzemBC6pR5Uh3R1rGOBialiu+2pnMT4zBVbG8mKiJG/6V0hLEIOmF7F/adGOSVkOIvbRelYxX8ge9qTtWupRWiJMmGVhd6aBVmZtUFASQY15vInG2wFnrKCEHrRDKZajbyKvQdejZcU= 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: Check that when POE is enabled, the POR_EL0 register is accessible. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Brown Cc: Shuah Khan Reviewed-by: Mark Brown --- tools/testing/selftests/arm64/abi/hwcap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git tools/testing/selftests/arm64/abi/hwcap.c tools/testing/selftests/arm64/abi/hwcap.c index d8909b2b535a..f2d6007a2b98 100644 --- tools/testing/selftests/arm64/abi/hwcap.c +++ tools/testing/selftests/arm64/abi/hwcap.c @@ -156,6 +156,12 @@ static void pmull_sigill(void) asm volatile(".inst 0x0ee0e000" : : : ); } +static void poe_sigill(void) +{ + /* mrs x0, POR_EL0 */ + asm volatile("mrs x0, S3_3_C10_C2_4" : : : "x0"); +} + static void rng_sigill(void) { asm volatile("mrs x0, S3_3_C2_C4_0" : : : "x0"); @@ -601,6 +607,14 @@ static const struct hwcap_data { .cpuinfo = "pmull", .sigill_fn = pmull_sigill, }, + { + .name = "POE", + .at_hwcap = AT_HWCAP2, + .hwcap_bit = HWCAP2_POE, + .cpuinfo = "poe", + .sigill_fn = poe_sigill, + .sigill_reliable = true, + }, { .name = "RNG", .at_hwcap = AT_HWCAP2, From patchwork Thu Aug 22 15:11:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773698 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 ABAE7C5321D for ; Thu, 22 Aug 2024 15:13:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37DCB8003D; Thu, 22 Aug 2024 11:13:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32C3B8001E; Thu, 22 Aug 2024 11:13:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CD698003D; Thu, 22 Aug 2024 11:13:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F111A8001E for ; Thu, 22 Aug 2024 11:13:27 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A3BF181788 for ; Thu, 22 Aug 2024 15:13:27 +0000 (UTC) X-FDA: 82480225254.14.6F8020D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf09.hostedemail.com (Postfix) with ESMTP id 15F8D14002E for ; Thu, 22 Aug 2024 15:13:25 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339589; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pU8VCuCTIjK7lA3OtU4H5wHq2JK3PvbDWYK/md3Tuyc=; b=oKlHSa6AKdJgRKhPvnBssdHtv83xOwdv17ESbv1p+PELC29JMJQT9BlhVlOZszDhOytD7H Yut66UzVAjqGPfxcWUD55QNjCRQbjCTcVnsw7XivnwE5Tb1MnTNUsK7+4pHDOG+4VWPwrG 2SPJ+0lNRHWwWxz0NDO0Kn6A2G2lcZI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339589; a=rsa-sha256; cv=none; b=Xax9xr2xtxDlMY6TeEsXjLHjRFeNPx01wke5ege0T26fRR8fw3txOxlOolrtY7RlUjQIxb FDcpTVpq4PLrXMJwqxqKqNLFaHoDma/W1WOXQC+t6HowOqNXRACcfodLcX4+/Oe7YOX2Lc qm6+XpceEnZY+t4+InOttrYvJJvUkyA= 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 7664D168F; Thu, 22 Aug 2024 08:13:51 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 580D03F58B; Thu, 22 Aug 2024 08:13:21 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 28/30] kselftest/arm64: parse POE_MAGIC in a signal frame Date: Thu, 22 Aug 2024 16:11:11 +0100 Message-Id: <20240822151113.1479789-29-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: owrqf983qorpcnud9sn8jjncf6x7cb7i X-Rspamd-Queue-Id: 15F8D14002E X-Rspamd-Server: rspam11 X-HE-Tag: 1724339605-552413 X-HE-Meta: U2FsdGVkX19cgzdZD/PZC05LQwRK7qlX3stA/1ixet4MHHwf0J+U3DdytL7glYVnhta0ipPtuDTIM85U/6Ec8mRkfAIMpEIVawB0+y5/rp2dYTz35CB1q9iXZJtT5yuurYpKqGI9X97jZ9gN3hrggF1a4RmBOi3xzBUUHriQcdGy+KTuXZbQbMl2PmklPx3Zr0Crow7ACbUrDf5MmIQnw4RH2Q/ZMdnF57XJeSBPNAJRDrFJyIzdoK88O4bapQuw08z2vpAah7jQVKtdQyFAMae3EUHxwTmKJsOpAu9I57NtNsToZRUWsBlGjQYyEHtVljDjXasHEzAgO5bm9tGxTcbQqED108FmfWN0ZcbxrXdFcRRhHGeRLCp32hg4AMeGRjsysxK0pzTdtQweeKybU2WKV3pznaQOiS5b+PSG73X8TfKUGk5uDCHmzIHRjExao5D8GbwZs6lckRFuc6/Sz6wHkGfXGYCstF8L9GLFhY4Ka3JxvLNSsFcTzV37JE5We0xaQdMLjOY/cwgAJWFVomJFjgvw99b9Q/CJYpWQUufra8URxNFkXQmPkZ61iWblCX0XGZw2JaU5j1YARK3nupHb699NgkZINEroIeTDccnoaK0a6C8qir53aTzKs2R6+RR4csS0IWnr/akHTnP7FBeh9GfgtR4Ma2hRHd6OhrOgDFwCxrSqMY132GYaJWub50xD6evZyZd39u7p9xkT+QVCbgt5BR5MkedsP9lBxKQN/2Oik7Xb2lvhuGPyypUYxwhlhrR1Dxbfcz4eTO+p5GsVgKZC7bEoQzYWt+kvEI5/J0T7Dv8hEY4PY3b0fuEgc5B9fcaulJmHO+ngUz87ntQ/GynnjAlpTaSnt5sJdYRN5NHdyIDuqzwf4236KaoHoczNZfdXRyIphPsMR6+Os64Hu9GqTY3AwSlNJtwajRn6EldisFGfpwCrB5PIKL7Fib2d3zPvEVuuzc4Q6s1 HMp5rKkm nDlbPoJNUPU9xMABucconKAxBJduqNRutbH7omSF2B2EOgx8oCg7/Ii5Dh7Y92ddVO2fnVAdzJOnsR4I8ENtC3/3vHZcNzV3qT51J891hbZqeuy1R/uuwDIKzXegcMfYEKibf/f1xeRJJklOGdHQDchwMDWLfzbuHgeK0nwiOg2FJftSvtjHN0SFyh3h+EtgJiYGhK8JJ98Llq+qPo/VP49d9RSO/3BPMTWvx9gPhDY0rMAeJBTCMiWHFMMfTfljUb81cWUyysS0LGsk= 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: Teach the signal frame parsing about the new POE frame, avoids warning when it is generated. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Brown Cc: Shuah Khan Reviewed-by: Mark Brown --- tools/testing/selftests/arm64/signal/testcases/testcases.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git tools/testing/selftests/arm64/signal/testcases/testcases.c tools/testing/selftests/arm64/signal/testcases/testcases.c index e4331440fed0..e6daa94fcd2e 100644 --- tools/testing/selftests/arm64/signal/testcases/testcases.c +++ tools/testing/selftests/arm64/signal/testcases/testcases.c @@ -161,6 +161,10 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) if (head->size != sizeof(struct esr_context)) *err = "Bad size for esr_context"; break; + case POE_MAGIC: + if (head->size != sizeof(struct poe_context)) + *err = "Bad size for poe_context"; + break; case TPIDR2_MAGIC: if (head->size != sizeof(struct tpidr2_context)) *err = "Bad size for tpidr2_context"; From patchwork Thu Aug 22 15:11:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773699 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 39F00C3DA4A for ; Thu, 22 Aug 2024 15:13:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBA118003E; Thu, 22 Aug 2024 11:13:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B69C68001E; Thu, 22 Aug 2024 11:13:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A31AE8003E; Thu, 22 Aug 2024 11:13:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 86BE18001E for ; Thu, 22 Aug 2024 11:13:32 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3070C141553 for ; Thu, 22 Aug 2024 15:13:32 +0000 (UTC) X-FDA: 82480225464.15.F91C99B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id 63A3A1C001B for ; Thu, 22 Aug 2024 15:13:30 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339502; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0v2110ndxTNPQPfCkNdnXDwPtBR9iCN3D470MJVMX2Y=; b=wdKSKf6UKF4wWhyYF93ZgLuC06+8x1hhaAqvW56sBhLsovtTrBhTMqJwhrrW5rOJypvEyQ 5OJbHVjDihqI0frV/Sw9N2kPEsL0kuWZIZuKEn9ncFb5Tz3MNs1YJ/pxPq0XuS1c7nBDAK pPgA8g4ByqO0nSZ8r5ebSNd53EE+NWg= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339502; a=rsa-sha256; cv=none; b=JMS6ZLX5O7mgI2NNBjCtqLe2fUXeNqbPxkjI+UJFSHPQcpMFQPf8FCOW50+VBUxld6hxz5 UO/RmD+pZBSwUMy+hhBn/WrxW48tVG80m6YfAhRVG3+aSI9gA/8wOAniAGUgqgsM7F6vep 1E0EiiePuYSSOZl9CtFlTZfxCo/9U6o= 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 C52391691; Thu, 22 Aug 2024 08:13:55 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A68193F58B; Thu, 22 Aug 2024 08:13:25 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 29/30] kselftest/arm64: Add test case for POR_EL0 signal frame records Date: Thu, 22 Aug 2024 16:11:12 +0100 Message-Id: <20240822151113.1479789-30-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 63A3A1C001B X-Stat-Signature: erg64nm3t3trj1mjujdjzxx11eh6t8b7 X-Rspam-User: X-HE-Tag: 1724339610-511033 X-HE-Meta: U2FsdGVkX19z09wpn6saDtsXStZy6dAOv/htpnWPBNppuOeIP8IMceQGDOEnWza/Yy3Sxh6ECYNQNUfd1k/3ym8VYYiOewNt19YH0WTJnTnx4Yo4lDcV58E5Egp8sSKAyQBnwlyFbbywx3bNPrgRqMuA5gUO9sxKOFmglLbCrnmX3rHkwcscwQ1sxPBb/Cqots0DbOgKh9Tuj/ZyP9rZ8QZERMw7jaYoZ+7ntelal2tMaL7NUbWVMQZ26SnGCd3KjZwJIu33nCPiiqoi3C9DgpvXPfeeOK4QL4mQjBdGRN2H8r4AkK/Yy8BzyzHxWy5s7P1+TXH06faKqqq/NmWmPLz4/jcmsStbvWUT9zGOrO77g00mujoVtpPOzqFBSMsLRIh+D5EL3S2PUhd8Ks2ZDEvz3gr9bWuy4LnpM/ujOMmIpK9WsI3WQCzwxBJkOkEIkpNCDLoICCejudLcVprj/0lHoSIiZbYbc56qImNGBRD6fJvEsEPyO4b0cXvQ8tm7bf0V6Pl4ljOpkZE6ocCbj7kEM0Cg1IFTh1Az8vo9aTBMstcUXGgaOij8psKsHSbvtg4id2nreyXhakIEkwwL58aR34qbcDUwlYDwf4meDeCM4uuqzy0bpuDQHKaiQDOPF4FWrai4pnKVrn8o6+HXjYrGtjNO69nyq9gn48O49bd5wFSUZRtoA10kmyx8vw4khW3xs4Dl8MxCAPi9DWVUsevip/XSjfoD5za+YYLsqURZEKec1zs0WI7RximtBFC3MEGKDmv/628r6vH3GhUgaNnjRMs850JvPDVBy1sgZwoEIi9l3W5PCsof/C7ECuaZomxbZY74N2if6Dj9wLMnkWtlgLmzcHEHWqtmjqUHGRFoWOZWSxfik/EV96JogrCmNUCU9lA4LaKNgJ0c7NOcI5vPTMLUBtRH14EZ/BVXmlB0/CctS3qYeanUVGIXaWYq2RXFtAMy8eTO5Plo0ps vfDih6vI gMWo2MBjbSz/grXOOKc5kzgSHic+a0tvoIHqs206GEgfLA8GWDFz0vw3U7fVrxF6iMCkGH1wlG+ccfcW8PiYXa0QWVs+H15vKRX2P0+6N3Eq92gls2RuK/W24h5I92DZJmvVPxX2sgpOC7M3nHzRtRLHQQ6jfVnA10F6LrFpDdaKBl7sFZyGyqS2WElGP++Lz15ks/U50z+CPDnY5/W5wHco72YT2olC4J0J6OWfkyAZjyZ0sxgKRMOOB/2xJTYe/HMw5C8p7wE0V5eyNHj8RUnXdDe2ykltqDawjdNiDn64XFl1QdcCInDgOMp1+/rpff14R 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: Ensure that we get signal context for POR_EL0 if and only if POE is present on the system. Copied from the TPIDR2 test. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Brown Cc: Shuah Khan Reviewed-by: Mark Brown Acked-by: Shuah Khan --- .../testing/selftests/arm64/signal/.gitignore | 1 + .../arm64/signal/testcases/poe_siginfo.c | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c diff --git tools/testing/selftests/arm64/signal/.gitignore tools/testing/selftests/arm64/signal/.gitignore index 1ce5b5eac386..b2f2bfd5c6aa 100644 --- tools/testing/selftests/arm64/signal/.gitignore +++ tools/testing/selftests/arm64/signal/.gitignore @@ -2,6 +2,7 @@ mangle_* fake_sigreturn_* fpmr_* +poe_* sme_* ssve_* sve_* diff --git tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c new file mode 100644 index 000000000000..36bd9940ee05 --- /dev/null +++ tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 Arm Limited + * + * Verify that the POR_EL0 register context in signal frames is set up as + * expected. + */ + +#include +#include +#include +#include +#include +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +static union { + ucontext_t uc; + char buf[1024 * 128]; +} context; + +#define SYS_POR_EL0 "S3_3_C10_C2_4" + +static uint64_t get_por_el0(void) +{ + uint64_t val; + + asm volatile( + "mrs %0, " SYS_POR_EL0 "\n" + : "=r"(val) + : + : ); + + return val; +} + +int poe_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc) +{ + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); + struct poe_context *poe_ctx; + size_t offset; + bool in_sigframe; + bool have_poe; + __u64 orig_poe; + + have_poe = getauxval(AT_HWCAP2) & HWCAP2_POE; + if (have_poe) + orig_poe = get_por_el0(); + + if (!get_current_context(td, &context.uc, sizeof(context))) + return 1; + + poe_ctx = (struct poe_context *) + get_header(head, POE_MAGIC, td->live_sz, &offset); + + in_sigframe = poe_ctx != NULL; + + fprintf(stderr, "POR_EL0 sigframe %s on system %s POE\n", + in_sigframe ? "present" : "absent", + have_poe ? "with" : "without"); + + td->pass = (in_sigframe == have_poe); + + /* + * Check that the value we read back was the one present at + * the time that the signal was triggered. + */ + if (have_poe && poe_ctx) { + if (poe_ctx->por_el0 != orig_poe) { + fprintf(stderr, "POR_EL0 in frame is %llx, was %llx\n", + poe_ctx->por_el0, orig_poe); + td->pass = false; + } + } + + return 0; +} + +struct tdescr tde = { + .name = "POR_EL0", + .descr = "Validate that POR_EL0 is present as expected", + .timeout = 3, + .run = poe_present, +}; From patchwork Thu Aug 22 15:11:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773700 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 875B7C52D7C for ; Thu, 22 Aug 2024 15:13:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1345F6B0142; Thu, 22 Aug 2024 11:13:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E6926B0145; Thu, 22 Aug 2024 11:13:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E79176B0143; Thu, 22 Aug 2024 11:13:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C13826B0138 for ; Thu, 22 Aug 2024 11:13:36 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7AB5514170E for ; Thu, 22 Aug 2024 15:13:36 +0000 (UTC) X-FDA: 82480225632.05.2DCC877 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id C4366180003 for ; Thu, 22 Aug 2024 15:13:34 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339574; a=rsa-sha256; cv=none; b=uwNXUExA7V75Nck3uriIliZO6/DHb+YEfRrpHkHTOetjJSqWQNIsrKaiUrYNtfAT0rSsA0 rUflnk/+HN1Kkqw6hviPklU0HtNZ7vUdC6DdGynoZ2oC9K26Ky+UwKJQ0BrsrXyMGUrHu/ dId8PDcNpO1+kiWiHY6UlUKAIVas0c8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@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=1724339574; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PtgYcAquF/+pUMmaCA/YK/T3qoyr8VMF+0I75YD9aNo=; b=1SxfBHM9fv+pWbIt7bvUDq0Di3Ee7QGRVOyp8gDmlKLU6EPmuMGEeNRazBlEAnKoHxln/q CpjhQ5TDlOHQF4PoX0nWAwfW8I35HseW9txK91TO1BH/vNWIoc8On+Z8QCcvmJqCS276tn tjlUyjM/lUysfhHwoinruxthbkx0oz4= 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 1EC09169C; Thu, 22 Aug 2024 08:14:00 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 00D0F3F58B; Thu, 22 Aug 2024 08:13:29 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 30/30] KVM: selftests: get-reg-list: add Permission Overlay registers Date: Thu, 22 Aug 2024 16:11:13 +0100 Message-Id: <20240822151113.1479789-31-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Stat-Signature: kx64pya3wmtgwozhiuzbfopt64mkgyqw X-Rspamd-Queue-Id: C4366180003 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724339614-935234 X-HE-Meta: U2FsdGVkX19naQs+NWnYdWzKl40wZGStbn7MCQF+gS+/psswQKOtwOoHvsoxUzX+/PpoS0oLMbAufamgCHjatXWCvfnk227k9SyfTZyGrAtzuhzGmEWEi64b5cl/8lGgjAeFEKDnQBEZq5aprdLayC7ZATvltOG4TImkKjeRhuYf+XRm+gkRBtOTraztN+CAMTWs8piRuSdqCmzcuj8/+4pvyB2RA4SFImsb4M+cVIetUI5LMYkA1ZbFuM8hlXKRW8TTqD0c6JtvsWmwBdsOMaydovxWlBTtPPSLp+pvYSTCqGUPPU2iWaRJL2BG1F8uZOB7gWUA+WSI4r0i+hZhRKrlUs8e/KvsoaxgaSdyjwop7W+q8Ja9jEnNRaRhKqsOQD9TKUEirZlZ92/Qj9EdqR1EuwcqLI3fPiSGj6SjPjAFSo0JYILlD2/Nf3SpLV74G2d8D742VAGqgUR4oVK7s3xKpK0Ouobw5iA2oWaujN+zCh0+GmJfksaruMpK5tddBnfoBIppLg0KFPGklIInJWGDFy+jkxsOgrv0udAGd4g1YV9NsBbN9t7dbxDtUAvnOYOQlZs2IOzEdHhtrwJIdeU8YTI0HnqntMFQZ43PfxUkelRMqocvYqtPHP4M8tdKOQ6cMrocFxjfMxJowJ0QLvRoSJ3Z7Ic18AcqOEszquxYLDCFNw7T1YnTQDpn4CMj/uu6piQTGLkya1rCQ5x7op8vool0d8spQIcdfINjcmsVwgkKqsbq70ixMbD9aCDUVWpANOxpFO1n4HWc4q41MF/sm8z7Jix1fdbYWD5xbRCTtjbzHmXkx/FGsJVxPr17LXML7SoyMllYf015IXISB4LnfejU74oNGLJx65CrgcnNpQMhI6vMmRtLux+3tq6aGdniL9McDDL9eAy7zXrN7rxOry945goC4oihyL88qqYShlt42zUN4VtGRmYZkZF594kwSL1yFFeu5sWt5Gp WnJf/Zaf 9NRA/kodgcdlNcAdUtlQ1v030myuU52Yyxthng8FEUS7KpcSVDTb3QoZf0CeUh/QOfyEwXZLYa+UIGXiuehezmjzBmx4YrbxtIW4WLfx+X5lPNFzkQOFtxfDifIznQHXD7qad5+CHEDcDP67JE2cN7ik7Lxq5FUy9mzhh9jxjqBLnKyk4FfezspMTOu6B8J/hynfMaanVPb2DwmXD80MKbiguGw== 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: Add new system registers: - POR_EL1 - POR_EL0 Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Marc Zyngier Cc: Oliver Upton Cc: Shuah Khan Reviewed-by: Mark Brown --- tools/testing/selftests/kvm/aarch64/get-reg-list.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git tools/testing/selftests/kvm/aarch64/get-reg-list.c tools/testing/selftests/kvm/aarch64/get-reg-list.c index 4abebde78187..d43fb3f49050 100644 --- tools/testing/selftests/kvm/aarch64/get-reg-list.c +++ tools/testing/selftests/kvm/aarch64/get-reg-list.c @@ -40,6 +40,18 @@ static struct feature_id_reg feat_id_regs[] = { ARM64_SYS_REG(3, 0, 0, 7, 3), /* ID_AA64MMFR3_EL1 */ 8, 1 + }, + { + ARM64_SYS_REG(3, 0, 10, 2, 4), /* POR_EL1 */ + ARM64_SYS_REG(3, 0, 0, 7, 3), /* ID_AA64MMFR3_EL1 */ + 16, + 1 + }, + { + ARM64_SYS_REG(3, 3, 10, 2, 4), /* POR_EL0 */ + ARM64_SYS_REG(3, 0, 0, 7, 3), /* ID_AA64MMFR3_EL1 */ + 16, + 1 } }; @@ -468,6 +480,7 @@ static __u64 base_regs[] = { ARM64_SYS_REG(3, 0, 10, 2, 0), /* MAIR_EL1 */ ARM64_SYS_REG(3, 0, 10, 2, 2), /* PIRE0_EL1 */ ARM64_SYS_REG(3, 0, 10, 2, 3), /* PIR_EL1 */ + ARM64_SYS_REG(3, 0, 10, 2, 4), /* POR_EL1 */ ARM64_SYS_REG(3, 0, 10, 3, 0), /* AMAIR_EL1 */ ARM64_SYS_REG(3, 0, 12, 0, 0), /* VBAR_EL1 */ ARM64_SYS_REG(3, 0, 12, 1, 1), /* DISR_EL1 */ @@ -475,6 +488,7 @@ static __u64 base_regs[] = { ARM64_SYS_REG(3, 0, 13, 0, 4), /* TPIDR_EL1 */ ARM64_SYS_REG(3, 0, 14, 1, 0), /* CNTKCTL_EL1 */ ARM64_SYS_REG(3, 2, 0, 0, 0), /* CSSELR_EL1 */ + ARM64_SYS_REG(3, 3, 10, 2, 4), /* POR_EL0 */ ARM64_SYS_REG(3, 3, 13, 0, 2), /* TPIDR_EL0 */ ARM64_SYS_REG(3, 3, 13, 0, 3), /* TPIDRRO_EL0 */ ARM64_SYS_REG(3, 3, 14, 0, 1), /* CNTPCT_EL0 */