From patchwork Wed Aug 7 09:16: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: 13756063 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 0C8971C8245; Wed, 7 Aug 2024 09:17:18 +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=1723022244; cv=none; b=NMb/4rGeaL27/aoQwfcd8w1g61Qgvt41WEkdcl7VgcasO0O2/xIA/Jm61I/tbWLvOfE3DoncteBrJTsh8cQ3ZR4iUUXfii5TOVdBwziKXbUL2tSV+fnbkpGUMqb5UrsO6aZ+838woUO8NJQzPuySNGihFBM3uurib+AkNbOyeEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723022244; c=relaxed/simple; bh=21NE45D05kd+63ejuqgp1rSDb0fTwjxyjDDlDLdKAD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QhO0eASw/DbPshTKf0DylCdsW3aGy5QO8lcljuyFCn0sB+U3pXKcozcgJwho7opAzMgiiMLXbJYTk54x45x+0bUSq8wkdaDXbfFbqiZUlh9yw5AW78Ko2ETs/RVcZdDKbBLtr82Dea8Jv5vGFz4NYL81gWNWlCDA4Cj4Kq5flkM= 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-a7d2a9a23d9so181618866b.3; Wed, 07 Aug 2024 02:17:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723022237; x=1723627037; 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=YN5QMKlCsBnSuOpgJ77oBHz6SGUB0HrYrhL/IhN9m+ET7QKiiA+Qac6gTQC7NkiWoE eGvJPdWjqehga0ucRZW76fZOkcPYkiP9Cpje9ReDEq4DDKKJgDRWiOyu9R3fKBWzn+xA al6eIxYd5OY4IQq0PFFZZyC3+bFBstetNKMU2gB6cpetkYJUpE2MOR6p/2KwXSvzDYa/ 7wMz8h3cvkFhTMpJ3CuqGIpIUPZpHjvMNVHLQztX+7HfXXgAt1iRr1FcUxgYF0KaMaVs ZL1CRzz5b92ySAO7645MwwIGNKOdEvV6yGxVbQajGrf+mJAtZfZfmbzeIfsix+CodNXv ZJXg== X-Forwarded-Encrypted: i=1; AJvYcCWwkSCHatIUUIgLr/VuQ+Vsu0dIbcRKVCRTjYl1W0BfW6er0UPY5JEAzFLKtvbRikmAtZC3n6jU5bO3Vn1oB7fs5vXcw5ZMhCfsuSUxmKkrk7gm8Gl/yb/IVh//qSuUQ55LvZmF X-Gm-Message-State: AOJu0Yzg0Eh07MPzd2gyrnKR7KYykr9DVto84HXGZgM1EbzoUjO1BgZm vszty8arc1ajToFx4lLHW2XPam7rXRtZElrVff2jW4GpeGTrZZju X-Google-Smtp-Source: AGHT+IFIx6xcc3ECTYqC11IKERlOkkDRxzouV5s7MOaC1Tc5K2guT+j6e59/hrFaENLXJ9Kql6qApA== X-Received: by 2002:a17:907:7f15:b0:a7a:a3f7:389d with SMTP id a640c23a62f3a-a7dc4fae89emr1124999266b.31.1723022236981; Wed, 07 Aug 2024 02:17:16 -0700 (PDT) Received: from localhost (fwdproxy-lla-000.fbsv.net. [2a03:2880:30ff::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9ec8d7fsm622601166b.219.2024.08.07.02.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 02:17:16 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, 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: Wed, 7 Aug 2024 02:16:47 -0700 Message-ID: <20240807091657.4191542-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240807091657.4191542-1-leitao@debian.org> References: <20240807091657.4191542-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 Wed Aug 7 09:16: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: 13756062 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.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 08FC01CCB32; Wed, 7 Aug 2024 09:17:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723022242; cv=none; b=a1n4V1POzSXhU3z9eXwoTKviwYu7ZBO2Y876Gdsr6FFY79Ype1V26GvnyPlmClx3tRWxGsW/1Beqm7SbIVGcpvvbQpHzK/8D9ClCvh1OBtvlG3q6kpexqVJjjEn682kvdmC3bs4OLzi8i6Ol0cWLICzql2lkhWqBckefH5l6WMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723022242; c=relaxed/simple; bh=uNPMmyO2gJaRHLVOL+/dVDGM5xdsI27/SpA8OMMZpis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gkiG8K892hoxIlBY7Xb+99Z3hw/nGstLwhKpiJTWTsDbN0cZchIeQqV6jYnu8vtsh4bXWpyzTWeiw9We+LlsgUMKaWsnjhDZH29Em5Boc3MGpy3Fach+xjxwYGikYwwKib9Af1LfZGX89rq7padzDii9LKlCRYJWuZcDV35PdqU= 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.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-lf1-f43.google.com with SMTP id 2adb3069b0e04-52efc60a6e6so2417901e87.1; Wed, 07 Aug 2024 02:17:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723022239; x=1723627039; 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=DgKWBUy10qJpV1qBTzEo50GKZh6uNwi3Vab6RUXF0mOGlD38VwNDQTS4bXX2Vo1R3p L7Mt+XRiYMsGsvJwQyXizy4YeXhkcjhO6urbNDHvySaFSIuhRQ0QOGWmEIXOfDO7wg3N 0lgbaWNZrAa0UqP+ZlJ+TNd+mzkPun4QCVx6Gh07f//DAF6Znv+oS7eHI6d7H43phuGZ gyeY7MemZTzXt6/wbRh94qgFfOOiKARt4Aym1HEriYZFYenOABSoPsk3AjMyTo8qeS+L x0ehJTgZ0hrwtTT15RmlZ0JuzZr4PTIX0ktljZ/bXIoB/rOGccKnwHVndQ9hv+ex335B k6Gg== X-Forwarded-Encrypted: i=1; AJvYcCVuDMnF6vCjW993jr/qG2zZS3Pe4jE+vK+qK5rTVLj+2CO7+F/JISPnyJJpCMv9jz+iq9H53+A80Lhxo0ucSCWTy0FQ3KcgC1mxI8V89PciWArO1BUpTnpMNj+aK/fW+w9e6ZAU X-Gm-Message-State: AOJu0Yz7im10Ql5rQC/rVH5O1T/gvKTC9XpkbFTkYPGjYJns8p6E6lCs GdnPucwph7gElgE434/J5A5XtfjkssSVCHs27Q6S/lkEcuxeGCYl X-Google-Smtp-Source: AGHT+IEPbSN6BxLnELhXOZlhNhgjA1X84lLNkfmyodMQUmOQ8Yc+dd/5ewUQrwhxl6ob7NjepVPQjA== X-Received: by 2002:a05:6512:e9c:b0:52c:db22:efbf with SMTP id 2adb3069b0e04-530bb36f150mr12736359e87.16.1723022238688; Wed, 07 Aug 2024 02:17:18 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9bc3bb5sm623072566b.25.2024.08.07.02.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 02:17:18 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, 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: Wed, 7 Aug 2024 02:16:48 -0700 Message-ID: <20240807091657.4191542-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240807091657.4191542-1-leitao@debian.org> References: <20240807091657.4191542-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 Wed Aug 7 09:16: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: 13756064 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 C7C711D174D; Wed, 7 Aug 2024 09:17:23 +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=1723022245; cv=none; b=c8T+HRBioIiwm0bwHZ1/cPwKPXSmFyH+OOnZn0fPwG+1hvkUnltXriRLjKSlEdNKqzh8yGBTsTGWcLofrI7j31KIQPh3GAgDV8xA8DHnI5Ux4KSzhcXn+ASBnSGEZFOsU4ddyyo4wIFU2t8NIPqwvEuTj/4WOxskm4GNvlwSzmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723022245; c=relaxed/simple; bh=nMXJenmlaaysU0JQZeH02SdjKwMQW62YdqF+yVs0neI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b9qVnlElbCgxW+lsLUh54C+blWTuIy8xhBCw3Ej2C/99rV5+7laTbks1yHphrDVizlP8Cw4yY26AcQ9yyiLsoWdxbiNJmzN+AMR4h/MzK1VFejD6dtWzVIWkK0rNvPMGmKUVut7o4lLRC260vWnN+nqo4IFzvKcNqaiDb5PRhuc= 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-a7a81bd549eso126348966b.3; Wed, 07 Aug 2024 02:17:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723022242; x=1723627042; 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=FZIxFpMs4aVNSizyXjhvnUygxp3uleByH5UVh7F73FIogsXCHMO3z5xEbTIh44xtQo tDJj5Gett+MMxMbFfo80BasNPc5g9kczye1XON9y7H6tG5Ko6XWXJzRgYu4Pe7KM+g8s k4SV5lJchjGKk3dC+a4nUVhqCE08FTnbqG5tdgc9yql702AnhYcWlpdM1quKFv9y8O0Y eGby3HulU5pEk0bWfCHKgbLsxm1XwwjaiIPxUrNzX6mRG4eXBp/K0ga1FcNEFEsK04h0 tjO5XGlvrL/ikcqozpLsGdyLGZwdmvxNUugeQpmuPXrYADUUMgXEo09qWKvM/jqm7C+S DKPQ== X-Forwarded-Encrypted: i=1; AJvYcCWXttAVzgCTTS+8+5u4erelOcbGxn6ODqhHSDJX2tZDvsF8s0tv1Bg70AFYJQuf+Z4qPD9OeFxkcWP6PLtxoQx9s24ZZkLa67g0EV+YKrktAinLEdZRi1rwpdRTq6uPiuNJu08d X-Gm-Message-State: AOJu0Yxh6lKrkFKEmU5vt2Jep3RtkXMU5qmKX4FKC9JMQAn27L7A46Fn +1SCgDvRxG4tjAxOYJtp7YiHo0SxFH0If0S4WEyswamCZ2Vz3sqp X-Google-Smtp-Source: AGHT+IGYrrtSvr2abXg42nbVFcuir0UM8yhOizms5GHi/6Q5PfKCLl++XRJ41cKAbXlqIl2mKZstTA== X-Received: by 2002:a17:907:7b87:b0:a72:4281:bc72 with SMTP id a640c23a62f3a-a7dc51014efmr1346148666b.63.1723022240389; Wed, 07 Aug 2024 02:17:20 -0700 (PDT) Received: from localhost (fwdproxy-lla-002.fbsv.net. [2a03:2880:30ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9c0cc2asm622541566b.63.2024.08.07.02.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 02:17:20 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, 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: Wed, 7 Aug 2024 02:16:49 -0700 Message-ID: <20240807091657.4191542-4-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240807091657.4191542-1-leitao@debian.org> References: <20240807091657.4191542-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 Wed Aug 7 09:16: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: 13756065 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B91E81D1743; Wed, 7 Aug 2024 09:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723022245; cv=none; b=gqsuZmnqsK7Hv6g8wFL9KQzeGwmVJMz0lxH6MhZ216aSX3nqoSlVQzu6PZl170nHTui1D6w7HpLQHjZVgPsBJgyQcZJ1gjp6bHKsZoId1Ug3J74nGrEEPgxbWlfbvZ//AcJMWuwMnWOo56t/iA+LGtumiyb+OZVL/eNj7xXOnrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723022245; c=relaxed/simple; bh=yTCdFjdAxkHmRI9W2QxfvJzihYP6I5yvau0CWdwzpiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ucksGjj22EIp2fTHCL3IR8w/cf7Xn7lNySw3TTFXWli52EAMk2Xz875hkcRB1JjWuz6rrvW1KG/UshPeReZ+MubthqDfYWvj0h0c0MPn/HtkuUmi/FD8T79i1YNNhFMBd3JtM/IqcUylSuy5CSCehVi3ALEs4dhDuvBspI3YNx8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a7b2dbd81e3so207381566b.1; Wed, 07 Aug 2024 02:17:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723022242; x=1723627042; 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=AxWgYZ3PKb57vRCyKU0CJAiTdqiY4gY2FiiazwfLXcE7B1zRF09xFVVm/20X6S5pVK 7tCt4Vn92gST9KbJ2bQGgK68hrKdvwQHdcjQarjtzf47GEZgnT7V7HOJAuxOxTKsjOxO lWNm7HNJTDBPZ7YvJgk7q7lVh2tH4UU9X1syW3idr28iZJgOIEoRvEEYPo0ZSWfka00q 3PwVnp6a/pbDUfoEbGssDUejdk1FyM/3e2qOcICAvT4hEMztBe49JBprDBdYazP1+Uf3 I0wie2HvMj6HCnSSORSbXEesBXbq5dB4c06U7jeaziGygMloKFlt54tKiJ7NVtDflvcS 7iqA== X-Forwarded-Encrypted: i=1; AJvYcCX5/TIY1GHx4GYTx77L0NQEiR25snejZJ42EjTnp+rYbqGzHPc8Ap2OP2cg51DHflgtoZz121eKc4d+iQKORs8sAKAx1MnSiQDCJorsIhkaUz6rHEjGt4+ZEZ9ds0xSSmpgHz/4 X-Gm-Message-State: AOJu0YzUmtM7KZfMvyr4O7ALnAYIG81TdQqsDC/gHXesNrFx7pq3qxJW lKjLC57/A6V1xENFR0ImV1SZUAu6qrbS6WJUboI5mJ+1ISIgUflm X-Google-Smtp-Source: AGHT+IGVdO3FE6qqMZblUZHBU3xxPe+gkyCq9/NsIDkefGo5oJJGZifguTy0GzwccAd+JkLcECzD6g== X-Received: by 2002:a17:907:968b:b0:a7a:952b:95ae with SMTP id a640c23a62f3a-a7dc509f900mr1346526566b.47.1723022242011; Wed, 07 Aug 2024 02:17: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-a7dc96c8b49sm621728666b.0.2024.08.07.02.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 02:17:21 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, 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: Wed, 7 Aug 2024 02:16:50 -0700 Message-ID: <20240807091657.4191542-5-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240807091657.4191542-1-leitao@debian.org> References: <20240807091657.4191542-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 Wed Aug 7 09:16: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: 13756066 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5D5E1D278E; Wed, 7 Aug 2024 09:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723022249; cv=none; b=RKj6mYSAtJnhlGPFnNl3OEnjsvisbKa/9JTIz/KsiUgMLd2mQz5DXI5HFDfvAOffej+gmVLT+pNhkjUlcFgKeepelNtWnwm/bur257oGSIPcgRaZt0/47UXDuI6BYwCt8PdaNnZSXvNEtC/DD7Ai2xAhM2JcgSjdGWHFNTtpBd4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723022249; c=relaxed/simple; bh=DjV5baq+7emiAISHcO2h0Kq+q/DrmV9u/Jbl/R+3iow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FINMRp9sflDxzEaeSvJk8+BHCoV/QuURR7dOouvArTDkEs+Pa24tZj5jw97wkO0FChXA4LLRYTes8UvLjbB+lbKCKFYSzbD/Ai9X9IbU/keav6OLwopoKGt8iZA0LsfOaHMkyrp9lvE7o8bV4hg1fRZs/KPBH3NNIJ+wlWRWqz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5b8c2a611adso2159308a12.1; Wed, 07 Aug 2024 02:17:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723022244; x=1723627044; 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=+Xn0gxmB3HHe9Nvo5kpK9WFXqf56bqn8ETol42PpP3k=; b=IzcFXJoZE9IcOscF65C5O7uFWLuspHqIDE3LU22TMSexNaUQU9sxv3Uam3sJ2YtuTK ZtOn7/bK1/7z7nPr1vcSewuxNKwVN32m0N/SIITtb5tyv1o2aucBNypGm4ykiUKjqnz/ 7a+BcJ0d4e66iNJdGfpEKoaPUXMFVzqDzI2/Q8dssgno6YDwbfr4JI0xGrZBlQBf1tkH v5PovFmRUMWh6r08w9vZi+OlgtcUyDitNIisgq6COBwRwR9oqRypzQhBj/c99eD3yEAW 692NYfeAS6pIuP1A6vHGVkq3/oqx7eXl95rPskn3EyFdyMioM2GUO3LLM8PgRMezRm1d 8l4Q== X-Forwarded-Encrypted: i=1; AJvYcCUf6bMSUFmNSaJ3I9nFRGcBb3btYwCzN+r7KdZAz7I2JbdI5wsoWiEdsObixBd9c3yBULMIqYEdkuBPaAWyRMSBKC06La0DGlEopM6OQUXzdAg1D2j+8Mxo/f0nhI/0RQVxFjRd X-Gm-Message-State: AOJu0YxpTFV322I+bBT++vhQceJy+LmardnMgzKXdGLpwQnH/u92m5JZ QFTNNIy9ryrbn9utnYMCt6FbRfoRYLbT25C9jXrjxpsPNR19Oj3C X-Google-Smtp-Source: AGHT+IHzdDAFb8v0s0v7I8cBUsIbYqlqHNziXDCUKd32gALUFrd9ILKr+uu4L9hrm7Dn7LT39dOKlQ== X-Received: by 2002:a50:8ad0:0:b0:5b9:1009:f42d with SMTP id 4fb4d7f45d1cf-5b91009f9femr9791270a12.32.1723022243846; Wed, 07 Aug 2024 02:17:23 -0700 (PDT) Received: from localhost (fwdproxy-lla-002.fbsv.net. [2a03:2880:30ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b839b2b556sm6794533a12.25.2024.08.07.02.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 02:17:23 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thevlad@fb.com, 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: Wed, 7 Aug 2024 02:16:51 -0700 Message-ID: <20240807091657.4191542-6-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240807091657.4191542-1-leitao@debian.org> References: <20240807091657.4191542-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..70e85b1a4ee8 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,46 @@ 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); +} + +/* 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(); +} + #ifdef CONFIG_NETCONSOLE_DYNAMIC /* @@ -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; }