Implement migration support for pflash_cfi01
cover Implement migration support for pflash_cfi01
These patches implement migration support for pflash_cfi01. The first patch just drops some useless state so we don't have to think about it for migration.
NB that pflash_cfi01 is used in the x86 pc model. I think this means that migration while the BIOS is accessing the flash wouldn't have worked properly. Since migration from a device with no vmstate to one with vmstate works OK this shouldn't break cross-version migration. However x86 maintainers may wish to review and confirm this for themselves...
Peter Maydell (2):
pflash_cfi01: Drop unused 'bypass' field
pflash_cfi01: Implement migration support
hw/pflash_cfi01.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/2 pflash_cfi01: Drop unused 'bypass' field
For pflash_cfi01 the 'bypass' field is set to zero and never changes, so remove it (it is a leftover from pflash_cfi02, where bypass is implemented).
--- hw/pflash_cfi01.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
hw/pflash_cfi01.c +2 -8
@@ -68,7 +68,6 @@ struct pflash_t {uint8_t width;uint8_t be;int wcycle;/* if 0, the flash is read normally */ -int bypass;int ro;uint8_t cmd;uint8_t status;
@@ -93,12 +92,8 @@ static void pflash_timer (void *opaque)DPRINTF ("%s: command %02x done\n" , __func__, pfl->cmd);/* Reset flash */ pfl->status ^=0x80 ; -if (pfl->bypass) { - pfl->wcycle =2 ; - }else { -memory_region_rom_device_set_readable (&pfl->mem, true); - pfl->wcycle =0 ; - } +memory_region_rom_device_set_readable (&pfl->mem, true); + pfl->wcycle =0 ; pfl->cmd =0 ; }
@@ -452,7 +447,6 @@ static void pflash_write(pflash_t *pfl, hwaddr offset, reset_flash:memory_region_rom_device_set_readable (&pfl->mem, true); - pfl->bypass =0 ; pfl->wcycle =0 ; pfl->cmd =0 ; }
Signature · 1 line
1.7.9.5
PATCH 2/2 pflash_cfi01: Implement migration support
In reply to Peter MaydellAdd a vmstate to pflash_cfi01, so that it can be live migrated.
XXX this device is in pc, so does this break cross version migration???
--- hw/pflash_cfi01.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
hw/pflash_cfi01.c +17 -3
@@ -67,7 +67,7 @@ struct pflash_t {uint64_t sector_len;uint8_t width;uint8_t be; -int wcycle;/* if 0, the flash is read normally */ +uint8_t wcycle;/* if 0, the flash is read normally */ int ro;uint8_t cmd;uint8_t status;
@@ -77,7 +77,7 @@ struct pflash_t {uint16_t ident3;uint8_t cfi_len;uint8_t cfi_table[0x52 ]; -hwaddr counter; +uint64_t counter;unsigned int writeblock_size;QEMUTimer *timer;MemoryRegion mem;
@@ -85,6 +85,19 @@ struct pflash_t {void *storage; }; +static const VMStateDescription vmstate_pflash = { + .name ="pflash_cfi01" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8 (wcycle, pflash_t), +VMSTATE_UINT8 (cmd, pflash_t), +VMSTATE_UINT8 (status, pflash_t), +VMSTATE_UINT64 (counter, pflash_t), +VMSTATE_END_OF_LIST () + } +}; +static void pflash_timer (void *opaque) {pflash_t *pfl = opaque;
@@ -223,7 +236,7 @@ static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,uint8_t *p = pfl->storage;DPRINTF ("%s: block write offset " TARGET_FMT_plx -" value %x counter " TARGET_FMT_plx"\n" , +" value %x counter %016" PRIx64"\n" , __func__, offset, value, pfl->counter);switch (width) {case 1 :
@@ -701,6 +714,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass, void *data) k->init = pflash_cfi01_init; dc->props = pflash_cfi01_properties; + dc->vmsd = &vmstate_pflash; }
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH 2/2] pflash_cfi01: Implement migration support
Quoted 4 lines · Peter Maydell
Add a vmstate to
pflash_cfi01, so that it can be live migrated.XXX this device is in pc, so does this break cross version migration???
Oops. I checked that this was going to work ok, but forgot to remove the XXX markers. I'm planning to put these patches into the arm-devs queue, so I'll just remove this line from the commit message at that point.
thanks
-- PMM
[Qemu-devel] Use of flash for x86 BIOS (was: [PATCH 0/2] Implement migration support for pflash_cfi01)
In reply to Peter Maydell[Note cc: Jordan, who added flash to x86 in commit bd183c79]
Quoted 10 lines · Peter Maydell
These patches implement migration support for
pflash_cfi01. The first patch just drops some useless state so we don't have to think about it for migration.NB that
pflash_cfi01is used in the x86 pc model. I think this means that migration while the BIOS is accessing the flash wouldn't have worked properly. Since migration from a device with no vmstate to one with vmstate works OK this shouldn't break cross-version migration. However x86 maintainers may wish to review and confirm this for themselves...
x86 maintainers may wish to *switch it off* until it's done fully and properly, by setting "pc-sysfw" property "rom_only" to 1.
x86 flash use was added in series "[PATCH v10 0/8] PC system flash support", commit 4732dcaf..1b89fafe, v1.1. Core code is pc_system_firmware_init(). Works as follows, as far as I can tell:
* Create a "pc-sysfw" device with default properties.
This device does nothing in particular, and is *not* guest-visible. It appears to be used just as a property container.
* If (default) property "rom_only" is non-zero, map the BIOS ROM the traditional way. Get its contents from the file named by -bios, default "bios.bin".
This is the case for isapc as well as pc-1.0 and older.
* Else, if KVM is enabled, putting BIOS in flash doesn't actually work (KVM restriction), so force "rom_only" to one, and map the BIOS ROM the traditional way, as above.
Fatal error if the user defined drive if=pflash,bus=0,unit=0, because that's valid only when we're using flash for the BIOS ROM.
I understand this case is meant to go away when the KVM restriction gets lifted.
* Else, map the BIOS ROM as flash device.
Note: for now, this case applies only when KVM is disabled.
- If the user did not define said pflash drive, create one with BIOS ROM contents (get it the same way as above). Failure is fatal.
- Create a "cfi.pflash01" block device backed by the pflash drive.
What does this mean?
1. The "pc-sysfw" device is mostly harmless.
2. Enabling/disabling KVM is guest-visible! With KVM disabled, you get a flash memory device. With KVM enabled, you get a ROM. Not good; KVM should be as transparent as possible to the guest.
I raised this issue last August, Jordan told me he's working on it[*], and I let the matter rest then. That was a mistake.
[*] http://lists.nongnu.org/archive/html/qemu-devel/2012-08/msg03178.html
Re: [Qemu-devel] Use of flash for x86 BIOS (was: [PATCH 0/2] Implement migration support for pflash_cfi01)
Quoted 15 lines · Markus Armbruster
[Note cc: Jordan, who added flash to x86 in commit
bd183c79]Quoted 10 lines · Peter Maydell
These patches implement migration support for
pflash_cfi01. The first patch just drops some useless state so we don't have to think about it for migration.NB that
pflash_cfi01is used in the x86 pc model. I think this means that migration while the BIOS is accessing the flash wouldn't have worked properly. Since migration from a device with no vmstate to one with vmstate works OK this shouldn't break cross-version migration. However x86 maintainers may wish to review and confirm this for themselves...
Quoted 2 lines
x86 maintainers may wish to *switch it off* until it's done fully and properly, by setting "pc-sysfw" property "
rom_only" to 1.
So does that mean that these patches can't be applied until the rom_only property is set, or is that a fix that can be made independently?
thanks
-- PMM
Re: [Qemu-devel] Use of flash for x86 BIOS
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Markus Armbruster
[Note cc: Jordan, who added flash to x86 in commit
bd183c79]Quoted 10 lines · Peter Maydell
These patches implement migration support for
pflash_cfi01. The first patch just drops some useless state so we don't have to think about it for migration.NB that
pflash_cfi01is used in the x86 pc model. I think this means that migration while the BIOS is accessing the flash wouldn't have worked properly. Since migration from a device with no vmstate to one with vmstate works OK this shouldn't break cross-version migration. However x86 maintainers may wish to review and confirm this for themselves...
Quoted 6 lines
Quoted 2 lines
x86 maintainers may wish to *switch it off* until it's done fully and properly, by setting "pc-sysfw" property "
rom_only" to 1.So does that mean that these patches can't be applied until the
rom_onlyproperty is set, or is that a fix that can be made independently?
If your patches work, then applying them can't make things worse for x86 than they already are, can it? Thus, independent, I guess.
Re: [Qemu-devel] Use of flash for x86 BIOS (was: [PATCH 0/2] Implement migration support for pflash_cfi01)
In reply to Markus ArmbrusterQuoted 2 lines · Markus Armbruster
x86 maintainers may wish to *switch it off* until it's done fully and properly, by setting "pc-sysfw" property "
rom_only" to 1.
This would completely disable the flash support. At the time this feature was added, I think it was well understood that kvm would not support the flash mode, while plain qemu could. If it was not a show-stopper to integrating the feature originally, what has changed?
rom_only was added as part of the flash support enabling. I guess in a way it would be amusing to use it to disabled that same feature.
Quoted 1 line
1. The "pc-sysfw" device is mostly harmless.
Indeed, and it's only marginally of interest until kvm supports it.
Admittedly, I've been completely ineffectual in resolving the kvm portion. More recently I tried to make use of KVM_MEM_READONLY to address this. I was able to get an VM exit on writes to flash, but not able to get the memory region to convert to full device mode so VM exits would occur on reads as well. I am once again stalled...
-Jordan
Re: [Qemu-devel] Use of flash for x86 BIOS
Quoted 5 lines · Jordan Justen
Quoted 2 lines · Markus Armbruster
x86 maintainers may wish to *switch it off* until it's done fully and properly, by setting "pc-sysfw" property "
rom_only" to 1.This would completely disable the flash support.
Unless the user enables it explicitly with something like "-global pc-sysfw.rom_only=0".
Quoted 4 lines
At the time this
feature was added, I think it was well understood that kvm would not support the flash mode, while plain qemu could. If it was not a show-stopper to integrating the feature originally, what has changed?
Nothing changed, and that's the problem.
Merging the feature was okay, I think. Defaulting it to "on" with TCG and "off" with KVM was a mistake, because that made enabling/disabling KVM guest-visible (see item 2. below). The default needs to be the same both with and without KVM. Since the thing still doesn't work with KVM, the default needs to be "off".
A possible explanation for making this mistake is that people assumed it would soon work with KVM. That turned out not to be the case.
Quoted 5 lines
rom_onlywas added as part of the flash support enabling. I guess in a way it would be amusing to use it to disabled that same feature.Quoted 1 line
1. The "pc-sysfw" device is mostly harmless.
Quoted 7 lines
Indeed, and it's only marginally of interest until kvm supports it.
Admittedly, I've been completely ineffectual in resolving the kvm portion. More recently I tried to make use of
KVM_MEM_READONLYto address this. I was able to get an VM exit on writes to flash, but not able to get the memory region to convert to full device mode so VM exits would occur on reads as well. I am once again stalled...
Have you discussed your difficulties on [email protected]?
Quoted 8 lines
Quoted 8 lines
2. Enabling/disabling KVM is guest-visible! With KVM disabled, you get a flash memory device. With KVM enabled, you get a ROM. Not good; KVM should be as transparent as possible to the guest.
I raised this issue last August, Jordan told me he's working on it[*], and I let the matter rest then. That was a mistake.
[*] http://lists.nongnu.org/archive/html/qemu-devel/2012-08/msg03178.html
Re: [Qemu-devel] Use of flash for x86 BIOS
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Jordan Justen
Quoted 1 line
1. The "pc-sysfw" device is mostly harmless.
Indeed, and it's only marginally of interest until kvm supports it.
Quoted 7 lines
Quoted 5 lines
Admittedly, I've been completely ineffectual in resolving the kvm portion. More recently I tried to make use of
KVM_MEM_READONLYto address this. I was able to get an VM exit on writes to flash, but not able to get the memory region to convert to full device mode so VM exits would occur on reads as well. I am once again stalled...Have you discussed your difficulties on [email protected]?
The most recent discussion that I'm aware of was:
http://lists.nongnu.org/archive/html/qemu-devel/2013-01/msg05150.html
http://lists.nongnu.org/archive/html/qemu-devel/2013-01/msg05236.html
(both are sub-threads under the same patch submission).
Laszlo
Re: [Qemu-devel] Use of flash for x86 BIOS
In reply to Markus ArmbrusterQuoted 18 lines · Markus Armbruster
Quoted 5 lines · Jordan Justen
Quoted 2 lines · Markus Armbruster
x86 maintainers may wish to *switch it off* until it's done fully and properly, by setting "pc-sysfw" property "
rom_only" to 1.This would completely disable the flash support.
Unless the user enables it explicitly with something like "-global pc-sysfw.rom_only=0".
Quoted 4 lines
At the time this
feature was added, I think it was well understood that kvm would not support the flash mode, while plain qemu could. If it was not a show-stopper to integrating the feature originally, what has changed?Nothing changed, and that's the problem.
Quoted 8 lines
Merging the feature was okay, I think. Defaulting it to "on" with TCG and "off" with KVM was a mistake, because that made enabling/disabling KVM guest-visible (see item 2. below). The default needs to be the same both with and without KVM. Since the thing still doesn't work with KVM, the default needs to be "off".
A possible explanation for making this mistake is that people assumed it would soon work with KVM. That turned out not to be the case.
Given this can be overridden on the command line it does seem reasonable to disable it by default until KVM support is in place.
Slight off topic, does pc_q35 intend to support SPI flash at some point? SPI programming is at a different MMIO address from the flash, so it should be possible to support with qemu/kvm today.
Are there any plans for Q35 to become the default qemu PC machine?
-Jordan
Re: [Qemu-devel] Use of flash for x86 BIOS
Quoted 26 lines · Jordan Justen
Quoted 25 lines · Markus Armbruster
Quoted 6 lines · Jordan Justen
Quoted 2 lines · Markus Armbruster
x86 maintainers may wish to *switch it off* until it's done fully and properly, by setting "pc-sysfw" property "
rom_only" to 1.This would completely disable the flash support.
Unless the user enables it explicitly with something like "-global pc-sysfw.rom_only=0".
Quoted 4 lines
At the time this
feature was added, I think it was well understood that kvm would not support the flash mode, while plain qemu could. If it was not a show-stopper to integrating the feature originally, what has changed?Nothing changed, and that's the problem.
Merging the feature was okay, I think. Defaulting it to "on" with TCG and "off" with KVM was a mistake, because that made enabling/disabling KVM guest-visible (see item 2. below). The default needs to be the same both with and without KVM. Since the thing still doesn't work with KVM, the default needs to be "off".
Quoted 5 lines
Quoted 2 lines
A possible explanation for making this mistake is that people assumed it would soon work with KVM. That turned out not to be the case.
Given this can be overridden on the command line it does seem reasonable to disable it by default until KVM support is in place.
Sent, you're cc'ed.
Quoted 3 lines
Slight off topic, does
pc_q35intend to support SPI flash at some point? SPI programming is at a different MMIO address from the flash, so it should be possible to support with qemu/kvm today.
No idea :)
Quoted 1 line
Are there any plans for Q35 to become the default qemu PC machine?
Unless I'm mistaken, that's the plan.
Re: [Qemu-devel] Use of flash for x86 BIOS
In reply to Jordan JustenQuoted 5 lines · Jordan Justen
Admittedly, I've been completely ineffectual in resolving the kvm portion. More recently I tried to make use of
KVM_MEM_READONLYto address this. I was able to get an VM exit on writes to flash, but not able to get the memory region to convert to full device mode so VM exits would occur on reads as well. I am once again stalled...
Hi Jordan,
What's memory region you want to get? I should admit that I do not have enough background of flash, could you please explain this requirement more detail?
Thanks!
Re: [Qemu-devel] Use of flash for x86 BIOS
Quoted 8 lines · Xiao Guangrong
Quoted 5 lines · Jordan Justen
Admittedly, I've been completely ineffectual in resolving the kvm portion. More recently I tried to make use of
KVM_MEM_READONLYto address this. I was able to get an VM exit on writes to flash, but not able to get the memory region to convert to full device mode so VM exits would occur on reads as well. I am once again stalled...
Quoted 5 lines
Hi Jordan,
What's memory region you want to get? I should admit that I do not have enough background of flash, could you please explain this requirement more detail?
The flash memory requires two modes.
Read/Execute mode:
* Initial state
* Writes will trap to QEMU, and may transition to Device mode based on QEMU device emulation
Device mode:
* Region is not executable
* All reads & writes will trap to QEMU
* May transition back to Read/Execute mode based on QEMU device emulation
Using KVM_MEM_READONLY I was able to get Read/Execute mode to work, but I was not able to get the memory region to transition to Device mode. (I couldn't get reads to trap to QEMU.)
-Jordan
Re: [Qemu-devel] Use of flash for x86 BIOS
Quoted 23 lines · Jordan Justen
Quoted 8 lines · Xiao Guangrong
Quoted 5 lines · Jordan Justen
Admittedly, I've been completely ineffectual in resolving the kvm portion. More recently I tried to make use of
KVM_MEM_READONLYto address this. I was able to get an VM exit on writes to flash, but not able to get the memory region to convert to full device mode so VM exits would occur on reads as well. I am once again stalled...Quoted 5 lines
Hi Jordan,
What's memory region you want to get? I should admit that I do not have enough background of flash, could you please explain this requirement more detail?
The flash memory requires two modes.
Read/Execute mode:
* Initial state
* Writes will trap to QEMU, and may transition to Device mode based on QEMU device emulation
Quoted 9 lines
Device mode:
* Region is not executable
* All reads & writes will trap to QEMU
* May transition back to Read/Execute mode based on QEMU device emulationUsing
KVM_MEM_READONLYI was able to get Read/Execute mode to work, but I was not able to get the memory region to transition to Device mode. (I couldn't get reads to trap to QEMU.)
You need to drop memslot when you transition to Device mode.
--
Gleb.
Re: [Qemu-devel] Use of flash for x86 BIOS
Quoted 29 lines · Gleb Natapov
Quoted 28 lines · Jordan Justen
Quoted 8 lines · Xiao Guangrong
Quoted 5 lines · Jordan Justen
Admittedly, I've been completely ineffectual in resolving the kvm portion. More recently I tried to make use of
KVM_MEM_READONLYto address this. I was able to get an VM exit on writes to flash, but not able to get the memory region to convert to full device mode so VM exits would occur on reads as well. I am once again stalled...Quoted 5 lines
Hi Jordan,
What's memory region you want to get? I should admit that I do not have enough background of flash, could you please explain this requirement more detail?
The flash memory requires two modes.
Read/Execute mode:
* Initial state
* Writes will trap to QEMU, and may transition to Device mode based on QEMU device emulationDevice mode:
* Region is not executable
* All reads & writes will trap to QEMU
* May transition back to Read/Execute mode based on QEMU device emulation
Quoted 5 lines
Quoted 4 lines
Using
KVM_MEM_READONLYI was able to get Read/Execute mode to work, but I was not able to get the memory region to transition to Device mode. (I couldn't get reads to trap to QEMU.)You need to drop memslot when you transition to Device mode.
Yes. After delete the memslot, you can intercept both write and read. ;)