From a2b53ade559c582a8e4b81155ae56b543bea3734 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Tue, 3 Dec 2024 17:54:29 +0000 Subject: [PATCH] virt: hvc_sysfs: Fix build for Linux v6.13 In Linux v6.13, commit 94a20fb9af16 ("sysfs: treewide: constify attribute callback of bin_attribute::mmap()") changed the type of the 'struct bin_attribute' argument of the bin_attribute:mmap function pointer to const. Use conftest to detect if this argument is const or not in the kernel the driver is being compiled against to fix the build. Bug 4991705 Change-Id: I791d6c9dde50f1444d0339ebd8a18434045f9026 Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3261699 (cherry picked from commit fae042552e211199a160e5d6a82a67edd7b7e03c) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3321698 Reviewed-by: Brad Griffis GVS: buildbot_gerritrpt --- drivers/virt/tegra/hvc_sysfs.c | 11 +++++++++-- scripts/conftest/Makefile | 1 + scripts/conftest/conftest.sh | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/virt/tegra/hvc_sysfs.c b/drivers/virt/tegra/hvc_sysfs.c index 39152c1e..67ed37f5 100644 --- a/drivers/virt/tegra/hvc_sysfs.c +++ b/drivers/virt/tegra/hvc_sysfs.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: GPL-2.0-only * * This program is free software; you can redistribute it and/or modify it @@ -15,6 +15,8 @@ * along with this program. If not, see . */ +#include + #include #include #include @@ -52,7 +54,12 @@ static struct hyp_shared_memory_info hyp_shared_memory_attrs[HYP_SHM_ID_NUM]; /* Map the HV trace buffer to the calling user process */ static int hvc_sysfs_mmap(struct file *fp, struct kobject *ko, - struct bin_attribute *attr, struct vm_area_struct *vma) +#if defined(NV_BIN_ATTRIBUTE_STRUCT_MMAP_HAS_CONST_BIN_ATTRIBUTE_ARG) /* Linux v6.13 */ + const struct bin_attribute *attr, +#else + struct bin_attribute *attr, +#endif + struct vm_area_struct *vma) { struct hyp_shared_memory_info *hyp_shm_info = container_of(attr, struct hyp_shared_memory_info, attr); diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index 0ce8355c..16335451 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -90,6 +90,7 @@ endef NV_CONFTEST_FUNCTION_COMPILE_TESTS += __alloc_disk_node_has_lkclass_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += __assign_str_has_no_src_arg +NV_CONFTEST_FUNCTION_COMPILE_TESTS += bin_attribute_struct_mmap_has_const_bin_attribute_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += blk_execute_rq_has_no_gendisk_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += blk_mq_alloc_disk_for_queue NV_CONFTEST_FUNCTION_COMPILE_TESTS += blk_mq_alloc_queue diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index 2631119c..231aa4a4 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -6502,6 +6502,27 @@ compile_test() { compile_check_conftest "$CODE" "NV___ALLOC_DISK_NODE_HAS_LKCLASS_ARG" "" "types" ;; + bin_attribute_struct_mmap_has_const_bin_attribute_arg) + # + # Determine if the 'bin_attribute' structure 'mmap' function pointer + # has const 'struct bin_attribute' argument. + # + # Commit 94a20fb9af16 ("sysfs: treewide: constify attribute callback + # of bin_attribute::mmap()") updated the 'mmap' function pointer to + # take a const 'bin_attribute' structure in Linux v6.13. + # + CODE=" + #include + void conftest(struct bin_attribute *attr) { + int (*fn)(struct file *, struct kobject *, + const struct bin_attribute *, + struct vm_area_struct *) = attr->mmap; + }" + + compile_check_conftest "$CODE" \ + "NV_BIN_ATTRIBUTE_STRUCT_MMAP_HAS_CONST_BIN_ATTRIBUTE_ARG" "" "types" + ;; + blk_execute_rq_has_no_gendisk_arg) # # Determine if the function blk_execute_rq() has an argument of