Skip to contentSkip to conversation

ata-sff: always map page before data transfer

PATCH Superseded Tycho Andersen 2 participants 3 messages May 2, 2017 – May 4, 2017 libata

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ata-sff: always map page before data transfer

The XPFO [1] patchset may unmap pages from physmap if they happened to be destined for userspace. If such a page is unmapped, it needs to be remapped. Rather than test if a page is in the highmem/xpfo unmapped state, Christoph suggested [2] that we simply always map the page.

[1]: https://lkml.org/lkml/2016/11/4/245
[2]: https://lkml.org/lkml/2016/11/4/253
---
I don't understand all the factors at play here, so thoughts are definitely welcome.

---
 drivers/ata/libata-sff.c | 50 +++++++++++++++++-------------------------------
 1 file changed, 18 insertions(+), 32 deletions(-)
drivers/ata/libata-sff.c +18 -32
index 2bd92dc..8da2572 100644
@@ -703,6 +703,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
 	struct page *page;
 	unsigned int offset;
 	unsigned char *buf;
+	unsigned long flags;
 
 	if (qc->curbytes == qc->nbytes - qc->sect_size)
 		ap->hsm_task_state = HSM_ST_LAST;
@@ -716,24 +717,16 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
 
 	DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
 
-	if (PageHighMem(page)) {
-		unsigned long flags;
-
-		/* FIXME: use a bounce buffer */
-		local_irq_save(flags);
-		buf = kmap_atomic(page);
+	/* FIXME: use a bounce buffer */
+	local_irq_save(flags);
+	buf = kmap_atomic(page);
 
-		/* do the actual data transfer */
-		ap->ops->sff_data_xfer(qc, buf + offset, qc->sect_size,
-				       do_write);
+	/* do the actual data transfer */
+	ap->ops->sff_data_xfer(qc, buf + offset, qc->sect_size,
+			       do_write);
 
-		kunmap_atomic(buf);
-		local_irq_restore(flags);
-	} else {
-		buf = page_address(page);
-		ap->ops->sff_data_xfer(qc, buf + offset, qc->sect_size,
-				       do_write);
-	}
+	kunmap_atomic(buf);
+	local_irq_restore(flags);
 
 	if (!do_write && !PageSlab(page))
 		flush_dcache_page(page);
@@ -836,6 +829,7 @@ static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
 	struct page *page;
 	unsigned char *buf;
 	unsigned int offset, count, consumed;
+	unsigned long flags;
 
 next_sg:
 	sg = qc->cursg;
@@ -861,24 +855,16 @@ static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
 
 	DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
 
-	if (PageHighMem(page)) {
-		unsigned long flags;
-
-		/* FIXME: use bounce buffer */
-		local_irq_save(flags);
-		buf = kmap_atomic(page);
+	/* FIXME: use bounce buffer */
+	local_irq_save(flags);
+	buf = kmap_atomic(page);
 
-		/* do the actual data transfer */
-		consumed = ap->ops->sff_data_xfer(qc, buf + offset,
-								count, rw);
+	/* do the actual data transfer */
+	consumed = ap->ops->sff_data_xfer(qc, buf + offset,
+							count, rw);
 
-		kunmap_atomic(buf);
-		local_irq_restore(flags);
-	} else {
-		buf = page_address(page);
-		consumed = ap->ops->sff_data_xfer(qc, buf + offset,
-								count, rw);
-	}
+	kunmap_atomic(buf);
+	local_irq_restore(flags);
 
 	bytes -= min(bytes, consumed);
 	qc->curbytes += count;
Signature · 1 line
2.9.3
#1 lore raw
Quoted 2 lines

I don't understand all the factors at play here, so thoughts are definitely welcome.

I don't fully understand the old code either. One thing that is weird is the "use a bounce buffer comment" which doesn't make any sense.

The other is the local_irq_save, which isn't really needed for kmap_atomic to start with, but maybe that's the reason why the original author didn't want to do it unconditionally?

So based on that:

drivers/ata/libata-sff.c static void ata_pio_sector(struct ata_queued_cmd *qc) · line 720

Quoted 1 line
drivers/ata/libata-sff.c +1 -0
+	/* FIXME: use a bounce buffer */

drop this comment..

Review

Quoted 1 line
(quoted diff) +1 -0
+	local_irq_save(flags);

.. remove the local_irq_save/local_irq_restore ..

drivers/ata/libata-sff.c static void ata_pio_sector(struct ata_queued_cmd *qc) · line 726

Quoted 3 lines
drivers/ata/libata-sff.c +3 -0
+	/* do the actual data transfer */
+	ap->ops->sff_data_xfer(qc, buf + offset, qc->sect_size,
+			       do_write);

.. and a nice alittle cleanup move the do_write onto the previous line.

drivers/ata/libata-sff.c static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) · line 864

Quoted 7 lines
drivers/ata/libata-sff.c +6 -0
+	/* FIXME: use bounce buffer */
+	local_irq_save(flags);
+	buf = kmap_atomic(page);
 
+	/* do the actual data transfer */
+	consumed = ap->ops->sff_data_xfer(qc, buf + offset,
+							count, rw);

And same here.

And we should be fine.

#2 lore raw
Quoted 1 line · Christoph Hellwig

And we should be fine.

Great, I just sent a v2. Thanks!

Tycho