From dc189dfb94a8198113b70416c12a25537036d193 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Tue, 3 Oct 2023 18:39:14 +0100 Subject: [PATCH] block: virtual-storage: Remove kernel version checks Rather than using kernel version checks to determine which kernel APIs to use, add the necessary tests to the conftest script to determine which kernel APIs are present in the kernel. This is beneficial for working with 3rd party Linux kernels that may have back-ported upstream changes into their kernel and so the kernel version checks do not work. Bug 4221847 Change-Id: Iec2c793ce408dab1cf7e5118c019dfe656dfa87c Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2992630 Tested-by: mobile promotions Reviewed-by: mobile promotions --- .../block/tegra_virt_storage/tegra_hv_ioctl.c | 3 +- .../block/tegra_virt_storage/tegra_hv_vblk.c | 11 +-- scripts/conftest/Makefile | 5 ++ scripts/conftest/conftest.sh | 88 +++++++++++++++++++ 4 files changed, 100 insertions(+), 7 deletions(-) diff --git a/drivers/block/tegra_virt_storage/tegra_hv_ioctl.c b/drivers/block/tegra_virt_storage/tegra_hv_ioctl.c index 265b9e4e..d81e32f4 100644 --- a/drivers/block/tegra_virt_storage/tegra_hv_ioctl.c +++ b/drivers/block/tegra_virt_storage/tegra_hv_ioctl.c @@ -5,7 +5,6 @@ #include -#include #include #include #include @@ -137,7 +136,7 @@ int vblk_submit_ioctl_req(struct block_device *bdev, rq->completion_data = (void *)ioctl_req; #endif -#if KERNEL_VERSION(5, 17, 0) <= LINUX_VERSION_CODE +#if defined(NV_BLK_EXECUTE_RQ_HAS_NO_GENDISK_ARG) /* Linux v5.17 */ blk_execute_rq(rq, 0); #else blk_execute_rq(vblkdev->gd, rq, 0); diff --git a/drivers/block/tegra_virt_storage/tegra_hv_vblk.c b/drivers/block/tegra_virt_storage/tegra_hv_vblk.c index 9690a73c..e561f805 100644 --- a/drivers/block/tegra_virt_storage/tegra_hv_vblk.c +++ b/drivers/block/tegra_virt_storage/tegra_hv_vblk.c @@ -5,7 +5,6 @@ #include -#include #include #include #include @@ -1186,9 +1185,9 @@ static void setup_device(struct vblk_dev *vblkdev) } /* And the gendisk structure. */ -#if KERNEL_VERSION(6, 0, 0) <= LINUX_VERSION_CODE +#if defined(NV_BLK_MQ_ALLOC_DISK_FOR_QUEUE_PRESENT) /* Linux v6.0 */ vblkdev->gd = blk_mq_alloc_disk_for_queue(vblkdev->queue, NULL); -#elif KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE +#elif defined(NV___ALLOC_DISK_NODE_HAS_LKCLASS_ARG) /* Linux v5.15 */ vblkdev->gd = __alloc_disk_node(vblkdev->queue, NUMA_NO_NODE, NULL); #else vblkdev->gd = __alloc_disk_node(VBLK_MINORS, NUMA_NO_NODE); @@ -1238,7 +1237,7 @@ static void setup_device(struct vblk_dev *vblkdev) } set_capacity(vblkdev->gd, (vblkdev->size / SECTOR_SIZE)); -#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE +#if defined(NV_DEVICE_ADD_DISK_HAS_INT_RETURN_TYPE) /* Linux v5.15 */ if (device_add_disk(vblkdev->device, vblkdev->gd, NULL)) { dev_err(vblkdev->device, "Error adding disk!\n"); return; @@ -1465,8 +1464,10 @@ static int tegra_hv_vblk_remove(struct platform_device *pdev) put_disk(vblkdev->gd); } -#if KERNEL_VERSION(5, 19, 0) >= LINUX_VERSION_CODE if (vblkdev->queue) +#if defined(NV_BLK_MQ_DESTROY_QUEUE_PRESENT) /* Linux v6.0 */ + blk_mq_destroy_queue(vblkdev->queue); +#else blk_cleanup_queue(vblkdev->queue); #endif diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index 85ab591d..83d15749 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -88,12 +88,17 @@ endef # provided by the module-specific Kbuild files. # +NV_CONFTEST_FUNCTION_COMPILE_TESTS += __alloc_disk_node_has_lkclass_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_destroy_queue NV_CONFTEST_FUNCTION_COMPILE_TESTS += block_device_operations_open_has_gendisk_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += block_device_operations_release_has_no_mode_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += bus_type_struct_remove_has_int_return_type NV_CONFTEST_FUNCTION_COMPILE_TESTS += class_create_has_no_owner_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += class_struct_devnode_has_const_dev_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += define_semaphore_has_number_arg +NV_CONFTEST_FUNCTION_COMPILE_TESTS += device_add_disk_has_int_return_type NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_thermal_of_zone_register NV_CONFTEST_FUNCTION_COMPILE_TESTS += disk_check_media_change NV_CONFTEST_FUNCTION_COMPILE_TESTS += drm_aperture_remove_framebuffers diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index 46e786a8..08c6983a 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -6329,6 +6329,76 @@ compile_test() { compile_check_conftest "$CODE" "NV_CRYPTO_PRESENT" "" "symbols" ;; + __alloc_disk_node_has_lkclass_arg) + # + # Determine if the function __alloc_disk_node() has an 'lkclass' + # argument. + # + # In Linux v5.15, commit 4dcc4874deb4 ("block: cleanup the lockdep + # handling in *alloc_disk") added the 'lkclass' argument to the + # __alloc_disk_node() function. + # + CODE=" + #include + struct gendisk *conftest___alloc_disk_node_has_lkclass_arg( + struct request_queue *q) { + return __alloc_disk_node(q, 0, NULL); + }" + + compile_check_conftest "$CODE" "NV___ALLOC_DISK_NODE_HAS_LKCLASS_ARG" "" "types" + ;; + + blk_execute_rq_has_no_gendisk_arg) + # + # Determine if the function blk_execute_rq() has an argument of + # type 'gendisk'. + # + # In Linux v5.17, commit b84ba30b6c7a ("block: remove the gendisk + # argument to blk_execute_rq") removed the 'gendisk' argument from + # the blk_execute_rq(). + # + CODE=" + #include + void conftest_blk_execute_rq_has_no_gendisk_arg(struct request *r) { + blk_execute_rq(r, false); + }" + + compile_check_conftest "$CODE" "NV_BLK_EXECUTE_RQ_HAS_NO_GENDISK_ARG" "" "types" + ;; + + blk_mq_alloc_disk_for_queue) + # + # Determine if function blk_mq_alloc_disk_for_queue() is present. + # + # In Linux v6.0, commit 6f8191fdf41d ("block: simplify disk shutdown") + # added the function blk_mq_alloc_disk_for_queue() and removed + # __alloc_disk_node(). + # + CODE=" + #include + void conftest_blk_mq_alloc_disk_for_queue(void) { + blk_mq_alloc_disk_for_queue(); + }" + + compile_check_conftest "$CODE" "NV_BLK_MQ_ALLOC_DISK_FOR_QUEUE_PRESENT" "" "functions" + ;; + + blk_mq_destroy_queue) + # + # Determine whether function blk_mq_destroy_queue() is present. + # + # In Linux v6.0, commit 6f8191fdf41d ("block: simplify disk shutdown") + # renamed the function blk_cleanup_disk() to blk_mq_destroy_queue(). + # + CODE=" + #include + void conftest_blk_mq_destroy_queue(void) { + blk_mq_destroy_queue(); + }" + + compile_check_conftest "$CODE" "NV_BLK_MQ_DESTROY_QUEUE_PRESENT" "" "functions" + ;; + block_device_operations_open_has_gendisk_arg) # # Determine if the 'open' function pointer from the @@ -6444,6 +6514,24 @@ compile_test() { compile_check_conftest "$CODE" "NV_DEFINE_SEMAPHORE_HAS_NUMBER_ARG" "" "types" ;; + device_add_disk_has_int_return_type) + # + # Determine if the function device_add_disk() returns an integer. + # + # In Linux v5.15, commit 83cbce957446 ("block: add error handling + # for device_add_disk / add_disk") updated the function + # device_add_disk() to return an integer. + # + CODE=" + #include + int conftest_device_add_disk_has_int_return_type(struct device *dev, + struct gendisk *disk) { + return device_add_disk(dev, disk, NULL); + }" + + compile_check_conftest "$CODE" "NV_DEVICE_ADD_DISK_HAS_INT_RETURN_TYPE" "" "types" + ;; + devm_thermal_of_zone_register) # # Determine whether devm_thermal_of_zone_register is present.