From 253af2e7bc837af3c5a733c9974e41ff884f5df8 Mon Sep 17 00:00:00 2001
From: Wei Gao <gaowei66@huawei.com>
Date: Thu, 3 Dec 2020 01:44:16 -0500
Subject: [PATCH] Crate: update kvm-ioctls and kvm-bindings deps.

1. Replace kvm-ioctls rust crate-io version by github version.
2. Upgrade kvm-bindings to v0.3.0.
3. Remove util/kvm_ioctl_ext.rs.

Signed-off-by: Wei Gao <gaowei66@huawei.com>
---
 Cargo.lock                                    | 26 +++----
 address_space/Cargo.toml                      |  4 +-
 address_space/src/listener.rs                 | 71 ++++++++++++++-----
 boot_loader/Cargo.toml                        |  4 +-
 device_model/Cargo.toml                       |  4 +-
 device_model/src/cpu/mod.rs                   | 59 +++++++++++----
 .../src/interrupt_controller/aarch64/gicv3.rs | 31 ++++----
 device_model/src/micro_vm/micro_syscall.rs    |  3 -
 util/Cargo.toml                               |  4 +-
 util/src/kvm_ioctls_ext.rs                    | 56 ---------------
 util/src/lib.rs                               |  1 -
 11 files changed, 131 insertions(+), 132 deletions(-)
 delete mode 100644 util/src/kvm_ioctls_ext.rs

