From patchwork Tue Sep 10 10:03:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798227 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 27C3C191F88; Tue, 10 Sep 2024 10:04:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962665; cv=none; b=EhJaUjCD98KWiBktMH802Mw3buZJtDZE+xZbdI1p3sKgroJnwDOgBRGbw0rVKca515bqFF/LRnDP9FfMC0jVTltmqzCS5J5SUtM6KlZ7NqbZF5mT/GTADml5WBgVHCfiN8D01FKXEXbLrXNZpdscSQEUWMBsz7L2X7YJlXS2BV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962665; c=relaxed/simple; bh=pRaK3Ku3IkQXoZTZoJ3KsKO2/UXaI4WyWbGGP/VRtPU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nCl39/kv0lXk/ShVTaP3r0fiyhrHtlvo+1C+yPxTaYiUt8n+Bha55JRxLKLD+ApsmxPMm3JA/8c7GWFWQuwmjZsOT/D9UuvxtCNRXfzdng1Ve5uXmFkCW1eaArlznQuKcL57zoF4d7hpYyZEVyELxEu9Ak5ZltVfq7UXVbpXU4Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-53567b4c3f4so478103e87.2; Tue, 10 Sep 2024 03:04:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962662; x=1726567462; 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=JEjz2XP772fB6v2V8zpQRQxhqoxNSwh9E/XJx/MNIPQ=; b=VTBILaNE3Z6ileZNj3+lWH/q4Evx9U8MB2j991PHVK+fCdKNHD+/NDRIzBIGwuqHAn KaFZ0vVW17sgN6QAzANnN/emvojBSMlcL7iPpeGLCcKDKbnBGeABOQND2R+rMp4/6SmO vSXV3yO41hEkATA01J6GiGFQWT5dBUxb8nUbIbP0EQOvh0Le4BJ74vuhe2Zq83lOGPR0 o6m0ZYt1vWC+rE0h3dNw03z7GTbF0kAsRILxEXcuymga5JB7aoCFIqB+cgQxr2dRtnhK siW/ADrluhkeHfOpOGIaGIyCEOrkXURdJw9SO45a2FXx3i3983sIcbY+my747LbvqO/i 022g== X-Forwarded-Encrypted: i=1; AJvYcCU3Ptgb/NZjxXx4Ua6svnEfRlQRBN2LoKZBcsECtDn7oFwTJTpSixN99xsvxmyqaICS+IMyN5X7Y06OX2M=@vger.kernel.org, AJvYcCXeNnoJ2ZbX0V+/QlR1j+d6q5XYwDKWfabFoADSZEBPGA19E8mIjCbBpU1Jmezyf93mwNzAKIMN@vger.kernel.org X-Gm-Message-State: AOJu0YyxaB4RSXdPcDPVWY6K72NWTDYiCFms52TURpiMIdt/RsJV3fYr tIhYSWwksxJHwzdyZvTq+r6ng870wWEdSulW81Llm+8wD1g+aTNC X-Google-Smtp-Source: AGHT+IE3ZKxexYx7/n/qTN1mtxrmEimDS+7YnBn8vip6x6vR0UHx41KzroI4bn/PfVHaxvzecZ3wVg== X-Received: by 2002:a05:6512:114b:b0:536:55cc:9641 with SMTP id 2adb3069b0e04-536587aa77cmr9607708e87.16.1725962661279; Tue, 10 Sep 2024 03:04:21 -0700 (PDT) Received: from localhost (fwdproxy-lla-113.fbsv.net. [2a03:2880:30ff:71::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25cf4a45sm455770366b.180.2024.09.10.03.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:20 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 01/10] net: netconsole: remove msg_ready variable Date: Tue, 10 Sep 2024 03:03:56 -0700 Message-ID: <20240910100410.2690012-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Variable msg_ready is useless, since it does not represent anything. Get rid of it, using buf directly instead. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 01cf33fa7503..03150e513cb2 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1075,7 +1075,6 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, const char *header, *body; int offset = 0; int header_len, body_len; - const char *msg_ready = msg; const char *release; int release_len = 0; int userdata_len = 0; @@ -1105,8 +1104,7 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, MAX_PRINT_CHUNK - msg_len, "%s", userdata); - msg_ready = buf; - netpoll_send_udp(&nt->np, msg_ready, msg_len); + netpoll_send_udp(&nt->np, buf, msg_len); return; } From patchwork Tue Sep 10 10:03:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798228 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 C528514D431; Tue, 10 Sep 2024 10:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962667; cv=none; b=IHHG+FrEIlTesR1//d0MeFxWUY7RHSiL2l4mTGVNxdjpmPMEUKZnK9PMsOQB3WAKt4ZFeSyQXytr2l50YUQhgf5OPPpK+bfAWZYjzN3ooVL+bEPLw/wcP3+TJ+ajbb1LBj9x3W+VOb8POtjxIk8dncg02C6yqqJ76imIAI1/Dkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962667; c=relaxed/simple; bh=oJIDy0qtaGw6j830beA+G8p0IPumns4yvWEkwTqum/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qyVOhgJlw5KBZfPQ6dVsXw6hWgyzCprxqiTH7/R2yvbpz6Ztyx1xDyIE4vzUvybFSawxtX2EKiDqE8ZYp9HQenUNu45s/EBZJBjADLgnwE0SGNRRIiey6XeuUOY4OLfTE8NcimvAM5rx/tq4cNheeQAZrgr418u23ct3ldwQosU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5c3c3b63135so5734203a12.3; Tue, 10 Sep 2024 03:04:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962664; x=1726567464; 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=R8arzrtSLiNViV6wdJz5xajd0j0cCB30Ei22v2izotk=; b=nhXaZ65NDmuV1AH9qU9bsU9QlODRUXIwmy4KHD3WpSXLYrOOPt5gNGyBwdZ2t1J0Yh vG9BXgJHAhLd/0xxWhJsl2s/jRfSrqFcxRaA+u4ETP8jnbbkcmjMqDN64O4sFZBzMXrU wP+Mov19Le729oJ5dUK2+ZuJJtBCBGVLJSh4t5wTaBPZcBBqlAfPs9AfBOVqxOd1XBjI qfysTa9CE0JJMhHadea7F/kEGZZXKxuFUO255nl0Nyy1wfjw5X4ra+jNry+CpozYAMQv gAJxAkUF1K9mTh+ASNDFFE1zfpwUN0l1iX7nqzkOKjhju5MiAQtqiixetHRLihWgIpXh PDmQ== X-Forwarded-Encrypted: i=1; AJvYcCUPbyB1OhUyeGgNDt7E5DqTNwvkxkhu1eAHdXyR0datXh7KaIQPd4mj7bzShPy1m/hGzEJAusw2arWvm1M=@vger.kernel.org, AJvYcCV7sqFwpPOgQFssTlo9GRAYYNJjPn60Jz1N3+T6jBMGRpCSlsjHTK2UI3uBi7t2EflI4nRxjr4r@vger.kernel.org X-Gm-Message-State: AOJu0YzaDD19r3mLT8uZA2QM+SRGNLvxieZx3RcLYmjRRO558AQyJh5U F0rbhBvwdgFI1BbAyYJFkmJOZrvwnfA0jxWb2uKT40JTybypj2yo X-Google-Smtp-Source: AGHT+IG+lrIlOCOYXcbkAPUKdrM8ci2bHZWOhdirCmht9GkUYdj5nUxSLwDnkCKDue9xMB1/962THw== X-Received: by 2002:a05:6402:13d3:b0:5c2:5141:8488 with SMTP id 4fb4d7f45d1cf-5c3dc78512bmr11949148a12.5.1725962663513; Tue, 10 Sep 2024 03:04:23 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd5245dsm4108553a12.52.2024.09.10.03.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:22 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 02/10] net: netconsole: split send_ext_msg_udp() function Date: Tue, 10 Sep 2024 03:03:57 -0700 Message-ID: <20240910100410.2690012-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The send_ext_msg_udp() function has become quite large, currently spanning 102 lines. Its complexity, along with extensive pointer and offset manipulation, makes it difficult to read and error-prone. The function has evolved over time, and it’s now due for a refactor. To improve readability and maintainability, isolate the case where no message fragmentation occurs into a separate function, into a new send_msg_no_fragmentation() function. This scenario covers about 95% of the messages. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 46 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 03150e513cb2..d31ac47b496a 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1058,6 +1058,32 @@ static struct notifier_block netconsole_netdev_notifier = { .notifier_call = netconsole_netdev_event, }; +static void send_msg_no_fragmentation(struct netconsole_target *nt, + const char *msg, + const char *userdata, + int msg_len, + int release_len) +{ + static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + const char *release; + + if (release_len) { + release = init_utsname()->release; + + scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); + msg_len += release_len; + } else { + memcpy(buf, msg, msg_len); + } + + if (userdata) + msg_len += scnprintf(&buf[msg_len], + MAX_PRINT_CHUNK - msg_len, + "%s", userdata); + + netpoll_send_udp(&nt->np, buf, msg_len); +} + /** * send_ext_msg_udp - send extended log message to target * @nt: target to send message to @@ -1090,23 +1116,9 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, release_len = strlen(release) + 1; } - if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) { - /* No fragmentation needed */ - if (nt->release) { - scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); - msg_len += release_len; - } else { - memcpy(buf, msg, msg_len); - } - - if (userdata) - msg_len += scnprintf(&buf[msg_len], - MAX_PRINT_CHUNK - msg_len, - "%s", userdata); - - netpoll_send_udp(&nt->np, buf, msg_len); - return; - } + if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) + return send_msg_no_fragmentation(nt, msg, userdata, msg_len, + release_len); /* need to insert extra header fields, detect header and body */ header = msg; From patchwork Tue Sep 10 10:03:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798229 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 8ADB0192D96; Tue, 10 Sep 2024 10:04:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962669; cv=none; b=hfQIUdSqsSj4wnRQy1fUzzI9j5q3eyDl4uTzMrGoOsxftmRF9EqlA1pMVELSM5ntt/IlyLrvKw7oqrr8gp9caoGG/U1lrR6CocZDNZsDqGSbCSb8pSWhJHpWdarpebdH9JWQ2aS+RBDlQYifooTvV+6jZSsJo89nbt2AnWySLz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962669; c=relaxed/simple; bh=b0aIxet0QXlwVUlrSckU71HVdA5OMCthBU4wm1Oj+xw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UXfV7UHtFAubAOk8mgm0o11s2/2a8zRjLn0ZfuO+/fk+/3+I48QHzDhYxyaKUoq2ibo4d3ZhsLDMB9nUrBe9n36DSF3DNoNmAbN4yFfHI08GP7e9nZMk4Z9xaoAjz1EsDMjINeZxWU9iJfNDF/6oNvTzkRe10YEc41Jp4ZCG7y4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a8d29b7edc2so411293566b.1; Tue, 10 Sep 2024 03:04:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962666; x=1726567466; 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=m6YmRt0ZJ0d/twgod5Qz5nnBIxWY8JCvQ0B1lUv4E5Q=; b=kQhEVFg0UXGxj24KgOzDtS2hvfCtp4YxwCj6ThYBYaH1KLfDi4Zo1DRH3hZZ/6LM1j iTcGfg3kpbghNMg8elt5qVohpOpBHbN1IBNQNMr4gPn9rODRg/Gg3jKR3LWD6mCBM/Yl F61ir/xmBhYldh6RUjb1wJPx8oHVM1tXt4w+lawWG49ZLVOE5N0dn5rnH12SOw73aaG5 irr1poLooa9aFRP92XQlO6A+nXGRc3Njs9LfjLUlYOtDPgmedeJLqwQ9GSCT8D6VOawp XcXZg0K/a+W4Mfhti/XQj/b1DsiGNcA7hQikb3s9W5cxDbhj07eB48nrTfPWHOWoYKzl LZAg== X-Forwarded-Encrypted: i=1; AJvYcCUChveBrZpLyCUphamO4NawvfipT4IteOTpm7iAVXmg1Mqm5gYpaYcTl9Du5PvNHbMmxUzVhCAlAdm2kyE=@vger.kernel.org, AJvYcCXnpT8XalR/dH8ZvGEItwO0jjjh5e3c/ugm4D2Cz0X0ebsbchdz/OJ++M/BCt7ggtRV5LnXx2nL@vger.kernel.org X-Gm-Message-State: AOJu0Yxamr8KUXQn0W/0egQDbi8xHVACgk6kUNpOmUuYV/u5hXVoQiHP FVLCWZAERfRijn5t3lrbrh6hDDjNqV1Hc5pwioiZ2CFnGAjxsJMp X-Google-Smtp-Source: AGHT+IFSG0Q3/0KAfQPCfDnyMN9V6STYJa1aHoiU6E4XT8a2r6mo+jKSOyxoV9lh1Gi+yZAM5KbckA== X-Received: by 2002:a17:906:6a1b:b0:a77:b4e3:4fca with SMTP id a640c23a62f3a-a8ffaaa23bbmr26374166b.9.1725962665751; Tue, 10 Sep 2024 03:04:25 -0700 (PDT) Received: from localhost (fwdproxy-lla-115.fbsv.net. [2a03:2880:30ff:73::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25ce96a7sm458426766b.158.2024.09.10.03.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:25 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 03/10] net: netconsole: separate fragmented message handling in send_ext_msg Date: Tue, 10 Sep 2024 03:03:58 -0700 Message-ID: <20240910100410.2690012-4-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Following the previous change, where the non-fragmented case was moved to its own function, this update introduces a new function called send_msg_fragmented to specifically manage scenarios where message fragmentation is required. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 78 ++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index d31ac47b496a..8faea9422ea1 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1084,41 +1084,20 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, netpoll_send_udp(&nt->np, buf, msg_len); } -/** - * send_ext_msg_udp - send extended log message to target - * @nt: target to send message to - * @msg: extended log message to send - * @msg_len: length of message - * - * Transfer extended log @msg to @nt. If @msg is longer than - * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with - * ncfrag header field added to identify them. - */ -static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, - int msg_len) +static void send_msg_fragmented(struct netconsole_target *nt, + const char *msg, + const char *userdata, + int msg_len, + int release_len) { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + int offset = 0, userdata_len = 0; const char *header, *body; - int offset = 0; int header_len, body_len; const char *release; - int release_len = 0; - int userdata_len = 0; - char *userdata = NULL; - -#ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata = nt->userdata_complete; - userdata_len = nt->userdata_length; -#endif - if (nt->release) { - release = init_utsname()->release; - release_len = strlen(release) + 1; - } - - if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) - return send_msg_no_fragmentation(nt, msg, userdata, msg_len, - release_len); + if (userdata) + userdata_len = nt->userdata_length; /* need to insert extra header fields, detect header and body */ header = msg; @@ -1134,11 +1113,18 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, * Transfer multiple chunks with the following extra header. * "ncfrag=/" */ - if (nt->release) + if (release_len) { + release = init_utsname()->release; scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); + } + + /* Copy the header into the buffer */ memcpy(buf + release_len, header, header_len); header_len += release_len; + /* for now on, the header will be persisted, and the body + * will be replaced + */ while (offset < body_len + userdata_len) { int this_header = header_len; int this_offset = 0; @@ -1184,6 +1170,38 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, } } +/** + * send_ext_msg_udp - send extended log message to target + * @nt: target to send message to + * @msg: extended log message to send + * @msg_len: length of message + * + * Transfer extended log @msg to @nt. If @msg is longer than + * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with + * ncfrag header field added to identify them. + */ +static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, + int msg_len) +{ + char *userdata = NULL; + int userdata_len = 0; + int release_len = 0; + +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata = nt->userdata_complete; + userdata_len = nt->userdata_length; +#endif + + if (nt->release) + release_len = strlen(init_utsname()->release) + 1; + + if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) + return send_msg_no_fragmentation(nt, msg, userdata, msg_len, + release_len); + + return send_msg_fragmented(nt, msg, userdata, msg_len, release_len); +} + static void write_ext_msg(struct console *con, const char *msg, unsigned int len) { From patchwork Tue Sep 10 10:03:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798230 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 D0C3F194145; Tue, 10 Sep 2024 10:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962671; cv=none; b=kCEne9++9XNVFCwdKDfIc612yFIDBN3YZQjzYghK4kTXmS9woGh4eBZ3rbJQaJvp8tE7Fh5ElRh5uwgKyJvapqbrbXzyNnkAbapoPZLfoKB+BNrHRZdyEtTKGBc4x+zMwmo1q7joXOeaElbiztOqpIWovpKhSEscAgFr5l2RZaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962671; c=relaxed/simple; bh=ZLXFzw8cggmveoMCih29nomf9TtufEacKFySgKw1xl0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSQ+/LfcT0QUpiybclDdOdOzq0hDXRti2y56Bw0srBEkaldMKOo8t6tH8O85pr/459d8awKKzwrPVhXd084CAxNiUBvRdf3K0ryC4oxxx+MF3vbinXNP1DnsiU58Z3JOuy5hEAjZLrN9KF62JTM3WgQW1hkOxEJ0Yq+ML/MURQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2f75129b3a3so51366531fa.2; Tue, 10 Sep 2024 03:04:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962668; x=1726567468; 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=svZ2oM7n93rJLFOl8KUffAWkoqKVUGNhykuSyHUkUd0=; b=nohxTiwfxbuAn4ZJrd+g4V3LuRWs/lN4Bgt2S8Tam7DSdPQ2dDSLiE1QWN/m+e20pk m7LWP8R0yMzGuGOzqd2PnkHLWVHh9L9z6oFJHD+sAoezQmMtE6nwb3x1DN1xmRLTHjUH 4m+U41xnQM9NMiJ5LtE+7g/nbYoAT04wcxusEJ2G/2aDTdbGLHTU0pogGJmq2Eueg+Uz Da4R/cDQ0Z2+m5Jaq84OvxD1o/7Lc2ptJ8IwSrtm1k6Zpg48HgLKIqs3PfgJkIVZVQXN 7An8v4eo99KXmVdLwgFjGlOGqTOyORhLz24fg4uHQc8peZtpNEUjhIgwQfHF5ald8QJi kqhA== X-Forwarded-Encrypted: i=1; AJvYcCUPXYy/a/r6c6D9DTkxSRt5Ux0VlRcpi8bw+u1Ak5+gWnifhrUQOm/3XEySNx4IUV64aSTRTjFW@vger.kernel.org, AJvYcCV52O6U0NvMZxNylEgO2gh178nmSm1rkvdY0TkHwd8Ry/rHcVm8VJaDfJXDX4ymqn0rNjGCr3ie6qkv/6A=@vger.kernel.org X-Gm-Message-State: AOJu0YxPFLMvJ+f4hy9bZEol8YTK9qlrAHzc29iXC1hXXc+MhcQfqJsG z7wT3TVYzHbseUF2AmfXlO4+Vup6JP9PGODNnDuWdvMIju3AZhvD X-Google-Smtp-Source: AGHT+IHxtI77mg54kWmkuczRnstyirIGeviLa3IyAo/SEhr5INIXO6R++KJuWSo9A8M3RTdMKZFScA== X-Received: by 2002:a05:651c:542:b0:2f6:6202:bfd5 with SMTP id 38308e7fff4ca-2f751f6a2c7mr85627431fa.34.1725962667740; Tue, 10 Sep 2024 03:04:27 -0700 (PDT) Received: from localhost (fwdproxy-lla-005.fbsv.net. [2a03:2880:30ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd8cdf7sm4064280a12.92.2024.09.10.03.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:27 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 04/10] net: netconsole: rename body to msg_body Date: Tue, 10 Sep 2024 03:03:59 -0700 Message-ID: <20240910100410.2690012-5-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org With the introduction of the userdata concept, the term body has become ambiguous and less intuitive. To improve clarity, body is renamed to msg_body, making it clear that the body is not the only content following the header. In an upcoming patch, the term body_len will also be revised for further clarity. The current packet structure is as follows: release, header, body, [msg_body + userdata] Here, [msg_body + userdata] collectively forms what is currently referred to as "body." This renaming helps to distinguish and better understand each component of the packet. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 8faea9422ea1..ca56c0ff57d0 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1092,22 +1092,22 @@ static void send_msg_fragmented(struct netconsole_target *nt, { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; - const char *header, *body; - int header_len, body_len; + const char *header, *msgbody; + int header_len, msgbody_len; const char *release; if (userdata) userdata_len = nt->userdata_length; - /* need to insert extra header fields, detect header and body */ + /* need to insert extra header fields, detect header and msgbody */ header = msg; - body = memchr(msg, ';', msg_len); - if (WARN_ON_ONCE(!body)) + msgbody = memchr(msg, ';', msg_len); + if (WARN_ON_ONCE(!msgbody)) return; - header_len = body - header; - body_len = msg_len - header_len - 1; - body++; + header_len = msgbody - header; + msgbody_len = msg_len - header_len - 1; + msgbody++; /* * Transfer multiple chunks with the following extra header. @@ -1122,10 +1122,10 @@ static void send_msg_fragmented(struct netconsole_target *nt, memcpy(buf + release_len, header, header_len); header_len += release_len; - /* for now on, the header will be persisted, and the body + /* for now on, the header will be persisted, and the msgbody * will be replaced */ - while (offset < body_len + userdata_len) { + while (offset < msgbody_len + userdata_len) { int this_header = header_len; int this_offset = 0; int this_chunk = 0; @@ -1133,23 +1133,24 @@ static void send_msg_fragmented(struct netconsole_target *nt, this_header += scnprintf(buf + this_header, sizeof(buf) - this_header, ",ncfrag=%d/%d;", offset, - body_len + userdata_len); + msgbody_len + userdata_len); - /* Not all body data has been written yet */ - if (offset < body_len) { - this_chunk = min(body_len - offset, + /* Not all msgbody data has been written yet */ + if (offset < msgbody_len) { + this_chunk = min(msgbody_len - offset, MAX_PRINT_CHUNK - this_header); if (WARN_ON_ONCE(this_chunk <= 0)) return; - memcpy(buf + this_header, body + offset, this_chunk); + memcpy(buf + this_header, msgbody + offset, this_chunk); this_offset += this_chunk; } - /* Body is fully written and there is pending userdata to write, - * append userdata in this chunk + + /* Msg 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; + if (offset + this_offset >= msgbody_len && + offset + this_offset < userdata_len + msgbody_len) { + int sent_userdata = (offset + this_offset) - msgbody_len; int preceding_bytes = this_chunk + this_header; if (WARN_ON_ONCE(sent_userdata < 0)) From patchwork Tue Sep 10 10:04:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798231 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 751B1195FD5; Tue, 10 Sep 2024 10:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962675; cv=none; b=t9WgxLybwUdbLT97EZsiibYLMnLsoro1x6dNsFpb+Jbkd2ygxAfCuTFpA/RtVNk0NCUNMuNQwUkr2P8vLUY5vlopElXplQ4NMI2fg+UN2UJuRY8sVzx1gULJQJLpG51Suz0PP1dP+c5cbTkGTh1qExqoiJwhelgVDNguHSYh20k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962675; c=relaxed/simple; bh=WxE+MqO9IF59LOFvBydiSddCHhj3Ff9s7KKnZYlLVPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GXYuQJQ79bSPUy1l45WoM/45U+VURqmxotbGXhpf/07LIoXLydqByhm7k6FRkkrsnJaF+opeXHAQu04qNQsCqJxjEAlo/tVQyRni8fF/91O1IAhJ5CEiJVg3a6RG8ThZzdx49PhPBjCfJzxsk2LwZRR1NxfJ5FZKWw+gECAseJ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a8d446adf6eso313765466b.2; Tue, 10 Sep 2024 03:04:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962671; x=1726567471; 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=mvXlMaYZ+vgHCaRdCb9MNmEXaTSsT8fjgwwnA5+yiDE=; b=WEwlgriJPmpbvfwjI+nhEsybCm9gHG8nJyZU172QkmxPefAGdUZwTM1qkDphwApm6I g2Y5kFfQpe+lMpGY5BGmVtxe3tYfnRKOK7Z5U76KJ24VzEEoFYxrv0lApuv8U/vW1tV6 58IA+PUoIi2g3uTWe4w8SWm5g7DBx7k1AwMkpj+WVoXluzpWXFP8475dkwUhopKWpjdS VwP7tBctWGIkGP86mM3dm6PsXUzAr70Fo7crfoLpiSrv66wxDxJBBkbvBBbjIds00ksZ PqpYRORjpNLaAHhoKt4FSybAAS2oedGF6BO0Gs13IiD3yhnvmvtHIBnSWyyDI2STsXkH leYQ== X-Forwarded-Encrypted: i=1; AJvYcCUO7MM6FDhxTjBISXAVlWpAJ1OuOyXKEBkx8DAMfuKVEOrr3VONgCOHTXAe7Tcds9mVo8Hxs1QOa6lPKd8=@vger.kernel.org, AJvYcCUVENSDHJaAOku4QSMB5dHwRxoRPCcQDwiQI7qhFhVvyEPj7uTwa+ZWReEf9UkCpEh2OE2aoaeh@vger.kernel.org X-Gm-Message-State: AOJu0YwY9+WCLdccacT9uEMPKSjLk+LN1rBmdBY/GpVpHgjz0RduFcPX oqSwXPGhq1EJt9YApt/W5FkfcdE8fNKYOff9ZxbJ1GYL34iI09Jn X-Google-Smtp-Source: AGHT+IFz5DIbnAPoUkyVreJwGeNYfbkEbZyM01gzEal9JX0fmkZhFpsG7vu2JqcW8m4INu8uxQProQ== X-Received: by 2002:a17:907:72d6:b0:a8a:83cb:ad13 with SMTP id a640c23a62f3a-a8ffad97d48mr18966366b.49.1725962669831; Tue, 10 Sep 2024 03:04:29 -0700 (PDT) Received: from localhost (fwdproxy-lla-007.fbsv.net. [2a03:2880:30ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d5da53sm456591566b.209.2024.09.10.03.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:29 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 05/10] net: netconsole: introduce variable to track body length Date: Tue, 10 Sep 2024 03:04:00 -0700 Message-ID: <20240910100410.2690012-6-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This new variable tracks the total length of the data to be sent, encompassing both the message body (msgbody) and userdata, which is collectively called body. By explicitly defining body_len, the code becomes clearer and easier to reason about, simplifying offset calculations and improving overall readability of the function. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index ca56c0ff57d0..ddf38141d30b 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1090,10 +1090,10 @@ static void send_msg_fragmented(struct netconsole_target *nt, int msg_len, int release_len) { + int header_len, msgbody_len, body_len; static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; const char *header, *msgbody; - int header_len, msgbody_len; const char *release; if (userdata) @@ -1122,10 +1122,11 @@ static void send_msg_fragmented(struct netconsole_target *nt, memcpy(buf + release_len, header, header_len); header_len += release_len; + body_len = msgbody_len + userdata_len; /* for now on, the header will be persisted, and the msgbody * will be replaced */ - while (offset < msgbody_len + userdata_len) { + while (offset < body_len) { int this_header = header_len; int this_offset = 0; int this_chunk = 0; @@ -1133,7 +1134,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, this_header += scnprintf(buf + this_header, sizeof(buf) - this_header, ",ncfrag=%d/%d;", offset, - msgbody_len + userdata_len); + body_len); /* Not all msgbody data has been written yet */ if (offset < msgbody_len) { @@ -1149,7 +1150,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, * write, append userdata in this chunk */ if (offset + this_offset >= msgbody_len && - offset + this_offset < userdata_len + msgbody_len) { + offset + this_offset < body_len) { int sent_userdata = (offset + this_offset) - msgbody_len; int preceding_bytes = this_chunk + this_header; From patchwork Tue Sep 10 10:04:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798232 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 CFD82194145; Tue, 10 Sep 2024 10:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962675; cv=none; b=qkWnpuELqsYWBkHKFKX6SSqJ6XjKNR86uIuNbkmqKnshjrK5Wv+b+txWSm+lQ0dB+9QtDHGug+Y8K6ifeNBx3GESE1cvd7SOgKmdAI5isU3NpTOVAN3ErBeHS6Mpqzi999uMC3ssVs/IG6g4P+vuWVbW5bwkBDR464NBWPo1w2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962675; c=relaxed/simple; bh=VmHLDyvUMxnd2R9x0S5TGw53JhfqyA6sCShhqanF4Lw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PYeLKgcbU41jcZUIvewjpxDAQOSxAd0fqwSNpoFtSc8GJuq+humNaoSWVrubOKOfA4S5vMCwP6IuClk82yqZXiLnRW873Gr4wTn3CwLE2YN62woJTJH12do8c/DD/hdItOm7eFhfZ1ixK5NAGflDTcC2MXhx48nr/r7lOP6dTCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5bef295a429so5976098a12.2; Tue, 10 Sep 2024 03:04:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962672; x=1726567472; 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=2Pqe4K0R7CoCqj5GJyoU7hPoXfTkXZJG/58IRFqgmqo=; b=xDZu/lHUbTAptLx528YQVqbD4e8b2uoWG0uY+h2oZcZ6L7+pp8nlc51rgnl50WdF4Q p2xMq18j4N3RTEGWnOZoI8zYROPAWG/61vlvYFIM2TXzOJCpAfToR8JUlTQfD5BwSsay m8SLbMu/vZYS2wU5wb4AGdjTaZF0msNOAfM3/77MLplul4ehKD2cXe7UOnlFPkI/Xnog Vw9NfJKO4OlwZ127UznDwLFRd1YVibdzmsm77Doex+kCHD7NK0AnGcqEhVvWG+ozjRsn ifMXlnISJ+Fiml+fATBFclXgzrdy6sXXzCbu40HHjTx8V1I5f+PUOyzCjK12gTI1O5KA UXNw== X-Forwarded-Encrypted: i=1; AJvYcCUzs9u0JDxytr7t0mT1/sNIhOYBQS79lj9qa7VM3nWftkMM2xRIfz6WO8MdiZmFUOPLd2i5wco6sapNXRs=@vger.kernel.org, AJvYcCWB5IeaOFeb5FPSUrqdQhOXTxN5LS29c2+TMM5w/1B1JqsO+FnzpNMMlrAB3vRUeo1Fi2FRWHEe@vger.kernel.org X-Gm-Message-State: AOJu0YzMw7sszWMSadbjb7B9MBV9QguAIX6IDyXOEmE5u2MX6s5XL2X1 V9dIm/wkzGF2Lg81pDIX6lsKqi0XoIOoK2yJKCqIe+lDD73YRgPP X-Google-Smtp-Source: AGHT+IGtg+3mKde3BezK/OSdRHNz2ImJo6UTLgRBpxLdF2FHuZHBdvceimsycIToJqIj2Dc6CbuGNg== X-Received: by 2002:a17:907:7fa6:b0:a83:9573:45cc with SMTP id a640c23a62f3a-a8ffaabe5b9mr22721466b.14.1725962672033; Tue, 10 Sep 2024 03:04:32 -0700 (PDT) Received: from localhost (fwdproxy-lla-115.fbsv.net. [2a03:2880:30ff:73::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25833887sm460592566b.28.2024.09.10.03.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:31 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 06/10] net: netconsole: track explicitly if msgbody was written to buffer Date: Tue, 10 Sep 2024 03:04:01 -0700 Message-ID: <20240910100410.2690012-7-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The current check to determine if the message body was fully sent is difficult to follow. To improve clarity, introduce a variable that explicitly tracks whether the message body (msgbody) has been completely sent, indicating when it's time to begin sending userdata. Additionally, add comments to make the code more understandable for others who may work with it. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index ddf38141d30b..1366b948bcbf 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1128,6 +1128,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, */ while (offset < body_len) { int this_header = header_len; + bool msgbody_written = false; int this_offset = 0; int this_chunk = 0; @@ -1146,12 +1147,22 @@ static void send_msg_fragmented(struct netconsole_target *nt, this_offset += this_chunk; } + if (offset + this_offset >= msgbody_len) + /* msgbody was finally written, either in the previous + * messages and/or in the current buf. Time to write + * the userdata. + */ + msgbody_written = true; + /* Msg body is fully written and there is pending userdata to * write, append userdata in this chunk */ - if (offset + this_offset >= msgbody_len && - offset + this_offset < body_len) { + if (msgbody_written && offset + this_offset < body_len) { + /* Track how much user data was already sent. First + * time here, sent_userdata is zero + */ int sent_userdata = (offset + this_offset) - msgbody_len; + /* offset of bytes used in current buf */ int preceding_bytes = this_chunk + this_header; if (WARN_ON_ONCE(sent_userdata < 0)) From patchwork Tue Sep 10 10:04:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798233 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 36535198A32; Tue, 10 Sep 2024 10:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962677; cv=none; b=hVtCuM7LurSjyZtkgt2+qQrJxTYWkjqSB/1C++UPVxB2BUHcZ4wDKJ3i12zHGnb57WpVQZ5yaN11xI8meVJkwvBxvNeVqVeS99YHMk2V9Pt22a5oGU5Cf7OOgwUXhn4gbheyc2CiR1qp9CI1WoCfBK2fZfVZr+awsMtsNApx/Yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962677; c=relaxed/simple; bh=mr7ozxLYNIKSDK28c1JS/rg+dGy/5mHfdcu4ZO66wkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OnRm5fu2YRXmC/oDMTCmn7I6wyYsr+JLuUdbrSBeQqi/4mVx3FTas88+FoxpFp/RxpAcoAtEF20drYWarljTzE+nyr2N8CBizLfJc2kcdgQ1AXIXMYfotE0CjGP/t2w9o+pk1mHGOwVE9bAO9ZAvaLTJakQsaJUo+o3Ws1Q+wUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5356aa9a0afso9241678e87.2; Tue, 10 Sep 2024 03:04:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962674; x=1726567474; 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=7YPaA0LtjHQmgp6W5R5O8D3n6pkkJ4FmCPhF61F3u3U=; b=vcLs0KzUoejPuklVALqjquVrKQY59uIR0hHHYS7VbvYsOpyeXVKQVxVcrYYFwUc9re c5KkTn4nbps/V18ObnTeUokqbYO1f0qnLpEFJgXlel4In3eTpgLVRJQn8E4opb9+/6D8 EpFWQ6BB+sa/hUDwy+DX6tG2ZkYzyWFtMIiwbH8ejZ0hcsGsAsLa6LpUaGlhstyhNK0e Uqay0e2xde5hfJiwkL0YZl4tC0qI3w/4QjHVKeUU1XB5IR6w2xoZH/Iad5unEYr2tEKG oPdKxV5eNWNQc28Bl+rzztCR/8V5+nIUmgupxiWcoDLzYrlqhY5dPhxAKlNRwcLGtXuZ 97FQ== X-Forwarded-Encrypted: i=1; AJvYcCVaqogqAC8V/APmvqD4Cod+FP/Mgg65eHkSXfHmG6r8VFutptqLRSd/zVGHmCz8AcoWimYMsUGu@vger.kernel.org, AJvYcCXp3YV8DwxP92cKZMF/NaFg1vfm3vjijoMtDfs5hpRsMaFTmoLRPV4yvijpRB6MsBVZHVbEqLbWmbolIjI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0Pvy9qgjxyVDaBPI3sXayOpU3ZhRHMc/ylw8xHyTfnFAyKaZy KsHIqCpQk1lJE806tOfR5dOtohObzxZPoNPKImtJBgMBUjTDvw3S X-Google-Smtp-Source: AGHT+IEhejx+G4yTvW5DvEUXUkfw9eLFs1/+vlLl+MqIm3iMXRw35/iBTH7WV91UbQiFrDGi41qZNw== X-Received: by 2002:a05:6512:1245:b0:536:54bd:8374 with SMTP id 2adb3069b0e04-53658818949mr7594604e87.60.1725962674110; Tue, 10 Sep 2024 03:04:34 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25ce86e0sm462696166b.143.2024.09.10.03.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:33 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 07/10] net: netconsole: extract release appending into separate function Date: Tue, 10 Sep 2024 03:04:02 -0700 Message-ID: <20240910100410.2690012-8-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Refactor the code by extracting the logic for appending the release into the buffer into a separate function. The goal is to reduce the size of send_msg_fragmented() and improve code readability. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 1366b948bcbf..2cdd2d6a2a18 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1084,6 +1084,14 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, netpoll_send_udp(&nt->np, buf, msg_len); } +static void append_release(char *buf) +{ + const char *release; + + release = init_utsname()->release; + scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); +} + static void send_msg_fragmented(struct netconsole_target *nt, const char *msg, const char *userdata, @@ -1094,7 +1102,6 @@ static void send_msg_fragmented(struct netconsole_target *nt, static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; const char *header, *msgbody; - const char *release; if (userdata) userdata_len = nt->userdata_length; @@ -1113,10 +1120,8 @@ static void send_msg_fragmented(struct netconsole_target *nt, * Transfer multiple chunks with the following extra header. * "ncfrag=/" */ - if (release_len) { - release = init_utsname()->release; - scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); - } + if (release_len) + append_release(buf); /* Copy the header into the buffer */ memcpy(buf + release_len, header, header_len); From patchwork Tue Sep 10 10:04:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798234 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 0019E190667; Tue, 10 Sep 2024 10:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962679; cv=none; b=NgHVaH/LNGe4cnG2v7zFauU+tPZMNv8GHPtgyF5dqtrHK8B9uKOg6uMdTfutw/LqIGo2TGrcA78TVfYF3w6TXziQdjAiWf6wHLpPfW/3IA+nwJKAzzpKvk4kUpsX4meBixO7rSHGpmOZAsZSja4/flbfleWuxrx9LIiANhM5d0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962679; c=relaxed/simple; bh=fVBe2+wvg1jvCIqi29qSEpWCHmDMPNeHFjsHpuV8Mhs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ot0h/n89VPUqERRW9EubqQf2vioBcLT5MUtqwJaHW0MMlXsG1r01D2x1AR4mGVYzj7of1oht6w24NvNNeJIMsZIE448Kupxqq7orE9Y/pvRBz71bmLFI/gi/MNnjOd1iHmXeT8bJmsPRbG5LOA89LJ+stKqc3p/VLVCdUaYWHF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5bef295a45bso2336113a12.0; Tue, 10 Sep 2024 03:04:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962676; x=1726567476; 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=cdFM3/nkoHZB47AixIU8OcFNaXm8D7juybaooP167So=; b=W9vkgWUhYqYRwNhUBZUyTHcI4Wql7dYAHcpY0Fc2Qky4mPy8gi8YvHizfoM35tTUvA j4Df274Gk1neoIl2xcEltyCOzG2MClyRs5sgGlGa4kGh+xS8arAu3YDzf77Brn1F7G4q tT+XeXhlNxgk3GmFFejjUhHO4Cn4r145Q/62lHQbIMSvOwhy1x9rF8vEWiUwjuzUQh0t 8T9mdmCYd2dXLJLmUX6JJCLbGfcVyGYiCxtt6QUyuEDVguQEIdzw2+3pdIuwvWBrEtNP BvXWXZqxyIm+jpjw/7mQDFbtCF+gcQArIDwdN7GWc6TPOyn48MIHEJNPkznvLLQklsgB gUWg== X-Forwarded-Encrypted: i=1; AJvYcCX/qTLon4tkGac9xz+454J9OkgAOHcPyagCGECGE/Z/3xOoEfUPCiLF3G1NXI3YtXpZs8/fKRon@vger.kernel.org, AJvYcCXksWbepFCSZ17R9Us9EOpAxApsriCs4XCACWjUpqI9Tg43mXz6zbFlfbdQ0MXxEpxq/1TA5DH4nuM/jc4=@vger.kernel.org X-Gm-Message-State: AOJu0YzsBTikvfckaaqboDGfnFDdDxXrdag8NFOsEdizgHp5cKfSguov n7vhn+GQTFbklzrej9/SIVXGe9bJIcEkesHmbQrQyjQ60V8ISIc1 X-Google-Smtp-Source: AGHT+IHUY7tD9gZc0uoUw5kf66usXyJ9SYYRRKZ1mt6AggCfnzqOMbt3TBVGU+AWMNx5t/fwThZ78g== X-Received: by 2002:a05:6402:1e93:b0:5be:d687:9e6c with SMTP id 4fb4d7f45d1cf-5c3dc7c9dbbmr10690001a12.36.1725962676147; Tue, 10 Sep 2024 03:04:36 -0700 (PDT) Received: from localhost (fwdproxy-lla-113.fbsv.net. [2a03:2880:30ff:71::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd41c36sm4078483a12.2.2024.09.10.03.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:35 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 08/10] net: netconsole: do not pass userdata up to the tail Date: Tue, 10 Sep 2024 03:04:03 -0700 Message-ID: <20240910100410.2690012-9-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Do not pass userdata to send_msg_fragmented, since we can get it later. This will be more useful in the next patch, where send_msg_fragmented() will be split even more, and userdata is only necessary in the last function. Suggested-by: Simon Horman Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 2cdd2d6a2a18..1de547b1deb7 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1060,13 +1060,17 @@ static struct notifier_block netconsole_netdev_notifier = { static void send_msg_no_fragmentation(struct netconsole_target *nt, const char *msg, - const char *userdata, int msg_len, int release_len) { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + const char *userdata = NULL; const char *release; +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata = nt->userdata_complete; +#endif + if (release_len) { release = init_utsname()->release; @@ -1094,17 +1098,18 @@ static void append_release(char *buf) static void send_msg_fragmented(struct netconsole_target *nt, const char *msg, - const char *userdata, int msg_len, int release_len) { + const char *header, *msgbody, *userdata; int header_len, msgbody_len, body_len; static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; - const char *header, *msgbody; - if (userdata) - userdata_len = nt->userdata_length; +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata = nt->userdata_complete; + userdata_len = nt->userdata_length; +#endif /* need to insert extra header fields, detect header and msgbody */ header = msg; @@ -1201,12 +1206,10 @@ static void send_msg_fragmented(struct netconsole_target *nt, static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, int msg_len) { - char *userdata = NULL; int userdata_len = 0; int release_len = 0; #ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata = nt->userdata_complete; userdata_len = nt->userdata_length; #endif @@ -1214,10 +1217,9 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, release_len = strlen(init_utsname()->release) + 1; if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) - return send_msg_no_fragmentation(nt, msg, userdata, msg_len, - release_len); + return send_msg_no_fragmentation(nt, msg, msg_len, release_len); - return send_msg_fragmented(nt, msg, userdata, msg_len, release_len); + return send_msg_fragmented(nt, msg, msg_len, release_len); } static void write_ext_msg(struct console *con, const char *msg, From patchwork Tue Sep 10 10:04:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798235 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 2696B199FB9; Tue, 10 Sep 2024 10:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962681; cv=none; b=OFeSL1+6BYxYBDlbK4cMYTe9vTMMPLQppaz1JKhWSsYY8y6TKxYxnIHgYpAMiNWyaUkMgaAtTb2cEiIFfcU6Xxs5+64/nFI+vVV38jKCMIIt/diNQeqLi9HrZl2FMYO1ojywSfp4RyN8EhNHeA7ypQj2DCukh3RT9YO2Ikg4dCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962681; c=relaxed/simple; bh=Kpg5GVd+w/ApQwWU94/53bFRdhB4gIrFUfrPQnFGMeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tUq5o7GK/YvLMYZOi5H0Jh3W0jOoIvnQ2tlcjUCRaGHYiK0yZqD8agoi0K4UZUh8Qa7tQCVeTEFDKYlN6w6L+yRdlihky0aBprCdqf5lN6r/A29Y7aTmyt1jMe0911zBiIQeXwKlZ0pMkOrHtY2Gko9joOPr2+5H4hr3jP3A+ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a8d6ac24a3bso242565166b.1; Tue, 10 Sep 2024 03:04:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962678; x=1726567478; 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=Ci3noUyKl461YZ7Pbmhfbca+9jJFB7ogsWsXgchngQ8=; b=aMZar1xeH9RcgMrwrzCKGwiwJ6WvO1FbQTLPHBzlTDvDGtiLDA8GyUDOJt4/rxQz/x TzOifNWcYXYlQZLkzjjd6EBA7MLKCy0FKzISJpzvoGdxGB5qxyhO+GsgV+25qtQ9zp4j p13icrTE0yZJvAGtb0oIqmGV7aE5xjWYOpgse5jQr1/MWq3tqFzoQ1UzaxzIH7Z/MQXu rfndlcZUM6BRszTLW1ewqhKUTpiStDTSMF4fTUisYxPd+xJ3NONcgbnLvOGk8bjTSYHx XtvkwB9xOEGryH989iosTCtrxuOPwFiFxEehGK1cDnk0dJv0dG3PPPrJ+eNP/Exbnl++ giXg== X-Forwarded-Encrypted: i=1; AJvYcCURD8njfXUQvdQnVcMTKet6UMlveDf1m/PRpLIVhwzmJJvPme8Dz41HGW46rt0GP6cT1pZxjS18pEs3ZZw=@vger.kernel.org, AJvYcCUTS4e6Yr20AbYLPEY0wnVnaCPtRqwhBn6sD/Pq92nlJHvrs0TF5LTr10cie/L21rOqx5xT0zEn@vger.kernel.org X-Gm-Message-State: AOJu0Ywg/FP0o8LBToFQoZOij/MForo0BKb3x5qx2RxaAHBfN07etj99 93UWcXKEWmf4F43UesyWQB5gZD2iicmiOo77+D/+U5RSbLeFoxrs X-Google-Smtp-Source: AGHT+IExsud9nczaylpSf8msA1H4Gpz8br4zdIBuYIBLEurlz0d782AiigGEC/Txq4R3siuqd6+89A== X-Received: by 2002:a17:907:1c1b:b0:a8d:4e69:4030 with SMTP id a640c23a62f3a-a8ffabc2359mr25685966b.19.1725962678353; Tue, 10 Sep 2024 03:04:38 -0700 (PDT) Received: from localhost (fwdproxy-lla-113.fbsv.net. [2a03:2880:30ff:71::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72eb0sm458917466b.132.2024.09.10.03.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:37 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 09/10] net: netconsole: split send_msg_fragmented Date: Tue, 10 Sep 2024 03:04:04 -0700 Message-ID: <20240910100410.2690012-10-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Refactor the send_msg_fragmented() function by extracting the logic for sending the message body into a new function called send_fragmented_body(). Now, send_msg_fragmented() handles appending the release and header, and then delegates the task of breaking up the body and sending the fragments to send_fragmented_body(). This is the final flow now: When send_ext_msg_udp() is called to send a message, it will: - call send_msg_no_fragmentation() if no fragmentation is needed or - call send_msg_fragmented() if fragmentation is needed * send_msg_fragmented() appends the header to the buffer, which is be persisted until the function returns * call send_fragmented_body() to iterate and populate the body of the message. It will not touch the header, and it will only replace the body, writing the msgbody and/or userdata. Also add some comment to make the code easier to review. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 82 +++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 1de547b1deb7..86473dc2963f 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1096,45 +1096,30 @@ static void append_release(char *buf) scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); } -static void send_msg_fragmented(struct netconsole_target *nt, - const char *msg, - int msg_len, - int release_len) +static void send_fragmented_body(struct netconsole_target *nt, char *buf, + const char *msgbody, int header_len, + int msgbody_len) { - const char *header, *msgbody, *userdata; - int header_len, msgbody_len, body_len; - static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ - int offset = 0, userdata_len = 0; + const char *userdata = NULL; + int body_len, offset = 0; + int userdata_len = 0; #ifdef CONFIG_NETCONSOLE_DYNAMIC userdata = nt->userdata_complete; userdata_len = nt->userdata_length; #endif - /* need to insert extra header fields, detect header and msgbody */ - header = msg; - msgbody = memchr(msg, ';', msg_len); - if (WARN_ON_ONCE(!msgbody)) - return; - - header_len = msgbody - header; - msgbody_len = msg_len - header_len - 1; - msgbody++; - - /* - * Transfer multiple chunks with the following extra header. - * "ncfrag=/" + /* body_len represents the number of bytes that will be sent. This is + * bigger than MAX_PRINT_CHUNK, thus, it will be split in multiple + * packets */ - if (release_len) - append_release(buf); - - /* Copy the header into the buffer */ - memcpy(buf + release_len, header, header_len); - header_len += release_len; - body_len = msgbody_len + userdata_len; - /* for now on, the header will be persisted, and the msgbody - * will be replaced + + /* In each iteration of the while loop below, we send a packet + * containing the header and a portion of the body. The body is + * composed of two parts: msgbody and userdata. We keep track of how + * many bytes have been sent so far using the offset variable, which + * ranges from 0 to the total length of the body. */ while (offset < body_len) { int this_header = header_len; @@ -1143,7 +1128,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, int this_chunk = 0; this_header += scnprintf(buf + this_header, - sizeof(buf) - this_header, + MAX_PRINT_CHUNK - this_header, ",ncfrag=%d/%d;", offset, body_len); @@ -1193,6 +1178,41 @@ static void send_msg_fragmented(struct netconsole_target *nt, } } +static void send_msg_fragmented(struct netconsole_target *nt, + const char *msg, + int msg_len, + int release_len) +{ + static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + int header_len, msgbody_len; + const char *msgbody; + + /* need to insert extra header fields, detect header and msgbody */ + msgbody = memchr(msg, ';', msg_len); + if (WARN_ON_ONCE(!msgbody)) + return; + + header_len = msgbody - msg; + msgbody_len = msg_len - header_len - 1; + msgbody++; + + /* + * Transfer multiple chunks with the following extra header. + * "ncfrag=/" + */ + if (release_len) + append_release(buf); + + /* Copy the header into the buffer */ + memcpy(buf + release_len, msg, header_len); + header_len += release_len; + + /* for now on, the header will be persisted, and the msgbody + * will be replaced + */ + send_fragmented_body(nt, buf, msgbody, header_len, msgbody_len); +} + /** * send_ext_msg_udp - send extended log message to target * @nt: target to send message to From patchwork Tue Sep 10 10:04:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13798236 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 433141922F2; Tue, 10 Sep 2024 10:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962683; cv=none; b=CNerJ1k178sw+VQ4ynJLgc7u0ESUhGkxVr6QOX2apSO1Wjo174UOTb2hgZsztP6ORbAunvk/0O/5aKCxkrGEJb1mL5Q1mPKx3v514AHwHzuuROfxE7cp1ao5bRicxipPf0mV2Aj60cgkgVLzcOMaNQDzUWzEFe8pa13J2VTTqJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962683; c=relaxed/simple; bh=BJV+r7fxxZqQ1eqNqmwAaK9bvos/cwcmNDivLsg5oJE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OJ1OF2myz8NM3beKJagnXPouX/0tD8SY16dynWaYUmNcZHqTiF6s63NHSa1Jpbc6/QEg+G9PNJfvBy/8pFRaa8BxYsYQ2GvL5Vi9ckf2IwmUoOF766OSMRsFM0CkwHs/IJK6f+1qTcfdBJUxBNGK0I4K9MEl2E33uzbab8cMzQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5c3d2f9f896so5740771a12.1; Tue, 10 Sep 2024 03:04:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725962680; x=1726567480; 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=NN/RftK0AtSsIg+UinUpjGI9Wdbejwds073AkbWDML8=; b=swMb8zShGi96JPDNZGZODhoygtLDcM+CBelJQ++ojWbwH+8tCAaNHAeTU8z6Mg00oh b6MlgD0yCCCaOFMs1YnIIehhEEIBdyMnW6YId2a9EprOxWIV1rrWy0aQD5YJ70BiAia7 kqZPwTnj129yTUmZcQpMZaqiGgnPTdS3k/3yb4byd6pMumcPI3KYtNziNvmQ+ldw6QSa LUb06zgLy+k1omL5Qq9lg81XPvawiKPGp8NVKPrxY0zTk9NYg2Cg9jCPsq8yVWiRAQtO 1PRiwpKKDKjc1SLMdngb0pFd5kPoe88y7VpADaJE0lQLiMsA9dY5VFut1sb4V0aO1iGw 7jVg== X-Forwarded-Encrypted: i=1; AJvYcCUMHZmwJYR4AniuM20UnBhJwoHht+xnYcj9lxkYw8IrNf5I5rZbtFePjgP6Sxs/A9jAnPz6T5sfbNiGoP4=@vger.kernel.org, AJvYcCUOgsWZmgt6Av6/m8cWd4D/3FJrZhdoEN6BoZ+p3en3tJ8GcSENvfqt5eECJA/q6smnwPpcI7A7@vger.kernel.org X-Gm-Message-State: AOJu0Yw0EaZcTTCyFo1adjA6+/G7BbOa3OPC/355GWxRY0DjIEdpE1V8 EcXPkZ88m4eWnmNkABjd3m2mPY/wlqGohZHJ08sh2FPX1cLDqFK0 X-Google-Smtp-Source: AGHT+IFX0pPWRAvDvfmSjrPODi7Lnuscg7NdxM/DXlinVH0dQq1JKuZbuzWHOWNdzZkncYbyFtaveA== X-Received: by 2002:a05:6402:3486:b0:5c3:2440:8570 with SMTP id 4fb4d7f45d1cf-5c3e9742dd6mr6770241a12.26.1725962680332; Tue, 10 Sep 2024 03:04:40 -0700 (PDT) Received: from localhost (fwdproxy-lla-114.fbsv.net. [2a03:2880:30ff:72::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd52071sm4102474a12.44.2024.09.10.03.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:04:39 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, Matthew Wood Cc: horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com Subject: [PATCH net-next v3 10/10] net: netconsole: fix wrong warning Date: Tue, 10 Sep 2024 03:04:05 -0700 Message-ID: <20240910100410.2690012-11-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100410.2690012-1-leitao@debian.org> References: <20240910100410.2690012-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org A warning is triggered when there is insufficient space in the buffer for userdata. However, this is not an issue since userdata will be sent in the next iteration. Current warning message: ------------[ cut here ]------------ WARNING: CPU: 13 PID: 3013042 at drivers/net/netconsole.c:1122 write_ext_msg+0x3b6/0x3d0 ? write_ext_msg+0x3b6/0x3d0 console_flush_all+0x1e9/0x330 The code incorrectly issues a warning when this_chunk is zero, which is a valid scenario. The warning should only be triggered when this_chunk is negative. Signed-off-by: Breno Leitao Fixes: 1ec9daf95093 ("net: netconsole: append userdata to fragmented netconsole messages") Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 86473dc2963f..624bfb342da0 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1165,8 +1165,14 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf, this_chunk = min(userdata_len - sent_userdata, MAX_PRINT_CHUNK - preceding_bytes); - if (WARN_ON_ONCE(this_chunk <= 0)) + if (WARN_ON_ONCE(this_chunk < 0)) + /* this_chunk could be zero if all the previous + * message used all the buffer. This is not a + * problem, userdata will be sent in the next + * iteration + */ return; + memcpy(buf + this_header + this_offset, userdata + sent_userdata, this_chunk);