From nobody Wed Jun 10 12:28:55 2026 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AF5637F001 for ; Mon, 20 Apr 2026 02:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776653788; cv=none; b=PoQQDu06cKw4UPmIcEzZcPTax0mnJ2C31ZFh1i0Qx2ePRNIvEnddr/flVkSBQGNanYXe87wGV9qWygY5Wtztc7D8UtHydm0TdcQNdm0HUkkBHOWeeaJI51mS6LgBPecCnke87NTRkweEslSFsAKvX+hgZdf94eusYn+Fi5caG54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776653788; c=relaxed/simple; bh=u4OAGjaTLHitOXmOMoh2P98LOLbxyvsz5/hPqsMZVkI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=o4W/v0cdpW1gH6cPFEA9ag3Pxfy67z8HHwb2V09U3kSgePH9mgJYnTYaWDcZIe4Pj3zoCRknusE87bqdtMNT5L1SzlZVgSPTC42gpqPx5bS9UvoQyY8Zp5qO3DSge+u6tK90LYy5g2tH4HRgPtl/757LNxyv7Hv1skxOBr0M9Eg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sung-woo.kim; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sung-woo.kim Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-79885f4a8ffso24010847b3.3 for ; Sun, 19 Apr 2026 19:56:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776653785; x=1777258585; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9+O44+JVKuk80yoA2AZ1Ss5dIsNhIz1HifmT4ZdqZZA=; b=A2lzw4yHBM6gup3wQTZdrfm2bGWuIXrhREk5dwPIRX6x3lj522bnzBKmkDefarCd1l IgwMPFa5P+IRFhQNOvy3BdxzpRZUpzYVJxqv/UrAAi2iL8qXC6CyQoypYSX5mZkklP8t aDgSOXwH2uT8T8ys4ZDENGiaDmLd2v6eKDlZtDy0okaL3/T29JZFheE8wb5nVFZVHLWu pxrTFQ5x/nHaghBql7OzY1WdTqRaJs6qlyP01AUFNehTfk3SiXapMux048hFabPucUtx ZNdvNjgLpwRxZ6cRHKQUMBp6oSefI9/kgB5mEAVjNhcQpsIf0EIkT0mImJhe2S/vJb0u xpLg== X-Forwarded-Encrypted: i=1; AFNElJ+O7pJf7NGPRqgFfgq9fhrOSlPUoHLLHVjuxEoGVKVKW5B+pfVDHUv53rdzCc+UNk9i2Rj6D51y8KPd+VY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx74JjZs81ZPIY9iTne3Hmxybo+PfVQjGcxwh8csQEUULwdiIi6 /k6kmAB9G+2EEdOvt4KGHOsfLnEW/iJIG4+5Y6sY6LGn8jaU4ZxmRlpo X-Gm-Gg: AeBDiesxCXGV9uzdMn730lSfJAMWJsU8b2SGJxRY/5FdoqnObK7ftRAgnm9tf2lju4m 1tltUDYw8sOiWcf7vUpom3EIN3bzEsh+Auw9iFgidTFMggPkqih84591OHse5Ywa7Cmu0XWrZhw zsK3aTMb2iVVTF5lqkUrHDFlIMgdCDElcLZNrZsaw1gxm5uCkPvALxxtc/jXX/6uSxh9nty8YZb eqmvq8ybYxNVWBWwlsxkqaJvqvlhvRzCWOXiL3Tt2BTbEYO+D3E/kmpaA0USGH1m1jDalbZ5EuH z+jyuUq05bCB15Id52wyvaAi6FmB8GKT6aoiOwfWXLZFRh//dktLlR+55r6I3o08l0z9rZ0UAvW jAWOK44NMQiQkKz6uNrglVrifgRjT60196WJ9YJXLNc3LZ9U7LU0QBTJHByeheqkHV9lMmuyWmJ yfumG2a0B5NrvRKFkQBWRi X-Received: by 2002:a05:690c:6e83:b0:7b8:f152:7526 with SMTP id 00721157ae682-7b9ecffb58fmr114883037b3.42.1776653785003; Sun, 19 Apr 2026 19:56:25 -0700 (PDT) Received: from tofu.. ([128.210.0.165]) by smtp.googlemail.com with ESMTPSA id 00721157ae682-7b9ee8be8e4sm38961957b3.14.2026.04.19.19.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2026 19:56:23 -0700 (PDT) From: Sungwoo Kim To: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Ben Widawsky Cc: Dave Tian , Sungwoo Kim , Jonathan Cameron , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] cxl/hdm: fix a warning in devm_remove_action() Date: Sun, 19 Apr 2026 22:55:47 -0400 Message-ID: <20260420025547.1704692-2-iam@sung-woo.kim> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the following race scenario, devm_remove_action() can be called before devm_add_action(), triggering a warning because there is no action to remove. To fix this, __cxl_dpa_reserve() performs devm_add_action(). This extends the critical section that embraces cxled->dpa_res =3D res and devm_add_action(), so cxl_dpa_free() cannot observe dpa_res without the devres action. Also, renamed __cxl_dpa_reserve() to __devm_cxl_dpa_reserve(). task 1: cxl_dpa_alloc() __cxl_dpa_alloc() guard(&cxl_rwsem.dpa) cxled->dpa_res =3D res; ...(1) devm_add_action() ...(4) task 2: cxl_dpa_free() guard(&cxl_rwsem.dpa) if (!cxled->dpa_res) ...(2) pass, due to (1) return 0; devm_cxl_dpa_release() devm_remove_action() ...(3) warning, no action is added yet Splat: WARNING: ./include/linux/device/devres.h:160 at devm_remove_action include/= linux/device/devres.h:160 [inline], CPU#0: syz.1.6464/25993 WARNING: ./include/linux/device/devres.h:160 at devm_cxl_dpa_release driver= s/cxl/core/hdm.c:290 [inline], CPU#0: syz.1.6464/25993 WARNING: ./include/linux/device/devres.h:160 at cxl_dpa_free+0x2a4/0x320 dr= ivers/cxl/core/hdm.c:572, CPU#0: syz.1.6464/25993 Fixes: cf880423b6a0 ("cxl/hdm: Add support for allocating DPA to an endpoin= t decoder") Fixes: 9c57cde0dcbd ("cxl/hdm: Enumerate allocated DPA") Signed-off-by: Sungwoo Kim --- V2: https://lore.kernel.org/linux-cxl/CAJNyHpL-fyDnEJv2bxKNjBAzxHZ9HmKTu72M= zcVhWiFrDRKzpw@mail.gmail.com/ V2->V3: - Fixed a potential deadlock in V2. - Renamed __cxl_dpa_reserve() to __devm_cxl_dpa_reserve(). drivers/cxl/core/hdm.c | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 0c80b76a5f9b..0492a878a065 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -336,7 +336,7 @@ static int request_skip(struct cxl_dev_state *cxlds, return -EBUSY; } =20 -static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled, +static int __devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled, resource_size_t base, resource_size_t len, resource_size_t skipped) { @@ -408,7 +408,19 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decod= er *cxled, =20 port->hdm_end++; get_device(&cxled->cxld.dev); - return 0; + + /* + * Perform devres registration while holding cxl_rwsem.dpa so + * cxl_dpa_free() cannot observe dpa_res without a matching devres + * action. + * Also, invoke the release action with the unlocked __cxl_dpa_release() + * since cxl_dpa_release() acquires the the cxl_rwsem.dpa. + */ + rc =3D devm_add_action(&port->dev, cxl_dpa_release, cxled); + if (rc) { + __cxl_dpa_release(cxled); + } + return rc; } =20 static int add_dpa_res(struct device *dev, struct resource *parent, @@ -499,16 +511,8 @@ int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *= cxled, resource_size_t base, resource_size_t len, resource_size_t skipped) { - struct cxl_port *port =3D cxled_to_port(cxled); - int rc; - - scoped_guard(rwsem_write, &cxl_rwsem.dpa) - rc =3D __cxl_dpa_reserve(cxled, base, len, skipped); - - if (rc) - return rc; - - return devm_add_action_or_reset(&port->dev, cxl_dpa_release, cxled); + guard(rwsem_write)(&cxl_rwsem.dpa); + return __devm_cxl_dpa_reserve(cxled, base, len, skipped); } EXPORT_SYMBOL_NS_GPL(devm_cxl_dpa_reserve, "CXL"); =20 @@ -606,7 +610,8 @@ static int __cxl_dpa_alloc(struct cxl_endpoint_decoder = *cxled, u64 size) struct resource *p, *last; int part; =20 - guard(rwsem_write)(&cxl_rwsem.dpa); + lockdep_assert_held_write(&cxl_rwsem.dpa); + if (cxled->cxld.region) { dev_dbg(dev, "decoder attached to %s\n", dev_name(&cxled->cxld.region->dev)); @@ -664,19 +669,13 @@ static int __cxl_dpa_alloc(struct cxl_endpoint_decode= r *cxled, u64 size) return -ENOSPC; } =20 - return __cxl_dpa_reserve(cxled, start, size, skip); + return __devm_cxl_dpa_reserve(cxled, start, size, skip); } =20 int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size) { - struct cxl_port *port =3D cxled_to_port(cxled); - int rc; - - rc =3D __cxl_dpa_alloc(cxled, size); - if (rc) - return rc; - - return devm_add_action_or_reset(&port->dev, cxl_dpa_release, cxled); + guard(rwsem_write)(&cxl_rwsem.dpa); + return __cxl_dpa_alloc(cxled, size); } =20 static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl) --=20 2.47.3