diff --git a/Cargo.lock b/Cargo.lock
index 289be29..5e4be40 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -25,8 +25,8 @@ name = "address_space"
 version = "0.1.0"
 dependencies = [
  "error-chain 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvm-bindings 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvm-ioctls 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-bindings 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-ioctls 0.5.0 (git+https://github.com/rust-vmm/kvm-ioctls)",
  "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "machine_manager 0.1.0",
@@ -63,8 +63,8 @@ version = "0.1.0"
 dependencies = [
  "address_space 0.1.0",
  "error-chain 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvm-bindings 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvm-ioctls 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-bindings 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-ioctls 0.5.0 (git+https://github.com/rust-vmm/kvm-ioctls)",
  "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "util 0.1.0",
@@ -89,8 +89,8 @@ dependencies = [
  "boot_loader 0.1.0",
  "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "error-chain 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvm-bindings 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvm-ioctls 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-bindings 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-ioctls 0.5.0 (git+https://github.com/rust-vmm/kvm-ioctls)",
  "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "machine_manager 0.1.0",
@@ -121,7 +121,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "kvm-bindings"
-version = "0.2.0"
+version = "0.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "vmm-sys-util 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -130,9 +130,9 @@ dependencies = [
 [[package]]
 name = "kvm-ioctls"
 version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/rust-vmm/kvm-ioctls#f87ee798e2d782329b02942e2f9b4d0b5c0eb3c7"
 dependencies = [
- "kvm-bindings 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-bindings 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
  "vmm-sys-util 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -250,8 +250,8 @@ name = "util"
 version = "0.1.0"
 dependencies = [
  "error-chain 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvm-bindings 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "kvm-ioctls 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-bindings 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kvm-ioctls 0.5.0 (git+https://github.com/rust-vmm/kvm-ioctls)",
  "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "vmm-sys-util 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -281,8 +281,8 @@ dependencies = [
 "checksum error-chain 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc"
 "checksum gimli 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c"
 "checksum itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
-"checksum kvm-bindings 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d381156ad52005b4655a9421401f02b80f9f049e653496e3ea6639a83fc12453"
-"checksum kvm-ioctls 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d99720f5df3814a7188f095ad6774775b7635dfdd62b7c091ce7e00a51c3c109"
+"checksum kvm-bindings 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1c07667561c3d12d77342baf28ca5d0f8c3ea2160778485640ec84a4571da2"
+"checksum kvm-ioctls 0.5.0 (git+https://github.com/rust-vmm/kvm-ioctls)" = "<none>"
 "checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
 "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
 "checksum miniz_oxide 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
diff --git a/address_space/Cargo.toml b/address_space/Cargo.toml
index 9324871..d2d2791 100644
--- a/address_space/Cargo.toml
+++ b/address_space/Cargo.toml
@@ -9,9 +9,9 @@ description = "provide memory management for VM"
 util = {path = "../util"}
 machine_manager = {path = "../machine_manager"}
 
-kvm-ioctls = "0.5.0"
 libc = "0.2.71"
-kvm-bindings = "0.2.0"
+kvm-bindings = "0.3.0"
+kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls", branch = "master" }
 vmm-sys-util = "0.6.1"
 error-chain = "0.12.4"
 log = "0.4.8"
diff --git a/address_space/src/listener.rs b/address_space/src/listener.rs
index b2eb227..08d6137 100644
--- a/address_space/src/listener.rs
+++ b/address_space/src/listener.rs
@@ -334,14 +334,31 @@ impl KvmMemoryListener {
     /// * `ioevtfd` - IoEvent would be deleted.
     fn delete_ioeventfd(&self, ioevtfd: &RegionIoEventFd) -> Result<()> {
         let io_addr = IoEventAddress::Mmio(ioevtfd.addr_range.base.raw_value());
-        self.fd
-            .unregister_ioevent(&ioevtfd.fd, &io_addr)
-            .chain_err(|| {
-                format!(
-                    "KVM unregister ioeventfd failed: mmio-addr {}",
-                    ioevtfd.addr_range.base.raw_value()
-                )
-            })?;
+        let ioctl_ret = if ioevtfd.data_match {
+            let length = ioevtfd.addr_range.size;
+            match length {
+                2 => self
+                    .fd
+                    .unregister_ioevent(&ioevtfd.fd, &io_addr, ioevtfd.data as u16),
+                4 => self
+                    .fd
+                    .unregister_ioevent(&ioevtfd.fd, &io_addr, ioevtfd.data as u32),
+                8 => self
+                    .fd
+                    .unregister_ioevent(&ioevtfd.fd, &io_addr, ioevtfd.data as u64),
+                _ => bail!("Unexpected ioeventfd data length"),
+            }
+        } else {
+            self.fd
+                .unregister_ioevent(&ioevtfd.fd, &io_addr, NoDatamatch)
+        };
+
+        ioctl_ret.chain_err(|| {
+            format!(
+                "KVM unregister ioeventfd failed: mmio-addr {}",
+                ioevtfd.addr_range.base.raw_value()
+            )
+        })?;
 
         Ok(())
     }
@@ -453,14 +470,32 @@ impl KvmIoListener {
     /// * `ioevtfd` - IoEvent of Region.
     fn delete_ioeventfd(&self, ioevtfd: &RegionIoEventFd) -> Result<()> {
         let io_addr = IoEventAddress::Pio(ioevtfd.addr_range.base.raw_value());
-        self.fd
-            .unregister_ioevent(&ioevtfd.fd, &io_addr)
-            .chain_err(|| {
-                format!(
-                    "KVM unregister ioeventfd failed: io-addr is {}",
-                    ioevtfd.addr_range.base.raw_value()
-                )
-            })?;
+
+        let ioctl_ret = if ioevtfd.data_match {
+            let length = ioevtfd.addr_range.size;
+            match length {
+                2 => self
+                    .fd
+                    .unregister_ioevent(&ioevtfd.fd, &io_addr, ioevtfd.data as u16),
+                4 => self
+                    .fd
+                    .unregister_ioevent(&ioevtfd.fd, &io_addr, ioevtfd.data as u32),
+                8 => self
+                    .fd
+                    .unregister_ioevent(&ioevtfd.fd, &io_addr, ioevtfd.data as u64),
+                _ => bail!("Unexpected ioeventfd data length"),
+            }
+        } else {
+            self.fd
+                .unregister_ioevent(&ioevtfd.fd, &io_addr, NoDatamatch)
+        };
+
+        ioctl_ret.chain_err(|| {
+            format!(
+                "KVM unregister ioeventfd failed: io-addr {}",
+                ioevtfd.addr_range.base.raw_value()
+            )
+        })?;
 
         Ok(())
     }
@@ -624,11 +659,9 @@ mod test {
         assert!(kml
             .handle_request(None, Some(&evtfd), ListenerReqType::AddIoeventfd)
             .is_ok());
-        // deleting this ioeventfd returns an error, for the reason that
-        // function `unregister_ioevent` in kvm-ioctls package doesn't support `data_match` argument yet.
         assert!(kml
             .handle_request(None, Some(&evtfd), ListenerReqType::DeleteIoeventfd)
-            .is_err());
+            .is_ok());
     }
 
     #[test]
diff --git a/boot_loader/Cargo.toml b/boot_loader/Cargo.toml
index cb51561..189146b 100644
--- a/boot_loader/Cargo.toml
+++ b/boot_loader/Cargo.toml
@@ -11,8 +11,8 @@ license = "Mulan PSL v2"
 address_space = { path = "../address_space" }
 util = { path = "../util" }
 
-kvm-bindings = "0.2.0"
-kvm-ioctls = "0.5.0"
+kvm-bindings = "0.3.0"
+kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls", branch = "master" }
 vmm-sys-util = "0.6.1"
 
 libc = "0.2.71"
diff --git a/device_model/Cargo.toml b/device_model/Cargo.toml
index a799fb5..f1eb805 100644
--- a/device_model/Cargo.toml
+++ b/device_model/Cargo.toml
@@ -8,8 +8,8 @@ license = "Mulan PSL v2"
 [dependencies]
 log = "0.4.8"
 libc = "0.2.71"
-kvm-bindings = "0.2.0"
-kvm-ioctls = "0.5.0"
+kvm-bindings = "0.3.0"
+kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls", branch = "master" }
 vmm-sys-util = "0.6.1"
 byteorder = "1.3.4"
 error-chain = "0.12.4"
diff --git a/device_model/src/cpu/mod.rs b/device_model/src/cpu/mod.rs
index 0914345..c754f38 100644
--- a/device_model/src/cpu/mod.rs
+++ b/device_model/src/cpu/mod.rs
@@ -181,6 +181,9 @@ pub trait CPUInterface {
     /// Reset registers value for `CPU`.
     fn reset(&self) -> Result<()>;
 
+    /// Make `CPU` destroy because of guest inner shutdown.
+    fn guest_shutdown(&self) -> Result<()>;
+
     /// Handle vcpu event from `kvm`.
     fn kvm_vcpu_exec(&self) -> Result<bool>;
 }
@@ -462,6 +465,23 @@ impl CPUInterface for CPU {
         }
     }
 
+    fn guest_shutdown(&self) -> Result<()> {
+        let (cpu_state, _) = &*self.state;
+        *cpu_state.lock().unwrap() = CpuLifecycleState::Stopped;
+        self.vm.destroy();
+
+        #[cfg(feature = "qmp")]
+        {
+            let shutdown_msg = schema::SHUTDOWN {
+                guest: true,
+                reason: "guest-shutdown".to_string(),
+            };
+            event!(SHUTDOWN; shutdown_msg);
+        }
+
+        Ok(())
+    }
+
     fn kvm_vcpu_exec(&self) -> Result<bool> {
         match self.fd.run() {
             Ok(run) => match run {
@@ -481,32 +501,43 @@ impl CPUInterface for CPU {
                 }
                 #[cfg(target_arch = "x86_64")]
                 VcpuExit::Hlt => {
-                    info!("Vcpu{} Received KVM_EXIT_HLT signal", self.id());
+                    info!("Vcpu{} received KVM_EXIT_HLT signal", self.id());
                     panic!("Hlt vpu {}", self.id());
                 }
-                VcpuExit::Shutdown | VcpuExit::SystemEvent => {
-                    info!("Vcpu{} Received an KVM_EXIT_SHUTDOWN signal", self.id());
-                    let (cpu_state, _) = &*self.state;
-                    *cpu_state.lock().unwrap() = CpuLifecycleState::Stopped;
-                    self.vm.destroy();
+                #[cfg(target_arch = "x86_64")]
+                VcpuExit::Shutdown => {
+                    info!("Vcpu{} received an KVM_EXIT_SHUTDOWN signal", self.id());
+                    self.guest_shutdown()?;
 
-                    #[cfg(feature = "qmp")]
+                    return Ok(false);
+                }
+                #[cfg(target_arch = "aarch64")]
+                VcpuExit::SystemEvent(event, flags) => {
+                    if event == kvm_bindings::KVM_SYSTEM_EVENT_SHUTDOWN
+                        || event == kvm_bindings::KVM_SYSTEM_EVENT_RESET
                     {
-                        let shutdown_msg = schema::SHUTDOWN {
-                            guest: true,
-                            reason: "guest-shutdown".to_string(),
-                        };
-                        event!(SHUTDOWN; shutdown_msg);
+                        info!(
+                            "Vcpu{} received an KVM_SYSTEM_EVENT_SHUTDOWN signal",
+                            self.id()
+                        );
+                        self.guest_shutdown()?;
+                    } else {
+                        error!(
+                            "Vcpu{} recevied unexpected system event with type 0x{:x}, flags 0x{:x}",
+                            self.id(),
+                            event,
+                            flags
+                        );
                     }
 
                     return Ok(false);
                 }
                 VcpuExit::FailEntry => {
-                    info!("Vcpu{} Received KVM_EXIT_FAIL_ENTRY signal", self.id());
+                    info!("Vcpu{} received KVM_EXIT_FAIL_ENTRY signal", self.id());
                     return Ok(false);
                 }
                 VcpuExit::InternalError => {
-                    info!("Vcpu{} Received KVM_EXIT_INTERNAL_ERROR signal", self.id());
+                    info!("Vcpu{} received KVM_EXIT_INTERNAL_ERROR signal", self.id());
                     return Ok(false);
                 }
                 r => panic!("Unexpected exit reason: {:?}", r),
diff --git a/device_model/src/interrupt_controller/aarch64/gicv3.rs b/device_model/src/interrupt_controller/aarch64/gicv3.rs
index 8f10165..fbad4db 100644
--- a/device_model/src/interrupt_controller/aarch64/gicv3.rs
+++ b/device_model/src/interrupt_controller/aarch64/gicv3.rs
@@ -15,7 +15,6 @@ use std::sync::{Arc, Mutex};
 use kvm_ioctls::{DeviceFd, VmFd};
 
 use machine_manager::machine::{KvmVmState, MachineLifecycle};
-use util::kvm_ioctls_ext::{check_device_attr, get_device_attr};
 use util::{device_tree, errors};
 
 use super::GICConfig;
@@ -46,7 +45,7 @@ type Result<T> = std::result::Result<T, Error>;
 pub struct KvmDevice;
 
 impl KvmDevice {
-    fn kvm_device_check(fd: &DeviceFd, group: u32, attr: u64) -> Result<bool> {
+    fn kvm_device_check(fd: &DeviceFd, group: u32, attr: u64) -> Result<()> {
         let attr = kvm_bindings::kvm_device_attr {
             group,
             attr,
@@ -54,13 +53,9 @@ impl KvmDevice {
             flags: 0,
         };
 
-        let support = check_device_attr(fd, &attr).map_err(Error::CheckDeviceAttribute)?;
-
-        if support == 0 {
-            Ok(true)
-        } else {
-            Ok(false)
-        }
+        Ok(fd
+            .has_device_attr(&attr)
+            .map_err(Error::CheckDeviceAttribute)?)
     }
 
     fn kvm_device_access(
@@ -82,7 +77,8 @@ impl KvmDevice {
                 .map_err(Error::SetDeviceAttribute)?;
         } else {
             let mut attr = attr;
-            get_device_attr(fd, &mut attr).map_err(Error::GetDeviceAttribute)?;
+            fd.get_device_attr(&mut attr)
+                .map_err(Error::GetDeviceAttribute)?;
         };
 
         Ok(())
@@ -204,14 +200,13 @@ impl GICv3 {
     }
 
     fn realize(&self) -> Result<()> {
-        let multi_redist_supported = KvmDevice::kvm_device_check(
-            &self.fd,
-            kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR,
-            kvm_bindings::KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION as u64,
-        )?;
-        if !multi_redist_supported && self.redist_regions.len() > 1 {
-            error!("Multi redistributor region not supported by KVM, max cpus count is 123");
-            return Err(Error::MultiRedistributor);
+        if self.redist_regions.len() > 1 {
+            KvmDevice::kvm_device_check(
+                &self.fd,
+                kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR,
+                kvm_bindings::KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION as u64,
+            )
+            .map_err(|_| Error::MultiRedistributor)?;
         }
 
         if self.redist_regions.len() == 1 {
diff --git a/device_model/src/micro_vm/micro_syscall.rs b/device_model/src/micro_vm/micro_syscall.rs
index ee8b816..cea82d4 100644
--- a/device_model/src/micro_vm/micro_syscall.rs
+++ b/device_model/src/micro_vm/micro_syscall.rs
@@ -14,7 +14,6 @@ extern crate libc;
 
 use crate::errors::Result;
 use crate::virtio::vhost::kernel::*;
-use util::kvm_ioctls_ext::{KVM_GET_DEVICE_ATTR, KVM_HAS_DEVICE_ATTR};
 use util::seccomp::{BpfRule, SeccompCmpOpt, SeccompOpt, SyscallFilter};
 use util::tap::{TUNSETIFF, TUNSETOFFLOAD, TUNSETVNETHDRSZ};
 
@@ -144,8 +143,6 @@ fn ioctl_allow_list() -> BpfRule {
         .add_constraint(SeccompCmpOpt::Eq, 1, TUNSETIFF() as u32)
         .add_constraint(SeccompCmpOpt::Eq, 1, TUNSETOFFLOAD() as u32)
         .add_constraint(SeccompCmpOpt::Eq, 1, TUNSETVNETHDRSZ() as u32)
-        .add_constraint(SeccompCmpOpt::Eq, 1, KVM_GET_DEVICE_ATTR() as u32)
-        .add_constraint(SeccompCmpOpt::Eq, 1, KVM_HAS_DEVICE_ATTR() as u32)
 }
 
 /// Register seccomp rules in syscall allowlist to seccomp.
diff --git a/util/Cargo.toml b/util/Cargo.toml
index 35c2d22..f4ff40f 100644
--- a/util/Cargo.toml
+++ b/util/Cargo.toml
@@ -11,6 +11,6 @@ license = "Mulan PSL v2"
 libc = "0.2.71"
 log = { version = "0.4.8", features = ["std"]}
 error-chain = "0.12.4"
-kvm-ioctls = "0.5.0"
-kvm-bindings = "0.2.0"
+kvm-bindings = "0.3.0"
+kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls", branch = "master" }
 vmm-sys-util = "0.6.1"
diff --git a/util/src/kvm_ioctls_ext.rs b/util/src/kvm_ioctls_ext.rs
deleted file mode 100644
index b9d63fd..0000000
--- a/util/src/kvm_ioctls_ext.rs
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2020 Huawei Technologies Co.,Ltd. All rights reserved.
-//
-// StratoVirt is licensed under Mulan PSL v2.
-// You can use this software according to the terms and conditions of the Mulan
-// PSL v2.
-// You may obtain a copy of Mulan PSL v2 at:
-//         http://license.coscl.org.cn/MulanPSL2
-// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
-// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-// See the Mulan PSL v2 for more details.
-
-use kvm_bindings::{kvm_device_attr, KVMIO};
-use kvm_ioctls::DeviceFd;
-use vmm_sys_util::errno;
-use vmm_sys_util::ioctl::{ioctl_with_mut_ref, ioctl_with_ref};
-
-pub type Result<T> = std::result::Result<T, errno::Error>;
-
-/// Gets a specified piece of device configuration and/or state.
-///
-/// See the documentation for `KVM_GET_DEVICE_ATTR`.
-///
-/// # Arguments
-///
-/// * `device_attr` - The device attribute to be read.
-pub fn get_device_attr(device_fd: &DeviceFd, device_attr: &mut kvm_device_attr) -> Result<()> {
-    let ret = unsafe {
-        // Here we trust the kernel not to read past the end of the kvm_device_attr struct.
-        ioctl_with_mut_ref(device_fd, KVM_GET_DEVICE_ATTR(), device_attr)
-    };
-    if ret != 0 {
-        return Err(errno::Error::last());
-    }
-    Ok(())
-}
-
-/// Check a specified piece of device feature.
-///
-/// See the documentation for `KVM_HAS_DEVICE_ATTR`.
-/// # Arguments
-///
-/// * `device_attr` - The device attribute to be check.
-pub fn check_device_attr(device_fd: &DeviceFd, device_attr: &kvm_device_attr) -> Result<u32> {
-    let ret = unsafe {
-        // Here we trust the kernel not to read past the end of the kvm_device_attr struct.
-        ioctl_with_ref(device_fd, KVM_HAS_DEVICE_ATTR(), device_attr)
-    };
-    if ret < 0 {
-        return Err(errno::Error::last());
-    }
-    Ok(ret as u32)
-}
-
-ioctl_iow_nr!(KVM_GET_DEVICE_ATTR, KVMIO, 0xe2, kvm_device_attr);
-ioctl_iow_nr!(KVM_HAS_DEVICE_ATTR, KVMIO, 0xe3, kvm_device_attr);
diff --git a/util/src/lib.rs b/util/src/lib.rs
index 553fee8..c84e083 100644
--- a/util/src/lib.rs
+++ b/util/src/lib.rs
@@ -27,7 +27,6 @@ pub mod checksum;
 pub mod daemonize;
 pub mod device_tree;
 pub mod epoll_context;
-pub mod kvm_ioctls_ext;
 mod link_list;
 pub mod num_ops;
 pub mod seccomp;
-- 
2.27.0

