From patchwork Tue Aug 1 08:32: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: 129202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2597241vqg; Tue, 1 Aug 2023 04:20:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlHBo3rzQnAFPz4IgU7V7+7l77OPp35W/U4avw12dM3v/O6oLJkC1TocbmSTtsRGQ8052nm4 X-Received: by 2002:a05:6a00:4397:b0:677:bb4c:c321 with SMTP id bt23-20020a056a00439700b00677bb4cc321mr11572116pfb.0.1690888853428; Tue, 01 Aug 2023 04:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690888853; cv=none; d=google.com; s=arc-20160816; b=fwPxLIsjpoZ+T0EVUiGm8GI+U2khin8YC9q93EpD6KvA/8xdPFurxjDmueeOXMBnr3 NcjLyN0A0sNsXFwlJCHWmfJfEKHSf3UVVctXQF2vOvV3PvSfzcyKCsObv7pVjndRsrPw Iu8ZTrMgpPWmBeeM5iIgwrf0mK1hRigj3fo4rwnvAITKJIQXbo5wMuxR6FJ8Vk2BzeAL TXsxMmDQskOi66Bh6U+vsvKApaootn3HQHvhAfA59HsWwudY4bLudTkZsnTY/GalAxDG 9dDiPqsf9yi78Y8VEp8DIxo6blWxgvHiILr/4L2bwnBqysBNNB1+b6W3X3oGKSg555NI /B8Q== 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=I5y4ZzeWW8luAL0UUSAfRPZUu+aLGZe2jSp5M/FygUc=; fh=nYO9ukkM7JnAAJZcChGC8UWBlCLXeJxIDT82cxoIaf0=; b=dLqF+aKjR22YuUCj1fq9xJYNGBoR35juSeCvAiwI7+nJgbpc0ce+yDv4AHC11fNX4i 7p2/jxH++ee2BSSnpny8fgzUX1x56e6qCpKe7PkN9iOSifY9F85kp2s+OSZCqq2sY/7L o+kx8g982OZP2tvkp6wveT6CQaLapds039DZlI+JpjFYLBReRIu5d/Sv4GP39ubxA5Rf 7+wd78LgBF5/YJmgbUI0wCygnbcniis7sMZ8RKT5o/pqihK+wn6ra41ChLOrBzFSDJA/ vlOMTn16gG4lRstqGS90PeNaD+VpJj14waqK0pcsrbRdu1YUSv9Qr5qJAzZBv6HjI+xi oDWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OsSnUd6m; 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 s16-20020a63af50000000b00563f317e54fsi8751043pgo.284.2023.08.01.04.20.39; Tue, 01 Aug 2023 04:20:53 -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=OsSnUd6m; 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 S232525AbjHAJEK (ORCPT + 99 others); Tue, 1 Aug 2023 05:04:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232646AbjHAJDK (ORCPT ); Tue, 1 Aug 2023 05:03:10 -0400 Received: from mgamail.intel.com (unknown [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6C7E30CB; Tue, 1 Aug 2023 02:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690880557; x=1722416557; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2rbYs2KdLMV2D8jndr60eRf402MI8mOow/QviwqPNSc=; b=OsSnUd6mSIF9JgyM/m/Irrl9ia5fcd/M9MnCDxrRZIwyQnAQ1tVEOlov thXLJQc52jq+fanSeA32RAE1VRoGlpkvCYno1q+9yUOYN7/N+7oaQGOxd tfGCGRz76WckgmCxZtVrcE5IbhHF9GfINsr3y7jU5mXDZulfG9FT1embe whCVSqbFnN4zcFCX8+jnWbGua+3SA7vW6PYshwfwtYYQdMS+D1sdNGk7+ 8OmbNOqNyFXKH6FYOWuTimen3NOkYpynmhp1xWCcXASceZdrztGjPqpDk lkZmzhklG+YytEsKacKrHhSGrZtp0PBgmCbuCBQ4+3FVbVxYytkkaIApX w==; X-IronPort-AV: E=McAfee;i="6600,9927,10788"; a="433082364" X-IronPort-AV: E=Sophos;i="6.01,246,1684825200"; d="scan'208";a="433082364" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Aug 2023 02:02:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10788"; a="975217001" X-IronPort-AV: E=Sophos;i="6.01,246,1684825200"; d="scan'208";a="975217001" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 01 Aug 2023 02:01:59 -0700 From: Xin Li To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org, linux-hyperv@vger.kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org Cc: Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Andy Lutomirski , Oleg Nesterov , Tony Luck , "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Paolo Bonzini , Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Peter Zijlstra , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Josh Poimboeuf , "Paul E . McKenney" , Catalin Marinas , Randy Dunlap , Steven Rostedt , Kim Phillips , Xin Li , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Liam R . Howlett" , Sebastian Reichel , "Kirill A . Shutemov" , Suren Baghdasaryan , Pawan Gupta , Babu Moger , Jim Mattson , Sandipan Das , Lai Jiangshan , Hans de Goede , Reinette Chatre , Daniel Sneddon , Breno Leitao , Nikunj A Dadhania , Brian Gerst , Sami Tolvanen , Alexander Potapenko , Andrew Morton , Arnd Bergmann , "Eric W . Biederman" , Kees Cook , Masami Hiramatsu , Masahiro Yamada , Ze Gao , Fei Li , Conghui , Ashok Raj , "Jason A . Donenfeld" , Mark Rutland , Jacob Pan , Jiapeng Chong , Jane Malalane , David Woodhouse , Boris Ostrovsky , Arnaldo Carvalho de Melo , Yantengsi , Christophe Leroy , Sathvika Vasireddy Subject: [PATCH RESEND v9 10/36] x86/fred: Add a new header file for FRED definitions Date: Tue, 1 Aug 2023 01:32:52 -0700 Message-Id: <20230801083318.8363-11-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801083318.8363-1-xin3.li@intel.com> References: <20230801083318.8363-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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: INBOX X-GMAIL-THRID: 1773025470038480768 X-GMAIL-MSGID: 1773025470038480768 From: "H. Peter Anvin (Intel)" Add a header file for FRED prototypes and definitions. Signed-off-by: H. Peter Anvin (Intel) Tested-by: Shan Kang Signed-off-by: Xin Li --- Changes since v6: * Replace pt_regs csx flags prefix FRED_CSL_ with FRED_CSX_. --- arch/x86/include/asm/fred.h | 104 ++++++++++++++++++++++++++++++++++++ 1 file changed, 104 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..d76e681a806f --- /dev/null +++ b/arch/x86/include/asm/fred.h @@ -0,0 +1,104 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Macros for Flexible Return and Event Delivery (FRED) + */ + +#ifndef ASM_X86_FRED_H +#define ASM_X86_FRED_H + +#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) + +/* + * RSP is aligned to a 64-byte boundary before used to push a new stack frame + */ +#define FRED_STACK_FRAME_RSP_MASK _AT(unsigned long, (~0x3f)) + +/* + * 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 +/* + * Used for the return address for call emulation during code patching, + * and measured in 64-byte cache lines. + */ +#define FRED_CONFIG_REDZONE_AMOUNT 1 +#define FRED_CONFIG_REDZONE (_AT(unsigned long, FRED_CONFIG_REDZONE_AMOUNT) << 6) +#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. + * + * There is space in the stack frame making it possible to extend event type + * and vector fields in the future. + */ +#define FRED_EVENT_TYPE_BITS 3 +#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 +#define FRED_NUM_OTHER_VECTORS 3 + +/* Flags above the SS selector (regs->ssx) */ +#define FRED_SSX_INTERRUPT_SHADOW_BIT 16 +#define FRED_SSX_INTERRUPT_SHADOW _BITUL(FRED_SSX_INTERRUPT_SHADOW_BIT) +#define FRED_SSX_SOFTWARE_INITIATED_BIT 17 +#define FRED_SSX_SOFTWARE_INITIATED _BITUL(FRED_SSX_SOFTWARE_INITIATED_BIT) +#define FRED_SSX_NMI_BIT 18 +#define FRED_SSX_NMI _BITUL(FRED_SSX_NMI_BIT) +#define FRED_SSX_64_BIT_MODE_BIT 57 +#define FRED_SSX_64_BIT_MODE _BITUL(FRED_SSX_64_BIT_MODE_BIT) + +#ifdef CONFIG_X86_FRED + +#ifndef __ASSEMBLY__ + +#include +#include + +struct fred_info { + /* Event data: CR2, DR6, ... */ + unsigned long edata; + unsigned long resv; +}; + +/* Full format of the FRED stack frame */ +struct fred_frame { + struct pt_regs regs; + struct fred_info info; +}; + +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; +} + +#endif /* __ASSEMBLY__ */ + +#endif /* CONFIG_X86_FRED */ + +#endif /* ASM_X86_FRED_H */