From patchwork Mon Apr 10 08:14:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 81397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1757466vqo; Mon, 10 Apr 2023 01:42:57 -0700 (PDT) X-Google-Smtp-Source: AKy350YVuMyYOcNaw0DqTSEf/3V/NwlyVJOMjjUM4M+fVsKBC1MzHmST9VRfUqOFMBGmelms6ffb X-Received: by 2002:a17:90b:3809:b0:23f:7666:c8a1 with SMTP id mq9-20020a17090b380900b0023f7666c8a1mr12782616pjb.18.1681116177341; Mon, 10 Apr 2023 01:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681116177; cv=none; d=google.com; s=arc-20160816; b=v6aACWzhVzT8KRnicdweaZhcLe8+pO7tgYC9cD7phZDylF6jZW3ptlN//Kn4pEIZxY 9eqc/dPhMo580MYPLU8iFbaOlmwLvHgHTiaXHSFkG+HA40QVl4EFmcN0cSXK+FSChRiY 6oX0dsHZShk/hiAhDkF4OBkR9+luvt8hQ5vLZXJEilAC75XVKJEQAVXwIjEBGYs+Ilnp epMru8xbdutGwAI3k2WqSCc0h81meHMaIT0RHowcAktVyZunjrkJBNLTrUIhWck/zL5s OJr+rv14V2oE8fXGnQ/BSxzwph7+uJzzR8ZFq3ZpOGveErM2NGyi+RuoVncN2GU/bE7m c/hA== 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=RRd0UBdwKjamp5FLwk0MN5YETEbG7sJ4jhrhEPxF8Ss=; b=aSS4uw3VCxCHFiVDgcZOptXWaB+3PQgKXVId24oXdWlwjkrkYVBgSaALFnuVvXxM1M Ol2mE6+lomnExxaHdQoBieqCt2xRQAyhLDJpZVkJ1WvwwEuEpxsoPiPYRwxCnHzDfvp/ lCGUR+7UzvX8bXUMBK5ruX2Ri/8LuEtV0xdc2fQZ99iG0554l1yT8wVqWOQwuAfouxhR 29u2q8l0xgfe6uWjQdILbCa+7ATNGpFK/Fu9J8HNga75aBF0QR4EXHXuW14AIdQQFae1 OAOry5XM1r3VDYFYxfJK4MXtLQAiUogyiPFraoCnvyI8UyMsa8WQ8pDxVNJ/ZybIBi4g u7ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z2RctO55; 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 l38-20020a635b66000000b0050fa02c0326si9585607pgm.277.2023.04.10.01.42.45; Mon, 10 Apr 2023 01:42:57 -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=Z2RctO55; 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 S229837AbjDJIl4 (ORCPT + 99 others); Mon, 10 Apr 2023 04:41:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbjDJIlI (ORCPT ); Mon, 10 Apr 2023 04:41:08 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72BA1421F; Mon, 10 Apr 2023 01:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681116067; x=1712652067; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SDGDSUDsSV7zT/y15Zj5Xr5rd8es//ZPrYL5DTYxefY=; b=Z2RctO55Cr0EW+CrOefb4eTSW8cMR0I816SMsRz7UijYHa/RCqGGqfaF bGjZ92XlRJIxgBYVuDjpVFrURJBVxtJT4f9+kobVguZs1cm+78zptzEVs s4B/y6Glvxj5gK/MpVVi9kTTw4EQJwJmzO+MoZrykbhTGJvPNwyzzqfmg Fix7eG+Pcn9kDupuwmet+xJ/qgtdPPsJ88NPFZsuHPxDBLPwbQCSNOsLD ZBAfHUpULGZUcDmwuOAKj757QqTb5EA4P1fjtPjk9naptQwrs1cDV3lQF y/MCGyuqM0nTTdUsZKhQ3l1ZW3QiQI578eiOFvGEoFbvMSBTVSsaFtlZc w==; X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="342078009" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="342078009" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 01:41:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="799436292" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="799436292" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga002.fm.intel.com with ESMTP; 10 Apr 2023 01:41:04 -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 v8 14/33] x86/fred: header file with FRED definitions Date: Mon, 10 Apr 2023 01:14:19 -0700 Message-Id: <20230410081438.1750-15-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410081438.1750-1-xin3.li@intel.com> References: <20230410081438.1750-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,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?1762778076681876109?= X-GMAIL-MSGID: =?utf-8?q?1762778076681876109?= 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 | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 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..b59397411ab9 --- /dev/null +++ b/arch/x86/include/asm/fred.h @@ -0,0 +1,106 @@ +/* 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) + +/* + * 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 +#define FRED_CONFIG_REDZONE_AMOUNT 1 /* measured in 64-byte cache lines */ +#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 */ +#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->csx) */ +#define FRED_CSX_ENABLE_NMI _BITUL(28) +#define FRED_CSX_ALLOW_SINGLE_STEP _BITUL(25) +#define FRED_CSX_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 */