From patchwork Fri Jan 6 08:55:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 40030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp728771wrt; Fri, 6 Jan 2023 01:24:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXv6Q2mFvn4yEZGyv0rT/oE7074yQdc01Ihpth0IP+hKm/PBxBlqId6a4V1AfLnmxaJ9FWK6 X-Received: by 2002:a17:906:7749:b0:7c5:fd:4352 with SMTP id o9-20020a170906774900b007c500fd4352mr62693252ejn.49.1672997041977; Fri, 06 Jan 2023 01:24:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672997041; cv=none; d=google.com; s=arc-20160816; b=sPsilQrfL+fut/mthW4/AfBGJaSgx1pdWp7cttV/V62gjkGihzbxNcMxRohedTfQ9F LsadtvYT07FieAxoAN6JiETIF/AA8RvIi+bf/yprAMQeBrZtVppgnNh7ZX8urRlWDBLV lSRZ0q27o3heP+74DPUejv0C+fG3yr9J40360BxPQTY3uEZW1X8Zu3XucBxM6MaCMN+n wGhmOjEVj3plGBtlVglU4yhopNS8y5qtJeU7T912EI9XHWT9gsrQVWk1k2UuAK9Rd7KS dUgoL6NfThrogTEmb4Vv4liKpbKGmCFCRRI1Y5c7jXfhpSKBLB3DdgXaB2525abEbrNI 7zxQ== 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=BdHbSf2qD0ydgRN+V+ZG8+MQ7VpBSYh48dk2d3xEPx6Kw7JygIp9bTZ5/7T/6jq/yY De/GZOJR7e/3bKncmKoCGeutJnpGwte5NJq5FP6C2THvE90KKVYF2Xx5Z4aVSnpzjN6M HaUDIQ7Ew6+hr34NJxn5zcbfj6P96aNwuLky9nvesPWdW/+SnShBUiJXvQfgyzrQsu52 Cmpn0zQomjem2MCSZy8LQeOXi6duGQLR4v1Ut85AsxWJYKtItDuA6//JIY8EAugpAfc/ IXU++zyNNbr0NXmZSUTVm3YyAQkzJ5CcDSDq6HgAe5ziCUGAvHrqgzopp0fip6qyoJyW FfDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=n57GCKCv; 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 nd21-20020a170907629500b0084d0ebd704bsi807565ejc.71.2023.01.06.01.23.38; Fri, 06 Jan 2023 01:24:01 -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=n57GCKCv; 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 S232404AbjAFJV5 (ORCPT + 99 others); Fri, 6 Jan 2023 04:21:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233024AbjAFJUV (ORCPT ); Fri, 6 Jan 2023 04:20:21 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 069CD6B5F4; Fri, 6 Jan 2023 01:20:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672996820; x=1704532820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tgdMYcOakRl86nvaaJrJKyKhhcEE7k0v0Jtz0oYjgp0=; b=n57GCKCvY42dSbUTjz5Fl45Hvk/vaQuaYEg9odEIXpNGEY2xM0wHnZo0 DwNH/WkCxhnLhZhRmFWSPurxlUkqJC3hZAY8eWVDvnKft1OXKOJVESAUB DSSXRKXHVfV/0T1dw51K40zN1qbsz/bw+kefIvVzDZbNcbhFLAnxExJyv iQsF4IV+/deXUYgZQGj3/fmhyq/AutphwfYtUJUgEa5it1hH/dHKTsuWE piwDNUb/iBpSteLFxZ350+F33cHz4ETBBZRl1Ho4bqxdkFXX1YiOAbmJO wsKGPPZaDNE0LFkhzJQs4PTxG8opkBK7XF03GldYTYsaDPsG/EjX3QfHL A==; X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="322511496" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="322511496" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2023 01:20:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="719139388" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="719139388" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga008.fm.intel.com with ESMTP; 06 Jan 2023 01:20:14 -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 v2 14/32] x86/fred: header file with FRED definitions Date: Fri, 6 Jan 2023 00:55:59 -0800 Message-Id: <20230106085617.17248-15-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106085617.17248-1-xin3.li@intel.com> References: <20230106085617.17248-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, 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?1754264546081250944?= X-GMAIL-MSGID: =?utf-8?q?1754264546081250944?= 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 */