From patchwork Fri Aug 2 06:13:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aruna Ramakrishna X-Patchwork-Id: 13751141 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 C7856C52D71 for ; Fri, 2 Aug 2024 06:13:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B10E16B0089; Fri, 2 Aug 2024 02:13:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A70F66B008A; Fri, 2 Aug 2024 02:13:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 912CC6B008C; Fri, 2 Aug 2024 02:13:40 -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 75E3F6B0089 for ; Fri, 2 Aug 2024 02:13:40 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1A2D714109F for ; Fri, 2 Aug 2024 06:13:40 +0000 (UTC) X-FDA: 82406289000.05.0D1CBAD Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf28.hostedemail.com (Postfix) with ESMTP id 467C8C000F for ; Fri, 2 Aug 2024 06:13:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=IzzimLWM; spf=pass (imf28.hostedemail.com: domain of aruna.ramakrishna@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=aruna.ramakrishna@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722579161; 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=8icyUdj43dziauj0xrsmeQuD/aTz/A64NReInB9aZYc=; b=hGkBdHEskb/CRY4jX+6qnGqSZ3wV9mJuYypCx7yn87RWV6KGc6Imf371SQmFmtftOv49B3 KW4YEttJKCojAxBWDW4Ziz3ginUJFp/SvUk5PS+iN7v0cM/8uMmwZ7mBn+mpGCTLeyRDL3 U0LMxb0fAc0HVGR0FFJKaRXAYhh+pt4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722579161; a=rsa-sha256; cv=none; b=kfa1OI+1548msusZKk7YW5aF6NnfUSiGL8Fhi84e325bX7iOJlD2f3XK4m6NKMw7cQxmDN we1ENgjfWmaZ36A6NTLY5W0OPpJzxKjsxPIbrmJqDMNMJCEsgWZAeHBxXTYLHgByXgGltO XFxYD5Odo4dMtpL8hF0DYarMyS4PI8g= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=IzzimLWM; spf=pass (imf28.hostedemail.com: domain of aruna.ramakrishna@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=aruna.ramakrishna@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4723fWdx014378; Fri, 2 Aug 2024 06:13:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=corp-2023-11-20; bh=8icyUdj43dziau j0xrsmeQuD/aTz/A64NReInB9aZYc=; b=IzzimLWMWvAGf6k3CGsloWcDCYr0RG w5rwngE4RulVFnzT80NeKxRx11hK2QlL8uteh8YCAR0dRjy4razzhLdEbEUYFV6w Dn0q7w0IZOJpOKtDx0ObwcPOV9hunJeH6U30Pd8vBu8szkrU28tAJZ54ce/6SBem YCd6np00C0r3ntp40kGz4QQfB+3Vaq4Q28ifr/XGTDFOLaKdDNZWHkeQDHvBE5do Eo5AVOGUHmGctyYbfcsqFF4Gkndp5eCrcMMjRZYjCueyI+4FuUSJFwb4a2ZTbXAz WOmmMaFimwbp9jAekUBttyFfIIvWn+zPe7yohnkOC/zPlz6MbJfZ6naw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40rjdy0fv7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 02 Aug 2024 06:13:24 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 4724blSM035586; Fri, 2 Aug 2024 06:13:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 40nvp16e9r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 02 Aug 2024 06:13:23 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 4726BM9Y012716; Fri, 2 Aug 2024 06:13:22 GMT Received: from aruramak-dev.osdevelopmeniad.oraclevcn.com (aruramak-dev.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.253.155]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 40nvp16e89-1; Fri, 02 Aug 2024 06:13:22 +0000 From: Aruna Ramakrishna To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, dave.hansen@linux.intel.com, tglx@linutronix.de, mingo@kernel.org, linux-mm@kvack.org, keith.lucas@oracle.com, jeffxu@chromium.org, rick.p.edgecombe@intel.com, jorgelo@chromium.org, keescook@chromium.org, sroettger@google.com, jannh@google.com, aruna.ramakrishna@oracle.com Subject: [PATCH v8 0/5] x86/pkeys: update PKRU to enable all pkeys before XSAVE Date: Fri, 2 Aug 2024 06:13:13 +0000 Message-Id: <20240802061318.2140081-1-aruna.ramakrishna@oracle.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-02_03,2024-08-01_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=990 mlxscore=0 suspectscore=0 malwarescore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408020042 X-Proofpoint-ORIG-GUID: m0w9hc6MQaIiUVwYaUupFncfHxGs7Xrm X-Proofpoint-GUID: m0w9hc6MQaIiUVwYaUupFncfHxGs7Xrm X-Rspamd-Queue-Id: 467C8C000F X-Stat-Signature: j4e8iyfqzb7bix4fiwwg4nzxo6zh95be X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722579218-321967 X-HE-Meta: U2FsdGVkX18tt4+LpmITrgeDgp4qgGFvz95BMLVwwKwtX5pKellSI9YirGT40LBn9XvFoE6PzN1lFBbI12OgHpnuduJJI0/WBvXjJAtsUpW9sxlt2TSIvCLiy/0BAZbUWTKO8xR62UiOBu3wNzSAFeZwmgzdczgKMUOTxSAFaLqUuynPh/UbvsL7VI4Q73lHDor+dcf1uKYNMyRvewC4k5tNIYRG7DzuKxIfRhNDnVLSonXdIFOYldh/OuW+hIyQHwQmcP/YbqWxnXVoLsxVgQAPUC81crxC2pZWzfG9lEqKZmXVUHo+nhxBhj1N7j5p6NdR8C778wzhqsdLd/+PjLEwn6pAOXYfrGRUyTnG69pSQ38z6O9BdrQoQUAM7jYT7vt19gUB8A/jn0fUahCJ9AKJJL/r97XXpni1B3ybCQ9CZPXwI4YPMgboUN6/L6YEC2F0uodAp1fiFzQ83kz58LYr9UpAqOswpl1IE/Qlj/1O0vkjxltdPcHj+71emBhpv1NmdZX+hl1QE3N9et92Z2BMioxkLeP5UUDnWP1m9VoMJdewq2Qg/dn7frCBeJfC/L57tuIDlI4slIiVBVZIbXERh4IWBcwLEv8+I8QPbi0tMPtmpHQ2V+ZhkwXjezV0vZyNrMM+6g+d1wsZzFXbUQyRXJ8Hls7wzzb8Cvhuw9O4oyUrdEALn5BUxP8IQ/87FhssEi88/WYPDqa++4sUzTolsd2rIHkNHoCiUDzUhJhrxGV1DMMZw88/RkQnH+S6gYgsA2f8wgViepBCNhvHHOZFZ6tLFVPIpYiVjmo+m8ZuLOVdt5IlzWz/9shKuaH58mxGhCjtZszbePYQxgx0PGWKneU84j0X0F7+iqYs0qBwWgwkUouSOz+Aho0Pc+1rLO4YREYDRHbhZTjn8iR2xbjnHvfW2+k0Fh1vYLNkMnJrLzO67ohMCaMOnPdgWB974gjqLMHcXU/KyCfgGWe cVztbbxx aiXHb8+PYro4/108350idRASTiyo3lllNLf13sEDDxacfyClHgZpDOQhu6zoqIjU/bwBPVZBN/lGhvybb9Yqblwcd6laCF6bJlhyG90W5mokSvQ1qYnUh2+apZPxxe7uYSiSbopEhP6Mtw0K/ShnabWRraBDA/u1OCmyZdNmRRKzC06kkToLEQXhyFA== 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: v8 updates: - Edited changelog for better readability v7 updates: - Rebased patchset to v6.11.0-rc1 - Removed ia32 and x32 function interface changes as PKRU is only supported in 64-bit mode, as suggested by Jeff Xu v6 updates: - Rebased patchset to v6.10.0-rc5 - Changed sig_prepare_pkru() back to enabling all pkeys, based on discussion with Jeff Xu v5 updates: - No major changes, mostly a resend of v4 - except for updating the commit description for patch 5/5 v4 updates (based on review feedback from Thomas Gleixner): - Simplified update_pkru_in_sigframe() - Changed sigpkru to enable minimally required keys (init_pkru and current pkru) - Modified pkey_sighandler_tests.c to use kselfttest framework - Fixed commit descriptions - Fixed sigreturn use case (pointed out by Jeff Xu) - Added a new sigreturn test case v3 updates (based on review feedback from Ingo Molnar and Dave Hansen): - Split the original patch into 3: - function interface changes - helper functions - functional change to write pkru on sigframe - Enabled all pkeys before XSAVE - i.e. wrpkru(0), rather than assuming that the alt sig stack is always protected by pkey 0. - Added a few test cases in pkey_sighandler_tests.c. I had some trouble adding these tests to tools/testing/selftests/mm/protection_keys.c, so they're in a separate file. Aruna Ramakrishna (4): x86/pkeys: Add PKRU as a parameter in signal handling functions x86/pkeys: Add helper functions to update PKRU on the sigframe x86/pkeys: Update PKRU to enable all pkeys before XSAVE x86/pkeys: Restore altstack access in sigreturn() Keith Lucas (1): selftests/mm: Add new testcases for pkeys arch/x86/include/asm/fpu/signal.h | 2 +- arch/x86/kernel/fpu/signal.c | 27 +- arch/x86/kernel/fpu/xstate.c | 13 + arch/x86/kernel/fpu/xstate.h | 2 + arch/x86/kernel/signal.c | 29 +- arch/x86/kernel/signal_64.c | 6 +- tools/testing/selftests/mm/Makefile | 2 + tools/testing/selftests/mm/pkey-helpers.h | 11 +- .../selftests/mm/pkey_sighandler_tests.c | 479 ++++++++++++++++++ tools/testing/selftests/mm/protection_keys.c | 10 - 10 files changed, 560 insertions(+), 21 deletions(-) create mode 100644 tools/testing/selftests/mm/pkey_sighandler_tests.c base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b prerequisite-patch-id: 7b2144970da943b19b53baab525a0fc653fcd7b8