From: Boaz Harrosh <bharrosh@panasas.com>
To: James Bottomley <James.Bottomley@suse.de>
Cc: Roel Kluin <roel.kluin@gmail.com>,
linux-scsi@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: Re: [PATCH] zfcp: Test kmalloc failure in scsi_get_vpd_page()
Date: Wed, 04 Nov 2009 18:18:09 +0200 [thread overview]
Message-ID: <4AF1A941.3080808@panasas.com> (raw)
In-Reply-To: <1257347360.2697.20.camel@mulgrave.site>
On 11/04/2009 05:09 PM, James Bottomley wrote:
> On Wed, 2009-11-04 at 10:54 +0200, Boaz Harrosh wrote:
>>> +
>>> + if (i < buf[3] && i > buf_len)
>>> + /* ran off the end of the buffer, give us benefit of doubt */
>>> + goto found;
>>
>> Some cheep devices are known to break when asked for pages they do not support
>> better return an -ETOOSMALL the user can check for. (And the comment above should
>> also take care of it)
>
> OK, so I struggled with this. The reason for the behaviour is that
> only USB devices with incredibly small page lists are likely to exhibit
> the problem. Whereas the page lists in array type devices are likely to
> grow. I don't want to run into the situation that your new $10m array
> suddenly gives an error with DIF/DIX because the page list is too big
> and the problem this is checking for only afflicts cheap and badly
> implemented HW.
>
If I remember the standard correctly and from inspecting the code 260 is the
maximum size for page 0. (And the maximum we supported until today for page
0 was 256) so there is no speculations here. 256 it should be. If you want
you can do an:
if (i < buf[3] && i > buf_len) {
if (likely(buf_len >= 255))
/* ran off the end of the buffer, give us benefit of doubt */
goto found;
else
return -ETOOSMALL;
}
which is only theoretical because we only check against buf[3] that cannot
be more then 255 so all is left is return -ETOOSMALL;
Callers that allocate smaller then 256 for this (hence the comment)
must check for -ETOOSMALL;. Or should call with >= 256.
<snip>
>>> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
>>> index 9093c72..fd1bd8f 100644
>>> --- a/drivers/scsi/sd.c
>>> +++ b/drivers/scsi/sd.c
>>> @@ -1864,19 +1864,20 @@ void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
>>> static void sd_read_block_limits(struct scsi_disk *sdkp)
>>> {
>>> unsigned int sector_sz = sdkp->device->sector_size;
>>> - char *buffer;
>>> + const int vpd_len = 32;
>>> + unsigned char *buffer = kmalloc(vpd_len, GFP_KERNEL);
>>>
>>
>> 32 sounds two small for me. Not because of the page but because of the
>> first pass. Why not just 255 as a rule. We kmalloc it anyway.
>
> It only needs 16 if you look at the code. 32 is actually the smallest
> kmalloc slab on 32 bit systems.
>
>> We used to allocate 255 here, for some devices out there this is surly
>> a regression.
>
> We did 255 because we were concerned about space for the page list ...
> hopefully I answered that one above.
>
No, I still disagree. Whats the point of checking at all? Surly there is a device
out there that has more then 12 pages but will breaks with wrong page. So what's
the limit? the standards say 260 why not stick with that. It's not at any hot path.
> James
>
>
Boaz
next prev parent reply other threads:[~2009-11-04 16:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-24 16:21 [PATCH] zfcp: Test kmalloc failure in scsi_get_vpd_page() Roel Kluin
2009-08-27 23:45 ` James Bottomley
2009-08-30 11:45 ` Boaz Harrosh
2009-08-30 14:35 ` James Bottomley
2009-11-03 18:33 ` James Bottomley
2009-11-04 8:54 ` Boaz Harrosh
2009-11-04 15:09 ` James Bottomley
2009-11-04 16:18 ` Boaz Harrosh [this message]
2009-11-04 17:50 ` James Bottomley
2009-11-05 8:29 ` Boaz Harrosh
2009-11-05 19:41 ` James Bottomley
2009-11-08 9:19 ` Boaz Harrosh
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=4AF1A941.3080808@panasas.com \
--to=bharrosh@panasas.com \
--cc=James.Bottomley@suse.de \
--cc=akpm@linux-foundation.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=roel.kluin@gmail.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