From dd4f96e5c974a61aa9e3d5cc2909b470473d6d82 Mon Sep 17 00:00:00 2001 From: Vedashree Vidwans Date: Tue, 24 Jan 2023 23:19:15 -0800 Subject: [PATCH] tegra: hwpm: fix kernel crash on TOT Currently on TOT, stream buffer map functions results in kernel crash. The kernel crash is an effect of incorrect conditions in the mapping function. Fix the code logic to use correct kernel version conditions to use appropriate DMA buffer structures. Bug 3893741 Change-Id: I3888ec01fdb2025f6d9c3a22296ca9d1abbcadb0 Signed-off-by: Vedashree Vidwans (cherry picked from commit 5a3476cfb6574eb5ace29801a4f428ce9d694ce9) Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2853211 Reviewed-by: Seema Khowala GVS: Gerrit_Virtual_Submit --- drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c | 21 +++++++++----------- drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h | 6 +++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c b/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c index 818dfcf..0766701 100644 --- a/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c +++ b/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. 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, @@ -32,7 +32,7 @@ #include -#if defined(CONFIG_TEGRA_HWPM_OOT) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) #include MODULE_IMPORT_NS(DMA_BUF); #endif @@ -92,7 +92,7 @@ static int tegra_hwpm_dma_map_mem_bytes_buffer(struct tegra_soc_hwpm *hwpm, struct tegra_soc_hwpm_alloc_pma_stream *alloc_pma_stream) { struct tegra_hwpm_os_linux *hwpm_linux = NULL; -#if defined(CONFIG_TEGRA_HWPM_OOT) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) int err = 0; #endif @@ -129,12 +129,11 @@ static int tegra_hwpm_dma_map_mem_bytes_buffer(struct tegra_soc_hwpm *hwpm, hwpm->mem_mgmt->mem_bytes_buf_va = sg_dma_address(hwpm->mem_mgmt->mem_bytes_sgt->sgl); -#if defined(CONFIG_TEGRA_HWPM_OOT) -#if LINUX_VERSION_CODE > KERNEL_VERSION(5, 10, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) /* - * Kernel version beyond 5.10 introduces - * dma_buf_map structure (called iosys_map in later versions). - * The kernel Virtual address generated from dma_buf_vmap API + * Kernel version 5.15 and above introduces dma_buf_map structure + * (called iosys_map in versions later than 5.18). + * The kernel virtual address generated from dma_buf_vmap API * is stored in mem_bytes_map, which is a dma_buf_map structure */ err = dma_buf_vmap(hwpm->mem_mgmt->mem_bytes_dma_buf, @@ -144,6 +143,7 @@ static int tegra_hwpm_dma_map_mem_bytes_buffer(struct tegra_soc_hwpm *hwpm, "Unable to map mem_bytes buffer into kernel VA space"); return -ENOMEM; } + hwpm->mem_mgmt->mem_bytes_kernel = hwpm->mem_mgmt->mem_bytes_map.vaddr; #else hwpm->mem_mgmt->mem_bytes_kernel = @@ -153,7 +153,6 @@ static int tegra_hwpm_dma_map_mem_bytes_buffer(struct tegra_soc_hwpm *hwpm, "Unable to map mem_bytes buffer into kernel VA space"); return -ENOMEM; } -#endif #endif memset(hwpm->mem_mgmt->mem_bytes_kernel, 0, 32); @@ -188,14 +187,12 @@ static int tegra_hwpm_reset_stream_buf(struct tegra_soc_hwpm *hwpm) hwpm->mem_mgmt->stream_dma_buf = NULL; if (hwpm->mem_mgmt->mem_bytes_kernel) { -#if defined(CONFIG_TEGRA_HWPM_OOT) -#if LINUX_VERSION_CODE > KERNEL_VERSION(5, 10, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) dma_buf_vunmap(hwpm->mem_mgmt->mem_bytes_dma_buf, &hwpm->mem_mgmt->mem_bytes_map); #else dma_buf_vunmap(hwpm->mem_mgmt->mem_bytes_dma_buf, hwpm->mem_mgmt->mem_bytes_kernel); -#endif #endif hwpm->mem_mgmt->mem_bytes_kernel = NULL; } diff --git a/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h b/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h index 4b00e67..3659a03 100644 --- a/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h +++ b/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. 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, @@ -15,11 +15,11 @@ #define TEGRA_HWPM_OS_LINUX_MEM_MGMT_UTILS_H #include -#if defined(CONFIG_TEGRA_HWPM_OOT) #include #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) #include #else +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) #include #endif #endif @@ -46,10 +46,10 @@ struct tegra_hwpm_mem_mgmt { struct dma_buf *mem_bytes_dma_buf; struct dma_buf_attachment *mem_bytes_attach; void *mem_bytes_kernel; -#if defined(CONFIG_TEGRA_HWPM_OOT) #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) struct iosys_map mem_bytes_map; #else +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) struct dma_buf_map mem_bytes_map; #endif #endif