From owner-dev-commits-src-main@freebsd.org Mon Jan 11 21:42:25 2021 Return-Path: Delivered-To: dev-commits-src-main@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 9F8084E77D9; Mon, 11 Jan 2021 21:42:25 +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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DF6cd4BxTz3DDq; Mon, 11 Jan 2021 21:42:25 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 82FDA21D8B; Mon, 11 Jan 2021 21:42:25 +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 10BLgPIH002746; Mon, 11 Jan 2021 21:42:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10BLgP1e002745; Mon, 11 Jan 2021 21:42:25 GMT (envelope-from git) Date: Mon, 11 Jan 2021 21:42:25 GMT Message-Id: <202101112142.10BLgP1e002745@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vincenzo Maffione Subject: git: 3005e10ddbfb - main - netmap: vtnet: fix RX initialization after netmap_reset() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: vmaffione X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3005e10ddbfbec3ecf46a080607bb0d85986eee5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jan 2021 21:42:25 -0000 The branch main has been updated by vmaffione: URL: https://cgit.FreeBSD.org/src/commit/?id=3005e10ddbfbec3ecf46a080607bb0d85986eee5 commit 3005e10ddbfbec3ecf46a080607bb0d85986eee5 Author: Vincenzo Maffione AuthorDate: 2021-01-11 21:38:32 +0000 Commit: Vincenzo Maffione CommitDate: 2021-01-11 21:38:32 +0000 netmap: vtnet: fix RX initialization after netmap_reset() At device reset, we must not publish those netmap receive buffers that are owned by userspace (nm_kr_rxspace). MFC after: 1 week --- sys/dev/netmap/if_vtnet_netmap.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sys/dev/netmap/if_vtnet_netmap.h b/sys/dev/netmap/if_vtnet_netmap.h index f787bf573a28..cd652938bca5 100644 --- a/sys/dev/netmap/if_vtnet_netmap.h +++ b/sys/dev/netmap/if_vtnet_netmap.h @@ -213,20 +213,25 @@ vtnet_netmap_rxq_populate(struct vtnet_rxq *rxq) struct netmap_kring *kring; struct netmap_slot *slot; int error; + int num; slot = netmap_reset(na, NR_RX, rxq->vtnrx_id, 0); if (slot == NULL) return -1; kring = na->rx_rings[rxq->vtnrx_id]; - /* Expose all the RX netmap buffers we can. In case of no indirect + /* + * Expose all the RX netmap buffers we can. In case of no indirect * buffers, the number of netmap slots in the RX ring matches the * maximum number of 2-elements sglist that the RX virtqueue can - * accommodate. We need to start from kring->nr_hwcur, which is 0 - * on netmap register and may be different from 0 if a virtio - * re-init happens while the device is in use by netmap. */ - rxq->vtnrx_nm_refill = kring->nr_hwcur; - error = vtnet_netmap_kring_refill(kring, na->num_rx_desc - 1); + * accommodate. We need to start from kring->nr_hwtail, which is 0 + * on the first netmap register and may be different from 0 if a + * virtio re-init (caused by a netma register or i.e., ifconfig) + * happens while the device is in use by netmap. + */ + rxq->vtnrx_nm_refill = kring->nr_hwtail; + num = na->num_rx_desc - 1 - nm_kr_rxspace(kring); + error = vtnet_netmap_kring_refill(kring, num); virtqueue_notify(rxq->vtnrx_vq); return error; @@ -256,7 +261,7 @@ vtnet_netmap_rxsync(struct netmap_kring *kring, int flags) * First part: import newly received packets. * Only accept our own buffers (matching the token). We should only get * matching buffers. The hwtail should never overrun hwcur, because - * we publish only N-1 receive buffers (and non N). + * we publish only N-1 receive buffers (and not N). * In any case we must not leave this routine with the interrupts * disabled, pending packets in the VQ and hwtail == (hwcur - 1), * otherwise the pending packets could stall.