OSDN Git Service

qmiga/qemu.git
2 years agopckbd: add QEMU interface comment for I8042_MMIO device
Mark Cave-Ayland [Fri, 24 Jun 2022 13:41:05 +0000 (14:41 +0100)]
pckbd: add QEMU interface comment for I8042_MMIO device

This describes the I8042_MMIO device interface implemented within QEMU.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20220624134109.881989-51-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agopckbd: switch I8042_MMIO device from update_irq() function to PS2 device gpio
Mark Cave-Ayland [Fri, 24 Jun 2022 13:41:04 +0000 (14:41 +0100)]
pckbd: switch I8042_MMIO device from update_irq() function to PS2 device gpio

Define a new qdev input gpio for handling incoming PS2 IRQs, and then wire up the
PS2 keyboard and mouse devices to use it. At the same time set update_irq() and
update_arg to NULL in ps2_kbd_init() and ps2_mouse_init() to ensure that any
accidental attempt to use the legacy update_irq() function will cause a NULL
pointer dereference.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-50-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: add QEMU interface comment
Mark Cave-Ayland [Fri, 24 Jun 2022 13:41:03 +0000 (14:41 +0100)]
lasips2: add QEMU interface comment

This describes the LASI PS2 device interface implemented within QEMU.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20220624134109.881989-49-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agolasips2: switch over from update_irq() function to PS2 device gpio
Mark Cave-Ayland [Fri, 24 Jun 2022 13:41:02 +0000 (14:41 +0100)]
lasips2: switch over from update_irq() function to PS2 device gpio

Add a qdev gpio input in lasips2_init() by taking the existing lasips2_port_set_irq()
function, updating it accordingly and then renaming to lasips2_set_irq(). Use these
new qdev gpio inputs to wire up the PS2 keyboard and mouse devices.

At the same time set update_irq() and update_arg to NULL in ps2_kbd_init() and
ps2_mouse_init() to ensure that any accidental attempt to use the legacy update_irq()
function will cause a NULL pointer dereference.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-48-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agolasips2: use sysbus IRQ for output IRQ
Mark Cave-Ayland [Fri, 24 Jun 2022 13:41:01 +0000 (14:41 +0100)]
lasips2: use sysbus IRQ for output IRQ

This enables the IRQ to be wired up using sysbus_connect_irq() in
lasips2_initfn().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-47-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agolasips2: implement lasips2_realize()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:41:00 +0000 (14:41 +0100)]
lasips2: implement lasips2_realize()

Move ps2_kbd_init() and ps2_mouse_init() from lasips2_initfn() to lasips2_realize.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-46-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: add base property
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:59 +0000 (14:40 +0100)]
lasips2: add base property

This is in preparation for handling vmstate_register() within the device.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-45-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agolasips2: move initialisation of PS2 ports from lasi_initfn() to lasi_init()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:58 +0000 (14:40 +0100)]
lasips2: move initialisation of PS2 ports from lasi_initfn() to lasi_init()

This can be improved once the ps2_kbd_init() and ps2_mouse_init() functions have
been removed, but for now move the existing logic from lasi_initfn() to
lasi_init(). At the same time explicitly set keyboard port id to 0, even if it
isn't technically required.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-44-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: move mapping of LASIPS2 registers to HPPA machine
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:57 +0000 (14:40 +0100)]
lasips2: move mapping of LASIPS2 registers to HPPA machine

Now that the register memory regions are exposed as SysBus memory regions, move
the mapping of the LASIPS2 registers from lasips2_initfn() to the HPPA machine
(which is its only user).

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-43-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: implement lasips2_init() function
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:56 +0000 (14:40 +0100)]
lasips2: implement lasips2_init() function

Move the initialisation of the keyboard and mouse memory regions to lasips2_init()
and expose them as SysBus memory regions.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-42-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: rename lasips2_init() to lasips2_initfn() and update it to return the LASIPS...
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:55 +0000 (14:40 +0100)]
lasips2: rename lasips2_init() to lasips2_initfn() and update it to return the LASIPS2 device

When QOMifying a device it is typical to use _init() as the suffix for an
instance_init function, however this name is already in use by the legacy LASIPS2
wrapper function. Eventually the wrapper function will be removed, but for now
rename it to lasips2_initfn() to avoid a naming collision.

At the same time update lasips2_initfn() return the LASIPS2 device so that it
can later be accessed using qdev APIs by the HPPA machine.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-41-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: move lasips2 QOM types from lasips2.c to lasips2.h
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:54 +0000 (14:40 +0100)]
lasips2: move lasips2 QOM types from lasips2.c to lasips2.h

This allows the QOM types in lasips2.c to be used elsewhere by simply including
lasips2.h.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-40-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: QOMify LASIPS2State
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:53 +0000 (14:40 +0100)]
lasips2: QOMify LASIPS2State

Currently lasip2_init() creates a new LASIPS2State directly which is used by the HPPA
machine. Introduce a new LASIPS2 QOM type that will soon be used to allow the HPPA
machine to be wired up using standard qdev GPIOs.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-39-mark.cave-ayland@ilande.co.uk>

2 years agopl050: add QEMU interface comment
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:52 +0000 (14:40 +0100)]
pl050: add QEMU interface comment

This describes the PL050 device interface implemented within QEMU.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20220624134109.881989-38-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agopl050: switch over from update_irq() function to PS2 device gpio
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:51 +0000 (14:40 +0100)]
pl050: switch over from update_irq() function to PS2 device gpio

Add a new pl050_init() function which initialises a qdev input gpio for handling
incoming PS2 IRQs, and then wire up the PS2 device to use it. At the same time
set update_irq() and update_arg to NULL in ps2_kbd_init() and ps2_mouse_init()
to ensure that any accidental attempt to use the legacy update_irq() function will
cause a NULL pointer dereference.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-37-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agopckbd: replace irq_kbd and irq_mouse with qemu_irq array in KBDState
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:50 +0000 (14:40 +0100)]
pckbd: replace irq_kbd and irq_mouse with qemu_irq array in KBDState

This allows both IRQs to be declared as a single qdev gpio array.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-36-mark.cave-ayland@ilande.co.uk>

2 years agops2: add gpio for output IRQ and optionally use it in ps2_raise_irq() and ps2_lower_irq()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:49 +0000 (14:40 +0100)]
ps2: add gpio for output IRQ and optionally use it in ps2_raise_irq() and ps2_lower_irq()

Define the gpio for the PS2 output IRQ in ps2_init() and add logic to optionally
use it in ps2_raise_irq() and ps2_lower_irq() if the gpio is connected. If the
gpio is not connected then call the legacy update_irq() function as before.

This allows the incremental conversion of devices from the legacy update_irq()
function to use gpios instead.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-35-mark.cave-ayland@ilande.co.uk>

2 years agops2: introduce ps2_lower_irq() instead of calling update_irq() directly
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:48 +0000 (14:40 +0100)]
ps2: introduce ps2_lower_irq() instead of calling update_irq() directly

This consolidates the logic of lowering the PS2 IRQ into one single function.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-34-mark.cave-ayland@ilande.co.uk>

2 years agops2: use ps2_raise_irq() instead of calling update_irq() directly
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:47 +0000 (14:40 +0100)]
ps2: use ps2_raise_irq() instead of calling update_irq() directly

This consolidates the logic of raising the PS2 IRQ into one single function.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-33-mark.cave-ayland@ilande.co.uk>

2 years agops2: make ps2_raise_irq() function static
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:46 +0000 (14:40 +0100)]
ps2: make ps2_raise_irq() function static

