From 10b813a25d3948de1e9ad5b2d4b384612e4a3381 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Thu, 23 May 2024 11:43:24 +0100 Subject: [PATCH] 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 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 Reviewed-by: Sagar Kamble --- drivers/gpu/nvgpu/os/linux/debug_gr.c | 23 +++++++---------------- drivers/gpu/nvgpu/os/linux/dmabuf_nvs.c | 25 ++++++++----------------- drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c | 6 +++++- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/debug_gr.c b/drivers/gpu/nvgpu/os/linux/debug_gr.c index b4d2b691f..02aca78df 100644 --- a/drivers/gpu/nvgpu/os/linux/debug_gr.c +++ b/drivers/gpu/nvgpu/os/linux/debug_gr.c @@ -1,18 +1,9 @@ -/* - * Copyright (c) 2017-2023, 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, - * version 2, as published by the Free Software Foundation. - * - * 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 . - */ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +#if defined(CONFIG_NVIDIA_CONFTEST) +#include +#endif #include #include @@ -250,7 +241,7 @@ static int cbc_ctrl_debug_mmap_cbc_store(struct file *f, struct vm_area_struct * err = -EINVAL; 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_DONTDUMP | VM_PFNMAP); vm_flags_clear(vma, VM_MAYWRITE); diff --git a/drivers/gpu/nvgpu/os/linux/dmabuf_nvs.c b/drivers/gpu/nvgpu/os/linux/dmabuf_nvs.c index fc24fef21..91f535bfa 100644 --- a/drivers/gpu/nvgpu/os/linux/dmabuf_nvs.c +++ b/drivers/gpu/nvgpu/os/linux/dmabuf_nvs.c @@ -1,18 +1,9 @@ -/* - * Copyright (c) 2022-2023, 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, - * version 2, as published by the Free Software Foundation. - * - * 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 . - */ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +#if defined(CONFIG_NVIDIA_CONFTEST) +#include +#endif #include #include @@ -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); -#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_DONTDUMP); #else @@ -153,7 +144,7 @@ static int nvgpu_nvs_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma #endif 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); #else vma->vm_flags |= VM_SHARED; diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c index a9a65886b..8ce9b300d 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c @@ -1,6 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-only // SPDX-FileCopyrightText: Copyright (c) 2011-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +#if defined(CONFIG_NVIDIA_CONFTEST) +#include +#endif + #include #include #include @@ -2853,7 +2857,7 @@ int gk20a_ctrl_dev_mmap(struct file *filp, struct vm_area_struct *vma) 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_DONTDUMP | VM_PFNMAP); #else