Skip to contentSkip to conversation

staging: unisys: visorhba: use sg helper to operate sgl

PATCH In review Ming Lei 5 participants 11 messages Jun 13, 2019 1 message not in the archive

Subsystems (6)
SCSI USB Staging s390 +2 more subsystems
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ming Lei

author
#1 lore raw

PATCH v2 7/15 usb: image: microtek: use sg helper to operate sgl

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

Cc Oliver Neukum <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/usb/image/microtek.c | 20 ++++++++------------
 drivers/usb/image/microtek.h |  2 +-
 2 files changed, 9 insertions(+), 13 deletions(-)
drivers/usb/image/microtek.c +8 -12
index 607be1f4fe27..0a57c2cc8e5a 100644
@@ -488,7 +488,6 @@ static void mts_command_done( struct urb *transfer )
 
 static void mts_do_sg (struct urb* transfer)
 {
-	struct scatterlist * sg;
 	int status = transfer->status;
 	MTS_INT_INIT();
 
@@ -500,13 +499,12 @@ static void mts_do_sg (struct urb* transfer)
 		mts_transfer_cleanup(transfer);
         }
 
-	sg = scsi_sglist(context->srb);
-	context->fragment++;
+	context->curr_sg = sg_next(context->curr_sg);
 	mts_int_submit_urb(transfer,
 			   context->data_pipe,
-			   sg_virt(&sg[context->fragment]),
-			   sg[context->fragment].length,
-			   context->fragment + 1 == scsi_sg_count(context->srb) ?
+			   sg_virt(context->curr_sg),
+			   context->curr_sg->length,
+			   sg_is_last(context->curr_sg) ?
 			   mts_data_done : mts_do_sg);
 }
 
@@ -526,22 +524,20 @@ static void
 mts_build_transfer_context(struct scsi_cmnd *srb, struct mts_desc* desc)
 {
 	int pipe;
-	struct scatterlist * sg;
-	
+
 	MTS_DEBUG_GOT_HERE();
 
 	desc->context.instance = desc;
 	desc->context.srb = srb;
-	desc->context.fragment = 0;
 
 	if (!scsi_bufflen(srb)) {
 		desc->context.data = NULL;
 		desc->context.data_length = 0;
 		return;
 	} else {
-		sg = scsi_sglist(srb);
-		desc->context.data = sg_virt(&sg[0]);
-		desc->context.data_length = sg[0].length;
+		desc->context.curr_sg = scsi_sglist(srb);
+		desc->context.data = sg_virt(desc->context.curr_sg);
+		desc->context.data_length = desc->context.curr_sg->length;
 	}
 
 
drivers/usb/image/microtek.h +1 -1
index 66685e59241a..7bd5f4639c4a 100644
@@ -21,7 +21,7 @@ struct mts_transfer_context
 	void *data;
 	unsigned data_length;
 	int data_pipe;
-	int fragment;
+	struct scatterlist *curr_sg;
 
 	u8 *scsi_status; /* status returned from ep_response after command completion */
 };
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH V2 07/15] usb: image: microtek: use sg helper to operate sgl

Quoted 2 lines · Ming Lei

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

Same changelog comment problem as I mentioned on the other patch, please fix up and resend.

thanks,

greg k-h

author
#3 lore raw

PATCH v2 8/15 staging: unisys: visorhba: use sg helper to operate sgl

In reply to a message not in the archive

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

---
 drivers/staging/unisys/visorhba/visorhba_main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/unisys/visorhba/visorhba_main.c +4 -5
index 2dad36a05518..dd979ee4dcf1 100644
@@ -871,12 +871,11 @@ static void do_scsi_nolinuxstat(struct uiscmdrsp *cmdrsp,
 			return;
 		}
 
-		sg = scsi_sglist(scsicmd);
-		for (i = 0; i < scsi_sg_count(scsicmd); i++) {
-			this_page_orig = kmap_atomic(sg_page(sg + i));
+		scsi_for_each_sg(scsicmd, sg, scsi_sg_count(scsicmd), i) {
+			this_page_orig = kmap_atomic(sg_page(sg));
 			this_page = (void *)((unsigned long)this_page_orig |
-					     sg[i].offset);
-			memcpy(this_page, buf + bufind, sg[i].length);
+					     sg->offset);
+			memcpy(this_page, buf + bufind, sg->length);
 			kunmap_atomic(this_page_orig);
 		}
 		kfree(buf);
