From patchwork Fri Jun 10 23:35:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12878167 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 D718FC433EF for ; Fri, 10 Jun 2022 23:35:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C51F8D00F3; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6747B8D00E2; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 452AC8D00F3; Fri, 10 Jun 2022 19:35:40 -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 1BB938D00E2 for ; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E65C920AE3 for ; Fri, 10 Jun 2022 23:35:39 +0000 (UTC) X-FDA: 79563935598.13.1708585 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf10.hostedemail.com (Postfix) with ESMTP id 496AEC0042 for ; Fri, 10 Jun 2022 23:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654904138; x=1686440138; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ERLwkkEZpG4vAVBowWhSWiEDw3prKfNk8Uv0IINg8GY=; b=eO+CyPoBvEtSia28e0Oig19ljZC2Hugnu0u1cWyrFa9DducPe4+LtOAY 6jpLrhOsn4LU+X3Os6zTXcty41qsm8Y08V8mavpaR9dOIIpJsYCWhgtyc fdiSBcI1ZwUHFTKhcxraI8LzG+QnTw00DCbJ6fbJUccCzCwIxhy15Lk4Y Lr+6gPwCXSFH4hNlxByKIvE1FuCpjDPw1lCcZ1zqSblYf56uRhW983hR7 x7LaiI1J93Z2f93jyDZyTo55TCkPstaK/UvLoaoUpsTZwCNxaOEiGjLkd VEY0r3hrDalSfOayZPKFd/kc3CFLjv8wcoMgdlmeyOVkN9HFc5RRO/Dnz Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="275311572" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="275311572" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:37 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="760716836" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:36 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , Dave Hansen , "Aneesh Kumar K . V" , Sohil Mehta , 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 1/6] testing/pkeys: Add command line options Date: Fri, 10 Jun 2022 16:35:28 -0700 Message-Id: <20220610233533.3649584-2-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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654904138; a=rsa-sha256; cv=none; b=ziUnwkLpttSZgSSZyhb2hA/LemgHfeWFlvSCk3M0x/krJzup9n3iwRI4O0w9C9k4pxmLIh JxSui/BW8kkRme6x35FD4m4n97o7MXyYCSO7OS7vntHvpIm17hIYHFvjkuJ/sLx5eaygaQ lGlHLtdTP19rUhpxbL0wzs9Wo1+EJus= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=eO+CyPoB; 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=1654904138; 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=OIxSmmNZgb3ZOAN1Vi1YiiS/qbh9zt4pIJ3I0mK82yI=; b=Gi3Go2jb7pk68kZIwq3XA5QJzbPxKVKxQ4Z478Vi8St8vweVTrNengc5pfvRrxQlIFnfSe Z54geIUrUyC5dGk90VZk6ZnugBrb/z+COyeQPn6BzXy3tTHZpsNRGo7MJNntGu1eeKzzpa MG0zOH/LY5/Ge0iCgK2FQ3eWZc6tkfQ= X-Stat-Signature: j6w14q6th9u8irj1mygon9yej6p5r8g5 X-Rspam-User: X-Rspamd-Queue-Id: 496AEC0042 X-Rspamd-Server: rspam07 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=eO+CyPoB; 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: 1654904138-280943 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 It is more convenient to use command line options for debug and iterations vs changing the code and recompiling. Add command line options for debug level and number of iterations. $ ./protection_keys_64 -h Usage: ./protection_keys_64 [-h,-d,-i ] --help,-h This help --debug,-d Increase debug level for each -d --iterations,-i repeate test times default: 22 Cc: Dave Hansen Cc: Aneesh Kumar K.V Signed-off-by: Ira Weiny --- tools/testing/selftests/vm/pkey-helpers.h | 7 +-- tools/testing/selftests/vm/protection_keys.c | 59 +++++++++++++++++--- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index 92f3be3dd8e5..7aaac1c8ebca 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -23,9 +23,8 @@ #define PTR_ERR_ENOTSUP ((void *)-ENOTSUP) -#ifndef DEBUG_LEVEL -#define DEBUG_LEVEL 0 -#endif +extern int debug_level; + #define DPRINT_IN_SIGNAL_BUF_SIZE 4096 extern int dprint_in_signal; extern char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE]; @@ -58,7 +57,7 @@ static inline void sigsafe_printf(const char *format, ...) } } #define dprintf_level(level, args...) do { \ - if (level <= DEBUG_LEVEL) \ + if (level <= debug_level) \ sigsafe_printf(args); \ } while (0) #define dprintf0(args...) dprintf_level(0, args) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 291bc1e07842..d0183c381859 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -44,9 +44,13 @@ #include #include #include +#include #include "pkey-helpers.h" +#define DEFAULT_ITERATIONS 22 + +int debug_level; int iteration_nr = 1; int test_nr; @@ -361,7 +365,7 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext) * here. */ dprintf1("pkey_reg_xstate_offset: %d\n", pkey_reg_xstate_offset()); - if (DEBUG_LEVEL > 4) + if (debug_level > 4) dump_mem(pkey_reg_ptr - 128, 256); pkey_assert(*pkey_reg_ptr); #endif /* arch */ @@ -480,7 +484,7 @@ int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot, dprintf2("SYS_mprotect_key sret: %d\n", sret); dprintf2("SYS_mprotect_key prot: 0x%lx\n", orig_prot); dprintf2("SYS_mprotect_key failed, errno: %d\n", errno); - if (DEBUG_LEVEL >= 2) + if (debug_level >= 2) perror("SYS_mprotect_pkey"); } return sret; @@ -1116,7 +1120,7 @@ void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) pkey_write_deny(pkey); ret = read(test_fd, ptr, 100); dprintf1("read ret: %d\n", ret); - if (ret < 0 && (DEBUG_LEVEL > 0)) + if (ret < 0 && (debug_level > 0)) perror("verbose read result (OK for this to be bad)"); pkey_assert(ret); } @@ -1155,7 +1159,7 @@ void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) pkey_write_deny(pkey); futex_ret = syscall(SYS_futex, ptr, FUTEX_WAIT, some_int-1, NULL, &ignored, ignored); - if (DEBUG_LEVEL > 0) + if (debug_level > 0) perror("futex"); dprintf1("futex() ret: %d\n", futex_ret); } @@ -1626,11 +1630,52 @@ void pkey_setup_shadow(void) shadow_pkey_reg = __read_pkey_reg(); } -int main(void) +static void print_help_and_exit(char *argv0) +{ + printf("Usage: %s [-h,-d,-i ]\n", argv0); + printf(" --help,-h This help\n"); + printf(" --debug,-d Increase debug level for each -d\n"); + printf(" --iterations,-i repeate test times\n"); + printf(" default: %d\n", DEFAULT_ITERATIONS); + printf("\n"); +} + +int main(int argc, char *argv[]) { - int nr_iterations = 22; - int pkeys_supported = is_pkeys_supported(); + int nr_iterations = DEFAULT_ITERATIONS; + int pkeys_supported; + + while (1) { + static struct option long_options[] = { + {"help", no_argument, 0, 'h' }, + {"debug", no_argument, 0, 'd' }, + {"iterations", required_argument, 0, 'i' }, + {0, 0, 0, 0 } + }; + int option_index = 0; + int c; + + c = getopt_long(argc, argv, "hdi:", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'h': + print_help_and_exit(argv[0]); + return 0; + case 'd': + debug_level++; + break; + case 'i': + nr_iterations = strtoul(optarg, NULL, 0); + break; + default: + print_help_and_exit(argv[0]); + exit(-1); + } + } + pkeys_supported = is_pkeys_supported(); srand((unsigned int)time(NULL)); setup_handlers(); From patchwork Fri Jun 10 23:35:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12878168 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 D173DC43334 for ; Fri, 10 Jun 2022 23:35:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FF2B8D00F4; Fri, 10 Jun 2022 19:35:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F36338D00E2; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA1B48D00F4; Fri, 10 Jun 2022 19:35:40 -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 C507E8D00E2 for ; Fri, 10 Jun 2022 19:35:40 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9C61F2060D for ; Fri, 10 Jun 2022 23:35:40 +0000 (UTC) X-FDA: 79563935640.06.CF7ED6A Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf10.hostedemail.com (Postfix) with ESMTP id 0D901C0042 for ; Fri, 10 Jun 2022 23:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654904140; x=1686440140; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dcKqMrWYeQV/7jbUzKkDrJIenL/1HTp7HjU/MpsQUU0=; b=bVkhDmy2khbySI7i3WVbVTTnj1/RwINaxpLKfQpztvTjmoYoVCyaJ/4k VY+gmh9C2PeAv0Xiu5dt26WvtRqob5e02lPV4sY2UGVJT+tsLLIrQEXxB BkVkhPDNibftYMmPx3oVAPZK9TaJYe0dex8w/IJNxT/Cx0tezBSY7cYft zml4WXsmHnwJRVPBe7zgSoXZoqFEERmDdL7YYzNBam+U8BQmywVgbJJwM pF9bngVAMA0ozkchmwxPoIB5B419xuU2x8LSNN/ifXc/HUbSbKMv6Epn+ ZiBmsGpo5hCj4OOcgjerRh1fQPzITIObXz07LoyV6A00oxilRHFM2Fxlr Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="275311574" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="275311574" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:37 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="586450901" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:37 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , Dave Hansen , "Aneesh Kumar K . V" , Sohil Mehta , 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 2/6] testing/pkeys: Don't use uninitialized variable Date: Fri, 10 Jun 2022 16:35:29 -0700 Message-Id: <20220610233533.3649584-3-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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654904140; a=rsa-sha256; cv=none; b=5PJrYYx+LFVXeOoIHpUar3Emz0fu9KT+4M5MmqdsLIxF9E81VYYmyvKbj7PH0KpeKze5yv 6OXRSMw6odLOslgZ9IElxF4MDHByW2+NwTk31gwtNx2WKuSqia019eU9/WSe0zNzA99qaY 7bFFPNOi2ReebQEgZShk2GkU5fNYZUM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=bVkhDmy2; 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=1654904140; 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=KraTxf8cLbmMQv+W367tSpGKjtxXrEwm9VaXBu5iQ98=; b=AoKFykljG/YLGI2RIi4TS06iJZTAvytZh0PCLTioEwsnlu1mu6KEzD8XX8oQsca+xfwQn2 QqgvKsn+1tVFd3tvTmeOdv83+CHBQRzO4dLmQbgPAovOX3r+wPg3AjKQQDwozTcWHJIWse FkFT+hTS8u0aPIJZ94lmwJZMaDaAfTo= X-Stat-Signature: 55xkpcembidbw43os1o4ya7nzanbyaok X-Rspam-User: X-Rspamd-Queue-Id: 0D901C0042 X-Rspamd-Server: rspam07 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=bVkhDmy2; 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: 1654904139-257206 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 err was being used in test_pkey_alloc_exhaust() prior to being assigned. errno is useful to know after a failed alloc_pkey() call. Change err to errno in the debug print. Cc: Dave Hansen Cc: Aneesh Kumar K.V Signed-off-by: Ira Weiny --- tools/testing/selftests/vm/protection_keys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index d0183c381859..43e47de19c0d 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1225,9 +1225,9 @@ void test_pkey_alloc_exhaust(int *ptr, u16 pkey) int new_pkey; dprintf1("%s() alloc loop: %d\n", __func__, i); new_pkey = alloc_pkey(); - dprintf4("%s()::%d, err: %d pkey_reg: 0x%016llx" + dprintf4("%s()::%d, errno: %d pkey_reg: 0x%016llx" " shadow: 0x%016llx\n", - __func__, __LINE__, err, __read_pkey_reg(), + __func__, __LINE__, errno, __read_pkey_reg(), shadow_pkey_reg); read_pkey_reg(); /* for shadow checking */ dprintf2("%s() errno: %d ENOSPC: %d\n", __func__, errno, ENOSPC); From patchwork Fri Jun 10 23:35:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12878171 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 0F247C43334 for ; Fri, 10 Jun 2022 23:35:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E0658D00F8; Fri, 10 Jun 2022 19:35:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C5C98D00F7; Fri, 10 Jun 2022 19:35:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 233858D00F8; Fri, 10 Jun 2022 19:35:44 -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 E1EEF8D00E2 for ; Fri, 10 Jun 2022 19:35:43 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B719C4A3 for ; Fri, 10 Jun 2022 23:35:43 +0000 (UTC) X-FDA: 79563935766.16.847149B Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf21.hostedemail.com (Postfix) with ESMTP id 1C5591C0085 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=qDvqVZ/A3fM/nZiMoOHgbdE/phpXdySZH6n5Muy9S6I=; b=TJpBekqi2hduzLj9YIu9DDifYJpSA0C7myhRcjv/Vx4P2jk9JqZQ6sJA 1QgllMrF94rO0K1x8ePyYCeSxVJtRZIm9z+jv6nAlXl2YT5frLfQ9QHFw yWu/2IlYtxQUlawBlLI5MgJkW6af4+Y+Q9R5cbApqx1znApEckF28aJcz LrSBCeLim8sqC+fbbvpP0EsQfuJ/CyH9/IS4ActyizW7rwxwUZW268KKY 5HpXKMdbcfQ1V6xmaedN9NoQc9SJ/X3cD7qaWzM+7mXSAPsVgfza8acTB lJvVJQCQxwRaMnGTKS3XsknKT28hFYq5RKUw6ZqTQo0KXkHDuPKIF3EcC A==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="339530891" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="339530891" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:38 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="828500280" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:37 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , Dave Hansen , "Aneesh Kumar K . V" , Sohil Mehta , 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 3/6] testing/pkeys: Add additional test for pkey_alloc() Date: Fri, 10 Jun 2022 16:35:30 -0700 Message-Id: <20220610233533.3649584-4-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 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=P/13HPSlJBLJOJBlkyEzlwgidL2szixiGkS8FTGhazs=; b=3Cksbyeqa8E287P0AxFFJi6lqo32na58OE5CdRDSBCmi+OutFzOx9FO9ptMA8vmdMfhNEZ 4CEM7+k7WY051OBjJpSNUhaqebEn3G02V7MmXT9OYLaTKh0+7jwscdWqp5ZBUAtsUEM6NP iLRkF1E+W4xmY6fuCQdPQUmoeXm4pBM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TJpBekqi; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf21.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=ira.weiny@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654904141; a=rsa-sha256; cv=none; b=zXjMp6Gz/hhmAPG3duFHmqKnV6qxQOXYpJKSe1uQerVMtPGY2htgxBc7i3R4KAcWqUGBlZ kZY7hmLPECUQWC0t/hBEg7xHjU7eaFiSpFvO2Hhd09FIgZ6aEL3t51FgDeGtbc40a81bCm 4EyAks1pD5T84mRbm1MO4NG9cgt1vs0= X-Stat-Signature: 9c3mqcegs38yn5ykkiq63pj6qcpfby5p X-Rspamd-Queue-Id: 1C5591C0085 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TJpBekqi; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf21.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=ira.weiny@intel.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1654904140-671458 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 When pkeys are not available on the hardware pkey_alloc() has specific behavior which was previously untested. Add test for this. Cc: Dave Hansen Cc: Aneesh Kumar K.V Signed-off-by: Ira Weiny --- tools/testing/selftests/vm/protection_keys.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 43e47de19c0d..4b733a75606f 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1554,6 +1554,16 @@ void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) do_not_expect_pkey_fault("plain read on recently PROT_EXEC area"); } +void test_pkey_alloc_on_unsupported_cpu(void) +{ + int test_pkey = sys_pkey_alloc(0, 0); + + dprintf1("pkey_alloc: %d (%d %s)\n", test_pkey, errno, + strerror(errno)); + pkey_assert(test_pkey < 0); + pkey_assert(errno == ENOSPC); +} + void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) { int size = PAGE_SIZE; @@ -1688,6 +1698,8 @@ int main(int argc, char *argv[]) printf("running PKEY tests for unsupported CPU/OS\n"); + test_pkey_alloc_on_unsupported_cpu(); + ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); assert(ptr != (void *)-1); test_mprotect_pkey_on_unsupported_cpu(ptr, 1); From patchwork Fri Jun 10 23:35:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12878172 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 A84DACCA47B for ; Fri, 10 Jun 2022 23:35:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DA9A8D00E2; Fri, 10 Jun 2022 19:35:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DA828D00F9; Fri, 10 Jun 2022 19:35:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B9468D00E2; Fri, 10 Jun 2022 19:35:44 -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 197B38D00F7 for ; Fri, 10 Jun 2022 19:35:44 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E715635DE5 for ; Fri, 10 Jun 2022 23:35:43 +0000 (UTC) X-FDA: 79563935766.21.9CB91B2 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf04.hostedemail.com (Postfix) with ESMTP id 3155240073 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=MchtFdici9/LHAAi4sFR4mcD0phAyK+8tBE2Ictb0Iw=; b=MlsOEH6A+4f5IvVac2IUil0POUdmxN+PhXCdyQ86Sw9o5abuVhu1Wc4Q 0G5R9xaTzB3+klVXEjnlqcga2ANy3CTp9MEKe1xr0exRN4FcOdcdGwL6v gyNllFu402490aDogaqbsf3M5S1y9CMQXM/svYpObWV2T07ukGo2u8lwv /RSHoYINBn73OacfczncGr+egRs9C7m5s7z8gMM4vYe+40lbgLxJtr/vt aC1VCxaCzIfqzPe7Vq8/bLS6e2OWhuY6UsJafUcQBDHqyuelp2BwpKsBc hk0OC7NtqNieCs3QurEZ2PcadULoDLk9gJ3638UCQp/DkrwvRLocCNYen Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="258214129" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="258214129" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:39 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="581302597" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:38 -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 , Sohil Mehta , Andrew Morton , 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 4/6] pkeys: Lift pkey hardware check for pkey_alloc() Date: Fri, 10 Jun 2022 16:35:31 -0700 Message-Id: <20220610233533.3649584-5-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 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=xuGf3Zw8CoyYfud5Z7iEh5ehVKS4FUO3uYKF7D7uZ+Q=; b=vy1iObLsBhFPqmAbzJfi3lLFUWZU1qGP5BYCWxOdda+o1++iAWSTQNAoQG5rBXs1iJRsGC mhDCtu00q33lKJbfWYLG54e+7qUHzn919En3Q+fBrhUdinfpn3WOdwJ8uOytv8mW7AhlaF IL3ahHWNt169MRNpPQpIZZLxokrHPWc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MlsOEH6A; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf04.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=ira.weiny@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654904141; a=rsa-sha256; cv=none; b=o90GjcoEEmB8ye+ITD0tmanUFrxOCHJuEcWc9A0YnN9eI3S7ScjYyQiPgJsoK83kc2rbPv cHhWahvVDSr+MjLEGdPgmMzLxiqKaaicRvrXTBl38z6znKdu6YrjQalHOckK/336+YbAqj ynLcJj8F57R//qf3T4DHKC1+ilyHJy0= X-Stat-Signature: os4wjeteuez1m1yssfi3igdygxzrcwhh X-Rspamd-Queue-Id: 3155240073 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MlsOEH6A; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf04.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=ira.weiny@intel.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1654904140-984221 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 pkey_alloc() is documented to return ENOSPC when the hardware does not support pkeys. On x86, pkey_alloc() incorrectly returns EINVAL. This is because mm_pkey_alloc() does not check for pkey support before returning a key. Therefore, if the keys are not exhausted pkey_alloc() continues on to call arch_set_user_pkey_access(). Unfortunately, when arch_set_user_pkey_access() detects the failed support it overwrites the ENOSPC return value with EINVAL. Ensure consistent behavior across architectures by lifting this check to the core mm code. Remove a couple of 'we' references in code comments as well. 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: Sohil Mehta Cc: Andrew Morton Cc: Dave Hansen Cc: Aneesh Kumar K.V Cc: linux-api@vger.kernel.org Fixes: e8c24d3a23a4 ("x86/pkeys: Allocation/free syscalls") Signed-off-by: Ira Weiny --- Thanks to Sohil for pointing out that the commit message could be more clear WRT how EINVAL is returned incorrectly. --- arch/powerpc/include/asm/pkeys.h | 8 +++----- mm/mprotect.c | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 59a2c7dbc78f..2c8351248793 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -85,18 +85,16 @@ static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) 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 + * Note: this is the one and only place to 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. */ u32 all_pkeys_mask = (u32)(~(0x0)); int ret; - if (!mmu_has_feature(MMU_FTR_PKEY)) - return -1; /* - * Are we out of pkeys? We must handle this specially because ffz() - * behavior is undefined if there are no zeros. + * Out of pkeys? Handle this specially because ffz() behavior is + * undefined if there are no zeros. */ if (mm_pkey_allocation_map(mm) == all_pkeys_mask) return -1; diff --git a/mm/mprotect.c b/mm/mprotect.c index ba5592655ee3..56d35de33725 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -773,6 +773,9 @@ SYSCALL_DEFINE2(pkey_alloc, unsigned long, flags, unsigned long, init_val) int pkey; int ret; + if (!arch_pkeys_enabled()) + return -ENOSPC; + /* No flags supported yet. */ if (flags) return -EINVAL; From patchwork Fri Jun 10 23:35:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12878169 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 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); /* From patchwork Fri Jun 10 23:35:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12878170 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 861F2C433EF for ; Fri, 10 Jun 2022 23:35:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 342368D00F6; Fri, 10 Jun 2022 19:35:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27F4B8D00E2; Fri, 10 Jun 2022 19:35:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00D898D00F6; Fri, 10 Jun 2022 19:35:42 -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 D82298D00E2 for ; Fri, 10 Jun 2022 19:35:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ADE0335DC1 for ; Fri, 10 Jun 2022 23:35:42 +0000 (UTC) X-FDA: 79563935724.02.E3CFC0F Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf10.hostedemail.com (Postfix) with ESMTP id 14DF4C004C for ; Fri, 10 Jun 2022 23:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654904142; x=1686440142; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XfSsZjEZ1l0M6Je8ux0RlvZeHHKfZHKU8L8K8HX1yVc=; b=KLIDghy+2mwQ4ZQ1m6ILXDXs+ttds2s6KsWK39jGuLDWkNl2IjGrBWNu 6or3H8zeWVHBcnrgo0J3OUcu8wObuDWE01Ms9E70jk6fTjkGgZ8nsJE5Z eziUBFuY6oc4Gm1Zhu8BFSJDdAH9Anz7A4pb41PCtBIWF8ztJjdGuxmvN BJbT7jIaAb+4JZquAsd+mSth/6HHZFBszgf/xbVcy+QYHoI8HxMBPf29k jQtAFb/wn7WmuTiGi/8Yivi6fY+JFv9awj6fzZadP2Hglo8dfXd1B6XCt UbF3q4Zw8ksqQ/nEsrA481oFn7Qcpp8hbqLwubT5bw8w1xcoOVhQa/dU5 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="275311587" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="275311587" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:41 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="760716868" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:41 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , Dave Hansen , "Aneesh Kumar K . V" , Sohil Mehta , 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 6/6] pkeys: Change mm_pkey_free() to void Date: Fri, 10 Jun 2022 16:35:33 -0700 Message-Id: <20220610233533.3649584-7-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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654904142; a=rsa-sha256; cv=none; b=Eb5r1Yit4iftI/+ccylFJ11Bm3JcY3m4MVQjejlcZ/a/IBC5aqUgekcljGgvUC8QAp42ia 0mPuV1QeJLs1YggRZsUNk2I/O+MOkZDvtqWjLKjhALTTPe7WEQHMivXS8LVPUdyR7y9R+j hdF0j9yM9nhMWYC0SY12noyRgaP1FjA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=KLIDghy+; 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=1654904142; 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=azjF+gHYp7kx8abvczMJd9cOPFVrjT1TXZedfPJ1RKM=; b=PfP7Wyq6UkBSAephqcT4pgL/w7pVuFS1fo82WPwjcBgGSJPz3sfBZG6vbs8eSihVxQD1zt Bn5teYHeEmFks741bZzaFOo3sondrIgl/XyAkfROJMyE9DBigrnpjWxoyFynj85OPaECXi cZjvrAMyrzqh8S0uboml7No5GgMzljI= X-Stat-Signature: xs96ipcghkyjktscnbm5kihzt7q9atwa X-Rspam-User: X-Rspamd-Queue-Id: 14DF4C004C X-Rspamd-Server: rspam07 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=KLIDghy+; 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: 1654904141-303361 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 Now that the pkey arch support is no longer checked in mm_pkey_free() there is no reason to have it return int. Change the return value to void. Cc: Dave Hansen Cc: Aneesh Kumar K.V Suggested-by: Sohil Mehta Signed-off-by: Ira Weiny --- arch/powerpc/include/asm/pkeys.h | 4 +--- arch/x86/include/asm/pkeys.h | 4 +--- include/linux/pkeys.h | 5 +---- mm/mprotect.c | 6 ++++-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index e96aa91f817b..4d01a48ab941 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -105,11 +105,9 @@ static inline int mm_pkey_alloc(struct mm_struct *mm) return ret; } -static inline int mm_pkey_free(struct mm_struct *mm, int pkey) +static inline void mm_pkey_free(struct mm_struct *mm, int pkey) { __mm_pkey_free(mm, pkey); - - return 0; } /* diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index da02737cc4d1..1f408f46fa9a 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -105,11 +105,9 @@ int mm_pkey_alloc(struct mm_struct *mm) } static inline -int mm_pkey_free(struct mm_struct *mm, int pkey) +void mm_pkey_free(struct mm_struct *mm, int pkey) { mm_set_pkey_free(mm, pkey); - - return 0; } static inline int vma_pkey(struct vm_area_struct *vma) diff --git a/include/linux/pkeys.h b/include/linux/pkeys.h index 86be8bf27b41..bf98c50a3437 100644 --- a/include/linux/pkeys.h +++ b/include/linux/pkeys.h @@ -30,10 +30,7 @@ static inline int mm_pkey_alloc(struct mm_struct *mm) return -1; } -static inline int mm_pkey_free(struct mm_struct *mm, int pkey) -{ - return -EINVAL; -} +static inline void mm_pkey_free(struct mm_struct *mm, int pkey) { } static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long init_val) diff --git a/mm/mprotect.c b/mm/mprotect.c index 41458e729c27..e872bdd2e228 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -809,8 +809,10 @@ SYSCALL_DEFINE1(pkey_free, int, pkey) return ret; mmap_write_lock(current->mm); - if (mm_pkey_is_allocated(current->mm, pkey)) - ret = mm_pkey_free(current->mm, pkey); + if (mm_pkey_is_allocated(current->mm, pkey)) { + mm_pkey_free(current->mm, pkey); + ret = 0; + } mmap_write_unlock(current->mm); /*