From nobody Thu Apr 9 15:05:52 2026 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 4C7CE2DEA75 for ; Sat, 7 Mar 2026 19:47:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772912849; cv=none; b=ppC4xVNlMAdcLD80sDq7+NcTF9Ye4nQm7Uz5D5D3xoyJIhG2CUm7r3AMXMo7MSAIYzkIy6WtNk5lEKJGou8hEWc3lGdVpM+B1vXOctdiPMCSs4ORJfTFVEUJOiohv3ANMbTBfkzWupiAxW36YaINHrQvsek2nv6GnjXdOmgbVAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772912849; c=relaxed/simple; bh=NhGvP3zh+3FspvIi3ZZKgCzITyJP9qVcs0ws6/EsZ+E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ldl/AMzaB/qDlcQyk9UJOeY1m80LMErpjXY+yMg8/zMu00JINXyorQ0gW8mRPY8UhAMawjvPTZSAbab8E/BH+skSm72T1P4lX0bwO9lG27oSEbObsiBvI/M4mi+5dcKtM1QVjCSfjMuUHjHknSzV0I2JkffeU/OetiZg0VloVFk= 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.169 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-f169.google.com with SMTP id 00721157ae682-79868cde1eeso114411397b3.2 for ; Sat, 07 Mar 2026 11:47:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772912847; x=1773517647; 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=V8aOBZcZ9tXID5tssFJJhBM5poUTOsJuGpZdRZooCLM=; b=Pll49RqEItNQmPXHWnkKf3/bV6KpRBlxpk451wn3uvpoAjXO5rRkDd+M6zy7W16Lld FJgaIuj+iqBAvKKp2CxGVWbNci5dpjes87RzBd990XVtsrqN6yGkyINEOZgSY1XIlko1 D/huFHmY63/MTJINYBZAHh92D2BUP8NN5LwGmyVALsW4vS9ZhyH90Lv5ZNdKZpCDxksx oL+5B/nvM3bBAMbxqsEb4fDqsD3Zzp4ReYZ2s2iDQZOoWiAB29vqOBeKVJOLLI0ZErg8 su+OOf5tYG7HayAEdz5Xw7Z4uXIHkdpfUhavfJmkFKGB0IteMj/cD6V2+6C36nSZnJg3 /JLA== X-Forwarded-Encrypted: i=1; AJvYcCUdU2n0ivKpByn27Ahnn9zY4DB28rgwGqFwAvWwAcY/bzj4pscua82hhnsO47LbSonQMZ1L8fDawv6moec=@vger.kernel.org X-Gm-Message-State: AOJu0YxyEsniFhYrqHEJZ2SF8SlJA6ikafOF8WqwVEVVxidhcrnDrVct aLx/eZiP05fEEyKApMwF9wLW5qMuMzKk10BfpHZrDv9kMAJNRQfRte0z X-Gm-Gg: ATEYQzwvyydgR+ziongWrkC7XxmhVLxDQQ1gE2LuGi0s+LG4LU+QxtHyF9cgq3NzRQV CzGL4ue6MCflF1LZfe8K3Z+scrLSe4ycBanXfa094oZ52iumUCXGSHqLiFQWC7KYGdtFcmz4j04 kMkfkxsiCGOZ5zJbAvqH9T7adkYg2n8W9IDQ39fFTQcgEoF1mlGaRIeEhKejBXAVkMtabBMEjgf x6/AwK4hoTAkxnKHzZ2V5oCaHgzYaXXuNPB1Cj25Sh2M84R4pcWeAsvthZDYtUsHqw+HlowKOAN qJND/sOX7BIu5JdQhUzLnHwv3Ejc9cgsc2j49rdxK77SAsrgRmJN25bIrXxonWoM6zgY9GEThkY rBGXGP8Uj81i2Ds4PnNBDO/mPJbncgS9BuodYJ/f3R2ljYV3/oKXcN+JKKr2Wt2suZ+6ahFxOqI noS5idVbcT5Q== X-Received: by 2002:a05:690c:dd3:b0:794:7be0:8217 with SMTP id 00721157ae682-798dd775535mr58874817b3.52.1772912847172; Sat, 07 Mar 2026 11:47:27 -0800 (PST) Received: from tofu.. ([128.210.0.165]) by smtp.googlemail.com with ESMTPSA id 00721157ae682-798ded6eca9sm23409447b3.22.2026.03.07.11.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Mar 2026 11:47:26 -0800 (PST) From: Sungwoo Kim To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Sungwoo Kim , Chao Shi , Weidong Zhu , Dave Tian , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] Fix race bug in nvme_poll_irqdisable() Date: Sat, 7 Mar 2026 14:46:36 -0500 Message-ID: <20260307194636.2755443-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 scenario, pdev can be disabled between (1) and (3) by (2). This sets pdev->msix_enabled =3D 0. Then, pci_irq_vector() will return MSI-X IRQ(>15) for (1) whereas return INTx IRQ(<=3D15) for (2). This causes IRQ warning because it tries to enable INTx IRQ that has never been disabled before. To fix this, save IRQ number into a local variable and ensure disable_irq() and enable_irq() operate on the same IRQ number. Even if pci_free_irq_vectors() frees the IRQ concurrently, disable_irq() and enable_irq() on a stale IRQ number is still valid and safe, and the depth accounting reamins balanced. task 1: nvme_poll_irqdisable() disable_irq(pci_irq_vector(pdev, nvmeq->cq_vector)) ...(1) enable_irq(pci_irq_vector(pdev, nvmeq->cq_vector)) ...(3) task 2: nvme_reset_work() nvme_dev_disable() pdev->msix_enable =3D 0; ...(2) crash log: Acked-by: Chao Shi Acked-by: Dave Tian Acked-by: Weidong Zhu Reviewed-by: Christoph Hellwig ------------[ cut here ]------------ Unbalanced enable for IRQ 10 WARNING: kernel/irq/manage.c:753 at __enable_irq+0x102/0x190 kernel/irq/man= age.c:753, CPU#1: kworker/1:0H/26 Modules linked in: CPU: 1 UID: 0 PID: 26 Comm: kworker/1:0H Not tainted 6.19.0-dirty #9 PREEMP= T(voluntary) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga= 6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Workqueue: kblockd blk_mq_timeout_work RIP: 0010:__enable_irq+0x107/0x190 kernel/irq/manage.c:753 Code: ff df 48 89 fa 48 c1 ea 03 0f b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 = d0 7c 04 84 d2 75 79 48 8d 3d 2e 7a 3f 05 41 8b 74 24 2c <67> 48 0f b9 3a e= 8 ef b9 21 00 5b 41 5c 5d e9 46 54 66 03 e8 e1 b9 RSP: 0018:ffffc900001bf550 EFLAGS: 00010046 RAX: 0000000000000007 RBX: 0000000000000000 RCX: ffffffffb20c0e90 RDX: 0000000000000000 RSI: 000000000000000a RDI: ffffffffb74b88f0 RBP: ffffc900001bf560 R08: ffff88800197cf00 R09: 0000000000000001 R10: 0000000000000003 R11: 0000000000000003 R12: ffff8880012a6000 R13: 1ffff92000037eae R14: 000000000000000a R15: 0000000000000293 FS: 0000000000000000(0000) GS:ffff8880b49f7000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555da4a25fa8 CR3: 00000000208e8000 CR4: 00000000000006f0 Call Trace: enable_irq+0x121/0x1e0 kernel/irq/manage.c:797 nvme_poll_irqdisable+0x162/0x1c0 drivers/nvme/host/pci.c:1494 nvme_timeout+0x965/0x14b0 drivers/nvme/host/pci.c:1744 blk_mq_rq_timed_out block/blk-mq.c:1653 [inline] blk_mq_handle_expired+0x227/0x2d0 block/blk-mq.c:1721 bt_iter+0x2fc/0x3a0 block/blk-mq-tag.c:292 __sbitmap_for_each_set include/linux/sbitmap.h:269 [inline] sbitmap_for_each_set include/linux/sbitmap.h:290 [inline] bt_for_each block/blk-mq-tag.c:324 [inline] blk_mq_queue_tag_busy_iter+0x969/0x1e80 block/blk-mq-tag.c:536 blk_mq_timeout_work+0x627/0x870 block/blk-mq.c:1763 process_one_work+0x956/0x1aa0 kernel/workqueue.c:3257 process_scheduled_works kernel/workqueue.c:3340 [inline] worker_thread+0x65c/0xe60 kernel/workqueue.c:3421 kthread+0x41a/0x930 kernel/kthread.c:463 ret_from_fork+0x6f8/0x8c0 arch/x86/kernel/process.c:158 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:246 irq event stamp: 74478 hardirqs last enabled at (74477): [] __raw_spin_unlock_i= rq include/linux/spinlock_api_smp.h:159 [inline] hardirqs last enabled at (74477): [] _raw_spin_unlock_ir= q+0x2c/0x60 kernel/locking/spinlock.c:202 hardirqs last disabled at (74478): [] __raw_spin_lock_irq= save include/linux/spinlock_api_smp.h:108 [inline] hardirqs last disabled at (74478): [] _raw_spin_lock_irqs= ave+0x85/0xa0 kernel/locking/spinlock.c:162 softirqs last enabled at (74304): [] __do_softirq kernel= /softirq.c:656 [inline] softirqs last enabled at (74304): [] invoke_softirq kern= el/softirq.c:496 [inline] softirqs last enabled at (74304): [] __irq_exit_rcu+0xdc= /0x120 kernel/softirq.c:723 softirqs last disabled at (74287): [] __do_softirq kernel= /softirq.c:656 [inline] softirqs last disabled at (74287): [] invoke_softirq kern= el/softirq.c:496 [inline] softirqs last disabled at (74287): [] __irq_exit_rcu+0xdc= /0x120 kernel/softirq.c:723 ---[ end trace 0000000000000000 ]--- Fixes: fa059b856a59 (nvme-pci: Simplify nvme_poll_irqdisable) Acked-by: Chao Shi Acked-by: Weidong Zhu Acked-by: Dave Tian Signed-off-by: Sungwoo Kim --- drivers/nvme/host/pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index d86f2565a..a7fb88aa8 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1484,14 +1484,16 @@ static irqreturn_t nvme_irq_check(int irq, void *da= ta) static void nvme_poll_irqdisable(struct nvme_queue *nvmeq) { struct pci_dev *pdev =3D to_pci_dev(nvmeq->dev->dev); + int irq; =20 WARN_ON_ONCE(test_bit(NVMEQ_POLLED, &nvmeq->flags)); =20 - disable_irq(pci_irq_vector(pdev, nvmeq->cq_vector)); + irq =3D pci_irq_vector(pdev, nvmeq->cq_vector); + disable_irq(irq); spin_lock(&nvmeq->cq_poll_lock); nvme_poll_cq(nvmeq, NULL); spin_unlock(&nvmeq->cq_poll_lock); - enable_irq(pci_irq_vector(pdev, nvmeq->cq_vector)); + enable_irq(irq); } =20 static int nvme_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob) --=20 2.47.3