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 05B57C43334 for ; Fri, 10 Jun 2022 23:35:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8722D8D00F2; Fri, 10 Jun 2022 19:35:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 822448D00E2; Fri, 10 Jun 2022 19:35:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69C0C8D00F2; Fri, 10 Jun 2022 19:35:39 -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 54C728D00E2 for ; Fri, 10 Jun 2022 19:35:39 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 2ABD3120204 for ; Fri, 10 Jun 2022 23:35:39 +0000 (UTC) X-FDA: 79563935598.27.45217E6 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf23.hostedemail.com (Postfix) with ESMTP id 76F23140055 for ; Fri, 10 Jun 2022 23:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654904137; x=1686440137; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Js4f9kz2YaYmoc0VfWWcGpSWtATIkYgM+SbstpVR+cU=; b=gZtlPCR757mY1kF3Nocz85d4aJgrjhz1Qw0W8mwa9xrbwoqulRYy1y9V wmVpGKxo+7hcazAMmeF89oODk1aod8BWbpWnOq1geaWNDAeVv+iaV8yuk 9g1I/XxKNkXDRJc3VyAYTBCHfh0FY4wqdT/833UDpeHjPmiN9bJ4ApcmQ AzpECCnZjDgowDBRvuN52tMPjzE7TnywL+ngcnwXzok2CgSQ1fnOPLudL gciKcra2WstnOPHZxWh5Vd5OMkCzaNJfKMm1JPq/RvIbPScZKYcdHT3j/ RgM4qqUagcK9a9yZ1MPpgfVgrhtaC2RYmDHaHnlI9ZajgO3aTy8Cbleux A==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="266547093" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="266547093" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:35 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="638384941" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:35 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , 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 0/6] User pkey minor bug fixes Date: Fri, 10 Jun 2022 16:35:27 -0700 Message-Id: <20220610233533.3649584-1-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654904137; 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:references:dkim-signature; bh=lvHE5GcBBPysGr7cDOf2YKXd2dbtP8Z/Bh1lPfKg9S8=; b=R618vviiH3r92JpXdNfwQ4VpKH16amUkxzrGXc+2njFBxitS7hT+gT+LxzhU/LSjoCUW+o s4+S/cwPaHBdXOykRCUvVcOFmRYlBOFOnB8qfb5VYWPhUV04lTgW+MoFzfUl8/yayrIWPq oKw6ncHtpYy1jHvahD3z/PffLhLMI1Y= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gZtlPCR7; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf23.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 134.134.136.20) smtp.mailfrom=ira.weiny@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654904137; a=rsa-sha256; cv=none; b=LEyO6lPz0boDJYSiBHcsgujDyvPPw6klCqak8YWScTZmJ5JATppVonxKe6L7AGnjS96tvC +1a6IvOwH+wR6H26KM3CXkj9nbkiRw4DB0SeCbgLfx9jkSyIPfwA5WIQr8FNwSEsln5ZjD 0YL6zjy7MVV2nYFPiZ+MBlZlnP9F0ig= X-Stat-Signature: kakthx66uyhh7jnxaxxhdhsuz8urhx91 X-Rspamd-Queue-Id: 76F23140055 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gZtlPCR7; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf23.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 134.134.136.20) smtp.mailfrom=ira.weiny@intel.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1654904137-34131 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 While evaluating the possibility of defining a new type for pkeys within the kernel I found a couple of minor bugs. Because these patches clean up the return codes from system calls I'm sending this out RFC hoping that users will speak up if anything breaks. I'm not too concerned about pkey_free() because it is unlikely that anyone is checking the return code. Interestingly enough, glibc recommends not calling pkey_free() because it does not change the access rights to the key and may be subsequently allocated again.[1][2] The pkey_alloc() is more concerning. However, I checked the Chrome source and it does not differentiate among the return codes and maps all errors into kNoMemoryProtectionKey. glibc says it returns ENOSYS if the system does not support pkeys but I don't see where ENOSYS is returned? AFAICS it just returns what the kernel returns. So it is probably up to user of glibc. In addition I've enhanced the pkey tests to verify and test the changes. Thanks to Rick Edgecombe and Sohil Mehta for internal review. [1] Quote from manual/memory.texi: Calling this function does not change the access rights of the freed protection key. The calling thread and other threads may retain access to it, even if it is subsequently allocated again. For this reason, it is not recommended to call the @code{pkey_free} function. [2] PKS had a similar issue and went to statically allocated keys instead. Ira Weiny (6): testing/pkeys: Add command line options testing/pkeys: Don't use uninitialized variable testing/pkeys: Add additional test for pkey_alloc() pkeys: Lift pkey hardware check for pkey_alloc() pkeys: Up level pkey_free() checks pkeys: Change mm_pkey_free() to void arch/powerpc/include/asm/pkeys.h | 18 ++--- arch/x86/include/asm/pkeys.h | 7 +- include/linux/pkeys.h | 5 +- mm/mprotect.c | 13 +++- tools/testing/selftests/vm/pkey-helpers.h | 7 +- tools/testing/selftests/vm/protection_keys.c | 75 +++++++++++++++++--- 6 files changed, 86 insertions(+), 39 deletions(-) base-commit: 874c8ca1e60b2c564a48f7e7acc40d328d5c8733 -- 2.35.1