Skip to content

xde detach panicked on Arc::try_unwrap #178

Closed

Description

@rzezeski

While doing a demo dry run we somehow got into a state where the opte1 xde device was removed from DLS (what dladm shows), but the OPTE Port opte1 was not deleted. No one on the call knows how this happened. It seems like something had possibly gone wrong with instance stop that left some state around, but we don't really know.

In this scenario we cannot manually delete the opte1 OPTE Port via opteadm because the xde handler code expects to be able to delete the DLS devnet ID.

    // destroy dls devnet device
    let ret = unsafe {
        dls::dls_devnet_destroy(xde.mh, &mut xde.linkid, boolean_t::B_TRUE)
    };

However, since the DLS device was already deleted this always fails. So then I recommended unloading the xde driver in order to clear the state, but that resulted in the following crash:

WARNING: panicked at 'called `Result::unwrap()` on an `Err` value: xde_underlay_port { name: "net0", mh: 0xfffffeb1d99b4028, mch: MacClient { close_flags: 0, mch: 0xfffffeb1cf1dd8e8 }, mph: 0xfffffeb1e2b05e08 }', src/xde.rs:947:51

The problem code is:

    let state = Box::from_raw(rstate as *mut XdeState);
    let underlay = state.underlay.into_inner();

    match underlay {
        Some(underlay) => {
            let u1 = Arc::try_unwrap(underlay.u1).unwrap();

Specifically, since there is still an outstanding port, there is more than one strong ref to the underlay (u1).

The solution is probably to have detatch first check that there are no existing ports, otherwise it needs to immediately return failure. However, in this scenario, that would mean there is no way to get OPTE/xde out of this broken state without restarting the machine. So perhaps, along with this change, we also need some "force" option for the delete port command so that it will delete the OPTE Port even if the DLS devnet device doesn't exist.

Activity

  1. rzezeski commented on Jul 8, 2022

    @rzezeski
    ContributorAuthor

    I have a hunch on how we got into this state based on oxidecomputer/omicron#1364. For this example we'll assume a guest using an OPTE Port of opte0 (as reported by opteadm list-ports), which has a DLS devnet entry name of opte0 (as reported by dladm), and a VNIC of vopte0 (as reported by dladm). The guest's viona has a handle open to vopte0. With that setup I think the following steps get us into trouble:

    1. Something besides the guest's viona device is holding a reference open to vopte0, say an instance of snoop(1M) run by the operator.
    2. The operator decides to stop the instance. The instance stop eventually calls the Drop impl for Omicron's OptePort structure. This drop impl does two things: attempts to delete vopte0, and then attempts to call the OpteCmd::DeleteXde command.
    3. The vopte0 deletion fails because the snoop process is holding onto it. But the drop impl proceeds to run the DeleteXde command anyways.
    4. The DeleteXde command has 3 steps: delete the DLS devnet entry, unregister the mac provider, remove the device from the devs list (which is what opteadm list-ports is based on).
    5. The deletion of the DLS devnet entry succeeds, but the unregistering of the mac provider fails because there are still outstanding clients (vopte0). Upon failure the DeleteXde command returns immediately, and thus the device is never removed from the devs list.

    The reason this can happen is that the DLS devnet entry is not actually opened by anything in this scenario, and thus the dls_devnet_t.dd_ref == 1. This allows the DLS devnet entry to be deleted even though the mac provider and OPTE port still exist. There are two things to consider here:

    • The plan is to NOT have a VNIC atop the OPTE port, but rather have clients directly consume it. In that case the DLS devnet would be opened and would have an additional reference keeping it from being deleted.
    • Until that happens, the DeleteXde code should probably only remove the DLS entry if the mac is successfully unregistered.
  2. rzezeski commented on Jul 8, 2022

    @rzezeski
    ContributorAuthor

    To prove this is the case we can look at state on host sock. Notice that the dd_ref for vopte0 is 2 because viona has it opened, but opte0 is 1 because nothing has it open. And if you look at the impl for dls_devnet_unset() you'll see that it proceeds with deletion so long as dd_ref == 1.

    rpz@sock ~ $ dladm
    LINK        CLASS     MTU    STATE    BRIDGE     OVER
    igb0        phys      1500   up       --         --
    igb1        phys      1500   unknown  --         --
    stub0       etherstub 9000   up       --         --
    underlay0   vnic      9000   up       --         stub0
    net0        vnic      1500   up       --         igb0
    net1        vnic      1500   up       --         igb0
    oxControlService0 vnic 9000  up       --         stub0
    oxControlStorage0 vnic 9000  up       --         stub0
    oxControlStorage1 vnic 9000  up       --         stub0
    oxControlStorage2 vnic 9000  up       --         stub0
    oxControlStorage3 vnic 9000  up       --         stub0
    oxControlStorage4 vnic 9000  up       --         stub0
    oxControlService1 vnic 9000  up       --         stub0
    oxControlService2 vnic 9000  up       --         stub0
    opte0       xde       1500   up       --         --
    vopte0      vnic      1500   up       --         opte0
    oxControlInstance0 vnic 9000 up       --         stub0
    
    rpz@sock ~ $ pfexec mdb -ke '::walk dls_devnet_cache |::printf "%s %u\n" dls_devnet_t dd_linkname dd_ref ! grep opte'
    opte0 1
    vopte0 2
    
  3. rzezeski commented on Jul 11, 2022

    @rzezeski
    ContributorAuthor

    Just to be completely sure I had this right I replicated the scenario described in oxidecomputer/omicron#1364 and verified that DLS devent deletion succeeds while mac unregister fails.

    First, dladm before stopping the instance.

    rpz@kalm:~$ dladm                                                         
    LINK        CLASS     MTU    STATE    BRIDGE     OVER 
    e1000g0     phys      1500   up       --         --     
    net0        vnic      1500   up       --         e1000g0                                                                                             
    net1        vnic      1500   up       --         e1000g0
    stub0       etherstub 9000   up       --         --    
    underlay0   vnic      9000   up       --         stub0 
    opte0       xde       1500   up       --         --    
    vopte0      vnic      1500   up       --         opte0 
    
    • Run a snoop on vopte0.
    • Run a DTrace one-liner to monitor return from DLS/mac.
    • Stop the instance.

    Sled agent log reports failure.

    {"msg":"Stopped and uninstalled zone","v":0,"name":"SledAgent","level":30,"time":"2022-07-11T16:29:07.995777624Z","hostname":"kalm","pid":951,"zone":"oxz_propolis-server_78281c03-4f24-4624-a2f5-404c254b6719","instance_id":"5cac8193-09eb-49cc-98ff-4b85104b1e9d","component":"InstanceManager"}
    Failed to delete VNIC: Failed to delete vnic vopte0: Command [/usr/sbin/dladm delete-vnic vopte0] executed and failed with status: exit status: 1. Stdout: , Stderr: dladm: vnic deletion failed: link busy
    
    WARNING: Failed to delete OPTE port 'opte0'
    

    DTrace one-liner shows that dls_devnet_destroy() succeeds while mac_unregister() fails.

    rpz@kalm:~$ pfexec dtrace -qn 'delete_xde:entry { self->t = 1; } dls_devnet_destroy:return,mac_unregister:return /self->t/ { printf("%s => %d\n", probefunc, arg1); } delete_xde:return { self->t = 0; }'
    dls_devnet_destroy => 0
    mac_unregister => 16
    

    dladm shows opte0 link is gone, but vopte0 still exists.

    ^Crpz@kalm:~$ dladm  
    LINK        CLASS     MTU    STATE    BRIDGE     OVER                                                                                                
    e1000g0     phys      1500   up       --         -- 
    net0        vnic      1500   up       --         e1000g0
    net1        vnic      1500   up       --         e1000g0
    stub0       etherstub 9000   up       --         --    
    underlay0   vnic      9000   up       --         stub0 
    vopte0      vnic      1500   up       --         opte0
    

    opteadm shows that opte0 still exists.

    rpz@kalm:~/oxidecomputer/opte/opteadm$ pfexec opteadm list-ports
    LINK                             MAC ADDRESS              IPv4 ADDRESS     STATE   
    opte0                            A8:40:25:F1:78:FD        172.30.0.5       running 
    
  4. rzezeski commented on Jul 11, 2022

    @rzezeski
    ContributorAuthor

    I tested the fix by putting my host into the state described above and then verifying that xde refuses to detach.

    rpz@kalm:~/oxidecomputer/opte/opteadm$ modinfo | grep xde
    251 fffffffff8142000  f6d60 279   1  xde (xde)
    rpz@kalm:~/oxidecomputer/opte/opteadm$ pfexec modunload -i 251
    can't unload the module: Device busy
    
    rpz@kalm:~$ tail -f /var/adm/messages
    Jul 11 18:56:36 kalm mac: [ID 435574 kern.info] NOTICE: xde1066 link up, 0 Mbps, unknown duplex
    Jul 11 18:56:36 kalm mac: [ID 469746 kern.info] NOTICE: vnic1067 registered
    Jul 11 18:56:36 kalm mac: [ID 435574 kern.info] NOTICE: vnic1067 link up, 0 Mbps, unknown duplex
    Jul 11 18:56:36 kalm mac: [ID 469746 kern.info] NOTICE: vnic1068 registered
    Jul 11 18:56:36 kalm mac: [ID 435574 kern.info] NOTICE: vnic1068 link up, 0 Mbps, unknown duplex
    Jul 11 18:56:42 kalm genunix: [ID 408114 kern.info] /pseudo/zconsnex@1/zcons@8 (zcons8) online
    Jul 11 18:56:54 kalm bnxe: [ID 801725 kern.info] NOTICE: (bnxe): QLogic NetXtreme II 10 Gigabit Ethernet Driver v7.10.4
    Jul 11 18:58:41 kalm mac: [ID 736570 kern.info] NOTICE: vnic1068 unregistered
    Jul 11 18:59:09 kalm mac: [ID 736570 kern.info] NOTICE: vnic1067 unregistered
    Jul 11 18:59:43 kalm xde: [ID 872122 kern.warning] WARNING: failed to detach: outstanding ports
    
  5. rzezeski commented on Jul 11, 2022

    @rzezeski
    ContributorAuthor

    Addressed in 0e78c72.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions