From patchwork Tue Sep 3 14:07:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788749 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.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 5E9591CA69D; Tue, 3 Sep 2024 14:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372488; cv=none; b=iCAdEqIw9jNwDpsq7vGGyp8JPx68gedF3h3BVnvNRyeB4swbthKAuWB1FM2Fi3xaTKTgU++doUflwJ7mo9Jle8Brd+NphFnBPb94/SEW+UBnoYomA0+0kzKc/vdDx9Vpc1yBbjWyn9Fb+hpKFZnus0FOKY5naLMhI3eIwWKJBdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372488; c=relaxed/simple; bh=yo2ngucoohaz4ZVlQSokhpzKAWCl9YfjIgSeu9P5Z9Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rCpQfIW7comfCtKfrPE3fn6g29AYMiuvO68Ywk5GKBaRU/SaZKIopgAEFmYIwKXGvLBlNuRCFhcD2jTwLNQare+QLKcfUo6LoUOQEuPIjoRF+nj/PgTv+/QhEHq6lfyuxlXgFab7rxfstSoLISKPniPZ/W1a6N8/1VWDMKBTNIQ= 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.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-ej1-f44.google.com with SMTP id a640c23a62f3a-a86abbd68ffso891175266b.0; Tue, 03 Sep 2024 07:08:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372485; x=1725977285; 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=MlldsvThyQe+t9ooRgmvSM2+Zu0mVfH7lLG856mOXwI=; b=Q3fe//lVYPtmTTKWYM5bd48P8tltv13grL/So5USxcC/E0zOSO7r3UvFFiBGmeAbfv 22ZwMk6WRviRNT+kcwHuKQyaIOAhqG8KOzfcttwZr4L8pphK3iqqjHEybp437EWlRtVu P42qwiOI06R1/yYLadIE2pnbEbgh26iabs1Qs8dCgUlhJ39XI8NrQ0gLx+m23ryEAy57 udd9j/zYnXqZzTPLY/FiJRTa7+vJePODwOnmxAYbVJ6nmGX2vo20YYb1w39abfsWUp1e zYQDfWhPoxSKZvCTKqn4D4VEBF11OumuddcQGA2MuFW4+/RiFkdQhODmhAXHGXsdRWzf HJSg== X-Forwarded-Encrypted: i=1; AJvYcCXNHF0saFw5EHd7zM3WI1WorjG//d/jcHrCEpKBJP9GM8+bzn/fdsXQZmglyp3o65346qAucUIS@vger.kernel.org, AJvYcCXs53P6Ui9m8yEdvLhekKo3o4VZ3st2/Mc/ziHRckVxR5uWgTtWxYyrAAYmd4C6eXXs4XuILvgVce/tnTA=@vger.kernel.org X-Gm-Message-State: AOJu0YwPCzFXjXrBQukIMb5fQqTOjvJnKDqJCbZH58jYEOizKiHgg23a wYGIeFb6DsJXmw58YUy21Q01nqqQ4INmspzAuqlPRbwdZXljAE3o X-Google-Smtp-Source: AGHT+IGIs9UmHV9t20hb0PFDHL0XL5gO3zPLO9/lSmMqoTuSw5wIrr+UGbjHd67tH4xJpeowfs9XHw== X-Received: by 2002:a17:907:94d6:b0:a75:7a8:d70c with SMTP id a640c23a62f3a-a89a249c510mr1345137066b.4.1725372484234; Tue, 03 Sep 2024 07:08:04 -0700 (PDT) Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d8117sm694239266b.172.2024.09.03.07.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07:08:03 -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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 1/9] net: netconsole: remove msg_ready variable Date: Tue, 3 Sep 2024 07:07:44 -0700 Message-ID: <20240903140757.2802765-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Variable msg_ready is useless, since it does not represent anything. Get rid of it, using buf directly instead. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 01cf33fa7503..03150e513cb2 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1075,7 +1075,6 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, const char *header, *body; int offset = 0; int header_len, body_len; - const char *msg_ready = msg; const char *release; int release_len = 0; int userdata_len = 0; @@ -1105,8 +1104,7 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, MAX_PRINT_CHUNK - msg_len, "%s", userdata); - msg_ready = buf; - netpoll_send_udp(&nt->np, msg_ready, msg_len); + netpoll_send_udp(&nt->np, buf, msg_len); return; } From patchwork Tue Sep 3 14:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788752 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 282FF57CB4; Tue, 3 Sep 2024 14:08:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372490; cv=none; b=VK0diBLL/Ec3ixwGezNKg37OONAzgCokBEc604P6TK7uieognuFV6VeLZsZvdv+2tDREkFe3pDujk7VG1V5/p4c+3jTtp3wbbuzju1lkrYzw07NHo0SzrSSdbq0nIdguxSOo2A7ZUVaSfvPkwXIEVUGgxahfIf3WlTxgEwOO2CM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372490; c=relaxed/simple; bh=J0ax/ms6BPhc5dtWz04kXQJE9Gp7S5ZujB4yIpDHEQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=faH/vHnT5arFXTcvXiNfeXxcCO+r6j3Fp2XMQcE/Z52y4HFrkOqsXztyiuuO9wInDOuBTFCA6AUWOrSCovX7rgIo6Zo1H9gn/VPbqTLpo8MbE2KUlfG/6H83taWIyP+hJvdr2mLOSf3t5NOXPNpoy08LOsOZ2dcrfx8ilFvaYbg= 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.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c24ebaa427so3626967a12.1; Tue, 03 Sep 2024 07:08:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372487; x=1725977287; 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=JhnUKYBqFoU50t/k4XKsK4OTUU5YHkYgYvF+1IbO5bo=; b=u2JtLI0/DHVFXZyQzpUG1SQ+4YTXavoQTwwu+ILmgSZQFqcGSdAUOxrXpQAdgpvED0 McMp36dI6CBwLd8CyPcJtPwAlD3CZMUoBttTznTXgQKtzsNj//Zffkb/zI/Qd5xiPN9C 0cTLBpj+nS168kn6ISvtpKs4RoZYQPbyXms+jQCrZ7yqJxWQI23x1CximDBi6XfbuilO 5QI/9ejshJJre9K+jmAJUWrxq/mJlryNljNB6edY2F2QQmWC8UzcPvW59kCU6fuM7FpS tgpWpxFEpi0nJSV/prd5pdzTGVzhBHUn7pSnV3PvSqBZEmURZfhuJ7mgaCwjdK4ZWztE F3fg== X-Forwarded-Encrypted: i=1; AJvYcCUsz+uF5hBZNpBkjIZNbKHrMGQ+Sdkn+onQDW+4wcdWKXv1y/OC67ECTwHNC1x7bLs3LiY/wiDTtEpEI3g=@vger.kernel.org, AJvYcCWOOwEdehdLxi63T8AtAy0UwdZ0syy95rc3HioZgyM8imOoOEw/yDYbEJmajvAWpYqGeM+rqFFr@vger.kernel.org X-Gm-Message-State: AOJu0YzyvpPNfX5MCGlbysY68/xPqwrgdfWMyjD/DiQAaSRspQz2dfu7 i7+76vTlb1MbXtP8kF6aMzJEiUmtJbiytRJAk6oqOMyeOoaEYEUQ X-Google-Smtp-Source: AGHT+IGb+WOqC2JVe3SnaVQOL/Fh5lVOUVB06ELOQFXMZb7AH/Lp2oaPuPmB8GSHWYXVSIxFhx7mqw== X-Received: by 2002:a05:6402:350f:b0:5c2:6e51:9d1a with SMTP id 4fb4d7f45d1cf-5c26e519fdcmr1718563a12.14.1725372486302; Tue, 03 Sep 2024 07:08:06 -0700 (PDT) Received: from localhost (fwdproxy-lla-009.fbsv.net. [2a03:2880:30ff:9::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c243054c26sm4405248a12.15.2024.09.03.07.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07: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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 2/9] net: netconsole: split send_ext_msg_udp() function Date: Tue, 3 Sep 2024 07:07:45 -0700 Message-ID: <20240903140757.2802765-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The send_ext_msg_udp() function has become quite large, currently spanning 102 lines. Its complexity, along with extensive pointer and offset manipulation, makes it difficult to read and error-prone. The function has evolved over time, and it’s now due for a refactor. To improve readability and maintainability, isolate the case where no message fragmentation occurs into a separate function, into a new send_msg_no_fragmentation() function. This scenario covers about 95% of the messages. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 45 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 03150e513cb2..0e43dacbd291 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1058,6 +1058,32 @@ static struct notifier_block netconsole_netdev_notifier = { .notifier_call = netconsole_netdev_event, }; +static void send_msg_no_fragmentation(struct netconsole_target *nt, + const char *msg, + const char *userdata, + int msg_len, + int release_len) +{ + static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + const char *release; + + if (release_len) { + release = init_utsname()->release; + + scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); + msg_len += release_len; + } else { + memcpy(buf, msg, msg_len); + } + + if (userdata) + msg_len += scnprintf(&buf[msg_len], + MAX_PRINT_CHUNK - msg_len, + "%s", userdata); + + netpoll_send_udp(&nt->np, buf, msg_len); +} + /** * send_ext_msg_udp - send extended log message to target * @nt: target to send message to @@ -1090,23 +1116,8 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, release_len = strlen(release) + 1; } - if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) { - /* No fragmentation needed */ - if (nt->release) { - scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); - msg_len += release_len; - } else { - memcpy(buf, msg, msg_len); - } - - if (userdata) - msg_len += scnprintf(&buf[msg_len], - MAX_PRINT_CHUNK - msg_len, - "%s", userdata); - - netpoll_send_udp(&nt->np, buf, msg_len); - return; - } + if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) + return send_msg_no_fragmentation(nt, msg, userdata, msg_len, release_len); /* need to insert extra header fields, detect header and body */ header = msg; From patchwork Tue Sep 3 14:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788753 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 546B76F2E7; Tue, 3 Sep 2024 14:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372493; cv=none; b=Y4G7oo3Di3ngsmukZYlhNFLuqlU86Tm03FaSA8CYfl5fiTZpVPsqTXbD9u0Ac4TsgORK6VV/BrNLtBFmVQ3umjknqCr4Euquivu6HIaeVTSz6ucMXStDT1pbzs/jjqrotZtdhsnf9yPWv1LdJtvCQXpA+dYdy10onkz/t/EjlfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372493; c=relaxed/simple; bh=DaTtyBeT2Xf2cSzOd42rn2RoCx7PY9UKkjpNo0fS/NU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MAyXRin79lUtXQZ3tpUywHZB/aRT/L4UJ3GlLyR+OXxZiR6ahnkzQU9IQIS9IcU3fyNKX6GHR7AKPQfKxkTVbCnyVZCvAhS2uXQmiUgiSshncTT59WaiHOs3X+lwTnWQB+OWYSdTG8HJea+TFMqWC9mAURrpX43VpsDEk/4wv8s= 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.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c26852af8fso1649351a12.2; Tue, 03 Sep 2024 07:08:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372490; x=1725977290; 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=Ri1EA58BV/TWrZaeQrKkMSfjb0f3rHKbzd1pYby/AY0=; b=xEI7drzFIGTgctV8ULRjSMHY4ixkRiPgDRzQPglo98Tk0Jm8IkWwGoYqaWOqQ/Y6tO rG8m3NxArCAgdi+z+zsC+49gq5GsV7PmcEMDd89olq06pU4tyIhX9s4N6qw3MULfgDfq NkQSEZdMJyQfk5eQTewKsSX3fU7c5Naf4C2FiuWubklrFQh0eAInr89//0MK/pOoH9Co PcixQtmV4rLfOe9VDt82YMXrN+y8T8aOZQn6Bl5RRSTmSVHwgE+o54dNJ9YjwE5cMyYp sTMV7zMEJQT/uy6NLE6aAt+PN1g3C2KLJNK5SRU+kxhKeA2pBZUApLI8eQ/N3FeRHBua DHZg== X-Forwarded-Encrypted: i=1; AJvYcCVFXZ+RnBI3y5DUo8xd4gcWCAGUDGJKtI3ch97oAcFuPfpcneUGO0y5mroX6PV1WbnR+VoXO38hkN/NqvQ=@vger.kernel.org, AJvYcCWQsscim/qJWwwZI0LdtQUCD2YmtDpZ0q36baz8+d/9yaDzMAV2QOxpVBLUlTL1LTangb+YTZDD@vger.kernel.org X-Gm-Message-State: AOJu0YwEAR2hnnXnk4Mlvj1GsOf0uV0uhtD7Gr5ER/vetRcFdiqx9rrs f4LP3nj6tuwPSeZa0ols+h9w2AqlpZd3omvDO6sI5MJbv3lRyuA1 X-Google-Smtp-Source: AGHT+IGFK+QPrc526rQXpunySM8256dcguA0aQ+3buHH7lSuUpKxp7eobgClYXJzDurOcHxXahtTDA== X-Received: by 2002:a05:6402:50cc:b0:5c2:6083:6256 with SMTP id 4fb4d7f45d1cf-5c2608364d2mr3587492a12.10.1725372488708; Tue, 03 Sep 2024 07:08:08 -0700 (PDT) Received: from localhost (fwdproxy-lla-006.fbsv.net. [2a03:2880:30ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c226ccfe84sm6447630a12.71.2024.09.03.07.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07: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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 3/9] net: netconsole: separate fragmented message handling in send_ext_msg Date: Tue, 3 Sep 2024 07:07:46 -0700 Message-ID: <20240903140757.2802765-4-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Following the previous change, where the non-fragmented case was moved to its own function, this update introduces a new function called send_msg_fragmented to specifically manage scenarios where message fragmentation is required. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 129 ++++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 55 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 0e43dacbd291..176ce6c616cb 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1058,66 +1058,20 @@ static struct notifier_block netconsole_netdev_notifier = { .notifier_call = netconsole_netdev_event, }; -static void send_msg_no_fragmentation(struct netconsole_target *nt, - const char *msg, - const char *userdata, - int msg_len, - int release_len) -{ - static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ - const char *release; - - if (release_len) { - release = init_utsname()->release; - - scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); - msg_len += release_len; - } else { - memcpy(buf, msg, msg_len); - } - - if (userdata) - msg_len += scnprintf(&buf[msg_len], - MAX_PRINT_CHUNK - msg_len, - "%s", userdata); - - netpoll_send_udp(&nt->np, buf, msg_len); -} - -/** - * send_ext_msg_udp - send extended log message to target - * @nt: target to send message to - * @msg: extended log message to send - * @msg_len: length of message - * - * Transfer extended log @msg to @nt. If @msg is longer than - * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with - * ncfrag header field added to identify them. - */ -static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, - int msg_len) +static void send_msg_fragmented(struct netconsole_target *nt, + const char *msg, + const char *userdata, + int msg_len, + int release_len) { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + int offset = 0, userdata_len = 0; const char *header, *body; - int offset = 0; int header_len, body_len; const char *release; - int release_len = 0; - int userdata_len = 0; - char *userdata = NULL; - -#ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata = nt->userdata_complete; - userdata_len = nt->userdata_length; -#endif - - if (nt->release) { - release = init_utsname()->release; - release_len = strlen(release) + 1; - } - if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) - return send_msg_no_fragmentation(nt, msg, userdata, msg_len, release_len); + if (userdata) + userdata_len = nt->userdata_length; /* need to insert extra header fields, detect header and body */ header = msg; @@ -1133,11 +1087,18 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, * Transfer multiple chunks with the following extra header. * "ncfrag=/" */ - if (nt->release) + if (release_len) { + release = init_utsname()->release; scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); + } + + /* Copy the header into the buffer */ memcpy(buf + release_len, header, header_len); header_len += release_len; + /* for now on, the header will be persisted, and the body + * will be replaced + */ while (offset < body_len + userdata_len) { int this_header = header_len; int this_offset = 0; @@ -1183,6 +1144,64 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, } } +static void send_msg_no_fragmentation(struct netconsole_target *nt, + const char *msg, + const char *userdata, + int msg_len, + int release_len) +{ + static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + const char *release; + + if (release_len) { + release = init_utsname()->release; + + scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); + msg_len += release_len; + } else { + memcpy(buf, msg, msg_len); + } + + if (userdata) + msg_len += scnprintf(&buf[msg_len], + MAX_PRINT_CHUNK - msg_len, + "%s", userdata); + + netpoll_send_udp(&nt->np, buf, msg_len); +} + +/** + * send_ext_msg_udp - send extended log message to target + * @nt: target to send message to + * @msg: extended log message to send + * @msg_len: length of message + * + * Transfer extended log @msg to @nt. If @msg is longer than + * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with + * ncfrag header field added to identify them. + */ +static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, + int msg_len) +{ + char *userdata = NULL; + int userdata_len = 0; + int release_len = 0; + +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata = nt->userdata_complete; + userdata_len = nt->userdata_length; +#endif + + if (nt->release) + release_len = strlen(init_utsname()->release) + 1; + + if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) + return send_msg_no_fragmentation(nt, msg, userdata, msg_len, + release_len); + + return send_msg_fragmented(nt, msg, userdata, msg_len, release_len); +} + static void write_ext_msg(struct console *con, const char *msg, unsigned int len) { From patchwork Tue Sep 3 14:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788754 X-Patchwork-Delegate: kuba@kernel.org 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 1AAB980C02; Tue, 3 Sep 2024 14:08:13 +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=1725372495; cv=none; b=JH6tMgwVlAdM29pLC5CcBT54Mcr3t3OVqii4M16Eot9L2nY11IFazzyD9p4e23b25+i/q3V/GFRMO1kK3CD1R14P6GYZaQB0SIN0WZHIkPS6VJOaiUfSeg7sZsll8nuFNJw3bU7dLPv/u3UbwZFcJvk4WXxEN8pRwg3fvwl9/Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372495; c=relaxed/simple; bh=3ovEhmMlvcYRcWnnDEuDTXJGthcPintxc8nzp8yHidY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EzIwqNp5Pr/RqrSzAU04xhWZWL0pL7ZlKLeaRrc7YJOs31ImTeJGIeTPcbqp0bs+3EVEI/lbghBYd4ZM35rxzvahTQqyvkIAZSVik2+Xpg+GRvtMZQiP1Ri1fwDFFiIxyRqbIAYM01Iqp4I8ueG1nwfdZ4u4MiOzLAdMhP3sv54= 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-5c241feb80dso6043650a12.0; Tue, 03 Sep 2024 07:08:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372492; x=1725977292; 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=Z+1Bdy2XyVHRe091GnGCx4ZHzpI5u7L1trE9x+a694M=; b=BYon7jHX6bxRF7SY9BPwA+bMMPAgDceCYnY7zYhfXgvnMl6XhQtcFQb1KfEmgTKPDT +VIkWN2HURUpi3MnNunyWRCVzSwZbH1Z+2K5c7f63bM9AQfha0ngfPPIgipiGNPKeNm+ /mU0ITAqqjPt6HHa45rNUikYv8K4ajOMkM6j3Re/zWLjWQ3OnPbN2aD3/oFzBGfU/GlY r0/Bq1J2PV+m5fxr03BFjK5re9hGTvYakvepgtjJ+ELjPlKd6aQg6AIdTwbafTVodSv5 e50yGBlGeelBnMpvjVR66Y+c0LxeyGsrP2s1o9nMnDydN1ot3kp3NSD/B70DMlW8at3e 0X6Q== X-Forwarded-Encrypted: i=1; AJvYcCW9R8fm6MTh2yZEW3oBZZVKQ574t/pdB/UbLFF9yDh0655YtX+4ACKP811ZvCqDuqUbZQZqlty9@vger.kernel.org, AJvYcCX/t2WoiOC43p+pra+0HCYeSzuCeaePybt8apbMk+xnVc7RxHz9qceyq/iV01KFLMXgwejtu2SbNaVZ3r4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5MOtPAPB+XVcH6mlftPsFe4eld2MWA4GeTmIlP0Z9NKP3QBwD wMz1+pPaSEmek/audhwcSKQNcPPwgBAg+4DjWFSexbt1Ot1Pq69s X-Google-Smtp-Source: AGHT+IEKzEsyiRq6MPjsVF2z+mM1EQRTWtf+z8G5UEwPWdAZQtSkqAZ79eHK0cXFhHvgYZ+zP/b6Zw== X-Received: by 2002:a05:6402:5110:b0:5c2:467a:185d with SMTP id 4fb4d7f45d1cf-5c2467a1d6bmr10454135a12.0.1725372491688; Tue, 03 Sep 2024 07:08:11 -0700 (PDT) Received: from localhost (fwdproxy-lla-009.fbsv.net. [2a03:2880:30ff:9::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c226ccf406sm6570395a12.59.2024.09.03.07.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07: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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 4/9] net: netconsole: rename body to msg_body Date: Tue, 3 Sep 2024 07:07:47 -0700 Message-ID: <20240903140757.2802765-5-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org With the introduction of the userdata concept, the term body has become ambiguous and less intuitive. To improve clarity, body is renamed to msg_body, making it clear that the body is not the only content following the header. In an upcoming patch, the term body_len will also be revised for further clarity. The current packet structure is as follows: release, header, body, [msg_body + userdata] Here, [msg_body + userdata] collectively forms what is currently referred to as "body." This renaming helps to distinguish and better understand each component of the packet. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 176ce6c616cb..0d924fba5814 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1066,22 +1066,22 @@ static void send_msg_fragmented(struct netconsole_target *nt, { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; - const char *header, *body; - int header_len, body_len; + const char *header, *msgbody; + int header_len, msgbody_len; const char *release; if (userdata) userdata_len = nt->userdata_length; - /* need to insert extra header fields, detect header and body */ + /* need to insert extra header fields, detect header and msgbody */ header = msg; - body = memchr(msg, ';', msg_len); - if (WARN_ON_ONCE(!body)) + msgbody = memchr(msg, ';', msg_len); + if (WARN_ON_ONCE(!msgbody)) return; - header_len = body - header; - body_len = msg_len - header_len - 1; - body++; + header_len = msgbody - header; + msgbody_len = msg_len - header_len - 1; + msgbody++; /* * Transfer multiple chunks with the following extra header. @@ -1096,10 +1096,10 @@ static void send_msg_fragmented(struct netconsole_target *nt, memcpy(buf + release_len, header, header_len); header_len += release_len; - /* for now on, the header will be persisted, and the body + /* for now on, the header will be persisted, and the msgbody * will be replaced */ - while (offset < body_len + userdata_len) { + while (offset < msgbody_len + userdata_len) { int this_header = header_len; int this_offset = 0; int this_chunk = 0; @@ -1107,23 +1107,23 @@ static void send_msg_fragmented(struct netconsole_target *nt, this_header += scnprintf(buf + this_header, sizeof(buf) - this_header, ",ncfrag=%d/%d;", offset, - body_len + userdata_len); + msgbody_len + userdata_len); - /* Not all body data has been written yet */ - if (offset < body_len) { - this_chunk = min(body_len - offset, + /* Not all msgbody data has been written yet */ + if (offset < msgbody_len) { + this_chunk = min(msgbody_len - offset, MAX_PRINT_CHUNK - this_header); if (WARN_ON_ONCE(this_chunk <= 0)) return; - memcpy(buf + this_header, body + offset, this_chunk); + memcpy(buf + this_header, msgbody + offset, this_chunk); this_offset += this_chunk; } - /* Body is fully written and there is pending userdata to write, + /* Msg body is fully written and there is pending userdata to write, * append userdata in this chunk */ - if (offset + this_offset >= body_len && - offset + this_offset < userdata_len + body_len) { - int sent_userdata = (offset + this_offset) - body_len; + if (offset + this_offset >= msgbody_len && + offset + this_offset < userdata_len + msgbody_len) { + int sent_userdata = (offset + this_offset) - msgbody_len; int preceding_bytes = this_chunk + this_header; if (WARN_ON_ONCE(sent_userdata < 0)) From patchwork Tue Sep 3 14:07:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788756 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.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 5774C13AA5D; Tue, 3 Sep 2024 14:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372497; cv=none; b=e+AGNbvG4uDeEGUYfZBLyDkM9bcJwj2aQrEFkuVeB3ZNIzD4+fCUAW7/sfJlPpL7TBuWhxHGcygOP38AJC93gwS/5sRGlwDxgYs15WDVE5lMYGjT9rsp/eLaFQx/C3jMwiCtaYG7gpaUpXvb9520hbP6TzsRnRVCeJAgkNNn7Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372497; c=relaxed/simple; bh=RT+ZtNbVz+k4YKtOmnAxrSyApMOA6CWuXom1rHUUaoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H2gu02lfcgWaB9ye5yzzVqFyP8kCczB7s+d9zPMpwuhWcawReFTL5N7XKui8MsrvfU80h70nKZ42EHzYNY16pMUSP1x6mFogNk32jnRaExXFs/cmKMdMJ9Nqt7vsWSErztPSOVMpwOyjyj0uu86X9TILJjXoFx0vl8amXZEJWjM= 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.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-lf1-f54.google.com with SMTP id 2adb3069b0e04-5343eeb4973so8331984e87.2; Tue, 03 Sep 2024 07:08:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372494; x=1725977294; 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=9a3bvnFGteZy01tz5eBRywVwtJeJzGi3ecq0wcAC/lc=; b=SQzA7wgLRgvmpyJp/+q1TermaQ5QwwIdaexJhncYQfDz1a9jIppR/napyNuoCRX81i DLltrRWnkKIp39816TpQ4OyyhRr1KVUKMCYz/Sg/NeNluE/xydBMSblJJoTXkSPtogAx K47cf9Sr1FCNL9HKi4KlHz4DPdBR2+zhE8KUFFWymBDUdis/WPuc3tXsMQJiLO4I35Np rBHMxNSUkDUmCuypcwPaBLlvBxU6BZ1DPfsONNdtmXepKhgpZM84HukranVk97HzeQWA ugW6duDagtptYKIuK2PYT7kvrWVoEyrcqXaOl+sZQ310I3ShvwST9M72B8rMxP+8cy/q UZJw== X-Forwarded-Encrypted: i=1; AJvYcCVEbuKPIbu8RP9xKWEim97kSZABzQCtJoO9+9Fj2nqpzUQAfzF3Uf1tCERkL3Va6Dv8KttXZHtQxMoKc7k=@vger.kernel.org, AJvYcCWyufy4LfKrZ8fSK2mfQJGHAdVt7Y095rMCClweZXG7xW4tQiH40JgKiKzKRzUcHjjAzIwquXeG@vger.kernel.org X-Gm-Message-State: AOJu0Yx+0DoeBz1Mtk9gw8AJcr8wf/VmQIiN1Ih1caU/lBArrySTWEOU VeVdFDd8dgAQ7ZPdkfU7WSW/YKFkzMF5+QMVjSpwXQdKSS4laTpt X-Google-Smtp-Source: AGHT+IGDXmunrNnDp6tRowAWA27oZs93mImUdcRx6iZveB30iM8VRckYTkknizgNfIvYEwCr3bdj5A== X-Received: by 2002:a05:6512:3b14:b0:52e:9cc7:4462 with SMTP id 2adb3069b0e04-53546b1dea6mr13086642e87.11.1725372493755; Tue, 03 Sep 2024 07:08:13 -0700 (PDT) Received: from localhost (fwdproxy-lla-010.fbsv.net. [2a03:2880:30ff:a::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8988feb61fsm700575566b.10.2024.09.03.07.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07:08:13 -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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 5/9] net: netconsole: introduce variable to track body length Date: Tue, 3 Sep 2024 07:07:48 -0700 Message-ID: <20240903140757.2802765-6-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This new variable tracks the total length of the data to be sent, encompassing both the message body (msgbody) and userdata, which is collectively called body. By explicitly defining body_len, the code becomes clearer and easier to reason about, simplifying offset calculations and improving overall readability of the function. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 0d924fba5814..22ccd9aa016a 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1064,10 +1064,10 @@ static void send_msg_fragmented(struct netconsole_target *nt, int msg_len, int release_len) { + int header_len, msgbody_len, body_len; static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; const char *header, *msgbody; - int header_len, msgbody_len; const char *release; if (userdata) @@ -1096,10 +1096,11 @@ static void send_msg_fragmented(struct netconsole_target *nt, memcpy(buf + release_len, header, header_len); header_len += release_len; + body_len = msgbody_len + userdata_len; /* for now on, the header will be persisted, and the msgbody * will be replaced */ - while (offset < msgbody_len + userdata_len) { + while (offset < body_len) { int this_header = header_len; int this_offset = 0; int this_chunk = 0; @@ -1107,7 +1108,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, this_header += scnprintf(buf + this_header, sizeof(buf) - this_header, ",ncfrag=%d/%d;", offset, - msgbody_len + userdata_len); + body_len); /* Not all msgbody data has been written yet */ if (offset < msgbody_len) { @@ -1122,7 +1123,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, * append userdata in this chunk */ if (offset + this_offset >= msgbody_len && - offset + this_offset < userdata_len + msgbody_len) { + offset + this_offset < body_len) { int sent_userdata = (offset + this_offset) - msgbody_len; int preceding_bytes = this_chunk + this_header; From patchwork Tue Sep 3 14:07:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788757 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.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 2C69013C809; Tue, 3 Sep 2024 14:08:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372499; cv=none; b=NZDhFoupPRdnad0ybtcRsHy1+zUglwhu0HPFpVXRim1JnuUhftUDIeoH8rRWt5qDv4rMDUsUn5QUSDSMqdEVQlqWRBcBNIU2HpSccDHOSkUhLX/E/PszXsKxfKwgjW2PeCkl2cGiiVWrgb6PPrGyzX5q56DGxejVhjkZFhmotdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372499; c=relaxed/simple; bh=+M7qNuodo5sP01NttdMsZ+3umS8JGZnU5Tz9IBweLxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OilW8QTRUu3Q52qX33O1YGcKkCyY9l365cHLKuopFgxOPZzbd7juAaLCxW1P5Hr/mPLXsaDS+hkHWYaqe0l4taY5Q5TeW7gFqw5g0c//RR2n60d+0y29CPdTmCr9MUdNXYOFtLBice17V386qAPfu70z5rdxM8lki0cvPQjhtjE= 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.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-ej1-f44.google.com with SMTP id a640c23a62f3a-a866d3ae692so307864466b.0; Tue, 03 Sep 2024 07:08:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372496; x=1725977296; 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=gnViOBozUk8wAT0QTZsOHNZO3CKQ095N/f5pUDM9mxI=; b=C/M9qTyYxuriddn/3v39QPzD1PppMy26vyTyYgpHrZVA3ek7plIsMAy5J+aFIrHWWI LDALhjowS+9vdAAJhZxKBYsVXCzCqZIpVEG5XsF4Ny2TRQYcXOtVBP+nrj7Sy+JMkiZy 7zgm9TxXvcjQlnPdI3acPF9KbrI2WTwjwo+0lCQLHXpmoV76+TZ8DZCYFano0WPRawwf z3n76d9Prhh+ygPJjjanstPwukSybvHt8EbzEoJ3O73C7hT73DbcKymq1yoPe/wegQd+ DReqWXuzp07Zq43U0EvI4FnSqAZJUYr4xlsJ9KfrBGR/OkKEP6ePS6a231DOngDB1MV6 5iCw== X-Forwarded-Encrypted: i=1; AJvYcCUGgHNF10VWEN43epjyMhVdEJYuWi0yKxHAWc38CwZ6X2VfP4a6xABVzv809t2GlqAjol4af/1q@vger.kernel.org, AJvYcCXhg4A+c1nI9UCYGGTEf1mrTwAw0e8nmUGug4l/OJTIT/BTijVZCiISvgEodQcFllyyzLJSMIL20jwSJ/I=@vger.kernel.org X-Gm-Message-State: AOJu0YwvLECy3HTpPsaW3dBO7ElceEVOLlxxlQzPba5xIdpacY6UCOMN YN+YSARSXMR8VkfDsfWDqY+eXAJkXBjzMlua2ArnKZR+8NNpaL+M X-Google-Smtp-Source: AGHT+IEo+Yj6GkA9PjgFilL8U4exSqzOIEsEaenuHaaVd2L8e+E2fX7KfM3shNgq1QOzqbSAZ9tmpg== X-Received: by 2002:a05:6402:42c5:b0:5c2:6dcf:8e24 with SMTP id 4fb4d7f45d1cf-5c26dcf900emr1979397a12.18.1725372495895; Tue, 03 Sep 2024 07:08:15 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c226ccfe78sm6389290a12.69.2024.09.03.07.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07: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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 6/9] net: netconsole: track explicitly if msgbody was written to buffer Date: Tue, 3 Sep 2024 07:07:49 -0700 Message-ID: <20240903140757.2802765-7-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The current check to determine if the message body was fully sent is difficult to follow. To improve clarity, introduce a variable that explicitly tracks whether the message body (msgbody) has been completely sent, indicating when it's time to begin sending userdata. Additionally, add comments to make the code more understandable for others who may work with it. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 22ccd9aa016a..c8a23a7684e5 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1102,6 +1102,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, */ while (offset < body_len) { int this_header = header_len; + bool msgbody_written = false; int this_offset = 0; int this_chunk = 0; @@ -1119,12 +1120,22 @@ static void send_msg_fragmented(struct netconsole_target *nt, memcpy(buf + this_header, msgbody + offset, this_chunk); this_offset += this_chunk; } + + if (offset + this_offset >= msgbody_len) + /* msgbody was finally written, either in the previous messages + * and/or in the current buf. Time to write the userdata. + */ + msgbody_written = true; + /* Msg body is fully written and there is pending userdata to write, * append userdata in this chunk */ - if (offset + this_offset >= msgbody_len && - offset + this_offset < body_len) { + if (msgbody_written && offset + this_offset < body_len) { + /* Track how much user data was already sent. First time here, sent_userdata + * is zero + */ int sent_userdata = (offset + this_offset) - msgbody_len; + /* offset of bytes used in current buf */ int preceding_bytes = this_chunk + this_header; if (WARN_ON_ONCE(sent_userdata < 0)) From patchwork Tue Sep 3 14:07:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788758 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 37206153BD9; Tue, 3 Sep 2024 14:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372502; cv=none; b=TOT/N+l0M3IyqqztzSFMyCiDsG1X2JhecJS1lmVBwPpMtoWNDvdQAiGjlB0boGYpqrKBhagMzE2CvqjU5AgWDBtwfvlTSTp+G7DxRSZv+UgrALiJ4nxkLQvSy9R3/x3M/MZ6hTgITt9bQURcmxoMt1wmLxTVCaRsw/5o6iuvlh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372502; c=relaxed/simple; bh=t77M5W+kIgKwAFHJfmdNTV404RH2uKt2Eph1DvmLlvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZGFvhubmfkVaBRJBN6lgzt88/ff/sRgc01u4iK86ktV2/Q2jcbFSV0XUGAAV0YTK/FUA5XUrX6lPbtaEAchODNmyTzBJKgAgE47zpUXOxAmSgKS3TK/GxCYD2Evvus5otMOHwMxEWPx2Z/5D7wz23x2bAJccb3kEzJs++olPrjA= 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.52 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-f52.google.com with SMTP id a640c23a62f3a-a86a37208b2so618807666b.0; Tue, 03 Sep 2024 07:08:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372498; x=1725977298; 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=ih9PC9k6wPmVOkf+4o0P4GhHfg/wLrT8/7dcdLX3m48=; b=uNNfMLfJh+qzjqFdDkoaxkYHM+It4ttVLdD/Z6/kbGpSpG9ja1uKwrNKiLKPe9BMRq jQPNNX6IvSmZoGV1Z7cIsGImkfIyKkG4iOrntsvGrGrSFUICUec9ovewiYrtfFtj9MLl C2gXdfPy/I9XjeVsKM73h8leyH4PU07g71kg5zmgxey/1d+4Ks8pW8FTIJGilCvTlKJE 2DppVM8c/e+qG9y0WH5ddi9FBFsPDEoX87fu2LQUY9HmNjhS6VQCLDkuSs0/q00pdFx2 +pcl9qhHFOC/DNAFfuplaktLsXFQEy2CIb6F+kI4+ueRfpN5F4OYuA7WpkU5wBy47W+K lJ0A== X-Forwarded-Encrypted: i=1; AJvYcCUBVgH8syonh+g7hGv5IKZwf/ftR8ZplwXjX9vR2iHBldw6pH0DFx08Jd9AW9sfWnHmlL7Ft82c@vger.kernel.org, AJvYcCV6+F1Sj40r2AGotYmvMeiBh3XmEpTfluxgdU2N5QSLQG4XkTZvMYcNnpD+Z81kMCKEH/GfCD2g/HpDpKc=@vger.kernel.org X-Gm-Message-State: AOJu0YzJxwlwL+O3OflpqiLK0sSfjp/5wjS3m3gA8My+WPz0hpH9CSBU ZouJ2oKqVACkaTT4hzi3zh0bcc7E4+YQp9E7N2QZqphRspPxP1ui X-Google-Smtp-Source: AGHT+IFhF+NDnLoVyJiMayu8TUu9ISf293FaXzrkvwn/p3O9fIy1Tv62iaIDsLLSpj+1Tkyg4IP/0A== X-Received: by 2002:a17:907:948f:b0:a72:750d:ab08 with SMTP id a640c23a62f3a-a897f77eef9mr1232058566b.14.1725372498007; Tue, 03 Sep 2024 07:08:18 -0700 (PDT) Received: from localhost (fwdproxy-lla-114.fbsv.net. [2a03:2880:30ff:72::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891daeb1sm687879266b.169.2024.09.03.07.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07: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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 7/9] net: netconsole: extract release appending into separate function Date: Tue, 3 Sep 2024 07:07:50 -0700 Message-ID: <20240903140757.2802765-8-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Refactor the code by extracting the logic for appending the release into the buffer into a separate function. The goal is to reduce the size of send_msg_fragmented() and improve code readability. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index c8a23a7684e5..be23def330e9 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1058,6 +1058,14 @@ static struct notifier_block netconsole_netdev_notifier = { .notifier_call = netconsole_netdev_event, }; +static void append_release(char *buf) +{ + const char *release; + + release = init_utsname()->release; + scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); +} + static void send_msg_fragmented(struct netconsole_target *nt, const char *msg, const char *userdata, @@ -1068,7 +1076,6 @@ static void send_msg_fragmented(struct netconsole_target *nt, static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; const char *header, *msgbody; - const char *release; if (userdata) userdata_len = nt->userdata_length; @@ -1087,10 +1094,8 @@ static void send_msg_fragmented(struct netconsole_target *nt, * Transfer multiple chunks with the following extra header. * "ncfrag=/" */ - if (release_len) { - release = init_utsname()->release; - scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); - } + if (release_len) + append_release(buf); /* Copy the header into the buffer */ memcpy(buf + release_len, header, header_len); From patchwork Tue Sep 3 14:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788759 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79CA217B400; Tue, 3 Sep 2024 14:08:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372504; cv=none; b=Tg5ZbT+HbPskyBa+ltSE9bzJIoKIPzChZQoJF8wWHpsOuXRVvmYNORF+dA34ha4IOfQeR75c8t3kRIoF2RAifVE7HjhoABkOc4GaTMwQp5I2ZCW6PPR37DN134+//wXMSxLvR3qXn/KveLbzcZJjqwo/mKyf/eeGjR54Xq/2EpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372504; c=relaxed/simple; bh=EwPyVn/LijRNWgfvUoFawLHlvDU/Q0kM5J0vNfBSGS4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=swBtFgy7G8pZCnw6dPhT6injqPJTp+3GBwgILy+XKoXPTP31vlMXxdu9ZsUzQcujVGgcgegPTpOs51sqdVNs9ctMqVYGyV4MwmklDISZM+711SNolZklSO1tkrORdNLE0Mgyp6AnmHnEajTj2h3bD+3uF+yWBlYkE05mBLUr9GQ= 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.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c26b5f1ea6so1103881a12.0; Tue, 03 Sep 2024 07:08:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372501; x=1725977301; 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=GyGg8aTOO3rjIDlwIW/gKtwMJEaI7ylDHBkQwlwXwLo=; b=pFuF61kkUu5adZnmwsA1kgIFWLoBBt2MDEeLaKZAM0A8tU9uYI+W/2/P46Ik7gTYeD Hbr/sVZJxzdE283i1cbMkfK9hY2Fd3h4vuvtVh6gRgxFRHuUcriho8v7pOA0v7ZJbQS3 XL057G+qJYufbKAmqEcXD6BPJSR4fRHlHZ2Pe6O8+CCYzDhJb85WRG333uENuJv4ivyt Lxgqul9W3NpnsD3TSwKh7w1n+6oqZdw4278yBxkn0UNyx29YK6rT/qdmyFRjTiq5wih4 /6uc+rhZNdRKgbhild6mIH1DIdptpSH4lPrcGH5m2C/dHyTUv9uMkzuD3u2XPErEltSv hFmw== X-Forwarded-Encrypted: i=1; AJvYcCU/iN8vlzDjNy/bSufGg/uUvFJ/ytaXAxm7q3bd8gZBCVFEopkRONx8aaGUrvpXMD+3PSHC6dhJXEciQxE=@vger.kernel.org, AJvYcCUd5QVFrnYSkIFbaje9SqSqinORTvcoke1pyCb7SfW47Oje7R5r/PypXHFcjE2J6JCBWwtEDDdF@vger.kernel.org X-Gm-Message-State: AOJu0Yz4DRsfTUAlWbZ2p5G7imdHqoixoBsipRRXUOrpyWyGffElV7Eq FAqEawh0+ebCy0ehqVhc4ZIrCEYoEeBi/nG8Xd+PjGcuEKCzokE/ X-Google-Smtp-Source: AGHT+IHRz0DEsKKk3Yu4k5hHRRxtDJ0PwzGZu9VmHxqzv7RkeNsrPN1NeuNPP+ZfeWpMRcyLVxMkwg== X-Received: by 2002:a17:907:d08:b0:a86:6d39:cbfd with SMTP id a640c23a62f3a-a89fafad393mr579857366b.57.1725372500117; Tue, 03 Sep 2024 07:08:20 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891a3ceasm683462766b.115.2024.09.03.07.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07: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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 8/9] net: netconsole: split send_msg_fragmented Date: Tue, 3 Sep 2024 07:07:51 -0700 Message-ID: <20240903140757.2802765-9-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Refactor the send_msg_fragmented() function by extracting the logic for sending the message body into a new function called send_fragmented_body(). Now, send_msg_fragmented() handles appending the release and header, and then delegates the task of sending the body to send_fragmented_body(). Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 85 +++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index be23def330e9..81d7d2b09988 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1066,45 +1066,21 @@ static void append_release(char *buf) scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); } -static void send_msg_fragmented(struct netconsole_target *nt, - const char *msg, - const char *userdata, - 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 = 0, userdata_len = 0; - const char *header, *msgbody; - - if (userdata) - userdata_len = nt->userdata_length; - - /* need to insert extra header fields, detect header and msgbody */ - header = msg; - msgbody = memchr(msg, ';', msg_len); - if (WARN_ON_ONCE(!msgbody)) - return; - - header_len = msgbody - header; - msgbody_len = msg_len - header_len - 1; - msgbody++; - - /* - * Transfer multiple chunks with the following extra header. - * "ncfrag=/" - */ - if (release_len) - append_release(buf); + int body_len, offset = 0; + const char *userdata = NULL; + int userdata_len = 0; - /* Copy the header into the buffer */ - memcpy(buf + release_len, header, header_len); - header_len += release_len; +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata = nt->userdata_complete; + userdata_len = nt->userdata_length; +#endif body_len = msgbody_len + userdata_len; - /* for now on, the header will be persisted, and the msgbody - * will be replaced - */ + while (offset < body_len) { int this_header = header_len; bool msgbody_written = false; @@ -1112,7 +1088,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, int this_chunk = 0; this_header += scnprintf(buf + this_header, - sizeof(buf) - this_header, + MAX_PRINT_CHUNK - this_header, ",ncfrag=%d/%d;", offset, body_len); @@ -1161,6 +1137,41 @@ static void send_msg_fragmented(struct netconsole_target *nt, } } +static void send_msg_fragmented(struct netconsole_target *nt, + const char *msg, + int msg_len, + int release_len) +{ + static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + int header_len, msgbody_len; + const char *msgbody; + + /* need to insert extra header fields, detect header and msgbody */ + msgbody = memchr(msg, ';', msg_len); + if (WARN_ON_ONCE(!msgbody)) + return; + + header_len = msgbody - msg; + msgbody_len = msg_len - header_len - 1; + msgbody++; + + /* + * Transfer multiple chunks with the following extra header. + * "ncfrag=/" + */ + if (release_len) + append_release(buf); + + /* Copy the header into the buffer */ + memcpy(buf + release_len, msg, header_len); + header_len += release_len; + + /* for now on, the header will be persisted, and the msgbody + * will be replaced + */ + send_fragmented_body(nt, buf, msgbody, header_len, msgbody_len); +} + static void send_msg_no_fragmentation(struct netconsole_target *nt, const char *msg, const char *userdata, @@ -1216,7 +1227,7 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, return send_msg_no_fragmentation(nt, msg, userdata, msg_len, release_len); - return send_msg_fragmented(nt, msg, userdata, msg_len, release_len); + return send_msg_fragmented(nt, msg, msg_len, release_len); } static void write_ext_msg(struct console *con, const char *msg, From patchwork Tue Sep 3 14:07:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13788760 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 DE14D18786B; Tue, 3 Sep 2024 14:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372506; cv=none; b=gj65+711qAOg16oEk6+AoDbsHDKJI+aiCZDk03Tv9wH10PYTEv/J6QIlxOsJPaLih0jBg4rOV96ppPq5nZjLaR04j895TJj5AgXk0OU9caS/NP2dF/xIpFRHfw+nEb0rGCfyXaFfo5xO0r0PYVUI4E4v4qGhHVKsEADnoBqfOIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725372506; c=relaxed/simple; bh=g5KsSG49oRt33PNXtrGSdHt1Y9XV1D5tMkkzqy74KZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q/i2PLsNSl2hYC+blSuDVGNIJMxlm6jh0DJSEWEArrjJXSh1f0h4op3tbBdHJgtaOcI+s3Vbq1Ajjb7g7Qzj6BnV/wcgUw68uUZ2e8uwK+FD7CmOZUj8Y3Q+zVTTYUQa70rqv5iDW8ZfiT0eHJY7VWvjwXDN4+2VR9sN7/SCz4k= 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.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-ej1-f43.google.com with SMTP id a640c23a62f3a-a8682bb5e79so660789066b.2; Tue, 03 Sep 2024 07:08:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725372503; x=1725977303; 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=emDa0Cu4b8tMOUv9O7EFPrzNcNUmMKCv5Eqwf3IBEIQ=; b=fxhT8ZoScnAkFnholuUgPsU+zbsjc346GPaxBrI5t7v/80fwgv4A6fLy9uxvO6MU7Q 01+qA07xy7MYE/jP/V0U5ikaC7PZ2+PnVEdU8TH4nxDAyXrZ8qsjhxNiR55FLIv6GqBU u4sggryIDTEgY5wZgJ0i9bCszms3i5U0Xu3YcRNtj9epe2+rltJtyxqYMiq5UOlJfAG0 huKLWNBs3cYnlS609XZdWp2c0Q3dIFwSCgPDTKsVbrP3eZ2hZwkV2Rk8UTGQflwRf2PE XAZjEz/LozfxdGggDESqkrbCWBkE7zlpbyFP83nQUbWjCbl5PX1YjBGXkNLmZFjjiJap LQkA== X-Forwarded-Encrypted: i=1; AJvYcCUZdFvm07E68xXQgkv1H7LPwvFOgciN1myJNdCW36Wj+ko6LCv82Q4xITyHD6i/HZjIzYtpIUib@vger.kernel.org, AJvYcCX9CP7SFcGkmb0hn4oPyZQpeZ9VfYGTKMfIxGMkwRoUwTtDKXtXoL8tix4POHbR2uyqwQa4wba//R/RgMw=@vger.kernel.org X-Gm-Message-State: AOJu0YxhCSLcUeo8lSeMs8ghdOPp+bAAwTV437LZ3IonsLMFQG/0tR1A /mPRlwjsYay5VUITmQAPWvWO5/uGyvgxVgk2UjSTjKwjWkUNvVx+GFkZg7gM X-Google-Smtp-Source: AGHT+IFkmkShia1eyAD0c3UFZFyDkiSQA8XeGHbJAKGYaXtEY5HI+qywLz+EkCKLCWesAkMR8vX/Cw== X-Received: by 2002:a17:906:9c84:b0:a86:77ac:7e4e with SMTP id a640c23a62f3a-a89fae1b87emr558609366b.34.1725372502665; Tue, 03 Sep 2024 07:08:22 -0700 (PDT) Received: from localhost (fwdproxy-lla-114.fbsv.net. [2a03:2880:30ff:72::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989022481sm684087366b.86.2024.09.03.07.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 07:08:21 -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, thevlad@meta.com, max@kutsevol.com Subject: [PATCH net-next 9/9] net: netconsole: Fix a wrong warning Date: Tue, 3 Sep 2024 07:07:52 -0700 Message-ID: <20240903140757.2802765-10-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240903140757.2802765-1-leitao@debian.org> References: <20240903140757.2802765-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org A warning is triggered when there is insufficient space in the buffer for userdata. However, this is not an issue since userdata will be sent in the next iteration. Current warning message: ------------[ cut here ]------------ WARNING: CPU: 13 PID: 3013042 at drivers/net/netconsole.c:1122 write_ext_msg+0x3b6/0x3d0 ? write_ext_msg+0x3b6/0x3d0 console_flush_all+0x1e9/0x330 The code incorrectly issues a warning when this_chunk is zero, which is a valid scenario. The warning should only be triggered when this_chunk is negative. Signed-off-by: Breno Leitao Fixes: 1ec9daf95093 ("net: netconsole: append userdata to fragmented netconsole messages") --- drivers/net/netconsole.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 81d7d2b09988..83662a28dc00 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1124,8 +1124,13 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf, this_chunk = min(userdata_len - sent_userdata, MAX_PRINT_CHUNK - preceding_bytes); - if (WARN_ON_ONCE(this_chunk <= 0)) + if (WARN_ON_ONCE(this_chunk < 0)) + /* this_chunk could be zero if all the previous message used + * all the buffer. This is not a problem, userdata will be sent + * in the next iteration + */ return; + memcpy(buf + this_header + this_offset, userdata + sent_userdata, this_chunk);