From: John Garry <john.garry@linux.dev>
To: Laurence Oberman <loberman@redhat.com>,
"Martin K . Petersen" <mkp@kernel.org>,
linux-scsi@vger.kernel.org
Cc: "James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
Bart Van Assche <bvanassche@acm.org>,
Martin Wilck <mwilck@suse.com>, Hannes Reinecke <hare@kernel.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] scsi: scsi_dh_alua: set handler_data before alua_initialize()
Date: Sun, 15 Nov 2026 18:04:54 +0000 [thread overview]
Message-ID: <37cb0b01-0c6a-4b3d-b3d8-c4e5a45977a8@linux.dev> (raw)
In-Reply-To: <20261109201120.1067815-1-loberman@redhat.com>
On 11/9/26 20:11, Laurence Oberman wrote:
> Since commit 50759b881e1d ("scsi: device_handler: alua: Call
> scsi_device_put() from non-atomic context"), alua_rtpg_queue() only
> queues an RTPG when sdev->handler_data points at an alua_dh_data whose
> port group matches:
>
> struct alua_dh_data *h = sdev->handler_data;
> ...
> if (h && rcu_dereference(h->pg) == pg) {
Do we still require this check (for h being non-NULL) after the change
in this patch? I assume that we flush any calls to this function prior
to unsetting sdev->handler_data.
>
> However alua_bus_attach() only assigns sdev->handler_data after
> alua_initialize() returns, and alua_initialize() -> alua_check_vpd()
> is where the initial RTPG is queued. At that point handler_data is
> still NULL, so the initial RTPG is silently dropped: no RTPG is sent,
> nothing is logged, and sdev->access_state keeps its zeroed default of
> active/optimized for every path.
>
> With dm-multipath this goes unnoticed, as pg_init calls
> scsi_dh_activate() once the map is loaded, which queues an RTPG after
> handler_data is set, and multipathd's alua prioritizer issues its own
> RTPG from userspace. Anything relying on sdev->access_state without a
> subsequent activate (sysfs access_state/preferred_path, native SCSI
> multipath path selection) sees every path as active/optimized until a
> Unit Attention or rescan triggers an RTPG.
>
> Seen on an HP P2000 G3 FC array (implicit ALUA, two port groups, four
> paths per LUN) with dm-multipath not in use: sg_rtpg reports port group
> 0 active/non-optimized and port group 1 active/optimized, but
> /sys/class/scsi_device/H:C:T:L/device/access_state reads
> active/optimized on all four paths after boot, and no
> "alua: port group XX state ..." message is logged. Writing "activate"
> to dh_state sends the RTPG and corrects access_state.
>
> Kernels without commit 50759b881e1d queue the attach-time RTPG
> unconditionally and are not affected.
>
> Fix by assigning sdev->handler_data before calling alua_initialize(),
> and clearing it again on failure. sdev->handler is only set once
> scsi_dh_handler_attach() sees ->attach() succeed, so no handler
> callback can observe the partially initialised alua_dh_data. On the
> failure paths of alua_initialize(), h has not been added to a port
> group and no RTPG has been queued, so freeing it is unchanged.
>
> Fixes: 50759b881e1d ("scsi: device_handler: alua: Call scsi_device_put() from non-atomic context")
> Cc: stable@vger.kernel.org
> Signed-off-by: Laurence Oberman <loberman@redhat.com>
> ---
>
> Notes:
> Tested on an HP P2000 G3 FC array (30 LUNs, 4 paths each): with this
> patch the "alua: port group 00 state N ..." messages are logged during
> boot and access_state shows two active/optimized and two
> active/non-optimized paths per LUN without any manual activate.
> Without it, all paths read active/optimized until an RTPG is triggered.
>
> I found this while testing John Garry's native SCSI multipath series
> (v9) on an HP P2000 G3 FC array (30 LUNs, 4 paths each, dm-multipath
> not in use). Native multipath uses sdev->access_state for path
> selection, and every path showed active/optimized, although sg_rtpg
> and dm-multipath (alua prio 50/10) both report port group 0 as
> active/non-optimized. No "alua: port group XX state ..." message was
> logged at boot. Writing "activate" to dh_state corrected access_state,
> which pointed at the attach-time RTPG never being queued.
>
> With this patch, the port group state messages are logged during boot
> and access_state shows two active/optimized and two
> active/non-optimized paths per LUN without any manual activate.
>
> This fix is independent of the native multipath series. It affects any
> user of access_state/preferred_path, and ALUA prep_fn fast-fail, on
> kernels with 50759b881e1d where nothing calls scsi_dh_activate()
> after attach.
>
> v9 series: https://lore.kernel.org/linux-scsi/20261108204733.557995-1-
> john.garry@linux.dev/
>
> drivers/scsi/device_handler/scsi_dh_alua.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
> index 87ac0a6d63e5..84ff3aed2c46 100644
> --- a/drivers/scsi/device_handler/scsi_dh_alua.c
> +++ b/drivers/scsi/device_handler/scsi_dh_alua.c
> @@ -1233,13 +1233,20 @@ static int alua_bus_attach(struct scsi_device *sdev)
> INIT_LIST_HEAD(&h->node);
>
> mutex_init(&h->init_mutex);
> + /*
> + * alua_rtpg_queue() only queues an RTPG when sdev->handler_data
> + * points at this alua_dh_data, so set it before alua_initialize()
> + * otherwise the initial RTPG issued from alua_check_vpd() is
> + * silently dropped and sdev->access_state is never populated.
> + */
> + sdev->handler_data = h;
Note: I was checking which members of alua_dh_data are not initialized
prior to publishing sdev->handler_data, and alua_dh_data.group_id is
never accessed at all AFAICS.
Thanks,
John
next prev parent reply other threads:[~2026-11-15 18:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 20:11 [PATCH] scsi: scsi_dh_alua: set handler_data before alua_initialize() Laurence Oberman
2026-11-11 11:14 ` Martin Wilck
2026-11-15 18:04 ` John Garry [this message]
2026-11-15 19:37 ` Laurence Oberman
2026-11-16 8:44 ` John Garry
2026-11-16 9:32 ` Martin Wilck
2026-11-18 4:49 ` Martin K. Petersen (Oracle)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=37cb0b01-0c6a-4b3d-b3d8-c4e5a45977a8@linux.dev \
--to=john.garry@linux.dev \
--cc=James.Bottomley@HansenPartnership.com \
--cc=bvanassche@acm.org \
--cc=hare@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=loberman@redhat.com \
--cc=mkp@kernel.org \
--cc=mwilck@suse.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.