Commit graph

98 commits

Author SHA1 Message Date
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
David Bond e92a3d8fa3 udev: 60-persistent-storage-tape.rules: handle duplicate device ID
Some SCSI tape devices use the same device ID (NAA registered device
designator) for the SCSI tape changer device and the first actual tape
device. For example, this one:

https://docs.oracle.com/en/storage/tape-storage/storagetek-sl150-modular-tape-library/slofs/bridged-tape-drives.html

   You must connect the bridged drive to an HBA supporting multiple
   LUNs (also referred to as LUN scanning). The SL150 Library uses a
   single SCSI ID and two logical unit numbers (LUN). LUN 0 controls
   the tape drive and LUN 1 which is configured as a SCSI medium
   changer device controls the robotics. Data is sent to the remaining
   LUN on the bridged drive or to LUNs on the other, unbridged drives
   in the partition, all of which are configured as SCSI
   sequential-access (tape) devices.

This may lead to errors because /dev/tape/by-id symlinks may sometimes
point to the st device representing the tape, and sometimes to the sg
device representing the changer.

Fix this by assigning an increased priority to the tape device, and creating
a separate -changer link for the SCSI tape changer.

Co-developed-by: Martin Wilck <mwilck@suse.com>
2022-03-08 23:12:10 +09:00
Zbigniew Jędrzejewski-Szmek f1b98127ff meson: do not use split() in file lists
The approach to use '''…'''.split() instead of a list of strings was initially
used when converting from automake because it allowed identical blocks of lines
to be used for both, making the conversion easier.

But over the years we have been using normal lists more and more, especially
when there were just a few filenames listed. This converts the rest.

No functional change.
2022-03-02 14:49:32 +01:00
Yu Watanabe da60d91c99 rule: fallback to use board information if product information is not set 2022-01-23 13:04:37 +09:00
Yu Watanabe a93306a22e rule: make ID_SYSFS_ATTRIBUTE_MODEL also accept product_name 2022-01-23 12:54:37 +09:00
Zbigniew Jędrzejewski-Szmek ba5b19ef4d Revert "udev: Import hwdb matches for USB devices"
This reverts commit 94cb45d57f.

This rule set up a duplicate import:

$ udevadm test /devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4.1/2-4.1.3
...
2-4.1.3: /usr/lib/udev/rules.d/40-libgphoto2.rules:9 Importing properties from results of builtin command 'usb_id'
2-4.1.3: /usr/lib/udev/rules.d/50-udev-default.rules:13 Skipping builtin 'usb_id' in IMPORT key
2-4.1.3: /usr/lib/udev/rules.d/50-udev-default.rules:13 Importing properties from results of builtin command 'hwdb --subsystem=usb'
2-4.1.3: hwdb modalias key: "usb:v17EFp3054:OneLink+ Giga"
2-4.1.3: /usr/lib/udev/rules.d/50-udev-default.rules:15 Importing properties from results of builtin command 'hwdb 'usb:v17efp3054''
2-4.1.3: No entry found from hwdb.
2-4.1.3: /usr/lib/udev/rules.d/50-udev-default.rules:15 Failed to run builtin 'hwdb 'usb:v17efp3054'': No data available
2-4.1.3: /usr/lib/udev/rules.d/50-udev-default.rules:52 MODE 0664

except that the existing one was done with uppercase digits and the full match pattern,
and the second one was done with lowercase digits.

With the previous commit we only have uppercase digits in our match patterns, so we can
drop the duplicate import. (Some other projects might have rules that used the lowercase
match patterns, and people might have some local rules that did that too. But the second
import was only added recently so I think it's better to rip off the bandaid quickly.)
2022-01-04 11:04:53 +01:00
Jarkko Sakkinen b5d3138f91 Enable /dev/sgx_vepc access for the group 'sgx'
Enable /dev/sgx_vepc access for the group 'sgx', which allows KVM-backed VMs
to host Intel Software Guard eXtension (SGX) enclaves. The upcoming QEMU
6.2 uses /dev/sgx_vepc to reserve portions of Enclave Page Cache (EPC) for
VMs. EPC is the reserved physical memory used for hosting enclaves.
2021-12-12 11:02:21 +00:00
Christian Brauner a6d1760024 build: preserve correct mode when generating files via jinja2
When using "capture : true" in custom_target()s the mode of the source
file is not preserved when the generated file is not installed and so
needs to be tweaked manually. Switch from output capture to creating the
target file and copy the permissions from the input file.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-08 12:06:48 +00:00
Bastien Nocera e78e11d8c5 hwdb: Tag IR cameras as such
So that front-ends can ignore them if they wish to.

See https://gitlab.gnome.org/GNOME/cheese/-/merge_requests/4
2021-10-27 00:14:41 +02:00
alexlzhu fab79a85af docs: Fixing typo in systemd.device man page and README.
systemd-udevd.service listens to kernel uevents and is needed for device
units to be available.

systemd-udevd.service is misspelled as systemd-udev.service in a couple places.

Fixing typo.
2021-09-29 22:18:38 +01:00