Bug 266561 - x11/nvidia-driver: compiler error: nvidia_os.c:283:19: error: incompatible integer to pointer conversion
Summary: x11/nvidia-driver: compiler error: nvidia_os.c:283:19: error: incompatible in...
Status: In Progress
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: Alexey Dokuchaev
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2022-09-23 06:39 UTC by O. Hartmann
Modified: 2022-11-18 17:14 UTC (History)
9 users (show)

See Also:
bugzilla: maintainer-feedback? (danfe)


Attachments
Typescript of my latest attempt (25.22 KB, text/plain)
2022-11-11 19:39 UTC, david
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description O. Hartmann 2022-09-23 06:39:55 UTC
OS: recent 14-CURRENT (after commit 7ae99f80b6661760c5de3edd330b279f04b092a2)
driver: nvidia-driver-510.60.02

error:
[...]
cc  -O2 -pipe -fno-strict-aliasing -DNV_VERSION_STRING=\"510.60.02\" -D__KERNEL__ -DNVRM -Wno-unused-function -Wuninitialized -O2 -fno-strict-aliasing -mno-red-zone -mcmodel=kernel -UDEBUG -U_DEBUG -DNDEBUG -DNV_SPECTRE_V2=1 -DNV_KERNEL_INTERFACE_LAYER -Werror=undef  -Werror -D_KERNEL -DKLD_MODULE -nostdinc  -I. -I../common/inc -include /usr/ports/x11/nvidia-driver/work/NVIDIA-FreeBSD-x86_64-510.60.02/src/nvidia/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include -fdebug-prefix-map=./i386=/usr/src/sys/i386/include     -MD  -MF.depend.nvidia_os_registry.o -MTnvidia_os_registry.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c nvidia_os_registry.c -o nvidia_os_registry.o
--- nvidia_pci.o ---
--- nvidia_os.o ---
nvidia_os.c:283:19: error: incompatible integer to pointer conversion passing 'vm_offset_t' (aka 'unsigned long') to parameter of type 'void *' [-Werror,-Wint-conversion]
    pmap_unmapdev((vm_offset_t)address, size);
                  ^~~~~~~~~~~~~~~~~~~~
./machine/pmap.h:511:26: note: passing argument to parameter here
void    pmap_unmapdev(void *, vm_size_t);
Comment 1 Tomoaki AOKI 2022-09-23 08:33:12 UTC
This should be because of 2 commits on git src main below.

  [1] commit	7ae99f80b6661760c5de3edd330b279f04b092a2
      pmap_unmapdev/bios: Accept a pointer instead of a vm_offset_t.

  [2] commit	f49fd63a6a130ae464cdc7756e6f7d0d747c82c4
      kmem_malloc/free: Use void * instead of vm_offset_t for kernel pointers.


These have a dedicated bump with the commit below. So we can sanely use the __FreeBSD_version 1400070.

  [3] commit	6bddde307e21eba297ac3f3e534b4cf3be81dfe2
      Bump __FreeBSD_version for pmap_unmap*() and kmem_*() API changes.


Unfortunately, I have not enough workable time to investigate fix now.


[1] https://cgit.freebsd.org/src/commit/?id=7ae99f80b6661760c5de3edd330b279f04b092a2

[2] https://cgit.freebsd.org/src/commit/?id=f49fd63a6a130ae464cdc7756e6f7d0d747c82c4

[3] https://cgit.freebsd.org/src/commit/?id=6bddde307e21eba297ac3f3e534b4cf3be81dfe2
Comment 2 david 2022-09-23 13:08:20 UTC
Also affects x11/nvidia-driver-390:
cc  -O2 -pipe -fno-strict-aliasing -DNV_VERSION_STRING=\"390.151\" -D__KERNEL__ -DNVRM -Wno-unused-function -Wuninitialized -O2 -fno-strict-aliasing -mno-red-zone -mcmodel=kernel -Wno-sign-compare -Wno-format-extra-args -UDEBUG -U_DEBUG -DNDEBUG -DNV_SPECTRE_V2=1 -DNV_KERNEL_INTERFACE_LAYER -Werror=undef  -Werror -D_KERNEL -DKLD_MODULE -nostdinc  -I. -I../common/inc -include /common/S4/obj/usr/src/amd64.amd64/sys/CANARY/common/ports/x11/nvidia-driver-390/work/NVIDIA-FreeBSD-x86_64-390.151/src/nvidia/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include -fdebug-prefix-map=./i386=/usr/src/sys/i386/include     -MD  -MF.depend.nvidia_os.o -MTnvidia_os.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c nvidia_os.c -o nvidia_os.o
nvidia_os.c:280:19: error: incompatible integer to pointer conversion passing 'vm_offset_t' (aka 'unsigned long') to parameter of type 'void *' [-Werror,-Wint-conversion]
    pmap_unmapdev((vm_offset_t)address, size);
                  ^~~~~~~~~~~~~~~~~~~~