Signature · 1 line
2.20.1
#4 lore raw
Quoted 2 lines · Ming Lei

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

I can not make any sense out of this changelog.

What "isn't safe"? What is a "sgl"?

Can this be applied "out of order"?

confused,

greg k-h

author
#5 lore raw
Quoted 7 lines · Greg Kroah-Hartman
Quoted 2 lines · Ming Lei

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

I can not make any sense out of this changelog.

What "isn't safe"? What is a "sgl"?

sgl is 'scatterlist' in kernel, and several linear sgl can be chained together, so accessing the sgl in linear way may see a chained sg, which is like a link pointer, then may cause trouble for driver.

Quoted 2 lines

Can this be applied "out of order"?

Yes, there isn't any dependency among the 15 patches.

Thanks,
Ming

#6 lore raw
Quoted 5 lines · Ming Lei
Quoted 4 lines · Greg Kroah-Hartman
Quoted 2 lines · Ming Lei

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

Quoted 7 lines
Quoted 3 lines

I can not make any sense out of this changelog.

What "isn't safe"? What is a "sgl"?

sgl is 'scatterlist' in kernel, and several linear sgl can be chained together, so accessing the sgl in linear way may see a chained sg, which is like a link pointer, then may cause trouble for driver.

What kind of "trouble"? Is this a bug fix that needs to be backported to stable kernels? How can this be triggered?

Quoted 3 lines
Quoted 1 line

Can this be applied "out of order"?

Yes, there isn't any dependency among the 15 patches.

Then perhaps you shouldn't send a numbered patch series with different patches sent to different maintainers, it just causes confusion :)

thanks,

greg k-h

maintainer
#7 lore raw
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Ming Lei
Quoted 7 lines · Greg Kroah-Hartman
Quoted 2 lines · Ming Lei

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

I can not make any sense out of this changelog.

What "isn't safe"? What is a "sgl"?

Quoted 7 lines
Quoted 4 lines

sgl is 'scatterlist' in kernel, and several linear sgl can be chained together, so accessing the sgl in linear way may see a chained sg, which is like a link pointer, then may cause trouble for driver.

What kind of "trouble"? Is this a bug fix that needs to be backported to stable kernels? How can this be triggered?

OK, stop. I haven't seen the commit log since the original hasn't appeared on the list yet, but the changelog needs to say something like this to prevent questions like the above, as I asked in the last review. Please make it something like this:

---
Scsi MQ makes a large static allocation for the first scatter gather list chunk for the driver to use. This is a performance headache we'd like to fix by reducing the size of the allocation to a 2 element array. Doing this will break the current guarantee that any driver using SG_ALL doesn't need to use the scatterlist iterators and can get away with directly dereferencing the array. Thus we need to update all drivers to use the scatterlist iterators and remove direct indexing of the scatterlist array before reducing the initial scatterlist allocation size in SCSI.
---

James

#8 lore raw
In reply to Ming Lei
Quoted 5 lines · Ming Lei
Quoted 4 lines · Greg Kroah-Hartman
Quoted 2 lines · Ming Lei

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

Quoted 8 lines
Quoted 3 lines

I can not make any sense out of this changelog.

What "isn't safe"? What is a "sgl"?

sgl is 'scatterlist' in kernel, and several linear sgl can be chained together, so accessing the sgl in linear way may see a chained sg, which is like a link pointer, then may cause trouble for driver.

So from a user perspective it results in an Oops? It would be really cool if you had the copy of the Oops btw so people could grep the git history for it.

(You need to resend with the improved commit message).

regards,
dan carpenter

author
#9 lore raw

PATCH v2 9/15 s390: zfcp_fc: use sg helper to operate sgl

In reply to a message not in the archive

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

Cc Steffen Maier <[email protected]>
Cc Benjamin Block <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
---
 drivers/s390/scsi/zfcp_fc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/s390/scsi/zfcp_fc.c +2 -2
index 33eddb02ee30..b018b61bd168 100644
@@ -620,7 +620,7 @@ static void zfcp_fc_sg_free_table(struct scatterlist *sg, int count)
 {
 	int i;
 
-	for (i = 0; i < count; i++, sg++)
+	for (i = 0; i < count; i++, sg = sg_next(sg))
 		if (sg)
 			free_page((unsigned long) sg_virt(sg));
 		else
@@ -641,7 +641,7 @@ static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count)
 	int i;
 
 	sg_init_table(sg, count);
