From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90967C25B75 for ; Fri, 31 May 2024 15:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zSRzPGrFmYezSD1chWVkIo1NMlDyjmfuLBB1CBPfA1M=; b=oxUdypuszYK3wv qcWhS8nAamd30KTe7TjiTvPnA3NVeF2BpuyUDUCRo4lykyo+EMR6Y86ZGZjnCKkrpxRvYkO26cPRm p74zonSHsSxL7oLErqRTwc6/9lfUivEO9JANxDtz02R7IDy+S1fefwZ2SGKLJ+tdDrWSg0y4YsORO qHydAXWt+8lxmlEOAhUKd577YcPFOl2kWfqVJo+Z6tOraTS3C0IYJhP1MBoR91Js7wd9PZfzfRQpM keVBLKV0Z3vXf4O5b/1z8DNUTgkcwvgNXrkaYl53UHkPN/V3SZboxLYmHxbXOScyXrGstklBK9Xfx OFW+PCEoLtuB6FW7DNHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD44t-0000000AfM5-11qP; Fri, 31 May 2024 15:21:59 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD44n-0000000AfJj-3AKo for linux-arm-kernel@lists.infradead.org; Fri, 31 May 2024 15:21:55 +0000 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 8D4BD1424; Fri, 31 May 2024 08:22: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 31AA63F641; Fri, 31 May 2024 08:21:44 -0700 (PDT) Date: Fri, 31 May 2024 16:21:38 +0100 From: Joey Gouly To: Szabolcs Nagy , dave.hansen@linux.intel.com Cc: linux-arm-kernel@lists.infradead.org, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.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, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v4 17/29] arm64: implement PKEYS support Message-ID: <20240531152138.GA1805682@e124191.cambridge.arm.com> References: <20240503130147.1154804-1-joey.gouly@arm.com> <20240503130147.1154804-18-joey.gouly@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240531_082153_935532_7608E86D X-CRM114-Status: GOOD ( 21.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Szabolcs, On Fri, May 31, 2024 at 03:57:07PM +0100, Szabolcs Nagy wrote: > The 05/03/2024 14:01, Joey Gouly wrote: > > Implement the PKEYS interface, using the Permission Overlay Extension. > ... > > +#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 (!arch_pkeys_enabled()) > > + 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: */ > > + if (init_val & PKEY_DISABLE_ACCESS) > > + new_por = POE_X; > > + else if (init_val & PKEY_DISABLE_WRITE) > > + new_por = POE_RX; > > + > > given that the architecture allows r,w,x permissions to be > set independently, should we have a 'PKEY_DISABLE_EXEC' or > similar api flag? > > (on other targets it can be some invalid value that fails) I didn't think about the best way to do that yet. PowerPC has a PKEY_DISABLE_EXECUTE. We could either make that generic, and X86 has to error if it sees that bit, or we add a arch-specific PKEY_DISABLE_EXECUTE like PowerPC. A user can still set it by interacting with the register directly, but I guess we want something for the glibc interface.. Dave, any thoughts here? > > > + /* 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 Thanks, Joey _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel