From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793095751; b=VL5NpFcWrA+J+b/qePj52ZuwWSKabRg4UgN9qIV44gNwAt2F9GdlwBJfJ73qGjsHt3vk kL+9RwxdRWdJCiQBEuvnLi7F4kxQMz8hTZCw4m32RbDWBeM2KgbdGCXHsNVEmMkFSaDGV 4bD8J+LrD9QNEbExGN++ztKmUa2apFMhBaSSwuMs+YcFBH36wCTvhY7r2xOcA/BeJVHoc OnLXqijc7v7ZkgN/72Li2llKLicSG53J/T7CZwKA0+uGmwVjoDyJ8XNENRrR4TQysUisP Ew5pVq9HNfzC7YOQXx0aF8OIvvBRFjuXiBbQUnSpHLvfeSsZNR10257l+kizaimxUSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793095751; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=Q1TQFPxvI9cCV2PEQR7e2VoXkM4CEOcgxtKO+kbRzJI=; b=a5NPXh/S9ey0TvFiPzDgxOqox5Oob4CBdBrl0ASeKTfknbikrxottftezJ339DxGPNbN wM2ZxdTk6JeU9SVxy6xhf1SwZq1h8coZg5ACuzLwBSxaKiQjIwWsj3QehWR6zhvPKKlGs cn3M+d6rQ7oo4H/h8j79nQ17/88D6+1lfC3PedPeiP1KwPX4U03cVVRMdkuV0GpGWBY7h k+8G0iBP7xZl8+iOthAmalQK2CNTwt6CoH7R1ARUuNui8eKZ26+JNR6Zyd8gMLc/+QwsO Z4UTftOETO1IajvNeeIwLWq6TQj046Oas5uEULSr789km2BBSOPhq/HJO4XdL7Ve2Xw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=WBXAb0tb; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72B00606A324 for ; Tue, 27 Oct 2026 10:09:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 72B00606A324 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=WBXAb0tb Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4a1df4c0966so5583395e9.1 for ; Tue, 27 Oct 2026 03:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1793095750; x=1793700550; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Q1TQFPxvI9cCV2PEQR7e2VoXkM4CEOcgxtKO+kbRzJI=; b=WBXAb0tbp2OMhaaP88j/zfTc5TECBWNVG585+Hqxb6IR+F1Ke7PrVKASf0vdcnHk/B EJdNi/5SO6OWqnnJQJMm7OzH5jVX4HaPvZ+hb+3Kn/i2PmggtvY1FtYGY+KtVY8EX85n G8YsR/EfxvZP9FCj6ZS8A2MK1BjNxKW+1s+5Y36C4/qjUSvhSfKtVs8zbL0ltsjXF5A0 D4+EqOL0C2KUW3l87l00LIRHw7JYkLJx/BKIVj5LsjX36A37qmGAmCLx9iJYcRccKbrg 9EOa1dgedAWdscomLZq976N9DqtT+ZeCUIHVY+cTLCqp4Hzu7h4PbhyeXVZNq4OcBzDO u1UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793095750; x=1793700550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Q1TQFPxvI9cCV2PEQR7e2VoXkM4CEOcgxtKO+kbRzJI=; b=BjW0g03grzIhkyBBCNhkcGtdEk8qdk582FDw0mKbm/PLz1c9rVooot4PCkC5jhUPke KHioQ7dfnvlo3aFPYQnDKiSKpPct7fb6MJaY9ONt74xyP+SQB0QFYA87hdujX6f0Knvw RWQmS2EZwIBB/upNgS/GqXbe6zacWNAgP/dPN+MIEKvBxqNDOIDZtlibBBeDQYS4LX4G ByqTmSyVZWxOPDTKZn5finTRyFVNStRxq2wTsPUtw35wouFM+HHDNiQ6CsP6+Bag4GQU qlH4tkhju1DhDWhVS8fU3ZAASHb/rFBdmIj6u72iGPRWB/W4bVhTZhAhHRkoEXhr05ga 5pzg== X-Forwarded-Encrypted: i=1; AKwUvByAebI1XgSX5B/7uomQEM5dZ8r4li4/v6DFnsxSWqoxoXeW6A3mFIXnpvaXgUFETh8OZQ24RgIrXX2R48Q=@vger.kernel.org X-Gm-Message-State: AFq9FYJu0IP61wQqAlwdBf/nldNzdS3GtiCFeyOAVW5waz+oGx1bwBQP ClwF1JbV+cp1iMhbYn9BbN31aFR0x5aoaQm8Q3rn+nZVybZa+nmMmIzSqBWCsc8B X-Gm-Gg: AYBFou0KlQtxiCdG9ZKqKT2NytJMkJlzYlALyfV82hi4fkqUGRJysfHGssoLV+WS1Yy DRI0iF57uKJPyE3pOvrwIi80I+pPUhPPHjMrmCZP2Tle3OOduHlA5XnlcDdnda5dYA2KR4uGnOP s0gbgaa/HKUZBaU0FsgGLT23Fys7uRS2C0VDA8uEeVA+I/TOJVqXQxHn1Ga+TPUFkEvB64a4XkX qCwfXhQOkWRQaNkHg/8eKQ9IhAWhSqBYFWaV9k3KwjkQkzvtSD9uvipk7W36K0dxcTdCU1qfqN4 RUIgqaX3laj+9sbg4VgbH8RMVVrB8YPJaO7mvE83EaBIoVmDxj59TF2oXM+l5czGoKId/1TlARN JzfZ6EINFRyl9VlSjVOf+vRAuQlx07g/M4FhtLQDFc/Y107sJZ6sN6D797RpKUvv86U1WnwObFv mYU/Qrl9bfuln34DFvqwBtPU9fahpVCt2ANFH7kQWpB27XRa7TBj85/cxvrsM4WlMYhJ5I8XEln cEKwL3UWs3rO4CoPFEwuU7ASWfLx69ewVRe4sPru/L1HUt2tvUtGTSLd17fljEure1O X-Received: by 2002:a05:600c:3115:b0:4a1:88df:8a2a with SMTP id 5b1f17b1804b1-4a7c16c5294mr46820035e9.13.1793095749477; Tue, 27 Oct 2026 03:09:09 -0700 (PDT) Received: from unicorn.lan.internal ([2a0d:3341:b894:4600:8f9a:af38:72d6:7c0e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a35a5822a7sm266582155e9.11.2026.10.27.03.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 03:09:08 -0700 (PDT) From: Giuseppe Piscitelli To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: Bart Van Assche , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] scsi: core: Balance the pseudo target reap reference Date: Tue, 27 Oct 2026 11:08:50 +0100 Message-ID: <20261027100859.1031135-1-ooonea@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261026202119.667348-1-ooonea@gmail.com> References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit With memory allocation profiling enabled, unloading scsi_debug reports allocations left at module unload. A stock Linux 7.2.11 VM without OpenZFS emitted the following on each of three load/unload cycles: [ 1.644665] drivers/scsi/scsi_debug.c:8863 module scsi_debug func:sdebug_add_host_helper has 1024 allocated at module unload [ 1.656260] drivers/scsi/scsi_debug.c:1261 module scsi_debug func:sdebug_target_alloc has 16 allocated at module unload scsi_alloc_target() supplies a reap reference for its caller. The SCSI device initializer takes another reference, which device removal drops. scsi_get_pseudo_sdev() drops its caller reference only when device allocation fails. On success the target cannot be destroyed, retaining its driver-private data and its parent host and adapter. Drop the caller reference in the common cleanup path, as the other scsi_alloc_target() callers do. Fixes: d630fbf6fc8c ("scsi: core: Support allocating a pseudo SCSI device") Signed-off-by: Giuseppe Piscitelli --- OpenAI Codex analyzed the teardown diagnostics and wrote this fix and its local validation. The new unpatched capture reproduces the symptom; it does not establish which of this fix and the separately proposed scsi_debug asynchronous cleanup fix removes each diagnostic. Changes in v2: - Include the allocation-at-unload diagnostics requested by Bart. - No code changes. Earlier validation covered four constructor/reference-count cases, a Linux 7.3 build and three ordinary corrected-module lifecycles. The new stock 7.2.11 run above captures the unpatched diagnostics only; no new patched-kernel build or comparison was run. drivers/scsi/scsi_scan.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 0f0f243..90e67f3 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -2156,14 +2156,13 @@ struct scsi_device *scsi_get_pseudo_sdev(struct Scsi_Host *shost) goto out; sdev = scsi_alloc_sdev(starget, U64_MAX, NULL); - if (!sdev) { - scsi_target_reap(starget); + if (!sdev) goto put_target; - } sdev->borken = 0; put_target: + scsi_target_reap(starget); /* See also the get_device(dev) call in scsi_alloc_target(). */ put_device(&starget->dev); base-commit: 6a53f401e671b75c129245e371ca6e9d47fc3c9a -- 2.54.0