Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2679057rwd; Mon, 15 May 2023 15:27:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Z2jtfe86a39pBIKMtUG1amNMk4NSdxmmPYFxm4p+goBoXj8U2GoT/SPyxKNjuqPyYhBaB X-Received: by 2002:a17:902:ba86:b0:1a6:bd5c:649d with SMTP id k6-20020a170902ba8600b001a6bd5c649dmr33085205pls.56.1684189622491; Mon, 15 May 2023 15:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684189622; cv=none; d=google.com; s=arc-20160816; b=eRWSIDh9Mtkhx0ggBj6toBBz3g0aBJc9+XfBlj3EcOcmrFYxR7OrMr9y1mROnBbCTW m6q5gd+2aqP3X/nrqQR0V7er4xqge3aKkwhevVelKg1TssvufmkXRaqdr7TGfVp/tVqu OkW/VP1m/bE+wLdJNVtXyyNJ23tWGCaFMr0nXr7E/UnacWt6H2v+yALhjg1S0R2Nuavk oOPrzQ9hkD3rNqthX+GA6kRIHBIsSQ7XXsC43GepRUD7ZDFW2+GgbXg90Z+VWSAjrXuj iIMBrOuyl+r8pIbLh+xK5MljyInHl/oteAx5Wb2w91Z8ajEIhHOEDrm4hheeSkWjff1g iwZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/XXboW2RqLWM0xFHKCb4u3lIqWi/mrnzAySViYBCOYw=; b=hphLkgF02aANL68Hq6P9+SFnhak1zBWzMhTyXXqP+VDTf4ssz6QpE5WfqJUZU9mCJ7 pRwDwDMtobWmQ7qxY5m2guBR5PSL3CL10B1AIWhwEUTSIVdNZFraem3KjcMU7UIN4MXr 9v6TrFvAriEFppKacDxM8F9bpf4fG+4/4NlsQGjiJjjrBT96NvhNjBl1Un7RpqSAwrPm sfgyTuhjmHk6QNQtK2sBXcRSlbz3wxbuJYF9S2UYidUda8r23vE+INPBE3ww/igJe9rt tnjNWxUzuyXijetwZsvKCz2pEmMmPpGKcFa1FTYt6xyiQU5OTug2N3uYRw5/0puCaxkV +d2Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 5-20020a170902ee4500b001a64fba3382si16208416plo.148.2023.05.15.15.26.50; Mon, 15 May 2023 15:27:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245600AbjEOWNh (ORCPT + 99 others); Mon, 15 May 2023 18:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245221AbjEOWNd (ORCPT ); Mon, 15 May 2023 18:13:33 -0400 X-Greylist: delayed 129731 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 15 May 2023 15:12:55 PDT Received: from bmailout2.hostsharing.net (bmailout2.hostsharing.net [IPv6:2a01:37:3000::53df:4ef0:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68A8E106DF; Mon, 15 May 2023 15:12:55 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (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 Global TLS RSA4096 SHA256 2022 CA1" (verified OK)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 498732800B6CC; Tue, 16 May 2023 00:12:53 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 3D6F34A830; Tue, 16 May 2023 00:12:53 +0200 (CEST) Date: Tue, 16 May 2023 00:12:53 +0200 From: Lukas Wunner To: Ilpo =?iso-8859-1?Q?J=E4rvinen?= Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, Rob Herring , Lorenzo Pieralisi , Krzysztof Wilczy??ski , Bjorn Helgaas , LKML Subject: Re: [PATCH 01/17] PCI: Add concurrency safe clear_and_set variants for LNKCTL{,2} Message-ID: <20230515221253.GA28117@wunner.de> References: <20230511131441.45704-2-ilpo.jarvinen@linux.intel.com> <20230511202332.GD31598@wunner.de> <51577aaa-dc96-d588-2ecf-5bac4b59284@linux.intel.com> <20230514101041.GA1881@wunner.de> <2832e4a-8ef5-8695-3ca2-2b2f287a44d@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2832e4a-8ef5-8695-3ca2-2b2f287a44d@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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 Mon, May 15, 2023 at 02:59:42PM +0300, Ilpo J?rvinen wrote: > While it does feel entirely unnecessary layer of complexity to me, it would > be possible to rename the original pcie_capability_clear_and_set_word() to > pcie_capability_clear_and_set_word_unlocked() and add this into > include/linux/pci.h: > > static inline int pcie_capability_clear_and_set_word(struct pci_dev *dev, > int pos, u16 clear, u16 set) > { > if (pos == PCI_EXP_LNKCTL || pos == PCI_EXP_LNKCTL2 || > pos == PCI_EXP_RTCTL) > pcie_capability_clear_and_set_word_locked(...); > else > pcie_capability_clear_and_set_word_unlocked(...); > } > > It would keep the interface exactly the same but protect only a selectable > set of registers. As pos is always a constant, the compiler should be able > to optimize all the dead code away. That's actually quite neat, I like it. It documents clearly which registers need protection because of concurrent RMWs and callers can't do anything wrong. Though I'd use a switch/case statement such that future additions of registers that need protection are always just a clean, one-line change. Plus some kernel-doc or code comment to explain that certain registers in the PCI Express Capability Structure are accessed concurrently in a RMW fashion, hence require locking. Since this protects specifically registers in the PCI Express Capability, whose location is cached in struct pci_dev->pcie_cap, I'm wondering if pcie_cap_lock is a clearer name. > PCI_EXP_SLTCTL write is protected by a mutex, it doesn't look something > that matches your initial concern about "hot paths (e.g. interrupt > handlers)". PCI_EXP_SLTCTL is definitely modified from the interrupt handler pciehp_ist(), but one could argue that hotplug interrupts don't usually occur *that* often. (We've had interrupt storms though from broken devices or ones with a shared interrupt etc.) I guess I'm just generally worried about acquiring a lock that's not necessary. E.g. on boot, numerous config space accesses are performed to enumerate and initialize devices and reducing concurrency might slow down boot times. It's just a risk that I'd recommend to avoid if possible. Thanks, Lukas