Skip to content

Commit b66e46c

Browse files
robhoesBob Ball
authored andcommitted
Get Nvidia VGPU_types from XML file (xapi-project#3238)
* VGPU_types: switch to file reader in functor The old functor mandated a line-by-line read function for the whitelist file, which is a little inflexible. Changing this allows us to create new module for NVidia, based on this functor, that takes an XML file as input. Signed-off-by: Rob Hoes <[email protected]> * VGPU_types: add stub Vendor_nvidia module Signed-off-by: Rob Hoes <[email protected]> * VGPU_types: reuse PCI access Signed-off-by: Rob Hoes <[email protected]> * VGPU_types: Vendor_nvidia: fill in read_writelist Signed-off-by: Rob Hoes <[email protected]> * VGPU_types: Vendor_nvidia tests Signed-off-by: Rob Hoes <[email protected]> * VGPU_types: use new Nvidia module with fallback to the old Signed-off-by: Rob Hoes <[email protected]>
1 parent 80a59e5 commit b66e46c

File tree

4 files changed

+389
-47
lines changed

4 files changed

+389
-47
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE vgpu SYSTEM "http://www.nvidia.com/dtd/vgpuConfig.dtd">
3+
4+
<vgpuconfig>
5+
<version>1.0</version>
6+
<globalSettings>
7+
<homogeneousVgpus>ignore me</homogeneousVgpus>
8+
<pluginSoName>ignore me as well</pluginSoName>
9+
</globalSettings>
10+
<vgpuType id="11" name="TYPE FOO1" class="NVS">
11+
<devId vendorId="0x10de" deviceId="0x1111" subsystemVendorId="0x10de" subsystemId="0x2222"></devId>
12+
<framebuffer>0x10000000</framebuffer>
13+
<numHeads>2</numHeads>
14+
<display width="1920" height="1200"></display>
15+
<moreData>0x400000</moreData>
16+
<evenMoreData>0x6000000</evenMoreData>
17+
</vgpuType>
18+
<vgpuType id="20" name="TYPE FOO2" class="NVS">
19+
<devId vendorId="0x10de" deviceId="0x1112" subsystemVendorId="0x10de" subsystemId="0x2223"></devId>
20+
<framebuffer>0x20000000</framebuffer>
21+
<numHeads>4</numHeads>
22+
<display width="2400" height="1600"></display>
23+
<moreData>0x400000</moreData>
24+
<evenMoreData>0x6000000</evenMoreData>
25+
</vgpuType>
26+
<vgpuType id="21" name="TYPE FOO3" class="NVS">
27+
<devId vendorId="0x10de" deviceId="0x1111" subsystemVendorId="0x10de" subsystemId="0x2222"></devId>
28+
<framebuffer>0x10000000</framebuffer>
29+
<numHeads>2</numHeads>
30+
<display width="1920" height="1200"></display>
31+
<moreData>0x400000</moreData>
32+
<evenMoreData>0x6000000</evenMoreData>
33+
</vgpuType>
34+
<pgpu>
35+
<devId vendorId="0x10de" deviceId="0x3333" subsystemVendorId="0x10de" subsystemId="0x4444"></devId>
36+
<supportedVgpu vgpuId="11">
37+
<maxVgpus>8</maxVgpus>
38+
<digest type="signature">ignore me</digest>
39+
</supportedVgpu>
40+
</pgpu>
41+
<pgpu>
42+
<devId vendorId="0x10de" deviceId="0x3334" subsystemVendorId="0x10de" subsystemId="0x0"></devId>
43+
<supportedVgpu vgpuId="11">
44+
<maxVgpus>8</maxVgpus>
45+
<digest type="signature">ignore me</digest>
46+
</supportedVgpu>
47+
</pgpu>
48+
<pgpu>
49+
<devId vendorId="0x10de" deviceId="0x3335" subsystemVendorId="0x10de" subsystemId="0x4445"></devId>
50+
<supportedVgpu vgpuId="20">
51+
<maxVgpus>8</maxVgpus>
52+
<digest type="signature">ignore me</digest>
53+
</supportedVgpu>
54+
<supportedVgpu vgpuId="21">
55+
<maxVgpus>16</maxVgpus>
56+
<digest type="signature">ignore me</digest>
57+
</supportedVgpu>
58+
</pgpu>
59+
</vgpuconfig>

ocaml/xapi/test_vgpu_type.ml

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let mib x = List.fold_left Int64.mul x [1024L; 1024L]
2323
module NvidiaTest = struct
2424
let string_of_vgpu_conf conf =
2525
let open Identifier in
26-
let open Nvidia in
26+
let open Nvidia_old in
2727
Printf.sprintf "%04x %s %04x %04x %Ld"
2828
conf.identifier.pdev_id
2929
(match conf.identifier.psubdev_id with
@@ -39,17 +39,17 @@ module NvidiaTest = struct
3939
module OfConfFile = Generic.Make(struct
4040
module Io = struct
4141
type input_t = string
42-
type output_t = Nvidia.vgpu_conf
42+
type output_t = Nvidia_old.vgpu_conf
4343

4444
let string_of_input_t x = x
4545
let string_of_output_t = string_of_vgpu_conf
4646
end
4747

48-
let transform = Nvidia.of_conf_file
48+
let transform = Nvidia_old.of_conf_file
4949

5050
let tests = [
5151
"test_data/test_vgpu_subdevid.conf",
52-
Nvidia.({
52+
Nvidia_old.({
5353
identifier = Identifier.({
5454
pdev_id = 0x3333;
5555
psubdev_id = Some 0x4444;
@@ -64,7 +64,7 @@ module NvidiaTest = struct
6464
file_path = "test_data/test_vgpu_subdevid.conf";
6565
});
6666
"test_data/test_vgpu_nosubdevid.conf",
67-
Nvidia.({
67+
Nvidia_old.({
6868
identifier = Identifier.({
6969
pdev_id = 0x3333;
7070
psubdev_id = None;
@@ -81,13 +81,117 @@ module NvidiaTest = struct
8181
]
8282
end)
8383

84+
let string_of_vgpu_conf conf =
85+
let open Identifier in
86+
let open Vendor_nvidia in
87+
Printf.sprintf "%04x %s %04x %04x %Ld %Ld %Ld %Ldx%Ld"
88+
conf.identifier.pdev_id
89+
(match conf.identifier.psubdev_id with
90+
| Some id -> Printf.sprintf "Some %04x" id
91+
| None -> "None")
92+
conf.identifier.vdev_id
93+
conf.identifier.vsubdev_id
94+
conf.framebufferlength
95+
conf.num_heads
96+
conf.max_instance
97+
conf.max_x
98+
conf.max_y
99+
100+
module ReadWhitelist = Generic.Make(struct
101+
module Io = struct
102+
type input_t = (string * int) (* whitelist * device_id *)
103+
type output_t = Vendor_nvidia.vgpu_conf list
104+
105+
let string_of_input_t (whitelist, device_id) =
106+
Printf.sprintf "(%s, %04x)" whitelist device_id
107+
let string_of_output_t =
108+
Test_printers.list string_of_vgpu_conf
109+
end
110+
111+
let transform (whitelist, device_id) =
112+
Vendor_nvidia.read_whitelist ~whitelist ~device_id
113+
114+
let tests = [
115+
("test_data/this-file-is-not-there.xml", 0x3333),
116+
[];
117+
("test_data/nvidia-whitelist.xml", 0x4444),
118+
[];
119+
("test_data/nvidia-whitelist.xml", 0x3333),
120+
[
121+
Vendor_nvidia.({
122+
identifier = Identifier.({
123+
pdev_id = 0x3333;
124+
psubdev_id = Some 0x4444;
125+
vdev_id = 0x1111;
126+
vsubdev_id = 0x2222;
127+
});
128+
framebufferlength = 0x10000000L;
129+
num_heads = 2L;
130+
max_instance = 8L;
131+
max_x = 1920L;
132+
max_y = 1200L;
133+
file_path = "test_data/nvidia-whitelist.xml";
134+
})
135+
];
136+
("test_data/nvidia-whitelist.xml", 0x3334),
137+
[
138+
Vendor_nvidia.({
139+
identifier = Identifier.({
140+
pdev_id = 0x3334;
141+
psubdev_id = None;
142+
vdev_id = 0x1111;
143+
vsubdev_id = 0x2222;
144+
});
145+
framebufferlength = 0x10000000L;
146+
num_heads = 2L;
147+
max_instance = 8L;
148+
max_x = 1920L;
149+
max_y = 1200L;
150+
file_path = "test_data/nvidia-whitelist.xml";
151+
})
152+
];
153+
("test_data/nvidia-whitelist.xml", 0x3335),
154+
[
155+
Vendor_nvidia.({
156+
identifier = Identifier.({
157+
pdev_id = 0x3335;
158+
psubdev_id = Some 0x4445;
159+
vdev_id = 0x1112;
160+
vsubdev_id = 0x2223;
161+
});
162+
framebufferlength = 0x20000000L;
163+
num_heads = 4L;
164+
max_instance = 8L;
165+
max_x = 2400L;
166+
max_y = 1600L;
167+
file_path = "test_data/nvidia-whitelist.xml";
168+
});
169+
Vendor_nvidia.({
170+
identifier = Identifier.({
171+
pdev_id = 0x3335;
172+
psubdev_id = Some 0x4445;
173+
vdev_id = 0x1111;
174+
vsubdev_id = 0x2222;
175+
});
176+
framebufferlength = 0x10000000L;
177+
num_heads = 2L;
178+
max_instance = 16L;
179+
max_x = 1920L;
180+
max_y = 1200L;
181+
file_path = "test_data/nvidia-whitelist.xml";
182+
})
183+
];
184+
185+
]
186+
end)
187+
84188
(* This test generates a lot of print --- set skip to false to enable *)
85189
let skip = true
86190

87191
let print_nv_types () =
88192
skip_if skip "Generates print...";
89193
try
90-
let open Nvidia in
194+
let open Nvidia_old in
91195
if (Sys.file_exists conf_dir
92196
&& Sys.is_directory conf_dir) then
93197
begin
@@ -176,7 +280,7 @@ module IntelTest = struct
176280
end
177281

178282
let transform (whitelist, device_id) =
179-
Intel.read_whitelist ~whitelist ~device_id |> List.rev
283+
Vendor_intel.read_whitelist ~whitelist ~device_id |> List.rev
180284

181285
let tests = [
182286
("test_data/gvt-g-whitelist-empty", 0x1234), [];
@@ -299,7 +403,7 @@ module AMDTest = struct
299403
end
300404

301405
let transform (whitelist, device_id) =
302-
AMD.read_whitelist ~whitelist ~device_id |> List.rev
406+
Vendor_amd.read_whitelist ~whitelist ~device_id |> List.rev
303407

304408
let tests = [
305409
("test_data/mxgpu-whitelist-empty", 0x1234), [];
@@ -442,6 +546,7 @@ let test =
442546
"test_vgpu_type" >:::
443547
[
444548
"nvidia_test_of_conf_file" >::: NvidiaTest.OfConfFile.tests;
549+
"nvidia_read_whitelist" >::: NvidiaTest.ReadWhitelist.tests;
445550
"nvidia_print_nv_types" >:: NvidiaTest.print_nv_types;
446551
"intel_read_whitelist_line" >::: IntelTest.ReadWhitelistLine.tests;
447552
"intel_read_whitelist" >::: IntelTest.ReadWhitelist.tests;

ocaml/xapi/xapi_globs.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ let nbd_firewall_config_script = ref "/opt/xensource/libexec/nbd-firewall-config
817817

818818
let disable_logging_for= ref []
819819

820+
let nvidia_whitelist = ref "/usr/share/nvidia/vgpu/vgpuConfig.xml"
821+
820822
let igd_passthru_vendor_whitelist = ref []
821823

822824
let gvt_g_whitelist = ref "/etc/gvt-g-whitelist"
@@ -983,6 +985,9 @@ let other_options = [
983985
"xenopsd-default", Arg.Set_string default_xenopsd,
984986
(fun () -> !default_xenopsd), "default xenopsd to use";
985987

988+
"nvidia-whitelist", Arg.Set_string nvidia_whitelist,
989+
(fun () -> !nvidia_whitelist), "path to the NVidia vGPU whitelist file";
990+
986991
gen_list_option "igd-passthru-vendor-whitelist"
987992
"list of PCI vendor IDs for integrated graphics passthrough (space-separated)"
988993
(fun s ->

0 commit comments

Comments
 (0)