From owner-svn-src-head@freebsd.org Mon Jun 1 16:10:45 2020 Return-Path: Delivered-To: svn-src-head@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 59EBD33AC14; Mon, 1 Jun 2020 16:10:45 +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) 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 49bKsK1nhcz4BS5; Mon, 1 Jun 2020 16:10:45 +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 38CF4E048; Mon, 1 Jun 2020 16:10:45 +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 051GAjFu087164; Mon, 1 Jun 2020 16:10:45 GMT (envelope-from vmaffione@FreeBSD.org) Received: (from vmaffione@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 051GAjbG087163; Mon, 1 Jun 2020 16:10:45 GMT (envelope-from vmaffione@FreeBSD.org) Message-Id: <202006011610.051GAjbG087163@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vmaffione set sender to vmaffione@FreeBSD.org using -f From: Vincenzo Maffione Date: Mon, 1 Jun 2020 16:10:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361696 - head/sys/dev/netmap X-SVN-Group: head X-SVN-Commit-Author: vmaffione X-SVN-Commit-Paths: head/sys/dev/netmap X-SVN-Commit-Revision: 361696 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jun 2020 16:10:45 -0000 Author: vmaffione Date: Mon Jun 1 16:10:44 2020 New Revision: 361696 URL: https://svnweb.freebsd.org/changeset/base/361696 Log: netmap: vtnet: fix RX virtqueue initialization bug The vtnet_netmap_rxq_populate() function erroneously assumed that kring->nr_hwcur = 0, i.e. the kring was in the initial state. However, this is not always the case: for example, when a vtnet reinit is triggered by some changes in the interface flags or capenable. This patch changes the behaviour of vtnet_netmap_kring_refill() so that it always starts publishing the netmap buffers starting from the current value of kring->nr_hwcur. MFC after: 1 week Modified: head/sys/dev/netmap/if_vtnet_netmap.h Modified: head/sys/dev/netmap/if_vtnet_netmap.h ============================================================================== --- head/sys/dev/netmap/if_vtnet_netmap.h Mon Jun 1 15:58:22 2020 (r361695) +++ head/sys/dev/netmap/if_vtnet_netmap.h Mon Jun 1 16:10:44 2020 (r361696) @@ -232,14 +232,20 @@ vtnet_netmap_txsync(struct netmap_kring *kring, int fl return 0; } +/* + * Publish (up to) num netmap receive buffers to the host, + * starting from the first one that the user made available + * (kring->nr_hwcur). + */ static int -vtnet_netmap_kring_refill(struct netmap_kring *kring, u_int nm_i, u_int head) +vtnet_netmap_kring_refill(struct netmap_kring *kring, u_int num) { struct netmap_adapter *na = kring->na; struct ifnet *ifp = na->ifp; struct netmap_ring *ring = kring->ring; u_int ring_nr = kring->ring_id; u_int const lim = kring->nkr_num_slots - 1; + u_int nm_i = kring->nr_hwcur; /* device-specific */ struct vtnet_softc *sc = ifp->if_softc; @@ -250,7 +256,7 @@ vtnet_netmap_kring_refill(struct netmap_kring *kring, struct sglist_seg ss[2]; struct sglist sg = { ss, 0, 0, 2 }; - for (; nm_i != head; nm_i = nm_next(nm_i, lim)) { + for (; num > 0; nm_i = nm_next(nm_i, lim), num--) { struct netmap_slot *slot = &ring->slot[nm_i]; uint64_t paddr; void *addr = PNMB(na, slot, &paddr); @@ -302,10 +308,11 @@ vtnet_netmap_rxq_populate(struct vtnet_rxq *rxq) kring->nr_pending_mode == NKR_NETMAP_ON)) return -1; - /* Expose all the RX netmap buffers. Note that the number of - * netmap slots in the RX ring matches the maximum number of - * 2-elements sglist that the RX virtqueue can accommodate. */ - error = vtnet_netmap_kring_refill(kring, 0, na->num_rx_desc); + /* 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. */ + error = vtnet_netmap_kring_refill(kring, na->num_rx_desc); virtqueue_notify(rxq->vtnrx_vq); return error < 0 ? ENXIO : 0; @@ -381,7 +388,12 @@ vtnet_netmap_rxsync(struct netmap_kring *kring, int fl */ nm_i = kring->nr_hwcur; /* netmap ring index */ if (nm_i != head) { - int nm_j = vtnet_netmap_kring_refill(kring, nm_i, head); + int howmany = head - nm_i; + int nm_j; + + if (howmany < 0) + howmany += kring->nkr_num_slots; + nm_j = vtnet_netmap_kring_refill(kring, howmany); if (nm_j < 0) return nm_j; kring->nr_hwcur = nm_j;