From nobody Thu Nov 28 15:42:52 2024 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 04E2418FDAF; Mon, 30 Sep 2024 13:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701943; cv=none; b=lNrtKM0X6IXOuaTqnM53gBfctDFTBs0u+68DxPNjFrxbQmBH1koRr7Yks2OLNHz598TY6oTAefvRWSZWw1O94AyMiiAIeiQM/CnQ+SAXYnOnImGNbPqpZo2Cp0qvA3C98PX3WKYBWfpgM+vSavhFdzl2FTPUrkJQE8m1LXA1D54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701943; c=relaxed/simple; bh=pRaK3Ku3IkQXoZTZoJ3KsKO2/UXaI4WyWbGGP/VRtPU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AKrF3tMEX/9ObOFrjSRPyolSkemROxIwRrySYvBzRKjhva8Ur+2Pnu3AFSgFj0KEIQt7H0sLiTTs+feFcOtedI2ZcJyRE84wmKWPuVSyImAXz0KTuMxHQffx5nsNcbcMOGhiowc3b97fhpHOyuF70YMu+MY16MZ1LNowJHYp+lM= 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.177 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-f177.google.com with SMTP id 38308e7fff4ca-2fabb837ddbso36432321fa.1; Mon, 30 Sep 2024 06:12:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701940; x=1728306740; 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=v6p9QFaswCe0JMdPm96r/jyLyOPbc0INa/yzf2f7bvjLzFQ5O/pNuA+/jp716S5CZ0 JoEQuih3ptPhf5mrj5x52KAdY+2UPep5IXzo/9G4X09AfTPnvINwtVzeJuPZCaKC0p2M VaZxWGYkWUZEKTnpXKaTVQzE5ZI0JgbENbFB8EDM1FgOZt6L66byjCeYj1N904/PEUDT 5X6kPFKDI4DwpG6O6EY8zH/u4HuNNp6tPYbEn+98MDeOtqdbqkTEqJEoGJBk/s6UOXlW VCbUgA7UxCYbtBXqeRKuir+mVTbN+YtyH5XUxMD0K4JgEszl+WyAKrvhj8UVWNeaDcV1 cg5g== X-Forwarded-Encrypted: i=1; AJvYcCVCDI99QskOw3/zebEYE3/dkxeRMcGDki5SiaCkIARBmQ7SS3N71Gdhx0g5zh3sCzzHNQaO1RnsZMfL70E=@vger.kernel.org, AJvYcCXJ+/e/jFVCcLk83hV6I7x02aeuYfHnSH8o5IIuSq2O13Qt5etd6qARnSKSZoVE1duiYabvFu4D@vger.kernel.org X-Gm-Message-State: AOJu0YzFf0iE+nvWmei6Z0ALrHJcaRopiFUSnCTIzRpb6SrErN1jneb7 yKpozAstuotSVIM20ROQfZkRzge2RhvJjpfA3xCUMhYGYKGkeZat X-Google-Smtp-Source: AGHT+IH+WAUaEf1YWJiluBVMe/TvS0Q+jjf7SnZ/LLAzf7IsYPn6xJuKxD+rfxCzPYl3qJP/ViaJ3Q== X-Received: by 2002:a05:6512:3d04:b0:538:96ce:f2ed with SMTP id 2adb3069b0e04-5389fc343c8mr7812782e87.10.1727701939989; Mon, 30 Sep 2024 06:12:19 -0700 (PDT) Received: from localhost (fwdproxy-lla-113.fbsv.net. [2a03:2880:30ff:71::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c2998cc0sm525840466b.191.2024.09.30.06.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12: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, max@kutsevol.com Subject: [PATCH net-next v4 01/10] net: netconsole: remove msg_ready variable Date: Mon, 30 Sep 2024 06:12:00 -0700 Message-ID: <20240930131214.3771313-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 Thu Nov 28 15:42:52 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 BD3F819049B; Mon, 30 Sep 2024 13:12:23 +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=1727701945; cv=none; b=laL2aqiwUZ5zJps+49/Css+4rLi65G41lD1fxHq2dAVjliKb6tz+tNMAndzEFU4H6K2Q0SDB0cm2JM2ICS5fYsvbERj2hSS3ob8wVZNRb4GkKx8V5HZFfbXsxpH9N+I48czSu2Zj9YdoDqk4WmXcyVujzMquxdiOzImuFzKlITU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701945; c=relaxed/simple; bh=oJIDy0qtaGw6j830beA+G8p0IPumns4yvWEkwTqum/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=brt7oxET1m/Gunxw7AqDIuSx+FDQuQhxTjE04W2s3zXPemkfaRpn5aqc3P4jh+JamJmlxnaddgJefCvcMwHLDl4W+/w+O4M+Anzn49SbpVDpreftz2x4F6aOLFOftdpnUf/9Sze/nGSGxcsWcF0dL4dspR4B+LnVQFaKtFBtobc= 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-5c87ab540b3so6469535a12.1; Mon, 30 Sep 2024 06:12:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701942; x=1728306742; 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=EExCKw1SIZg5EfZ+rKDRl5QFJTp5uI+pxJLMEjIus8AslFdyqYsRT5LmIMLNB7DXsp +BgiGNOnlTnMPmp+JR8QzUpPw1ccgAjxINsLTlugqCdgh8xGeB0c73UTyrAsqTEbtTZ3 11TFeigzzdhIA4kVB7hWdD4MM0ZtUbLI0Bc4k4P7xnKQsDpZymMqnKCZ8AmkT0Smi1u9 DdTeOINjkEHB+txXwYu1A+RAI204i06brqp2Psm1TniPnnuqzqlrwRRlZ7wsAiISEaKf Ftz0b9Gw3AjSlypsCiBjuoi7VH9ZXiJz/mBf5QeirLwJJ1KksCOKpi6Aci3TxqYBuAjL 27eA== X-Forwarded-Encrypted: i=1; AJvYcCV3uNdFQyoiR7uXGfhuflSjXHfl8RGpivXmCce7r097BzGR5tnJiWt9PIjn4ozQft9j12yiDWyg4axkuF0=@vger.kernel.org, AJvYcCX85NVHKov/RZVF+pR/OeDnOtpecusXZTbx85UzThhMCjKk7RJCnyuDXl9Nj827DaSDhXHLaxhD@vger.kernel.org X-Gm-Message-State: AOJu0YwxsA1My2tnXakkdmOVPcDyqhq3g/PcY7XlCS/4je+DLyNtCdBC NZ7HY/PejKAZz9/5h/wjmhFZdvChudS0LSyzc0WbxWiFYkjMM3Q/ X-Google-Smtp-Source: AGHT+IHyBpmUVzZ0O2BMdKrjyrPUVceR2YtVu1A/TtxUg+WNR62bbWI8Ib0xVC2GwGkjCVg1rN8wZg== X-Received: by 2002:a17:907:31c4:b0:a8d:4cec:fcec with SMTP id a640c23a62f3a-a93b165dbafmr1719795266b.26.1727701941952; Mon, 30 Sep 2024 06:12:21 -0700 (PDT) Received: from localhost (fwdproxy-lla-000.fbsv.net. [2a03:2880:30ff::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c2948231sm531563166b.99.2024.09.30.06.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12: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, max@kutsevol.com Subject: [PATCH net-next v4 02/10] net: netconsole: split send_ext_msg_udp() function Date: Mon, 30 Sep 2024 06:12:01 -0700 Message-ID: <20240930131214.3771313-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 Thu Nov 28 15:42:52 2024 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 05991191F60; Mon, 30 Sep 2024 13:12:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701947; cv=none; b=iNed3SRuIlHVkl56Ciddg41tQ0E+QGdJNkhaofWHMrjgGSoL3npo5ZHsuGCQrAVhIabmG9zBl5I7kATCit4MdsN9yu3FN9ketgwrxO9o5SUWhJLLNOJoDkMjRqnqLut56Q2XEkYsH2j/W7I90zZiZ/FGP4GryaBgnRJ/KkiGlyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701947; c=relaxed/simple; bh=G06VWIjgSkb5T+Rhxs4tVbY5voMH09vj86RMygQPa1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LJTz4AJqpxjfWR8MLhYjGoeNaKELrJBVjc3nmy01bv6mYuOm5JBBzc/p+3ZQuuX/c9b4TrpBxep/+oqwT9FbEUXa+dSNSAMds6PJl0jhcHnNUTKSlmMxlJz1wuA0Gaxys4509lyfX/UKnvCavEaJdXRPQ7s98ebVYAfQayUlJrU= 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.46 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-f46.google.com with SMTP id a640c23a62f3a-a8d6d0fe021so763439966b.1; Mon, 30 Sep 2024 06:12:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701944; x=1728306744; 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=YBhPBaj2saKKoTM2iemIROzb/EIYC5E3NS9/4E4lyRg=; b=v+gDye/iSU+aEEryzweOkujM1kxCNLvGXZ/L+N7JzioQAqJG2Pwk5Bo7TcpmFaC98X TBzWfmA67hzS1L7i/4EL+2Bk04FIWJ9Q7loa6ndQ5imSILdoC/54rv3Xwq6kTyeTm1w9 zGiXRgdriF7vKKsP7SKJw+7OoQj9TL+cCbACFB8AXwdc2zLbll1PnMl5OYDjOEuK9x32 bie6o9qgxMkXhU+wiNwvFltPaHl5phE0OsfZ7Gra7QwFKfET3wcCZoE6qHOJZkKKD27I ltdPrZ0w6K0wO+p37cKUBerUu7QQ3/AuwVmox847wF2Chy7tmL7QTCopOu/IbtZV6MON o+ew== X-Forwarded-Encrypted: i=1; AJvYcCWqiUSY0UP+edsRi+lpH2BFTQ+uU0P8sOI0izE2jJJV0dV/Gpdxkjs7jFOYqnkPUwrZyi5sSTPufSrbGXw=@vger.kernel.org, AJvYcCXenjAz+Y9hkgJBkdcp7OWTyGWNoWzLTAjHRfFudnbZn4iIChQD9pEFJWSvUmUh33Qp2uvs1JcZ@vger.kernel.org X-Gm-Message-State: AOJu0YwvfBIhiVzL87PpWJ8riSQgqyi+y7jLpSCNs3RVycoqQSyIDsQ6 R8YRSFrDKWYdqJX4/ac8gze51EKIU/BA81xNSBt4KcpwYtnFc3wD X-Google-Smtp-Source: AGHT+IEeDeqbch11hW5mAXQhW+Ia9+/OiDSMyKiD2uUZdy95sri7bA0yletOYapk5xttQyXPFQD+JA== X-Received: by 2002:a17:907:3d87:b0:a8d:302e:e1fe with SMTP id a640c23a62f3a-a93c4af052amr1343124266b.63.1727701944152; Mon, 30 Sep 2024 06:12: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-a93c2948034sm525826866b.125.2024.09.30.06.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12:23 -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, max@kutsevol.com Subject: [PATCH net-next v4 03/10] net: netconsole: separate fragmented message handling in send_ext_msg Date: Mon, 30 Sep 2024 06:12:02 -0700 Message-ID: <20240930131214.3771313-4-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 | 76 +++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index d31ac47b496a..6cd0a9f25db3 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1084,42 +1084,23 @@ 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; =20 #ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata =3D nt->userdata_complete; - userdata_len =3D nt->userdata_length; + if (userdata) + 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); - /* need to insert extra header fields, detect header and body */ header =3D msg; body =3D memchr(msg, ';', msg_len); @@ -1134,11 +1115,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 +1172,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 Thu Nov 28 15:42:52 2024 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 4B05C191F89; Mon, 30 Sep 2024 13:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701950; cv=none; b=N93DmVqNPPJ8EIbdQm1TfJXXCjlmM4AITHTx8I6D81gAxmP6PIi+rnWlIktvrpexTGfisoRY5PyhAt06YMRWMhLZ5nl6c5MpIPaI5YlqKdWb2UxfOpsY15spY/NQS8iRrB6+5pErrr05JQ5njVEfES5xn+mOLvnHxZZm6vURhQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701950; c=relaxed/simple; bh=SRuTFsQm1/t/gwh3wg+P5pj2mOTPr/yZIbz8OLYwnQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mea4BCabRoPvkzcQrSPqVJ+OEC7VZoJ1vaHtXx/76xAM/kD+3Mhna+A1UVaCS07FA4GU1Ghj/lU6CPA7XjoxdI0r6fWi9b+rH3TrSjoxy7mzkv3xXVLWScBocvXpduznwsLk59CDB9KApX0RJOZuax114Hv9gcuECE9GOtdVT3A= 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.181 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-f181.google.com with SMTP id 38308e7fff4ca-2fad100dd9fso10666681fa.3; Mon, 30 Sep 2024 06:12:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701946; x=1728306746; 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=feXGILhytIeS4QpNPlfPx+rOZRUaL2lrSGKXoIjtvVU=; b=A4YPqEbkp1xNaZSV6X2GvOjyaC5Qrn2HSe73zEDFB/qYfrSor+R/7vTI7NR/yRIVV7 7wH/xkuSN7tFhHq17V+MSxjXeln9R+F65kVq/NyS3ZEZt376EUc/tVhYW0bPKa73NGWh f0fEqc4M1W7p/+mzpMjrEIGaDnJVf+F5+nbEe/Q1+CfnGGKgEv9cHSHTC6kN6Eeanasj +ti0eSPNaCLES9lzW6+uZltdMn/v8RW5Dd7fKbedm86OmGBAgJUEUiikrOTvwImafivi RSlXuwsKZLr7i5+TkE6B/DBiYfJi2M8tdLFdqDosB4ljdM90GqfFHHmGB/vU7jGAo7lO gjtw== X-Forwarded-Encrypted: i=1; AJvYcCVcPlyr7CKj9QcE1tZpTpu/NdB7C6jv5O9Nrsj9iFDAvfvBuK1vaZSwpWEH0D4VUNSTQBP3mNl1/QweBX8=@vger.kernel.org, AJvYcCWrmFEKGj2BhbkctMTfr46ujxrQyAyFSnAwddAKyvB5NXdeyv8HsyfZ3s2RUn2QVWW9ySxrXzm7@vger.kernel.org X-Gm-Message-State: AOJu0Ywj/ELiyg48iZ8bD9KHOZJDftMps94bNSr3GDV6WW0hAIFWPSmA qB0low1A10rdhrlCdvuPWJMYMhqI2t88aQI2GSnvgzMUM9VfZlpd X-Google-Smtp-Source: AGHT+IH4v/VnlWFRX8tIxgYmqYQC9Fi+hgqJQkFV9RM6GnCmDjwMnlGdM0ik3Kjld3TYvUl12J8xGw== X-Received: by 2002:a05:651c:54d:b0:2ef:2905:f36d with SMTP id 38308e7fff4ca-2f9d3e4966dmr84919091fa.16.1727701946064; Mon, 30 Sep 2024 06:12:26 -0700 (PDT) Received: from localhost (fwdproxy-lla-007.fbsv.net. [2a03:2880:30ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27ecf90sm530077566b.97.2024.09.30.06.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12: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, max@kutsevol.com Subject: [PATCH net-next v4 04/10] net: netconsole: rename body to msg_body Date: Mon, 30 Sep 2024 06:12:03 -0700 Message-ID: <20240930131214.3771313-5-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 6cd0a9f25db3..da42dffa6296 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1092,8 +1092,8 @@ 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, *body; - int header_len, body_len; + const char *header, *msgbody; + int header_len, msgbody_len; const char *release; =20 #ifdef CONFIG_NETCONSOLE_DYNAMIC @@ -1101,15 +1101,15 @@ static void send_msg_fragmented(struct netconsole_t= arget *nt, userdata_len =3D nt->userdata_length; #endif =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. @@ -1124,10 +1124,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; @@ -1135,23 +1135,24 @@ 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 + + /* 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 Thu Nov 28 15:42:52 2024 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 C37551922F6; Mon, 30 Sep 2024 13:12:29 +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=1727701952; cv=none; b=O6Zl5QkcKGNcAfuUMm2nzZwCX+ct4KL0f5RQnjpjnythT8iiYaP5nCIKinGXJpECRzL5ceHiFLCQZPEd+Ggm7rJEMKaTKBKveJvbLpzqrvNNiH/QeakFKqTZIu33SZzm28j1DCBSQ38qVzN9N1Kkh++MUtr7ulrq1ewhiicBnkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701952; c=relaxed/simple; bh=tEvqjLyOELmf3FPDSTwodtrmDPjSk4Ucls88y+kFrgg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ujgg9PIGxG1RzXjFWPDRnUH0+hXPH6SVFzmCqNlseh/tkICxI5f3lV5FEXojPXw/Kj68uXh+IX0TbOEcshHSXJItn8sV7QrnWyB9TgHKFJiiE9NwlYpoxrQYMG5l4LiQV6EmDv6Z9FvBNKAmS0rKbHWq1AOyKwzKGTAdlKDBaiE= 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-5c896b9b3e1so1788183a12.2; Mon, 30 Sep 2024 06:12:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701948; x=1728306748; 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=C2f7bj5YU9jZj+tChoovOkdp6lmafyVJGyWlFQy5iXQ=; b=XG5LCuysSu4FQnxaJML7WujwwC5z5dBtENO5zJfYnCO1QzrHJ2SgSNGgTnXJTuPZvR XQdBSdRo8ptfUWvjlMtXd4CGWtHg2qLT6fWwAFL9jbpkDWGyy9tgFESNICeUm0ttP7Mo QtfkMfPBVDilndtDAo/b1UG2nP3mAHJQ16+pXeXsaVmIzyPM3/mi3BY3scPng+zkjb2M nspoaHtqwVDJnOHe3zgxxJBaP4LhVQAcaQ7KKLcyNcJ6ibwdLiZjX0GQufR5QKKNlSYr 64yJGVDNxZUHuOVAptAwlTFhYJJg9r9/CI82PqDQamJ1Xzlxg80mZ/J6kkuwuAuj0VJ1 Xy+g== X-Forwarded-Encrypted: i=1; AJvYcCUdnZBCBjvUhGlvi8SiB4vjYZHeIT6u4JG8PVegLwrFy1br+khYaa08b8ey8WRiQPtd9EJPuYEF3yvTAj0=@vger.kernel.org, AJvYcCX+DA0Nr7NqbgNHhRAFnihakv80kVGc9Tf9nqBQwwfAr8kU2XzUiNtWtrlAp4jgXhzx42oxOtdV@vger.kernel.org X-Gm-Message-State: AOJu0YwJUFMQTP/YKaXR/rm3wkn/kp106SoeZxEizOVyOCLJnZH0UhU0 htr+lWAkdykcoQPZJPEDWMsbNj1Jnq3s5Eo7sQH2b3q0Sb8EJAak X-Google-Smtp-Source: AGHT+IE2rcZvxSQ2QILa2kKXR59QbIvqI4wUeqQTjzbK2aadc21CEy4WreDv36ZHr1mVW1BbMKoAOw== X-Received: by 2002:a17:907:1b13:b0:a86:c1ff:c973 with SMTP id a640c23a62f3a-a93c4a4e10fmr1277202466b.47.1727701947944; Mon, 30 Sep 2024 06:12:27 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27c5aadsm529721366b.79.2024.09.30.06.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12: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, max@kutsevol.com Subject: [PATCH net-next v4 05/10] net: netconsole: introduce variable to track body length Date: Mon, 30 Sep 2024 06:12:04 -0700 Message-ID: <20240930131214.3771313-6-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 da42dffa6296..eacb1bdb0c30 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 #ifdef CONFIG_NETCONSOLE_DYNAMIC @@ -1124,10 +1124,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; @@ -1135,7 +1136,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) { @@ -1151,7 +1152,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 Thu Nov 28 15:42:52 2024 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 BA14C19258C; Mon, 30 Sep 2024 13:12:31 +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=1727701953; cv=none; b=l4YBctaz5n6oz34rW2SJEof7/sdwIw3lM4+NRmPkYdxZgZCCU651aLJYDs5VrbGYVJbp9Y9GT8dIGkjiNbfDLOJ/56a/0sY5MDOane3sfBI7dQR2OiUL18C2R32fZYlCTRzP6SRqvgs5/6/wyZaZlBHzh7qCTdibRZ7XWyEPEno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701953; c=relaxed/simple; bh=H7eqZp65Jgpb1u/+psH07NpvdOXjVU2jFsr1nTVJCsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fUR+mgrA5WupkrBv+bxTQA/YIGrDLwobXQ7byXmLsjb+ZRBmQf7PNMzvynTzlZfKeUn00QLkJBy6eKlugK3z6vOkVt5vL8u9kHK7tWM6CLrze9IHZQZ3zAj33jwr7URO59r+yf8PhuNd9AOxEWQqMlUwXsgIjlZe1TI+c1sHe0Y= 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-5c88b5c375fso2784189a12.3; Mon, 30 Sep 2024 06:12:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701950; x=1728306750; 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=IacXoX8k0E+HQ0hDaxFmO6ely6HyqGS2IJ10GYKgLHQ=; b=fPXchF2BPw3xTcaOSof3nHx23pTTRBzRRcgc+vj8FOCPXV52CTzKnmy2YtQtzm1oH1 vL1ZYmrGzQcMFkkIxbM/4Ycu8hcvIPtV+QqaiChANEVVFWvkZ6jkeanEMJnViN4Yl3ll IfdqzAhQK4dKYAFlkyFnZYLiFQk6hJzbsvEvg4I792jlWNyRVdeXevKYart6u4vzo7BA JR+FeojK0OQukkgleFeFsK+AtU61bMs8bAE6gmDayUfKh0SZrDM8pClnmLuMu62Vtwrq DY2T9R6S7zYo6ZeKvzOkBuDt27P7WrllWfC5ZGD4kFs7YaGDytJvB50oaZyvcw2jdbJr gz+A== X-Forwarded-Encrypted: i=1; AJvYcCU4P4v8oOha+vq65zoU5IlcZIPVkVxfJTaqFiQC0dGUr+SDEv5Qhqq4+Xnfc9abTMXdW06bVd9Z2m4ROzA=@vger.kernel.org, AJvYcCViwswUp5ttd7ehHcJ6ZnBphFgUSb+BOLjPogIoi2MgEgJo7O9LMO9xZRR7x+ohZ+UAVFDV5Fbz@vger.kernel.org X-Gm-Message-State: AOJu0YwCIg9QgbNCcrP6pALW8IaYN8eKTYFzUCTkC9O0OP+F4FQkJso0 pgtjsZeXOwHm9dE7iFTeiCZ/eRw4LasWkB1YZf+8SxPg7iH+5sTi X-Google-Smtp-Source: AGHT+IG1n7ePZLLJIcgnuKWMRUpH9K5dXbGlKEUjNSp0Twi4qY6bElBn8yo045enRhqyQn9yPoIjdQ== X-Received: by 2002:a17:906:6a12:b0:a8d:6910:d0dc with SMTP id a640c23a62f3a-a93c4aebc3fmr1393888666b.53.1727701949753; Mon, 30 Sep 2024 06:12:29 -0700 (PDT) Received: from localhost (fwdproxy-lla-003.fbsv.net. [2a03:2880:30ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27c5977sm529291866b.55.2024.09.30.06.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12: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, max@kutsevol.com Subject: [PATCH net-next v4 06/10] net: netconsole: track explicitly if msgbody was written to buffer Date: Mon, 30 Sep 2024 06:12:05 -0700 Message-ID: <20240930131214.3771313-7-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index eacb1bdb0c30..4e3b68a2c7c6 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1130,6 +1130,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 @@ -1148,12 +1149,21 @@ static void send_msg_fragmented(struct netconsole_t= arget *nt, this_offset +=3D this_chunk; } =20 + /* msgbody was finally written, either in the previous + * messages and/or in the current buf. Time to write + * the userdata. + */ + msgbody_written |=3D offset + this_offset >=3D msgbody_len; + /* 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 Thu Nov 28 15:42:52 2024 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 73856192B6B; Mon, 30 Sep 2024 13:12:33 +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=1727701955; cv=none; b=KjwTgPpKcYiDFQXSmqJZC3FSBVY3+mVNZEWTMDikOOkSr3rqBjuvJopredLNu2aZ/nc9vUgIsxYnbi5ipW6tTD2Fth2LtAITLesbaU8jIXtIsKdninLHRzBobTVoiq68n93UpDUMf6iU+nRtHo0wEqnBU9CJy+/ky36lf8+DkZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701955; c=relaxed/simple; bh=WhY8AarLSn1RIRR7rpc3dbIpD+E52YcOd7B65Pc8uJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VoPP1w7KnZZaj5Y3WyOLYlGdoV1NRtl/7w5T7ab+XHEHHrqDIBxplinwfwqBYLy7eCU8SJ8ppPdAWbf/U2DGKZMmXUVS5tmQFI31HshvDniLIKGiBaMxMe+VPQmTHd4Rn+4Lh76JR7pC4yZsuqhFt5cUYaTKKtSchKTn8u9wAWY= 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-5c8784e3bc8so5326402a12.1; Mon, 30 Sep 2024 06:12:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701952; x=1728306752; 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=Zz+SZr3/kWcukH8OzB83TA3rnjsiwupgf9c024P3hEw=; b=SP1XvZ5K84FCxByuZn9e8Lfd5J33Usa3qNAE42Q8YnsME8fr/akuG5jViJHburwcrM QVqy9cKruhtJN2ecVcdIy1wfwms91Lp/qHVuVIugOuy7JKiuQZhpuKhqfxlampFNCMCs 82iFeARVijp1k1AhyH5fLDXzySddBFJyHgnW3yYmNllnGsFCIZNxL5bcekbdlsA3EDYi Hfdvh73i4iY31ob5FYSskzxfMeawF83dCbYLJ3mQXdBXxvZL9N3hUdjYAgJ9/wpzy/0i egOBUZxEoluAtyzvHYGbFMX7IKVKVE4J8hUfcWPIWZdqAEs3yLY6ErR+k/ZF8/bQdAW+ HkGw== X-Forwarded-Encrypted: i=1; AJvYcCW6MlEYe1gVemKkjk0A1oMUuf2nr1vInSTEb586/5i6ZxxVVt2ycLnijLwzhLotvqRv2ib4F4L141mSM8g=@vger.kernel.org, AJvYcCWNMLUxK1ihCwQlmxfZMqUDCSornD71KcVJt4BcHrItza373k/RbVbxTP7f0kVNK9CWa+6JF4pl@vger.kernel.org X-Gm-Message-State: AOJu0YySfSjaJhX4rvI0UTWQk8TYcp0Jg7f+4ZEIrk1XXY6KcNK/f1td 9lZ/x0fXpUPz4Jv2PDwrarSWbwh12SEW25U/v/f/gr4hhxqcR1Ro X-Google-Smtp-Source: AGHT+IFgV7yBJRkLc6WJ2T/GvT1/jjkoLis6hnEjnPgYzYEMF7c9GF911qRl8/AE79jF5/gwyYqkUw== X-Received: by 2002:a05:6402:2788:b0:5c8:9e36:ccb4 with SMTP id 4fb4d7f45d1cf-5c89e36cf0fmr1934400a12.9.1727701951545; Mon, 30 Sep 2024 06:12:31 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c882495491sm4489250a12.87.2024.09.30.06.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12: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, max@kutsevol.com Subject: [PATCH net-next v4 07/10] net: netconsole: extract release appending into separate function Date: Mon, 30 Sep 2024 06:12:06 -0700 Message-ID: <20240930131214.3771313-8-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 4e3b68a2c7c6..4a20bcab0b02 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 #ifdef CONFIG_NETCONSOLE_DYNAMIC if (userdata) @@ -1115,10 +1122,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 Thu Nov 28 15:42:52 2024 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.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 2002C192D78; Mon, 30 Sep 2024 13:12:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701956; cv=none; b=YgylIqVmaa49Log0DoNdyHo1KqWRxvdU5t6kU6Ncq7axVtACPnFCVpEIAX6JTHhsXday2Hm1HVAFyPF5T2RmHMH7sG/ZJFPAfVUrsvL3c9zfHR6Cg/Q+Uit7YUEl/Rm01jaSy2MKUIQzE0/NilBwYRbotZR2zrK9RbepYknzF0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701956; c=relaxed/simple; bh=zTNAMyL/JzNpPNPijEGwC0EtChrujzdvS8Qk2cIGDy8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jb9ETFtRnqfcg3iyGCnzVnwXEuq+9rv39TH1ejXDhrQ/ySW3AdJTmCWDmS+Yt/I+C003zOpKrGa/23mtYDPd8b5vjAiXkT+KO2zByyGI5hqjLN5l+VH6mTX9TfjlxnqU2tl8jvI8dp8DdW8JCu/zKSOfAwe8Dh88osHfcZE7QIs= 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.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-ej1-f50.google.com with SMTP id a640c23a62f3a-a8d2daa2262so502034766b.1; Mon, 30 Sep 2024 06:12:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701953; x=1728306753; 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=dte1BRYAJLLwHh4pCmZC5hBkzqPqK7pt5D4K6M9ka5Q=; b=vrFiQKadhvQiqsACDK2fZvCsA36CRYG2U/Q2ztfzSRah9iSkptIUOJLQATvf51YjHd iPiQO7UpfGZ50KJ2Mf8QdO8OnnZiNCq75nt2zA5ZTJzdPOcD+mwsBVnDywUUbgf2Bkhh afFvj+6U1ODjQX8ni+txoFlqXISTy7NSkVTUJB3gy/Y2jKJR5tOfyEqiD/0g/b6WKCwB eaAsnic+/PqLxTgG4tdcQ8es86bNrmtJPDhvodVcBUNoeS6O2hCCR0p4oSn7MOlZ5rJ1 jbamLnr4pCyHibPKhg1BrEENNWv6QKtQ/v0ZVHC/SDGcP+IoTwospUzrifMQVJ/jx7bN tgSw== X-Forwarded-Encrypted: i=1; AJvYcCVhvOHgvYeaDQbnWbQj/6mRs7WDkg14LULznQD4J1VtkH62gHsCiYqrW0a6l87ZVYUPn6e6XwE8@vger.kernel.org, AJvYcCWfqhbsAD/vgmtRoQLbI3iaMmZGQyUm5163UfNHu9vbUnuzOQlqQ3HjgEXvAH6l9BxTQpZ2LPFb0gMB2uk=@vger.kernel.org X-Gm-Message-State: AOJu0YzyPG8HsMuNRdBqAoLf9YBfR4CJ0Xijarg0DQ56ibxyIO+IEdzS 4uRQgYdKZjzpbWYEAO/6SsFWmWHnv3JwlOeNJzG847mIQNDyI2xd X-Google-Smtp-Source: AGHT+IEq864tMU2SjR00rmH1keO1clY+YuKZKzgBFgINNUYt69nIF1XuF2EdW6Dk7iR25RMGfgqr7Q== X-Received: by 2002:a17:907:eac:b0:a86:7199:af37 with SMTP id a640c23a62f3a-a93c4aca8d9mr1494540166b.58.1727701953384; Mon, 30 Sep 2024 06:12:33 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c299e5desm531297566b.223.2024.09.30.06.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12:32 -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, max@kutsevol.com Subject: [PATCH net-next v4 08/10] net: netconsole: do not pass userdata up to the tail Date: Mon, 30 Sep 2024 06:12:07 -0700 Message-ID: <20240930131214.3771313-9-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 4a20bcab0b02..7266d4232d5d 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) { @@ -1102,10 +1105,11 @@ 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, *msgbody; + const char *userdata =3D NULL; =20 #ifdef CONFIG_NETCONSOLE_DYNAMIC - if (userdata) - userdata_len =3D nt->userdata_length; + userdata =3D nt->userdata_complete; + userdata_len =3D nt->userdata_length; #endif =20 /* need to insert extra header fields, detect header and msgbody */ @@ -1202,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 @@ -1215,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 Thu Nov 28 15:42:52 2024 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.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 2EF80193415; Mon, 30 Sep 2024 13:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701959; cv=none; b=e9GbtfxEeczAFEX+F0Y+PmYUPbpbn2qIaFOuspl7bjCKAvSnJXYpsj2M8AXIFHFtZpRpXtqzaWb/HJjqlivvKVTPF2UbKMXwv1x07SDmaLTUiN1sudQhkUeBMAJF0g1navlUWZEKJSJjRmsQnFivJGufVwOOHaN9cR1X/AMnmqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701959; c=relaxed/simple; bh=jbXgxSeiaA31t+HzqYsoEUa1OWK7xqFLCYY516n42ZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pSbFVoLg9NoFSyscew+/2Rcx8EPZKyiawY6PCiE26QawF4Uzg0Jig0++Jws3eWWUehDTEyyPawy6uO33RJSDmMmN6WS7nkhPgu9C15QuKdXUEKFsy7lCYAasHqNFo3Tw3F1XSPsY/TEmSH8UhhuTG9kvWgQVJe2nAf38wDiy6Uk= 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.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-ej1-f48.google.com with SMTP id a640c23a62f3a-a8d6d0fe021so763477966b.1; Mon, 30 Sep 2024 06:12:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701956; x=1728306756; 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=Mi0FXoMOYCAp5UnsROnjsc3YYE1l36rxsWdxJwhJ5X0=; b=TSTwBEE4CrHmx4CMtewlAO5AGnTiAv2aAoevfztdUz8kKoJPN/QVpDSIZEVeKGUQ9c JcuAWKXSI46+SG4/J4V9FG+E3iNY5QSWtLzgndKTRxUG0/U31oo9Zz0s9ILFCDdB5VM8 6AWa+N9Wv7wNE6vhsi3SFN2pkw6L2zapaLWO8CaFYwtVjFTNB0/P2hCnGgStoDTchD3Y Zf1jYr2fNy1EC8TyQ3/rX3apUqsNGhpKZXLlDz6yO6d5T3Wn9x9JwPeWGddCztxRXhR4 //BYbmgeDdZ3xlIh1hbIsgqK3z+0P6pPpxMY5YyYOWWiMXgyEVPDrnjv+8ofCVNhQ9DO O7yA== X-Forwarded-Encrypted: i=1; AJvYcCVZyBciB6N/XQPd7pSlfzJKMuAJKq2RhKb0iMuKqEc5CHlueWJgIojyfUhcs5iszWtlKSkFIVbpGp2+Pww=@vger.kernel.org, AJvYcCXuEF94gwNPOBGqtYOFDNSLKdvJf+9UdA3xqqPo3FU4A1hY1HZaHN2/Yn9pvu1RPDgPDCD5MAz+@vger.kernel.org X-Gm-Message-State: AOJu0YwgeaudnEfRyA27C3zy3+yjKWAW2dXew4lGKlTbv0qx04tFbVMu Hn5SXwWR9WWVPmH3d0MrnRLhs1pvDPyVM5JqDei+Rg7kHk6g30f/ X-Google-Smtp-Source: AGHT+IHK3AMN4wRZONbv80xChi69/rVklmLtWbo0vCKAQ3kF8NBfgppTRucy2+7fKGlbCLN5zsxnbA== X-Received: by 2002:a17:906:dac3:b0:a8b:c9d4:5cef with SMTP id a640c23a62f3a-a93c4946a7cmr1267429366b.29.1727701955374; Mon, 30 Sep 2024 06:12:35 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c2978c18sm538949866b.148.2024.09.30.06.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12:34 -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, max@kutsevol.com Subject: [PATCH net-next v4 09/10] net: netconsole: split send_msg_fragmented Date: Mon, 30 Sep 2024 06:12:08 -0700 Message-ID: <20240930131214.3771313-10-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 | 81 +++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 7266d4232d5d..f724511cf567 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1096,46 +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; const char *userdata =3D NULL; + int body_len, offset =3D 0; + 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/" + /* 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 +=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; @@ -1144,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 +1177,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 Thu Nov 28 15:42:52 2024 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 08B51192D78; Mon, 30 Sep 2024 13:12:38 +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=1727701960; cv=none; b=IY/zR7mqsChWcQYEOn+TxoUJzSqUigg+QaxTz5nLMoFnpgbzh8cq7f1eDexx2oZv+cU/8Np/PqmGjeqMfvBTLEESD17CqdAQM25Tg35forty/f1bL1qcY+UAXxKypvaDNCgjMTeHVf6LAWWXG0GI3DIJY3rCxexaGDjj34FLxXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727701960; c=relaxed/simple; bh=YoM8JfTyubmHxwyaR780Z4MLjoKPXDQNorh4/OwIsSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pJ7j+Rc964VUTOeyMHKHudt5BviHODYRnpvWZXYd6enqrlm8DBRLmxEqlQc88cWlnDCklSK+I5cHHowbGdojOd4w00rwebZEyzuwbmXL5qvY6c9+X/gchSg4PW6+QJ1uMo3fkiktbliUE644OzQT4X3EcP/x3qh7C7W0N6M1AmY= 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-5c88b5c375fso2784325a12.3; Mon, 30 Sep 2024 06:12:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727701957; x=1728306757; 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=M94vldEyuuxRxO4IdgpqluNKuv+egbA35R49EuAXB5k=; b=LWoEqK4AehAOiO++6o85fktIhOeMNb5PcvFI+3Im9x7p37QX4WQZEQNx9jef9Ngd7q WNifFpwKBKRaa40JL4oLGOjr60Cs8CbQYOLwt+3/HKQoIAeFlKkovOtsHg3RYgNFBAd+ XPqxxtSojYl9qGT+wf3IpbBadDxQ8qWt3VXmg0eQQ8DuV0hg+bvSQY0P7bnBV3hNf0eK UZvxfIMWAcApq3VoL/Pc7/eZvxj7eORfLFhniiw0eClC/0eSAcLiLRY6scckY/QyPsZH sW5/VOtcDnZuNqVKEWY6Pi/kymxxxEU+ofyfH6u380Al3BOMPRUa6bCdXazWXXNc0Y/0 6zpA== X-Forwarded-Encrypted: i=1; AJvYcCUENp2bfasn8IeEYx4qBwcmacgfkHAtkVzbYh42gYlQq+0KDzTQ2WVoZa93Ab+G8eudXnw+3jzFF1GSFEg=@vger.kernel.org, AJvYcCXeeEHH14vOaTOZacz9Ndw/VkhnH67HaK9+AaeT9igL9Sc18GlgX+okYZ/3Vpc0Cx7RRRDxwCy0@vger.kernel.org X-Gm-Message-State: AOJu0YwgkSstMR+1P6ErQ08kISahS3oyhgWP5T2s1RV31pAeVjLox6CY hhOZOh8rhCVVTgf9lPLy8CXY85WMgTrqsfNJvG7or293gK7xbfxr X-Google-Smtp-Source: AGHT+IH6Y2rTIy3dvSJEkp+aAJG0YoFNk2Um9vgMkgloRl+3noBVk3cFbg0OQ/pVKprj/KMikAei1Q== X-Received: by 2002:a05:6402:2812:b0:5c8:8538:b770 with SMTP id 4fb4d7f45d1cf-5c88538bbbfmr10342103a12.8.1727701957157; Mon, 30 Sep 2024 06:12:37 -0700 (PDT) Received: from localhost (fwdproxy-lla-114.fbsv.net. [2a03:2880:30ff:72::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c88245e9e2sm4485793a12.46.2024.09.30.06.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 06:12:36 -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, max@kutsevol.com Subject: [PATCH net-next v4 10/10] net: netconsole: fix wrong warning Date: Mon, 30 Sep 2024 06:12:09 -0700 Message-ID: <20240930131214.3771313-11-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240930131214.3771313-1-leitao@debian.org> References: <20240930131214.3771313-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 f724511cf567..4ea44a2f48f7 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1164,8 +1164,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