This function is no longer used outside of ps2.c and so can be declared static.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-32-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: move ps2_kbd_init() and ps2_mouse_init() to i8042_mmio_realize()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:45 +0000 (14:40 +0100)]
pckbd: move ps2_kbd_init() and ps2_mouse_init() to i8042_mmio_realize()

Move ps2_kbd_init() and ps2_mouse_init() from i8042_mm_init() to
i8042_mmio_realize() to further reduce the initialisation logic done in
i8042_mm_init().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-31-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: more vmstate_register() from i8042_mm_init() to i8042_mmio_realize()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:44 +0000 (14:40 +0100)]
pckbd: more vmstate_register() from i8042_mm_init() to i8042_mmio_realize()

Note in this case it is not possible to register a (new) VMStateDescription in
the DeviceClass without breaking migration compatibility for the MIPS magnum
machine.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-30-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agopckbd: move mapping of I8042_MMIO registers to MIPS magnum machine
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:43 +0000 (14:40 +0100)]
pckbd: move mapping of I8042_MMIO registers to MIPS magnum machine

Now that the register memory region is exposed as a SysBus memory region, move
the mapping of the I8042_MMIO registers from i8042_mm_init() to the MIPS magnum
machine (which is its only user).

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-29-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: alter i8042_mm_init() to return a I8042_MMIO device
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:42 +0000 (14:40 +0100)]
pckbd: alter i8042_mm_init() to return a I8042_MMIO device

This exposes the I8042_MMIO device to the caller to allow the register memory
region to be mapped outside of i8042_mm_init().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-28-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: implement i8042_mmio_init() function
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:41 +0000 (14:40 +0100)]
pckbd: implement i8042_mmio_init() function

This enables use to set the required value of extended_state directly during
device init rather than in i8042_mm_init().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-27-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agopckbd: implement i8042_mmio_realize() function
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:40 +0000 (14:40 +0100)]
pckbd: implement i8042_mmio_realize() function

Move the initialisation of the register memory region to the I8042_MMIO device
realize function and expose it using sysbus_init_mmio().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-26-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: add size qdev property to I8042_MMIO device
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:39 +0000 (14:40 +0100)]
pckbd: add size qdev property to I8042_MMIO device

This will soon be used to set the size of the register memory region using a
qdev property.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-25-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: add mask qdev property to I8042_MMIO device
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:38 +0000 (14:40 +0100)]
pckbd: add mask qdev property to I8042_MMIO device

This allows the KBDState mask value to be set using a qdev property rather
than directly in i8042_mm_init().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-24-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: implement i8042_mmio_reset() for I8042_MMIO device
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:37 +0000 (14:40 +0100)]
pckbd: implement i8042_mmio_reset() for I8042_MMIO device

This allows the I8042_MMIO reset function to be registered directly within the
DeviceClass rather than using qemu_register_reset() directly.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-23-mark.cave-ayland@ilande.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2 years agopckbd: introduce new I8042_MMIO QOM type
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:36 +0000 (14:40 +0100)]
pckbd: introduce new I8042_MMIO QOM type

Currently i8042_mm_init() creates a new KBDState directly which is used by the MIPS
magnum machine. Introduce a new I8042_MMIO QOM type that will soon be used to
allow the MIPS magnum machine to be wired up using standard qdev GPIOs.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Helge Deller <deller@gmx.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220624134109.881989-22-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: move ISAKBDState from pckbd.c to i8042.h
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:35 +0000 (14:40 +0100)]
pckbd: move ISAKBDState from pckbd.c to i8042.h

This allows the QOM types in pckbd.c to be used elsewhere by simply including
i8042.h.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-21-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: move KBDState from pckbd.c to i8042.h
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:34 +0000 (14:40 +0100)]
pckbd: move KBDState from pckbd.c to i8042.h

This allows the QOM types in pckbd.c to be used elsewhere by simply including
i8042.h.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-20-mark.cave-ayland@ilande.co.uk>

2 years agopckbd: checkpatch fixes
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:33 +0000 (14:40 +0100)]
pckbd: checkpatch fixes

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-19-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: rename ps2dev_update_irq() to lasips2_port_set_irq()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:32 +0000 (14:40 +0100)]
lasips2: rename ps2dev_update_irq() to lasips2_port_set_irq()

This better reflects that the IRQ input opaque is a LASIPS2Port structure
and not a PS2_DEVICE.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-18-mark.cave-ayland@ilande.co.uk>

2 years agolasips2: spacing fixes
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:31 +0000 (14:40 +0100)]
lasips2: spacing fixes

This helps improve the readability of lasips2.c.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-17-mark.cave-ayland@ilande.co.uk>

2 years agopl050: split pl050_update_irq() into separate pl050_set_irq() and pl050_update_irq...
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:30 +0000 (14:40 +0100)]
pl050: split pl050_update_irq() into separate pl050_set_irq() and pl050_update_irq() functions

This will soon allow pl050_set_irq() to be used as a GPIO input function.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-16-mark.cave-ayland@ilande.co.uk>

2 years agopl050: checkpatch fixes
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:29 +0000 (14:40 +0100)]
pl050: checkpatch fixes

This patch also includes a couple of minor spacing updates.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-15-mark.cave-ayland@ilande.co.uk>

2 years agops2: don't use vmstate_register() in ps2_mouse_init()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:28 +0000 (14:40 +0100)]
ps2: don't use vmstate_register() in ps2_mouse_init()

Since PS2_MOUSE_DEVICE is a qdev device then vmstate_ps2_mouse can be registered
using the DeviceClass vmsd field instead. There is no need to use
qdev_set_legacy_instance_id() to ensure migration compatibility since the first 2
parameters to vmstate_register() are NULL and 0 respectively.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-14-mark.cave-ayland@ilande.co.uk>

2 years agops2: don't use vmstate_register() in ps2_kbd_init()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:27 +0000 (14:40 +0100)]
ps2: don't use vmstate_register() in ps2_kbd_init()

Since PS2_KBD_DEVICE is a qdev device then vmstate_ps2_keyboard can be registered
using the DeviceClass vmsd field instead. There is no need to use
qdev_set_legacy_instance_id() to ensure migration compatibility since the first 2
parameters to vmstate_register() are NULL and 0 respectively.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-13-mark.cave-ayland@ilande.co.uk>

2 years agops2: implement ps2_mouse_realize() and use it to register ps2_mouse_handler
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:26 +0000 (14:40 +0100)]
ps2: implement ps2_mouse_realize() and use it to register ps2_mouse_handler

Move the registration of ps2_mouse_handler from ps2_mouse_init() to a new
ps2_mouse_realize() function. Since the abstract PS2_DEVICE parent class doesn't
have a realize() function then it is not necessary to store the reference to
it in PS2DeviceClass and use device_class_set_parent_realize().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-12-mark.cave-ayland@ilande.co.uk>

2 years agops2: implement ps2_kbd_realize() and use it to register ps2_keyboard_handler
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:25 +0000 (14:40 +0100)]
ps2: implement ps2_kbd_realize() and use it to register ps2_keyboard_handler

Move the registration of ps2_keyboard_handler from ps2_kbd_init() to a new
ps2_kbd_realize() function. Since the abstract PS2_DEVICE parent class doesn't
have a realize() function then it is not necessary to store the reference to
it in PS2DeviceClass and use device_class_set_parent_realize().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-11-mark.cave-ayland@ilande.co.uk>

2 years agops2: remove duplicate setting of scancode_set in ps2_kbd_init()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:24 +0000 (14:40 +0100)]
ps2: remove duplicate setting of scancode_set in ps2_kbd_init()

The default value for scancode_set is already set in ps2_kbd_reset() so there is no
need to duplicate this in ps2_kbd_init().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-10-mark.cave-ayland@ilande.co.uk>

