scsi: ibmvfc: make ibmvfc support FPIN messages
Subsystems (3)
Tyrel Datwyler
maintainerv11 cover scsi: ibmvfc: make ibmvfc support FPIN messages
This patch series adds FPIN (fabric performance impact notification) support to the ibmvfc (IBM Virtual Fibre Channel) driver. This comes in three flavors:
- basic, to recognize existing FPIN messages from the virtual I/O server (VIOS) (patch 4)
- full, supporting additional FPIN information and using its own asynchronous sub-queue and interrupt (patches 6-10)
- extended, supporting FC-LS-5 (patch 11)
Full and extended FPIN support requires a new asynchronous sub-queue with its own interrupt. The asynchronous sub-queue support requires ibmvfc to also support a new IBMVFC_NOOP command, which the driver recognizes and ignores (patch 5).
The asynchronous sub-queue work is split across four patches: patch 6 defines the necessary data structures, patch 8 adds the interrupt and drain routines for the queue, patch 9 extends channel registration and deregistration to accommodate the new queue, and patches 1-3 fix IRQ cleanup and error handling bugs exposed during that work. Patch 10 wires everything together, registering the async sub-queue during channel initialization and advertising support to VIOS during NPIV login.
All three modes convert an incoming FPIN message from VIOS to an FC extended link service message, in some cases using default values for information not provided by the VIOS FPIN message but expected in the FC ELS message. This FC ELS message is passed to fc_host_rcv_fpin for updating statistics and sending the information upstream by netlink multicast, where it may be read by listeners including the DM multipath daemon "multipathd."
---
Changes in v11:
- Split the IRQ cleanup and NULL-pointer fixes out of the "register and
use" patch into two dedicated bug-fix patches (patches 1-2 and 1-3),
making the series 11 patches instead of 9
- Replaced the single ibmvfc_queue async_sub_crq field in ibmvfc_host with
an ibmvfc_channels async_scrqs field, reusing the existing channel infrastructure for allocation, registration, and teardown (patches 6, 9, 10)
- Added IBMVFC_PROTO_ASYNC to enum ibmvfc_protocol; ibmvfc_register_channel() and ibmvfc_deregister_channel() now dispatch on protocol rather than a negative-index sentinel (patch 9)
- Added IBMVFC_ASYNC_SUB_CRQ_FMT format enum value and corresponding
async_scrq pointer in union ibmvfc_msgs (patch 6)
- ibmvfc_alloc_channels() selects IBMVFC_ASYNC_SUB_CRQ_FMT for async
protocol channels so queues are sized for ibmvfc_async_sub_crq entries
(patch 10)
- Link to v10: https://lore.kernel.org/linux-scsi/[email protected]/
Changes in v10:
- Fix ibmvfc_find_target() to use logical and (&&) instead of logical or (||) when checking whether fc and nvme remote ports are NULL (patch 4)
- Fix build issues due to missing & operator when referencing the host lock during irqsave/restore calls (patch 4, patch 7, patch 8, patch 11)
- Fix kunit build issues caused by inclusion of code meant for later patches (patch 4, patch 7, patch 11)
- Link to v9: https://lore.kernel.org/linux-scsi/[email protected]/
Changes in v9:
- Fix ibmvfc_find_target() to check for either a valid rport or nvme_remote_port
so nvme targets are not silently dropped (patch 4)
- Restore xxx_host_remove() ordering and destroy async work queue prior to these
calls. Check that the host is not offline prior to enqueuing new async work
(patch 4)
- Link to v8: https://lore.kernel.org/linux-scsi/[email protected]
Changes in v8:
- Split patch 6 into two patches: extend channel registration/deregistration
for async subq (patch 9), and clear sub-CRQ IRQ on registration failure
and guard teardown (patch 1)
- Fixed NULL dereference in ibmvfc_deregister_channel() when called on
an unallocated queue: guard memset() behind scrq->msgs.handle check
- Fixed variable-shadowing bug in ibmvfc_register_channel() error path
where H_FREE_SUB_CRQ hcall result clobbered the return code
- Deregister and re-register async sub-CRQ in ibmvfc_reenable_crq_queue()
and ibmvfc_reset_crq() alongside SCSI channel queues
- Link to v7: https://patch.msgid.link/[email protected]
Changes in v7:
- Removed CRQ valid bit clearing to callers of ibmvfc_handle_async in
all cases
- Added validity checks that IBMVFC_ASYNC_ID_IS_ASSOC_ID is clear
before using node_name
- Fixed error path cleanup in ibmvfc_init_sub_crqs
- Deregister and reregister async sub-CRQ in CRQ reset and reenable
code.
- Moved work queue destruction after sub CRQs teardown in ibmvfc_remove
- Modified async event handling code to use a tagged union rather than
void *.
- Use WQ_UNBOUND rather than WQ_PERCPU for fpin workqueue, as FPIN
events should be rare. Hold q_lock only in
ibmvfc_drain_async_subq(), like ibmvfc_drain_sub_crq().
- Hardened KUnit tests to use host_lock and kref.
- Link to v6: https://patch.msgid.link/[email protected]
Changes in v6:
- Use alloc_workqueue rather than devm_alloc_workqueue, and add
explicit destroy_workqueue calls
- Moved ibmvfc_find_target into patch 4
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- Incorporate changes for NVME-over-FC.
- Removed now redundant fabric login patch.
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- Refactored channel registration
- Check whether async work queue is allocated before using or freeing
- Fixed work queue allocation/destruction
- Skip basic KUnit test when there are no ibmvfc devices available
- Fix target not found condition in ibmvfc_process_async_work
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Fixed latent bug, exposed by VFC_NOOP, related to dataless CRQs and events
- Fixed FPIN TLV descriptor length calculations
- Use safe list walker to walk targets in ibmvfc_process_async_work
- Added write memory barriers after clearing CRQ valid field
- Use per-vhost work queue for FPIN work
- Link to v2: https://patch.msgid.link/[email protected]
Highlights of changes in v2:
- Refactored mostly common FPIN conversion routines and async event
processing into single routines with wrappers for differences.
- Moved FPIN processing to a work queue to avoid conflicts with
fc_host_fpin_rcv and memory allocation
- Set descriptor sizes correctly
- Use target WWPN for basic FPIN descriptor
- Split patch 4 into 3 patches, for definition, allocation, and use of
the asynchronous sub-queue for events
- Link to v1: https://patch.msgid.link/[email protected]
To: "James E.J. Bottomley" <[email protected]>
To: "Martin K. Petersen" <[email protected]>
To: Madhavan Srinivasan <[email protected]>
To: Michael Ellerman <[email protected]>
To: Nicholas Piggin <[email protected]>
To: "Christophe Leroy (CS GROUP)" <[email protected]>
To: Tyrel Datwyler <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Dave Marquardt (9):
scsi: ibmvfc: fix IRQ leak and guard deregister on channel reg failure
scsi: ibmvfc: add basic FPIN support
scsi: ibmvfc: add NOOP command support
scsi: ibmvfc: add FPIN extended flag and async sub-CRQ queue handle
scsi: ibmvfc: extend async event handlers for async sub-CRQ events
scsi: ibmvfc: add interrupt routine for asynchronous sub CRQ
scsi: ibmvfc: extend channel reg/dereg helpers for async sub-CRQ
scsi: ibmvfc: register and use asynchronous sub CRQ for events
scsi: ibmvfc: handle extended FPIN events
Tyrel Datwyler (2):
scsi: ibmvfc: fix potential clobbering of rc after failed irq setup
scsi: ibmvfc: fix potential NULL pointer dereference on failed queue
allocation
drivers/scsi/Kconfig | 10 + drivers/scsi/ibmvscsi/Makefile | 1 + drivers/scsi/ibmvscsi/ibmvfc-core.c | 720 ++++++++++++++++++++++++--- drivers/scsi/ibmvscsi/ibmvfc.h | 66 +++ drivers/scsi/ibmvscsi/ibmvfc_kunit.c | 409 +++++++++++++++ 5 files changed, 1141 insertions(+), 65 deletions(-) create mode 100644 drivers/scsi/ibmvscsi/ibmvfc_kunit.c
Signature · 1 line
2.55.0
Tyrel Datwyler
maintainerPATCH v11 1/11 scsi: ibmvfc: fix IRQ leak and guard deregister on channel reg failure
From: Dave Marquardt <[email protected]>
If request_irq() fails during ibmvfc_register_channel(), the error path disposes of the IRQ mapping via irq_dispose_mapping() but leaves scrq->irq populated with the stale virq number. A subsequent call to ibmvfc_deregister_channel() during teardown or reset cleanup then unconditionally invokes free_irq() and irq_dispose_mapping() on the stale IRQ descriptor, triggering kernel warnings.
Fix this by:
1. Explicitly setting scrq->irq to 0 after irq_dispose_mapping() in the ibmvfc_register_channel() error path.
2. Guarding free_irq() and irq_dispose_mapping() with a check for scrq->irq in ibmvfc_deregister_channel() so unmapped or unregistered queues are safely skipped.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/scsi/ibmvscsi/ibmvfc-core.c +6 -3
@@ -6436,6 +6436,7 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost,if (rc) {dev_err (dev,"Couldn't register sub-crq[%d] irq\n" , index);irq_dispose_mapping (scrq->irq); + scrq->irq =0 ; goto irq_failed; }
@@ -6464,9 +6465,11 @@ static void ibmvfc_deregister_channel(struct ibmvfc_host *vhost,ENTER ; -free_irq (scrq->irq, scrq); -irq_dispose_mapping (scrq->irq); - scrq->irq =0 ; +if (scrq->irq) { +free_irq (scrq->irq, scrq); +irq_dispose_mapping (scrq->irq); + scrq->irq =0 ; + } do { rc = plpar_hcall_norets(H_FREE_SUB_CRQ, vdev->unit_address,
Signature · 1 line
2.55.0
Tyrel Datwyler
maintainerPATCH v11 2/11 scsi: ibmvfc: fix potential clobbering of rc after failed irq setup
In reply to Tyrel DatwylerFix a variable-shadowing bug in ibmvfc_register_channel() where the irq_failed cleanup loop reused rc for the H_FREE_SUB_CRQ hcall result, clobbering the error code returned to the caller.
Introduce hcall_rc for the cleanup loop instead.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/ibmvscsi/ibmvfc-core.c +3 -2
@@ -6392,6 +6392,7 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost,struct vio_dev *vdev =to_vio_dev (dev);struct ibmvfc_queue *scrq = &channels->scrqs[index];int rc = -ENOMEM ; +int hcall_rc;ENTER ;
@@ -6447,8 +6448,8 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost, irq_failed:do { - rc =plpar_hcall_norets (H_FREE_SUB_CRQ , vdev->unit_address, scrq->cookie); - }while (rc ==H_BUSY ||H_IS_LONG_BUSY (rc)); + hcall_rc =plpar_hcall_norets (H_FREE_SUB_CRQ , vdev->unit_address, scrq->cookie); + }while (hcall_rc ==H_BUSY ||H_IS_LONG_BUSY (hcall_rc)); reg_failed:LEAVE ;return rc;
Signature · 1 line
2.55.0
Tyrel Datwyler
maintainerPATCH v11 3/11 scsi: ibmvfc: fix potential NULL pointer dereference on failed queue allocation
In reply to Tyrel DatwylerGuard the memset() in ibmvfc_deregister_channel() behind a check of scrq->msgs.handle to prevent a NULL dereference when the function is called on a queue that was never allocated, such as async_sub_crq when multi-queue is disabled or initialization failed before ibmvfc_alloc_queue() was reached.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/ibmvscsi/ibmvfc-core.c +4 -2
@@ -6481,8 +6481,10 @@ static void ibmvfc_deregister_channel(struct ibmvfc_host *vhost,dev_err (dev,"Failed to free sub-crq[%d]: rc=%ld\n" , index, rc);/* Clean out the queue */ -memset (scrq->msgs.crq,0 ,PAGE_SIZE ); - scrq->cur =0 ; +if (scrq->msgs.handle) { +memset (scrq->msgs.crq,0 ,PAGE_SIZE ); + scrq->cur =0 ; + }LEAVE ; }
Signature · 1 line
2.55.0
Tyrel Datwyler
maintainerPATCH v11 4/11 scsi: ibmvfc: add basic FPIN support
In reply to Tyrel DatwylerFrom: Dave Marquardt <[email protected]>
Implement support for a basic level of Fabric Performance Impact Notifications (FPIN) in the ibmvfc driver to enable monitoring of fabric congestion and link integrity events.
Add async event handler for IBMVFC_AE_FPIN events that offloads FPIN processing to a dedicated workqueue. Convert VIOS FPIN messages to standard fc_els_fpin structures and pass them to fc_host_fpin_rcv() for processing by the FC transport layer.
Introduce common FPIN conversion routines that will be reused for full and extended FPIN support in subsequent patches. Add KUnit test infrastructure to validate FPIN event handling and statistics updates.
Add ibmvfc_handle_async() support for IBMVFC_AE_FPIN events, a dedicated workqueue for FPIN processing, FPIN message conversion to fc_els_fpin format, handling of link congestion, port congestion, port cleared, port degraded, and congestion cleared events, and a KUnit test module for FPIN functionality.
--- drivers/scsi/Kconfig | 10 + drivers/scsi/ibmvscsi/Makefile | 1 + drivers/scsi/ibmvscsi/ibmvfc-core.c | 295 ++++++++++++++++++++++++++- drivers/scsi/ibmvscsi/ibmvfc.h | 17 ++ drivers/scsi/ibmvscsi/ibmvfc_kunit.c | 149 ++++++++++++++ 5 files changed, 469 insertions(+), 3 deletions(-) create mode 100644 drivers/scsi/ibmvscsi/ibmvfc_kunit.c
drivers/scsi/Kconfig +10 -0
@@ -760,6 +760,16 @@ config SCSI_IBMVFC To compile this driver as a module, choose M here: the module will be called ibmvfc. +config SCSI_IBMVFC_KUNIT_TEST + tristate "KUnit tests for the IBM POWER Virtual FC Client" if !KUNIT_ALL_TESTS + depends on SCSI_IBMVFC && KUNIT + default KUNIT_ALL_TESTS + help + Compile IBM POWER Virtual FC client KUnit tests. These tests + specifically test FPIN functionality. To compile this driver + as a module, choose M here: the module will be called + ibmvfc_kunit. + config SCSI_IBMVFC_TRACE bool "enable driver internal trace" depends on SCSI_IBMVFC
drivers/scsi/ibmvscsi/Makefile +1 -0
@@ -3,3 +3,4 @@ ibmvfc-objs := ibmvfc-core.o ibmvfc-nvme.o obj-$(CONFIG_SCSI_IBMVSCSI) += ibmvscsi.o obj-$(CONFIG_SCSI_IBMVFC) += ibmvfc.o +obj-$(CONFIG_SCSI_IBMVFC_KUNIT_TEST) += ibmvfc_kunit.o
drivers/scsi/ibmvscsi/ibmvfc-core.c +292 -3
363 lines not on this page · raw message
drivers/scsi/ibmvscsi/ibmvfc.h +17 -0
@@ -750,8 +750,12 @@ enum ibmvfc_ae_fpin_status {IBMVFC_AE_FPIN_PORT_CONGESTED =0x2 ,IBMVFC_AE_FPIN_PORT_CLEARED =0x3 ,IBMVFC_AE_FPIN_PORT_DEGRADED =0x4 , + IBMVFC_AE_FPIN_CONGESTION_CLEARED = 0x5, }; +#define IBMVFC_FPIN_DEFAULT_EVENT_PERIOD (5*60*MSEC_PER_SEC)/* 5 minutes */ +#define IBMVFC_FPIN_DEFAULT_EVENT_THRESHOLD (5*60*MSEC_PER_SEC/2)/* 2.5 minutes */ + struct ibmvfc_async_crq { volatile u8 valid; u8 link_state;
@@ -781,6 +785,12 @@ struct ibmvfc_async_sub_crq { } id; } __packed__aligned(8) ; +struct ibmvfc_async_work { +struct ibmvfc_host *vhost; +struct ibmvfc_async_crq crq; +struct work_struct async_work_s; +}; +union ibmvfc_iu {struct ibmvfc_mad_common mad_common;struct ibmvfc_npiv_login_mad npiv_login;
@@ -1022,6 +1032,7 @@ struct ibmvfc_host {wait_queue_head_t work_wait_q;struct nvme_fc_local_port *nvme_local_port;struct completion nvme_delete_done; +struct workqueue_struct *fpin_workq; };struct ibmvfc_event *__ibmvfc_get_event (struct ibmvfc_queue *queue,int reserved);
@@ -1088,4 +1099,10 @@ static inline struct ibmvfc_host *ibmvfc_channels_to_vhost(struct ibmvfc_channel#define ibmvfc_remove_trace_file (kobj, attr) do { } while (0)#endif +#if IS_ENABLED (CONFIG_KUNIT ) +#include <kunit/visibility.h> +VISIBLE_IF_KUNIT void ibmvfc_handle_async(struct ibmvfc_async_crq *crq, struct ibmvfc_host *vhost); +VISIBLE_IF_KUNIT struct ibmvfc_host *ibmvfc_get_first_vhost(void); +#endif +#endif
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v11 04/11] scsi: ibmvfc: add basic FPIN support
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] scsi: ibmvfc: missing scsi_host_put() in test success path - [Medium] scsi: ibmvfc: missing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] scsi: ibmvfc: missing scsi_host_put() in test success path
- [Medium] scsi: ibmvfc: missing host_lock around ibmvfc_handle_async() in KUnit test --
commit 29ab8a9a78c94679b8187ae357d2978336830599
Author: Dave Marquardt <[email protected]>
scsi: ibmvfc: add basic FPIN support
Implement support for a basic level of Fabric Performance Impact Notifications (FPIN) in the ibmvfc driver to enable monitoring of fabric congestion and link integrity events. This includes async event handling and KUnit test infrastructure.
Quoted 6 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +0
-0@@ -0,0 +1,149 @@
[ ... ]
Quoted 2 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +2
-0+static void ibmvfc_async_fpin_test (struct kunit *test) +{
[ ... ]
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+ vhost =ibmvfc_get_first_vhost (); +if (!vhost) +kunit_skip (test,"No ibmvfc devices available" );
[ ... ]
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 73
Quoted 9 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +9
-0+for (fs =IBMVFC_AE_FPIN_LINK_CONGESTED ; fs <=IBMVFC_AE_FPIN_CONGESTION_CLEARED ; fs++) { + ae[fs].valid =0x80 ; + ae[fs].link_state =IBMVFC_AE_LS_LINK_UP ; + ae[fs].fpin_status = fs; + ae[fs].event =cpu_to_be64 (IBMVFC_AE_FPIN ); + ae[fs].scsi_id =cpu_to_be64 (tgt->scsi_id); + ae[fs].wwpn =cpu_to_be64 (tgt->wwpn); + ae[fs].node_name =cpu_to_be64 (tgt->ids.node_name); +ibmvfc_handle_async (&ae[fs], vhost);
[Severity: Medium]
Does this invocation of ibmvfc_handle_async() need to be protected by the host_lock?
If a concurrent device removal via ibmvfc_remove() sets vhost->state to IBMVFC_HOST_OFFLINE and destroys fpin_workq just before this handles the async event, could queue_work() be called on a freed workqueue?
Quoted 4 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +4
-0+ ae[fs].valid =0 ; +wmb ();/* ensure valid bit clear is visible before checking stats */ + } +flush_workqueue (vhost->fpin_workq);
[ ... ]
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 110
Quoted 8 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +8
-0+ ae[0 ].valid =0x80 ; + ae[0 ].link_state =IBMVFC_AE_LS_LINK_UP ; + ae[0 ].fpin_status =0 ;/* bad value */ + ae[0 ].event =cpu_to_be64 (IBMVFC_AE_FPIN ); + ae[0 ].scsi_id =cpu_to_be64 (tgt->scsi_id); + ae[0 ].wwpn =cpu_to_be64 (tgt->wwpn); + ae[0 ].node_name =cpu_to_be64 (tgt->ids.node_name); +ibmvfc_handle_async (&ae[0 ], vhost);
[Severity: Medium]
Is the host_lock similarly required around this call to ibmvfc_handle_async() to prevent a use-after-free if the device is concurrently unbound?
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+ ae[0 ].valid =0 ; +wmb ();/* ensure valid bit clear is visible before checking stats */ +flush_workqueue (vhost->fpin_workq);
[ ... ]
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 134
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+kref_put (&tgt->kref, ibmvfc_release_tgt); +put_device (&rport->dev); +}
[Severity: Medium]
Does this successful exit path leak the Scsi_Host reference?
The call to ibmvfc_get_first_vhost() at the beginning of the test acquires a reference via scsi_host_get(), but unlike the error return paths, there doesn't appear to be a corresponding scsi_host_put() call here.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v11 04/11] scsi: ibmvfc: add basic FPIN support
Quoted 43 lines · [email protected] writes:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] scsi: ibmvfc: missingscsi_host_put()in test success path
- [Medium] scsi: ibmvfc: missinghost_lockaroundibmvfc_handle_async()in KUnit test --commit
29ab8a9a78c94679b8187ae357d2978336830599
Author: Dave Marquardt <[email protected]>scsi: ibmvfc: add basic FPIN support
Implement support for a basic level of Fabric Performance Impact Notifications (FPIN) in the ibmvfc driver to enable monitoring of fabric congestion and link integrity events. This includes async event handling and KUnit test infrastructure.
Quoted 6 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +0
-0@@ -0,0 +1,149 @@[ ... ]
Quoted 2 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +2
-0+static void ibmvfc_async_fpin_test (struct kunit *test) +{[ ... ]
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+ vhost =ibmvfc_get_first_vhost (); +if (!vhost) +kunit_skip (test,"No ibmvfc devices available" );[ ... ]
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 73
Quoted 9 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +9
-0+for (fs =IBMVFC_AE_FPIN_LINK_CONGESTED ; fs <=IBMVFC_AE_FPIN_CONGESTION_CLEARED ; fs++) { + ae[fs].valid =0x80 ; + ae[fs].link_state =IBMVFC_AE_LS_LINK_UP ; + ae[fs].fpin_status = fs; + ae[fs].event =cpu_to_be64 (IBMVFC_AE_FPIN ); + ae[fs].scsi_id =cpu_to_be64 (tgt->scsi_id); + ae[fs].wwpn =cpu_to_be64 (tgt->wwpn); + ae[fs].node_name =cpu_to_be64 (tgt->ids.node_name); +ibmvfc_handle_async (&ae[fs], vhost);[Severity: Medium]
Does this invocation ofibmvfc_handle_async()need to be protected by thehost_lock?
Quoted 3 lines
If a concurrent device removal via
ibmvfc_remove()setsvhost->statetoIBMVFC_HOST_OFFLINEand destroysfpin_workqjust before this handles the async event, couldqueue_work()be called on a freed workqueue?
Yes, this routine should acquire the host_lock before calling ibmvfc_handle_async.
Quoted 5 lines
Quoted 4 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +4
-0+ ae[fs].valid =0 ; +wmb ();/* ensure valid bit clear is visible before checking stats */ + } +flush_workqueue (vhost->fpin_workq);[ ... ]
Quoted 13 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 110
Quoted 8 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +8
-0+ ae[0 ].valid =0x80 ; + ae[0 ].link_state =IBMVFC_AE_LS_LINK_UP ; + ae[0 ].fpin_status =0 ;/* bad value */ + ae[0 ].event =cpu_to_be64 (IBMVFC_AE_FPIN ); + ae[0 ].scsi_id =cpu_to_be64 (tgt->scsi_id); + ae[0 ].wwpn =cpu_to_be64 (tgt->wwpn); + ae[0 ].node_name =cpu_to_be64 (tgt->ids.node_name); +ibmvfc_handle_async (&ae[0 ], vhost);[Severity: Medium]
Is thehost_locksimilarly required around this call toibmvfc_handle_async()to prevent a use-after-free if the device is concurrently unbound?
Yes.
Quoted 11 lines
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+ ae[0 ].valid =0 ; +wmb ();/* ensure valid bit clear is visible before checking stats */ +flush_workqueue (vhost->fpin_workq);[ ... ]
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 134
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+kref_put (&tgt->kref, ibmvfc_release_tgt); +put_device (&rport->dev); +}[Severity: Medium]
Does this successful exit path leak theScsi_Hostreference?
Quoted 3 lines
The call to
ibmvfc_get_first_vhost()at the beginning of the test acquires a reference viascsi_host_get(), but unlike the error return paths, there doesn't appear to be a correspondingscsi_host_put()call here.
Yes, this needs a scsi_host_put() call.
-Dave
Re: [PATCH v11 04/11] scsi: ibmvfc: add basic FPIN support
Quoted 45 lines · Dave Marquardt
Quoted 43 lines · [email protected] writes:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] scsi: ibmvfc: missingscsi_host_put()in test success path
- [Medium] scsi: ibmvfc: missinghost_lockaroundibmvfc_handle_async()in KUnit test --commit
29ab8a9a78c94679b8187ae357d2978336830599
Author: Dave Marquardt <[email protected]>scsi: ibmvfc: add basic FPIN support
Implement support for a basic level of Fabric Performance Impact Notifications (FPIN) in the ibmvfc driver to enable monitoring of fabric congestion and link integrity events. This includes async event handling and KUnit test infrastructure.
Quoted 6 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +0
-0@@ -0,0 +1,149 @@[ ... ]
Quoted 2 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +2
-0+static void ibmvfc_async_fpin_test (struct kunit *test) +{[ ... ]
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+ vhost =ibmvfc_get_first_vhost (); +if (!vhost) +kunit_skip (test,"No ibmvfc devices available" );[ ... ]
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 73
Quoted 9 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +9
-0+for (fs =IBMVFC_AE_FPIN_LINK_CONGESTED ; fs <=IBMVFC_AE_FPIN_CONGESTION_CLEARED ; fs++) { + ae[fs].valid =0x80 ; + ae[fs].link_state =IBMVFC_AE_LS_LINK_UP ; + ae[fs].fpin_status = fs; + ae[fs].event =cpu_to_be64 (IBMVFC_AE_FPIN ); + ae[fs].scsi_id =cpu_to_be64 (tgt->scsi_id); + ae[fs].wwpn =cpu_to_be64 (tgt->wwpn); + ae[fs].node_name =cpu_to_be64 (tgt->ids.node_name); +ibmvfc_handle_async (&ae[fs], vhost);[Severity: Medium]
Does this invocation ofibmvfc_handle_async()need to be protected by thehost_lock?
Quoted 5 lines
Quoted 3 lines
If a concurrent device removal via
ibmvfc_remove()setsvhost->statetoIBMVFC_HOST_OFFLINEand destroysfpin_workqjust before this handles the async event, couldqueue_work()be called on a freed workqueue?Yes, this routine should acquire the
host_lockbefore callingibmvfc_handle_async.
So, the host_lock is taken early in the routine and held in this case. I'm getting mixed messages in my research on whether return or something like KUNIT_FAIL() is required after kunit_skip(). I will add return statements.
Quoted 21 lines
Quoted 5 lines
Quoted 4 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +4
-0+ ae[fs].valid =0 ; +wmb ();/* ensure valid bit clear is visible before checking stats */ + } +flush_workqueue (vhost->fpin_workq);[ ... ]
Quoted 13 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 110
Quoted 8 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +8
-0+ ae[0 ].valid =0x80 ; + ae[0 ].link_state =IBMVFC_AE_LS_LINK_UP ; + ae[0 ].fpin_status =0 ;/* bad value */ + ae[0 ].event =cpu_to_be64 (IBMVFC_AE_FPIN ); + ae[0 ].scsi_id =cpu_to_be64 (tgt->scsi_id); + ae[0 ].wwpn =cpu_to_be64 (tgt->wwpn); + ae[0 ].node_name =cpu_to_be64 (tgt->ids.node_name); +ibmvfc_handle_async (&ae[0 ], vhost);[Severity: Medium]
Is thehost_locksimilarly required around this call toibmvfc_handle_async()to prevent a use-after-free if the device is concurrently unbound?Yes.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+ ae[0 ].valid =0 ; +wmb ();/* ensure valid bit clear is visible before checking stats */ +flush_workqueue (vhost->fpin_workq);[ ... ]
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 134
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+kref_put (&tgt->kref, ibmvfc_release_tgt); +put_device (&rport->dev); +}
-Dave
Re: [PATCH v11 04/11] scsi: ibmvfc: add basic FPIN support
Quoted 51 lines · Dave Marquardt
Quoted 49 lines · Dave Marquardt
Quoted 46 lines · [email protected] writes:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] scsi: ibmvfc: missingscsi_host_put()in test success path
- [Medium] scsi: ibmvfc: missinghost_lockaroundibmvfc_handle_async()in KUnit test --commit
29ab8a9a78c94679b8187ae357d2978336830599
Author: Dave Marquardt <[email protected]>scsi: ibmvfc: add basic FPIN support
Implement support for a basic level of Fabric Performance Impact Notifications (FPIN) in the ibmvfc driver to enable monitoring of fabric congestion and link integrity events. This includes async event handling and KUnit test infrastructure.
Quoted 6 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +0
-0@@ -0,0 +1,149 @@[ ... ]
Quoted 2 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +2
-0+static void ibmvfc_async_fpin_test (struct kunit *test) +{[ ... ]
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +3
-0+ vhost =ibmvfc_get_first_vhost (); +if (!vhost) +kunit_skip (test,"No ibmvfc devices available" );[ ... ]
drivers/scsi/ibmvscsi/ibmvfc_kunit.c line 73
Quoted 9 lines
drivers/scsi/ibmvscsi/ibmvfc_kunit.c new file +9
-0+for (fs =IBMVFC_AE_FPIN_LINK_CONGESTED ; fs <=IBMVFC_AE_FPIN_CONGESTION_CLEARED ; fs++) { + ae[fs].valid =0x80 ; + ae[fs].link_state =IBMVFC_AE_LS_LINK_UP ; + ae[fs].fpin_status = fs; + ae[fs].event =cpu_to_be64 (IBMVFC_AE_FPIN ); + ae[fs].scsi_id =cpu_to_be64 (tgt->scsi_id); + ae[fs].wwpn =cpu_to_be64 (tgt->wwpn); + ae[fs].node_name =cpu_to_be64 (tgt->ids.node_name); +ibmvfc_handle_async (&ae[fs], vhost);[Severity: Medium]
Does this invocation ofibmvfc_handle_async()need to be protected by thehost_lock?If a concurrent device removal via
ibmvfc_remove()setsvhost->statetoIBMVFC_HOST_OFFLINEand destroysfpin_workqjust before this handles the async event, couldqueue_work()be called on a freed workqueue?
Quoted 6 lines
Quoted 1 line
Yes, this routine should acquire the
host_lockbefore callingibmvfc_handle_async.So, the
host_lockis taken early in the routine and held in this case. I'm getting mixed messages in my research on whether return or something likeKUNIT_FAIL()is required afterkunit_skip(). I will add return statements.
Contemplating this a little longer, I don't think any change is needed here. I think this is a false positive by Sashiko. Is it confused by kunit_skip() calls?
-Dave
Tyrel Datwyler
maintainerPATCH v11 5/11 scsi: ibmvfc: add NOOP command support
In reply to Tyrel DatwylerFrom: Dave Marquardt <[email protected]>
Add support for handling IBMVFC_NOOP format CRQ messages from the VIOS partner.
Advertise the client's ability to handle NOOP commands by setting the IBMVFC_CAN_USE_NOOP_CMD capability in ibmvfc_set_login_info().
Handle and ignore IBMVFC_NOOP format messages in both ibmvfc_handle_crq() and ibmvfc_handle_scrq(). In both handlers, log a rate-limited error if a NOOP is received while in the IBMVFC_ACTIVE state without the partner having advertised IBMVFC_SUPPORT_NOOP_CMD.
In ibmvfc_handle_scrq(), also fix a typo ("Got and invalid" -> "Got an invalid"), add a missing return on invalid message types, and guard against null event pointers before processing CRQ responses.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/scsi/ibmvscsi/ibmvfc-core.c +25 -2
@@ -1578,7 +1578,9 @@ static void ibmvfc_set_login_info(struct ibmvfc_host *vhost) login_info->flags |=cpu_to_be16 (IBMVFC_CLIENT_MIGRATED ); login_info->max_cmds =cpu_to_be32 (max_cmds); - login_info->capabilities =cpu_to_be64 (IBMVFC_CAN_MIGRATE |IBMVFC_CAN_SEND_VF_WWPN ); + login_info->capabilities = +cpu_to_be64 (IBMVFC_CAN_MIGRATE |IBMVFC_CAN_SEND_VF_WWPN | +IBMVFC_CAN_USE_NOOP_CMD );if (vhost->mq_enabled || vhost->using_channels) { login_info->capabilities |=cpu_to_be64 (IBMVFC_CAN_USE_CHANNELS );
@@ -3695,6 +3697,14 @@ static void ibmvfc_handle_crq(struct ibmvfc_crq *crq, struct ibmvfc_host *vhost,if (crq->format ==IBMVFC_ASYNC_EVENT )return ; +if (crq->format ==IBMVFC_NOOP ) { +if (vhost->state ==IBMVFC_ACTIVE && + !ibmvfc_check_caps (vhost,IBMVFC_SUPPORT_NOOP_CMD )) +dev_err_ratelimited (vhost->dev, +"Received unexpected NOOP command from partner\n" ); +return ; + } +/* The only kind of payload CRQs we should get are responses to * things we send. Make sure this response is to something we * actually sent
@@ -4225,7 +4235,20 @@ static void ibmvfc_handle_scrq(struct ibmvfc_crq *crq, struct ibmvfc_host *vhostcase IBMVFC_CRQ_XPORT_EVENT :return ;default : -dev_err (vhost->dev,"Got and invalid message type 0x%02x\n" , crq->valid); +dev_err (vhost->dev,"Got an invalid message type 0x%02x\n" , crq->valid); +return ; + } + +if (crq->format ==IBMVFC_NOOP ) { +if (vhost->state ==IBMVFC_ACTIVE && + !ibmvfc_check_caps (vhost,IBMVFC_SUPPORT_NOOP_CMD )) +dev_err_ratelimited (vhost->dev, +"Received unexpected NOOP command from partner\n" ); +return ; + } + +if (unlikely (!evt)) { +dev_err (vhost->dev,"Received null event\n" );return ; }
Signature · 1 line
2.55.0
Tyrel Datwyler
maintainerPATCH v11 6/11 scsi: ibmvfc: add FPIN extended flag and async sub-CRQ queue handle
In reply to Tyrel DatwylerFrom: Dave Marquardt <[email protected]>
Add IBMVFC_ASYNC_IS_FPIN_EXT flag bit (0x02) to ibmvfc_async_sub_crq.flags to distinguish extended FPIN events from standard ones.
Add async_scrqs field of type ibmvfc_channels to ibmvfc_host to hold the channel set for the asynchronous sub-CRQ, alongside the existing scsi_scrqs and nvme_scrqs channels. This uses the same ibmvfc_channels infrastructure as the SCSI and NVMe channel queues.
Add IBMVFC_ASYNC_SUB_CRQ_FMT to enum ibmvfc_msg_fmt and a corresponding async_scrq pointer to union ibmvfc_msgs to support the new async sub-CRQ message format.
--- drivers/scsi/ibmvscsi/ibmvfc.h | 4 ++++ 1 file changed, 4 insertions(+)
drivers/scsi/ibmvscsi/ibmvfc.h +4 -0
@@ -773,6 +773,7 @@ struct ibmvfc_async_sub_crq {volatile u8 valid;u8 flags;#define IBMVFC_ASYNC_ID_IS_ASSOC_ID 0x01 +#define IBMVFC_ASYNC_IS_FPIN_EXT 0x02u8 link_state;u8 fpin_status;__be16 event;
@@ -893,6 +894,7 @@ enum ibmvfc_msg_fmt {IBMVFC_CRQ_FMT =0 ,IBMVFC_ASYNC_FMT ,IBMVFC_SUB_CRQ_FMT , + IBMVFC_ASYNC_SUB_CRQ_FMT, }; union ibmvfc_msgs {
@@ -900,6 +902,7 @@ union ibmvfc_msgs {struct ibmvfc_crq *crq;struct ibmvfc_async_crq *async;struct ibmvfc_sub_crq *scrq; +struct ibmvfc_async_sub_crq *async_scrq; };struct ibmvfc_queue {
@@ -992,6 +995,7 @@ struct ibmvfc_host {struct ibmvfc_queue async_crq;struct ibmvfc_channels scsi_scrqs;struct ibmvfc_channels nvme_scrqs; +struct ibmvfc_channels async_scrqs;struct ibmvfc_npiv_login login_info;union ibmvfc_npiv_login_data *login_buf;dma_addr_t login_buf_dma;
Signature · 1 line
2.55.0
Tyrel Datwyler
maintainerPATCH v11 7/11 scsi: ibmvfc: extend async event handlers for async sub-CRQ events
In reply to Tyrel DatwylerFrom: Dave Marquardt <[email protected]>
Refactor async event handling to support both traditional async CRQs and new asynchronous sub-queue CRQs.
Introduce struct ibmvfc_async_crq_event, a tagged union that wraps either an ibmvfc_async_crq (main CRQ) or an ibmvfc_async_sub_crq (async sub-CRQ), with an enum ibmvfc_async_crq_type discriminator. Replace the ibmvfc_async_work bare union and is_subq bool with a single event field of this type.
Modify ibmvfc_handle_async() to accept a struct ibmvfc_async_crq_event * instead of a void * plus a bool flag. Update ibmvfc_process_async_work() to dispatch based on event.type.
Add ibmvfc_full_fpin_to_desc() to convert full FPIN messages from async sub-queue format to fc_els_fpin structures. Update FPIN processing logic to extract WWPN, node_name, and scsi_id from the appropriate union member based on event type.
Update KUnit tests to use struct ibmvfc_async_crq_event arrays at call sites.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 163 +++++++++++++++++++++------ drivers/scsi/ibmvscsi/ibmvfc.h | 18 ++- drivers/scsi/ibmvscsi/ibmvfc_kunit.c | 161 +++++++++++++++++++++++--- 3 files changed, 285 insertions(+), 57 deletions(-)
drivers/scsi/ibmvscsi/ibmvfc-core.c +126 -37
@@ -3426,6 +3426,45 @@ ibmvfc_basic_fpin_to_desc(struct ibmvfc_async_crq *crq, u64 wwpn) cpu_to_be32(1)); } +/** +* ibmvfc_full_fpin_to_desc(): allocate and populate a struct fc_els_fpin struct +* containing a descriptor. +* @ibmvfc_fpin: Pointer to async subq FPIN data +* +* Allocate a struct fc_els_fpin containing a descriptor and populate +* based on data from *ibmvfc_fpin. +* +* Return: +* NULL - unable to allocate structure +* non-NULL - pointer to populated struct fc_els_fpin +*/ +static struct fc_els_fpin * +ibmvfc_full_fpin_to_desc (struct ibmvfc_async_sub_crq *ibmvfc_fpin) +{ +__be16 type; + +switch (ibmvfc_fpin->fpin_status) { +case IBMVFC_AE_FPIN_LINK_CONGESTED : +case IBMVFC_AE_FPIN_PORT_CONGESTED : + type =cpu_to_be16 (FPIN_CONGN_DEVICE_SPEC ); +break ; +case IBMVFC_AE_FPIN_PORT_CLEARED : +case IBMVFC_AE_FPIN_CONGESTION_CLEARED : + type =cpu_to_be16 (FPIN_CONGN_CLEAR ); +break ; +case IBMVFC_AE_FPIN_PORT_DEGRADED : + type =cpu_to_be16 (FPIN_LI_UNKNOWN ); +break ; +default : +return NULL ; + } + +return ibmvfc_common_fpin_to_desc (ibmvfc_fpin->fpin_status, ibmvfc_fpin->wwpn, + type,cpu_to_be16 (0 ), +cpu_to_be32 (IBMVFC_FPIN_DEFAULT_EVENT_THRESHOLD ), +cpu_to_be32 (1 )); +} +/** * ibmvfc_find_target - Search for a target in a target list * @target_list: list head of targets to search
@@ -3463,28 +3502,40 @@ static struct ibmvfc_target *ibmvfc_find_target(struct list_head *target_list,*/ static void ibmvfc_process_async_work (struct work_struct *work) { +struct ibmvfc_async_sub_crq *subq =NULL ;struct ibmvfc_async_work *aw; -struct ibmvfc_async_crq *crq; +struct ibmvfc_async_crq *crq =NULL ;struct ibmvfc_target *tgt;struct ibmvfc_host *vhost; -struct fc_els_fpin *fpin; +struct fc_els_fpin *fpin =NULL ;unsigned long flags; +__be64 node_name; +__be64 scsi_id; +__be64 wwpn; aw = container_of_const(work, struct ibmvfc_async_work, async_work_s); vhost = aw->vhost; - crq = &aw->crq; +if (aw->event.type ==IBMVFC_ASYNC_CRQ_SUB ) { + subq = &aw->event.subq; + scsi_id =0 ; + wwpn = subq->wwpn; + node_name = (subq->flags &IBMVFC_ASYNC_ID_IS_ASSOC_ID ) ?0 : subq->id.node_name; + }else { + crq = &aw->event.async_crq; + scsi_id = crq->scsi_id; + wwpn = crq->wwpn; + node_name = crq->node_name; + } -if (!crq->scsi_id && !crq->wwpn && !crq->node_name) +if (!scsi_id && !wwpn && !node_name) goto free;spin_lock_irqsave (vhost->host->host_lock, flags); - tgt =ibmvfc_find_target (&vhost->scsi_scrqs.targets, crq->scsi_id, - crq->wwpn, crq->node_name); + tgt =ibmvfc_find_target (&vhost->scsi_scrqs.targets, scsi_id, wwpn, node_name); +if (!tgt) {/* Target not found in scsi_scrqs, search nvme_scrqs */ - tgt =ibmvfc_find_target (&vhost->nvme_scrqs.targets, - crq->scsi_id, crq->wwpn, - crq->node_name); + tgt =ibmvfc_find_target (&vhost->nvme_scrqs.targets, scsi_id, wwpn, node_name); }if (tgt) {
@@ -3496,7 +3547,11 @@ static void ibmvfc_process_async_work(struct work_struct *work) goto free; } - fpin =ibmvfc_basic_fpin_to_desc (crq, tgt->wwpn); +if (crq) + fpin =ibmvfc_basic_fpin_to_desc (crq, tgt->wwpn); +else + fpin =ibmvfc_full_fpin_to_desc (subq); +if (fpin) { fc_host_fpin_rcv(tgt->vhost->host, sizeof(*fpin) + be32_to_cpu(fpin->desc_len),
@@ -3512,25 +3567,51 @@ static void ibmvfc_process_async_work(struct work_struct *work)/** * ibmvfc_handle_async - Handle an async event from the adapter -* @crq: crq to process +* @ae: tagged union wrapping either an ibmvfc_async_crq (main CRQ) or an +* ibmvfc_async_sub_crq (async sub-CRQ); the type field identifies which * @vhost: ibmvfc host struct * **/ -VISIBLE_IF_KUNIT void ibmvfc_handle_async(struct ibmvfc_async_crq *crq, +VISIBLE_IF_KUNIT void ibmvfc_handle_async(struct ibmvfc_async_crq_event *ae,struct ibmvfc_host *vhost) { -const struct ibmvfc_async_desc *desc =ibmvfc_get_ae_desc (be64_to_cpu (crq->event)); +struct ibmvfc_async_crq *async_crq =NULL ; +struct ibmvfc_async_sub_crq *subq =NULL ; +const struct ibmvfc_async_desc *desc;struct ibmvfc_async_work *aw;struct ibmvfc_target *tgt; - -ibmvfc_log (vhost, desc->log_level,"%s event received. scsi_id: %llx, wwpn: %llx," -" node_name: %llx%s\n" , desc->desc,be64_to_cpu (crq->scsi_id), -be64_to_cpu (crq->wwpn),be64_to_cpu (crq->node_name), -ibmvfc_get_link_state (crq->link_state)); - -switch (be64_to_cpu (crq->event)) { +__be64 node_name; +__be64 scsi_id; +u8 link_state; +__be64 wwpn; +u64 event; + +if (ae->type ==IBMVFC_ASYNC_CRQ_SUB ) { + subq = &ae->subq; + event =be16_to_cpu (subq->event); + link_state = subq->link_state; + scsi_id =0 ; + wwpn = subq->wwpn; + node_name = subq->flags &IBMVFC_ASYNC_ID_IS_ASSOC_ID ?0 : subq->id.node_name; + }else { + async_crq = &ae->async_crq; + event =be64_to_cpu (async_crq->event); + link_state = async_crq->link_state; + scsi_id = async_crq->scsi_id; + wwpn = async_crq->wwpn; + node_name = async_crq->node_name; + } + + desc =ibmvfc_get_ae_desc (event); +ibmvfc_log (vhost, desc->log_level, +"%s event received. scsi_id: %llx, wwpn: %llx, node_name: %llx, event %llx%s\n" , + desc->desc,be64_to_cpu (scsi_id), +be64_to_cpu (wwpn),be64_to_cpu (node_name), event, +ibmvfc_get_link_state (link_state)); + +switch (event) {case IBMVFC_AE_RESUME : -switch (crq->link_state) { +switch (link_state) {case IBMVFC_AE_LS_LINK_DOWN :ibmvfc_link_down (vhost,IBMVFC_LINK_DOWN );break ;
@@ -3569,33 +3650,33 @@ VISIBLE_IF_KUNIT void ibmvfc_handle_async(struct ibmvfc_async_crq *crq,case IBMVFC_AE_ELS_PRLO :case IBMVFC_AE_ELS_PLOGI :list_for_each_entry (tgt, &vhost->scsi_scrqs.targets, queue) { -if (!crq->scsi_id && !crq->wwpn && !crq->node_name) +if (!scsi_id && !wwpn && !node_name)break ; -if (crq->scsi_id &&cpu_to_be64 (tgt->scsi_id) != crq->scsi_id) +if (scsi_id &&cpu_to_be64 (tgt->scsi_id) != scsi_id)continue ; -if (crq->wwpn &&cpu_to_be64 (tgt->ids.port_name) != crq->wwpn) +if (wwpn &&cpu_to_be64 (tgt->ids.port_name) != wwpn)continue ; -if (crq->node_name &&cpu_to_be64 (tgt->ids.node_name) != crq->node_name) +if (node_name &&cpu_to_be64 (tgt->ids.node_name) != node_name)continue ; -if (tgt->need_login &&be64_to_cpu (crq->event) ==IBMVFC_AE_ELS_LOGO ) +if (tgt->need_login && event ==IBMVFC_AE_ELS_LOGO ) tgt->logo_rcvd =1 ; -if (!tgt->need_login ||be64_to_cpu (crq->event) ==IBMVFC_AE_ELS_PLOGI ) { +if (!tgt->need_login || event ==IBMVFC_AE_ELS_PLOGI ) {ibmvfc_del_tgt (tgt);ibmvfc_reinit_host (vhost); } }list_for_each_entry (tgt, &vhost->nvme_scrqs.targets, queue) { -if (!crq->scsi_id && !crq->wwpn && !crq->node_name) +if (!scsi_id && !wwpn && !node_name)break ; -if (crq->scsi_id &&cpu_to_be64 (tgt->scsi_id) != crq->scsi_id) +if (scsi_id &&cpu_to_be64 (tgt->scsi_id) != scsi_id)continue ; -if (crq->wwpn &&cpu_to_be64 (tgt->ids.port_name) != crq->wwpn) +if (wwpn &&cpu_to_be64 (tgt->ids.port_name) != wwpn)continue ; -if (crq->node_name &&cpu_to_be64 (tgt->ids.node_name) != crq->node_name) +if (node_name &&cpu_to_be64 (tgt->ids.node_name) != node_name)continue ; -if (tgt->need_login &&be64_to_cpu (crq->event) ==IBMVFC_AE_ELS_LOGO ) +if (tgt->need_login && event ==IBMVFC_AE_ELS_LOGO ) tgt->logo_rcvd =1 ; -if (!tgt->need_login ||be64_to_cpu (crq->event) ==IBMVFC_AE_ELS_PLOGI ) { +if (!tgt->need_login || event ==IBMVFC_AE_ELS_PLOGI ) {ibmvfc_del_tgt (tgt);ibmvfc_reinit_host (vhost); }
@@ -3618,14 +3699,14 @@ VISIBLE_IF_KUNIT void ibmvfc_handle_async(struct ibmvfc_async_crq *crq,if (aw) {INIT_WORK (&aw->async_work_s, ibmvfc_process_async_work); aw->vhost = vhost; - aw->crq = *crq; + aw->event = *ae;queue_work (vhost->fpin_workq, &aw->async_work_s); }else dev_err_ratelimited (vhost->dev,"can't offload async CRQ to work queue\n" );break ;default : -dev_err (vhost->dev,"Unknown async event received: %lld\n" , crq->event); +dev_err (vhost->dev,"Unknown async event received: %llu\n" , event);break ; } }
@@ -4166,7 +4247,11 @@ static void ibmvfc_tasklet(void *data)while (!done) {/* Pull all the valid messages off the async CRQ */ while ((async =ibmvfc_next_async_crq (vhost)) !=NULL ) { -ibmvfc_handle_async (async, vhost); +struct ibmvfc_async_crq_event ae = { + .type =IBMVFC_ASYNC_CRQ_MAIN , + .async_crq = *async, + }; +ibmvfc_handle_async (&ae, vhost); async->valid =0 ;wmb (); }
@@ -4180,8 +4265,12 @@ static void ibmvfc_tasklet(void *data)vio_enable_interrupts (vdev);if ((async =ibmvfc_next_async_crq (vhost)) !=NULL ) { +struct ibmvfc_async_crq_event ae = { + .type =IBMVFC_ASYNC_CRQ_MAIN , + .async_crq = *async, + };vio_disable_interrupts (vdev); -ibmvfc_handle_async (async, vhost); +ibmvfc_handle_async (&ae, vhost); async->valid =0 ;wmb (); }else if ((crq =ibmvfc_next_crq (vhost)) !=NULL ) {
drivers/scsi/ibmvscsi/ibmvfc.h +16 -2
@@ -786,9 +786,22 @@ struct ibmvfc_async_sub_crq { } id; } __packed__aligned(8) ; +enum ibmvfc_async_crq_type { +IBMVFC_ASYNC_CRQ_MAIN =0 , +IBMVFC_ASYNC_CRQ_SUB , +}; + +struct ibmvfc_async_crq_event { +enum ibmvfc_async_crq_type type; +union { +struct ibmvfc_async_crq async_crq; +struct ibmvfc_async_sub_crq subq; + }; +}; +struct ibmvfc_async_work {struct ibmvfc_host *vhost; -struct ibmvfc_async_crq crq; +struct ibmvfc_async_crq_event event;struct work_struct async_work_s; };
@@ -1105,7 +1118,8 @@ static inline struct ibmvfc_host *ibmvfc_channels_to_vhost(struct ibmvfc_channel#if IS_ENABLED (CONFIG_KUNIT )#include <kunit/visibility.h> -VISIBLE_IF_KUNIT void ibmvfc_handle_async(struct ibmvfc_async_crq *crq, struct ibmvfc_host *vhost); +VISIBLE_IF_KUNIT void ibmvfc_handle_async(struct ibmvfc_async_crq_event *event, +struct ibmvfc_host *vhost); VISIBLE_IF_KUNIT struct ibmvfc_host *ibmvfc_get_first_vhost(void);#endif
drivers/scsi/ibmvscsi/ibmvfc_kunit.c +143 -18
195 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v11 07/11] scsi: ibmvfc: extend async event handlers for async sub-CRQ events
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] scsi: ibmvfc: FPIN descriptor uses potentially unpopulated WWPN from sub-CRQ --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scsi: ibmvfc: FPIN descriptor uses potentially unpopulated WWPN from sub-CRQ --
commit 8a1ab5ee327462636518cdba29b91df0f867bb9f
Author: Dave Marquardt <[email protected]>
scsi: ibmvfc: extend async event handlers for async sub-CRQ events
This commit refactors async event handling to support both traditional async CRQs and new asynchronous sub-queue CRQs. It introduces a tagged union that wraps the async event and dispatches processing based on event type.
Quoted 24 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +16
-0@@ -3426,6 +3426,45 @@ ibmvfc_basic_fpin_to_desc(struct ibmvfc_async_crq *crq, u64 wwpn) cpu_to_be32(1)); } +/** +* ibmvfc_full_fpin_to_desc(): allocate and populate a struct fc_els_fpin struct +* containing a descriptor. +* @ibmvfc_fpin: Pointer to async subq FPIN data +* +* Allocate a struct fc_els_fpin containing a descriptor and populate +* based on data from *ibmvfc_fpin. +* +* Return: +* NULL - unable to allocate structure +* non-NULL - pointer to populated struct fc_els_fpin +*/ +static struct fc_els_fpin * +ibmvfc_full_fpin_to_desc (struct ibmvfc_async_sub_crq *ibmvfc_fpin) +{ +__be16 type;
[ ... ]
Quoted 5 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +5
-0+return ibmvfc_common_fpin_to_desc (ibmvfc_fpin->fpin_status, ibmvfc_fpin->wwpn, + type,cpu_to_be16 (0 ), +cpu_to_be32 (IBMVFC_FPIN_DEFAULT_EVENT_THRESHOLD ), +cpu_to_be32 (1 )); +}
[ ... ]
Quoted 4 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +0
-0@@ -3463,28 +3502,40 @@ static struct ibmvfc_target *ibmvfc_find_target(struct list_head *target_list,*/ static void ibmvfc_process_async_work (struct work_struct *work) {
[ ... ]
drivers/scsi/ibmvscsi/ibmvfc-core.c static void ibmvfc_process_async_work(struct work_struct *work) · line 3554
Quoted 10 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +5
-1@@ -3496,7 +3547,11 @@ static void ibmvfc_process_async_work(struct work_struct *work) goto free; } - fpin =ibmvfc_basic_fpin_to_desc (crq, tgt->wwpn); +if (crq) + fpin =ibmvfc_basic_fpin_to_desc (crq, tgt->wwpn); +else + fpin =ibmvfc_full_fpin_to_desc (subq); +
[Severity: Medium]
If the hardware sends an async sub-CRQ FPIN event lacking a WWPN but providing a valid node_name or scsi_id, the driver successfully resolves the target (tgt) earlier in this function.
However, ibmvfc_full_fpin_to_desc() uses subq->wwpn instead of the resolved tgt->wwpn. Could this generate an FPIN descriptor with a zero attached WWPN, causing fc_host_fpin_rcv() to fail to match the target's rport and drop the congestion statistics update?
The legacy CRQ path safely passes tgt->wwpn via ibmvfc_basic_fpin_to_desc(). Should ibmvfc_full_fpin_to_desc() be updated to also take tgt->wwpn?
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +0
-0if (fpin) { fc_host_fpin_rcv(tgt->vhost->host, sizeof(*fpin) + be32_to_cpu(fpin->desc_len),
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [PATCH v11 07/11] scsi: ibmvfc: extend async event handlers for async sub-CRQ events
Quoted 71 lines · [email protected] writes:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scsi: ibmvfc: FPIN descriptor uses potentially unpopulated WWPN from sub-CRQ --commit
8a1ab5ee327462636518cdba29b91df0f867bb9f
Author: Dave Marquardt <[email protected]>scsi: ibmvfc: extend async event handlers for async sub-CRQ events
This commit refactors async event handling to support both traditional async CRQs and new asynchronous sub-queue CRQs. It introduces a tagged union that wraps the async event and dispatches processing based on event type.
Quoted 24 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +16
-0@@ -3426,6 +3426,45 @@ ibmvfc_basic_fpin_to_desc(struct ibmvfc_async_crq *crq, u64 wwpn) cpu_to_be32(1)); } +/** +* ibmvfc_full_fpin_to_desc(): allocate and populate a struct fc_els_fpin struct +* containing a descriptor. +* @ibmvfc_fpin: Pointer to async subq FPIN data +* +* Allocate a struct fc_els_fpin containing a descriptor and populate +* based on data from *ibmvfc_fpin. +* +* Return: +* NULL - unable to allocate structure +* non-NULL - pointer to populated struct fc_els_fpin +*/ +static struct fc_els_fpin * +ibmvfc_full_fpin_to_desc (struct ibmvfc_async_sub_crq *ibmvfc_fpin) +{ +__be16 type;[ ... ]
Quoted 5 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +5
-0+return ibmvfc_common_fpin_to_desc (ibmvfc_fpin->fpin_status, ibmvfc_fpin->wwpn, + type,cpu_to_be16 (0 ), +cpu_to_be32 (IBMVFC_FPIN_DEFAULT_EVENT_THRESHOLD ), +cpu_to_be32 (1 )); +}[ ... ]
Quoted 4 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +0
-0@@ -3463,28 +3502,40 @@ static struct ibmvfc_target *ibmvfc_find_target(struct list_head *target_list,*/ static void ibmvfc_process_async_work (struct work_struct *work) {[ ... ]
drivers/scsi/ibmvscsi/ibmvfc-core.c static void ibmvfc_process_async_work(struct work_struct *work) · line 3554
Quoted 10 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +5
-1@@ -3496,7 +3547,11 @@ static void ibmvfc_process_async_work(struct work_struct *work) goto free; } - fpin =ibmvfc_basic_fpin_to_desc (crq, tgt->wwpn); +if (crq) + fpin =ibmvfc_basic_fpin_to_desc (crq, tgt->wwpn); +else + fpin =ibmvfc_full_fpin_to_desc (subq); +[Severity: Medium]
If the hardware sends an async sub-CRQ FPIN event lacking a WWPN but providing a validnode_nameorscsi_id, the driver successfully resolves the target (tgt) earlier in this function.
Quoted 7 lines
However,
ibmvfc_full_fpin_to_desc()usessubq->wwpninstead of the resolvedtgt->wwpn. Could this generate an FPIN descriptor with a zero attached WWPN, causingfc_host_fpin_rcv()to fail to match the target's rport and drop the congestion statistics update?The legacy CRQ path safely passes
tgt->wwpnviaibmvfc_basic_fpin_to_desc(). Shouldibmvfc_full_fpin_to_desc()be updated to also taketgt->wwpn?
I agree. I've extended ibmvfc_full_fpin_to_desc() with a new u64 wwpn argument, similar to ibmvfc_basic_fpin_to_desc().
-Dave
Tyrel Datwyler
maintainerPATCH v11 8/11 scsi: ibmvfc: add interrupt routine for asynchronous sub CRQ
In reply to Tyrel DatwylerFrom: Dave Marquardt <[email protected]>
Add ibmvfc_interrupt_async_subq(), an IRQ handler dedicated to asynchronous sub-CRQ events from the adapter. The handler disables the sub-CRQ IRQ and then calls ibmvfc_drain_async_subq() to consume all pending entries before re-enabling interrupts.
ibmvfc_drain_async_subq() holds the per-queue q_lock while processing. It loops over available CRQ entries via ibmvfc_next_scrq(), wrapping each in a typed struct ibmvfc_async_crq_event and dispatching it to ibmvfc_handle_async(), then clears the valid bit and issues a write barrier. After draining, it re-enables the sub-CRQ IRQ and performs one final check for a newly arrived entry to close the IRQ-enable race; if one is found it is processed before exiting the loop.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
drivers/scsi/ibmvscsi/ibmvfc-core.c +54 -0
@@ -4377,6 +4377,60 @@ static struct ibmvfc_crq *ibmvfc_next_scrq(struct ibmvfc_queue *scrq)return crq; } +static void ibmvfc_drain_async_subq (struct ibmvfc_queue *scrq) +{ +struct ibmvfc_host *vhost = scrq->vhost; +unsigned long flags; +struct ibmvfc_crq *crq; +int done =0 ; + +spin_lock_irqsave (vhost->host->host_lock, flags); +spin_lock (scrq->q_lock); +while (!done) { +while ((crq =ibmvfc_next_scrq (scrq)) !=NULL ) { +struct ibmvfc_async_crq_event ae = { + .type =IBMVFC_ASYNC_CRQ_SUB , + .subq = *(struct ibmvfc_async_sub_crq *)crq, + }; +ibmvfc_handle_async (&ae, scrq->vhost); + crq->valid =0 ; +wmb ();/* complete write */ + } + +ibmvfc_toggle_scrq_irq (scrq,1 ); + crq =ibmvfc_next_scrq (scrq); +if (crq !=NULL ) { +struct ibmvfc_async_crq_event ae = { + .type =IBMVFC_ASYNC_CRQ_SUB , + .subq = *(struct ibmvfc_async_sub_crq *)crq, + }; +ibmvfc_toggle_scrq_irq (scrq,0 ); +ibmvfc_handle_async (&ae, scrq->vhost); + crq->valid =0 ; +wmb ();/* complete write */ + }else + done =1 ; + } +spin_unlock (scrq->q_lock); +spin_unlock_irqrestore (vhost->host->host_lock, flags); +} + +/** +* ibmvfc_interrupt_async_subq - Handle an async event from the adapter +* @irq: interrupt request +* @scrq_instance: async subq +* +**/ +static irqreturn_t __maybe_unused ibmvfc_interrupt_async_subq (int irq,void *scrq_instance) +{ +struct ibmvfc_queue *scrq = (struct ibmvfc_queue *)scrq_instance; + +ibmvfc_toggle_scrq_irq (scrq,0 ); +ibmvfc_drain_async_subq (scrq); + +return IRQ_HANDLED ; +} +static void ibmvfc_drain_sub_crq (struct ibmvfc_queue *scrq) {struct ibmvfc_crq *crq;
Signature · 1 line
2.55.0
Tyrel Datwyler
maintainerPATCH v11 9/11 scsi: ibmvfc: extend channel reg/dereg helpers for async sub-CRQ
In reply to Tyrel DatwylerFrom: Dave Marquardt <[email protected]>
ibmvfc_register_channel() and ibmvfc_deregister_channel() previously only handled SCSI and NVMe sub-CRQ channels identified by the channel protocol (IBMVFC_PROTO_SCSI, IBMVFC_PROTO_NVME). The async sub-CRQ had no registration path through these helpers, requiring separate handling.
Add a new IBMVFC_PROTO_ASYNC protocol value to enum ibmvfc_protocol. Extend both functions to handle IBMVFC_PROTO_ASYNC channels: the IRQ is named "ibmvfc-<addr>-async<index>" and the handler is set to ibmvfc_interrupt_async_subq rather than the per-protocol ibmvfc_interrupt_mq handler.
Remove the __maybe_unused annotation from ibmvfc_interrupt_async_subq now that it is referenced in ibmvfc_register_channel().
Error messages in both paths are updated to include the channel protocol to distinguish async sub-CRQ failures from SCSI/NVMe sub-CRQ failures. Kernel-doc headers are added to both functions.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 46 +++++++++++++++++++++++++---- drivers/scsi/ibmvscsi/ibmvfc.h | 1 + 2 files changed, 42 insertions(+), 5 deletions(-)
drivers/scsi/ibmvscsi/ibmvfc-core.c +41 -5
@@ -4421,7 +4421,7 @@ static void ibmvfc_drain_async_subq(struct ibmvfc_queue *scrq)* @scrq_instance: async subq * **/ -static irqreturn_t __maybe_unused ibmvfc_interrupt_async_subq (int irq,void *scrq_instance) +static irqreturn_t ibmvfc_interrupt_async_subq (int irq,void *scrq_instance) {struct ibmvfc_queue *scrq = (struct ibmvfc_queue *)scrq_instance;
@@ -6812,6 +6812,21 @@ static int ibmvfc_init_crq(struct ibmvfc_host *vhost)return retrc; } +/** +* ibmvfc_register_channel - Register a sub-CRQ channel with the hypervisor +* @vhost: ibmvfc host struct +* @channels: ibmvfc channels struct containing the channel array and protocol +* @index: index into the channels array for the queue to register, or +* a negative value to register the async sub-CRQ +* +* Register a sub-CRQ with the hypervisor via h_reg_sub_crq, map its hardware +* IRQ to a Linux IRQ, and bind an interrupt handler to it. The handler is +* selected based on the channel protocol (SCSI or NVMe) for normal queues, or +* set to the async sub-CRQ handler when @index is negative. +* +* Return value: +* 0 on success / non-zero on failure +**/ static int ibmvfc_register_channel (struct ibmvfc_host *vhost,struct ibmvfc_channels *channels,int index)
@@ -6839,7 +6854,8 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost,if (!scrq->irq) { rc = -EINVAL ; -dev_err (dev,"Error mapping sub-crq[%d] irq\n" , index); +dev_err (dev,"Error mapping protocol (%d) sub-crq[%d] irq\n" , + channels->protocol, index); goto irq_failed; }
@@ -6854,6 +6870,11 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost, vdev->unit_address, index); scrq->handler = ibmvfc_interrupt_mq;break ; +case IBMVFC_PROTO_ASYNC : +snprintf (scrq->name,sizeof (scrq->name),"ibmvfc-%x-async%d" , + vdev->unit_address, index); + scrq->handler = ibmvfc_interrupt_async_subq; +break ;default :dev_err (dev,"Unknown channel protocol (%d)\n" , channels->protocol);
@@ -6863,7 +6884,8 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost, rc =request_irq (scrq->irq, scrq->handler,0 , scrq->name, scrq);if (rc) { -dev_err (dev,"Couldn't register sub-crq[%d] irq\n" , index); +dev_err (dev,"Couldn't register protocol (%d) sub-crq[%d] irq\n" , + channels->protocol, index);irq_dispose_mapping (scrq->irq); scrq->irq =0 ; goto irq_failed;
@@ -6883,6 +6905,18 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost,return rc; } +/** +* ibmvfc_deregister_channel - Deregister a sub-CRQ channel with the hypervisor +* @vhost: ibmvfc host struct +* @channels: ibmvfc channels struct containing the sub-CRQ array +* @index: index into the sub-CRQ array, or -1 to deregister the +* asynchronous sub-CRQ +* +* Frees the IRQ, disposes of the IRQ mapping, and calls H_FREE_SUB_CRQ to +* release the sub-CRQ with the hypervisor. On success the queue message +* buffer is zeroed and the current index is reset. If H_FREE_SUB_CRQ fails, +* an error is logged but the channel resources are cleaned up regardless. +*/ static void ibmvfc_deregister_channel (struct ibmvfc_host *vhost,struct ibmvfc_channels *channels,int index)
@@ -6905,8 +6939,10 @@ static void ibmvfc_deregister_channel(struct ibmvfc_host *vhost, scrq->cookie); }while (rc ==H_BUSY ||H_IS_LONG_BUSY (rc)); -if (rc) -dev_err (dev,"Failed to free sub-crq[%d]: rc=%ld\n" , index, rc); +if (rc) { +dev_err (dev,"Failed to free protocol (%d) sub-crq[%d]: rc=%ld\n" , + channels->protocol, index, rc); + }/* Clean out the queue */ if (scrq->msgs.handle) {
drivers/scsi/ibmvscsi/ibmvfc.h +1 -0
@@ -839,6 +839,7 @@ enum ibmvfc_target_action {enum ibmvfc_protocol {IBMVFC_PROTO_SCSI =0 ,IBMVFC_PROTO_NVME =1 , +IBMVFC_PROTO_ASYNC =2 , };struct ibmvfc_target {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v11 09/11] scsi: ibmvfc: extend channel reg/dereg helpers for async sub-CRQ
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] scsi: ibmvfc: kernel-doc incorrectly instructs passing negative index --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] scsi: ibmvfc: kernel-doc incorrectly instructs passing negative index --
commit 6798e7ba7398cb1f91e10a6432ae9b3192653f37
Author: Dave Marquardt <[email protected]>
scsi: ibmvfc: extend channel reg/dereg helpers for async sub-CRQ
ibmvfc_register_channel() and ibmvfc_deregister_channel() previously only handled SCSI and NVMe sub-CRQ channels identified by the channel protocol. The async sub-CRQ had no registration path through these helpers, requiring separate handling. This commit adds IBMVFC_PROTO_ASYNC to extend both functions to handle the async sub-CRQ.
Quoted 4 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +0
-0
[ ... ]
Quoted 12 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +8
-0@@ -6812,6 +6812,21 @@ static int ibmvfc_init_crq(struct ibmvfc_host *vhost)return retrc; } +/** +* ibmvfc_register_channel - Register a sub-CRQ channel with the hypervisor +* @vhost: ibmvfc host struct +* @channels: ibmvfc channels struct containing the channel array and protocol +* @index: index into the channels array for the queue to register, or +* a negative value to register the async sub-CRQ +* +* Register a sub-CRQ with the hypervisor via h_reg_sub_crq, map its hardware
drivers/scsi/ibmvscsi/ibmvfc-core.c static int ibmvfc_init_crq(struct ibmvfc_host *vhost) · line 6832
Quoted 10 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +7
-0+* IRQ to a Linux IRQ, and bind an interrupt handler to it. The handler is +* selected based on the channel protocol (SCSI or NVMe) for normal queues, or +* set to the async sub-CRQ handler when @index is negative. +* +* Return value: +* 0 on success / non-zero on failure +**/ static int ibmvfc_register_channel (struct ibmvfc_host *vhost,struct ibmvfc_channels *channels,int index)
[Severity: Low]
Does this kernel-doc correctly document the expected index values?
The documentation explicitly directs the caller to pass a negative index for async sub-CRQs, but ibmvfc_register_channel() begins with an unconditional array access:
struct ibmvfc_queue *scrq = &channels->scrqs[index];
If a developer follows the documentation and passes a negative index, wouldn't this result in an immediate out-of-bounds array access? Currently, callers pass 0 for the async sub-CRQ, so this crash isn't reachable today, but the comment could mislead future users.
[ ... ]
Quoted 9 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +5
-0@@ -6883,6 +6905,18 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost,return rc; } +/** +* ibmvfc_deregister_channel - Deregister a sub-CRQ channel with the hypervisor +* @vhost: ibmvfc host struct +* @channels: ibmvfc channels struct containing the sub-CRQ array +* @index: index into the sub-CRQ array, or -1 to deregister the
drivers/scsi/ibmvscsi/ibmvfc-core.c static int ibmvfc_register_channel(struct ibmvfc_host *vhost, · line 6922
Quoted 10 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +7
-0+* asynchronous sub-CRQ +* +* Frees the IRQ, disposes of the IRQ mapping, and calls H_FREE_SUB_CRQ to +* release the sub-CRQ with the hypervisor. On success the queue message +* buffer is zeroed and the current index is reset. If H_FREE_SUB_CRQ fails, +* an error is logged but the channel resources are cleaned up regardless. +*/ static void ibmvfc_deregister_channel (struct ibmvfc_host *vhost,struct ibmvfc_channels *channels,int index)
[Severity: Low]
Is this the same documentation issue as above?
The kernel-doc for ibmvfc_deregister_channel() directs using -1 for the asynchronous sub-CRQ, but similar to ibmvfc_register_channel(), it accesses the array unconditionally:
struct ibmvfc_queue *scrq = &channels->scrqs[index];
Could this lead to an out-of-bounds array access if someone passes -1 as documented?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [PATCH v11 09/11] scsi: ibmvfc: extend channel reg/dereg helpers for async sub-CRQ
Quoted 50 lines · [email protected] writes:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] scsi: ibmvfc: kernel-doc incorrectly instructs passing negative index --commit
6798e7ba7398cb1f91e10a6432ae9b3192653f37
Author: Dave Marquardt <[email protected]>scsi: ibmvfc: extend channel reg/dereg helpers for async sub-CRQ
ibmvfc_register_channel()andibmvfc_deregister_channel()previously only handled SCSI and NVMe sub-CRQ channels identified by the channel protocol. The async sub-CRQ had no registration path through these helpers, requiring separate handling. This commit addsIBMVFC_PROTO_ASYNCto extend both functions to handle the async sub-CRQ.Quoted 4 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +0
-0[ ... ]
Quoted 12 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +8
-0@@ -6812,6 +6812,21 @@ static int ibmvfc_init_crq(struct ibmvfc_host *vhost)return retrc; } +/** +* ibmvfc_register_channel - Register a sub-CRQ channel with the hypervisor +* @vhost: ibmvfc host struct +* @channels: ibmvfc channels struct containing the channel array and protocol +* @index: index into the channels array for the queue to register, or +* a negative value to register the async sub-CRQ +* +* Register a sub-CRQ with the hypervisor via h_reg_sub_crq, map its hardware drivers/scsi/ibmvscsi/ibmvfc-core.c static int ibmvfc_init_crq(struct ibmvfc_host *vhost) · line 6832
Quoted 10 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +7
-0+* IRQ to a Linux IRQ, and bind an interrupt handler to it. The handler is +* selected based on the channel protocol (SCSI or NVMe) for normal queues, or +* set to the async sub-CRQ handler when @index is negative. +* +* Return value: +* 0 on success / non-zero on failure +**/ static int ibmvfc_register_channel (struct ibmvfc_host *vhost,struct ibmvfc_channels *channels,int index)[Severity: Low]
Does this kernel-doc correctly document the expected index values?The documentation explicitly directs the caller to pass a negative index for async sub-CRQs, but
ibmvfc_register_channel()begins with an unconditional array access:
Quoted 6 lines
struct ibmvfc_queue *scrq = &channels->scrqs[index];If a developer follows the documentation and passes a negative index, wouldn't this result in an immediate out-of-bounds array access? Currently, callers pass 0 for the async sub-CRQ, so this crash isn't reachable today, but the comment could mislead future users.
Right. This suggestion to use a negative index is an artifact of older implementation choices and was missed in more recent patch revisions. I'll fix it in v12.
Quoted 24 lines
[ ... ]
Quoted 9 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +5
-0@@ -6883,6 +6905,18 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost,return rc; } +/** +* ibmvfc_deregister_channel - Deregister a sub-CRQ channel with the hypervisor +* @vhost: ibmvfc host struct +* @channels: ibmvfc channels struct containing the sub-CRQ array +* @index: index into the sub-CRQ array, or -1 to deregister the drivers/scsi/ibmvscsi/ibmvfc-core.c static int ibmvfc_register_channel(struct ibmvfc_host *vhost, · line 6922
Quoted 10 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +7
-0+* asynchronous sub-CRQ +* +* Frees the IRQ, disposes of the IRQ mapping, and calls H_FREE_SUB_CRQ to +* release the sub-CRQ with the hypervisor. On success the queue message +* buffer is zeroed and the current index is reset. If H_FREE_SUB_CRQ fails, +* an error is logged but the channel resources are cleaned up regardless. +*/ static void ibmvfc_deregister_channel (struct ibmvfc_host *vhost,struct ibmvfc_channels *channels,int index)[Severity: Low]
Is this the same documentation issue as above?
Quoted 8 lines
The kernel-doc for
ibmvfc_deregister_channel()directs using -1 for the asynchronous sub-CRQ, but similar toibmvfc_register_channel(), it accesses the array unconditionally:struct ibmvfc_queue *scrq = &channels->scrqs[index];Could this lead to an out-of-bounds array access if someone passes -1 as documented?
I'll fix this also.
-Dave
Tyrel Datwyler
maintainerPATCH v11 10/11 scsi: ibmvfc: register and use asynchronous sub CRQ for events
In reply to Tyrel DatwylerFrom: Dave Marquardt <[email protected]>
Wire the async sub-CRQ into the sub-CRQ lifecycle so it is allocated, registered, and freed alongside the SCSI channel queues.
In ibmvfc_probe(), initialize vhost->async_scrqs with desired_queues=1, max_queues=1, and protocol=IBMVFC_PROTO_ASYNC. Add ibmvfc_release_channels() as a helper to free a channels array and its queue buffers.
In ibmvfc_init_sub_crqs(), allocate the async sub-CRQ via ibmvfc_alloc_channels() before allocating the SCSI channels. Register it with the VIOS via ibmvfc_reg_sub_crqs(). Either failure disables multi-queue and aborts init.
In ibmvfc_alloc_channels(), select IBMVFC_ASYNC_SUB_CRQ_FMT for async protocol channels instead of IBMVFC_SUB_CRQ_FMT, so the queue is sized for ibmvfc_async_sub_crq entries.
In ibmvfc_release_sub_crqs(), ibmvfc_reenable_crq_queue(), and ibmvfc_reset_crq(), deregister and re-register the async sub-CRQ alongside the SCSI channel queues.
In ibmvfc_channel_setup_done(), capture the async sub-CRQ handle returned by the VIOS in the channel setup response and store it in vhost->async_scrqs.scrqs[0].vios_cookie. Pass the async sub-CRQ cookie to the VIOS in ibmvfc_channel_setup() via async_sub_crq_handle.
In ibmvfc_set_login_info(), advertise IBMVFC_USE_ASYNC_SUBQ, IBMVFC_CAN_HANDLE_FPIN, and IBMVFC_YES_SCSI capabilities whenever multi-queue channels are enabled. IBMVFC_YES_SCSI was previously only set for NVMe-enabled configurations; move it to the common multi-queue path so it is always advertised when channels are in use.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 82 ++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 24 deletions(-)
drivers/scsi/ibmvscsi/ibmvfc-core.c +58 -24
@@ -964,6 +964,7 @@ static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)struct vio_dev *vdev =to_vio_dev (vhost->dev);unsigned long flags; +ibmvfc_dereg_sub_crqs (vhost, &vhost->async_scrqs);ibmvfc_dereg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_dereg_sub_crqs (vhost, &vhost->nvme_scrqs);
@@ -986,6 +987,7 @@ static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)spin_unlock (vhost->crq.q_lock);spin_unlock_irqrestore (vhost->host->host_lock, flags); +ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->nvme_scrqs);
@@ -1006,6 +1008,7 @@ static int ibmvfc_reset_crq(struct ibmvfc_host *vhost)struct vio_dev *vdev =to_vio_dev (vhost->dev);struct ibmvfc_queue *crq = &vhost->crq; +ibmvfc_dereg_sub_crqs (vhost, &vhost->async_scrqs);ibmvfc_dereg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_dereg_sub_crqs (vhost, &vhost->nvme_scrqs);
@@ -1042,6 +1045,7 @@ static int ibmvfc_reset_crq(struct ibmvfc_host *vhost)spin_unlock (vhost->crq.q_lock);spin_unlock_irqrestore (vhost->host->host_lock, flags); +ibmvfc_reg_sub_crqs (vhost, &vhost->async_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->nvme_scrqs);
@@ -1584,9 +1588,11 @@ static void ibmvfc_set_login_info(struct ibmvfc_host *vhost)if (vhost->mq_enabled || vhost->using_channels) { login_info->capabilities |=cpu_to_be64 (IBMVFC_CAN_USE_CHANNELS ); + login_info->capabilities |=cpu_to_be64 (IBMVFC_USE_ASYNC_SUBQ ); + login_info->capabilities |=cpu_to_be64 (IBMVFC_CAN_HANDLE_FPIN ); + login_info->capabilities |=cpu_to_be64 (IBMVFC_YES_SCSI );if (vhost->nvme_enabled) { login_info->capabilities |=cpu_to_be64 (IBMVFC_YES_NVMEOF ); - login_info->capabilities |=cpu_to_be64 (IBMVFC_YES_SCSI ); login_info->capabilities |=cpu_to_be64 (IBMVFC_CAN_USE_WWPN_ALL ); } }
@@ -5783,6 +5789,7 @@ static void ibmvfc_channel_setup_done(struct ibmvfc_event *evt) {struct ibmvfc_host *vhost = evt->vhost;struct ibmvfc_channel_setup *setup = vhost->channel_setup_buf; +struct ibmvfc_channels *async = &vhost->async_scrqs;struct ibmvfc_channels *scsi = &vhost->scsi_scrqs;struct ibmvfc_channels *nvme = &vhost->nvme_scrqs;u32 mad_status =be16_to_cpu (evt->xfer_iu->channel_setup.common.status);
@@ -5813,6 +5820,7 @@ static void ibmvfc_channel_setup_done(struct ibmvfc_event *evt)for (i =0 ; i < nvme->active_queues; i++) nvme->scrqs[i].vios_cookie =be64_to_cpu (setup->channel_handles[scsi->active_queues + i]); + async->scrqs[0 ].vios_cookie =be64_to_cpu (setup->async_sub_crq_handle);ibmvfc_dbg (vhost,"Using %u SCSI channels\n" , scsi->active_queues);
@@ -5847,6 +5855,7 @@ static void ibmvfc_channel_setup(struct ibmvfc_host *vhost)struct ibmvfc_event *evt =ibmvfc_get_reserved_event (&vhost->crq);struct ibmvfc_channels *scsi = &vhost->scsi_scrqs;struct ibmvfc_channels *nvme = &vhost->nvme_scrqs; +struct ibmvfc_channels *async = &vhost->async_scrqs;unsigned int scsi_channels =min (scsi->desired_queues, vhost->max_vios_scsi_channels); unsigned int nvme_channels =
@@ -5872,6 +5881,7 @@ static void ibmvfc_channel_setup(struct ibmvfc_host *vhost)for (i =0 ; i < nvme_channels; i++) setup_buf->channel_handles[scsi_channels + i] =cpu_to_be64 (nvme->scrqs[i].cookie); + setup_buf->async_sub_crq_handle =cpu_to_be64 (async->scrqs[0 ].cookie); }ibmvfc_init_event (evt, ibmvfc_channel_setup_done,IBMVFC_MAD_FORMAT );
@@ -6719,6 +6729,9 @@ static int ibmvfc_alloc_queue(struct ibmvfc_host *vhost, queue->evt_depth = scsi_qdepth; queue->reserved_depth =IBMVFC_NUM_INTERNAL_SUBQ_REQ ;break ; +case IBMVFC_ASYNC_SUB_CRQ_FMT : + fmt_size =sizeof (*queue->msgs.async_scrq); +break ;default :dev_warn (dev,"Unknown command/response queue message format: %d\n" , fmt);return -EINVAL ;
@@ -6993,6 +7006,7 @@ static int ibmvfc_alloc_channels(struct ibmvfc_host *vhost, struct ibmvfc_channels *channels) {struct ibmvfc_queue *scrq; +enum ibmvfc_msg_fmt fmt;int i, j;int rc =0 ;
@@ -7000,9 +7014,10 @@ static int ibmvfc_alloc_channels(struct ibmvfc_host *vhost,if (!channels->scrqs)return -ENOMEM ; + fmt = (channels->protocol !=IBMVFC_PROTO_ASYNC ) ?IBMVFC_SUB_CRQ_FMT :IBMVFC_ASYNC_SUB_CRQ_FMT ;for (i =0 ; i < channels->max_queues; i++) { scrq = &channels->scrqs[i]; - rc =ibmvfc_alloc_queue (vhost, scrq,IBMVFC_SUB_CRQ_FMT ); + rc =ibmvfc_alloc_queue (vhost, scrq, fmt);if (rc) {for (j = i; j >0 ; j--) { scrq = &channels->scrqs[j -1 ];
@@ -7018,17 +7033,39 @@ static int ibmvfc_alloc_channels(struct ibmvfc_host *vhost,return rc; } +static void ibmvfc_release_channels (struct ibmvfc_host *vhost, +struct ibmvfc_channels *channels) +{ +struct ibmvfc_queue *scrq; +int i; + +if (channels->scrqs) { +for (i =0 ; i < channels->max_queues; i++) { + scrq = &channels->scrqs[i]; +ibmvfc_free_queue (vhost, scrq); + } + +kfree (channels->scrqs); + channels->scrqs =NULL ; + channels->active_queues =0 ; + } +} +static void ibmvfc_init_sub_crqs (struct ibmvfc_host *vhost) { +ENTER ;if (!vhost->mq_enabled)return ; -if (ibmvfc_alloc_channels (vhost, &vhost->scsi_scrqs)) { - vhost->do_enquiry =0 ; - vhost->mq_enabled =0 ; -return ; - } +/* register async_sub_crq channel */ +if (ibmvfc_alloc_channels (vhost, &vhost->async_scrqs)) + goto out; + +ibmvfc_reg_sub_crqs (vhost, &vhost->async_scrqs); + +if (ibmvfc_alloc_channels (vhost, &vhost->scsi_scrqs)) + goto deregister_async_sub_crq;ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);
@@ -7040,29 +7077,23 @@ static void ibmvfc_init_sub_crqs(struct ibmvfc_host *vhost) }LEAVE ; -} - -static void ibmvfc_release_channels (struct ibmvfc_host *vhost, -struct ibmvfc_channels *channels) -{ -struct ibmvfc_queue *scrq; -int i; - -if (channels->scrqs) { -for (i =0 ; i < channels->max_queues; i++) { - scrq = &channels->scrqs[i]; -ibmvfc_free_queue (vhost, scrq); - } +return ; -kfree (channels->scrqs); - channels->scrqs =NULL ; - channels->active_queues =0 ; - } +deregister_async_sub_crq: +ibmvfc_dereg_sub_crqs (vhost, &vhost->async_scrqs); +ibmvfc_release_channels (vhost, &vhost->async_scrqs); +out: + vhost->do_enquiry =0 ; + vhost->mq_enabled =0 ; +return ; }static void ibmvfc_release_sub_crqs (struct ibmvfc_host *vhost) {ENTER ; +ibmvfc_dereg_sub_crqs (vhost, &vhost->async_scrqs); +ibmvfc_release_channels (vhost, &vhost->async_scrqs); +if (!vhost->scsi_scrqs.scrqs)return ;
@@ -7328,6 +7359,9 @@ static int ibmvfc_probe(struct vio_dev *vdev, const struct vio_device_id *id) vhost->task_set =1 ; vhost->mq_enabled = mq_enabled; + vhost->async_scrqs.desired_queues =1 ; + vhost->async_scrqs.max_queues =1 ; + vhost->async_scrqs.protocol =IBMVFC_PROTO_ASYNC ; vhost->scsi_scrqs.desired_queues =min (shost->nr_hw_queues, nr_scsi_channels); vhost->scsi_scrqs.max_queues = shost->nr_hw_queues; vhost->scsi_scrqs.protocol =IBMVFC_PROTO_SCSI ;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v11 10/11] scsi: ibmvfc: register and use asynchronous sub CRQ for events
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] scsi: ibmvfc: double registration of scsi_scrqs and missing async_scrqs registration --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: ibmvfc: double registration of scsi_scrqs and missing async_scrqs registration --
commit d44dbe8300fc3639dbfcef8f1950443462606f5b
Author: Dave Marquardt <[email protected]>
scsi: ibmvfc: register and use asynchronous sub CRQ for events
This commit wires the async sub-CRQ into the sub-CRQ lifecycle so it is allocated, registered, and freed alongside the SCSI channel queues.
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +0
-0
[ ... ]
drivers/scsi/ibmvscsi/ibmvfc-core.c static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost) · line 993
Quoted 8 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +1
-0@@ -986,6 +987,7 @@ static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)spin_unlock (vhost->crq.q_lock);spin_unlock_irqrestore (vhost->host->host_lock, flags); +ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->nvme_scrqs);
[Severity: High]
Could this introduce a regression where scsi_scrqs is accidentally registered twice instead of registering async_scrqs?
Because the first call was added as ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs), it appears to skip the async sub-CRQ registration entirely. This leaves the async sub-CRQ permanently disabled after a CRQ re-enablement, which could prevent asynchronous event handling (like FPINs) after recovery.
Also, wouldn't the double registration of scsi_scrqs cause ibmvfc_register_channel() to fail? If H_REG_SUB_CRQ returns an error for an already registered channel, this will abort the registration and clear vhost->do_enquiry = 0, functionally breaking multi-queue capabilities during standard operational recovery paths.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH v11 10/11] scsi: ibmvfc: register and use asynchronous sub CRQ for events
Quoted 29 lines · [email protected] writes:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: ibmvfc: double registration ofscsi_scrqsand missingasync_scrqsregistration --commit
d44dbe8300fc3639dbfcef8f1950443462606f5b
Author: Dave Marquardt <[email protected]>scsi: ibmvfc: register and use asynchronous sub CRQ for events
This commit wires the async sub-CRQ into the sub-CRQ lifecycle so it is allocated, registered, and freed alongside the SCSI channel queues.
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +0
-0[ ... ]
drivers/scsi/ibmvscsi/ibmvfc-core.c static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost) · line 993
Quoted 8 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +1
-0@@ -986,6 +987,7 @@ static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)spin_unlock (vhost->crq.q_lock);spin_unlock_irqrestore (vhost->host->host_lock, flags); +ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->nvme_scrqs);[Severity: High]
Could this introduce a regression wherescsi_scrqsis accidentally registered twice instead of registeringasync_scrqs?
Quoted 5 lines
Because the first call was added as
ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs), it appears to skip the async sub-CRQ registration entirely. This leaves the async sub-CRQ permanently disabled after a CRQ re-enablement, which could prevent asynchronous event handling (like FPINs) after recovery.
Yes, this is broken. The added call should be
ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs);
and will be fixed in v12.
Quoted 5 lines
Also, wouldn't the double registration of
scsi_scrqscauseibmvfc_register_channel()to fail? IfH_REG_SUB_CRQreturns an error for an already registered channel, this will abort the registration and clearvhost->do_enquiry= 0, functionally breaking multi-queue capabilities during standard operational recovery paths.
-Dave
Tyrel Datwyler
maintainerRe: [PATCH v11 10/11] scsi: ibmvfc: register and use asynchronous sub CRQ for events
Quoted 37 lines · Dave Marquardt
Quoted 29 lines · [email protected] writes:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: ibmvfc: double registration ofscsi_scrqsand missingasync_scrqsregistration --commit
d44dbe8300fc3639dbfcef8f1950443462606f5b
Author: Dave Marquardt <[email protected]>scsi: ibmvfc: register and use asynchronous sub CRQ for events
This commit wires the async sub-CRQ into the sub-CRQ lifecycle so it is allocated, registered, and freed alongside the SCSI channel queues.
Quoted 3 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +0
-0[ ... ]
drivers/scsi/ibmvscsi/ibmvfc-core.c static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost) · line 993
Quoted 8 lines
drivers/scsi/ibmvscsi/ibmvfc-core.c +1
-0@@ -986,6 +987,7 @@ static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)spin_unlock (vhost->crq.q_lock);spin_unlock_irqrestore (vhost->host->host_lock, flags); +ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->scsi_scrqs);ibmvfc_reg_sub_crqs (vhost, &vhost->nvme_scrqs);[Severity: High]
Could this introduce a regression wherescsi_scrqsis accidentally registered twice instead of registeringasync_scrqs?Quoted 5 lines
Because the first call was added as
ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs), it appears to skip the async sub-CRQ registration entirely. This leaves the async sub-CRQ permanently disabled after a CRQ re-enablement, which could prevent asynchronous event handling (like FPINs) after recovery.
Quoted 3 lines
Yes, this is broken. The added call should be
ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs);
Still wrong. s/scsi_scrqs/async_scrqs
-Tyrel
Quoted 11 lines
and will be fixed in v12.
Quoted 5 lines
Also, wouldn't the double registration of
scsi_scrqscauseibmvfc_register_channel()to fail? IfH_REG_SUB_CRQreturns an error for an already registered channel, this will abort the registration and clearvhost->do_enquiry= 0, functionally breaking multi-queue capabilities during standard operational recovery paths.-Dave
Tyrel Datwyler
maintainerPATCH v11 11/11 scsi: ibmvfc: handle extended FPIN events
In reply to Tyrel DatwylerFrom: Dave Marquardt <[email protected]>
Implement support for extended FPIN messages received via the asynchronous sub-queue, completing full FPIN functionality.
Extended FPIN messages provide more detailed information about fabric events compared to basic FPIN messages, including specific event types, modifiers, thresholds, and event counts.
Add ibmvfc_ext_fpin_to_desc() to convert extended FPIN messages from async sub-queue format to fc_els_fpin structures with complete descriptor information. Update ibmvfc_process_async_work() and ibmvfc_handle_async() to zero node_name and dispatch to ibmvfc_ext_fpin_to_desc() when the IBMVFC_ASYNC_IS_FPIN_EXT flag is set.
Set the IBMVFC_CAN_HANDLE_FPIN_EXT capability bit during login to inform VIOS that the client can process extended FPIN messages. Also add the IBMVFC_SUPPORT_FPIN_EXT response capability bit definition used to gate extended FPIN processing.
Add KUnit tests to exercise extended FPIN event handling across all FPIN status and event type combinations.
struct ibmvfc_async_subq_fpin uses volatile on its valid and wwpn fields, consistent with the existing ibmvfc_crq, ibmvfc_async_crq, and ibmvfc_async_sub_crq structs in ibmvfc.h, all of which mark their hardware-owned ring-buffer fields volatile to prevent the compiler from caching or eliminating reads of memory written directly by the VIOS.
--- drivers/scsi/ibmvscsi/ibmvfc-core.c | 67 ++++++++++++- drivers/scsi/ibmvscsi/ibmvfc.h | 30 ++++++ drivers/scsi/ibmvscsi/ibmvfc_kunit.c | 135 +++++++++++++++++++++++++++ 3 files changed, 228 insertions(+), 4 deletions(-)
drivers/scsi/ibmvscsi/ibmvfc-core.c +63 -4
@@ -1591,6 +1591,7 @@ static void ibmvfc_set_login_info(struct ibmvfc_host *vhost) login_info->capabilities |=cpu_to_be64 (IBMVFC_USE_ASYNC_SUBQ ); login_info->capabilities |=cpu_to_be64 (IBMVFC_CAN_HANDLE_FPIN ); login_info->capabilities |=cpu_to_be64 (IBMVFC_YES_SCSI ); + login_info->capabilities |=cpu_to_be64 (IBMVFC_CAN_HANDLE_FPIN_EXT );if (vhost->nvme_enabled) { login_info->capabilities |=cpu_to_be64 (IBMVFC_YES_NVMEOF ); login_info->capabilities |=cpu_to_be64 (IBMVFC_CAN_USE_WWPN_ALL );
@@ -3471,6 +3472,41 @@ ibmvfc_full_fpin_to_desc(struct ibmvfc_async_sub_crq *ibmvfc_fpin) cpu_to_be32(1)); } +/** +* ibmvfc_ext_fpin_to_desc(): allocate and populate a struct fc_els_fpin struct +* containing a descriptor. +* @ibmvfc_fpin: Pointer to async subq FPIN data +* +* Allocate a struct fc_els_fpin containing a descriptor and populate +* based on data from *ibmvfc_fpin. +* +* Return: +* NULL - unable to allocate structure +* non-NULL - pointer to populated struct fc_els_fpin +*/ +static struct fc_els_fpin * +ibmvfc_ext_fpin_to_desc (struct ibmvfc_async_subq_fpin *ibmvfc_fpin) +{ +u8 flags = ibmvfc_fpin->fpin_data.flags; +__be32 threshold =cpu_to_be32 (IBMVFC_FPIN_DEFAULT_EVENT_THRESHOLD ); +__be16 modifier =0 ; +__be32 count =cpu_to_be32 (1 ); +__be16 type =0 ; + +if (flags &IBMVFC_FPIN_EVENT_TYPE_VALID ) + type = ibmvfc_fpin->fpin_data.event_type; +if (flags &IBMVFC_FPIN_MODIFIER_VALID ) + modifier = ibmvfc_fpin->fpin_data.event_type_modifier; +if (flags &IBMVFC_FPIN_THRESHOLD_VALID ) + threshold = ibmvfc_fpin->fpin_data.event_threshold; +if (flags &IBMVFC_FPIN_EVENT_COUNT_VALID ) + count = ibmvfc_fpin->fpin_data.event_data.event_count; + +return ibmvfc_common_fpin_to_desc (ibmvfc_fpin->fpin_status, + ibmvfc_fpin->wwpn, type, + modifier, threshold, count); +} +/** * ibmvfc_find_target - Search for a target in a target list * @target_list: list head of targets to search
@@ -3509,6 +3545,7 @@ static struct ibmvfc_target *ibmvfc_find_target(struct list_head *target_list,static void ibmvfc_process_async_work (struct work_struct *work) {struct ibmvfc_async_sub_crq *subq =NULL ; +struct ibmvfc_async_subq_fpin *sqfpin;struct ibmvfc_async_work *aw;struct ibmvfc_async_crq *crq =NULL ;struct ibmvfc_target *tgt;
@@ -3525,7 +3562,10 @@ static void ibmvfc_process_async_work(struct work_struct *work) subq = &aw->event.subq; scsi_id =0 ; wwpn = subq->wwpn; - node_name = (subq->flags &IBMVFC_ASYNC_ID_IS_ASSOC_ID ) ?0 : subq->id.node_name; +if (subq->flags & (IBMVFC_ASYNC_IS_FPIN_EXT |IBMVFC_ASYNC_ID_IS_ASSOC_ID )) + node_name =0 ; +else + node_name = subq->id.node_name; }else { crq = &aw->event.async_crq; scsi_id = crq->scsi_id;
@@ -3555,8 +3595,24 @@ static void ibmvfc_process_async_work(struct work_struct *work)if (crq) fpin =ibmvfc_basic_fpin_to_desc (crq, tgt->wwpn); -else - fpin =ibmvfc_full_fpin_to_desc (subq); +else { +static_assert (sizeof (struct ibmvfc_async_subq_fpin ) == +sizeof (struct ibmvfc_async_sub_crq )); +static_assert (offsetof(struct ibmvfc_async_subq_fpin , fpin_data) == + offsetof(struct ibmvfc_async_sub_crq , nport_id)); + sqfpin = (struct ibmvfc_async_subq_fpin *)subq; +if ((subq->flags &IBMVFC_ASYNC_IS_FPIN_EXT ) ==0 ) { + fpin =ibmvfc_full_fpin_to_desc (subq); + }else if (!(sqfpin->fpin_data.flags &IBMVFC_FPIN_EVENT_TYPE_VALID )) { +dev_err_ratelimited (vhost->dev, +"Invalid extended FPIN event received\n" ); + }else if (!ibmvfc_check_caps (vhost,IBMVFC_SUPPORT_FPIN_EXT )) { +dev_err_ratelimited (vhost->dev, +"Unexpected extended FPIN event received\n" ); + }else { + fpin =ibmvfc_ext_fpin_to_desc (sqfpin); + } + }if (fpin) { fc_host_fpin_rcv(tgt->vhost->host,
@@ -3598,7 +3654,10 @@ VISIBLE_IF_KUNIT void ibmvfc_handle_async(struct ibmvfc_async_crq_event *ae, link_state = subq->link_state; scsi_id =0 ; wwpn = subq->wwpn; - node_name = subq->flags &IBMVFC_ASYNC_ID_IS_ASSOC_ID ?0 : subq->id.node_name; +if (subq->flags & (IBMVFC_ASYNC_IS_FPIN_EXT |IBMVFC_ASYNC_ID_IS_ASSOC_ID )) + node_name =0 ; +else + node_name = subq->id.node_name; }else { async_crq = &ae->async_crq; event =be64_to_cpu (async_crq->event);
drivers/scsi/ibmvscsi/ibmvfc.h +30 -0
@@ -210,6 +210,7 @@ struct ibmvfc_npiv_login {#define IBMVFC_CAN_USE_WWPN_ALL 0x080#define IBMVFC_USE_ASYNC_SUBQ 0x100#define IBMVFC_CAN_USE_NOOP_CMD 0x200 +#define IBMVFC_CAN_HANDLE_FPIN_EXT 0x800__be64 node_name;struct srp_direct_buf async;u8 partition_name[IBMVFC_MAX_NAME ];
@@ -261,6 +262,7 @@ struct ibmvfc_npiv_login_resp {#define IBMVFC_SUPPORT_WWPN_ALL 0x0400#define IBMVFC_ASYNC_SUBQ 0x0800#define IBMVFC_SUPPORT_NOOP_CMD 0x1000 +#define IBMVFC_SUPPORT_FPIN_EXT 0x2000__be32 max_cmds;__be32 scsi_id_sz;__be64 max_dma_len;
@@ -786,6 +788,34 @@ struct ibmvfc_async_sub_crq { } id; } __packed__aligned(8) ; +struct ibmvfc_fpin_data { +#define IBMVFC_FPIN_EVENT_TYPE_VALID 0x01 +#define IBMVFC_FPIN_MODIFIER_VALID 0x02 +#define IBMVFC_FPIN_THRESHOLD_VALID 0x04 +#define IBMVFC_FPIN_SEVERITY_VALID 0x08 +#define IBMVFC_FPIN_EVENT_COUNT_VALID 0x10 +u8 flags; +u8 reserved[3 ]; +__be16 event_type; +__be16 event_type_modifier; +__be32 event_threshold; +union { +u8 severity; +__be32 event_count; + } event_data; +} __packed__aligned(8) ; + +struct ibmvfc_async_subq_fpin { +volatile u8 valid; +u8 flags; +u8 link_state; +u8 fpin_status; +__be16 event; +__be16 pad; +volatile __be64 wwpn; +struct ibmvfc_fpin_data fpin_data; +} __packed__aligned(8) ; +enum ibmvfc_async_crq_type {IBMVFC_ASYNC_CRQ_MAIN =0 ,IBMVFC_ASYNC_CRQ_SUB ,
drivers/scsi/ibmvscsi/ibmvfc_kunit.c +135 -0
150 lines not on this page · raw message
Signature · 1 line
2.55.0