From nobody Sun Dec 14 06:34:41 2025 Received: from mail-qv1-f97.google.com (mail-qv1-f97.google.com [209.85.219.97]) (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 0BBF05B5AB for ; Sat, 13 Dec 2025 00:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765585199; cv=none; b=edANcEc+WLT16n0MyZ/zH977SuCa7Ak7KVAv6ZCoWhsbZjgukfR1k024S8SHF8UdOoJgfFXUhkNC0YuZuCJkpRVNsy0Mdx1I+M445aT/ZdE7DB7EyjgNFt2xBumbbBjLx6XF37Q4LvYBFBfB7Qvl7swJx3c6qPiM3iizOGpkAyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765585199; c=relaxed/simple; bh=4nxj9fWTh8u/vSR7WUxAw8mtJOihB2zIXoz2Q6QD3Zw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QNamKqJYxA7kBchV/aSXdj8/aHX97WF2HQSahOD2kSbhW0MAMG67teoIIp32Go32M3elcFAQaav0D1PkeeEvDQq1Y+21pGP6Aom5/HxcaekaesT8ViHIjtkEVrueGWB0BDc9ndFl9anoXDmFqtAUuIj8f4sEtMUCFPm0QljLeWY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=OCpO7H5F; arc=none smtp.client-ip=209.85.219.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="OCpO7H5F" Received: by mail-qv1-f97.google.com with SMTP id 6a1803df08f44-8804d738294so2458466d6.2 for ; Fri, 12 Dec 2025 16:19:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1765585197; x=1766189997; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OSG6es0J0cc7VS5khpOgLsO5uiuIwff2vbQ6mje6Gvs=; b=OCpO7H5FVFh95vpZa17jY97Jbpmn8AUxFjvMOIJ/x0qn9BsAk5hYHj3ism+38fh4Tb scwjixMhlMtsshSRMSTSx6npZDy5Xpte9LuQOHxfcN8M16dLxxDMCHDyr/w8SydptJ38 AAvGqHHbwIxwQk/tf9MrL/WITA6M0mFXkzG25+rJDuUIz3hjaSv4VGanOunYi5xDyPqw YNnDzh8hbvpJ1duKKQxV8xKNf5Jqy3c7r/wcGvMtTB0ztA0WZm5DvnsNQQUJ4vr4/ZLj c1bDWX9pPN3Bb+Ho4C4uRRDPoAORwPM8YemGXF31bzG2mLEHg3sAhncjSeNwQNKHIoVT mG0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765585197; x=1766189997; 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=OSG6es0J0cc7VS5khpOgLsO5uiuIwff2vbQ6mje6Gvs=; b=m1e5of1ETFYCj/0aaK9X3J3RohgJV+m3rClwnCyxoVHjjWeSjSuoYrf91CPZTO/M4W HsShrBhFoHKpA/Y9zsPfTsSdfScU8xaakKPqxZLBZBFRAZIfGjx+9Cs4oTMt6k3VAJuu irs6mqz/FKZASOa77C8j9lmbDO8t8/2ValATd4KVGvoCkJxFE8LlojxZKSFPr0Qu3/6U J5XydekSSfjzoM+EyhcHfZh/9OwCtEHtwKX66UGUeUMCIi7ChwF94VZ+86Zkl/A/a99t biqkmieJR2AdKXHb6dIdOvY5T5PyRcU7PdAzOJa8l/sDoR4FBbwZgXEkebUfmfqelEDk c19w== X-Forwarded-Encrypted: i=1; AJvYcCUB+ZhHg0oYB33WdOZXSGiYIdbNO0bbobjjM5PCrhcQ4VvdC5pBsYo9XOMhsmwwGTCmqiLg163Q6EPGt3A=@vger.kernel.org X-Gm-Message-State: AOJu0YzSPsvG8MFAqy4T90tzkYxqh5s7uUXPdjtqrG8wzVS7Q9nSz7Gj UnF+V23wTd4IV4tw5XsgjQ/4s1ZxgCcfFnBBaID6Zd/s8DB7laNWL7tqzu6wt7ub7kxGTDVwXXk njolAynyvzoaDKWv8T4y+Kl9jh0IrTlRJoLuBVlLoeqKqW0b7umT5 X-Gm-Gg: AY/fxX6NcvH4jfp1/vhAkgsrAwXHrHv9knbfQh1Wl4O8a28U6r4B1uLzI+kUsOMeksX wzdyYIuYrHNaE7gn4l8MvCEOVgpmXEqa5iWw2RcNTiy42aLmhrgdaZH/C7QEGk83IM+XSrHXuYK oUagKK3cG6pwmjGQYyuCFAX1DQxfrwINOh2Py/b6Bdpar5qqviW6vmMS1wFxm6tA8Eb97JcO6Qo kxpxXLzQVjRgiFvjp332/w+IX3kIqCxmkqi06za62LkNBIhlK8mSPJl+Z1cvqWPMheLHRU+l6n2 NbD1N+ph9Q12w160srLMlJa1C0+RDWBYanpzLtyeFobYy3Gp1QdZXv1RXe3/7WFqrZi842Lv6Z+ Vs8t4VTBEinv1ljhnOGDOKh1ppZY= X-Google-Smtp-Source: AGHT+IFZ2DBVpOqAAbHT521TfS4EEsrCsl84UBX25d4y729HKZPVq461pjAQhlhPCUyOXEFpgIbN86WHLEru X-Received: by 2002:a05:620a:4416:b0:89f:5a1b:1ec9 with SMTP id af79cd13be357-8bb398d9574mr434257785a.1.1765585196820; Fri, 12 Dec 2025 16:19:56 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id af79cd13be357-8bab5c04048sm84427685a.6.2025.12.12.16.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 16:19:56 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (unknown [IPv6:2620:125:9007:640:ffff::1199]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id DAE3634027F; Fri, 12 Dec 2025 17:19:55 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id D4DCAE41AC3; Fri, 12 Dec 2025 17:19:55 -0700 (MST) From: Caleb Sander Mateos To: Ming Lei , Jens Axboe Cc: Uday Shankar , Caleb Sander Mateos , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ublk: clean up user copy references on ublk server exit Date: Fri, 12 Dec 2025 17:19:49 -0700 Message-ID: <20251213001950.2103303-1-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 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" If a ublk server process releases a ublk char device file, any requests dispatched to the ublk server but not yet completed will retain a ref value of UBLK_REFCOUNT_INIT. Before commit e63d2228ef83 ("ublk: simplify aborting ublk request"), __ublk_fail_req() would decrement the reference count before completing the failed request. However, that commit optimized __ublk_fail_req() to call __ublk_complete_rq() directly without decrementing the request reference count. The leaked reference count incorrectly allows user copy and zero copy operations on the completed ublk request. It also triggers the WARN_ON_ONCE(refcount_read(&io->ref)) warnings in ublk_queue_reinit() and ublk_deinit_queue(). Commit c5c5eb24ed61 ("ublk: avoid ublk_io_release() called after ublk char dev is closed") already fixed the issue for ublk devices using UBLK_F_SUPPORT_ZERO_COPY or UBLK_F_AUTO_BUF_REG. However, the reference count leak also affects UBLK_F_USER_COPY, the other reference-counted data copy mode. Fix the condition in ublk_check_and_reset_active_ref() to include all reference-counted data copy modes. This ensures that any ublk requests still owned by the ublk server when it exits have their reference counts reset to 0. Signed-off-by: Caleb Sander Mateos Fixes: e63d2228ef83 ("ublk: simplify aborting ublk request") --- drivers/block/ublk_drv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index df9831783a13..78f3e22151b9 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -1581,12 +1581,11 @@ static void ublk_set_canceling(struct ublk_device *= ub, bool canceling) =20 static bool ublk_check_and_reset_active_ref(struct ublk_device *ub) { int i, j; =20 - if (!(ub->dev_info.flags & (UBLK_F_SUPPORT_ZERO_COPY | - UBLK_F_AUTO_BUF_REG))) + if (!ublk_dev_need_req_ref(ub)) return false; =20 for (i =3D 0; i < ub->dev_info.nr_hw_queues; i++) { struct ublk_queue *ubq =3D ublk_get_queue(ub, i); =20 --=20 2.45.2