From nobody Fri Nov 11 15:04:06 2022 X-Original-To: dev-commits-src-main@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 4N826H1gP7z4dtgB; Fri, 11 Nov 2022 15:04:07 +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 4N826H12Qwz4H4g; Fri, 11 Nov 2022 15:04:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668179047; 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=eIjja6+Xl+KcjVIRcont+XqtDHwH23ISRMpUzi6jwpc=; b=YB3Eohwx+zWSF/TFijz4sPtQKXX3vkJiKDgMKrpNdY9U9OXPWSrRjjtCRAzoU3ikYXbBrA uEErT6kbS388iQU4yBRXYeOvcYKltqXO05R+S8kcvyxYgFlt+JgG0MEimyil7WCjvQFbUa Wj8EsrsmUqerN7RlZg7IH61uvYxZ9EXn94pmwQPa124DGT5QGdoQyS4msfUwBD7yawI4LS T59EGIs+7KWKfgVsIwicJAR7/eAsRbPV4sqizIkQJaByv1QidVX4grMEfPX3GcUiABCMFN RXct2mMcxaT9RuPDnWgaAIpul+n4DnOl7KkFwcKTyTmDnUWiRBey3MnUwB1blA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668179047; 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=eIjja6+Xl+KcjVIRcont+XqtDHwH23ISRMpUzi6jwpc=; b=A6Tamj6I7Gj5tP9xSQ1cxjpNR7pSjPkIXLRnmQ+JmAl3gPcyq8NeISvFKAQhlnvgheXzDF l4GsTdy/zDiaJ6yFE7Tbo9LDs/SWmkUKzjA9Xbxb+5392S7ZAj9GtWo/CXPzR3GGPqNggD gm8Yhb7FAPOrqXRN4+OD2gEgCtu1sIOKuyav0CiJN8Ozh4G54YZkUS1Jb9uUYgsgJ1M2/V 1wEQkr20x4R6zODew8oXBGxX4jzZWkaAtZ0Lce7+L7F1SjBnkneWbCXB7zacdN24lf712f hxWENbXHgHgWMzth2aJl2Re8YpTBnRTYiTXjYB82ao6lVUMoPF7uXZ0sQAh89Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668179047; a=rsa-sha256; cv=none; b=Y/z2rtU9xc2vocjR4NuRbTZYuOhojRM7qpI2xdtaPPSJ0QDsYw/OMxbKMsT0sxwDp/cYDf /wfcpzT3c0CxyiWiiuBa8F0IkH04qk5hIEyYu+D7LUUvLYkkW4KOiuZcVQEzv8jhXtCtL+ Deu5uLfkQ90HWa+Oxx4RFx2E5SO7k/BOaWUlBEMV6vNA0XM8qSG5AYpXga8eoMuvijM/b3 mVpG+8n0F49JXk+xBWuE8td/SbGsDs0ayy0MJd4XxDCCamADSR/TJwakYRiyUgi+vmO40o YVg7T4W+Hsfp/AHz4R5bcp19O0YgvJEHHTaR9mW4qWGPthfyEv30sXfPqyolNw== 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 4N826H05jjzmMf; Fri, 11 Nov 2022 15:04:07 +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 2ABF46lQ094138; Fri, 11 Nov 2022 15:04:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2ABF46UW094137; Fri, 11 Nov 2022 15:04:06 GMT (envelope-from git) Date: Fri, 11 Nov 2022 15:04:06 GMT Message-Id: <202211111504.2ABF46UW094137@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: 0ced97acb051 - main - bhyve: Define an accessor for net backend private data List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 0ced97acb05197cb2ef30932786eab0512f77e07 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0ced97acb05197cb2ef30932786eab0512f77e07 commit 0ced97acb05197cb2ef30932786eab0512f77e07 Author: Mark Johnston AuthorDate: 2022-11-11 15:01:40 +0000 Commit: Mark Johnston CommitDate: 2022-11-11 15:01:40 +0000 bhyve: Define an accessor for net backend private data Use it to silence warnings about potential unaligned accesses. No functional change intended. MFC after: 1 week Reviewed by: corvink, jhb Differential Revision: https://reviews.freebsd.org/D37289 --- usr.sbin/bhyve/net_backends.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/usr.sbin/bhyve/net_backends.c b/usr.sbin/bhyve/net_backends.c index 4e80cd885e52..5dd5f8a17d66 100644 --- a/usr.sbin/bhyve/net_backends.c +++ b/usr.sbin/bhyve/net_backends.c @@ -168,10 +168,12 @@ struct net_backend { /* Size of backend-specific private data. */ size_t priv_size; - /* Room for backend-specific data. */ - char opaque[0]; + /* Backend-specific private data follows. */ }; +#define NET_BE_PRIV(be) ((void *)((be) + 1)) +#define NET_BE_SIZE(be) (sizeof(*be) + (be)->priv_size) + SET_DECLARE(net_backend_set, struct net_backend); #define VNET_HDR_LEN sizeof(struct virtio_net_rxhdr) @@ -207,7 +209,7 @@ struct tap_priv { static void tap_cleanup(struct net_backend *be) { - struct tap_priv *priv = (struct tap_priv *)be->opaque; + struct tap_priv *priv = NET_BE_PRIV(be); if (priv->mevp) { mevent_delete(priv->mevp); @@ -222,7 +224,7 @@ static int tap_init(struct net_backend *be, const char *devname, nvlist_t *nvl __unused, net_be_rxeof_t cb, void *param) { - struct tap_priv *priv = (struct tap_priv *)be->opaque; + struct tap_priv *priv = NET_BE_PRIV(be); char tbuf[80]; int opt = 1; #if defined(INET6) || defined(INET) @@ -323,7 +325,7 @@ tap_send(struct net_backend *be, const struct iovec *iov, int iovcnt) static ssize_t tap_peek_recvlen(struct net_backend *be) { - struct tap_priv *priv = (struct tap_priv *)be->opaque; + struct tap_priv *priv = NET_BE_PRIV(be); ssize_t ret; if (priv->bbuflen > 0) { @@ -353,7 +355,7 @@ tap_peek_recvlen(struct net_backend *be) static ssize_t tap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt) { - struct tap_priv *priv = (struct tap_priv *)be->opaque; + struct tap_priv *priv = NET_BE_PRIV(be); ssize_t ret; if (priv->bbuflen > 0) { @@ -381,7 +383,7 @@ tap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt) static void tap_recv_enable(struct net_backend *be) { - struct tap_priv *priv = (struct tap_priv *)be->opaque; + struct tap_priv *priv = NET_BE_PRIV(be); mevent_enable(priv->mevp); } @@ -389,7 +391,7 @@ tap_recv_enable(struct net_backend *be) static void tap_recv_disable(struct net_backend *be) { - struct tap_priv *priv = (struct tap_priv *)be->opaque; + struct tap_priv *priv = NET_BE_PRIV(be); mevent_disable(priv->mevp); } @@ -453,7 +455,7 @@ static int ng_init(struct net_backend *be, const char *devname __unused, nvlist_t *nvl, net_be_rxeof_t cb, void *param) { - struct tap_priv *p = (struct tap_priv *)be->opaque; + struct tap_priv *p = NET_BE_PRIV(be); struct ngm_connect ngc; const char *value, *nodename; int sbsz; @@ -629,7 +631,7 @@ netmap_set_vnet_hdr_len(struct net_backend *be, int vnet_hdr_len) { int err; struct nmreq req; - struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + struct netmap_priv *priv = NET_BE_PRIV(be); nmreq_init(&req, priv->ifname); req.nr_cmd = NETMAP_BDG_VNET_HDR; @@ -686,7 +688,7 @@ static int netmap_init(struct net_backend *be, const char *devname, nvlist_t *nvl __unused, net_be_rxeof_t cb, void *param) { - struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + struct netmap_priv *priv = NET_BE_PRIV(be); strlcpy(priv->ifname, devname, sizeof(priv->ifname)); priv->ifname[sizeof(priv->ifname) - 1] = '\0'; @@ -717,7 +719,7 @@ netmap_init(struct net_backend *be, const char *devname, static void netmap_cleanup(struct net_backend *be) { - struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + struct netmap_priv *priv = NET_BE_PRIV(be); if (priv->mevp) { mevent_delete(priv->mevp); @@ -732,7 +734,7 @@ static ssize_t netmap_send(struct net_backend *be, const struct iovec *iov, int iovcnt) { - struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + struct netmap_priv *priv = NET_BE_PRIV(be); struct netmap_ring *ring; ssize_t totlen = 0; int nm_buf_size; @@ -811,7 +813,7 @@ txsync: static ssize_t netmap_peek_recvlen(struct net_backend *be) { - struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + struct netmap_priv *priv = NET_BE_PRIV(be); struct netmap_ring *ring = priv->rx; uint32_t head = ring->head; ssize_t totlen = 0; @@ -831,7 +833,7 @@ netmap_peek_recvlen(struct net_backend *be) static ssize_t netmap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt) { - struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + struct netmap_priv *priv = NET_BE_PRIV(be); struct netmap_slot *slot = NULL; struct netmap_ring *ring; uint8_t *iov_frag_buf; @@ -898,7 +900,7 @@ netmap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt) static void netmap_recv_enable(struct net_backend *be) { - struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + struct netmap_priv *priv = NET_BE_PRIV(be); mevent_enable(priv->mevp); } @@ -906,7 +908,7 @@ netmap_recv_enable(struct net_backend *be) static void netmap_recv_disable(struct net_backend *be) { - struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + struct netmap_priv *priv = NET_BE_PRIV(be); mevent_disable(priv->mevp); } @@ -1021,7 +1023,7 @@ netbe_init(struct net_backend **ret, nvlist_t *nvl, net_be_rxeof_t cb, return (EINVAL); } - nbe = calloc(1, sizeof(*nbe) + tbe->priv_size); + nbe = calloc(1, NET_BE_SIZE(tbe)); *nbe = *tbe; /* copy the template */ nbe->fd = -1; nbe->sc = param;