From patchwork Tue Apr 4 10:26:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 79006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2941649vqo; Tue, 4 Apr 2023 04:15:15 -0700 (PDT) X-Google-Smtp-Source: AKy350Zmkv6SMxohoUILdPl1gMf0Sd8UFKjQF7oSJNfO0lIegp3d2EyCnv6Q7Em6zbOS/fF31NE6 X-Received: by 2002:a17:90b:4b01:b0:23f:7625:49b6 with SMTP id lx1-20020a17090b4b0100b0023f762549b6mr2427513pjb.37.1680606915518; Tue, 04 Apr 2023 04:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680606915; cv=none; d=google.com; s=arc-20160816; b=s8Ylu/cUzthntFm7U/C1U0VQ9jpORL7PtMk9ymEZRcvPitPtv5fe4Df6QC+eDMewIT okGY9XU64226kQm2EQuSnVgWHJf9x6NVRPrvJMcNkU9w+ekJRgZxx6mdF+M3VkiZARey l2jev9r36hJYmSyUDMNdueA9rrWwmQz3BGWYtP24DPgk6zgwJYqBgAcbDyuJtVhQNTsc ba8tF1tXnIotyS5j9jf2QNV6uM2agL22/317h2fiLLU1KsPCpEDxVF6GbDF/0S7YSyuD iExjSc4eBEEip7aVqV136ysJYg0IdNH/p6AjPX2AEqif6VvHlYW5r+CBSoWSdHWqY3gC pV2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xiBkMNop4zUxT+iIfOnmWuMSopGG/t7/1Amns2i3v5k=; b=UEWvCSowiEU8Fd8SssNh1Z5jOpgCZ6DdzW8SPEO+cuDcC1OEEyjFY3C9x7ocvdJVmy xSp+tUSYPAbpvPCmpMTDx86NHAwBu2DjOWCbxwIFuiFIHbv7l4g5MWi3h1VVpPWuvv7N A2qhb/qBh6WdompmLEFlpKwzMt6p1SZ9JupJ16lmfQsOQCMbK3HDh6p2F/gYOxHLGceH JGNibZMKMovdPlvHx79teJI4v3DhV1aaiBqnUaBc+6geXg7IDpJjdPFJqk9Ex0xjok9b PKVVGg6N4awWqk1D+KdDI6RnHGE4Gyd+T7vszUlA7Ayz47HFCqkLVDD4m4nh5h/WIh/t 0L1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nZH5g8eD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c10-20020a634e0a000000b0050f8790a843si10201487pgb.189.2023.04.04.04.15.02; Tue, 04 Apr 2023 04:15:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nZH5g8eD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234741AbjDDKy1 (ORCPT + 99 others); Tue, 4 Apr 2023 06:54:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234493AbjDDKxa (ORCPT ); Tue, 4 Apr 2023 06:53:30 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D76CD421F; Tue, 4 Apr 2023 03:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680605588; x=1712141588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xePdNXHU682aUfMVCFmcmPRxw9pVvyjrZ2d9bkzRB0U=; b=nZH5g8eDFrMberKP41DjOHonCxLU2ztX3mG6kN+ZqwGRyLZcgORv9b97 sDg1uCPyyogr2GRlPgSn79BlBZf4yr5ynL98IczMuMsdrxvoiX310AGb6 JbLg24g6PIx4Cw3Jrm7jrpW3nRxl/kjdMUHteJUaZDvQwu0RkKdN4imo2 SDxlxIBRbxvCVExw/YGIa/rriYpQpuQKb+NYBzxSsBgPjL5cJOMhDTYyL h0W/W7NbUbjwc1pTtnmjxWXAv4mOwG5ceOgssxQ5vF6gWseW9xgMNgxqG i1EEUBUM+p9yHDHIKJI7foafdTEvr5+lTpxWMv71QV0vNENsC0wyydi/e A==; X-IronPort-AV: E=McAfee;i="6600,9927,10669"; a="330734016" X-IronPort-AV: E=Sophos;i="5.98,317,1673942400"; d="scan'208";a="330734016" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 03:53:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10669"; a="775597805" X-IronPort-AV: E=Sophos;i="5.98,317,1673942400"; d="scan'208";a="775597805" Received: from unknown (HELO fred..) ([172.25.112.68]) by FMSMGA003.fm.intel.com with ESMTP; 04 Apr 2023 03:53:01 -0700 From: Xin Li To: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, andrew.cooper3@citrix.com, seanjc@google.com, pbonzini@redhat.com, ravi.v.shankar@intel.com, jiangshanlai@gmail.com, shan.kang@intel.com Subject: [PATCH v7 09/33] x86/cpu: add X86_CR4_FRED macro Date: Tue, 4 Apr 2023 03:26:52 -0700 Message-Id: <20230404102716.1795-10-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230404102716.1795-1-xin3.li@intel.com> References: <20230404102716.1795-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762244077004334411?= X-GMAIL-MSGID: =?utf-8?q?1762244077004334411?= From: "H. Peter Anvin (Intel)" Add X86_CR4_FRED macro for the FRED bit in %cr4. This bit should be a pinned bit, not to be changed after initialization. Signed-off-by: H. Peter Anvin (Intel) Tested-by: Shan Kang Signed-off-by: Xin Li --- arch/x86/include/uapi/asm/processor-flags.h | 2 ++ arch/x86/kernel/cpu/common.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/uapi/asm/processor-flags.h b/arch/x86/include/uapi/asm/processor-flags.h index c47cc7f2feeb..a90933f1ff41 100644 --- a/arch/x86/include/uapi/asm/processor-flags.h +++ b/arch/x86/include/uapi/asm/processor-flags.h @@ -132,6 +132,8 @@ #define X86_CR4_PKE _BITUL(X86_CR4_PKE_BIT) #define X86_CR4_CET_BIT 23 /* enable Control-flow Enforcement Technology */ #define X86_CR4_CET _BITUL(X86_CR4_CET_BIT) +#define X86_CR4_FRED_BIT 32 /* enable FRED kernel entry */ +#define X86_CR4_FRED _BITULL(X86_CR4_FRED_BIT) /* * x86-64 Task Priority Register, CR8 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 8cd4126d8253..e8cf6f4cfb52 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -412,10 +412,15 @@ static __always_inline void setup_umip(struct cpuinfo_x86 *c) cr4_clear_bits(X86_CR4_UMIP); } -/* These bits should not change their value after CPU init is finished. */ +/* + * These bits should not change their value after CPU init is finished. + * The explicit cast to unsigned long suppresses a warning on i386 for + * x86-64 only feature bits >= 32. + */ static const unsigned long cr4_pinned_mask = - X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_UMIP | - X86_CR4_FSGSBASE | X86_CR4_CET; + (unsigned long) + (X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_UMIP | + X86_CR4_FSGSBASE | X86_CR4_CET | X86_CR4_FRED); static DEFINE_STATIC_KEY_FALSE_RO(cr_pinning); static unsigned long cr4_pinned_bits __ro_after_init;