Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2134017ybp; Sat, 12 Oct 2019 04:51:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbbF95oK5HUtFjA4XudDNjDY5Kw9XxGwBlBJJs12YSfA+8rOz0MltCeYft+XA2Anl8ZW72 X-Received: by 2002:a17:906:3053:: with SMTP id d19mr19242070ejd.109.1570881097500; Sat, 12 Oct 2019 04:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570881097; cv=none; d=google.com; s=arc-20160816; b=q3I8M/yBilkuYWvHiBVyWYVW9ytWGY9z9rLxqOmuBsYn9DaW00z0y4mc7qY8LArblr eS4qZRTYP4On8U0+/UJaNv1uYx3ECPawxu2oa2vGnnqQg3P7WFgEGEYGZzpj0sief28a ZkwBP7XHBymnpsuf1a57jv+MAu7XlMa6YOuAee7FAwjgti6zv5dhSGl635g3s8DbGKrP ml73ToZzZfQToGKdR6pKUElyK5+X8Oq9o+xPorpUl3Ox7z3FLvL5PdVfGnhCt8eWeF08 plkkO/vrblgJbqbzbBAEzjfFxcjczmbQXe4UjrOYy5nyZsAX6SrKTwlA3f+FANFLovpJ px3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=y11pBCe1CKAjsPMn1sqz/oYdoQIUENwcNyPETlfS7fU=; b=e6t3OhTLDnsZNLu6KYYeCXIDnZK+qp+Gdhfb3Ac7R8e3wSMXJiwdFeA/e3B00C3EiW AHYjLWDFKURBjbT7yLdTNfqHRodbGGB5I1mvD+A2P3SIP+criLeVx9Dqa9w8ZqEZ4yzk lV6lIRtoSjjXt8Yh2IhwVqv4SBgvw05/JVakhn6MP65zZohKRTr/M64yi+d4fmEJ9V+8 V6s3ztcBH0PKprlcx3qjeim+4L4WkYffcF51toSf1by31P7b7oetakg+JKbGV092VYvA b7OdX2591eMudnkLpl/3M1xoj+soizN6/p3LstdhX2YYKy3P3qniQ1yLLPXcihB7Ajw6 Ov8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ITLTft8A; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si7156237eje.338.2019.10.12.04.50.58; Sat, 12 Oct 2019 04:51:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ITLTft8A; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727594AbfJLLoZ (ORCPT + 99 others); Sat, 12 Oct 2019 07:44:25 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39580 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727083AbfJLLmZ (ORCPT ); Sat, 12 Oct 2019 07:42:25 -0400 Received: by mail-lj1-f193.google.com with SMTP id y3so12261395ljj.6; Sat, 12 Oct 2019 04:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=y11pBCe1CKAjsPMn1sqz/oYdoQIUENwcNyPETlfS7fU=; b=ITLTft8A4VLVxPboRseeDV2uqnjEVCF9cadQ+LcoeaUZcDpo3zF2O9AINuaIkyND6L /1/lA/sScUZblZRjpvdoky/Bc0HYMr8YCUQGgpgqnrRY65N1GZVfSSQ78f+qAElw2Dcw DpuohN20RNKfrIsPyxBYk7hT79xOqI9tvYT1+X+BNOTbTfNkBjP6b6G0kdC0ssvHjX6B IA5f5o8aDKnxfsB3SI8fQrvnwyu1xEhuhtjWrELnT7hja3YhnG82AkmLuU8p6RHYDhBV Qi+I8f0icJ5AmGNR2cMB66fu4D6Xg1X3oTfLzFSpI28qfPjZjYhC5vwmGxKPO0mpL+Y5 kp/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=y11pBCe1CKAjsPMn1sqz/oYdoQIUENwcNyPETlfS7fU=; b=tyLUG+bF+c4MBlPxkP0ILpiTFZiualTP+VmkX7Fb/pxzusKjZLt7wZTHx9OROHK5Os Sdg9jZ+yZDIXjx32FEWBtIU6rz+vDexVs0/QxYgS7HChRYb2OfnZYtB4tvC/2s51ZRLC PgPQSeIP+yBsGihs669dUCPFWqSb5cytKKPlqxFi3Vdb8NYywT20o1e2luQ6o9fcVNUf uL6OqAFNlUgqT0qmDpPJEzUEYXHDYikpnoiRSLdvFIqqAY89F2N/GSpzNF91bfDLyYI7 zoOOgLS7ctxTpGVo9MvGscyWu7lsS611G7XUfpCHrZ7fqi+kYkcFKypKdH6zbFrvMaTu 5LlA== X-Gm-Message-State: APjAAAWIgTpXjpZ/KU/uTan6J+ILQX7J24jzwWAp/NEENV0rTXOpeQ/p ld57swf8RVrRXSIRzaWw6Yr3rrEIq279Jumq8wE= X-Received: by 2002:a2e:9695:: with SMTP id q21mr12014562lji.105.1570880540837; Sat, 12 Oct 2019 04:42:20 -0700 (PDT) MIME-Version: 1.0 References: <20190928164843.31800-1-ap420073@gmail.com> <20190928164843.31800-2-ap420073@gmail.com> <20191010101925.GA93190@bistromath.localdomain> In-Reply-To: <20191010101925.GA93190@bistromath.localdomain> From: Taehee Yoo Date: Sat, 12 Oct 2019 20:42:09 +0900 Message-ID: Subject: Re: [PATCH net v4 01/12] net: core: limit nested device depth To: Sabrina Dubroca Cc: David Miller , Netdev , linux-wireless@vger.kernel.org, Jakub Kicinski , Johannes Berg , j.vosburgh@gmail.com, vfalico@gmail.com, Andy Gospodarek , =?UTF-8?B?SmnFmcOtIFDDrXJrbw==?= , Roopa Prabhu , saeedm@mellanox.com, manishc@marvell.com, rahulv@marvell.com, kys@microsoft.com, haiyangz@microsoft.com, Stephen Hemminger , sashal@kernel.org, hare@suse.de, varun@chelsio.com, ubraun@linux.ibm.com, kgraul@linux.ibm.com, Jay Vosburgh , Cody Schuffelen , bjorn@mork.no Content-Type: text/plain; charset="UTF-8" Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Thu, 10 Oct 2019 at 19:19, Sabrina Dubroca wrote: > Hi Sabrina, Thank you for review and testing! > 2019-09-28, 16:48:32 +0000, Taehee Yoo wrote: > > @@ -6790,23 +6878,45 @@ int netdev_walk_all_lower_dev(struct net_device *dev, > > void *data), > > void *data) > > { > > - struct net_device *ldev; > > - struct list_head *iter; > > - int ret; > > + struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV + 1]; > > + struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1]; > > + int ret, cur = 0; > > > > - for (iter = &dev->adj_list.lower, > > - ldev = netdev_next_lower_dev(dev, &iter); > > - ldev; > > - ldev = netdev_next_lower_dev(dev, &iter)) { > > - /* first is the lower device itself */ > > - ret = fn(ldev, data); > > - if (ret) > > - return ret; > > + now = dev; > > + iter = &dev->adj_list.lower; > > > > - /* then look at all of its lower devices */ > > - ret = netdev_walk_all_lower_dev(ldev, fn, data); > > - if (ret) > > - return ret; > > + while (1) { > > + if (now != dev) { > > + ret = fn(now, data); > > + if (ret) > > + return ret; > > + } > > + > > + next = NULL; > > + while (1) { > > + ldev = netdev_next_lower_dev(now, &iter); > > + if (!ldev) > > + break; > > + > > + if (!next) { > > + next = ldev; > > + niter = &ldev->adj_list.lower; > > + } else { > > + dev_stack[cur] = ldev; > > + iter_stack[cur++] = &ldev->adj_list.lower; > > + break; > > + } > > + } > > + > > + if (!next) { > > + if (!cur) > > + return 0; > > Hmm, I don't think this condition is correct. > > If we have this topology: > > > bridge0 > / | \ > / | \ > / | \ > dummy0 vlan1 vlan2 > | \ > dummy1 dummy2 > > We end up with the expected lower/upper levels for all devices: > > | device | upper | lower | > |---------+-------+-------| > | dummy0 | 2 | 1 | > | dummy1 | 3 | 1 | > | dummy2 | 3 | 1 | > | vlan1 | 2 | 2 | > | vlan2 | 2 | 2 | > | bridge0 | 1 | 3 | > > > If we then add macvlan0 on top of bridge0: > > > macvlan0 > | > | > bridge0 > / | \ > / | \ > / | \ > dummy0 vlan1 vlan2 > | \ > dummy1 dummy2 > > > we can observe that __netdev_update_upper_level is only called for > some of the devices under bridge0. I added a perf probe: > > # perf probe -a '__netdev_update_upper_level dev->name:string' > > which gets hit for bridge0 (called directly by > __netdev_upper_dev_link) and then dummy0, vlan1, dummy1. It is never > called for vlan2 and dummy2. > > After this, we have the following levels (*): > > | device | upper | lower | > |----------+-------+-------| > | dummy0 | 3 | 1 | > | dummy1 | 4 | 1 | > | dummy2 | 3 | 1 | > | vlan1 | 3 | 2 | > | vlan2 | 2 | 2 | > | bridge0 | 2 | 3 | > | macvlan0 | 1 | 4 | > > For dummy0, dummy1, vlan1, the upper level has increased by 1, as > expected. For dummy2 and vlan2, it's still the same, which is wrong. > > > (*) observed easily by adding another probe: > > # perf probe -a 'dev_get_stats dev->name:string dev->upper_level dev->lower_level' > > and running "ip link" > > Or you can just add prints and recompile, of course :) > Thank you so much, I found a bug very easily with your test config. I will fix this bug in a v5 patch. > > + next = dev_stack[--cur]; > > + niter = iter_stack[cur]; > > + } > > + > > + now = next; > > + iter = niter; > > } > > > > return 0; > > -- > Sabrina Thank you, Taehee Yoo