From patchwork Sun May 29 12:50:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 16310 X-Patchwork-Delegate: mareklindner@neomailbox.ch Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 136538175C; Sun, 29 May 2016 14:50:34 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=narfation.org Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=VZVHXuVL; dkim-adsp=fail (unprotected policy); dkim-atps=neutral Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=79.140.41.39; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=pass header.from=narfation.org Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id B632C80778 for ; Sun, 29 May 2016 14:50:31 +0200 (CEST) Received: from sven-desktop.home.narfation.org (p200300C593C609FD0000000000002E16.dip0.t-ipconnect.de [IPv6:2003:c5:93c6:9fd::2e16]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 22C0F1100E7; Sun, 29 May 2016 14:50:31 +0200 (CEST) Authentication-Results: v3-1039.vlinux.de; dmarc=none header.from=narfation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=narfation.org; s=20121; t=1464526231; bh=JQUH85SupCwbAN/JzVpvkDcbuB3lzeH7ZXTbVm0ri+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VZVHXuVLOQifRjOCKd3ZVVFWhjrnqDUbuG2R8Vr4QVB2pM81+He9leKtD1x6ZCFQ5 i/FRrGltvEePujJbPsAkzDcds34HWYJlXcWazVlNCquaqvylgPGdmOneN9ng/46siO rFN7aEISEHpeHygTmgw19b6mqB20JAlhKOZ5wDdI= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 29 May 2016 14:50:25 +0200 Message-Id: <1464526225-10178-1-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464439110-3113-1-git-send-email-sven@narfation.org> References: <1464439110-3113-1-git-send-email-sven@narfation.org> Subject: [B.A.T.M.A.N.] [PATCH 6/6] batman-adv: Avoid sysfs name collision for netns moves X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" The kobject_put is only removing the sysfs entry and corresponding entries when its reference counter becomes zero. This tends to lead to collisions when a device is moved between two different network namespaces because some of the sysfs files have to be removed first and then added again to the already moved sysfs entry. WARNING: CPU: 0 PID: 290 at lib/kobject.c:240 kobject_add_internal+0x5ec/0x8a0 kobject_add_internal failed for batman_adv with -EEXIST, don't try to register things with the same name in the same directory. But the caller of kobject_put can already remove the sysfs entry before it does the kobject_put. This removal is done even when the reference counter is not yet zero and thus avoids the problem. Signed-off-by: Sven Eckelmann --- Minor addition while testing the patchset with namespaces + CONFIG_DEBUG_KOBJECT_RELEASE=y Idea was taken from bridge del_nbp(...) net/batman-adv/sysfs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c index 9ca90d1..a146fcf 100644 --- a/net/batman-adv/sysfs.c +++ b/net/batman-adv/sysfs.c @@ -713,6 +713,8 @@ rem_attr: for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr)); + kobject_uevent(bat_priv->mesh_obj, KOBJ_REMOVE); + kobject_del(bat_priv->mesh_obj); kobject_put(bat_priv->mesh_obj); bat_priv->mesh_obj = NULL; out: @@ -727,6 +729,8 @@ void batadv_sysfs_del_meshif(struct net_device *dev) for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr)); + kobject_uevent(bat_priv->mesh_obj, KOBJ_REMOVE); + kobject_del(bat_priv->mesh_obj); kobject_put(bat_priv->mesh_obj); bat_priv->mesh_obj = NULL; } @@ -782,6 +786,8 @@ rem_attr: for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr) sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr)); + kobject_uevent(vlan->kobj, KOBJ_REMOVE); + kobject_del(vlan->kobj); kobject_put(vlan->kobj); vlan->kobj = NULL; out: @@ -801,6 +807,8 @@ void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv, for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr) sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr)); + kobject_uevent(vlan->kobj, KOBJ_REMOVE); + kobject_del(vlan->kobj); kobject_put(vlan->kobj); vlan->kobj = NULL; } @@ -1103,6 +1111,8 @@ out: void batadv_sysfs_del_hardif(struct kobject **hardif_obj) { + kobject_uevent(*hardif_obj, KOBJ_REMOVE); + kobject_del(*hardif_obj); kobject_put(*hardif_obj); *hardif_obj = NULL; }