Problems with nvidia-dkms-515 configuration

I am encountering errors with configuring nvidia graphics driver, due to an error processing nvidia-dkms-515.
I believe this may be due to a mismatch between the gcc compiler, but I am unable to fix it. Can someone please help me?

Here’s the error I am getting when I run $sudo apt install build-essential

$sudo apt install build-essential
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (12.9ubuntu3).
0 upgraded, 0 newly installed, 0 to remove and 190 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up nvidia-dkms-515 (515.65.01-0ubuntu0.22.04.1) ...
update-initramfs: deferring update (trigger activated)
INFO:Enable nvidia
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
Removing old nvidia-515.65.01 DKMS files...
Deleting module nvidia-515.65.01 completely from the DKMS tree.
Loading new nvidia-515.65.01 DKMS files...
Building for 5.15.0-48-generic
Building for architecture x86_64
Building initial module for 5.15.0-48-generic
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/nvidia-kernel-source-515.0.crash'
Error! Bad return status for module build on kernel: 5.15.0-48-generic (x86_64)
Consult /var/lib/dkms/nvidia/515.65.01/build/make.log for more information.
dpkg: error processing package nvidia-dkms-515 (--configure):
 installed nvidia-dkms-515 package post-installation script subprocess returned error exit status 10
dpkg: dependency problems prevent configuration of nvidia-driver-515:
 nvidia-driver-515 depends on nvidia-dkms-515 (<= 515.65.01-1); however:
  Package nvidia-dkms-515 is not configured yet.
 nvidia-driver-515 depends on nvidia-dkms-515 (>= 515.65.01); however:
  Package nvidia-dkms-515 is not configured yet.

dpkg: error processing package nvidia-driver-515 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                  Processing triggers for initramfs-tools (0.140ubuntu13) ...
update-initramfs: Generating /boot/initrd.img-5.15.0-48-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/ubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Errors were encountered while processing:
 nvidia-dkms-515
 nvidia-driver-515
E: Sub-process /usr/bin/dpkg returned an error code (1)

I have appended the contents of make.log at the bottom of this message (/var/lib/dkms/nvidia/515.65.01/build/make.log)

Within make.log, the line that indicates error according to me:
cc: error: unrecognized command-line option ‘-mharden-sls=all’
Although other things could be wrong that I am not catching. There is also a warning that:

  warning: the compiler differs from the one used to build the kernel
  The kernel was built by: gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
  You are using:           cc (GCC) 11.2.0

I tried reinstalling gcc using

$ sudo apt remove gcc
$ sudo apt install build-essential

but my errors are not resolved yet, and gcc version is as shown below.

Here are my system details:

