From nobody Thu Jul 20 21:13:31 2023 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R6QQm07q0z4nPSY for ; Thu, 20 Jul 2023 21:13:36 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R6QQl4x7Yz3nVC for ; Thu, 20 Jul 2023 21:13:35 +0000 (UTC) (envelope-from mjguzik@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-1b060bce5b0so960336fac.3 for ; Thu, 20 Jul 2023 14:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689887613; x=1690492413; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=eGLEJb4him2NXmWDv285L/PbhQsB9LSfZTUcvUXk1hw=; b=iTRsxiPUIEaVFeiawTy0gCOGHd6g+OO0gQ1S4qgTkdxo1gorPei8du5ZBUGL762xKT hWs4iChXEz/xYqWw4bLQVDvpQrKe7R5S8kTTr08qhCKoCOH4TPtNLVKl+kOSPKphda96 U1qnJ+AtgRdO80V5ReQwmFjU6758CE7k1MtxPE0cTOKX06w0Lf+9PcfhaOXnuCY89q7b ltl4T12O34x+EQu6L0+EYuiVXzN7unNchf2xP5T3sR5OGlXyzQhrm3QQLlrKxfEeHljz N/EK+PjAVSohnCgx0VIfPPz1qwudXTMRaOGaG8AFv7xKf0NtJe/SHtNOEYOc9csiOB2p 5foA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689887613; x=1690492413; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eGLEJb4him2NXmWDv285L/PbhQsB9LSfZTUcvUXk1hw=; b=JNEZ7eDKiZUOGm03LcjR6EZYQ76g3w4U5nmWNNTClTV6WxY4vzBkzuWlwq8F9T8kI5 1trzBq7R6dJvUc/vuJCU1eu0G6Y8QaZHS49DMuaSz6NQ+1phGExZR6fMr0fhORE/SfBv KZLno9Xb37VRjrh0TvFFXZteFKAbcHNF+gmE5tBxwu9Y1/pnGEBl91ZSW4UHIjfD5NRg X1zbRis4qsk4ynRNq1m+JV8oE5ecUlH29M+Er7A6PQnsjLbeXgxgN03WrK8uotKuJHEW xCkdlD3L82nB+HpjHISX79Zv23+0xiL/jL9kDRK/DMiWMJevowElofjnhzUFKmCQyRGc KyFw== X-Gm-Message-State: ABy/qLY5uGfiOF89f9UXGjA8v+wR4QeMVzzE5GiURFu4aR3n/DuuEDGD Jdd7FVgaYbt2i9thWUhciayFDfd26rCBovwpLjUaGb1V X-Google-Smtp-Source: APBJJlFs4Z/qyfhg2hCADGod7zRPWdqJxH7y8IUAvzoxfL2r2mN1pJbJAT1iw6z15JnXYPCDZT8hJXWo526aoN9F5tU= X-Received: by 2002:a05:6870:910d:b0:1ba:989b:ca65 with SMTP id o13-20020a056870910d00b001ba989bca65mr582348oae.19.1689887612476; Thu, 20 Jul 2023 14:13:32 -0700 (PDT) List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Received: by 2002:a8a:1198:0:b0:4e1:6042:cdc9 with HTTP; Thu, 20 Jul 2023 14:13:31 -0700 (PDT) In-Reply-To: <120E9843-2732-4D2D-A23D-CB608F199E84@karels.net> References: <120E9843-2732-4D2D-A23D-CB608F199E84@karels.net> From: Mateusz Guzik Date: Thu, 20 Jul 2023 23:13:31 +0200 Message-ID: Subject: Re: confusion about root partition causes panic during startup To: Mike Karels Cc: Current FreeBSD Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4R6QQl4x7Yz3nVC X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2001:4860:4864::/48, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated On 7/20/23, Mike Karels wrote: > I installed an additional NVME drive on a system, and then booted. It > turns > out that the new drive became nda0, renumbering the other drives. The > loader > found the correct partition to boot (the only choice), and loaded the > kernel > correctly. However, /etc/fstab still had the old name (nvd1p2), which is > now drive 2. I expected it to drop into single user, but instead the > system > panicked in vfs_mountroot_shuffle trying to switch root devices (see > below). > It doesn't seem that having the wrong root device in /etc/fstab should > cause > a panic; it makes it harder to patch the system. I was unable to get the > system to boot using boot-to-single-user or setting currdev, but I managed > to remember doing "boot -a" from a loader prompt to get the system to ask > the root device before mounting it. I can easily reproduce this to test. > Probably the NDFREE_PNBUF() shouldn't happen if namei() returned an error. > ye, this should do it (untested): diff --git a/sys/kern/vfs_mountroot.c b/sys/kern/vfs_mountroot.c index 956d29e3f084..85398ff781e4 100644 --- a/sys/kern/vfs_mountroot.c +++ b/sys/kern/vfs_mountroot.c @@ -352,13 +352,13 @@ vfs_mountroot_shuffle(struct thread *td, struct mount *mpdevfs) NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspath); error = namei(&nd); if (error) { - NDFREE_PNBUF(&nd); fspath = "/mnt"; NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspath); error = namei(&nd); } if (!error) { + NDFREE_PNBUF(&nd); vp = nd.ni_vp; error = (vp->v_type == VDIR) ? 0 : ENOTDIR; if (!error) @@ -376,7 +376,6 @@ vfs_mountroot_shuffle(struct thread *td, struct mount *mpdevfs) } else vput(vp); } - NDFREE_PNBUF(&nd); if (error) printf("mountroot: unable to remount previous root " @@ -387,6 +386,7 @@ vfs_mountroot_shuffle(struct thread *td, struct mount *mpdevfs) NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, "/dev"); error = namei(&nd); if (!error) { + NDFREE_PNBUF(&nd); vp = nd.ni_vp; error = (vp->v_type == VDIR) ? 0 : ENOTDIR; if (!error) > Mike > > Trying to mount root from ufs:/dev/nvd1p2 [rw]... > WARNING: WITNESS option enabled, expect reduced performance. > mountroot: unable to remount devfs under /dev (error 2) > panic: Assertion _ndp->ni_cnd.cn_pnbuf != NULL failed at > ../../../kern/vfs_mountroot.c:416 > cpuid = 19 > time = 11 > KDB: stack backtrace: > db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame > 0xfffffe006d3bac40 > vpanic() at vpanic+0x149/frame 0xfffffe006d3bac90 > panic() at panic+0x43/frame 0xfffffe006d3bacf0 > vfs_mountroot() at vfs_mountroot+0x1bf7/frame 0xfffffe006d3bae60 > start_init() at start_init+0x23/frame 0xfffffe006d3baef0 > fork_exit() at fork_exit+0x82/frame 0xfffffe006d3baf30 > fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe006d3baf30 > --- trap 0x5c035c02, rip = 0x680c680c680c680c, rsp = 0x1b6b1f6b1b6b1b6b, rbp > = 0x4eb54eb54eb54eb5 --- > KDB: enter: panic > [ thread pid 1 tid 100002 ] > Stopped at kdb_enter+0x32: movq $0,0xde7643(%rip) > > -- Mateusz Guzik