From owner-dev-commits-src-all@freebsd.org Tue Jan 19 05:08:32 2021 Return-Path: Delivered-To: dev-commits-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 209DB4E54B4; Tue, 19 Jan 2021 05:08:32 +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 4DKcB63hYfz4XCN; Tue, 19 Jan 2021 05:08:29 +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 ADC1A208E5; Tue, 19 Jan 2021 05:08:26 +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 10J58QIF086034; Tue, 19 Jan 2021 05:08:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10J58QXe086033; Tue, 19 Jan 2021 05:08:26 GMT (envelope-from git) Date: Tue, 19 Jan 2021 05:08:26 GMT Message-Id: <202101190508.10J58QXe086033@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bryan Venteicher Subject: git: b470419ea52a - main - if_vtnet: Rework 4be723f63 max multiqueue pairs check MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bryanv X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b470419ea52ae5c93ac9892b2ed48aba0e7b4047 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2021 05:08:32 -0000 The branch main has been updated by bryanv: URL: https://cgit.FreeBSD.org/src/commit/?id=b470419ea52ae5c93ac9892b2ed48aba0e7b4047 commit b470419ea52ae5c93ac9892b2ed48aba0e7b4047 Author: Bryan Venteicher AuthorDate: 2021-01-19 04:55:25 +0000 Commit: Bryan Venteicher CommitDate: 2021-01-19 04:55:25 +0000 if_vtnet: Rework 4be723f63 max multiqueue pairs check Verify the max_virtqueue_pairs is within the range allowed by the spec. Reviewed by: grehan (mentor) Differential Revision: https://reviews.freebsd.org/D27920 --- sys/dev/virtio/network/if_vtnet.c | 48 +++++++++++++++++++++++------------- sys/dev/virtio/network/if_vtnetvar.h | 2 +- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c index 6f1ef8506009..425c79da9428 100644 --- a/sys/dev/virtio/network/if_vtnet.c +++ b/sys/dev/virtio/network/if_vtnet.c @@ -657,6 +657,21 @@ vtnet_negotiate_features(struct vtnet_softc *sc) negotiated_features = virtio_negotiate_features(dev, features); + if (virtio_with_feature(dev, VIRTIO_NET_F_MQ)) { + uint16_t npairs; + + npairs = virtio_read_dev_config_2(dev, + offsetof(struct virtio_net_config, max_virtqueue_pairs)); + if (npairs < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN || + npairs > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX) { + device_printf(dev, "Invalid max_virtqueue_pairs value: " + "%d. Multiqueue feature disabled.\n", npairs); + features &= ~VIRTIO_NET_F_MQ; + negotiated_features = + virtio_negotiate_features(dev, features); + } + } + if (virtio_with_feature(dev, VTNET_LRO_FEATURES) && virtio_with_feature(dev, VIRTIO_NET_F_MRG_RXBUF) == 0) { /* @@ -763,23 +778,22 @@ vtnet_setup_features(struct vtnet_softc *sc) } if (sc->vtnet_max_vq_pairs > 1) { - int max; + int req; /* - * Limit the maximum number of queue pairs to the lower of - * the number of CPUs and the configured maximum. The actual - * number of queues that get used may be less. + * Limit the maximum number of requested queue pairs to the + * number of CPUs and the configured maximum. */ - max = vtnet_tunable_int(sc, "mq_max_pairs", vtnet_mq_max_pairs); - if (max > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN) { - if (max > mp_ncpus) - max = mp_ncpus; - if (max > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX) - max = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX; - if (max > 1) { - sc->vtnet_requested_vq_pairs = max; - sc->vtnet_flags |= VTNET_FLAG_MQ; - } + req = vtnet_tunable_int(sc, "mq_max_pairs", vtnet_mq_max_pairs); + if (req < 1) + req = 1; + if (req > sc->vtnet_max_vq_pairs) + req = sc->vtnet_max_vq_pairs; + if (req > mp_ncpus) + req = mp_ncpus; + if (req > 1) { + sc->vtnet_req_vq_pairs = req; + sc->vtnet_flags |= VTNET_FLAG_MQ; } } } @@ -3272,7 +3286,7 @@ vtnet_set_active_vq_pairs(struct vtnet_softc *sc) return; } - npairs = sc->vtnet_requested_vq_pairs; + npairs = sc->vtnet_req_vq_pairs; if (vtnet_ctrl_mq_cmd(sc, npairs) != 0) { device_printf(dev, @@ -4172,8 +4186,8 @@ vtnet_setup_sysctl(struct vtnet_softc *sc) SYSCTL_ADD_INT(ctx, child, OID_AUTO, "max_vq_pairs", CTLFLAG_RD, &sc->vtnet_max_vq_pairs, 0, "Number of maximum supported virtqueue pairs"); - SYSCTL_ADD_INT(ctx, child, OID_AUTO, "requested_vq_pairs", - CTLFLAG_RD, &sc->vtnet_requested_vq_pairs, 0, + SYSCTL_ADD_INT(ctx, child, OID_AUTO, "req_vq_pairs", + CTLFLAG_RD, &sc->vtnet_req_vq_pairs, 0, "Number of requested virtqueue pairs"); SYSCTL_ADD_INT(ctx, child, OID_AUTO, "act_vq_pairs", CTLFLAG_RD, &sc->vtnet_act_vq_pairs, 0, diff --git a/sys/dev/virtio/network/if_vtnetvar.h b/sys/dev/virtio/network/if_vtnetvar.h index ed4921454d7d..96cd68abba82 100644 --- a/sys/dev/virtio/network/if_vtnetvar.h +++ b/sys/dev/virtio/network/if_vtnetvar.h @@ -168,8 +168,8 @@ struct vtnet_softc { int vtnet_if_flags; int vtnet_max_mtu; int vtnet_act_vq_pairs; + int vtnet_req_vq_pairs; int vtnet_max_vq_pairs; - int vtnet_requested_vq_pairs; int vtnet_lro_entry_count; int vtnet_lro_mbufq_depth;