Skip to content

Commit

Permalink
GPUDirect Storage kernel driver (nvidia-fs) ver-2.19.6 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabgupta3 committed Mar 6, 2024
1 parent af65003 commit 1913aed
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 24 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
nvidia-fs (2.19.6) RELEASE; urgency=low
* Fix compilation issue for 6.5 kernel
* Fix bug in calculation of physical_chunks for p2p allocation

nvidia-fs (2.18.3) RELEASE; urgency=low
* Return error in DFS callback path for bad Meta data
* Fix compilation issue for 6.2 kernel
Expand Down
2 changes: 1 addition & 1 deletion src/GDS_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.2.11
1.9.0.20
32 changes: 32 additions & 0 deletions src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ fi

cat > $TEST_C <<EOF
#include <linux/fs.h>
#include <linux/pagemap.h>
#include "test.h"
int test (void)
Expand Down Expand Up @@ -467,6 +468,37 @@ if compile_prog "Checking if devnode in class has doesn't have const device or n
output_sym "HAVE_NO_CONST_DEVICE_IN_DEVNODE"
fi

cat > $TEST_C <<EOF
#include "test.h"
#include <linux/device.h>
#include <linux/export.h>
int test (void)
{
struct class* nvfs_class;
nvfs_class = class_create(THIS_MODULE, "testclass");
return 0;
}
EOF
if compile_prog "Checking if class_create has two parameters or not ..."; then
output_sym "CLASS_CREATE_HAS_TWO_PARAMS"
fi

cat > $TEST_C <<EOF
#include "test.h"
#include <linux/mm_types.h>
int test (void)
{
struct vm_area_struct vma;
vma.vm_flags = 0;
return 0;
}
EOF
if compile_prog "Checking if vma_flags are modifiable directly ..."; then
output_sym "NVFS_VM_FLAGS_NOT_CONSTANT"
fi

echo "#endif" >> $config_host_h
rm -rf build

17 changes: 13 additions & 4 deletions src/nvfs-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ nvfs_get_dma_address(nvfs_io_t* nvfsio,
}