2 years agops2: implement ps2_reset() for the PS2_DEVICE QOM type based upon ps2_common_reset()
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:23 +0000 (14:40 +0100)]
ps2: implement ps2_reset() for the PS2_DEVICE QOM type based upon ps2_common_reset()

The functionality of ps2_common_reset() can be moved into a new ps2_reset() function
for the PS2_DEVICE QOM type. Update PS2DeviceClass to hold a reference to the parent
reset function and update the PS2_KBD_DEVICE and PS2_MOUSE_DEVICE types to use
device_class_set_parent_reset() accordingly.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-9-mark.cave-ayland@ilande.co.uk>

2 years agops2: introduce PS2DeviceClass
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:22 +0000 (14:40 +0100)]
ps2: introduce PS2DeviceClass

This is in preparation for allowing the new PS2_KBD_DEVICE and PS2_MOUSE_DEVICE
QOM types to reference the parent PS2_DEVICE device reset() function.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-8-mark.cave-ayland@ilande.co.uk>

2 years agops2: improve function prototypes in ps2.c and ps2.h
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:21 +0000 (14:40 +0100)]
ps2: improve function prototypes in ps2.c and ps2.h

With the latest changes it is now possible to improve some of the function
prototypes in ps2.c and ps.h to use the appropriate PS2KbdState or
PS2MouseState type instead of being a void opaque.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-7-mark.cave-ayland@ilande.co.uk>

2 years agops2: move QOM type definitions from ps2.c to ps2.h
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:20 +0000 (14:40 +0100)]
ps2: move QOM type definitions from ps2.c to ps2.h

Move the QOM type definitions into the ps2.h header file to allow the new QOM
types to be used by other devices.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-6-mark.cave-ayland@ilande.co.uk>

2 years agops2: QOMify PS2MouseState
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:19 +0000 (14:40 +0100)]
ps2: QOMify PS2MouseState

Make PS2MouseState into a new PS2_MOUSE_DEVICE QOM type which inherits from the
abstract PS2_DEVICE type.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-5-mark.cave-ayland@ilande.co.uk>

2 years agops2: QOMify PS2KbdState
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:18 +0000 (14:40 +0100)]
ps2: QOMify PS2KbdState

Make PS2KbdState into a new PS2_KBD_DEVICE QOM type which inherits from the
abstract PS2_DEVICE type.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-4-mark.cave-ayland@ilande.co.uk>

2 years agops2: QOMify PS2State
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:17 +0000 (14:40 +0100)]
ps2: QOMify PS2State

Make PS2State a new abstract PS2_DEVICE QOM type to represent the common
functionality shared between PS2 keyboard and mouse devices.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-3-mark.cave-ayland@ilande.co.uk>

2 years agops2: checkpatch fixes
Mark Cave-Ayland [Fri, 24 Jun 2022 13:40:16 +0000 (14:40 +0100)]
ps2: checkpatch fixes

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
Message-Id: <20220624134109.881989-2-mark.cave-ayland@ilande.co.uk>

2 years agoMerge tag 'for-upstream' of git://repo.or.cz/qemu/kevin into staging
Richard Henderson [Fri, 24 Jun 2022 17:52:46 +0000 (10:52 -0700)]
Merge tag 'for-upstream' of git://repo.or.cz/qemu/kevin into staging

Block layer patches

- Add vduse-blk export
- Dirty bitmaps: Fix and improve bitmap merge
- gluster: correctly set max_pdiscard
- rbd: report a better error when namespace does not exist
- aio_wait_kick: add missing memory barrier
- Code cleanups

# -----BEGIN PGP SIGNATURE-----
#
# iQJFBAABCAAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmK10yURHGt3b2xmQHJl
# ZGhhdC5jb20ACgkQfwmycsiPL9YnXg/+J9PKsGl7hbJUFVIb4RZ3pMQ0o4xC1TbS
# OjA63RRwdJWt1gGsgLNH6kdsgz04FXiXk7XNDTe8MYn21bvznCYGFsI2EFJiit+x
# HkOYXJwAGsrfKBViq8QznosBQbwf9fOrDUlOdbnixFH/dx6DXUZM2F9ud5shiuiC
# vrP76zjUgSlHhPwL+0xsJSNxxNISv845uN9SYNpiGbZDaYLBtNbEc8NA2GMOYW45
# sCbxJDxNSFNrTT5gaZyo4KGFH9393qJSmYHJ+q53elbhje5dpmcn2c/AkIG7/UM4
# HsEWd7Gj1YbLQV6kvkefJzF4BOuZmN/b8sG+LRDjrEMHLeOw5rh2ETmkQfIdy2H3
# 2U52mHqw9bMGWtds0ocOJFKw3vPZuOCJaA+ql/A0aWGO9Fjivx1cQcOVXn3jKgj5
# 7riSxigK9TCTd92Qhi3j4do86mJi9NpjgawbQ5oOvKqUiq29moOwcv1hit0WVzwB
# hJp2qsrM6w00wFseyp+10vHigW7ZMNEIh4TKYLfZ15Gvy6YIG/m/oyCYF4oVM5y5
# knbsnJBRpTjLnggag86Pk8Ji+Lxi0cbv7zrbn++/S9OLQ5VMV5OpxKXHmyX2HyXa
# RCV0rMaTC3s4hy8gElDSwSeor6NBaJ9TECcit67uJ/kw1eK+omoa4hKMCgKf6qYC
# GY+NRPELJGA=
# =OuiN
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 24 Jun 2022 08:07:17 AM PDT
# gpg:                using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6
# gpg:                issuer "kwolf@redhat.com"
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full]

* tag 'for-upstream' of git://repo.or.cz/qemu/kevin:
  vduse-blk: Add name option
  vduse-blk: Add serial option
  nbd: Drop dead code spotted by Coverity
  aio_wait_kick: add missing memory barrier
  block/gluster: correctly set max_pdiscard
  block/rbd: report a better error when namespace does not exist
  qsd: document vduse-blk exports
  libvduse: Add support for reconnecting
  vduse-blk: Add vduse-blk resize support
  vduse-blk: Implement vduse-blk export
  libvduse: Add VDUSE (vDPA Device in Userspace) library
  linux-headers: Add vduse.h
  block/export: Abstract out the logic of virtio-blk I/O process
  block/export: Fix incorrect length passed to vu_queue_push()
  block: Support passing NULL ops to blk_set_dev_ops()
  block: simplify handling of try to merge different sized bitmaps
  block: improve block_dirty_bitmap_merge(): don't allocate extra bitmap
  block: block_dirty_bitmap_merge(): fix error path
  block: get rid of blk->guest_block_size
  block: drop unused bdrv_co_drain() API

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2 years agoMerge tag 'linux-user-for-7.1-pull-request' of https://gitlab.com/laurent_vivier...
Richard Henderson [Fri, 24 Jun 2022 15:58:33 +0000 (08:58 -0700)]
Merge tag 'linux-user-for-7.1-pull-request' of https://gitlab.com/laurent_vivier/qemu into staging

linux-user pull request 20220624

# -----BEGIN PGP SIGNATURE-----
#
# iQJGBAABCAAwFiEEzS913cjjpNwuT1Fz8ww4vT8vvjwFAmK1iJISHGxhdXJlbnRA
# dml2aWVyLmV1AAoJEPMMOL0/L748NYIP/R11Ztk4XH8LNDszg/s0y+D3FJm3XAkj
# 5LHaJdRGu9KsCO1zVkZDbhm81LIzY8yEzoQKZhV0vy6A071A2QNp8Pu6JZ4fMt6H
# kIwKclwW7WOiI8Ox+cLW4YYPJvY0tbe9yGoHJnLQjjYOOPeoUQKJ/0wK6sBgnK4y
# R8u2x4AvE5hgFfQvI0HRF1Q1e4y5MQt1WmLIxsGl2yCKzKWA0LrPuLgLROLQPbFj
# R/7fNwQkFW0PGnyyd8MMzRTEV6mdNZ9rQDA8/n2Nqgf7uQQFsOpHfXnhoJPz/CGi
# njhixJXingozKb/mX8OA5/NO0Ps7n7/WgugB36QvaoG9M4+E+9vjOkKTFo0LtfeA
# r75++/gNcJhQrMRU6/jSRx25dlWjfuLmEbUVvvGYtgQJ1hsAs6UwXO9EF5n4ZOr8
# qzgbW0GssvFO8+Ow5HQvWOHENR6ylJSSGc0bvX61ZH+h7cJRbELCiO3wkpyGe8zN
# OjG4tHbAnqKhN52k2uannNnPPqXI4f7GMV91pPXqM5oppY0BNMKRC6+nIS6Ew1D3
# FnNDwYJcDBXRY+Abqdrxfx2BSC35cl7Bfl+OVkXal9tGZTmFB+NOaeFWs9fdHXFA
# QE0Ct3xMut6SfJCNLvHwvBHwYq5yDCV/dngGonqgacn+F/epkbdY9sdlsYeRbud2
# h1tremHRgq9e
# =6mTR
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 24 Jun 2022 02:49:06 AM PDT
# gpg:                using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C
# gpg:                issuer "laurent@vivier.eu"
# gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [undefined]
# gpg:                 aka "Laurent Vivier <laurent@vivier.eu>" [undefined]
# gpg:                 aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" [undefined]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F  5173 F30C 38BD 3F2F BE3C

* tag 'linux-user-for-7.1-pull-request' of https://gitlab.com/laurent_vivier/qemu:
  linux-user: Adjust child_tidptr on set_tid_address() syscall
  linux-user: Add partial support for MADV_DONTNEED
  linux-user/x86_64: Fix ELF_PLATFORM

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2 years agovduse-blk: Add name option
Xie Yongji [Tue, 14 Jun 2022 05:15:32 +0000 (13:15 +0800)]
vduse-blk: Add name option

Currently we use 'id' option as the name of VDUSE device.
It's a bit confusing since we use one value for two different
purposes: the ID to identfy the export within QEMU (must be
distinct from any other exports in the same QEMU process, but
can overlap with names used by other processes), and the VDUSE
name to uniquely identify it on the host (must be distinct from
other VDUSE devices on the same host, but can overlap with other
export types like NBD in the same process). To make it clear,
this patch adds a separate 'name' option to specify the VDUSE
name for the vduse-blk export instead.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Message-Id: <20220614051532.92-7-xieyongji@bytedance.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agovduse-blk: Add serial option
Xie Yongji [Tue, 14 Jun 2022 05:15:31 +0000 (13:15 +0800)]
vduse-blk: Add serial option

Add a 'serial' option to allow user to specify this value
explicitly. And the default value is changed to an empty
string as what we did in "hw/block/virtio-blk.c".

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Message-Id: <20220614051532.92-6-xieyongji@bytedance.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agonbd: Drop dead code spotted by Coverity
Eric Blake [Mon, 16 May 2022 21:05:19 +0000 (16:05 -0500)]
nbd: Drop dead code spotted by Coverity

CID 1488362 points out that the second 'rc >= 0' check is now dead
code.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Fixes: 172f5f1a40(nbd: remove peppering of nbd_client_connected)
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20220516210519.76135-1-eblake@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoaio_wait_kick: add missing memory barrier
Emanuele Giuseppe Esposito [Tue, 24 May 2022 17:30:54 +0000 (13:30 -0400)]
aio_wait_kick: add missing memory barrier

It seems that aio_wait_kick always required a memory barrier
or atomic operation in the caller, but nobody actually
took care of doing it.

Let's put the barrier in the function instead, and pair it
with another one in AIO_WAIT_WHILE. Read aio_wait_kick()
comment for further explanation.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-Id: <20220524173054.12651-1-eesposit@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock/gluster: correctly set max_pdiscard
Fabian Ebner [Fri, 20 May 2022 07:59:22 +0000 (09:59 +0200)]
block/gluster: correctly set max_pdiscard

