From patchwork Wed May 8 18:57: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: 13659075 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 43971C04FFE for ; Wed, 8 May 2024 18:58:57 +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=FsXrWPfTM98wQe3SjASU3+viacYdXKbiIPvnVFVHLLA=; b=DG3xlW2zz4nvoB QPoKj1RA1LhR0sdksWfQ16R4rUkfGBzEjDnH8WlYcgM/qhomaYHKqwpIarIxhbxsEdb9xptpwBN5K er48EsTlr1pX2CzcVRPE4H6JovLPQ4AYDrmBrSkICu5LhDSegaeSdv5NlrL9DpSPTzJsj1nTctHgj tWgdHblmxICQ+Hcgzc1B+xOI+wsdVaYAlGkWViRPhvGtPG6EMA+/RK7wch7lnZNvVVLt3WV/4K/rB 2tluJ5nEb3JSIDA99ZlQY+LxYwxULOqxlTy9Kyg5VGlbpPSNhgCM8yhILbuws6efPdSAv2qYZPnka kzi7PZcZeWJPONEWxPcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4mUy-0000000GcqC-0lYb; Wed, 08 May 2024 18:58:40 +0000 Received: from mail-dm6nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2415::600] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4mUJ-0000000Gc5t-35Vt for linux-arm-kernel@lists.infradead.org; Wed, 08 May 2024 18:58:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kMidHUhtRzeJ/t7mCm/b8xyhLofsMviwCIzas3SGIbNihQJKJ/lFX3LBv+hroaeXMTOaOnGrXEOxVXf3JmzmK+vOmB73VUFCDn+7vuDc4nveCaUdHYkc7BwyIZqfDtZzFu59hdi4aGms9XT/L+UCZa7hw+bYkHD3ejPThK/EJOJnXM0zvZKtoPg7uisZl4e9gUDBmtlSIoX34EP9KNfDbXvGpPW4TuSDaorC/ABo1Jf1fbgVdMBn+xRiJHc3Zh8iZPlkz0aWoZoxmJp6IH+mi87DTzhvkdvp/MMokc9Ie4cn2f1Asrz6u2BycyYWs4h6O5vglMH3jUcwjOJOP0mhqw== 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=7Yd2J89cHeZ+kwbtskl9Z/l3Yrj8Lj9Itg60NrwJzs0=; b=B7bE3cDy83ibQ8fvlURu6NdQ8hys2k253SRVp3xozxfeT3oNJ9He3pgVS7RmUEg4wruLDWN2Vw7SItfbKC054Ir77nI0QBo4kjax17R6gFO72HU+makbqjVS3950sL9plHIO/0Gd5/Nyfw993pRI8e0EpF1w9fx3+VHFDZmzWz0MSLAhUfWamUYUSz6nay6/aFP0sCexVH46o4lk7fVzASA8/6ag4AsiJM42xCt7A9igQIIB2fuLcdZXHUU6K0HcOdbBUVcdFMpFlKKqwvG45FnCBl+3N8ahvJ6P8HERx/IG8JhX+4mGxO1fpEhVr96vV0WRgU5Zp+ifh//QZo3GoA== 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=7Yd2J89cHeZ+kwbtskl9Z/l3Yrj8Lj9Itg60NrwJzs0=; b=Yj2F9ciDgG2BJfzG3HqSHPufMpUJeaBUbx4aHC9jq7MnkqCYNlIVrR+wTy39F0k6xrtZkCxmljM2WEQEnIXCq4/tSUBH/1FifUDrLfaXzwlRi6npjT7o4xlH8piyMM+J0wb/y19Lx21ZrT7Br6ow59OcdI3ersXHJNpRzn25JcKHTgGWXmZvAqj211+FVjHPtJCnqofI8RbOvhbqXz/89po2juN26FpVH2Tz2junLGsTF7oheK5tcJkCLf/ze0q2JPH4lRPgZetV3qszMeCPKagiPcxZywu/7qr7CFeLssggOFtwJRopVC3wdEfHXaU0Hl+RZ795fz/R2X7H7dc5BQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by CY8PR12MB7514.namprd12.prod.outlook.com (2603:10b6:930:92::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.46; Wed, 8 May 2024 18:57:29 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%3]) with mapi id 15.20.7544.045; Wed, 8 May 2024 18:57:29 +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 v7 13/14] iommu/arm-smmu-v3: Allow a PASID to be set when RID is IDENTITY/BLOCKED Date: Wed, 8 May 2024 15:57:21 -0300 Message-ID: <13-v7-9597c885796c+d2-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v7-9597c885796c+d2-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR03CA0027.namprd03.prod.outlook.com (2603:10b6:208:2d::40) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|CY8PR12MB7514:EE_ X-MS-Office365-Filtering-Correlation-Id: bf1c56e4-cbcc-44a0-86d4-08dc6f90b4be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|366007|7416005|1800799015|376005; X-Microsoft-Antispam-Message-Info: qquxx29URg7maX3kZp5oEqG2VslmBtMISDTRQ5NS4T8tuBAa5j+zBw8IiPleUueAtEuZ6qRdFiF4fpfshyCToA37byl7n6rv90OWlQvSFWAWXHX0MGjzlm1s7y5rixS7zNcJEZJ/3tXqxMKDZwKbSa0iUSW2rzEVp8kKHYGBP5vHZPZvQFn7pOo2gKH3MbS7Xkh3VyVhg9hx0OldK6a1gFgWljUciz89eOcvcHZiQiha4j/GMHuHyPzODac63sGu6ju6Vyu6vd4/M3HMxRBtJhpjPKf5Z8OxxFttiyCXLQD/kkzFKyBq6JZ64WCYry1UbsW1uOmhLJUyh1nrCGvA7OxmrEj4DHIWL6cbab5nkWceUksffm1+NJNlnfzQcIrBCKfE9z5RbNDZSc5Rv8CXt1cciLS19gEYJYELGduXZeNpUczxFJpStFBAWcf/ptfbQalLaCa7UCYwZMDVydVEdYD63rrBILC77HxUAxX6G/zNAzEq6F//dmyOB5pBJritpquJAnYfA9kwqQoz6eAB/V1oUHFJLwcqgDL+1lKX65fOMoakCthtEZJ3Kn33o4XYDTvXIUa4gxcEGerF2XytQxeub52jnBdv+UVEnx7uC3RgFOeiyeDPY+UtHjkMGqdpBBBZu/cnbPwlw0Etc6Xe10YHmmi+Yyz7Gm3H4HjLOhOKjEbgNQ6zlj+vc0jyDjoSGk8lGsNDTjQeHAvyP7lPYZbh/Qd3QWJkj6qVGf/dk1GahYM3zWhI2wShdkzU1dNVfrFpKiqYjknaIW07Oa4777Py8KSlcgaELjbVlUOwJu9EVt56Jniq72dZM8RLmxmCvnnPzhkOY3uXGL5FVu49CFr89r8te2EnCepP2FWP1WiMH+HAftjQDAkySvwn3JXVDFtcC1cjmYEkYYlnhh7gn4TCy3BsJ7059+z7xdtxCi2fwpxZ273kWdg+vll8CXtVEpu0QPAvfdYlTFGt3vZ+9zF3JXLkQFQ9MVM0SS9B377DNUsm5Tsqs10/CfPp5xEhHWbdt05OOWgZXwDHhCuvqiGnz4nyaS+QX+7mvXaD+Aor0/5QJOlapLToUAPb0rnBnHPdeX2Czphmkbxbdpv2cPjO/CaTzmgcUQsGi5EBbvVhnu0lBX7K/jmd3nG+s3xon2nkAjUFpnfCwwJrGnGgtQfqFlA6MVNeHCt3iKOgGCvnTRjcwuj2fjmYdXUuBuq547fZWLxOvgDZUfwui64JrU4xla+I0eX1lsOIxoRNJN29X/jsq90kPtZvySTUf1OblBnGkTCIp+5X7tIaM3Mp/w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(7416005)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-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YFBb8IM9LedBIsKP5n18PdIlZ4brCa912Ev4vQ5uGFcnUCd/EttBj/S15clhryaazAUcUVoe0p2UzVHVBZVaipAbmh8motdhSC9gHHFFtbZ8yY0cCapbviIVr3GcBxspuYXkJzORzcfLDUE0Fp2iOgdQhMwyGYa+WvH3bvMkRy6VwTwfcSWgKGDNETNWLXGV2sUm8ypS88mS0rw0in9nU4w/4itWSkULU0sbF2tEvcihAr8gh7apqzRkarmBLRJLD3kVGIki5gGgBRB60OFxIlCADpTSeQVUeeSjNandYZEsg0mQYYJ2hQYQD2L74CjAGgqBGMH9DPMUK19NkhaxOEf7S9SDnTlAb/zoBXIyyVQywX5nmgjg/1JnVLSKW4HyyHe4EcEu+dnQ1Icp3+nCWe2pu+T7XHVhHCMxGVDWt8QRI+U5XtqofJbv6GqOhEqv593OpjOiTblpPdIsJVD1TE7LlJOB5+33b02uOkrZXTSMCK2wGmPPX59VX/tqH5Jc8FF30zK+2mMdUcofyNyyxAh74o5b/fIE5FQO6u/hZnQK2iwahpfgA7wP5RRbY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf1c56e4-cbcc-44a0-86d4-08dc6f90b4be X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2024 18:57:27.9222 (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: 2fdFn9ZXcrkwJ0pg1MueKuLzrU7rdihs5Hx18hkiLidBgrm2LdGzgIa+ZC2mMWDs X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7514 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240508_115759_963700_6C8CC5F1 X-CRM114-Status: GOOD ( 22.21 ) 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 If the STE doesn't point to the CD table we can upgrade it by reprogramming the STE with the appropriate S1DSS. We may also need to turn on ATS at the same time. Keep track if the installed STE is pointing at the cd_table and the ATS state to trigger this path. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 49 ++++++++++++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +- 2 files changed, 49 insertions(+), 3 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 41d7a0664a445d..ccc10ad3ab996d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2435,6 +2435,9 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, master->cd_table.in_ste = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target->data[0])) == STRTAB_STE_0_CFG_S1_TRANS; + master->ste_ats_enabled = + FIELD_GET(STRTAB_STE_1_EATS, le64_to_cpu(target->data[1])) == + STRTAB_STE_1_EATS_TRANS; for (i = 0; i < master->num_streams; ++i) { u32 sid = master->streams[i].id; @@ -2765,10 +2768,36 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return 0; } +static void arm_smmu_update_ste(struct arm_smmu_master *master, + struct iommu_domain *sid_domain, + bool want_ats) +{ + unsigned int s1dss = STRTAB_STE_1_S1DSS_TERMINATE; + struct arm_smmu_ste ste; + + if (master->cd_table.in_ste && master->ste_ats_enabled == want_ats) + return; + + if (sid_domain->type == IOMMU_DOMAIN_IDENTITY) + s1dss = STRTAB_STE_1_S1DSS_BYPASS; + else + WARN_ON(sid_domain->type != IOMMU_DOMAIN_BLOCKED); + + /* + * Change the STE into a cdtable one with SID IDENTITY/BLOCKED behavior + * using s1dss if necessary. The cd_table is already installed then + * the S1DSS is correct and this will just update the EATS. Otherwise + * it installs the entire thing. This will be hitless. + */ + arm_smmu_make_cdtable_ste(&ste, master, want_ats, s1dss); + arm_smmu_install_ste_for_dev(master, &ste); +} + 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 iommu_domain *sid_domain = iommu_get_domain_for_dev(master->dev); struct attach_state state = { /* * For now the core code prevents calling this when a domain is @@ -2784,8 +2813,10 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, if (smmu_domain->smmu != master->smmu) return -EINVAL; - if (!master->cd_table.in_ste) - return -ENODEV; + if (!master->cd_table.in_ste && + sid_domain->type != IOMMU_DOMAIN_IDENTITY && + sid_domain->type != IOMMU_DOMAIN_BLOCKED) + return -EINVAL; cdptr = arm_smmu_alloc_cd_ptr(master, pasid); if (!cdptr) @@ -2797,6 +2828,7 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, goto out_unlock; arm_smmu_write_cd_entry(master, pasid, cdptr, cd); + arm_smmu_update_ste(master, sid_domain, state.want_ats); arm_smmu_attach_commit(master, &state); @@ -2819,6 +2851,19 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, arm_smmu_atc_inv_master(master, pasid); arm_smmu_remove_master_domain(master, &smmu_domain->domain, pasid); mutex_unlock(&arm_smmu_asid_lock); + + /* + * When the last user of the CD table goes away downgrade the STE back + * to a non-cd_table one. + */ + if (!arm_smmu_ssids_in_use(&master->cd_table)) { + struct iommu_domain *sid_domain = + iommu_get_domain_for_dev(master->dev); + + if (domain->type == IOMMU_DOMAIN_IDENTITY || + domain->type == IOMMU_DOMAIN_BLOCKED) + sid_domain->ops->attach_dev(sid_domain, dev); + } } static void arm_smmu_attach_dev_ste(struct iommu_domain *domain, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 71ecced1db0226..3c189a48e29757 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -705,7 +705,8 @@ struct arm_smmu_master { /* Locked by the iommu core using the group mutex */ struct arm_smmu_ctx_desc_cfg cd_table; unsigned int num_streams; - bool ats_enabled; + bool ats_enabled : 1; + bool ste_ats_enabled : 1; bool stall_enabled; bool sva_enabled; bool iopf_enabled;