From 6c4a0bb6cd72d9cb835472ddef9b32a59593032b Mon Sep 17 00:00:00 2001 From: Sagar Kamble Date: Thu, 13 Feb 2020 15:46:21 +0530 Subject: [PATCH] gpu: nvgpu: API updates for newer kernel access_ok, totalram_pages and zap_vma_ptes are updated in the newer kernel. Update accordingly. Bug 2834141 Change-Id: I3097308740f1af3092ac0a5ac2f0146db8148e12 Signed-off-by: Sagar Kamble Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2294097 Tested-by: mobile promotions Reviewed-by: Debarshi Dutta Reviewed-by: Vijayakumar Subbu Reviewed-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/driver_common.c | 6 +++++- drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c | 10 ++++++++++ drivers/gpu/nvgpu/os/linux/os_linux.h | 5 +++++ drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c | 6 +++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/driver_common.c b/drivers/gpu/nvgpu/os/linux/driver_common.c index 9b617f01e..74f80fa5b 100644 --- a/drivers/gpu/nvgpu/os/linux/driver_common.c +++ b/drivers/gpu/nvgpu/os/linux/driver_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2020, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -112,7 +112,11 @@ static void nvgpu_init_gr_vars(struct gk20a *g) { nvgpu_gr_init(g); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) + nvgpu_log_info(g, "total ram pages : %lu", totalram_pages()); +#else nvgpu_log_info(g, "total ram pages : %lu", totalram_pages); +#endif g->max_comptag_mem = totalram_size_in_mb; } diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c index 504bdfd91..e09a3d7b2 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c @@ -1633,8 +1633,13 @@ static int nvgpu_gpu_set_deterministic_opts(struct gk20a *g, } /* Trivial sanity check first */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) + if (!access_ok(user_channels, + args->num_channels * sizeof(int))) { +#else if (!access_ok(VERIFY_READ, user_channels, args->num_channels * sizeof(int))) { +#endif err = -EFAULT; goto out; } @@ -2095,8 +2100,13 @@ static void alter_usermode_mapping(struct gk20a *g, * b) !poweroff and vmap_mapped -> do nothing as already mapped */ if (poweroff && vma_mapped) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) + zap_vma_ptes(vma, vma->vm_start, vma->vm_end - vma->vm_start); + err = 0; +#else err = zap_vma_ptes(vma, vma->vm_start, vma->vm_end - vma->vm_start); +#endif if (err == 0) { vma->vm_flags = VM_NONE; priv->usermode_vma.vma_mapped = false; diff --git a/drivers/gpu/nvgpu/os/linux/os_linux.h b/drivers/gpu/nvgpu/os/linux/os_linux.h index 6f975632e..f9c568d6b 100644 --- a/drivers/gpu/nvgpu/os/linux/os_linux.h +++ b/drivers/gpu/nvgpu/os/linux/os_linux.h @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -188,6 +189,10 @@ static inline struct device *dev_from_gk20a(struct gk20a *g) #define INTERFACE_NAME "nvhost%s-gpu" +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) +#define totalram_size_in_mb (totalram_pages() >> (10 - (PAGE_SHIFT - 10))) +#else #define totalram_size_in_mb (totalram_pages >> (10 - (PAGE_SHIFT - 10))) +#endif #endif diff --git a/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c b/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c index 96a40589b..091e35925 100644 --- a/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c +++ b/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c @@ -1,7 +1,7 @@ /* * Virtualized GPU for Linux * - * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -470,7 +470,11 @@ int vgpu_probe(struct platform_device *pdev) vgpu_create_sysfs(dev); nvgpu_gr_init(gk20a); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) + nvgpu_log_info(gk20a, "total ram pages : %lu", totalram_pages()); +#else nvgpu_log_info(gk20a, "total ram pages : %lu", totalram_pages); +#endif gk20a->max_comptag_mem = totalram_size_in_mb; nvgpu_ref_init(&gk20a->refcount);