From patchwork Fri Jan 26 18:15:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13533114 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB35EC47422 for ; Fri, 26 Jan 2024 18:16:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wpZUvR3lXmXSRsgfYqk/Wk2Q4raJ3nh6SFexGBZRTA4=; b=pWMYnNDjSDD5/I PxQFpYsGbu/xggVbp79ryerEQcLoKytMGCPlHL9IMkmGERx0iIVdpZ0uy2ixQuk7vZSwM+GOapdAf e1aqRPW2FXsrTHnD9D6iTOxYIxr3aFJM1+EdL3b/3JeqIGuH2kaSLzVNWCPWVDZZrEt03w3capitj FF4jkHlnurIHK1a+uRbSnuwD1mlPmKlgMbgs0lxDlNMW9Y3I+MkF3vy3Eg79vso7F5xkbEQigYmD+ cVcqIl1cmcjBf/lUDCTpi50pU3aKO0h3mevbp20SP4Prl/oRezZeTkJ6CD8YKucZlIS3fFsWVAj6z M5HAz33fviB3xK2krhkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQkg-0000000523k-1O5V; Fri, 26 Jan 2024 18:16:30 +0000 Received: from mail-dm6nam10on20605.outbound.protection.outlook.com ([2a01:111:f400:7e88::605] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQk4-000000051Vs-17ak for linux-arm-kernel@lists.infradead.org; Fri, 26 Jan 2024 18:15:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RuFwmBn2n8zXVmWgvKNJ52CH+SCSkrSr5ileNVPqRrTFeMSOG57OLg29NMGOJH6t7E1NyAHgUUnuEgP5bP87qwNrzoH63O6S4ZrQK2pY2Ixb8o0+30ECjx7ulqTLqKgih44pzfJDSJ4M7oqI9EzohqAkxkGCAuzZiAiJtYc1Y7aLiaei/kxE+4xI0h/MOg64GwYW/pTtqSTvFjxyPbxvH9Eutw7N+xeBkgw4IqbWS0l1NBRkYxj/B1haXPBF0wR371DUz/gx9uaaCtpGS8tppjIYfut4xDXhb3pKWmGpBljwnb4CdPecsL1RteXnLQZV9h7ODME8r9xu2EFAvRm2JQ== 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=OjupnVJ2T0we0nVfAmgNqoQcbNhw/8HuxqhGeas1gDk=; b=BYQc8OQFkHH3f1dsDtwNokpcCS+UAROSzk/9fjdQQcopVW2gAv3TuUmTq8bK2l7Sh+BRp4pYUKOMN08uiS4hDshXJCuIP7yEv9dt0J3MtUhK2sk6JKarOs8uRoNipQjIMbNqvUzLEFC5g4RlQO15Flfxkv4UCRGOFD3pkmsslF7AkXj8GRzCzRtFLE6ak1aORZJ8Nu1HlVPQNq9RF3Gkapxd36raWmOrwsA72vkCb6W+L2hl9uQSO70Er2Tojes/DSQM32hkZYKAgMFDBRea4gTWOe/+AOr9E9HObxCvF1eDZ/KBSjGSWyOLJC38S+wcIT8A20qDAAst9O4vI28JXw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OjupnVJ2T0we0nVfAmgNqoQcbNhw/8HuxqhGeas1gDk=; b=Zd3ltFGad2OH5IoZbG7I4q5WvlXOmKza5M7aVZrR+epwXEt6yAqFa/1lHCc1kjOndCBoC7Mkf3j/eiWa2acEhZ9jDY4DNtolDuf5nftdH2wKJ0weg9QaaJksaPeL/4dITjxgk5+DAwH8PZmFQXmk5Emlz5XbmnRabOBujbJzm0LPVgTp0W9pKEYz7RfaKFQt/XOAyLSCb0mLRhht0I1nT7b7Pf1bQ2+IxLoBdwHyCI7B7GseRRxxmOd5xZB7Fvd2ujK/+5cvb/miV6QUXJmp+kvhXhcXNWeqZcHv5GyROi4bbQr4f+/yQjet5wwA+ynXvCHWGtViA2jvJvbgpH6IKQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by PH7PR12MB7185.namprd12.prod.outlook.com (2603:10b6:510:201::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.29; Fri, 26 Jan 2024 18:15:37 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7228.022; Fri, 26 Jan 2024 18:15:37 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v4 19/27] iommu/arm-smmu-v3: Keep track of arm_smmu_master_domain for SVA Date: Fri, 26 Jan 2024 14:15:21 -0400 Message-ID: <19-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: SN6PR16CA0040.namprd16.prod.outlook.com (2603:10b6:805:ca::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH7PR12MB7185:EE_ X-MS-Office365-Filtering-Correlation-Id: 84361178-3f99-4e6c-3842-08dc1e9ac90f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7uwIusB7BChwD19YiRzf1iQsN0XsI//KMUPlaVYU+nX4xcF2ZJjjeNfMZyQQKvBTajkDPvC+q0l9Np9SR515k79Sqirw/bsaNfZ9toSng+ys1orNCOZbSFgO0q+g8w+EAFdGmkiHBGLxFDDRA7MSx1M/WDUjhIj1Z4gXAdamVs0x1KtistSbyOQQ1MsMR5Be0Bhu7OgoNOc2j/ARili0uht2egU58SdL4pAfJKuCofGeMggUV8wdK7MreMiZ06l6X0LwLqh7XfX8AIJrQozw3ArHgYWUmPWpWVRvXiNFH5FWpwSQEOsRsp3C6aaZND8lcupz8IVKvkVfeqeXHYnicN0jkijGq/kQaHpjJguDfpHLxITgb2jric1ufS6YhZP89Y7oFcXp5ppyZe+jycJHmlqUoxL5XXtOiG/c/wwzDNE1GRYD6ViRmyriGMPw4jFVP5eO+grtq5v+tjvay39i8m0PLynC8MyHSj3gG3cgjqHplo5xlXzBr7gidpjv1n0ECUaZELv6uz0NfSDY7f2L+LrkJj+UOCxpRdhTtHzLcWIKcoljQxOvU9jsDKkp42B6 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(39860400002)(376002)(136003)(366004)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(8676002)(5660300002)(66946007)(316002)(66476007)(478600001)(110136005)(54906003)(26005)(6486002)(6512007)(6666004)(2906002)(8936002)(7416002)(2616005)(66556008)(4326008)(6506007)(36756003)(38100700002)(83380400001)(41300700001)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2Y3MHfiTez0GkSf+zBMccv6Fz/YTkxALL5c4EwK85gIVfcnwhPxG+r4juFRKaU8+697EWIhwBXs+q4S7AKUCShEue8+EYB5/PhDi+hdJeuQAcVp8IBiYfIMrCAlkHWl4a+knkmiB4/kEzB5U1XBDTcRft5JW+GjpMNV8UXIAV2nW6dBlkFbuqO+sGYSoSvN2mUeQUUskiCzcsx8uqlIS0prmnAC7PFWKTgRg3k29MnEiySdykdhyDEPyIzh6ey8plaFmvxS75yCGHNGH368+h69gPaYxcFUKs+qLuq4Ws8FW7QDlI6V71HWl0zM7jQ3uEd2iCs7g9Wp4j4TwEIXkTPf94jRkXbYdTn5HwQ3lxWrnGV/Pk6vpRYitmzkUB9ku9tdglu7KKuCsTMWzQ0Ax+i+Cu2OrSKYfSe1MXZM5kGgkcSoi1cht1vaZA/SHydIrZmkhUFSaNESW/NPeSu0puyHHAgr9OL51WptPm7IacKYgEbYRYG66sNX2jfqnz5lI7Y5CpXp8ZKbBaG1rIZVQ3s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com X-MS-Exchange-CrossTenant-Network-Message-Id: 84361178-3f99-4e6c-3842-08dc1e9ac90f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:15:32.7869 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZZ2TQc+3hWys0v2EKvLhi6kwrQn43ji4cbehgTR844VIUh8f4YEC7dV6XRb2EjGD X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7185 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240126_101552_445463_F3276E0C X-CRM114-Status: GOOD ( 11.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the smmu_domain->devices list is unused for SVA domains. Fill it in with the SSID and master of every arm_smmu_set_pasid() using the same logic as the RID attach. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index a8e9276990b006..961000f308b9bd 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2592,7 +2592,8 @@ to_smmu_domain_devices(struct iommu_domain *domain) /* The domain can be NULL only when processing the first attach */ if (!domain) return NULL; - if (domain->type & __IOMMU_DOMAIN_PAGING) + if ((domain->type & __IOMMU_DOMAIN_PAGING) || + domain->type == IOMMU_DOMAIN_SVA) return to_smmu_domain(domain); return NULL; } @@ -2803,7 +2804,9 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, ioasid_t pasid, const struct arm_smmu_cd *cd) { + struct attach_state state = {.ssid = pasid}; struct arm_smmu_cd *cdptr; + int ret; if (!arm_smmu_is_s1_domain(iommu_get_domain_for_dev(master->dev))) return -ENODEV; @@ -2811,14 +2814,30 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, cdptr = arm_smmu_get_cd_ptr(master, pasid); if (!cdptr) return -ENOMEM; + + mutex_lock(&arm_smmu_asid_lock); + ret = arm_smmu_attach_prepare(master, &smmu_domain->domain, &state); + if (ret) + goto out_unlock; + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); - return 0; + + arm_smmu_attach_commit(master, &state); + +out_unlock: + mutex_unlock(&arm_smmu_asid_lock); + return ret; } void arm_smmu_remove_pasid(struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, ioasid_t pasid) { + mutex_lock(&arm_smmu_asid_lock); arm_smmu_clear_cd(master, pasid); + if (master->ats_enabled) + arm_smmu_atc_inv_master(master, pasid); + arm_smmu_remove_master_domain(master, &smmu_domain->domain, pasid); + mutex_unlock(&arm_smmu_asid_lock); } static int arm_smmu_attach_dev_ste(struct iommu_domain *domain,