Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1015074rdb; Fri, 2 Feb 2024 10:39:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpl1K9d1dX/alIgEzU6PBx/9cX1YC8zvUzFHjfwTVRb8/oUrttGoZIMa40QK0YeNOovAzz X-Received: by 2002:a05:6a20:5141:b0:19e:2aab:f727 with SMTP id b1-20020a056a20514100b0019e2aabf727mr5318340pzc.57.1706899187207; Fri, 02 Feb 2024 10:39:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706899187; cv=pass; d=google.com; s=arc-20160816; b=vwUaIfdNIDBAtRTvk+8yqoSOc5aVpv+4SoI/T7v27HcmLxzizLIw874gMwkjJ6+44O T1AifMw+IxEXzPj4DeOzCimQbYYljgEnlONkMBY8d08OT++XJQWm6Ko1V7wW7WHT8H7h HIM6xD1rBHTpGLNB8pQc5iZ0mHzrUVlfeWJ1BiDPjOpz2ONiTksnno/lkt5VMNMubb2S FnsRDvFs5TTUtlBTqDOvkar3xE6rZzZuDSwsvCo6XVjIR9PwD50XpWC5tYqD9JYNynAk xcVIZCw66a34i5WUnhP/C8F8uXcXhUd/9XlZrC7+oQ3Hz3S0XFk7sTo6Py48IMV1Cbq9 +JIg== 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=mKY/vb7ne4r20oLRD4g/tL2tYRvTDOGOXvqIPkhpwSw=; fh=3I13c1GR4Xh0iCl8OtzzWHc7I3OG8GDO01suyV1NIgA=; b=CoW1A7cc5Ck8ipHuH3Q1zVawUS9N2QwgPj2K8FbSERxFd6DzVbgjy6oJ4oQAoFVCXK PkH0WQ+bXlnX00oAeZ0LZNwR9Bsua27lSKbI/QlmC02fL7n3QEAEulvsVM2zbCRJr5Ys VOhOlTlW8SxeI4Clsj7HU150FBz7Wi7QDMVofjTw2kUCSP+55qM4t4XcplV1CVlttB0B 2oPnX9HBr1ZWHZB+ZqEsZhTI3/aBQLOdpCsPMdxNerFfXSyBYOLPvByj7OFv18NlZYCA BZ3xzje02qeQ1GWR3F3uNuMD7jaTQhaQ3K6HzkJm/x79HSwAtPod71LqALtJ5aKMBXrB Fk0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GKy92vuR; 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-50304-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50304-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCXi5971cWi+UKONrEgGMd/nDLWu9+pILF4iYoZGAs9OYEjuljA470uDVKgXJBL2tvBLZkFr0zK4c4pGnhFLkncn3baBqkNInwDVU/RxPw== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id r6-20020a056a00216600b006d9aa48c4e7si1873712pff.110.2024.02.02.10.39.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 10:39:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50304-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GKy92vuR; 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-50304-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50304-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9DC60B276D8 for ; Fri, 2 Feb 2024 18:16:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D706114D432; Fri, 2 Feb 2024 18:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GKy92vuR" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 72D9E14AD10; Fri, 2 Feb 2024 18:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706897782; cv=none; b=Fzh0HrUKLMDzbRcPkSv3HY+JC6baF5GjgD0HZBlpl3KJfTdki+BbcGpD3QqTwZfENJtzdiIY1PZqqIT+FbKrc9+5O67a8SL3svCZ8ldX42HQP/Rdek88J/Wca5lbQBtZ6fPTj+FB16z7cO5ZW2A8NOcFc/zz5mD+5Eonmkhj8nE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706897782; c=relaxed/simple; bh=nzaDdjcfPayXh4qIG8StvPK20F+fr27KrMWe3tHTVYc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=djbz7W3F/M8RMCIZ9uJDfIsmTcLAjwO9ZnMEfeZU86tW4A+ZDIVKjpyXVKlLCJd4rZ5rnHdBef1uczFOWCZuO7usnR3g6QnIhjWAHk0BLmozogvxiwtcZaMflvc//qL4h4Ab+rg+ex8DVDv6bLKhfoHzqLDZBBn1SzZ9dPmqg3M= 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=GKy92vuR; arc=none smtp.client-ip=198.175.65.10 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=1706897781; x=1738433781; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=nzaDdjcfPayXh4qIG8StvPK20F+fr27KrMWe3tHTVYc=; b=GKy92vuRH7cZgi04sr30nvhMdDkwfqD/JLB+Skq/YCLNKid/Q/9XPAYv yBEdKp3tfqiqv7hFHYlgXnFhuACkTB4tby40PTR0u3vtHgs5dpV7WmoBp dhLDypqJcfRMJTzMNVYnhZ202LaFl7+DwSx4ayQcqSfUgIUhd3l9RiOg2 to84bIlMlGcT6wmjiotP2ufHWOQT+PQJ/bcm4URTDNDk9LdbX39aghq70 cyPVLXbby0BMuTQO3DMmgRmTafLcozelgq9ODBN/Ss/KGDpSHmFYp2ZMt A1Xsil6ZZVN2PV+0gfXIJ9IrRGB30aUkI9bXby0MuSYOwZa9xFBoLUMmw Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17623706" X-IronPort-AV: E=Sophos;i="6.05,238,1701158400"; d="scan'208";a="17623706" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 10:16:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,238,1701158400"; d="scan'208";a="4747421" Received: from iweiny-desk3.amr.corp.intel.com (HELO localhost) ([10.213.160.232]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 10:16:19 -0800 From: Ira Weiny Date: Fri, 02 Feb 2024 10:16:19 -0800 Subject: [PATCH] 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240202-cxl-cper-smatch-v1-1-7a4103c7f5a0@intel.com> X-B4-Tracking: v=1; b=H4sIAHIxvWUC/x2MQQqAIBAAvyJ7bkEXD9VXooPZlgtlohFB9Pckm MscZh4onIUL9OqBzJcUOWIV0yjwwcWVUebqQJqsJm3Q3xv6xBnL7k4fsKXJUGe7tgK1SpkXuf/ jML7vBztUPm5hAAAA To: "Rafael J. Wysocki" , Dan Williams , Jonathan Cameron 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=1706897778; l=2362; i=ira.weiny@intel.com; s=20221222; h=from:subject:message-id; bh=nzaDdjcfPayXh4qIG8StvPK20F+fr27KrMWe3tHTVYc=; b=F9rjbrfKk6RcbUwsD27CBnFnQJvDp/y0gj0O2zXp9+uSl5dLtFILK6JSrVFraw2H71usgPOqa l9v/bIJngtgAECJAr/BuZYQebcbX3btEztGxiIW4oA1EpXYxT7ZCNeu X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=brwqReAJklzu/xZ9FpSsMPSQ/qkSalbg6scP3w809Ec= Smatch caught that cxl_cper_post_event() is called with a spinlock held or preemption disabled.[1] There is no need for the callback to sleep. Replace the RW semaphore with a RW lock. A static call was considered but ARM does not select HAVE_STATIC_CALL and in that case setting the function pointer uses a RW semaphore. [1] https://lore.kernel.org/all/b963c490-2c13-4b79-bbe7-34c6568423c7@moroto.mountain/ Reported-by: Dan Carpenter Signed-off-by: Ira Weiny --- drivers/acpi/apei/ghes.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 7b7c605166e0..bdc0ec2813a3 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -677,7 +678,7 @@ static void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata, /* * Only a single callback can be registered for CXL CPER events. */ -static DECLARE_RWSEM(cxl_cper_rw_sem); +static DEFINE_RWLOCK(cxl_callback_lock); static cxl_cper_callback cper_callback; /* CXL Event record UUIDs are formatted as GUIDs and reported in section type */ @@ -721,14 +722,14 @@ static void cxl_cper_post_event(enum cxl_event_type event_type, return; } - guard(rwsem_read)(&cxl_cper_rw_sem); + guard(read_lock_irqsave)(&cxl_callback_lock); if (cper_callback) cper_callback(event_type, rec); } int cxl_cper_register_callback(cxl_cper_callback callback) { - guard(rwsem_write)(&cxl_cper_rw_sem); + guard(write_lock_irq)(&cxl_callback_lock); if (cper_callback) return -EINVAL; cper_callback = callback; @@ -738,7 +739,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_cper_register_callback, CXL); int cxl_cper_unregister_callback(cxl_cper_callback callback) { - guard(rwsem_write)(&cxl_cper_rw_sem); + guard(write_lock_irq)(&cxl_callback_lock); if (callback != cper_callback) return -EINVAL; cper_callback = NULL; --- base-commit: 861c0981648f5b64c86fd028ee622096eb7af05a change-id: 20240201-cxl-cper-smatch-82b129498498 Best regards, -- Ira Weiny