Message ID | 20230511131441.45704-15-ilpo.jarvinen@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4370778vqo; Thu, 11 May 2023 06:27:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6FOIZ/pCtFJi+4gVRBVfvdmDddvY+5x495gqOBQbZVtXlnJv1flK6pT7Eg0n1ZG0zx6pw/ X-Received: by 2002:a05:6a00:a23:b0:63d:45f3:9fc with SMTP id p35-20020a056a000a2300b0063d45f309fcmr25864139pfh.5.1683811643461; Thu, 11 May 2023 06:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683811643; cv=none; d=google.com; s=arc-20160816; b=ROkLlGaOzJze2/peNxg2XXy+UdB7p889abptdG4HM2VCVJdAuoEKR5wtTZaEssbTck 6VY1PyA45qRH8QFBhfmmAQp6eYwuiaKcN/QMaChiwVs3RpliuOAP95CDzk62nDppeASO GpfYi06kOZ4PC2Au1oLfxvLYRDQfzRI18Vkqv8vO25UsOgEbqyyzeaxUz7ntkVjzkasJ mS1ljFtO1y08vspgPftQsElsbi7bIFDRcHV3JZciYc/Zv73E8sQuCzvPO+rLa7roBBvY rdiClvSAHrOn0Q3Xg0jyLWJfqWovjcNC/JEvq38ELZbUpZI3ZwpMvq9oZ5A6VgckjfmX Qfug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YeBPTdDDMroafvAQNxXsyBWmUnLIZRzqS5QH0XyhNO0=; b=FghKDdPqoTndqLxr4Z2an/99IA/Mb5RYJhj0RogfpS/hm/DkPvv4SgQR1o93rXvvUy hamBR+cW7D5ucT4tXrbuSHDLEktCa9H7jHjlfVN049T/8VFRDqDrJ52/valB1xDP1OO5 ScNw22idDoezPGnrdK4oiDj3EDkgnrQtL0mdkB+YMYv72gj7jadVl18ofw7AXIwiHT5L jPmKJe6U9SoDBuxxjYJWBL/KKlcFdme7gjIi4MuDglqm3sl7BhfIxG9aWVIgWupCYt2x iAs1PodYORXoEK96DiuDFIF0h6iC9CB6KuSVmJPE8k6Zldic/prBnH2CjfV2CUtDOn0N Wk+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D4rZk0Ou; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a63ae41000000b00524cf947602si6532090pgp.686.2023.05.11.06.27.08; Thu, 11 May 2023 06:27:23 -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=@intel.com header.s=Intel header.b=D4rZk0Ou; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238198AbjEKNSA (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Thu, 11 May 2023 09:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238197AbjEKNRa (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 11 May 2023 09:17:30 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC441106FD; Thu, 11 May 2023 06:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683810970; x=1715346970; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KJEqc9zquHSi/5eWbL8pGz0gttsldrrPx96rTLeTqbQ=; b=D4rZk0Ou6cxktpD2Q0qDG53sIfjIfwcxz509/ATegj/rudsFZcOfHBEh B4T7iP2kHqUQeK3HUXhJzBZtgXSbwG1fz/hq+uhQ352SRwlurwQ8EVeyD NMalNN/IdiwFK3lCbG6iPfyDKZirBLKaI/6hOD0RnUBxzhOD5dGHOrvHE iZsIOK36zD5WWWy5tqLxeL1wxiiOfV/LdJVHBdr34gXhnMaincbxE9mVc lGQ8jSHk844kgln3kr3Hy87xlvBlTdi+2d/wRP/SnHCJ2GHvVA8MF1dLm f1N/K5HcTY4tlCAIwR3skUg8XBrJ5x06/w5XxiKgzpaW5AvhCy8qJpQWg Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="378619700" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="378619700" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 06:15:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="650170074" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="650170074" Received: from jsanche3-mobl1.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.39.112]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 06:15:48 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com> To: linux-pci@vger.kernel.org, Bjorn Helgaas <helgaas@kernel.org>, Rob Herring <robh@kernel.org>, Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>, =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= <kw@linux.com>, Lukas Wunner <lukas@wunner.de>, Heiner Kallweit <hkallweit1@gmail.com>, nic_swsd@realtek.com, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com> Subject: [PATCH 14/17] r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL Date: Thu, 11 May 2023 16:14:38 +0300 Message-Id: <20230511131441.45704-15-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com> References: <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765604477803051809?= X-GMAIL-MSGID: =?utf-8?q?1765604477803051809?= |
Series |
PCI: Improve LNKCTL & LNKCTL2 concurrency control
|
|
Commit Message
Ilpo Järvinen
May 11, 2023, 1:14 p.m. UTC
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/ethernet/realtek/r8169_main.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
Comments
On 11.05.2023 15:14, Ilpo Järvinen wrote: > Don't assume that only the driver would be accessing LNKCTL. ASPM > policy changes can trigger write to LNKCTL outside of driver's control. > > Use pcie_lnkctl_clear_and_set() which does proper locking to avoid > losing concurrent updates to the register value. > Wouldn't it be more appropriate to add proper locking to the underlying pcie_capability_clear_and_set_word()? > Suggested-by: Lukas Wunner <lukas@wunner.de> > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> > --- > drivers/net/ethernet/realtek/r8169_main.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c > index a7e376e7e689..c0294a833681 100644 > --- a/drivers/net/ethernet/realtek/r8169_main.c > +++ b/drivers/net/ethernet/realtek/r8169_main.c > @@ -2686,14 +2686,12 @@ static void __rtl_ephy_init(struct rtl8169_private *tp, > > static void rtl_disable_clock_request(struct rtl8169_private *tp) > { > - pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, > - PCI_EXP_LNKCTL_CLKREQ_EN); > + pcie_lnkctl_clear_and_set(tp->pci_dev, PCI_EXP_LNKCTL_CLKREQ_EN, 0); > } > > static void rtl_enable_clock_request(struct rtl8169_private *tp) > { > - pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, > - PCI_EXP_LNKCTL_CLKREQ_EN); > + pcie_lnkctl_clear_and_set(tp->pci_dev, 0, PCI_EXP_LNKCTL_CLKREQ_EN); > } > > static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)
On Thu, 11 May 2023, Heiner Kallweit wrote: > On 11.05.2023 15:14, Ilpo Järvinen wrote: > > Don't assume that only the driver would be accessing LNKCTL. ASPM > > policy changes can trigger write to LNKCTL outside of driver's control. > > > > Use pcie_lnkctl_clear_and_set() which does proper locking to avoid > > losing concurrent updates to the register value. > > > > Wouldn't it be more appropriate to add proper locking to the > underlying pcie_capability_clear_and_set_word()? As per discussion for the other patch, that's where this series is now aiming to in v2.
On Thu, May 11, 2023 at 09:49:52PM +0200, Heiner Kallweit wrote: > On 11.05.2023 15:14, Ilpo Järvinen wrote: > > Don't assume that only the driver would be accessing LNKCTL. ASPM > > policy changes can trigger write to LNKCTL outside of driver's control. > > > > Use pcie_lnkctl_clear_and_set() which does proper locking to avoid > > losing concurrent updates to the register value. > > Wouldn't it be more appropriate to add proper locking to the > underlying pcie_capability_clear_and_set_word()? PCI config space accessors such as this one are also used in hot paths (e.g. interrupt handlers). They should be kept lean (and lockless) by default. We only need locking for specific PCIe Extended Capabilities which are concurrently accessed by PCI core code and drivers. Thanks, Lukas
On Thu, May 11, 2023 at 11:00:02PM +0300, Ilpo Järvinen wrote: > On Thu, 11 May 2023, Heiner Kallweit wrote: > > On 11.05.2023 15:14, Ilpo Järvinen wrote: > > > Don't assume that only the driver would be accessing LNKCTL. ASPM > > > policy changes can trigger write to LNKCTL outside of driver's control. > > > > > > Use pcie_lnkctl_clear_and_set() which does proper locking to avoid > > > losing concurrent updates to the register value. > > > > > > > Wouldn't it be more appropriate to add proper locking to the > > underlying pcie_capability_clear_and_set_word()? > > As per discussion for the other patch, that's where this series is now > aiming to in v2. That discussion wasn't cc'ed to Heiner. For reference, this is the message Ilpo is referring to: https://lore.kernel.org/linux-pci/ZF1AjOKDVlbNFJPK@bhelgaas/
On 11.05.2023 22:10, Lukas Wunner wrote: > On Thu, May 11, 2023 at 11:00:02PM +0300, Ilpo Järvinen wrote: >> On Thu, 11 May 2023, Heiner Kallweit wrote: >>> On 11.05.2023 15:14, Ilpo Järvinen wrote: >>>> Don't assume that only the driver would be accessing LNKCTL. ASPM >>>> policy changes can trigger write to LNKCTL outside of driver's control. >>>> >>>> Use pcie_lnkctl_clear_and_set() which does proper locking to avoid >>>> losing concurrent updates to the register value. >>>> >>> >>> Wouldn't it be more appropriate to add proper locking to the >>> underlying pcie_capability_clear_and_set_word()? >> >> As per discussion for the other patch, that's where this series is now >> aiming to in v2. > > That discussion wasn't cc'ed to Heiner. For reference, this is the > message Ilpo is referring to: > > https://lore.kernel.org/linux-pci/ZF1AjOKDVlbNFJPK@bhelgaas/ Thanks for the link!
On 11.05.2023 22:02, Lukas Wunner wrote: > On Thu, May 11, 2023 at 09:49:52PM +0200, Heiner Kallweit wrote: >> On 11.05.2023 15:14, Ilpo Järvinen wrote: >>> Don't assume that only the driver would be accessing LNKCTL. ASPM >>> policy changes can trigger write to LNKCTL outside of driver's control. >>> >>> Use pcie_lnkctl_clear_and_set() which does proper locking to avoid >>> losing concurrent updates to the register value. >> >> Wouldn't it be more appropriate to add proper locking to the >> underlying pcie_capability_clear_and_set_word()? > > PCI config space accessors such as this one are also used in hot paths > (e.g. interrupt handlers). They should be kept lean (and lockless) I *think* in case the system uses threaded interrupts you may need locking also in interrupt handlers. > by default. We only need locking for specific PCIe Extended Capabilities > which are concurrently accessed by PCI core code and drivers. > > Thanks, > > Lukas
diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index a7e376e7e689..c0294a833681 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -2686,14 +2686,12 @@ static void __rtl_ephy_init(struct rtl8169_private *tp, static void rtl_disable_clock_request(struct rtl8169_private *tp) { - pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, - PCI_EXP_LNKCTL_CLKREQ_EN); + pcie_lnkctl_clear_and_set(tp->pci_dev, PCI_EXP_LNKCTL_CLKREQ_EN, 0); } static void rtl_enable_clock_request(struct rtl8169_private *tp) { - pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, - PCI_EXP_LNKCTL_CLKREQ_EN); + pcie_lnkctl_clear_and_set(tp->pci_dev, 0, PCI_EXP_LNKCTL_CLKREQ_EN); } static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)