From nobody Fri Nov 11 15:04:11 2022 X-Original-To: dev-commits-src-all@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 4N826M5m16z4dtgM; Fri, 11 Nov 2022 15:04:11 +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 4N826M4cggz4H6t; Fri, 11 Nov 2022 15:04:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668179051; 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=3jR/o01U5LO5ooFMxfYsJpj2T9b3MloABeWTqOqW6F0=; b=A4+AD4Uy93bvVqnBd+NOw5z3a0dEbl1R5AKXubwJk2mouo/ffM2VFlVwKt+yvKNZ5HXc1a 5XJcVwQD9kPkFvOMKXEHGMBPoUCAHKl0QAuXFB/WPb9yBtXJDSdvsnIw/pvFw5oBnx8C0O iQFOXQyMp96k3nGee68AZkLwyFUB2hbUP4tnc4qOqa3Ajs+TF4hV8EkU9IDOX1Ns8HQ2+Q wbTPP2fW0udgAjVrfryegZ/atRIXv802fvqCiyYFBMR7n9uvKzqpqHjDrwCqWFT1/G9wz2 faNogB463iKujIZXJ0bvSz6+g/5b3XgWM4THFQM5fF3ss4n42suo/98oChVNaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668179051; 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=3jR/o01U5LO5ooFMxfYsJpj2T9b3MloABeWTqOqW6F0=; b=dnkPtKDv0nEMDatcBSJiqnLb+qy4dMUbh9e3nFaLkzWWSIOkNA63GDukyzMhox26DQAjNA q3lOxvN+Jmfi23LBYeAgPSD/UidLUohwSMdi9Z+M9Sd9pqORJGenAXLXCtvMBSJNsthL6t wCcphgUapJ5I9GPyUSG0twBIIc6h9kQt2Eau158SUAVY772MSnAYtsXink09BjC5BwdGGr U5Dzlf5jZ35mHA+ihjkguUUjlotg9duNixdwmoYRDMYOISSaxbARtFvVnxKOIUWP2lXJ0+ zIhZC6DqdxnDD+Ed9BqHjADMb20hVjiiKvWN6bri2UKM8I17CiExdUKl86EvwQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668179051; a=rsa-sha256; cv=none; b=EQg945an36SPNXNt/99ZjB1cpTFscmsTiqP6nBuWeeOdofNnxcVOHkcJQA26RJdn0gXJm8 49DjwPgnKdszNEsb6/WUUonnpyjEjsWYiwgo5lKsz90Z4Rek7TZdwQO+V3oMY5Wu7dkUK5 I4OHsIxU/WdEPM4qKJCaZWwXRDNfDckw0szSVXWQV6KdAf/vQ/G8PziiibCkqsMERXiDGw AeLACewkmVsdevSGP5F81zhxt62NGLqx+6SY1YHGi2SLK1LdW7vXPzDRDVZNk20oupV4cr fUdp5iRRUeGWFJBPbCZCvssqsYF9lDCXnuOeGGf/MX3JikAgAfhVwa8xkLo4Bg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4N826M3dX9zmDx; Fri, 11 Nov 2022 15:04:11 +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 2ABF4BHr094244; Fri, 11 Nov 2022 15:04:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2ABF4BbO094243; Fri, 11 Nov 2022 15:04:11 GMT (envelope-from git) Date: Fri, 11 Nov 2022 15:04:11 GMT Message-Id: <202211111504.2ABF4BbO094243@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 719e307f80c7 - main - bhyve: Cast away const when fetching a config nvlist List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 719e307f80c724a39814557e35ac890c75dcd402 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=719e307f80c724a39814557e35ac890c75dcd402 commit 719e307f80c724a39814557e35ac890c75dcd402 Author: Mark Johnston AuthorDate: 2022-11-11 15:02:42 +0000 Commit: Mark Johnston CommitDate: 2022-11-11 15:02:42 +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 --- 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 de138795f4d1..6339ddb9f2ee 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");