From patchwork Tue Dec 20 06:36:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 34925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2813467wrn; Mon, 19 Dec 2022 23:03:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WuAt20FvVu8cr9Fnemgtsx7RmXayq+LirmbdhaPHFq+mXI8o/Bx6LwWAKY3vmEVfnRweP X-Received: by 2002:a62:3287:0:b0:56b:d0eb:47b3 with SMTP id y129-20020a623287000000b0056bd0eb47b3mr43406369pfy.5.1671519818488; Mon, 19 Dec 2022 23:03:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671519818; cv=none; d=google.com; s=arc-20160816; b=G09quD/HLTlpIFd4c1wVdX6RvV4PMsyq4zYtE9UEwLtqJFMTrKYMJqRR8qr3GIN4Ld QmwTNfrwLJV13NAScTgkhEpMmLjVFxg+XlYDLorjGmgGi2HkXqodhpHWyxwTspWA2zjs AJTBWTDRjXqhUkbZzWzMXlVftc6Tz37B4ipBKPuUWAHQ21x4BZIheVYz9zrdaQornkTl wh603/lPpO94f1bqg22TPSO/jV8XlHKB9/DlcVyWodV14uiMEHHq8U+dQYkcOcCVrKYg BkVRKYsiCt/1yPhWM/lR65jmThke8gp8dBP4sn+/r3BuZ2/kFgfTJM8miNJWBkQ1S0oY Q3Wg== 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=uUmvWLnWqfq81tL7ITHmImYvnLaCxrVriE8fySfnLF4=; b=scXfsrpLlV6EOCi6V7b5exD8b1WLxA5lNFS9V4TMLICm0M4HqZSdCaN4/zWVhThPNJ 2aUF3631+qiA7/Fn2/rtM3qDbQRKAUncakwBzikp1bZ4cS5nE4vhTuWk/Wun5SX60kAA GIzwX+5yteJqpkAVdML84/klmPJHL3w+g45xZQZGAPf/lQ3dTE0JFNLmmIwRwqKuOQVs dM0xvc7zK3lUekjsljG2eIU6BCL6t9zQgv8dEfP/YJSoTPl7c37bsaix6xqmCbjGdAw9 O5WloOmk5TqnQMO2YXSBzPnIaRyFdbwDX2iZ8z0I99z0DQvpop1o+szFH7+qUEpWhBlv I6Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E6payz2V; 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 cm9-20020a056a00338900b0057a7f9dbc3fsi12529816pfb.117.2022.12.19.23.03.25; Mon, 19 Dec 2022 23:03:38 -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=E6payz2V; 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 S233571AbiLTHC5 (ORCPT + 99 others); Tue, 20 Dec 2022 02:02:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbiLTHBh (ORCPT ); Tue, 20 Dec 2022 02:01:37 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E9451581B; Mon, 19 Dec 2022 23:01:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671519695; x=1703055695; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HmlZIFRY86SsuxVZ3f2cHdcHUA8c4g3To7+jNRITrUo=; b=E6payz2VgowUdCzRGPgWkiXUWnis+v8GmVUqmj77PWlPp+p6gTAQzcps 4dHir9pP4YvgZtV5QlvFqITV+wU2VMi1z2MFL4S0Eubid/hGE6AsBObhP OPZQ5yhSj1vK6I7+lWYH5sm1tG4b7TlMLOjy5dyFCKholaFwBL6ss9Xks KJATmvjlNIP5iQKnU+zG5G2A3la2sNKV26mULpwZNh4N+N0o9KeZZ97NA i55qroHf2arNj7b1GjMWOaP3yVtTdcGe3IVbBkru5dPdsjziZGYPAingQ l9E7Kp4NQXqtpViVhKDBd0UDpN134exdaPrsmcD/lKvtlQdwiY3C9GxiL w==; X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="302972022" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="302972022" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2022 23:01:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="644326473" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="644326473" Received: from unknown (HELO fred..) ([172.25.112.68]) by orsmga007.jf.intel.com with ESMTP; 19 Dec 2022 23:01:13 -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 14/32] x86/fred: header file with FRED definitions Date: Mon, 19 Dec 2022 22:36:40 -0800 Message-Id: <20221220063658.19271-15-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221220063658.19271-1-xin3.li@intel.com> References: <20221220063658.19271-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1752715565130149258?= X-GMAIL-MSGID: =?utf-8?q?1752715565130149258?= 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 | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 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..6292b28d461d --- /dev/null +++ b/arch/x86/include/asm/fred.h @@ -0,0 +1,99 @@ +/* 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. + */ +#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 */