From nobody Thu May 05 23:30:24 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 31D471ABE61F; Thu, 5 May 2022 23:30: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KvVL90mJjz4Vf2; Thu, 5 May 2022 23:30:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651793425; 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=lafi0SYuGkTbWjF/qIRpDm9/3g4TJoyWShTIBfh3nB0=; b=U941GQB+SAgY9bY806oN1Dqmthw15ct+Zt8x3QafWYaan37SxGx/9+q1jgCf6HlcI9rOJu tDgN56kCtT7NXAu9tFsn+VB0sBD+IES95Hi3//FQ4dAX4G0aZpG2Tw/RYtdUkP+eiNihOX GxEp8LY6RiHEdM6NlcfSKYcOZq3bO08ZHN+ftTgNmgorI3JFI6TiNcuOPdMw3Mm3X8DsEh uSJe141YUTpaidng6+0jlGRzzvI6/MMBNb/qYuKTKXDIJbWx5HpRTxcQr/M+rS2oIQYQqw Dw+vj7KdYTlFN2ew1lzJzHqJb6ipVrMsZRIyS1IaIP0XmdkigTKXTMHJxsgssw== 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 DB4B911111; Thu, 5 May 2022 23:30:24 +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 245NUOfG036953; Thu, 5 May 2022 23:30:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 245NUO8G036952; Thu, 5 May 2022 23:30:24 GMT (envelope-from git) Date: Thu, 5 May 2022 23:30:24 GMT Message-Id: <202205052330.245NUO8G036952@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: b483b6b256b2 - main - cxgbe tom: Force unsigned modulus for queue indices. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b483b6b256b2957f857db9092ef3c420a5143972 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651793425; 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=lafi0SYuGkTbWjF/qIRpDm9/3g4TJoyWShTIBfh3nB0=; b=dyIDiyMYNb5Rys82klroPpL9p7UAhmEJz+fZu+dlLrSfdiYkqNQmTjQX7MplXJmhqfwwjT 6gwOXC2KOGsyizWtiFBWM0gJDKf8093zY7db7dPs4orV03JDkxbLfb+1ntZ/9/JC0IBLZ6 SRKGh0CXIcxI+Erpn6Hq2HPUszZgM1JF6i6VGJjiGb+5ys8nVm402EvFTgv/WpKzbbd+pm FDiPnVTa8gKnI1mlls4sR0xYfJZacH2/cfJ+fJ2zPB8Y7IS0Em+FvTYAHC7i7U0pbScswY lf/++pbn3AJVknhMgHSPsbOMGxnmEA5RRSIq5gYtVMs+CI+by1XSXXGimpZVLQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651793425; a=rsa-sha256; cv=none; b=WfW7gje4aiU9UScRu2Gvse3lZAThWhoUzZjKQ/N1uwF9T4uvPCcNJShGRlX8N9HImTkePw yLMqaFquCOgVUqKxXIYz3ou/cBQDcdvzYAoAgI7goR08CkgHCLaYdE+HBqN6YJY7+Gj4cN rAv3GRnGb9zQHY8dt/r/DPSGU25TF4YRpelzftSUUSHb4HzUDVkP3r98bpoz3iYg0B71al ZMDRVY8gKo6F1shvAfA67nuKrgjjd338pDGhjVz3u1gD7KwUhDLnG5bdhV/zuUJD0ycxzV JtU9tc5pRQw4QWzPJphycW7QxntUafip34SRID52jQeAY4LpaAH42GnbDAC0+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=b483b6b256b2957f857db9092ef3c420a5143972 commit b483b6b256b2957f857db9092ef3c420a5143972 Author: John Baldwin AuthorDate: 2022-05-04 22:59:44 +0000 Commit: John Baldwin CommitDate: 2022-05-05 23:30:14 +0000 cxgbe tom: Force unsigned modulus for queue indices. The final transmit and receive queue indices need to be positive values. However, since txq_idx and rxq_idx are signed (to permit using -1 to as a marker for uninitialized values), using %= with another integer type (vi->nofld[tr]xq) yielded a sign-extended modulus value. This resulted in negative queue indices and a buffer underrun when arc4random() returned a value with the sign bit set. Use a temporary unsigned variable to hold the "raw" queue index to force unsigned modulus. This worked previously because the modulus was previously applied directly to the return value of arc4random() which is unsigned before the result was assigned to txq_idx and rxq_idx. Discussed with: np Fixes: db28d4a0cd1c cxgbe/t4_tom: Support for round-robin selection of offload queues. Sponsored by: Chelsio Communications --- sys/dev/cxgbe/tom/t4_tom.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sys/dev/cxgbe/tom/t4_tom.c b/sys/dev/cxgbe/tom/t4_tom.c index 3c1554a8eaf3..9bd6145c9acc 100644 --- a/sys/dev/cxgbe/tom/t4_tom.c +++ b/sys/dev/cxgbe/tom/t4_tom.c @@ -1294,6 +1294,7 @@ init_conn_params(struct vi_info *vi , struct offload_settings *s, struct inpcb *inp = sotoinpcb(so); struct tcpcb *tp = intotcpcb(inp); u_long wnd; + u_int q_idx; MPASS(s->offload != 0); @@ -1378,23 +1379,21 @@ init_conn_params(struct vi_info *vi , struct offload_settings *s, /* Tx queue for this connection. */ if (s->txq == QUEUE_RANDOM) - cp->txq_idx = arc4random(); + q_idx = arc4random(); else if (s->txq == QUEUE_ROUNDROBIN) - cp->txq_idx = atomic_fetchadd_int(&vi->txq_rr, 1); + q_idx = atomic_fetchadd_int(&vi->txq_rr, 1); else - cp->txq_idx = s->txq; - cp->txq_idx %= vi->nofldtxq; - cp->txq_idx += vi->first_ofld_txq; + q_idx = s->txq; + cp->txq_idx = vi->first_ofld_txq + q_idx % vi->nofldtxq; /* Rx queue for this connection. */ if (s->rxq == QUEUE_RANDOM) - cp->rxq_idx = arc4random(); + q_idx = arc4random(); else if (s->rxq == QUEUE_ROUNDROBIN) - cp->rxq_idx = atomic_fetchadd_int(&vi->rxq_rr, 1); + q_idx = atomic_fetchadd_int(&vi->rxq_rr, 1); else - cp->rxq_idx = s->rxq; - cp->rxq_idx %= vi->nofldrxq; - cp->rxq_idx += vi->first_ofld_rxq; + q_idx = s->rxq; + cp->rxq_idx = vi->first_ofld_rxq + q_idx % vi->nofldrxq; if (SOLISTENING(so)) { /* Passive open */