Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp355584lqj; Wed, 10 Apr 2024 12:28:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUckB/Xb6uX1ibJEPGUTr2Zm217wj66KTQGCSuM1C0+bSiAvrBeB5S1wLqp5osva7AS7nhyZgSZ8htcItj7XX8Z4no/IlOpkLhljbVrcQ== X-Google-Smtp-Source: AGHT+IFOe3l69drEL1LFHlciUN3BMzh7TqEaEHP6olzy4KysAAon5JccI2G9JR3Gm3IxA8CGyRbI X-Received: by 2002:a17:906:eb15:b0:a4d:fcc9:905c with SMTP id mb21-20020a170906eb1500b00a4dfcc9905cmr2413020ejb.20.1712777329431; Wed, 10 Apr 2024 12:28:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712777329; cv=pass; d=google.com; s=arc-20160816; b=iDG5jGq50OMhCMeIVmIuyimvNDzKtN0o/4ZvGs7y7uGl+GTkWkDhGVxz3NZAU7V9GO 3AskrIItUu4mnZ/P1wtsMYr/qykuexwdo/lNQSfWhXfPE62rhS9yr26/x3GEjwRBMBVg EAWb3pArnrGTfQhw/Gl8jigOsAgHMC4Bk67wdyQAz+CMga6teIiSXJENDLet44GjqYF0 q1XZLqt8dkJH1tO8r03pEJMTHhFv7oy45ku+n5809Oeqg2x0yYuenm/lxnx+UQhd0iqE X311nv3d9wnIFrv+TlAaIohpK2OpGFOX/2A4ba//ZnlL4+oHGNh3ZQWl3/VzWqVZ6MEl n72Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=iZuGnDl5iq8qWpM8sk44fZtM1Xc8rHOCd37weSddsck=; fh=K0evAU9aB2wYxFl5IiNnSWFgrfwTj4ztpsxcc8kmaiw=; b=ZJyEIDZJ0PQCBSnxgpEINu2GNMJCL5Xjg2eXhbXE/0+TuufGhu6nQYxYjykQuUX/i1 pQqw7p1L94130shCdeP/wfvpG01J9MqC6rXUjXMswj7Bk+dpC/zq+c9tBIcEaDXzb9L1 hv84I5h2S84HtOqFJps2ZqVaywbcYFZxDJK7pN4RH0U+bHNs4YCQ7ufYvnZfWryQmcQ2 az11DYtcVtjH7RfY3UpcXH8m0eWD0vlJUZuhZ8FWg3DjkMkJRpHNVjmOciWkzSoPhL/Y mI23iwQsANkZj1T7QJ6LZ85R46hc9oM66kzMdH2e5YJsnUqWtGueRZSQtC3ce5SbfH82 /KWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V4KcJiaC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-139256-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139256-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. [147.75.80.249]) by mx.google.com with ESMTPS id g21-20020a170906395500b00a462435da0bsi5701558eje.659.2024.04.10.12.28.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 12:28:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139256-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V4KcJiaC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-139256-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139256-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 2D9F71F25123 for ; Wed, 10 Apr 2024 19:28:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F055181330; Wed, 10 Apr 2024 19:28:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V4KcJiaC" 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 32CC317F370; Wed, 10 Apr 2024 19:28:42 +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=1712777323; cv=none; b=u/+CwLzWMaOYNdxa+aDhQwdFIMey22efMw64wRfbU1KJqXAoTw1FYM2LddlhzB1izQTqRTolo152MfVYM8Yfvn9Jtsq21I/zq8d3Pdv93D6GwIPtGl4L6xfh0eHOsnDseWpLJq4mJBVcXYbH7qzmJse345qMIR0S7E8Kv7xPooU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712777323; c=relaxed/simple; bh=WOeeQkSWa4cC+JdRWhi+F3uBgT2A/qX4BlXL0RnkUCI=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=Rpg8Awrzuecq5aZxtisoWwVZZJ7G/NusLTPMZyWljALC43sMyoT4d/F3L4n7AqMvakeyjxvI+gjf2yzYSQ+U2q8S8onv2iChH8oGQyXd8ezHcgKU7OMqp6tee8F99AYliTBck3WvGQf9/xPwrtH13RFV04ypINydCe+c+Izhm4o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V4KcJiaC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5928DC433F1; Wed, 10 Apr 2024 19:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712777322; bh=WOeeQkSWa4cC+JdRWhi+F3uBgT2A/qX4BlXL0RnkUCI=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=V4KcJiaCI8JlpuHxsNMA2kz2SSkPb8I65KHr01c0bKDpPWkjrrN9fJ2uS8aDjHR1d npEtvjCySIDywAXfkqTrCw05tsQT7NvA1DrpALdePR392tb4lVeuk8u4c3879QTyCO BiJpuEt1IfiHGy/dBiQQ/T0yyIUDSWLo1LI4o/QIB/wePkwZs+peO8FEj6rJa1P1cV seUk5IOw7Xzt9xUoOmk+c15h4jYVYuQ0sjaGT2Da2fQ7KBzNqr97uoDgXec2wvB33/ oWNw3w/JrPhXPs6vWXZ6chIdKRXa19HVfg9mzOE0GHvFFPF6wchSzhAZA4CYXL8XL7 YcYPIZwuxh3JA== Date: Wed, 10 Apr 2024 14:28:40 -0500 From: Bjorn Helgaas To: Vidya Sagar Cc: "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 , Will Deacon , Joerg Roedel Subject: Re: [Query] ACS enablement in the DT based boot flow Message-ID: <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: [+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. Bjorn