From nobody Sat Nov 30 12:36:03 2024 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 5E9D41B9B22; Mon, 9 Sep 2024 13:08:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887291; cv=none; b=CMBZD5S75FbMVYumRhTfZUZj5FwRyVfcvTmFE0LoHAuAEVeAgjcRvN/b4fRPA5383AeyabSwwGZ8pw77NAi5KQWS7oHyefsqnoKuYFKe9jLimLMFmI156lNVLrnKsLB/bPHMZdADvGaQk9Oaa1sZoZjaRzez96fzfaPEpOHr9lw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887291; c=relaxed/simple; bh=pRaK3Ku3IkQXoZTZoJ3KsKO2/UXaI4WyWbGGP/VRtPU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DKyMmOs5ws8UHSrjAmIeEQz8fUeTVUskpBIXiPqBNrRnGpcXSAlC60xpExi45yi1IdvRKsuOHMqHKWRHInCaESJv0jP7jEghfmZYjQARI58EceYjUk43oNbrFvkee/5r7kfUJMpo5MHuffjXUlyQPgmBlvzqV09garb88KW2WbI= 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.45 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-f45.google.com with SMTP id 2adb3069b0e04-5365cf5de24so2474552e87.1; Mon, 09 Sep 2024 06:08:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887287; x=1726492087; 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=X+/zJa0tRh8xRbGhMePaFb/x0GDPbZMd8v7Tq6CmLvwe17BusFInRAzQjVrhgUCqn1 Ijb2hohzWPPtkgHrVe3YK32PKFXdJ5wcZNoZyHHBMG2QRcgiN5Y71ejcZzkTg5oonJUt NvImTuyNgtcdOp4BWFasFMZE9E0XBfz95dKi/Oy/7IT3RBJ2lzyVw9UnVtHGxggLmy5p s4Z36ZMUoq6baDg8uUcCTqhD7mJqUl2bSL/xEIpY6Gy3X50eK0bmpzd8IipeiH5RqvQR iClagb3s280wG7OAacTFIwV4Oy7TEq18y1lJwwCa0SMN3s/gFV8c8ISwlyVdO/x6b3Iw 7ijA== X-Forwarded-Encrypted: i=1; AJvYcCWRqQ3GKmMHbKGkVWPOtxqWlCNnNyRqGKJ0Fcj5y9YxNF0MTNzfJAnpBP3HqM/qrD28gPNNSFG7@vger.kernel.org, AJvYcCXhrhN6sOs7ZLlQOhrmzY9OtzkAmqQoWD4m1AnDWjNDBtHz4p7akM+PRRMnMlqRT7iLvHq+sVrYlHfIYIY=@vger.kernel.org X-Gm-Message-State: AOJu0YzbMsHw/YS2vlKlkCEU6tomhqLWt+wDNgX1il7vhbv0y/CFn0wO jdkfUheXBcCx8ICHsBuuZ6Kb921FBD1ccF3mzE0IInPo/Tchy9tL X-Google-Smtp-Source: AGHT+IEJBqpHVWtqlpvZ/Q0u/cQd0lbEGSJxVNB3EVR8pTi1XvjfhTBr1VM800Q+48zT8hF1hSksgQ== X-Received: by 2002:a05:6512:694:b0:536:545c:bbfa with SMTP id 2adb3069b0e04-536587ac1e7mr5159796e87.20.1725887286492; Mon, 09 Sep 2024 06:08:06 -0700 (PDT) Received: from localhost (fwdproxy-lla-000.fbsv.net. [2a03:2880:30ff::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd41cedsm3012821a12.5.2024.09.09.06.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:05 -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 v2 01/10] net: netconsole: remove msg_ready variable Date: Mon, 9 Sep 2024 06:07:42 -0700 Message-ID: <20240909130756.2722126-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D 0; int header_len, body_len; - const char *msg_ready =3D msg; const char *release; int release_len =3D 0; int userdata_len =3D 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); =20 - msg_ready =3D buf; - netpoll_send_udp(&nt->np, msg_ready, msg_len); + netpoll_send_udp(&nt->np, buf, msg_len); return; } =20 --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 79A231B81C7; Mon, 9 Sep 2024 13:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887292; cv=none; b=nri87R3lRMSlhUyDaXzc6h0tYJsS5WcGFzy6lJU+YeWMb6BiD4S0uR0THOl2aHg6XNBVYtTK/o4F6nWDcg25VfMR0fV6TDysapuluLmfPgXYAhMO9mmRK+ULTG844ZZdLSvAhYSFlAfT5Vd+bcWVtKohgS2brlGXgT7/XXPJjm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887292; c=relaxed/simple; bh=KlWvtgP776H3SGAl7+pUSjAVYPwx6ASIe7XSiqsaNgo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fyh7vKsidLxMudarowmejtXiR8mbxVu+fBhL5t0vtMfObmJqkoWXCdcXxB9h0+ROzx3R37BDjcgRS557HgOPe/dii3JHXM4ObdV8NiOXPjhnFMf4+/VU4GTgq9zC9aKHx5MskWzXcnzjrPn/qZ1wTFsAEmgh5kAth5DzCvwD93Q= 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.43 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-f43.google.com with SMTP id 4fb4d7f45d1cf-5c24ebaa427so8169825a12.1; Mon, 09 Sep 2024 06:08:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887289; x=1726492089; 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=/vjwlQJTs89Ef/RIHRnwfyBxPAxdJWhwqwNkCraTk7k=; b=F1Va/vvk5K1kFIlIrZjX3Mwl8lfnRyNC/qSsdBJpVdifGbPbdAm0QYozr4cSqq4nmA lmdw5/3F360P7O7ZvwsFB8ZODlrbLE8f+M3QKMpwdUH3BfxrDI12dtyMvrIjBxqdBNYv GpQ2GBXoeviiDoD3+qptZJIZiSomqSHNUvJgsqAA3IATYMVT95MqgmUSE4R4RVw5Izbn LgGNcfgbLkXwv2CJwpdGdUr+cwWkOt7JjYcFB7TXLwVgYE+YabxGHqjDO7OtvXQKc9KL RnuQzC6FnHYFZlWiO59o0yvQOLptFvOb0m6EzNgu7GxGtme60CPQxBJz5gwVjvPvSRui X83g== X-Forwarded-Encrypted: i=1; AJvYcCUuLbWyV09vWDAAmBmTQkfinixGgEwZam/BzKVELHObYyH3oh4zcUraZ2EavuhwvFE3y23Ltb3pWP4ytWw=@vger.kernel.org, AJvYcCW4tB7kWd/Sd9n2k0FSsZLLXs2Q8kp1hGs+AISojYZBgu60guBZZzAOTxwdOKyK+q/vBMVXTHBH@vger.kernel.org X-Gm-Message-State: AOJu0YypJfFNyo9k3wXM0dER/0hDn5JoyvTSdtHLKgCkZc8cpbr7SVOc 0+LrY3x2hmXfEh3mpo/N0NvG3whWdP8KDt3tq2LpPUQIxSH9AvCN X-Google-Smtp-Source: AGHT+IFCaadGLqYBIQE/R8KwNLQ77x3OmVtlvpH++8pGBvWnu3ylQjUVO+wzkwhoWzahiAGlGni1HQ== X-Received: by 2002:a17:907:c06:b0:a87:370:8dfc with SMTP id a640c23a62f3a-a8a8603e91fmr1225785466b.14.1725887288631; Mon, 09 Sep 2024 06:08:08 -0700 (PDT) Received: from localhost (fwdproxy-lla-007.fbsv.net. [2a03:2880:30ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d2583392csm341059266b.40.2024.09.09.06.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:07 -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 v2 02/10] net: netconsole: split send_ext_msg_udp() function Date: Mon, 9 Sep 2024 06:07:43 -0700 Message-ID: <20240909130756.2722126-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=99s 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_notif= ier =3D { .notifier_call =3D netconsole_netdev_event, }; =20 +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 =3D init_utsname()->release; + + scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); + msg_len +=3D release_len; + } else { + memcpy(buf, msg, msg_len); + } + + if (userdata) + msg_len +=3D 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_targe= t *nt, const char *msg, release_len =3D strlen(release) + 1; } =20 - if (msg_len + release_len + userdata_len <=3D MAX_PRINT_CHUNK) { - /* No fragmentation needed */ - if (nt->release) { - scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); - msg_len +=3D release_len; - } else { - memcpy(buf, msg, msg_len); - } - - if (userdata) - msg_len +=3D 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 <=3D MAX_PRINT_CHUNK) + return send_msg_no_fragmentation(nt, msg, userdata, msg_len, + release_len); =20 /* need to insert extra header fields, detect header and body */ header =3D msg; --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 07B7C1BA275; Mon, 9 Sep 2024 13:08:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887294; cv=none; b=FMFqIULTHYBu3SN1yYiyc0MpukCkyug99zGLobuhvwG1rK/punGTkjnAUsKXuK01YV5OCyigK2h0cye/WOC9RGnBY2QJSXtoxhpGiPipcor2KaKcSM8hiwB9SLKq65ZIC7ucbKkZCT74xrUFBVSJWJKFk4uB/x8WcgMwaNN+bWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887294; c=relaxed/simple; bh=b0aIxet0QXlwVUlrSckU71HVdA5OMCthBU4wm1Oj+xw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fp10LS/eB/ipQclc5e+3dImaGkFcozg1bdfaGXrgWTSuoXXvO05iuaAGrt2ouGUrSV5FegHdEKhh3cYsKN2g4Qa5kzCwIeJ9gO660XKSpS3oYvGvKnWwfC+vHx5R8AxtxNko7IaIfCP3fHrU3er3G9Wqij0/4g5cEo/yHbrOtsQ= 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.44 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-f44.google.com with SMTP id 2adb3069b0e04-53655b9bbcdso4025990e87.2; Mon, 09 Sep 2024 06:08:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887291; x=1726492091; 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=Z4ZSmg0Cl/jYk+bTI2nI4rfvoGAXNEjHmRneg63oapeG56pRR06e9n0sCdIz8y6yX9 u9dJsTfgpBsZ+OwxTYBTGOqqVbecePzLwgWyAwQmPfOOkQjwhd1X2YEF1+5DlNpw/k8V lMgGj0HfVxCxpl1wGn1DVh0FKxMC0dCfeEkYjxDY0/7t6+MQKn1bex8p+/4UVvh41H5i GAchheFKik54eEjXBdnza1FUCbuat0GuI6vUpzy+X15BJjzUd4Yd0G6bT0NknUNNT/RY dfParut6VaA28L8NEih6qec6lRI1uT5JPyzpf8pJyj5MQAxQOUdMi3if4NUgOXVZmTpa 1CBQ== X-Forwarded-Encrypted: i=1; AJvYcCV0owp2mnboJe6jj1Lmt0XtpuEqJ6/Z8vs2voX76kBEbgTVKi+4zfT4QiQaqHyu4GC8U61VIFJ4@vger.kernel.org, AJvYcCVyeV80BrByLTdZe4YG/gsTN2MZa/srD504RUTQup9Sh7/+rq6UZAtUBkiVTTgz9CjLMfHtL7fiPePia2w=@vger.kernel.org X-Gm-Message-State: AOJu0YwCkve/YsEahEKJYnfxcykTCUoqedHznVJbofYQYU46LLLJQGfB reCoRxHHrz8vL5SB+GDydvpYSxTNtUpNxe/7DQcMJcWMbTOFRa0+ X-Google-Smtp-Source: AGHT+IExl/fv4Y3nhEX82xi4IAL0eKbKKENkaDQZmm2yCCuqZHcYv6CWlRE0a36E4y2s55tVOl2VlQ== X-Received: by 2002:a05:6512:1386:b0:52e:fd84:cec0 with SMTP id 2adb3069b0e04-5365881028bmr5805104e87.52.1725887290637; Mon, 09 Sep 2024 06:08:10 -0700 (PDT) Received: from localhost (fwdproxy-lla-000.fbsv.net. [2a03:2880:30ff::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72815sm342825966b.140.2024.09.09.06.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:10 -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 v2 03/10] net: netconsole: separate fragmented message handling in send_ext_msg Date: Mon, 9 Sep 2024 06:07:44 -0700 Message-ID: <20240909130756.2722126-4-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 netcon= sole_target *nt, netpoll_send_udp(&nt->np, buf, msg_len); } =20 -/** - * 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 =3D 0, userdata_len =3D 0; const char *header, *body; - int offset =3D 0; int header_len, body_len; const char *release; - int release_len =3D 0; - int userdata_len =3D 0; - char *userdata =3D NULL; - -#ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata =3D nt->userdata_complete; - userdata_len =3D nt->userdata_length; -#endif =20 - if (nt->release) { - release =3D init_utsname()->release; - release_len =3D strlen(release) + 1; - } - - if (msg_len + release_len + userdata_len <=3D MAX_PRINT_CHUNK) - return send_msg_no_fragmentation(nt, msg, userdata, msg_len, - release_len); + if (userdata) + userdata_len =3D nt->userdata_length; =20 /* need to insert extra header fields, detect header and body */ header =3D msg; @@ -1134,11 +1113,18 @@ static void send_ext_msg_udp(struct netconsole_targ= et *nt, const char *msg, * Transfer multiple chunks with the following extra header. * "ncfrag=3D/" */ - if (nt->release) + if (release_len) { + release =3D 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 +=3D release_len; =20 + /* for now on, the header will be persisted, and the body + * will be replaced + */ while (offset < body_len + userdata_len) { int this_header =3D header_len; int this_offset =3D 0; @@ -1184,6 +1170,38 @@ static void send_ext_msg_udp(struct netconsole_targe= t *nt, const char *msg, } } =20 +/** + * 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 =3D NULL; + int userdata_len =3D 0; + int release_len =3D 0; + +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata =3D nt->userdata_complete; + userdata_len =3D nt->userdata_length; +#endif + + if (nt->release) + release_len =3D strlen(init_utsname()->release) + 1; + + if (msg_len + release_len + userdata_len <=3D 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) { --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 385251BA29C; Mon, 9 Sep 2024 13:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887298; cv=none; b=eqpkOp1p9Msm0ZduXC9QfVQCxaomBISEVZn5n2zVu2PdZOkSGEfaQ2MZFbxarWSNKLzYf1+NW3S6DCS396H0LUnPKi/j7Mqs4ferlRINIyrFtFkbKvJ6pfJHSKX+L+E5v3d2hiEEjTZR4O0ebxG/AKDwO1/nfczFPhbfhv2km40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887298; c=relaxed/simple; bh=/F8PsJuwplf303ZjtrzQo6u5uEVDxw1PCl7xxY2uGnE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PZ47FLBGXc2SVixfVoMaA/NOPSLgkirLjnn8WMs9RHbfguXpbmBJDnSpBmtn9GpQ+lZVuiwKVmgAHAK7s2tD61lABAiM7zsB2SmOCtX5fW7WeV/0HUAQdAeAnTO/8ATWV32ZzonJxO6rssIMu/zINUGjJPibJFkqT5gGleb3G6g= 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.51 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-f51.google.com with SMTP id a640c23a62f3a-a8d6ac24a3bso46349166b.1; Mon, 09 Sep 2024 06:08:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887294; x=1726492094; 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=GaIbZREnxE/xiP/kuQHnVNQd4fNh6D0OvTTm6CKCav4=; b=SRUozXUhBFLzHRJT6TjBWe0sIbslKrbZvO9LOZPhe7eSg4XBo1hwGtx4WF2qcTc/Oi W3HVPsXkdfQR03rt8pi982XaBmHamWV9G+yp79Aa0TE3JLeNzBbMhV23xYW1EdZNQf1N iHE/oSd+Q2qBgNZO3Es8Ibi8KPvnam9mfyNwfs7Jy/z3K4P8F2P88JxUwdO/cE5e0dl9 HWieEdthpYmtTW/u416V4foaejNzlpiOpsz1RVtmCavUtkLHUrrgO8mSDJBu5t/W9NX7 ZYdRLG2qgTsmS+PgeujOBX2AXBm9qTeRrn8FDYJBDHW3il2vwBE4I8+u+IWQXTgcyDgH 56Kg== X-Forwarded-Encrypted: i=1; AJvYcCUmvDK9T9x6012Te5rGrQIavE38vuXZftFxZLF5LTReZ+M4I0bNd3TbQXOAoSNv8R3q29ALXWIBK0IO5dE=@vger.kernel.org, AJvYcCXRkuHTps69djaTgZ9Is/0nc/PuCYGmYf6aNq/0qTxjho4Bxu7Os8fR6qXYRJxmG8p/ZW/kE0Y6@vger.kernel.org X-Gm-Message-State: AOJu0YzPV67/slAYmAPBjXcjZq2eeubr7QvtRxtnxj123veDc6i0xK5d 1lxeTF7YEkHEVK5Yujw4n1SA2Xx61mNQtaSY4xpRT7TseUQg3DnP8qDUpA== X-Google-Smtp-Source: AGHT+IFMpQk7JguY+YDYJGe0z7Qu8dHnTZUNhsuk7QoWvpWysK/sbcbtfHM8rlAy+iUaAuj1Qx+18w== X-Received: by 2002:a17:906:5807:b0:a8a:6bd8:b671 with SMTP id a640c23a62f3a-a8a6bd8b8abmr1353941366b.5.1725887293819; Mon, 09 Sep 2024 06:08:13 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d2583c1e9sm341152666b.23.2024.09.09.06.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:12 -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 v2 04/10] net: netconsole: rename body to msg_body Date: Mon, 9 Sep 2024 06:07:45 -0700 Message-ID: <20240909130756.2722126-5-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 48 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 8faea9422ea1..c312ad6d5cf8 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1092,22 +1092,22 @@ static void send_msg_fragmented(struct netconsole_t= arget *nt, { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset =3D 0, userdata_len =3D 0; - const char *header, *body; - int header_len, body_len; + const char *header, *msgbody; + int header_len, msgbody_len; const char *release; =20 if (userdata) userdata_len =3D nt->userdata_length; =20 - /* need to insert extra header fields, detect header and body */ + /* need to insert extra header fields, detect header and msgbody */ header =3D msg; - body =3D memchr(msg, ';', msg_len); - if (WARN_ON_ONCE(!body)) + msgbody =3D memchr(msg, ';', msg_len); + if (WARN_ON_ONCE(!msgbody)) return; =20 - header_len =3D body - header; - body_len =3D msg_len - header_len - 1; - body++; + header_len =3D msgbody - header; + msgbody_len =3D msg_len - header_len - 1; + msgbody++; =20 /* * Transfer multiple chunks with the following extra header. @@ -1122,10 +1122,10 @@ static void send_msg_fragmented(struct netconsole_t= arget *nt, memcpy(buf + release_len, header, header_len); header_len +=3D release_len; =20 - /* 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 =3D header_len; int this_offset =3D 0; int this_chunk =3D 0; @@ -1133,23 +1133,31 @@ static void send_msg_fragmented(struct netconsole_t= arget *nt, this_header +=3D scnprintf(buf + this_header, sizeof(buf) - this_header, ",ncfrag=3D%d/%d;", offset, - body_len + userdata_len); + msgbody_len + userdata_len); =20 - /* Not all body data has been written yet */ - if (offset < body_len) { - this_chunk =3D min(body_len - offset, + /* Not all msgbody data has been written yet */ + if (offset < msgbody_len) { + this_chunk =3D min(msgbody_len - offset, MAX_PRINT_CHUNK - this_header); if (WARN_ON_ONCE(this_chunk <=3D 0)) return; - memcpy(buf + this_header, body + offset, this_chunk); + memcpy(buf + this_header, msgbody + offset, this_chunk); this_offset +=3D this_chunk; } - /* Body is fully written and there is pending userdata to write, - * append userdata in this chunk + + if (offset + this_offset >=3D msgbody_len) + /* msgbody was finally written, either in the previous + * messages and/or in the current buf. Time to write + * the userdata. + */ + msgbody_written =3D true; + + /* Msg body is fully written and there is pending userdata to + * write, append userdata in this chunk */ - if (offset + this_offset >=3D body_len && - offset + this_offset < userdata_len + body_len) { - int sent_userdata =3D (offset + this_offset) - body_len; + if (offset + this_offset >=3D msgbody_len && + offset + this_offset < userdata_len + msgbody_len) { + int sent_userdata =3D (offset + this_offset) - msgbody_len; int preceding_bytes =3D this_chunk + this_header; =20 if (WARN_ON_ONCE(sent_userdata < 0)) --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 D954D1B86E6; Mon, 9 Sep 2024 13:08:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887299; cv=none; b=eZuzsWNEgx0WiFK2rHKdzlMr6+e1+HL4XZiDwvsfNJk+QgzUplMk+71pUNWTYIJ/ubfTykuhx/VmqAlKcppzh0MEUlWbK/ZSdc4qjn/EemRK5AX5gGXaz2y1glwZ+ZvkerBkVR7bk5Wnlj3R/eisHaUCJ/871SARAtfFA3EgqiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887299; c=relaxed/simple; bh=VV2zpiuKj7DKyxtXNIqhoTQLV28baNogHGEr1Aqy9DQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qVyx7+D3urcAg2nl7gwAvb39N5Arhg2GVUxyTde3P9+9bRUfnJN+olCVHOQTzxLqchVUazMmppKMLEoWx6wuIERy5dqdUleyJLcsnVsBaSvudmeaF7O3AmNYUuA5QJg6GuRdm70aL1Q6z+XPAPCPKZkV/YEDe9KXQudt3U8Tbn0= 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.43 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-f43.google.com with SMTP id 4fb4d7f45d1cf-5c25f01879fso5371903a12.1; Mon, 09 Sep 2024 06:08:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887296; x=1726492096; 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=fYym74QBEdDEHcZ5TJhaGw38Vw7Nq8JnshvqDISovk0=; b=XrvLL1RW5fyEj5U+EnbXAhedgzJHSMVk9hrakEtp//IFi6q0yDbRMV4Yx/tuJXF3cM EfNOPW8zm8dS0rTqR3ygyQfeOX5xtia1Xan15tN7wsU6KIWqBjxHXIReChJXyCyN3uJl gHgWciKmHxlikNvcdu3N954wK6VD34Y9wX77dPX9jj8HHQzVBwugQgqkt8fCU03YSTa4 VDEV9yz7/KSmmHtar4oHVKK/d++YvIgalFsjeg3/WZAtmTHRMCv0iYtLUCKVSXpm52cy deTC3cvmecAQXvgyqg1kFrxcUO0Rx5LrXFJDD+opH7xsSTzBldsxOctt8y9/pB3NY5i1 5SEA== X-Forwarded-Encrypted: i=1; AJvYcCVYgIMUcj2JncOwTEXQrs5KdaCYMKOQfrLl0YfBFARDhjgp68Gpl9QxUAPlUawPWTvbpRGLBHHQ@vger.kernel.org, AJvYcCWNIPf1n3xbgLjb/kPvmfpPnj7acDyearHMKxCwT7joXw+YJKJwOSSZ7whySC2T/HGebdDzA1kfD+AYrcE=@vger.kernel.org X-Gm-Message-State: AOJu0YxowoJ/3rQjTbYi9J3S+7guYKyRjaidrH2mQspTvjSI4PyrHGIf JXa/DyvxKOlD2WYKhRtCwY5pshzZkbLCjL4xP4+CGd5Tc3XP2oC4 X-Google-Smtp-Source: AGHT+IFDCAF9grHK/Qjnq7X6yZMGXs7FxOrYGIh/j4dbO3psd+oC9B/3WgbNkSBTr0aU2w2cV/j7xg== X-Received: by 2002:a05:6402:3718:b0:5c2:6fd3:4a36 with SMTP id 4fb4d7f45d1cf-5c3dc79c8b5mr6954379a12.16.1725887295971; Mon, 09 Sep 2024 06:08:15 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd46886sm2955479a12.34.2024.09.09.06.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:15 -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 v2 05/10] net: netconsole: introduce variable to track body length Date: Mon, 9 Sep 2024 06:07:46 -0700 Message-ID: <20240909130756.2722126-6-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 c312ad6d5cf8..e3350016db0d 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1090,10 +1090,10 @@ static void send_msg_fragmented(struct netconsole_t= arget *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 =3D 0, userdata_len =3D 0; const char *header, *msgbody; - int header_len, msgbody_len; const char *release; =20 if (userdata) @@ -1122,10 +1122,11 @@ static void send_msg_fragmented(struct netconsole_t= arget *nt, memcpy(buf + release_len, header, header_len); header_len +=3D release_len; =20 + body_len =3D 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 =3D header_len; int this_offset =3D 0; int this_chunk =3D 0; @@ -1133,7 +1134,7 @@ static void send_msg_fragmented(struct netconsole_tar= get *nt, this_header +=3D scnprintf(buf + this_header, sizeof(buf) - this_header, ",ncfrag=3D%d/%d;", offset, - msgbody_len + userdata_len); + body_len); =20 /* Not all msgbody data has been written yet */ if (offset < msgbody_len) { @@ -1156,7 +1157,7 @@ static void send_msg_fragmented(struct netconsole_tar= get *nt, * write, append userdata in this chunk */ if (offset + this_offset >=3D msgbody_len && - offset + this_offset < userdata_len + msgbody_len) { + offset + this_offset < body_len) { int sent_userdata =3D (offset + this_offset) - msgbody_len; int preceding_bytes =3D this_chunk + this_header; =20 --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 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 9F0BC1B86E4; Mon, 9 Sep 2024 13:08:19 +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=1725887301; cv=none; b=K4pWlMezreFGgQGvXO2WnbM8icqRe5G8xyMU3MpW60DBeZbGJOu6KzA857RL5Q6xAWD1NZ0cnOCZN+HQoOjW2bql0QQ6aQOIxVWETL7uOjzqoEiWU2vFD+kTvS3W4/tDiGhDWS2/4wDE3VLoTkQvJRNMgKdoVIv7X1g3Yq1dfOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887301; c=relaxed/simple; bh=wz4RNDumEdEfzGuNdo2cdE+72FVQyN7S964XuEih65M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r9hgXudsxuh4aSR2tcFlskBIImkUuJ8dT2K6INu6HzxfYVukVkx9sDiv+yaMRyt8RxAcwjVgklyJ5mxB6uLvkeP9xY+Rwzea7bXw0RGn/1H9qn1BF85wic6sNpwk+SCZd9EtaEf9bKSsjrTzQBbaWgCfWH064jz1CWm2Jgm2Aqw= 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-a8d404c7634so175325966b.3; Mon, 09 Sep 2024 06:08:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887298; x=1726492098; 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=f6K3mbQ5LyA763gr290EAxVIUfbF8tkfg7wJo8NwS6Y=; b=FluLleJJDDljlakXTHEZEWiWAPY2gve5I0tA1ghR48zvGlv4jz/u+EiVIEDZVXXdUP xKR14GC/CVFTmJdJxHkcBr54yC7uqFKZLRI+p1hJiVhNDuU9d55G5M8OsRG3gG9gy12h ++9bML9PQ5axO6iMElNcGRdhb5U0L4wSC6LuOOBlaICCzSlFym/VXo5e8ZKkJTNB3SxK 83Z143Ne/kyzRnQRcemXCa3u27z5D9brDeg4vvrptMXlwG0/y0W3Sz7upqvXajSw74sk 1eHUqQmbh1mMyB8AGFjvFuim/5p+wc2yafsxu+Jk6j3LujSHQht43qjnmg64YRBJ9xBG NwUw== X-Forwarded-Encrypted: i=1; AJvYcCUL9bGJq7aIXHvPyQF2u3V6r7w7VHcVGnQPl/uT24h5VeCk8uIOFZfeS1rI8n/iq6yPXBiUqp+u6QGQujQ=@vger.kernel.org, AJvYcCXyibRlLruke2A/lBkaBtYNYTzPqRSCLImbN+ypLAA9ouAqUWtcVS/u/JLly+WScgxTxDCg0YQ8@vger.kernel.org X-Gm-Message-State: AOJu0Yyzpu2rmm6J/je/3C+/JdL267jFm21EB8NzRDoVRaGOVxRhSXML rtbXXxBxqq4xWp6P/vDSPqEl3nZgvLBVopD0zoQE1/pP716uPDg2 X-Google-Smtp-Source: AGHT+IGcvu3+ye3I/1xYbHB1igh7Iv8h7ANc2ue2phfDnYCC8xdrsIkPIRBTANr3F41wl0BjrxprNg== X-Received: by 2002:a17:907:60cb:b0:a8d:3998:2de with SMTP id a640c23a62f3a-a8d39982a9emr449204366b.12.1725887297917; Mon, 09 Sep 2024 06:08:17 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d2598b85bsm339183666b.77.2024.09.09.06.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:17 -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 v2 06/10] net: netconsole: track explicitly if msgbody was written to buffer Date: Mon, 9 Sep 2024 06:07:47 -0700 Message-ID: <20240909130756.2722126-7-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index e3350016db0d..1366b948bcbf 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1128,6 +1128,7 @@ static void send_msg_fragmented(struct netconsole_tar= get *nt, */ while (offset < body_len) { int this_header =3D header_len; + bool msgbody_written =3D false; int this_offset =3D 0; int this_chunk =3D 0; =20 @@ -1156,9 +1157,12 @@ static void send_msg_fragmented(struct netconsole_ta= rget *nt, /* Msg body is fully written and there is pending userdata to * write, append userdata in this chunk */ - if (offset + this_offset >=3D 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 =3D (offset + this_offset) - msgbody_len; + /* offset of bytes used in current buf */ int preceding_bytes =3D this_chunk + this_header; =20 if (WARN_ON_ONCE(sent_userdata < 0)) --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 CA9991BAEE6; Mon, 9 Sep 2024 13:08:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887303; cv=none; b=SPciF8uCziXthzQkgDAvizA9/xya+ZF/3z7aCDeM9jcXxJY8oQsdFgZKcoDzs+4xiV4VgNL66AzY0sjSzl3AGOppoON9CL0fsAzuG1x9oycD/Dwc1OyIXqNcC3bhCnaLahjAitNuPowHboIrUuPM7Y3n+hz8YOSPUgVylo/oR24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887303; c=relaxed/simple; bh=mr7ozxLYNIKSDK28c1JS/rg+dGy/5mHfdcu4ZO66wkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z69q+bqlI4Wro7HizOzF2vAfZZY0YtalYapfX5w/c2Dha+a4arLKh+1texggCJt9Y0EFvUcJ+TiXINaLiuqg4bOUy3EAilmEa/AiJPtcDCL3BZuI9OtxyEebxRF7ryQ+E53jInkw9kkqNb+tuAaMc5lmLxRDn5v7cB7k4kvJRUA= 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.54 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-f54.google.com with SMTP id 4fb4d7f45d1cf-5c245c62362so5754439a12.0; Mon, 09 Sep 2024 06:08:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887300; x=1726492100; 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=aMlmVi1HV0bOjoIC9XC2+oYfNTvQo9Vk3W7upUYsQ7iPyFZpOw79X+GYpA/NiNm2I9 ki2q1XOMCkBniDgn0emeY1qHN/eC4+YOr06nKh30Gc0JTH8UEfZ2oYgS/vIL1l2d7nTN 9qmgx0VUvrSpUUBjQpvpAlPHf2t7XPNurcWdD6WeDkRje0bUiZ7GHwYjk9RrKizaV+75 KvUCfC23myHpzPfMwGHIgFqZ0t9FEogdia4W83LPlYfEehOZ8vCOUseQYPGh6xTzsM89 hed3sfV1U0yElC0XfIsOezWio1J4cLeQMPu3iJHSvg1miKCecmZzCEuz/XrKf+ce2okl wv7w== X-Forwarded-Encrypted: i=1; AJvYcCU+aJc6/SHKMPsNSZyJWn45wyGZF3AT8Ehv9der85eeNoP3PQx4r165UUNF2Yy0/u+2Ba4AaD3R82FyiPs=@vger.kernel.org, AJvYcCU6EvxlipODvy/tkOqwplO8vameV+8eI7rm1R76Hj0ZTc6pW/PvBY2CYo6Va9KLcKpP1HR7LnD7@vger.kernel.org X-Gm-Message-State: AOJu0YwUHLgqKY2/adSI5UTaoYvIWE9i+8sBauvgxH0EsOGh0h4ZhLCl 17ex5xYU4XxEP0jJsUZVGOYnS5rFfDHtXOsNEA+RH/RbvuV+VCwE X-Google-Smtp-Source: AGHT+IFFQpCHV3UeZu1w4ZrH470XJDbitPgmrxubQcj3nXOXVMpTzyGjFdGSEBxuxm+sXR9zm1TaAA== X-Received: by 2002:a05:6402:518b:b0:5bf:f1:908 with SMTP id 4fb4d7f45d1cf-5c3dc7bd6e3mr8490789a12.24.1725887299888; Mon, 09 Sep 2024 06:08:19 -0700 (PDT) Received: from localhost (fwdproxy-lla-112.fbsv.net. [2a03:2880:30ff:70::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd467f5sm2992854a12.36.2024.09.09.06.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:19 -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 v2 07/10] net: netconsole: extract release appending into separate function Date: Mon, 9 Sep 2024 06:07:48 -0700 Message-ID: <20240909130756.2722126-8-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 netcons= ole_target *nt, netpoll_send_udp(&nt->np, buf, msg_len); } =20 +static void append_release(char *buf) +{ + const char *release; + + release =3D 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_tar= get *nt, static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset =3D 0, userdata_len =3D 0; const char *header, *msgbody; - const char *release; =20 if (userdata) userdata_len =3D nt->userdata_length; @@ -1113,10 +1120,8 @@ static void send_msg_fragmented(struct netconsole_ta= rget *nt, * Transfer multiple chunks with the following extra header. * "ncfrag=3D/" */ - if (release_len) { - release =3D init_utsname()->release; - scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); - } + if (release_len) + append_release(buf); =20 /* Copy the header into the buffer */ memcpy(buf + release_len, header, header_len); --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.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 7CBA21BB696; Mon, 9 Sep 2024 13:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887306; cv=none; b=N/hlFGkjaBerPQGrXjaDZcxSD8lHvavrtqU5AhRADTexk34PS9unc3QaqqELO3TX98q5EzabwQL6ZR/bDzP4FKNTWbsqMi7NBXLOKHnNm57gwjJKts6UwrQPK7xkWX0XiAf7JCwMkqFCufOMtt4IlHdEBz5/3SL8pi1PHrSWUWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887306; c=relaxed/simple; bh=EtjSQnPNIJ95ZklMek21/jf8gOIAaIEvedCephVcUxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LjFUzdd5VxredMq2WV37LStAM1CVvUjsM2/RfCy/+JsGoKkUsy2PJYYZYdth4MRmIyNbeZLWxPOeGywHTsdhc/hqa7INGaEVvL8tSovS9nv1kk9RYCxWofdhp5Ifgy/yT/uvU5oZAK/7B6/cFg7g7UluotmFC7X/rRKuOkk3uk4= 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.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-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5c0aa376e15so2077073a12.1; Mon, 09 Sep 2024 06:08:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887303; x=1726492103; 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=XFn6nX3drdenAEXYyF+UJuZhfXzH0bJrdOrn5tiRtrw=; b=rTl9i1kpjAgitHVCrVz6EFogF6HMYiOSfqIoIKtgvFdnxf1iTpCXBn0wr5k0LUxco6 wperB+poYzwlV3G54zxar2sQj1iBTi4BGFktQ+9WINQRYTeAj9DuwwqFzqg9IpXY2tNL mEXpDy0FreGnrqW7OoK91awflkJXc53GH84amvr9Q8NlPhVbEpGXRTCNuLftd6Y3NHvR 28nAK76HAFGznIYkhSPCBfOrkskAabSl83m3rdZCMpiYIdAV+KmHaPKVysYvvn4QVJx2 zysf9KDT7jcRDDbnSOoh/8ueHI5c16pDbMXXfiahnW0CQ8kcuwavxOYzbCHkARf2PvYt P/9w== X-Forwarded-Encrypted: i=1; AJvYcCXAX1CjdMo3asLJgrOa2E4Z1fOJHCqwKo9nSS/r5HfhWHFlrGiGQ27HcUXbgNHWrihXOlN4MOTy9YvQbH0=@vger.kernel.org, AJvYcCXwq401wOO7rQGejax8egmKh2+br1ZbIVAmhl25iOAet+aif5GN6zldjhdZqNRDA5piV7cS426C@vger.kernel.org X-Gm-Message-State: AOJu0Yy+kI0R2u7OwBzGXVx8WiuLapdoLS6JhG5qNw0NaQl/yXjNuIJg br9qwdYBMgjffY9/Qr4gUw91IiZbHQ3VqHmE1QiykkKNzKGzpvhA X-Google-Smtp-Source: AGHT+IF1WXJ+AkVqtoYOjqn6bdo7t8I7Lssml/gQzNonf6Q+0N2fPfTpXzuazFGy3GPJH4aAHr1FrA== X-Received: by 2002:a05:6402:5386:b0:5c2:6bb8:1859 with SMTP id 4fb4d7f45d1cf-5c3dc79768emr9939844a12.19.1725887302653; Mon, 09 Sep 2024 06:08:22 -0700 (PDT) Received: from localhost (fwdproxy-lla-009.fbsv.net. [2a03:2880:30ff:9::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd5214fsm3001212a12.54.2024.09.09.06.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:21 -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 v2 08/10] net: netconsole: do not pass userdata up to the tail Date: Mon, 9 Sep 2024 06:07:49 -0700 Message-ID: <20240909130756.2722126-9-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- drivers/net/netconsole.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 2cdd2d6a2a18..4044a6307d44 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1060,13 +1060,17 @@ static struct notifier_block netconsole_netdev_noti= fier =3D { =20 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 =3D NULL; const char *release; =20 +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata =3D nt->userdata_complete; +#endif + if (release_len) { release =3D init_utsname()->release; =20 @@ -1094,7 +1098,6 @@ static void append_release(char *buf) =20 static void send_msg_fragmented(struct netconsole_target *nt, const char *msg, - const char *userdata, int msg_len, int release_len) { @@ -1103,8 +1106,10 @@ static void send_msg_fragmented(struct netconsole_ta= rget *nt, int offset =3D 0, userdata_len =3D 0; const char *header, *msgbody; =20 - if (userdata) - userdata_len =3D nt->userdata_length; +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata =3D nt->userdata_complete; + userdata_len =3D nt->userdata_length; +#endif =20 /* need to insert extra header fields, detect header and msgbody */ header =3D msg; @@ -1201,12 +1206,10 @@ static void send_msg_fragmented(struct netconsole_t= arget *nt, static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, int msg_len) { - char *userdata =3D NULL; int userdata_len =3D 0; int release_len =3D 0; =20 #ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata =3D nt->userdata_complete; userdata_len =3D nt->userdata_length; #endif =20 @@ -1214,10 +1217,9 @@ static void send_ext_msg_udp(struct netconsole_targe= t *nt, const char *msg, release_len =3D strlen(init_utsname()->release) + 1; =20 if (msg_len + release_len + userdata_len <=3D 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); =20 - return send_msg_fragmented(nt, msg, userdata, msg_len, release_len); + return send_msg_fragmented(nt, msg, msg_len, release_len); } =20 static void write_ext_msg(struct console *con, const char *msg, --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 655161BB6A7; Mon, 9 Sep 2024 13:08:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887308; cv=none; b=buQyj3vJadz7RVMvDKsp+C543Z+nqBNgfU+RNIitIn4MgzCHaOD4tAdaxXgCMZjbfxkHzMLXL4soBBZMk9Yk9u+8cKLm/N8+lE+My3U6hjlquYr1ZOt1FhcdD2S+Y/R12XhF264xRcGALWzeASDiWehFhDhLbuob+L3L1SjkyMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887308; c=relaxed/simple; bh=bay1BmvMTEjXyTKOfu/BteSKBHIIgfFaVrxSYvytk9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sdmXI7SaWTnnIYSo+90OcDNHivNIrReGVln3481RpQbroWBzK2p4s6y8ot3lPDVzxp8IEWy58zbx26yORK/EG2ND1FcAisUlDU6oOcUJC3gfZ/5l1lXxcGVLlphWNdaSf6cgSdWABm4k+VAFTr+C3rl8DNWh0B51NvGITUeIO3E= 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.54 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-f54.google.com with SMTP id a640c23a62f3a-a8d3cde1103so256764366b.2; Mon, 09 Sep 2024 06:08:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887305; x=1726492105; 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=PUULhhCelhsLy1sGMiRmrDd8EZHd+oqEaR7JydE1Frw=; b=LTijXX4ns2uE2cIJ81E1gh0SeD+F6572l18hpX+TrI+0fpG6a31kw3FfriJNZIiK+n eVIdSAhuUe7uTksUR8gYPTgNHSauwLshlXHTflT4mW3FCckzuYysyF0BDWmqC9HvUzus sk8eH5jb1wMbeUO7gLGtEEuUmcqr0PIqEHLV42b8uVi0cdgXci65A+ruB/NreIM1t3q2 Lke2RZfHriV/tmvHwCyf+lvIVeEe81R+R5OlgFu1cP9ADTw0VFLd/43in/mIcvSdjLjo U5fs6bsHbDhlGkpCFyOdJz0elBsTKVoOHaTzVmdn2oHJjAVyt8fbFuHRHKl8PdSPpy+5 i7JA== X-Forwarded-Encrypted: i=1; AJvYcCWl5pyQ0NmEzRbXsxIQTot/CDUqOUR4wUkXAXQkd+0IpXtnxI2VUm9Bahr5d5QN7v3injVx5JUf@vger.kernel.org, AJvYcCXqBCOkYLx5ZzcYSTHHUOAnzM4UWgjlEbWbMTGeIIuCfzp/HPZraQc8sVTGe1kU7uQUCoiKGN5t9bD9T5Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+Dv58RgGS7/5xwjzaes9zQJp7q01qJNyYDn0BeDOKwOJ3e+SN 4ItSWkG2hZZrB3DOFvi2dv1psw31Ds8krRYSuS4xgKkR0VhFcIOqym3GdQ== X-Google-Smtp-Source: AGHT+IEARhdcDI+kAW4TUH7I4Sgu7gaxy6DsWpASYcbuNlMuF7Pk3UOg2IPJKstpgWM8PevyFQENHQ== X-Received: by 2002:a17:907:94d0:b0:a8a:8cdb:838c with SMTP id a640c23a62f3a-a8d1c72cd08mr887815066b.53.1725887304670; Mon, 09 Sep 2024 06:08:24 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d40cebsm337925866b.200.2024.09.09.06.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:24 -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 v2 09/10] net: netconsole: split send_msg_fragmented Date: Mon, 9 Sep 2024 06:07:50 -0700 Message-ID: <20240909130756.2722126-10-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 4044a6307d44..6a778a8690c3 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); } =20 -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) { - int header_len, msgbody_len, body_len; - static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ - int offset =3D 0, userdata_len =3D 0; - const char *header, *msgbody; + int body_len, offset =3D 0; + const char *userdata =3D NULL; + int userdata_len =3D 0; =20 #ifdef CONFIG_NETCONSOLE_DYNAMIC userdata =3D nt->userdata_complete; userdata_len =3D nt->userdata_length; #endif =20 - /* need to insert extra header fields, detect header and msgbody */ - header =3D msg; - msgbody =3D memchr(msg, ';', msg_len); - if (WARN_ON_ONCE(!msgbody)) - return; - - header_len =3D msgbody - header; - msgbody_len =3D msg_len - header_len - 1; - msgbody++; - - /* - * Transfer multiple chunks with the following extra header. - * "ncfrag=3D/" + /* boy_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 +=3D release_len; - body_len =3D 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 =3D header_len; @@ -1143,7 +1128,7 @@ static void send_msg_fragmented(struct netconsole_tar= get *nt, int this_chunk =3D 0; =20 this_header +=3D scnprintf(buf + this_header, - sizeof(buf) - this_header, + MAX_PRINT_CHUNK - this_header, ",ncfrag=3D%d/%d;", offset, body_len); =20 @@ -1193,6 +1178,41 @@ static void send_msg_fragmented(struct netconsole_ta= rget *nt, } } =20 +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 =3D memchr(msg, ';', msg_len); + if (WARN_ON_ONCE(!msgbody)) + return; + + header_len =3D msgbody - msg; + msgbody_len =3D msg_len - header_len - 1; + msgbody++; + + /* + * Transfer multiple chunks with the following extra header. + * "ncfrag=3D/" + */ + if (release_len) + append_release(buf); + + /* Copy the header into the buffer */ + memcpy(buf + release_len, msg, header_len); + header_len +=3D 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 --=20 2.43.5 From nobody Sat Nov 30 12:36:03 2024 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 70A5E1BBBD0; Mon, 9 Sep 2024 13:08:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887310; cv=none; b=qTnGkD2xuAyKZynJalFY75a5ATPC82tRuM/SYCoC/ULYYj8MnJa6TQGyTQAAuSSm1+Dvuum7OcYY9Zb0y9O0oG8PFzKKTwqnFPQwb0OIdSY6Af0jD7FJ58cknwmPD9r/6zT1qrgkrMsfD4PFTZxIJrGkexo6fwEv9rCoLSWwmv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725887310; c=relaxed/simple; bh=1G+O70kQlgUjlXyCifi2cYhG6zmRThen8fxju0O3iPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IhkdjD58dKSal+p0JV+DPRtr+X5Xdz20VIuv/hWZm2nXGouiwGLZJyZvcNOf1LM24OJ9YAApFHgKoAaCr9rgo3xMUt573/QM3lWM/WRUlUnoyadVpGG7LyV3wYIvaT/sS48psvgr2nOPUQe6U55xDb+5J9ju0ivHBP843KNEEG8= 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.53 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-f53.google.com with SMTP id 4fb4d7f45d1cf-5c3d209da98so404906a12.1; Mon, 09 Sep 2024 06:08:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887307; x=1726492107; 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=kAJypcMSdNG3RzgBifEDQ+E+OlrCHokwMoz1N9CXNp0=; b=qVHBvWqMucKH0DHQ2B9LBcN7Iqh1LuHK/K/6QIFLTvNNJuDsz8iYIIhjt/47q+NV77 gvTocqanwiyj2fHbyJHceN5Hx25noEduzfKVM5KKAuui9DNDnO2zFpjh7eOt5gpAbYD3 SF04SvOyXVdWF7EkljV1AxGgIdIs18a2zMS1d7qUDikgyAXgn0i/GbPIJV/icmUefqko iyLuPHngmAqSTQN+ok/alCfldJndGBeg0R8C/0XrWkMICgj1QWj07eps2YR0jNfnoO/J OufAaPa+GB9CUYaA8fiWAcpzKrjz9nP04nB3/a570DpF3rtotDKqN0llfHita8MFVIio RgPg== X-Forwarded-Encrypted: i=1; AJvYcCWfHqAhjEIEy24CuSEDfmJOSc+F4B5XkK+xwzqjeXHJNJ0UhajbD2tqyns+uA6l/Z7zMg1EYiJ8@vger.kernel.org, AJvYcCXdjmEis2bR6od/igsRLR+HIVx6f/PFBpswCkfVmSzRHaKQkHof9OtR2J3p+t+444QRyFiYfwV5tLG5i9w=@vger.kernel.org X-Gm-Message-State: AOJu0YyMKihNG0IbaGlzMCc0ywSgebVbmKuiovs02W3Xf+Itx0ANU5jM 0TPksUHGxDIPXb7w90p+iljYefvQ5U+bAVBOQSxi2xIPb5jTcyLF2fyMUA== X-Google-Smtp-Source: AGHT+IFDjqJL8rCosrnIxltP0D1c+uxNMUZLBADnfw22+kPu9o41pUDMhEHzF8fTQGGYQ/zn//Z7XA== X-Received: by 2002:a05:6402:4316:b0:5c2:1014:295a with SMTP id 4fb4d7f45d1cf-5c3c1f742d6mr20151664a12.2.1725887306580; Mon, 09 Sep 2024 06:08:26 -0700 (PDT) Received: from localhost (fwdproxy-lla-000.fbsv.net. [2a03:2880:30ff::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd5245dsm3038743a12.52.2024.09.09.06.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 06:08:26 -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 v2 10/10] net: netconsole: fix wrong warning Date: Mon, 9 Sep 2024 06:07:51 -0700 Message-ID: <20240909130756.2722126-11-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909130756.2722126-1-leitao@debian.org> References: <20240909130756.2722126-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_e= xt_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 netcon= sole messages") --- 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 6a778a8690c3..7d2e021f04f4 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1165,8 +1165,14 @@ static void send_fragmented_body(struct netconsole_t= arget *nt, char *buf, =20 this_chunk =3D min(userdata_len - sent_userdata, MAX_PRINT_CHUNK - preceding_bytes); - if (WARN_ON_ONCE(this_chunk <=3D 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); --=20 2.43.5