Commit Graph

107 Commits

Author SHA1 Message Date
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
Gustavo Noronha Silva
6b8e90545e Apply known iocost solutions to block devices
Meta's resource control demo project[0] includes a benchmark tool that can
be used to calculate the best iocost solutions for a given SSD.

  [0]: https://github.com/facebookexperimental/resctl-demo

A project[1] has now been started to create a publicly available database
of results that can be used to apply them automatically.

  [1]: https://github.com/iocost-benchmark/iocost-benchmarks

This change adds a new tool that gets triggered by a udev rule for any
block device and queries the hwdb for known solutions. The format for
the hwdb file that is currently generated by the github action looks like
this:

  # This file was auto-generated on Tue, 23 Aug 2022 13:03:57 +0000.
  # From the following commit:
  # ca82acfe93
  #
  # Match key format:
  # block:<devpath>:name:<model name>:

  # 12 points, MOF=[1.346,1.346], aMOF=[1.249,1.249]
  block:*:name:HFS256GD9TNG-62A0A:fwver:*:
    IOCOST_SOLUTIONS=isolation isolated-bandwidth bandwidth naive
    IOCOST_MODEL_ISOLATION=rbps=1091439492 rseqiops=52286 rrandiops=63784 wbps=192329466 wseqiops=12309 wrandiops=16119
    IOCOST_QOS_ISOLATION=rpct=0.00 rlat=8807 wpct=0.00 wlat=59023 min=100.00 max=100.00
    IOCOST_MODEL_ISOLATED_BANDWIDTH=rbps=1091439492 rseqiops=52286 rrandiops=63784 wbps=192329466 wseqiops=12309 wrandiops=16119
    IOCOST_QOS_ISOLATED_BANDWIDTH=rpct=0.00 rlat=8807 wpct=0.00 wlat=59023 min=100.00 max=100.00
    IOCOST_MODEL_BANDWIDTH=rbps=1091439492 rseqiops=52286 rrandiops=63784 wbps=192329466 wseqiops=12309 wrandiops=16119
    IOCOST_QOS_BANDWIDTH=rpct=0.00 rlat=8807 wpct=0.00 wlat=59023 min=100.00 max=100.00
    IOCOST_MODEL_NAIVE=rbps=1091439492 rseqiops=52286 rrandiops=63784 wbps=192329466 wseqiops=12309 wrandiops=16119
    IOCOST_QOS_NAIVE=rpct=99.00 rlat=8807 wpct=99.00 wlat=59023 min=75.00 max=100.00

The IOCOST_SOLUTIONS key lists the solutions available for that device
in the preferred order for higher isolation, which is a reasonable
default for most client systems. This can be overriden to choose better
defaults for custom use cases, like the various data center workloads.

The tool can also be used to query the known solutions for a specific
device or to apply a non-default solution (say, isolation or bandwidth).

Co-authored-by: Santosh Mahto <santosh.mahto@collabora.com>
2023-04-20 16:45:57 +02:00
Zbigniew Jędrzejewski-Szmek
ba5a469648
Merge pull request #27169 from yuwata/udev-rule-refuse-unsafe-path
sd-device,udev: refuse unsafe path in SYMLINK= and TAG=
2023-04-11 14:43:50 +02:00
Yu Watanabe
6fdc9fbc0f udev/scsi_id: rename positional arguments 2023-04-11 06:07:03 +09:00
Yu Watanabe
49e3e219b0 rules: drop doubled space 2023-04-08 04:50:04 +09:00
Zbigniew Jędrzejewski-Szmek
d05e1be86e udev: restore compat symlink for nvme devices
In 5118e8e71d, the rules were changed to add
OPTIONS="string_escape=replace" to creation of
ENV{ID_SERIAL}="$env{ID_MODEL}_$env{ID_SERIAL_SHORT}", so that "/" would be
escaped. But this also changes how the symlink looks for devices that do not
have "/". This adds back the old symlink for compat, except when a slash
is present.

In the meantime, we changed the symlink format to include ${ND_NSID}. Since
the symlink with unescaped characters are older than that, for compat we
only need to cover the older type. (Symlinks without escaping and with ${ND_NSID}
were never created.)  This makes it slightly easier on users: the non-deprecated
symlinks are with "_${ND_NSID}", so they are easier to distinguish.

Fixes #27155.

