Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp9286281rwr; Thu, 11 May 2023 12:37:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6nVKAtuiQUj4HFTVAenuYMpfmPjCD1KjC52Koeh6yxeDrdS5TaCkkpKDRZ2qyLe3PFh6ID X-Received: by 2002:a17:902:ec8a:b0:1aa:f3c4:7582 with SMTP id x10-20020a170902ec8a00b001aaf3c47582mr31217000plg.31.1683833837046; Thu, 11 May 2023 12:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683833837; cv=none; d=google.com; s=arc-20160816; b=gWDdb9u0apZJv8uxl9KJVrRbzZH7KBpbWlCAULEh+lXdy9Ddcri+6I+dEsXGhab/Jc 2ThYmRq0VFIXrOqh9tBpgL7Bzu/TL7cq+PKH6bVKz9WWTEi4b5Y/vf8s5TOgc506Buh5 LfpudkBLoYpzoM99D6urHqO9amQ8Qae0XFm0dKiLrKhgdv4l0hmcUb4PmuUtPBbMDvIZ lUC1oAwuIe8QntmGeqv7tkiaRfWZlpjmxJT9CG8XBlbdwNnDpI6uAamoChjWnMzOfJyU bMd/e46UBHSYMxtlODGCoKU+JFTBmFNQDmS3TEyMdliDqKInv5w7m4OFoxACI2IsSjXr eUSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=C9xUZuHQ6v7XAN4+Svs6XCwALhy65yzudvfyU017Z0o=; b=mzo/euoA7wRR7P2CeNOMawX9dxquAmv0N5gBp4We5VehKSHuLkZ0nuOTLF+G7Rbhig DwdgD6xV9Da/sGDBsiENvxGzxB69HxZNxtOXeiyKuPksNFY8vCssM4VMeZgvPZlpOEJ1 QjQlG91W7l1ACJnz12n1SFYu8ifK3PH04ExADWqH4Yuw7BAMxeKiWla002aVyNCgqt1A e0YC4xlpZ/Z8z9xz6wtT+vQajpBAM69e2SOsSJFcahE+Olh3AEBj0Ni3ipXiwVbSA/5W TW5Ppl4oF9hUVb8nukXd6RE4xvK5erJNzILOYSJRsy2yZxSpIZSqGjq4h6Vd0yPddsAP WUUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hjjNUy+E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a170902b28900b001a986e5bd92si6980783plr.83.2023.05.11.12.37.02; Thu, 11 May 2023 12:37:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hjjNUy+E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239158AbjEKTXg (ORCPT + 99 others); Thu, 11 May 2023 15:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238599AbjEKTXa (ORCPT ); Thu, 11 May 2023 15:23:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4CABAD3A; Thu, 11 May 2023 12:22:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EF24B650FC; Thu, 11 May 2023 19:22:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19A35C433D2; Thu, 11 May 2023 19:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683832974; bh=QpSSk/1ebWRADeVKkTa0UQcYPlC3k/G654CAP3C9inA=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=hjjNUy+EMZYUa9Mq/8GFHcLgiNT1wA7pnV4d5hK0g5b5gfK/AxH0JtcG3mfc26cM0 0TLz0V91O3tCA7Tg68LvnFnyG93r0BojVB4UoPw36+TfN+suZe17QTwllS99InSZd+ PZmdpfOahm8FX8WgCf9PSAz9+Wg7GLPJSVG0683QUq4698jNt1vleo6u0oI3KvOyjw GEarGhSluLFERM0wXSI3EWxkl2wpJE31/ryrcMRzzKONgNDgxz5oo+0rFmfZk7iXCO 6pUez+FBLUFPTE/ANUW2la4479WLQC31Dz1MWo+kOs2oJ4wCoAsrFsKXBeS07tHNvt 2WaY/zmB8dPmg== Date: Thu, 11 May 2023 14:22:52 -0500 From: Bjorn Helgaas To: Ilpo =?iso-8859-1?Q?J=E4rvinen?= Cc: linux-pci@vger.kernel.org, Rob Herring , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Lukas Wunner , Bjorn Helgaas , LKML Subject: Re: [PATCH 01/17] PCI: Add concurrency safe clear_and_set variants for LNKCTL{,2} Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5140259d-4425-3166-438a-bc9fbbaa49f9@linux.intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 11, 2023 at 08:35:48PM +0300, Ilpo J?rvinen wrote: > On Thu, 11 May 2023, Bjorn Helgaas wrote: > > > On Thu, May 11, 2023 at 04:14:25PM +0300, Ilpo J?rvinen wrote: > > > A few places write LNKCTL and LNKCTL2 registers without proper > > > concurrency control and this could result in losing the changes > > > one of the writers intended to make. > > > > > > Add pcie_capability_clear_and_set_word_locked() and helpers to use it > > > with LNKCTL and LNKCTL2. The concurrency control is provided using a > > > spinlock in the struct pci_dev. > > > > > > Suggested-by: Lukas Wunner > > > Signed-off-by: Ilpo J?rvinen > > > > Thanks for raising this issue! Definitely looks like something that > > needs attention. > > > > > --- > > > drivers/pci/access.c | 14 ++++++++++++++ > > > drivers/pci/probe.c | 1 + > > > include/linux/pci.h | 17 +++++++++++++++++ > > > 3 files changed, 32 insertions(+) > > > > > > diff --git a/drivers/pci/access.c b/drivers/pci/access.c > > > index 3c230ca3de58..d92a3daadd0c 100644 > > > --- a/drivers/pci/access.c > > > +++ b/drivers/pci/access.c > > > @@ -531,6 +531,20 @@ int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos, > > > } > > > EXPORT_SYMBOL(pcie_capability_clear_and_set_dword); > > > > > > +int pcie_capability_clear_and_set_word_locked(struct pci_dev *dev, int pos, > > > + u16 clear, u16 set) > > > +{ > > > + unsigned long flags; > > > + int ret; > > > + > > > + spin_lock_irqsave(&dev->cap_lock, flags); > > > + ret = pcie_capability_clear_and_set_word(dev, pos, clear, set); > > > + spin_unlock_irqrestore(&dev->cap_lock, flags); > > > + > > > + return ret; > > > +} > > > +EXPORT_SYMBOL(pcie_capability_clear_and_set_word_locked); > > > > I didn't see the prior discussion with Lukas, so maybe this was > > answered there, but is there any reason not to add locking to > > pcie_capability_clear_and_set_word() and friends directly? > > > > It would be nice to avoid having to decide whether to use the locked > > or unlocked versions. It would also be nice to preserve the use of > > PCI_EXP_LNKCTL directly, for grep purposes. And it would obviate the > > need for some of these patches, e.g., the use of > > pcie_capability_clear_word(), where it's not obvious at the call site > > why a change is needed. > > There wasn't that big discussion about it (internally). I brought both > alternatives up and Lukas just said he didn't know what's the best > approach (+ gave a weak nudge towards the separate accessor so I went > with it to make forward progress). Based on that I don't think he had a > strong opinion on it. > > I'm certainly fine to just use it in the normal accessor functions that > do RMW and add the locking there. It would certainly have to those good > sides you mentioned. Let's start with that, then. Many of these are ASPM-related updates that IMHO should not be in drivers at all. Drivers should use PCI core interfaces so the core doesn't get confused. Bjorn