aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Paolino <m.paolino@virtualopensystems.com>2024-07-12 13:13:30 +0000
committerMichele Paolino <m.paolino@virtualopensystems.com>2024-07-25 13:38:07 +0000
commit78268b295615143255c9968087897226e9c16053 (patch)
tree2c82ff186c3efc2e7eaf76d7278ce363e7d46445
parentc434ed98e4269ac17456242c42a4a67bb05e24dd (diff)
virtio-loopback-driver fixes
Updates kernel version checks to successfully compile both on aws and AGL Ref Hardware v2: improve accuracy of the linux kernel versions Bug-AGL: SPEC-4834 Change-Id: Ibc75e3b1b8c1085afbcb02bd4976080b7dbc59cb Signed-off-by: Michele Paolino <m.paolino@virtualopensystems.com>
-rw-r--r--loopback_driver.c16
-rw-r--r--loopback_driver.h9
2 files changed, 22 insertions, 3 deletions
diff --git a/loopback_driver.c b/loopback_driver.c
index 5bb1181..989b865 100644
--- a/loopback_driver.c
+++ b/loopback_driver.c
@@ -30,6 +30,8 @@
#include <linux/platform_device.h>
#include <linux/kernel.h>
#include <linux/device.h>
+#include <linux/version.h>
+#include <linux/slab.h>
/* Virtio-loopback includes */
#include <linux/dma-mapping.h>
@@ -429,6 +431,10 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned int in
goto error_new_virtqueue;
}
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(6,0,0)
+ vq->num_max = num;
+#endif
/* Activate the queue */
write_adapter(virtqueue_get_vring_size(vq), VIRTIO_MMIO_QUEUE_NUM, 4);
if (vm_dev->version == 1) {
@@ -735,7 +741,7 @@ int pf_mmap_vm_page(struct file *filp, struct vm_area_struct *vma)
uint64_t size = (unsigned long)(vma->vm_end - vma->vm_start);
uint64_t pfn = ((cur_ram_idx++) * 0x40000);
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,11,0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,3,0)
vma->vm_flags |= VM_PFNMAP;
#else
vm_flags_set(vma, VM_PFNMAP);
@@ -921,7 +927,13 @@ static long loopback_ioctl(struct file *file,
userspace_task = pid_task(find_vpid(efd_data.pid), PIDTYPE_PID);
rcu_read_lock();
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,11,220)
+ efd_file = fcheck_files(userspace_task->files, efd_data.efd[0]);
+#else
efd_file = files_lookup_fd_rcu(userspace_task->files, efd_data.efd[0]);
+#endif
+
rcu_read_unlock();
efd_ctx = eventfd_ctx_fileget(efd_file);
@@ -1074,7 +1086,7 @@ static int __init loopback_init(void)
err = alloc_chrdev_region(&dev, 0, MAX_DEV, "loopback");
dev_major = MAJOR(dev);
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,11,0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,4,0)
loopback_class = class_create(THIS_MODULE, "loopback");
#else
loopback_class = class_create("loopback");
diff --git a/loopback_driver.h b/loopback_driver.h
index 1a767d9..bb713aa 100644
--- a/loopback_driver.h
+++ b/loopback_driver.h
@@ -24,6 +24,8 @@
#define DRIVER "LOOPBACK"
+#include <linux/version.h>
+
/* max Minor devices */
#define MAX_DEV 1
@@ -348,7 +350,12 @@ int mmap_communication_shared_space(struct file *filp, struct vm_area_struct *vm
uint64_t com_mmap_pfn = ((uint64_t)virt_to_phys(com_mmap_virt)) >> PAGE_SHIFT;
int ret;
- vm_flags_set(vma, VM_RESERVED);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,16,0)
+ vma->vm_flags |= VM_RESERVED;
+#else
+ vm_flags_set(vma, VM_RESERVED);
+#endif
+
ret = remap_pfn_range(vma, vma->vm_start, com_mmap_pfn, size, vma->vm_page_prot);
if (ret != 0) {