libpciaccess issueshttps://gitlab.freedesktop.org/xorg/lib/libpciaccess/-/issues2024-02-06T21:37:10Zhttps://gitlab.freedesktop.org/xorg/lib/libpciaccess/-/issues/190.18: deprecation warning2024-02-06T21:37:10ZTomasz Kłoczko0.18: deprecation warningAfter remove all hardcoded warning flags using below patch
<details>
<summary>patch</summary>
```patch
--- a/meson.build
+++ b/meson.build
@@ -29,40 +29,6 @@
c = meson.get_compiler('c')
-add_project_arguments(
- c.get_supported_arg...After remove all hardcoded warning flags using below patch
<details>
<summary>patch</summary>
```patch
--- a/meson.build
+++ b/meson.build
@@ -29,40 +29,6 @@
c = meson.get_compiler('c')
-add_project_arguments(
- c.get_supported_arguments(
- '-Wpointer-arith',
- '-Wmissing-declarations',
- '-Wformat=2',
- '-Wstrict-prototypes',
- '-Wmissing-prototypes',
- '-Wnested-externs',
- '-Wbad-function-cast',
- '-Wold-style-definition',
- '-Wdeclaration-after-statement',
- '-Wunused',
- '-Wuninitialized',
- '-Wshadow',
- '-Wmissing-noreturn',
- '-Wmissing-format-attribute',
- '-Wredundant-decls',
- '-Wlogical-op',
- '-Werror=implicit',
- '-Werror=nonnull',
- '-Werror=init-self',
- '-Werror=main',
- '-Werror=missing-braces',
- '-Werror=sequence-point',
- '-Werror=return-type',
- '-Werror=trigraphs',
- '-Werror=array-bounds',
- '-Werror=write-strings',
- '-Werror=address',
- '-Werror=int-to-pointer-cast',
- ),
- language : 'c'
-)
-
config = configuration_data()
config.set_quoted(
```
</summary></details>
it is possible to see some
<details>
<summary>warning</summary>
```console
../src/common_init.c: In function ‘pci_system_cleanup’:
../src/common_init.c:108:17: warning: ‘pci_device_unmap_region’ is deprecated [-Wdeprecated-declarations]
108 | (void) pci_device_unmap_region( & pci_sys->devices[i].base, j );
| ^
In file included from ../src/common_init.c:38:
../include/pciaccess.h:88:18: note: declared here
88 | int __deprecated pci_device_unmap_region(struct pci_device *dev,
| ^~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘pci_device_linux_sysfs_write8’:
../src/linux_sysfs.c:988:13: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
988 | pwrite(handle->fd, &data, 1, port + handle->base);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c:990:13: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
990 | pwrite(handle->fd, &data, 1, port);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘pci_device_linux_sysfs_write16’:
../src/linux_sysfs.c:974:13: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
974 | pwrite(handle->fd, &data, 2, port + handle->base);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c:976:13: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
976 | pwrite(handle->fd, &data, 2, port);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘pci_device_linux_sysfs_write32’:
../src/linux_sysfs.c:960:13: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
960 | pwrite(handle->fd, &data, 4, port + handle->base);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c:962:13: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
962 | pwrite(handle->fd, &data, 4, port);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘pci_device_linux_sysfs_read8’:
../src/linux_sysfs.c:944:13: warning: ignoring return value of ‘pread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
944 | pread(handle->fd, &ret, 1, port + handle->base);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c:946:13: warning: ignoring return value of ‘pread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
946 | pread(handle->fd, &ret, 1, port);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘pci_device_linux_sysfs_read16’:
../src/linux_sysfs.c:927:13: warning: ignoring return value of ‘pread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
927 | pread(handle->fd, &ret, 2, port + handle->base);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c:929:13: warning: ignoring return value of ‘pread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
929 | pread(handle->fd, &ret, 2, port);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘pci_device_linux_sysfs_read32’:
../src/linux_sysfs.c:910:13: warning: ignoring return value of ‘pread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
910 | pread(handle->fd, &ret, 4, port + handle->base);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c:912:13: warning: ignoring return value of ‘pread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
912 | pread(handle->fd, &ret, 4, port);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘pci_device_linux_sysfs_set_enable’:
../src/linux_sysfs.c:774:5: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
774 | write( fd, enable ? "1" : "0" , 1 );
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘pci_device_linux_sysfs_read_rom’:
../src/linux_sysfs.c:418:5: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
418 | write( fd, "1", 1 );
| ^~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c:437:5: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
437 | write( fd, "0", 1 );
| ^~~~~~~~~~~~~~~~~~~
../src/linux_sysfs.c: In function ‘parse_separate_sysfs_files’:
../src/linux_sysfs.c:169:9: warning: ignoring return value of ‘read’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
169 | read(fd, resource, 512);
| ^~~~~~~~~~~~~~~~~~~~~~~
```
</details>
It would be really good to make use of those warnings flags optional or use ten only with `--buildtype=devel` or use these flags only in CI by call meson `CFLAGS="<all_warnings_flags>" meson <meson_options>` because:
- some of those flags are masking important warnings
- on packaging prod packages use those flags only makes build log longerhttps://gitlab.freedesktop.org/xorg/lib/libpciaccess/-/issues/6pci_system_{init,cleanup} aren't reference-counted2019-07-11T16:25:01ZBugzilla Migration Userpci_system_{init,cleanup} aren't reference-counted## Submitted by Vitaliy Filippov
Assigned to **Xorg Project Team**
**[Link to original bug (#84325)](https://bugs.freedesktop.org/show_bug.cgi?id=84325)**
## Description
Created attachment 106847
Patch for libpciaccess
On my lapt...## Submitted by Vitaliy Filippov
Assigned to **Xorg Project Team**
**[Link to original bug (#84325)](https://bugs.freedesktop.org/show_bug.cgi?id=84325)**
## Description
Created attachment 106847
Patch for libpciaccess
On my laptop with 2 graphics cards (integrated Intel + discrete Radeon 8770M) X.Org crashes in the very beginning of DE startup. I.e I enter my login and password in the display manager (which starts fine), and after that KDE splashscreen shows up, and X crashes right after showing the first icon on KDE splashscreen. The same is with XFCE, X crashes during its startup.
Stack trace:
```
Program received signal SIGSEGV, Segmentation fault.
0x00007fbc716b197c in pci_device_vgaarb_set_target (dev=0x0) at ../../src/common_vgaarb.c:230
230 dev = pci_sys->vga_default_dev;
(gdb) bt
#0 0x00007fbc716b197c in pci_device_vgaarb_set_target (dev=0x0) at ../../src/common_vgaarb.c:230
#1 0x00007fbc724ad700 in xf86VGAarbiterLock (pScrn=pScrn@entry=0x7fbc72b09af0) at ../../../../hw/xfree86/common/xf86VGAarbiter.c:92
#2 0x00007fbc7248ac30 in DPMSSetScreen (pScrn=0x7fbc72b09af0, level=0) at ../../../../hw/xfree86/common/xf86DPMS.c:141
#3 0x00007fbc7248af26 in DPMSSet (client=<optimized out>, level=level@entry=0) at ../../../../hw/xfree86/common/xf86DPMS.c:176
#4 0x00007fbc72505a6b in ProcDPMSDisable (client=<optimized out>) at ../../Xext/dpms.c:159
#5 ProcDPMSDispatch (client=<optimized out>) at ../../Xext/dpms.c:227
#6 0x00007fbc7244cf07 in Dispatch () at ../../dix/dispatch.c:432
#7 0x00007fbc72451096 in dix_main (argc=10, argv=0x7fff6e319c88, envp=<optimized out>) at ../../dix/main.c:296
#8 0x00007fbc7010ab45 in __libc_start_main (main=0x7fbc7243b4e0 <main>, argc=10, argv=0x7fff6e319c88, init=<optimized out>,
fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fff6e319c78) at libc-start.c:287
#9 0x00007fbc7243b50e in _start ()
```
This is caused by a null-pointer dereference in libpciaccess: X.Org tries to call pci_device_vgaarb_set_target(), but pci_sys is NULL at that point. This is caused by use of pci_system_init() and pci_system_cleanup() by libdrm-intel in function drm_intel_probe_agp_aperture_size() from intel_bufmgr.c.
X.Org calls pci_system_init() in the very beginning, then libdrm-intel also calls pci_system_init(). libpciaccess just blindly accepts the second call and does the initialisation one more time (which also makes the previous pci_sys instance leak). Then libdrm-intel calls pci_system_cleanup() and libpciaccess again accepts this call and frees pci_sys.
After some time, X.Org tries to use libpciaccess, but pci_sys is already freed, which leads to a crash.
The solution that first came to my mind is to "reference count" init/cleanup calls so real init doesn't happen twice, and real cleanup doesn't happen until the last user calls it. Maybe there is a more proper way to fix it (for example maybe libdrm-intel should be fixed?), but I'm attaching the patch with my fix; X.Org crash goes away after rebuilding libpciaccess with it...
My system is Debian, kernel is 3.16.2 amd64, X.org is 1.16.0, libpciaccess is 0.13.2, mesa is 10.4-dev from oibaf PPA. Also filed this bug as https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=761445
**Patch 106847**, "Patch for libpciaccess":
[patch-libpciaccess-pci_sys-refcnt.diff](/uploads/1c2ae6d376a1357d81f78baf8c439354/patch-libpciaccess-pci_sys-refcnt.diff)https://gitlab.freedesktop.org/xorg/lib/libpciaccess/-/issues/1Bad handling of some ROMs when using sysfs2019-03-10T23:04:32ZBugzilla Migration UserBad handling of some ROMs when using sysfs## Submitted by Pierre Willenbrock
Assigned to **Xorg Project Team**
**[Link to original bug (#19061)](https://bugs.freedesktop.org/show_bug.cgi?id=19061)**
## Description
Created attachment 21104
Make libpciaccess rom handling be...## Submitted by Pierre Willenbrock
Assigned to **Xorg Project Team**
**[Link to original bug (#19061)](https://bugs.freedesktop.org/show_bug.cgi?id=19061)**
## Description
Created attachment 21104
Make libpciaccess rom handling behave better
On my system, the "resource"-file for the graphics adapter reports a rom of 0 size, but the "rom"-file is 128k. This leads to rom_size == 0. Intel driver allocates a 64k buffer for read_rom in this case(normally, it allocates rom_size) and read_rom happily overwrites the data after those 64k with the rest of the rom.
This does not happen if rom_size is set to 128k and read_rom prevents reading more than advertised(which could still be samller than the size of the rom-file, if the rom-resource line says so).
```
->cat /sys/bus/pci/devices/0000\:00\:02.0/resource
0x00000000f8100000 0x00000000f81fffff 0x0000000000020204
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x00000000e0000000 0x00000000efffffff 0x000000000002120c
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000001800 0x0000000000001807 0x0000000000020101
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000002
->ls -l /sys/bus/pci/devices/0000\:00\:02.0/rom
-r-------- 1 root root 131072 12. Dez 19:03 /sys/bus/pci/devices/0000:00:02.0/rom
```
**Patch 21104**, "Make libpciaccess rom handling behave better":
[libpciaccess.patch](/uploads/48ce3477d5096c9b2bc4890e741e3417/libpciaccess.patch)
Version: git