Message ID | 20230208184321.867666-1-gankulkarni@os.amperecomputing.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3625171wrn; Wed, 8 Feb 2023 10:50:18 -0800 (PST) X-Google-Smtp-Source: AK7set93HNtGOeW14olicvhuS7M74G+X6JkywhwfP3tbcfcfEnZ7FJ8dKYTKRikjI+UiT+AetOeP X-Received: by 2002:a05:6a20:7f8e:b0:be:9972:1605 with SMTP id d14-20020a056a207f8e00b000be99721605mr7518811pzj.1.1675882218383; Wed, 08 Feb 2023 10:50:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1675882218; cv=pass; d=google.com; s=arc-20160816; b=E9U6y7fvKeH1zhlxvAJZ88D+M6goQ8zhn3t7rMF6prjmImX5eU8+7A7Q50j10TE07Y Qu0L5ERj8v0vVGeukdYDSVTaz8oCHrE+4LPc2flwHb0Wat9leGYdcyud7EaWyy4R3GAE eGKVkQgOTWGeLkugE5FZA9O5euEOu15vrAjLeUgqS8424a89PhALQFIAiH7F6mETLvxa 6PberRH1STPwtc1yAJbb+pfxv/2rVtssB5BG4XqEIwIOM76qj9Y2eGpWytoKYyScBe+P 3suhe2a1AoAwvTFym9D1yUOnBsacVnObo0SLBvQH0M+sbAqeJWwlciThBOP+RKJsP2OE Bh8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=PduJKKTXFIsfNhRg08c2oah3aHxiHm73GdqFmMecpjY=; b=vT5RSrfEBo8fvZhhD/2llSTYg25RKSa8MSg6NPu/Rep4VSVnFlsEe1ap35zAyGw+/+ h9f1wKsZQwlktfOXPodJo3ONYxm40YGqmiyQbmen2KS1JFSbRU0p+tEFc1mG8mzoLkNm 6AH2BALxusX+ESm9Oofs7h1NjHicskhlIYJjGiNmESuNnHGSYYnkwhF2UxYH/v4kQYRI +HxEfH027MKxkBd+DWaXxy3uNjGDn2b18zwNOMzckGb/9xxaCajnRa4CJD+WQDM/FyN1 h8AaOB8/a/HGhsWN8VoIC9AKUm2OHFaO8HWpTFZnwM5hpPV22U0Z9zSBp/mRqAGuSmKS bM5A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=ptaOipxr; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 13-20020a17090a190d00b0022929341650si2910793pjg.15.2023.02.08.10.50.03; Wed, 08 Feb 2023 10:50:18 -0800 (PST) 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=@os.amperecomputing.com header.s=selector2 header.b=ptaOipxr; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbjBHSnw (ORCPT <rfc822;ivan.orlov0322@gmail.com> + 99 others); Wed, 8 Feb 2023 13:43:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjBHSnv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 8 Feb 2023 13:43:51 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2094.outbound.protection.outlook.com [40.107.237.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CC944B6; Wed, 8 Feb 2023 10:43:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DiqXVm8GoUOxJK8yz6Cm3CrGmOfbmcHmc2bSH3PihfVF2HllkLSRrcMvnsqg3KTNjSXT86BmcJb0iWYi8bVWp/eYyG2+MHPrEGDk3tyL/69ufPIfGX9zKkHMRC2oyqiamn7r7SwLAX4tVdRzuibXrM/NhBwWplla0xKRAAJtNsBPpcRh2kd6kANDCCn90yJ4VqdF8McCQxhhGmwzlH74yiCf0eVC0S/wHdOd4ySLugKkGERzUrrdbDqhSST9uMKYHTIidMXg2oflKcH6wb+Eg0PLn3Jgoe/d5kvoIPuKufMJhTiQXj9Q5sQIKY6ceKd3PkXDboPlI48AmdebrhdLPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PduJKKTXFIsfNhRg08c2oah3aHxiHm73GdqFmMecpjY=; b=EsupisavtW831g2i/PtjV7dY98k5JlWr9opwrdEsV0aZLJJmPh7ZXCBihKd8l1ttJQMQlByiVgzP2qBVza46g6trWVN6eVyFOKT8cXsVMzhniAzvKMjTIsNw5RboarYuziExFaIAs8M5t96oqujJjtx0E/pwk+bRQbJagx2h0MYgaCC2+TFikDBbhfS63dLzRjiqs3IfnLj+g/X7EtI8vM1YoD4jTWG+4Oh82GUAS7LNpy0DuOZa1iM7Qf+fxz0Lv/aq2cmyomiEEOX8gr1cFtD4BNUrs1mXqAbsRpxz5tVD28tTa5Agh2cthX35HIi72cFzDV17pnuN5qnJMexdZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PduJKKTXFIsfNhRg08c2oah3aHxiHm73GdqFmMecpjY=; b=ptaOipxrZaMw9TXTiG7+7wEMWUw5cvCrszmpAVXQG9D6wdYVma6TOOhfZY5yvTZ1qLolLqCuU4vlfajrPQNLrmRIHcgRYA3jvLEWvOQ8ZtWxUV0nhl7f+Q2lRlZwFCxrsiDMz4Wn4LAQ2EkfGbHasSdUJY1otOg60nM13rlWUPY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) by BYAPR01MB5176.prod.exchangelabs.com (2603:10b6:a03:76::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.34; Wed, 8 Feb 2023 18:43:41 +0000 Received: from DM8PR01MB6824.prod.exchangelabs.com ([fe80::6b5b:1242:818c:e70d]) by DM8PR01MB6824.prod.exchangelabs.com ([fe80::6b5b:1242:818c:e70d%3]) with mapi id 15.20.6086.017; Wed, 8 Feb 2023 18:43:40 +0000 From: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, bhelgaas@google.com Cc: jean-philippe@linaro.org, darren@os.amperecomputing.com, scott@os.amperecomputing.com, gankulkarni@os.amperecomputing.com Subject: [PATCH] PCI/ATS: Allow to enable ATS on VFs even if it is not enabled on PF Date: Wed, 8 Feb 2023 10:43:21 -0800 Message-Id: <20230208184321.867666-1-gankulkarni@os.amperecomputing.com> X-Mailer: git-send-email 2.38.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SN4PR0501CA0036.namprd05.prod.outlook.com (2603:10b6:803:40::49) To DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM8PR01MB6824:EE_|BYAPR01MB5176:EE_ X-MS-Office365-Filtering-Correlation-Id: ef94d597-c804-4cae-101d-08db0a0465a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J+hTav5A1mx27QRXvAteRdZ/zFI5HQIG32Kn7VtbL9tWa7NXb+cH8fQ+BPNkJ2d8hYYiMz8no3CisrMhBZX+AT1pGywN8Z5MvnvJMWyU5OPFtLGu8Vxzu4p6Ws2MvFjJQrFcWoOxVXbO+K0bZqzcMdg0m/h4YrooGalBDEyVkZ24HhpRj4tXvN5dG5Pwwp70tDZkVAUvrliWZDW2vwnkY5BbCYQZhBXx94Ab1BOf0u12LIPJmHMlgk0z1cuWZPjh3c0fvGRvDjKy4lbCLZpCUw6r145nEk4NANJuR1Ujk6hGvc9At7HT1UQvMCjt0JHVL1gljwI7tOgRB8+UuGswioFsiSoVfb75h3DRaWiN6Gcu2D/rdDtkx1itg+9MvtBu3/imzH+ZbCEOIZzCEdFeeJye44IYwuasdbZQhsxXSJZBXYAysDFuBRJxPUusI5oW3yocnYE6tINiQq5GNkwsv7uwBEaOZgF9djxR35NwUYTS5BlDlaTJ4X9kmycSxrEAWUoF0+a+++XrF69Do2c/Od8TRoTdQ9uMXh9pWtPidHUQeCp8L5jrsDe1TWPEdBs42Usuw47ooUIk6rbGCyE65W/y4zK3EXAAMZSYtpgZCd5hQMywTKC+DgX0nyIo3XCtE0MerG173FJXH0gAMjc8Iu6/8SaIUQMKeChMCnndblybpS7DvnSU6gGpRYFQ6tmA1cQEK3LdM/bBWM6oloOqow== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM8PR01MB6824.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(136003)(396003)(366004)(39850400004)(346002)(376002)(451199018)(8936002)(4326008)(38100700002)(478600001)(38350700002)(6486002)(6512007)(2616005)(186003)(26005)(52116002)(6666004)(107886003)(6506007)(1076003)(41300700001)(5660300002)(316002)(8676002)(86362001)(66946007)(66556008)(66476007)(83380400001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D+5FJUp9Gva8CD3G0rJ/rtJBvd/Gvim6t2RZjMZtsrvO8uh95uiTumllv6Z3CPxHhTWp7u1d4fleLvBqcPT/rCzAiaorEZ7cItc81f1IPEQd/xytb1TcTjGK4sYCV2DWTU9rTj9Y/ddv3D/heWqoXuJU39QqwmL3fFpCTYNM1IPkoemzmWabHtMyd2ADW4s7sMpGFWUThpHMwSxlq9SU8oKzifH7l1aJjrbl321wnawZVQsyKCBRuEHq5tLdZCn52SWBirBhbeFgLd+pZRk+IyrSAyw8iOSJh6/f0dThKtGZBXK1azkdOe/bhOGZaO+PKXQX787qliqMEFOq4ntRdbbNKlQal8K2GWI0/qjZx0MzTi2hyhmkxJgLU/GHRb5gNohmqQMphqNK426Mwf5tQQAwT97otQnS+FMYC78PzCMoeuDEhJzgLAdFOuZp004sxS3EjMjMNDMwhHxsKZit3MTrGfSHbHtplDQafwqWsNVfHsZvVGSlQr4i13OC79e4/9fqrgzk1+utD/2hiLzOf8x0tbhpLsVvXGDrqGfbP9f+im1Nbq2wRY7ztxGHuunf9qWZd3g2UL/TNkJxnOjHBtq0c8HXWr1/xfBtB/ziiXIdzhx4PPU0iBMWGOmvchtbWO+xJY+JWUsGFWsJZvDrZW00lCGIce4+EpM+kT7/wjJpt0FUQ48YbgPGqdUBR7+RRxXn14ACTxTL856aqek2hpEBG4rGywlkD4JGdQ7hO2OIzkukoORluRhktUTyRJfv+oxJuBPk6hkrs3caqyMsomAgrP78sH0jgjXOZCPfWvII74fKmgtB9eJoak2RHhJeidB6kcuey0Tokc4WF+PmIc8omxu99PID6JEwj+edqFRtq1ZDLgQ1qH65Bj+lXbV+BGgR8iRw4JVNU1JcnW9RGLGU339X7zFjSMBANCNAl5Q8NXpqbsWO3Qraf2Tdz6Vo/7v+K5esU1bqsgJsjVXfmyY1fJaYiv1kOicuFhYNHOQnyZ9S17RAQLgkDJxqrtyqJA6DDOY/iAZ28jKh3S8f8rCX2ip2UTTIlPYD+Xogp3+Pp8FEdYJmIJbB7mXA1SeHs/rri75L3PeJKZHK4mMq23brDHQK5ypTTSv+Jkh9UJPy5dkhBI3b28BBztYf79Ai9OXBZy1X2Pfa9RehLAOdF/tyyrVZlXUSISaASO6RuZ4e8SGn9EjIadG2rvKJYjiB1WyyPoFvOj14H5bmllWdktysaVG459PFxsDk/jSQjEAWqhDPeFZk5IILpATwGQIpqfvEsfJopU953OeFE4Mtucn+agl22em8DGCgOdKs9/OzsLPlEyrS7xXTCvYlDNMsqQuK4zUdOo+XMOnjRNqSQCCxfQaR/K9FN13MDtCjJtbz7Sm9efanIFNyRFQQz5sobyWZGG4H6rCVuctXDtsTMrQpsNLSX2kVF5yTrpbR2v+6NR799MkFCQNnTCL6pABn+lW7PCIPR1TZehGT9R3i/ElhQ7oBHEhLxr7ajLWS8EkL3MzCpcakn8qyboBI2KPsG05w52Dkk7/T9yffRQwgpUMABVq9tQOgMttQ80M5WsDqiMM4oYkpU7cmAWSsjriK3nUMxcEd3kAU5Wsw7ZDxUhKBeL+sun3sFjUKHcGk1qk= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef94d597-c804-4cae-101d-08db0a0465a2 X-MS-Exchange-CrossTenant-AuthSource: DM8PR01MB6824.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2023 18:43:40.7462 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fznqysSwWkWUguFZ9vEb3wCu43X2us7bw/pTyTuAIcGvkYnNYN0ol5qzKtNXibBu7NPZbdvXo2oVfnqIhKB2q8LQL4yJRjTOP+EkO07KHNuHzFbeepVWC1QOdmzk3sU8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR01MB5176 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757289872988780130?= X-GMAIL-MSGID: =?utf-8?q?1757289872988780130?= |
Series |
PCI/ATS: Allow to enable ATS on VFs even if it is not enabled on PF
|
|
Commit Message
Ganapatrao Kulkarni
Feb. 8, 2023, 6:43 p.m. UTC
As per PCIe specification(section 10.5), If a VF implements an
ATS capability, its associated PF must implement an ATS capability.
The ATS Capabilities in VFs and their associated PFs are permitted to
be enabled independently.
Also, it states that the Smallest Translation Unit (STU) for VFs must be
hardwired to Zero and the associated PF's value applies to VFs STU.
The current code allows to enable ATS on VFs only if it is already
enabled on associated PF, which is not necessary as per the specification.
It is only required to have valid STU programmed on PF to enable
ATS on VFs. Adding code to write the first VFs STU to a PF's STU
when PFs ATS is not enabled.
Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
---
drivers/pci/ats.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
Comments
On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: > As per PCIe specification(section 10.5), If a VF implements an > ATS capability, its associated PF must implement an ATS capability. > The ATS Capabilities in VFs and their associated PFs are permitted to > be enabled independently. > Also, it states that the Smallest Translation Unit (STU) for VFs must be > hardwired to Zero and the associated PF's value applies to VFs STU. > > The current code allows to enable ATS on VFs only if it is already > enabled on associated PF, which is not necessary as per the specification. > > It is only required to have valid STU programmed on PF to enable > ATS on VFs. Adding code to write the first VFs STU to a PF's STU > when PFs ATS is not enabled. Can you please add here quotes from the spec and its version? I don't see anything like this in my version of PCIe specification. Thanks > > Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> > --- > drivers/pci/ats.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c > index f9cc2e10b676..a97ec67201d1 100644 > --- a/drivers/pci/ats.c > +++ b/drivers/pci/ats.c > @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps) > if (ps < PCI_ATS_MIN_STU) > return -EINVAL; > > - /* > - * Note that enabling ATS on a VF fails unless it's already enabled > - * with the same STU on the PF. > - */ > ctrl = PCI_ATS_CTRL_ENABLE; > if (dev->is_virtfn) { > pdev = pci_physfn(dev); > + > + if (!pdev->ats_enabled && > + (pdev->ats_stu < PCI_ATS_MIN_STU)) { > + u16 ctrl2; > + > + /* Associated PF's STU value applies to VFs. */ > + pdev->ats_stu = ps; > + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - PCI_ATS_MIN_STU); > + pci_write_config_word(pdev, pdev->ats_cap + PCI_ATS_CTRL, ctrl2); > + } > + > if (pdev->ats_stu != ps) > return -EINVAL; > } else { > -- > 2.39.1 >
[+cc Will, Robin, Joerg for arm-smmu-v3 page size question] On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: > On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: > > As per PCIe specification(section 10.5), If a VF implements an > > ATS capability, its associated PF must implement an ATS capability. > > The ATS Capabilities in VFs and their associated PFs are permitted to > > be enabled independently. > > Also, it states that the Smallest Translation Unit (STU) for VFs must be > > hardwired to Zero and the associated PF's value applies to VFs STU. > > > > The current code allows to enable ATS on VFs only if it is already > > enabled on associated PF, which is not necessary as per the specification. > > > > It is only required to have valid STU programmed on PF to enable > > ATS on VFs. Adding code to write the first VFs STU to a PF's STU > > when PFs ATS is not enabled. > > Can you please add here quotes from the spec and its version? I don't see > anything like this in my version of PCIe specification. See PCIe r6.0, sec 10.5.1. > > Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> > > --- > > drivers/pci/ats.c | 15 +++++++++++---- > > 1 file changed, 11 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c > > index f9cc2e10b676..a97ec67201d1 100644 > > --- a/drivers/pci/ats.c > > +++ b/drivers/pci/ats.c > > @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps) > > if (ps < PCI_ATS_MIN_STU) > > return -EINVAL; > > > > - /* > > - * Note that enabling ATS on a VF fails unless it's already enabled > > - * with the same STU on the PF. > > - */ > > ctrl = PCI_ATS_CTRL_ENABLE; > > if (dev->is_virtfn) { > > pdev = pci_physfn(dev); > > + > > + if (!pdev->ats_enabled && > > + (pdev->ats_stu < PCI_ATS_MIN_STU)) { > > + u16 ctrl2; > > + > > + /* Associated PF's STU value applies to VFs. */ > > + pdev->ats_stu = ps; > > + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - PCI_ATS_MIN_STU); > > + pci_write_config_word(pdev, pdev->ats_cap + PCI_ATS_CTRL, ctrl2); > > + } For reference, it is this way because of edc90fee916b ("PCI: Allocate ATS struct during enumeration"). The rationale was that since the PF STU applies to all VFs, we should require that the PF STU be programmed before enabling ATS on any of the VFs. This patch relaxes that so the PF STU would be set either by (a) enabling ATS on the PF or (b) enabling ATS on the first VF. This looks racy because theoretically drivers for VF A and VF B could independently call pci_enable_ats() with different IOMMU page sizes, and we don't know which will get there first. Most callers supply a compile-time constant (PAGE_SHIFT or VTD_PAGE_SHIFT), so it won't matter. arm_smmu_enable_ats() is fancier, but I *assume* it would still supply the same IOMMU page size for all VFs of a given PF. But it's still kind of ugly to call pci_enable_ats(dev_A) and have it muck with the configuration of dev_B. Maybe we should configure the PF STU (without enabling ATS) at enumeration-time in pci_ats_init()? Is there some way to get the IOMMU page size at that time? > > if (pdev->ats_stu != ps) > > return -EINVAL; > > } else { > > -- > > 2.39.1 > >
On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote: > [+cc Will, Robin, Joerg for arm-smmu-v3 page size question] > > On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: > > On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: > > > As per PCIe specification(section 10.5), If a VF implements an > > > ATS capability, its associated PF must implement an ATS capability. > > > The ATS Capabilities in VFs and their associated PFs are permitted to > > > be enabled independently. > > > Also, it states that the Smallest Translation Unit (STU) for VFs must be > > > hardwired to Zero and the associated PF's value applies to VFs STU. > > > > > > The current code allows to enable ATS on VFs only if it is already > > > enabled on associated PF, which is not necessary as per the specification. > > > > > > It is only required to have valid STU programmed on PF to enable > > > ATS on VFs. Adding code to write the first VFs STU to a PF's STU > > > when PFs ATS is not enabled. > > > > Can you please add here quotes from the spec and its version? I don't see > > anything like this in my version of PCIe specification. > > See PCIe r6.0, sec 10.5.1. Awesome, I have old versions. Thanks
On Thu, Feb 16, 2023 at 09:26:15AM +0200, Leon Romanovsky wrote: > On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote: > > [+cc Will, Robin, Joerg for arm-smmu-v3 page size question] > > > > On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: > > > On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: > > > > As per PCIe specification(section 10.5), If a VF implements an > > > > ATS capability, its associated PF must implement an ATS capability. > > > > The ATS Capabilities in VFs and their associated PFs are permitted to > > > > be enabled independently. > > > > Also, it states that the Smallest Translation Unit (STU) for VFs must be > > > > hardwired to Zero and the associated PF's value applies to VFs STU. > > > > > > > > The current code allows to enable ATS on VFs only if it is already > > > > enabled on associated PF, which is not necessary as per the specification. > > > > > > > > It is only required to have valid STU programmed on PF to enable > > > > ATS on VFs. Adding code to write the first VFs STU to a PF's STU > > > > when PFs ATS is not enabled. > > > > > > Can you please add here quotes from the spec and its version? I don't see > > > anything like this in my version of PCIe specification. > > > > See PCIe r6.0, sec 10.5.1. > > Awesome, I have old versions. OK, where should I read about this sentence? "It is only required to have valid STU programmed on PF to enable ATS on VFs. Adding code to write the first VFs STU to a PF's STU when PFs ATS is not enabled." From spec: "Smallest Translation Unit (STU) - This value indicates to the Function the minimum number of 4096-byte blocks that is indicated in a Translation Completions or Invalidate Requests. This is a power of 2 multiplier and the number of blocks is 2STU. A value of 0 0000b indicates one block and a value of 1 1111b indicates 231 blocks (or 8 TB total) For VFs, this field must be hardwired to Zero. The associated PF's value applies. Default value is 0 0000b" And enable bit doesn't have any sentence about STU. Thanks
On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote: > [+cc Will, Robin, Joerg for arm-smmu-v3 page size question] > > On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: > > On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: > > > As per PCIe specification(section 10.5), If a VF implements an > > > ATS capability, its associated PF must implement an ATS capability. > > > The ATS Capabilities in VFs and their associated PFs are permitted to > > > be enabled independently. Well, the spec is one thing, existing hardware the other. Have you checked the history of the PF-before-VF requirement before making that change? It is possible that early PASID-capable hardware actually required PF-before-VF enablement of ATS. Regards, Joerg
On Thu, Feb 16, 2023 at 09:46:51AM +0200, Leon Romanovsky wrote: > On Thu, Feb 16, 2023 at 09:26:15AM +0200, Leon Romanovsky wrote: > > On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote: > > > [+cc Will, Robin, Joerg for arm-smmu-v3 page size question] > > > > > > On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: > > > > On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: > > > > > As per PCIe specification(section 10.5), If a VF implements an > > > > > ATS capability, its associated PF must implement an ATS capability. > > > > > The ATS Capabilities in VFs and their associated PFs are permitted to > > > > > be enabled independently. > > > > > Also, it states that the Smallest Translation Unit (STU) for VFs must be > > > > > hardwired to Zero and the associated PF's value applies to VFs STU. > > > > > > > > > > The current code allows to enable ATS on VFs only if it is already > > > > > enabled on associated PF, which is not necessary as per the specification. > > > > > > > > > > It is only required to have valid STU programmed on PF to enable > > > > > ATS on VFs. Adding code to write the first VFs STU to a PF's STU > > > > > when PFs ATS is not enabled. > > > > > > > > Can you please add here quotes from the spec and its version? I don't see > > > > anything like this in my version of PCIe specification. In PCIe r6.0, 10.5.1 ATS Extended Capability: "The ATS Capabilities in VFs and their associated PFs are permitted to be enabled independently." > For VFs, this field must be hardwired to Zero. The associated PF's value applies. > Default value is 0 0000b" And this sentence indicates that the PF's STU should be configured appropriately in order to use ATS in the VF. So a driver is permitted to enable the VF ATS capability without enabling the PF ATS cap, though the STU value of the PF cap still applies. But the first sentence is weak ("permitted" instead of "required"), so as Joerg said, some device implementations may still require to enable the PF cap in order to enable the VF cap. Maybe we could have a list of vendor:device IDs which allow enabling the VF cap independently? Thanks, Jean
On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote: > [+cc Will, Robin, Joerg for arm-smmu-v3 page size question] > > On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: > > On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: > > > As per PCIe specification(section 10.5), If a VF implements an > > > ATS capability, its associated PF must implement an ATS capability. > > > The ATS Capabilities in VFs and their associated PFs are permitted to > > > be enabled independently. > > > Also, it states that the Smallest Translation Unit (STU) for VFs must be > > > hardwired to Zero and the associated PF's value applies to VFs STU. > > > > > > The current code allows to enable ATS on VFs only if it is already > > > enabled on associated PF, which is not necessary as per the specification. > > > > > > It is only required to have valid STU programmed on PF to enable > > > ATS on VFs. Adding code to write the first VFs STU to a PF's STU > > > when PFs ATS is not enabled. > > > > Can you please add here quotes from the spec and its version? I don't see > > anything like this in my version of PCIe specification. > > See PCIe r6.0, sec 10.5.1. > > > > Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> > > > --- > > > drivers/pci/ats.c | 15 +++++++++++---- > > > 1 file changed, 11 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c > > > index f9cc2e10b676..a97ec67201d1 100644 > > > --- a/drivers/pci/ats.c > > > +++ b/drivers/pci/ats.c > > > @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps) > > > if (ps < PCI_ATS_MIN_STU) > > > return -EINVAL; > > > > > > - /* > > > - * Note that enabling ATS on a VF fails unless it's already enabled > > > - * with the same STU on the PF. > > > - */ > > > ctrl = PCI_ATS_CTRL_ENABLE; > > > if (dev->is_virtfn) { > > > pdev = pci_physfn(dev); > > > + > > > + if (!pdev->ats_enabled && > > > + (pdev->ats_stu < PCI_ATS_MIN_STU)) { > > > + u16 ctrl2; > > > + > > > + /* Associated PF's STU value applies to VFs. */ > > > + pdev->ats_stu = ps; > > > + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - PCI_ATS_MIN_STU); > > > + pci_write_config_word(pdev, pdev->ats_cap + PCI_ATS_CTRL, ctrl2); > > > + } > > For reference, it is this way because of edc90fee916b ("PCI: Allocate > ATS struct during enumeration"). The rationale was that since the PF > STU applies to all VFs, we should require that the PF STU be > programmed before enabling ATS on any of the VFs. > > This patch relaxes that so the PF STU would be set either by (a) > enabling ATS on the PF or (b) enabling ATS on the first VF. > > This looks racy because theoretically drivers for VF A and VF B could > independently call pci_enable_ats() with different IOMMU page sizes, > and we don't know which will get there first. > > Most callers supply a compile-time constant (PAGE_SHIFT or > VTD_PAGE_SHIFT), so it won't matter. arm_smmu_enable_ats() is > fancier, but I *assume* it would still supply the same IOMMU page size > for all VFs of a given PF. > > But it's still kind of ugly to call pci_enable_ats(dev_A) and have it > muck with the configuration of dev_B. Maybe we should configure the > PF STU (without enabling ATS) at enumeration-time in pci_ats_init()? > Is there some way to get the IOMMU page size at that time? Not really, on Arm the supported page sizes are discovered when probing the SMMU registers, which may happen later than enumeration, during module loading. What this patch is trying to solve is: * want the PF to bypass SMMU translation, and the VF to undergo SMMU translation (in order to assign it to a VM) * SMMU forbids enabling ATS for a configuration that bypasses translation. So the PF ATS capability must be left disabled. For this situation I wonder if we could do: the SMMU driver, seeing that the PF is configured to bypass, calls a new function "pci_configure_ats()" instead of pci_enable_ats(), which would only set the STU but leave the cap disabled. Then when setting up translation for the VF, the SMMU driver calls pci_enable_ats() as usual, which sees the PF's STU set appropriately and succeeds. Thanks, Jean
On 16-02-2023 04:42 pm, Jean-Philippe Brucker wrote: > On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote: >> [+cc Will, Robin, Joerg for arm-smmu-v3 page size question] >> >> On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: >>> On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: >>>> As per PCIe specification(section 10.5), If a VF implements an >>>> ATS capability, its associated PF must implement an ATS capability. >>>> The ATS Capabilities in VFs and their associated PFs are permitted to >>>> be enabled independently. >>>> Also, it states that the Smallest Translation Unit (STU) for VFs must be >>>> hardwired to Zero and the associated PF's value applies to VFs STU. >>>> >>>> The current code allows to enable ATS on VFs only if it is already >>>> enabled on associated PF, which is not necessary as per the specification. >>>> >>>> It is only required to have valid STU programmed on PF to enable >>>> ATS on VFs. Adding code to write the first VFs STU to a PF's STU >>>> when PFs ATS is not enabled. >>> >>> Can you please add here quotes from the spec and its version? I don't see >>> anything like this in my version of PCIe specification. >> >> See PCIe r6.0, sec 10.5.1. >> >>>> Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> >>>> --- >>>> drivers/pci/ats.c | 15 +++++++++++---- >>>> 1 file changed, 11 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c >>>> index f9cc2e10b676..a97ec67201d1 100644 >>>> --- a/drivers/pci/ats.c >>>> +++ b/drivers/pci/ats.c >>>> @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps) >>>> if (ps < PCI_ATS_MIN_STU) >>>> return -EINVAL; >>>> >>>> - /* >>>> - * Note that enabling ATS on a VF fails unless it's already enabled >>>> - * with the same STU on the PF. >>>> - */ >>>> ctrl = PCI_ATS_CTRL_ENABLE; >>>> if (dev->is_virtfn) { >>>> pdev = pci_physfn(dev); >>>> + >>>> + if (!pdev->ats_enabled && >>>> + (pdev->ats_stu < PCI_ATS_MIN_STU)) { >>>> + u16 ctrl2; >>>> + >>>> + /* Associated PF's STU value applies to VFs. */ >>>> + pdev->ats_stu = ps; >>>> + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - PCI_ATS_MIN_STU); >>>> + pci_write_config_word(pdev, pdev->ats_cap + PCI_ATS_CTRL, ctrl2); >>>> + } >> >> For reference, it is this way because of edc90fee916b ("PCI: Allocate >> ATS struct during enumeration"). The rationale was that since the PF >> STU applies to all VFs, we should require that the PF STU be >> programmed before enabling ATS on any of the VFs. >> >> This patch relaxes that so the PF STU would be set either by (a) >> enabling ATS on the PF or (b) enabling ATS on the first VF. >> >> This looks racy because theoretically drivers for VF A and VF B could >> independently call pci_enable_ats() with different IOMMU page sizes, >> and we don't know which will get there first. >> >> Most callers supply a compile-time constant (PAGE_SHIFT or >> VTD_PAGE_SHIFT), so it won't matter. arm_smmu_enable_ats() is >> fancier, but I *assume* it would still supply the same IOMMU page size >> for all VFs of a given PF. >> >> But it's still kind of ugly to call pci_enable_ats(dev_A) and have it >> muck with the configuration of dev_B. Maybe we should configure the >> PF STU (without enabling ATS) at enumeration-time in pci_ats_init()? >> Is there some way to get the IOMMU page size at that time? > > Not really, on Arm the supported page sizes are discovered when probing > the SMMU registers, which may happen later than enumeration, during module > loading. > > What this patch is trying to solve is: > * want the PF to bypass SMMU translation, and the VF to undergo SMMU > translation (in order to assign it to a VM) > * SMMU forbids enabling ATS for a configuration that bypasses translation. > So the PF ATS capability must be left disabled. > > For this situation I wonder if we could do: the SMMU driver, seeing that > the PF is configured to bypass, calls a new function "pci_configure_ats()" IMO, This seems to be feasible solution for this situation, which addresses SMMU-ATS expectation in bypass and we could avoid PCI VFs race. pci_configure_ats() can be called to program/configure STU of a PF in smmu-bypass mode. > instead of pci_enable_ats(), which would only set the STU but leave the > cap disabled. Then when setting up translation for the VF, the SMMU driver > calls pci_enable_ats() as usual, which sees the PF's STU set appropriately > and succeeds. > > Thanks, > Jean Thanks, Ganapat
Hi Bjorn, On 16-02-2023 05:06 pm, Ganapatrao Kulkarni wrote: > > > On 16-02-2023 04:42 pm, Jean-Philippe Brucker wrote: >> On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote: >>> [+cc Will, Robin, Joerg for arm-smmu-v3 page size question] >>> >>> On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: >>>> On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: >>>>> As per PCIe specification(section 10.5), If a VF implements an >>>>> ATS capability, its associated PF must implement an ATS capability. >>>>> The ATS Capabilities in VFs and their associated PFs are permitted to >>>>> be enabled independently. >>>>> Also, it states that the Smallest Translation Unit (STU) for VFs >>>>> must be >>>>> hardwired to Zero and the associated PF's value applies to VFs STU. >>>>> >>>>> The current code allows to enable ATS on VFs only if it is already >>>>> enabled on associated PF, which is not necessary as per the >>>>> specification. >>>>> >>>>> It is only required to have valid STU programmed on PF to enable >>>>> ATS on VFs. Adding code to write the first VFs STU to a PF's STU >>>>> when PFs ATS is not enabled. >>>> >>>> Can you please add here quotes from the spec and its version? I >>>> don't see >>>> anything like this in my version of PCIe specification. >>> >>> See PCIe r6.0, sec 10.5.1. >>> >>>>> Signed-off-by: Ganapatrao Kulkarni >>>>> <gankulkarni@os.amperecomputing.com> >>>>> --- >>>>> drivers/pci/ats.c | 15 +++++++++++---- >>>>> 1 file changed, 11 insertions(+), 4 deletions(-) >>>>> >>>>> diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c >>>>> index f9cc2e10b676..a97ec67201d1 100644 >>>>> --- a/drivers/pci/ats.c >>>>> +++ b/drivers/pci/ats.c >>>>> @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps) >>>>> if (ps < PCI_ATS_MIN_STU) >>>>> return -EINVAL; >>>>> - /* >>>>> - * Note that enabling ATS on a VF fails unless it's already >>>>> enabled >>>>> - * with the same STU on the PF. >>>>> - */ >>>>> ctrl = PCI_ATS_CTRL_ENABLE; >>>>> if (dev->is_virtfn) { >>>>> pdev = pci_physfn(dev); >>>>> + >>>>> + if (!pdev->ats_enabled && >>>>> + (pdev->ats_stu < PCI_ATS_MIN_STU)) { >>>>> + u16 ctrl2; >>>>> + >>>>> + /* Associated PF's STU value applies to VFs. */ >>>>> + pdev->ats_stu = ps; >>>>> + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - >>>>> PCI_ATS_MIN_STU); >>>>> + pci_write_config_word(pdev, pdev->ats_cap + >>>>> PCI_ATS_CTRL, ctrl2); >>>>> + } >>> >>> For reference, it is this way because of edc90fee916b ("PCI: Allocate >>> ATS struct during enumeration"). The rationale was that since the PF >>> STU applies to all VFs, we should require that the PF STU be >>> programmed before enabling ATS on any of the VFs. >>> >>> This patch relaxes that so the PF STU would be set either by (a) >>> enabling ATS on the PF or (b) enabling ATS on the first VF. >>> >>> This looks racy because theoretically drivers for VF A and VF B could >>> independently call pci_enable_ats() with different IOMMU page sizes, >>> and we don't know which will get there first. >>> >>> Most callers supply a compile-time constant (PAGE_SHIFT or >>> VTD_PAGE_SHIFT), so it won't matter. arm_smmu_enable_ats() is >>> fancier, but I *assume* it would still supply the same IOMMU page size >>> for all VFs of a given PF. >>> >>> But it's still kind of ugly to call pci_enable_ats(dev_A) and have it >>> muck with the configuration of dev_B. Maybe we should configure the >>> PF STU (without enabling ATS) at enumeration-time in pci_ats_init()? >>> Is there some way to get the IOMMU page size at that time? >> >> Not really, on Arm the supported page sizes are discovered when probing >> the SMMU registers, which may happen later than enumeration, during >> module >> loading. >> >> What this patch is trying to solve is: >> * want the PF to bypass SMMU translation, and the VF to undergo SMMU >> translation (in order to assign it to a VM) >> * SMMU forbids enabling ATS for a configuration that bypasses >> translation. >> So the PF ATS capability must be left disabled. >> >> For this situation I wonder if we could do: the SMMU driver, seeing that >> the PF is configured to bypass, calls a new function >> "pci_configure_ats()" > > IMO, This seems to be feasible solution for this situation, which > addresses SMMU-ATS expectation in bypass and we could avoid PCI VFs > race. pci_configure_ats() can be called to program/configure STU of a PF > in smmu-bypass mode. > Can we add pci_configure_ats/pci_configure_ats_stu helper? >> instead of pci_enable_ats(), which would only set the STU but leave the >> cap disabled. Then when setting up translation for the VF, the SMMU >> driver >> calls pci_enable_ats() as usual, which sees the PF's STU set >> appropriately >> and succeeds. >> >> Thanks, >> Jean > > Thanks, > Ganapat Thanks, Ganapat
On Thu, Feb 16, 2023 at 11:12:24AM +0000, Jean-Philippe Brucker wrote: > On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote: > > On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote: > > > On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote: > > > > As per PCIe specification(section 10.5), If a VF implements an > > > > ATS capability, its associated PF must implement an ATS capability. > > > > The ATS Capabilities in VFs and their associated PFs are permitted to > > > > be enabled independently. > > > > Also, it states that the Smallest Translation Unit (STU) for VFs must be > > > > hardwired to Zero and the associated PF's value applies to VFs STU. > > > > > > > > The current code allows to enable ATS on VFs only if it is already > > > > enabled on associated PF, which is not necessary as per the specification. > > > > > > > > It is only required to have valid STU programmed on PF to enable > > > > ATS on VFs. Adding code to write the first VFs STU to a PF's STU > > > > when PFs ATS is not enabled. > > > > > > Can you please add here quotes from the spec and its version? I don't see > > > anything like this in my version of PCIe specification. > > > > See PCIe r6.0, sec 10.5.1. > > > > > > Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> > > > > --- > > > > drivers/pci/ats.c | 15 +++++++++++---- > > > > 1 file changed, 11 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c > > > > index f9cc2e10b676..a97ec67201d1 100644 > > > > --- a/drivers/pci/ats.c > > > > +++ b/drivers/pci/ats.c > > > > @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps) > > > > if (ps < PCI_ATS_MIN_STU) > > > > return -EINVAL; > > > > > > > > - /* > > > > - * Note that enabling ATS on a VF fails unless it's already enabled > > > > - * with the same STU on the PF. > > > > - */ > > > > ctrl = PCI_ATS_CTRL_ENABLE; > > > > if (dev->is_virtfn) { > > > > pdev = pci_physfn(dev); > > > > + > > > > + if (!pdev->ats_enabled && > > > > + (pdev->ats_stu < PCI_ATS_MIN_STU)) { > > > > + u16 ctrl2; > > > > + > > > > + /* Associated PF's STU value applies to VFs. */ > > > > + pdev->ats_stu = ps; > > > > + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - PCI_ATS_MIN_STU); > > > > + pci_write_config_word(pdev, pdev->ats_cap + PCI_ATS_CTRL, ctrl2); > > > > + } > > > > For reference, it is this way because of edc90fee916b ("PCI: Allocate > > ATS struct during enumeration"). The rationale was that since the PF > > STU applies to all VFs, we should require that the PF STU be > > programmed before enabling ATS on any of the VFs. > > > > This patch relaxes that so the PF STU would be set either by (a) > > enabling ATS on the PF or (b) enabling ATS on the first VF. > > > > This looks racy because theoretically drivers for VF A and VF B could > > independently call pci_enable_ats() with different IOMMU page sizes, > > and we don't know which will get there first. > > > > Most callers supply a compile-time constant (PAGE_SHIFT or > > VTD_PAGE_SHIFT), so it won't matter. arm_smmu_enable_ats() is > > fancier, but I *assume* it would still supply the same IOMMU page size > > for all VFs of a given PF. > > > > But it's still kind of ugly to call pci_enable_ats(dev_A) and have it > > muck with the configuration of dev_B. Maybe we should configure the > > PF STU (without enabling ATS) at enumeration-time in pci_ats_init()? > > Is there some way to get the IOMMU page size at that time? > > Not really, on Arm the supported page sizes are discovered when probing > the SMMU registers, which may happen later than enumeration, during module > loading. > > What this patch is trying to solve is: > * want the PF to bypass SMMU translation, and the VF to undergo SMMU > translation (in order to assign it to a VM) > * SMMU forbids enabling ATS for a configuration that bypasses translation. > So the PF ATS capability must be left disabled. > > For this situation I wonder if we could do: the SMMU driver, seeing that > the PF is configured to bypass, calls a new function "pci_configure_ats()" > instead of pci_enable_ats(), which would only set the STU but leave the > cap disabled. Then when setting up translation for the VF, the SMMU driver > calls pci_enable_ats() as usual, which sees the PF's STU set appropriately > and succeeds. Seems reasonable. It's weird to me that the SMMU is between PCI and memory, but the driver seems to insert itself in the middle after PCI enumeration. And maybe even after some PCI device driver binding? But I guess if you arrange for the SMMU driver to configure the PF before the VF driver gets started, that's all we need from a PCI perspective. Bjorn
On Tue, Feb 21, 2023 at 09:46:24AM -0600, Bjorn Helgaas wrote: > It's weird to me that the SMMU is between PCI and memory, but the > driver seems to insert itself in the middle after PCI enumeration. > And maybe even after some PCI device driver binding? No this shouldn't happen, because device drivers expect DMA to be operational in their probe() function, so at that point the IOMMU must be configured. The core and IOMMU subsystems enforce probe dependency between the SMMU and the PCI device, using links described by ACPI or device tree. Thanks, Jean
diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index f9cc2e10b676..a97ec67201d1 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps) if (ps < PCI_ATS_MIN_STU) return -EINVAL; - /* - * Note that enabling ATS on a VF fails unless it's already enabled - * with the same STU on the PF. - */ ctrl = PCI_ATS_CTRL_ENABLE; if (dev->is_virtfn) { pdev = pci_physfn(dev); + + if (!pdev->ats_enabled && + (pdev->ats_stu < PCI_ATS_MIN_STU)) { + u16 ctrl2; + + /* Associated PF's STU value applies to VFs. */ + pdev->ats_stu = ps; + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - PCI_ATS_MIN_STU); + pci_write_config_word(pdev, pdev->ats_cap + PCI_ATS_CTRL, ctrl2); + } + if (pdev->ats_stu != ps) return -EINVAL; } else {