From patchwork Sun Feb 4 23:27:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wood X-Patchwork-Id: 196598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp572557dyb; Sun, 4 Feb 2024 15:31:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+zdFnI1WPykggTbrgu1dHWZwxz8AUft5NumT/QNj/vtjfvoUEymL/0yNL7C8CT4WlyeXG X-Received: by 2002:a05:6871:528e:b0:218:de13:e11e with SMTP id hu14-20020a056871528e00b00218de13e11emr7017648oac.22.1707089461529; Sun, 04 Feb 2024 15:31:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707089461; cv=pass; d=google.com; s=arc-20160816; b=jhE2bYR8fKf+RH0dmCJUOrfnAUa+FD7kT/SeTVUe4FM+2upJ0jjQzYx5kvlpmb24DA JH/wDJKdwcqu5o+kjlhOY9O1nO71Og/cFu8WuHyg/sZrzBEA5GeMk0LITkc4gqIZpdgz u51idlUdi99ydF5BodSE3j5Jbbm6eASTuF+kiN907h4EXBRXxnNMwkwdm3VHbW+1aesk 3H6QF5TbLzswXy/DDWlGIr/RS3cjCKzCSVk4egjgPekaikYFnlRnMqTUnZD2WdikacQe HpE9rsGaosxg4AtHtOm/ZtTlSoXKluXi8DucZvCswqCVBvK/5LV5MEv/GBI43WmUjKYz /8ow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=yXl72+2pLCBU+d11ILW3XEAr8eYnZKYv5qLeQI8w0AM=; fh=3OxhOxdpWuyBEXZrVS8Q6Jg9UMQcvf70v/BhQd1jllo=; b=pbIfh7Er1q2sLs7wBCJ/M0bEhofuS+z3I1BNdcZAUvk3BzhUUxvToD4s2NjzHXO22d Dd35ExdkyZ5G3whXM6HTK3Cfck/FjI0psxwsH5gWZel53A1uBXXScHciOtBC9/k3cR0U 1WEzGPr3M4C5F7WugBAiBY2Z7Jdp0e9g6L0lXqdibq6KKmMVSBT3B3uH53mUKyBld5sn WHe8VosjgCH6T/E3W8+AhECzFxJ7leg6CBnbieCdsgL4y/QPVtnkHkNa3fRRjrhCn3CQ 88aT/B/VLNkc6XOzpIwT+FE/YEtOKYYcszaI8hdV3SMsyVLc0xrfy+JOSxMiQpPfBe95 /GWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kVXDo6PX; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-51941-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51941-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCWpVw/AnBr2DWjYBX6A3mv+zQdEjU5sXDzTU7AFjVCXjySQdwfTXjOzfkKNGgFpcTxb2PtpVuaJX5Aj10fOzjo6SuAaqw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d12-20020a05622a05cc00b0042a53f687a1si7073944qtb.754.2024.02.04.15.31.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 15:31:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51941-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kVXDo6PX; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-51941-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51941-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 52FDA1C20A7F for ; Sun, 4 Feb 2024 23:31:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6CF7433082; Sun, 4 Feb 2024 23:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kVXDo6PX" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 189F51DA32; Sun, 4 Feb 2024 23:28:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707089285; cv=none; b=G/2IdFA7tl1n0CHfXfDCc0raJ4tU4RPUfKZHF30Dg9JXxzA/XVoPLU1b4WtPYsDVC7PQa425At6yWocSkTy0EQ2tAhpGFbbKICqoIhrIkS4fOV1oTZMh7wok7RQ4njD+HGc2k+Z3MA+bF8g01htSzpyAYo3rH3EvbHP/4+wwnT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707089285; c=relaxed/simple; bh=SSARsMhAO/CnotTOTu32poP3ZTXfjxsFKPzvMvSGpmw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NJNhKyrXjNUOUeeQETPBGxHMUklPwac4NuG1vdLqVqG+L15QEJP9MLE3HcXoYn7qIPo7Vl+Nj/4eh2LnFthfnst41JA2rNo5U9OIHms2mdpi9BVPunZq0323D7LEhXk+iYjS1FnuxPNdp5LqOU1RnYeGqqoOFayevwd7V3jRvYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kVXDo6PX; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d7431e702dso31522935ad.1; Sun, 04 Feb 2024 15:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707089283; x=1707694083; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yXl72+2pLCBU+d11ILW3XEAr8eYnZKYv5qLeQI8w0AM=; b=kVXDo6PX3WisPT4+K/SpZCPksqBhx4MK0IsaSMiXQLNaRulQ+FED6xree4iNCPgsH7 Xl5CnydzmApkTWS+dg1hOuZuVqTTga8qNRBkMjBF+ogdAfhfyFTgeyry3qwYyIhGAUmV 41RILtRK9Srk9BdESftS9hc2FK4aQSD709LcwhLRp8kdDyweYpXC/9YaZRxbF9p8oI8P 3ujl0A0euVBrzFWBQ+VIT8Vvcy17AOL8bU6RJe4wRtUP8ojSGc+tksBU2uKN3bZpwkxH wjl4ww9BAqUEa5dy+uxtu7Ru09jqmvHDJM854L4ooYRtJebZnNKOwlR5aTeSr683DFYr Pi0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707089283; x=1707694083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yXl72+2pLCBU+d11ILW3XEAr8eYnZKYv5qLeQI8w0AM=; b=aMj4ve4r6DhKtvjZQqfb4C5f6R0NVzGR3KtcyECAsTiSthBfpbyhBO9+/oWMhdFT7z YHGQmBeQMp0XdOtM3aM4bf2uMIGqDF97aGSuqFiTyTKJ/GoREV7CETiKTQa//1ka3doZ ShAhPPqapoC0rA5e/veMLW8WINBsO8Z2Pfx+DhDbplWa2/XK/Em6dJ5osc9cn9oFpmFI 4c8mn3wub4KobRc9KU9c9RtHBe0JTllyfo8grRiz3rk5kttceymi0boCfrnKRCW2A6Tv veNPm81uia2HBbYElHRQe/feQDk9SKZw5RSjk3xWqIrhp6qwxpL4mjpGgiJKjGYmcdO2 QHeg== X-Gm-Message-State: AOJu0YwjUeC19aXULl6w+quYH0v7ZVTisbLHex2lV10/po66VRFhbYA8 wiyFgoryZOc9DyHkRDZACCzzLA55/B9IG/46aIeCVUyfPEkvPGUt X-Received: by 2002:a17:902:f811:b0:1d9:5038:f116 with SMTP id ix17-20020a170902f81100b001d95038f116mr10955622plb.34.1707089283351; Sun, 04 Feb 2024 15:28:03 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVllZG6ovWYFRpf45jxUip1i/3By1OUOv+jD20x5+U2NbHMT4IZgLz4CKn5a5q6vF6+HHINBn2Yl1IEd9jGdG/4/GlOUytxdyjeSTNmJp6pIisorjcCnX9ejrxjLPfKSZ1/4b7pueyHmVxghcmdca+atdvevcaBPX9ufXStpEfNl+ezaLvvmVvziLR6UdIyxuTVERuoZ8dKJGBINd1O Received: from localhost ([2601:644:9380:8cd0::7fb4]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b001d9a40f50c4sm1494063plg.301.2024.02.04.15.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 15:28:03 -0800 (PST) From: Matthew Wood To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Breno Leitao , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 8/8] net: netconsole: append userdata to fragmented netconsole messages Date: Sun, 4 Feb 2024 15:27:39 -0800 Message-ID: <20240204232744.91315-9-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240204232744.91315-1-thepacketgeek@gmail.com> References: <20240204232744.91315-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790013039259583617 X-GMAIL-MSGID: 1790013039259583617 Regardless of whether the original message body or formatted userdata exceeds the MAX_PRINT_CHUNK, append userdata to the netconsole message starting with the first chunk that has available space after writing the body. Co-developed-by: Breno Leitao Signed-off-by: Breno Leitao Signed-off-by: Matthew Wood --- drivers/net/netconsole.c | 50 +++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index d53bb1172336..0de108a1c0c8 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1085,24 +1085,48 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, memcpy(buf + release_len, header, header_len); header_len += release_len; - while (offset < body_len) { + while (offset < body_len + userdata_len) { int this_header = header_len; - int this_chunk; + int this_offset = 0; + int this_chunk = 0; this_header += scnprintf(buf + this_header, sizeof(buf) - this_header, - ",ncfrag=%d/%d;", offset, body_len); - - this_chunk = min(body_len - offset, - MAX_PRINT_CHUNK - this_header); - if (WARN_ON_ONCE(this_chunk <= 0)) - return; - - memcpy(buf + this_header, body + offset, this_chunk); - - netpoll_send_udp(&nt->np, buf, this_header + this_chunk); + ",ncfrag=%d/%d;", offset, + body_len + userdata_len); + + /* Not all body data has been written yet */ + if (offset < body_len) { + this_chunk = min(body_len - offset, + MAX_PRINT_CHUNK - this_header); + if (WARN_ON_ONCE(this_chunk <= 0)) + return; + memcpy(buf + this_header, body + offset, this_chunk); + this_offset += this_chunk; + } + /* Body is fully written and there is pending userdata to write, + * append userdata in this chunk + */ + if (offset + this_offset >= body_len && + offset + this_offset < userdata_len + body_len) { + int sent_userdata = (offset + this_offset) - body_len; + int preceding_bytes = this_chunk + this_header; + + if (WARN_ON_ONCE(sent_userdata < 0)) + return; + + this_chunk = min(userdata_len - sent_userdata, + MAX_PRINT_CHUNK - preceding_bytes); + if (WARN_ON_ONCE(this_chunk <= 0)) + return; + memcpy(buf + this_header + this_offset, + userdata + sent_userdata, + this_chunk); + this_offset += this_chunk; + } - offset += this_chunk; + netpoll_send_udp(&nt->np, buf, this_header + this_offset); + offset += this_offset; } }