i386: drop FDC in pc-q35-2.4+ if neither it nor floppy drives are wanted
PATCH 1/1 i386: drop FDC in pc-q35-2.4+ if neither it nor floppy drives are wanted
It is Very annoying to carry forward an outdatEd coNtroller with a mOdern Machine type.
Hence, let us not instantiate the FDC when all of the following apply:
- the machine type is pc-q35-2.4 or later,
- "-device isa-fdc" is not passed on the command line (nor in the config file),
- no "-drive if=floppy,..." is requested.
The first part of the code flow, updated by the patch, is as follows:
1. The "no_floppy = 1" machine class setting causes "default_floppy" in main() to become zero.
2. Hence default_drive() will not call drive_add() and drive_new() for IF_FLOPPY, index=0.
This alone would not suffice, because the pc_basic_device_init() function creates the FDC regardless of actual floppy drives. Therefore,
3. pc_basic_device_init() should only create the FDC if that's desirable for the platform (= all PIIX types, and Q35 types earlier than 2.4), *or* the user requested at least one IF_FLOPPY drive.
4. If the FDC is not created, callers of pc_basic_device_init() -- pc_q35_init() and pc_init1() -- will pass floppy=NULL to pc_cmos_init(). Luckily, pc_cmos_init() already handles that case.
I verified the patch under the following scenarios, with "info qtree" and with the MAP command of the UEFI shell (in OVMF):
- "pc" machine type -- no changes, FDC present,
- "pc-q35-2.3" machine type -- no changes, FDC present,
- "pc-q35" machine type with "-device isa-fdc" -- no changes, FDC present,
- "pc-q35" machine type with "-drive if=floppy,..." -- no changes, FDC present,
- "pc-q35" -- no FDC.
--- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 4 +++- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 12 +++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-)
include/hw/i386/pc.h +1 -0
@@ -199,6 +199,7 @@ qemu_irq *pc_allocate_cpu_irq(void);DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus);void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs);
hw/i386/pc.c +3 -1
@@ -1395,6 +1395,7 @@ static const MemoryRegionOps ioportF0_io_ops = {void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs)
@@ -1489,8 +1490,9 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,for (i =0 ; i <MAX_FD ; i++) { fd[i] =drive_get (IF_FLOPPY ,0 , i); + force_fdctrl |= !!fd[i]; } - *floppy =fdctrl_init_isa (isa_bus, fd); + *floppy = force_fdctrl ?fdctrl_init_isa (isa_bus, fd) :NULL ; }void pc_nic_init (ISABus *isa_bus,PCIBus *pci_bus)
hw/i386/pc_piix.c +1 -1
@@ -242,7 +242,7 @@ static void pc_init1(MachineState *machine, }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, true, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0x4 );pc_nic_init (isa_bus, pci_bus);
hw/i386/pc_q35.c +9 -3
@@ -60,6 +60,7 @@ static bool smbios_uuid_encoded = true;*/ static bool gigabyte_align = true;static bool has_reserved_memory = true; +static bool force_fdctrl;/* PC hardware initialisation */ static void pc_q35_init (MachineState *machine)
@@ -250,7 +251,7 @@ static void pc_q35_init(MachineState *machine) }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, force_fdctrl, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0xff0104 );/* connect pm stuff to lpc */
@@ -291,6 +292,7 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { + force_fdctrl = true; }static void pc_compat_2_2 (MachineState *machine)
@@ -424,7 +426,8 @@ static void pc_q35_init_1_4(MachineState *machine)#define PC_Q35_2_4_MACHINE_OPTIONS \ PC_Q35_MACHINE_OPTIONS, \ .default_machine_opts = "firmware=bios-256k.bin", \ - .default_display = "std" + .default_display = "std", \ + .no_floppy = 1static QEMUMachine pc_q35_machine_v2_4 = {PC_Q35_2_4_MACHINE_OPTIONS ,
@@ -433,7 +436,10 @@ static QEMUMachine pc_q35_machine_v2_4 = { .init = pc_q35_init, }; -#define PC_Q35_2_3_MACHINE_OPTIONS PC_Q35_2_4_MACHINE_OPTIONS +#define PC_Q35_2_3_MACHINE_OPTIONS \ + PC_Q35_MACHINE_OPTIONS, \ + .default_machine_opts = "firmware=bios-256k.bin", \ + .default_display = "std"static QEMUMachine pc_q35_machine_v2_3 = {PC_Q35_2_3_MACHINE_OPTIONS ,
Signature · 1 line
1.8.3.1
Quoted 139 lines · Laszlo Ersek
It is Very annoying to carry forward an outdatEd coNtroller with a mOdern Machine type.
Hence, let us not instantiate the FDC when all of the following apply:
- the machine type is pc-q35-2.4 or later,
- "-device isa-fdc" is not passed on the command line (nor in the config file),
- no "-drive if=floppy,..." is requested.The first part of the code flow, updated by the patch, is as follows:
1. The "
no_floppy= 1" machine class setting causes "default_floppy" inmain()to become zero.2. Hence
default_drive()will not calldrive_add()anddrive_new()forIF_FLOPPY, index=0.This alone would not suffice, because the
pc_basic_device_init()function creates the FDC regardless of actual floppy drives. Therefore,3.
pc_basic_device_init()should only create the FDC if that's desirable for the platform (= all PIIX types, and Q35 types earlier than 2.4), *or* the user requested at least oneIF_FLOPPYdrive.4. If the FDC is not created, callers of
pc_basic_device_init()--pc_q35_init()andpc_init1()-- will pass floppy=NULL topc_cmos_init(). Luckily,pc_cmos_init()already handles that case.I verified the patch under the following scenarios, with "info qtree" and with the MAP command of the UEFI shell (in OVMF):
- "pc" machine type -- no changes, FDC present,
- "pc-q35-2.3" machine type -- no changes, FDC present,
- "pc-q35" machine type with "-device isa-fdc" -- no changes, FDC present,
- "pc-q35" machine type with "-drive if=floppy,..." -- no changes, FDC present,
- "pc-q35" -- no FDC.Suggested-by Markus Armbruster <[email protected]>Cc Markus Armbruster <[email protected]>Cc Paolo Bonzini <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>--- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 4 +++- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 12 +++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-)include/hw/i386/pc.h +1
-0@@ -199,6 +199,7 @@ qemu_irq *pc_allocate_cpu_irq(void);DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus);void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs);hw/i386/pc.c +3
-1@@ -1395,6 +1395,7 @@ static const MemoryRegionOps ioportF0_io_ops = {void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs)@@ -1489,8 +1490,9 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,for (i =0 ; i <MAX_FD ; i++) { fd[i] =drive_get (IF_FLOPPY ,0 , i); + force_fdctrl |= !!fd[i]; } - *floppy =fdctrl_init_isa (isa_bus, fd); + *floppy = force_fdctrl ?fdctrl_init_isa (isa_bus, fd) :NULL ; }void pc_nic_init (ISABus *isa_bus,PCIBus *pci_bus)hw/i386/pc_piix.c +1
-1@@ -242,7 +242,7 @@ static void pc_init1(MachineState *machine, }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, true, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0x4 );pc_nic_init (isa_bus, pci_bus);hw/i386/pc_q35.c +5
-2@@ -60,6 +60,7 @@ static bool smbios_uuid_encoded = true;*/ static bool gigabyte_align = true;static bool has_reserved_memory = true; +static bool force_fdctrl;/* PC hardware initialisation */ static void pc_q35_init (MachineState *machine)@@ -250,7 +251,7 @@ static void pc_q35_init(MachineState *machine) }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, force_fdctrl, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0xff0104 );/* connect pm stuff to lpc */ @@ -291,6 +292,7 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { + force_fdctrl = true; }static void pc_compat_2_2 (MachineState *machine)@@ -424,7 +426,8 @@ static void pc_q35_init_1_4(MachineState *machine)#define PC_Q35_2_4_MACHINE_OPTIONS \ PC_Q35_MACHINE_OPTIONS, \ .default_machine_opts = "firmware=bios-256k.bin", \ - .default_display = "std" + .default_display = "std", \ + .no_floppy = 1static QEMUMachine pc_q35_machine_v2_4 = {PC_Q35_2_4_MACHINE_OPTIONS ,@@ -433,7 +436,10 @@ static QEMUMachine pc_q35_machine_v2_4 = { .init = pc_q35_init,
hw/i386/pc_q35.c static QEMUMachine pc_q35_machine_v2_4 = { · line 445
Quoted 10 lines
hw/i386/pc_q35.c +4
-1}; -#define PC_Q35_2_3_MACHINE_OPTIONS PC_Q35_2_4_MACHINE_OPTIONS +#define PC_Q35_2_3_MACHINE_OPTIONS \ + PC_Q35_MACHINE_OPTIONS, \ + .default_machine_opts = "firmware=bios-256k.bin", \ + .default_display = "std"static QEMUMachine pc_q35_machine_v2_3 = {PC_Q35_2_3_MACHINE_OPTIONS ,
Quoted 2 lines · Laszlo Ersek
It is Very annoying to carry forward an outdatEd coNtroller with a mOdern Machine type.
Surely Unnecessary Crap can still Kill Security.
Quoted 10 lines
Hence, let us not instantiate the FDC when all of the following apply:
- the machine type is pc-q35-2.4 or later,
- "-device isa-fdc" is not passed on the command line (nor in the config file),
- no "-drive if=floppy,..." is requested.The first part of the code flow, updated by the patch, is as follows:
1. The "
no_floppy= 1" machine class setting causes "default_floppy" inmain()to become zero.
Yup. It's copied around some, but that's its only real effect.
Quoted 2 lines
2. Hence
default_drive()will not calldrive_add()anddrive_new()forIF_FLOPPY, index=0.
This is the backend created for the board to pick up. If the board doesn't pick it up, the backend remains unused, which is confusing. Boards that don't pick up IF_FLOPPY backends should set no_floppy to avoid the confusion. Aside: precious few do.
In short: good.
Quoted 5 lines
This alone would not suffice, because the
pc_basic_device_init()function creates the FDC regardless of actual floppy drives. Therefore,3.
pc_basic_device_init()should only create the FDC if that's desirable for the platform (= all PIIX types, and Q35 types earlier than 2.4),
This is the conservative choice.
Arguably, Q35 got versioned prematurely. Dropping the FDC from Q35 unconditionally has been proposed, on the basis that it wasn't fit for serious use in prior releases anyway. I think if we decide we're fine with changing the released Q35 machine types incompatibly, then we should consider going all the way and simply drop them.
But let's not get review of this patch bogged down in a Q35 versioning debate. Whatever we want done there, we can do on top of this patch.
Quoted 1 line
*or* the user requested at least one
IF_FLOPPYdrive.
This is the magic to keep -drive if=floppy just work with Q35.
On the one hand, we've come to hate command line magic.
On the other hand, this is exactly the kind of magic -drive does. For instance, PC boards create lsi53c895a SCSI HBAs for -drive if=scsi. Your patch makes them create an isa-fdc for -drive if=floppy.
Magic or no magic, I don't care. Whatever it takes to get the FDC out of Q35.
If the magic should run into review trouble, putting it into its own patch may help keeping the non-magic (and hopefully uncontroversial) parts out of the debate.
Quoted 9 lines
4. If the FDC is not created, callers of
pc_basic_device_init()--pc_q35_init()andpc_init1()-- will pass floppy=NULL topc_cmos_init(). Luckily,pc_cmos_init()already handles that case.I verified the patch under the following scenarios, with "info qtree" and with the MAP command of the UEFI shell (in OVMF):
- "pc" machine type -- no changes, FDC present,
- "pc-q35-2.3" machine type -- no changes, FDC present,
- "pc-q35" machine type with "-device isa-fdc" -- no changes, FDC present,
Perhaps worth mentioning somewhere in the commit message: instead of the arcane -global isa-fdc.driveA=... (which breaks down when you have more than one isa-fdc), you simply do the regular -device isa-fdc,driveA=...
Discussed in a bit more details in
<http://lists.nongnu.org/archive/html/qemu-devel/2015-05/msg03121.html>.
Quoted 21 lines
- "pc-q35" machine type with "-drive if=floppy,..." -- no changes, FDC present,
- "pc-q35" -- no FDC.Suggested-by Markus Armbruster <[email protected]>Cc Markus Armbruster <[email protected]>Cc Paolo Bonzini <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>--- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 4 +++- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 12 +++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-)include/hw/i386/pc.h +0
-0
include/hw/i386/pc.h qemu_irq *pc_allocate_cpu_irq(void); · line 205
Quoted 7 lines
include/hw/i386/pc.h +1
-0@@ -199,6 +199,7 @@ qemu_irq *pc_allocate_cpu_irq(void);DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus);void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs);
The name @force_fdctrl gave me pause: what are we forcing here?
I guess your rationale is something like "force creation of FDC even when there are no if=floppy drives." Hmm.
Quoted 49 lines
hw/i386/pc.c +3
-1@@ -1395,6 +1395,7 @@ static const MemoryRegionOps ioportF0_io_ops = {void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs)@@ -1489,8 +1490,9 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,for (i =0 ; i <MAX_FD ; i++) { fd[i] =drive_get (IF_FLOPPY ,0 , i); + force_fdctrl |= !!fd[i]; } - *floppy =fdctrl_init_isa (isa_bus, fd); + *floppy = force_fdctrl ?fdctrl_init_isa (isa_bus, fd) :NULL ; }void pc_nic_init (ISABus *isa_bus,PCIBus *pci_bus)hw/i386/pc_piix.c +1
-1@@ -242,7 +242,7 @@ static void pc_init1(MachineState *machine, }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, true, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0x4 );pc_nic_init (isa_bus, pci_bus);hw/i386/pc_q35.c +1
-0@@ -60,6 +60,7 @@ static bool smbios_uuid_encoded = true;*/ static bool gigabyte_align = true;static bool has_reserved_memory = true; +static bool force_fdctrl;/* PC hardware initialisation */ static void pc_q35_init (MachineState *machine)
hw/i386/pc_q35.c static void pc_q35_init(MachineState *machine) · line 257
Quoted 8 lines
hw/i386/pc_q35.c +1
-1@@ -250,7 +251,7 @@ static void pc_q35_init(MachineState *machine) }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, force_fdctrl, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0xff0104 );/* connect pm stuff to lpc */
If we can get from MachineState *machine to its MachineClass, we could use MachineClass member no_floppy, and not need force_fdctrl. Probably a wash.
Quoted 20 lines
hw/i386/pc_q35.c +3
-1@@ -291,6 +292,7 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { + force_fdctrl = true; }static void pc_compat_2_2 (MachineState *machine)@@ -424,7 +426,8 @@ static void pc_q35_init_1_4(MachineState *machine)#define PC_Q35_2_4_MACHINE_OPTIONS \ PC_Q35_MACHINE_OPTIONS, \ .default_machine_opts = "firmware=bios-256k.bin", \ - .default_display = "std" + .default_display = "std", \ + .no_floppy = 1static QEMUMachine pc_q35_machine_v2_4 = {PC_Q35_2_4_MACHINE_OPTIONS ,@@ -433,7 +436,10 @@ static QEMUMachine pc_q35_machine_v2_4 = { .init = pc_q35_init,
hw/i386/pc_q35.c static QEMUMachine pc_q35_machine_v2_4 = { · line 445
Quoted 10 lines
hw/i386/pc_q35.c +4
-1}; -#define PC_Q35_2_3_MACHINE_OPTIONS PC_Q35_2_4_MACHINE_OPTIONS +#define PC_Q35_2_3_MACHINE_OPTIONS \ + PC_Q35_MACHINE_OPTIONS, \ + .default_machine_opts = "firmware=bios-256k.bin", \ + .default_display = "std"static QEMUMachine pc_q35_machine_v2_3 = {PC_Q35_2_3_MACHINE_OPTIONS ,
If you want to try ideas from my review, go ahead. Even if not:
Quoted 7 lines · Markus Armbruster
hw/i386/pc_q35.c static void pc_q35_init(MachineState *machine) · line 257
Quoted 5 lines
hw/i386/pc_q35.c +1
-1-pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, force_fdctrl, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0xff0104 );/* connect pm stuff to lpc */ If we can get from MachineState *machine to its MachineClass,
Sure you can, it's just MACHINE_GET_CLASS(machine).
Paolo
Quoted 3 lines
we could
use MachineClass memberno_floppy, and not needforce_fdctrl. Probably a wash.
Copying John Snow (FDC maintainer) and the qemu-block list.
Am 27.05.2015 um 23:06 hat Laszlo Ersek geschrieben:
Quoted 152 lines
It is Very annoying to carry forward an outdatEd coNtroller with a mOdern Machine type.
Hence, let us not instantiate the FDC when all of the following apply:
- the machine type is pc-q35-2.4 or later,
- "-device isa-fdc" is not passed on the command line (nor in the config file),
- no "-drive if=floppy,..." is requested.The first part of the code flow, updated by the patch, is as follows:
1. The "
no_floppy= 1" machine class setting causes "default_floppy" inmain()to become zero.2. Hence
default_drive()will not calldrive_add()anddrive_new()forIF_FLOPPY, index=0.This alone would not suffice, because the
pc_basic_device_init()function creates the FDC regardless of actual floppy drives. Therefore,3.
pc_basic_device_init()should only create the FDC if that's desirable for the platform (= all PIIX types, and Q35 types earlier than 2.4), *or* the user requested at least oneIF_FLOPPYdrive.4. If the FDC is not created, callers of
pc_basic_device_init()--pc_q35_init()andpc_init1()-- will pass floppy=NULL topc_cmos_init(). Luckily,pc_cmos_init()already handles that case.I verified the patch under the following scenarios, with "info qtree" and with the MAP command of the UEFI shell (in OVMF):
- "pc" machine type -- no changes, FDC present,
- "pc-q35-2.3" machine type -- no changes, FDC present,
- "pc-q35" machine type with "-device isa-fdc" -- no changes, FDC present,
- "pc-q35" machine type with "-drive if=floppy,..." -- no changes, FDC present,
- "pc-q35" -- no FDC.Suggested-by Markus Armbruster <[email protected]>Cc Markus Armbruster <[email protected]>Cc Paolo Bonzini <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>--- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 4 +++- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 12 +++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-)include/hw/i386/pc.h +1
-0@@ -199,6 +199,7 @@ qemu_irq *pc_allocate_cpu_irq(void);DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus);void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs);hw/i386/pc.c +3
-1@@ -1395,6 +1395,7 @@ static const MemoryRegionOps ioportF0_io_ops = {void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs)@@ -1489,8 +1490,9 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,for (i =0 ; i <MAX_FD ; i++) { fd[i] =drive_get (IF_FLOPPY ,0 , i); + force_fdctrl |= !!fd[i]; } - *floppy =fdctrl_init_isa (isa_bus, fd); + *floppy = force_fdctrl ?fdctrl_init_isa (isa_bus, fd) :NULL ; }void pc_nic_init (ISABus *isa_bus,PCIBus *pci_bus)hw/i386/pc_piix.c +1
-1@@ -242,7 +242,7 @@ static void pc_init1(MachineState *machine, }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, true, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0x4 );pc_nic_init (isa_bus, pci_bus);hw/i386/pc_q35.c +9
-3@@ -60,6 +60,7 @@ static bool smbios_uuid_encoded = true;*/ static bool gigabyte_align = true;static bool has_reserved_memory = true; +static bool force_fdctrl;/* PC hardware initialisation */ static void pc_q35_init (MachineState *machine)@@ -250,7 +251,7 @@ static void pc_q35_init(MachineState *machine) }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, force_fdctrl, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0xff0104 );/* connect pm stuff to lpc */ @@ -291,6 +292,7 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { + force_fdctrl = true; }static void pc_compat_2_2 (MachineState *machine)@@ -424,7 +426,8 @@ static void pc_q35_init_1_4(MachineState *machine)#define PC_Q35_2_4_MACHINE_OPTIONS \ PC_Q35_MACHINE_OPTIONS, \ .default_machine_opts = "firmware=bios-256k.bin", \ - .default_display = "std" + .default_display = "std", \ + .no_floppy = 1static QEMUMachine pc_q35_machine_v2_4 = {PC_Q35_2_4_MACHINE_OPTIONS ,@@ -433,7 +436,10 @@ static QEMUMachine pc_q35_machine_v2_4 = { .init = pc_q35_init, }; -#define PC_Q35_2_3_MACHINE_OPTIONS PC_Q35_2_4_MACHINE_OPTIONS +#define PC_Q35_2_3_MACHINE_OPTIONS \ + PC_Q35_MACHINE_OPTIONS, \ + .default_machine_opts = "firmware=bios-256k.bin", \ + .default_display = "std"static QEMUMachine pc_q35_machine_v2_3 = {PC_Q35_2_3_MACHINE_OPTIONS ,Signature · 1 line
1.8.3.1
Quoted 57 lines · Markus Armbruster
Quoted 2 lines · Laszlo Ersek
It is Very annoying to carry forward an outdatEd coNtroller with a mOdern Machine type.
Surely Unnecessary Crap can still Kill Security.
Quoted 10 lines
Hence, let us not instantiate the FDC when all of the following apply:
- the machine type is pc-q35-2.4 or later,
- "-device isa-fdc" is not passed on the command line (nor in the config file),
- no "-drive if=floppy,..." is requested.The first part of the code flow, updated by the patch, is as follows:
1. The "
no_floppy= 1" machine class setting causes "default_floppy" inmain()to become zero.Yup. It's copied around some, but that's its only real effect.
Quoted 2 lines
2. Hence
default_drive()will not calldrive_add()anddrive_new()forIF_FLOPPY, index=0.This is the backend created for the board to pick up. If the board doesn't pick it up, the backend remains unused, which is confusing. Boards that don't pick up
IF_FLOPPYbackends should setno_floppyto avoid the confusion. Aside: precious few do.In short: good.
Quoted 5 lines
This alone would not suffice, because the
pc_basic_device_init()function creates the FDC regardless of actual floppy drives. Therefore,3.
pc_basic_device_init()should only create the FDC if that's desirable for the platform (= all PIIX types, and Q35 types earlier than 2.4),This is the conservative choice.
Arguably, Q35 got versioned prematurely. Dropping the FDC from Q35 unconditionally has been proposed, on the basis that it wasn't fit for serious use in prior releases anyway. I think if we decide we're fine with changing the released Q35 machine types incompatibly, then we should consider going all the way and simply drop them.
But let's not get review of this patch bogged down in a Q35 versioning debate. Whatever we want done there, we can do on top of this patch.
Quoted 1 line
*or* the user requested at least one
IF_FLOPPYdrive.This is the magic to keep -drive if=floppy just work with Q35.
On the one hand, we've come to hate command line magic.
On the other hand, this is exactly the kind of magic -drive does. For instance, PC boards create lsi53c895a SCSI HBAs for -drive if=scsi. Your patch makes them create an isa-fdc for -drive if=floppy.
Quoted 6 lines
Magic or no magic, I don't care. Whatever it takes to get the FDC out of Q35.
If the magic should run into review trouble, putting it into its own patch may help keeping the non-magic (and hopefully uncontroversial) parts out of the debate.
I think it's a good idea to split, if you redo the patch anyway.
Quoted 48 lines
Quoted 9 lines
4. If the FDC is not created, callers of
pc_basic_device_init()--pc_q35_init()andpc_init1()-- will pass floppy=NULL topc_cmos_init(). Luckily,pc_cmos_init()already handles that case.I verified the patch under the following scenarios, with "info qtree" and with the MAP command of the UEFI shell (in OVMF):
- "pc" machine type -- no changes, FDC present,
- "pc-q35-2.3" machine type -- no changes, FDC present,
- "pc-q35" machine type with "-device isa-fdc" -- no changes, FDC present,Perhaps worth mentioning somewhere in the commit message: instead of the arcane -global isa-fdc.driveA=... (which breaks down when you have more than one isa-fdc), you simply do the regular -device isa-fdc,driveA=...
Discussed in a bit more details in
<http://lists.nongnu.org/archive/html/qemu-devel/2015-05/msg03121.html>.Quoted 21 lines
- "pc-q35" machine type with "-drive if=floppy,..." -- no changes, FDC present,
- "pc-q35" -- no FDC.Suggested-by Markus Armbruster <[email protected]>Cc Markus Armbruster <[email protected]>Cc Paolo Bonzini <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>--- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 4 +++- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 12 +++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-)include/hw/i386/pc.h +0
-0include/hw/i386/pc.h qemu_irq *pc_allocate_cpu_irq(void); · line 205
Quoted 7 lines
include/hw/i386/pc.h +1
-0@@ -199,6 +199,7 @@ qemu_irq *pc_allocate_cpu_irq(void);DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus);void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs);The name @force_fdctrl gave me pause: what are we forcing here?
Quoted 2 lines
I guess your rationale is something like "force creation of FDC even when there are no if=floppy drives." Hmm.
I kind of dislike this name too.
Quoted 96 lines
Quoted 49 lines
hw/i386/pc.c +3
-1@@ -1395,6 +1395,7 @@ static const MemoryRegionOps ioportF0_io_ops = {void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi,ISADevice **rtc_state, +bool force_fdctrl,ISADevice **floppy,bool no_vmport,uint32 hpet_irqs)@@ -1489,8 +1490,9 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,for (i =0 ; i <MAX_FD ; i++) { fd[i] =drive_get (IF_FLOPPY ,0 , i); + force_fdctrl |= !!fd[i]; } - *floppy =fdctrl_init_isa (isa_bus, fd); + *floppy = force_fdctrl ?fdctrl_init_isa (isa_bus, fd) :NULL ; }void pc_nic_init (ISABus *isa_bus,PCIBus *pci_bus)hw/i386/pc_piix.c +1
-1@@ -242,7 +242,7 @@ static void pc_init1(MachineState *machine, }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, true, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0x4 );pc_nic_init (isa_bus, pci_bus);hw/i386/pc_q35.c +1
-0@@ -60,6 +60,7 @@ static bool smbios_uuid_encoded = true;*/ static bool gigabyte_align = true;static bool has_reserved_memory = true; +static bool force_fdctrl;/* PC hardware initialisation */ static void pc_q35_init (MachineState *machine)hw/i386/pc_q35.c static void pc_q35_init(MachineState *machine) · line 257
Quoted 8 lines
hw/i386/pc_q35.c +1
-1@@ -250,7 +251,7 @@ static void pc_q35_init(MachineState *machine) }/* init basic PC hardware */ -pc_basic_device_init (isa_bus, gsi, &rtc_state, &floppy, +pc_basic_device_init (isa_bus, gsi, &rtc_state, force_fdctrl, &floppy, (pc_machine->vmport !=ON_OFF_AUTO_ON ),0xff0104 );/* connect pm stuff to lpc */ If we can get from MachineState *machine to its MachineClass, we could use MachineClass member
no_floppy, and not needforce_fdctrl. Probably a wash.Quoted 20 lines
hw/i386/pc_q35.c +3
-1@@ -291,6 +292,7 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { + force_fdctrl = true; }static void pc_compat_2_2 (MachineState *machine)@@ -424,7 +426,8 @@ static void pc_q35_init_1_4(MachineState *machine)#define PC_Q35_2_4_MACHINE_OPTIONS \ PC_Q35_MACHINE_OPTIONS, \ .default_machine_opts = "firmware=bios-256k.bin", \ - .default_display = "std" + .default_display = "std", \ + .no_floppy = 1static QEMUMachine pc_q35_machine_v2_4 = {PC_Q35_2_4_MACHINE_OPTIONS ,@@ -433,7 +436,10 @@ static QEMUMachine pc_q35_machine_v2_4 = { .init = pc_q35_init,hw/i386/pc_q35.c static QEMUMachine pc_q35_machine_v2_4 = { · line 445
Quoted 10 lines
hw/i386/pc_q35.c +4
-1}; -#define PC_Q35_2_3_MACHINE_OPTIONS PC_Q35_2_4_MACHINE_OPTIONS +#define PC_Q35_2_3_MACHINE_OPTIONS \ + PC_Q35_MACHINE_OPTIONS, \ + .default_machine_opts = "firmware=bios-256k.bin", \ + .default_display = "std"static QEMUMachine pc_q35_machine_v2_3 = {PC_Q35_2_3_MACHINE_OPTIONS ,If you want to try ideas from my review, go ahead. Even if not:
Reviewed-by Markus Armbruster <[email protected]>
Re: [Qemu-devel] [PATCH] i386: drop FDC in pc-q35-2.4+ if neither
In reply to Laszlo ErsekQuoted 8 lines
It is Very annoying to carry forward an outdatEd coNtroller with a mOdern Machine type.
Hence, let us not instantiate the FDC when all of the following apply:
- the machine type is pc-q35-2.4 or later,
- "-device isa-fdc" is not passed on the command line (nor in the config file),
- no "-drive if=floppy,..." is requested.
Don't forget the FDC0 entry in the ACPI DSDT !
Right now, FDC0's _STA method returns 0x0F or 0x00, depending on the value of \_SB_.PCI0.ISA_.FDEN, which is hard-coded to 1 (so 0x0F always, basically :) )
I remember tinkering with that a while ago (allowing for FDEN or the actual value of FDC0._STA to be patched in at startup, depending on no_floppy or force_Fdctrl. I also did that for the AppleSMC entry, but I notice that now the entire SMC is patched in conditionally, from hw/i386/acpi-build.c. Maybe patching in the whole FDC0 node in a similar fashion would be appropriate here as well ?
Thanks,
--Gabriel
Re: [Qemu-devel] [PATCH] i386: drop FDC in pc-q35-2.4+ if neither
Quoted 10 lines · Gabriel L. Somlo
Quoted 8 lines
It is Very annoying to carry forward an outdatEd coNtroller with a mOdern Machine type.
Hence, let us not instantiate the FDC when all of the following apply:
- the machine type is pc-q35-2.4 or later,
- "-device isa-fdc" is not passed on the command line (nor in the config file),
- no "-drive if=floppy,..." is requested.Don't forget the FDC0 entry in the ACPI DSDT !
No worries, everything is fine here.
Quoted 2 lines
Right now, FDC0's
_STAmethod returns0x0For0x00, depending on the value of \_SB_.PCI0.ISA_.FDEN,
Yes.
Quoted 2 lines
which is hard-coded to 1 (so
0x0F
always, basically :) )
Yes on piix4.
On q35 FDEN maps to the floppy drive enable bit of the ich9 lpc. And ich9_lpc_machine_ready() sets this (and other) enable bits.
/me double checks things.
Ok, in theory. In practice there seems to be something wrong. linux kernel log on q35 (with floppy) yields this:
[root@fedora ~]# dmesg | grep pnp
pnp: PnP ACPI init
pnp 00:00: Plug and Play ACPI device, IDs PNP0b00 (active) pnp 00:01: Plug and Play ACPI device, IDs PNP0303 (active) pnp 00:02: Plug and Play ACPI device, IDs PNP0f13 (active) pnp 00:03: Plug and Play ACPI device, IDs PNP0501 (active)
pnp: PnP ACPI: found 4 devices
Floppy (PNP0700) is not present. Hmm ...
Seems be be this:
hw/isa/lpc_ich9.c +1 -1
@@ -494,7 +494,7 @@ static void ich9_lpc_machine_ready(Notifier *n, void *opaque)/* lpt */ pci_conf[0x82 ] |=0x04 ; } -if (memory_region_present (io_as,0x3f0 )) { +if (memory_region_present (io_as,0x3f2 )) {/* floppy */ pci_conf[0x82 ] |=0x08 ; }
Oh, and this ...
$ virsh qemu-monitor-command fedora-org-q35.base --hmp "info mtree" | grep fdc
00000000000003f1-00000000000003f5 (prio 0, RW): fdc
00000000000003f7-00000000000003f7 (prio 0, RW): fdc... looks fishy too. Shouldn't that be 0x3f2-0x3f6 for the first range?
cheers,
Gerd
Re: [Qemu-devel] [PATCH] i386: drop FDC in pc-q35-2.4+ if neither
Quoted 10 lines · Gerd Hoffmann
(quoted diff) +1
-1@@ -494,7 +494,7 @@ static void ich9_lpc_machine_ready(Notifier *n, void *opaque) /* lpt */ pci_conf[0x82] |= 0x04; } - if (memory_region_present(io_as, 0x3f0)) { + if (memory_region_present(io_as, 0x3f2)) { /* floppy */ pci_conf[0x82] |= 0x08; }
Quoted 7 lines
Oh, and this ...
$ virsh qemu-monitor-command fedora-org-q35.base --hmp "info mtree" | grep fdc 00000000000003f1-00000000000003f5 (prio 0, RW): fdc 00000000000003f7-00000000000003f7 (prio 0, RW): fdc... looks fishy too. Shouldn't that be 0x3f2-0x3f6 for the first range?
I think 0x3f0-0x3f5 based on this:
hw/block/fdc.c: FD_REG_SRA = 0x00, hw/block/fdc.c: FD_REG_SRB = 0x01, hw/block/fdc.c: FD_REG_DOR = 0x02, hw/block/fdc.c: FD_REG_TDR = 0x03, hw/block/fdc.c: FD_REG_MSR = 0x04, hw/block/fdc.c: FD_REG_DSR = 0x04, hw/block/fdc.c: FD_REG_FIFO = 0x05, hw/block/fdc.c: FD_REG_DIR = 0x07, hw/block/fdc.c: FD_REG_CCR = 0x07,
So:
hw/block/fdc.c +1 -1
@@ -2186,7 +2186,7 @@ static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp) }static const MemoryRegionPortio fdc_portio_list[] = { - {1 ,5 ,1 , .read = fdctrl_read, .write = fdctrl_write }, + {0 ,6 ,1 , .read = fdctrl_read, .write = fdctrl_write }, {7 ,1 ,1 , .read = fdctrl_read, .write = fdctrl_write },PORTIO_END_OF_LIST (), };
Paolo
Re: [Qemu-devel] [PATCH] i386: drop FDC in pc-q35-2.4+ if neither
Hi,
Quoted 25 lines
Quoted 5 lines
$ virsh qemu-monitor-command fedora-org-q35.base --hmp "info mtree" | grep fdc 00000000000003f1-00000000000003f5 (prio 0, RW): fdc 00000000000003f7-00000000000003f7 (prio 0, RW): fdc... looks fishy too. Shouldn't that be 0x3f2-0x3f6 for the first range?
I think 0x3f0-0x3f5 based on this:
hw/block/fdc.c: FD_REG_SRA = 0x00, hw/block/fdc.c: FD_REG_SRB = 0x01, hw/block/fdc.c: FD_REG_DOR = 0x02, hw/block/fdc.c: FD_REG_TDR = 0x03, hw/block/fdc.c: FD_REG_MSR = 0x04, hw/block/fdc.c: FD_REG_DSR = 0x04, hw/block/fdc.c: FD_REG_FIFO = 0x05, hw/block/fdc.c: FD_REG_DIR = 0x07, hw/block/fdc.c: FD_REG_CCR = 0x07,So:
hw/block/fdc.c +0
-0
hw/block/fdc.c static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp) · line 2192
Quoted 8 lines
hw/block/fdc.c +1
-1@@ -2186,7 +2186,7 @@ static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp) }static const MemoryRegionPortio fdc_portio_list[] = { - {1 ,5 ,1 , .read = fdctrl_read, .write = fdctrl_write }, + {0 ,6 ,1 , .read = fdctrl_read, .write = fdctrl_write }, {7 ,1 ,1 , .read = fdctrl_read, .write = fdctrl_write },PORTIO_END_OF_LIST (), };
The io ranges for FDC0 in hw/i386/acpi-dsdt-isa.dsl are not consistent with that though. If 0x3f0 is correct (which seems to be the case from a brief look) this needs to be fixed up.
cheers,
Gerd
Re: [Qemu-devel] [PATCH] i386: drop FDC in pc-q35-2.4+ if neither
Quoted 7 lines · Gerd Hoffmann
Quoted 7 lines
hw/block/fdc.c +0
-0@@ -2186,7 +2186,7 @@ static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp) }
Quoted 10 lines
hw/block/fdc.c static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp) · line 2192
Quoted 6 lines
hw/block/fdc.c +1
-1static const MemoryRegionPortio fdc_portio_list[] = { - {1 ,5 ,1 , .read = fdctrl_read, .write = fdctrl_write }, + {0 ,6 ,1 , .read = fdctrl_read, .write = fdctrl_write }, {7 ,1 ,1 , .read = fdctrl_read, .write = fdctrl_write },PORTIO_END_OF_LIST (), };The io ranges for FDC0 in hw/i386/acpi-dsdt-isa.dsl are not consistent with that though. If
0x3f0is correct (which seems to be the case from a brief look) this needs to be fixed up.
Agreed. Who draws the short straw? :)
Paolo
Re: [Qemu-devel] [PATCH] i386: drop FDC in pc-q35-2.4+ if neither
Quoted 20 lines · Paolo Bonzini
Quoted 7 lines · Gerd Hoffmann
Quoted 7 lines
hw/block/fdc.c +0
-0@@ -2186,7 +2186,7 @@ static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp) }Quoted 10 lines
hw/block/fdc.c static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp) · line 2192
Quoted 6 lines
hw/block/fdc.c +1
-1static const MemoryRegionPortio fdc_portio_list[] = { - {1 ,5 ,1 , .read = fdctrl_read, .write = fdctrl_write }, + {0 ,6 ,1 , .read = fdctrl_read, .write = fdctrl_write }, {7 ,1 ,1 , .read = fdctrl_read, .write = fdctrl_write },PORTIO_END_OF_LIST (), };The io ranges for FDC0 in hw/i386/acpi-dsdt-isa.dsl are not consistent with that though. If
0x3f0is correct (which seems to be the case from a brief look) this needs to be fixed up.
Quoted 1 line
Agreed. Who draws the short straw? :)
==== <- mine is 4 ch^Winches ;)
cheers,
Gerd
PS: patch sent.