From nobody Tue Nov 29 17:40:24 2022 X-Original-To: dev-commits-src-branches@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 4NM8kJ4Hqqz4jMSm; Tue, 29 Nov 2022 17:40:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NM8kJ3T9Sz4bwp; Tue, 29 Nov 2022 17:40:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669743624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6Q37zZNmDEdLD08ao3pHQorYE85XaGrFQgdy188+G9g=; b=s3UOoBKTTRB7ZovwV0ILk1Dy+ltsjY3iD0w3lG9EuKkS6sHIMfcj4Ps+gC6nNtIS8aBRz7 XGyRDgxwz/A3ctREcAFJWCjegDG8Wl01QAln6pFpQoI82+2i+IvW2JfWJkp6eh4fvhhs3I sU62hhntOAEYmEY71mqo51jDgpCsPz02THwSfQE+np14NTiPIHYku0100yjqvd7wMjHKQY ivNYfrpY9Ab1tKlVRacNd2I1zSE5soWkzC+CY9vXPnDr1Y9rM39wGUbmzOjXDf6dlGJlkO 39dn9o/6Ov2ZEvGSKWLGGig88kkdC+T2Ny8oMwvBO9KLCPkRP2HIfaP4CyJhTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669743624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6Q37zZNmDEdLD08ao3pHQorYE85XaGrFQgdy188+G9g=; b=a/tPGVTpd2tCK6ZyGMfAcbmn3B1fnOWk62jvq4TbmKWfluUwHNKlShVkz/6SYQ5wbDkRA5 LwEkSsTCox4z3TcwdF76HCr3FpPC3ncNUZQFfcsLb4KP4NI23MA52oHbne7w15w1BAPSlN o92rTkMIfg/xHepfAZvV1l0zU9ur+sP6TSQY3zEdzPJcpr/YfOck0QkK36amsBSuoSsqIZ Jd2TmMgMTivE+Kxsw+9IoW4hbYVNHgSK/N+8xJFgDEWINQ4k9ZsrYMLMcYi5udULSEB1+3 3ClLN+G2548IHusWlkKBV9pW5EUTtBnDsqNc2/PQ0AI7xNrPsxjaAxxzIOhJSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669743624; a=rsa-sha256; cv=none; b=nCyeKus5CcQ7dAQQJq5d8NtQXBL4IK10fYz9eEPH1uXx5h8M6y6ptTDI/4WPHhB5lT533s YeVXuhzs1Gd6LcZG7qpGSReEqH1wcB4mKyIPktOanlT1pnZ+OySiZkvVQd/eduWsHy91zM o5hnVCff/iHnKHUqYvz7iG9fapK3HUotOU6kAz/6OGULnbmUTDVAnJk9MuFKY/VGAUdJ/e BQOLjq7uzR/L8cr8TjRrG/2CoW3lUa8c2Uej9yFa5GGLwm1IqpRFfl6X9JXtEw1wMJs9Kn 4enumdUMbL+zHkp6CX01kGXZfEs3HFspgOM88vTWxUdXueM4MZQlF8GoiLkLQA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NM8kJ2YZwzQW5; Tue, 29 Nov 2022 17:40:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2ATHeOeQ051739; Tue, 29 Nov 2022 17:40:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2ATHeOCV051738; Tue, 29 Nov 2022 17:40:24 GMT (envelope-from git) Date: Tue, 29 Nov 2022 17:40:24 GMT Message-Id: <202211291740.2ATHeOCV051738@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: a5fee360b4d5 - stable/13 - bhyve: Cast away const when fetching a config nvlist List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a5fee360b4d5fa0a5f6b1c9e556f50e887ceda45 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=a5fee360b4d5fa0a5f6b1c9e556f50e887ceda45 commit a5fee360b4d5fa0a5f6b1c9e556f50e887ceda45 Author: Mark Johnston AuthorDate: 2022-11-11 15:02:42 +0000 Commit: Mark Johnston CommitDate: 2022-11-29 17:40:13 +0000 bhyve: Cast away const when fetching a config nvlist Silence a warning from the compiler about "const" being discarded. The warning is correct: nvlist values are supposed to be immutable. However, fixing this properly will require some contortions on behalf of consumers who look up a subtree of the config and modify it. Per a discussion on freebsd-virtualization@, the solution will probably be to outright replace the use of nvlists for VM configuration, but until that happens let's document the problem and silence the warning. No functional change intended. MFC after: 2 weeks Reviewed by: corvink, jhb Differential Revision: https://reviews.freebsd.org/D37293 (cherry picked from commit 719e307f80c724a39814557e35ac890c75dcd402) --- usr.sbin/bhyve/config.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/config.c b/usr.sbin/bhyve/config.c index f398ea76fc58..e302f919adab 100644 --- a/usr.sbin/bhyve/config.c +++ b/usr.sbin/bhyve/config.c @@ -65,7 +65,17 @@ _lookup_config_node(nvlist_t *parent, const char *path, bool create) break; } if (nvlist_exists_nvlist(nvl, name)) - nvl = (nvlist_t *)nvlist_get_nvlist(nvl, name); + /* + * XXX-MJ it is incorrect to cast away the const + * qualifier like this since the contract with nvlist + * says that values are immuatable, and some consumers + * will indeed add nodes to the returned nvlist. In + * practice, however, it appears to be harmless with the + * current nvlist implementation, so we just live with + * it until the implementation is reworked. + */ + nvl = __DECONST(nvlist_t *, + nvlist_get_nvlist(nvl, name)); else if (nvlist_exists(nvl, name)) { for (copy = tofree; copy < name; copy++) if (*copy == '\0') @@ -76,6 +86,10 @@ _lookup_config_node(nvlist_t *parent, const char *path, bool create) nvl = NULL; break; } else if (create) { + /* + * XXX-MJ as with the case above, "new_nvl" shouldn't be + * mutated after its ownership is given to "nvl". + */ new_nvl = nvlist_create(0); if (new_nvl == NULL) errx(4, "Failed to allocate memory");