From patchwork Thu Aug 8 12:25:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13757364 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 32BD818DF79; Thu, 8 Aug 2024 12:25:31 +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=1723119934; cv=none; b=uIXU37mDKzTIfYFa3xtEgG8AeWHquBzxxGWdl7qRDVCLjTlDhiOwDklfqKI/wLeZMuhEcuvDoB9+GW8mt8t8bNVVCQ9je3taKHwI/XSMolwS9S/UeB8CLaSyuw8iTlzSXQPqPX7Nt/B5qSgDec+QDqoAXHPkTw1MESB8GyxU44w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119934; c=relaxed/simple; bh=21NE45D05kd+63ejuqgp1rSDb0fTwjxyjDDlDLdKAD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GGAOKu1pvkOQOPhgwgns63l+eafqWUOJNDB/Pt08zj9++RbkNI8h/dOf8VuvfMJHwW2+Q8dr6fMpzpC2VYuyO9RDs5sxBCBLAv9wCaA0MboqRsIQQ22JH5Tq3X8DDIMFk9poWlkXuJSe1vrSzaL4XJx54XPuaTLhBL/s0hrdrv0= 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-a7a83a968ddso101058066b.0; Thu, 08 Aug 2024 05:25:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723119929; x=1723724729; 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=Oetxee9IMfZJjcpz+QqY4cG+Xmvizi5jKcfwfQxazyM=; b=IvwtdGR+KEV89yp9EiVqmHyoRTWP64BMJ1yE57IfQnfs+q5yZn8TLy0m8Pn8nV9Hy8 J/9H2YXsOWOPbLSQtmcJV4M1dmWD2rNYMlGM4XhSoy0AKBhfnr+eYmi0JHNN8uv7Gw6i O+DW4siqPlRMoewM1QJl0yYml9K90usyRi6UkcLcPS5Ccty2uxStBrcPXgHdPf7Sl2tP pHniLkQyA+UPIM+ijhzr6ee+poJfTiNrp8u1qXgVR3PJmntdLzy9kQE2nb1XqsaUoTtu RADexqIRcXjM9lKfbRd4JRVS4fXYB5pWyIrIyBah1u/E2UzjeonK8KJAV3RBV1+QtOvA lSAg== X-Forwarded-Encrypted: i=1; AJvYcCUEYrfKxVnqBkp4k4S1jTrXkj6JfYr3+l7TSbzzBwz4vKdsRF2nF+rQMmHbLQVYhS4r0RUKXcz624Nkqnns4bBBPjfy2gBebIC+5WtfVjO9GUnFxdwPndr692TpI6y3VswL9lMd X-Gm-Message-State: AOJu0Yw4a1nbTRPttrK9EPwmxd6y5HdzG+1xNAH9Gl7yK0Mlfle/n6oB Hdz60USB6Et3iFMG5n0teTgDgiPhxmaQo83FdGKBw9pkkJflD0Gx X-Google-Smtp-Source: AGHT+IFeyf71IZdc5qIXVp3SwJjPT4RpTtvIOqRQYR0rG7xzU0sBIJ8uS8MHh+0md/VzgBPFt6V6vg== X-Received: by 2002:a17:907:e698:b0:a7d:a29e:5c41 with SMTP id a640c23a62f3a-a8090dc0e7amr111218866b.40.1723119929307; Thu, 08 Aug 2024 05:25:29 -0700 (PDT) Received: from localhost (fwdproxy-lla-006.fbsv.net. [2a03:2880:30ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9ecabb2sm732411166b.214.2024.08.08.05.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 05:25:28 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next v2 1/5] net: netpoll: extract core of netpoll_cleanup Date: Thu, 8 Aug 2024 05:25:07 -0700 Message-ID: <20240808122518.498166-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240808122518.498166-1-leitao@debian.org> References: <20240808122518.498166-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 Extract the core part of netpoll_cleanup(), so, it could be called from a caller that has the rtnl lock already. Netconsole uses this in a weird way right now: __netpoll_cleanup(&nt->np); spin_lock_irqsave(&target_list_lock, flags); netdev_put(nt->np.dev, &nt->np.dev_tracker); nt->np.dev = NULL; nt->enabled = false; This will be replaced by do_netpoll_cleanup() as the locking situation is overhauled. Signed-off-by: Breno Leitao Reviewed-by: Rik van Riel --- include/linux/netpoll.h | 1 + net/core/netpoll.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index bd19c4b91e31..cd4e28db0cbd 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -64,6 +64,7 @@ int netpoll_setup(struct netpoll *np); void __netpoll_cleanup(struct netpoll *np); void __netpoll_free(struct netpoll *np); void netpoll_cleanup(struct netpoll *np); +void do_netpoll_cleanup(struct netpoll *np); netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb); #ifdef CONFIG_NETPOLL diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 55bcacf67df3..a58ea724790c 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -853,14 +853,20 @@ void __netpoll_free(struct netpoll *np) } EXPORT_SYMBOL_GPL(__netpoll_free); +void do_netpoll_cleanup(struct netpoll *np) +{ + __netpoll_cleanup(np); + netdev_put(np->dev, &np->dev_tracker); + np->dev = NULL; +} +EXPORT_SYMBOL(do_netpoll_cleanup); + void netpoll_cleanup(struct netpoll *np) { rtnl_lock(); if (!np->dev) goto out; - __netpoll_cleanup(np); - netdev_put(np->dev, &np->dev_tracker); - np->dev = NULL; + do_netpoll_cleanup(np); out: rtnl_unlock(); } From patchwork Thu Aug 8 12:25:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13757365 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.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 44BEC18E029; Thu, 8 Aug 2024 12:25:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119934; cv=none; b=MNAYjya55aCW7jCbp/GnSkMxQHhJZs5KmvnHJRf2ZKZxLYFR1VKomqEGcxdWoVZ678Kj4jZqFIAJgpas53kZgNpBcqOpFzreX/comuJsaHbY4BThiI9qAiBwj7e9Dmg4iwDiaIUbmQKt8+2gzUjSJuzb5p9u4u2i9XON2HY1ogU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119934; c=relaxed/simple; bh=uNPMmyO2gJaRHLVOL+/dVDGM5xdsI27/SpA8OMMZpis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CufOQ2xcRQjpmL9SrxS1+2Jws0gCA/WxBM0cyQw9e2KvPm8GhoEvYhacu5131/DuvXIMzGHKXUIC63oKm4AgzrHpebwhxllOv2bvotHJrQhfylpXZFh9jOKdsH7BgCVdLsk4L8cv9fd/TZVXuTWSFjiSzntQncYyz3q0tvSepEY= 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.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-ej1-f42.google.com with SMTP id a640c23a62f3a-a7aa086b077so88700766b.0; Thu, 08 Aug 2024 05:25:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723119932; x=1723724732; 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=9KhhVYpxynjfN7h4t5a1WXRfToCFw5V8n+fHSGGgbFM=; b=V0IxGmnWfeuy9qZDlW7gakVxPGeHDMkdnEmp3fErbgdoNurLm/hAnQZVYIdy6gWtDB UNOlc2gpVLo3zuX+F8YaA4vedY5Nz/pmQEkn5KdYDJS2EBuog6NYsGIyzVh0k15FMHpW aq7Lq9b/oq4t1nk6LmumLfRsjkBlGRzKgzTZGl8FvFq4b7aWl8XsEZP6bTIouPW1M3Yh U7shGAL8c1YQ6MX7SZDheBC1Mm+eaIrdpDtg5sMjFfrhabOAODdaOjt+4IoAA9HkeLvK iLOdKQenWBIgUndPC59AtZ5VWnjifh8AEXABB1bNapeK3I0/okPmrNog6PKt9cnUieFX bXjQ== X-Forwarded-Encrypted: i=1; AJvYcCVZr3Gq6IYgqm8oF0jycTlPqbR5eANoOcdjNWyxi3bPS3RgVGQKPmocfSyUOPL+wjLjj6L7QflIAq1X1SM+iE3U80w7cemdinTgnRYItlzk74Gus3XJauwWrKPlz5vEIgX971em X-Gm-Message-State: AOJu0Yx/xUGh0ghefPUpFo8T3+SUS/SiDS57Xi9Q45VlDUJwOtazPGXm cNBP4frfwgCgUD93g63zrkgrAffA6eQJXZvXDTRqhVu6rAco1d0/ X-Google-Smtp-Source: AGHT+IGE0v3w8mV3R26kohgNkIzIE2idRulRz3a9k+sHNowvjgfs8zGyd97KjnKKs5cGdjHupRKAGQ== X-Received: by 2002:a17:907:f756:b0:a77:e48d:bae with SMTP id a640c23a62f3a-a8090c6b6d6mr133994466b.28.1723119931268; Thu, 08 Aug 2024 05:25:31 -0700 (PDT) Received: from localhost (fwdproxy-lla-010.fbsv.net. [2a03:2880:30ff:a::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9d88741sm740044066b.150.2024.08.08.05.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 05:25:30 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next v2 2/5] net: netconsole: Correct mismatched return types Date: Thu, 8 Aug 2024 05:25:08 -0700 Message-ID: <20240808122518.498166-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240808122518.498166-1-leitao@debian.org> References: <20240808122518.498166-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 netconsole incorrectly mixes int and ssize_t types by using int for return variables in functions that should return ssize_t. This is fixed by updating the return variables to the appropriate ssize_t type, ensuring consistency across the function definitions. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index ffedf7648bed..b4d2ef109e31 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -336,7 +336,7 @@ static ssize_t enabled_store(struct config_item *item, struct netconsole_target *nt = to_target(item); unsigned long flags; bool enabled; - int err; + ssize_t err; mutex_lock(&dynamic_netconsole_mutex); err = kstrtobool(buf, &enabled); @@ -394,7 +394,7 @@ static ssize_t release_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); bool release; - int err; + ssize_t err; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -422,7 +422,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); bool extended; - int err; + ssize_t err; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -469,7 +469,7 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - int rv = -EINVAL; + ssize_t rv = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -492,7 +492,7 @@ static ssize_t remote_port_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - int rv = -EINVAL; + ssize_t rv = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -685,7 +685,7 @@ static ssize_t userdatum_value_store(struct config_item *item, const char *buf, struct userdatum *udm = to_userdatum(item); struct netconsole_target *nt; struct userdata *ud; - int ret; + ssize_t ret; if (count > MAX_USERDATA_VALUE_LENGTH) return -EMSGSIZE; From patchwork Thu Aug 8 12:25:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13757366 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FF2C18E044; Thu, 8 Aug 2024 12:25:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119937; cv=none; b=N1+wYKZJOMGzicGTgjm+Skk2+X33zwmjELhrIjsW+DXnvzj8VYA8/S8nX1BbIHOGBofwBJURVRt3TZLCiAJ983FMitgcl/pYUtdeBm9w5j0bqg3+t0MJsX7/MEigt82R1/nizZrA742CZGw5AStUYDwgiVwS4Ov2PfqYZmXMmLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119937; c=relaxed/simple; bh=nMXJenmlaaysU0JQZeH02SdjKwMQW62YdqF+yVs0neI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dAfGxRwN/DMlcFJY0vuFTspGx5R8MbeMeLXiyEx/jYmZkYDdlEKrcs9MNzpYXrEx5hsDR84eGPfwMbjKAU1Sg/bT0vLrLFAdlQjBLi2HI9lTM7IdygyGB3ZVkQ+OJA8se2b+oIHMdLgZZTsxBatwVcuT5QncljQ3cFF3VD9eX5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52efbb55d24so1567642e87.1; Thu, 08 Aug 2024 05:25:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723119933; x=1723724733; 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=9PEQPsLBLzyzK/qbQY0aDtr7vNIA7SxB8GpCInNcz9w=; b=la9nkJoKDPZS23B4FXu/EHw5DwY6phSz075KiZceO05iy67Qwm18JPPVY6KXJmj8l6 pEhgv1qL5rgcTKKjb0FFRtf1saseRo0t2/1jEqFQl5cx3G0qncKvreyiWCcV9V7JxOpU tu0ZwlbCmpPvyJBLOE48CpejYLrLWoWis3a6RMP9JNhanKv1e4TtykSn6ZsiL03Lqtr4 AfCltNz8IBUgEmbhUZ/haPQPKUTvs/tq69eBU54FnTArbsEY3OL3Va89MB6a5FJEXoxJ VwOV8J1iig/czrKFKgLRgDwGRLe9w0O5m6THtCHdY2Xr3AfwwZvTfc1s6cIPIqcNR2RQ op1w== X-Forwarded-Encrypted: i=1; AJvYcCX/Z5BAsH3tuvTgo/1isAd7c+d+QVHsHp7ebsk+wx24lN+SPN1mjHZlVNCGciC1ztUVd5Ns7LHq0+eUhDUzIY7pncDV4ISj+aGIO9jfHFWfi2eJqv1CPjjlZH2vVNA0CZlKm/Bw X-Gm-Message-State: AOJu0YxKGjvX5HK20ce3F/7R3JSHsrE8fWZaWSNrL+HQwdQ5rpufAWmF R7s3IToZqPS5/sZv3fKAoylFcn8X9a0RhWWn25ilP6cP4v1NsHwz X-Google-Smtp-Source: AGHT+IF8Pubd0VyAZXyy3Ohp4CO6hSPwIxATlhMwYmw8/uu0Bjz4xAzODW5HzfiAaOTfaoLrSYiQdg== X-Received: by 2002:a05:6512:31c6:b0:52c:dd94:bda9 with SMTP id 2adb3069b0e04-530e588c933mr1596695e87.56.1723119933087; Thu, 08 Aug 2024 05:25:33 -0700 (PDT) Received: from localhost (fwdproxy-lla-002.fbsv.net. [2a03:2880:30ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9bc3cd0sm751449866b.11.2024.08.08.05.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 05:25:32 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next v2 3/5] net: netconsole: Standardize variable naming Date: Thu, 8 Aug 2024 05:25:09 -0700 Message-ID: <20240808122518.498166-4-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240808122518.498166-1-leitao@debian.org> References: <20240808122518.498166-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 Update variable names from err to ret in cases where the variable may return non-error values. This change facilitates a forthcoming patch that relies on ret being used consistently to handle return values, regardless of whether they indicate an error or not. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index b4d2ef109e31..0e43b5088bbb 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -336,14 +336,14 @@ static ssize_t enabled_store(struct config_item *item, struct netconsole_target *nt = to_target(item); unsigned long flags; bool enabled; - ssize_t err; + ssize_t ret; mutex_lock(&dynamic_netconsole_mutex); - err = kstrtobool(buf, &enabled); - if (err) + ret = kstrtobool(buf, &enabled); + if (ret) goto out_unlock; - err = -EINVAL; + ret = -EINVAL; if (enabled == nt->enabled) { pr_info("network logging has already %s\n", nt->enabled ? "started" : "stopped"); @@ -365,8 +365,8 @@ static ssize_t enabled_store(struct config_item *item, */ netpoll_print_options(&nt->np); - err = netpoll_setup(&nt->np); - if (err) + ret = netpoll_setup(&nt->np); + if (ret) goto out_unlock; nt->enabled = true; @@ -386,7 +386,7 @@ static ssize_t enabled_store(struct config_item *item, return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return err; + return ret; } static ssize_t release_store(struct config_item *item, const char *buf, @@ -394,18 +394,18 @@ static ssize_t release_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); bool release; - ssize_t err; + ssize_t ret; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); - err = -EINVAL; + ret = -EINVAL; goto out_unlock; } - err = kstrtobool(buf, &release); - if (err) + ret = kstrtobool(buf, &release); + if (ret) goto out_unlock; nt->release = release; @@ -414,7 +414,7 @@ static ssize_t release_store(struct config_item *item, const char *buf, return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return err; + return ret; } static ssize_t extended_store(struct config_item *item, const char *buf, @@ -422,18 +422,18 @@ static ssize_t extended_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); bool extended; - ssize_t err; + ssize_t ret; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); - err = -EINVAL; + ret = -EINVAL; goto out_unlock; } - err = kstrtobool(buf, &extended); - if (err) + ret = kstrtobool(buf, &extended); + if (ret) goto out_unlock; nt->extended = extended; @@ -442,7 +442,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf, return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return err; + return ret; } static ssize_t dev_name_store(struct config_item *item, const char *buf, @@ -469,7 +469,7 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - ssize_t rv = -EINVAL; + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -478,21 +478,21 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, goto out_unlock; } - rv = kstrtou16(buf, 10, &nt->np.local_port); - if (rv < 0) + ret = kstrtou16(buf, 10, &nt->np.local_port); + if (ret < 0) goto out_unlock; mutex_unlock(&dynamic_netconsole_mutex); return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return rv; + return ret; } static ssize_t remote_port_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - ssize_t rv = -EINVAL; + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -501,14 +501,14 @@ static ssize_t remote_port_store(struct config_item *item, goto out_unlock; } - rv = kstrtou16(buf, 10, &nt->np.remote_port); - if (rv < 0) + ret = kstrtou16(buf, 10, &nt->np.remote_port); + if (ret < 0) goto out_unlock; mutex_unlock(&dynamic_netconsole_mutex); return strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return rv; + return ret; } static ssize_t local_ip_store(struct config_item *item, const char *buf, From patchwork Thu Aug 8 12:25:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13757367 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 1640B18E76D; Thu, 8 Aug 2024 12:25:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119938; cv=none; b=UywZEHvBIR/HI/j58CME52M5Y5h9esQ4yv85zOt4YSeEl13MDf1Dz7I3S4RJKmmJINJKjHuzQUONQP4FsywGrqdGLWnNjjT2MeBXToIZG74WOaRKHnSgP+/DulZKkCP3JGcku/OQvHAZX3NTEHQAMMpoepk/ZYFLlsKgZvjZy7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119938; c=relaxed/simple; bh=yTCdFjdAxkHmRI9W2QxfvJzihYP6I5yvau0CWdwzpiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r7c6pVrKHwbkndYEaQSMeLQgOAHneVOkryIkXx3gK1NVLDwY4CBzj9gQ2SgLGX4r2MjQqbQJRfjvGCF7eQt6tmCEZsrdSZOud+tmEqfDn1971e5zGrH1M7fuHC9f+2D026a1uU62V5mAxTLq6dlSpeqfShxgp6VFWKYYhxr9Ofk= 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.169 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-f169.google.com with SMTP id 38308e7fff4ca-2ef32fea28dso8631451fa.2; Thu, 08 Aug 2024 05:25:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723119935; x=1723724735; 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=kVSTja/S5Oln97aB6kFN81pfMbhMbR37wyk8sMAq4/s=; b=C0C1v9AzraEA/Yuf5C+oUj2yBqSY3Cx2DcAjyUNNvr24Vx1cv2g9SzxhbVLbGEUTUR pUI1yHTLc3sJEdziqH44hZ4yW1+1NO5vbY66yieCLIWMlov2Zfrk8NLPeSrTrlZ6qbou HyBs+HjJ5vjWr6rH6OkPY0e07xLzv+QSicuaRwYXQ9Ec/51J2TTKlTZENLikzxGbjf1k DRLA3Z9FaE9aM+ou96h6vfKsARkqA3UavaTtZ3IS4bfq0OmHVoEwqbIaNuIgqVg1fxHQ VilVQFLP3jKyZrBUa9Y5k9C9yMj+cUoka0G7t55mLCwEk00ZuPFbIVb6khyPht6SCmEZ Gxlw== X-Forwarded-Encrypted: i=1; AJvYcCXGoMvzwGNLFuMy/UkKDSIINL8iXUMJr9BMxvokb3pZlJs+kNAGHGm5fi8fPaoxeHIJg22Kjy+yhJPgWvXwFy2HByU2hz8+zdkhz8mzndfgOlGHqnhlBLJT3GuBZbaiXYTjZBs8 X-Gm-Message-State: AOJu0YyOQosTJIikFwIF+oXrQXCR3A4MqVdxTCcY/6kFxoiyRsgmzZGL uREFXsUkV+x9C7UidZuFqosuzGyMjQNZD9AfJhwp5AQcFVhpJ5is X-Google-Smtp-Source: AGHT+IGFgNFqEL3b5QRaV337DBZuadXMMUkXYWwk4fYy+LPCQ2hnTKikQuk7to/oKAdTxNIaC0H/4A== X-Received: by 2002:a05:6512:3b13:b0:530:aa3e:f397 with SMTP id 2adb3069b0e04-530e5892278mr1374301e87.43.1723119935013; Thu, 08 Aug 2024 05:25:35 -0700 (PDT) Received: from localhost (fwdproxy-lla-011.fbsv.net. [2a03:2880:30ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9ec8cd5sm733047666b.213.2024.08.08.05.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 05:25:34 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next v2 4/5] net: netconsole: Unify Function Return Paths Date: Thu, 8 Aug 2024 05:25:10 -0700 Message-ID: <20240808122518.498166-5-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240808122518.498166-1-leitao@debian.org> References: <20240808122518.498166-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 return flow in netconsole's dynamic functions is currently inconsistent. This patch aims to streamline and standardize the process by ensuring that the mutex is unlocked before returning the ret value. Additionally, this update includes a minor functional change where certain strnlen() operations are performed with the dynamic_netconsole_mutex locked. This adjustment is not anticipated to cause any issues, however, it is crucial to document this change for clarity. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 0e43b5088bbb..69eeab4a1e26 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -382,8 +382,7 @@ static ssize_t enabled_store(struct config_item *item, netpoll_cleanup(&nt->np); } - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -410,8 +409,7 @@ static ssize_t release_store(struct config_item *item, const char *buf, nt->release = release; - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -437,9 +435,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf, goto out_unlock; nt->extended = extended; - - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -481,8 +477,7 @@ static ssize_t local_port_store(struct config_item *item, const char *buf, ret = kstrtou16(buf, 10, &nt->np.local_port); if (ret < 0) goto out_unlock; - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -504,8 +499,7 @@ static ssize_t remote_port_store(struct config_item *item, ret = kstrtou16(buf, 10, &nt->np.remote_port); if (ret < 0) goto out_unlock; - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -515,6 +509,7 @@ static ssize_t local_ip_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -541,17 +536,17 @@ static ssize_t local_ip_store(struct config_item *item, const char *buf, goto out_unlock; } - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return -EINVAL; + return ret; } static ssize_t remote_ip_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -578,11 +573,10 @@ static ssize_t remote_ip_store(struct config_item *item, const char *buf, goto out_unlock; } - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return -EINVAL; + return ret; } static ssize_t remote_mac_store(struct config_item *item, const char *buf, @@ -590,6 +584,7 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); u8 remote_mac[ETH_ALEN]; + ssize_t ret = -EINVAL; mutex_lock(&dynamic_netconsole_mutex); if (nt->enabled) { @@ -604,11 +599,10 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf, goto out_unlock; memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN); - mutex_unlock(&dynamic_netconsole_mutex); - return strnlen(buf, count); + ret = strnlen(buf, count); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); - return -EINVAL; + return ret; } struct userdatum { @@ -700,9 +694,7 @@ static ssize_t userdatum_value_store(struct config_item *item, const char *buf, ud = to_userdata(item->ci_parent); nt = userdata_to_target(ud); update_userdata(nt); - - mutex_unlock(&dynamic_netconsole_mutex); - return count; + ret = count; out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; From patchwork Thu Aug 8 12:25:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13757368 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19BB518EFD7; Thu, 8 Aug 2024 12:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119942; cv=none; b=u0DgOUsj70J2kyHULAG8hdh88+uASmSDOBdX2cHWbY8zJrVvwxZGQHh2vZZ47uISbIoEPHoCexkKnGUiKSxXNg52qMFozykqnr5pp+QwZcyLU4MB3vjd/mu6EZC4l0wJtqpGW5Oy1cpKsrtpG1P/Sm4i0FKGmfz25mD8hkdoShE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119942; c=relaxed/simple; bh=5TqD4p19NXHKwsgMgVySYj01lP7UhZYaAEdv8KqjG/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q3pe5IG99XF0RASHzDdWvMix5FgWAvqx6fZWKiPOj+5r3tG8ck+XMYeTn5BmM5hMiuisTz0xo4y8MfFDyh+fN66x4eBS/KCFpJaozstXziNzfaYSqaQK/BW2awsB7lsbdz11N4LCufqwHO8SRb221HghZZyzaGppg5ifqSH7X+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-530e22878cfso803410e87.2; Thu, 08 Aug 2024 05:25:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723119937; x=1723724737; 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=qDfb+QvqWWfg/YQQb8fsjsoxliIhml6FJcmS7F0nZsY=; b=JwjaudSWSmQcWv2ktKX4P49fcvaGBSkfjCas6N/RGOEbS3tm/J9btSWw2VQs6PzXty +pPW2vWE5aLM5rnF2t5jaLdTZT59Muw40MXPpg1eVFVDZzUC+e/0r4faxPdkTOJzZRku e0XFisNpoax++XyfEoJCbMs6QzbaKy/XUlUjiJjLORyl3Z8SwRaRkZlxiT7H5bN2m+sI qqxgW0SzIlP6p7H2M7XgkreRaNl7ydzHGUMDxKtfk4nIFRmsd9aKpoWVQ8KBVuw2BxFj s9z0HdzXE/mk0GRhigrvvAMGTKXsoVEkpPpp8U7glxexPAMl11IxZL5cLcl0U6tKkkD2 YBoA== X-Forwarded-Encrypted: i=1; AJvYcCV2nWaZ+vc+bgzoM0HLrOO94/PI4brpCQmZ5LWymvyJ1qkqwikp+ngOeGqa8QJ2ywa1DtqqFI0hI9DZD7Dpb7u2hl7Fy478BFQlYx/TnbGhCxc9LL+Pe8F/Hu/1ySxGw8aSat4i X-Gm-Message-State: AOJu0Yz4y0jOYvbZ+ZA+5bKLTs4x2vUi9WpGD/TrnZCr9LwzdSoOkv/7 NEubaYtMUD/q2nlLiRUbrVsLaK8JUDZ5Mr5ysylb8F/OmdSjM3DK X-Google-Smtp-Source: AGHT+IHy8re8Bt/FC5pXPBNCLsUbzJ727eyE+CC9KA19wp3XS0Rh/A4SEdATD7QcVdAdgmDbVQhHfA== X-Received: by 2002:a05:6512:398a:b0:52e:f2a6:8e1a with SMTP id 2adb3069b0e04-530e5843ed7mr1183042e87.29.1723119937033; Thu, 08 Aug 2024 05:25:37 -0700 (PDT) Received: from localhost (fwdproxy-lla-115.fbsv.net. [2a03:2880:30ff:73::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bbb2d3518dsm609239a12.78.2024.08.08.05.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 05:25:36 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, davej@codemonkey.org.uk Subject: [PATCH net-next v2 5/5] net: netconsole: Defer netpoll cleanup to avoid lock release during list traversal Date: Thu, 8 Aug 2024 05:25:11 -0700 Message-ID: <20240808122518.498166-6-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240808122518.498166-1-leitao@debian.org> References: <20240808122518.498166-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 Current issue: - The `target_list_lock` spinlock is held while iterating over target_list() entries. - Mid-loop, the lock is released to call __netpoll_cleanup(), then reacquired. - This practice compromises the protection provided by `target_list_lock`. Reason for current design: 1. __netpoll_cleanup() may sleep, incompatible with holding a spinlock. 2. target_list_lock must be a spinlock because write_msg() cannot sleep. (See commit b5427c27173e ("[NET] netconsole: Support multiple logging targets")) Defer the cleanup of the netpoll structure to outside the target_list_lock() protected area. Create another list (target_cleanup_list) to hold the entries that need to be cleaned up, and clean them using a mutex (target_cleanup_list_lock). Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 83 ++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 69eeab4a1e26..43c29b15adbf 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -37,6 +37,7 @@ #include #include #include +#include MODULE_AUTHOR("Matt Mackall "); MODULE_DESCRIPTION("Console driver for network interfaces"); @@ -72,9 +73,16 @@ __setup("netconsole=", option_setup); /* Linked list of all configured targets */ static LIST_HEAD(target_list); +/* target_cleanup_list is used to track targets that need to be cleaned outside + * of target_list_lock. It should be cleaned in the same function it is + * populated. + */ +static LIST_HEAD(target_cleanup_list); /* This needs to be a spinlock because write_msg() cannot sleep */ static DEFINE_SPINLOCK(target_list_lock); +/* This needs to be a mutex because netpoll_cleanup might sleep */ +static DEFINE_MUTEX(target_cleanup_list_lock); /* * Console driver for extended netconsoles. Registered on the first use to @@ -210,6 +218,33 @@ static struct netconsole_target *alloc_and_init(void) return nt; } +/* Clean up every target in the cleanup_list and move the clean targets back to + * the main target_list. + */ +static void netconsole_process_cleanups_core(void) +{ + struct netconsole_target *nt, *tmp; + unsigned long flags; + + /* The cleanup needs RTNL locked */ + ASSERT_RTNL(); + + mutex_lock(&target_cleanup_list_lock); + list_for_each_entry_safe(nt, tmp, &target_cleanup_list, list) { + /* all entries in the cleanup_list needs to be disabled */ + WARN_ON_ONCE(nt->enabled); + do_netpoll_cleanup(&nt->np); + /* moved the cleaned target to target_list. Need to hold both + * locks + */ + spin_lock_irqsave(&target_list_lock, flags); + list_move(&nt->list, &target_list); + spin_unlock_irqrestore(&target_list_lock, flags); + } + WARN_ON_ONCE(!list_empty(&target_cleanup_list)); + mutex_unlock(&target_cleanup_list_lock); +} + #ifdef CONFIG_NETCONSOLE_DYNAMIC /* @@ -246,6 +281,19 @@ static struct netconsole_target *to_target(struct config_item *item) struct netconsole_target, group); } +/* Do the list cleanup with the rtnl lock hold. rtnl lock is necessary because + * netdev might be cleaned-up by calling __netpoll_cleanup(), + */ +static void netconsole_process_cleanups(void) +{ + /* rtnl lock is called here, because it has precedence over + * target_cleanup_list_lock mutex and target_cleanup_list + */ + rtnl_lock(); + netconsole_process_cleanups_core(); + rtnl_unlock(); +} + /* Get rid of possible trailing newline, returning the new length */ static void trim_newline(char *s, size_t maxlen) { @@ -376,13 +424,20 @@ static ssize_t enabled_store(struct config_item *item, * otherwise we might end up in write_msg() with * nt->np.dev == NULL and nt->enabled == true */ + mutex_lock(&target_cleanup_list_lock); spin_lock_irqsave(&target_list_lock, flags); nt->enabled = false; + /* Remove the target from the list, while holding + * target_list_lock + */ + list_move(&nt->list, &target_cleanup_list); spin_unlock_irqrestore(&target_list_lock, flags); - netpoll_cleanup(&nt->np); + mutex_unlock(&target_cleanup_list_lock); } ret = strnlen(buf, count); + /* Deferred cleanup */ + netconsole_process_cleanups(); out_unlock: mutex_unlock(&dynamic_netconsole_mutex); return ret; @@ -942,7 +997,7 @@ static int netconsole_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { unsigned long flags; - struct netconsole_target *nt; + struct netconsole_target *nt, *tmp; struct net_device *dev = netdev_notifier_info_to_dev(ptr); bool stopped = false; @@ -950,9 +1005,9 @@ static int netconsole_netdev_event(struct notifier_block *this, event == NETDEV_RELEASE || event == NETDEV_JOIN)) goto done; + mutex_lock(&target_cleanup_list_lock); spin_lock_irqsave(&target_list_lock, flags); -restart: - list_for_each_entry(nt, &target_list, list) { + list_for_each_entry_safe(nt, tmp, &target_list, list) { netconsole_target_get(nt); if (nt->np.dev == dev) { switch (event) { @@ -962,25 +1017,16 @@ static int netconsole_netdev_event(struct notifier_block *this, case NETDEV_RELEASE: case NETDEV_JOIN: case NETDEV_UNREGISTER: - /* rtnl_lock already held - * we might sleep in __netpoll_cleanup() - */ nt->enabled = false; - spin_unlock_irqrestore(&target_list_lock, flags); - - __netpoll_cleanup(&nt->np); - - spin_lock_irqsave(&target_list_lock, flags); - netdev_put(nt->np.dev, &nt->np.dev_tracker); - nt->np.dev = NULL; + list_move(&nt->list, &target_cleanup_list); stopped = true; - netconsole_target_put(nt); - goto restart; } } netconsole_target_put(nt); } spin_unlock_irqrestore(&target_list_lock, flags); + mutex_unlock(&target_cleanup_list_lock); + if (stopped) { const char *msg = "had an event"; @@ -999,6 +1045,11 @@ static int netconsole_netdev_event(struct notifier_block *this, dev->name, msg); } + /* Process target_cleanup_list entries. By the end, target_cleanup_list + * should be empty + */ + netconsole_process_cleanups_core(); + done: return NOTIFY_DONE; }