-	for (i = 0; i < count; i++, sg++) {
+	for (i = 0; i < count; i++, sg = sg_next(sg)) {
 		addr = (void *) get_zeroed_page(GFP_KERNEL);
 		if (!addr) {
 			zfcp_fc_sg_free_table(sg, i);
Signature · 1 line
2.20.1
#10 lore raw

Re: [PATCH V2 09/15] s390: zfcp_fc: use sg helper to operate sgl

Quoted 27 lines · Ming Lei

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

Cc Steffen Maier <[email protected]>
Cc Benjamin Block <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
---
 drivers/s390/scsi/zfcp_fc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/s390/scsi/zfcp_fc.c +1 -1
index 33eddb02ee30..b018b61bd168 100644
@@ -620,7 +620,7 @@ static void zfcp_fc_sg_free_table(struct scatterlist *sg, int count)
 {
 	int i;
 
-	for (i = 0; i < count; i++, sg++)
+	for (i = 0; i < count; i++, sg = sg_next(sg))
 		if (sg)
 			free_page((unsigned long) sg_virt(sg));
 		else

drivers/s390/scsi/zfcp_fc.c static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count) · line 647

Quoted 8 lines
drivers/s390/scsi/zfcp_fc.c +1 -1
@@ -641,7 +641,7 @@ static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count)
 	int i;
 
 	sg_init_table(sg, count);
-	for (i = 0; i < count; i++, sg++) {
+	for (i = 0; i < count; i++, sg = sg_next(sg)) {
 		addr = (void *) get_zeroed_page(GFP_KERNEL);
 		if (!addr) {
 			zfcp_fc_sg_free_table(sg, i);

Color more confused. Where did the rest of this patch-set go? I don't see any other patches from this series of 15 on linux-scsi? Neither on my mail-account, nor on the archive https://marc.info/?l=linux-scsi

I was looking for a bit more context.

Signature · 4 lines
With Best Regards, Benjamin Block      /      Linux on IBM Z Kernel Development
IBM Systems & Technology Group   /  IBM Deutschland Research & Development GmbH
Vorsitz. AufsR.: Matthias Hartmann       /      Gesch�ftsf�hrung: Dirk Wittkopp
Sitz der Gesellschaft: B�blingen / Registergericht: AmtsG Stuttgart, HRB 243294
author
#11 lore raw

Re: [PATCH V2 09/15] s390: zfcp_fc: use sg helper to operate sgl

Quoted 41 lines · Benjamin Block
Quoted 27 lines · Ming Lei

The current way isn't safe for chained sgl, so use sg helper to operate sgl.

Cc Steffen Maier <[email protected]>
Cc Benjamin Block <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
---
 drivers/s390/scsi/zfcp_fc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/s390/scsi/zfcp_fc.c +1 -1
index 33eddb02ee30..b018b61bd168 100644
@@ -620,7 +620,7 @@ static void zfcp_fc_sg_free_table(struct scatterlist *sg, int count)
 {
 	int i;
 
-	for (i = 0; i < count; i++, sg++)
+	for (i = 0; i < count; i++, sg = sg_next(sg))
 		if (sg)
 			free_page((unsigned long) sg_virt(sg));
 		else

drivers/s390/scsi/zfcp_fc.c static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count) · line 647

Quoted 8 lines
drivers/s390/scsi/zfcp_fc.c +1 -1
@@ -641,7 +641,7 @@ static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count)
 	int i;
 
 	sg_init_table(sg, count);
-	for (i = 0; i < count; i++, sg++) {
+	for (i = 0; i < count; i++, sg = sg_next(sg)) {
 		addr = (void *) get_zeroed_page(GFP_KERNEL);
 		if (!addr) {
 			zfcp_fc_sg_free_table(sg, i);

Color more confused. Where did the rest of this patch-set go? I don't see any other patches from this series of 15 on linux-scsi? Neither on my mail-account, nor on the archive https://marc.info/?l=linux-scsi

Quoted 1 line

I was looking for a bit more context.

Yeah, I also can't find them on the archive, maybe there is issue related with my email box.

I need to check it now.

Thanks,
Ming