From patchwork Tue Feb 6 22:15:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 197664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1854548dyb; Tue, 6 Feb 2024 14:16:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnh3RqTAbCWChXO6pEiWTHYOICtyY/yHgCIPgsEBucvRhJHDnSq5OWt05dlmK334DxXliJ X-Received: by 2002:aa7:d94a:0:b0:55f:d808:328c with SMTP id l10-20020aa7d94a000000b0055fd808328cmr2769768eds.31.1707257766668; Tue, 06 Feb 2024 14:16:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707257766; cv=pass; d=google.com; s=arc-20160816; b=Aw7Hdacf/YHGODNj5P+ZdCHnSZ9ob2umySSZ21phJGtmt2vCO6RPy05Xuh7/WW9wki 1rwjs+SOSW1/vva0zzM+FdZby7HztThdJEooB8MU2sSO3xJSjiJrTgUFgco718dsORkw JGcRMAS+Ok1zMB46V43G6hVxrlsO1eg+kkcyKH4fnD/wVQdNHDyd8qS2IVz18JbmEdqF iFeHZOkurnJ9pIOE8AD7visM7Domx//CIZY03UBs1DUP9axfDBXhlazB9cNTZIQ7Rx8Q YkWNwz3QZ/XSBRBhHWFJYVHq/f+9E2Oo73yYQl5Y+xQzuODU/DvrrVbXU5vuQ+mYdPIz gQTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=EMjfH+Eq79J0RJ5VaBLcUdFK/Snrtxa9ZNvVUrpcNBQ=; fh=6LXeRhvQOjoOtGhqnNAijOp08ToT/LIS7TUhi50aWGI=; b=tKp07FBwP/s7pZ2nuM/mjkvizNYrd8VGlLxgGtGIO842JIFwJdJ8GwZBNOG3u7XvV/ hvblSq43YS5ZDjhA+Ee/BrUZTYw1jHBsmaovWZAduQpND4Q/+7nMy5U7ga0VSf6fwW4D 7DnDTmFp/jzTorIzgqalEvs0ETaHzXi27rtb/ZsAuPf1qhXcvGM4IeqoHWFYfDJy74oR nXdDUUQ9t2aAcrnXkFmmAyojxxwD8KxSyXmOzC0NWoehd7TZH5ZaENfY76kxmmHu+Yn/ KNGG7vadgj9bwaswYBOHwrXRtJl1MHjHZaYU6bxC6moByiMQGiXeCpSMw4Vo7vyUSXl6 Z4Bg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cKsvKrw9; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-55682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55682-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUdHcU+K0ir4SpY6+in0u0NGheRX6ct7O10ifi2LGaeorFSLqspKFo+MHpdO4D2yf6OnSz0wOFM79WA0ynmvIanVGVm8Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c6-20020aa7c746000000b0055f60f9d92esi1659775eds.476.2024.02.06.14.16.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 14:16:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cKsvKrw9; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-55682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55682-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 48FBF1F253E1 for ; Tue, 6 Feb 2024 22:16:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99AFD1C298; Tue, 6 Feb 2024 22:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cKsvKrw9" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEAF61BF37; Tue, 6 Feb 2024 22:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707257745; cv=none; b=XyvhN3DHfg+5mEwVlGrQ6EkiX1bxCWUhyLyujykhvu8DiQBZNS5C/12WG4c2yVh+gq0QsoKMREsEYTUi+jS628R0zxcp56DsPurNKx5Q+eskyaaQKKV6ahwV8Dqs8EJXab2AgFqOn71IU2J0hFWhJ35QCEoVFWX/wWtODU0nzF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707257745; c=relaxed/simple; bh=pNOvyJzuQeqsakt9aKOjJ4ZIQm/Pu1dcPBieRGr2pfY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=JquZTGxddezq5+6uxPbrYdo8OlWyt9cqXkLQTYIhjlQJXkINjo3veAjMfPBM10qazqUagDlY2tizNNyh7r3VvLSiy/S8YsQNCh7IKc105aXzPaPJzUQCT1XaONoigZWa0iXQRHNIW4JhSvLXMPcum1b4fd+DXsY0vhY0fm2/WwM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cKsvKrw9; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707257744; x=1738793744; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=pNOvyJzuQeqsakt9aKOjJ4ZIQm/Pu1dcPBieRGr2pfY=; b=cKsvKrw9A0ya1sjn9KhwKu0A/Sabb5be5vBwQAB2K21K/JJ62pHLsIZT kfwtz0A7rngV7EbUqYnG+rKfla68STZiCM79Brs/FFHzoUyJFS9L1FZkE HV/VpdavsuCoEB4A50dsni6bK6//RP+e89d1OGEWek/G5sYZPn9GaU8e8 Bmw56bSKiShgGzJZbCxWskZlTPDld7BiZDttK3h5XHLPGJRitiiRyY1he HuznZ95MTVcl7sKNrLpActCZWPRLPOaZUg7FtLmp8Mw5PqcRFoJz9fSs3 ES3jTGMIO7JCl7UiE8Al3of9m99VvzVwgdS3Gcph7CAdqA9ZbPiFvX+M+ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10976"; a="752032" X-IronPort-AV: E=Sophos;i="6.05,248,1701158400"; d="scan'208";a="752032" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 14:15:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,248,1701158400"; d="scan'208";a="31961892" Received: from iweiny-desk3.amr.corp.intel.com (HELO localhost) ([10.212.121.225]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 14:15:41 -0800 From: Ira Weiny Date: Tue, 06 Feb 2024 14:15:32 -0800 Subject: [PATCH v2] acpi/ghes: Prevent sleeping with spinlock held Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240206-cxl-cper-smatch-v2-1-84ed07563c31@intel.com> X-B4-Tracking: v=1; b=H4sIAIOvwmUC/2WNzQrCMBCEX6Xs2ZVkjbT11PeQHmLc2oX+kYRSK Xl3Y8GTMJdvYL7ZIbAXDnArdvC8SpB5ykCnAlxvpxejPDMDKTKKlEa3DegW9hhGG12PFT001aa uciCvFs+dbIfx3mbuJcTZv4+DVX/bn4v+XKtGjaU1Wl1c2V2tamSKPJzdPEKbUvoA/Vifua4AA AA= To: "Rafael J. Wysocki" , Dan Williams , Jonathan Cameron , Smita Koralahalli Cc: linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Carpenter , Ira Weiny X-Mailer: b4 0.13-dev-2d940 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707257741; l=3430; i=ira.weiny@intel.com; s=20221222; h=from:subject:message-id; bh=pNOvyJzuQeqsakt9aKOjJ4ZIQm/Pu1dcPBieRGr2pfY=; b=zulniw+JGONEhhR3l9xf9ERy4LztcTPp0L7Czo1Q81GvydQm3+3uD4h0r22IytdFlLkj27dIH 98npAckYuUsAiANciy2AeJqOMBeToAPJ1iFaRScYD0fwtg/rclcUvXl X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=brwqReAJklzu/xZ9FpSsMPSQ/qkSalbg6scP3w809Ec= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790189519870875323 X-GMAIL-MSGID: 1790189519870875323 Smatch caught that cxl_cper_post_event() is called with a spinlock held or preemption disabled.[1] The callback takes the device lock to perform address translation and therefore might sleep. The record data is released back to BIOS in ghes_clear_estatus() which requires it to be copied for use in the workqueue. Copy the record to a lockless list and schedule a work item to process the record outside of atomic context. [1] https://lore.kernel.org/all/b963c490-2c13-4b79-bbe7-34c6568423c7@moroto.mountain/ Reported-by: Dan Carpenter Signed-off-by: Ira Weiny --- Changes in v2: - djbw: device_lock() sleeps so we need to call the callback in process context - iweiny: create work queue to handle processing the callback - Link to v1: https://lore.kernel.org/r/20240202-cxl-cper-smatch-v1-1-7a4103c7f5a0@intel.com --- drivers/acpi/apei/ghes.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) --- base-commit: 99bd3cb0d12e85d5114425353552121ec8f93adc change-id: 20240201-cxl-cper-smatch-82b129498498 Best regards, diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 7b7c605166e0..aa41e9128118 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -679,6 +679,12 @@ static void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata, */ static DECLARE_RWSEM(cxl_cper_rw_sem); static cxl_cper_callback cper_callback; +static LLIST_HEAD(cxl_cper_rec_list); +struct cxl_cper_work_item { + struct llist_node node; + enum cxl_event_type event_type; + struct cxl_cper_event_rec rec; +}; /* CXL Event record UUIDs are formatted as GUIDs and reported in section type */ @@ -706,9 +712,34 @@ static cxl_cper_callback cper_callback; GUID_INIT(0xfe927475, 0xdd59, 0x4339, \ 0xa5, 0x86, 0x79, 0xba, 0xb1, 0x13, 0xb7, 0x74) +static void cxl_cper_work_fn(struct work_struct *work) +{ + struct llist_node *entries, *cur, *n; + struct cxl_cper_work_item *wi; + + guard(rwsem_read)(&cxl_cper_rw_sem); + + entries = llist_del_all(&cxl_cper_rec_list); + if (!entries) + return; + + /* Process oldest to newest */ + entries = llist_reverse_order(entries); + llist_for_each_safe(cur, n, entries) { + wi = llist_entry(cur, struct cxl_cper_work_item, node); + + if (cper_callback) + cper_callback(wi->event_type, &wi->rec); + kfree(wi); + } +} +static DECLARE_WORK(cxl_cper_work, cxl_cper_work_fn); + static void cxl_cper_post_event(enum cxl_event_type event_type, struct cxl_cper_event_rec *rec) { + struct cxl_cper_work_item *wi; + if (rec->hdr.length <= sizeof(rec->hdr) || rec->hdr.length > sizeof(*rec)) { pr_err(FW_WARN "CXL CPER Invalid section length (%u)\n", @@ -721,9 +752,16 @@ static void cxl_cper_post_event(enum cxl_event_type event_type, return; } - guard(rwsem_read)(&cxl_cper_rw_sem); - if (cper_callback) - cper_callback(event_type, rec); + wi = kmalloc(sizeof(*wi), GFP_ATOMIC); + if (!wi) { + pr_err(FW_WARN "CXL CPER failed to allocate work item\n"); + return; + } + + wi->event_type = event_type; + memcpy(&wi->rec, rec, sizeof(wi->rec)); + llist_add(&wi->node, &cxl_cper_rec_list); + schedule_work(&cxl_cper_work); } int cxl_cper_register_callback(cxl_cper_callback callback)