From patchwork Tue Oct 3 06:24:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 147672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1899585vqb; Mon, 2 Oct 2023 23:57:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFtYV7sca6OioI60nLMzF9kj9RDpwv7aA0c60FHr4N5M3NMuXX7uCdm0/J0C67+BuRjTCC X-Received: by 2002:a05:6a20:430e:b0:141:d640:794a with SMTP id h14-20020a056a20430e00b00141d640794amr17943614pzk.39.1696316277575; 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=x/Aqed8FORzOsz5Mb+aA7gnyo6lECZ9GIe6ZbPgKEvNtNBxy5GngvmA/d3NvJpsH7F xvn0F6JJoREMXudkhJaglwho/K86yQdAOkd1w9owu178rWqiIWBgTMgtRDAVXz/OG0Fv ztiduqhw6zJoJf8dd0mP+58Hw+VJpMzjszdWpO3H00eGQbnaeLvlUwVWMuOj5D6M7GDU CdIdaMfk1a96/Fm8BCJ0hs58GGtq/8wkrdMFBW7a3e6jeahzR+v2So28sDREroWSPe9t xWJy/9DsZSiJnQGFI008RDlmd7jl5Sl0G4/STDKEWRhIcHhBM5yJJTk5Qk4kctoXg3XH XDUA== 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 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x11-20020a170902ec8b00b001c566ea86eesi835485plg.177.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 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; 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 2620:137:e000::3:7 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 CB5A18135297; Mon, 2 Oct 2023 23:57:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239349AbjJCG5u (ORCPT + 18 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 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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 23:57:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778716536949450102 X-GMAIL-MSGID: 1778716536949450102 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)