Skip to content

Commit c5c27fd

Browse files
mserilindig
authored andcommitted
CA-236863: division by 0 in VGPU-g detection (xapi-project#281)
* CA-236863: division by 0 in VGPU-g detection If the Intel GPU BAR size is too small, the number of VGPUs per PGPU could become zero and give rise to a division by zero. The suggested fix adds an itermediate check to the VGPU generation code to prevent this from happening. Signed-off-by: Marcello Seri <[email protected]> * CA-236863: add warning in the logs if BAR size is too small Signed-off-by: Marcello Seri <[email protected]> * Cleanup vgpu_type record creation Signed-off-by: Marcello Seri <[email protected]>
1 parent 71b953c commit c5c27fd

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

ocaml/xapi/xapi_vgpu_type.ml

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -467,36 +467,55 @@ module Intel = struct
467467
List.nth device.Pci.Pci_dev.size 2
468468
|> Int64.of_nativeint
469469
in
470-
List.map
470+
let rec collect acc = function
471+
| [] -> acc
472+
| Some v :: tail -> collect (v :: acc) tail
473+
| None :: tail -> collect acc tail
474+
in
475+
whitelist
476+
|> List.map
471477
Identifier.(fun conf ->
472478
let vgpus_per_pgpu =
473479
bar_size /// 1024L /// 1024L
474480
/// conf.identifier.low_gm_sz
475481
--- 1L
476482
in
477-
let vgpu_size = Constants.pgpu_default_size /// vgpus_per_pgpu in
478-
{
479-
vendor_name;
480-
model_name = conf.model_name;
481-
framebuffer_size = conf.framebufferlength;
482-
max_heads = conf.num_heads;
483-
max_resolution_x = conf.max_x;
484-
max_resolution_y = conf.max_y;
485-
size = vgpu_size;
486-
internal_config = [
487-
Xapi_globs.vgt_low_gm_sz, Int64.to_string conf.identifier.low_gm_sz;
488-
Xapi_globs.vgt_high_gm_sz, Int64.to_string conf.identifier.high_gm_sz;
489-
Xapi_globs.vgt_fence_sz, Int64.to_string conf.identifier.fence_sz;
490-
] @ (
491-
match conf.identifier.monitor_config_file with
483+
if vgpus_per_pgpu <= 0L then
484+
begin
485+
warn "Not enough memory for Intel VGPUs. \
486+
If you intend to use them, increase the GPU \
487+
BAR size in the BIOS settings.";
488+
None
489+
end
490+
else
491+
let vgpu_size =
492+
Constants.pgpu_default_size /// vgpus_per_pgpu
493+
in
494+
let internal_config = let open Xapi_globs in
495+
List.concat [
496+
[ vgt_low_gm_sz, Int64.to_string conf.identifier.low_gm_sz
497+
; vgt_high_gm_sz, Int64.to_string conf.identifier.high_gm_sz
498+
; vgt_fence_sz, Int64.to_string conf.identifier.fence_sz
499+
]
500+
; match conf.identifier.monitor_config_file with
492501
| Some monitor_config_file ->
493-
[Xapi_globs.vgt_monitor_config_file, monitor_config_file]
502+
[vgt_monitor_config_file, monitor_config_file]
494503
| None -> []
495-
);
496-
identifier = GVT_g conf.identifier;
497-
experimental = conf.experimental;
498-
})
499-
whitelist
504+
]
505+
in
506+
Some {
507+
vendor_name;
508+
model_name = conf.model_name;
509+
framebuffer_size = conf.framebufferlength;
510+
max_heads = conf.num_heads;
511+
max_resolution_x = conf.max_x;
512+
max_resolution_y = conf.max_y;
513+
size = vgpu_size;
514+
internal_config = internal_config;
515+
identifier = GVT_g conf.identifier;
516+
experimental = conf.experimental;
517+
})
518+
|> collect []
500519

501520
let find_or_create_supported_types ~__context ~pci
502521
~is_system_display_device

0 commit comments

Comments
 (0)