Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3052378rwd; Fri, 16 Jun 2023 11:30:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4AE00U2qlIu1nzoLtuY94GxKsddKT/M0otshnDnsgINGMMZoqfkDV/zEZFXRqoJjtipoXr X-Received: by 2002:a17:90a:4e84:b0:25b:f453:a612 with SMTP id o4-20020a17090a4e8400b0025bf453a612mr2390383pjh.41.1686940251283; Fri, 16 Jun 2023 11:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686940251; cv=none; d=google.com; s=arc-20160816; b=h4c899caNsOKSYzb+2TQjiKLUSzfLRkIaQKQkKNgIByY9MN+Hka1EQ93tU8xwe0cOE fUqBP5RUeA/al86d4Dofi3Hoj2hI5uDRsoydhoGBTF4Cw6IBp5TNPoh3PrdLbIjeMSpU MSeAWWklRpQKBQYEGJquSPGbZoYsZ4ea1+edl/pO94i93ebB396Qqr9aYlGWAzwWcUTI 9ZLIXF7JgthIksJn43RPvEJvyAhLwI6RBeZRQLPNVF2P/JXla1dt00tRMD5mCC43p8gB N3mAIyA/S2AcrozDmpDcfcyYAt81ePNI+hpUSkh2ENOtI13pgc1Nc81lc3AgJyMDlr9k chVQ== 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-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=/n8Uw4SQ+qecEfhG8wnAmM6CJZIedHoyrPF9+lDDwjY=; b=rYOPn2BT1nqVKHm3z8ZtqC3UhT+cUi9h152ZuJvYf+w4+HNnzyvkpL1QqtAkz+le8X DGlut63ByQNXUuPU9K9rPimpzrFjcayGhcBwQulkrP8Mg6+iuqRtSV4XJ3r4Lahx9FmC HIsLsSDcvJu47A76fjzqziXSe5Lgc+bs28F6mnlCk98NAv6djRjnPhc/vwLLI/Q/jSYB 5C2kmgcjDFCTchhw+I6ZNT+GZYGVIa4Fn6QtSDnqjdXSrxzu8sdnm52J6mLPcy16ToQf cR21f9z377cYJXg+Rl4BlyB3H1T75x+hQxPQ6HisBmAkjJUDGTdiTWyCMtM1wl8+tNx5 QKhA== 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 mr15-20020a17090b238f00b0025bdc4a4105si2025960pjb.117.2023.06.16.11.30.35; Fri, 16 Jun 2023 11:30:51 -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 S232509AbjFPSYP (ORCPT + 99 others); Fri, 16 Jun 2023 14:24:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjFPSYN (ORCPT ); Fri, 16 Jun 2023 14:24:13 -0400 Received: from bmailout1.hostsharing.net (bmailout1.hostsharing.net [83.223.95.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C4F835AC; Fri, 16 Jun 2023 11:24:12 -0700 (PDT) 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 Global TLS RSA4096 SHA256 2022 CA1" (verified OK)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id D8190300002D5; Fri, 16 Jun 2023 20:24:09 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id BEFB21E8240; Fri, 16 Jun 2023 20:24:09 +0200 (CEST) Date: Fri, 16 Jun 2023 20:24:09 +0200 From: Lukas Wunner To: Smita Koralahalli Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , oohall@gmail.com, Mahesh J Salgaonkar , Kuppuswamy Sathyanarayanan , Yazen Ghannam , Fontenot Nathan Subject: Re: [PATCH v2 2/2] PCI: pciehp: Clear the optional capabilities in DEVCTL2 on a hot-plug Message-ID: <20230616182409.GA8894@wunner.de> References: <20230418210526.36514-1-Smita.KoralahalliChannabasappa@amd.com> <20230418210526.36514-3-Smita.KoralahalliChannabasappa@amd.com> <20230511111902.GA10720@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,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: X-Mailing-List: linux-kernel@vger.kernel.org Hi Smita, My apologies for the delay! On Mon, May 22, 2023 at 03:23:31PM -0700, Smita Koralahalli wrote: > On 5/11/2023 4:19 AM, Lukas Wunner wrote: > > On Tue, Apr 18, 2023 at 09:05:26PM +0000, Smita Koralahalli wrote: > > > Clear all capabilities in Device Control 2 register as they are optional > > > and it is not determined whether the next device inserted will support > > > these capabilities. Moreover, Section 6.13 of the PCIe Base > > > Specification [1], recommends clearing the ARI Forwarding Enable bit on > > > a hot-plug event as its not guaranteed that the newly added component > > > is in fact an ARI device. > > > > Clearing ARI Forwarding Enable sounds reasonable, but I don't see > > why all the other bits in the Device Control 2 register need to be > > cleared. If there isn't a reason to clear them, I'd be in favor of > > leaving them alone. > > I understand. The SPEC doesn't "clearly" state to clear the other bits > except ARI on a hot-plug event. > > But, we came across issues when a device with 10-bit tags was removed and > replaced with a device that didn't support 10-bit tags. The device became > inaccessible and the port was not able to be recovered without a system > reset. So, we thought it would be better to cherry pick all bits that were > negotiated between endpoint and root port and decided that we should clear > them all on removal. Hence, my first revision of this patch series had aimed > to clear only ARI, AtomicOp Requestor and 10 bit tags as these were the > negotiated settings between endpoint and root port. Ideally, these settings > should be re-negotiated and set up for optimal operation on a hot add. Makes total sense. I like the approach of clearing only these three bits, as you did in v1 of the patch. I also appreciate the detailed explanation that you've provided. Much of your e-mail can be copy-pasted to the commit message, in my opinion it's valuable information to any reviewer and future reader of the commit. > We had some internal discussions to understand if SPEC has it documented > somewhere. And we could see in Section 2.2.6.2, it implies that: > [i] If a Requester sends a 10-Bit Tag Request to a Completer that lacks > 10-Bit Completer capability, the returned Completion(s) will have Tags with > Tag[9:8] equal to 00b. Since the Requester is forbidden to generate these > Tag values for 10-Bit Tags, such Completions will be handled as Unexpected > Completions, which by default are Advisory Non-Fatal Errors. The Requester > must follow standard PCI Express error handling requirements. > [ii] In configurations where a Requester with 10-Bit Tag Requester > capability needs to target multiple Completers, one needs to ensure that the > Requester sends 10-Bit Tag Requests only to Completers that have 10-Bit Tag > Completer capability. > > Now, we might wonder, why clear them (especially 10-bit tags and AtomicOps) > if Linux hasn't enabled them at all as the "10-Bit Tag Requester Enable" bit > is not defined in Linux currently. But, these features might be enabled by > Platform FW for "performance reasons" if the endpoint supports and now it is > the responsibility of the operating system to disable it on a hot remove > event. Again, makes total sense. > According to implementation notes in 2.2.6.2: "For platforms where the RC > supports 10-Bit Tag Completer capability, it is highly recommended for > platform firmware or operating software that configures PCIe hierarchies to > Set the 10-Bit Tag Requester Enable bit automatically in Endpoints with > 10-Bit Tag Requester capability. This enables the important class of 10-Bit > Tag capable adapters that send Memory Read Requests only to host memory." So > if the endpoint and root port both support 10-bit tags BIOS is enabling it > at boot time.. > > I ran a quick check to see how DEV_CTL2 registers for root port look on a > 10-bit tag supported NVMe device. > > pci 0000:80:05.1: DEVCTL2 0x1726 (Bit 12: 10-bit tag is enabled..) > pci 0000:80:05.1: DEVCAP2 0x7f19ff > > So, it seems like BIOS has enabled 10-bit tags at boot time even though > Linux hasn't enabled it. > > Some couple of ways we think could be: > [1] Check if these bits are enabled by Platform at boot time, clear them > only it is set during hotplug flow. > [2] Clear them unconditionally as I did.. > [3] Enable 10-bits tags in Linux when a device is probed just like how we do > for ARI.. > > Similarly call pci_enable_atomic_ops_to_root() during a hot add.. Personally I'm fine with option [2]. If you or Bjorn prefer option [3], I'm fine with that as well. > > As for clearing ARI Forwarding Enable, it seems commit b0cc6020e1cc > > ("PCI: Enable ARI if dev and upstream bridge support it; disable > > otherwise") already solved this problem. Quoth its commit message: [...] > > My superficial understanding of that patch is that we do find function 0, > > while enumerating it we clear the ARI Forwarding Enable bit and thus the > > remaining functions become accessible and are subsequently enumerated. > > > > Are you seeing issues when removing an ARI-capable endpoint from a > > hotplug slot and replacing it with a non-ARI-capable device? > > If you do, the question is why the above-quoted commit doesn't avoid them. > > Yeah! Sorry I missed this. ARI is already checked and enabled during device > initialization. It doesn't hurt to additionally clear on hot-removal. Thanks, Lukas