Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp209965rdb; Tue, 5 Dec 2023 03:23:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGygYyfWi55YMAaz5qAgi3IkXwJROUUm/jzjyg3e3mfh7Tpx7ICBPLzsfNbOtEceAa6IrD7 X-Received: by 2002:a05:6358:2813:b0:170:17eb:1e5 with SMTP id k19-20020a056358281300b0017017eb01e5mr3766441rwb.40.1701775385551; Tue, 05 Dec 2023 03:23:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701775385; cv=none; d=google.com; s=arc-20160816; b=Aa8qUxtEqiXzf77C+J+8+9fKkadZWOfzVQo5kXo4Zhdh4oIZCAGrhs3KLefPR3KXWE jBWWuqj2uabzlB5kL5gNv3XyUqSP3ipQoydTYcvgHkKn0hVaDrYinqtsW298H1gyQcl/ lMRj2WMpINMl0nj6/vBqg3UNhSOor+Aa6dALzkapdYLyycL2JUYLApVo5kABHvlYMdCL y6CXCBqPplqOjQP1GeV7RbqSFdb1xZ7WsxvcFqq2xqZa3giGYm6SRqi40Gafg8L439vM vKimu38cV5yf+gQamp3QQlJrbl2r+q2/NxSzxmvO7gTxGQep29PGlUayJerRU3ddzx+z MLZA== 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=FwQUc9tQToMtazxlFg2zWniA4tJ3gf3CXGxl7X+J2ho=; fh=uCCWEUVpLc/xDP/D3WvGY/BxHU9d0NQYu/T71GEsNmA=; b=y5tXRmTfczrmWjuh8+nFG3uGmRZXhD012y/SjkneYXlAwp3I5zY/uChNNIkZCtpJmI UZKpOR3NQ6K83TjZZs1io98Q8ceNl26C69vgMMCMc8FBOXkzMx1B6fC31E67BHDZhEoj SjNPFgdJpI19IfFQvryS8SN95Q8Uw8KSgWbrSToeEhryBNJT3ihMwB8ZrLv0JurSp360 8I8tR+84j0yVjcwQvKq/pmvFTLKeNSYF43paZ+dcJKnZCk6e0Syl2ovjkfB4hkwwc8YU CyPz0i2fIckqK5dEsupCBj3jCaSvyBu1nxDZS4R2x4EJviQozmxj6Lui92vZwPqc/yCB bcFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QIRaaP4a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e14-20020a65678e000000b005c673abd811si4541136pgr.254.2023.12.05.03.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:23:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QIRaaP4a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B8AD780C0389; Tue, 5 Dec 2023 03:23:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442292AbjLELWj (ORCPT + 99 others); Tue, 5 Dec 2023 06:22:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442153AbjLELVj (ORCPT ); Tue, 5 Dec 2023 06:21:39 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4D3A1B3; Tue, 5 Dec 2023 03:21:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701775293; x=1733311293; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9l8F1WmhlJ7jRL54JQMm6v1HYP6GXYsOB2qRuf6ZAIU=; b=QIRaaP4ai5nU0yfEW7NPpKlu303fM6X7aecv/i6NhDYravKCctIv55lE FO/Gcu5T/LeC80K53qiG8I07J4H/+ZbebLSaybD0VVEiz+YI6gCdkplkZ h9iRXiXqjape/Nn2kIurZ0t6VAqzncA/tQba3nn7CbXDjG8p6/DJi6u5J dKaGOfoY0aFq0ok5QlprrGSYQqQRIQNDNNDpyE8HFN8uSFQKL/hyJqwhH SqbWhw8FnWzSypeC7l42SB6N2O5EGPXBLK8rvPOvhGIKNnjy94X5Q4gLL KmlVMbvUSPwOFXScPdRN/z2+W4oFNTvsnJE82WgRo2VTMwhMBewL51Ceg w==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="942607" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="942607" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2023 03:21:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="1018192988" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="1018192988" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 05 Dec 2023 03:21:23 -0800 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: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, luto@kernel.org, pbonzini@redhat.com, seanjc@google.com, peterz@infradead.org, jgross@suse.com, ravi.v.shankar@intel.com, mhiramat@kernel.org, andrew.cooper3@citrix.com, jiangshanlai@gmail.com, nik.borisov@suse.com, shan.kang@intel.com Subject: [PATCH v13 25/35] x86/fred: Add a machine check entry stub for FRED Date: Tue, 5 Dec 2023 02:50:14 -0800 Message-ID: <20231205105030.8698-26-xin3.li@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205105030.8698-1-xin3.li@intel.com> References: <20231205105030.8698-1-xin3.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 05 Dec 2023 03:23:04 -0800 (PST) Like #DB, when occurred on different ring level, i.e., from user or kernel context, #MCE needs to be handled on different stack: User #MCE on current task stack, while kernel #MCE on a dedicated stack. This is exactly how FRED event delivery invokes an exception handler: ring 3 event on level 0 stack, i.e., current task stack; ring 0 event on the #MCE dedicated stack specified in the IA32_FRED_STKLVLS MSR. So unlike IDT, the FRED machine check entry stub doesn't do stack switch. Tested-by: Shan Kang Signed-off-by: Xin Li --- Changes since v5: * Disallow #DB inside #MCE for robustness sake (Peter Zijlstra). --- arch/x86/kernel/cpu/mce/core.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 1642018dd6c9..d524eb87f76c 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -53,6 +53,7 @@ #include #include #include +#include #include "internal.h" @@ -2150,6 +2151,31 @@ DEFINE_IDTENTRY_MCE_USER(exc_machine_check) exc_machine_check_user(regs); local_db_restore(dr7); } + +#ifdef CONFIG_X86_FRED +/* + * When occurred on different ring level, i.e., from user or kernel + * context, #MCE needs to be handled on different stack: User #MCE + * on current task stack, while kernel #MCE on a dedicated stack. + * + * This is exactly how FRED event delivery invokes an exception + * handler: ring 3 event on level 0 stack, i.e., current task stack; + * ring 0 event on the #MCE dedicated stack specified in the + * IA32_FRED_STKLVLS MSR. So unlike IDT, the FRED machine check entry + * stub doesn't do stack switch. + */ +DEFINE_FREDENTRY_MCE(exc_machine_check) +{ + unsigned long dr7; + + dr7 = local_db_save(); + if (user_mode(regs)) + exc_machine_check_user(regs); + else + exc_machine_check_kernel(regs); + local_db_restore(dr7); +} +#endif #else /* 32bit unified entry point */ DEFINE_IDTENTRY_RAW(exc_machine_check) -- 2.43.0