Commit Graph

144 Commits

Author SHA1 Message Date
Lennart Poettering
9da582984b udev: consider serial ports as unconfigured only if both port and iomem_base sysattr is zero
Various archs do not know the "io port" concept, hence check for the
"iomem" configuration, too.

Fixes: #34800
2024-10-17 18:59:38 +09:00
Yu Watanabe
548360817e
Merge pull request #34482 from bgurney-rh/alt-nvme-multins-symlink-fix
Pin obsolete NVMe symlinks to namespace 1
2024-10-16 10:05:46 +09:00
Uday Shankar
225ddc4a72 udev: allow persistent storage rules for ublk devices
Tools such as lsblk which query the udev database instead of probing
devices directly fail when run on ublk devices. For instance, in the
following commands, the partition type is missing, despite the fact that
/dev/ublkb0 was just partitioned with a single Linux filesystem type
partition.

$ lsblk /dev/ublkb0
NAME       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
ublkb0     259:0    0 31.3G  0 disk
└─ublkb0p1 259:1    0 31.2G  0 part
$ lsblk -o pkname,parttype /dev/ublkb0
PKNAME PARTTYPE

ublkb0

This happens because ublk devices are missing from a couple of
whitelists in the udev rules which are responsible for populating the
database with the data lsblk is looking for. Add the ublk devices to
these whitelists.
2024-10-11 10:29:26 +02:00
Peter Hutterer
305272ab2b logind: add support for hidraw devices
Add support for opening /dev/hidraw devices via logind's TakeDevice().
Same semantics as our support for evdev devices, but it requires the
HIDIOCREVOKE ioctl in the kernel.
2024-10-03 09:36:57 +01:00
Bryan Gurney
77d8f15262 Pin obsolete NVMe symlinks to namespace 1
In order to preserve backwards compatibility with legacy NVMe devices,
create the obsolete symlinks, but only if they are associated with
namespace ID 1.

Signed-off-by: Bryan Gurney <bgurney@redhat.com>
2024-09-18 15:38:14 -04:00
Karel Zak
eb360dd9a1 udev: allow persistent storage rules for zram devices
The /dev/zramN devices can be used as regular block devices. They are
typically used for swap areas, but it would be beneficial to have
LABEL and UUID in the udev database to make it more user-friendly for
tools such as lsblk or mount (if used with other filesystems).
2024-09-11 17:01:26 +02:00
Peter Rajnoha
cbe65d38cf udev: allow persistent storage rules for rbd devices
The RADOS Block Device (rbd) can be used as any other block device with
further layers on top of it, hence allow the common persistent storage
rules to apply, including watching for changes.
2024-09-06 08:26:44 +09:00
Chengen Du
6bd12be3fa udev: Handle PTP device symlink properly on udev action 'change'
PTP device symlink creation rules are currently executed only when the
udev action is 'add'. If a user reloads the rules and runs the udevadm
trigger command to reapply changes, the symlink may be deleted, which
can prevent the chronyd service from restarting properly.

Signed-off-by: Chengen Du <chengen.du@canonical.com>
2024-08-15 15:38:46 +09:00
vdovhanych
2cf425ec57 add udev rules for trezor hw wallet devices 2024-07-24 08:22:44 +01:00
Hans de Goede
fd820e76e4 rules: Add uaccess tag to /dev/udmabuf
In some cases userspace may need to create dmabuffers from userspace
on such example is the software ISP part of libcamera which needs to
allocate dma-buffers for the output of the software ISP.

