It isn't required to be exposed to client modules, privatize it.
Signed-off-by: Viresh Kumar viresh.kumar@linaro.org --- V3: New commit
crates/xen-ioctls/src/xdm/xdm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crates/xen-ioctls/src/xdm/xdm.rs b/crates/xen-ioctls/src/xdm/xdm.rs index 3aa5289794fe..06b589967dde 100644 --- a/crates/xen-ioctls/src/xdm/xdm.rs +++ b/crates/xen-ioctls/src/xdm/xdm.rs @@ -242,7 +242,7 @@ impl XenDeviceModelHandle { do_dm_op(&self.fd, domid, &mut privcmd_dm_op_buffers) }
- pub fn config_irqfd( + fn config_irqfd( &self, fd: EventFd, domid: u16,
The kernel's irqfd macro has changed a bit. Make a corresponding change here too.
Signed-off-by: Viresh Kumar viresh.kumar@linaro.org --- V2: New commit
crates/xen-ioctls/src/private.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/crates/xen-ioctls/src/private.rs b/crates/xen-ioctls/src/private.rs index 59a75f67f18d..50833e750f2d 100644 --- a/crates/xen-ioctls/src/private.rs +++ b/crates/xen-ioctls/src/private.rs @@ -12,7 +12,7 @@ use libc::{c_ulong, c_void, ioctl, mmap, munmap, MAP_SHARED, PROT_READ, PROT_WRI use std::fs::OpenOptions; use std::io::Error; use std::os::unix::io::AsRawFd; -use vmm_sys_util::ioctl::_IOC_NONE; +use vmm_sys_util::ioctl::{_IOC_NONE, _IOC_WRITE};
use crate::xdm::types::{PrivcmdDeviceModelIrqFd, PrivcmdDeviceModelOp}; use crate::xfm::types::{PrivCmdMmapBatchV2, PrivCmdMmapResource}; @@ -74,12 +74,11 @@ ioctl_ioc_nr!( );
/* - * #define IOCTL_PRIVCMD_IRQFD \ - * _IOC(_IOC_NONE, 'P', 8, sizeof(privcmd_irqfd_t)) + * #define IOCTL_PRIVCMD_IRQFD _IOW('P', 8, privcmd_irqfd_t) */ ioctl_ioc_nr!( IOCTL_PRIVCMD_IRQFD, - _IOC_NONE, + _IOC_WRITE, XEN_PRIVCMD_TYPE, 8 as u32, std::mem::size_of::<PrivcmdDeviceModelIrqFd>() as u32
This adds support to issue the set ioeventfd ioctl via the privcmd file.
Signed-off-by: Viresh Kumar viresh.kumar@linaro.org --- V3: Privatize config_ioeventfd() V2: Change based on merged kernel code.
crates/xen-ioctls/Cargo.toml | 1 + crates/xen-ioctls/src/private.rs | 15 +++++- crates/xen-ioctls/src/xdm/types.rs | 18 +++++++ crates/xen-ioctls/src/xdm/xdm.rs | 82 ++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-)
diff --git a/crates/xen-ioctls/Cargo.toml b/crates/xen-ioctls/Cargo.toml index a9e26f9fe0e0..bc4d21e5847b 100644 --- a/crates/xen-ioctls/Cargo.toml +++ b/crates/xen-ioctls/Cargo.toml @@ -11,3 +11,4 @@ edition = "2018" [dependencies] libc = ">=0.2.95" vmm-sys-util = ">=0.9.0" +xen-bindings = { path = "../xen-bindings" } diff --git a/crates/xen-ioctls/src/private.rs b/crates/xen-ioctls/src/private.rs index 50833e750f2d..13cb3fc8c669 100644 --- a/crates/xen-ioctls/src/private.rs +++ b/crates/xen-ioctls/src/private.rs @@ -14,7 +14,9 @@ use std::io::Error; use std::os::unix::io::AsRawFd; use vmm_sys_util::ioctl::{_IOC_NONE, _IOC_WRITE};
-use crate::xdm::types::{PrivcmdDeviceModelIrqFd, PrivcmdDeviceModelOp}; +use crate::xdm::types::{ + PrivcmdDeviceModelIoeventFd, PrivcmdDeviceModelIrqFd, PrivcmdDeviceModelOp, +}; use crate::xfm::types::{PrivCmdMmapBatchV2, PrivCmdMmapResource};
pub const PAGE_SHIFT: u32 = 12; @@ -84,6 +86,17 @@ ioctl_ioc_nr!( std::mem::size_of::<PrivcmdDeviceModelIrqFd>() as u32 );
+/* + * #define IOCTL_PRIVCMD_IOEVENTFD _IOW('P', 9, privcmd_ioeventfd_t) + */ +ioctl_ioc_nr!( + IOCTL_PRIVCMD_IOEVENTFD, + _IOC_WRITE, + XEN_PRIVCMD_TYPE, + 9 as u32, + std::mem::size_of::<PrivcmdDeviceModelIoeventFd>() as u32 +); + pub const HYPERCALL_EVTCHN: &str = "/dev/xen/evtchn"; pub const HYPERCALL_PRIVCMD: &str = "/dev/xen/privcmd"; pub const HYPERCALL_BUFFER_FILE: &str = "/dev/xen/hypercall"; diff --git a/crates/xen-ioctls/src/xdm/types.rs b/crates/xen-ioctls/src/xdm/types.rs index b000a68f0cf1..963583e34b97 100644 --- a/crates/xen-ioctls/src/xdm/types.rs +++ b/crates/xen-ioctls/src/xdm/types.rs @@ -157,3 +157,21 @@ pub struct PrivcmdDeviceModelIrqFd { pub domid: u16, pub pad: [u8; 2], } + +pub const PRIVCMD_IOEVENTFD_FLAG_DEASSIGN: u32 = 1; + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +// tools/include/xen-sys/Linux/privcmd.h::privcmd_ioeventfd +pub struct PrivcmdDeviceModelIoeventFd { + pub ioreq: *mut c_void, + pub ports: *const u32, + pub addr: u64, + pub addr_len: u32, + pub event_fd: u32, + pub vcpus: u32, + pub vq: u32, + pub flags: u32, + pub domid: u16, + pub pad: [u8; 2], +} diff --git a/crates/xen-ioctls/src/xdm/xdm.rs b/crates/xen-ioctls/src/xdm/xdm.rs index 06b589967dde..7a48ec63ac1f 100644 --- a/crates/xen-ioctls/src/xdm/xdm.rs +++ b/crates/xen-ioctls/src/xdm/xdm.rs @@ -17,6 +17,8 @@ use std::os::unix::io::AsRawFd;
use vmm_sys_util::eventfd::EventFd;
+use xen_bindings::bindings::ioreq; + #[cfg(target_arch = "aarch64")] use crate::aarch64::types::*; #[cfg(target_arch = "x86_64")] @@ -307,4 +309,84 @@ impl XenDeviceModelHandle { ) -> Result<(), std::io::Error> { self.config_irqfd(fd, domid, irq, level, PRIVCMD_IRQFD_FLAG_DEASSIGN) } + + fn config_ioeventfd( + &self, + kick: &EventFd, + ioreq: &mut ioreq, + ports: &[u32], + addr: u64, + addr_len: u32, + vq: u32, + vcpus: u32, + domid: u16, + flags: u32, + ) -> Result<(), std::io::Error> { + let mut ioeventfd = PrivcmdDeviceModelIoeventFd { + ioreq: ioreq as *mut _ as *mut c_void, + ports: ports as *const _ as *const u32, + addr, + addr_len, + event_fd: kick.as_raw_fd() as u32, + vcpus, + vq, + flags, + domid, + pad: [0; 2], + }; + + let ret = unsafe { + // The expression "&mut ioeventfd as *mut _" creates a reference to ioeventfd before casting it + // to a *mut c_void. + ioctl( + self.fd.as_raw_fd(), + IOCTL_PRIVCMD_IOEVENTFD(), + &mut ioeventfd as *mut _ as *mut c_void, + ) + }; + + if ret < 0 { + return Err(Error::last_os_error()); + } + + Ok(()) + } + + pub fn set_ioeventfd( + &self, + kick: &EventFd, + ioreq: &mut ioreq, + ports: &[u32], + addr: u64, + addr_len: u32, + vq: u32, + vcpus: u32, + domid: u16, + ) -> Result<(), std::io::Error> { + self.config_ioeventfd(kick, ioreq, ports, addr, addr_len, vq, vcpus, domid, 0) + } + + pub fn clear_ioeventfd( + &self, + kick: &EventFd, + ioreq: &mut ioreq, + ports: &[u32], + addr: u64, + addr_len: u32, + vq: u32, + vcpus: u32, + domid: u16, + ) -> Result<(), std::io::Error> { + self.config_ioeventfd( + kick, + ioreq, + ports, + addr, + addr_len, + vq, + vcpus, + domid, + PRIVCMD_IOEVENTFD_FLAG_DEASSIGN, + ) + } }
On Wed, 18 Oct 2023 at 23:55, Viresh Kumar viresh.kumar@linaro.org wrote:
This adds support to issue the set ioeventfd ioctl via the privcmd file.
Signed-off-by: Viresh Kumar viresh.kumar@linaro.org
V3: Privatize config_ioeventfd() V2: Change based on merged kernel code.
crates/xen-ioctls/Cargo.toml | 1 + crates/xen-ioctls/src/private.rs | 15 +++++- crates/xen-ioctls/src/xdm/types.rs | 18 +++++++ crates/xen-ioctls/src/xdm/xdm.rs | 82 ++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-)
diff --git a/crates/xen-ioctls/Cargo.toml b/crates/xen-ioctls/Cargo.toml index a9e26f9fe0e0..bc4d21e5847b 100644 --- a/crates/xen-ioctls/Cargo.toml +++ b/crates/xen-ioctls/Cargo.toml @@ -11,3 +11,4 @@ edition = "2018" [dependencies] libc = ">=0.2.95" vmm-sys-util = ">=0.9.0" +xen-bindings = { path = "../xen-bindings" } diff --git a/crates/xen-ioctls/src/private.rs b/crates/xen-ioctls/src/private.rs index 50833e750f2d..13cb3fc8c669 100644 --- a/crates/xen-ioctls/src/private.rs +++ b/crates/xen-ioctls/src/private.rs @@ -14,7 +14,9 @@ use std::io::Error; use std::os::unix::io::AsRawFd; use vmm_sys_util::ioctl::{_IOC_NONE, _IOC_WRITE};
-use crate::xdm::types::{PrivcmdDeviceModelIrqFd, PrivcmdDeviceModelOp}; +use crate::xdm::types::{
- PrivcmdDeviceModelIoeventFd, PrivcmdDeviceModelIrqFd, PrivcmdDeviceModelOp,
+}; use crate::xfm::types::{PrivCmdMmapBatchV2, PrivCmdMmapResource};
pub const PAGE_SHIFT: u32 = 12; @@ -84,6 +86,17 @@ ioctl_ioc_nr!( std::mem::size_of::<PrivcmdDeviceModelIrqFd>() as u32 );
+/*
- #define IOCTL_PRIVCMD_IOEVENTFD _IOW('P', 9, privcmd_ioeventfd_t)
- */
+ioctl_ioc_nr!(
- IOCTL_PRIVCMD_IOEVENTFD,
- _IOC_WRITE,
- XEN_PRIVCMD_TYPE,
- 9 as u32,
- std::mem::size_of::<PrivcmdDeviceModelIoeventFd>() as u32
+);
pub const HYPERCALL_EVTCHN: &str = "/dev/xen/evtchn"; pub const HYPERCALL_PRIVCMD: &str = "/dev/xen/privcmd"; pub const HYPERCALL_BUFFER_FILE: &str = "/dev/xen/hypercall"; diff --git a/crates/xen-ioctls/src/xdm/types.rs b/crates/xen-ioctls/src/xdm/types.rs index b000a68f0cf1..963583e34b97 100644 --- a/crates/xen-ioctls/src/xdm/types.rs +++ b/crates/xen-ioctls/src/xdm/types.rs @@ -157,3 +157,21 @@ pub struct PrivcmdDeviceModelIrqFd { pub domid: u16, pub pad: [u8; 2], }
+pub const PRIVCMD_IOEVENTFD_FLAG_DEASSIGN: u32 = 1;
+#[repr(C)] +#[derive(Debug, Copy, Clone)] +// tools/include/xen-sys/Linux/privcmd.h::privcmd_ioeventfd +pub struct PrivcmdDeviceModelIoeventFd {
- pub ioreq: *mut c_void,
- pub ports: *const u32,
- pub addr: u64,
- pub addr_len: u32,
- pub event_fd: u32,
- pub vcpus: u32,
- pub vq: u32,
- pub flags: u32,
- pub domid: u16,
- pub pad: [u8; 2],
+} diff --git a/crates/xen-ioctls/src/xdm/xdm.rs b/crates/xen-ioctls/src/xdm/xdm.rs index 06b589967dde..7a48ec63ac1f 100644 --- a/crates/xen-ioctls/src/xdm/xdm.rs +++ b/crates/xen-ioctls/src/xdm/xdm.rs @@ -17,6 +17,8 @@ use std::os::unix::io::AsRawFd;
use vmm_sys_util::eventfd::EventFd;
+use xen_bindings::bindings::ioreq;
#[cfg(target_arch = "aarch64")] use crate::aarch64::types::*; #[cfg(target_arch = "x86_64")] @@ -307,4 +309,84 @@ impl XenDeviceModelHandle { ) -> Result<(), std::io::Error> { self.config_irqfd(fd, domid, irq, level, PRIVCMD_IRQFD_FLAG_DEASSIGN) }
- fn config_ioeventfd(
Thanks for the respin - I have applied your patches.
Mathieu
stratos-dev@op-lists.linaro.org