From nobody Wed Dec 1 12:48:37 2021 X-Original-To: dev-commits-src-branches@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 E55EA18BA2F3; Wed, 1 Dec 2021 12:48:39 +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 4J3zRB0wrvz3jsv; Wed, 1 Dec 2021 12:48:37 +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 295011CCB; Wed, 1 Dec 2021 12:48:37 +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 1B1CmbIs065947; Wed, 1 Dec 2021 12:48:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B1CmbWs065946; Wed, 1 Dec 2021 12:48:37 GMT (envelope-from git) Date: Wed, 1 Dec 2021 12:48:37 GMT Message-Id: <202112011248.1B1CmbWs065946@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: dfd5240189ca - stable/13 - netinet: Implement in_cksum_skip() using m_apply() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: dfd5240189ca024b268e53df2f0a3076df57b240 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638362919; 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=mDJO7VAiijOT99SXK5CThttoeB0sjP2PM2WLwjAoZcs=; b=nE+XSH3YmEjiEetZhSD9rY2roTCqjXZctl0gFR+FI/dqP6DistYlFzPFnctkQLTS1bOQa8 cxhLL9wGYNKITStZwYp8d02yVE+D9buGPQN0l4AfTAYxLW9ZWSnVy0PAUWxK1QZTU0EGmx 2s9jw4//GOEXTwH8ubG68I35+3XPpBLNUf8s3IPf9RbOAluPJZCf8pnxTbROACvMxDeU5h 4917Z3nHRnXBk5isolOM53u0VQbTG/FVXrz4OH2iDiURM7AlRh2uoTXvrHAmQx5sA/l2xv kWIXGVtAU06PwfFmISKjVoye+1jqHIhYg2h4PDoz/U/MH7aYS7akyXQ5ieJOxw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638362919; a=rsa-sha256; cv=none; b=sZhaTfC9QE+VH6CjaqWL/ObvTuOi+O4N/Yd/7B/+lnYH3jOTJCuwpKS+x4OcZRLk1BBqvo 7NpO17KDOkTWgILvkSl8R1+8j/4AIvldFS5UGwUY7FGhkkZKQpY8H+PNhFYLqzNJERPlgb 869MsKjEIWelk3kRg3tfBTwqQIYT6GsGMW3uIPUozVHDWBp+Z4JgXehijukxRD9CE4Dqb0 ZJV+b/ZIsguBeunfUOJZ6Blj6lU6cB0nVfSa0fl7/k94GG246wKTeFBgwZHQ502wjBP8sY q4XmTgWusn8JdlTIKm9d11N2IGT93UKSUuirCV6/xFA63zW9WYuUVMiQKHk5Eg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=dfd5240189ca024b268e53df2f0a3076df57b240 commit dfd5240189ca024b268e53df2f0a3076df57b240 Author: Mark Johnston AuthorDate: 2021-11-24 18:19:54 +0000 Commit: Mark Johnston CommitDate: 2021-12-01 12:43:03 +0000 netinet: Implement in_cksum_skip() using m_apply() This allows it to work with unmapped mbufs. In particular, in_cksum_skip() calls no longer need to be preceded by calls to mb_unmapped_to_ext() to avoid a page fault. PR: 259645 Reviewed by: gallatin, glebius, jhb Sponsored by: The FreeBSD Foundation (cherry picked from commit 0d9c3423f59bb305301f5a5bc7c8f5daf7b7aa52) --- sys/netinet/in_cksum.c | 63 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/sys/netinet/in_cksum.c b/sys/netinet/in_cksum.c index 581950c8afa4..98317d4dac4a 100644 --- a/sys/netinet/in_cksum.c +++ b/sys/netinet/in_cksum.c @@ -49,7 +49,9 @@ __FBSDID("$FreeBSD$"); #include /* - * These implementations may be overridden on a per-platform basis. + * These implementations may be overridden on a per-platform basis. On + * platforms with a direct map, the implementation of in_cksum() must handle + * unmapped mbufs. */ #ifndef HAVE_MD_IN_CKSUM @@ -203,44 +205,43 @@ in_pseudo(u_int32_t a, u_int32_t b, u_int32_t c) return (sum); } +struct cksum_skip_partial_args { + uint64_t csum; + int clen; +}; + +static int +in_cksum_skip_partial(void *arg, void *data, u_int len) +{ + struct cksum_skip_partial_args *a; + + a = arg; + if (((uintptr_t)data ^ a->clen) & 1) + a->csum += in_cksumdata(data, len) << 8; + else + a->csum += in_cksumdata(data, len); + a->clen += len; + return (0); +} + u_short in_cksum_skip(struct mbuf *m, int len, int skip) { - u_int64_t sum = 0; - int mlen = 0; - int clen = 0; - caddr_t addr; + struct cksum_skip_partial_args a; union q_util q_util; union l_util l_util; + uint64_t sum; len -= skip; - for (; skip && m; m = m->m_next) { - if (m->m_len > skip) { - mlen = m->m_len - skip; - addr = mtod(m, caddr_t) + skip; - goto skip_start; - } else { - skip -= m->m_len; - } - } - - for (; m && len; m = m->m_next) { - if (m->m_len == 0) - continue; - mlen = m->m_len; - addr = mtod(m, caddr_t); -skip_start: - if (len < mlen) - mlen = len; - - if ((clen ^ (uintptr_t) addr) & 1) - sum += in_cksumdata(addr, mlen) << 8; - else - sum += in_cksumdata(addr, mlen); - clen += mlen; - len -= mlen; - } + /* + * The use of m_apply() allows this routine to operate on unmapped + * mbufs. + */ + a.csum = 0; + a.clen = 0; + (void)m_apply(m, skip, len, in_cksum_skip_partial, &a); + sum = a.csum; REDUCE16; return (~sum & 0xffff); }