scsi: storvsc: Don't pass unused PFNs to Hyper-V host
PATCH 1/1 scsi: storvsc: Don't pass unused PFNs to Hyper-V host
In a SCSI request, storvsc pre-allocates space for up to MAX_PAGE_BUFFER_COUNT physical frame numbers to be passed to Hyper-V. If the size of the I/O request requires more PFNs, a separate memory area of exactly the correct size is dynamically allocated.
But when the pre-allocated area is used, current code always passes MAX_PAGE_BUFFER_COUNT PFNs to Hyper-V, even if fewer are needed. While this doesn't break anything because the additional PFNs are always zero, more bytes than necessary are copied into the VMBus channel ring buffer. This takes CPU cycles and wastes space in the ring buffer. For a typical 4 Kbyte I/O that requires only a single PFN, 248 unnecessary bytes are copied.
Fix this by setting the payload_sz based on the actual number of PFNs required, not the size of the pre-allocated space.
--- drivers/scsi/storvsc_drv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/storvsc_drv.c +4 -4
@@ -1780,7 +1780,7 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) length =scsi_bufflen (scmnd); payload = (struct vmbus_packet_mpb_array *)&cmd_request->mpb; - payload_sz =sizeof (cmd_request->mpb); + payload_sz =0 ;if (scsi_sg_count (scmnd)) {unsigned long offset_in_hvpg =offset_in_hvpage (sgl->offset);
@@ -1789,10 +1789,10 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)unsigned long hvpfn, hvpfns_to_add;int j, i =0 , sg_count; -if (hvpg_count >MAX_PAGE_BUFFER_COUNT ) { + payload_sz = (hvpg_count *sizeof (u64) + +sizeof (struct vmbus_packet_mpb_array )); - payload_sz = (hvpg_count *sizeof (u64) + -sizeof (struct vmbus_packet_mpb_array )); +if (hvpg_count >MAX_PAGE_BUFFER_COUNT ) { payload =kzalloc (payload_sz,GFP_ATOMIC );if (!payload)return SCSI_MLQUEUE_DEVICE_BUSY ;
Signature · 1 line
1.8.3.1
kernel test robot
build botFYI: kernel test robot notices the stable kernel rule is not satisfied.
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
Rule: 'Cc: [email protected]' or 'commit <sha1> upstream.'
Subject: [PATCH 1/1] scsi: storvsc: Don't pass unused PFNs to Hyper-V host
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Martin K. Petersen
AppliedQuoted 13 lines · Michael Kelley
In a SCSI request, storvsc pre-allocates space for up to
MAX_PAGE_BUFFER_COUNTphysical frame numbers to be passed to Hyper-V. If the size of the I/O request requires more PFNs, a separate memory area of exactly the correct size is dynamically allocated.But when the pre-allocated area is used, current code always passes
MAX_PAGE_BUFFER_COUNTPFNs to Hyper-V, even if fewer are needed. While this doesn't break anything because the additional PFNs are always zero, more bytes than necessary are copied into the VMBus channel ring buffer. This takes CPU cycles and wastes space in the ring buffer. For a typical 4 Kbyte I/O that requires only a single PFN, 248 unnecessary bytes are copied.
Quoted 1 line
[...]
Applied to 6.4/scsi-fixes, thanks!
[1/1] scsi: storvsc: Don't pass unused PFNs to Hyper-V host
https://git.kernel.org/mkp/scsi/c/4e81a6cba517
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering