Message ID | b6718a3512ec0a97c6ef4a5b5c1f3de72238c603.1654961918.git.brchuckz@aol.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v2] xen/pass-through: merge emulated bits correctly | expand |
On Sat, Jun 11, 2022 at 12:43:29PM -0400, Chuck Zmudzinski wrote: > In xen_pt_config_reg_init(), there is an error in the merging of the > emulated data with the host value. With the current Qemu, instead of > merging the emulated bits with the host bits as defined by emu_mask, > the emulated bits are merged with the host bits as defined by the > inverse of emu_mask. In some cases, depending on the data in the > registers on the host, the way the registers are setup, and the > initial values of the emulated bits, the end result will be that > the register is initialized with the wrong value. > > To correct this error, use the XEN_PT_MERGE_VALUE macro to help ensure > the merge is done correctly. > > This correction is needed to resolve Qemu project issue #1061, which > describes the failure of Xen HVM Linux guests to boot in certain > configurations with passed through PCI devices, that is, when this error > disables instead of enables the PCI_STATUS_CAP_LIST bit of the > PCI_STATUS register of a passed through PCI device, which in turn > disables the MSI-X capability of the device in Linux guests with the end > result being that the Linux guest never completes the boot process. > > Fixes: 2e87512eccf3 > Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1061 > Buglink: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=988333 > > Signed-off-by: Chuck Zmudzinski <brchuckz@aol.com> Reviewed-by: Anthony PERARD <anthony.perard@citrix.com> Thank you, looks like it's been a long quest to figure this one out.
diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index ffd915654c..bc0383f7fb 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -1966,10 +1966,10 @@ static void xen_pt_config_reg_init(XenPCIPassthroughState *s, if ((data & host_mask) != (val & host_mask)) { uint32_t new_val; - /* Mask out host (including past size). */ - new_val = val & host_mask; - /* Merge emulated ones (excluding the non-emulated ones). */ - new_val |= data & host_mask; + /* Merge the emulated bits (data) with the host bits (val) + * and mask out the bits past size to enable restoration + * of the proper value for logging below. */ + new_val = XEN_PT_MERGE_VALUE(val, data, host_mask) & size_mask; /* Leave intact host and emulated values past the size - even though * we do not care as we write per reg->size granularity, but for the * logging below lets have the proper value. */
In xen_pt_config_reg_init(), there is an error in the merging of the emulated data with the host value. With the current Qemu, instead of merging the emulated bits with the host bits as defined by emu_mask, the emulated bits are merged with the host bits as defined by the inverse of emu_mask. In some cases, depending on the data in the registers on the host, the way the registers are setup, and the initial values of the emulated bits, the end result will be that the register is initialized with the wrong value. To correct this error, use the XEN_PT_MERGE_VALUE macro to help ensure the merge is done correctly. This correction is needed to resolve Qemu project issue #1061, which describes the failure of Xen HVM Linux guests to boot in certain configurations with passed through PCI devices, that is, when this error disables instead of enables the PCI_STATUS_CAP_LIST bit of the PCI_STATUS register of a passed through PCI device, which in turn disables the MSI-X capability of the device in Linux guests with the end result being that the Linux guest never completes the boot process. Fixes: 2e87512eccf3 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1061 Buglink: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=988333 Signed-off-by: Chuck Zmudzinski <brchuckz@aol.com> --- v2: Edit the commit message to more accurately describe the cause of the error. hw/xen/xen_pt_config_init.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)