Skip to contentSkip to conversation

Invalidating udev cache...

RFC Superseded Denys Dmytriyenko 6 participants 11 messages Apr 14, 2009 – Apr 18, 2009

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw
Quoted 21 lines · Tom Rini
Quoted 20 lines · Koen Kooi
Quoted 19 lines · Denys Dmytriyenko
Quoted 17 lines · Koen Kooi
Quoted 6 lines · Mike (mwester)
Quoted 4 lines · Mike (mwester)

A slight improvement would be to make the dev.tar file dependent upon the bootargs; i.e. invalidate /etc/dev.tar file if the boot command line doesn't match the current command line. This could be a very fast operation, just "cmp /proc/cmdline /etc/dev_cmdline" or similar.

Quoted 8 lines

As I consider this further, we could actually just save and compare /proc/atags if that's present on the device in question (falling back to /proc/cmdline if not present). That would catch *any* changes passed in to the kernel via the bootloader.

Flashing a new kernel would seem to be another logical place to invalidate the cache, so adding a comparison of "uname -rv" would be a reasonable way to catch that.

That should indeed take care of bootargs and kernel version changes. I'm still tempted to add option 2) to all that :)

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Sorry for bringing up this old discussion. Are there any plans to implement the above checks in udev?

Plans yes, time no :(

Can we make sure they're optional?

I'd like to revive this old topic and propose a patch, which implements most of the above points. I'm not sure about making it optional and /proc/atags. So, anyway, the patch will follow, please provide comments.

Signature · 1 line
Denys
#1 lore raw

PATCH 1/1 udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

---
 recipes/udev/udev-124/init |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
recipes/udev/udev-124/init +9 -1
index 9e11f08..840cddd 100644
@@ -34,7 +34,10 @@ LANG=C awk "\$2 == \"/dev\" && \$4 == \"tmpfs\" { exit 1 }" /proc/mounts && {
         mkdir -m 0755 /dev/shm
 }
 
-if [ -e /etc/dev.tar ]; then
+# Invalidate udev cache if the kernel or its bootargs/cmdline have changed
+[ -x /bin/uname ] && /bin/uname -mrspv > /tmp/uname || touch /tmp/uname
+[ -r /proc/cmdline ] && cat /proc/cmdline > /tmp/cmdline || touch /tmp/cmdline
+if [ -e /etc/dev.tar ] && cmp -s /tmp/uname /etc/uname && cmp -s /tmp/cmdline /etc/cmdline; then
 	(cd /; tar xf /etc/dev.tar)
 	not_first_boot=1
 fi
@@ -50,10 +53,15 @@ kill_udevd > "/dev/null" 2>&1
 		if [ "$not_first_boot" != "" ];then
 			/sbin/udevadm trigger --subsystem-nomatch=tty --subsystem-nomatch=mem --subsystem-nomatch=vc --subsystem-nomatch=vtconsole --subsystem-nomatch=misc --subsystem-nomatch=dcon --subsystem-nomatch=pci_bus  --subsystem-nomatch=graphics  --subsystem-nomatch=backlight --subsystem-nomatch=video4linux  --subsystem-nomatch=platform
 			(/sbin/udevadm settle --timeout=3; /sbin/udevadm control env STARTUP=)&
+			rm -f /tmp/uname
+			rm -f /tmp/cmdline
 		else
 			/sbin/udevadm trigger
 			/sbin/udevadm settle
+			echo -n " and populating dev cache"
 			(cd /; tar cf /etc/dev.tar dev)
+			mv /tmp/uname /etc/uname
+			mv /tmp/cmdline /etc/cmdline
 		fi
 
 echo
Signature · 1 line
1.6.0.6
#2 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

recipes/udev/udev-124/init kill_udevd > "/dev/null" 2>&1 · line 64

Quoted 2 lines · Denys Dmytriyenko
recipes/udev/udev-124/init +2 -0
+			mv /tmp/uname /etc/uname
+			mv /tmp/cmdline /etc/cmdline

I think we should put those in /etc/udev or /var/lib/udev if udev will be the only consumer.

regards,

Koen

#3 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

Quoted 6 lines · Denys Dmytriyenko

recipes/udev/udev-124/init kill_udevd > "/dev/null" 2>&1 · line 64

Quoted 2 lines
recipes/udev/udev-124/init +2 -0
+			mv /tmp/uname /etc/uname
+			mv /tmp/cmdline /etc/cmdline

I think we should put those in /etc/udev or /var/lib/udev if udev will be the only consumer.

+1, e.g.

/etc/udev/saved.uname
/etc/udev/saved.cmdline

#4 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

Quoted 11 lines · Holger Schurig
Quoted 6 lines · Denys Dmytriyenko

recipes/udev/udev-124/init kill_udevd > "/dev/null" 2>&1 · line 64

Quoted 2 lines
recipes/udev/udev-124/init +2 -0
+			mv /tmp/uname /etc/uname
+			mv /tmp/cmdline /etc/cmdline

I think we should put those in /etc/udev or /var/lib/udev if udev will be the only consumer.

+1, e.g.

/etc/udev/saved.uname
/etc/udev/saved.cmdline

Good point, I'll be sending the update. Are there any other comments/suggestions?

Signature · 1 line
Denys
#5 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

Quoted 8 lines · Denys Dmytriyenko
Quoted 7 lines · Holger Schurig
Quoted 6 lines · Denys Dmytriyenko
Quoted 2 lines

+                 mv /tmp/uname /etc/uname
+                 mv /tmp/cmdline /etc/cmdline

I think we should put those in /etc/udev or /var/lib/udev if udev will be the only consumer.

Quoted 7 lines
Quoted 4 lines

+1, e.g.

/etc/udev/saved.uname
/etc/udev/saved.cmdline

Good point, I'll be sending the update. Are there any other comments/suggestions?

It would be nice to, while on that, evaluate the possibility of updating udev; 0.141 fixes a serious security whole and even if most embedded systems usually runs as root, there're many that doesn't.

Signature · 3 lines
Otavio Salvador                  O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854         http://projetos.ossystems.com.br
#6 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

Quoted 14 lines · Otavio Salvador
Quoted 13 lines · Denys Dmytriyenko
Quoted 11 lines · Holger Schurig
Quoted 6 lines · Denys Dmytriyenko

recipes/udev/udev-124/init kill_udevd > "/dev/null" 2>&1 · line 64

Quoted 2 lines
recipes/udev/udev-124/init +2 -0
+                 mv /tmp/uname /etc/uname
+                 mv /tmp/cmdline /etc/cmdline

I think we should put those in /etc/udev or /var/lib/udev if udev will be the only consumer.

+1, e.g.

/etc/udev/saved.uname
/etc/udev/saved.cmdline

Quoted 7 lines
Quoted 2 lines

Good point, I'll be sending the update. Are there any other comments/suggestions?

It would be nice to, while on that, evaluate the possibility of updating udev; 0.141 fixes a serious security whole and even if most embedded systems usually runs as root, there're many that doesn't.

Also 141 will allow us to reduce the recipe to something like 'inherit autotools_stage' :)

