qemu-xen: Intel GPU passthrough, fix OpRegion mapping. (v3)
PATCH 1/1 qemu-xen: Intel GPU passthrough, fix OpRegion mapping. (v3)
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset 0xfc).
To work correctly this patch needs a change in hvmloader.
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>
Oups, patch is missing.
Jean
commit a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]> Date: Wed Nov 23 07:53:30 2011 +0000
qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset 0xfc).
To work correctly this patch needs a change in hvmloader.
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
hw/pass-through.c +48 -1
@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev,static int pt_exp_rom_bar_reg_restore (struct pt_dev *ptdev,struct pt_reg_tbl *cfg_entry,uint32_t real_offset,uint32_t dev_value,uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, +struct pt_reg_tbl *cfg_entry, +uint32_t *value,uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, +struct pt_reg_tbl *cfg_entry, +uint32_t *value,uint32_t dev_value,uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, +struct pt_reg_grp_info_tbl *grp_reg,uint32_t base_offset);/* pt_reg_info_tbl declaration * - only for emulated register (either a part or whole bit).
@@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { .u.dw.write = pt_exp_rom_bar_reg_write, .u.dw.restore = pt_exp_rom_bar_reg_restore, }, +/* Intel IGFX OpRegion reg */ + { + .offset = PCI_INTEL_OPREGION, + .size = 4, + .init_val = 0, + .no_wb = 1, + .u.dw.read = pt_intel_opregion_read, + .u.dw.write = pt_intel_opregion_write, + .u.dw.restore = NULL, + }, { .size = 0, },
@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { .grp_id = 0xFF, .grp_type = GRP_TYPE_EMU, .grp_size = 0x40, - .size_init = pt_reg_grp_size_init, + .size_init = pt_reg_grp_header0_size_init, .emu_reg_tbl= pt_emu_reg_header0_tbl, },/* PCI PowerManagement Capability reg group */
@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev,return reg->init_val; } +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, +struct pt_reg_grp_info_tbl *grp_reg,uint32_t base_offset) +{ +/* +** By default we will trap up to 0x40 in the cfg space. +** If an intel device is pass through we need to trap 0xfc, +** therefore the size should be 0xff. +*/ +if (igd_passthru) +return 0xFF ; +return grp_reg->grp_size; +} +/* get register group size */ static uint8_t pt_reg_grp_size_init (struct pt_dev *ptdev,struct pt_reg_grp_info_tbl *grp_reg,uint32_t base_offset)
@@ -4154,6 +4185,22 @@ static int pt_pmcsr_reg_restore(struct pt_dev *ptdev,return 0 ; } +static int pt_intel_opregion_read (struct pt_dev *ptdev, +struct pt_reg_tbl *cfg_entry, +uint32_t *value,uint32_t valid_mask) +{ + *value =igd_read_opregion (ptdev); +return 0 ; +} + +static int pt_intel_opregion_write (struct pt_dev *ptdev, +struct pt_reg_tbl *cfg_entry, +uint32_t *value,uint32_t dev_value,uint32_t valid_mask) +{ +igd_write_opregion (ptdev, *value); +return 0 ; +} + static struct pt_dev * register_real_device(PCIBus *e_bus, const char *e_dev_name, int e_devfn, uint8_t r_bus, uint8_t r_dev, uint8_t r_func, uint32_t machine_irq, struct pci_access *pci_access,
hw/pass-through.h +2 -0
@@ -422,6 +422,8 @@ PCIBus *intel_pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, const char *name, uint16_t revision);void igd_pci_write (PCIDevice *pci_dev,uint32_t config_addr,uint32_t val,int len);uint32_t igd_pci_read (PCIDevice *pci_dev,uint32_t config_addr,int len); +uint32_t igd_read_opregion (struct pt_dev *pci_dev); +void igd_write_opregion (struct pt_dev *real_dev,uint32_t val);#endif /* __PASSTHROUGH_H__ */
hw/pt-graphics.c +54 -19
111 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 87 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3Author: Jean Guyader <[email protected]> Date: Wed Nov 23 07:53:30 2011 +0000qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
hw/pass-through.c +21
-1@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev,static int pt_exp_rom_bar_reg_restore (struct pt_dev *ptdev,struct pt_reg_tbl *cfg_entry,uint32_t real_offset,uint32_t dev_value,uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, +struct pt_reg_tbl *cfg_entry, +uint32_t *value,uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, +struct pt_reg_tbl *cfg_entry, +uint32_t *value,uint32_t dev_value,uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, +struct pt_reg_grp_info_tbl *grp_reg,uint32_t base_offset);/* pt_reg_info_tbl declaration * - only for emulated register (either a part or whole bit). @@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { .u.dw.write = pt_exp_rom_bar_reg_write, .u.dw.restore = pt_exp_rom_bar_reg_restore, }, +/* Intel IGFX OpRegion reg */ + { + .offset = PCI_INTEL_OPREGION, + .size = 4, + .init_val = 0, + .no_wb = 1, + .u.dw.read = pt_intel_opregion_read, + .u.dw.write = pt_intel_opregion_write, + .u.dw.restore = NULL, + }, { .size = 0, },@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { .grp_id = 0xFF, .grp_type = GRP_TYPE_EMU, .grp_size = 0x40, - .size_init = pt_reg_grp_size_init, + .size_init = pt_reg_grp_header0_size_init, .emu_reg_tbl= pt_emu_reg_header0_tbl, },/* PCI PowerManagement Capability reg group */ @@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev,return reg->init_val; } +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, +struct pt_reg_grp_info_tbl *grp_reg,uint32_t base_offset)
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 10 lines
hw/pass-through.c +10
-0+{ +/* +** By default we will trap up to 0x40 in the cfg space. +** If an intel device is pass through we need to trap 0xfc, +** therefore the size should be 0xff. +*/ +if (igd_passthru) +return 0xFF ; +return grp_reg->grp_size; +}
Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between 0x40 and 0xff, that previously were probably passed through?
Quoted 95 lines · Stefano Stabellini
Quoted 94 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]>
Date: Wed Nov 23 07:53:30 2011 +0000qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
hw/pass-through.c +28
-1@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev, static int pt_exp_rom_bar_reg_restore(struct pt_dev *ptdev, struct pt_reg_tbl *cfg_entry, uint32_t real_offset, uint32_t dev_value, uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, + struct pt_reg_tbl *cfg_entry, + uint32_t *value, uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, + struct pt_reg_tbl *cfg_entry, + uint32_t *value, uint32_t dev_value, uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset); /* pt_reg_info_tbl declaration* - only for emulated register (either a part or whole bit). @@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { .u.dw.write = pt_exp_rom_bar_reg_write, .u.dw.restore = pt_exp_rom_bar_reg_restore, }, + /* Intel IGFX OpRegion reg */ + { + .offset = PCI_INTEL_OPREGION, + .size = 4, + .init_val = 0, + .no_wb = 1, + .u.dw.read = pt_intel_opregion_read, + .u.dw.write = pt_intel_opregion_write, + .u.dw.restore = NULL, + }, { .size = 0, },@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { .grp_id = 0xFF, .grp_type = GRP_TYPE_EMU, .grp_size = 0x40, - .size_init = pt_reg_grp_size_init, + .size_init = pt_reg_grp_header0_size_init, .emu_reg_tbl= pt_emu_reg_header0_tbl, }, /* PCI PowerManagement Capability reg group */@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, return reg->init_val; } +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset) +{ + /* + ** By default we will trap up to 0x40 in the cfg space. + ** If an intel device is pass through we need to trap 0xfc, + ** therefore the size should be 0xff. + */ + if (igd_passthru)
Quoted 9 lines
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 3 lines
hw/pass-through.c +3
-0+ return 0xFF; + return grp_reg->grp_size; +}Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between
0x40and0xff, that previously were probably passed through?
Based on how pt_find_reg_grp is implemented that doesn't make any difference.
Jean
Quoted 107 lines · Jean Guyader
Quoted 95 lines · Stefano Stabellini
Quoted 94 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]>
Date: Â Wed Nov 23 07:53:30 2011 +0000Â Â qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
  The OpRegion shouldn't be mapped 1:1 because the address in the host   can't be used in the guest directly.
  This patch traps read and write access to the opregion of the Intel   GPU config space (offset
0xfc).  To work correctly this patch needs a change in hvmloader.
  HVMloader will allocate 2 pages for the OpRegion and write this address   on the config space of the Intel GPU. Qemu will trap and map the host   OpRegion to the guest. Any write to this offset after that won't have   any effect. Any read of this config space offset will return the address   in the guest.
