From nobody Thu Jan 11 04:52:13 2024 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 4T9XMf061pz56Psv; Thu, 11 Jan 2024 04:52:14 +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 4T9XMd5Rspz40Nf; Thu, 11 Jan 2024 04:52:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704948733; 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=0NiGnVdArcqsHethmyJEuFrWPD2ZdwNQ+MWInW1cYa8=; b=D+jTwHmzl0QviJQvINOCIvRQpSF0956I6XPHShX1/A89gqKa0dW1nulnn3Q83Or1SM2u4s 07w8HhDQDN7flP5/mylwrIO0c1BmUCR9jZ7ZCm/5ZU0i0FuoQieX1MCYZNxkKR40rAyBzt sClhLQ5TqruMqRx/AogoQQbkMDW+WW83D1JUMUpJRZiEZvJfavs4U7QRAc4lWhuP3iq4WD cPSnvV9tA6X+Er2zjh/HRH48TflFClX4J09cgo4PeFT8K5U717wX8QQv0zOEI7i4uSqscv f8udwEhvh/x741KQNrhej/yZpIIyW27mtQTkUGj6sZunyj4LwU9AoqrR69Pgmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704948733; 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=0NiGnVdArcqsHethmyJEuFrWPD2ZdwNQ+MWInW1cYa8=; b=je+jidk5k0fvV5tvinx0+TujPEOa3kqa2DzhufC0TfWF70uMDvKZ5MoCHTE27cc+D6ReOC qS/mWuS5TRvWXUcO3s0TU2NFq24y0x0bkF17XTzhHYmM4vvK/BXfkSE8/vuFVsYJBlKJ3w 4on0xWEjsR9pK9gpr/JEikVaUsgCSdSmU9yoSTEAvJN8Q9FyOzkuZPHxigwtRo+44WN7ce JjFl3fDOxg1M4C9iQTW7I0TZROTinyoPwxYRLIVTsY4uXTOK/6laEuldsnl6qThSvgencF gsCRNv13G+UTrfvR3cvhdZvEj8ZV9CSHFzUARKxnxp25rAIi9lZEepkEbgNTEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704948733; a=rsa-sha256; cv=none; b=uTq19YzingLkKASnUTirQK4K6/UgLl6D5G8i0rRLYRTnC39inRwzr2a1XbtRmD3oVhCgqB 822HJFwZMBqdIYZTObI6YcFvtE31ISvT9/xIYPQayUWfAaVtPwhN6/v9ykcv5dwSkdpItp dTSPqyXTIbP06qft8AW6T476euh7OQBnCgGNDFXk39v0CVtyGTky/kvN/4C/O2UHqzSD1Q rbEi4RXkD6oO4FFk8SJVio+3e6AcRFu0HLNdNbQw1ev6YbNwUBLzhYvbfv6psl8kL2H04Y MzzFb0cuc0zAJUHWXycFyDWTNQ/mbmmhd/ddwFDaPf/BhAVZiSe2izkDazKBSA== 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 4T9XMd4YWBz14yN; Thu, 11 Jan 2024 04:52:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40B4qDq8041627; Thu, 11 Jan 2024 04:52:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40B4qDOK041624; Thu, 11 Jan 2024 04:52:13 GMT (envelope-from git) Date: Thu, 11 Jan 2024 04:52:13 GMT Message-Id: <202401110452.40B4qDOK041624@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: f75d7fac109b - main - netlink: avoid putting empty mbufs on the socket queue 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f75d7fac109bf8e322b07456c5361ee62f5635c2 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=f75d7fac109bf8e322b07456c5361ee62f5635c2 commit f75d7fac109bf8e322b07456c5361ee62f5635c2 Author: Gleb Smirnoff AuthorDate: 2024-01-11 04:51:53 +0000 Commit: Gleb Smirnoff CommitDate: 2024-01-11 04:51:53 +0000 netlink: avoid putting empty mbufs on the socket queue When processing incoming Netlink messages in nl_process_nbuf() kernel always allocates a writer with a buffer to put generated reply to. However, certain messages aren't replied. That makes nlmsg_flush() to put an empty buffer to the socket. Avoid doing that because avoiding is much easier than dealing with empty buffers on the receiver side. --- sys/netlink/netlink_domain.c | 7 +------ sys/netlink/netlink_io.c | 2 ++ sys/netlink/netlink_message_writer.c | 11 +++++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/sys/netlink/netlink_domain.c b/sys/netlink/netlink_domain.c index 94989af73dfe..7ecafbf99d26 100644 --- a/sys/netlink/netlink_domain.c +++ b/sys/netlink/netlink_domain.c @@ -740,12 +740,7 @@ nl_soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio, TAILQ_FOREACH(nb, &sb->nl_queue, tailq) { u_int offset; - /* - * XXXGL: zero length buffer may be at the tail of a queue - * when a writer overflows socket buffer. When this is - * improved, use MPASS(nb->offset < nb->datalen). - */ - MPASS(nb->offset <= nb->datalen); + MPASS(nb->offset < nb->datalen); offset = nb->offset; while (offset < nb->datalen) { hdr = (struct nlmsghdr *)&nb->data[offset]; diff --git a/sys/netlink/netlink_io.c b/sys/netlink/netlink_io.c index 5f50c40f71d8..61d9d657556a 100644 --- a/sys/netlink/netlink_io.c +++ b/sys/netlink/netlink_io.c @@ -201,6 +201,8 @@ nl_send(struct nl_writer *nw, struct nlpcb *nlp) struct nl_buf *nb; MPASS(nw->hdr == NULL); + MPASS(nw->buf != NULL); + MPASS(nw->buf->datalen > 0); IF_DEBUG_LEVEL(LOG_DEBUG2) { struct nlmsghdr *hdr = (struct nlmsghdr *)nw->buf->data; diff --git a/sys/netlink/netlink_message_writer.c b/sys/netlink/netlink_message_writer.c index 50305e3d9d80..59bc6aabaa3f 100644 --- a/sys/netlink/netlink_message_writer.c +++ b/sys/netlink/netlink_message_writer.c @@ -100,6 +100,7 @@ _nlmsg_ignore_limit(struct nl_writer *nw) bool _nlmsg_flush(struct nl_writer *nw) { + bool result; if (__predict_false(nw->hdr != NULL)) { /* Last message has not been completed, skip it. */ @@ -109,8 +110,14 @@ _nlmsg_flush(struct nl_writer *nw) nw->hdr = NULL; } - NL_LOG(LOG_DEBUG2, "OUT"); - bool result = nw->cb(nw); + if (nw->buf->datalen == 0) { + MPASS(nw->num_messages == 0); + nl_buf_free(nw->buf); + nw->buf = NULL; + return (true); + } + + result = nw->cb(nw); nw->num_messages = 0; if (!result) {