Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5225778rwd; Mon, 12 Jun 2023 01:43:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64CgW3/rRrJfxSxFNvG+LVYSEnpNrXIlI2oSr7xRWl7beGwfb6RKzYK88HCQPWyvEgGYxZ X-Received: by 2002:a17:907:97c6:b0:961:800b:3f1e with SMTP id js6-20020a17090797c600b00961800b3f1emr9936851ejc.73.1686559412861; Mon, 12 Jun 2023 01:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686559412; cv=none; d=google.com; s=arc-20160816; b=dUaaS3mZk8x3wVMvCyvOreBSwRzkkQlYF+09Doi078E+uPQxDyBiEO4f5Lv8RMBnqN cKqxkPGhNm9jnzRNPeTFtCGNM+kjN9CWkGrt8oDhpkLDqbUZm+ur14vH0m7vYhlx7Yxl lDlXpkFu31MwJfBHgqC9FDFG+fKixKSkumBDBnaUXGX0Xg3VH946XBg83KU7/pBh2aUR IiLF7icmH4qlWIueSyaihBM1IJVrEIKj6/6IwjAeOD63zfrLiilncSQJkIVQxs3MWnhT 3G5XBqfgMd6lFPDHLWk58Q8jB5B29KpVng4MvzDNQbRiR/Mkeg/kNU47jvh1n8nXKDkI T1gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WidRurjT0ZQjqOTCZg3cgknles+iUNaqKBpmmjcz4WU=; b=Yc7BJenBNKRyPzrrp1CA7BQjViSVMp3Z/6i2tXJUuFpL1C8iburgX3SvpOuyBWthGf eGbCcbrO1HuhY2xqmMKLoBHEKw3ebtGLshvKt8x9EgmdXJJWl9NVwjMtzAaOkn8etRVZ tpAtyW2E+Srl9+I9OQHePBn68ygUPDYEqD5WJ6x4QNSG7M18ZlWNnXQQMv6FDqL1GxsQ Ey4rpuLHnXqbT+5yoDLyNQLCGZIZjt8DVJIGV/gUSi01y4IpyRRgpQQIJb8l6wSUpelO TIMQV3thSAZJduOFg4QEHE1bdtYMb9SvowQrdNAH3w0zGx4qQMLsUuoDLjQnTJT366bQ /czg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YJKR9XUJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a170906089100b0097394940d6dsi1511318eje.406.2023.06.12.01.43.08; Mon, 12 Jun 2023 01:43:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YJKR9XUJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230369AbjFLIRI (ORCPT + 99 others); Mon, 12 Jun 2023 04:17:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230316AbjFLIQ7 (ORCPT ); Mon, 12 Jun 2023 04:16:59 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B54671B3; Mon, 12 Jun 2023 01:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686557815; x=1718093815; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ardrXUUaDCUC8rYZCEBB1Od/Uz+5UBeHiqci3S1ZWy0=; b=YJKR9XUJKHPzbG3FpLGDi0XSCdvGHDU8DqE9SlJqmBWhIas7+sYoCZMI rS+2ajFgNVl7fxdVSZNeHooLfUnQkLHsO3iRrv9qZ8/oGU4Gj0R7S4Lv4 5v8b0hoLDKbXb8a4reGGKWvbrUBsZaH5oFC/1fNILChjDeRfTLg6Um81d 6+tyuYgzkoNAaXOxkyKSFCIXOdP9lTTHIY2ehJU9HNJStHvDmv99AT2ja 6KGSpBIvhZQfe5P8IUXpB1OqZ3FaqQHFazrfYP1weQE5DcsqsufzEnmE9 y/flNQSybSOPiMDJ/pwChTPkEVk0aMWviE54HAIaT9FOXl1+nccOMn/yS w==; X-IronPort-AV: E=McAfee;i="6600,9927,10738"; a="360457577" X-IronPort-AV: E=Sophos;i="6.00,236,1681196400"; d="scan'208";a="360457577" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 00:59:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10738"; a="855514931" X-IronPort-AV: E=Sophos;i="6.00,236,1681196400"; d="scan'208";a="855514931" Received: from smizr3x-mobl3.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.43.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 00:59:13 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 470A010CC1C; Mon, 12 Jun 2023 10:59:10 +0300 (+03) Date: Mon, 12 Jun 2023 10:59:10 +0300 From: "kirill.shutemov@linux.intel.com" To: "Huang, Kai" Cc: "kvm@vger.kernel.org" , "Hansen, Dave" , "david@redhat.com" , "bagasdotme@gmail.com" , "ak@linux.intel.com" , "Wysocki, Rafael J" , "linux-kernel@vger.kernel.org" , "Chatre, Reinette" , "Christopherson,, Sean" , "pbonzini@redhat.com" , "tglx@linutronix.de" , "linux-mm@kvack.org" , "Yamahata, Isaku" , "Luck, Tony" , "peterz@infradead.org" , "Shahar, Sagi" , "imammedo@redhat.com" , "Gao, Chao" , "Brown, Len" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Huang, Ying" , "Williams, Dan J" Subject: Re: [PATCH v11 19/20] x86/mce: Improve error log of kernel space TDX #MC due to erratum Message-ID: <20230612075910.jqkiofjm6mkdl7cy@box.shutemov.name> References: <116cafb15625ac0bcda7b47143921d0c42061b69.1685887183.git.kai.huang@intel.com> <20230609131754.dhii5ctfwtzx667o@box.shutemov.name> <90aefcfd663c654197c5878e410f55cc4473eb79.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <90aefcfd663c654197c5878e410f55cc4473eb79.camel@intel.com> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 On Mon, Jun 12, 2023 at 03:08:40AM +0000, Huang, Kai wrote: > On Fri, 2023-06-09 at 16:17 +0300, kirill.shutemov@linux.intel.com wrote: > > On Mon, Jun 05, 2023 at 02:27:32AM +1200, Kai Huang wrote: > > > The first few generations of TDX hardware have an erratum. Triggering > > > it in Linux requires some kind of kernel bug involving relatively exotic > > > memory writes to TDX private memory and will manifest via > > > spurious-looking machine checks when reading the affected memory. > > > > > > == Background == > > > > > > Virtually all kernel memory accesses operations happen in full > > > cachelines. In practice, writing a "byte" of memory usually reads a 64 > > > byte cacheline of memory, modifies it, then writes the whole line back. > > > Those operations do not trigger this problem. > > > > > > This problem is triggered by "partial" writes where a write transaction > > > of less than cacheline lands at the memory controller. The CPU does > > > these via non-temporal write instructions (like MOVNTI), or through > > > UC/WC memory mappings. The issue can also be triggered away from the > > > CPU by devices doing partial writes via DMA. > > > > > > == Problem == > > > > > > A partial write to a TDX private memory cacheline will silently "poison" > > > the line. Subsequent reads will consume the poison and generate a > > > machine check. According to the TDX hardware spec, neither of these > > > things should have happened. > > > > > > To add insult to injury, the Linux machine code will present these as a > > > literal "Hardware error" when they were, in fact, a software-triggered > > > issue. > > > > > > == Solution == > > > > > > In the end, this issue is hard to trigger. Rather than do something > > > rash (and incomplete) like unmap TDX private memory from the direct map, > > > improve the machine check handler. > > > > > > Currently, the #MC handler doesn't distinguish whether the memory is > > > TDX private memory or not but just dump, for instance, below message: > > > > > > [...] mce: [Hardware Error]: CPU 147: Machine Check Exception: f Bank 1: bd80000000100134 > > > [...] mce: [Hardware Error]: RIP 10: {__tlb_remove_page_size+0x10/0xa0} > > > ... > > > [...] mce: [Hardware Error]: Run the above through 'mcelog --ascii' > > > [...] mce: [Hardware Error]: Machine check: Data load in unrecoverable area of kernel > > > [...] Kernel panic - not syncing: Fatal local machine check > > > > > > Which says "Hardware Error" and "Data load in unrecoverable area of > > > kernel". > > > > > > Ideally, it's better for the log to say "software bug around TDX private > > > memory" instead of "Hardware Error". But in reality the real hardware > > > memory error can happen, and sadly such software-triggered #MC cannot be > > > distinguished from the real hardware error. Also, the error message is > > > used by userspace tool 'mcelog' to parse, so changing the output may > > > break userspace. > > > > > > So keep the "Hardware Error". The "Data load in unrecoverable area of > > > kernel" is also helpful, so keep it too. > > > > > > Instead of modifying above error log, improve the error log by printing > > > additional TDX related message to make the log like: > > > > > > ... > > > [...] mce: [Hardware Error]: Machine check: Data load in unrecoverable area of kernel > > > [...] mce: [Hardware Error]: Machine Check: Memory error from TDX private memory. May be result of CPU erratum. > > > > The message mentions one part of issue -- CPU erratum -- but misses the > > other required part -- kernel bug that makes kernel access the memory it > > not suppose to. > > > > How about below? > > "Memory error from TDX private memory. May be result of CPU erratum caused by > kernel bug." Fine, I guess. -- Kiryl Shutsemau / Kirill A. Shutemov