hw/pass-through.c +8
-0@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev, Â static int pt_exp_rom_bar_reg_restore(struct pt_dev *ptdev, Â Â Â struct pt_reg_tbl *cfg_entry, Â Â Â uint32_t real_offset, uint32_t dev_value, uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, + Â Â Â Â struct pt_reg_tbl *cfg_entry, + Â Â Â Â uint32_t *value, uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, + Â Â Â Â struct pt_reg_tbl *cfg_entry, + Â Â Â Â uint32_t *value, uint32_t dev_value, uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + Â Â Â Â struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset);Â /*
pt_reg_info_tbldeclaration
 * - only for emulated register (either a part or whole bit).hw/pass-through.c +11
-1@@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = {      .u.dw.write = pt_exp_rom_bar_reg_write,      .u.dw.restore = pt_exp_rom_bar_reg_restore,    }, +   /* Intel IGFX OpRegion reg */ +   { +     .offset   = PCI_INTEL_OPREGION, +     .size    = 4, +     .init_val  = 0, +     .no_wb    = 1, +     .u.dw.read  = pt_intel_opregion_read, +     .u.dw.write  = pt_intel_opregion_write, +     .u.dw.restore  = NULL, +   },    {      .size = 0,    },@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = {      .grp_id   = 0xFF,      .grp_type  = GRP_TYPE_EMU,      .grp_size  = 0x40, -     .size_init  = pt_reg_grp_size_init, +     .size_init  = pt_reg_grp_header0_size_init,      .emu_reg_tbl= pt_emu_reg_header0_tbl,    },   /* PCI PowerManagement Capability reg group */
hw/pass-through.c +9
-0@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, Â Â Â return reg->init_val; Â } +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + Â Â Â Â struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset) +{ + Â Â /* +Â Â ** By default we will trap up to 0x40 in the cfg space. +Â Â ** If an intel device is pass through we need to trap 0xfc, +Â Â ** therefore the size should be 0xff. +Â Â */ + Â Â if (igd_passthru)Quoted 9 lines
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 3 lines
hw/pass-through.c +3
-0+ Â Â Â Â return 0xFF; + Â Â return grp_reg->grp_size; +}Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between
0x40and0xff, that previously were probably passed through?
Quoted 1 line
Based on how
pt_find_reg_grpis implemented that doesn't make any difference.
actually there is a small change in behaviour: before your patch pt_find_reg_grp would return NULL for any cfg register between 0x40 and 0xff. Now if igd_passthru is set pt_find_reg_grp would return the reg_grp_entry corresponding to "Header Type0 reg group" and then pt_find_reg would return NULL.
This case seems to be handled correctly and bring to the same results in both pt_pci_write_config and pt_pci_read_config.
In any case PCI_INTEL_OPREGION should be part of "Header Type0 reg group" only it if really is part of this group otherwise it should be in its own separate group.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 118 lines · Stefano Stabellini
Quoted 107 lines · Jean Guyader
Quoted 95 lines · Stefano Stabellini
Quoted 94 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]>
Date: ?? Wed Nov 23 07:53:30 2011 +0000?? ?? qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
?? ?? The OpRegion shouldn't be mapped 1:1 because the address in the host ?? ?? can't be used in the guest directly.
?? ?? This patch traps read and write access to the opregion of the Intel ?? ?? GPU config space (offset
0xfc).?? ?? To work correctly this patch needs a change in hvmloader.
?? ?? HVMloader will allocate 2 pages for the OpRegion and write this address ?? ?? on the config space of the Intel GPU. Qemu will trap and map the host ?? ?? OpRegion to the guest. Any write to this offset after that won't have ?? ?? any effect. Any read of this config space offset will return the address ?? ?? in the guest.
hw/pass-through.c +8
-0@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev, ??static int pt_exp_rom_bar_reg_restore(struct pt_dev *ptdev, ?? ?? ??struct pt_reg_tbl *cfg_entry, ?? ?? ??uint32_t real_offset, uint32_t dev_value, uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t dev_value, uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset);??/*
pt_reg_info_tbldeclaration
?? * - only for emulated register (either a part or whole bit).hw/pass-through.c +11
-1@@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { ?? ?? ?? ?? ??.u.dw.write = pt_exp_rom_bar_reg_write, ?? ?? ?? ?? ??.u.dw.restore = pt_exp_rom_bar_reg_restore, ?? ?? ??}, + ?? ??/* Intel IGFX OpRegion reg */ + ?? ??{ + ?? ?? ?? ??.offset ?? ?? = PCI_INTEL_OPREGION, + ?? ?? ?? ??.size ?? ?? ?? = 4, + ?? ?? ?? ??.init_val ?? = 0, + ?? ?? ?? ??.no_wb ?? ?? ??= 1, + ?? ?? ?? ??.u.dw.read ?? = pt_intel_opregion_read, + ?? ?? ?? ??.u.dw.write ??= pt_intel_opregion_write, + ?? ?? ?? ??.u.dw.restore ??= NULL, + ?? ??}, ?? ?? ??{ ?? ?? ?? ?? ??.size = 0, ?? ?? ??},@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { ?? ?? ?? ?? ??.grp_id ?? ?? = 0xFF, ?? ?? ?? ?? ??.grp_type ?? = GRP_TYPE_EMU, ?? ?? ?? ?? ??.grp_size ?? = 0x40, - ?? ?? ?? ??.size_init ??= pt_reg_grp_size_init, + ?? ?? ?? ??.size_init ??= pt_reg_grp_header0_size_init, ?? ?? ?? ?? ??.emu_reg_tbl= pt_emu_reg_header0_tbl, ?? ?? ??},?? ?? ??/* PCI PowerManagement Capability reg group */
hw/pass-through.c +9
-0@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, ?? ?? ??return reg->init_val; ??} +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset) +{ + ?? ??/* + ?? ??** By default we will trap up to 0x40 in the cfg space. + ?? ??** If an intel device is pass through we need to trap 0xfc, + ?? ??** therefore the size should be 0xff. + ?? ??*/ + ?? ??if (igd_passthru)Quoted 9 lines
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 3 lines
hw/pass-through.c +3
-0+ ?? ?? ?? ??return 0xFF; + ?? ??return grp_reg->grp_size; +}Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between
0x40and0xff, that previously were probably passed through?Quoted 1 line
Based on how
pt_find_reg_grpis implemented that doesn't make any difference.actually there is a small change in behaviour: before your patch
pt_find_reg_grpwould return NULL for any cfg register between0x40and0xff. Now ifigd_passthruis setpt_find_reg_grpwould return thereg_grp_entrycorresponding to "Header Type0 reg group" and thenpt_find_regwould return NULL.
This case seems to be handled correctly and bring to the same results in bothpt_pci_write_configandpt_pci_read_config.
Quoted 3 lines
In any case
PCI_INTEL_OPREGIONshould be part of "Header Type0 reg group" only it if really is part of this group otherwise it should be in its own separate group.
The pci pass through groups have been designed to pass through pci capabilities from the device. You can't really create a group for something which isn't a pci capability.
I have noted the change of behavior but that doesn't have any impact on what we will return to the guest so I think it fine.
Jean
Quoted 123 lines · Jean Guyader
Quoted 118 lines · Stefano Stabellini
Quoted 107 lines · Jean Guyader
Quoted 95 lines · Stefano Stabellini
Quoted 94 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]>
Date: ?? Wed Nov 23 07:53:30 2011 +0000?? ?? qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
?? ?? The OpRegion shouldn't be mapped 1:1 because the address in the host ?? ?? can't be used in the guest directly.
?? ?? This patch traps read and write access to the opregion of the Intel ?? ?? GPU config space (offset
0xfc).?? ?? To work correctly this patch needs a change in hvmloader.
?? ?? HVMloader will allocate 2 pages for the OpRegion and write this address ?? ?? on the config space of the Intel GPU. Qemu will trap and map the host ?? ?? OpRegion to the guest. Any write to this offset after that won't have ?? ?? any effect. Any read of this config space offset will return the address ?? ?? in the guest.
hw/pass-through.c +8
-0@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev, ??static int pt_exp_rom_bar_reg_restore(struct pt_dev *ptdev, ?? ?? ??struct pt_reg_tbl *cfg_entry, ?? ?? ??uint32_t real_offset, uint32_t dev_value, uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t dev_value, uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset);??/*
pt_reg_info_tbldeclaration
?? * - only for emulated register (either a part or whole bit).hw/pass-through.c +11
-1@@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { ?? ?? ?? ?? ??.u.dw.write = pt_exp_rom_bar_reg_write, ?? ?? ?? ?? ??.u.dw.restore = pt_exp_rom_bar_reg_restore, ?? ?? ??}, + ?? ??/* Intel IGFX OpRegion reg */ + ?? ??{ + ?? ?? ?? ??.offset ?? ?? = PCI_INTEL_OPREGION, + ?? ?? ?? ??.size ?? ?? ?? = 4, + ?? ?? ?? ??.init_val ?? = 0, + ?? ?? ?? ??.no_wb ?? ?? ??= 1, + ?? ?? ?? ??.u.dw.read ?? = pt_intel_opregion_read, + ?? ?? ?? ??.u.dw.write ??= pt_intel_opregion_write, + ?? ?? ?? ??.u.dw.restore ??= NULL, + ?? ??}, ?? ?? ??{ ?? ?? ?? ?? ??.size = 0, ?? ?? ??},@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { ?? ?? ?? ?? ??.grp_id ?? ?? = 0xFF, ?? ?? ?? ?? ??.grp_type ?? = GRP_TYPE_EMU, ?? ?? ?? ?? ??.grp_size ?? = 0x40, - ?? ?? ?? ??.size_init ??= pt_reg_grp_size_init, + ?? ?? ?? ??.size_init ??= pt_reg_grp_header0_size_init, ?? ?? ?? ?? ??.emu_reg_tbl= pt_emu_reg_header0_tbl, ?? ?? ??},?? ?? ??/* PCI PowerManagement Capability reg group */
hw/pass-through.c +9
-0@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, ?? ?? ??return reg->init_val; ??} +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset) +{ + ?? ??/* + ?? ??** By default we will trap up to 0x40 in the cfg space. + ?? ??** If an intel device is pass through we need to trap 0xfc, + ?? ??** therefore the size should be 0xff. + ?? ??*/ + ?? ??if (igd_passthru)Quoted 9 lines
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 3 lines
hw/pass-through.c +3
-0+ ?? ?? ?? ??return 0xFF; + ?? ??return grp_reg->grp_size; +}Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between
0x40and0xff, that previously were probably passed through?Quoted 1 line
Based on how
pt_find_reg_grpis implemented that doesn't make any difference.actually there is a small change in behaviour: before your patch
pt_find_reg_grpwould return NULL for any cfg register between0x40and0xff. Now ifigd_passthruis setpt_find_reg_grpwould return thereg_grp_entrycorresponding to "Header Type0 reg group" and thenpt_find_regwould return NULL.
This case seems to be handled correctly and bring to the same results in bothpt_pci_write_configandpt_pci_read_config.Quoted 3 lines
In any case
PCI_INTEL_OPREGIONshould be part of "Header Type0 reg group" only it if really is part of this group otherwise it should be in its own separate group.
Quoted 6 lines
The pci pass through groups have been designed to pass through pci capabilities from the device. You can't really create a group for something which isn't a pci capability.
I have noted the change of behavior but that doesn't have any impact on what we will return to the guest so I think it fine.
in that case, ack
Quoted 124 lines · Stefano Stabellini
Quoted 123 lines · Jean Guyader
Quoted 121 lines · Stefano Stabellini
Quoted 107 lines · Jean Guyader
Quoted 95 lines · Stefano Stabellini
Quoted 94 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]>
Date: ?? Wed Nov 23 07:53:30 2011 +0000?? ?? qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
?? ?? The OpRegion shouldn't be mapped 1:1 because the address in the host ?? ?? can't be used in the guest directly.
?? ?? This patch traps read and write access to the opregion of the Intel ?? ?? GPU config space (offset
0xfc).?? ?? To work correctly this patch needs a change in hvmloader.
?? ?? HVMloader will allocate 2 pages for the OpRegion and write this address ?? ?? on the config space of the Intel GPU. Qemu will trap and map the host ?? ?? OpRegion to the guest. Any write to this offset after that won't have ?? ?? any effect. Any read of this config space offset will return the address ?? ?? in the guest.
hw/pass-through.c +8
-0@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev, ??static int pt_exp_rom_bar_reg_restore(struct pt_dev *ptdev, ?? ?? ??struct pt_reg_tbl *cfg_entry, ?? ?? ??uint32_t real_offset, uint32_t dev_value, uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t dev_value, uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset);??/*
pt_reg_info_tbldeclaration
?? * - only for emulated register (either a part or whole bit).hw/pass-through.c +11
-1@@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { ?? ?? ?? ?? ??.u.dw.write = pt_exp_rom_bar_reg_write, ?? ?? ?? ?? ??.u.dw.restore = pt_exp_rom_bar_reg_restore, ?? ?? ??}, + ?? ??/* Intel IGFX OpRegion reg */ + ?? ??{ + ?? ?? ?? ??.offset ?? ?? = PCI_INTEL_OPREGION, + ?? ?? ?? ??.size ?? ?? ?? = 4, + ?? ?? ?? ??.init_val ?? = 0, + ?? ?? ?? ??.no_wb ?? ?? ??= 1, + ?? ?? ?? ??.u.dw.read ?? = pt_intel_opregion_read, + ?? ?? ?? ??.u.dw.write ??= pt_intel_opregion_write, + ?? ?? ?? ??.u.dw.restore ??= NULL, + ?? ??}, ?? ?? ??{ ?? ?? ?? ?? ??.size = 0, ?? ?? ??},@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { ?? ?? ?? ?? ??.grp_id ?? ?? = 0xFF, ?? ?? ?? ?? ??.grp_type ?? = GRP_TYPE_EMU, ?? ?? ?? ?? ??.grp_size ?? = 0x40, - ?? ?? ?? ??.size_init ??= pt_reg_grp_size_init, + ?? ?? ?? ??.size_init ??= pt_reg_grp_header0_size_init, ?? ?? ?? ?? ??.emu_reg_tbl= pt_emu_reg_header0_tbl, ?? ?? ??},?? ?? ??/* PCI PowerManagement Capability reg group */
hw/pass-through.c +9
-0@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, ?? ?? ??return reg->init_val; ??} +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset) +{ + ?? ??/* + ?? ??** By default we will trap up to 0x40 in the cfg space. + ?? ??** If an intel device is pass through we need to trap 0xfc, + ?? ??** therefore the size should be 0xff. + ?? ??*/ + ?? ??if (igd_passthru)Quoted 9 lines
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 3 lines
hw/pass-through.c +3
-0+ ?? ?? ?? ??return 0xFF; + ?? ??return grp_reg->grp_size; +}Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between
0x40and0xff, that previously were probably passed through?Quoted 1 line
Based on how
pt_find_reg_grpis implemented that doesn't make any difference.actually there is a small change in behaviour: before your patch
pt_find_reg_grpwould return NULL for any cfg register between0x40and0xff. Now ifigd_passthruis setpt_find_reg_grpwould return thereg_grp_entrycorresponding to "Header Type0 reg group" and thenpt_find_regwould return NULL.
This case seems to be handled correctly and bring to the same results in bothpt_pci_write_configandpt_pci_read_config.In any case
PCI_INTEL_OPREGIONshould be part of "Header Type0 reg group" only it if really is part of this group otherwise it should be in its own separate group.
Quoted 8 lines
Quoted 6 lines
The pci pass through groups have been designed to pass through pci capabilities from the device. You can't really create a group for something which isn't a pci capability.
I have noted the change of behavior but that doesn't have any impact on what we will return to the guest so I think it fine.
in that case, ack
Ian,
Could you apply this patch please?
Jean
Quoted 130 lines · Jean Guyader
Quoted 128 lines · Stefano Stabellini
Quoted 127 lines · Jean Guyader
Quoted 118 lines · Stefano Stabellini
Quoted 107 lines · Jean Guyader
Quoted 95 lines · Stefano Stabellini
Quoted 94 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]>
Date: ?? Wed Nov 23 07:53:30 2011 +0000?? ?? qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
?? ?? The OpRegion shouldn't be mapped 1:1 because the address in the host ?? ?? can't be used in the guest directly.
?? ?? This patch traps read and write access to the opregion of the Intel ?? ?? GPU config space (offset
0xfc).?? ?? To work correctly this patch needs a change in hvmloader.
?? ?? HVMloader will allocate 2 pages for the OpRegion and write this address ?? ?? on the config space of the Intel GPU. Qemu will trap and map the host ?? ?? OpRegion to the guest. Any write to this offset after that won't have ?? ?? any effect. Any read of this config space offset will return the address ?? ?? in the guest.
hw/pass-through.c +8
-0@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev, ??static int pt_exp_rom_bar_reg_restore(struct pt_dev *ptdev, ?? ?? ??struct pt_reg_tbl *cfg_entry, ?? ?? ??uint32_t real_offset, uint32_t dev_value, uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t dev_value, uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset);??/*
pt_reg_info_tbldeclaration
?? * - only for emulated register (either a part or whole bit).hw/pass-through.c +11
-1@@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { ?? ?? ?? ?? ??.u.dw.write = pt_exp_rom_bar_reg_write, ?? ?? ?? ?? ??.u.dw.restore = pt_exp_rom_bar_reg_restore, ?? ?? ??}, + ?? ??/* Intel IGFX OpRegion reg */ + ?? ??{ + ?? ?? ?? ??.offset ?? ?? = PCI_INTEL_OPREGION, + ?? ?? ?? ??.size ?? ?? ?? = 4, + ?? ?? ?? ??.init_val ?? = 0, + ?? ?? ?? ??.no_wb ?? ?? ??= 1, + ?? ?? ?? ??.u.dw.read ?? = pt_intel_opregion_read, + ?? ?? ?? ??.u.dw.write ??= pt_intel_opregion_write, + ?? ?? ?? ??.u.dw.restore ??= NULL, + ?? ??}, ?? ?? ??{ ?? ?? ?? ?? ??.size = 0, ?? ?? ??},@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { ?? ?? ?? ?? ??.grp_id ?? ?? = 0xFF, ?? ?? ?? ?? ??.grp_type ?? = GRP_TYPE_EMU, ?? ?? ?? ?? ??.grp_size ?? = 0x40, - ?? ?? ?? ??.size_init ??= pt_reg_grp_size_init, + ?? ?? ?? ??.size_init ??= pt_reg_grp_header0_size_init, ?? ?? ?? ?? ??.emu_reg_tbl= pt_emu_reg_header0_tbl, ?? ?? ??},?? ?? ??/* PCI PowerManagement Capability reg group */
hw/pass-through.c +9
-0@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, ?? ?? ??return reg->init_val; ??} +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset) +{ + ?? ??/* + ?? ??** By default we will trap up to 0x40 in the cfg space. + ?? ??** If an intel device is pass through we need to trap 0xfc, + ?? ??** therefore the size should be 0xff. + ?? ??*/ + ?? ??if (igd_passthru)Quoted 9 lines
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 3 lines
hw/pass-through.c +3
-0+ ?? ?? ?? ??return 0xFF; + ?? ??return grp_reg->grp_size; +}Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between
0x40and0xff, that previously were probably passed through?Quoted 1 line
Based on how
pt_find_reg_grpis implemented that doesn't make any difference.actually there is a small change in behaviour: before your patch
pt_find_reg_grpwould return NULL for any cfg register between0x40and0xff. Now ifigd_passthruis setpt_find_reg_grpwould return thereg_grp_entrycorresponding to "Header Type0 reg group" and thenpt_find_regwould return NULL.
This case seems to be handled correctly and bring to the same results in bothpt_pci_write_configandpt_pci_read_config.Quoted 3 lines
In any case
PCI_INTEL_OPREGIONshould be part of "Header Type0 reg group" only it if really is part of this group otherwise it should be in its own separate group.The pci pass through groups have been designed to pass through pci capabilities from the device. You can't really create a group for something which isn't a pci capability.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
I have noted the change of behavior but that doesn't have any impact on what we will return to the guest so I think it fine.
in that case, ack
Ian,
Could you apply this patch please?
Hi Ian,
I was going through my email and it seems that this patch didn't make it into qemu-xen-unstable.
Thanks,
Jean
Quoted 139 lines · Jean Guyader
Quoted 124 lines · Stefano Stabellini
Quoted 123 lines · Jean Guyader
Quoted 121 lines · Stefano Stabellini
Quoted 107 lines · Jean Guyader
Quoted 95 lines · Stefano Stabellini
Quoted 94 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]>
Date: ?? Wed Nov 23 07:53:30 2011 +0000?? ?? qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
?? ?? The OpRegion shouldn't be mapped 1:1 because the address in the host ?? ?? can't be used in the guest directly.
?? ?? This patch traps read and write access to the opregion of the Intel ?? ?? GPU config space (offset
0xfc).?? ?? To work correctly this patch needs a change in hvmloader.
?? ?? HVMloader will allocate 2 pages for the OpRegion and write this address ?? ?? on the config space of the Intel GPU. Qemu will trap and map the host ?? ?? OpRegion to the guest. Any write to this offset after that won't have ?? ?? any effect. Any read of this config space offset will return the address ?? ?? in the guest.
hw/pass-through.c +8
-0@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev, ??static int pt_exp_rom_bar_reg_restore(struct pt_dev *ptdev, ?? ?? ??struct pt_reg_tbl *cfg_entry, ?? ?? ??uint32_t real_offset, uint32_t dev_value, uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t dev_value, uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset);??/*
pt_reg_info_tbldeclaration
?? * - only for emulated register (either a part or whole bit).hw/pass-through.c +11
-1@@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { ?? ?? ?? ?? ??.u.dw.write = pt_exp_rom_bar_reg_write, ?? ?? ?? ?? ??.u.dw.restore = pt_exp_rom_bar_reg_restore, ?? ?? ??}, + ?? ??/* Intel IGFX OpRegion reg */ + ?? ??{ + ?? ?? ?? ??.offset ?? ?? = PCI_INTEL_OPREGION, + ?? ?? ?? ??.size ?? ?? ?? = 4, + ?? ?? ?? ??.init_val ?? = 0, + ?? ?? ?? ??.no_wb ?? ?? ??= 1, + ?? ?? ?? ??.u.dw.read ?? = pt_intel_opregion_read, + ?? ?? ?? ??.u.dw.write ??= pt_intel_opregion_write, + ?? ?? ?? ??.u.dw.restore ??= NULL, + ?? ??}, ?? ?? ??{ ?? ?? ?? ?? ??.size = 0, ?? ?? ??},@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { ?? ?? ?? ?? ??.grp_id ?? ?? = 0xFF, ?? ?? ?? ?? ??.grp_type ?? = GRP_TYPE_EMU, ?? ?? ?? ?? ??.grp_size ?? = 0x40, - ?? ?? ?? ??.size_init ??= pt_reg_grp_size_init, + ?? ?? ?? ??.size_init ??= pt_reg_grp_header0_size_init, ?? ?? ?? ?? ??.emu_reg_tbl= pt_emu_reg_header0_tbl, ?? ?? ??},?? ?? ??/* PCI PowerManagement Capability reg group */
hw/pass-through.c +9
-0@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, ?? ?? ??return reg->init_val; ??} +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset) +{ + ?? ??/* + ?? ??** By default we will trap up to 0x40 in the cfg space. + ?? ??** If an intel device is pass through we need to trap 0xfc, + ?? ??** therefore the size should be 0xff. + ?? ??*/ + ?? ??if (igd_passthru)Quoted 9 lines
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 3 lines
hw/pass-through.c +3
-0+ ?? ?? ?? ??return 0xFF; + ?? ??return grp_reg->grp_size; +}Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between
0x40and0xff, that previously were probably passed through?Quoted 1 line
Based on how
pt_find_reg_grpis implemented that doesn't make any difference.actually there is a small change in behaviour: before your patch
pt_find_reg_grpwould return NULL for any cfg register between0x40and0xff. Now ifigd_passthruis setpt_find_reg_grpwould return thereg_grp_entrycorresponding to "Header Type0 reg group" and thenpt_find_regwould return NULL.
This case seems to be handled correctly and bring to the same results in bothpt_pci_write_configandpt_pci_read_config.In any case
PCI_INTEL_OPREGIONshould be part of "Header Type0 reg group" only it if really is part of this group otherwise it should be in its own separate group.Quoted 8 lines
Quoted 6 lines
The pci pass through groups have been designed to pass through pci capabilities from the device. You can't really create a group for something which isn't a pci capability.
I have noted the change of behavior but that doesn't have any impact on what we will return to the guest so I think it fine.
in that case, ack
Ian,
Could you apply this patch please?
Jean
Quoted 130 lines · Jean Guyader
Quoted 128 lines · Stefano Stabellini
Quoted 127 lines · Jean Guyader
Quoted 118 lines · Stefano Stabellini
Quoted 107 lines · Jean Guyader
Quoted 95 lines · Stefano Stabellini
Quoted 94 lines · Jean Guyader
Quoted 8 lines · Jean Guyader
The OpRegion shouldn't be mapped 1:1 because the address in the host can't be used in the guest directly.
This patch traps read and write access to the opregion of the Intel GPU config space (offset
0xfc).To work correctly this patch needs a change in hvmloader.
Quoted 7 lines
HVMloader will allocate 2 pages for the OpRegion and write this address on the config space of the Intel GPU. Qemu will trap and map the host OpRegion to the guest. Any write to this offset after that won't have any effect. Any read of this config space offset will return the address in the guest.
Signed-off-by Jean Guyader <[email protected]>commit
a6036bee23bb338e6cf48e9f0d75ff0845f8cfe3
Author: Jean Guyader <[email protected]>
Date: ?? Wed Nov 23 07:53:30 2011 +0000?? ?? qemu-xen: Intel GPU passthrough, fix OpRegion mapping.
?? ?? The OpRegion shouldn't be mapped 1:1 because the address in the host ?? ?? can't be used in the guest directly.
?? ?? This patch traps read and write access to the opregion of the Intel ?? ?? GPU config space (offset
0xfc).?? ?? To work correctly this patch needs a change in hvmloader.
?? ?? HVMloader will allocate 2 pages for the OpRegion and write this address ?? ?? on the config space of the Intel GPU. Qemu will trap and map the host ?? ?? OpRegion to the guest. Any write to this offset after that won't have ?? ?? any effect. Any read of this config space offset will return the address ?? ?? in the guest.
hw/pass-through.c +8
-0@@ -238,6 +238,14 @@ static int pt_bar_reg_restore(struct pt_dev *ptdev, ??static int pt_exp_rom_bar_reg_restore(struct pt_dev *ptdev, ?? ?? ??struct pt_reg_tbl *cfg_entry, ?? ?? ??uint32_t real_offset, uint32_t dev_value, uint32_t *value); +static int pt_intel_opregion_read (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t valid_mask); +static int pt_intel_opregion_write (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_tbl *cfg_entry, + ?? ?? ?? ??uint32_t *value, uint32_t dev_value, uint32_t valid_mask); +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset);??/*
pt_reg_info_tbldeclaration
?? * - only for emulated register (either a part or whole bit).hw/pass-through.c +11
-1@@ -444,6 +452,16 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { ?? ?? ?? ?? ??.u.dw.write = pt_exp_rom_bar_reg_write, ?? ?? ?? ?? ??.u.dw.restore = pt_exp_rom_bar_reg_restore, ?? ?? ??}, + ?? ??/* Intel IGFX OpRegion reg */ + ?? ??{ + ?? ?? ?? ??.offset ?? ?? = PCI_INTEL_OPREGION, + ?? ?? ?? ??.size ?? ?? ?? = 4, + ?? ?? ?? ??.init_val ?? = 0, + ?? ?? ?? ??.no_wb ?? ?? ??= 1, + ?? ?? ?? ??.u.dw.read ?? = pt_intel_opregion_read, + ?? ?? ?? ??.u.dw.write ??= pt_intel_opregion_write, + ?? ?? ?? ??.u.dw.restore ??= NULL, + ?? ??}, ?? ?? ??{ ?? ?? ?? ?? ??.size = 0, ?? ?? ??},@@ -737,7 +755,7 @@ static const struct pt_reg_grp_info_tbl pt_emu_reg_grp_tbl[] = { ?? ?? ?? ?? ??.grp_id ?? ?? = 0xFF, ?? ?? ?? ?? ??.grp_type ?? = GRP_TYPE_EMU, ?? ?? ?? ?? ??.grp_size ?? = 0x40, - ?? ?? ?? ??.size_init ??= pt_reg_grp_size_init, + ?? ?? ?? ??.size_init ??= pt_reg_grp_header0_size_init, ?? ?? ?? ?? ??.emu_reg_tbl= pt_emu_reg_header0_tbl, ?? ?? ??},?? ?? ??/* PCI PowerManagement Capability reg group */
hw/pass-through.c +9
-0@@ -3006,6 +3024,19 @@ static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, ?? ?? ??return reg->init_val; ??} +static uint8_t pt_reg_grp_header0_size_init (struct pt_dev *ptdev, + ?? ?? ?? ??struct pt_reg_grp_info_tbl *grp_reg, uint32_t base_offset) +{ + ?? ??/* + ?? ??** By default we will trap up to 0x40 in the cfg space. + ?? ??** If an intel device is pass through we need to trap 0xfc, + ?? ??** therefore the size should be 0xff. + ?? ??*/ + ?? ??if (igd_passthru)Quoted 9 lines
hw/pass-through.c static uint32_t pt_msixctrl_reg_init(struct pt_dev *ptdev, · line 3038
Quoted 3 lines
hw/pass-through.c +3
-0+ ?? ?? ?? ??return 0xFF; + ?? ??return grp_reg->grp_size; +}Apart from the trivial code style error in the comment above, is this going to have the unintended side effect of initializing as 0 all the emulated registers between
0x40and0xff, that previously were probably passed through?Quoted 1 line
Based on how
pt_find_reg_grpis implemented that doesn't make any difference.actually there is a small change in behaviour: before your patch
pt_find_reg_grpwould return NULL for any cfg register between0x40and0xff. Now ifigd_passthruis setpt_find_reg_grpwould return thereg_grp_entrycorresponding to "Header Type0 reg group" and thenpt_find_regwould return NULL.
This case seems to be handled correctly and bring to the same results in bothpt_pci_write_configandpt_pci_read_config.Quoted 3 lines
In any case
PCI_INTEL_OPREGIONshould be part of "Header Type0 reg group" only it if really is part of this group otherwise it should be in its own separate group.The pci pass through groups have been designed to pass through pci capabilities from the device. You can't really create a group for something which isn't a pci capability.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
I have noted the change of behavior but that doesn't have any impact on what we will return to the guest so I think it fine.
in that case, ack
Ian,
Could you apply this patch please?
Hi Ian,
I was going through my email and it seems that this patch didn't make it into qemu-xen-unstable.
Thanks,
Jean