Mostly untested :(  I only have a boring nvme device with no special characters
in the id, and the symlinks are unchanged for it by this patch.
2023-04-08 04:50:04 +09:00
Dmitry V. Levin
519044f565 rules: add whitespace after comma before the line continuation 2023-03-27 10:00:30 +00:00
Dmitry V. Levin
4c61088497 rules: remove stray whitespace before comma between tokens 2023-03-27 10:00:30 +00:00
Thomas Blume
c5ba7a2a4d udev-rules: fix nvme symlink creation on namespace changes
The nvme by-id symlink changes to the latest namespace when a new namespace gets
added, for example by connecting multiple NVMe/TCP host controllers via nvme
connect-all.
That is incorrect for persistent device links.
The persistent symbolic device link should continue to point to the same NVMe
namespace throughout the lifetime of the current boot.
Therefore the namespace id needs to be added to the link name.
2023-03-21 15:46:45 +01:00
Lennart Poettering
5ac52d1f7b udev: add /dev/loop/ symlinks
This adds symlinks that allow accessing loopback block devices via stable
names that reference their backing block devices, make the unpredictable
naming of loopback devices less of an issue.

Example:

1. Create a loopback block device for a file $F

   losetup --find $F

2. Reference the backing block device via its inode:

   L="$(stat -c '/dev/loop/by-inode/%Hd:%Ld-%i' $F)"
   fdisk $L

In the above the loop device name (which might be /dev/loop47 or any
other name) is not used at all.
2023-03-09 16:41:26 +01:00
Dmitry V. Levin
f94e9529fe rules: do not use blkid builtin if built without blkid support
When built without blkid, then udev-builtin-blkid is not built,
and the verifier warns about the unknown builtin:

60-persistent-storage.rules:114 Unknown builtin command: blkid --hint=session_offset=$env{ID_CDROM_MEDIA_SESSION_LAST_OFFSET}
60-persistent-storage.rules:117 Unknown builtin command: blkid --noraid
60-persistent-storage.rules:120 Unknown builtin command: blkid
60-persistent-storage.rules: udev rules check failed
2023-03-08 18:55:40 +00:00
Dmitry V. Levin
dc652e7dc3 rules: remove redundant duplicate comparisons
$ grep -F -n -o 'ENV{DISKSEQ}=="?*", ' rules.d/60-persistent-storage.rules
139:ENV{DISKSEQ}=="?*",
139:ENV{DISKSEQ}=="?*",
140:ENV{DISKSEQ}=="?*",
140:ENV{DISKSEQ}=="?*",

Reported-by: Alexey Gladkov <legion@kernel.org>
Fixes: 17d97d4c90 ("udev: create disk/by-diskseq symlink only when the device has diskseq")
Fixes: 583dc6d933 ("udev: also create partition /dev/disk/by-diskseq/ symlinks")
2023-02-26 07:51:26 +09:00
Jan Janssen
4c6d1e1665 meson: Install missing udev rule 2023-01-27 18:23:02 +01:00
Lennart Poettering
583dc6d933 udev: also create partition /dev/disk/by-diskseq/ symlinks 2022-12-23 12:42:37 +01:00
Yu Watanabe
de8409ac43 rules: add missing line continuation
Fixes a bug introduced by 953c928c24.

Fixes #25811.
2022-12-21 09:52:07 +01:00
Zbigniew Jędrzejewski-Szmek
953c928c24 udev: rework 60-evdev.rules to be "additive"
We would execute up to four hwdb match patterns (+ the keyboard builtin):
After the first hit, we would skip the other patterns, because of the GOTO="evdev_end"
action.

57bb707d48 (rules: Add extended evdev/input match
rules for event nodes with the same name), added an additional match with
":phys:<phys>:ev:<ev>" inserted. This breaks backwards compatibility for user
hwdb patterns, because we quit after the first match.

In general hwdb properties are "additive". We often have a general rule that
matches a wider class and then some specific overrides. E.g. in this particular
case, we have a match for all trackpoints, and then a bunch of model-specific
settings.

So let's change the rules to try all the match patterns and combine the
received properties. We execute builtin-keyboard once at the end, if there was
at least one match.

Fixes #25698. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2152226.

This also impacts other cases which I think would be very confusing for users.
Since we quit after a first successful match, if we had e.g. a match for
'evdev:input:b*v*p*' in out database, and the user added a match using
'evdev:name:*', which is the approach we document in the .hwdb files and which
users quite often use, it would be silently ignored. What's worse, if we added
our 'evdev:input:b*v*p*' match at a later point, user's match would stop
working. If we combine all the properties, we get more stable behaviour.
2022-12-12 13:44:33 +01:00
Yu Watanabe
5286da064c udev: add safe guard for setting by-id symlink
The ID_BUS property is necessary for creating by-id symlinks.
2022-11-03 09:59:54 +09:00
Yu Watanabe
b2e53f5a0f udev: drop redundant call of usb_id and assignment of ID_USB_INTERFACE_NUM
The usb_id builtin command is already called in the above, and the
command sets the ID_USB_INTERFACE_NUM property.
2022-11-03 09:59:35 +09:00
Yu Watanabe
01e704eba9 udev: first set properties based on usb subsystem
After 479da1107a, the usb_id builtin
command does not set ID_SERIAL if ID_BUS is already set.
Before the commit, all properties set based on pci bus were overwritten
by the usb_id, hence now it is sufficient setting them only when ID_BUS is
not set yet.

Fixes #25238.
2022-11-03 09:53:19 +09:00
Yu Watanabe
479da1107a udev: always create device symlinks for USB disks
Previously, ata_id might not be able to retrieve attributes correctly,
and properties from usb_id were used as a fallback. See issue #24921
and PR #24923. To keep backward compatibility, still we need to create
symlinks based on USB serial.

Fixes #25179.
2022-10-30 12:02:02 +01:00
Yu Watanabe
2ce39d78b8 udev-builtin-kmod: support to run without arguments
If no module name is provided, then try to load modules based on the
device modealias.

Previously, MODALIAS property is passed as an argument, but it may
contain quotation. Hence, unfortunately the modalias may be modified
and cannot load expected modules.

Fixes #24715.
2022-10-14 21:32:24 +09:00
Lubomir Rintel
73bf6859cb udev/rules: add by-path and by-ibdev links to infiniband verbs
The uverbs devices are sequentially numbered and are not guarranteed to
stay stable across reboot.

At least one good person was disappointed by this, because they couldn't
find their device: https://bugzilla.redhat.com/show_bug.cgi?id=2036515

Let's add a few helpful links.
2022-10-14 12:18:08 +09:00
Yu Watanabe
67c3e1f63a udev: support by-path devlink for multipath nvme block devices
If multipath feature is enabled, nvme block devices may belong to the
"nvme-subsystem" subsystem, instead of "nvme" subsystem.
(What a confusing name...)

Then, the syspath is something like the following,
    /sys/devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1
Hence, we need to find the 'real parent' device, such as
    /sys/devices/pci0000:00/0000:00:1c.4/0000:3c:00.0/nvme/nvme0

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2031810.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2124964.
Replaces #24748.
2022-09-23 10:21:46 +09:00
Yu Watanabe
0cf2dcf154 udev/rules,hwdb: filter out mostly meaningless default strings
The filter is generated based on the following results:
---
git clone git@github.com:linuxhw/DMI.git
cd DMI
git grep -h -A2 '^System Information$' | grep 'Manufacturer' | sort | uniq -c | sort -nr | less
git grep -h -A2 '^System Information$' | grep 'Product Name' | sort | uniq -c | sort -nr | less
---

Closes #24446.
2022-09-06 03:38:09 +09:00
Michal Sekletar
466266c172 rules: import previous SYSTEMD_READY state for suspended DM devices and skip other rules
We can't get any FS meta-data from a suspended device. Hence defer
making any plugged/unplugged decisions, i.e. we just import whatever was
previous state and skip processing all other rules.

Thanks Lennart Poettering <lennart@poettering.net> for suggesting this
solution.
2022-08-19 20:13:47 +01:00
Alper Nebi Yasak
ac3c031e38 udev: hwdb: Add rules to match cros-ec-accel by 'location' sysfs file
The cros-ec-accel devices report their mounting location by the 'label'
sysfs file only since Linux v6.0. With earlier kernels, a nonstandard
'location' file reports this, but slightly differently (lid instead of
display) [1].

Add udev rules to import the correct hwdb entries based on this
'location' file for cros-ec-accel devices, so that the base-mounted
accel matrix has the correct value for older kernels as well.

[1] https://kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio-cros-ec
2022-08-18 21:17:19 +03:00
Alper Nebi Yasak
e2f25ae648 udev: hwdb: Match iio sensors based on their label
The IIO subsystem exposes a 'label' sysfs file to help userspace better
identify its devices [1]. Standardized labels include the sensor type
along with its location, including 'accel-base' and 'accel-display'.

Most Chrome OS boards have two accelerometers that are indistinguishable
except for this label (or a 'location' sysfs file before Linux v6.0),
and need different mounting matrix corrections based on their location.

Add a udev rule that matches hwdb entries using this label, so we can
correct both accelerometers on these devices with hwdb entries. The
existing rules and hwdb entries are not modified to keep potential
out-of-tree entries working, but new entries in this form will override
existing ones. Also add currently standardized labels to parse-hwdb.py.

[1] https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio
2022-08-18 21:17:19 +03:00
Bastien Nocera
9cb1dcae8c hwdb: Allow users access to USB serial for analysers
Allow users at the console access to the USB serial interface for USB
analysers.

See 9e2dbfef47
2022-08-09 18:12:19 +02:00
Darsey Litzenberger
b5e17d7fed udev: add flag to allow disabling blkid probing
This can be useful for users of slow block devices.

For example, the persistent-storage rules are needed for USB floppy
drives be recognized by udisks2, but the extra blkid calls cause
thrashing for 25+ seconds after every disk change.

With this change, a user wishing to avoid the extra blkid invocation(s)
could create /etc/udev/rules.d/55-floppy-noprobe.rules as follows:

    # Don't probe PC floppy drives
    SUBSYSTEM=="block", KERNEL=="fd*", \
        ENV{UDEV_DISABLE_PERSISTENT_STORAGE_BLKID_FLAG}="1"

    # Don't probe USB floppy drives
    SUBSYSTEM=="block", SUBSYSTEMS=="usb", \
        ATTRS{bInterfaceClass}=="08", ATTRS{bInterfaceSubClass}=="04", \
        ENV{UDEV_DISABLE_PERSISTENT_STORAGE_BLKID_FLAG}="1"

I didn't exclude floppies by default in this change, because floppy
devices are also emulated by some BIOSes/hypervisors in some cases, and
I don't know how many systems would fail to boot if /dev/disk/by-uuid/*
became unavailable for 'floppy disks' on those systems.
2022-07-15 07:54:14 +09:00
Yu Watanabe
f9aabf2c2c meson: install 70-power-switch.rules
Fixes a bug introduced by 155078c835.

Fixes #23425.
2022-05-19 05:04:58 +09:00
Mario Limonciello
fa9a43a690 Add support to set autosuspend delay via hwdb 2022-05-09 21:14:12 -05:00
Zbigniew Jędrzejewski-Szmek
e8a5b13e45 meson: move vconsole rules to rules.d/ 2022-05-05 11:51:44 +02:00
Zbigniew Jędrzejewski-Szmek
155078c835 meson: move udev rules to rules.d/ 2022-05-05 11:51:44 +02:00
Yu Watanabe
9a78ee002f udev: set ID_IGNORE_DISKSEQ for md devices 2022-04-14 00:12:02 +09:00
Yu Watanabe
0224c31ea3 udev: do not create disk/by-diskseq symlink when ID_IGNORE_DISKSEQ property is set 2022-04-14 00:11:57 +09:00
Yu Watanabe
17d97d4c90 udev: create disk/by-diskseq symlink only when the device has diskseq
Follow-up for 0d08db7f89.
2022-04-13 23:09:47 +09:00
Zbigniew Jędrzejewski-Szmek
8f04a1ca2b meson: also allow setting GIT_VERSION via templates
GIT_VERSION is not available as a config.h variable, because it's rendered
into version.h during builds. Let's rework jinja2 rendering to also
parse version.h. No functional change, the new variable is so far unused.

I guess this will make partial rebuilds a bit slower, but it's useful
to be able to use the full version string.
2022-04-05 22:18:31 +02:00
Lennart Poettering
0d08db7f89 udev: add /dev/disk/by-diskseq symlink for block devices
This adds another symlink for block devices:

    /dev/disk/by-diskseq/<number>

where the number is the diskseq number as exposed by the kernel. It's
useful for apps because they can use it to open a device by diskseq, in
a way that is safe against device node reuse. I.e. if a device node path
like this is passed to an app it could open the device node via the
symlink and also parse the diskseq from the path. Once the device is
opened it could compare the parsed diskseq with the one returned by
BLKGETDISKSEQ on the open node, and if it matches they know they are
talking to the right device.

Fixes: #22906
2022-04-01 23:44:37 +09:00