From owner-svn-src-all@freebsd.org Sat Sep 28 12:02:44 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6AD971257C3; Sat, 28 Sep 2019 12:02:44 +0000 (UTC) (envelope-from vmaffione@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46gS382GRZz48vy; Sat, 28 Sep 2019 12:02:44 +0000 (UTC) (envelope-from vmaffione@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 21906118D; Sat, 28 Sep 2019 12:02:44 +0000 (UTC) (envelope-from vmaffione@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x8SC2hxd050327; Sat, 28 Sep 2019 12:02:43 GMT (envelope-from vmaffione@FreeBSD.org) Received: (from vmaffione@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x8SC2hwV050325; Sat, 28 Sep 2019 12:02:43 GMT (envelope-from vmaffione@FreeBSD.org) Message-Id: <201909281202.x8SC2hwV050325@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vmaffione set sender to vmaffione@FreeBSD.org using -f From: Vincenzo Maffione Date: Sat, 28 Sep 2019 12:02:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r352841 - head/usr.sbin/bhyve X-SVN-Group: head X-SVN-Commit-Author: vmaffione X-SVN-Commit-Paths: head/usr.sbin/bhyve X-SVN-Commit-Revision: 352841 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Sep 2019 12:02:44 -0000 Author: vmaffione Date: Sat Sep 28 12:02:43 2019 New Revision: 352841 URL: https://svnweb.freebsd.org/changeset/base/352841 Log: bhyve: support for enabling/disabling the net backend Extend the net backend interface with two functions, namely netbe_rx_disable() and netbe_rx_enable(), which can be used by the net device emulators to stop the backend from invoking the receive callback. This is useful for device emulators, i.e., on hardware resets or to implement receive backpressure. The mevent module has been extendede to support the addition of a disabled event. To prevent race conditions, the net backends will start with receive operation disabled. A follow-up patch will use the new functionalities in the virtio-net device. Reviewed by: jhb, markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D20973 Modified: head/usr.sbin/bhyve/mevent.c head/usr.sbin/bhyve/net_backends.c head/usr.sbin/bhyve/net_backends.h Modified: head/usr.sbin/bhyve/mevent.c ============================================================================== --- head/usr.sbin/bhyve/mevent.c Sat Sep 28 09:54:03 2019 (r352840) +++ head/usr.sbin/bhyve/mevent.c Sat Sep 28 12:02:43 2019 (r352841) @@ -62,10 +62,11 @@ __FBSDID("$FreeBSD$"); #define MEVENT_MAX 64 -#define MEV_ADD 1 -#define MEV_ENABLE 2 -#define MEV_DISABLE 3 -#define MEV_DEL_PENDING 4 +#define MEV_ADD 1 +#define MEV_ENABLE 2 +#define MEV_DISABLE 3 +#define MEV_DEL_PENDING 4 +#define MEV_ADD_DISABLED 5 extern char *vmname; @@ -161,6 +162,9 @@ mevent_kq_flags(struct mevent *mevp) case MEV_ADD: ret = EV_ADD; /* implicitly enabled */ break; + case MEV_ADD_DISABLED: + ret = EV_ADD | EV_DISABLE; + break; case MEV_ENABLE: ret = EV_ENABLE; break; @@ -249,9 +253,10 @@ mevent_handle(struct kevent *kev, int numev) } } -struct mevent * -mevent_add(int tfd, enum ev_type type, - void (*func)(int, enum ev_type, void *), void *param) +static struct mevent * +mevent_add_state(int tfd, enum ev_type type, + void (*func)(int, enum ev_type, void *), void *param, + int state) { struct mevent *lp, *mevp; @@ -299,13 +304,21 @@ mevent_add(int tfd, enum ev_type type, LIST_INSERT_HEAD(&change_head, mevp, me_list); mevp->me_cq = 1; - mevp->me_state = MEV_ADD; + mevp->me_state = state; mevent_notify(); exit: mevent_qunlock(); return (mevp); +} + +struct mevent * +mevent_add(int tfd, enum ev_type type, + void (*func)(int, enum ev_type, void *), void *param) +{ + + return mevent_add_state(tfd, type, func, param, MEV_ADD); } static int Modified: head/usr.sbin/bhyve/net_backends.c ============================================================================== --- head/usr.sbin/bhyve/net_backends.c Sat Sep 28 09:54:03 2019 (r352840) +++ head/usr.sbin/bhyve/net_backends.c Sat Sep 28 12:02:43 2019 (r352841) @@ -110,6 +110,17 @@ struct net_backend { ssize_t (*recv)(struct net_backend *be, struct iovec *iov, int iovcnt); /* + * Ask the backend to enable or disable receive operation in the + * backend. On return from a disable operation, it is guaranteed + * that the receive callback won't be called until receive is + * enabled again. Note however that it is up to the caller to make + * sure that netbe_recv() is not currently being executed by another + * thread. + */ + void (*recv_enable)(struct net_backend *be); + void (*recv_disable)(struct net_backend *be); + + /* * Ask the backend for the virtio-net features it is able to * support. Possible features are TSO, UFO and checksum offloading * in both rx and tx direction and for both IPv4 and IPv6. @@ -248,6 +259,22 @@ tap_recv(struct net_backend *be, struct iovec *iov, in return (ret); } +static void +tap_recv_enable(struct net_backend *be) +{ + struct tap_priv *priv = (struct tap_priv *)be->opaque; + + mevent_enable(priv->mevp); +} + +static void +tap_recv_disable(struct net_backend *be) +{ + struct tap_priv *priv = (struct tap_priv *)be->opaque; + + mevent_disable(priv->mevp); +} + static uint64_t tap_get_cap(struct net_backend *be) { @@ -270,6 +297,8 @@ static struct net_backend tap_backend = { .cleanup = tap_cleanup, .send = tap_send, .recv = tap_recv, + .recv_enable = tap_recv_enable, + .recv_disable = tap_recv_disable, .get_cap = tap_get_cap, .set_cap = tap_set_cap, }; @@ -282,6 +311,8 @@ static struct net_backend vmnet_backend = { .cleanup = tap_cleanup, .send = tap_send, .recv = tap_recv, + .recv_enable = tap_recv_enable, + .recv_disable = tap_recv_disable, .get_cap = tap_get_cap, .set_cap = tap_set_cap, }; @@ -571,6 +602,22 @@ netmap_recv(struct net_backend *be, struct iovec *iov, return (totlen); } +static void +netmap_recv_enable(struct net_backend *be) +{ + struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + + mevent_enable(priv->mevp); +} + +static void +netmap_recv_disable(struct net_backend *be) +{ + struct netmap_priv *priv = (struct netmap_priv *)be->opaque; + + mevent_disable(priv->mevp); +} + static struct net_backend netmap_backend = { .prefix = "netmap", .priv_size = sizeof(struct netmap_priv), @@ -578,6 +625,8 @@ static struct net_backend netmap_backend = { .cleanup = netmap_cleanup, .send = netmap_send, .recv = netmap_recv, + .recv_enable = netmap_recv_enable, + .recv_disable = netmap_recv_disable, .get_cap = netmap_get_cap, .set_cap = netmap_set_cap, }; @@ -590,6 +639,8 @@ static struct net_backend vale_backend = { .cleanup = netmap_cleanup, .send = netmap_send, .recv = netmap_recv, + .recv_enable = netmap_recv_enable, + .recv_disable = netmap_recv_disable, .get_cap = netmap_get_cap, .set_cap = netmap_set_cap, }; @@ -805,3 +856,16 @@ netbe_rx_discard(struct net_backend *be) return netbe_recv(be, &iov, 1); } +void +netbe_rx_disable(struct net_backend *be) +{ + + return be->recv_enable(be); +} + +void +netbe_rx_enable(struct net_backend *be) +{ + + return be->recv_disable(be); +} Modified: head/usr.sbin/bhyve/net_backends.h ============================================================================== --- head/usr.sbin/bhyve/net_backends.h Sat Sep 28 09:54:03 2019 (r352840) +++ head/usr.sbin/bhyve/net_backends.h Sat Sep 28 12:02:43 2019 (r352841) @@ -46,6 +46,8 @@ int netbe_set_cap(net_backend_t *be, uint64_t cap, ssize_t netbe_send(net_backend_t *be, struct iovec *iov, int iovcnt); ssize_t netbe_recv(net_backend_t *be, struct iovec *iov, int iovcnt); ssize_t netbe_rx_discard(net_backend_t *be); +void netbe_rx_disable(net_backend_t *be); +void netbe_rx_enable(net_backend_t *be); /*