Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2810805rwb; Mon, 15 Aug 2022 11:48:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Y76TGOTD/6Xc1uvv67w8VVe3NytK9zU5yKsI0SHMq7dVxLuoLfDo7ABerpHo0EZhizv2/ X-Received: by 2002:a17:907:a064:b0:730:726f:c62c with SMTP id ia4-20020a170907a06400b00730726fc62cmr11274072ejc.86.1660589331885; Mon, 15 Aug 2022 11:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660589331; cv=none; d=google.com; s=arc-20160816; b=Gr8m6OKGWO9LvzSEKTlWToKif4Wopd6kkQSFY1zvSxL2LYBGn6Ct/vpAWyM8nsdnLF j05TMcRnR6H60E2vOUeqFRZNnEwoF1V1Pg/2ubDR3o7jJtgDrvltcUeiAUkCcApTe2FO kk78KnJefaPixju1P0GEc2XcoMR44u++KcOAzZ9g5q15eIrS9VJz96IgOzCb1iEOdPG3 1mNf1lDB5KAHrWC/fiE1VXdmLpbXQRWLPbcz+Oo/lSNqvSgU4SEYJFeP6l+1EidI65r3 ViaU3eHTD2O32QanEY6g4wmiWiZu+fiGhOKSJnkDkA32IQR3tYBMa2cW5g2sNCGgwdiT ACgg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=60tWSXC9QqaVfjJNXtPDvlKCKIZVi2WFZnhON48u3Aw=; b=DaNd+DbBxcTiRbsDWLU9YbYJDip0ckD/SxTbzSUpXGhecpKQDQj0ex5KnU3BP1kLMu eFAfuM4PCD9aYVzv+NVQs13hqmQBl3mqVmog+mPnCkcRTc4+woZlF6foXmS2XeUIdC7a V4OMPiZI0o/+IJpmnoNqHNwOiYZ303L/8lfHO4PYx2fCrkA+zeahtOOGUkdYj67VWVrp pP/Xm69xPjhDxxJ1sYvw4k1gjHsyoO0Yh2ICGlRU89eqTzXDHbx79iDA3mBDLnfmYDnF ZMrhoTlXJtzGiT1HS1e5QQO0oCwGMjFfAsbpsa440GnuNLurkuRRDqyyHhoEkAHZ2Vt0 7bPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tv09AXFU; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o4-20020a170906974400b00730a3b5af1fsi9631220ejy.338.2022.08.15.11.48.26; Mon, 15 Aug 2022 11:48: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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tv09AXFU; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243258AbiHOSiG (ORCPT + 99 others); Mon, 15 Aug 2022 14:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243610AbiHOSgr (ORCPT ); Mon, 15 Aug 2022 14:36:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CC8F3C8CB; Mon, 15 Aug 2022 11:23:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B0650B8106E; Mon, 15 Aug 2022 18:23:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16CA0C433D7; Mon, 15 Aug 2022 18:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660587795; bh=Hb2R0SkT5uiniydQNAyBxRHeGOY/ofRQ3SDcxSmhPw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tv09AXFUOgQXfqtoZ3srZff9Lp6Bk+LR50m6XnhQwVM6J9U1sZWBgUa6LImFztfii 3MHBOUKEIamqO51+WxJnUpAZUVkD8TENRiasZ2e8xKhaGAZyKggQnCy0OlDmF2zcTC 7nBI5+lWqlx5JZkzYTfA3IgqLUGyeUMekJei/gjE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Auger , Jin Liu , Jean-Philippe Brucker , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.15 198/779] ACPI: VIOT: Fix ACS setup Date: Mon, 15 Aug 2022 19:57:22 +0200 Message-Id: <20220815180345.736578716@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 From: Eric Auger [ Upstream commit 3dcb861dbc6ab101838a1548b1efddd00ca3c3ec ] Currently acpi_viot_init() gets called after the pci device has been scanned and pci_enable_acs() has been called. So pci_request_acs() fails to be taken into account leading to wrong single iommu group topologies when dealing with multi-function root ports for instance. We cannot simply move the acpi_viot_init() earlier, similarly as the IORT init because the VIOT parsing relies on the pci scan. However we can detect VIOT is present earlier and in such a case, request ACS. Introduce a new acpi_viot_early_init() routine that allows to call pci_request_acs() before the scan. While at it, guard the call to pci_request_acs() with #ifdef CONFIG_PCI. Fixes: 3cf485540e7b ("ACPI: Add driver for the VIOT table") Signed-off-by: Eric Auger Reported-by: Jin Liu Reviewed-by: Jean-Philippe Brucker Tested-by: Jean-Philippe Brucker Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/acpi/bus.c | 1 + drivers/acpi/viot.c | 26 ++++++++++++++++++++------ include/linux/acpi_viot.h | 2 ++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index fc9bb06d5411..7774b603a796 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -1340,6 +1340,7 @@ static int __init acpi_init(void) pci_mmcfg_late_init(); acpi_iort_init(); + acpi_viot_early_init(); acpi_hest_init(); ghes_init(); acpi_scan_init(); diff --git a/drivers/acpi/viot.c b/drivers/acpi/viot.c index d2256326c73a..647f11cf165d 100644 --- a/drivers/acpi/viot.c +++ b/drivers/acpi/viot.c @@ -248,6 +248,26 @@ static int __init viot_parse_node(const struct acpi_viot_header *hdr) return ret; } +/** + * acpi_viot_early_init - Test the presence of VIOT and enable ACS + * + * If the VIOT does exist, ACS must be enabled. This cannot be + * done in acpi_viot_init() which is called after the bus scan + */ +void __init acpi_viot_early_init(void) +{ +#ifdef CONFIG_PCI + acpi_status status; + struct acpi_table_header *hdr; + + status = acpi_get_table(ACPI_SIG_VIOT, 0, &hdr); + if (ACPI_FAILURE(status)) + return; + pci_request_acs(); + acpi_put_table(hdr); +#endif +} + /** * acpi_viot_init - Parse the VIOT table * @@ -319,12 +339,6 @@ static int viot_pci_dev_iommu_init(struct pci_dev *pdev, u16 dev_id, void *data) epid = ((domain_nr - ep->segment_start) << 16) + dev_id - ep->bdf_start + ep->endpoint_id; - /* - * If we found a PCI range managed by the viommu, we're - * the one that has to request ACS. - */ - pci_request_acs(); - return viot_dev_iommu_init(&pdev->dev, ep->viommu, epid); } diff --git a/include/linux/acpi_viot.h b/include/linux/acpi_viot.h index 1eb8ee5b0e5f..a5a122431563 100644 --- a/include/linux/acpi_viot.h +++ b/include/linux/acpi_viot.h @@ -6,9 +6,11 @@ #include #ifdef CONFIG_ACPI_VIOT +void __init acpi_viot_early_init(void); void __init acpi_viot_init(void); int viot_iommu_configure(struct device *dev); #else +static inline void acpi_viot_early_init(void) {} static inline void acpi_viot_init(void) {} static inline int viot_iommu_configure(struct device *dev) { -- 2.35.1