From patchwork Thu Mar 2 05:24:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 63233 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4063918wrd; Wed, 1 Mar 2023 21:54:34 -0800 (PST) X-Google-Smtp-Source: AK7set+ozgCl53otEz7/6QOGnOvkDSWrAe7gxM3zyJx1Mi5CDO8PepzyhFpI3siIa3EdBHUsPyLh X-Received: by 2002:aa7:cb12:0:b0:4ac:b2c8:aeaf with SMTP id s18-20020aa7cb12000000b004acb2c8aeafmr9547850edt.26.1677736474367; Wed, 01 Mar 2023 21:54:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677736474; cv=none; d=google.com; s=arc-20160816; b=hJTwazRsZdD3fiMocYRibljbeS/quAC176IJCbr0Db9Q9rU2L2pWBraqY0o5/itUSS 9cJY3n1lMqpLU+8qk2gCqy6n3wUybsuyzyXw87cXzGrEJGxU8DVogHibonrw7Cff+YSQ NcmdujlJmpk//MPStUH3nQ/OuwvLFqd6cj+jNTj3o278NRu0JaYjjAVGVEj85kAApHCH HHpfZCT385OH8mdX7WD4j/pELfECxGK5mtT/EsIvldJwKwjGW0TBmZ0pgAstTv2/D37w EdQGjHF/Wweb3lv/c3IADnBhKz7R9+Qxm+IeKg8rt5BCEJj1tCdWJu4Pp3m/FIgCroSS 4x8A== 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=BWZ/Fs/YqPHhG+vbleqMrIxlzACZYftKS0YHpwFAQyI=; b=Fypm+lVAsUI60ZL4zDPRNR/rCZoDolCc+DIWfcYFCXV6EhVlWZkdA7VqRLDaAMUqqg QKM5tR3RyY/pevwx0rff1in3gf1MF4ka0sxVOWDZF0c7/QPxi14ityiMf86NYJ8PBzLv sseP4z1iUpz7BBO1ChF6uEjYtA2HRClKpEL4/KAeahiFkxQEVU0zscHTQwCiGGjdpl/A TqcguolY0364cI3wE9P0pG0jYjMPcVd42fuyZSltC/spGZu201x7UlMkKU8LCUPKHrJD eqzu+WfxMa910IE+bNyKDR7DgBPJo9bDyt/hbO9TIkV9v9qGfH9P6kt6Xnfld6gCEUkW efAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WcuqUjLt; 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 d25-20020a50fb19000000b004beaccf8fd3si2398513edq.409.2023.03.01.21.54.12; Wed, 01 Mar 2023 21:54:34 -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=WcuqUjLt; 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 S229968AbjCBFva (ORCPT + 99 others); Thu, 2 Mar 2023 00:51:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229861AbjCBFu5 (ORCPT ); Thu, 2 Mar 2023 00:50:57 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0EF84DE12; Wed, 1 Mar 2023 21:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677736255; x=1709272255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zbDdVunyGdhXyhjUE3Gbpn/xbHM27xiNyk5ThtGHdLg=; b=WcuqUjLtgjAOK+DLaIe6uzx5hbjPPIsCCX2YrCUB8e0u/7K0voKg+kxF ODNzVC4/TZbOozJmIc+TMJNSTO/vDAs6j2BUMnsoSdtOD6hENS4uOTasd o/I/TUekjaF7sMBTjFAEcfn9OoxdeRSjBdDB509KktFlY7LZ9pdkHCjuz 8K7kg6tPR/akGB1suwqgfcRaffFcEEX/09hBhEYQwWc8CaFmCRu/LQ6lT JJXASbRrgyrugIAkxZsjR9+lxdDyxe/0f2azVBNYlx36Trkz7ehu1J3CL l4K0bu+L90wcK5RQrjY9rkajrxf/s/67MueRhZlt0PM5CrJhnwkvGPk0H A==; X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="420887132" X-IronPort-AV: E=Sophos;i="5.98,226,1673942400"; d="scan'208";a="420887132" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2023 21:50:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="920530924" X-IronPort-AV: E=Sophos;i="5.98,226,1673942400"; d="scan'208";a="920530924" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 01 Mar 2023 21:50:48 -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: [PATCH v4 17/34] x86/fred: add a page fault entry stub for FRED Date: Wed, 1 Mar 2023 21:24:54 -0800 Message-Id: <20230302052511.1918-18-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230302052511.1918-1-xin3.li@intel.com> References: <20230302052511.1918-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?1759234201263719558?= X-GMAIL-MSGID: =?utf-8?q?1759234201263719558?= From: "H. Peter Anvin (Intel)" Add a page fault entry stub for FRED. On a FRED system, the faulting address (CR2) is passed on the stack, to avoid the problem of transient state. Thus we get the page fault address from the stack instead of CR2. Signed-off-by: H. Peter Anvin (Intel) Tested-by: Shan Kang Signed-off-by: Xin Li --- arch/x86/include/asm/fred.h | 2 ++ arch/x86/mm/fault.c | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/fred.h b/arch/x86/include/asm/fred.h index 2f337162da73..57affbf80ced 100644 --- a/arch/x86/include/asm/fred.h +++ b/arch/x86/include/asm/fred.h @@ -94,6 +94,8 @@ static __always_inline unsigned long fred_event_data(struct pt_regs *regs) #define DEFINE_FRED_HANDLER(f) noinstr DECLARE_FRED_HANDLER(f) typedef DECLARE_FRED_HANDLER((*fred_handler)); +DECLARE_FRED_HANDLER(fred_exc_page_fault); + #endif /* __ASSEMBLY__ */ #endif /* CONFIG_X86_FRED */ diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index a498ae1fbe66..0f946121de14 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -33,6 +33,7 @@ #include /* kvm_handle_async_pf */ #include /* fixup_vdso_exception() */ #include +#include /* fred_event_data() */ #define CREATE_TRACE_POINTS #include @@ -1507,9 +1508,10 @@ handle_page_fault(struct pt_regs *regs, unsigned long error_code, } } -DEFINE_IDTENTRY_RAW_ERRORCODE(exc_page_fault) +static __always_inline void page_fault_common(struct pt_regs *regs, + unsigned int error_code, + unsigned long address) { - unsigned long address = read_cr2(); irqentry_state_t state; prefetchw(¤t->mm->mmap_lock); @@ -1556,3 +1558,17 @@ DEFINE_IDTENTRY_RAW_ERRORCODE(exc_page_fault) irqentry_exit(regs, state); } + +DEFINE_IDTENTRY_RAW_ERRORCODE(exc_page_fault) +{ + page_fault_common(regs, error_code, read_cr2()); +} + +#ifdef CONFIG_X86_FRED + +DEFINE_FRED_HANDLER(fred_exc_page_fault) +{ + page_fault_common(regs, regs->orig_ax, fred_event_data(regs)); +} + +#endif /* CONFIG_X86_FRED */