Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1854959lqt; Sun, 21 Apr 2024 12:17:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPdg4PSXTWJq9A+hF1n8CSQGb40HQZs8R5wnM0OsgX0dbFU5+L4Yv0jhblttBoVc0latRbVchHLN8zotJ6+zI5HVsH+orvXzs/MduO7g== X-Google-Smtp-Source: AGHT+IEJZGzFbeF19Q5jFjj5eTCv5k9+eYfAaTjDKGPDHHvWIph2tw7b/BbynuiO7gw+TPlm93jD X-Received: by 2002:adf:fa88:0:b0:34a:d130:611b with SMTP id h8-20020adffa88000000b0034ad130611bmr2292396wrr.17.1713727061365; Sun, 21 Apr 2024 12:17:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713727061; cv=pass; d=google.com; s=arc-20160816; b=HIQLEELGqM1f96QbmiYiOOmu8sNOjmTJ9k1CM9eo3b13yGvT8UyyPLD9AX7Z3ZjbQL /OmhvXwWYd9wKhVTygNYwNpzt/aZcK2np2Fr9hNIo1wEkXt9V/0WWc/KlT6ua3i6v6hC njvn9aDlVmDAKkq2cPChc+ZSbq9T/au7zJiUya0UJEpnUVaCRr6cTtsN8EcG5huVmEbn FGvmkoaFqe0pQjU/si7cyJnpBkB1soOgLrTvP4Zan+K8SgA3h6e+8PS7j7Kf8J54PyYV JNi2Dh/gmK0KUG/h5f0jWly107I88INV8KPH7t7ATanGFOUk/l7H2vQk5U5g46c8xC+o bpRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=p1VoGOGzxhtwT8+sGa7qwolMNXPHkLbcyItzkmhQziU=; fh=e7SUgze3bojFpK4UZT49qRWY2sE6F/naojafWbsBGMw=; b=R+HZbjesUb3Ei7OZgt0GGxy31Tu9YeLCOHdb00n3xzgR60/bGRgpa9EWi2OCYiCQRh OFr1WkGMyPD1llKd7G98qaRs08edambCHm+/VnOlupl4Ml6OicVaJHfdV92jx/rKVKic FdOKTWGdiMXR6f8CA/AH4XsjCaL7W6LP9hwCP8HrrQy7f4OBGdvhoe0zCrrcrrTO8fJo 04PtcSwjz/MeNppX+NNAc2gDhKBycUsdi5YuDdHOq3TOiFNc1VaPNuRl4QAI56Iol3qi U2LUiWa0wAeowEyhnQhANKBMNArxIT9ftjiKc2nlK6JzBdXY4EeT7D05WP0zbEijwsfA splQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Lo50098D; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152594-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152594-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g13-20020a1709063b0d00b00a462a5a4948si4918141ejf.276.2024.04.21.12.17.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 12:17:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152594-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Lo50098D; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152594-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152594-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F179A1F21458 for ; Sun, 21 Apr 2024 19:17:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7EDE3FB8B; Sun, 21 Apr 2024 19:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lo50098D" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2D323F8ED for ; Sun, 21 Apr 2024 19:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713727052; cv=none; b=HDGMoBmrZsqkJGsZAYLlLGKbTppn4uv71UeQvNpo5s8sBm7fFco7lNkdb3KwQ4QvRWCs8dBQl6LDMZhy8H00Kenxl3Jj3fkmtuqFhgS8clHCCDqW5g0nRo0FW7zVTDRlWLXWSC0AAMkI0JwdB72ZN6qUOmnBXrOpti3KT0wJmKA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713727052; c=relaxed/simple; bh=J0OuVPrjKnI+2yDEh2HpOwIHUwKzrGSnjwOnVRO+I9w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Q2/Xs2jLxPNnaPFcqQWJJKn3RoJE5amo95wFN2Hpe0iZVN732hW84SE6gRTebIxEhy5NIwIUpGayN2ghmuMx5jbsXd8Q/zKQyjWrA2yptVSVMghLSXKrLL3hVue+XoZ8KxXp1qi2a56A5tI0Fb+oZSQI+4FuhDr+XTNltjBBEXM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lo50098D; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4397CC113CE; Sun, 21 Apr 2024 19:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713727052; bh=J0OuVPrjKnI+2yDEh2HpOwIHUwKzrGSnjwOnVRO+I9w=; h=From:To:Cc:Subject:Date:From; b=Lo50098Dwtw0gXq6T/8vjxoZxdE43Ngplj+Obijq6Z6mDLMdct9VdG2tJ74CZS5RK clS1QjzfncEq24hRCG1AE7eP0CwdSRPoX0E0s5c12JUgc7g+IsHcXStVtW7k71ape7 79WpxIXrDLU8G8HEaTshLtRSDPei0B7cOJkokNEDJpWIjCuRnfiYCTl3YwYRB2HA6n rKvPvz2l+P79Kpoj1QVoF7TVAaTliS7I95amvGiziLJ2OHet3llbTldB2yzRzNkvex ItxEopqR/gqmLtntj5cW3rm7r/I1n0sVHxm72GBE10vUgPgp6DLC1nom2wesav3/+G 6uLJruFrwcBsQ== From: bp@kernel.org To: X86 ML Cc: LKML , David Kaplan , Borislav Petkov Subject: [PATCH] x86/cpu: Fix check for RDPKRU in __show_regs() Date: Sun, 21 Apr 2024 21:17:28 +0200 Message-ID: <20240421191728.32239-1-bp@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Kaplan cpu_feature_enabled(X86_FEATURE_OSPKE) does not necessarily reflect whether CR4.PKE is set on the CPU. In particular, they may differ on non-BSP CPUs before setup_pku() is executed. In this scenario, RDPKRU will #UD causing the system to hang. Fix by checking CR4 for PKE enablement which is always correct for the current CPU. The scenario happens by inserting a WARN* before setup_pku() in identiy_cpu() or some other diagnostic which would lead to calling __show_regs(). [ bp: Massage commit message. ] Signed-off-by: David Kaplan Signed-off-by: Borislav Petkov (AMD) --- arch/x86/kernel/process_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 7062b84dd467..6d3d20e3e43a 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -139,7 +139,7 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode, log_lvl, d3, d6, d7); } - if (cpu_feature_enabled(X86_FEATURE_OSPKE)) + if (cr4 & X86_CR4_PKE) printk("%sPKRU: %08x\n", log_lvl, read_pkru()); } -- 2.43.0