patches and low-level development discussion
 help / color / mirror / code / Atom feed
* [PATCH 1/2] host/rootfs: assign-devices: silence errors
@ 2025-11-02 15:00 Alyssa Ross
  2025-11-02 15:00 ` [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent Alyssa Ross
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alyssa Ross @ 2025-11-02 15:00 UTC (permalink / raw)
  To: devel; +Cc: Demi Marie Obenour, Yureka Lilian

The expected warnings frequently confuse people.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
 host/rootfs/image/usr/bin/assign-devices | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/host/rootfs/image/usr/bin/assign-devices b/host/rootfs/image/usr/bin/assign-devices
index 1332a40..58dd3cc 100755
--- a/host/rootfs/image/usr/bin/assign-devices
+++ b/host/rootfs/image/usr/bin/assign-devices
@@ -5,4 +5,9 @@
 elglob -0 devices /sys/bus/pci/drivers/vfio-pci/????:??:??.?
 forx -pE device { $devices }
 
+# This script is designed to be re-entrant and called multiple times.
+# This means we expect to sometimes get an error due to the device
+# already having been added.  If there's a different error,
+# cloud-hypervisor will probably log it itself anyway.
+redirfd -w 2 /dev/null
 ch-remote --api-socket /run/vm/by-name/sys.netvm/vmm add-device path=${device}

base-commit: e0f5aad7901d150b1abe381ffd99d554e65e758b
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent
  2025-11-02 15:00 [PATCH 1/2] host/rootfs: assign-devices: silence errors Alyssa Ross
@ 2025-11-02 15:00 ` Alyssa Ross
  2025-11-02 20:08   ` Demi Marie Obenour
  2025-11-02 20:49   ` Alyssa Ross
  2025-11-02 20:09 ` [PATCH 1/2] host/rootfs: assign-devices: silence errors Demi Marie Obenour
  2025-11-02 20:49 ` Alyssa Ross
  2 siblings, 2 replies; 6+ messages in thread
From: Alyssa Ross @ 2025-11-02 15:00 UTC (permalink / raw)
  To: devel; +Cc: Demi Marie Obenour, Yureka Lilian

udev actions needs to be idempotent, so when we switch to udev, we
have the choice of making this script idempotent, or doing goto hacks
to stop udev running it more than once.  I like this better.

assign-devices is already idempotent, so all we need to do to achieve
idempotency is avoid unbinding and rebinding the driver if it's
already the right one.

Link: https://spectrum-os.org/lists/archives/spectrum-devel/87ikgxwq0v.fsf@alyssa.is
Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
 host/rootfs/image/etc/mdev/net/add | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/host/rootfs/image/etc/mdev/net/add b/host/rootfs/image/etc/mdev/net/add
index f343779..62c152e 100755
--- a/host/rootfs/image/etc/mdev/net/add
+++ b/host/rootfs/image/etc/mdev/net/add
@@ -1,6 +1,6 @@
 #!/bin/execlineb -P
 # SPDX-License-Identifier: EUPL-1.2+
-# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2021, 2025 Alyssa Ross <hi@alyssa.is>
 
 # Assign the whole IOMMU group containing this device to the network
 # VM.
