From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E4E3CCA47D for ; Fri, 10 Jun 2022 23:35:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE1B28D00F5; Fri, 10 Jun 2022 19:35:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C69418D00E2; Fri, 10 Jun 2022 19:35:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB9F78D00F5; Fri, 10 Jun 2022 19:35:41 -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 8D63E8D00E2 for ; Fri, 10 Jun 2022 19:35:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6463535168 for ; Fri, 10 Jun 2022 23:35:41 +0000 (UTC) X-FDA: 79563935682.23.D04D027 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf10.hostedemail.com (Postfix) with ESMTP id D9C3EC0042 for ; Fri, 10 Jun 2022 23:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654904141; x=1686440141; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E0S7lAVxIGr1gPnTIVSUeXKWXCH1YKeQN7klBTJ1vLE=; b=YvhgNsZllbhq3CGtwWbV3LPRISi/QFFWzK0lkrlCBxC90SVV5lY7Zxh7 a5Ztfg9PAmNOoHYhOA8fU8HwwP8a7cXO0GDGIUfMNj0RznoE0PZuA8Lu/ Eyy+gcBlZQNDrPW4edqaj6L1QbSQ/bzwj/TnfJrWUU0g/UghzsRnlPN7k xqTOsK11BF0zSPxxpnwmorPYneggV/jsQK9ediOkx1GebFqRiOyd6OHo3 VYDB65Xw7g9OxLA3axFgsRVMieZaLjhszzb9kInGq3KN0/emEIVm7lETv WpMsDGFVDq84C4nWWeEN8rDdrpwNr1RDCuOJlIrvN9siTfnY95M5L8H2c w==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="275311584" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="275311584" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:40 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="909166943" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:40 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , ahaas@chromium.org, clemensb@chromium.org, gdeepti@chromium.org, jkummerow@chromium.org, manoskouk@chromium.org, thibaudm@chromium.org, Florian Weimer , Andrew Morton , Sohil Mehta , Dave Hansen , "Aneesh Kumar K . V" , x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH 5/6] pkeys: Up level pkey_free() checks Date: Fri, 10 Jun 2022 16:35:32 -0700 Message-Id: <20220610233533.3649584-6-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220610233533.3649584-1-ira.weiny@intel.com> References: <20220610233533.3649584-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654904141; a=rsa-sha256; cv=none; b=Q16A58M2eiIs0mtUDny/+pWztuFfVsRvuQSAp3nl4FiwcUBsoRAhpQa4CGnmpI3o6rnmLI TdV3Gh5Q/XaazDObRI4Nb3O+THsL4uqJWGGoIQ24FmbJEIISyjgFHSQEJ8q7/y3X1Crv5k oKyob7yocyN2aMz+OE25MG9eHSVpfwQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YvhgNsZl; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf10.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=ira.weiny@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654904141; 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:dkim-signature; bh=du9S7y8Xy10Bpst/+S6RATllP69ZxhoLR7RuoE8MzGs=; b=Iw07ZCe/iJQvlOwg8ugmagFlaEKWbfH1gHcXfPEMdhitaVYKfzmDCbGR0siaTd87JpDlN/ nkvkREYcgx+T8YTM5xeOPA3HVS0FeUT/IOKl2YKZHrXaB1fkWe3IpRkLT4GmoCpMEp/rkA +drIjnss2/kBJuYeEOXo7DTnu9ymhIw= X-Stat-Signature: ycq8agdcuqce1gwium96r7e8ydjuk8is X-Rspam-User: X-Rspamd-Queue-Id: D9C3EC0042 X-Rspamd-Server: rspam07 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YvhgNsZl; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf10.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=ira.weiny@intel.com X-HE-Tag: 1654904140-721766 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: From: Ira Weiny x86 is missing a hardware check for pkey support in pkey_free(). While the net result is the same (-EINVAL returned), pkey_free() has well defined behavior which will be easier to maintain in one place. For powerpc the return code is -1 rather than -EINVAL. This changes that behavior slightly but this is very unlikely to break any user space. Lift the checks for pkey_free() to the core mm code and ensure consistency with returning -EINVAL. Cc: ahaas@chromium.org Cc: clemensb@chromium.org Cc: gdeepti@chromium.org Cc: jkummerow@chromium.org Cc: manoskouk@chromium.org Cc: thibaudm@chromium.org Cc: Florian Weimer Cc: Andrew Morton Cc: linux-api@vger.kernel.org Cc: Sohil Mehta Cc: Dave Hansen Cc: Aneesh Kumar K.V Signed-off-by: Ira Weiny --- Thanks to Sohil for suggesting I mention the powerpc return value in the commit message. Also Sohil suggested changing mm_pkey_free() from int to void. This is added as a separate patch with his suggested by. --- arch/powerpc/include/asm/pkeys.h | 6 ------ arch/x86/include/asm/pkeys.h | 3 --- mm/mprotect.c | 8 ++++++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 2c8351248793..e96aa91f817b 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -107,12 +107,6 @@ static inline int mm_pkey_alloc(struct mm_struct *mm) static inline int mm_pkey_free(struct mm_struct *mm, int pkey) { - if (!mmu_has_feature(MMU_FTR_PKEY)) - return -1; - - if (!mm_pkey_is_allocated(mm, pkey)) - return -EINVAL; - __mm_pkey_free(mm, pkey); return 0; diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index 2e6c04d8a45b..da02737cc4d1 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -107,9 +107,6 @@ int mm_pkey_alloc(struct mm_struct *mm) 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; diff --git a/mm/mprotect.c b/mm/mprotect.c index 56d35de33725..41458e729c27 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -803,10 +803,14 @@ SYSCALL_DEFINE2(pkey_alloc, unsigned long, flags, unsigned long, init_val) SYSCALL_DEFINE1(pkey_free, int, pkey) { - int ret; + int ret = -EINVAL; + + if (!arch_pkeys_enabled()) + return ret; mmap_write_lock(current->mm); - ret = mm_pkey_free(current->mm, pkey); + if (mm_pkey_is_allocated(current->mm, pkey)) + ret = mm_pkey_free(current->mm, pkey); mmap_write_unlock(current->mm); /* -- 2.35.1