regards,

Koen

#7 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

In reply to Denys Dmytriyenko
Quoted 4 lines · Denys Dmytriyenko
---
 recipes/udev/udev-124/init |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

So, for making it optional, how about adding something to /etc/default to enable / disable dev caching all together? And, I believe /proc/atags would just be cp /proc/atags /tmp/atags || touch /tmp/atags.

Signature · 1 line
Tom Rini
#8 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

Quoted 10 lines · Tom Rini
Quoted 4 lines · Denys Dmytriyenko
---
  recipes/udev/udev-124/init |   10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)

So, for making it optional, how about adding something to /etc/default to enable / disable dev caching all together? And, I believe /proc/atags would just be cp /proc/atags /tmp/atags || touch /tmp/atags.

Do we really want atags in there? As the name says, they are ARM TAGs, and only when kexec is enabled. Does it buy us anything over /proc/cmdline?

regards,

Koen

#9 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

Quoted 8 lines · Koen Kooi
Quoted 7 lines · Tom Rini
Quoted 4 lines · Denys Dmytriyenko
---
  recipes/udev/udev-124/init |   10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)
Quoted 7 lines
Quoted 3 lines

So, for making it optional, how about adding something to /etc/default to enable / disable dev caching all together? And, I believe /proc/atags would just be cp /proc/atags /tmp/atags || touch /tmp/atags.

Do we really want atags in there? As the name says, they are ARM TAGs, and only when kexec is enabled. Does it buy us anything over /proc/cmdline?

I'll leave that up to mwester as it was his suggestion originally.

Signature · 1 line
Tom Rini
#10 lore raw

Re: [PATCH] udev 124: add cache invalidation logic on kernel change or its bootargs/cmdline

Quoted 8 lines · Tom Rini
Quoted 7 lines · Koen Kooi
Quoted 6 lines · Tom Rini
Quoted 4 lines · Denys Dmytriyenko
---
  recipes/udev/udev-124/init |   10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

So, for making it optional, how about adding something to /etc/default to enable / disable dev caching all together? And, I believe /proc/atags would just be cp /proc/atags /tmp/atags || touch /tmp/atags.

Do we really want atags in there? As the name says, they are ARM TAGs, and only when kexec is enabled. Does it buy us anything over /proc/cmdline?

I'll leave that up to mwester as it was his suggestion originally.

Executive Summary: I don't really care one way or another.

Detail for why this was mentioned in the first place:

The discussion that led up the ARM ATAG suggestion involved an exploration of all the possible things that could happen to a device that might cause trouble because of a stale cache. Using /proc/cmdline is good, but the suggestion to use the ATAG list was offered because it captures not just the command line itself, but might also capture other hardware changes.

As a specific example, consider the use case where one takes a bootable SD-card image from one om-gta02 device, and plugs it into a different one with a different hardware version (significant on the om-gta0x devices). The use of /proc/cmdline will result in a stale cache; the use of /proc/atags will catch that the revision number in the atag list has changed.

Is that sufficient reason to use /proc/atags? I think that's a pretty far-fetched and unusual use-case, and if someone is doing that, they should expect things to break.

So I have no real-world concern if just /proc/cmdline is used.

Regards,
Mike (mwester)