Skip to contentSkip to conversation

pflash: flush rom device memory region

PATCH In review Stefan Hajnoczi 2 participants 2 messages Jan 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pflash: flush rom device memory region

pflash devices should mark the memory region dirty and invalidate TBs after directly writing to the RAM backing the ROM device.

Note that pflash_cfi01_get_memory() is used by several machine types to populate ROM contents directly. Callers are untouched by this patch because they only modify memory before the guest is started.

---
Based-on: <[email protected]>

Split from the original patch series. Philippe asked me to drop the flush calls in ->realize() since they are unnecessary.

Peter: Your ARM tree has the memory_region_flush_rom_device() patch that this depends on, so it may be easiest for this to go via your tree.

 hw/block/pflash_cfi01.c | 3 +++
 hw/block/pflash_cfi02.c | 6 ++++++
 2 files changed, 9 insertions(+)
hw/block/pflash_cfi01.c +3 -0
index bffb4c40e7..2f0b9c4c02 100644
@@ -446,6 +446,7 @@ static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
         break;
     }
 
+    memory_region_flush_rom_device(&pfl->mem, offset, width);
 }
 
 static void pflash_write(pflash_t *pfl, hwaddr offset,
@@ -482,6 +483,8 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,
             if (!pfl->ro) {
                 memset(p + offset, 0xff, pfl->sector_len);
                 pflash_update(pfl, offset, pfl->sector_len);
+                memory_region_flush_rom_device(&pfl->mem, offset,
+                                               pfl->sector_len);
             } else {
                 pfl->status |= 0x20; /* Block erase error */
             }
hw/block/pflash_cfi02.c +6 -0
index 0f8b7b8c7b..47edce8dcf 100644
@@ -378,6 +378,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset,
                     pflash_update(pfl, offset, 4);
                     break;
                 }
+
+                memory_region_flush_rom_device(&pfl->orig_mem, offset, width);
             }
             pfl->status = 0x00 | ~(value & 0x80);
             /* Let's pretend write is immediate */
@@ -426,6 +428,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset,
             if (!pfl->ro) {
                 memset(pfl->storage, 0xFF, pfl->chip_len);
                 pflash_update(pfl, 0, pfl->chip_len);
+                memory_region_flush_rom_device(&pfl->orig_mem, 0,
+                                               pfl->chip_len);
             }
             pfl->status = 0x00;
             /* Let's wait 5 seconds before chip erase is done */
@@ -441,6 +445,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset,
             if (!pfl->ro) {
                 memset(p + offset, 0xFF, pfl->sector_len);
                 pflash_update(pfl, offset, pfl->sector_len);
+                memory_region_flush_rom_device(&pfl->orig_mem, offset,
+                                               pfl->sector_len);
             }
             pfl->status = 0x00;
             /* Let's wait 1/2 second before sector erase is done */
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Stefan Hajnoczi

pflash devices should mark the memory region dirty and invalidate TBs after directly writing to the RAM backing the ROM device.

Note that pflash_cfi01_get_memory() is used by several machine types to populate ROM contents directly. Callers are untouched by this patch because they only modify memory before the guest is started.

Quoted 66 lines

---
Based-on: <[email protected]>

Split from the original patch series. Philippe asked me to drop the flush calls in ->realize() since they are unnecessary.

Peter: Your ARM tree has the memory_region_flush_rom_device() patch that this depends on, so it may be easiest for this to go via your tree.

 hw/block/pflash_cfi01.c | 3 +++
 hw/block/pflash_cfi02.c | 6 ++++++
 2 files changed, 9 insertions(+)
hw/block/pflash_cfi01.c +3 -0
index bffb4c40e7..2f0b9c4c02 100644
@@ -446,6 +446,7 @@ static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
         break;
     }
 
+    memory_region_flush_rom_device(&pfl->mem, offset, width);
 }
 
 static void pflash_write(pflash_t *pfl, hwaddr offset,
@@ -482,6 +483,8 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,
             if (!pfl->ro) {
                 memset(p + offset, 0xff, pfl->sector_len);
                 pflash_update(pfl, offset, pfl->sector_len);
+                memory_region_flush_rom_device(&pfl->mem, offset,
+                                               pfl->sector_len);
             } else {
                 pfl->status |= 0x20; /* Block erase error */
             }
hw/block/pflash_cfi02.c +6 -0
index 0f8b7b8c7b..47edce8dcf 100644
@@ -378,6 +378,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset,
                     pflash_update(pfl, offset, 4);
                     break;
                 }
+
+                memory_region_flush_rom_device(&pfl->orig_mem, offset, width);
             }
             pfl->status = 0x00 | ~(value & 0x80);
             /* Let's pretend write is immediate */
@@ -426,6 +428,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset,
             if (!pfl->ro) {
                 memset(pfl->storage, 0xFF, pfl->chip_len);
                 pflash_update(pfl, 0, pfl->chip_len);
+                memory_region_flush_rom_device(&pfl->orig_mem, 0,
+                                               pfl->chip_len);
             }
             pfl->status = 0x00;
             /* Let's wait 5 seconds before chip erase is done */
@@ -441,6 +445,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset,
             if (!pfl->ro) {
                 memset(p + offset, 0xFF, pfl->sector_len);
                 pflash_update(pfl, offset, pfl->sector_len);
+                memory_region_flush_rom_device(&pfl->orig_mem, offset,
+                                               pfl->sector_len);
             }
             pfl->status = 0x00;
             /* Let's wait 1/2 second before sector erase is done */