From 42b16f852ec44c11360a01194c778ebc6ed438e0 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Mon, 11 Mar 2024 09:07:33 +0100 Subject: [PATCH] Enable to (un)hide a PCI device through the API New API: - `PCI.hide`: hide a PCI device from the dom0 kernel - `PCI.unhide`: unhide a PCI device from the dom0 kernel - `PCI.is_hidden`: return whether a PCI device is hidden This is already possible for PGPUs with the `{enable/disable}_dom0_access` calls this extends it to all PCI devices. Signed-off-by: Benjamin Reis --- ocaml/idl/datamodel.ml | 21 ++++++++++++++++++++- ocaml/xapi/message_forwarding.ml | 26 +++++++++++++++++++++++++- ocaml/xapi/xapi_pci.ml | 9 +++++++++ ocaml/xapi/xapi_pci.mli | 9 +++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/ocaml/idl/datamodel.ml b/ocaml/idl/datamodel.ml index 15f1c4c66c6..a31e015b63d 100644 --- a/ocaml/idl/datamodel.ml +++ b/ocaml/idl/datamodel.ml @@ -6519,11 +6519,30 @@ end (** PCI devices *) module PCI = struct + let hide = + call ~name:"hide" ~lifecycle:[(Published, rel_vgpu_tech_preview, "")] + ~doc:"Hide a PCI device from the dom0 kernel. (Takes affect after next boot.)" + ~params:[(Ref _pci, "self", "The PCI to hide")] + ~allowed_roles:_R_POOL_OP () + + let unhide = + call ~name:"unhide" ~lifecycle:[(Published, rel_vgpu_tech_preview, "")] + ~doc:"Unhide a PCI device from the dom0 kernel. (Takes affect after next boot.)" + ~params:[(Ref _pci, "self", "The PCI to unhide")] + ~allowed_roles:_R_POOL_OP () + + let is_hidden = + call ~name:"is_hidden" ~lifecycle:[(Published, rel_vgpu_tech_preview, "")] + ~doc:"Check whether a PCI device will be hidden from the dom0 kernel on boot." + ~params:[(Ref _pci, "self", "The PCI")] + ~result:(Bool, "Wether the PCI is hidden from the dom0 kernel") + ~allowed_roles:_R_POOL_OP () + let t = create_obj ~name:_pci ~descr:"A PCI device" ~doccomments:[] ~gen_constructor_destructor:false ~gen_events:true ~in_db:true ~lifecycle:[(Published, rel_boston, "")] - ~messages:[] ~messages_default_allowed_roles:_R_POOL_OP + ~messages:[hide; unhide; is_hidden] ~messages_default_allowed_roles:_R_POOL_OP ~persist:PersistEverything ~in_oss_since:None ~db_logging:Log_destroy ~contents: [ diff --git a/ocaml/xapi/message_forwarding.ml b/ocaml/xapi/message_forwarding.ml index b2eb86c805d..6232ad88613 100644 --- a/ocaml/xapi/message_forwarding.ml +++ b/ocaml/xapi/message_forwarding.ml @@ -5867,7 +5867,31 @@ functor module Secret = Local.Secret - module PCI = struct end + module PCI = struct + let hide ~__context ~self = + info "PCI.hide: pci = '%s'" (pci_uuid ~__context self) ; + let host = Db.PCI.get_host ~__context ~self in + let local_fn = Local.PCI.hide ~self in + do_op_on ~__context ~local_fn ~host (fun session_id rpc -> + Client.PCI.hide ~rpc ~session_id ~self + ) + + let unhide ~__context ~self = + info "PCI.unhide: pci = '%s'" (pci_uuid ~__context self) ; + let host = Db.PCI.get_host ~__context ~self in + let local_fn = Local.PCI.unhide ~self in + do_op_on ~__context ~local_fn ~host (fun session_id rpc -> + Client.PCI.unhide ~rpc ~session_id ~self + ) + + let is_hidden ~__context ~self = + info "PCI.is_hidden: pci = '%s'" (pci_uuid ~__context self) ; + let host = Db.PCI.get_host ~__context ~self in + let local_fn = Local.PCI.is_hidden ~self in + do_op_on ~__context ~local_fn ~host (fun session_id rpc -> + Client.PCI.is_hidden ~rpc ~session_id ~self + ) + end module VTPM = struct let create ~__context ~vM ~is_unique = diff --git a/ocaml/xapi/xapi_pci.ml b/ocaml/xapi/xapi_pci.ml index 6e72c366ec7..c01a653c878 100644 --- a/ocaml/xapi/xapi_pci.ml +++ b/ocaml/xapi/xapi_pci.ml @@ -319,3 +319,12 @@ let get_system_display_device () = ) None items with _ -> None + +let hide ~__context ~self = + Pciops.hide_pci ~__context self + +let unhide ~__context ~self = + Pciops.unhide_pci ~__context self + +let is_hidden ~__context ~self = + Pciops.is_pci_hidden ~__context self diff --git a/ocaml/xapi/xapi_pci.mli b/ocaml/xapi/xapi_pci.mli index dd71dfffcc2..8c63ef77add 100644 --- a/ocaml/xapi/xapi_pci.mli +++ b/ocaml/xapi/xapi_pci.mli @@ -51,3 +51,12 @@ val disable_system_display_device : unit -> unit val dequarantine : __context:Context.t -> Xenops_interface.Pci.address -> unit (** dequarantine a PCI device. This is idempotent. *) + +val hide : __context:Context.t -> self:API.ref_PCI -> unit +(** Hide a PCI device from the dom0 kernel. (Takes affect after next boot.) *) + +val unhide : __context:Context.t -> self:API.ref_PCI -> unit +(** Unhide a PCI device from the dom0 kernel. (Takes affect after next boot.) *) + +val is_hidden : __context:Context.t -> self:API.ref_PCI -> bool +(** Check whether a PCI device will be hidden from the dom0 kernel on boot. *)