Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp715272lqa; Sun, 28 Apr 2024 00:23:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6AcJNI0oMQzivy30l9T7SlwAmNds0zuOw6iCVsfmOsM9N3tOcAGMNRJA4P7a7fcfGmu/z1/wPlLMY5H3pZJi4+ra7JfsFwKP4uTLaiA== X-Google-Smtp-Source: AGHT+IGXjIyjWHQZ6dMecBCiEfsnK52ZWLsq2c7qGG8vbcqYVtp4/GJ/dkg+C5x13FDFZtheUxme X-Received: by 2002:a17:906:52d4:b0:a58:ed37:8c38 with SMTP id w20-20020a17090652d400b00a58ed378c38mr1650736ejn.50.1714289014518; Sun, 28 Apr 2024 00:23:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714289014; cv=pass; d=google.com; s=arc-20160816; b=q62/UktkUl+oU35IHIKAL1XLNUlpIIfkswkEdOX6Hn3xMmRedsXOSzl/HvDTp16ire 2CPOKnZ8tgGusat/vH76Hb1h1nAUrASBnP3RJQzguPU2OXz6+ubXr6HY6iFAF9hvLhO7 tA0HuWX/G7TlIVvxiaXpycKiI0tKv28tpa6YBZcaa0bDhDFSxmG5cNROUBqGE6EmOkGg rRgIJ7IysTVhvfr3aR3DZWa9nby5wbNPFzW3TgCIZA2iu1xOHYg1jXedJ9h0GH25nw5w fpw44IROn5eTU8ZbGmkPCklecAttu0kpA4LiAVjDM8B1IJfPkrEOYfWrqiTq3f2uy1lk Gb+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=U46OXA1LUy+87xEVQSP48YVHnnA9MBrht9mpUSXePZU=; fh=NR9oz0VN1rkrlLcmc1V2HiZbDqLkok/+29mcwFSpH48=; b=EMwGQdDuZXfGwseeB1yT3IBJqvSUeH0RKRe2z6b+bJCrLVgwTlDj/gsAZ2LTRLj8ps 3HpYhW6SJRTybFvcA5jeh1TM47icIGD4xJY9s5aYZaj/zgwFgMAuvUZM42r0XAJpDry0 hnJhcFp1rGKH6F1Ij+WJvsGE+kHRO88Unv8qo97t9xfcswthaIO9Jcn5v9WnXb77+y2e tpqNLbaAeBjDx7YLYVq/V5/bMlklPOrdD/FMBUi4igHGRSSSppmj+dqH6MECm5ywXM/h f+OVUqxr79Pr1vD2tLrousczSJNnvTbMfHAUo8kNmQbhdupSwd7TPuUTD/81I1pomzLm od9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nE66YgTI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-161307-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161307-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ji1-20020a170907980100b00a55b0d25f1asi9370920ejc.306.2024.04.28.00.23.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 00:23:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161307-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nE66YgTI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-161307-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161307-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 40B801F21844 for ; Sun, 28 Apr 2024 07:23:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEFAD50A7A; Sun, 28 Apr 2024 07:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nE66YgTI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DE82D50251; Sun, 28 Apr 2024 07:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714289005; cv=none; b=Gc6UpBcHvPO8UfzeaFr5mXk9XN1AEsASoAbvhLZC9B5Q3fFa3hrhMDLv+QmiRbftogrbj7pvl3fVMfDsHl5/RJ1FTTKlqBf7rxGEYOGFiWICrZHhV5kJT+Tj8ZX+pRBP2ROs9zUF07L3VKjnBKZ2rKCfxCxSzad9S4gytDG7+JU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714289005; c=relaxed/simple; bh=DP/Aemdi0KQCVAXsAFaA/0biCg9ptDN5YTYd2q7KhJo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PNT/n7rh7YZdPSoroBBKT1U33ohcDND7V19Iih0S7Dh7Qp3AtpaAEgyRCSR0IIWL5jmOhNWD8lG7uXKFxWGffgTJso9sGTmm400Zc466nzP90OWQI7ImJyNtVMthg727alQJB6x001BAK4GUbB3/F7av4UGRAB6YlDBfP15MbmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nE66YgTI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F02F1C113CC; Sun, 28 Apr 2024 07:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714289004; bh=DP/Aemdi0KQCVAXsAFaA/0biCg9ptDN5YTYd2q7KhJo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nE66YgTI69QfmVwPjTW2XnkJQBVd7P/4BPQ3n0Sz3wK+PAt5TCm2pCZuuKN6PDgoX pD2uajeEUrDUANVaxos2Kkcfj8zcJ7j9KAqtwBrRpK7YmQ5Uc3jv6WoMAd5EgUQKPr jF4ihlx0R1lV4LNlNeyt9D79u3zgWW4ci81MQAWx/xu19H+sMAUaSKXX3HxrAL4edU WTdcu8YK2R1QRkzCuP9BoDL5t1GJ8y/FlIT/TNzoM4t6b9EjuWNbScqd1nWhNsAKsd EiCPeUtKIrqHhyRIqX/2u2B8O2XZ+LFNdgVFKJ+l+qfFNBWLTG6uSpMkEeWd2iCHa2 PNIV8SeDkhd1g== Date: Sun, 28 Apr 2024 08:23:18 +0100 From: Will Deacon To: Bjorn Helgaas Cc: Vidya Sagar , "Rafael J. Wysocki" , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Lorenzo Pieralisi , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Manikanta Maddireddy , Shanker Donthineni , Krishna Thota , Joerg Roedel Subject: Re: [Query] ACS enablement in the DT based boot flow Message-ID: <20240428072318.GA11447@willie-the-truck> References: <20240410192840.GA2147526@bhelgaas> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240410192840.GA2147526@bhelgaas> User-Agent: Mutt/1.10.1 (2018-07-13) On Wed, Apr 10, 2024 at 02:28:40PM -0500, Bjorn Helgaas wrote: > [+cc Will, Joerg] > > On Mon, Apr 01, 2024 at 10:40:15AM +0000, Vidya Sagar wrote: > > Hi folks, > > ACS (Access Control Services) is configured for a PCI device through > > pci_enable_acs(). The first thing pci_enable_acs() checks for is > > whether the global flag 'pci_acs_enable' is set or not. The global > > flag 'pci_acs_enable' is set by the function pci_request_acs(). > > > > pci_enable_acs() function is called whenever a new PCI device is > > added to the system > > > > pci_enable_acs+0x4c/0x2a4 > > pci_acs_init+0x38/0x60 > > pci_device_add+0x1a0/0x670 > > pci_scan_single_device+0xc4/0x100 > > pci_scan_slot+0x6c/0x1e0 > > pci_scan_child_bus_extend+0x48/0x2e0 > > pci_scan_root_bus_bridge+0x64/0xf0 > > pci_host_probe+0x18/0xd0 > > > > In the case of a system that boots using device-tree blob, > > pci_request_acs() is called when the device driver binds with the > > respective device > > > > of_iommu_configure+0xf4/0x230 > > of_dma_configure_id+0x110/0x340 > > pci_dma_configure+0x54/0x120 > > really_probe+0x80/0x3e0 > > __driver_probe_device+0x88/0x1c0 > > driver_probe_device+0x3c/0x140 > > __device_attach_driver+0xe8/0x1e0 > > bus_for_each_drv+0x78/0xf0 > > __device_attach+0x104/0x1e0 > > device_attach+0x14/0x30 > > pci_bus_add_device+0x50/0xd0 > > pci_bus_add_devices+0x38/0x90 > > pci_host_probe+0x40/0xd0 > > > > Since the device addition always happens first followed by the > > driver binding, this flow effectively makes sure that ACS never gets > > enabled. > > > > Ideally, I would expect the pci_request_acs() get called (probably > > by the OF framework itself) before calling pci_enable_acs(). > > > > This happens in the ACPI flow where pci_request_acs() is called > > during IORT node initialization (i.e. iort_init_platform_devices() > > function). > > > > Is this understanding correct? If yes, would it make sense to call > > pci_request_acs() during OF initialization (similar to IORT > > initialization in ACPI flow)? > > Your understanding looks correct to me. My call graph notes, FWIW: > > mem_init > pci_iommu_alloc # x86 only > amd_iommu_detect # init_state = IOMMU_START_STATE > iommu_go_to_state(IOMMU_IVRS_DETECTED) > state_next > switch (init_state) > case IOMMU_START_STATE: > detect_ivrs > pci_request_acs > pci_acs_enable = 1 # <-- > detect_intel_iommu > pci_request_acs > pci_acs_enable = 1 # <-- > > pci_scan_single_device # PCI enumeration > ... > pci_init_capabilities > pci_acs_init > pci_enable_acs > if (pci_acs_enable) # <-- > pci_std_enable_acs > > __driver_probe_device > really_probe > pci_dma_configure # pci_bus_type.dma_configure > if (OF) > of_dma_configure > of_dma_configure_id > of_iommu_configure > pci_request_acs # <-- 6bf6c24720d3 > iommu_probe_device > else if (ACPI) > acpi_dma_configure > acpi_dma_configure_id > acpi_iommu_configure_id > iommu_probe_device > > The pci_request_acs() in of_iommu_configure(), which happens too late > to affect pci_enable_acs(), was added by 6bf6c24720d3 ("iommu/of: > Request ACS from the PCI core when configuring IOMMU linkage"), so I > cc'd Will and Joerg. I don't know if that *used* to work and got > broken somehow, or if it never worked as intended. I don't have any way to test this, but I'm supportive of having the same flow for DT and ACPI-based flows. Vidya, are you able to cook a patch? Will