Skip to content

During switchroot, devices transition plugged -> dead -> plugged #11997

Closed

Description

@owtaylor

systemd version the issue has been seen with
v240 and v241

Used distribution
Fedora

Unexpected behaviour you saw
With systemd 240 and 241, at switch root time, all devices change plugged -> dead -> plugged. (I tested fedora 29 + v239, v240, and v241, and it was a v239 -> v240 regression.)

In some cases, this might be mostly harmless, but see https://pagure.io/fedora-silverblue/issue/8 for a problem that it causes.

Steps to reproduce the problem

  • Install Fedora 30 nightly in a VM
  • Boot with systemd.log-level=debug printk.devkmsg=on log_buf_len=1M on the kernel command line
  • Search for plugged -> dead in the logs

Notes

With some poking and debug message insertion, I determined that the initial call to device_enumerate() after re-exec is not finding any devices - which is what I think is causing the problem - I couldn't easily find the cause in the v239 ... v240 diff.

Activity

  1. added
    regression ⚠️
    on Mar 14, 2019
  2. added this to the v242 milestone on Mar 14, 2019
  3. yuwata commented on Mar 14, 2019

    @yuwata
    Member

    I think this is caused by 1fb70e6.

    Before the commit, device_catchup() does not emit state change (plugged -> dead).

  4. added a commit that references this issue on Mar 15, 2019
    c6e892b
  5. yuwata commented on Mar 15, 2019

    @yuwata
    Member

    I hope #12013 fixes this.

  6. poettering commented on Mar 26, 2019

    @poettering
    Member

    I have the suspicion it would be a better fix to drop the initrd udev db cleanup service from the initrd. #otaylor, does that fix stuff for you?

  7. poettering commented on Mar 26, 2019

    @poettering
    Member

    (i mean, a don't really see why we would flush the udev db like we currently do. We trigger everything anyway thus making sure the new rules are in effect and its just extra worl to flush the db explicitly and it means we drop props and tags for a time during boot which creates this issue here.)

  8. poettering commented on Mar 26, 2019

    @poettering
    Member

    The only other option i see would be to freeze device unit states in pid1 while udev is not running and until all devices have been triggered and processed once. But that's always going to be awfully racy. And what happens with devices that actually really disappear during the transition? I mean, the user might actually pull a usb stick from the device right when we transition and that should definitely make the device unit in pid1 to go down

  9. poettering commented on Mar 26, 2019

    @poettering
    Member

    hmm, another idea might be to set the "db_persist" option on all devices in the initrd we consider relevant for systemd. it's frickin ugly though, but would make sure that once a device is relevant to systemd it stays so across the transition

  10. poettering commented on Mar 26, 2019

    @poettering
    Member

    So, yeah, I think the best approach for now would be to set "db_persist" on the select few devices where we really care and let's see if that makes things work.

  11. owtaylor commented on Mar 27, 2019

    @owtaylor
    ContributorAuthor

    I have the suspicion it would be a better fix to drop the initrd udev db cleanup service from the initrd. #otaylor, does that fix stuff for you?

    I tried this - patching systemd to remove initrd-udevadm-cleanup-db.service - and:

    • I don't see any plugged -> dead messages
    • my system passes the 5-consecutive-boots test
    • my system seems functional in other ways on the surface

    So, yeah, I think the best approach for now would be to set "db_persist" on the select few devices where we really care and let's see if that makes things work.

    I don't have much of an idea how to go about coming up with such a patch or figuring out what devices "where we really care". Can test it if someone does.

    @keszybz - do you have any opinions on this from a distro perspective? I think it would be great to have some fox for this in Fedora 30 - but it doesn't necessarily need to be the same fix as the long-term systemd fix. To my inexperienced eyes, dropping initrd-udevadm-cleanup-db.service would probably be pretty risky to do last minute compared to other options.

  12. added 2 commits that reference this issue on Mar 29, 2019
    057ed88
  13. yuwata commented on Mar 29, 2019

    @yuwata
    Member

    I've created #12148 and #12149 based on the above @poettering's suggestions. PTAL.

  14. yuwata commented on Apr 1, 2019

    @yuwata
    Member

    So, there exist three fix for this issue: #12013, #12148 and #12149.

    In the long run, I think #12148 is the most favorable way. Now many devices are initialized by udevd twice: in the initrd phase and after switching root. I guess most of the second initialization processes are redundant. Though, #12148 itself does not stop the double initialization. Also, I am not sure this is a good first step, i.e. before dropping initrd-udevadm-cleanup-db.service we may need to expose a flag whether a device is already initialized or not. Not sure.

    I think #12013 is the safest way within the three PRs to fix this issue, as it just fixes a side effect introduced by 1fb70e6. But as already mentioned by @poettering, some devices may disappear during switching root and pid1 cannot detect that...

  15. reopened this on Jul 3, 2019
  16. modified the milestones: v242, v243 on Jul 3, 2019
  17. yuwata commented on Jul 4, 2019

    @yuwata
    Member

    #12013 (comment)

    This is racy... if pid1 is reloaded between the switch root and udev being started up everything is still fucked...

    @fbuihuu Is the issue caused by this race condition?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pid1regression ⚠️

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions