Skip to content

Commit 66f04e8

Browse files
authored
CP-52131/CP-53474: Reorder operations during pci_add (#6426)
Reorder the operations in _pci_add: 1) So that Xen can verify calls to grant ioport and iomem permissions, reorder the calls so that the device is assigned to the domain before granting permissions for the resources. When Secure Boot is enabled, Xen will enforce that ioport/iomem permissions can be granted to a domain only when the corresponding device is assigned to that domain. 2) Add the device to QEMU after assigning to the domain. Rather than accessing the PCI config space through dom0 sysfs which is blocked when Secure Boot is enabled, QEMU in XS9 has been updated to use a hypercall to access the PCI config space of a device assigned to a domain. Therefore, add the device to QEMU after assigning it to the domain rather than before so that the config space accesses it performs during the QMP call succeed.
2 parents 48ae1a3 + 451bb35 commit 66f04e8

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

ocaml/xenopsd/xc/device.ml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,30 +1215,6 @@ module PCI = struct
12151215
|> String.trim
12161216
|> int_of_string
12171217
in
1218-
if hvm && qmp_add then
1219-
if Service.Qemu.is_running ~xs domid then
1220-
let id =
1221-
Printf.sprintf "pci-pt-%02x_%02x.%01x" host.bus host.dev host.fn
1222-
in
1223-
let _qmp_result =
1224-
qmp_send_cmd domid
1225-
(Qmp.Device_add
1226-
{
1227-
driver= "xen-pci-passthrough"
1228-
; device=
1229-
Qmp.Device.PCI
1230-
{
1231-
id
1232-
; devfn
1233-
; hostaddr= string_of_address host
1234-
; permissive= false
1235-
}
1236-
}
1237-
)
1238-
in
1239-
()
1240-
else
1241-
raise (Domain_not_running (host, domid)) ;
12421218
let addresses =
12431219
sysfs_pci_dev ^ string_of_address host ^ "/resource"
12441220
|> Unixext.string_of_file
@@ -1264,15 +1240,39 @@ module PCI = struct
12641240
in
12651241
Xenctrl.domain_iomem_permission xc domid scan_start scan_size true
12661242
in
1267-
List.iteri apply_io_permission addresses ;
12681243
let xcext = Xenctrlext.get_handle () in
1244+
ignore (quarantine host) ;
1245+
Xenctrlext.assign_device xcext domid (encode_bdf host)
1246+
_xen_domctl_dev_rdm_relaxed ;
1247+
List.iteri apply_io_permission addresses ;
12691248
( if irq > 0 then
12701249
Xenctrlext.physdev_map_pirq xcext domid irq |> fun x ->
12711250
Xenctrl.domain_irq_permission xc domid x true
12721251
) ;
1273-
ignore (quarantine host) ;
1274-
Xenctrlext.assign_device xcext domid (encode_bdf host)
1275-
_xen_domctl_dev_rdm_relaxed
1252+
if hvm && qmp_add then
1253+
if Service.Qemu.is_running ~xs domid then
1254+
let id =
1255+
Printf.sprintf "pci-pt-%02x_%02x.%01x" host.bus host.dev host.fn
1256+
in
1257+
let _qmp_result =
1258+
qmp_send_cmd domid
1259+
(Qmp.Device_add
1260+
{
1261+
driver= "xen-pci-passthrough"
1262+
; device=
1263+
Qmp.Device.PCI
1264+
{
1265+
id
1266+
; devfn
1267+
; hostaddr= string_of_address host
1268+
; permissive= false
1269+
}
1270+
}
1271+
)
1272+
in
1273+
()
1274+
else
1275+
raise (Domain_not_running (host, domid))
12761276

12771277
let add ~xc ~xs ~hvm pcidevs domid =
12781278
let host_addr {host; guest= _; _} = host in

0 commit comments

Comments
 (0)