Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1517706imj; Sun, 10 Feb 2019 04:14:28 -0800 (PST) X-Google-Smtp-Source: AHgI3IYjLcNJzCRWWj0n4zyTTiX8USqk8R48Pdecmn5xwRiikQndnH78w+yyCpYnV2LaV95rjwB2 X-Received: by 2002:aa7:8a45:: with SMTP id n5mr23601892pfa.151.1549800868836; Sun, 10 Feb 2019 04:14:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549800868; cv=none; d=google.com; s=arc-20160816; b=R3Io+Pudw18yDYjDtAo40TUIvwc9955V/sSyRgdFPWwhDHFezRD8IKsP5J9cyJ7Ruv IulYmCF7mu2y273z02DA7w3JdE4dTI1L4UyKZIN2ejx+TRT+aInRpKJkT43pHQtjYWV6 CNpijSN+kvtocfYgbZxDn+DxdyLCl0K47ASsODO6I8r6I5vsOI5VkBA0EaHJkaFET1J8 7wgoNA4lFO+Q1PQ78wxzIT9ET7YNaZ7TUndYjWe5u70BzfsBZp5hM3St4gdhcUJre8Gc /nEqmFLLgGoRMZ7yrHvJCh7jZ40GofI+Oc/rnnnrPNtG6xb0Wngb9kfKx58K90+ZDWnc /FaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=xaDObTShoR3r7+eDeVpM6YHgOYpaIdAFHOicp1qM1xY=; b=PZRRb9TW0HMDVaQ7mKCC9LSzr8gepIWjAnJ6M81WfxULITVHvYleBwy9y6Au17GhPA zuqojzfwl2G4VOZhdZyUUrgV86ZbAVI6tfZsfVjdDv9AvKFt++2BVEDFG178H5SE5DkU E5+AI8WaVHubvcydUMQfImvAEhAG4osgYYsKjIOE9JbEtRLpIOAxO8ufFWE57c8NNiqL qb3dQr8nSx5avhyMi7bUI8WkdsVWYmGM9TDUnv/GQ0NGBlbH3v/8kauHAUIBms1ev7PQ 6vHD9ID340n5XNOYV27P9cIolsmCCE7m/wsnJhiVSbijyntCXeEtgTcQPF4cFyqLI4PL 8X7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si2973417pfn.180.2019.02.10.04.13.59; Sun, 10 Feb 2019 04:14:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726088AbfBJMN4 (ORCPT + 99 others); Sun, 10 Feb 2019 07:13:56 -0500 Received: from bmailout1.hostsharing.net ([83.223.95.100]:34345 "EHLO bmailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726002AbfBJMN4 (ORCPT ); Sun, 10 Feb 2019 07:13:56 -0500 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id D10E930000CDE; Sun, 10 Feb 2019 13:13:53 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id A755BF53; Sun, 10 Feb 2019 13:13:53 +0100 (CET) Date: Sun, 10 Feb 2019 13:13:53 +0100 From: Lukas Wunner To: Mika Westerberg Cc: linux-kernel@vger.kernel.org, Michael Jamet , Yehezkel Bernat , Andreas Noever , Andy Shevchenko Subject: Re: [PATCH v2 12/28] thunderbolt: Add functions for allocating and releasing hop IDs Message-ID: <20190210121353.fw7gj4pm7ce3flvf@wunner.de> References: <20190206131738.43696-1-mika.westerberg@linux.intel.com> <20190206131738.43696-13-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190206131738.43696-13-mika.westerberg@linux.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 06, 2019 at 04:17:22PM +0300, Mika Westerberg wrote: > Each port has a separate path configuration space that is used for > finding the next hop (switch) in the path. Hop ID is an index to this > configuration space and hop IDs 0 - 7 are reserved. > > In order to get next available hop ID for each direction we provide two > pairs of helper functions that can be used to allocate and release hop > IDs for a given port. [...] > +static int tb_port_alloc_hopid(struct tb_port *port, bool in, int min_hopid, > + int max_hopid) > +{ > + int port_max_hopid; > + struct ida *ida; > + > + if (in) { > + port_max_hopid = port->config.max_in_hop_id; > + ida = &port->in_hopids; > + } else { > + port_max_hopid = port->config.max_out_hop_id; > + ida = &port->out_hopids; > + } > + > + /* Hop IDs 0-7 are reserved */ > + if (min_hopid < 8) > + min_hopid = 8; > + > + if (max_hopid < 0 || max_hopid > port_max_hopid) > + max_hopid = port_max_hopid; > + > + return ida_simple_get(ida, min_hopid, max_hopid + 1, GFP_KERNEL); > +} If there are two Macs at the ends of the daisy-chain with Thunderbolt devices in-between, the other Mac may already have established tunnels to some of the devices and therefore has occupied hop entries in the devices' path config space. How do you ensure that you don't allocate the same entries and overwrite the other Mac's hop entries, thereby breaking its tunnels? Because you're only allocating the hop entries locally here. Maybe there's some check in a later patch whether a hop entry is already occupied, I'm not even halfway through this patch bomb. Thanks, Lukas