Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Jason Yan <yanaijie@huawei.com>,
	John Garry <john.g.garry@oracle.com>,
	linux-ide@vger.kernel.org
Cc: Xingui Yang <yangxingui@huawei.com>
Subject: Re: [PATCH v3] ata: libata-scsi: Use correct device no in ata_find_dev()
Date: Tue, 23 May 2023 19:22:27 +0900	[thread overview]
Message-ID: <af5fffde-252a-b18f-d061-1e2b5122b75f@kernel.org> (raw)
In-Reply-To: <4a48966b-c193-06c7-54b0-d175a9009de9@huawei.com>

On 5/23/23 18:23, Jason Yan wrote:
> On 2023/5/23 16:29, John Garry wrote:
>> On 23/05/2023 09:04, Damien Le Moal wrote:
>>> For devices not attached to a port multiplier and managed directly by
>>> libata, the device number passed to ata_find_dev() must always be lower
>>> than the maximum number of devices returned by ata_link_max_devices().
>>> That is 1 for SATA devices or 2 for an IDE link with master+slave
>>> devices. This device number is the scsi device ID which matches these
>>> constraint as the ID are generated per port and so never exceed the
>>> link maximum.
>>>
>>> However, for libsas managed devices, scsi device IDs are assigned per
>>> scsi host, leading to device IDs for SATA devices that can be well in
>>> excess of libata per-link maximum number of devices. This results in
>>> ata_find_dev() always returning NULL for libsas managed devices except
>>> for the first device of the host with ID (device number) 0. This issue
>>> is visible by executing hdparm command, which fails:
>>>
>>> hdparm -i /dev/sdX
>>> /dev/sdX:
>>>    HDIO_GET_IDENTITY failed: No message of desired type
>>>
>>> Fix this by rewriting ata_find_dev() to ignore the device number for
>>> non-pmp attached devices with a link with at most 1 device, that is SATA
>>> devices on SATA ports. For these, device number 0 is always used to
>>> return the correct ata_device struct of the port link. This change
>>> excludes IDE master/slave setups (maximum number of devices per link
>>> is 2) and port-multiplier attached devices. Also, to be consistant with
>>> the fact that scsi device IDs and channel numbers used as device numbers
>>> are both unsigned int, change the devno argument of ata_find_dev() to
>>> unsinged int.
>>>
>>> Reported-by: Xingui Yang <yangxingui@huawei.com>
>>> Fixes: 41bda9c98035 ("libata-link: update hotplug to handle PMP links")
>>> Cc: stable@vger.kernel.org
>>> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
>>
>> Reviewed-by: John Garry <john.g.garry@oracle.com>
> 
> Hi Damien & John,
> 
> I think we may missed something. What about if we do this:
> 
> echo "scsi add-single-device 0 0 100 0" >/proc/scsi/scsi
> 
> Then in ata_scsi_user_scan() we will return device "0 0 0 0 " and rescan 
> this device, which is wrong?

On first review, I think it is OK because there is one scsi host per port. So
when ata_scsi_user_scan() with ID 100, the shost passed to it corresponds to an
ata_port that is for that device ID 100, and then ata_find_dev() changing devno
from 100 to 0 is correct.

But that "one shost == one port" seems to be correct only for pure libata, that
is, AHCI and other SATA/PATA adapters. For libsas, I am not so sure: the initial
"ap = ata_shost_to_port(shost)" in ata_scsi_user_scan() seems totally bogus for
the libsas case, while it is clearly OK for AHCI... Hmm... Needs more digging.


> 
> Thanks,
> Jason

-- 
Damien Le Moal
Western Digital Research


  reply	other threads:[~2023-05-23 10:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23  8:04 [PATCH v3] ata: libata-scsi: Use correct device no in ata_find_dev() Damien Le Moal
2023-05-23  8:29 ` John Garry
2023-05-23  8:43   ` Damien Le Moal
2023-05-23  9:23   ` Jason Yan
2023-05-23 10:22     ` Damien Le Moal [this message]
2023-05-29  6:45     ` Damien Le Moal
2023-05-29  9:10       ` Jason Yan
2023-05-23  9:01 ` Sergey Shtylyov

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=af5fffde-252a-b18f-d061-1e2b5122b75f@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=john.g.garry@oracle.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=yanaijie@huawei.com \
    --cc=yangxingui@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox