Skip to contentSkip to conversation

sr: don't use GFP_DMA

PATCH Applied Christoph Hellwig 3 participants 7 messages Dec 22, 2021 – Dec 23, 2021 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sr: don't use GFP_DMA

The allocated buffers are used as a command payload, for which the block layer and/or DMA API do the proper bounce buffering if needed.

---

Changes since v1:
- also cover the two callsites in sr_vendor.c

Diffstat:

 drivers/scsi/sr.c        | 2 +-
 drivers/scsi/sr_vendor.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/sr.c +1 -1
index 14c122839c409..f925b1f1f9ada 100644
@@ -855,7 +855,7 @@ static void get_capabilities(struct scsi_cd *cd)
 
 
 	/* allocate transfer buffer */
-	buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
+	buffer = kmalloc(512, GFP_KERNEL);
 	if (!buffer) {
 		sr_printk(KERN_ERR, cd, "out of memory.\n");
 		return;
drivers/scsi/sr_vendor.c +2 -2
index 1f988a1b9166f..a61635326ae0a 100644
@@ -131,7 +131,7 @@ int sr_set_blocklength(Scsi_CD *cd, int blocklength)
 	if (cd->vendor == VENDOR_TOSHIBA)
 		density = (blocklength > 2048) ? 0x81 : 0x83;
 
-	buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
+	buffer = kmalloc(512, GFP_KERNEL);
 	if (!buffer)
 		return -ENOMEM;
 
@@ -179,7 +179,7 @@ int sr_cd_check(struct cdrom_device_info *cdi)
 	if (cd->cdi.mask & CDC_MULTI_SESSION)
 		return 0;
 
-	buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
+	buffer = kmalloc(512, GFP_KERNEL);
 	if (!buffer)
 		return -ENOMEM;
 
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#1 lore raw

Hi Christoph,

Quoted 20 lines · Christoph Hellwig

The allocated buffers are used as a command payload, for which the block layer and/or DMA API do the proper bounce buffering if needed.

---

Changes since v1:
- also cover the two callsites in sr_vendor.c

Diffstat:

 drivers/scsi/sr.c        | 2 +-
 drivers/scsi/sr_vendor.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/sr.c +0 -0
index 14c122839c409..f925b1f1f9ada 100644

drivers/scsi/sr.c static void get_capabilities(struct scsi_cd *cd) · line 858

Quoted 5 lines
drivers/scsi/sr.c +1 -1
@@ -855,7 +855,7 @@ static void get_capabilities(struct scsi_cd *cd)
 
 
 	/* allocate transfer buffer */
-	buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
+	buffer = kmalloc(512, GFP_KERNEL);

Thanks a lot for doing this. When I browsed the code path, I come to blk_rq_map_kern() but I am not sure if blk_queue_may_bounce() is true in the sr_probe() case, then it may enter into bio_map_kern().

Next I will post my original patchset to mute the allocation failure if it's requesting page from DMA zone and DMA zone has no managed page. And meanwhile, I will try to collect those places of kmalloc(GFP_DMA) into a RFC mail, see if we can change them one by one. Anyone can pick one place to fix if interested or knowing it well. Finally, we can remove the need of dma-kmalloc() as people suggested. Any comment?

For this patch, it's an awesome start, thx.

Quoted 28 lines
drivers/scsi/sr.c +0 -0
 	if (!buffer) {
 		sr_printk(KERN_ERR, cd, "out of memory.\n");
 		return;
drivers/scsi/sr_vendor.c +2 -2
index 1f988a1b9166f..a61635326ae0a 100644
@@ -131,7 +131,7 @@ int sr_set_blocklength(Scsi_CD *cd, int blocklength)
 	if (cd->vendor == VENDOR_TOSHIBA)
 		density = (blocklength > 2048) ? 0x81 : 0x83;
 
-	buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
+	buffer = kmalloc(512, GFP_KERNEL);
 	if (!buffer)
 		return -ENOMEM;
 
@@ -179,7 +179,7 @@ int sr_cd_check(struct cdrom_device_info *cdi)
 	if (cd->cdi.mask & CDC_MULTI_SESSION)
 		return 0;
 
-	buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
+	buffer = kmalloc(512, GFP_KERNEL);
 	if (!buffer)
 		return -ENOMEM;
 
Signature · 1 line
2.30.2
#2 lore raw
Quoted 7 lines · Baoquan He

drivers/scsi/sr.c static void get_capabilities(struct scsi_cd *cd) · line 858

Quoted 3 lines
drivers/scsi/sr.c +1 -1
 	/* allocate transfer buffer */
-	buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
+	buffer = kmalloc(512, GFP_KERNEL);

Thanks a lot for doing this. When I browsed the code path, I come to blk_rq_map_kern() but I am not sure if blk_queue_may_bounce() is true in the sr_probe() case, then it may enter into bio_map_kern().

blk_queue_may_bounce will be entered for the few drives that set BLK_BOUNCE_HIGH because they can't handle highmem (which is a subset of the non-ZONE_DMA memory). The only driver that actually requires ZONE_DMA based bouncing is ps3rom, and that driver does a manual and ubconditional bounce buffering.

Quoted 5 lines

Next I will post my original patchset to mute the allocation failure if it's requesting page from DMA zone and DMA zone has no managed page. And meanwhile, I will try to collect those places of kmalloc(GFP_DMA) into a RFC mail, see if we can change them one by one. Anyone can pick one place to fix if interested or knowing it well.

I've already sent out patches for all of drivers/scsi/ today, except for the ps3rom bounce buffer alllocation which is fine but should probably be changed to use the page allocator directly.

Quoted 2 lines

Finally, we can remove the
need of dma-kmalloc() as people suggested. Any comment?

Yes.

#3 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Baoquan He

drivers/scsi/sr.c static void get_capabilities(struct scsi_cd *cd) · line 858

Quoted 3 lines
drivers/scsi/sr.c +1 -1
 	/* allocate transfer buffer */
-	buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
+	buffer = kmalloc(512, GFP_KERNEL);

Thanks a lot for doing this. When I browsed the code path, I come to blk_rq_map_kern() but I am not sure if blk_queue_may_bounce() is true in the sr_probe() case, then it may enter into bio_map_kern().

Quoted 5 lines

blk_queue_may_bounce will be entered for the few drives that set BLK_BOUNCE_HIGH because they can't handle highmem (which is a subset of the non-ZONE_DMA memory). The only driver that actually requires ZONE_DMA based bouncing is ps3rom, and that driver does a manual and ubconditional bounce buffering.

Got it now, thx.

Quoted 10 lines
Quoted 6 lines

Next I will post my original patchset to mute the allocation failure if it's requesting page from DMA zone and DMA zone has no managed page. And meanwhile, I will try to collect those places of kmalloc(GFP_DMA) into a RFC mail, see if we can change them one by one. Anyone can pick one place to fix if interested or knowing it well.

I've already sent out patches for all of drivers/scsi/ today, except for the ps3rom bounce buffer alllocation which is fine but should probably be changed to use the page allocator directly.

Sounds really great.

Any thought or plan for those callsites in other places? Possibly we can skip those s390 related drivers since s390 only has DMA zone, no DMA32, it should be OK.

And could you please also add me to CC when send out these patches? We have this problem in our RHEL8 which is based on kernel4.18, if finally removing dma-kmalloc(), we need back port these driver fixes too. If not paying attention, these patches may scatter in different sub-components and unnoticable.

Quoted 6 lines
Quoted 3 lines

Finally, we can remove the
need of dma-kmalloc() as people suggested. Any comment?

Yes.

#4 lore raw
Quoted 3 lines · Baoquan He

Any thought or plan for those callsites in other places? Possibly we can skip those s390 related drivers since s390 only has DMA zone, no DMA32, it should be OK.

Yes, this needs a bit of an audit. A lot of them might be best handled by the subsysem maintainers, e.g. for crypto media and sound.

Quoted 5 lines

And could you please also add me to CC when send out these patches? We have this problem in our RHEL8 which is based on kernel4.18, if finally removing dma-kmalloc(), we need back port these driver fixes too. If not paying attention, these patches may scatter in different sub-components and unnoticable.

I already sent them out yesterday. Just look for everything with GFP_DMA in the subject line in the current scsi tree for 5.17.

#5 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Baoquan He

Any thought or plan for those callsites in other places? Possibly we can skip those s390 related drivers since s390 only has DMA zone, no DMA32, it should be OK.

Yes, this needs a bit of an audit. A lot of them might be best handled by the subsysem maintainers, e.g. for crypto media and sound.

Yes, agree. I can send a mail to subsystem maintainers about this, ask them for help.

Quoted 9 lines
Quoted 6 lines

And could you please also add me to CC when send out these patches? We have this problem in our RHEL8 which is based on kernel4.18, if finally removing dma-kmalloc(), we need back port these driver fixes too. If not paying attention, these patches may scatter in different sub-components and unnoticable.

I already sent them out yesterday. Just look for everything with GFP_DMA in the subject line in the current scsi tree for 5.17.

Got, thx.

#6 lore raw
In reply to Christoph Hellwig

Christoph,

Quoted 2 lines

The allocated buffers are used as a command payload, for which the block layer and/or DMA API do the proper bounce buffering if needed.

Applied to 5.17/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering