From dfbef6c812c4f7c04650221cc50aaf98fb3fb9bc Mon Sep 17 00:00:00 2001 From: Prashant Date: Sat, 16 Nov 2024 15:07:25 +0000 Subject: [PATCH] GPUDirect Storage kernel driver (nvidia-fs) ver-2.23.1 commit --- ChangeLog | 3 +++ src/GDS_VERSION | 2 +- src/nvfs-core.c | 53 +++++++++++++++++++++++++++++++++++++++++++++---- src/nvfs-mmap.c | 2 +- src/nvfs-mmap.h | 2 +- src/nvfs-rdma.c | 7 +++---- src/nvfs-vers.h | 4 ++-- 7 files changed, 60 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index b19977c..ffeb9bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +nvidia-fs (2.23.1) RELEASE; urgency=low + * Use persistent_p2p APIs >= nvidia driver version 555 + * Fix bug in copy_to_uer through batch API nvidia-fs (2.22.3) RELEASE; urgency=low * Switch to nvidia_p2p_get_pages_persistent() call for baremetal on x86 nvidia-fs (2.20.5) RELEASE; urgency=low diff --git a/src/GDS_VERSION b/src/GDS_VERSION index 6d937cd..73a567b 100644 --- a/src/GDS_VERSION +++ b/src/GDS_VERSION @@ -1 +1 @@ -1.11.0.20 +1.12.0.25 diff --git a/src/nvfs-core.c b/src/nvfs-core.c index 9925acb..80d3597 100644 --- a/src/nvfs-core.c +++ b/src/nvfs-core.c @@ -85,6 +85,10 @@ #define MAJ_MIN_P_V(maj, min, patch) maj##.##min##.##patch #define MOD_VERS(major, minor, p) MAJ_MIN_P_V(major, minor, p) +#define NVIDIA_DRIVER_PATH "/sys/module/nvidia/version" +#define NVIDIA_DRIVER_BUF_SIZE 4 +#define NVIDIA_MIN_DRIVER_FOR_VGPU 555 + static int major_number; static struct class* nvfs_class = NULL; static struct device* nvfs_device[MAX_NVFS_DEVICES]; @@ -2287,7 +2291,7 @@ static long nvfs_ioctl(struct file *file, unsigned int ioctl_num, local_param.ioargs.ioctl_return = PTR_ERR(nvfs_batch); if (copy_to_user((void *) ioctl_param, (void*) &local_param, - sizeof(nvfs_ioctl_param_union))) { + sizeof(nvfs_ioctl_batch_ioargs_t))) { nvfs_err("%s:%d copy_to_user failed\n", __func__, __LINE__); } nvfs_stat(&nvfs_n_batch_err); @@ -2306,7 +2310,7 @@ static long nvfs_ioctl(struct file *file, unsigned int ioctl_num, nvfs_stat64(&nvfs_n_batches_ok); } if (copy_to_user((void *) ioctl_param, (void*) &local_param, - sizeof(nvfs_ioctl_param_union))) { + sizeof(nvfs_ioctl_batch_ioargs_t))) { local_param.ioargs.ioctl_return = -EFAULT; nvfs_stat(&nvfs_n_batch_err); nvfs_err("%s:%d copy_to_user failed\n", __func__, __LINE__); @@ -2437,6 +2441,39 @@ static char *nvfs_devnode(const struct device *dev, umode_t *mode) return NULL; } +static int get_nvidia_driver_version(void){ + struct file *file; + char buf[NVIDIA_DRIVER_BUF_SIZE]; + loff_t pos = 0; + ssize_t bytes_read; + int value; + + file = filp_open(NVIDIA_DRIVER_PATH, O_RDONLY, 0); + if (IS_ERR(file)) { + nvfs_err("Error opening nvidia driver version file: %ld\n", PTR_ERR(file)); + return -1; + } + + bytes_read = kernel_read(file, buf, NVIDIA_DRIVER_BUF_SIZE - 1, &pos); + + if (bytes_read < 0) { + nvfs_err("Error reading file: %ld\n", bytes_read); + filp_close(file, NULL); + return -1; + } else { + buf[bytes_read] = '\0'; + int ret = kstrtoint(buf,10,&value); + if (ret != 0) { + nvfs_err("Failed to convert driver version to int: %s, ret: %d\n", buf, ret); + filp_close(file, NULL); + return -1; + } + + } + filp_close(file, NULL); + return value; +} + /* * Initialize nvfs driver */ @@ -2444,13 +2481,21 @@ static int __init nvfs_init(void) { int i; + int version= get_nvidia_driver_version(); + + // if the version is greater than or qequal 555, use persistent_p2p APIs + if (version >= NVIDIA_MIN_DRIVER_FOR_VGPU) { + nvfs_use_legacy_p2p_allocation = 0; + } + + // if the driver version is less than 555, but it's x86 and BM, use the persistent_p2p APIs #if defined(CONFIG_X86_64) - if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)){ + if (nvfs_use_legacy_p2p_allocation == 1 && !cpu_feature_enabled(X86_FEATURE_HYPERVISOR)){ // X86 and not a VM nvfs_use_legacy_p2p_allocation = 0; } #endif - + pr_info("nvidia_fs: Initializing nvfs driver module\n"); major_number = register_chrdev(0, DEVICE_NAME, &nvfs_dev_fops); diff --git a/src/nvfs-mmap.c b/src/nvfs-mmap.c index 8a6419e..e38cdb8 100644 --- a/src/nvfs-mmap.c +++ b/src/nvfs-mmap.c @@ -1179,7 +1179,7 @@ nvfs_mgroup_ptr_t nvfs_mgroup_from_page_range(struct page* page, int nblocks, un unsigned block_idx; unsigned cur_page; - nvfs_dbg("setting for %d nblocks from page: %p and start offset :%u\n", nblocks, page, start_offset); + nvfs_dbg("setting metadata for %d nblocks from page: %p and start offset :%u\n", nblocks, page, start_offset); nvfs_mgroup = __nvfs_mgroup_from_page(page, false); if (!nvfs_mgroup) return NULL; diff --git a/src/nvfs-mmap.h b/src/nvfs-mmap.h index 85423b3..71fbe3e 100644 --- a/src/nvfs-mmap.h +++ b/src/nvfs-mmap.h @@ -131,7 +131,7 @@ struct nvfs_gpu_args { u64 gpuvaddr; // GPU Buffer address u64 gpu_buf_len; // length of gpu buffer struct page *end_fence_page; // end fence addr pinned page - u32 offset_in_page; // end_fence_addr byte offset in end_fence_page + u32 offset_in_page; // end_fence_addr byte offset in end_fence_page atomic_t io_state; // IO state transitions atomic_t dma_mapping_in_progress; // Mapping in progress for a specific PCI device atomic_t callback_invoked; diff --git a/src/nvfs-rdma.c b/src/nvfs-rdma.c index 9ba2992..8773558 100644 --- a/src/nvfs-rdma.c +++ b/src/nvfs-rdma.c @@ -40,7 +40,7 @@ int nvfs_set_rdma_reg_info_to_mgroup( uint32_t nkeys; int ret = -EINVAL; - nvfs_dbg("SG: %s CPU vaddr: %llx \n", __func__, rdma_reg_info_args->cpuvaddr); + nvfs_dbg("%s CPU vaddr: %llx \n", __func__, rdma_reg_info_args->cpuvaddr); nvfs_mgroup = nvfs_get_mgroup_from_vaddr(rdma_reg_info_args->cpuvaddr); if(nvfs_mgroup == NULL || unlikely(IS_ERR(nvfs_mgroup))) { @@ -58,7 +58,7 @@ int nvfs_set_rdma_reg_info_to_mgroup( shadow_buf_size = (nvfs_mgroup->nvfs_blocks_count) * NVFS_BLOCK_SIZE; - nvfs_dbg("SG: %s nvfs_mgroup = %p\n GPU vaddr: %llx", __func__, + nvfs_dbg("%s nvfs_mgroup = %p\n GPU vaddr: %llx", __func__, nvfs_mgroup, nvfs_mgroup->gpu_info.gpuvaddr); @@ -130,7 +130,7 @@ int nvfs_get_rdma_reg_info_from_mgroup( nvfs_mgroup = nvfs_get_mgroup_from_vaddr(rdma_reg_info_args->cpuvaddr); if(nvfs_mgroup == NULL || unlikely(IS_ERR(nvfs_mgroup))) { - printk("SG Error: nvfs_mgroup NULL\n"); + nvfs_err("Error: nvfs_mgroup NULL\n"); return -EINVAL; } shadow_buf_size = (nvfs_mgroup->nvfs_blocks_count) * NVFS_BLOCK_SIZE; @@ -214,7 +214,6 @@ int nvfs_clear_rdma_reg_info_in_mgroup( nvfs_mgroup = nvfs_get_mgroup_from_vaddr(rdma_clear_info_args->cpuvaddr); if(nvfs_mgroup == NULL || unlikely(IS_ERR(nvfs_mgroup))) { nvfs_err("%s Error: nvfs_mgroup NULL\n", __func__); - printk("SG Error: nvfs_mgroup NULL\n"); return -1; } diff --git a/src/nvfs-vers.h b/src/nvfs-vers.h index e0c1859..76bff4f 100644 --- a/src/nvfs-vers.h +++ b/src/nvfs-vers.h @@ -26,10 +26,10 @@ #define NVFS_DRIVER_MAJOR_VERSION 2 //2-bytes -#define NVFS_DRIVER_MINOR_VERSION 22 //2-bytes +#define NVFS_DRIVER_MINOR_VERSION 23 //2-bytes // template for build version -#define NVFS_DRIVER_PATCH_VERSION 3 +#define NVFS_DRIVER_PATCH_VERSION 1 static inline unsigned int nvfs_driver_version(void) { return (NVFS_DRIVER_MAJOR_VERSION << 16) | NVFS_DRIVER_MINOR_VERSION;