On 64-bit platforms, assigning SIZE_MAX to the int64_t max_pdiscard
results in a negative value, and the following assertion would trigger
down the line (it's not the same max_pdiscard, but computed from the
other one):
qemu-system-x86_64: ../block/io.c:3166: bdrv_co_pdiscard: Assertion
`max_pdiscard >= bs->bl.request_alignment' failed.

On 32-bit platforms, it's fine to keep using SIZE_MAX.

The assertion in qemu_gluster_co_pdiscard() is checking that the value
of 'bytes' can safely be passed to glfs_discard_async(), which takes a
size_t for the argument in question, so it is kept as is. And since
max_pdiscard is still <= SIZE_MAX, relying on max_pdiscard is still
fine.

Fixes: 0c8022876f ("block: use int64_t instead of int in driver discard handlers")
Cc: qemu-stable@nongnu.org
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Message-Id: <20220520075922.43972-1-f.ebner@proxmox.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock/rbd: report a better error when namespace does not exist
Stefano Garzarella [Tue, 17 May 2022 07:10:12 +0000 (09:10 +0200)]
block/rbd: report a better error when namespace does not exist

If the namespace does not exist, rbd_create() fails with -ENOENT and
QEMU reports a generic "error rbd create: No such file or directory":

    $ qemu-img create rbd:rbd/namespace/image 1M
    Formatting 'rbd:rbd/namespace/image', fmt=raw size=1048576
    qemu-img: rbd:rbd/namespace/image: error rbd create: No such file or directory

Unfortunately rados_ioctx_set_namespace() does not fail if the namespace
does not exist, so let's use rbd_namespace_exists() in qemu_rbd_connect()
to check if the namespace exists, reporting a more understandable error:

    $ qemu-img create rbd:rbd/namespace/image 1M
    Formatting 'rbd:rbd/namespace/image', fmt=raw size=1048576
    qemu-img: rbd:rbd/namespace/image: namespace 'namespace' does not exist

Reported-by: Tingting Mao <timao@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20220517071012.6120-1-sgarzare@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoqsd: document vduse-blk exports
Stefan Hajnoczi [Wed, 25 May 2022 12:19:47 +0000 (13:19 +0100)]
qsd: document vduse-blk exports

Document vduse-blk exports in qemu-storage-daemon --help and the
qemu-storage-daemon(1) man page.

Based-on: <20220523084611.91-1-xieyongji@bytedance.com>
Cc: Xie Yongji <xieyongji@bytedance.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220525121947.859820-1-stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agolibvduse: Add support for reconnecting
Xie Yongji [Mon, 23 May 2022 08:46:11 +0000 (16:46 +0800)]
libvduse: Add support for reconnecting

To support reconnecting after restart or crash, VDUSE backend
might need to resubmit inflight I/Os. This stores the metadata
such as the index of inflight I/O's descriptors to a shm file so
that VDUSE backend can restore them during reconnecting.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Message-Id: <20220523084611.91-9-xieyongji@bytedance.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agovduse-blk: Add vduse-blk resize support
Xie Yongji [Mon, 23 May 2022 08:46:10 +0000 (16:46 +0800)]
vduse-blk: Add vduse-blk resize support

To support block resize, this uses vduse_dev_update_config()
to update the capacity field in configuration space and inject
config interrupt on the block resize callback.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220523084611.91-8-xieyongji@bytedance.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agovduse-blk: Implement vduse-blk export
Xie Yongji [Mon, 23 May 2022 08:46:09 +0000 (16:46 +0800)]
vduse-blk: Implement vduse-blk export

This implements a VDUSE block backends based on
the libvduse library. We can use it to export the BDSs
for both VM and container (host) usage.

The new command-line syntax is:

$ qemu-storage-daemon \
    --blockdev file,node-name=drive0,filename=test.img \
    --export vduse-blk,node-name=drive0,id=vduse-export0,writable=on

After the qemu-storage-daemon started, we need to use
the "vdpa" command to attach the device to vDPA bus:

$ vdpa dev add name vduse-export0 mgmtdev vduse

Also the device must be removed via the "vdpa" command
before we stop the qemu-storage-daemon.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220523084611.91-7-xieyongji@bytedance.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agolibvduse: Add VDUSE (vDPA Device in Userspace) library
Xie Yongji [Mon, 23 May 2022 08:46:08 +0000 (16:46 +0800)]
libvduse: Add VDUSE (vDPA Device in Userspace) library

VDUSE [1] is a linux framework that makes it possible to implement
software-emulated vDPA devices in userspace. This adds a library
as a subproject to help implementing VDUSE backends in QEMU.

[1] https://www.kernel.org/doc/html/latest/userspace-api/vduse.html

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Message-Id: <20220523084611.91-6-xieyongji@bytedance.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agolinux-headers: Add vduse.h
Xie Yongji [Mon, 23 May 2022 08:46:07 +0000 (16:46 +0800)]
linux-headers: Add vduse.h

This adds vduse header to linux headers so that the
relevant VDUSE API can be used in subsequent patches.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220523084611.91-5-xieyongji@bytedance.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock/export: Abstract out the logic of virtio-blk I/O process
Xie Yongji [Mon, 23 May 2022 08:46:06 +0000 (16:46 +0800)]
block/export: Abstract out the logic of virtio-blk I/O process

Abstract the common logic of virtio-blk I/O process to a function
named virtio_blk_process_req(). It's needed for the following commit.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Message-Id: <20220523084611.91-4-xieyongji@bytedance.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock/export: Fix incorrect length passed to vu_queue_push()
Xie Yongji [Mon, 23 May 2022 08:46:05 +0000 (16:46 +0800)]
block/export: Fix incorrect length passed to vu_queue_push()

Now the req->size is set to the correct value only
when handling VIRTIO_BLK_T_GET_ID request. This patch
fixes it.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Message-Id: <20220523084611.91-3-xieyongji@bytedance.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock: Support passing NULL ops to blk_set_dev_ops()
Xie Yongji [Mon, 23 May 2022 08:46:04 +0000 (16:46 +0800)]
block: Support passing NULL ops to blk_set_dev_ops()

This supports passing NULL ops to blk_set_dev_ops()
so that we can remove stale ops in some cases.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220523084611.91-2-xieyongji@bytedance.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock: simplify handling of try to merge different sized bitmaps
Vladimir Sementsov-Ogievskiy [Tue, 17 May 2022 11:12:06 +0000 (14:12 +0300)]
block: simplify handling of try to merge different sized bitmaps

We have too much logic to simply check that bitmaps are of the same
size. Let's just define that hbitmap_merge() and
bdrv_dirty_bitmap_merge_internal() require their argument bitmaps be of
same size, this simplifies things.

Let's look through the callers:

For backup_init_bcs_bitmap() we already assert that merge can't fail.

In bdrv_reclaim_dirty_bitmap_locked() we gracefully handle the error
that can't happen: successor always has same size as its parent, drop
this logic.

In bdrv_merge_dirty_bitmap() we already has assertion and separate
check. Make the check explicit and improve error message.

Signed-off-by: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
Reviewed-by: Nikita Lapshin <nikita.lapshin@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20220517111206.23585-4-v.sementsov-og@mail.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock: improve block_dirty_bitmap_merge(): don't allocate extra bitmap
Vladimir Sementsov-Ogievskiy [Tue, 17 May 2022 11:12:05 +0000 (14:12 +0300)]
block: improve block_dirty_bitmap_merge(): don't allocate extra bitmap

We don't need extra bitmap. All we need is to backup the original
bitmap when we do first merge. So, drop extra temporary bitmap and work
directly with target and backup.

Still to keep old semantics, that on failure target is unchanged and
user don't need to restore, we need a local_backup variable and do
restore ourselves on failure path.

Signed-off-by: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
Message-Id: <20220517111206.23585-3-v.sementsov-og@mail.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock: block_dirty_bitmap_merge(): fix error path
Vladimir Sementsov-Ogievskiy [Tue, 17 May 2022 11:12:04 +0000 (14:12 +0300)]
block: block_dirty_bitmap_merge(): fix error path

At the end we ignore failure of bdrv_merge_dirty_bitmap() and report
success. And still set errp. That's wrong.

Signed-off-by: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
Reviewed-by: Nikita Lapshin <nikita.lapshin@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20220517111206.23585-2-v.sementsov-og@mail.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock: get rid of blk->guest_block_size
Stefan Hajnoczi [Wed, 18 May 2022 13:09:45 +0000 (14:09 +0100)]
block: get rid of blk->guest_block_size

Commit 1b7fd729559c ("block: rename buffer_alignment to
guest_block_size") noted:

  At this point, the field is set by the device emulation, but completely
  ignored by the block layer.

The last time the value of buffer_alignment/guest_block_size was
actually used was before commit 339064d50639 ("block: Don't use guest
sector size for qemu_blockalign()").

This value has not been used since 2013. Get rid of it.

Cc: Xie Yongji <xieyongji@bytedance.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220518130945.2657905-1-stefanha@redhat.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Alberto Faria <afaria@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agoblock: drop unused bdrv_co_drain() API
Stefan Hajnoczi [Sat, 21 May 2022 12:27:14 +0000 (13:27 +0100)]
block: drop unused bdrv_co_drain() API

bdrv_co_drain() has not been used since commit 9a0cec664eef ("mirror:
use bdrv_drained_begin/bdrv_drained_end") in 2016. Remove it so there
are fewer drain scenarios to worry about.

Use bdrv_drained_begin()/bdrv_drained_end() instead. They are "mixed"
functions that can be called from coroutine context. Unlike
bdrv_co_drain(), these functions provide control of the length of the
drained section, which is usually the right thing.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220521122714.3837731-1-stefanha@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Alberto Faria <afaria@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 years agolinux-user: Adjust child_tidptr on set_tid_address() syscall
Helge Deller [Sat, 28 May 2022 10:52:10 +0000 (12:52 +0200)]
linux-user: Adjust child_tidptr on set_tid_address() syscall

Keep track of the new child tidptr given by a set_tid_address() syscall.

Do not call the host set_tid_address() syscall because we are emulating
the behaviour of writing to child_tidptr in the exit() path.

Signed-off-by: Helge Deller<deller@gmx.de>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <YpH+2sw1PCRqx/te@p100>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2 years agolinux-user: Add partial support for MADV_DONTNEED
Ilya Leoshkevich [Tue, 21 Jun 2022 14:42:05 +0000 (16:42 +0200)]
linux-user: Add partial support for MADV_DONTNEED

Currently QEMU ignores madvise(MADV_DONTNEED), which break apps that
rely on this for zeroing out memory [1]. Improve the situation by doing
a passthrough when the range in question is a host-page-aligned
anonymous mapping.

This is based on the patches from Simon Hausmann [2] and Chris Fallin
[3]. The structure is taken from Simon's patch. The PAGE_MAP_ANONYMOUS
bits are superseded by commit 26bab757d41b ("linux-user: Introduce
PAGE_ANON"). In the end the patch acts like the one from Chris: we
either pass-through the entire syscall, or do nothing, since doing this
only partially would not help the affected applications much. Finally,
add some extra checks to match the behavior of the Linux kernel [4].

[1] https://gitlab.com/qemu-project/qemu/-/issues/326
[2] https://patchew.org/QEMU/20180827084037.25316-1-simon.hausmann@qt.io/
[3] https://github.com/bytecodealliance/wasmtime/blob/v0.37.0/ci/qemu-madvise.patch
[4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/madvise.c?h=v5.19-rc3#n1368

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220621144205.158452-1-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2 years agoMerge tag 'nvme-next-pull-request' of git://git.infradead.org/qemu-nvme into staging
Richard Henderson [Thu, 23 Jun 2022 21:52:30 +0000 (14:52 -0700)]
Merge tag 'nvme-next-pull-request' of git://git.infradead.org/qemu-nvme into staging

hw/nvme updates

- sriov functionality
- odd fixes

# -----BEGIN PGP SIGNATURE-----
#
# iQEzBAABCAAdFiEEUigzqnXi3OaiR2bATeGvMW1PDekFAmK02wUACgkQTeGvMW1P
# DenNPwgAwhQCXXacTb+6vEdxN30QoWygzQj5BLm//SiXlj7hBX7P/JqCxYF5vUDU
# EaZkl4n3ry5T1xqlUWIBFdIAmKyrsWz2eKTrX41g64i/L+/nfJXZ+IgQc3WkM/FK
# 5NwwAE8q/JGiRczLesF/9QvQq/90L6QtyC48bsS8AIcl5IcqHCKGwEJS7LErltex
# YZDJyTNU4wB2XFophylJUL43GrHa/kUFA2ZHgs9iuH0p5LGG6UM3KoinBKcbwn47
# iEWKccvsHSyfE8VpJJS5STMEeGGaBPziZ654ElLmzVq6EXDKMCoX03naQ9Q8oSpl
# FiktbxllCYdmECb44PNBEd/nLdpCdQ==
# =o54a
# -----END PGP SIGNATURE-----
# gpg: Signature made Thu 23 Jun 2022 02:28:37 PM PDT
# gpg:                using RSA key 522833AA75E2DCE6A24766C04DE1AF316D4F0DE9
# gpg: Good signature from "Klaus Jensen <its@irrelevant.dk>" [unknown]
# gpg:                 aka "Klaus Jensen <k.jensen@samsung.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: DDCA 4D9C 9EF9 31CC 3468  4272 63D5 6FC5 E55D A838
#      Subkey fingerprint: 5228 33AA 75E2 DCE6 A247  66C0 4DE1 AF31 6D4F 0DE9

* tag 'nvme-next-pull-request' of git://git.infradead.org/qemu-nvme:
  hw/nvme: clear aen mask on reset
  Revert "hw/block/nvme: add support for sgl bit bucket descriptor"
  hw/nvme: clean up CC register write logic
  hw/acpi: Make the PCI hot-plug aware of SR-IOV
  hw/nvme: Update the initalization place for the AER queue
  docs: Add documentation for SR-IOV and Virtualization Enhancements
  hw/nvme: Add support for the Virtualization Management command
  hw/nvme: Initialize capability structures for primary/secondary controllers
  hw/nvme: Calculate BAR attributes in a function
  hw/nvme: Remove reg_size variable and update BAR0 size calculation
  hw/nvme: Make max_ioqpairs and msix_qsize configurable in runtime
  hw/nvme: Implement the Function Level Reset
  hw/nvme: Add support for Secondary Controller List
  hw/nvme: Add support for Primary Controller Capabilities
  hw/nvme: Add support for SR-IOV

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2 years agohw/nvme: clear aen mask on reset
Klaus Jensen [Thu, 12 May 2022 09:30:55 +0000 (11:30 +0200)]
hw/nvme: clear aen mask on reset

The internally maintained AEN mask is not cleared on reset. Fix this.

Reviewed-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agoRevert "hw/block/nvme: add support for sgl bit bucket descriptor"
Klaus Jensen [Mon, 2 May 2022 05:55:54 +0000 (07:55 +0200)]
Revert "hw/block/nvme: add support for sgl bit bucket descriptor"

This reverts commit d97eee64fef35655bd06f5c44a07fdb83a6274ae.

The emulated controller correctly accounts for not including bit buckets
in the controller-to-host data transfer, however it doesn't correctly
account for the holes for the on-disk data offsets.

Reported-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: clean up CC register write logic
Klaus Jensen [Tue, 17 May 2022 11:07:51 +0000 (13:07 +0200)]
hw/nvme: clean up CC register write logic

The SRIOV series exposed an issued with how CC register writes are
handled and how CSTS is set in response to that. Specifically, after
applying the SRIOV series, the controller could end up in a state with
CC.EN set to '1' but with CSTS.RDY cleared to '0', causing drivers to
expect CSTS.RDY to transition to '1' but timing out.

Clean this up.

Reviewed-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Reviewed-by: Lukasz Maniak <lukasz.maniak@linux.intel.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/acpi: Make the PCI hot-plug aware of SR-IOV
Łukasz Gieryk [Mon, 9 May 2022 14:16:20 +0000 (16:16 +0200)]
hw/acpi: Make the PCI hot-plug aware of SR-IOV

PCI device capable of SR-IOV support is a new, still-experimental
feature with only a single working example of the Nvme device.

This patch in an attempt to fix a double-free problem when a
SR-IOV-capable Nvme device is hot-unplugged in the following scenario:

Qemu CLI:
---------
-device pcie-root-port,slot=0,id=rp0
-device nvme-subsys,id=subsys0
-device nvme,id=nvme0,bus=rp0,serial=deadbeef,subsys=subsys0,sriov_max_vfs=1,sriov_vq_flexible=2,sriov_vi_flexible=1

Guest OS:
---------
sudo nvme virt-mgmt /dev/nvme0 -c 0 -r 1 -a 1 -n 0
sudo nvme virt-mgmt /dev/nvme0 -c 0 -r 0 -a 1 -n 0
echo 1 > /sys/bus/pci/devices/0000:01:00.0/reset
sleep 1
echo 1 > /sys/bus/pci/devices/0000:01:00.0/sriov_numvfs
nvme virt-mgmt /dev/nvme0 -c 1 -r 1 -a 8 -n 1
nvme virt-mgmt /dev/nvme0 -c 1 -r 0 -a 8 -n 2
nvme virt-mgmt /dev/nvme0 -c 1 -r 0 -a 9 -n 0
sleep 2
echo 01:00.1 > /sys/bus/pci/drivers/nvme/bind

Qemu monitor:
-------------
device_del nvme0

Explanation of the problem and the proposed solution:

1) The current SR-IOV implementation assumes it’s the PhysicalFunction
   that creates and deletes VirtualFunctions.
2) It’s a design decision (the Nvme device at least) for the VFs to be
   of the same class as PF. Effectively, they share the dc->hotpluggable
   value.
3) When a VF is created, it’s added as a child node to PF’s PCI bus
   slot.
4) Monitor/device_del triggers the ACPI mechanism. The implementation is
   not aware of SR/IOV and ejects PF’s PCI slot, directly unrealizing all
   hot-pluggable (!acpi_pcihp_pc_no_hotplug) children nodes.
5) VFs are unrealized directly, and it doesn’t work well with (1).
   SR/IOV structures are not updated, so when it’s PF’s turn to be
   unrealized, it works on stale pointers to already-deleted VFs.

The proposed fix is to make the PCI ACPI code aware of SR/IOV.

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Update the initalization place for the AER queue
Łukasz Gieryk [Mon, 9 May 2022 14:16:19 +0000 (16:16 +0200)]
hw/nvme: Update the initalization place for the AER queue

This patch updates the initialization place for the AER queue, so it’s
initialized once, at controller initialization, and not every time
controller is enabled.

While the original version works for a non-SR-IOV device, as it’s hard
to interact with the controller if it’s not enabled, the multiple
reinitialization is not necessarily correct.

With the SR/IOV feature enabled a segfault can happen: a VF can have its
controller disabled, while a namespace can still be attached to the
controller through the parent PF. An event generated in such case ends
up on an uninitialized queue.

While it’s an interesting question whether a VF should support AER in
the first place, I don’t think it must be answered today.

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agodocs: Add documentation for SR-IOV and Virtualization Enhancements
Lukasz Maniak [Mon, 9 May 2022 14:16:18 +0000 (16:16 +0200)]
docs: Add documentation for SR-IOV and Virtualization Enhancements

Documentation describes 5 new parameters being added regarding SR-IOV:
sriov_max_vfs
sriov_vq_flexible
sriov_vi_flexible
sriov_max_vi_per_vf
sriov_max_vq_per_vf

The description also includes the simplest possible QEMU invocation
and the series of NVMe commands required to enable SR-IOV support.

Signed-off-by: Lukasz Maniak <lukasz.maniak@linux.intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Add support for the Virtualization Management command
Łukasz Gieryk [Mon, 9 May 2022 14:16:17 +0000 (16:16 +0200)]
hw/nvme: Add support for the Virtualization Management command

With the new command one can:
 - assign flexible resources (queues, interrupts) to primary and
   secondary controllers,
 - toggle the online/offline state of given controller.

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Initialize capability structures for primary/secondary controllers
Łukasz Gieryk [Mon, 9 May 2022 14:16:16 +0000 (16:16 +0200)]
hw/nvme: Initialize capability structures for primary/secondary controllers

With four new properties:
 - sriov_v{i,q}_flexible,
 - sriov_max_v{i,q}_per_vf,
one can configure the number of available flexible resources, as well as
the limits. The primary and secondary controller capability structures
are initialized accordingly.

Since the number of available queues (interrupts) now varies between
VF/PF, BAR size calculation is also adjusted.

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Calculate BAR attributes in a function
Łukasz Gieryk [Mon, 9 May 2022 14:16:15 +0000 (16:16 +0200)]
hw/nvme: Calculate BAR attributes in a function

An NVMe device with SR-IOV capability calculates the BAR size
differently for PF and VF, so it makes sense to extract the common code
to a separate function.

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Remove reg_size variable and update BAR0 size calculation
Łukasz Gieryk [Mon, 9 May 2022 14:16:14 +0000 (16:16 +0200)]
hw/nvme: Remove reg_size variable and update BAR0 size calculation

The n->reg_size parameter unnecessarily splits the BAR0 size calculation
in two phases; removed to simplify the code.

With all the calculations done in one place, it seems the pow2ceil,
applied originally to reg_size, is unnecessary. The rounding should
happen as the last step, when BAR size includes Nvme registers, queue
registers, and MSIX-related space.

Finally, the size of the mmio memory region is extended to cover the 1st
4KiB padding (see the map below). Access to this range is handled as
interaction with a non-existing queue and generates an error trace, so
actually nothing changes, while the reg_size variable is no longer needed.

    --------------------
    |      BAR0        |
    --------------------
    [Nvme Registers    ]
    [Queues            ]
    [power-of-2 padding] - removed in this patch
    [4KiB padding (1)  ]
    [MSIX TABLE        ]
    [4KiB padding (2)  ]
    [MSIX PBA          ]
    [power-of-2 padding]

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Make max_ioqpairs and msix_qsize configurable in runtime
Łukasz Gieryk [Mon, 9 May 2022 14:16:13 +0000 (16:16 +0200)]
hw/nvme: Make max_ioqpairs and msix_qsize configurable in runtime

The NVMe device defines two properties: max_ioqpairs, msix_qsize. Having
them as constants is problematic for SR-IOV support.

SR-IOV introduces virtual resources (queues, interrupts) that can be
assigned to PF and its dependent VFs. Each device, following a reset,
should work with the configured number of queues. A single constant is
no longer sufficient to hold the whole state.

This patch tries to solve the problem by introducing additional
variables in NvmeCtrl’s state. The variables for, e.g., managing queues
are therefore organized as:
 - n->params.max_ioqpairs – no changes, constant set by the user
 - n->(mutable_state) – (not a part of this patch) user-configurable,
                        specifies number of queues available _after_
                        reset
 - n->conf_ioqpairs - (new) used in all the places instead of the ‘old’
                      n->params.max_ioqpairs; initialized in realize()
                      and updated during reset() to reflect user’s
                      changes to the mutable state

Since the number of available i/o queues and interrupts can change in
runtime, buffers for sq/cqs and the MSIX-related structures are
allocated big enough to handle the limits, to completely avoid the
complicated reallocation. A helper function (nvme_update_msixcap_ts)
updates the corresponding capability register, to signal configuration
changes.

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Implement the Function Level Reset
Łukasz Gieryk [Mon, 9 May 2022 14:16:12 +0000 (16:16 +0200)]
hw/nvme: Implement the Function Level Reset

This patch implements the Function Level Reset, a feature currently not
implemented for the Nvme device, while listed as a mandatory ("shall")
in the 1.4 spec.

The implementation reuses FLR-related building blocks defined for the
pci-bridge module, and follows the same logic:
    - FLR capability is advertised in the PCIE config,
    - custom pci_write_config callback detects a write to the trigger
      register and performs the PCI reset,
    - which, eventually, calls the custom dc->reset handler.

Depending on reset type, parts of the state should (or should not) be
cleared. To distinguish the type of reset, an additional parameter is
passed to the reset function.

This patch also enables advertisement of the Power Management PCI
capability. The main reason behind it is to announce the no_soft_reset=1
bit, to signal SR-IOV support where each VF can be reset individually.

The implementation purposedly ignores writes to the PMCS.PS register,
as even such naïve behavior is enough to correctly handle the D3->D0
transition.

It’s worth to note, that the power state transition back to to D3, with
all the corresponding side effects, wasn't and stil isn't handled
properly.

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Add support for Secondary Controller List
Lukasz Maniak [Mon, 9 May 2022 14:16:11 +0000 (16:16 +0200)]
hw/nvme: Add support for Secondary Controller List

Introduce handling for Secondary Controller List (Identify command with
CNS value of 15h).

Secondary controller ids are unique in the subsystem, hence they are
reserved by it upon initialization of the primary controller to the
number of sriov_max_vfs.

ID reservation requires the addition of an intermediate controller slot
state, so the reserved controller has the address 0xFFFF.
A secondary controller is in the reserved state when it has no virtual
function assigned, but its primary controller is realized.
Secondary controller reservations are released to NULL when its primary
controller is unregistered.

Signed-off-by: Lukasz Maniak <lukasz.maniak@linux.intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Add support for Primary Controller Capabilities
Lukasz Maniak [Mon, 9 May 2022 14:16:10 +0000 (16:16 +0200)]
hw/nvme: Add support for Primary Controller Capabilities

Implementation of Primary Controller Capabilities data
structure (Identify command with CNS value of 14h).

Currently, the command returns only ID of a primary controller.
Handling of remaining fields are added in subsequent patches
implementing virtualization enhancements.

Signed-off-by: Lukasz Maniak <lukasz.maniak@linux.intel.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agohw/nvme: Add support for SR-IOV
Lukasz Maniak [Mon, 9 May 2022 14:16:09 +0000 (16:16 +0200)]
hw/nvme: Add support for SR-IOV

This patch implements initial support for Single Root I/O Virtualization
on an NVMe device.

Essentially, it allows to define the maximum number of virtual functions
supported by the NVMe controller via sriov_max_vfs parameter.

Passing a non-zero value to sriov_max_vfs triggers reporting of SR-IOV
capability by a physical controller and ARI capability by both the
physical and virtual function devices.

NVMe controllers created via virtual functions mirror functionally
the physical controller, which may not entirely be the case, thus
consideration would be needed on the way to limit the capabilities of
the VF.

NVMe subsystem is required for the use of SR-IOV.

Signed-off-by: Lukasz Maniak <lukasz.maniak@linux.intel.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2 years agoMerge tag 'pull-migration-20220623b' of https://gitlab.com/dagrh/qemu into staging
Richard Henderson [Thu, 23 Jun 2022 17:14:20 +0000 (10:14 -0700)]
Merge tag 'pull-migration-20220623b' of https://gitlab.com/dagrh/qemu into staging

[v3] Migration pull 2022-06-23

This replaces my and Juan's earlier pulls over the last 2 days;
4th time lucky?

Compared to my pull earlier:
  Removed Hyman's dirty ring set

In this migration PULL request:
- Dainiel Berrangé - qemufileops cleanup
- Leonardo Bras  - cleanups for zero copy
- Juan Quintela  - RDMA cleanups

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCAAdFiEERfXHG0oMt/uXep+pBRYzHrxb/ecFAmK0mnwACgkQBRYzHrxb
# /ecJYQ/8DdQBVYpJjpHj3mBx39aXodM7uM4Jt1okuSF92y9KRSNdIs3nvvwWAZbL
# dWAUHUZBNOfZF7Eqe6WWCIDNxUTz88RkMM16N3+a5sqBa0xU6rP6cvyw9vYrnsmx
# aHVQ1ESosTby2qcb1ofjYRXWNt7GhDtRIH55m3mSalP/WAgjMe3MsrAtz66T4w55
# 4paTVwgS/WMuLD9dqyESyofePnvtM8z3ye2a75JRscBQYmpO+XuX3IX5ah6m439s
# fI1BezQU2Q4YNDmCEWvdfZ2tqgcfi8dHnu0JB9QTfbkPVh9jw25VPpnymimMB7iW
# MlXAlDr7m9HQI6OjIkq8pXBcgWQpbVGMon1CcrDmGCReEjnQ5lTsb27fkXzf/Nwu
# 09iuNfYGcSGAbZ8GZa/lrRTGeINrSj99uOVxrTvVS0db2+1va3hkamGMULhsdX6O
# smOrje79pVLAr7JJSMH2bqFv9cKtLu77HndSVtswkRRMhtDU+VQI5FxYlwueuawJ
# toDM4DJMd3pJHIpPrUwxlo4D9dkdxPfqC1GATDPxw9/vYgbORn8fkt5g9EYxBzc0
# pWRY9SNuw0MC54JGEoFc77+VKJXK1A97j9GoF+Vyoh30yTgZ3q9tm2eElpYwtHDy
# t8zEVC9QadcgMdRAnJqgZgaWdfwKiHpjplSn5lOGDLOo7gfSmik=
# =ajVU
# -----END PGP SIGNATURE-----
# gpg: Signature made Thu 23 Jun 2022 09:53:16 AM PDT
# gpg:                using RSA key 45F5C71B4A0CB7FB977A9FA90516331EBC5BFDE7
# gpg: Good signature from "Dr. David Alan Gilbert (RH2) <dgilbert@redhat.com>" [full]

* tag 'pull-migration-20220623b' of https://gitlab.com/dagrh/qemu: (25 commits)
  migration: remove the QEMUFileOps abstraction
  migration: remove the QEMUFileOps 'get_return_path' callback
  migration: remove the QEMUFileOps 'writev_buffer' callback
  migration: remove the QEMUFileOps 'get_buffer' callback
  migration: remove the QEMUFileOps 'close' callback
  migration: remove the QEMUFileOps 'set_blocking' callback
  migration: remove the QEMUFileOps 'shut_down' callback
  migration: remove unused QEMUFileGetFD typedef / qemu_get_fd method
  migration: introduce new constructors for QEMUFile
  migration: hardcode assumption that QEMUFile is backed with QIOChannel
  migration: stop passing 'opaque' parameter to QEMUFile hooks
  migration: convert savevm to use QIOChannelBlock for VMState
  migration: introduce a QIOChannel impl for BlockDriverState VMState
  migration: rename qemu_file_update_transfer to qemu_file_acct_rate_limit
  migration: rename qemu_update_position to qemu_file_credit_transfer
  migration: rename qemu_ftell to qemu_file_total_transferred
  migration: rename 'pos' field in QEMUFile to 'bytes_processed'
  migration: rename rate limiting fields in QEMUFile
  migration: remove unreachble RDMA code in save_hook impl
  migration: switch to use QIOChannelNull for dummy channel
  ...

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2 years agomigration: remove the QEMUFileOps abstraction
Daniel P. Berrangé [Mon, 20 Jun 2022 11:02:05 +0000 (12:02 +0100)]
migration: remove the QEMUFileOps abstraction

Now that all QEMUFile callbacks are removed, the entire concept can be
deleted.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2 years agomigration: remove the QEMUFileOps 'get_return_path' callback
Daniel P. Berrangé [Mon, 20 Jun 2022 11:02:04 +0000 (12:02 +0100)]
migration: remove the QEMUFileOps 'get_return_path' callback

This directly implements the get_return_path logic using QIOChannel APIs.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2 years agomigration: remove the QEMUFileOps 'writev_buffer' callback
Daniel P. Berrangé [Mon, 20 Jun 2022 11:02:03 +0000 (12:02 +0100)]
migration: remove the QEMUFileOps 'writev_buffer' callback

This directly implements the writev_buffer logic using QIOChannel APIs.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2 years agomigration: remove the QEMUFileOps 'get_buffer' callback
Daniel P. Berrangé [Mon, 20 Jun 2022 11:02:02 +0000 (12:02 +0100)]
migration: remove the QEMUFileOps 'get_buffer' callback

This directly implements the get_buffer logic using QIOChannel APIs.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  dgilbert: Fixup len = *-*EIO as spotted by Peter Xu

2 years agomigration: remove the QEMUFileOps 'close' callback
Daniel P. Berrangé [Mon, 20 Jun 2022 11:02:01 +0000 (12:02 +0100)]
migration: remove the QEMUFileOps 'close' callback

This directly implements the close logic using QIOChannel APIs.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2 years agomigration: remove the QEMUFileOps 'set_blocking' callback
Daniel P. Berrangé [Mon, 20 Jun 2022 11:02:00 +0000 (12:02 +0100)]
migration: remove the QEMUFileOps 'set_blocking' callback

This directly implements the set_blocking logic using QIOChannel APIs.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2 years agomigration: remove the QEMUFileOps 'shut_down' callback
Daniel P. Berrangé [Mon, 20 Jun 2022 11:01:59 +0000 (12:01 +0100)]
migration: remove the QEMUFileOps 'shut_down' callback

This directly implements the shutdown logic using QIOChannel APIs.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2 years agomigration: remove unused QEMUFileGetFD typedef / qemu_get_fd method
Daniel P. Berrangé [Mon, 20 Jun 2022 11:01:58 +0000 (12:01 +0100)]
migration: remove unused QEMUFileGetFD typedef / qemu_get_fd method

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2 years agomigration: introduce new constructors for QEMUFile
Daniel P. Berrangé [Mon, 20 Jun 2022 11:01:57 +0000 (12:01 +0100)]
migration: introduce new constructors for QEMUFile

Prepare for the elimination of QEMUFileOps by introducing a pair of new
constructors. This lets us distinguish between an input and output file
object explicitly rather than via the existance of specific callbacks.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>