$uname -m && cat /etc/*release
		NAME="Ubuntu"
		VERSION_ID="22.04"
		VERSION="22.04 LTS (Jammy Jellyfish)"

$gcc --version
gcc (GCC) 11.2.0

$lspci | grep -i nvidia
		41:00.0 VGA compatible controller: NVIDIA Corporation TU106 [GeForce RTX 2060 SUPER] (rev a1)
		41:00.1 Audio device: NVIDIA Corporation TU106 High Definition Audio Controller (rev a1)
		41:00.2 USB controller: NVIDIA Corporation TU106 USB 3.1 Host Controller (rev a1)
		41:00.3 Serial bus controller: NVIDIA Corporation TU106 USB Type-C UCSI Controller (rev a1)

$uname -r 
		5.15.0-48-generic

Contents of make.log

Fri Sep 23 06:23:35 PM CDT 2022
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-48-generic'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || (		\
echo >&2;							\
echo >&2 "  ERROR: Kernel configuration is invalid.";		\
echo >&2 "         include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it.";	\
echo >&2 ;							\
/bin/false)
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
  You are using:           cc (GCC) 11.2.0
make -f ./scripts/Makefile.build obj=/var/lib/dkms/nvidia/515.65.01/build \
single-build= \
need-builtin=1 need-modorder=1
  ln -sf /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-kernel.o_binary /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-kernel.o
  ln -sf /var/lib/dkms/nvidia/515.65.01/build/nvidia-modeset/nv-modeset-kernel.o_binary /var/lib/dkms/nvidia/515.65.01/build/nvidia-modeset/nv-modeset-kernel.o
 CONFTEST: hash__remap_4k_pfn
 CONFTEST: set_pages_uc
 CONFTEST: list_is_first
 CONFTEST: set_memory_uc
 CONFTEST: set_memory_array_uc
 CONFTEST: set_pages_array_uc
 CONFTEST: ioremap_cache
 CONFTEST: ioremap_wc
 CONFTEST: sg_alloc_table
 CONFTEST: pci_get_domain_bus_and_slot
 CONFTEST: get_num_physpages
 CONFTEST: efi_enabled
 CONFTEST: pde_data
 CONFTEST: proc_remove
 CONFTEST: pm_vt_switch_required
 CONFTEST: xen_ioemu_inject_msi
 CONFTEST: phys_to_dma
 CONFTEST: get_dma_ops
 CONFTEST: dma_attr_macros
 CONFTEST: dma_map_page_attrs
 CONFTEST: write_cr4
 CONFTEST: of_get_property
 CONFTEST: of_find_node_by_phandle
 CONFTEST: of_node_to_nid
 CONFTEST: pnv_pci_get_npu_dev
 CONFTEST: of_get_ibm_chip_id
 CONFTEST: pci_bus_address
 CONFTEST: pci_stop_and_remove_bus_device
 CONFTEST: pci_remove_bus_device
 CONFTEST: cpuhp_setup_state
 CONFTEST: register_cpu_notifier
 CONFTEST: dma_map_resource
 CONFTEST: get_backlight_device_by_name
 CONFTEST: timer_setup
 CONFTEST: pci_enable_msix_range
 CONFTEST: kernel_read_has_pointer_pos_arg
 CONFTEST: kernel_write
 CONFTEST: kthread_create_on_node
 CONFTEST: of_find_matching_node
 CONFTEST: dev_is_pci
 CONFTEST: dma_direct_map_resource
 CONFTEST: tegra_get_platform
 CONFTEST: tegra_bpmp_send_receive
 CONFTEST: flush_cache_all
 CONFTEST: vmf_insert_pfn
 CONFTEST: jiffies_to_timespec
 CONFTEST: ktime_get_raw_ts64
 CONFTEST: ktime_get_real_ts64
 CONFTEST: full_name_hash
 CONFTEST: hlist_for_each_entry
 CONFTEST: pci_enable_atomic_ops_to_root
 CONFTEST: vga_tryget
 CONFTEST: pgprot_decrypted
 CONFTEST: cc_mkdec
 CONFTEST: iterate_fd
 CONFTEST: seq_read_iter
 CONFTEST: sg_page_iter_page
 CONFTEST: unsafe_follow_pfn
 CONFTEST: drm_gem_object_get
 CONFTEST: drm_gem_object_put_unlocked
 CONFTEST: set_close_on_exec
 CONFTEST: add_memory_driver_managed
 CONFTEST: device_property_read_u64
 CONFTEST: devm_of_platform_populate
 CONFTEST: of_dma_configure
 CONFTEST: of_property_count_elems_of_size
 CONFTEST: of_property_read_variable_u8_array
 CONFTEST: i2c_new_client_device
 CONFTEST: i2c_unregister_device
 CONFTEST: of_get_named_gpio
 CONFTEST: devm_gpio_request_one
 CONFTEST: gpio_direction_input
 CONFTEST: gpio_direction_output
 CONFTEST: gpio_get_value
 CONFTEST: gpio_set_value
 CONFTEST: gpio_to_irq
 CONFTEST: icc_get
 CONFTEST: icc_put
 CONFTEST: icc_set_bw
 CONFTEST: dma_buf_export_args
 CONFTEST: dma_buf_ops_has_kmap
 CONFTEST: dma_buf_ops_has_kmap_atomic
 CONFTEST: dma_buf_ops_has_map
 CONFTEST: dma_buf_ops_has_map_atomic
 CONFTEST: dma_buf_has_dynamic_attachment
 CONFTEST: dma_buf_attachment_has_peer2peer
 CONFTEST: dma_set_mask_and_coherent
 CONFTEST: get_task_ioprio
 CONFTEST: address_space_init_once
 CONFTEST: vzalloc
 CONFTEST: wait_on_bit_lock_argument_count
 CONFTEST: bitmap_clear
 CONFTEST: usleep_range
 CONFTEST: radix_tree_empty
 CONFTEST: radix_tree_replace_slot
 CONFTEST: pnv_npu2_init_context
 CONFTEST: cpumask_of_node
 CONFTEST: ioasid_get
 CONFTEST: migrate_vma_setup
 CONFTEST: drm_dev_unref
 CONFTEST: drm_reinit_primary_mode_group
 CONFTEST: get_user_pages_remote
 CONFTEST: get_user_pages
 CONFTEST: drm_gem_object_lookup
 CONFTEST: drm_atomic_state_ref_counting
 CONFTEST: drm_driver_has_gem_prime_res_obj
 CONFTEST: drm_atomic_helper_connector_dpms
 CONFTEST: drm_connector_funcs_have_mode_in_name
 CONFTEST: drm_framebuffer_get
 CONFTEST: drm_dev_put
 CONFTEST: drm_format_num_planes
 CONFTEST: drm_connector_for_each_possible_encoder
 CONFTEST: drm_rotation_available
 CONFTEST: drm_vma_offset_exact_lookup_locked
 CONFTEST: nvhost_dma_fence_unpack
 CONFTEST: is_export_symbol_gpl_of_node_to_nid
 CONFTEST: is_export_symbol_gpl_sme_active
 CONFTEST: is_export_symbol_present_swiotlb_map_sg_attrs
 CONFTEST: is_export_symbol_present_swiotlb_dma_ops
 CONFTEST: is_export_symbol_present___close_fd
 CONFTEST: is_export_symbol_present_close_fd
 CONFTEST: is_export_symbol_present_get_unused_fd
 CONFTEST: is_export_symbol_present_get_unused_fd_flags
 CONFTEST: is_export_symbol_present_nvhost_get_default_device
 CONFTEST: is_export_symbol_present_nvhost_syncpt_unit_interface_get_byte_offset
 CONFTEST: is_export_symbol_present_nvhost_syncpt_unit_interface_get_aperture
 CONFTEST: is_export_symbol_present_tegra_dce_register_ipc_client
 CONFTEST: is_export_symbol_present_tegra_dce_unregister_ipc_client
 CONFTEST: is_export_symbol_present_tegra_dce_client_ipc_send_recv
 CONFTEST: is_export_symbol_present_dram_clk_to_mc_clk
 CONFTEST: is_export_symbol_present_get_dram_num_channels
 CONFTEST: is_export_symbol_present_tegra_dram_types
 CONFTEST: is_export_symbol_present_pxm_to_node
 CONFTEST: is_export_symbol_present_int_active_memcg
 CONFTEST: is_export_symbol_present_kthread_create_on_node
 CONFTEST: file_operations
 CONFTEST: kuid_t
 CONFTEST: dma_ops
 CONFTEST: swiotlb_dma_ops
 CONFTEST: noncoherent_swiotlb_dma_ops
 CONFTEST: vm_fault_has_address
 CONFTEST: vm_insert_pfn_prot
 CONFTEST: vmf_insert_pfn_prot
 CONFTEST: vm_ops_fault_removed_vma_arg
 CONFTEST: vmbus_channel_has_ringbuffer_page
 CONFTEST: device_driver_of_match_table
 CONFTEST: device_of_node
 CONFTEST: node_states_n_memory
 CONFTEST: kmem_cache_has_kobj_remove_work
 CONFTEST: sysfs_slab_unlink
 CONFTEST: proc_ops
 CONFTEST: timespec64
 CONFTEST: vmalloc_has_pgprot_t_arg
 CONFTEST: mm_has_mmap_lock
 CONFTEST: pci_channel_state
 CONFTEST: pci_dev_has_ats_enabled
 CONFTEST: mt_device_gre
 CONFTEST: remove_memory_has_nid_arg
 CONFTEST: add_memory_driver_managed_has_mhp_flags_arg
 CONFTEST: address_space
 CONFTEST: backing_dev_info
 CONFTEST: mm_context_t
 CONFTEST: vm_fault_t
 CONFTEST: mmu_notifier_ops_invalidate_range
 CONFTEST: migrate_vma_added_flags
 CONFTEST: make_device_exclusive_range
 CONFTEST: drm_bus_present
 CONFTEST: drm_bus_has_bus_type
 CONFTEST: drm_bus_has_get_irq
 CONFTEST: drm_bus_has_get_name
 CONFTEST: drm_driver_has_device_list
 CONFTEST: drm_driver_has_legacy_dev_list
 CONFTEST: drm_driver_has_set_busid
 CONFTEST: drm_crtc_state_has_connectors_changed
 CONFTEST: drm_init_function_args
 CONFTEST: drm_helper_mode_fill_fb_struct
 CONFTEST: drm_master_drop_has_from_release_arg
 CONFTEST: drm_driver_unload_has_int_return_type
 CONFTEST: drm_atomic_helper_crtc_destroy_state_has_crtc_arg
 CONFTEST: drm_atomic_helper_plane_destroy_state_has_plane_arg
 CONFTEST: drm_mode_object_find_has_file_priv_arg
 CONFTEST: dma_buf_owner
 CONFTEST: drm_connector_list_iter
 CONFTEST: drm_atomic_helper_swap_state_has_stall_arg
 CONFTEST: drm_driver_prime_flag_present
 CONFTEST: drm_gem_object_has_resv
 CONFTEST: drm_crtc_state_has_async_flip
 CONFTEST: drm_crtc_state_has_pageflip_flags
 CONFTEST: drm_format_modifiers_present
 CONFTEST: drm_vma_node_is_allowed_has_tag_arg
 CONFTEST: drm_vma_offset_node_has_readonly
 CONFTEST: drm_display_mode_has_vrefresh
 CONFTEST: drm_driver_master_set_has_int_return_type
 CONFTEST: drm_driver_has_gem_free_object
 CONFTEST: drm_prime_pages_to_sg_has_drm_device_arg
 CONFTEST: drm_driver_has_gem_prime_callbacks
 CONFTEST: drm_crtc_atomic_check_has_atomic_state_arg
 CONFTEST: drm_gem_object_vmap_has_map_arg
 CONFTEST: drm_plane_atomic_check_has_atomic_state_arg
 CONFTEST: drm_device_has_pdev
 CONFTEST: drm_crtc_state_has_no_vblank
 CONFTEST: drm_mode_config_has_allow_fb_modifiers
 CONFTEST: dma_resv_add_fence
 CONFTEST: dma_resv_reserve_fences
 CONFTEST: reservation_object_reserve_shared_has_num_fences_arg
 CONFTEST: dom0_kernel_present
 CONFTEST: nvidia_vgpu_kvm_build
 CONFTEST: nvidia_grid_build
 CONFTEST: nvidia_grid_csp_build
 CONFTEST: pm_runtime_available
 CONFTEST: pci_class_multimedia_hd_audio
 CONFTEST: drm_available
 CONFTEST: drm_atomic_available
 CONFTEST: is_export_symbol_gpl_refcount_inc
 CONFTEST: is_export_symbol_gpl_refcount_dec_and_test
 CONFTEST: drm_alpha_blending_available
 CONFTEST: ib_peer_memory_symbols
  cc -Wp,-MMD,/var/lib/dkms/nvidia/515.65.01/build/nvidia/.nv.o.d -nostdinc -isystem /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -I./ubuntu/include -include ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -DCONFIG_X86_X32_ABI -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mfunction-return=thunk-extern -fno-jump-tables -mharden-sls=all -fno-delete-null-pointer-checks -O2 -Wframe-larger-than=1024 -fstack-protector-strong -Wno-main -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -gdwarf-5 -pg -mrecord-mcount -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-array-bounds -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -I/var/lib/dkms/nvidia/515.65.01/build/common/inc -I/var/lib/dkms/nvidia/515.65.01/build -Wall -MD -Wno-cast-qual -Wno-error -Wno-format-extra-args -D__KERNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\"515.65.01\" -Wno-unused-function -Wuninitialized -fno-strict-aliasing -ffreestanding -mno-red-zone -mcmodel=kernel -DNV_UVM_ENABLE -DNV_SPECTRE_V2=0 -DNV_KERNEL_INTERFACE_LAYER -I/var/lib/dkms/nvidia/515.65.01/build/nvidia -DNVIDIA_UNDEF_LEGACY_BIT_MACROS -UDEBUG -U_DEBUG -DNDEBUG  -fsanitize=bounds -fsanitize=shift -fsanitize=bool -fsanitize=enum  -DMODULE  -DKBUILD_BASENAME='"nv"' -DKBUILD_MODNAME='"nvidia"' -D__KBUILD_MODNAME=kmod_nvidia -c -o /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv.o /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv.c
  cc -Wp,-MMD,/var/lib/dkms/nvidia/515.65.01/build/nvidia/.nv-pci.o.d -nostdinc -isystem /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -I./ubuntu/include -include ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -DCONFIG_X86_X32_ABI -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mfunction-return=thunk-extern -fno-jump-tables -mharden-sls=all -fno-delete-null-pointer-checks -O2 -Wframe-larger-than=1024 -fstack-protector-strong -Wno-main -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -gdwarf-5 -pg -mrecord-mcount -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-array-bounds -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -I/var/lib/dkms/nvidia/515.65.01/build/common/inc -I/var/lib/dkms/nvidia/515.65.01/build -Wall -MD -Wno-cast-qual -Wno-error -Wno-format-extra-args -D__KERNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\"515.65.01\" -Wno-unused-function -Wuninitialized -fno-strict-aliasing -ffreestanding -mno-red-zone -mcmodel=kernel -DNV_UVM_ENABLE -DNV_SPECTRE_V2=0 -DNV_KERNEL_INTERFACE_LAYER -I/var/lib/dkms/nvidia/515.65.01/build/nvidia -DNVIDIA_UNDEF_LEGACY_BIT_MACROS -UDEBUG -U_DEBUG -DNDEBUG  -fsanitize=bounds -fsanitize=shift -fsanitize=bool -fsanitize=enum  -DMODULE  -DKBUILD_BASENAME='"nv_pci"' -DKBUILD_MODNAME='"nvidia"' -D__KBUILD_MODNAME=kmod_nvidia -c -o /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-pci.o /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-pci.c
  cc -Wp,-MMD,/var/lib/dkms/nvidia/515.65.01/build/nvidia/.nv-dmabuf.o.d -nostdinc -isystem /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -I./ubuntu/include -include ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -DCONFIG_X86_X32_ABI -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mfunction-return=thunk-extern -fno-jump-tables -mharden-sls=all -fno-delete-null-pointer-checks -O2 -Wframe-larger-than=1024 -fstack-protector-strong -Wno-main -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -gdwarf-5 -pg -mrecord-mcount -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-array-bounds -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -I/var/lib/dkms/nvidia/515.65.01/build/common/inc -I/var/lib/dkms/nvidia/515.65.01/build -Wall -MD -Wno-cast-qual -Wno-error -Wno-format-extra-args -D__KERNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\"515.65.01\" -Wno-unused-function -Wuninitialized -fno-strict-aliasing -ffreestanding -mno-red-zone -mcmodel=kernel -DNV_UVM_ENABLE -DNV_SPECTRE_V2=0 -DNV_KERNEL_INTERFACE_LAYER -I/var/lib/dkms/nvidia/515.65.01/build/nvidia -DNVIDIA_UNDEF_LEGACY_BIT_MACROS -UDEBUG -U_DEBUG -DNDEBUG  -fsanitize=bounds -fsanitize=shift -fsanitize=bool -fsanitize=enum  -DMODULE  -DKBUILD_BASENAME='"nv_dmabuf"' -DKBUILD_MODNAME='"nvidia"' -D__KBUILD_MODNAME=kmod_nvidia -c -o /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-dmabuf.o /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-dmabuf.c
  cc -Wp,-MMD,/var/lib/dkms/nvidia/515.65.01/build/nvidia/.nv-acpi.o.d -nostdinc -isystem /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -I./ubuntu/include -include ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -DCONFIG_X86_X32_ABI -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mfunction-return=thunk-extern -fno-jump-tables -mharden-sls=all -fno-delete-null-pointer-checks -O2 -Wframe-larger-than=1024 -fstack-protector-strong -Wno-main -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -gdwarf-5 -pg -mrecord-mcount -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-array-bounds -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -I/var/lib/dkms/nvidia/515.65.01/build/common/inc -I/var/lib/dkms/nvidia/515.65.01/build -Wall -MD -Wno-cast-qual -Wno-error -Wno-format-extra-args -D__KERNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\"515.65.01\" -Wno-unused-function -Wuninitialized -fno-strict-aliasing -ffreestanding -mno-red-zone -mcmodel=kernel -DNV_UVM_ENABLE -DNV_SPECTRE_V2=0 -DNV_KERNEL_INTERFACE_LAYER -I/var/lib/dkms/nvidia/515.65.01/build/nvidia -DNVIDIA_UNDEF_LEGACY_BIT_MACROS -UDEBUG -U_DEBUG -DNDEBUG  -fsanitize=bounds -fsanitize=shift -fsanitize=bool -fsanitize=enum  -DMODULE  -DKBUILD_BASENAME='"nv_acpi"' -DKBUILD_MODNAME='"nvidia"' -D__KBUILD_MODNAME=kmod_nvidia -c -o /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-acpi.o /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-acpi.c
cc: error: unrecognized command-line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv.o] Error 1
make[2]: *** Waiting for unfinished jobs....
cc: error: unrecognized command-line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-dmabuf.o] Error 1
cc: error: unrecognized command-line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-pci.o] Error 1
cc: error: unrecognized command-line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/515.65.01/build/nvidia/nv-acpi.o] Error 1
make[1]: *** [Makefile:1884: /var/lib/dkms/nvidia/515.65.01/build] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-48-generic'
make: *** [Makefile:82: modules] Error 2

unrecognized command-line option ‘-mharden-sls=all’ points to the kernel being compiled with latest cpu bug mitigations but the compiler being too old. Vanilla gcc introduced it in 11.3/12.1. Though I don’t know if Ubuntu included it in a patch for their 11.2. Better also ask in the Ubuntu forums, I find it rather odd this is happening.