@@ -12,6 +12,13 @@ importas -i devpath DEVPATH
 foreground {
   pipeline { ls -1 /sys${devpath}/iommu_group/devices }
   forstdin -pE device
+  if -t {
+    backtick -E driver_name {
+      backtick -E driver_path { readlink /sys/bus/pci/devices/${device}/driver }
+      basename -- $driver_path
+    }
+    test $driver_name != vfio-pci
+  }
   foreground {
     redirfd -w 2 /dev/null
     redirfd -w 1 /sys/bus/pci/devices/${device}/driver/unbind
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent
  2025-11-02 15:00 ` [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent Alyssa Ross
@ 2025-11-02 20:08   ` Demi Marie Obenour
  2025-11-02 20:49   ` Alyssa Ross
  1 sibling, 0 replies; 6+ messages in thread
From: Demi Marie Obenour @ 2025-11-02 20:08 UTC (permalink / raw)
  To: Alyssa Ross, devel; +Cc: Yureka Lilian


[-- Attachment #1.1.1: Type: text/plain, Size: 1782 bytes --]

On 11/2/25 10:00, Alyssa Ross wrote:
> udev actions needs to be idempotent, so when we switch to udev, we
> have the choice of making this script idempotent, or doing goto hacks
> to stop udev running it more than once.  I like this better.
> 
> assign-devices is already idempotent, so all we need to do to achieve
> idempotency is avoid unbinding and rebinding the driver if it's
> already the right one.
> 
> Link: https://spectrum-os.org/lists/archives/spectrum-devel/87ikgxwq0v.fsf@alyssa.is
> Signed-off-by: Alyssa Ross <hi@alyssa.is>

Reviewed-by: Demi Marie Obenour <demiobenour@gmail.com>

> ---
>  host/rootfs/image/etc/mdev/net/add | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/host/rootfs/image/etc/mdev/net/add b/host/rootfs/image/etc/mdev/net/add
> index f343779..62c152e 100755
> --- a/host/rootfs/image/etc/mdev/net/add
> +++ b/host/rootfs/image/etc/mdev/net/add
> @@ -1,6 +1,6 @@
>  #!/bin/execlineb -P
>  # SPDX-License-Identifier: EUPL-1.2+
> -# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
> +# SPDX-FileCopyrightText: 2021, 2025 Alyssa Ross <hi@alyssa.is>
>  
>  # Assign the whole IOMMU group containing this device to the network
>  # VM.
> @@ -12,6 +12,13 @@ importas -i devpath DEVPATH
>  foreground {
>    pipeline { ls -1 /sys${devpath}/iommu_group/devices }
>    forstdin -pE device
> +  if -t {
> +    backtick -E driver_name {
> +      backtick -E driver_path { readlink /sys/bus/pci/devices/${device}/driver }
> +      basename -- $driver_path
> +    }
> +    test $driver_name != vfio-pci
> +  }
>    foreground {
>      redirfd -w 2 /dev/null
>      redirfd -w 1 /sys/bus/pci/devices/${device}/driver/unbind
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] host/rootfs: assign-devices: silence errors
  2025-11-02 15:00 [PATCH 1/2] host/rootfs: assign-devices: silence errors Alyssa Ross
  2025-11-02 15:00 ` [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent Alyssa Ross
@ 2025-11-02 20:09 ` Demi Marie Obenour
  2025-11-02 20:49 ` Alyssa Ross
  2 siblings, 0 replies; 6+ messages in thread
From: Demi Marie Obenour @ 2025-11-02 20:09 UTC (permalink / raw)
  To: Alyssa Ross, devel; +Cc: Yureka Lilian


[-- Attachment #1.1.1: Type: text/plain, Size: 1247 bytes --]

On 11/2/25 10:00, Alyssa Ross wrote:
> The expected warnings frequently confuse people.

Ideally there would be a way to suppress only "device already added
errors", but since there is not:

> Signed-off-by: Alyssa Ross <hi@alyssa.is>
> ---
>  host/rootfs/image/usr/bin/assign-devices | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/host/rootfs/image/usr/bin/assign-devices b/host/rootfs/image/usr/bin/assign-devices
> index 1332a40..58dd3cc 100755
> --- a/host/rootfs/image/usr/bin/assign-devices
> +++ b/host/rootfs/image/usr/bin/assign-devices
> @@ -5,4 +5,9 @@
>  elglob -0 devices /sys/bus/pci/drivers/vfio-pci/????:??:??.?
>  forx -pE device { $devices }
>  
> +# This script is designed to be re-entrant and called multiple times.
> +# This means we expect to sometimes get an error due to the device
> +# already having been added.  If there's a different error,
> +# cloud-hypervisor will probably log it itself anyway.
> +redirfd -w 2 /dev/null
>  ch-remote --api-socket /run/vm/by-name/sys.netvm/vmm add-device path=${device}
> 
> base-commit: e0f5aad7901d150b1abe381ffd99d554e65e758b

Reviewed-by: Demi Marie Obenour <demiobenour@gmail.com>
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent
  2025-11-02 15:00 ` [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent Alyssa Ross
  2025-11-02 20:08   ` Demi Marie Obenour
@ 2025-11-02 20:49   ` Alyssa Ross
  1 sibling, 0 replies; 6+ messages in thread
From: Alyssa Ross @ 2025-11-02 20:49 UTC (permalink / raw)
  To: Alyssa Ross, devel; +Cc: Demi Marie Obenour, Yureka Lilian

This patch has been committed as 1d666582892fbdf812662b4490caf7821078eaf9,
which can be viewed online at
https://spectrum-os.org/git/spectrum/commit/?id=1d666582892fbdf812662b4490caf7821078eaf9.

This is an automated message.  Send comments/questions/requests to:
Alyssa Ross <hi@alyssa.is>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] host/rootfs: assign-devices: silence errors
  2025-11-02 15:00 [PATCH 1/2] host/rootfs: assign-devices: silence errors Alyssa Ross
  2025-11-02 15:00 ` [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent Alyssa Ross
  2025-11-02 20:09 ` [PATCH 1/2] host/rootfs: assign-devices: silence errors Demi Marie Obenour
@ 2025-11-02 20:49 ` Alyssa Ross
  2 siblings, 0 replies; 6+ messages in thread
From: Alyssa Ross @ 2025-11-02 20:49 UTC (permalink / raw)
  To: Alyssa Ross, devel; +Cc: Demi Marie Obenour, Yureka Lilian

This patch has been committed as f202f8d9c55034b9696f20199e7db2db535a0909,
which can be viewed online at
https://spectrum-os.org/git/spectrum/commit/?id=f202f8d9c55034b9696f20199e7db2db535a0909.

This is an automated message.  Send comments/questions/requests to:
Alyssa Ross <hi@alyssa.is>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-02 20:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-02 15:00 [PATCH 1/2] host/rootfs: assign-devices: silence errors Alyssa Ross
2025-11-02 15:00 ` [PATCH 2/2] host/rootfs: /etc/mdev/net/add: make idempotent Alyssa Ross
2025-11-02 20:08   ` Demi Marie Obenour
2025-11-02 20:49   ` Alyssa Ross
2025-11-02 20:09 ` [PATCH 1/2] host/rootfs: assign-devices: silence errors Demi Marie Obenour
2025-11-02 20:49 ` Alyssa Ross

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).