if (ret) {
nvfs_info("Unabled to obtain dma_mapping :%d for %p-%p "
nvfs_info("Unable to obtain dma_mapping :%d for %p-%p "
"PCI_DEVID %d\n", ret, gpu_info, peer,
NVFS_GET_PCI_DEVID(peer));
goto out;
Expand Down Expand Up @@ -1303,9 +1303,14 @@ static int nvfs_pin_gpu_pages(nvfs_ioctl_map_t *input_param,
nvfs_dbg("GPU Physical page[%d]=0x%016llx\n",
i, gpu_info->page_table->pages[i]->physical_address);

if ((gpu_info->page_table->pages[i]->physical_address + GPU_PAGE_SIZE) !=
gpu_info->page_table->pages[i + 1]->physical_address)
n_phys_chunks += 1;
//create a new segment when the physical addresses are non contiguous
// or force a new segment at physical address boundary of (4G - 64k)
// to handle possible SMMU mappings being non-contiguous
if ((gpu_info->page_table->pages[i]->physical_address + GPU_PAGE_SIZE) !=
gpu_info->page_table->pages[i + 1]->physical_address)
n_phys_chunks += 1;
else if (i > 0 && (i % NVFS_P2P_MAX_CONTIG_GPU_PAGES == 0))
n_phys_chunks += 1;
}

gpu_info->n_phys_chunks = n_phys_chunks;
Expand Down Expand Up @@ -2411,7 +2416,11 @@ static int __init nvfs_init(void)
pr_info("nvidia_fs: registered correctly with major number %d\n",
major_number);

#ifdef CLASS_CREATE_HAS_TWO_PARAMS
nvfs_class = class_create(THIS_MODULE, CLASS_NAME);
#else
nvfs_class = class_create(CLASS_NAME);
#endif

if (IS_ERR(nvfs_class)) {
unregister_chrdev(major_number, DEVICE_NAME);
Expand Down
2 changes: 2 additions & 0 deletions src/nvfs-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ void nvfs_io_process_exiting(nvfs_mgroup_ptr_t nvfs_mgroup);
#define NVFS_IOCTL_BATCH_IO _IOW(NVFS_MAGIC, 8, int)
#endif

//Max contiguous physical GPU memory for P2P is (4GiB - 64k) or 65535 64k pages
#define NVFS_P2P_MAX_CONTIG_GPU_PAGES 65535
#define PAGE_PER_GPU_PAGE_SHIFT ilog2(GPU_PAGE_SIZE / PAGE_SIZE)
#define GPU_PAGE_SHIFT 16
#define GPU_PAGE_SIZE ((u64)1 << GPU_PAGE_SHIFT)
Expand Down
23 changes: 16 additions & 7 deletions src/nvfs-dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ static int nvfs_blk_rq_map_sg_internal(struct request_queue *q,
struct scatterlist *sg = NULL;
struct bio_vec bvec;
uint64_t curr_phys_addr = 0, prev_phys_addr = 0;
unsigned long gpu_page_index = 0;
pgoff_t pgoff = 0;


#ifdef TEST_DISCONTIG_ADDR
int key;
Expand Down Expand Up @@ -416,17 +419,23 @@ static int nvfs_blk_rq_map_sg_internal(struct request_queue *q,
#else
curr_phys_addr = nvfs_mgroup_get_gpu_physical_address(nvfs_mgroup, bvec.bv_page);
#endif
nvfs_mgroup_get_gpu_index_and_off(nvfs_mgroup, bvec.bv_page, &gpu_page_index, &pgoff);
// we no longer need nvfs_mgroup from this point onwards
CHECK_AND_PUT_MGROUP(nvfs_mgroup);
nvfs_mgroup = NULL;

if (sg != NULL) {
if (prev_phys_addr && is_gpu_page_contiguous(prev_phys_addr, curr_phys_addr)) {
sg->length += bvec.bv_len;
prev_phys_addr = curr_phys_addr;
continue;
}
}
if (sg != NULL) {
if (prev_phys_addr && is_gpu_page_contiguous(prev_phys_addr, curr_phys_addr)) {
//DONT allow merge at (4G - 64K) to handle possible discontiguous IOVA
// by SMMU
if((gpu_page_index == 0) ||
(gpu_page_index % NVFS_P2P_MAX_CONTIG_GPU_PAGES != 0)) {
sg->length += bvec.bv_len;
prev_phys_addr = curr_phys_addr;
continue;
}
}
}

new_segment:
nsegs++;
Expand Down
28 changes: 18 additions & 10 deletions src/nvfs-mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ static int nvfs_mgroup_mmap_internal(struct file *filp, struct vm_area_struct *v
nvfs_mgroup_ptr_t nvfs_mgroup, nvfs_new_mgroup;
struct nvfs_gpu_args *gpu_info;
int os_pages_count;
vm_flags_t vm_flags;

nvfs_stat64(&nvfs_n_mmap);
/* check length - do not allow larger mappings than the number of
Expand All @@ -643,30 +644,37 @@ static int nvfs_mgroup_mmap_internal(struct file *filp, struct vm_area_struct *v
nvfs_err("mmap size not a multiple of 64K: 0x%lx for size >64k \n", length);
goto error;
}

if ((vma->vm_flags & (VM_MAYREAD|VM_READ|VM_MAYWRITE|VM_WRITE)) != (VM_MAYREAD|VM_READ|VM_MAYWRITE|VM_WRITE))
#ifdef NVFS_VM_FLAGS_NOT_CONSTANT
vm_flags = vma->vm_flags;
#else
vm_flags = ACCESS_PRIVATE(vma, __vm_flags);
#endif
if ((vm_flags & (VM_MAYREAD|VM_READ|VM_MAYWRITE|VM_WRITE)) != (VM_MAYREAD|VM_READ|VM_MAYWRITE|VM_WRITE))
{
nvfs_err("cannot open vma without PROTO_WRITE|PROT_READ flags: %lx \n", vma->vm_flags);
nvfs_err("cannot open vma without PROTO_WRITE|PROT_READ flags: %lx \n", vm_flags);
goto error;
}

if ((vma->vm_flags & (VM_EXEC)) != 0)
if ((vm_flags & (VM_EXEC)) != 0)
{
nvfs_err("cannot open vma with MAP_EXEC flags: %lx \n", vma->vm_flags);
nvfs_err("cannot open vma with MAP_EXEC flags: %lx \n", vm_flags);
goto error;
}

/* if VM_SHARED is not set the page->mapping is not NULL */
if ((vma->vm_flags & (VM_SHARED)) == 0)
if ((vm_flags & (VM_SHARED)) == 0)
{
nvfs_err("cannot open vma without MAP_SHARED: %lx \n", vma->vm_flags);
nvfs_err("cannot open vma without MAP_SHARED: %lx \n", vm_flags);
goto error;
}

/* dont allow mremap to expand and dont allow copy on fork */
#ifdef NVFS_VM_FLAGS_NOT_CONSTANT
vma->vm_flags |= VM_IO | VM_MIXEDMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_DONTCOPY;
#else
vm_flags_set(vma, VM_IO | VM_MIXEDMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_DONTCOPY);
#endif
vma->vm_ops = &nvfs_mmap_ops;

nvfs_new_mgroup = (nvfs_mgroup_ptr_t)kzalloc(sizeof(struct nvfs_io_mgroup), GFP_KERNEL);
if (!nvfs_new_mgroup) {
ret = -ENOMEM;
Expand Down Expand Up @@ -1255,8 +1263,8 @@ int nvfs_mgroup_metadata_set_dma_state(struct page* page,
if(nvfs_mpage->nvfs_state != NVFS_IO_QUEUED &&
nvfs_mpage->nvfs_state != NVFS_IO_DMA_START)
{
nvfs_err("%s: found page in wrong state: %d, page->index: %ld at block: %d len: %u and offset: %u\n",
__func__, nvfs_mpage->nvfs_state, page->index % NVFS_MAX_SHADOW_PAGES, i, bv_len, bv_offset);
nvfs_err("%s: found page in wrong state: %d, page->index: %ld at block: %d len: %u and offset: %u\n",
__func__, nvfs_mpage->nvfs_state, page->index % NVFS_MAX_SHADOW_PAGES, i, bv_len, bv_offset);
nvfs_mpage->nvfs_state = NVFS_IO_DMA_ERROR;
nvfs_mgroup_put(nvfs_mgroup);
WARN_ON_ONCE(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 18 //2-bytes
#define NVFS_DRIVER_MINOR_VERSION 19 //2-bytes

// template for build version
#define NVFS_DRIVER_PATCH_VERSION 3
#define NVFS_DRIVER_PATCH_VERSION 6

static inline unsigned int nvfs_driver_version(void) {
return (NVFS_DRIVER_MAJOR_VERSION << 16) | NVFS_DRIVER_MINOR_VERSION;
Expand Down

0 comments on commit 1913aed

Please sign in to comment.