gpu: nvgpu: Use conftest for VM flags

Using kernel version for detecting kernel changes does not work for some
3rd party Linux distributions that back port kernel changes to their
kernel. The conftest script has a test for detecting if the 'vm_flags'
variable can be set directly or if the appropriate helper functions must
be used. Update the NVGPU driver to use the definition provided by
conftest to determine if the 'vm_flags' variable can set set directly or
not.

Bug 4014315

Change-Id: I6ebfbfa622259e15560152bf70315451a52fba81
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/3164870
(cherry picked from commit 2c9097363d29a235eb5c41530cdd3896694599d2)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/3172302
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Sagar Kamble <skamble@nvidia.com>
This commit is contained in:
Jon Hunter
2024-05-23 11:43:24 +01:00
committed by mobile promotions
parent 6d8106348a
commit 10b813a25d
3 changed files with 20 additions and 34 deletions

View File

@@ -1,18 +1,9 @@
/* // SPDX-License-Identifier: GPL-2.0-only
* Copyright (c) 2017-2023, NVIDIA CORPORATION. All rights reserved. // SPDX-FileCopyrightText: Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it #if defined(CONFIG_NVIDIA_CONFTEST)
* under the terms and conditions of the GNU General Public License, #include <nvidia/conftest.h>
* version 2, as published by the Free Software Foundation. #endif
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nvgpu/gk20a.h> #include <nvgpu/gk20a.h>
#include <nvgpu/gr/ctx.h> #include <nvgpu/gr/ctx.h>
@@ -250,7 +241,7 @@ static int cbc_ctrl_debug_mmap_cbc_store(struct file *f, struct vm_area_struct *
err = -EINVAL; err = -EINVAL;
goto done; goto done;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) #if defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS) /* Linux v6.3 */
vm_flags_set(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE | vm_flags_set(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE |
VM_DONTDUMP | VM_PFNMAP); VM_DONTDUMP | VM_PFNMAP);
vm_flags_clear(vma, VM_MAYWRITE); vm_flags_clear(vma, VM_MAYWRITE);

View File

@@ -1,18 +1,9 @@
/* // SPDX-License-Identifier: GPL-2.0-only
* Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. // SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it #if defined(CONFIG_NVIDIA_CONFTEST)
* under the terms and conditions of the GNU General Public License, #include <nvidia/conftest.h>
* version 2, as published by the Free Software Foundation. #endif
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/version.h> #include <linux/version.h>
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
@@ -144,7 +135,7 @@ static int nvgpu_nvs_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma
nvgpu_nvs_ctrl_fifo_lock_queues(g); nvgpu_nvs_ctrl_fifo_lock_queues(g);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) #if defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS) /* Linux v6.3 */
vm_flags_set(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE | vm_flags_set(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE |
VM_DONTDUMP); VM_DONTDUMP);
#else #else
@@ -153,7 +144,7 @@ static int nvgpu_nvs_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma
#endif #endif
if (buf->mask == NVGPU_NVS_CTRL_FIFO_QUEUE_CLIENT_EVENTS_READ) { if (buf->mask == NVGPU_NVS_CTRL_FIFO_QUEUE_CLIENT_EVENTS_READ) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) #if defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS) /* Linux v6.3 */
vm_flags_set(vma, VM_SHARED); vm_flags_set(vma, VM_SHARED);
#else #else
vma->vm_flags |= VM_SHARED; vma->vm_flags |= VM_SHARED;

View File

@@ -1,6 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: Copyright (c) 2011-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-FileCopyrightText: Copyright (c) 2011-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#if defined(CONFIG_NVIDIA_CONFTEST)
#include <nvidia/conftest.h>
#endif
#include <linux/version.h> #include <linux/version.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/cdev.h> #include <linux/cdev.h>
@@ -2853,7 +2857,7 @@ int gk20a_ctrl_dev_mmap(struct file *filp, struct vm_area_struct *vma)
nvgpu_mutex_acquire(&l->ctrl_privs_lock); nvgpu_mutex_acquire(&l->ctrl_privs_lock);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) #if defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS) /* Linux v6.3 */
vm_flags_set(vma, VM_IO | VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE | vm_flags_set(vma, VM_IO | VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE |
VM_DONTDUMP | VM_PFNMAP); VM_DONTDUMP | VM_PFNMAP);
#else #else