From b4a937788cead345f8f00419bd250d1d92b0290f Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Wed, 1 Oct 2025 11:54:47 -0400 Subject: Fix build warnings and errors on Linux 6.14 - Remove repetitive declarations of two `bus_type` structs. - Fix mmu.c to use an always-64-bit member for `parent_addr`. - Remove call to `page_mapcount_reset()` that isn't needed. - Correct `nvdebug_pd_page` documentation. - Disable missing prototype and missing declaration warnings. - Fix an improper type, and a missing type conversion. Tested build on Linux 6.14.0 (x86_64), 5.4.0 (x86_64), and 4.9.337 (aarch64). --- Makefile | 3 ++- mmu.c | 27 +++++++++++++-------------- nvdebug.h | 2 +- nvdebug_entry.c | 2 -- stubs.h | 1 - 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 9d6d374..e7b160c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ obj-m += nvdebug.o nvdebug-objs = runlist_procfs.o device_info_procfs.o runlist.o mmu.o \ nvdebug_entry.o bus.o nvdebug_linux.o copy_topology_procfs.o -KBUILD_CFLAGS += -DGIT_HASH=\"$(shell git --git-dir=$(PWD)/.git rev-parse --short HEAD)\" +KBUILD_CFLAGS += -DGIT_HASH=\"$(shell git --git-dir=$(PWD)/.git rev-parse --short HEAD)\" \ + -Wno-missing-prototypes -Wno-missing-declarations # -mfentry above if not building due to mcount missing all: diff --git a/mmu.c b/mmu.c index e2b9a91..bab2ea0 100644 --- a/mmu.c +++ b/mmu.c @@ -229,19 +229,20 @@ int translate_page_directory(struct nvdebug_state *g, // explictly permitted (see linux/mm_types.h). This struct is thus used by // casting a pointer of struct page to a pointer of struct nvdebug_pd_page, // then accessing the associated fields. This pointer may also be freely cast -// back to a sturct page pointer. -// We have 24 (32-bit) or 44 (64-bit) bytes available in the page struct -// (according to the documentation on struct page). Our comments indicate what -// available parts of struct page we repurpose for our own needs. +// back to a struct page pointer. +// We have 20 (32-bit) or 40 (64-bit) bytes available in the page struct +// (according to the documentation on struct page). We use 20 (32-bit) or 28 +// (64-bit) bytes. Our comments indicate what available parts of struct page we +// repurpose for our own needs. struct nvdebug_pd_page { unsigned long __flags; // From struct page; do not touch! // Overlaps struct page.lru struct list_head list; // 4/8 bytes - // Overlaps struct page.mapping (and page.share on 32-bit) - uintptr_t parent_addr; // 8 bytes - // Overlaps struct page.share (page.private on 32-bit) + // Overlaps struct page.lru (and page.mapping on 32-bit) + uint64_t parent_addr; // 8 bytes + // Overlaps struct page.mapping (page.share on 32-bit) enum PD_TARGET parent_aperture; // 4 bytes - // Overlaps page.private (page.page_type on 32-bit) + // Overlaps page.mapping and page.share (page.private on 32-bit) dma_addr_t dma_addr; // 4/8 bytes }; @@ -262,12 +263,12 @@ int gc_page_directory(struct nvdebug_state *g, bool force) { // (This is depth-first because map_page_directory() always allocates and // pushes page directory allocations before page table allocations.) list_for_each_entry_safe_reverse(page, _page, &g->pd_allocs, list) { - printk_debug(KERN_DEBUG "[nvdebug] %s: Checking if page directory/table at %llx (SYS_MEM_?) with parent at %lx (%s) is unused...\n", __func__, page->dma_addr, page->parent_addr, pd_target_to_text(page->parent_aperture)); + printk_debug(KERN_DEBUG "[nvdebug] %s: Checking if page directory/table at %llx (SYS_MEM_?) with parent at %llx (%s) is unused...\n", __func__, page->dma_addr, page->parent_addr, pd_target_to_text(page->parent_aperture)); // Try to determine if we're still in-use. We consider ourselves // potentially in-use if our parent still points to us. parent_kva = pd_deref(g, page->parent_addr, page->parent_aperture); if (IS_ERR(parent_kva)) { - printk(KERN_ERR "[nvdebug] %s: Error resolving %#lx in GPU %s to a kernel-accessible address. Error %ld.\n", __func__, page->parent_addr, pd_target_to_text(page->parent_aperture), PTR_ERR(parent_kva)); + printk(KERN_ERR "[nvdebug] %s: Error resolving %#llx in GPU %s to a kernel-accessible address. Error %ld.\n", __func__, page->parent_addr, pd_target_to_text(page->parent_aperture), PTR_ERR(parent_kva)); return -ENOTRECOVERABLE; } // A NULL kva indicates parent no longer exists @@ -277,14 +278,12 @@ int gc_page_directory(struct nvdebug_state *g, bool force) { continue; // Free this page table/directory and delete our parent's pointer to us if (parent_entry.addr_w == (page->dma_addr >> 12)) { - printk(KERN_WARNING "[nvdebug] %s: Deleting page table/directory at %llx (SYS_MEM_?) with parent at %lx (%s) that may still be in-use!\n", __func__, page->dma_addr, page->parent_addr, pd_target_to_text(page->parent_aperture)); + printk(KERN_WARNING "[nvdebug] %s: Deleting page table/directory at %llx (SYS_MEM_?) with parent at %llx (%s) that may still be in-use!\n", __func__, page->dma_addr, page->parent_addr, pd_target_to_text(page->parent_aperture)); writeq(0, parent_kva); } // Unmap, zero, free, and remove from tracking (these all return void) dma_unmap_page(g->dev, page->dma_addr, PAGE_SIZE, DMA_TO_DEVICE); memset(page_to_virt((struct page*)page), 0, PAGE_SIZE); - // Necessary to reset mapcount as we (ab)use its state for other things - page_mapcount_reset((struct page*)page); // Same reset needed for mapping ((struct page*)page)->mapping = NULL; // Remove this page from our list of allocated pages @@ -607,7 +606,7 @@ int translate_v1_page_directory(struct nvdebug_state *g, // Convert VID_MEM/SYS_MEM address to Kernel-accessible Virtual Address (KVA) pte_kva = pd_deref(g, pte_phys, V12PD_TARGET(pde.alt_target)); if (IS_ERR_OR_NULL(pde_kva)) { - printk(KERN_ERR "[nvdebug] %s: Unable to resolve %#lx in GPU %s to a kernel-accessible address. Error %ld.\n", __func__, pte_phys, pd_target_to_text(pde.alt_target), PTR_ERR(pte_kva)); + printk(KERN_ERR "[nvdebug] %s: Unable to resolve %#lx in GPU %s to a kernel-accessible address. Error %ld.\n", __func__, pte_phys, pd_target_to_text(V12PD_TARGET(pde.alt_target)), PTR_ERR(pte_kva)); return PTR_ERR(pte_kva); } // Read page table entry diff --git a/nvdebug.h b/nvdebug.h index 3ac8db4..ecfb051 100644 --- a/nvdebug.h +++ b/nvdebug.h @@ -1620,7 +1620,7 @@ static inline const char *compute_preempt_type_to_text(enum COMPUTE_PREEMPT_TYPE return "INVALID"; } } -static inline const char *graphics_preempt_type_to_text(enum COMPUTE_PREEMPT_TYPE t) { +static inline const char *graphics_preempt_type_to_text(enum GRAPHICS_PREEMPT_TYPE t) { switch (t) { case PREEMPT_WFI: return "WFI"; diff --git a/nvdebug_entry.c b/nvdebug_entry.c index c0cfa63..8293fdc 100644 --- a/nvdebug_entry.c +++ b/nvdebug_entry.c @@ -48,8 +48,6 @@ extern struct file_operations copy_topology_file_ops; struct nvdebug_state g_nvdebug_state[NVDEBUG_MAX_DEVICES]; unsigned int g_nvdebug_devices = 0; -// Bus types are global symbols in the kernel -extern struct bus_type platform_bus_type; // Starting in Kernel 5.6, proc_ops is required instead of file_operations. // As file_operations is larger than proc_ops, we can overwrite the memory diff --git a/stubs.h b/stubs.h index b909587..da14bed 100644 --- a/stubs.h +++ b/stubs.h @@ -29,7 +29,6 @@ pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev) // Functions from drivers/pci/search.h #include #include -extern struct bus_type pci_bus_type; #if LINUX_VERSION_CODE < KERNEL_VERSION(5,3,0) static int match_pci_dev_by_id(struct device *dev, void *data) -- cgit v1.2.2