Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2368878rdb; Tue, 10 Oct 2023 01:36:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLRVypbgzCMVIWctGlKS1rMlPmliVHT8c0WSOs6bu8iTPwbd4EokqdlBvLrfB1rnmAkEUT X-Received: by 2002:a25:4f82:0:b0:d8b:737f:823b with SMTP id d124-20020a254f82000000b00d8b737f823bmr16093162ybb.0.1696926984472; Tue, 10 Oct 2023 01:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696926984; cv=none; d=google.com; s=arc-20160816; b=bKj2+bYUUhr6QW6EI+oqQjVDZl/MdMfW4+xWrZhrnJa3qVl/Lm55qwJrRZJZ+hrAOK mJNgBSz82kE/IBuhVFzWGQG6ABF3q1ffw2tHBxHJFxzTHH4q/Zj81Gw2zlzcRs4BUpIf NTKyqJBL5ubjLuTx68BrHH/RGFB3mB0C3iM7Y4GRVia0ooGfoYApo/XrEuL2MQnkB7jx EB3FmuHTfr50ebXknNRCaU9iEaOXLkY/L8buzU2Yg8g20aej6TkBFHjM/TmdPix0snVu SPC+ouDbp6AZu0nSbcuiXF86EPH5pvTvrF4LAxchONyAEOdyWDKS6cSQCVmvMRN4lXmh pE0w== 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=CtvDqJuLbtjIG6g4yGDIx6D3KnuyD3Usb3oRJRR2zKs=; fh=qpQuS5DB8/tFQfmdgX1i3QvppRzkrzhfKx2/rzpwOaE=; b=Tyzsai3iLhXPJFaVbJlGKIjGL0Cd4DCRNatrscYyDFMcZinCg6VocpIiyQYLRo1amQ ZYyVQxffySpNnIS8ylxrz/oa3Kt3OZbfDvEMMED2RTPY5BP4bpnqwwxftZRLI7l271nd AM6Ga9NpRb0UJ1ozqFicw3bzK83jQ3stcPH8CpKnIug6UhC90+wY1uyKhx4auni06jZk VApWIi5FSnOfc0SBPqTYdGsM855IDx4cGQzJ2pxcU41IqqHiC01UWuIup9ubwOJP2OPe ngss6TJUe/RJnP3nHfRkOidDhM106tEwgxVsAmp6QPmEu77JTtgH17rvEIWnujtVM19F XyHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=keJcEqYF; 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 a1-20020a655c81000000b0057ab7f46381si10821963pgt.76.2023.10.10.01.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 01:36:24 -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=keJcEqYF; 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 54FA380CF52F; Tue, 10 Oct 2023 01:36:09 -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 S1442930AbjJJIfl (ORCPT + 99 others); Tue, 10 Oct 2023 04:35:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442898AbjJJIfg (ORCPT ); Tue, 10 Oct 2023 04:35:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1450DA4; Tue, 10 Oct 2023 01:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696926934; x=1728462934; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m7pCDbhKS6+u2jcznAubfaRxlAgJtSYbB0zCkXhtCcE=; b=keJcEqYFaOJEYzUkdJs8Jft5Ct6gYDwV5Lf18cWLvqtj64Kif8BUg2r2 1dEaf9aaXoipwdTjWVzuXgdfobvcwluduObiJeCQoLSk3p151Kd0C2iMg 6vzMDb+Rh+CBdKeE0F0d6RfRqxJ08xEYm9VFMmGFj2zxcV9MPdrskqYoU 2srdz334BLAsk0fpy1PBsE1A+1OwIfVGqsg8Wr3Is1gaV4/Gbeg0h5eTY Q3NA/BDiabkx5f0HO6/ec9HBbokMe3edoknx9tN4qEi1Vie1f+64QI7hw SLKBWbUSf4IbLRsfWduakHttw1NZtQWtgKyBdiy8mhzx9lBm8/9t9ymJh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="363689792" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="363689792" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 01:35:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="1084687182" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="1084687182" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 01:35:33 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Michael Roth , Paolo Bonzini , Sean Christopherson , linux-coco@lists.linux.dev, Chao Peng Subject: [PATCH 03/12] x86/mce/inject: Add notrigger entry to suppress MCE injection Date: Tue, 10 Oct 2023 01:35:11 -0700 Message-Id: <97809b68e427922948044e33599c2fc7c9f6134c.1696926843.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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]); Tue, 10 Oct 2023 01:36:10 -0700 (PDT) X-Spam-Level: ** From: Isaku Yamahata The current x86 MCE injection framework injects MCE when writing to /sys/kernel/debug/mce-inject/bank. KVM wants to inject machine check on behalf of vcpu context instead of the context of writing to the bank file. Because ACPI APEI has a similar requirement and it adds /sys/kernel/debug/apei/notrigger to suppress immediate injection. By Following it, add /sys/kernel/debug/mce-inject/notrigger to suppress MCE injection. The alternative is add new value "notrigger" to /sys/kernel/debug/mce-inject/flags in addition to "sw", "hw", "df", and "th". Because it may break user space ABI, this option follow ACPI APEI error injection. Supposed usage flow: $ echo 1 > notrigger ... setup MCE values $ echo 0 > bank The last step to setup mce value to inject with MC bank 0. Originally this step injects mce. With noijnect=1, don't inject. $ echo 1 > /sys/kernel/debug/kvm/-/vcpu/mce-inject tell KVM to inject MCE in the context of vcpu. Signed-off-by: Isaku Yamahata --- arch/x86/kernel/cpu/mce/inject.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/kernel/cpu/mce/inject.c b/arch/x86/kernel/cpu/mce/inject.c index 461858ae18f9..88603a6c0afe 100644 --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -34,6 +34,7 @@ #include "internal.h" static bool hw_injection_possible; +static u64 notrigger; /* * Collect all the MCi_XXX settings @@ -598,6 +599,8 @@ static int inj_bank_set(void *data, u64 val) } m->bank = val; + if (notrigger) + return 0; /* * sw-only injection allows to write arbitrary values into the MCA @@ -637,6 +640,21 @@ MCE_INJECT_GET(bank); DEFINE_SIMPLE_ATTRIBUTE(bank_fops, inj_bank_get, inj_bank_set, "%llu\n"); +static int inj_notrigger_get(void *data, u64 *val) +{ + *val = notrigger; + return 0; +} + +static int inj_notrigger_set(void *data, u64 val) +{ + notrigger = val; + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(notrigger_fops, inj_notrigger_get, inj_notrigger_set, + "%llx\n"); + static const char readme_msg[] = "Description of the files and their usages:\n" "\n" @@ -685,6 +703,9 @@ static const char readme_msg[] = "\n" "mcgstatus:\t Set MCG_STATUS: the bits in that MSR describes the current state\n" "\t of the processor after the MCE.\n" +"\n" +"notrigger:\t Suppress triggering the injection when set to non-zero\n" +"\t The injection is triggered by other way.\n" "\n"; static ssize_t @@ -714,6 +735,8 @@ static struct dfs_node { { .name = "cpu", .fops = &extcpu_fops, .perm = S_IRUSR | S_IWUSR }, { .name = "mcgstatus", .fops = &mcgstatus_fops, .perm = S_IRUSR | S_IWUSR }, + { .name = "notrigger", .fops = ¬rigger_fops, + .perm = S_IRUSR | S_IWUSR }, { .name = "README", .fops = &readme_fops, .perm = S_IRUSR | S_IRGRP | S_IROTH }, }; -- 2.25.1