From patchwork Thu Sep 14 04:47: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: 139322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp124615vqi; Wed, 13 Sep 2023 22:26:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwd0w1Ood17yyaVfXR7ZGBQ8O3ZG776TLTpvmyrYgxVza9sGrzLFj9f6MF5nEu3w0RvB/s X-Received: by 2002:a67:ee03:0:b0:44e:b396:419d with SMTP id f3-20020a67ee03000000b0044eb396419dmr4296075vsp.3.1694669166682; Wed, 13 Sep 2023 22:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694669166; cv=none; d=google.com; s=arc-20160816; b=fqU6LRSktyGX3MchAwRpIOqy1IM3CshboaMNXl7JT55gZpRPt13o/Uv0Nid2Q6oIdc gfHHKidUCpUFPx7E7PHjJ6kWhhkXG7qciaI/OcOSaCkF8IbcBT629+qqiuEsVs0kAxB6 yYWx0ZzM398iANZvMT9h8LuQ6Z8M8LL/X9ydZAjjizSXPjrb5j0OXH1U3wvhhDS+PO3h pam6EMWjHGj7M0SsjE/x1eTK2F3oRuhInX8t4i1HBEtb4dilY1wqIR5dDiNpiDzFt6VL 3fw+7YH81YXKmhUEmw2EUQJKE/mRTX+zSvIbsKp46g0N2cFIMOzzvjOU6Z92zKhjYYio +ISw== 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=jqCbnajAXgJ+s7A1aA7DOHJD13/+EpD442pw8d+Ofss=; b=jWAmaVfHAAD6qkOQoqMoC4Bh1mdXAAX+P5DGaYLyA1kOR78yrjdhCJAWP6n7aN+zKm dYY2jB5CIP1a5dMHflJ787oHh+UyMpGvJHb3ajVZz9Ep1ezeSxI3uID6gndfkR2gvgL5 KtHR/hzcYdHzDX81dKPFMGD/xJOy2Aco4B7vBf3QBsqHuN88aO7gfNM7MznP+QEdMRgA OVVuCvRtyA00UuWX0x0BDlWLlizxaVg+75544ojDPZuFki/nt+BXF91evX9PZcpG9kpL 2vSlTM98nnqITrlnZAvfuCt74qX0TsYlhgg0BO13Ds/5qpmq0LrikOsiO0FHOComz8uq hUWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qpf19+Ra; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id l190-20020a6325c7000000b00573fc129011si737050pgl.797.2023.09.13.22.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 22:26:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qpf19+Ra; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 5377A802A35E; Wed, 13 Sep 2023 22:20:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235630AbjINFUa (ORCPT + 35 others); Thu, 14 Sep 2023 01:20:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235353AbjINFTp (ORCPT ); Thu, 14 Sep 2023 01:19:45 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EBB61FF0; Wed, 13 Sep 2023 22:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694668763; x=1726204763; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bNtEfhEic2/4eI6U3F6LZD3GtdQN7TZ08d/4AOd+L9I=; b=Qpf19+RaO/+rNSUYgEK7ndADjr3LeHPs76DLwBipJExN6G1CQrM8P+m3 nwC0BWdGNC0d+Z51WvlTlTSr6va2ap5B5QsuwyRKgGnb1PoeGuco/jCgc lYVTCj4+nr8bEWaDYYWYMqQTx19SwSwwiu4offfYDea4RRG/bGKOi6nPw jpw49Yu5EUg+9JaSU/TTCZ9YOZmE/0YQ5MAdAtYE700XEclWxPe7pBWkX b/xZLe85BM692YVUNBcFnuq6Y3otYNTEo3Lw25lOapfhyYDHi0t7nWp92 14H45rVITSYZJyR9HlpUo2mju6wCfObZZOXvmzkE3wQxGvlzGcjJ96Bq4 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="382661419" X-IronPort-AV: E=Sophos;i="6.02,145,1688454000"; d="scan'208";a="382661419" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 22:17:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="779488820" X-IronPort-AV: E=Sophos;i="6.02,145,1688454000"; d="scan'208";a="779488820" Received: from unknown (HELO fred..) ([172.25.112.68]) by orsmga001.jf.intel.com with ESMTP; 13 Sep 2023 22:17:42 -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 Subject: [PATCH v10 27/38] x86/fred: Add a machine check entry stub for FRED Date: Wed, 13 Sep 2023 21:47:54 -0700 Message-Id: <20230914044805.301390-28-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914044805.301390-1-xin3.li@intel.com> References: <20230914044805.301390-1-xin3.li@intel.com> MIME-Version: 1.0 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 (groat.vger.email [0.0.0.0]); Wed, 13 Sep 2023 22:20:57 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776989416121466291 X-GMAIL-MSGID: 1776989416121466291 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)