Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1777280rdb; Mon, 2 Oct 2023 23:57:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDt9Z1AdxTgaBQtf/wG8sGs2bcOfvlMZe3DYB9qhE2NDh8AbkXP0jcLVYE2Gi8TZfQc/6w X-Received: by 2002:a05:6a20:12ca:b0:140:6d68:ce07 with SMTP id v10-20020a056a2012ca00b001406d68ce07mr16253536pzg.52.1696316277633; Mon, 02 Oct 2023 23:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696316277; cv=none; d=google.com; s=arc-20160816; b=BVQKM5kEgpFTbDFZ1c2M++N822D8+3DwnVDjwoiUxn0UQ3TOSMZCLRcWlk/LHJAW8C a6zlhScF038ihV3oBrUrCLDiLIpJ6mJaxyEnNe/z2G4Ob58Ld0i2S0MdeVL7xQUD+B1W 9HrrtZDWFapqV7WGp2rGbeDwuucy2neWOzEUslTpyUAz20zC4U8TF7ad6hV1nNJQJFuc zsH+qNr+TgL59qbrOJr6/lVrZfH325VsujR49OxLseDynttrHwwdt69OjXhgVzAhlCvr ug/4pHrBioM8esHeXhCaRGb+FhUmKZkx12+Ow4IBvo1E03/DCPNpTUgtn4ySHLDvzTni 3P+w== 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=RYtazmEiUZouwK5sDJ9DS0fjOpmsfVVL+4zG0pg0LkE=; fh=Tb1p8S3iOxe/kX/WSNC3xEJzSVgGJ5DaxSrKb+pzH+4=; b=N/L1s36CXPighq87Soc4v4ZltAPwz5UMTsLY1ykgmKvN93b4hAoEC5g7L6Ss033BIY dcuvZjoXbhEAMwtlBr08N+kawUTa/VbrUeepBwOiGR0H1H9ewGcx8J5rFvMTQqnKleCW V27f4+eXA8T5YKmE1/AIYAK87wW1BXM9cKlSk/ZigyfqCD4w8Iya3YatBg9TEXkdNqAQ 2ue/NrKHGPah0yhMKvkNIDJuGcDswekntpD60wV72qer26TZ6GadhWuPvUAbxT0gr8Zh rfQGBG0ZC1UhMHl3+GrAMjlAX41wgoa+ujsidVl7zZPgBmP2KwStaxBtmz8Q6o2vks5m 4XNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Yi/z7nBM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id fi23-20020a056a00399700b00691023321ebsi887834pfb.113.2023.10.02.23.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:57:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Yi/z7nBM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 9D3B78082077; Mon, 2 Oct 2023 23:57:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230317AbjJCG5u (ORCPT + 99 others); Tue, 3 Oct 2023 02:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239522AbjJCG5l (ORCPT ); Tue, 3 Oct 2023 02:57:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19132AD; Mon, 2 Oct 2023 23:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696316129; x=1727852129; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bNtEfhEic2/4eI6U3F6LZD3GtdQN7TZ08d/4AOd+L9I=; b=Yi/z7nBMIQmwh6m0Mc7MSjp6xVnaZzSN2N9HdApVBXN7+GJYt5tOUB1f 892EA2jb/fEAdRe/MrP2c+p606IPGKwZ0jD8RP2AC728YzjtAr+3HFG71 WMhKimaz7a7SOfxqwpxKzmhUtfWnVVLcN5N4YD77O0uG6yfOS2VcXUQTW tZ+reDa8CcAzMd/uy2DNOPEZIKehddWSu+vPi4alm7jXoQlOyJ3iZ+Wje diFANd6wKgix7mtr/5gXIusL8zvrRTJcP2GWroiBqneKUoH8Wsl0/ySDJ Enp8uMrVpr6aJcrE66No58N5OzebtdnA7X68swasH3WI1gDCydZTIY/Ej w==; X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="367858241" X-IronPort-AV: E=Sophos;i="6.03,196,1694761200"; d="scan'208";a="367858241" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 23:54:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="1081900986" X-IronPort-AV: E=Sophos;i="6.03,196,1694761200"; d="scan'208";a="1081900986" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga005.fm.intel.com with ESMTP; 02 Oct 2023 23:54:48 -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: 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 Subject: [PATCH v12 27/37] x86/fred: Add a machine check entry stub for FRED Date: Mon, 2 Oct 2023 23:24:48 -0700 Message-Id: <20231003062458.23552-28-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003062458.23552-1-xin3.li@intel.com> References: <20231003062458.23552-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 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 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 23:57:56 -0700 (PDT) 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 6f35f724cc14..da0a4a102afe 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -52,6 +52,7 @@ #include #include #include +#include #include "internal.h" @@ -2144,6 +2145,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.34.1