Skip to content

Commit

Permalink
Merge pull request xapi-project#5411 from edwintorok/master
Browse files Browse the repository at this point in the history
Merge Xen-4.17 update
  • Loading branch information
edwintorok authored Feb 1, 2024
2 parents 0554a7d + 96d012a commit fe5d334
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 17 deletions.
66 changes: 52 additions & 14 deletions ocaml/xenopsd/xc/domain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ type x86_arch_emulation_flags = Xenctrl.x86_arch_emulation_flags =
| X86_EMU_VPCI
[@@deriving rpcty]

type x86_arch_misc_flags = Xenctrl.x86_arch_misc_flags = X86_MSR_RELAXED
[@@deriving rpcty]

type xen_x86_arch_domainconfig = Xenctrl.xen_x86_arch_domainconfig = {
emulation_flags: x86_arch_emulation_flags list
; misc_flags: x86_arch_misc_flags list [@default [X86_MSR_RELAXED]]
(* misc_flags is missing when migrating from old version.
set the default to relaxed MSR for backwards compatibility *)
}
[@@deriving rpcty]

Expand All @@ -66,6 +72,8 @@ type domain_create_flag = Xenctrl.domain_create_flag =
| CDF_OOS_OFF
| CDF_XS_DOMAIN
| CDF_IOMMU
| CDF_NESTED_VIRT
| CDF_VPMU
[@@deriving rpcty]

type domain_create_iommu_opts = Xenctrl.domain_create_iommu_opts =
Expand Down Expand Up @@ -97,6 +105,8 @@ type domctl_create_config = Xenctrl.domctl_create_config = {
; max_evtchn_port: int
; max_grant_frames: int
; max_maptrack_frames: int
; max_grant_version: int
; cpupool_id: int32
; arch: arch_domainconfig
}
[@@deriving rpcty]
Expand Down Expand Up @@ -288,6 +298,27 @@ let make ~xc ~xs vm_info vcpus domain_config uuid final_uuid no_sharept =
sprintf "Guest type %s unavailable" (if hvm then "HVM" else "PV")
) ;

let get_platform_key ~key ~default check =
let platformdata = vm_info.platformdata in
let unknown = List.assoc_opt key platformdata |> Option.value ~default:"" in
let on_error msg =
error "VM = %s; %s platform/%s=\"%s\"." (Uuidx.to_string uuid) msg key
unknown ;
invalid_arg (Printf.sprintf "platform/%s=%s" key unknown)
in
if not @@ Platform.is_valid ~key ~platformdata then
on_error "Unrecognized value" ;
let wants = Platform.is_true ~key ~platformdata ~default in
match check wants with Ok () -> wants | Error msg -> on_error msg
in

let require_hvm wants : (_, _) result =
if wants && not hvm then
Error "HVM required for"
else
Ok ()
in

(* HVM guests must select a paging mode of either HAP "Hardware Assisted
Paging" or Shadow. *)
let hap =
Expand All @@ -298,17 +329,9 @@ let make ~xc ~xs vm_info vcpus domain_config uuid final_uuid no_sharept =
unconditionally and raise an error if unavailable. Otherwise, use
HAP if available, falling back to Shadow if not. *)
let hap =
match List.assoc_opt "hap" vm_info.platformdata with
| Some "true" ->
true
| Some "false" ->
false
| Some unknown ->
error "VM = %s; Unrecognized value platform/hap=\"%s\"."
(Uuidx.to_string uuid) unknown ;
invalid_arg ("platform/hap=" ^ unknown)
| None ->
List.mem CAP_HAP host_info.capabilities
get_platform_key ~key:"hap"
(fun _ -> Ok ())
~default:(List.mem CAP_HAP host_info.capabilities)
in

(* HAP depends on 2nd Gen VT-x/SVM, or firmware/Xen settings. Shadow
Expand All @@ -327,18 +350,30 @@ let make ~xc ~xs vm_info vcpus domain_config uuid final_uuid no_sharept =
let iommu = vm_info.pci_passthrough in
if iommu then
assert_capability CAP_DirectIO ~on_error:(fun () -> "IOMMU unavailable") ;
let nested_virt =
get_platform_key ~key:"nested_virt" ~default:false require_hvm
in
let vpmu = get_platform_key ~key:"vpmu" ~default:false (fun _ -> Ok ()) in

info "VM = %s; Creating %s%s%s" (Uuidx.to_string uuid)
info "VM = %s; Creating %s%s%s%s%s" (Uuidx.to_string uuid)
(if hvm then "HVM" else "PV")
(if hap then " HAP" else "")
(if iommu then " IOMMU" else "") ;
(if iommu then " IOMMU" else "")
(if nested_virt then " NESTEDVIRT" else "")
(if vpmu then " VPMU" else "") ;

let config =
{
ssidref= vm_info.ssidref
; handle= Uuidx.to_string uuid
; flags=
[(hvm, CDF_HVM); (hap, CDF_HAP); (iommu, CDF_IOMMU)]
[
(hvm, CDF_HVM)
; (hap, CDF_HAP)
; (iommu, CDF_IOMMU)
; (nested_virt, CDF_NESTED_VIRT)
; (vpmu, CDF_VPMU)
]
|> List.filter_map (fun (cond, flag) -> if cond then Some flag else None)
; iommu_opts=
( match no_sharept with
Expand All @@ -359,6 +394,9 @@ let make ~xc ~xs vm_info vcpus domain_config uuid final_uuid no_sharept =
int_of_string (List.assoc "max_maptrack_frames" vm_info.platformdata)
with _ -> 1024
)
; max_grant_version=
(if List.mem CAP_Gnttab_v2 host_info.capabilities then 2 else 1)
; cpupool_id= 0l
; arch= domain_config
}
in
Expand Down
3 changes: 3 additions & 0 deletions ocaml/xenopsd/xc/domain.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ val emulation_flags_pvh : x86_arch_emulation_flags list

val emulation_flags_all : x86_arch_emulation_flags list

type x86_arch_misc_flags = X86_MSR_RELAXED

type xen_x86_arch_domainconfig = {
(* Xenctrl.xen_x86_arch_domainconfig = *)
emulation_flags: x86_arch_emulation_flags list
; misc_flags: x86_arch_misc_flags list
}

type arch_domainconfig =
Expand Down
15 changes: 12 additions & 3 deletions ocaml/xenopsd/xc/xenops_server_xen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,22 @@ module VmExtra = struct
let domain_config_of_vm vm =
let open Vm in
let open Domain in
let misc_flags =
if
Platform.is_true ~key:"msr-relaxed"
~platformdata:vm.Xenops_interface.Vm.platformdata ~default:false
then
[X86_MSR_RELAXED]
else
[]
in
match vm.ty with
| PV _ ->
X86 {emulation_flags= []}
X86 {emulation_flags= []; misc_flags}
| PVinPVH _ | PVH _ ->
X86 {emulation_flags= emulation_flags_pvh}
X86 {emulation_flags= emulation_flags_pvh; misc_flags}
| HVM _ ->
X86 {emulation_flags= emulation_flags_all}
X86 {emulation_flags= emulation_flags_all; misc_flags}

(* Known versions of the VM persistent metadata created by xenopsd *)
let persistent_version_pre_lima = 0
Expand Down

0 comments on commit fe5d334

Please sign in to comment.