Skip to contentSkip to conversation

libata: fix DMA to stack in reading devslp_timing parameters

PATCH Applied David Woodhouse 3 participants 4 messages Mar 29, 2013 – Apr 3, 2013 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libata: fix DMA to stack in reading devslp_timing parameters

Commit 803739d25c2343da6d2f95eebdcbc08bf67097d4 ("[libata] replace sata_settings with devslp_timing"), which was also Cc: stable, used a stack buffer to receive data from ata_read_log_page(), which triggers
the following warning:
ahci 0000:00:1f.2: DMA-API: device driver maps memory fromstack [addr=ffff880140469948]

Fix this by using ap->sector_buf instead of a stack buffer.

---
I'm somewhat ignorant, but it looks like this is kind of thing is what ap->sector_buf is *for*, right? And in ata_dev_configure() nobody else is likely to be using it?

drivers/ata/libata-core.c +1 -1
index 497adea..b1160ee 100644
@@ -2329,7 +2329,7 @@ int ata_dev_configure(struct ata_device *dev)
 		 * from SATA Settings page of Identify Device Data Log.
 		 */
 		if (ata_id_has_devslp(dev->id)) {
-			u8 sata_setting[ATA_SECT_SIZE];
+			u8 *sata_setting = ap->sector_buf;
 			int i, j;
 
 			dev->flags |= ATA_DFLAG_DEVSLP;
Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#1 lore raw

Hi David,

Quoted 6 lines

Fix this by using ap->sector_buf instead of a stack buffer.

---
I'm somewhat ignorant, but it looks like this is kind of thing is what ap->sector_buf is *for*, right? And in ata_dev_configure() nobody else is likely to be using it?

Your fix is fine with me, thanks. I didn't notice this warning since CONFIG_DMA_API_DEBUG was not set here.

Regards,
Shane

#2 lore raw
In reply to David Woodhouse
Quoted 3 lines · David Woodhouse

Commit 803739d25c2343da6d2f95eebdcbc08bf67097d4 ("[libata] replace sata_settings with devslp_timing"), which was also Cc: stable, used a stack buffer to receive data from ata_read_log_page()...

That commit also changes from using ata_id_has_ncq() to ata_id_has_devslp() as the condition for reading the SATA settings log page (log 0x30 page 0x08), because of compatibility issues with some drives which *do* implement NCQ but not DEVSLP.

It's not entirely clear to me that this change was correct. Even if the drive does support DEVSLP, the timings in the SATA settings log page are optional, and we're supposed to use default values if they are not provided. I can imagine some DEVSLP-capable drives not having that page either.

Shouldn't we be reading page zero of the 0x30 log, which *is* mandatory, and looking there to see which pages are supported?

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
Applied
#3 lore raw
In reply to David Woodhouse
Quoted 10 lines · David Woodhouse

Commit 803739d25c2343da6d2f95eebdcbc08bf67097d4 ("[libata] replace sata_settings with devslp_timing"), which was also Cc: stable, used a
stack buffer to receive data from ata_read_log_page(), which triggers
the following warning:
ahci 0000:00:1f.2: DMA-API: device driver maps memory fromstack [addr=ffff880140469948]

Fix this by using ap->sector_buf instead of a stack buffer.

applied

Quoted 3 lines

I'm somewhat ignorant, but it looks like this is kind of thing is what ap->sector_buf is *for*, right? And in ata_dev_configure() nobody else is likely to be using it?

yep