At first the plan was to allow console users access to /dev/dma_heap/*,
this was discussed with various kernel folks here:
https://lore.kernel.org/all/bb372250-e8b8-4458-bc99-dd8365b06991@redhat.com/

Giving console users access to the dma_heap's was deemed a bad idea
because memory allocated this way is not accounted in cgroup limits.

Giving access to /dev/udmabuf OTOH was deemed acceptable so that
is what this patch adds.

Resolves: #32662
2024-07-17 09:36:45 +02:00
Ian Abbott
c8596cc640 udev: tag MTD devices for systemd
Allow systemd units to require/bind to MTD devices.  One use case is for
using a systemd service to attach an MTD device to an UBI controller,
which cannot be done until the MTD device has been probed.

Fixes #33096
2024-06-12 00:18:33 +01:00
Daan De Meyer
dc38f9addd rules: Limit the number of device units generated for serial ttys
As per the suggestion in https://github.com/systemd/systemd/issues/33242.

This reduces the number of /dev/ttySXX device units generated in
mkosi from 32 to 4.
2024-06-12 00:09:26 +01:00
Max Staudt
8416dc8bca udev: permanent symlinks with USB revision for /dev/media*
As a follow-up in the style of:
  873be895ed ("udev: add USB revision in ID_PATH")
this patch adds a second symlink for media controllers, this time
including the USB revision.

This means that in addition to persistent symlinks like:
  pci-0000:04:00.3-usb-0:1:1.0-media-controller -> ../../media0

We now also get:
  pci-0000:04:00.3-usbv2-0:1:1.0-media-controller -> ../../media0

...which helps distinguish media devices plugged into different USB root
hubs provided by the same PCI card, at least as long as they are for
different USB revisions.

Fixes: 04f19d6735 ("udev: Add /dev/media/by-path symlinks for media controllers")
2024-04-18 14:09:42 +02:00
Martin Wilck
c072860593 99-systemd.rules: rework SYSTEMD_READY logic for device mapper
Device mapper devices are set up in multiple steps. The first step, which
generates the initial "add" event, only creates an empty container, which is
useless for higher layers. SYSTEMD_READY should be set to 0 on this event to
avoid premature device activation.

The event that matters is the "activation" event: the first "change" event on
which DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 is not set. When this event arrives,
the device is ready for being scanned by blkid and similar tools, and for being
activated by systemd.

Intermittent events with DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 should be ignored
as far as systemd or higher-level block layers are concerned. Previous device
properties and symlinks should be preserved: the device shouldn't be scanned or
activated, but shouldn't be deactivated, either.  In particular, SYSTEM_READY
shouldn't be set to 0 if it wasn't set before, because that might cause mounted
file systems to be unmounted. Such intermittent events may occur any time,
before or after the "activation" event.

DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 can have multiple reasons. One possible reason
is that the device is suspended. There are other reasons that depend on the
device-mapper subsystem (LVM, multipath, dm-crypt, etc.).

The current systemd rule set

1) sets SYSTEMD_READY=0 if DM_UDEV_DISABLE_OTHER_RULES_FLAG is set in "add"
events;
2) imports SYSTEMD_READY from the udev db if DM_SUSPENDED is set, and jumps to systemd_end;
3) sets SYSTEMD_READY=1, otherwise.

This logic has several flaws:

* 1) can cause file systems to be unmounted if an coldplug event arrives while
a file system is suspended. This rule shouldn't be applied for coldplug events
or in general, "synthetic" add events;
* 2) evaluates DM_SUSPENDED=1, which is a device-mapper internal property.
It's wrong to infer that a device is accessible if DM_SUSPENDED=0.
The jump to systemd_end may cause properties and/or symlinks to be lost;
* 3) is superfluous, because SYSTEMD_READY=1 is equivalent with SYSTEMD_READY
being unset, and can create the wrong impression that the device was explicitly
activated.

This patch fixes the logic as follows:

- apply 1) only if DM_NAME is empty, which is only the case for the first
"genuine add" event;
- change 2) to use DM_UDEV_DISABLE_OTHER_RULES_FLAG instead of DM_SUSPENDED,
and remove the GOTO directive;
- remove 3).

Fixes: b7cf1b6 ("udev: use SYSTEMD_READY to mask uninitialized DM devices")
Fixes: 35a6750 ("rules: set SYSTEMD_READY=0 on DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 only with ADD event (#2747)")

Signed-off-by: Martin Wilck <mwilck@suse.com>
2024-04-03 12:48:14 +01:00
Max Staudt
04f19d6735 udev: Add /dev/media/by-path symlinks for media controllers
Add persistent symlinks for media controller ("mediaX") devices, based
on their ID_PATH udev properties.

For example, if the uvcvideo driver creates /dev/media0, a persistent
name may be:
/dev/media/by-path/pci-0000:04:00.3-usb-0:1:1.0-media-controller

Persistent links are a handy tool to make scripts self-documenting
during development or in tests, as well as less error prone in case of
devices changing enumeration order. For media controllers, one can
alternatively scan through all of them and look for a matching bus_info
in their struct media_device_info, but the links are much handier when
drafting something by hand.

A similar pattern already exists for Video4Linux /dev/videoX devices,
see 60-persistent-v4l.rules for those.
2024-02-22 19:27:29 +00:00
Werner Sembach
7ebbaaa7f4 Fix systemd-backlight ignoring numbered kbd_backlight entries
If there are name collisions in the leds subsystem, the 2nd device node with the
colliding name gets automatically renamed by appending _1, the third by
appending _2 and so on.

This wildcard change makes sure that systemd-backlight also catches these
renamed nodes for kbd_backlight entries.
2024-01-22 22:03:35 +00:00
我超厉害
8a86e15f07
udev: even if a device is a zac device, scsi-$ID_SERIAL will be reserved for it (#30459)
Co-authored-by: wangyuhang <wangyuhang27@huawei.com>
2024-01-16 14:57:07 +09:00
Lennart Poettering
4e1f0037b8 units: add a tpm2.target synchronization point and small generator that pulls in
Distributions apparently only compile a subset of TPM2 drivers into the
kernel. For those not compiled it but provided as kmod we need a
synchronization point: we must wait before the first TPM2 interaction
until the driver is available and accessible.

This adds a tpm2.target unit as such a synchronization point. It's
ordered after /dev/tpmrm0, and is pulled in by a generator whenever we
detect that the kernel reported a TPM2 to exist but we have no device
for it yet.

This should solve the issue, but might create problems: if there are TPM
devices supported by firmware that we don't have Linux drivers for we'll
hang for a bit. Hence let's add a kernel cmdline switch to disable (or
alternatively force) this logic.

Fixes: #30164
2024-01-03 13:49:02 +01:00
djantti
43ee987a1f udev: add hwdb execution for hidraw subsystem devices
Hwdb call for hidraw subsystem is missing and AV controller devices defined in hwdb.d/70-av-production.hwdb never get the proper permissions for /dev/hidraw*. This patch implements hwdb execution also for hidraw devices.
2023-12-25 02:16:44 +09:00
Franck Bui
3553fddb1e rules: set up tty permissions and group for /dev/hvc* nodes
Before b4bf9007cb, the permissions and group of the hypervisor consoles were
set by agetty(8).
2023-12-20 21:01:05 +09:00
Lukas Nykryn
3b2e7dc5a2 udev: allow/denylist for reading sysfs attributes when composing a NIC name
Users can currently pick specific versions of NIC naming, but that
does not guarantee that NIC names won't change after the kernel adds
a new sysfs attribute.

This patch allows for an allow/deny list of sysfs attributes
that could be used when composing the name.

These lists can be supplied as an hwdb entry in the form of
/etc/udev/hwdb.d/50-net-naming-allowlist.hwdb
net:naming:drvirtio_net
  ID_NET_NAME_ALLOW=0
  ID_NET_NAME_ALLOW_ACPI_INDEX=1
  ID_NET_NAME_ALLOW_ADDR_ASSIGN_TYPE=1
  ID_NET_NAME_ALLOW_ADDRESS=1
  ID_NET_NAME_ALLOW_ARI_ENABLED=1
  ID_NET_NAME_ALLOW_DEV_PORT=1
  ID_NET_NAME_ALLOW_FUNCTION_ID=1
  ID_NET_NAME_ALLOW_IFLINK=1
  ID_NET_NAME_ALLOW_INDEX=1
  ID_NET_NAME_ALLOW_LABEL=1
  ID_NET_NAME_ALLOW_PHYS_PORT_NAME=1
  ID_NET_NAME_ALLOW_TYPE=1
2023-12-19 19:15:52 +09:00
Roland Hieber
3af66c089b udev: generate system-unique storage symlinks using device path
When the same disk image is written to multiple storage units, for
example an external SD card and an internal eMMC, the symlinks in
/dev/disk/by-{label,uuid,partlabel,partuuid}/ are no longer unique, and
will point to the device that is probed last.

Adressing partitions via labels and UUIDs is nice to work with, and
depending on the use case, it might also be more robust than using the
symlinks in /dev/disk/by-path/ containing the partition number. Combine
the two approaches to create unique symlinks containing both the device
path as well as the respective UUIDs or labels, and throw in a symlink
using the devpath and the partition number for the sake of completeness.

For an exemplary GPT-partitioned disk at "platform-2198000.mmc" with a
partition containing an ext4 file system, this might create symlinks of
the following form:

  /dev/disk/by-path/platform-2198000.mmc-part/by-partnum/1
  /dev/disk/by-path/platform-2198000.mmc-part/by-partuuid/e5a75233-3b90-4aec-8075-b4dd7132b48d
  /dev/disk/by-path/platform-2198000.mmc-part/by-partlabel/rootfs
  /dev/disk/by-path/platform-2198000.mmc-part/by-uuid/b2c92f24-8215-4680-b931-f423aae5f1c9
  /dev/disk/by-path/platform-2198000.mmc-part/by-label/rootfs

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
2023-12-06 22:22:08 +01:00
janana
c1a2ada897 rules: go to the end of rules indeed when dm is suspended
The previous patch 466266c does not make sense indeed, that is to say, if the SYSTEMD_READY is not recorded in the database, the GOTO="systemd_end" will not be applied.

The IMPORT{db} is actually a matching token, it returns false when there is no SYSTEMD_READY recorded in the database.

The previous patch 466266c tended to inherit the state of SYSTEMD_READY from the database and skip to the end of current rule file. But when the database does not contain SYSTEMD_READY, e.g., the dm-* is not set db_persistent during initrd and the database will be cleared after switching root, the following rules will still be applied not as expected.
2023-11-29 09:57:55 +01:00
Lennart Poettering
50f4469ed7 rules: don't condition usb-gadget.target target on 'add' action
The dependency should exist continously, like all our similar deps do.
Hence drop the "add" conditionalization.
2023-11-25 12:52:23 +09:00
Lukas Nykryn
2b5b25f123 udev: add new builtin net_driver
Currently the ID_NET_DRIVER is set in net_setup_link builtin.
But this is called pretty late in the udev processing chain.

Right now in some custom rules it was workarounded by calling ethtool
binary directly, which is ugly.

So let's split this code to a separate builtin.
2023-11-01 16:00:19 +00:00
Yu Watanabe
4ef83d9c88 udev: revert workarounds for issues caused by the devlink creation optimization
This reverts the following two commits:
- "udev: decrease devlink priority for encrypted partitions"
  c4521fc17b.
- "udev: decrease devlink priority for iso disks"
  df1dccd255.

These commits are workarounds for issues caused by
331aa7aa15.
With the previous commit, these workarounds are not necessary anymore,
as partitions are always processed later than their whole disk, and
a decrypted volume is also processed later than its backing volume.
2023-11-01 19:47:00 +09:00
Lennart Poettering
ec541c569b hwdb,rules: mark host-to-host network devices as only requiring link local addressing
This is a generalization of this logic:

https://github.com/NetworkManager/NetworkManager/blob/main/data/90-nm-thunderbolt.rules

It applies not just to thunderbolt, but to any kind of device, even
matched by vendor/product, via hwdb.

I added two entries for Prolific PC-to-PC devices (of which I have one
lying around).
2023-10-30 18:57:41 +01:00
Matthias Schiffer
84ff5894db rules: add mtd/by-name symlinks
Add persistent symlinks for MTD devices like SPI-NOR flash, based on the
partition names specified on the cmdline, in a Device Tree, or by other
MTD partitioning parser drivers. Using the persistent name can be
preferable to using the numbered /dev/mtdX device, as the latter can
change depending on probe order or when partitioning has changed.
2023-10-17 11:43:30 +02:00
Chris Patterson
23cbe90d7d 99-systemd.rules.in: tag PTP devices with systemd
Chronyd and similar time services, when using PTP devices, may need
the BindsTo/After directives to ensure the devices are available
before starting.  Tag PTP devices with systemd to allow for wider
adoption.

Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
2023-08-28 10:42:27 +01:00
Yu Watanabe
7a05926fbe udev: re-introduce symlinks for loopback block device
But the directories are changed from /dev/loop/by-ref/ -> /dev/disk/by-loop-ref/
and /dev/loop/by-inode/ -> /dev/disk/by-loop-inode/.
As /dev/loop/ is used by losetup command for other purpose.
See issue #28475.

This effectively reverts commits 9915cc6086,
5022fab15f, and
c0d998248e.
2023-08-10 07:05:47 +09:00
Yu Watanabe
074d90926f udev: set ID_NAME and ID_SERIAL to MMC/memstick devices again
Fixes a bug introduced by 998db5871f.

Fixes #28671.
2023-08-08 12:05:30 +01:00
Yu Watanabe
12b4cffdae meson: introduce HAVE_DMI flag
The condition is used at several places. Let's introduce a simple flag
for that.
2023-08-03 20:37:16 +09:00
Yu Watanabe
c4521fc17b udev: decrease devlink priority for encrypted partitions
Decrease devlink priority for encrypted partitions, and make the priority for
decrypted DM devices relatively higher. This is for the case that an encrypted
partition and its decrypted DM device have the same label.
2023-08-02 22:03:14 +01:00
Luca Boccassi
b0d3095fd6 Drop split-usr and unmerged-usr support
As previously announced, execute order 66:

https://lists.freedesktop.org/archives/systemd-devel/2022-September/048352.html

The meson options split-usr, rootlibdir and rootprefix become no-ops
that print a warning if they are set to anything other than the
default values. We can remove them in a future release.
2023-07-28 19:34:03 +01:00
Yu Watanabe
6636b2b6bf udev: set ID_PATH properties for all pci, usb, and platform devices
Before c43ff248f9, the following line in
60-drm.rules also sets ID_PATH for all pci, usb, and platform devices:
===
ACTION!="remove", SUBSYSTEM=="drm", SUBSYSTEMS=="pci|usb|platform", IMPORT{builtin}="path_id"
===
Unfortunately, some existing rules rely on the unexpected behavior.
To keep the backward compatibility, let's set ID_PATH for them.

Fixes #28411.
2023-07-25 17:56:59 +01:00
Yu Watanabe
df1dccd255 udev: decrease devlink priority for iso disks
Previously, if the priority is same, devlinks are always replaced by
newer events. The commit 331aa7aa15 changes
that to keep the existing devlink. That should not change any behavior
when the devices that request the same symlink do not have any
dependency, e.g. when /dev/sda1 and /dev/adb1 request the same
/dev/disk/by-label symlink, as there are no guarantee that which device
is processed first.

However, when devices has dependency, e.g. /dev/sda and /dev/sda1
request the same /dev/disk/by-label symlink, previously the symlink
always pointed to the partition, as the partition is always processed
later. But, 331aa7aa15 makes the symlink
point to the whole disk.

The change by 331aa7aa15 is crucial to
improve performance of devlink handling, especially when a system has
large number of disks with same label or so. Hence, cannot and should
not be reverted.

So, let's workaround the case, as such situation should happen only when
the disk is a hybrind ISO image, I guess.

Fixes #28468.
2023-07-21 11:42:34 +01:00
Luca Boccassi
9915cc6086 Revert "udev: add /dev/loop/ symlinks"
Turns out this causes a regression and breaks losetup. It will need to
be reworked in conjunction with util-linux changes.

Fixes https://github.com/systemd/systemd/issues/28475

This reverts commit 5ac52d1f7b.
2023-07-20 22:28:23 +01:00
Lennart Poettering
c65c2f0aa6 rules: drop weird spaces 2023-06-20 15:04:31 +02:00
Lennart Poettering
dafd65b150 rules: split out DMI related rules from udev-default.rules
The DMI rules where so far guarded by an ACTION=="add" rule, but that
doesn't really make sense for setting properties (only for setting
access modes/ownership of nodes).

Hence let's move this into its own file, that guards properly on
ACTION!="remove".

Before this change the hardware vendor/model info would be dropped
whenever the device was retriggered.
2023-06-20 14:44:36 +02:00
Simon Braunschmidt
99d3dd2ba7 99-systemd.rules.in: guard systemd-backlight udev rules by ENABLE_BACKLIGHT
Linux kernel will, as documented in drivers/video/backlight/backlight.c,
report changes to a backlights brightness as a uevent (ACTION=change).

systemd-udev will consume the uevent, match on this rule and try to
activate the systemd-backlight service for the backlight. BUT when
systemd is not compiled with backlight support, this will lead to
failure that is reported in the journal.

Since the failure to activate systemd-backlight and subsequent failure
log entry happens on every backlight brightness change, we found the
resulting logspam during regular operation excessive and came up with
this patch to mitigate it.

The conditional is also extended to "*kbd_backlight" match, since
even though we did not investigate to see if the logspam would be
similar, the unconditional match to activate systemd-backlight here
would also not make sense when the feature is not compiled in.

Signed-off-by: Simon Braunschmidt <simon.braunschmidt@iba-group.com>
2023-06-05 17:59:04 +01:00
Yu Watanabe
998db5871f udev: introduce .PART_SUFFIX internal property
To make unify rules for disk and partition.
2023-05-26 16:38:09 +02:00
Stanislaw Gruszka
3d1e78e362 rules: add rule for accel devices
Accel (Compute Acceleration) are new devices for AI/ML computation:
https://docs.kernel.org/accel/introduction.html

They are part of DRM subsystem. Add them to 'render' group since
no other appropriate group in standard linux systems exist. This
can be changed when proper common user-space components will emerge,
and new group for acceleration devices access will be established.

Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
2023-05-26 04:17:22 +09:00
Zbigniew Jędrzejewski-Szmek
21392bcb1c
Merge pull request #27483 from yuwata/udev-id-path-usb-revision
udev: include USB revision in ID_PATH
2023-05-25 10:24:45 +02:00
Yu Watanabe
873be895ed udev: add USB revision in ID_PATH
xHCI host controller may register two (or more?) USB root hubs for USB
2.0 and USB 3.0, and devices under the hubs may have same ID_PATH.
So, to avoid the conflict, let's introduce ID_PATH_WITH_USB_REVISION
that includes the USB revision.

Closes #19406.
2023-05-20 14:27:10 +09:00
Yu Watanabe
874c408935 udev: check existence of property before use 2023-05-20 14:26:05 +09:00
Zbigniew Jędrzejewski-Szmek
f78d6ff2ab rules: start systemd-vconsole-setup via unit
We started systemd-vconsole-setup in two ways: via a dbus call from localed to
do systemd-vconsole-setup.service/restart, and from udev, calling the binary
directly. This patch makes udev call
  systemctl restart systemd-vconsole-setup.service
effectively implementing the same method as localed.

Ordering is implemented at the unit level, so we can use --no-block to not
block here.
2023-05-19 17:46:47 +02:00
Yu Watanabe
fc73d97182 udev/iocost: invert DEVTYPE match
No functional change, just refactoring.
Addresses https://github.com/systemd/systemd/pull/23325#discussion_r1171006967.
2023-04-26 14:50:25 +09:00
Yu Watanabe
c413ae18b5 udev/iocost: use ID_MODEL_FROM_DATABASE if exists
To make the rule consistent with 'iocost query'.
2023-04-26 14:50:25 +09:00
Luca Boccassi
21453b8b4b
Merge pull request #27349 from mrc0mmand/codespell
tree-wide: code spelling fixes
2023-04-20 22:02:17 +01:00
Frantisek Sumsal
94d82b5980 tree-wide: code spelling fixes
As reported by Fossies.
2023-04-20 21:54:59 +02:00