Skip to content

Commit

Permalink
GPUDirect Storage kernel driver (nvidia-fs) ver-2.23.1 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantp-nv-11 committed Nov 16, 2024
1 parent 2d2b552 commit dfbef6c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 13 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/GDS_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.0.20
1.12.0.25
53 changes: 49 additions & 4 deletions src/nvfs-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -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__);
Expand Down Expand Up @@ -2437,20 +2441,61 @@ 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
*/
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);
Expand Down
2 changes: 1 addition & 1 deletion src/nvfs-mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/nvfs-mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/nvfs-rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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);


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/nvfs-vers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dfbef6c

Please sign in to comment.