From patchwork Thu Aug 8 15:13:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang Ruan X-Patchwork-Id: 13757853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A75A1C3DA4A for ; Thu, 8 Aug 2024 15:13:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57D8B6B00E9; Thu, 8 Aug 2024 11:13:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A5356B00DB; Thu, 8 Aug 2024 11:13:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AB5B6B00E9; Thu, 8 Aug 2024 11:13:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EE8C96B00DB for ; Thu, 8 Aug 2024 11:13:39 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AABCD414EE for ; Thu, 8 Aug 2024 15:13:39 +0000 (UTC) X-FDA: 82429422558.18.C959F2D Received: from esa3.hc1455-7.c3s2.iphmx.com (esa3.hc1455-7.c3s2.iphmx.com [207.54.90.49]) by imf15.hostedemail.com (Postfix) with ESMTP id 2071CA0023 for ; Thu, 8 Aug 2024 15:13:36 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=fj2 header.b=QqhsuvQd; spf=pass (imf15.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 207.54.90.49 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com; dmarc=pass (policy=reject) header.from=fujitsu.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723129952; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=a41YnmUzqDovxtesQJciAICS9pMJSCtzJTIOnmdLE1s=; b=TzE2NF3a39KdUpMDlk84bPThiv0fKQfnHBwbPFMygCPb9lGt+H4xF4qO0a8T91zuNKpKdo mqC/IlIXECFF3OnY1gFcWVTWbpie0EJTCnrdPonBLneiETWwMGv3EkLDSsDMgWySGCFb6x cZ9b9gQcpx80im1XKbnkDn3dFiNc79Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723129952; a=rsa-sha256; cv=none; b=q6hGdBaka9H8GBNFCdxGIGbD1W9xktyfB6pHl0OpjLdDVx/NIzvzFI5ZSU4iJ9pHVF4Jmf n50UJ48j3E/hKUi3haOLXLOj1ehN/lKPodN50C9lmF18LYRnzneRQO9oNOYvSPjj2ryb6c taGubDdHteCRG7oIEonXQ/pH9kPPP8Y= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=fj2 header.b=QqhsuvQd; spf=pass (imf15.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 207.54.90.49 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com; dmarc=pass (policy=reject) header.from=fujitsu.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1723130018; x=1754666018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KgIqmjD+KlW1kjDaEXej5x0fZ6oZID/cY1gsTrU8Dv4=; b=QqhsuvQdaFcqxKbI1PIXAaSOIEjr1nw2VbY0INvDmxRF5+aC0cTxGd4W jLXUPfLFy7mAeY4+wvR6AkY+HMdNq6iOvcL40S+U2RcrTLnEpOx1K8hjh aGGFr2U26X7+H1FdgE3tFswtOvMraUWhBBcmJwD9Q1k9S6SlFIHz25oEy 4iFMH5vNOG60DKQlNc1DiBzw9Oi9qQvgDx7duYQSU1nQWzO8a4V4lE+05 vDEjoOF9RowQYaOZixrLul9JMSUeCk9qwbSaTUNFbdCPiLNl2joWbRgcB KlSV9LgkLrNDLzmn8PlNK4IORvX88XbnvvCIKaoJSq8WXqRXtP7PGwMq5 Q==; X-CSE-ConnectionGUID: 0jKP0z9PRs2cffWbEYTUaA== X-CSE-MsgGUID: SCVHpWv9RFKjHm1JbBAY9Q== X-IronPort-AV: E=McAfee;i="6700,10204,11158"; a="170172151" X-IronPort-AV: E=Sophos;i="6.09,273,1716217200"; d="scan'208";a="170172151" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 00:13:35 +0900 Received: from yto-m3.gw.nic.fujitsu.com (yto-nat-yto-m3.gw.nic.fujitsu.com [192.168.83.66]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id AB217C68E1 for ; Fri, 9 Aug 2024 00:13:32 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by yto-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id E62ACD9764 for ; Fri, 9 Aug 2024 00:13:31 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id 6F54F2008E881 for ; Fri, 9 Aug 2024 00:13:31 +0900 (JST) Received: from irides.g08.fujitsu.local (unknown [10.167.226.114]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 8C5951A000C; Thu, 8 Aug 2024 23:13:30 +0800 (CST) From: Shiyang Ruan To: qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, linux-edac@vger.kernel.org, linux-mm@kvack.org, dan.j.williams@intel.com, vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com, alison.schofield@intel.com Cc: bp@alien8.de, dave.jiang@intel.com, dave@stgolabs.net, ira.weiny@intel.com, james.morse@arm.com, linmiaohe@huawei.com, mchehab@kernel.org, nao.horiguchi@gmail.com, rric@kernel.org, tony.luck@intel.com, ruansy.fnst@fujitsu.com Subject: [PATCH v4 1/2] cxl/core: introduce device reporting poison hanlding Date: Thu, 8 Aug 2024 23:13:27 +0800 Message-Id: <20240808151328.707869-2-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808151328.707869-1-ruansy.fnst@fujitsu.com> References: <20240808151328.707869-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28584.000 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28584.000 X-TMASE-Result: 10--14.315400-10.000000 X-TMASE-MatchedRID: xXA8JSLb31sZHQl0dvECsQ0QY5VnQyAN9LMB0hXFSeinw6VQ+/MY/aJf gPmvd/XOfBnw4TEwb3JFUO4Lwe1qd/mi+iQw41eA/sUSFaCjTLw7x+Tuf7McDOjMOEZ5AL0SmRD Sh3pCEkOqbnUbIrDbhZdYXl3VkvoTqUUaBCb+VbHEOJqSsn5KmRYHLuVbwKXA33Nl3elSfsqyEH XzDCqxQcYS7GmsALUGD+giDHW5zvvQ9t8zINQJxDe9MF4SNA1+eF6MevMVZUDWeQtrcncLfegoS vaKsl/kIvrftAIhWmLy9zcRSkKatcOJmY4XRXkVyRfzRkrgkUH5UnqVnIHSzyxMw0FMkBlZLy7E GpbOGkod28lWFjU6v6bDnpxC0iz1mtdd6hGWj/x1e7Xbb6Im2resiCwR1MqZemnPKw9dcAo7/6w m+1WoGTE7bCG779IoSUJkKHLyNuXlFpsfMgM6DNyBRU/cKn690VvRkjCHhK6bKItl61J/yZ+inT K0bC9eKrauXd3MZDX+2MfnmxupmrdgHidVdLaElLjCcbrd1WCkN9kx8PZr3bjg6uqJ6r4l X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Stat-Signature: aa3mxnwhkkbqogoft4ocdng5chn43fts X-Rspamd-Queue-Id: 2071CA0023 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723130016-190283 X-HE-Meta: U2FsdGVkX1/keMiwPSZxrrkEaCi3BCmTLANkHt6Y5bjHvIwinGctYScRBHJRfrVLZJjo206vL6o/8HtgLsn9vSvmLEzCwZ9YIUWmd6jMhNiS+qgImVZCSEWqilQsbC4Jwci7sjyAS5vlK64GNpeowMj7+j2fQfrdbX6DQK+9yhImCbCYQ0pp69ApmFxsdg0oBW/WKXpmWh/0K0OOl+MBZF6qNg42rL/V3HkrPTHAHCSM5Wy9yC52NWILTNrAoXQ6H7PWYIm4LcPJKPfI/pz7nsJ0fBIjwRzhOmYFKhV0KMi8DWuCCmUYrmMCZFgfYrT3+kgpHifV+Cgn5EQUtnO1sy2PFEvrL+YmICTC720QByVH9bdNnfjOYTEQ4bLPeb6zJbpmSa9N81JVAfOX5Ob88U+/ZlpFd1kv+qByXUt83fdUsJ+9/BLxP6A4nBC2Yq+ChwBaD1goz0FeKbjBQBC1rUFT7fJ/zrCfYS73ITf3auBffw6j2Do+8Y4+nRYN2Gi5iQzD7aAxbYdJnGfYkUX2iJ3XcUeryr7EtK70fnoqVROdmz1nK+xKzUedVwVB3yswp5LiDBdgPoMa5nT6BAwFGh0S5G+lVn94z0S2burkyG0i4TeFdmxX9rFUhmU8ZUsfLr1RWjvERAtkEqEesOgMLXc5M/ROE0mbAdjrykQet8HLSBkW8RbdD6fBCH105BbN5oS6iKhRFTGtHCaDqeV/NQyscctFk8lE3bLYRM9/FjQic9NPubojQNpYOziiNzAybliED3gGwnhlwxt3Nrc+rg8MGM/dS7DiqEGNEOCc6B8YSyWxNUELQExA7oSKi3GLNR1pY3rLE+ZK9TncMK47tp9MiUc+DsJbGb9lUFgjhO4VdZtUkHKqh/xlhYSz/6MKzr5Nsm+rZ985m3UFqITgh6MLhvOaccItBCVHXfTnUxkH16XV1mOzqI5XO1ghjLvpwHT3uMrU4Twed/s+Jyf rUCIfZkB wtm4mK2H3ab2GoXjzabRT49T7JeBJBAW8st2VpEkTowiqPesK+xSeTEcWuCw5VpTPqltCo4gdCEWIoSsTyn4IcB4O8eapPh1iOXNy0e+sBYq/z6vgRd1YCnGlXLeROEE/72u8IslABJ67hYTCfGkbzk9evC7myUu7U9clS99BOHs1MHmSX9GEhqAX4H6Z/GrHjofIZpQrwZ1nIYDCxPqTTvQYiEzTfc/l5wGeVlGdh2Tuws1ihQHlfjFhPL9XEt5ipSVvTZE726Br+wF69shThnR6Qd+wMzZG3NzzImBfvyMPw/eGOfyOyb3Uow== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: CXL device can find&report memory problems, even before MCE is detected by CPU. AFAIK, the current kernel only traces POISON error event from FW-First/OS-First path, but it doesn't handle them, neither notify processes who are using the POISON page like MCE does. Thus, user have to read logs from trace and find out which device reported the error and which applications are affected. That is not an easy work and cannot be handled in time. Thus, it is needed to add the feature to make the work done automatically and quickly. Once CXL device reports the POISON error (via FW-First/OS-First), kernel handles it immediately, similar to the flow when a MCE is triggered. The current call trace of error reporting&handling looks like this: ``` 1. MCE (interrupt #18, while CPU consuming POISON) -> do_machine_check() -> mce_log() -> notify chain (x86_mce_decoder_chain) -> memory_failure() 2.a FW-First (optional, CXL device proactively find&report) -> CXL device -> Firmware -> OS: ACPI->APEI->GHES->CPER -> CXL driver -> trace \-> memory_failure() ^----- ADD 2.b OS-First (optional, CXL device proactively find&report) -> CXL device -> MSI -> OS: CXL driver -> trace \-> memory_failure() ^------------------------------- ADD ``` This patch adds calling memory_failure() while CXL device reporting error is received, marked as "ADD" in figure above. Signed-off-by: Shiyang Ruan --- drivers/cxl/core/mbox.c | 75 ++++++++++++++++++++++++++++++++------- drivers/cxl/cxlmem.h | 8 ++--- drivers/cxl/pci.c | 4 +-- include/linux/cxl-event.h | 16 ++++++++- 4 files changed, 83 insertions(+), 20 deletions(-) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index e5cdeafdf76e..0cb6ef2e6600 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -849,10 +849,55 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds) } EXPORT_SYMBOL_NS_GPL(cxl_enumerate_cmds, CXL); -void cxl_event_trace_record(const struct cxl_memdev *cxlmd, - enum cxl_event_log_type type, - enum cxl_event_type event_type, - const uuid_t *uuid, union cxl_event *evt) +static void cxl_report_poison(struct cxl_memdev *cxlmd, u64 hpa) +{ + unsigned long pfn = PHYS_PFN(hpa); + + memory_failure_queue(pfn, 0); +} + +static void cxl_event_handle_general_media(struct cxl_memdev *cxlmd, + enum cxl_event_log_type type, + u64 hpa, + struct cxl_event_gen_media *rec) +{ + if (type == CXL_EVENT_TYPE_FAIL) { + switch (rec->media_hdr.transaction_type) { + case CXL_EVENT_TRANSACTION_READ: + case CXL_EVENT_TRANSACTION_WRITE: + case CXL_EVENT_TRANSACTION_SCAN_MEDIA: + case CXL_EVENT_TRANSACTION_INJECT_POISON: + cxl_report_poison(cxlmd, hpa); + break; + default: + break; + } + } +} + +static void cxl_event_handle_dram(struct cxl_memdev *cxlmd, + enum cxl_event_log_type type, + u64 hpa, + struct cxl_event_dram *rec) +{ + if (type == CXL_EVENT_TYPE_FAIL) { + switch (rec->media_hdr.transaction_type) { + case CXL_EVENT_TRANSACTION_READ: + case CXL_EVENT_TRANSACTION_WRITE: + case CXL_EVENT_TRANSACTION_SCAN_MEDIA: + case CXL_EVENT_TRANSACTION_INJECT_POISON: + cxl_report_poison(cxlmd, hpa); + break; + default: + break; + } + } +} + +void cxl_event_handle_record(struct cxl_memdev *cxlmd, + enum cxl_event_log_type type, + enum cxl_event_type event_type, + const uuid_t *uuid, union cxl_event *evt) { if (event_type == CXL_CPER_EVENT_MEM_MODULE) { trace_cxl_memory_module(cxlmd, type, &evt->mem_module); @@ -880,18 +925,22 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd, if (cxlr) hpa = cxl_dpa_to_hpa(cxlr, cxlmd, dpa); - if (event_type == CXL_CPER_EVENT_GEN_MEDIA) + if (event_type == CXL_CPER_EVENT_GEN_MEDIA) { trace_cxl_general_media(cxlmd, type, cxlr, hpa, &evt->gen_media); - else if (event_type == CXL_CPER_EVENT_DRAM) + cxl_event_handle_general_media(cxlmd, type, hpa, + &evt->gen_media); + } else if (event_type == CXL_CPER_EVENT_DRAM) { trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->dram); + cxl_event_handle_dram(cxlmd, type, hpa, &evt->dram); + } } } -EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, CXL); +EXPORT_SYMBOL_NS_GPL(cxl_event_handle_record, CXL); -static void __cxl_event_trace_record(const struct cxl_memdev *cxlmd, - enum cxl_event_log_type type, - struct cxl_event_record_raw *record) +static void __cxl_event_handle_record(struct cxl_memdev *cxlmd, + enum cxl_event_log_type type, + struct cxl_event_record_raw *record) { enum cxl_event_type ev_type = CXL_CPER_EVENT_GENERIC; const uuid_t *uuid = &record->id; @@ -903,7 +952,7 @@ static void __cxl_event_trace_record(const struct cxl_memdev *cxlmd, else if (uuid_equal(uuid, &CXL_EVENT_MEM_MODULE_UUID)) ev_type = CXL_CPER_EVENT_MEM_MODULE; - cxl_event_trace_record(cxlmd, type, ev_type, uuid, &record->event); + cxl_event_handle_record(cxlmd, type, ev_type, uuid, &record->event); } static int cxl_clear_event_record(struct cxl_memdev_state *mds, @@ -1012,8 +1061,8 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds, break; for (i = 0; i < nr_rec; i++) - __cxl_event_trace_record(cxlmd, type, - &payload->records[i]); + __cxl_event_handle_record(cxlmd, type, + &payload->records[i]); if (payload->flags & CXL_GET_EVENT_FLAG_OVERFLOW) trace_cxl_overflow(cxlmd, type, payload); diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index afb53d058d62..5c4810dcbdeb 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -826,10 +826,10 @@ void set_exclusive_cxl_commands(struct cxl_memdev_state *mds, void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds, unsigned long *cmds); void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status); -void cxl_event_trace_record(const struct cxl_memdev *cxlmd, - enum cxl_event_log_type type, - enum cxl_event_type event_type, - const uuid_t *uuid, union cxl_event *evt); +void cxl_event_handle_record(struct cxl_memdev *cxlmd, + enum cxl_event_log_type type, + enum cxl_event_type event_type, + const uuid_t *uuid, union cxl_event *evt); int cxl_set_timestamp(struct cxl_memdev_state *mds); int cxl_poison_state_init(struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 4be35dc22202..6e65ca89f666 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -1029,8 +1029,8 @@ static void cxl_handle_cper_event(enum cxl_event_type ev_type, hdr_flags = get_unaligned_le24(rec->event.generic.hdr.flags); log_type = FIELD_GET(CXL_EVENT_HDR_FLAGS_REC_SEVERITY, hdr_flags); - cxl_event_trace_record(cxlds->cxlmd, log_type, ev_type, - &uuid_null, &rec->event); + cxl_event_handle_record(cxlds->cxlmd, log_type, ev_type, + &uuid_null, &rec->event); } static void cxl_cper_work_fn(struct work_struct *work) diff --git a/include/linux/cxl-event.h b/include/linux/cxl-event.h index 0bea1afbd747..be4342a2b597 100644 --- a/include/linux/cxl-event.h +++ b/include/linux/cxl-event.h @@ -7,6 +7,20 @@ #include #include +/* + * Event transaction type + * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43 + */ +enum cxl_event_transaction_type { + CXL_EVENT_TRANSACTION_UNKNOWN = 0X00, + CXL_EVENT_TRANSACTION_READ, + CXL_EVENT_TRANSACTION_WRITE, + CXL_EVENT_TRANSACTION_SCAN_MEDIA, + CXL_EVENT_TRANSACTION_INJECT_POISON, + CXL_EVENT_TRANSACTION_MEDIA_SCRUB, + CXL_EVENT_TRANSACTION_MEDIA_MANAGEMENT, +}; + /* * Common Event Record Format * CXL rev 3.0 section 8.2.9.2.1; Table 8-42 @@ -26,7 +40,7 @@ struct cxl_event_media_hdr { __le64 phys_addr; u8 descriptor; u8 type; - u8 transaction_type; + u8 transaction_type; /* enum cxl_event_transaction_type */ /* * The meaning of Validity Flags from bit 2 is * different across DRAM and General Media records From patchwork Thu Aug 8 15:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang Ruan X-Patchwork-Id: 13757854 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2196C52D7B for ; Thu, 8 Aug 2024 15:13:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 493656B00EC; Thu, 8 Aug 2024 11:13:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F6636B00EE; Thu, 8 Aug 2024 11:13:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15EE06B00ED; Thu, 8 Aug 2024 11:13:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E1EA16B00EB for ; Thu, 8 Aug 2024 11:13:40 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6381281321 for ; Thu, 8 Aug 2024 15:13:40 +0000 (UTC) X-FDA: 82429422600.13.9EF29E7 Received: from esa10.hc1455-7.c3s2.iphmx.com (esa10.hc1455-7.c3s2.iphmx.com [139.138.36.225]) by imf09.hostedemail.com (Postfix) with ESMTP id D0637140017 for ; Thu, 8 Aug 2024 15:13:37 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=fj2 header.b=MFAdByq1; spf=pass (imf09.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 139.138.36.225 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com; dmarc=pass (policy=reject) header.from=fujitsu.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723129931; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v14/iHD72wpMklXcfm9tv3/7i6uAtVHzhlpwqpzLSD4=; b=et4pw9H/3p2ZiGhYYEeQVOej/Ne6JrMCIGKf+6VKMMcco0N6BHSqCYdQ1OzHLZ0t0SAvz0 Kzatm+htkFMgj9pZ0gdDCNzaAatx3NA24uKyg0m1KmvEiHQdAxbobpy+BqfegDcaKDiOur 7ItVSZc7M+WW8V4+/DNKcwRg3PglvQc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=fj2 header.b=MFAdByq1; spf=pass (imf09.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 139.138.36.225 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com; dmarc=pass (policy=reject) header.from=fujitsu.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723129931; a=rsa-sha256; cv=none; b=wL8LznsD3VUT/owZ/x+jLl7TfXaN9cR7t60iG6i5hgPSl8ipKD8ad2pLA7V5LVbQRp9oCF CIzd1IfnMXAp0jBE95pn86dMleKzoA0EcQa9e3FLDGvfRRi3LzehXN7GIMrsCLNzpq+YN7 +Kh/gCbUTwZZYSXNLIvU8VzTjY805jE= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1723130017; x=1754666017; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V+txiutig01/lSTX5GU2xXQ/Ecok4xMPvtbSdLTFmbo=; b=MFAdByq1WsLEYk0IQWd1pC5ab3SF6zGCCi6M2aftghyMBfgo4GNdMyJN eWkl1cJuHRYhOQkEyFdJQC3n6VjjF2d/CTNK/fycVIOpe1H9ueotjL1xi YP6a+XulnGghUD+2x1E7K+BTuDxWhGGMXa6GG6TQMWUJ2t3VuFGCAH7da GaFvZwOEJQwLL3k22RucXoQLs5pm+YMC6AgGM53j9RSlUNGUY5tDfj2Sk EI3aB9JPwBDHl4mnK8JTdi52eNHQcnEWYQsBof5S4pg+Z7ukwxcvcHX06 0hNwZsHqJCnB5xn0n04UJ/AF+Ci0gGHGMcClzeYdbaZHWTKe1jebCDAW5 w==; X-CSE-ConnectionGUID: HJ5MG+D3QXOlZ4wfsmmgqg== X-CSE-MsgGUID: HhW2HzuST0OSp8FBAU8CpA== X-IronPort-AV: E=McAfee;i="6700,10204,11158"; a="157585582" X-IronPort-AV: E=Sophos;i="6.09,273,1716217200"; d="scan'208";a="157585582" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa10.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 00:13:35 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 8327BC68E1 for ; Fri, 9 Aug 2024 00:13:33 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id BA9CFD5115 for ; Fri, 9 Aug 2024 00:13:32 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 2C7DA229360 for ; Fri, 9 Aug 2024 00:13:32 +0900 (JST) Received: from irides.g08.fujitsu.local (unknown [10.167.226.114]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 4D8B81A000A; Thu, 8 Aug 2024 23:13:31 +0800 (CST) From: Shiyang Ruan To: qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, linux-edac@vger.kernel.org, linux-mm@kvack.org, dan.j.williams@intel.com, vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com, alison.schofield@intel.com Cc: bp@alien8.de, dave.jiang@intel.com, dave@stgolabs.net, ira.weiny@intel.com, james.morse@arm.com, linmiaohe@huawei.com, mchehab@kernel.org, nao.horiguchi@gmail.com, rric@kernel.org, tony.luck@intel.com, ruansy.fnst@fujitsu.com Subject: [PATCH v4 2/2] cxl: avoid duplicated report from MCE & device Date: Thu, 8 Aug 2024 23:13:28 +0800 Message-Id: <20240808151328.707869-3-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808151328.707869-1-ruansy.fnst@fujitsu.com> References: <20240808151328.707869-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28584.000 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28584.000 X-TMASE-Result: 10--16.139300-10.000000 X-TMASE-MatchedRID: mBR/8PU27l8ZHQl0dvECsazGfgakLdjaKQNhMboqZlpqrsOvUFEKy3kY O/9k4Xg2bn+bq+W8j6XQJxNDXN5QxO4rOj+PdZuMVnzlQiaE21qxXA8wqNmbVrwYtb0g7Ywtu0m nSBAOWht+3E64qYVhyfoS5B31PW6f3tF9vYxzQ43wgrvJFY9E0Vvh1cEykiSGLX3qyf3ewG+qbv 7m/AcFJSbOYzaQt2Phra3G1NjT5m2njNSDi/vkV02xVQmDwU6mCZa9cSpBObnAuQ0xDMaXkH4qt YI9sRE/4K9FmervsqWylFSPywhifTBF72xzhJLNyRfzRkrgkUHzWEMQjooUzbs3Yh2IOCYz/svd Vly7w9ldRSgb+5TWboftADTYJ316uybvDkIalGDHyCtnYFmFhoIw3bnTjwR6icvz9DxarMGk86u MB98iNvBn25uFP/vzYcMGA+vBhspccQ8eam5EfRRFJJyf5BJe3QfwsVk0UbslCGssfkpInQ== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D0637140017 X-Stat-Signature: 6fr9f7wo19qd5qw5hrs3nyw9885impj8 X-Rspam-User: X-HE-Tag: 1723130017-831026 X-HE-Meta: U2FsdGVkX1+sAc6nOq2QcpMcURycUcuEsLqtYUhzeE/LN3Ue5NIeGg2DHOk9AtlP0vwKOvVwjAG+cm0gXs9Z7xWsrUGTG2l7b/yqM3KUxi+BLP9+05sM8CjYAiUnrR4aLUFrVU2Dhm8WsDBNkPp6oKROVH85zgIX8LklqFVEIWIeUdqLWqiWanKU0Ei5Qb2bDVJznRuLagZW4jW8QloD51W4+ka6fn08+HyZ1rsJxnepAUldx9Eggh38vzBWnhs1g9cX57qF5DM1Vl9W3MKqdOzseVk6rIiPzvskyAOMfqeOrlOvLFf+zFuAYXBx6XqFTrqc6g590TpnpNCd3bVzEO36Wo7ghNeaRT+vTPr/R2BRQBXvdzui5+Gwzty/mNmI6ENWbZqcRnFiF2E+BDw0amCIpu0RKZ7C8Hpv5DShGL1bdERbVp0HraWRirZNKtF+ormuTrAg3OTGCIjpl3zn6foOQvpVNCNWIEVFlV0qThb2XInVuKIHfOZu4bzJ4efMG+S/6CEB0uEzLT1AKbvLttqSZvwJJ3n9gdUyufSWmY2EAvGoHEQiTud183jWf0zz2WiiClKkWZa0/isM2QQa/egse9bhYbkVPcrSbXTazRXmfa4qiLxh1RZxgfuAgfSdr8Kxrc5UCxAy/SCVAT9byA9qJOcdqN5U7BH2sCshHpdb7l3RqSi20xefh/ZubtzrIvHUM7RaqKPC5jz6PhI/FG6g8dapVzuCy6NRJEoOdsgwsd9s8Q068a+edGRcV+Fi+CHnYmMU06l67DedAo172J10tgOB9jyD40BxUfvTZ7KYJpa+v78JWqH3NDsllb+yzitUZZk2U0RtPC8x6JRJXpmNK4dL2epcpT4Q/qUQOHkyWHEhQVNiqPkQB+mNPgC0r4Z0WdkwGr4aG6NlRPzbyoupXqjrJ4GB3YZoWXmCPQge4QgZz/3sAEJb2LCdi93O0XmEkEMOY6NA5qpzqOJ dweBZmlU wokrUfURFGQZBJz/qeVyYP/tBOsbucQr3y5cvgM76NV0NJbxqYmZPATRjke0aV/NTsPL4NxZFZSznLp7o8FNNXV5oqPH3gXvqdyTRPxg4++Rixh0IyoRuKlqzuKkvpWi3xf2Yu6nm490Y24PCFoIP1/nz10O/ExlgJikE/Yd0D7jWCfYflGf9T7KyivukhgiBSK9f/zZ9ynz5YChWFTg1v9deSbJ3Jo9JdLj4mx2EqL2gvlj+ttrn9B21+45CbsUvM+vKh9xMuqxE1gXrxc6W6WJ+v/uOkuTqjKkpFUJVdOlj0tF8IQvZmL8Xbg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since CXL device is a memory device, while CPU is consuming a poison page of CXL device, it always triggers a MCE (via interrupt #18) and calls memory_failure() to handle POISON page, no matter which-First path is configured. CXL device could also find and report the POISON, kernel now not only traces but also calls memory_failure() to handle it, which is marked as "NEW" in the figure blow. ``` 1. MCE (interrupt #18, while CPU consuming POISON) -> do_machine_check() -> mce_log() -> notify chain (x86_mce_decoder_chain) -> memory_failure() <---------------------------- EXISTS 2.a FW-First (optional, CXL device proactively find&report) -> CXL device -> Firmware -> OS: ACPI->APEI->GHES->CPER -> CXL driver -> trace \-> memory_failure() ^----- NEW 2.b OS-First (optional, CXL device proactively find&report) -> CXL device -> MSI -> OS: CXL driver -> trace \-> memory_failure() ^------------------------------- NEW ``` But in this way, the memory_failure() could be called twice or even at same time, as is shown in the figure above: (1.) and (2.a or 2.b), before the POISON page is cleared. memory_failure() has it own mutex lock so it actually won't be called at same time and the later call could be avoided because HWPoison bit has been set. However, assume such a scenario, "CXL device reports POISON error" triggers 1st call, user see it from log and want to clear the poison by executing `cxl clear-poison` command, and at the same time, a process tries to access this POISON page, which triggers MCE (it's the 2nd call). Since there is no lock between the 2nd call with clearing poison operation, race condition may happen, which may cause HWPoison bit of the page in an unknown state. Thus, we have to avoid the 2nd call. This patch[2] introduces a new notifier_block into `x86_mce_decoder_chain` and a POISON cache list, to stop the 2nd call of memory_failure(). It checks whether the current poison page has been reported (if yes, stop the notifier chain, don't call the following memory_failure() to report again). Signed-off-by: Shiyang Ruan --- arch/x86/include/asm/mce.h | 1 + drivers/cxl/core/mbox.c | 115 +++++++++++++++++++++++++++++++++++++ drivers/cxl/core/memdev.c | 6 +- drivers/cxl/cxlmem.h | 3 + 4 files changed, 124 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h index 3ad29b128943..5da45e870858 100644 --- a/arch/x86/include/asm/mce.h +++ b/arch/x86/include/asm/mce.h @@ -182,6 +182,7 @@ enum mce_notifier_prios { MCE_PRIO_NFIT, MCE_PRIO_EXTLOG, MCE_PRIO_UC, + MCE_PRIO_CXL, MCE_PRIO_EARLY, MCE_PRIO_CEC, MCE_PRIO_HIGHEST = MCE_PRIO_CEC diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 0cb6ef2e6600..b21700428c35 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -925,6 +927,9 @@ void cxl_event_handle_record(struct cxl_memdev *cxlmd, if (cxlr) hpa = cxl_dpa_to_hpa(cxlr, cxlmd, dpa); + if (hpa != ULLONG_MAX && cxl_mce_recorded(hpa)) + return; + if (event_type == CXL_CPER_EVENT_GEN_MEDIA) { trace_cxl_general_media(cxlmd, type, cxlr, hpa, &evt->gen_media); @@ -1457,6 +1462,112 @@ int cxl_poison_state_init(struct cxl_memdev_state *mds) } EXPORT_SYMBOL_NS_GPL(cxl_poison_state_init, CXL); +DEFINE_XARRAY(cxl_mce_records); + +bool cxl_mce_recorded(u64 hpa) +{ + XA_STATE(xas, &cxl_mce_records, hpa); + void *entry; + + xas_lock_irq(&xas); + entry = xas_load(&xas); + if (entry) { + xas_unlock_irq(&xas); + return true; + } + entry = xa_mk_value(hpa); + xas_store(&xas, entry); + xas_unlock_irq(&xas); + + return false; +} +EXPORT_SYMBOL_NS_GPL(cxl_mce_recorded, CXL); + +void cxl_mce_clear(u64 hpa) +{ + XA_STATE(xas, &cxl_mce_records, hpa); + void *entry; + + xas_lock_irq(&xas); + entry = xas_load(&xas); + if (entry) { + xas_store(&xas, NULL); + } + xas_unlock_irq(&xas); +} +EXPORT_SYMBOL_NS_GPL(cxl_mce_clear, CXL); + +struct cxl_contains_hpa_context { + bool contains; + u64 hpa; +}; + +static int __cxl_contains_hpa(struct device *dev, void *arg) +{ + struct cxl_contains_hpa_context *ctx = arg; + struct cxl_endpoint_decoder *cxled; + struct range *range; + u64 hpa = ctx->hpa; + + if (!is_endpoint_decoder(dev)) + return 0; + + cxled = to_cxl_endpoint_decoder(dev); + range = &cxled->cxld.hpa_range; + + if (range->start <= hpa && hpa <= range->end) { + ctx->contains = true; + return 1; + } + + return 0; +} + +static bool cxl_contains_hpa(const struct cxl_memdev *cxlmd, u64 hpa) +{ + struct cxl_contains_hpa_context ctx = { + .contains = false, + .hpa = hpa, + }; + struct cxl_port *port; + + port = cxlmd->endpoint; + guard(rwsem_write)(&cxl_region_rwsem); + if (port && cxl_num_decoders_committed(port)) + device_for_each_child(&port->dev, &ctx, __cxl_contains_hpa); + + return ctx.contains; +} + +static int cxl_handle_mce(struct notifier_block *nb, unsigned long val, + void *data) +{ + struct mce *mce = (struct mce *)data; + struct cxl_memdev_state *mds = container_of(nb, struct cxl_memdev_state, + mce_notifier); + u64 hpa; + + if (!mce || !mce_usable_address(mce)) + return NOTIFY_DONE; + + hpa = mce->addr & MCI_ADDR_PHYSADDR; + + /* Check if the PFN is located on this CXL device */ + if (!pfn_valid(hpa >> PAGE_SHIFT) && + !cxl_contains_hpa(mds->cxlds.cxlmd, hpa)) + return NOTIFY_DONE; + + /* + * Search PFN in the cxl_mce_records, if already exists, don't continue + * to do memory_failure() to avoid a poison address being reported + * more than once. + */ + if (cxl_mce_recorded(hpa)) + return NOTIFY_STOP; + else + return NOTIFY_OK; +} + struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev) { struct cxl_memdev_state *mds; @@ -1476,6 +1587,10 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev) mds->ram_perf.qos_class = CXL_QOS_CLASS_INVALID; mds->pmem_perf.qos_class = CXL_QOS_CLASS_INVALID; + mds->mce_notifier.notifier_call = cxl_handle_mce; + mds->mce_notifier.priority = MCE_PRIO_CXL; + mce_register_decode_chain(&mds->mce_notifier); + return mds; } EXPORT_SYMBOL_NS_GPL(cxl_memdev_state_create, CXL); diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 0277726afd04..9d4ed4dc4d51 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -376,10 +376,14 @@ int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa) goto out; cxlr = cxl_dpa_to_region(cxlmd, dpa); - if (cxlr) + if (cxlr) { + u64 hpa = cxl_dpa_to_hpa(cxlr, cxlmd, dpa); + + cxl_mce_clear(hpa); dev_warn_once(mds->cxlds.dev, "poison clear dpa:%#llx region: %s\n", dpa, dev_name(&cxlr->dev)); + } record = (struct cxl_poison_record) { .address = cpu_to_le64(dpa), diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 5c4810dcbdeb..d2d906c26755 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -502,6 +502,7 @@ struct cxl_memdev_state { struct cxl_fw_state fw; struct rcuwait mbox_wait; + struct notifier_block mce_notifier; int (*mbox_send)(struct cxl_memdev_state *mds, struct cxl_mbox_cmd *cmd); }; @@ -837,6 +838,8 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, int cxl_trigger_poison_list(struct cxl_memdev *cxlmd); int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa); int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa); +bool cxl_mce_recorded(u64 pfn); +void cxl_mce_clear(u64 pfn); #ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc(void);