Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7231014rdb; Wed, 3 Jan 2024 08:40:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXIpjUIsy42M3sBbY6L2I2hDrwQOp0R5Pure3yB2h6JkXPvlJAPh/z6ZROgn6GVbsePr+H X-Received: by 2002:a17:90a:5801:b0:28c:4527:ef9a with SMTP id h1-20020a17090a580100b0028c4527ef9amr1453485pji.40.1704300026752; Wed, 03 Jan 2024 08:40:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704300026; cv=none; d=google.com; s=arc-20160816; b=Sk3ittS/Uc+MBovVP7YzxxVC4F6qaTB75yrdOjwMjSwPZSzAo5LGX+FpixAIpCC9tt 4JcWxUibRIkInNbavmNDReG9EJMfoCBBK5k4ae7m0YnEAFPGQ+lEof+LIL41qvo+RXuB kF1A49jwnl1pbgfFel5QhlhvszIYNIZILjcelnQXaOQ06QPrwKtpMCeHT/F0CF2dTKAw JjIHn28W9rqqjtOAS6xf9Sn/XoN/743tJ5mmgpMhtpOB1Ri+90G1d70Q1pkgQ8iAnsAy yPvItjGUmBhAXDDhyMpGMwfPVWn7J8u/ZZGxX32hpQHLCCY9sWkwBQnqI+68cwDNm4RT 5keg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:references:message-id:subject:cc:to:from:date; bh=sPiZwH68Pl5kvu5vUsnxlxJHtg0DJeaWMP7Sr91KCtU=; fh=vlRGUsBy0j9/BaHOaFituJ6FkezermbqQhX6NEhjBGI=; b=ruLGuF1A0o72c7zR8wV5H3bKlkBZB0z75L9PaFaqHdq9TjzEejBs95whGgT6p4pY3U JoAcpLobSO7Nb5dh0Oq5kQps06TyG/I7D1X5S3vmttJDVEEc3Q7aMQg4H3XpLSjZoszC Z8yNNob1dhLKldRQ6U2Ob1oyyUNmbC10dak0t68B8THjBRgoTseGor3mI3t7yr/ShL9E xtj1C3HZXrD3TxfNXvL8W4Ch1GxbUThIWh4fvP4uxrbapRmdpZoc7Yheg5X/j+taCGy4 eRnkUel5ACr6zwM9wzwdGnw9+ObN3U1yArG34l30XCbNNT1O+7LfUm09x8DmDiu12n1V ivMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-15761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15761-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a6-20020a17090ad80600b0028b9ece36acsi1459771pjv.168.2024.01.03.08.40.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 08:40:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-15761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15761-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3E9CB2854E3 for ; Wed, 3 Jan 2024 16:40:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 510EA1BDE4; Wed, 3 Jan 2024 16:40:17 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from bmailout2.hostsharing.net (bmailout2.hostsharing.net [83.223.78.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FCE81BDCD; Wed, 3 Jan 2024 16:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=h08.hostsharing.net Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS RSA CA G1" (verified OK)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 698962800BB42; Wed, 3 Jan 2024 17:40:06 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 5C41E10B43F; Wed, 3 Jan 2024 17:40:06 +0100 (CET) Date: Wed, 3 Jan 2024 17:40:06 +0100 From: Lukas Wunner To: Ilpo =?iso-8859-1?Q?J=E4rvinen?= Cc: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , Krzysztof Wilczy??ski , Alexandru Gagniuc , Krishna chaitanya chundru , Srinivas Pandruvada , "Rafael J . Wysocki" , linux-pm@vger.kernel.org, Bjorn Helgaas , LKML , Alex Deucher , Daniel Lezcano , Amit Kucheria , Zhang Rui Subject: Re: [PATCH v3 08/10] PCI/bwctrl: Add "controller" part into PCIe bwctrl Message-ID: <20240103164006.GA3463@wunner.de> References: <20230929115723.7864-1-ilpo.jarvinen@linux.intel.com> <20230929115723.7864-9-ilpo.jarvinen@linux.intel.com> <20231230184905.GA6104@wunner.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) On Mon, Jan 01, 2024 at 08:12:43PM +0200, Ilpo J?rvinen wrote: > On Sat, 30 Dec 2023, Lukas Wunner wrote: > > On Fri, Sep 29, 2023 at 02:57:21PM +0300, Ilpo J?rvinen wrote: > > > --- a/drivers/pci/pcie/bwctrl.c > > > +static u16 speed2lnkctl2(enum pci_bus_speed speed) > > > +{ > > > + static const u16 speed_conv[] = { > > > + [PCIE_SPEED_2_5GT] = PCI_EXP_LNKCTL2_TLS_2_5GT, > > > + [PCIE_SPEED_5_0GT] = PCI_EXP_LNKCTL2_TLS_5_0GT, > > > + [PCIE_SPEED_8_0GT] = PCI_EXP_LNKCTL2_TLS_8_0GT, > > > + [PCIE_SPEED_16_0GT] = PCI_EXP_LNKCTL2_TLS_16_0GT, > > > + [PCIE_SPEED_32_0GT] = PCI_EXP_LNKCTL2_TLS_32_0GT, > > > + [PCIE_SPEED_64_0GT] = PCI_EXP_LNKCTL2_TLS_64_0GT, > > > + }; > > > > Looks like this could be a u8 array to save a little bit of memory. > > > > Also, this seems to duplicate pcie_link_speed[] defined in probe.c. > > It's not the same. pcie_link_speed[] is indexed by a different thing Ah, missed that. Those various conversion functions are confusing. > > > + dev_speeds = READ_ONCE(bus->pcie_dev_speeds); > > > > Hm, why is the compiler barrier needed? > > It's probably an overkill but there could be a checker which finds this > read is not protected by anything while the value could get updated > concurrectly Why should it be updated? It's a static value cached on enumeration and never changed AFAICS. > If the value selected cannot be set because of endpoint no longer being > there, the other parts of the code will detect that. If the endpoint is hot-unplugged, the link is down, so retraining the link will fail. If the device is replaced concurrently to retraining then you may try to retrain to a speed which is too fast or too slow for the new device. Maybe it's necessary to cope with that? Basically find the pci_dev on the bus with the device/function id and check if the pci_dev pointer still points to the same location. Another idea would be to hook up bwctrl with pciehp so that pciehp tells bwctrl the device is gone and any speed changes should be aborted. We've hooked up DPC with pciehp in a similar way. > So if I just add a comment to this line why there's the data race and keep > it as is? I'd just drop the READ_ONCE() here if there's not a good reason for it. Thanks, Lukas