From patchwork Fri Feb 24 07:01:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 61158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp756493wrd; Thu, 23 Feb 2023 23:30:11 -0800 (PST) X-Google-Smtp-Source: AK7set9bAhIqpSOnhK+4dQ3zlw3W/kcXG2R5tsoCo14xj0sWocHtnZ5dso8acnITkLvH6ZCZN9c/ X-Received: by 2002:a17:906:8484:b0:8b1:7f7d:7282 with SMTP id m4-20020a170906848400b008b17f7d7282mr27593776ejx.7.1677223811452; Thu, 23 Feb 2023 23:30:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677223811; cv=none; d=google.com; s=arc-20160816; b=znGIkYss7HZX6lYggIjKCMWVFPe8yvz35Sn2eb1hK5sEuFiK0K7mTz0KJ4hwJ5cIpv d5Lnj+S8BCZNCEUiVzxrHWlRDXKjrTfyPIyrMXjYM2raIV/K4BRDES+x3e2nWJCnGf9e uTzAYnr81ftkiLmkiQsD+vrvLw+4CEMz6CkYX9PAuWtohKWa8qiEiYZKOebo/TrZY+EL wEfekOLFJObhZA4wdKXMJWrjPfsfw4E5CaUYDAnmfsW9qeo2JIF5cA1utDwBeD6HC7fu i1bQp7r7ioyc5v2gOyRCVG/50sf+nJ3D2kvf4Njv8lliOzJeIHXb4qJYA32pW7lfwFO7 3V/Q== 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=spZ/td6vZoESmeMVeAejcZrAyPt8wfkEvyAB6B7v1QY=; b=t70G6DSvJVNdNY75tiax9NLUDa+ZCVulC8YS1Q/Zdme4g2S5nqQJv2ri2iAWdpOChh i7SLKVGR89aVQC0Z3Nwcy5Ogvl3Loa3KCQYXuUWnEpeNT3Ni6MXS0uvxaTMtvsSWh2TP n3CpzvdP9NRgCNGbKbOzotefcGM6mmt8DPPooZIjTeXkP7izZ98J/tDfxv671k0fdZfG AmrVR44/IfNqYOPzD18WqGxNQAZ8buynQ+Rl8lOHjLB/eFc0xQYG0/us0OT60FBSBqbO /ez76wf2s8nHNqG5iqSzKqNKSswnwhBg0cnII9u8PJyjC833hoMisoQpM7+CqUSqL7rg AKSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JALtesKa; 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 fd4-20020a1709072a0400b008dbb5a2ea5fsi12088994ejc.644.2023.02.23.23.29.47; Thu, 23 Feb 2023 23:30:11 -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=JALtesKa; 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 S230018AbjBXH2u (ORCPT + 99 others); Fri, 24 Feb 2023 02:28:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjBXH2Q (ORCPT ); Fri, 24 Feb 2023 02:28:16 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08DAD3BD99; Thu, 23 Feb 2023 23:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677223684; x=1708759684; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LJAXoIH5EY7acqY4mtQFvimkQPN5qKlFIb9dyMRhzXM=; b=JALtesKalKiWS8Um/rnVqxvJwn6iKwexl0KWvppcuoKq39bBspCUB3ZI M/UWFkVd5/vI3IkAlPJWn/V6eer3kaRiMnsuSZx40OkDgI88bH4OWXwIi LOO8kzytLxNfAoL321LZQPHSXmxnp1j5YJYkuGOsdxDGpM4KDEDmPzF9v wLtGor4Mcdrg8qj5sKeLaVDE11uI+U3zogq1K7fcwOKa6a9H/IOYBXHfT a6zlHd/DRfNEgWUbbvQZJ3SNFb1CEshXSegNCOzP58rz3NSIj4L6Yist7 8r4Lo1sU89qOYbNjNCAPECEnSPn6ROxnuAfCI2eg5QpA98dgdDrGPS4VF A==; X-IronPort-AV: E=McAfee;i="6500,9779,10630"; a="334836059" X-IronPort-AV: E=Sophos;i="5.97,324,1669104000"; d="scan'208";a="334836059" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2023 23:27:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10630"; a="815639240" X-IronPort-AV: E=Sophos;i="5.97,324,1669104000"; d="scan'208";a="815639240" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga001.fm.intel.com with ESMTP; 23 Feb 2023 23:27:23 -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 v3 17/32] x86/fred: add a page fault entry stub for FRED Date: Thu, 23 Feb 2023 23:01:30 -0800 Message-Id: <20230224070145.3572-18-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230224070145.3572-1-xin3.li@intel.com> References: <20230224070145.3572-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1758696635212145731?= X-GMAIL-MSGID: =?utf-8?q?1758696635212145731?= 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) 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 f4de2cdd1c7f..de300bda60ee 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 7b0d4ab894c8..f31053f32048 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 @@ -1528,9 +1529,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); @@ -1577,3 +1579,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 */