From nobody Tue Dec 2 02:19:50 2025 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.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 5D7C3757EA for ; Thu, 20 Nov 2025 00:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763597731; cv=none; b=QyTAOWhy5jmmIoCYLo+Kr/KJqrQq09wqBeTmW2er/0XusBaWvtdA8N2JKg9RX4dX5Q43ZdLbCFbOlhByP10CvZIF6HeO8tuBk2jLJLp2JMZsHSkjOjMkDtqzF1MMxI0sx475peDgbSn4c/HYSPAy0L4h9YxsanA+4UWHuAqeW3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763597731; c=relaxed/simple; bh=xCpkEYzNomcjUq2RBhM2Nj8mJD+qDxOUs76mrgKtjgc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ok+F5aoNQ5wh8a+rbZq/7jfVSKmwBhxVYOSV3K0I7eo8bnPxFQnRYfrn0fHcjr4RgI6hRQ38yfDtHPbCBaNyzx9ylPd9ebD7uEKEHgoK6MWraS2n1WpRGEYroPuiFTJcdACgmOGg0dFY4oly8At5otSxLwHdz21jkhtGuljdGRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ilcqdqx3; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ilcqdqx3" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4779ebfa91aso563475e9.3 for ; Wed, 19 Nov 2025 16:15:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763597727; x=1764202527; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=trfVqswjg1NdlW9xJm6ysY3CFs26x2tsI+zzVlfdYrM=; b=ilcqdqx3DfVtObg3ADQ08riv07HVPT5l6fTbieMSfVIjZP/KYSdsP0CB8JKs8dZdzi mZFdHxcYQw2N3LG3a4bpzrYfCNAI/yYZFHRZHv4GuRF1tPHj/yi12MCRAckywJeR+dbc aihQBSMF5TlSvlpStPiwJAfbt72ADHVv2XjkLgCce8mbUUliwi1QkpGm/ErJvX67qJQg KpwOSLibOVjfzEh27M4tCwXOuZhGY10Awd3dtkE2iGRRlTOKsht6pr+FEltz0CMtYUy6 C0Cxsi0ABvZugEp7z2s0uihB5iGuRxArDWfgsjpblN+ZsTbIAPYSqr4WsDPZQAX81jHA wE+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763597727; x=1764202527; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=trfVqswjg1NdlW9xJm6ysY3CFs26x2tsI+zzVlfdYrM=; b=egNkQthzY8KYVuOS0G67YVwnPbxFlIozI/rO3oYXwbsXKIPQYpqBdKpw71M9ewkJkC s83XFYpBiM/Rw+vcUGAc8Mo9BS3dNnuPDAxGTkQUaN15F12OySxsoDB32Zq9dbfbPkUu e5wKMHK0lNh+2RU0xiGmbRVuW8k/6+jSv+MLpCNP4s0Y4lpJjUMnL2QsNHjCBXND0Ac0 9Tm+hs3XpdVPAdYhwyRPBXBf0OcIsKeTDl6OthO1bL+DB8jh+HcKhde+Wk7t9TKvzOIk +7r+lnMcJhssmKVaGH3IoK0/FrxVNc9AT7ndShvG/GYKWKwZpp8eWc4Pqo/ThuhpuqII f5Rg== X-Forwarded-Encrypted: i=1; AJvYcCWeIW0048cx/0tfL2vZQrad+qeoCY7Eq2rWJFEIsBncah45xBBjxZTlZ+aDprKrpGKw6FI0kkLaG1oh8BI=@vger.kernel.org X-Gm-Message-State: AOJu0YwPJl0A0rRcIL+me0MzwIFi0E+/aXBgmaDafQs15X5IWortLp3B OpD81X7Y7Na0Egs3hTNiCpYNueML+lfpaGlSOnKZxWQo6V7Vdz/CNfwp X-Gm-Gg: ASbGncvsbNbLO14xQCtqR2SiyJdvh2m/upN0hMygwye0wURCEKgnZWaffqJF8HGQ7fS EohOGuH9SO5DQ/v76F9F9uQprV1eXE/9aUqYq0P4vMeUhjIQ/04WZ1ser64FlNLF1uH1k8lp74A vXz05SjMrYHcTXBw+yO9ncf4Wu2V1zJlcDI0mEv6zEdoAzGf0b5O61ZBS/vHNL/oAnIToPegYSe N/AQlLd3gWEADja+mrDncUNd7t0SfSPw0efEUkRZ4fMsKaYjlbQBBGFX81bMCxawNfwQx9bbDQV +i+p8V2KsA5vMO0tK0mwEahlNRR0hru+A5kQhFC2bXA37/vFM6dM6oALR2zcugueENmAAcqf9Px 916acg37EfNrplRUhsPxlyvPEPpNr+zma+ogb+sFRVi+sdh/2XhSxE2ZEkO8SHwy68aFaKU9FSj WCv2x7uJ9jAhIbXnIhgzMI9kdfcfcTHFMv1vEiXg== X-Google-Smtp-Source: AGHT+IEiQxaxA/A54OsLoBVuiEEkFz+e6t06y8Ajf7M4vany3n7BtGT/D3/7t3IQL3xUNHYfHJZUQA== X-Received: by 2002:a05:600c:4f4f:b0:477:aed0:f402 with SMTP id 5b1f17b1804b1-477b8d8a7e2mr6219385e9.8.1763597726622; Wed, 19 Nov 2025 16:15:26 -0800 (PST) Received: from localhost ([2a03:2880:31ff:40::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7f2e432sm1970904f8f.9.2025.11.19.16.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 16:15:26 -0800 (PST) From: Gustavo Luiz Duarte Date: Wed, 19 Nov 2025 16:14:49 -0800 Subject: [PATCH net-next v3 1/4] netconsole: Simplify send_fragmented_body() 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 Message-Id: <20251119-netconsole_dynamic_extradata-v3-1-497ac3191707@meta.com> References: <20251119-netconsole_dynamic_extradata-v3-0-497ac3191707@meta.com> In-Reply-To: <20251119-netconsole_dynamic_extradata-v3-0-497ac3191707@meta.com> To: Breno Leitao , Andre Carvalho , Simon Horman , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Gustavo Luiz Duarte X-Mailer: b4 0.13.0 Refactor send_fragmented_body() to use separate offset tracking for msgbody, and extradata instead of complex conditional logic. The previous implementation used boolean flags and calculated offsets which made the code harder to follow. The new implementation maintains independent offset counters (msgbody_offset, extradata_offset) and processes each section sequentially, making the data flow more straightforward and the code easier to maintain. This is a preparatory refactoring with no functional changes, which will allow easily splitting extradata_complete into separate userdata and sysdata buffers in the next patch. Signed-off-by: Gustavo Luiz Duarte Reviewed-by: Breno Leitao --- drivers/net/netconsole.c | 111 ++++++++++++++++++++-----------------------= ---- 1 file changed, 46 insertions(+), 65 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index bb6e03a92956..5fe5896d6ff5 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1560,89 +1560,70 @@ static void append_release(char *buf) } =20 static void send_fragmented_body(struct netconsole_target *nt, - const char *msgbody, int header_len, + const char *msgbody_ptr, int header_len, int msgbody_len, int extradata_len) { - int sent_extradata, preceding_bytes; - const char *extradata =3D NULL; - int body_len, offset =3D 0; + const char *extradata_ptr =3D NULL; + int data_len, data_sent =3D 0; + int extradata_offset =3D 0; + int msgbody_offset =3D 0; =20 #ifdef CONFIG_NETCONSOLE_DYNAMIC - extradata =3D nt->extradata_complete; + extradata_ptr =3D nt->extradata_complete; #endif + if (WARN_ON_ONCE(!extradata_ptr && extradata_len !=3D 0)) + return; =20 - /* body_len represents the number of bytes that will be sent. This is + /* data_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 */ - body_len =3D msgbody_len + extradata_len; + data_len =3D msgbody_len + extradata_len; =20 /* In each iteration of the while loop below, we send a packet - * containing the header and a portion of the body. The body is + * containing the header and a portion of the data. The data is * composed of two parts: msgbody and extradata. 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. + * many bytes have been sent so far using the data_sent variable, which + * ranges from 0 to the total bytes to be sent. */ - while (offset < body_len) { - int this_header =3D header_len; - bool msgbody_written =3D false; - int this_offset =3D 0; + while (data_sent < data_len) { + int extradata_left =3D extradata_len - extradata_offset; + int msgbody_left =3D msgbody_len - msgbody_offset; + int buf_offset =3D 0; int this_chunk =3D 0; =20 - this_header +=3D scnprintf(nt->buf + this_header, - MAX_PRINT_CHUNK - this_header, - ",ncfrag=3D%d/%d;", offset, - body_len); - - /* 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(nt->buf + this_header, msgbody + offset, - this_chunk); - this_offset +=3D this_chunk; + /* header is already populated in nt->buf, just append to it */ + buf_offset =3D header_len; + + buf_offset +=3D scnprintf(nt->buf + buf_offset, + MAX_PRINT_CHUNK - buf_offset, + ",ncfrag=3D%d/%d;", data_sent, + data_len); + + /* append msgbody first */ + this_chunk =3D min(msgbody_left, MAX_PRINT_CHUNK - buf_offset); + memcpy(nt->buf + buf_offset, msgbody_ptr + msgbody_offset, + this_chunk); + msgbody_offset +=3D this_chunk; + buf_offset +=3D this_chunk; + data_sent +=3D this_chunk; + + /* after msgbody, append extradata */ + if (extradata_ptr && extradata_left) { + this_chunk =3D min(extradata_left, + MAX_PRINT_CHUNK - buf_offset); + memcpy(nt->buf + buf_offset, + extradata_ptr + extradata_offset, this_chunk); + extradata_offset +=3D this_chunk; + buf_offset +=3D this_chunk; + data_sent +=3D this_chunk; } =20 - /* msgbody was finally written, either in the previous - * messages and/or in the current buf. Time to write - * the extradata. - */ - msgbody_written |=3D offset + this_offset >=3D msgbody_len; - - /* Msg body is fully written and there is pending extradata to - * write, append extradata in this chunk - */ - if (msgbody_written && offset + this_offset < body_len) { - /* Track how much user data was already sent. First - * time here, sent_userdata is zero - */ - sent_extradata =3D (offset + this_offset) - msgbody_len; - /* offset of bytes used in current buf */ - preceding_bytes =3D this_chunk + this_header; - - if (WARN_ON_ONCE(sent_extradata < 0)) - return; - - this_chunk =3D min(extradata_len - sent_extradata, - MAX_PRINT_CHUNK - preceding_bytes); - 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, extradata will be sent in the next - * iteration - */ - return; - - memcpy(nt->buf + this_header + this_offset, - extradata + sent_extradata, - this_chunk); - this_offset +=3D this_chunk; - } + /* if all is good, send the packet out */ + if (WARN_ON_ONCE(data_sent > data_len)) + return; =20 - send_udp(nt, nt->buf, this_header + this_offset); - offset +=3D this_offset; + send_udp(nt, nt->buf, buf_offset); } } =20 --=20 2.47.3