From a92e1d1a8d9a4dcaff3c6dc3d6b47d4b2e341155 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 14 Jun 2017 03:33:43 +0200 Subject: Support kernels up to 4.9 (patch provided by Timo) --- driver/compat.h | 9 +++++++++ driver/umem.c | 22 +++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'driver') diff --git a/driver/compat.h b/driver/compat.h index 24cc5a9..ba9d15a 100644 --- a/driver/compat.h +++ b/driver/compat.h @@ -37,4 +37,13 @@ # define __devinitdata #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) +# define get_user_pages_compat(vma, nr, pages) get_user_pages(vma, nr, FOLL_WRITE, pages, NULL) +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0) +# define get_user_pages_compat(vma, nr, pages) get_user_pages(vma, nr, 1, 0, pages, NULL) +#else +# define get_user_pages_compat(vma, nr, pages) get_user_pages(current, current->mm, vma, nr, 1, 0, pages, NULL) +#endif + + #endif diff --git a/driver/umem.c b/driver/umem.c index 8d73207..e643102 100644 --- a/driver/umem.c +++ b/driver/umem.c @@ -81,15 +81,7 @@ int pcidriver_umem_sgmap(pcidriver_privdata_t *privdata, umem_handle_t *umem_han /* Get the page information */ down_read(¤t->mm->mmap_sem); - res = get_user_pages( - current, - current->mm, - umem_handle->vma, - nr_pages, - 1, - 0, /* do not force, FIXME: shall I? */ - pages, - NULL ); + res = get_user_pages_compat(umem_handle->vma, nr_pages, pages); up_read(¤t->mm->mmap_sem); /* Error, not all pages mapped */ @@ -106,7 +98,7 @@ int pcidriver_umem_sgmap(pcidriver_privdata_t *privdata, umem_handle_t *umem_han /* Lock the pages, then populate the SG list with the pages */ /* page0 is different */ if ( !PageReserved(pages[0]) ) - __set_page_locked(pages[0]); + lock_page(pages[0]); offset = (umem_handle->vma & ~PAGE_MASK); length = (umem_handle->size > (PAGE_SIZE-offset) ? (PAGE_SIZE-offset) : umem_handle->size); @@ -117,7 +109,7 @@ int pcidriver_umem_sgmap(pcidriver_privdata_t *privdata, umem_handle_t *umem_han for(i=1; i PAGE_SIZE) ? PAGE_SIZE : count), 0); @@ -166,10 +158,10 @@ umem_sgmap_unmap: if (nr_pages > 0) { for(i=0; ipages[i] )) { SetPageDirty( umem_entry->pages[i] ); - __clear_page_locked(umem_entry->pages[i]); + unlock_page(umem_entry->pages[i]); } /* and release it from the cache */ - page_cache_release( umem_entry->pages[i] ); + put_page( umem_entry->pages[i] ); } } -- cgit v1.2.3