./machine/pmap.h:511:26: note: passing argument to parameter here
void    pmap_unmapdev(void *, vm_size_t);
                            ^
1 error generated.
*** Error code 1

Stop.
make[7]: stopped in /common/S4/obj/usr/src/amd64.amd64/sys/CANARY/common/ports/x11/nvidia-driver-390/work/NVIDIA-FreeBSD-x86_64-390.151/src/nvidia
*** Error code 1


[This was during source update from main-n258133-09ee0fc023c0 to main-n258156-f968cb140fcf with
PORTS_MODULES+=x11/nvidia-driver-390
in /etc/src.conf.]
Comment 3 John Baldwin freebsd_committer freebsd_triage 2022-09-23 16:34:09 UTC
I uploaded a review already for this immediately after the source commit that is waiting on maintainer approval: https://reviews.freebsd.org/D36671
Comment 4 Tomoaki AOKI 2022-09-24 01:26:06 UTC
(In reply to John Baldwin from comment #3)

Thanks! The patch on Phab D36671 you pointed worked fine for me.
Tried both on main at git 00d8a28f19b21ce2955c0cf24a040824ec506da5, amd64 and stable/13 (just to be sure nothing broken there) at 42538fde45d3d768be41b9f89777e0c8b278be20, amd64.

Both are on exactly the same hardware (installed on different physical drive on the same PC).

Tested only for x11/nvidia-driver only, but should work fine for all other x11/nvidia-driver-* ports, as they all are slave ports of x11/nvidia-driver that separately sets DISTVERSION, PORTREVISION and PKGNAMESUFFIX.
Comment 5 O. Hartmann 2022-09-24 06:08:17 UTC
The patch works for me too, but as the former comment also states, I only tested x11/nvidia-driver for nvidia-driver-510.60.02 and x11/nvidia-driver-515.76 (latest from mVidia for FreeBSD). It works so far.
Comment 6 Nuno Teixeira freebsd_committer freebsd_triage 2022-09-26 10:04:04 UTC
Just for curiosity, do we need to rebuild nvidia-drivers when tracking current?

For a long time that I only update nvidia pkg...

I will wait for review to fix current build and start using:
---
SYSDIR=path/to/src/sys
PORTS_MODULES=graphics/drm-kmod x11/nvidia-driver
---
this way I rebuild nvidia (dedicated) and intel (onboard).

Thanks
Comment 7 Kurt Jaeger freebsd_committer freebsd_triage 2022-09-27 08:40:00 UTC
(In reply to Nuno Teixeira from comment #6)
As far as I understand, only if the KBI changes in a way that affects
the interface between the kmod and the kernel. changes in the layout of structures etc. might trigger a need for a recompile.
Comment 8 Marcin Cieślak 2022-09-27 11:20:44 UTC
I have just managed to get my NVIDIA working again on main-9a7c520a781, using nvidia-driver-340 with this patch applied

This is Nvidia GeForce 9300M GS on Sony VAIO VGN-Z31VN

(I have to use custom acpi_call invocations to use the LCD screen of a laptop, but this is the same as before).
Comment 9 Marcin Cieślak 2022-09-27 11:22:39 UTC
Additional note - the binary driver built for -CURRENT eb45bc6829157 back in April 2022 DIDN'T work.

I think the machine panicked (typing blind "reset" rebooted it). Did the ABI change, too?
Comment 10 John Baldwin freebsd_committer freebsd_triage 2022-09-27 17:07:56 UTC
The commit in question (changing pmap_unmapdev()) did not change the ABI, but I'm sure there have been other ABI changes since April on main.  There is no guarantee of ABI stability on main.
Comment 11 david 2022-11-01 11:38:28 UTC
With the ports tree at main-n599463-b68905f365b9 (so jhb@'s patch is applied to ports/x11/nvidia-driver/Makefile), I still see:

nvidia_os.c:283:19: error: incompatible integer to pointer conversion passing 'vm_offset_t' (aka 'unsigned long') to parameter of type 'void *' [-Werror,-Wint-conversion]
    pmap_unmapdev((vm_offset_t)address, size);
                  ^~~~~~~~~~~~~~~~~~~~
./machine/pmap.h:476:26: note: passing argument to parameter here
void    pmap_unmapdev(void *, vm_size_t);
                            ^
1 error generated.
*** Error code 1

(source tree at main-n258958-c7631f9153b7).  My last successful build of head on a laptop (that uses x11/nvidia-driver) was:

FreeBSD 14.0-CURRENT #594 main-n258133-09ee0fc023c0: Thu Sep 22 11:03:49 UTC 2022     root@g1-70.catwhisker.org:/common/S4/obj/usr/src/amd64.amd64/sys/CANARY amd64 1400068 1400068

Last one on my headless build machine was:

FreeBSD 14.0-CURRENT #212 main-n258958-c7631f9153b: Tue Nov  1 11:03:03 UTC 2022     root@freebeast.catwhisker.org:/common/S4/obj/usr/src/amd64.amd64/sys/GENERIC amd64 1400073 1400073
Comment 12 John Baldwin freebsd_committer freebsd_triage 2022-11-01 21:26:23 UTC
(In reply to david from comment #11)
Hmmm, the ports patch should rewrite the pmap_unampdev line to remove the cast for OS versions >= 1400070, so I'm not sure why it isn't patching on the newer tree (that has a matching OS version).
Comment 13 david 2022-11-01 22:04:09 UTC
(In reply to John Baldwin from comment #12)
I'm happy to experiment, given a clue....
Comment 14 david 2022-11-11 19:39:18 UTC
Created attachment 238019 [details]
Typescript of my latest attempt

"gen_fbsd_git_tag" is a little shell script that mimics the logic newvers.sh uses to generate a string that identifies a commit (by default, HEAD) in a git repo.  The first invocation shows the state for /usr/src; the second, for /usr/ports.  I thought that providing some evidence might be of use -- or (possibly) of interest, at least.
Comment 15 david 2022-11-18 02:50:26 UTC
(In reply to John Baldwin from comment #12)
OK; I finally had some time to look at this.

Empirically, it seems that OSVERSION is derived from the running system, rather than the sources for what is (to be|being) built.  E.g.:

g1-48(14.0-C)[1] uname -aUK
FreeBSD g1-48.catwhisker.org 14.0-CURRENT FreeBSD 14.0-CURRENT #260 main-n258133-09ee0fc023c0: Thu Sep 22 11:02:41 UTC 2022     root@g1-48.catwhisker.org:/common/S4/obj/usr/src/amd64.amd64/sys/CANARY amd64 1400068 1400068
g1-48(14.0-C)[2] grep '^#define  *__FreeBSD_version' /usr/include/sys/param.h /usr/src/sys/sys/param.h
/usr/include/sys/param.h:#define __FreeBSD_version 1400068
/usr/src/sys/sys/param.h:#define __FreeBSD_version 1400073
g1-48(14.0-C)[3] make -C /usr/ports/x11/nvidia-driver -V OSVERSION
1400068
g1-48(14.0-C)[4] gen_fbsd_git_tag
main-n259278-9e6bbe47a503

So I suppose I need to build head once without the Nvidia driver; that done, then build x11/nvidia-driver.
Comment 16 John Baldwin freebsd_committer freebsd_triage 2022-11-18 17:09:36 UTC
Mmm, yes, that is the way that OSVERSION works, and in general kmod ports expect the two versions to be in sync.  Possibly the glue for building ports as part of buildkernel should override OSVERSION to be the version from the tree being built?
Comment 17 david 2022-11-18 17:14:29 UTC
(In reply to John Baldwin from comment #16)
I think that would help, particularly in the case of ports being built because they are added to the "PORTS_MODULES" variable.  Otherwise, we're rather missing the mark, I think.

Thanks for the response.