From patchwork Fri Feb 24 07:01:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 61161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp756576wrd; Thu, 23 Feb 2023 23:30:19 -0800 (PST) X-Google-Smtp-Source: AK7set+cnR5PrjELkzn0du5tTedx4gJKYqpAyfI41STdKb5r+SdeCCCzT0vOyGhjV7CuwxODyK4v X-Received: by 2002:a05:6402:6ca:b0:4ac:b32d:3dab with SMTP id n10-20020a05640206ca00b004acb32d3dabmr11628671edy.29.1677223818954; Thu, 23 Feb 2023 23:30:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677223818; cv=none; d=google.com; s=arc-20160816; b=Nff36BgKJk1K7NxByhCJ48IqLjPDWnzvy4fOFVev6CW7P9gwwg1+RqAjH58tpupmMS PnJxamQFOfQFPssttiAnveHVvXBpLToTMP2gP40rj8xioxbhGYWCB5Cvt6BeBkgR5C5b tAjZdZ+qtPJo/7h3aU0eL8v4+5ZA2ubSDuOzlb9CmtQsltvb1VpUOmaybQ6RBcXHVnTa 4LTiRWCgp6EhDdfOcaw9vaG4BI2CTxpRxvMtvtBlFSdtpZCF2XzJ2fYqVDAIqoC5+zOD JnLWkUE+arPWrTKjWRLVCVbclidtvlfRxVVPKARxkjkRdqnP94qeE4ehAbFgETz48SqY 4e4g== 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=iTNqrrcJ5SdWpVhQ+2iC/JDCXVhYJ0UIe0yolcNg2B4=; b=gxDKpMDon/0c7Uu/h6V8P4/G/8FFT1U5Jx+EoXHhJZ0abvr1hf6ZnqKVxf6Z/HUliE Gno/CNURAlegkgZ7xeZT21UKai7FHh2AjRNdVlRO07LE3suLGLGPNvjs7/4+hmwnLByz qQ1EWNXepwqN6gzUF9nIaFwkrR7OaCskugKHzUvtXQnuP2exsvwVOue2I1ArcjPZyCAh n/sxXFPSEJP0lAzIOj6uaAi23q0e3ink2DqdDjsKFhwvo5R0DRWCb8FRNT6Dj+spbQSu /JFCgeB8sIDNpwo5trF5MehbAz0hGbIZDN3RVRke4352+Cki6aw9U5xiHFpD49C+Mt8C rNsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iaOLLL5C; 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 w21-20020a056402071500b004aaa07a9475si10171948edx.50.2023.02.23.23.29.56; Thu, 23 Feb 2023 23:30:18 -0800 (PST) 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=iaOLLL5C; 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 S229990AbjBXH2l (ORCPT + 99 others); Fri, 24 Feb 2023 02:28:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbjBXH2P (ORCPT ); Fri, 24 Feb 2023 02:28:15 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E433439B8C; Thu, 23 Feb 2023 23:28:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677223681; x=1708759681; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tgdMYcOakRl86nvaaJrJKyKhhcEE7k0v0Jtz0oYjgp0=; b=iaOLLL5CMtrEjpVGli29hO2Rz0UEz5Jljwt75jT6hOTm1IjzH5pAsG0l uOiVsG+ndzJpdB9g11gKIfFqOvY7D+mI6APxVw1lZhJ7RSeZznMKmKbHN J65CgN/T1R3DD/ie40S8ofYwlEsVpMj90YEHCQSnp36IhALJ+hwbcNs++ 0QX2CJx68UA6ENlCXLJNZyZavYqqNAXQNg+GvxOLZ9V//g1QvF6eJIaV5 AXYGbXOHjDKjIsdIrNtfDgdLbpHpFjgJgTxlcK1n571uq05dqftba7DpQ JlUhZZZXSW8M7EdOoynWfbKNTBTOJ2284pA+zhFYaiHHqnYUvuvlLHv0s A==; X-IronPort-AV: E=McAfee;i="6500,9779,10630"; a="334836026" X-IronPort-AV: E=Sophos;i="5.97,324,1669104000"; d="scan'208";a="334836026" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2023 23:27:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10630"; a="815639228" X-IronPort-AV: E=Sophos;i="5.97,324,1669104000"; d="scan'208";a="815639228" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga001.fm.intel.com with ESMTP; 23 Feb 2023 23:27:22 -0800 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 Subject: [RFC PATCH v3 14/32] x86/fred: header file with FRED definitions Date: Thu, 23 Feb 2023 23:01:27 -0800 Message-Id: <20230224070145.3572-15-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230224070145.3572-1-xin3.li@intel.com> References: <20230224070145.3572-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,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=ham 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?1758696643174999892?= X-GMAIL-MSGID: =?utf-8?q?1758696643174999892?= From: "H. Peter Anvin (Intel)" Add a header file for FRED prototypes and definitions. Signed-off-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li --- arch/x86/include/asm/fred.h | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 arch/x86/include/asm/fred.h diff --git a/arch/x86/include/asm/fred.h b/arch/x86/include/asm/fred.h new file mode 100644 index 000000000000..f4de2cdd1c7f --- /dev/null +++ b/arch/x86/include/asm/fred.h @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * arch/x86/include/asm/fred.h + * + * Macros for Flexible Return and Event Delivery (FRED) + */ + +#ifndef ASM_X86_FRED_H +#define ASM_X86_FRED_H + +#ifdef CONFIG_X86_FRED + +#include +#include + +/* + * FRED return instructions + * + * Replace with "ERETS"/"ERETU" once binutils support FRED return instructions. + * The binutils version supporting FRED instructions is still TBD, and will + * update once we have it. + */ +#define ERETS _ASM_BYTES(0xf2,0x0f,0x01,0xca) +#define ERETU _ASM_BYTES(0xf3,0x0f,0x01,0xca) + +/* + * Event stack level macro for the FRED_STKLVLS MSR. + * Usage example: FRED_STKLVL(X86_TRAP_DF, 3) + * Multiple values can be ORd together. + */ +#define FRED_STKLVL(v,l) (_AT(unsigned long, l) << (2*(v))) + +/* FRED_CONFIG MSR */ +#define FRED_CONFIG_CSL_MASK 0x3 +#define FRED_CONFIG_SHADOW_STACK_SPACE _BITUL(3) +#define FRED_CONFIG_REDZONE(b) __ALIGN_KERNEL_MASK((b), _UL(0x3f)) +#define FRED_CONFIG_INT_STKLVL(l) (_AT(unsigned long, l) << 9) +#define FRED_CONFIG_ENTRYPOINT(p) _AT(unsigned long, (p)) + +/* FRED event type and vector bit width and counts */ +#define FRED_EVENT_TYPE_BITS 3 /* only 3 bits used in FRED 3.0 */ +#define FRED_EVENT_TYPE_COUNT _BITUL(FRED_EVENT_TYPE_BITS) +#define FRED_EVENT_VECTOR_BITS 8 +#define FRED_EVENT_VECTOR_COUNT _BITUL(FRED_EVENT_VECTOR_BITS) + +/* FRED EVENT_TYPE_OTHER vector numbers */ +#define FRED_SYSCALL 1 +#define FRED_SYSENTER 2 + +/* Flags above the CS selector (regs->csl) */ +#define FRED_CSL_ENABLE_NMI _BITUL(28) +#define FRED_CSL_ALLOW_SINGLE_STEP _BITUL(25) +#define FRED_CSL_INTERRUPT_SHADOW _BITUL(24) + +#ifndef __ASSEMBLY__ + +#include +#include + +/* FRED stack frame information */ +struct fred_info { + unsigned long edata; /* Event data: CR2, DR6, ... */ + unsigned long resv; +}; + +/* Full format of the FRED stack frame */ +struct fred_frame { + struct pt_regs regs; + struct fred_info info; +}; + +/* Getting the FRED frame information from a pt_regs pointer */ +static __always_inline struct fred_info *fred_info(struct pt_regs *regs) +{ + return &container_of(regs, struct fred_frame, regs)->info; +} + +static __always_inline unsigned long fred_event_data(struct pt_regs *regs) +{ + return fred_info(regs)->edata; +} + +/* + * How FRED event handlers are called. + * + * FRED event delivery establishes the full supervisor context + * by pushing everything related to the event being delivered + * to the FRED stack frame, e.g., the faulting linear address + * of a #PF is pushed as event data of the FRED #PF stack frame. + * Thus a struct pt_regs has everything needed and it's the only + * input parameter required for a FRED event handler. + */ +#define DECLARE_FRED_HANDLER(f) void f (struct pt_regs *regs) +#define DEFINE_FRED_HANDLER(f) noinstr DECLARE_FRED_HANDLER(f) +typedef DECLARE_FRED_HANDLER((*fred_handler)); + +#endif /* __ASSEMBLY__ */ + +#endif /* CONFIG_X86_FRED */ + +#endif /* ASM_X86_FRED_H */