From patchwork Tue Jun 25 12:37:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711072 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 D9B52C3065B for ; Tue, 25 Jun 2024 12:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=7ZBGtwPpp3fcnbTHEZr175AqPgn1a6tgFjBT16keTNo=; b=DNzi6u0Ok5HWna4MfUN+8T0xt9 xuH0dzIQSH/DmeENkAo/P89VUSry3ZdN/XrRqwO6mgGZyaLKdxdNFaNpB3ieqLfPlJZLH/08ZMiC0 2N5+VZZoN3UeedZ+WXi5VIZXFDnRnZTGmzLU0W9BtZo4zGRZM/DCLv2m/DskHNjkFQ2VxcG93KkT8 km0xNOacLlrrwI/b4+Le+G7ATxgUYI44xKhsxOjsiFkZgkdB79TqnlcEwgJ7UgaKJBH4MHdf+zx9o H3d2IejHY28wB8fBGgBbSRz2ZfZLCnmVHVtTHkiKp39YmSSv6mLvKDmSX+UJ8sJjW59tAqr/4J/EK M/cGehsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5RK-00000002o0V-37Lu; Tue, 25 Jun 2024 12:38:26 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qu-00000002nfA-4Bf6 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RcEFPhu/OXwOTFxy1B/MiV9P+LHspN/bk2wmFNW3Lt8opmvuWutcl+SC2aKoYz1dlJW2bR58vWv90OsvxO5V2x3928WyFYwFboaWJsx3/Q2bmKwTNIvP08ybKsdjJLlOaMQp8MFoTu9Qn/uvmGui47eU/Ol0fFC5qXInEqXwuw28BnsJyf+Ozb5Wc1iLLoutFWilRlJ1KI9ZyZfGzzA6cxI1XSRwqXd/L5UWJHtGvHMa5GmzNxAqjcNDSlfqD/YHCj6efD1qrbl4KGuWdTxtHLD6vbr8+1ggLBh9lg4PXHoOemjXCrP0QzL73wZioG+/IDzIBwJCJMSNGzmryfTKSg== 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=7ZBGtwPpp3fcnbTHEZr175AqPgn1a6tgFjBT16keTNo=; b=IfQdpOi88MZCAUXMotqdSLtzVyt0v2LgT/p3a/3b3TqBt0xiULlmhA6oVzQXKonWo4q8kzZZF94Gw2Sr4uivm/B9y25YI8etBTgVfCE/SuaNSEx+WpYQcQP2yQi5eB0Mo8wj3RJdvytdpr/KsWCRI4VzhKGdK+g5lvuP+DCDKfEOnhXqyVFcO/sZ0fvaOVQY4MrQnJc6NxFJujBiYB2AjJN2VLg8NEoo/rt4waT9IrHIT6lHAb356K7HiCLQpRXeL1AcQ/wTijvZYLHBMHw3oo0W0qqyLKKfU8TPvM+1iSDtDApkirk8ftyXUNaCCVV5OE+a7pI9umEe/0Iq10JUoQ== 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=7ZBGtwPpp3fcnbTHEZr175AqPgn1a6tgFjBT16keTNo=; b=lkchFCSogxIzq22wOKPUq+tMycFgJ2xstiLlgTWpGlEjLbku62e7Q64XrtmVNy/U8II04cRWBw51iF4xbp5cdM/tkEjpwnu7zpGc3XiEMIGY7m3ZIz85QocAgc7x/sj/1YMZpt393FkQfx3dmr0wQhWMEDbYajQnL0uu3zbGhjUaPNT7tnSY2bcHUl0SsLdfocBXjBiYHs8cTBh0nbqB0IFkS6Sq3h7C3z3KjseTrXjzl2Em043woHXaejrgNf8hkHWLYhtutJ/UIbUCmLNbSerLgrdT2EQsiwoXLmqzuAA1Xc6GQYWj9adk4GhMp/+fjTAXSqGJlaVhC12mEa/x7Q== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:49 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:49 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 01/14] iommu/arm-smmu-v3: Convert to domain_alloc_sva() Date: Tue, 25 Jun 2024 09:37:32 -0300 Message-ID: <1-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0154.namprd03.prod.outlook.com (2603:10b6:208:32f::28) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: f01a293c-a4d7-492d-2412-08dc95139e4f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: IEv/8djGNtq2geRthekr27ObunvVo9TH7jilzisqUzoLVsr7ZfHAALmmN8cLJRNxHD+6LBcyQlJbEUVXSNdWvOeU2dOIxb7wCcMZxO/3mWcSxMuwKXIpYqUmXGTO0Mgb94rFoqsSQINc28SXy1jIBKzpxhrgroiE8Ym/pvnG3F1tPghAwifWVOYuz1FLqw9Mr1rMMjs+4YTXBy+9eK7SC4bOhCszXNiKACfqJ+/SpIiip2kWrlWHYmM+uAggTksyFL7HBm5pD7tVffv95GNnhXFpqTL5NG1AgIoyjpbdwOEJC3D6IjO4jU81w8VwviXGn7Lw85FeiKDpieT5GS4l4l9ySEoZIxgwHoncAdLVgF8etAqUEUVZ9KvKPw416T0uWX7yEmGqBgJr/VJsXQYznKY6VTlx6cdJVlBFpe8xTk1YuiNGP85vFemHfTkyJluC331pKTgskuAy0PqyyfTw/BtiJOk7GnOF7pl9qaX+Jj4oOGj5Auh7bxA/+O3qUx52pe5IXWB2KHxES5wBFbw58YMODYVehNwe0eiAxkFnuFm5X0kILZo7i5F7BTif0WR1NSF78jYptIl9VyONyQu+pQj+AM1mM1a6UYqOHcpLcuIw+qI7ZOt9ENlJBjD+buaTZN4bRBbwAS1UQlxPPQgF01DjdPklrUp7LDl5p/Bwk3dXCkqdLZ+I5G95UJ7jk5J7ETseWs+lEtc3VHifSJbXZmv8XUK/6TtKZv5znUADAqUpsU0kc3oltvH6RX3Q6bz62gSM7u9KP0yaZ4igF9IomXns9UfvZCZ+K6ZlGrKTMYFOq7xekkSrHXJ0wxole29A+A932traJKLfLRVBu4BoL7o/GcfCsczhwlaxeH6SXjC1MFePRC1l8MY2hvGiP3MRlZw1kpZQ+Uj6I0zNwuJd2ac/XhIyx4tF62BZtDimFDcdStCoqBf1Dfg5U8vNZRR88jasm2YLfET5qoYlio1W9oIIaVO/YUNhJBfHAMfy1kyMBph48ik5xKS6PysN5OlUTTm8Ax9dgqsV/lGiCsU+peVlJ2K1YjvyD6Ea7B2xZsAj6wuXZpqCOQPfUXVTDWn4/zeu+whFirmrBbpSlKGpO+XcB0LJy80c+Paj8jURZfIpEJ2gg7A5x3yQ++CRmNUwFAIWgdldRb1YbuTnfumM0acwdVodE+qVwuyQjLyKj50c4eIl08bjK4X/esJmROmr+OzPnhXCRsjWTBK8/TrzGWGIN3T5tH5YoopxUTRV/PxLFIsUN8NnuFNYj6i687NP6DEbRrLJBGdn++m+slkIWXSYa1h2EDm+JsezdSeQXGohPF9SarFYtRRGq3YDfXtO 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o9rbU1Hpo8VrUxy5zlxbRE3XryubdDZCbEKXQ9j+VQEX+RvG+d16DJn/fpRDuFk1jKn5IFong1olYkml83LmdDi+YnwHDGfnlMzEEbpqSPp1mbp5TQ69rSWWFqGj6PH9iwLtPZy8Y/2eoL933leA3J6dPDX+e2W2wr7XfarGe1nbmpKEISpzY047gvYbkbtkILGuFffunfXzz6CLx3sTr8xhGFjF2qnP1R2bUrhkFBwP6cmKqZyBslcOKClUbhK2A2Unftv6Afhw9kki6iyLRwJ+yBVtRKG92f+2/FvKEesi6Ha6wyXAD6eGtKVEH4zwyWrivHfMXMvWjUfXA99la2UrbgdYB10c8QFqh/Czk6iZtQ8K5KhGwZaYoBEpXrtEr5RbbUbt0k5sQdk0mlyppmx/vBMb1R/Kx7Y36HFpcOQH0PEAoDZ9kUhsjzvBn4EiofOFbhRb2LoRZIQGpEu+9yfoWuF46PSqDgxWRI+n+b0kKz0hNctoeO4kv9b6CUshcXlJZVshPpnfe7OWo0ubfTsNIQDPydjJPgZfcP4xzHd2uv9VQsr7Xa4geih9Uz84S4v1ZwCCXzNbaiLjtFiSlf/F18i1ROxHKpYmjyAJSNUlnBvjSL+JdmeKwIVAK5+zJCYGTjXHDSjBBFXpi2TGGiIeJPdhdBV5rDDH2IC9H5T3JPECSdjLAOcY1C4t5/ZmP/dz52i1WmA/xxnY5rBpwNMqrrjFKJUpS5L2yNG/x6dH2lWlFvSzdiuhemH3P58hfm+ayBIvEPOEpXmRQeoQJQ5t7mNb+wTYMQrBWNATgFiZCWdnkK8K3IyOQ24mt3O+g59LqCXnsu5WIVR2foR2dmFwK3umU8wobD1Kt2rhZHRkq6FoU+5J/LcPKvtsz04y2c8yw86jjyLj0D2EZqV7ymNhQ0emx5agxDTLUmIhzRMpMwPziULkgfzqhrJPq+qIeJlwPQrWBSSaMt8VIhZIjn+mJiGtjULVf7OETPWSD7FU12zQDP5IpvH3JZa44YSK8SCKjXn+Fd9eWUxiWLDZLMdmQr0hVGbElr/wF/ewnfqWrOz4N+X8thzemHfJQnodExVHztTGuf/O4jI0jCwH+GhjnYwtpWTfoovgfy2Jkj8PDNnDCWcewKL+UH8Y6KiI0k3q/gfpQxEntBJZqEU4Xfl1jRJdT7hMUOynQRljO8j2/AX/9X07E2w7AgYO66cxNr5WlnDhKEfCS4sorytKQzRbEfhT2f4CpgNi7vtTzQUSb5hgsaYYEq7zIZGVtCdCdbE81PTGcA2mRYh5Q92pJoxz4XURJP0qsle32lN+v0fCQY/bO1xzURpZfI1brg7pQaFgleF0e/x/RiMh0CnmR3AltTm2bA3VYO6enGkm/UnIh3YM/9lQGw0Giv+9dWrpkaiIebOLuJPhHqmNw4Frc7XoBKxuiJ74PESRDzWwKYgC14psloGMP/m5W/Rr93uu7CwElFphBazsWr/AZPP0b3hQwtOVLwI9yshnX2CYK3yhaHK57ZieHeEYyG4tDaTCHQSykCKQxeWXfHjelgGvKD+6yD6Jsf1EMeZguEsjMtLgOBXEZroHikmOcI0AEDRm X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f01a293c-a4d7-492d-2412-08dc95139e4f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:47.3789 (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: siTk4aJvrQsZ3ZZnoxVx0affdx0AxYIqnBP5Y9y1xF0LVez77ciRmONV9ktEzv5k X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053801_115077_142ECE8F X-CRM114-Status: GOOD ( 11.94 ) 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 This allows the driver the receive the mm and always a device during allocation. Later patches need this to properly setup the notifier when the domain is first allocated. Remove ops->domain_alloc() as SVA was the only remaining purpose. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 6 ++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 +--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 8 +++----- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index e490ffb3801545..28f8bf4327f69a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -656,13 +656,15 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { .free = arm_smmu_sva_domain_free }; -struct iommu_domain *arm_smmu_sva_domain_alloc(void) +struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, + struct mm_struct *mm) { struct iommu_domain *domain; domain = kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) - return NULL; + return ERR_PTR(-ENOMEM); + domain->type = IOMMU_DOMAIN_SVA; domain->ops = &arm_smmu_sva_domain_ops; return domain; 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 ab415e107054c1..bd79422f7b6f50 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2237,14 +2237,6 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } -static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) -{ - - if (type == IOMMU_DOMAIN_SVA) - return arm_smmu_sva_domain_alloc(); - return ERR_PTR(-EOPNOTSUPP); -} - static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) { struct arm_smmu_domain *smmu_domain; @@ -3097,8 +3089,8 @@ static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, .blocked_domain = &arm_smmu_blocked_domain, .capable = arm_smmu_capable, - .domain_alloc = arm_smmu_domain_alloc, .domain_alloc_paging = arm_smmu_domain_alloc_paging, + .domain_alloc_sva = arm_smmu_sva_domain_alloc, .probe_device = arm_smmu_probe_device, .release_device = arm_smmu_release_device, .device_group = arm_smmu_device_group, 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 1242a086c9f948..b10712d3de66a9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -802,7 +802,8 @@ int arm_smmu_master_enable_sva(struct arm_smmu_master *master); int arm_smmu_master_disable_sva(struct arm_smmu_master *master); bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master); void arm_smmu_sva_notifier_synchronize(void); -struct iommu_domain *arm_smmu_sva_domain_alloc(void); +struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, + struct mm_struct *mm); void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id); #else /* CONFIG_ARM_SMMU_V3_SVA */ @@ -838,10 +839,7 @@ static inline bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master static inline void arm_smmu_sva_notifier_synchronize(void) {} -static inline struct iommu_domain *arm_smmu_sva_domain_alloc(void) -{ - return NULL; -} +#define arm_smmu_sva_domain_alloc NULL static inline void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct device *dev, From patchwork Tue Jun 25 12:37:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711070 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 71E36C2BBCA for ; Tue, 25 Jun 2024 12:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=RiQNhmMdDikOXGESry1EWwFazvSFA/KajKnQo4+YLMU=; b=STKQLgic5WnnwbqWb/iPRvohrw sNMU26osDHVG1vsaJjWQx18Y7JpVNvvgROpHBto5XooWyjFyvu5izl7ZLFQ0Grs/lMviay1hUmyja cSuBn++a2J5JAs8wwFG1HbxhTFd/yeJ6YbvHdKnNrQJ4UGZQStYjo55NlICiWUn5Vnn/ZpRwUJSvn h+7RiewdFI/ICoppvDG26e30TpfaBKR5NkfgHhU56UG5wPHeU/WX5kyALkUrsHDtCZywMxOW1SxEe hWi3vyUCc5SUvzHMijqZBDsInIdKNlys+3Gbu8EUmSp4GOMVWTjIwkdKjpTnqRrxKnh9wYJOGSA6S gZu9y1qQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5R7-00000002nsy-2tKq; Tue, 25 Jun 2024 12:38:13 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qo-00000002nfA-3D2C for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:37:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JfFtcVUAzGz81NjgKN2ZyiySEdTUbfzuvFDMaUkRydQKGLrV1oAsN79GnOQ5e2wYuMhgDI1X9kACyU6VaVnSv+pT5ZrLCYe/9VsXFUOQ2Yp+44LsZNB7Ry/IE3ysfDtXz91SsPk6nAC28Qv5wu2hmn3Ek6Gyvv+xZRSBdGYALJwuQ+Bs+MhzJnezt0FhdQUVUCxG62DfONZ2Y0/m+JDuL9PobOea0rSdMfDRLuQ3jkHuzhG+lpgv/8qpTTKBtTgRKtJAU/IdQG3HayuMlTFP9bcSTMwvYI5An4MCA35h3s/Tzu7c/F+vs/YA9r54oQ6TgGvZU2Laz8OTW90KiIBr+A== 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=RiQNhmMdDikOXGESry1EWwFazvSFA/KajKnQo4+YLMU=; b=P0aw/fsa6K13UkdKd//jH5Tr05xieHtpcFwHujCuM3Wc5j0JCVNY1AZ1N897xnbIwXByRDnuS9yw5ZVFt5/DVIYv3XEiRBV+jovMrBLlcQkvX+qpdkonGZ7BANJSXjlKXVh+Qy04IIDCtnCrzGWr4r5juPkNeQSsCFOhyTRXaZuw8/Ryp5hfVnSbbRGFLDk5UnV403qfKKYKggRoi/NbSkkZa6hiT5gGtRhBdT6zSZNFkeEIB5CVTGkBKiQjWB6MHayBAPWXLtq/BtAr+hVJ5sUxpmarEHLDR6bRsHMLu7SOVfC8DMfU5BJ6v84yAdCNIR3b7pyfLJs9s3//8d1+7A== 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=RiQNhmMdDikOXGESry1EWwFazvSFA/KajKnQo4+YLMU=; b=kZou4tYvuoHTBofQLcLVYjMpPdHFTCcuq3DttunY9MxpTl24DQgJQcM0JRuUtaJUzr9KVsDlv31b0vDGF5mwlHUoQ8mMkRK3lkZZWwc+6E59b4iUGxtB8m03SO9bAjGGLR4hKje6bgdGPapofVtcDeBr/C6mUN4Ro00lF+RVyvcLbzdd/e7s6220h78+j9r4To7dXPPz+ySJKMKtMYPnl6i6Fz1J1SlL3IQj3LTlo82u8AXQYmqucQatzX79CvQMAkgAwvu+1NGhoeuUnznneIw6U9dDikMnjqT1JrxI/DrGELoE4YzS+d3eHUrWCPodTxMQ4rehlPIDDctduPqicg== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:47 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:47 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 02/14] iommu/arm-smmu-v3: Start building a generic PASID layer Date: Tue, 25 Jun 2024 09:37:33 -0300 Message-ID: <2-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR08CA0022.namprd08.prod.outlook.com (2603:10b6:208:239::27) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: ed97b583-3157-4631-6aaa-08dc95139d95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: 8WLJbyrueB7Nl45DjwZo79OLbZ2nFt50KfAfrhoYv0vvd65rLiGZS2F56UbJYJ+Qv93Tgo93Oa25d3E/gGH8Uxdeto6yaK1O0fAw2IpAHcGEViIYGB61hXdLA+H9KK62XODQzo9GzmnEh+qIygHNKPZim+JJogFFAuhpAM/X62WMVPeQyKQ8qR+BmmKzkyLrdlw324XA6wxMY+WX3iEpprZOr86loPPbzZfv15aj+ObXSAb+a8/iKgJEcIGXlko5mpR/6QPCs4GhNG6w/Kw/ckbLV461b+0VJ9UWLeFmVO/Hgt4kbkmlZwzrLvWbpTq+V+ddAtbCWuWmJ94+p+hNP4Rhm+aawzhw5Pp/hA7sXEuIp/1dAx4/HDGVDGumZBWsCLzGuF4Or2QAPOHxw4p7f1Ew9alQ0znoNYyRFRY9bJmyGaP6H87qJfmwSqQlRQC9akbEZXuNewXLCD/vh8h+kYjcTFHlA5z5dfOhUOGCjVzH2LlPfQO98O2VDLI3EzZqVOGvg1RCxEtzL4oaszz23RrHMdzw3s+KLMs1L6YSZx/R9VyzKtwJVp3HZ5wc49hCstgT3xNhOXkeQkZB1kfqAQAd2+81DAhcmUGc8wLxJ1uHo4HZXGqrnf9NEb5OHIrXBTG8+GgvAc8MuP43n4iSsfBuDZo6aVgefxJ4EkGY5iy+OEUTH+xlO/pMbHlYhxQFkw07D9odP5ucdzVkrnO8G8d2HZPsok0J/mpWW9Ty792NFhjE9z/GuXecnwLgowHsDIDBYy4MD8N5FACUZbwSlGIWp3tB9MhPR2wAOoxKVnoB348vlC/7SqkTJS6Vv0rn3m6vLsD2rhD8AF7drtq8VPDS62ujpYzIYbttf3r69dhGFFrm2RneehK5gc29pkDue3x8KsmT/98AoWuYrgoYisr5Gaf9NAJeMrovY907piC28Q4YF6HyqL4wEFpA3fxrTfLHLi5fCW4j6O4a13pPnBg0PsQCvVHQTjvSVv9KW1MIWYGcbXW7MtB4h/N8+anR/Xke4ZXzID/h6r2PyFksAJpioMZ+pZO9PNWJTU5A0anQ8UAY7ZGJpgcrGHRS+3sTgKw0n7cBW6KuppVGNEaxszMaiPhmqsyJhU2sRlcD2BYadTN2BBEtF6WsOCP5+w/Up7NspygI+Ko3nEqLfLeMOemwZqbArSBE/0hdTikQMAnJbgrVTNThUwjc5JTAzSFODFXiiiMoGCC41e6P5jEV7LSr+OZKkjI11kydvWbv+AvwiEv1Mv97Vunrs5cd8UT7pbq92Yn8AFI7F2xBNjuUcfsXgrP4wcsttS6fmTKuLYc= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4lPuljBv07SiLFSrqZXfYedVPj87IWZkHqzAz91+Y07FsyQQLogXF1Bn0ro2wwbSaO9vTf8zmR1O9WKuhSLLSFfXD2RmuHcOPy90RtLhAg67CYpMliLCkeJSJ+xTem3YCNoSDITSWGR1sNiFIpKd5huGzHU6UyIQD/X8fiO/CkTTUEc9qLR5TqrPJEqig6fxhrDxXQhMdNFOhqzfu2uF7kkRBHIDJBQGzLkuThY5ZqGOKdpCHwp+gYQbK7+bwM/eOgWxgWYnsLJebBRe99LrLO+kERJlDQh6yf+7wp/oaH7BPBE8iiFOKPw051vq7sgb26GjSvYSWJYqsZUxZwMf84mBWKA2KN+osA12svxY2Z7vKN1ml7L6onV7wYNvTc5MeU7893K7MqELM1qELLQRuumX068OsuOETVm3cjWYzptgz5Q8i0cmBBsmHUW3PJqY7uAOpEND6ikfKVZ8Xvhd91L1D3DWQeuw24mPNoXRtlgLvgTpZDxnP5vMWelVSshTPfP/PT+WWmqVjHX1NURJuQiGOSm8hFAueJQicQ/wgk/YyseEoSSUm9bWK4qyOE72CRYNDkqmPBIi7DHfcgf8ER3s5FOx8zNrPMEHRomIB0iXw726ldPY6kfQciio5Lr6aJSJ18FysW3pjp2l3EfVfRVcokJr0AcAHDMBjEcDXuqv8Yl/w6sdWPwabksrQN5TjMjU39lmV9Iu+F0qvoSYUsh4m0boz6MllqcL4Q+fTIO7kPSQtGKo8QRu/kU2yr7s1mMjzi9vDgAYjAiCJPQRnMCcSuPCl4TJcEHXNh4ExGyj8z6RydQd0OESs15vD8dIV6oUV0neHKfPn2DitrW3qRg5yVAI+kv2FUxFCA6xRPqW17f1PQnVA77LNpgdoX3KsL6i3lwnk3LvXh3CHeaoKTh1J2Caie8EJX/3MFGz7u+IvZ6LtsXwIXmqARQ7lUlFxRZQTNW95zYuT8SUvujhsoN/Tiv3CeZ2rgRoOLRiD/6a6rqTtaENnrIQgU98Li4XOuDZZF/Nr1GeLBmlNMqRejcE04bExE2KCWCb2lrXWRVFnHDb8rOHUSLcsmkD+YR/fA+XKnYrLiiFnHRra/5eQ1tGsepFM7OTJgqSGXzQ7Dcvo7jw/RBbLYlxTikuKUTUtwyXevXGRhtv1YakQIeFR2UN66iXzWzlF1rabU7m90kJQGVjyis7qfnPfDGBJ/Uv8nfh9YQlfBTPSl5Y67dDTts0m1ZoOgwZrASvVrlxP+m/WXYobfGRpkmGq33BG+2IgeXVGnk0PCUFvRX5cZqQh4PTYgJVEslmXrOTGn32Jmjwpb94Tu/mP/1PICFKqJNTudXrgXOrTuLCs1twQVNpW2vbC3DEH+Pjxl/lzTbVjkSGAUfhH0ty2DhwPjB8TN1cIn8xPbEGFNJpDmDBw5gaq7gAVq9lozbjeawXU4hw82NYBvZuz8K/JsXp+6WIytxMCLgYv9lLhdaAiZvPx8Timw0wFIaQKc9v0BPCqBjBGPJ70f37WeyRz8MTC9G8hBVFZhgFwINGtGYB/dzneHT9tHGK5ZlnO8qVgAYWL/hmGpXVG2YteSKyB0a8wWeHJ0D4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed97b583-3157-4631-6aaa-08dc95139d95 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.2611 (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: L5NFu0OPLXLhdOKxPjJfyTqGccFBW5d2QrplGiQo0N/KgK+BoSt2ln8LWs9iwaWi X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053754_994541_678AB494 X-CRM114-Status: GOOD ( 18.88 ) 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 Add arm_smmu_set_pasid()/arm_smmu_remove_pasid() which are to be used by callers that already constructed the arm_smmu_cd they wish to program. These functions will encapsulate the shared logic to setup a CD entry that will be shared by SVA and S1 domain cases. Prior fixes had already moved most of this logic up into __arm_smmu_sva_bind(), move it to it's final home. Following patches will relieve some of the remaining SVA restrictions: - The RID domain is a S1 domain and has already setup the STE to point to the CD table - The programmed PASID is the mm_get_enqcmd_pasid() - Nothing changes while SVA is running (sva_enable) SVA invalidation will still iterate over the S1 domain's master list, later patches will resolve that. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 57 ++++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 32 ++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 ++- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 28f8bf4327f69a..71ca87c2c5c3b6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -417,29 +417,27 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) arm_smmu_free_shared_cd(cd); } -static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid, - struct mm_struct *mm) +static struct arm_smmu_bond *__arm_smmu_sva_bind(struct device *dev, + struct mm_struct *mm) { int ret; - struct arm_smmu_cd target; - struct arm_smmu_cd *cdptr; struct arm_smmu_bond *bond; struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct iommu_domain *domain = iommu_get_domain_for_dev(dev); struct arm_smmu_domain *smmu_domain; if (!(domain->type & __IOMMU_DOMAIN_PAGING)) - return -ENODEV; + return ERR_PTR(-ENODEV); smmu_domain = to_smmu_domain(domain); if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) - return -ENODEV; + return ERR_PTR(-ENODEV); if (!master || !master->sva_enabled) - return -ENODEV; + return ERR_PTR(-ENODEV); bond = kzalloc(sizeof(*bond), GFP_KERNEL); if (!bond) - return -ENOMEM; + return ERR_PTR(-ENOMEM); bond->mm = mm; @@ -449,22 +447,12 @@ static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid, goto err_free_bond; } - cdptr = arm_smmu_alloc_cd_ptr(master, mm_get_enqcmd_pasid(mm)); - if (!cdptr) { - ret = -ENOMEM; - goto err_put_notifier; - } - arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); - arm_smmu_write_cd_entry(master, pasid, cdptr, &target); - list_add(&bond->list, &master->bonds); - return 0; + return bond; -err_put_notifier: - arm_smmu_mmu_notifier_put(bond->smmu_mn); err_free_bond: kfree(bond); - return ret; + return ERR_PTR(ret); } bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) @@ -611,10 +599,9 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct arm_smmu_bond *bond = NULL, *t; struct arm_smmu_master *master = dev_iommu_priv_get(dev); + arm_smmu_remove_pasid(master, to_smmu_domain(domain), id); + mutex_lock(&sva_lock); - - arm_smmu_clear_cd(master, id); - list_for_each_entry(t, &master->bonds, list) { if (t->mm == mm) { bond = t; @@ -633,17 +620,33 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id) { - int ret = 0; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct mm_struct *mm = domain->mm; + struct arm_smmu_bond *bond; + struct arm_smmu_cd target; + int ret; if (mm_get_enqcmd_pasid(mm) != id) return -EINVAL; mutex_lock(&sva_lock); - ret = __arm_smmu_sva_bind(dev, id, mm); - mutex_unlock(&sva_lock); + bond = __arm_smmu_sva_bind(dev, mm); + if (IS_ERR(bond)) { + mutex_unlock(&sva_lock); + return PTR_ERR(bond); + } - return ret; + arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); + ret = arm_smmu_set_pasid(master, NULL, id, &target); + if (ret) { + list_del(&bond->list); + arm_smmu_mmu_notifier_put(bond->smmu_mn); + kfree(bond); + mutex_unlock(&sva_lock); + return ret; + } + mutex_unlock(&sva_lock); + return 0; } static void arm_smmu_sva_domain_free(struct iommu_domain *domain) 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 bd79422f7b6f50..3f19436fe86a37 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1211,8 +1211,8 @@ struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, return &l1_desc->l2ptr[ssid % CTXDESC_L2_ENTRIES]; } -struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, - u32 ssid) +static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, + u32 ssid) { struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; struct arm_smmu_device *smmu = master->smmu; @@ -2412,6 +2412,10 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, int i, j; struct arm_smmu_device *smmu = master->smmu; + master->cd_table.in_ste = + FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target->data[0])) == + STRTAB_STE_0_CFG_S1_TRANS; + for (i = 0; i < master->num_streams; ++i) { u32 sid = master->streams[i].id; struct arm_smmu_ste *step = @@ -2632,6 +2636,30 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return 0; } +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 arm_smmu_cd *cdptr; + + /* The core code validates pasid */ + + if (!master->cd_table.in_ste) + return -ENODEV; + + cdptr = arm_smmu_alloc_cd_ptr(master, pasid); + if (!cdptr) + return -ENOMEM; + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); + return 0; +} + +void arm_smmu_remove_pasid(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, ioasid_t pasid) +{ + arm_smmu_clear_cd(master, pasid); +} + static int arm_smmu_attach_dev_ste(struct device *dev, struct arm_smmu_ste *ste) { 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 b10712d3de66a9..6a74d3d884fe8d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -602,6 +602,7 @@ struct arm_smmu_ctx_desc_cfg { dma_addr_t cdtab_dma; struct arm_smmu_l1_ctx_desc *l1_desc; unsigned int num_l1_ents; + u8 in_ste; u8 s1fmt; /* log2 of the maximum number of CDs supported by this table */ u8 s1cdmax; @@ -777,8 +778,6 @@ extern struct mutex arm_smmu_asid_lock; void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid); struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid); -struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, - u32 ssid); void arm_smmu_make_s1_cd(struct arm_smmu_cd *target, struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain); @@ -786,6 +785,12 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, struct arm_smmu_cd *cdptr, const struct arm_smmu_cd *target); +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); +void arm_smmu_remove_pasid(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, ioasid_t pasid); + void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, size_t granule, bool leaf, From patchwork Tue Jun 25 12:37:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711074 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 8B73FC2BBCA for ; Tue, 25 Jun 2024 12:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=wabBNxXyE372fzKVV6MgX7cQKFqRQEGkHidiVPr8psU=; b=ANMHx7sYuTbI04HmRFviZJc+5a hnxkAMnmuHI2xo/Eh37jVXlhdLnSGaVdAagVTE/44OrgZKMw93TdAciz2SWUUCW/RiOQz9i0nITUF JpPhX6MYt3YYTlEgJ9q8Y63ibGyKZlxEiHosisYvZ3+CP9x3Mjczvhn++8CbqA9N9Uanwfb+ZylsH PVCYdRFQz6wHfRuojbYjC9VAHxvvacwvKiNMW4qJQHeMHhEmQ81Gh9CHuPAbPrSBTlC+GVoQBtxu2 K+vvuAC9jTvcerwc9rlk8BfIiF8LxAFT+CnZ3+L8pwCD1MRL0K/LtJ1J1gw+95c9KAKEgRIiGQjnc g7IUhjfA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5RP-00000002o2s-1P4L; Tue, 25 Jun 2024 12:38:31 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qv-00000002nk8-35nY for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y/ZOCu7LlBVlkY+VsDdPI4oJcZ/2932ieSms4tXJbNIVr4jbvF4cQM4np/56/x8EqHVstUwlFYFjWxP7aoVpQbLtTkTTGYeWKEbFD8sWS4P33vBdP465YdZta8b3YzfckUHLa/TrGcbibHS8f289WIX4qgUBK55lde5j3WVW/QHls98I4bvVk8MSxU226vNif6047Tbvrt356XuUFGlSmnVNy88fNWvXI7mUwSV+iwLFGwAOXCUiyn2oKj5+78DSVZLgkBSs+0LAzuSfByO+9vEzwlXbDFys/H7KdV0AImGF5+u0ey1vVIEaszHJ0pVKtIM/ig9TwjEBqRIw6Auafw== 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=wabBNxXyE372fzKVV6MgX7cQKFqRQEGkHidiVPr8psU=; b=KfMq+TyMi9auIMLSGpjiy+SkmnzzEwXbn+8Dzww/snKEDf1Z8e1YbzfGhRS61u7jnM1I1TW7tx3QAeSeQJ9010gNbz4MQmLoUAY7wwgtJRJZnGqK5zxjTOIzqxUPjhSXLxnvuGQYikLwhlzoiwhgDR41xqLUXM7Jvg3ahuowCRScbqsaXFShGsm845FVNOcf5O34srK8JyoylKbX+2SZuIFxILbFdwDVkKKfHyDt6vcG+SI70LcXU+6CVWpdSduqcPmep8jJlPC7TioQyOPSZYQG/Ae2bgKLKYhtiIlvbLQ+z5ylk5kFO88IO4EmYmgzovvSahqx3z1kdfFxu6z00g== 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=wabBNxXyE372fzKVV6MgX7cQKFqRQEGkHidiVPr8psU=; b=iKPbcwwvliCZOp7GbRju6n2n97/+wnrrAbwmIU+0r7frqnwUXBSUnvCgjF+o6H44qm4ARRT24ra2fQJFJ12gQTE4mVV1J196+18cUddjtLIzOURLwG5sYV/Lkv1Erd6PKGkGIo1OYf1IF+1U+2hM8tkRh0C35qxPC78R1fVyxJf3wVHSOo12qZSAbudF59OGSUd9PgzIwJfQPSGRWp5WJqo4qz61Va4fQ+pmCj+4ZU55M80vv52ispus1G6uAd+xUGaWruQOtfdUZfq3Q2FVDdlh/ElyRog8bDT4uljoKt4349qURvqW/KWXGfULDcu+R/bk12o3YA6WopAQtF0b7Q== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:49 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:49 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 03/14] iommu/arm-smmu-v3: Make smmu_domain->devices into an allocated list Date: Tue, 25 Jun 2024 09:37:34 -0300 Message-ID: <3-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0007.namprd13.prod.outlook.com (2603:10b6:208:160::20) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b0a42cc-388f-4e43-86e8-08dc95139e09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: wpZy99BxgZHPA2T7ki7cb68gFyX00a8JSuu2zopaB9n3AX5m97tHlPeHCNh1khsuOxk331z6i3T7IUs8kUE4imj9Czh1fCyqULDCITN7f/mePumcVshpF21qxPvn7OToYJce2pjSPwXdsibCgEH+jOsZwkhAXM25sseglr9dF2vYgSWcegjP/YuQ94EitMVwBvig8sKJJBC5Zx3PRk0tp9JVMLmfkCVOvfvoUC3RPcInAuPdY8VVUX9UiToUN825u7aoTyeQYo0W4mCWjlPmAqlTLsoUE8/wyiNnuuezFbj+WP49+hFJ2GfMzBtAeH1TODzGNwyG0TqiBfaZUz32xLt9XbAkCX+J0XM4SZh5yhVXKa/dFw1vvLB3Pgh/a+5uyZBO6SA51lfGzGScExDh0Y7/38K9gREkEPBLksvFhhcJCk5H+agWQOSC/rXL1GtXwJrJdS+NwKjOewMklPRufEnHjkCiSNOuJRLZIT9VRBq4ju8yl3SuW74FUgv3V/t+/ac1bZDIsBqWyYiYEMdioQAGOBHU9kb/e0gx6VoEW5oLRTq4vcCGXfigxRtmkEhUIhZ5UsbRBREuRYUzTgYU4xBfjjId5kRS827Lkyz1TNLpzNeQwBJyJxypMEauxQmfWL5+ghVRwIYzqdMamRPOirj0kOg/QW6WTW+NkiCbEnOE0cyhLnd8dq3iiU29QL9BhBQYquJtxWkGn1kbkLvpRjHf2vtuQB9NSfIghPJgN3EItyhwRVVO5V2NwgXMkD/WxnfaJLPkgpvsmfj8xumxwYEY3HdPH51VYBdWrkX5o9G+bRqRKJH296QJf8phS6Yi1htvq5Hqov15Ac+XJmkMFhfJfFgFLfumXNiirM/VqMozDdSghZ6cr0UK3gYRS5kGPFucfkDS20blCr/iHalhuZiH93CVL++rRMO/2qV2YIGoW7zXzQGs6tfFDvlV8BPsSBGP+zSSRIVzriLztCgp3Jg67qw4QauOD/qCVCxI0j0GbgY7uxvAWDtYmn12Y3l5s7EIOQHN6Bp6vebZ6m7VjbV69dZJXI5x37BRklLp32tREm6a3gWZQWWFw8DP/ktQtofNe6zE6ihC9wFwcY8eUsQKVL+DXmeU/S8j2HFBkHrdAXCsuyyNpxYXHV5sm2l97ISr9cj7pvR66X+iYaSjtkMptu2eOC9I2cAWpugAjfeUt3p/5TA1zJTOCg4KaZg+unRcI5I73ueHGgqj9cJCEw9stnu+GhEvAlVUs7qPUOiPmYsvGyEch8mG0gbozXy/LBkxfd9NAKfs7iY2mnQW8EoDbaiMZsIVlwBPmonoB7sNY2tCXdBct0oKmrnjPixH 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UVA0pQ+y4l8H+zL9ayuiMBmdflLIVpVpOqZ5r81WJZCVkdDdnMVh2mkzyIRLHvXsoyyiRZAWE17lCG7RYyWuokObo3mTjQJ++9LyOIUKiCWklyOmHkG0RQshvUXAT2fPA0Way42yy7qX+Q2xfgJPGAaJsraVd7+aIp6LRQcrc8oMFS6quTHpH3QviufUO0otvTA6+Cj4rKW2FzyMYSCM00ddZgNOJKPGmEgb3AerU2Mws0Ep4l6hOeBo+mU0II04JHoa3qGZjkBHPFHXdescV2PAyF/2OQtnrCR/L3WLUgc4hxJ5lSuDR8fPi9/bFdNtHGvN7r17UMIS0v14GDgz6y7OA8McNT/x0unae8TNHT3NaaZbjUFSiGciaNU8JiXbYAeuQnY2FfZAW8Flb04RpvFyVo+qTkQjhFMhfFJnIISzhInibyCAcTIc5XUCXjke4UagKYG9vjJWFasoEIz8R3AhgivDijcjZSa6zM6gqwSCglgud5A2KG3MgeYtoDo7aCRzAyE6auZtQFQDw+UJdgzqbhe5kBbP2WIqF5Gj6F140zzHcUFtjq8PrG/fCupRRl80tgGz6iS8CDdOpPHR6Vbmf7YZmi/N8EiPy3oIJIpS5Yy9Z9+OdJxu/VYwu7drZ8NeUIWPPHtQhaGByK1l9awFBfqmr/RITDuNjBoztHjTsbp3RlkYzEdPY46zmqLt973DQbq2HKnWgCbvYSBA/PJdSEvQA1ZpIdL1EdrMunDoI9NqmcMo/6UJAyUSew73sbUafN8RUuG3sK70LUXzsBcJgOj2RkLOFGCOpOa/FdHeqlhcf8TNAwT7/jeCWCslqmZ1W0ccY3WlKCBCrqhlloM3Y1b/d0Li4oPMKSFo78wJ192ACGFpKyjKGytsp8BHzojJp8MrnNfeJluM1g0g2WdEYYrXcEUXxtzWTjJVqybt/BAcudH2tH8pjPmM0laSR5joKSeFQnjNts2I289uo96fU6V5YVGV7WRgbpNJhEPb9LAv925ACxDqyyMkPbnJOB7WtMwHu+JRPuq0KuA/MBYuJbfxxR63csum/dopxN7MgdP8KBJ8BUzqDOHfPO5tpu72bYh43IeAlh9J2/TruxL2k2+gxUqlJSVbo+609J4OYUWJ1UBmhgGW0TiQ+eAog25Ci7bhl0C9BsTmCXZAweV1d5YVVNooNuqfi/ctfUdXV0hqSMouVch7h5p7d8914AGhufo7B61DbYi7hnfdcCXVXK7HFG3o/6APpQ/jM+I2hTw188s77xWKElne+gq+vpqRuvcLE3zl5hKoxdsShpt/PP3b05TMn0Rl7E8rIPB8OLKu5X/ebLjy1gK3bvJQ2o7eJXm9jhOGwsP5lpybLGScQW0Izks1WLEYEwX24Qpp1hu5kKo4iVCCrMLbP9GRwX8CvHLAIMeUGgZCOjgkwxxwMbR2OCiXR5igZOhvjq4zC0vOfFgb7BgAXrnMkNsSs/Tp32VZf4ia5knKQLqVsgloeWb+7LjIqZV9LnJ2adlsD/wNGFx5TCsnrbOh6taXXkTusPy4cWdtUqprpwFJqHCLwvi+VvUwrUiZLuExLjiMwHQcNh5HJWdAppyBPlnq X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b0a42cc-388f-4e43-86e8-08dc95139e09 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.9555 (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: QbIneuE8WrZmPNtCYvtoCwy5EZLzR/uKy5x1rx9GuEjWKfUgmNbo/Jq5pfU5c+52 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053801_898840_65B9917A X-CRM114-Status: GOOD ( 15.72 ) 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 The next patch will need to store the same master twice (with different SSIDs), so allocate memory for each list element. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 11 ++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 39 ++++++++++++++++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 +++- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 71ca87c2c5c3b6..cb3a0e4143c84a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -38,12 +38,13 @@ static DEFINE_MUTEX(sva_lock); static void arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) { - struct arm_smmu_master *master; + struct arm_smmu_master_domain *master_domain; struct arm_smmu_cd target_cd; unsigned long flags; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_for_each_entry(master, &smmu_domain->devices, domain_head) { + list_for_each_entry(master_domain, &smmu_domain->devices, devices_elm) { + struct arm_smmu_master *master = master_domain->master; struct arm_smmu_cd *cdptr; /* S1 domains only support RID attachment right now */ @@ -301,7 +302,7 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) { struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); struct arm_smmu_domain *smmu_domain = smmu_mn->domain; - struct arm_smmu_master *master; + struct arm_smmu_master_domain *master_domain; unsigned long flags; mutex_lock(&sva_lock); @@ -315,7 +316,9 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * but disable translation. */ spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_for_each_entry(master, &smmu_domain->devices, domain_head) { + list_for_each_entry(master_domain, &smmu_domain->devices, + devices_elm) { + struct arm_smmu_master *master = master_domain->master; struct arm_smmu_cd target; struct arm_smmu_cd *cdptr; 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 3f19436fe86a37..532fe17f28bfe5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2015,10 +2015,10 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_master *master) int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, unsigned long iova, size_t size) { + struct arm_smmu_master_domain *master_domain; int i; unsigned long flags; struct arm_smmu_cmdq_ent cmd; - struct arm_smmu_master *master; struct arm_smmu_cmdq_batch cmds; if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_ATS)) @@ -2046,7 +2046,10 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, cmds.num = 0; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_for_each_entry(master, &smmu_domain->devices, domain_head) { + list_for_each_entry(master_domain, &smmu_domain->devices, + devices_elm) { + struct arm_smmu_master *master = master_domain->master; + if (!master->ats_enabled) continue; @@ -2534,9 +2537,26 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) pci_disable_pasid(pdev); } +static struct arm_smmu_master_domain * +arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_master *master) +{ + struct arm_smmu_master_domain *master_domain; + + lockdep_assert_held(&smmu_domain->devices_lock); + + list_for_each_entry(master_domain, &smmu_domain->devices, + devices_elm) { + if (master_domain->master == master) + return master_domain; + } + return NULL; +} + static void arm_smmu_detach_dev(struct arm_smmu_master *master) { struct iommu_domain *domain = iommu_get_domain_for_dev(master->dev); + struct arm_smmu_master_domain *master_domain; struct arm_smmu_domain *smmu_domain; unsigned long flags; @@ -2547,7 +2567,11 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) arm_smmu_disable_ats(master, smmu_domain); spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_del_init(&master->domain_head); + master_domain = arm_smmu_find_master_domain(smmu_domain, master); + if (master_domain) { + list_del(&master_domain->devices_elm); + kfree(master_domain); + } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); master->ats_enabled = false; @@ -2561,6 +2585,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct arm_smmu_device *smmu; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_master_domain *master_domain; struct arm_smmu_master *master; struct arm_smmu_cd *cdptr; @@ -2597,6 +2622,11 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return -ENOMEM; } + master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); + if (!master_domain) + return -ENOMEM; + master_domain->master = master; + /* * Prevent arm_smmu_share_asid() from trying to change the ASID * of either the old or new domain while we are working on it. @@ -2610,7 +2640,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->ats_enabled = arm_smmu_ats_supported(master); spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_add(&master->domain_head, &smmu_domain->devices); + list_add(&master_domain->devices_elm, &smmu_domain->devices); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); switch (smmu_domain->stage) { @@ -2925,7 +2955,6 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) master->dev = dev; master->smmu = smmu; INIT_LIST_HEAD(&master->bonds); - INIT_LIST_HEAD(&master->domain_head); dev_iommu_priv_set(dev, master); ret = arm_smmu_insert_master(smmu, master); 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 6a74d3d884fe8d..01769b5286a83a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -697,7 +697,6 @@ struct arm_smmu_stream { struct arm_smmu_master { struct arm_smmu_device *smmu; struct device *dev; - struct list_head domain_head; struct arm_smmu_stream *streams; /* Locked by the iommu core using the group mutex */ struct arm_smmu_ctx_desc_cfg cd_table; @@ -731,6 +730,7 @@ struct arm_smmu_domain { struct iommu_domain domain; + /* List of struct arm_smmu_master_domain */ struct list_head devices; spinlock_t devices_lock; @@ -767,6 +767,11 @@ void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, u16 asid); #endif +struct arm_smmu_master_domain { + struct list_head devices_elm; + struct arm_smmu_master *master; +}; + static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) { return container_of(dom, struct arm_smmu_domain, domain); From patchwork Tue Jun 25 12:37:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711073 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 3D415C30659 for ; Tue, 25 Jun 2024 12:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=vAZRBExWVoCMcRTBP9kntNfJ4lB3ba61O3KaTvFm1Vw=; b=BS9bdAc3QC+rxXLk2ZXXan8mKT X97wCGHVQ/abrLLbT1LcXpDeciX5lDApn2zImUt9gEU9N1BblcvmrLkOAwlNJTN7IpEjDde0LYGZU fxqUNJysQ1eoqAJ/ZMGVzYbcq/FSaDA4TVsBFB6qPQ43qRtHzUwpKx0AoviB5qd5A7QPRSn91LGTT 8eh72YFS3VF0/TZlJ7bOyqG+vG3+JDgdztu2MENpEJlXtfqhLF7al3BNpyx5zb+vtTS3RKDWsTfnT Jqw/XEY8jLpyEerQAoJjHvG7lUN4NOftBAd3UHvxb9Dbj0zSXIe9OsubDkA2RgTKkma/C+OVXRGrG l941mXmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5RG-00000002nyV-3KD2; Tue, 25 Jun 2024 12:38:22 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qs-00000002nfA-45T9 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fOMo4Ai391D3dmrbqOS0dsBmiSpsDf7YCiru5Wc1knjOz1vOTIdF+ISARb9Hje7WZE8sExpSGWuBja+cRQt/4Lh5d4jIGxiJfHmizgRZ/nkMTB9Qb3Q6jn4neE0JzsmKFzReWukevjBqtkpCUnB+9/5gXgGx13qdUqA97H28DcUo96IkapNjyhcp80ZY3GnHQM/ZtSinnsKdRQSZQiWQce/Tuq4N5rKDIzJqry37FT6xGwIxyZO//etMXeJH0U6qwsCC07vXfZO6gZxm9ucEuowbiIDDJXNYJAnFseJSotO+JQavgNbE/TGlWrDW6PrksG6g4e16Hlul9ch1wb3eBQ== 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=vAZRBExWVoCMcRTBP9kntNfJ4lB3ba61O3KaTvFm1Vw=; b=dJKvhioSK3ej69RXStZ8IHElkSmKnHVFdgpphmXQEdIRVwvyZkR3KFsNijB0ITYTDyRuLhH1h5eSKkwv1AOq7QBbPWgR2dxLAcuxRMFKxrkSllaTKb61jXoBNmqzzy4hVU/CaN+/+n+gtwdYYiiPt6+zcgWyXhB/+A8swt47w8182NeizX+xoYbCpVTp/iSfFdmxixx/woBbx+O2OfAhue4ciWYWuM1kR/jTX+oWC0jmBlHLyzcMfBxstPfCI/merKYbUYzpQB9S1bYcJbU7V6IBg4qU9IUnWKC5IYWMv+XFrMYHBOsez8Ogo56XmwHRshK+MIOGAEnoC6ApXmXIRw== 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=vAZRBExWVoCMcRTBP9kntNfJ4lB3ba61O3KaTvFm1Vw=; b=m3PKLgikar4xn7BCqrR2ibK7EmljhLdksH9K/tkBeh5YfRgYYYpISchYf9PrSYgxenaIm+5fLUIghiB6mfsGSehd+vQHHNa+MRdUpleHJfUC/EBl0fEQnonj+W1bYAL0la/JqcBF8Ml5vbzPxlFjni9DW7neRxcSgEkV1SsD5hLsCtvN1iEOKq8YlGzxz5cnOa6i9BhI0CY9SM9hoRfNtgOEWQjk5xzDrx2l3/K/tveoBvjD2JtBVb8Zb8Fiqh1gf3e9GPnUHzsPr0BnS3zToudW+H7q+cCJtC77EBHbdVaCb3X7K1NbdM9KynWcMRTD8IDMsbCaR+Gx/gXYrmmD3g== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:48 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:48 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 04/14] iommu/arm-smmu-v3: Make changing domains be hitless for ATS Date: Tue, 25 Jun 2024 09:37:35 -0300 Message-ID: <4-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR08CA0029.namprd08.prod.outlook.com (2603:10b6:208:239::34) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: 1bd8d07d-01a2-406d-b7f6-08dc95139dc8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: JovNhJ/PFM7pzJf8RANSMqTNhf8RJM1CelivFZ56+oxcxDZeHfKfuv3i1hxHOWCbl+d7ZA6glelYI/04JaYlXDzItlaGLihkM4mOy9ZTqNrtMS+p9Lz0g9xwNIYgiPRi3gWc/wmxeej5Bkt7XhR440oFHSDbiUfarJFOM9yCDt2BHKDqvCnYZfhR/8MnNaWCD2mQ/OyDz0lWbrfnyaX5/BuxSOMRZ0AI3gw6CPuHEdOSEYoZO7RacCRkluYIIfP/WmgmgGq3YrVjPJoAEDU3eIF6/+y04Wxbfn78k62zK9UxjMXB1d4c6K6IbtsY0ZabCxtR1AEt1LoNSukJ2P/7XSdIH04hHl8KExQlfF6prT+0UZ+Cg9RJgQhf6JD0EL7fIOVVsBC7xVv7XwKz0ktLE0Fy8oqrnSh8ieWtqnvjYQq+uFKKZEoJtaGb6MnyMHXWCLoSCjJGg8uliT+Sv2DDxxGCeEnYRAvl09AgoNyAE6Pw4/xUtLHoRs0Kt8VJ70lTseAuhs/uYk94JCCQTeCHxCoTCD+vRJPO4BLx/JGPECTJSdqyoyuHSCyPRXz1yWnxb9mvPHcp3v/8GoHlYwrlklFzrjnOELe14Nu1df6eMweiKzy3yBmGFPj7hJivo6YcIL0v1hz/1/ELBh79Xu9OiyLu1rVL/tf+oYxDSmk729AM6uTAGHTpNUqJp7LcuDxghhls3vfh3g9OUE9QQq4z3o6G0Pc5q3tJYIyXDY1DmdF6erbTx3Z5S5lXFtP4qrIetrQYpFANHIuKuq1/Dd6Zwjgbm10x020bsU+EK2WigFU8TbMJsvDMTw4mFGV3LYZoAfRDiONq0ny6AFdsbz67DgbCTYDtrJdgiMZQ+Kw3gPLutnxjP0hvt3/5T5FjnYaMwBzXkD+kKqG6mL5a5cJ9bLhlEmTUQw7BVPfnAjJ6tEH77cUQdLLLvabTh+jyJuvMrHsPb+uvwxUFfY1YgsBjUYZIHfaxjavzBt0f4B2uFtJmuQSMHH/Um4e/uZ3SiPsEGzwTEAfeDLtq0RcRwTRGn4cUrOqI17laYst4vWAVMIPGdzREzzD4V2us4EcoSRbocQ034Yc2g0iQK1SNTpRfUe5L5IQI5VIJYxyK7/WPUi0YbHnFG/0aPB83ePC5DSdteKEF4joTcC33iq4MM/nmECmMk6qkhkCdfNOdd/7jWCqKkz9is/+I0WP+JEa+WLXZNba3Kkskgke6VZXnMw1F14gAqOADQxvhEmwOB6GKtHbX8KgkVYWiOQFhdfdzMsMjuwuna9v0TvvZELXl16D8/DlqJR+ellZ0dL3wHEOwIgo= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Tp0SKVMNbP+O+z4qr+kHn0CmvTi0Z92jLDNhbolOt60U0n9XCGEzDofskHcynGVzL3ObLboj/HZOHX1ZkcZs6K1eoLkdEPpimFQLTc0UWnRf2SL1km4d4M0TmjwDHwRvH0PBjNlJTnGZaqWcobimsdxecV18KJhTJ4b5ECng13BhEDdKppndxq5NJVLt6Aj48Rh+siF/t0sAuH65+4mxU2uuDvKg8rXeXPIRAY93yucakw/SygbQZp8bAnVkE+L2XGSLvOEr2C5zUlcnF6bUbW7Nhr7gElr6yT1cIoF7TIoyW9CfezlgBEyqRY600oZ442klcQIwirvFlojIdJDd90mb31Cx/q/8xFdetjkTs97V/XfQX6zhWxUEJoOr/OPvOoRkwVBtRqSDhE36SGGxhU+kx4bvzQ8g6Tjdf/hGRYR/NKsX1OEUOIZjIgDUBgNR1BGFOFsY945lwFxxU07Nbs2LSNaEj1KplyGUz6+EgAA5/m/BgA+CM16vNC/0g/aIk9F9WIeGOg1PSVfh6nyf6iqCWZDCtdyFxDskQKtEBDb8pB8xs9A3SudZQ/WBx2JBP8uVqd2D10NxKoUFJsztKH5iC7PX8CjmRVIV41hLFlgfqzwmteJiXcuMobWrHcuTZi05ZjPznIesf5Im0EFs3AvujgxJmKSU26iGQAKtY1cri6fViKgvTheG7ny31tKTExiFoHSF7uefRr4VF1uDPSvwsZh4/bg0KTzlWGf+e+FXS2/s08FU5by6u2yUgCbNgUVKEFdTgxuel9WAF3S6e5zAN8dDawnJ0kZCWjyz6QXM0YR6PmGqZWriAlY07f5416KbS5G72cWLWuWdRUTMca1PDJF+hVYiS7kcTa3ces8qiusnG8goLkLG9dVLRR3pb/3YA5Z/LXiIR1g9FRD2xrgoqI8wdndE/hB2S2RAqqGnh3zpsFDIRc4Yz3fxpSRlkOCtEzKJE9D4JWQXHquo7eciAJMugryjH6BCYMwPdEseXCgva0GTH09t8RMtsiZvMe4YB+yb/ORNFmSfaIusISPcfXXy/lsHd3m0QPsp8/MAT2R7FZZNlL4aoCzNsxDzpeDgcwKO5Ac4LoZeoooyWaZdzIhKe/JkgkJ2eRB2YFeyIM6KbcpSimLoXuQNcf+G9okzFxurghS3E0iV5I/gKVSRmXHoU23ubCVFqWjJDtEsY0IqO236EJAnv8tdmveWAY5PZt81cmAWN38Q51GMdOaAfdBYqoMJSsgFeR2bhvV7QpI2LrwhkOaDfxoa5lbH0o5mIzzOhZQ21XY9dzHpA3JX8ysUHMZUBHEYAO1Ou2uyOCLxTD8+Sueh7tuCv8GJwd5kOVPxw3shII13Psnnjq5vlamvP/XhlLdpMMYPF7GEXHeJInicQmw2w6GuhcUUJZ/IF6i0wzgGhen1VvAM1C7MYEabeDW30bP8x6VfkZw71Ww5z07MABjHVl3E7URurEIgfqsmw2rDQYQFa0j8ueC2Ul8e8bZfITnmMdPWlF7sowELWUZqr20+CToGfIzXdEHBRkKPbWvB4leyVoxNAQbrG2DpUmM5D/EXJ3ZZFd/3yY9ygVRSFw7Ysv4US579 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1bd8d07d-01a2-406d-b7f6-08dc95139dc8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.5566 (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: yysZfC0ySogr1sSEtx2gvuLJYaieLMu196H4a91K9mNG4BSdquh1iVcJ0GtRvmZG X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053759_131932_AF7B3A63 X-CRM114-Status: GOOD ( 24.28 ) 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 The core code allows the domain to be changed on the fly without a forced stop in BLOCKED/IDENTITY. In this flow the driver should just continually maintain the ATS with no change while the STE is updated. ATS relies on a linked list smmu_domain->devices to keep track of which masters have the domain programmed, but this list is also used by arm_smmu_share_asid(), unrelated to ats. Create two new functions to encapsulate this combined logic: arm_smmu_attach_prepare() arm_smmu_attach_commit() The two functions can sequence both enabling ATS and disabling across the STE store. Have every update of the STE use this sequence. Installing a S1/S2 domain always enables the ATS if the PCIe device supports it. The enable flow is now ordered differently to allow it to be hitless: 1) Add the master to the new smmu_domain->devices list 2) Program the STE 3) Enable ATS at PCIe 4) Remove the master from the old smmu_domain This flow ensures that invalidations to either domain will generate an ATC invalidation to the device while the STE is being switched. Thus we don't need to turn off the ATS anymore for correctness. The disable flow is the reverse: 1) Disable ATS at PCIe 2) Program the STE 3) Invalidate the ATC 4) Remove the master from the old smmu_domain Move the nr_ats_masters adjustments to be close to the list manipulations. It is a count of the number of ATS enabled masters currently in the list. This is stricly before and after the STE/CD are revised, and done under the list's spin_lock. This is part of the bigger picture to allow changing the RID domain while a PASID is in use. If a SVA PASID is relying on ATS to function then changing the RID domain cannot just temporarily toggle ATS off without also wrecking the SVA PASID. The new infrastructure here is organized so that the PASID attach/detach flows will make use of it as well in following patches. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Michael Shavit Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 5 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 237 +++++++++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 6 +- 3 files changed, 177 insertions(+), 71 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c index 315e487fd990eb..a460b71f585789 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c @@ -164,7 +164,7 @@ static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste, .smmu = &smmu, }; - arm_smmu_make_cdtable_ste(ste, &master); + arm_smmu_make_cdtable_ste(ste, &master, true); } static void arm_smmu_v3_write_ste_test_bypass_to_abort(struct kunit *test) @@ -231,7 +231,6 @@ static void arm_smmu_test_make_s2_ste(struct arm_smmu_ste *ste, { struct arm_smmu_master master = { .smmu = &smmu, - .ats_enabled = ats_enabled, }; struct io_pgtable io_pgtable = {}; struct arm_smmu_domain smmu_domain = { @@ -247,7 +246,7 @@ static void arm_smmu_test_make_s2_ste(struct arm_smmu_ste *ste, io_pgtable.cfg.arm_lpae_s2_cfg.vtcr.sl = 3; io_pgtable.cfg.arm_lpae_s2_cfg.vtcr.tsz = 4; - arm_smmu_make_s2_domain_ste(ste, &master, &smmu_domain); + arm_smmu_make_s2_domain_ste(ste, &master, &smmu_domain, ats_enabled); } static void arm_smmu_v3_write_ste_test_s2_to_abort(struct kunit *test) 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 532fe17f28bfe5..d33d97496a03fb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1538,7 +1538,7 @@ EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_bypass_ste); VISIBLE_IF_KUNIT void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master) + struct arm_smmu_master *master, bool ats_enabled) { struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; struct arm_smmu_device *smmu = master->smmu; @@ -1561,7 +1561,7 @@ void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, STRTAB_STE_1_S1STALLD : 0) | FIELD_PREP(STRTAB_STE_1_EATS, - master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); if (smmu->features & ARM_SMMU_FEAT_E2H) { /* @@ -1591,7 +1591,8 @@ EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_cdtable_ste); VISIBLE_IF_KUNIT void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain) + struct arm_smmu_domain *smmu_domain, + bool ats_enabled) { struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; const struct io_pgtable_cfg *pgtbl_cfg = @@ -1608,7 +1609,7 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, target->data[1] = cpu_to_le64( FIELD_PREP(STRTAB_STE_1_EATS, - master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); if (smmu->features & ARM_SMMU_FEAT_ATTR_TYPES_OVR) target->data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, @@ -2450,22 +2451,16 @@ static bool arm_smmu_ats_supported(struct arm_smmu_master *master) return dev_is_pci(dev) && pci_ats_supported(to_pci_dev(dev)); } -static void arm_smmu_enable_ats(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain) +static void arm_smmu_enable_ats(struct arm_smmu_master *master) { size_t stu; struct pci_dev *pdev; struct arm_smmu_device *smmu = master->smmu; - /* Don't enable ATS at the endpoint if it's not enabled in the STE */ - if (!master->ats_enabled) - return; - /* Smallest Translation Unit: log2 of the smallest supported granule */ stu = __ffs(smmu->pgsize_bitmap); pdev = to_pci_dev(master->dev); - atomic_inc(&smmu_domain->nr_ats_masters); /* * ATC invalidation of PASID 0 causes the entire ATC to be flushed. */ @@ -2474,22 +2469,6 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master, dev_err(master->dev, "Failed to enable ATS (STU %zu)\n", stu); } -static void arm_smmu_disable_ats(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain) -{ - if (!master->ats_enabled) - return; - - pci_disable_ats(to_pci_dev(master->dev)); - /* - * Ensure ATS is disabled at the endpoint before we issue the - * ATC invalidation via the SMMU. - */ - wmb(); - arm_smmu_atc_inv_master(master); - atomic_dec(&smmu_domain->nr_ats_masters); -} - static int arm_smmu_enable_pasid(struct arm_smmu_master *master) { int ret; @@ -2553,46 +2532,181 @@ arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, return NULL; } -static void arm_smmu_detach_dev(struct arm_smmu_master *master) +/* + * If the domain uses the smmu_domain->devices list return the arm_smmu_domain + * structure, otherwise NULL. These domains track attached devices so they can + * issue invalidations. + */ +static struct arm_smmu_domain * +to_smmu_domain_devices(struct iommu_domain *domain) { - struct iommu_domain *domain = iommu_get_domain_for_dev(master->dev); + /* The domain can be NULL only when processing the first attach */ + if (!domain) + return NULL; + if (domain->type & __IOMMU_DOMAIN_PAGING) + return to_smmu_domain(domain); + return NULL; +} + +static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, + struct iommu_domain *domain) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain_devices(domain); struct arm_smmu_master_domain *master_domain; - struct arm_smmu_domain *smmu_domain; unsigned long flags; - if (!domain || !(domain->type & __IOMMU_DOMAIN_PAGING)) + if (!smmu_domain) return; - smmu_domain = to_smmu_domain(domain); - arm_smmu_disable_ats(master, smmu_domain); - spin_lock_irqsave(&smmu_domain->devices_lock, flags); master_domain = arm_smmu_find_master_domain(smmu_domain, master); if (master_domain) { list_del(&master_domain->devices_elm); kfree(master_domain); + if (master->ats_enabled) + atomic_dec(&smmu_domain->nr_ats_masters); } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); +} - master->ats_enabled = false; +struct arm_smmu_attach_state { + /* Inputs */ + struct iommu_domain *old_domain; + struct arm_smmu_master *master; + /* Resulting state */ + bool ats_enabled; +}; + +/* + * Start the sequence to attach a domain to a master. The sequence contains three + * steps: + * arm_smmu_attach_prepare() + * arm_smmu_install_ste_for_dev() + * arm_smmu_attach_commit() + * + * If prepare succeeds then the sequence must be completed. The STE installed + * must set the STE.EATS field according to state.ats_enabled. + * + * If the device supports ATS then this determines if EATS should be enabled + * in the STE, and starts sequencing EATS disable if required. + * + * The change of the EATS in the STE and the PCI ATS config space is managed by + * this sequence to be in the right order so that if PCI ATS is enabled then + * STE.ETAS is enabled. + * + * new_domain can be a non-paging domain. In this case ATS will not be enabled, + * and invalidations won't be tracked. + */ +static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, + struct iommu_domain *new_domain) +{ + struct arm_smmu_master *master = state->master; + struct arm_smmu_master_domain *master_domain; + struct arm_smmu_domain *smmu_domain = + to_smmu_domain_devices(new_domain); + unsigned long flags; + + /* + * arm_smmu_share_asid() must not see two domains pointing to the same + * arm_smmu_master_domain contents otherwise it could randomly write one + * or the other to the CD. + */ + lockdep_assert_held(&arm_smmu_asid_lock); + + if (smmu_domain) { + /* + * The SMMU does not support enabling ATS with bypass/abort. + * When the STE is in bypass (STE.Config[2:0] == 0b100), ATS + * Translation Requests and Translated transactions are denied + * as though ATS is disabled for the stream (STE.EATS == 0b00), + * causing F_BAD_ATS_TREQ and F_TRANSL_FORBIDDEN events + * (IHI0070Ea 5.2 Stream Table Entry). Thus ATS can only be + * enabled if we have arm_smmu_domain, those always have page + * tables. + */ + state->ats_enabled = arm_smmu_ats_supported(master); + + master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); + if (!master_domain) + return -ENOMEM; + master_domain->master = master; + + /* + * During prepare we want the current smmu_domain and new + * smmu_domain to be in the devices list before we change any + * HW. This ensures that both domains will send ATS + * invalidations to the master until we are done. + * + * It is tempting to make this list only track masters that are + * using ATS, but arm_smmu_share_asid() also uses this to change + * the ASID of a domain, unrelated to ATS. + * + * Notice if we are re-attaching the same domain then the list + * will have two identical entries and commit will remove only + * one of them. + */ + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + if (state->ats_enabled) + atomic_inc(&smmu_domain->nr_ats_masters); + list_add(&master_domain->devices_elm, &smmu_domain->devices); + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + } + + if (!state->ats_enabled && master->ats_enabled) { + pci_disable_ats(to_pci_dev(master->dev)); + /* + * This is probably overkill, but the config write for disabling + * ATS should complete before the STE is configured to generate + * UR to avoid AER noise. + */ + wmb(); + } + return 0; +} + +/* + * Commit is done after the STE/CD are configured with the EATS setting. It + * completes synchronizing the PCI device's ATC and finishes manipulating the + * smmu_domain->devices list. + */ +static void arm_smmu_attach_commit(struct arm_smmu_attach_state *state) +{ + struct arm_smmu_master *master = state->master; + + lockdep_assert_held(&arm_smmu_asid_lock); + + if (state->ats_enabled && !master->ats_enabled) { + arm_smmu_enable_ats(master); + } else if (master->ats_enabled) { + /* + * The translation has changed, flush the ATC. At this point the + * SMMU is translating for the new domain and both the old&new + * domain will issue invalidations. + */ + arm_smmu_atc_inv_master(master); + } + master->ats_enabled = state->ats_enabled; + + arm_smmu_remove_master_domain(master, state->old_domain); } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; - unsigned long flags; struct arm_smmu_ste target; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct arm_smmu_device *smmu; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - struct arm_smmu_master_domain *master_domain; + struct arm_smmu_attach_state state = { + .old_domain = iommu_get_domain_for_dev(dev), + }; struct arm_smmu_master *master; struct arm_smmu_cd *cdptr; if (!fwspec) return -ENOENT; - master = dev_iommu_priv_get(dev); + state.master = master = dev_iommu_priv_get(dev); smmu = master->smmu; /* @@ -2622,11 +2736,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return -ENOMEM; } - master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); - if (!master_domain) - return -ENOMEM; - master_domain->master = master; - /* * Prevent arm_smmu_share_asid() from trying to change the ASID * of either the old or new domain while we are working on it. @@ -2635,13 +2744,11 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) */ mutex_lock(&arm_smmu_asid_lock); - arm_smmu_detach_dev(master); - - master->ats_enabled = arm_smmu_ats_supported(master); - - spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_add(&master_domain->devices_elm, &smmu_domain->devices); - spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + ret = arm_smmu_attach_prepare(&state, domain); + if (ret) { + mutex_unlock(&arm_smmu_asid_lock); + return ret; + } switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: { @@ -2650,18 +2757,19 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); arm_smmu_write_cd_entry(master, IOMMU_NO_PASID, cdptr, &target_cd); - arm_smmu_make_cdtable_ste(&target, master); + arm_smmu_make_cdtable_ste(&target, master, state.ats_enabled); arm_smmu_install_ste_for_dev(master, &target); break; } case ARM_SMMU_DOMAIN_S2: - arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); + arm_smmu_make_s2_domain_ste(&target, master, smmu_domain, + state.ats_enabled); arm_smmu_install_ste_for_dev(master, &target); arm_smmu_clear_cd(master, IOMMU_NO_PASID); break; } - arm_smmu_enable_ats(master, smmu_domain); + arm_smmu_attach_commit(&state); mutex_unlock(&arm_smmu_asid_lock); return 0; } @@ -2690,10 +2798,14 @@ void arm_smmu_remove_pasid(struct arm_smmu_master *master, arm_smmu_clear_cd(master, pasid); } -static int arm_smmu_attach_dev_ste(struct device *dev, - struct arm_smmu_ste *ste) +static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, + struct device *dev, struct arm_smmu_ste *ste) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_attach_state state = { + .master = master, + .old_domain = iommu_get_domain_for_dev(dev), + }; if (arm_smmu_master_sva_enabled(master)) return -EBUSY; @@ -2704,16 +2816,9 @@ static int arm_smmu_attach_dev_ste(struct device *dev, */ mutex_lock(&arm_smmu_asid_lock); - /* - * The SMMU does not support enabling ATS with bypass/abort. When the - * STE is in bypass (STE.Config[2:0] == 0b100), ATS Translation Requests - * and Translated transactions are denied as though ATS is disabled for - * the stream (STE.EATS == 0b00), causing F_BAD_ATS_TREQ and - * F_TRANSL_FORBIDDEN events (IHI0070Ea 5.2 Stream Table Entry). - */ - arm_smmu_detach_dev(master); - + arm_smmu_attach_prepare(&state, domain); arm_smmu_install_ste_for_dev(master, ste); + arm_smmu_attach_commit(&state); mutex_unlock(&arm_smmu_asid_lock); /* @@ -2732,7 +2837,7 @@ static int arm_smmu_attach_dev_identity(struct iommu_domain *domain, struct arm_smmu_master *master = dev_iommu_priv_get(dev); arm_smmu_make_bypass_ste(master->smmu, &ste); - return arm_smmu_attach_dev_ste(dev, &ste); + return arm_smmu_attach_dev_ste(domain, dev, &ste); } static const struct iommu_domain_ops arm_smmu_identity_ops = { @@ -2750,7 +2855,7 @@ static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain, struct arm_smmu_ste ste; arm_smmu_make_abort_ste(&ste); - return arm_smmu_attach_dev_ste(dev, &ste); + return arm_smmu_attach_dev_ste(domain, dev, &ste); } static const struct iommu_domain_ops arm_smmu_blocked_ops = { 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 01769b5286a83a..f9b4bfb2e6b723 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -758,10 +758,12 @@ void arm_smmu_make_abort_ste(struct arm_smmu_ste *target); void arm_smmu_make_bypass_ste(struct arm_smmu_device *smmu, struct arm_smmu_ste *target); void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master); + struct arm_smmu_master *master, + bool ats_enabled); void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain); + struct arm_smmu_domain *smmu_domain, + bool ats_enabled); void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, struct arm_smmu_master *master, struct mm_struct *mm, u16 asid); From patchwork Tue Jun 25 12:37:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711095 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 2A5ABC2BBCA for ; Tue, 25 Jun 2024 12:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=RMhaN0GEtCNsfPgD3QJL5CcnxTDRZV+09R33NzJD3ak=; b=OP0k2dEX5XXlvQH6DaqvGjFQv1 pW1R3/qWamxR6QFa67IwI3c0v3WXWUSbsiuPbDhmXkojFAe19leOAfE5+43WUXKTKb/e9Yjx9FsHI 9iqJfNT1mJ2aFAuKl6vYmf9iGrjR3MiBXqLiaSlN1eG75cVJuCxOY9/OYZOTAqwIYbhoMWNXAXtV+ hVj39iKnOl+NIxHhYlI+yCJvlB2J+ijU53QG6m0pG5PJhfIjb/4a7E57snIX4brLBa11VBtwKPMaf tYGZkx7RDhFpm2LWEEb/ZvTcGjsx7lpD9lrowYO+L+39B8Ht+kT8pVbs+UEr+Uw1WT/DM+BYSb4bU m/4r3Jew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5fh-00000002rIz-15tA; Tue, 25 Jun 2024 12:53:17 +0000 Received: from mail-mw2nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:200a::601] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5fb-00000002rHz-3rDS for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:53:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UlA9GVi8DOrdtSny5BK/CIimoJQuiJv7rVdIz1A+eYSbFu2l55bLFOX4yLooM5scDEXw/b44H5Uhg70LmZ/Hgf2ic8RMz++KdWemgy5+f/lCa4050aBUazPm6cWQQNrgEOI7iL1X+FNKDY1Fzt+nF7yG8Bbq8wv8EuTEzqoAqHGZyTzxfcVdzT+yMGI5sYfS9n5j7hiJARbvRWR7FYFgJWrzF4A4zkcPcthsCSGFQ7xLgX8o9FttsmPLM0lB6MKJC/xehs1PFUjD9OMoJcHonLGf451S2qYhxHb42/bTMiCSJEJEerr3McafaBHvXObystAkburMEK6rJMAPVFOjZg== 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=RMhaN0GEtCNsfPgD3QJL5CcnxTDRZV+09R33NzJD3ak=; b=ADTRhahAHd2Gqq9fuJCearybopAlyFUUI7N94Zx8dFHVXpMoLFBy/mfRIZrgsB8wi05DCPztCNKQMe7mgeLzIvvPu7WL16h+fOmzng9aEgYuyZr3MUuiedO7YdlR2uyUvUjdF0jGSo4wClYHUoxqKT2HkL/za0we8qUHsfoSrtT7WRZ21ubVfXeCtVx2y5Gan5w+ahlwsqgNPx/aSy5n3z9OXEbKzkoYrQbrfy3oi2tlD2sRytZawDTs1OrazlBnEwZMSemGwQbEFl6J28A4fuI083Z1Z1bfGUIbwCEe+HarToSVQNL302yFK84R0n6z2f66pbVQp/Dm5yWHpP4eOQ== 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=RMhaN0GEtCNsfPgD3QJL5CcnxTDRZV+09R33NzJD3ak=; b=c3UUCmqmAIgI99Ve+0CCQIcmzLLc4+ArhsE+cacvdFEDjgRqPwRcuOb5m2oZIJy93/99263lVh43trvdvqyu/M1U7L3AyaWcT4lFG9Y7TuyP/0xeXVfc+l1k+vRe2x1KT9AeB6QvZlQT5oY2Tf+zoz6hG91Ab8R7rfqRVb4lwkLDba5gC0rj15MvE8Eu/0272vqeg0cEtw837JLbvBaq5ALq6TJBJOhowVW+JhYPHNAxDn6usGySXgRGp79VQwrW3kgxPTrpmAZLD/pw8mw1I/bJ0bXcvga09ycjolNuqz4AFlFYkrUTQFw6U93M+vlm7q0RswIwFBetBkfvW8Ddzw== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:46 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:46 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 05/14] iommu/arm-smmu-v3: Add ssid to struct arm_smmu_master_domain Date: Tue, 25 Jun 2024 09:37:36 -0300 Message-ID: <5-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR08CA0026.namprd08.prod.outlook.com (2603:10b6:208:239::31) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: 7b8e2866-5b26-40d4-8ce0-08dc95139d92 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: 8c7lRyv3MK071jJRYG3X4cR0FOTXBLIRMjGeOQt7IneEsqVc/BmGEEHZMn1yZhXoSQwKwSvIRD5mUjRzONv9QsbbNq8CEUDLjBUI0J7Rc7VR8BmDOKpxIhFcqN6wXQg5JvOuFWsNZQK8lOtawtXJWjGPtkN1OOfY/THlyMqzxltqG5LShjyDztE6aHbr+jQdLaeG27HnHc8lfTBIoqy9zejfAaSupDZsm+CsHFRdISIoUG6vhdWAWawCUPwB46FrW1aVTYKBmEXau6UqjTlKIEJkCWI5pWuh1hK/bduiKCmO/nYe8wLnMyqv8rjqUXWDXQ0janctUSVMS885wlE0hjwm1VgPXkGvWHQx4oUJzB1uetgHX8UzItzHtRknAIAhnNAwQs6lHfMSeKfROqp/ueDXJnpOhCnyWDj1kl/UsELlFZuTOm1l98Ls8KK/+fELA/g0Elh7Rj+C1K1ziKydrGMhO7I13trAWbr5ckh/+lKRHFw0GvuyEg/Dy1k38Qpm5kAAW0pVM7w7+I8M/b72WxOmdIXoKjovQcYX3dJlb8Df4Hh7dZC261sf0omYRsutZPrDzx92+wcz23MraSw+xYnPFrZweyvno566C5s1D6cpAeK187qK1p5VFICjLWkhjBenXNf04i6DIf/3ytbe2Ys61nqL3kspxKz3Zh2T2kJ2iga5P3O4P9EK+ekH8QJpa+bDwCGXP1VoUn96CIypbzhrWgEZEQhAfPErCFdVSVScJ41zwiHUI8JFddP90Tkbn6ie6cg98MKfXcEEUvt7vFjd+YESiwYLDhFXoBGhRgWzrjcjLePtC+bo0UXA9I1NhaOCwJrDaEQx0khHazqPg/PpCBdRe3rZO9SuaTWKYmZq9aWpA59MUIyks2fAgbcbzH1ybslQ7wSKknuebvudUF+mNj2bJpGdWgDz0Dkbb97ohUgMfIxXMt11dUJInbTpwHdYB9p0RbL65CEdmfpg2UELhUzzoOpX1wgeBwTTQyKuyvJe2hcjuEoFsXxdxSFG5BSwMkqp+fpbn8MLPbbAk48/NV3mnhDmvFJPU8WYBAFhh6C5BPG8BR9DWV8MHmDQC4RUPFMskVcjfOTcq08wHAQlzAlYDev5yyUSxnexXdpZ1Q47QIeAXuuyHEWgCNCFphvB7yILTKKcPuEzULBmPlKMAdP7yiaOER0pxkirmGfrG0gSTbH2j2QzC2cjsKswYC6xRdMLaVaNgjxD7Mey+1zdQmoAIWUwsUNb+WCMbzKGkeVu+5EbC9PDqvD36B1//2JuRm58vwJ4EDs+S6mr8eAfrbTPiXT+O3oEYK4gKkI= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Pgb8r8vBgO/VbMHhtlFn68GKjNEJ78kfsKMuKaqPhBYwpV8/th2+ZgvXRK6XIbUbjS7jJgz3UcpieQq8CcRqN4xpGar3veDGYkwOe8dxgfiH8khG/bU5QT+0oj00ga9uG/IDwc/miGzi9FZvZ5ZyvKX7mO+MDnLH/bLV13xYEdLxI4h01NMXSZNPYPRc8ssgJ4+gTD2eOj1eZl/DZ6H5gAKdgffmEqQMisSF6a/w1+YNCRqEcyl7OBPBNmciEHAvhWmd16Ierg7GHf4eqqDMJjelFcw2d5kxlGprM7b5Ykr9HMz2D3bKdqeFfxwS3MjmPWhqriFlkiuzRY/9ojlwAqDTTN/6uSJLhYo1AEGOWlqNVJsfDt6S+/VLjXzioAimsZ1JSPnFr01TLEjc/XzDi4ivrD1OFOJ9VZ8jaKKdNQvVvy7bZJc6zhnXa6TIkDMCxprJ/aykMSAuKyhtkjtwQ3qSgalZclzZ2GtaENLiP49UB/J3tkSnA3m1IPBL3DaKfMxcya0hg/F1hQGwBAXTE7Iu5e+kRqrZgRR1JsiGuwrlEABJ85X7QRNLiJEZ7zSiP/QNBMsdG7iLkqi0D0uf8X2F1qv8BmukcF20Tih5P86i4Cf+sZUwTp8f5jgmY2rKt5NvBnbP4r6SMiDxXPNunGZ0ipSktYWtKA52nIrnphtDMHLYp2hdY5kXqJDGg7ROu+K7eS8AfmrpghUwFaBuLZgLpKZPxs6pnFOA6xyMBNI0ypDG921KP7CXDkY9D5zqmNaFFp8tv8g9Akbo4s0BQ7rFyTLefZkfXKVmE/AbJ5Qkmd7KuUwJcvZ1NUySKFjfTW7dvIBU12S43OihTaQaDDldpSH7/ByG/J16AjbTme1sM/1Y+rFZOsRZd3HtnREdrKeH/33ujycpgLlfv6EbPxzGsrySKhzDbh/qqtZHF2yHLbI6eaWMvTrbqaiaFZ0BOyclO8ELCvMQlAls0X/mwnfyjESy6KzJRMqXzKlp8O4lkQTHXJ5/MAWebwU6kG4GRIDtKCagNM7CFTKoDX7Q9gWp8OxxPoeKDi45oNXqhGyaH+OEm/QucNVNk4m9BICklpIF9r2E//ziNUci5HUuoPvloYhfFO5zOJcslv8znXZkccM1zAIrDmZcb58rxgapyyNqTjdpPSUYgpnEaBhmE0K17p+LEyV0A6ZJ2y5E8WEw6Qr/ewgqURIhFgtlDGUmVvjDi1UXkjcS4wYh/qGwYgGPFzYtLdtYQThW58QuiIucoAh560ZRJbrsZE8ALtMpHKRCa5NXSksEjQj3o+k+OYLeTV9ztYW0zP3YwAfqgUcuET0koRVs51Nu2vEaInMvHZe8FA8UKunZCTcmMjgluOlPMqA/ViFUqjrPGiuP8uhVhuu8VRYpo6QqfLlDKvL5nECcwng/uqGfku9wHTxE0DWPImZD8ywnYBaJKE3jeT37XHke4dw91ClGsiS0D05rDCErLxRQkikGYDvYCCCYII6x9rGdfu1vx7ymyKE0uTxGzhy9nbO9du8rhmGGNDbaTK0jM63YYBifOBpDA6QHr14r653GiXYnxqtunYGTAnFc2Dg0qd78Ds0TX3IcLoLB X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7b8e2866-5b26-40d4-8ce0-08dc95139d92 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.2078 (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: zKyUTXMnprRUSeIDTjFSE6L9aUMsplCX8oWagyIC4E9l5r+NOscCDJDM0TQCcHtL X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_055312_145257_DEBB92E0 X-CRM114-Status: GOOD ( 15.48 ) 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 Prepare to allow a S1 domain to be attached to a PASID as well. Keep track of the SSID the domain is using on each master in the arm_smmu_master_domain. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 15 ++++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 42 +++++++++++++++---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 5 ++- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index cb3a0e4143c84a..d31caceb584984 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -47,13 +47,12 @@ arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) struct arm_smmu_master *master = master_domain->master; struct arm_smmu_cd *cdptr; - /* S1 domains only support RID attachment right now */ - cdptr = arm_smmu_get_cd_ptr(master, IOMMU_NO_PASID); + cdptr = arm_smmu_get_cd_ptr(master, master_domain->ssid); if (WARN_ON(!cdptr)) continue; arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); - arm_smmu_write_cd_entry(master, IOMMU_NO_PASID, cdptr, + arm_smmu_write_cd_entry(master, master_domain->ssid, cdptr, &target_cd); } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); @@ -294,8 +293,8 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, smmu_domain); } - arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), start, - size); + arm_smmu_atc_inv_domain_sva(smmu_domain, mm_get_enqcmd_pasid(mm), start, + size); } static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) @@ -332,7 +331,7 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid); - arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), 0, 0); + arm_smmu_atc_inv_domain_sva(smmu_domain, mm_get_enqcmd_pasid(mm), 0, 0); smmu_mn->cleared = true; mutex_unlock(&sva_lock); @@ -411,8 +410,8 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) */ if (!smmu_mn->cleared) { arm_smmu_tlb_inv_asid(smmu_domain->smmu, cd->asid); - arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), 0, - 0); + arm_smmu_atc_inv_domain_sva(smmu_domain, + mm_get_enqcmd_pasid(mm), 0, 0); } /* Frees smmu_mn */ 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 d33d97496a03fb..f563f2ee6fd76d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2013,8 +2013,8 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_master *master) return arm_smmu_cmdq_batch_submit(master->smmu, &cmds); } -int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, - unsigned long iova, size_t size) +static int __arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, + ioasid_t ssid, unsigned long iova, size_t size) { struct arm_smmu_master_domain *master_domain; int i; @@ -2042,8 +2042,6 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, if (!atomic_read(&smmu_domain->nr_ats_masters)) return 0; - arm_smmu_atc_inv_to_cmd(ssid, iova, size, &cmd); - cmds.num = 0; spin_lock_irqsave(&smmu_domain->devices_lock, flags); @@ -2054,6 +2052,16 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, if (!master->ats_enabled) continue; + /* + * Non-zero ssid means SVA is co-opting the S1 domain to issue + * invalidations for SVA PASIDs. + */ + if (ssid != IOMMU_NO_PASID) + arm_smmu_atc_inv_to_cmd(ssid, iova, size, &cmd); + else + arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, + &cmd); + for (i = 0; i < master->num_streams; i++) { cmd.atc.sid = master->streams[i].id; arm_smmu_cmdq_batch_add(smmu_domain->smmu, &cmds, &cmd); @@ -2064,6 +2072,19 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, return arm_smmu_cmdq_batch_submit(smmu_domain->smmu, &cmds); } +static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, + unsigned long iova, size_t size) +{ + return __arm_smmu_atc_inv_domain(smmu_domain, IOMMU_NO_PASID, iova, + size); +} + +int arm_smmu_atc_inv_domain_sva(struct arm_smmu_domain *smmu_domain, + ioasid_t ssid, unsigned long iova, size_t size) +{ + return __arm_smmu_atc_inv_domain(smmu_domain, ssid, iova, size); +} + /* IO_PGTABLE API */ static void arm_smmu_tlb_inv_context(void *cookie) { @@ -2085,7 +2106,7 @@ static void arm_smmu_tlb_inv_context(void *cookie) cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } - arm_smmu_atc_inv_domain(smmu_domain, IOMMU_NO_PASID, 0, 0); + arm_smmu_atc_inv_domain(smmu_domain, 0, 0); } static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, @@ -2183,7 +2204,7 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, * Unfortunately, this can't be leaf-only since we may have * zapped an entire table. */ - arm_smmu_atc_inv_domain(smmu_domain, IOMMU_NO_PASID, iova, size); + arm_smmu_atc_inv_domain(smmu_domain, iova, size); } void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, @@ -2518,7 +2539,8 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) static struct arm_smmu_master_domain * arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, - struct arm_smmu_master *master) + struct arm_smmu_master *master, + ioasid_t ssid) { struct arm_smmu_master_domain *master_domain; @@ -2526,7 +2548,8 @@ arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, list_for_each_entry(master_domain, &smmu_domain->devices, devices_elm) { - if (master_domain->master == master) + if (master_domain->master == master && + master_domain->ssid == ssid) return master_domain; } return NULL; @@ -2559,7 +2582,8 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, return; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - master_domain = arm_smmu_find_master_domain(smmu_domain, master); + master_domain = arm_smmu_find_master_domain(smmu_domain, master, + IOMMU_NO_PASID); if (master_domain) { list_del(&master_domain->devices_elm); kfree(master_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 f9b4bfb2e6b723..f4061ffc1e612d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -772,6 +772,7 @@ void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, struct arm_smmu_master_domain { struct list_head devices_elm; struct arm_smmu_master *master; + ioasid_t ssid; }; static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) @@ -803,8 +804,8 @@ void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, size_t granule, bool leaf, struct arm_smmu_domain *smmu_domain); bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd); -int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, - unsigned long iova, size_t size); +int arm_smmu_atc_inv_domain_sva(struct arm_smmu_domain *smmu_domain, + ioasid_t ssid, unsigned long iova, size_t size); #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); From patchwork Tue Jun 25 12:37:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711093 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 5DD31C2BBCA for ; Tue, 25 Jun 2024 12:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=CrTXGyZLQ5FtW0AFYk6OXLwD0FCE7zEIQ9P+Er4Ywho=; b=eB9q6blqHKA+0W3lsgSQ+V99Ji fetkhEcSxwZ29to8MkT+QOMpa8tvhsfVH/cCuMvVNE88iF+7l+N1eUyrDGbeIlbb08fGu3p9JtKA6 LvOkuXrqnP06uQ62/aaIkt+dcn5ap09PkynQiJbz+oInh6AcnOdb3LofBYjDDfPbIEiJImnj7vidd gpvPdNLPqsWcssHeNB3qGgsxyX3TwOcZIlcH61OB+bgxv0y5b0VhrHTK9b/Xy0HZRpJjOmpaj9jXP SjU73HpkhCMrkx62YrUxf2uKno4wJQiRqoCEyFGpGTwXEhDAkdd32ybh3eLDawj+sAnl31EKMYslO /z2RZzAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5eX-00000002r85-3Hkt; Tue, 25 Jun 2024 12:52:05 +0000 Received: from mail-dm6nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2415::601] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5eS-00000002r77-2LnD for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:52:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EgB4Bn4kDe7hBBUvKICIDNaRoB0EF4ly8OgWTfpkF0kf+HyEZhtcCOMfMMExgSF99wG9abGHCc61mAJ/Fl6sTirQOwM6/jE6jAE9uohMuMK7tWKIE4Yx4XPq5Ys1NnyhxlxPJhdJ41J/3fA1fjiC165gsONZYGr3HAHzO+8EIrobl3WECTiEPJ1/tSThsYCJc020f3pa8ArWFKw1pvjxdeNp2fygfY2I+QkY0AoklgmrbbnX5oyjMLz/YmyRT70YMK1iB4fiEFBKUSJk1VUYQb0pinG4uYbYkVE4IjV8ddFA0dRRzCz/hTZkarKi6THWtb8RBBgJ66hII0UKiy0K/A== 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=CrTXGyZLQ5FtW0AFYk6OXLwD0FCE7zEIQ9P+Er4Ywho=; b=ilpnnwa0R544jxeEHQ18lH2ogLiC0J8cNMOEsGkoDU+QGDKlA97v47N6CM4JtWCofOWs/B+XgpnyStzjLsafHLpXr3t2iCHYtXlt8gnVByIqM/mjL17T79SOPxEWeZQjbykwdqIZXSJaXlvt3ES9nyi7vN7m35E+RnjMHUgymf7zkhGwTzYJAmXtJE8K1fBF9B7seOlPlqCUc5oNDGnX59LDHOnN5zgt6kwu56zsUFa3BOL3u3gZoPOY4fN8gUzJmEwMKyHRkIQ3NRt0wR8YMab/4pBVg7nh3QewH+drGjcZm/RaH5O27r/Qyl0/rOFNQdOuyS6qswgf44c7GktOfg== 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=CrTXGyZLQ5FtW0AFYk6OXLwD0FCE7zEIQ9P+Er4Ywho=; b=g2GWgdaDB1jX0Yvk6F+/zx+N6jWsw0qkRR3Uy8CQh9iR3Ibo0eAjKFx8UCygkSVOkGHHMDzHznbyuZwgZ33hl2S8YOjtn8dWJll/se9kKlS8LGmtV5IZFY1cgD6LCZVTXX3Ct5rdcqXgQMNO4WHggvVqXlR2kVcB5r9pnVDWQTSc81HFRMvyQdBYfJvE4xsQqcGBsVBUjZa50gjQRnnSedYQ7+wzfCAi7xw3IutJaA8K6tsyoYDyoWh4dPPmwO3NiB0C+tSgie4TFI5xxwe+pkmBWwHIdbDzXJMkukHXyNly4WDPGHUQed2CbW+DXHtC2ezSG8F+6pnB9uphHlkl7g== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:46 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:46 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 06/14] iommu/arm-smmu-v3: Do not use master->sva_enable to restrict attaches Date: Tue, 25 Jun 2024 09:37:37 -0300 Message-ID: <6-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR05CA0045.namprd05.prod.outlook.com (2603:10b6:208:335::25) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: b0699e82-eaa0-4319-564b-08dc95139d92 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: mWAtimW9ZYLezF3TlbHoxGKfa6tl/BaTB7LS4fa8znbscE/b45gesX3L+4IIXHs+LdyffNpV4Srzm5C3fcAx+PC/xdJyJSfhgSLaWr+Nv7tfRETZlEWoALZt61dAW69LiAyY7NEvU2VKcu30ahsZQycOR+UciSK4NiV9DAfGTWfuzaj1X1kjuhv9JEsfoDJwsXWxy5lFKXALKA7/sJ74KoDTg6O8fTqX+BT2xF0YoDD/bxI160vCfuZ5qngMZGa2j4FtqcpzO9RIhFJmTEDXsb6dsFhaiAe8o2U/k6egiQ5cfk+IIptY5TES49XKnLorbQjEAPLipnHLCXvZ6vfrWQzrsn/62KiAvFyQyHD7qbz1KMMxoyEG1DJFfXAo3q+BbY4Y0fHKoFBvCwnctEYiiIGE+R0PbAfNnouxDZ/tciGk6rBXq3Yf19pyElsUVllhpv+xtA38M/qmjDc1Xl8tEX6hzRkQHuxVLivZUPljGcGk4wwNwSESDPtGAm2+OO9HDYE9pd3d5StLOhcx3FiOx2XYj8IcjkUr0jf0coOFkmqDFvZ6QpANCar6REp7U+APox/xuTLCR1Tg+KQJMFsvJvRXGdfLjh9a/G4tiyURXnbLgGEI2BSN/pfye80OGMUMS8elnZT+kHe2UWHVYusL2Xy7CkrilLZXzIGk7FkdB4BxwKmDXQvM/Z5DWfmujVFfW2tkEKk45McrNHhrRby09F0gWAIFwCIZzZE7tMHDTtdlckkxmJbIxwwb44MWAvzI60Y3JURcRlavGKyDDdsOSiy3ZE8yqQ6334H1q4dSMZ11X+Jvm/0qfjlb+UME1szZLvzx4854W8mK5N3Tagg+KY4av+QK/oCUXNmIrtfA/BLcKogzlffqYdWVA2ZpTsXTqpWr+G9On/VfbubqdWp79/TBtHA5gbrcMwaJRvaugp87vCq/XH/spHXMD3dL2XyNFAutffEDpPe5dSMQQRfPsvfUkss9Tr3KDhEnZk6wCuSeQ4blmKWeGaPUFDbuMejVQjr7xrsIjSTLWRJ0gPIQzET26LZGOobVzBDKFhtRxOFQSoY6dmHmBbHLBkuXYRwloatvGnANmnkWra8zV111Klno+mx+/MRIV4KKchd9YmeS/ihNEERhDeAA7mHRC4EVVzERRbuXZG7Jzk7aYkIqw5df9e3nowH1WIJBI4n22HO1Nrje1SHZktIr5JcsprMH54PWPcjzLLoltiVbzgttdOjVIts9D+GA4X+APWkYWC+VKbk3iLgS4xI1/GrGIsQD3zeGifstxWGP9w2RS/rRmqz9+VLrvU1Ttv0yNVM9mEE= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: q7TaxrlNgHfvtcxWZEpDNKtKOtVMWATzq9YddGITonua2YVRbS48ixrtNxIFGrTaM970hvUXJfQNj6ykb7Noff1GuyjiDMoHr6BcZfahoW/wGhSnyG8iO6jKt3rAJBRJvh6q7s9ZoiKEvdZeRDiHtOIUvVVlfnAeON1z8pMsoUfm1MqB5Ur2zM3IdHW0ZtjP+36VIL4QGAnyhnmW7gwmSVOUtdVVzkZBXEQFHJGKbpSSod88AC5mRSSJcEVGsVKscPQY+TWjXKr0HSLx4o0WlbBkslhf6hx9xkh/xy4kGwgETZUSbAuwhOLnGMSOiCspHSlyAVgnEFZQzZD9D2ErTwN8+8mE9mgTMjaCqx1fvjStObh+QNjzogc9WOtj4Dy7uBTLeNhf384gFLKZjpkeJvMKcyajDn2TW79I2GAmyf98ElTGSTmiPDQRqtMybeXBWmZFAO5rJyqqAw9KTSFza3kJISJfU3hE8fnX6ouCKjpGhdRoItOMT75u82tLVHHUqoC4DaS+ng8KaOySX/Mly0vy3ft24IA4XPHEjjWAYJlDjE2cjGCwPZNsMcElAnL79BG97o8JMmGuUaRem3G2X/SvHsYSnoFcMkMrDZSXDokIY5ChnV+AjCSU2bvvbvx9u+joAvLfv4EFR9BOBxn4QkT8JzZn3QEZzNRppMqRbWrPqqxt6VqCOZYgcImhOKVKdtSns5C185eMoejs/OL74dKs4HakfNjlJ3DkS7LUAtuFvMcLEpbVa5+tekubhbf855sT3BDDF2VpiMwecdahQzz81Wwy49ekPQdprDHuPKAMHiLXrPeainiDfhCRVEMJU9vuQPXdqjIU6aqIwsxNLgvkI1DYypOYF6QZenjJqjogz/5pEgHeH8uFgYdk0nay++vmL1lXO2KuNTt7Q8AuFp6GwZWzMiKbf5507dbim0i7wKF/+GXIHEE+dLQO6CDpD0KfjXpZKwxmBf/Cys+SRDx9fOSl8hfgBYKmMk+vAhBLBDzY/r0VBbJ/I0lzm69FAicphmT52uyBFTpKnnio6OrG/nhzcSeg5WlfCV8VBxIlTu/Ks28Zo5oQ1GJHb+/rBTybTuB3UlvxuKYCaPuYtvFnoIR5ioSKMg8rjSkTD/NzIm7kZkTTD5wBlwSqZhP+Q2RKVhjSQVlI3MXvmI6M5xU4flGepGvhfna02c3tf408cpqLWKDDPKEftKRn01HO+rBwESszv4e0zvFJWotLREE3sSj3pBfVdVlz2QINnomV3C51fVi4rqVLtMZquOLWwddqnBpr7g5XwMUTH80T/uT7nqbkMTiRAjk3yhjTVYjfnPYTvisSWyQxJvlQ1uIfWmIpDscbaYk1oZlH5Mu+wExjpmk38dC7o0UDB7vBNyO8WTmdAycF8czRfJlRH9AtDKiZ+ekPpwogCHZTU4tQsylJ8tMLi6wez9wLr6RCv86F458QsN5QG4Gs8lMtjFQHegQ4fDWZKUpdrQKkyQyz1MIXnoYQ12V/WmbQzovlqlAa2dup3MntE56KdVrZAjuKrWFEIw8TbfaknU2Bm39X0bbPahfURV6TpUjIDa3dituDlrB62KfRIw16IgRX8zYM X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0699e82-eaa0-4319-564b-08dc95139d92 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.1502 (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: itlpA6hHhizlF5h3LEQrktS33wjI4/fNXICGG6N1ATzPmOHEIB4H93t3+rl3wGFu X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_055200_610554_D7AA6315 X-CRM114-Status: GOOD ( 20.63 ) 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 We no longer need a master->sva_enable to control what attaches are allowed. Instead we can tell if the attach is legal based on the current configuration of the master. Keep track of the number of valid CD entries for SSID's in the cd_table and if the cd_table has been installed in the STE directly so we know what the configuration is. The attach logic is then made into: - SVA bind, check if the CD is installed - RID attach of S2, block if SSIDs are used - RID attach of IDENTITY/BLOCKING, block if SSIDs are used arm_smmu_set_pasid() is already checking if it is possible to setup a CD entry, at this patch it means the RID path already set a STE pointing at the CD table. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 ++++++ 2 files changed, 19 insertions(+), 12 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 f563f2ee6fd76d..38d1465a44b479 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1289,6 +1289,8 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, struct arm_smmu_cd *cdptr, const struct arm_smmu_cd *target) { + bool target_valid = target->data[0] & cpu_to_le64(CTXDESC_CD_0_V); + bool cur_valid = cdptr->data[0] & cpu_to_le64(CTXDESC_CD_0_V); struct arm_smmu_cd_writer cd_writer = { .writer = { .ops = &arm_smmu_cd_writer_ops, @@ -1297,6 +1299,13 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, .ssid = ssid, }; + if (ssid != IOMMU_NO_PASID && cur_valid != target_valid) { + if (cur_valid) + master->cd_table.used_ssids--; + else + master->cd_table.used_ssids++; + } + arm_smmu_write_entry(&cd_writer.writer, cdptr->data, target->data); } @@ -2733,16 +2742,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) state.master = master = dev_iommu_priv_get(dev); smmu = master->smmu; - /* - * Checking that SVA is disabled ensures that this device isn't bound to - * any mm, and can be safely detached from its old domain. Bonds cannot - * be removed concurrently since we're holding the group mutex. - */ - if (arm_smmu_master_sva_enabled(master)) { - dev_err(dev, "cannot attach - SVA enabled\n"); - return -EBUSY; - } - mutex_lock(&smmu_domain->init_mutex); if (!smmu_domain->smmu) { @@ -2758,7 +2757,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) cdptr = arm_smmu_alloc_cd_ptr(master, IOMMU_NO_PASID); if (!cdptr) return -ENOMEM; - } + } else if (arm_smmu_ssids_in_use(&master->cd_table)) + return -EBUSY; /* * Prevent arm_smmu_share_asid() from trying to change the ASID @@ -2831,7 +2831,7 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, .old_domain = iommu_get_domain_for_dev(dev), }; - if (arm_smmu_master_sva_enabled(master)) + if (arm_smmu_ssids_in_use(&master->cd_table)) return -EBUSY; /* 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 f4061ffc1e612d..65b75dbfd15914 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -602,12 +602,19 @@ struct arm_smmu_ctx_desc_cfg { dma_addr_t cdtab_dma; struct arm_smmu_l1_ctx_desc *l1_desc; unsigned int num_l1_ents; + unsigned int used_ssids; u8 in_ste; u8 s1fmt; /* log2 of the maximum number of CDs supported by this table */ u8 s1cdmax; }; +/* True if the cd table has SSIDS > 0 in use. */ +static inline bool arm_smmu_ssids_in_use(struct arm_smmu_ctx_desc_cfg *cd_table) +{ + return cd_table->used_ssids; +} + struct arm_smmu_s2_cfg { u16 vmid; }; From patchwork Tue Jun 25 12:37:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711094 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 99E6CC2BBCA for ; Tue, 25 Jun 2024 12:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=WtEi5+8vA/edyn/3LkOJ4tMVBbAgVrmh1gPHsAWFYAY=; b=yNwVnL97DcMmbMqKtelOI0j7AC CQm8zgqMncAhnrRCQO7eUYDlqWAc3VZ9aZW6twGiZ8ztJT+HPQk1WSiBuqBfT5dHW3sOri3mDjBUU oFl4vtXP43sv9OnSux5Jcv9Rx9s/Jdw4Jck5awA4jkFlPRJcmhvNuHC9Bq71wzUlPdq+ojhakXlpM iyrv5K789pr+EJraIo3j8ydgXWiay5pUL+Qfk4MgPzio6v9BC/ZH8tFziPrSVQrmDOXkyNdrCSMn1 cga6gOWyhHKbOG0zuLQQP9TugWM8EuGLJWIHWOmuwouGtKQBv7vDE7VBkQ377CCkXCGxl2FMKc9dg rDSV/6Vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5f7-00000002rDZ-2Vg0; Tue, 25 Jun 2024 12:52:41 +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 1sM5f2-00000002rCp-1Ogv for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:52:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YIG0yxYflZAkXSOtBOHS50iKtvyxMLEwWRlAN1mroE/w0xXEWiGp463AGQkRwDpQ6q6lLSX9rdZoIz118U1VyC1Vx49yoFhffpQmnsGFh40tKopkX7PVcHrPRd8sZad6y7FSuUVWiyt64xs/AgftadH14R5RKYhXgemrSrKOZpgJWoeWG18PCelXXVq+b0Ch4UmrN85rKS3XIz0WrZdYdeKfiL+U0b0ue/y1GEvURvBCqNF9vqBMoPpkYy1eCsPmV8agUX5k6RVxC3wbjpQ7K/l1Q73aEnvc1ybsSGcVwbQ79PkVyXI6/TPTz0sy4JtOO7S0pJAkXQjXglXbpkZdXw== 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=WtEi5+8vA/edyn/3LkOJ4tMVBbAgVrmh1gPHsAWFYAY=; b=cV6nsGNw5ElT4f7cU8XlirdknoP8Wiv3Egg4LebsQ+qPv+OhhWecM4BS6cOHUiOQLAYn2rv4u+NaHOoK3BljdtAodJWAZK+EXeurYjmXGrYiHfN/aEvbvVSGXxyghiXJerMC23gpPFZY5lqQnjVBi3wlk9tLSLF6IAM8g4tSsykVS4MQeRVwI8x1XUXkyI+/iiDiEF1LmFdsNTGo1ONjWZPu+AUHYMNzhqi+hk9Ijqq45OVxM0WaZn4Y+zF5mwMQ5oTOLTX1uEIyE1sORXd7g38e9hq2mg304PXfjIcUFFHLHyCKJP1RoEhWHrR/OeAVk/vxz59aLA/yqqYX+qQccg== 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=WtEi5+8vA/edyn/3LkOJ4tMVBbAgVrmh1gPHsAWFYAY=; b=aYEjyiHDPBogbmfI4P2sVJkmVmxfKG4qVilNOOtJFLD6PDKZ8TsY74jGcS36VFAVMBqA683MoIujRGaogMrYWaGhetZl3TxqrJRg51ils82X/2ckoTv3SaN1QCoXE6F6a06YeWac+xzIQa6rWsB9OOFbeKYEUQfDKV8qOE3G6nUnwutK2yEZ6yiyHFPfp64OycfdoWeZUhmiHnafWOoUVj9N8ulPP3gpeasslBlPkJ+J/tAgJcPKwUzd2Gwsp/fUXccvHCA3rB23GJCyVeecOBj0VIicJ28keb2NILylWKYCO1uoShBqRYarWNbS5ZA4eJC2/2ew2wue5nanrRkxZg== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:47 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:47 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 07/14] iommu/arm-smmu-v3: Thread SSID through the arm_smmu_attach_*() interface Date: Tue, 25 Jun 2024 09:37:38 -0300 Message-ID: <7-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0034.namprd13.prod.outlook.com (2603:10b6:208:160::47) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: c3a430ea-115a-49ca-bf43-08dc95139dba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: IIeCOJ1bMtWyE9Y3VIhHi4eI+YY9r4YWopAp5VAxd7og1xkIwFfPwEcO7GjHTbAJrHGW9um0iwcAw9RyudX6rGro5kGupRcPRuxWgrB0CXP45NKHIs+Z8ZlXItUa9ozRYD3/YNLC1BewmmdQ1FF1NPN68pY5qS/ImQH5UHGPHyfSQkybIMm9Th/W0coLdi1YgwhUfloRMd70ABfQxfyDcEZ41afZNQgAyWAfON8L6ZN77AYY8Y8/YCwrNx4R2AN2P/PloAFpcB18zHz/WN3+MCT7q2Qcp0EuPWU0jRAPD5/Z9mHD3TsjVEWak+TMRm4EKLJmfY93LZdaBdU6CSyspUno2j3Yfc/yd2s4MiRYvcBhcWrcPrq+fwUAa46GFHx8GgswTzkZ0fThDP3TtfEAkJPFtBdKVBaq0z+5hs/1aZwacFxaXI+uG3/QxQjTALqDMDw3Wf5ItZOx09WDQXX2Goa3t00IRp0S9TRJANp7eb83pnr2Gj7IWvGIDG2J8wJi0eOCL7t0U4TkfqP+DACb9m8zYeGb16VkMyEg4cvBtpOY/n/WLemCgYv6ZY5X9PTEWarRMZlUhwDQ84C8GzC+w1IFIoc+OOwCzN12qYg/+yuNirg8H28GtBdpSLeHdNhq0LesH4gWE/SnzIgiNs+3Xhmo35oEkMKTRNr2IpfGN+9Qpz5VjL7l55rP7S0eXtkJhMs/Wy9f8udP8GTLXDvvdMQ/3Af6lVRtO93KfnK/czls4TKXNhxdnj5YIxlZaVMYgRbYy7YrEzCPhIqyWz8OJRQ3swpMDQ+ny3LDOOU5AWNhW+dZlQzChGrhzy8M9551e9jmySGza0v0vaNIcdqbI//eCBSStsSZQ1gKZGJHM7tWeR+objDKG2HUQLrIDrd8WMv8M33Rig/IYwGmADHWUtzo8f1N0xXmwPI4ZZ7VpkHKMioRYxbpxxAS3DDAg1nxeYi1sIERkK6MYU/HicvAIw64oSiCDvV/LBQdette4XC161y08tk0OvHtZ/pnOTqcdPiHcxTKIpzwShCSUBzZt2CDwm61DrPBEYz8nvbY55Ix1rqf4lHmSm+uXRv4RYdW9i+9WWrau9ofgqR+42nxkUEWE4bEhDRoU82My/6ent3day23Dw7ZwCSq1ORlBHThy2+VhHhfs0LPitGShXzyPL65zrdTXfTWHQp62NU+sBpVaeBZnfNwlJb/PViPAY4g410xsEdPoKpM0NNZWqYeGhQf5CoqN5wZbQwA7yF2eIw+rQXUOavHuzwTV4MAj6rFf7WBWThZsUSXvwtmfzjZh11OI4JlP6XuIAb0A1cDpCs= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ut1H+y6iEdKMbewZnPMRI9tQJDm8ShB2tFa2wGa6yXukYPuAYojQFDBfsxVwjHnAAKy9dROXoCFdSc1nAIwRcbTQ+4ns+did5JOXJTAtgvvihyQhIIdq5ZdIIXviHIsWM0IFiPNA6J9OUOQGkgTbKp3COx08gtoidH2PwKREn2Xzm1hNpwLtFtK3WGix6OBCHy3GA5YHyfk5ilTHtuv0kTgrFaf1sqO2QDD9o8btDie/aUdO369PpYsVaQzF6PzrzH04SkUYk0PfN59M5CXFanVebmsxNIu6yEt8WcDIkQHHZkqAx27AtN5na28n4IXT4gDeqds7dQuGBQCvccF39CgisjGKbswpkLqDuLewTh3lr9jWUY4jfeYFDJT0g4/a5ZhvhYUfwSUApnsCp41IgpEkcIiunoUp6jYzvPX6ar2Oewcjx7jOklJnbqadkte7vnOrfx7kQQw456SIq+/OMIlnCZgsKVor27InTGFByEkrr7KDtjrSzFKi8/DBg4/c1G9H1RAAm4CfNmxMsI/ZfD25RPWCqnqQUnKOSskWn/kKjunWFbtWvUI3+k9lYcypVp7SRt/FP5wFCuL2DiAFLF3Hzpzfhs5LosItQoTap6elr5C6vZuUVewrvJ2275pz6PHzxt6grazgbc2wbHWw9WCd3ZIcik+d4HO4/M4NJSggNfKfHZaqDWMfcVSOstzDaRXnjgmyR+Ocswtf+CDVrg6M/oPyDXiL1r73eM5QlOa6cnSKojJSclnIJ1LzCunNg2DqGe+XQCqUQRyR558dasZJVFT1i2ELAfe2dKdmD9nipENj6+ryPtYqO0XTkZ4R877nMVKUC8geORSOtdOq66vgKJVzqdrEqZ6m740VEyH7YKKKG6xiO8w5OGfTpu0uXC6Ty4biqRuc8nNUOPl2T4rJagmXAI+5TtEQRQtbmUFjCTKzYEFBa+gi3s+cj5W5UD++N/arTViMrAV4XG47vfncznET1kRUDsgf+YEFBMN126jfF6JcEzaB/+WfMc5H6BOsdxOIKYZHrgo5ZoxDVNx3yhhJZ0PK1NYGA3vK5JZUqP1L9hoJi4f/PJqhTJ2cZ+9Jlhdu7DWkwWfUBYXqqXugjmcBPAJBVkIL1p45VN1uNwFaTGWhiZr0AVKWJhoP9ZcBh4Fu+Jnm8q27yRxxH1SFKMv/o9d0vz1F3BUJwSINy3qosTMB6z19Lcss+F54FHZodnazUQAYT5sKh9uVcffTz4/YvxlZQr15Pmbj4/3hfnrsShBc2fnt5jUSDAYSa4pJQ8SxYnVh4mhYxZ6enUmkowmRzmnwAvwuXn5/GxQ1D/HLzsQpphpyhBg+CjP1QtyqGeN1P2WyW1HigtslrAhbmsydyhFyLsYmSRYIZxZSVLucFeXibcJmX/yJdch6wLE0QSaFetzWfWqfBxb10UjRqt7QOzgt2/Hq2lpvNLzL34FSTH4iYCZ9GeKFOXDOFOu3JPlxgJmdvvvruO1ZDH8IAyYwfE6Ie3kEvLHzy3ngXvEiKki2yIUPxcBtkb4JVV/vfbXRNQL9isJf0bHmhqyTQHYii3OVOZzN+lm3z9orve+woNtoiVedtvPZ5B9A X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3a430ea-115a-49ca-bf43-08dc95139dba X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.3933 (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: 2a8Dz9WC78qmiP5lJQIm730qjc+l8FeluHFG90K/nNqn5xEzVpHIglPliCUsFXcw X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_055236_391930_1B36DAFA X-CRM114-Status: GOOD ( 15.75 ) 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 Allow creating and managing arm_smmu_mater_domain's with a non-zero SSID through the arm_smmu_attach_*() family of functions. This triggers ATC invalidation for the correct SSID in PASID cases and tracks the per-attachment SSID in the struct arm_smmu_master_domain. Generalize arm_smmu_attach_remove() to be able to remove SSID's as well by ensuring the ATC for the PASID is flushed properly. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 26 ++++++++++++++------- 1 file changed, 17 insertions(+), 9 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 38d1465a44b479..f6634c37601b89 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2005,13 +2005,14 @@ arm_smmu_atc_inv_to_cmd(int ssid, unsigned long iova, size_t size, cmd->atc.size = log2_span; } -static int arm_smmu_atc_inv_master(struct arm_smmu_master *master) +static int arm_smmu_atc_inv_master(struct arm_smmu_master *master, + ioasid_t ssid) { int i; struct arm_smmu_cmdq_ent cmd; struct arm_smmu_cmdq_batch cmds; - arm_smmu_atc_inv_to_cmd(IOMMU_NO_PASID, 0, 0, &cmd); + arm_smmu_atc_inv_to_cmd(ssid, 0, 0, &cmd); cmds.num = 0; for (i = 0; i < master->num_streams; i++) { @@ -2494,7 +2495,7 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master) /* * ATC invalidation of PASID 0 causes the entire ATC to be flushed. */ - arm_smmu_atc_inv_master(master); + arm_smmu_atc_inv_master(master, IOMMU_NO_PASID); if (pci_enable_ats(pdev, stu)) dev_err(master->dev, "Failed to enable ATS (STU %zu)\n", stu); } @@ -2581,7 +2582,8 @@ to_smmu_domain_devices(struct iommu_domain *domain) } static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, - struct iommu_domain *domain) + struct iommu_domain *domain, + ioasid_t ssid) { struct arm_smmu_domain *smmu_domain = to_smmu_domain_devices(domain); struct arm_smmu_master_domain *master_domain; @@ -2591,8 +2593,7 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, return; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - master_domain = arm_smmu_find_master_domain(smmu_domain, master, - IOMMU_NO_PASID); + master_domain = arm_smmu_find_master_domain(smmu_domain, master, ssid); if (master_domain) { list_del(&master_domain->devices_elm); kfree(master_domain); @@ -2606,6 +2607,7 @@ struct arm_smmu_attach_state { /* Inputs */ struct iommu_domain *old_domain; struct arm_smmu_master *master; + ioasid_t ssid; /* Resulting state */ bool ats_enabled; }; @@ -2663,6 +2665,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, if (!master_domain) return -ENOMEM; master_domain->master = master; + master_domain->ssid = state->ssid; /* * During prepare we want the current smmu_domain and new @@ -2710,17 +2713,20 @@ static void arm_smmu_attach_commit(struct arm_smmu_attach_state *state) if (state->ats_enabled && !master->ats_enabled) { arm_smmu_enable_ats(master); - } else if (master->ats_enabled) { + } else if (state->ats_enabled && master->ats_enabled) { /* * The translation has changed, flush the ATC. At this point the * SMMU is translating for the new domain and both the old&new * domain will issue invalidations. */ - arm_smmu_atc_inv_master(master); + arm_smmu_atc_inv_master(master, state->ssid); + } else if (!state->ats_enabled && master->ats_enabled) { + /* ATS is being switched off, invalidate the entire ATC */ + arm_smmu_atc_inv_master(master, IOMMU_NO_PASID); } master->ats_enabled = state->ats_enabled; - arm_smmu_remove_master_domain(master, state->old_domain); + arm_smmu_remove_master_domain(master, state->old_domain, state->ssid); } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) @@ -2732,6 +2738,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_attach_state state = { .old_domain = iommu_get_domain_for_dev(dev), + .ssid = IOMMU_NO_PASID, }; struct arm_smmu_master *master; struct arm_smmu_cd *cdptr; @@ -2829,6 +2836,7 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, struct arm_smmu_attach_state state = { .master = master, .old_domain = iommu_get_domain_for_dev(dev), + .ssid = IOMMU_NO_PASID, }; if (arm_smmu_ssids_in_use(&master->cd_table)) From patchwork Tue Jun 25 12:37:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711071 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 A8A2BC30658 for ; Tue, 25 Jun 2024 12:38:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=+l4qD+mKFXX4MhsIh9r0N1HWTEmP80OD635uvKRa8VA=; b=Wg+HlAMNTrvGWMGMAe6O6ULAOH qswc7VnUHYuhz/iMSHw9BlN9/XK+hxA0tsx23AUSlvkz3yeHrYZfJLk2ZjZpW8O0Cs3gpSN4p+kw0 d2jCwFjZtfeuo2FCoT+iyZN0c7phNzwXlHq9msCsKnvDHZWlBYiOg1EdnD1jCn3R5yB+EWmSWrttl owqlEmY1o74Jo+sCIZelHqyreVW2OofdNXUwC3miRvd5OjOlRSE0AVBKXGNbX4ku+JeRGU3wlLXc5 mxUEsvr8HFLCSE8xSqa9YgtDnCDO602udsZQ/S89M+u7anhOBS9RzEdQeG0LDjNdfLGi/OfWeoavc gjAV+rag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5RD-00000002nxW-3KyI; Tue, 25 Jun 2024 12:38:19 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qq-00000002nfA-47n3 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:37:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iF3j/UozLAQVV4nZsJZEVeZ1VNe+243lCEDoDMDAlAmqP3qBX3HpYNWKbak4EDFhTdPaMXHBVDa0VtDB1Ff+gNTc8eatoXJR9nBkl1pZhqbW9ZUOgSIQRRv7ctmRxNzxS6fBB8iRoXeyRmhsZwb9fjb+2Xz3gfHpUErCQoRL2AJOJ/DFN7iMzzHspsGJNNr/jEry5dzmjCVBZTtOps7Y6VsBxwAdGH5I5NGIbql8MCa6pxIHTk11gnlXitI+tYzQup0OzaEyFUifk4K6o4jyh9PaIZegjH6CCAfdg6n5/Zy7eC14dpx42HCuHrOmVMYWeLUvhmP+PSVoJc7kgbEtCg== 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=+l4qD+mKFXX4MhsIh9r0N1HWTEmP80OD635uvKRa8VA=; b=D05YVysICTdTclhGiiQmcI0WwnyXszsLIjNoMSHoHA7Y7GjCMEtwiafxpoaeF5eLX4f8yVDWYJxtyqcEHVU2knj+JXCIOhhsWeP9ZYvt37PGfHDXMk5wHL/2u1744uQ7zn9iMoMNjYQXYYbqW6l8z0KFZUwQH3W+e7ESzP6fzU0yHIRob6dhYX0Ih/8gx6rd2nNeFgZFH3wm1H8g7W779iTK0qmilGopDWFixhZeX2sfalhyPYA9AieD6euFwnLHJQ/OGP+Wdw2Qw8JcPqDCR6Z1LNW6ptdKcrKcwdXTBJvzBrEWQ1X5Mhbg5u+VsFnDHzZRboFAAOjWtojSWyAA6A== 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=+l4qD+mKFXX4MhsIh9r0N1HWTEmP80OD635uvKRa8VA=; b=HtUitHIYSwq2eUr/n+iYktXzdPWaxpoYszKeP5Sjbm6KdU32lH8jZKwJty/ohNH2yhZ7r1o8UOofIFuF0l7KKTU8gpSGLlrG4eCBLXt9/MtpQPL64m5ymNo7RcF143CWiLM2EOHniXl3Epjwm3gbZAnS9ycOz1Uk1ru9Zbnc5uSKF9cC34ZVKMjx3FbFo933FSyUpKr2Yxbic+0SVZlLA9dAuuJPNWR0JkYN2vdlBr+yISu87+HklAuF4VGmALAqYC0HRu5mOjiTOxGXXQa2EAwYiGgpqMqX0120H4Ec2s8PQDXyDF8lJPc25mLdQa0XX0Rx41yJCCB6mMZWQsrzbw== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:47 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:47 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 08/14] iommu/arm-smmu-v3: Make SVA allocate a normal arm_smmu_domain Date: Tue, 25 Jun 2024 09:37:39 -0300 Message-ID: <8-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0171.namprd03.prod.outlook.com (2603:10b6:208:32f::31) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: b8c1121f-4a81-405f-c886-08dc95139dc1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: xRlVkEDqdzMedYf+mMa6WWdZEA2EMZY5VKBYCbO8bE3TqYL/b6ExTUtgN3OJZvrkdhGSQxARE0DRErBaN9RHcFfUtjGOs976hy0ozq/ntQHPKIZeA1EGA7Ce2beLVLD1JXaFTVSvr3vaYBicUPrUHKzWtI6KjljuJ2VO5Sf/eiLt07QdjP2Kere9Z3HBl22gnS3Y9POybC8fkjPNrXdJxdXdwBj6k/k1jInau2+Z2v7YpS3UQJpZ3BRx7H3MGDlTdRh5ogMWoMa/2pHJjj4Dyb4/nzlk43XYMxlA5LWdYbMrZ3qNdFe/KSA+PZFThGnrH8jog6a9IQn/ZBeGt4+rBh1YXcJKobfPpIn6I5VeyyZiloUmcNSQZ3CR3pANUzSFcFGT94a0cq+aPvYqsKhrju1gIYy00Uq2difxsZ25U1nW/mcL9nUfXLPcz1lhlDpiZJTqfR/DjXu4PvGCs8J0uCclLsDZChWKa14nIvcq/oarlX6nea4xMZ9FwnDUWpznTTSKRdeiEZNfT6SXgD8/GpY2alYf+djqtPxzTMpT/3NrHtucho6pIypGolwk0Id3wb/omd2IjNgGVIl/gV4pc7WNMO0jyzsyyranxyrDm2wncR3Dvpi/EBy21hXU94jtUIu6bfRuwu3nR6DWTnCXtEN2WXp6xCvQ/Z5gtNW0QObVVDA5ERXhbBkmTzTHJd7Tfmzp0/qHzehDxujKYJbYhCdUQicuhTnQhYqdShMxlDc9u2Y/QxrwJxV4o5kNyw8HGmAScsn8pgyzn6H3V2wSlU2rSijoNxTuTpEQt7v7vQwdxcDLujzDIONL/8zSIfQGAQaXSbGyhXTabRnlZuusnyc40SZbTYlCtIbP/2cBT3gBNigoK4LJUXO33vq9PMnUz8c8VphunzB4XPnYZ1eyuh0tSfp97CPTy4GN7QYKZDtgDVqCJ2Z1rZRuNVVoFIQ1mwbvSDKPM9wq29N6qxiDKApyo5lJFwykRFsku5D8W6zKFR5KFkdojcYOaX31iqFKaT4GH66+fYdlbI0rJacyXxZg7JrACkllzttDe849ym9eie084GtTYpVJmgdhkTku0HTXlh3JIqt8bSEcHkBr+BELPJ3bkQRWCqwist610RH6FnrKAuKk+zjdClpi0ro3WN5TGXE/B92M9ySh5GZpMoaJAVx0XVzhDgS+Yy5cBh+uxpzYFGtpKVxllXOcTJn7f8wooTrE8oUMDpSGtlT4mKeVDCJcSo/ZyHwtJ9aF6LLd5uN9753JMSCq2jJTu7AZW4nPQKZv03F51S3+JCC3YTqhlZH455oV54oAEOWGAEg= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3ZEYPZXYv2k4vJhkxG2+OBZXeIwH4e6fq11N0NQs6Rux6ZJBCtIIcLw3T0NCDWTLh1FzxQwpJVJDAHIHfY7C6C8badAckyV+ShD7gj0Rl+Uy3gdsQiT2vsuzbogbSOvEt8+ExCcnQkGV2KH1FrJWkW/rBTr2pIdtdoXSYZw1S+2BTGyvTsG4yACyiCeHGMjQUsjm8C7tMMQUpUi6IiujtfojTgCW3mGuMc5vEWMW+PAAOZLIs1Rn0LdG9VRQiTDUJNpaNj6izmq5vRXt+rDJCzGLayD8IaOmbf/jdjiGH0q0XPvKEeYuE7Nu/VjE8zARU6URqfF0F/Yi8KZRrzHTUs5bOMkyyJQI6P9ZOHKKPC/cYbSoDcO7ESoJxSBK2DQYpsrOp2PSNCkycgH8Ql7bLzpYe60eeYoZTdWKAXl37JFAy3qX89/NLKDhMOgPV5SQTC48ZA5OhfbHnnn710rqDkcGhwgUiwtRNQ9bOstSlrhP153AjjdmdTyBlhXOWQIWJc0FiNYRQiuKSads1b7vt7Neq3vOZIgYeIxu9i0r8xGHduDZ7xKKVVF4++MyW3zAvxvzyq7t1AIC9P69+z1nfPHUnQQ++3u765u1xw4EmelztJNpACgpkk8W2vz2LH7FT9TWtx+XfIoSTL0DXmPbPHsGkdaefNaZXg101DNtiJUtcOpDRR7wvAJphq2IlSfITQoVEUMsieu+sc4LlrOgmFq00bFR9sNnjgXEHuE4FhSKD+34zqbcZSzECvoeIfr/gWpoc6aNH4sqy6+UGlMmmpjUvPIw7KIGEKZhYP3agjo2JqsTc6XwF/a5Q7Ws/CYes8ER7QR0AgQuIo9IVjsgg/BNE+Lkd2LtgCuRrPPC+Av/N7UFFb2GxcdE536I7Sd7W2wOUXfL0TGmGByPMFFvlu+dYhoNe15GJWjI2/n5LCDZ5Ca+4LUkHQYi1kzXOw2Od9Ruek+1Y+A8Bz248sJ83dszpZ8ZU3xacL/6Eq9S+Fl2p+k9XjDTA2jxp9MMvFUE3dN3gUGLU5wgv9mHk9HhlhzbPiZQLOYEg78l2Cpbj0bDIZUletWb1tUXwErajs7NqgEeJPrPYbm9hWD08E8O6EwZ5Kgv6L7T6wVqCGM5zQSNsTkO1Zu+6EoykJd4NxcajmKIH4R5cWbUTdCUZBDl1iNDXXSHO1qR4IUIKLdKVtWZUcSoLE6urvDK575s+vh93vdCeR9iAivXSEpygrsBARJ4t7SrjgmgIfII+B2NMcHJ9B/nMkgxHvo2kErjW1FptiXuWssEKCysOjy9gL+WB4PJqmO+UDyhkFpMbxVZW67gHPJ/ZJOTB2Mvqom9fb7x6x3TKMpAqkLJ3CLeeyMRK/jkb42hXLQo81CXm+NkwmDH+cFQIcxEmZTsD10PfbbiyIRs57lSxBpG6Nah8if+vU1EvxIlE2/uA1PFGUCYrW8T7nKd5aKdNfKFbo+pZbWoP6N3WT2h+r/JvegMudwizAraVqCY/5+TuqTVjQamBI+wQLlJ6EOn8YZDFVtPyY8PkjsoFMcXtyAeVsOXmYR+kW+SUSdmgF+zj3E04l3IzXsamNx/GbpYS81AxqvZEOhP X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8c1121f-4a81-405f-c886-08dc95139dc1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.4248 (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: HkfgeLe71cMEtG4D4foMUx/66NA+LKjoCZ6m/CQTKlqHB1r+q2cuzmtReWjrIkO5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053757_101900_5A7B1897 X-CRM114-Status: GOOD ( 14.23 ) 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 SVA domain is a naked struct iommu_domain, allocate a struct arm_smmu_domain instead. This is necessary to be able to use the struct arm_master_domain mechanism. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 21 +++++++------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 31 +++++++++++++------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index d31caceb584984..aa033cd65adc5a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -639,7 +639,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, } arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); - ret = arm_smmu_set_pasid(master, NULL, id, &target); + ret = arm_smmu_set_pasid(master, to_smmu_domain(domain), id, &target); if (ret) { list_del(&bond->list); arm_smmu_mmu_notifier_put(bond->smmu_mn); @@ -653,7 +653,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, static void arm_smmu_sva_domain_free(struct iommu_domain *domain) { - kfree(domain); + kfree(to_smmu_domain(domain)); } static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { @@ -664,13 +664,16 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct mm_struct *mm) { - struct iommu_domain *domain; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_domain *smmu_domain; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); - if (!domain) - return ERR_PTR(-ENOMEM); - domain->type = IOMMU_DOMAIN_SVA; - domain->ops = &arm_smmu_sva_domain_ops; + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); + smmu_domain->domain.type = IOMMU_DOMAIN_SVA; + smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; + smmu_domain->smmu = smmu; - return domain; + return &smmu_domain->domain; } 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 f6634c37601b89..dc1d53ce2b40fb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2272,6 +2272,22 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } +struct arm_smmu_domain *arm_smmu_domain_alloc(void) +{ + struct arm_smmu_domain *smmu_domain; + + smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); + if (!smmu_domain) + return ERR_PTR(-ENOMEM); + + mutex_init(&smmu_domain->init_mutex); + INIT_LIST_HEAD(&smmu_domain->devices); + spin_lock_init(&smmu_domain->devices_lock); + INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + + return smmu_domain; +} + static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) { struct arm_smmu_domain *smmu_domain; @@ -2281,14 +2297,9 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) * We can't really do anything meaningful until we've added a * master. */ - smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); - if (!smmu_domain) - return ERR_PTR(-ENOMEM); - - mutex_init(&smmu_domain->init_mutex); - INIT_LIST_HEAD(&smmu_domain->devices); - spin_lock_init(&smmu_domain->devices_lock); - INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); if (dev) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); @@ -2303,7 +2314,7 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) return &smmu_domain->domain; } -static void arm_smmu_domain_free(struct iommu_domain *domain) +static void arm_smmu_domain_free_paging(struct iommu_domain *domain) { struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_device *smmu = smmu_domain->smmu; @@ -3305,7 +3316,7 @@ static struct iommu_ops arm_smmu_ops = { .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, .enable_nesting = arm_smmu_enable_nesting, - .free = arm_smmu_domain_free, + .free = arm_smmu_domain_free_paging, } }; 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 65b75dbfd15914..212c18c70fa03e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -790,6 +790,8 @@ static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) extern struct xarray arm_smmu_asid_xa; extern struct mutex arm_smmu_asid_lock; +struct arm_smmu_domain *arm_smmu_domain_alloc(void); + void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid); struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid); From patchwork Tue Jun 25 12:37:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711096 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 6C194C2BBCA for ; Tue, 25 Jun 2024 12:54:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=1i++RQCQL5qxV7vyGBJbGGXKxmuLTHlROMHhcJi/+gk=; b=nJEm7i2IbhFyPdbYSnJ/RtTWP/ DTh+TWur/akQ3VvPSgoWey9dPQxyYMTP/j0Rp/7DfUPZIESTjtywsHpttWIVOPLK3EJ8YJ5339gVR x5XWSbqGn0K3wqNJDLpNMCtDeH2D904m1OjDxpT6Vk6hJT7gDBfWeZGlgq1tSicrFtQwQCOehbY0s jJglVF4kO+zNVFKRDmasLiQK6AGe63MNK5CworGUZy8nkgEhLykqUbRINrBAOuqvFhn+f37Pex8JU P26hmwOwPo3X4aQZvA7HgdYny5AWSIxG2Um5vwOQIcLNXk0DhJxqLRXaEugU91E0d3AFG7Fa7hoZS Kanb2XZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5gI-00000002rUp-10Wh; Tue, 25 Jun 2024 12:53:54 +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 1sM5gC-00000002rTx-3ec8 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:53:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kedrYKLc98xunUYZCAgAQJb301j1WtQk9Pnus1TBzvj6iiUBmwG+/sdyoNAuEf/pikmahUfb31iEq1pqyTJ78cNsKWR/ygarYiQJ4rLlDPmMBdNugxSDcoJDC1yOumR4P/s9DUstONw7GHnfMI8iZXVrZ0nRTBcZrT9882T4utzUWaED3k8Acojnq/6u38vdztCDcjjrIb/uVppXsRs9u4Eu47BSNpAIM/owTl+VBJl6RRPBnTYrsFbR9O0y8YS7ytjUqxuNPIUipniLT3D+nbuTgemeGyRGsQvCtqQYllfbT56JqLEE+OBkrpTDTd1C4nL9RBbRZe85n2CO7ngR7g== 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=1i++RQCQL5qxV7vyGBJbGGXKxmuLTHlROMHhcJi/+gk=; b=jZPhGigW6yKKZaJ6SdJyp9crktCKEjC2uBDXXDD2C3KqAq/xqAsC2msIx0vIEDf/TlfQOwxGEZRPN5GxSUXdbzLLybBNJRAqmVPcKYMFtksQjNSCxIRA7EQVB/eBNesNaycUzHxgVrfBKx76O0OTSOpzEr9PKYXegSTNl/EWzm/LnKKucMUz8c2i77pvDcBMfKGmfWOrM1nSlN722sfbrgMhFeug6DHkbvTvBGKoa5EUr1pnrKiYhyzTD0MtLAhYtu4JmMX81eVu/GkPtjq8MRouMoR2hnRGbepd34v8HS2UhcPOqT+OdSbJJcRAx1WPPsFWQGWjpj+666OecGhVig== 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=1i++RQCQL5qxV7vyGBJbGGXKxmuLTHlROMHhcJi/+gk=; b=tMknIM6gw7enQP+JYGMMYhSGp5hW8/eC3UE1ZsUxWI/HSMy5ZeZhrjRYi8E5iuFnHqTs5u0FTHBdCAA2BPQq58XwllmtfMc2CPce899D5OjkdAoJuSns65BH9a7xtwxF592H2cGRipuiQrZiaj91arCpfeyRLbvVwB9hySFSzxOyaZXp4ZKfV0Oxy/hJgOJ4lIKdcsHaWDsLc2UolHr+jewQj1+U3QEnkqqxCgxF50dhWGYZCIxoTh8GAPxX8KK5YtC78iuOQHKrWo0lTfxp79umlfOe1Nn1CdUkoI30/OiIwQCNNmejpLzqwiK8w3qxr7xHFwRuXQSoN99CY3VjwQ== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:48 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:48 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 09/14] iommu/arm-smmu-v3: Keep track of arm_smmu_master_domain for SVA Date: Tue, 25 Jun 2024 09:37:40 -0300 Message-ID: <9-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0008.namprd13.prod.outlook.com (2603:10b6:208:160::21) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e6b3a05-8b9c-4791-c112-08dc95139dbf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: Yt8oSQO4ozpoGYwcXNpGFk/v8SfXQJdsimVKH1zuIuCg0pjnoBtKYZFytgwYDWZvpCTFezEZf/1RaWhHTSqkS6ZuUVgc9ZU3L1+IoaOStJtLQL/imjMwFM3kce65aa4kOf2FFOn5/iH7MKRHvNbvC1sDZ83hN3Rb+7ndpsddCuHuwrLThRyAf5s7BEXsi3SG0FdIJhGbTE6rz9w2uMD5/+XFFkgpMtk8WlATqryDFQs4sY4XD6UEAW1oEX0uzo+q+WNKn0P+XhEisaEZSyYozeo41v1qU9f1CgyY6PXcOzciYUDI1nXoFHzl/dQUTjHCzwnlqm3MI37SwJsS5mblXc+j3LlDCWJWtrxE6u4Ayfai3+3KyG9yl6AKx9orZwZ7vtkwWIzwfNUTnkfoDN6zSfue/TcbsXNa6OSrUG/mkXR2TlR0Go6/20aLBRqneJ3oIYoJrukImCKHumicoORc8xdcIKZqbdnJsDTKS3YUowG3QohiReyCLVGBkZ36+FN4j2O0RiCBW4qygodBo4gCQ9lvLgZ8Gb5tnSUVwNLcKmSk+4BOcg5l5eI7Ar7n4NNZgpkOwPMybMJ6IuKY0DjO/rtDVfOpk1zsP050qvXi1bOoA4kbnPq0ataMfC6iOCCPwJ2pqknQgHwuq7/AfELLr4XmrjByVTOwgKg5K2LQxu6tnqzNsxOXfFdTLORh3EaQ4mb+lSN9BbhkWud7+dlCSyJIPHCoTI54B0nwwDWdSRGpnpmHgave2Sv5qssnDuEqENeYd+0wjChdWIwajfm5Q8qNRIy7syU2TPNApI1NznHaYS4it/nU8r/yOpIbFAqq70DlV2nyQaqvTodN+DQGif9SnMUYsEzAH5GWi+CAIg/vtK2mPYc8X5kl8Se2uAYx7XvxWyto2yNAkU3TdJwBqIv9ZNyUo0XzADUZaSRnv3S4/MNbfM/GaCNvv+Lj1Yhw3Q26y7V5lcM/DH+D6UNnvtQNVcme2djNh/R3KEUMhdeP8+yfX6+rHB27ErRf/+YpVStcHs/pxsFtgBnuYHLJRcO39Z3L8vUZSLiqNIr5UhRJipGMcp8DXbgqNHaaP8KX4zXPhsX5q5OL3yQr4GZTPVITPsIzJBf+DN9rzc8q7b1TuG0Xhev2X/mqMI3Gb0H3z4KrAkp9UF6CCacq4yyAXQmPamuFwLiRtM/TJBA0FTuStjXi91q9pyRCNLN0EroNVIznU7eM2s1Oy26kKzYY1gwigi2SeUR4Ok7OLta0WgMwEsVRYTC8KFgcKvx4CKbEZPEbSgn35oCdFz6vO8XM8dzWPn2fRF0RgSSrBYKp68o= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z89r19csGpd8eW8bYXRo5895h5PZNnWhExuhJRwcIVFKIR8k4ON1v7/1rbfAoGDNhzAf4kftlZPw1AdKg6k54AdF4NLZL+Etfo37ZMVWZjWhee+TjiMnNJ8wrX/ajUurS4+fSq8ZeN3mQmh/6zMBz76qiyKI3ksny/RC9xqMBR3g09JxSl3szl3reDKUasVMhCHI8NXq4TlqZPAd7DpasuSGESno1pzihdDnohY8GpdpjmkqZ95mWSHn0FSKbmXd/ivg6W+WCnUGyM6gnSL4qoFKtUrdBxIr56c+oY9jH/cQTI4mtO2JHQx+AxgQ1OVOEoSLwhY7Fu6VGquqAE40cUPEE78h4yp5hDM6PNrR7ckfkoLA6C8O9XbqAC2g7VNzgD/qVyPt/o3WYPb9sgdPlsVmJ1sOhlwBjfnsY8N//qc70r092DxcjGJyOT0wuGR/c7akhLA6t/sV5LCO8ArgbGm8f+ogRbrky42RQUF/N02EF6dB8Zghqhk0GNAw2iPpIVp1mP3DQaqc8CCrl3QVYYpPh5Ir/hPWX/njSfmQ70gJ2bthpyAr/Sx1wqwSsEkmGrGT+vZfeQCZYE0zhBxDdVzDKHt+eOwxG7mstsnEx/yswbRV+6EwgL07SPuwOKW9GGJqI4H+uuxbll0vYLz7oGKc3ueF3IC71a/bktTJ0gvSn2xIMFWni/trG4zWv99BWFxlye9VrRtYZ8v6byEGvql1JPGiN9iW2Quor1Gj9q3PfDm9nbEs6TdVeWm2Cete/fXTLEv+FT58e+cdRQsuZ1L1mNUcb+dsxW/3Ya0QY2as2c2NJTlY6f1AD1r74HwDoX0QpmOyWWcULqA3GkzgihkzVJ4N6howYwSzTy8PKV73YcdcmJADgviX2ILOIwb9Jx4VAVfX7fIPSk4wwiZjRh99so9knZYDK5Z5F21H5Sa0sqfxladWCmNGam70I3cRwvq7wxnS1wu9qo+zOYHW4FBojIi1uHqxqrkjXhUTzBYQ0VNfhmnOTqgmevjh5QiL0vcZjEbm2rhQpgY9oZouVPI+uI4KpvFpps31V4VOKMmtwAg/bYOgHGjQRuQ9x4LokDWk3NWrDlOZ1Pn+IvsIvndc6zOfAf+VPF5OkmmnAEoxu/On9dbFkmL8VFLI4qbiDKTIhX9ZJFClwAM+FhSH4RMgSxnZupVATqp5wtZBvC+b9hRNgE1RVF9psL5+xsHv6NHwEvvmBbHylRLmlCgmLSSz9qGV5p1vet//f79vLaAQJrDN6/pZjeZg4vSsI3nu6rcdTJFBgKCcSKnXBBpr1kBHvc6FYhOVrKIC0YRr/OpeODGaNBzHH8yWptD4QbKnjCXxtHn0W/1J0BihDiF4fKPYK8c5DKm+0jMQTcVM8B9C2OVQxRUaSC59iX06Jlviqxzoprhnm+ozccAWMRxFnSy3+68piHspJLibmM+KNPYdWh5tUHWfLA9m9vFW7fSl92Tb8mL2C/W5hZp25f2yWEmK07Lm6/3PEleJSB5oxbs37dixrguvFJEpAkIBg7nDcHZl6lpWMbLK+5aSgFE+D/B8tMK0nJvI7/bu0/2eWn9gHog/cWeAUMBu6gBxNlPy X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e6b3a05-8b9c-4791-c112-08dc95139dbf X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.4663 (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: i9Re99zyu1IIvzu/Cb1wNNIlrND4n25neus4OVS84a9ZD0CpVtGGCZsFXrtgL9Nc X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_055349_026668_DC08785B X-CRM114-Status: GOOD ( 14.68 ) 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 Fill in the smmu_domain->devices list in the new struct arm_smmu_domain that SVA allocates. Keep track of every SSID and master that is using the domain reusing the logic for the RID attach. This is the first step to making the SVA invalidation follow the same design as S1/S2 invalidation. At present nothing will read this list. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 30 +++++++++++++++++++-- 1 file changed, 28 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 dc1d53ce2b40fb..527560b36b3993 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2587,7 +2587,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; } @@ -2820,7 +2821,16 @@ 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 arm_smmu_attach_state state = { + .master = master, + /* + * For now the core code prevents calling this when a domain is + * already attached, no need to set old_domain. + */ + .ssid = pasid, + }; struct arm_smmu_cd *cdptr; + int ret; /* The core code validates pasid */ @@ -2830,14 +2840,30 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, cdptr = arm_smmu_alloc_cd_ptr(master, pasid); if (!cdptr) return -ENOMEM; + + mutex_lock(&arm_smmu_asid_lock); + ret = arm_smmu_attach_prepare(&state, &smmu_domain->domain); + if (ret) + goto out_unlock; + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); - return 0; + + arm_smmu_attach_commit(&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, From patchwork Tue Jun 25 12:37:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711077 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 4904FC2BBCA for ; Tue, 25 Jun 2024 12:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=xAjflk7emW4D2Zs/4PQo41aWLZyg3vDkN8uWjeOGRYo=; b=sGJgH8eI3ein3l+eys8Pezk4Un NzmH1HuRzRufMBhynDh8IfFvtPK0KmlGYUF5j+MHlFRRZ8LmLLsTZ+jsYZpl/JD6e+YHnyiOtV5hX 3s5ac8gH64f0gAXyKo16u/NifDKAK3/cxBfcF3XkKJifZash/pTrYWoIeLrJkVdojtvih/lMUGn4n NrxcSpVBfDuxFFWXr6cXFMPIfwFQDXRwR4WmnirPlYzOBI3G1j+JY++XKVy3gmFZSiupKLkR2GXJQ y9NErGNOZcbik9zkurCmkF7EMvSPWebRZwQhgowI4QSI8hPQKbuE82bbC3ZTKrsdbbXzAt0ihSyUe H2jTmWag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Rd-00000002oCI-3zUQ; Tue, 25 Jun 2024 12:38:45 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qx-00000002nk8-2x64 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JhqsO1w8ZWgCG8tkWEHtypO1vZwNuimAlgMMwCUXzSojG9d8VT7OCpcZXtcWX/Pry8ddH0iBQaFN4+QTiJF3LFr4LBNQHd7v84fWpcFMgOkMPA3VYC8EdvzY6JlZ+Wx7bFqWPGfkvUo60VM6f1R2+NFphny3HYxyvIHXEMYY/47Yi9RhN9qRB0bo+ssDEASanyOlOyCTDQJEYIIrci6nQdi+Wvx3u2VqyxHUGC/GsCVRVvZaf6U9S1tuhbaqX/E1F0CXxYalEUG72ORpNHRZBz6rI71HEyGssqavOvhcZ9/mGCh71NZeYge9XD0pwIRCAWaRnX2FdclNsbAugJvZcA== 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=xAjflk7emW4D2Zs/4PQo41aWLZyg3vDkN8uWjeOGRYo=; b=TEW+7VKZAkpf+uIGU5jfneWgit/A6/8x6eDQ+BhFDrh9lfz26xJisUw7E2yLHFBmTBe8WnCHv40LMDdn8+vJNOVjySIGnjTmHdgQBTY7P0rNRnpQK12V+ORXQMdSpUfu/++XjeZD8Vj2zYlJozFKix1viIbydRPQzkn7nAPnnIppmLlUdL7pS3dZfgEwZqPueXhs0oYmFxwQJOMCctTIDTYbCu0/U8oppdqNWf5mg1gDChmzwcsp+F698G2D9LDiNqzSkRu6wx0Xg1oXOErcwPjuuFjedz3LlPBQ1yQVCXIAcQzdNB5ZJTqaDLoqx2p402WWLgU9zBZlVaYijv1Ylg== 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=xAjflk7emW4D2Zs/4PQo41aWLZyg3vDkN8uWjeOGRYo=; b=bKd7V+F3LNywXJsBgQFeQ8PNgX+7DvsydJ/3KUPoBzi0YhR9AD+BRMLxvFGhjus/7SnqOjx2fu1or/g1fkjOFXgfrdteKZfn7JdwMExGgTktlS+RVYXplshGfquki65xtsstuM9pzsoYv+JBC4IEx+Lxs3TjRI1gJ4ZP7EVKa8DOXtNEMgOcZToUHXpK3EWC1mNZO22iJW9wjM0GfyiPXEVGNZsY6TNAdw+voajj0et9nuepHyTLbdVL1OMhvLUjMUH03STGBa7+yiRYQAN0nu/h3PSjRGbID1PrZIen5wjEbRLF+xdq6PGJ/vhT/AbisopuUXvr2pKJ2QrUBz316g== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:50 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:49 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 10/14] iommu/arm-smmu-v3: Put the SVA mmu notifier in the smmu_domain Date: Tue, 25 Jun 2024 09:37:41 -0300 Message-ID: <10-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0001.namprd13.prod.outlook.com (2603:10b6:208:160::14) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: 5559c07a-a011-47fd-f4ce-08dc95139e4f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: pPVCrhyip2Uh26VEyvnFtDUoUlkMAn605azhwDPx/QLeFK4bf9AE7QUtQ9mRGPUN0c4xDls2qhzj/ElCFfiHBdw57QEDZqaJNYPFxevuPAGBkB+hxdPvyJdxVNNfaFN9vYgPDBvxqG3bry9cwHYiEdN0ZlZ9QGo8xEvqbKMWAfz0PsT4OkwjP9ocQ52yptpOkcjGIzvKjAlrl1J8gNFTFlEfuRppHsWXQXuYggKxnPvx/R8Mb19bjI00xI6M1qRIHt2rM1NmR5GerTKbECXCP4g/vUHZoRRxB6SUYjcRLleka3du2Zrwi7JSiYgPBvCRA3xmuSnkOk1NtKxN1cVcupsXSaAApxXx5ExV3MRYqmPpZ9afoPjOvcIry9yzB++WG3wWUp5B691AZFlhNjndijW4B82LuS7iWrOcAmBfR+wB4ZvpQzIy1rN4Qf/hXRRcgqKQQnttbg2wHGZAiB3rvA8O/DGdgeyk+R+BfVbQjsKQDGmhRFDnvje5aWmbx8KllPFy8ACvAQA9MVgUrjKMjXrwIK0d6Wb48Dq2tPmqS+ueTvvT2bA1Gj7+IojEOsC4HdIpfEXH1ZIaBfRWTlXDnV+pLUODBjz4PVThpGr+Rb/XQ8wxe8zrRM5NU0UuJPP5wKHifJn3HkdeisZQGcFl2UjaVWXapUOseqoeFVRUDtJnS83UGqoHcinbneGXdeKYbNFzjCFLXIQkcyJJkWX90rn7e/I5in8j3IMgHkxTU9GkSRritdXvPQzdvJ/tDlwBkFtdWygS2WT/8FOtx66mUdm5OZMlA/xpwNDiZ9i7jGAAtyUkApom1B3cVYsrYJ2jyVkDT3GzZVmB+ybGHZ9CzxqY3H1L/t40A/lZLWC9aYVdlxRqjyd5d/M8OFZf42mNjkaCfMScnHls5dnF0aaEuSgmLxkZEhMpxfrAehwUE3/wPDKLf8mi5uWTDloKVOkzA+WA3vKf5KM8pjw5n48CexXALUixXpW36Uwiak1mV5lu0GajzBT2ECAGS8xRx7ZY8uE/EzS11KQqbI4vZnBoycjfNKzI6F5eQAdHPpr9sLQT/X4X8Vp5Da/QifCHXRZjkNKqobRyla40AItDw+r3WGf+NRrGt+7s3NLF+IT/FeTcjTKNh2a6sB8wb6ItIJwrUWZZqRYj4jP9uldMK3Y617iS1WqApG9iwL1VEzVhPLixbJXEhyUErRabdw5vcii2KBBaaxASsjmlKhJ2eMtxMZRkObozpeBX93cU/eskIJTsPpibPzRxeiNg9PUrD2Ufw6NryFfumJny987oK6LOZ/ndy76EHsOXxqfc1n911A5HjAsKGLj5fFkQDNUzJNm+ 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: agpDSL0Y6a3LCg0bfQ1j62oqvcJOBIowChIwjWIJ+XnaGTsZ2kT9Y0R2Iu68KFR1B9sUAV8vSOBj3T9D3nu4LE91mvF6bbjdsNQEl4JTS4XCq/RTbnqrCb2rFXxeZ7IcassEXUtHbg0l8wHO7207cO7xskKofpFJjI6dR9vFSqTVW07i2ipLuj7h6ESstSB/VxQlIKBnm9+Nv+ttRH2lgZ0dY8Ft03N+gQyf7tQu9irZE3/7kwYT8pshceJMsW/nNERMtvW2jAQUUUtq9RTsuacOlgnGJUM2K1OKvHeiVwHcrS3M+U57GM7KK3zTfTydbA9gPZ+cSmtGV/2jbccmByFkk34HD5S3XLYbZfy/Ugm/q6NbDlsCx/7hs8ZFH17Wh/cc/KbkpCyRw9IbvF6ElxC3/SMSPCrd7H8rUCWe7TTHsk8211JYX/6hQh9+4lTi62475qL26gQ1vrQwEtFzFUdSmmgMjCqFJHAL2R+KBxBRUnINn6mwft6P6Cl3v4/b/6fB7M2ReEGUEiSJdforYWiRZkQujFAevtSjUR6NYBD/ZsEu4Q78HPLpfWKlfdVuarZTRZuVgZ7OuTBwta5/CrftpdJJ5gt9XfhzCVe2XkPOffl1LYw+y28nk/IlF7Mjpm8ZXoHhzGsYSsenedg0eqi/2YwBFr2vz3uEQGnaVRUIbiIeNPloT9iHX506NrCmsszopQjjDFi1eyDtO+lecebu7IQukVv2i/gf6UZd/CuiaouhQfY30+22xNuy8qQBzBMGjQ11oQILo5jOotBkAwqCaKZKluq1cCYJd9AYRXSHLP4gxvqWd5OZTYwXczIdu+YroC3qgfogLkvOy52GH8Puef0vsY58PZGsrg1iktPcvl0AbhhUANFJgiQePvm+PSeMS/8pc9q0WYU5b2pahy5zf8ljnpnNVJ/gSUHxBEc9WzSQUSIOcUMogllLqxX0MGqtcz95sW7fjm35f+R3CrmklN/ADtZ18Ou3LJzkXmkcSrxJrNkzt+WOAkjcumb8qghq4f2ogMkAnWHpgR2Rv2glSh+y1OiwctXhIvuBBAz/uX0sGL56jWWx7eF33tQHu2EMCnk+eeiGNiVYYG1jTmHQBpkCTihwFnZPwMs4eK6KtH/5TAbKAVjnsURlmaD8tWCe10sqdNn8frOlRb8Jyrtg5q+JrKEPukqfrgN6oNNFRq/+pt1CXxxCZyu9ILaX6WjRaWvVwG0QDOfub09fM/U/ot9iV4jORCVdniRtfCW8VoukUDnt1cRohtJLedAPCbU5elmfo4zgbeN/9WrCOoF9TALaG+rKC40KHNB/JS9c3L5d1mZPEPpWDrd2cQogFg9vDKo/0ChkSFllgR+tn2oxKDUu8hKxahPVZAF2/W0fZF32Wv/9GGKIRnzkmW+MrZEwzNxrSomFmkId0WK1g46k1K0mNV2UrChB0H7mI40zHGECzyXEM9Hpy5/Df+zHMe07LULqx63qQrswnSj+9dI0apW6ykUWbJqgD9OVKGa/j2mEMdeWVVI5cJnWoobmu8lVobRxHx/Oum8PXZ9bgAZBCJQOp1ODvmTw9DursdPv4RQPFqLVTcDazLjLGUSo X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5559c07a-a011-47fd-f4ce-08dc95139e4f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:47.4743 (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: lTpsjSk5GCdz/HnHLyfGBWZehfwwvEzfmLF2WFtNIx48/MOdKIlsOin+GxakbJqC X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053804_066216_F2EFB304 X-CRM114-Status: GOOD ( 21.70 ) 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 This removes all the notifier de-duplication logic in the driver and relies on the core code to de-duplicate and allocate only one SVA domain per mm per smmu instance. This naturally gives a 1:1 relationship between SVA domain and mmu notifier. It is a significant simplication of the flow, as we end up with a single struct arm_smmu_domain for each MM and the invalidation can then be shifted to properly use the masters list like S1/S2 do. Remove all of the previous mmu_notifier, bond, shared cd, and cd refcount logic entirely. The logic here is tightly wound together with the unusued BTM support. Since the BTM logic requires holding all the iommu_domains in a global ASID xarray it conflicts with the design to have a single SVA domain per PASID, as multiple SMMU instances will need to have different domains. Following patches resolve this by making the ASID xarray per-instance instead of global. However, converting the BTM code over to this methodology requires many changes. Thus, since ARM_SMMU_FEAT_BTM is never enabled, remove the parts of the BTM support for ASID sharing that interact with SVA as well. A followup series is already working on fully enabling the BTM support, that requires iommufd's VIOMMU feature to bring in the KVM's VMID as well. It will come with an already written patch to bring back the ASID sharing using a per-instance ASID xarray. https://lore.kernel.org/linux-iommu/20240208151837.35068-1-shameerali.kolothum.thodi@huawei.com/ https://lore.kernel.org/linux-iommu/26-v6-228e7adf25eb+4155-smmuv3_newapi_p2_jgg@nvidia.com/ Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Michael Shavit Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 395 +++--------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 69 +-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 15 +- 3 files changed, 86 insertions(+), 393 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index aa033cd65adc5a..a7c36654dee5a5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -13,29 +13,9 @@ #include "arm-smmu-v3.h" #include "../../io-pgtable-arm.h" -struct arm_smmu_mmu_notifier { - struct mmu_notifier mn; - struct arm_smmu_ctx_desc *cd; - bool cleared; - refcount_t refs; - struct list_head list; - struct arm_smmu_domain *domain; -}; - -#define mn_to_smmu(mn) container_of(mn, struct arm_smmu_mmu_notifier, mn) - -struct arm_smmu_bond { - struct mm_struct *mm; - struct arm_smmu_mmu_notifier *smmu_mn; - struct list_head list; -}; - -#define sva_to_bond(handle) \ - container_of(handle, struct arm_smmu_bond, sva) - static DEFINE_MUTEX(sva_lock); -static void +static void __maybe_unused arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) { struct arm_smmu_master_domain *master_domain; @@ -58,58 +38,6 @@ arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); } -/* - * Check if the CPU ASID is available on the SMMU side. If a private context - * descriptor is using it, try to replace it. - */ -static struct arm_smmu_ctx_desc * -arm_smmu_share_asid(struct mm_struct *mm, u16 asid) -{ - int ret; - u32 new_asid; - struct arm_smmu_ctx_desc *cd; - struct arm_smmu_device *smmu; - struct arm_smmu_domain *smmu_domain; - - cd = xa_load(&arm_smmu_asid_xa, asid); - if (!cd) - return NULL; - - if (cd->mm) { - if (WARN_ON(cd->mm != mm)) - return ERR_PTR(-EINVAL); - /* All devices bound to this mm use the same cd struct. */ - refcount_inc(&cd->refs); - return cd; - } - - smmu_domain = container_of(cd, struct arm_smmu_domain, cd); - smmu = smmu_domain->smmu; - - ret = xa_alloc(&arm_smmu_asid_xa, &new_asid, cd, - XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL); - if (ret) - return ERR_PTR(-ENOSPC); - /* - * Race with unmap: TLB invalidations will start targeting the new ASID, - * which isn't assigned yet. We'll do an invalidate-all on the old ASID - * later, so it doesn't matter. - */ - cd->asid = new_asid; - /* - * Update ASID and invalidate CD in all associated masters. There will - * be some overlap between use of both ASIDs, until we invalidate the - * TLB. - */ - arm_smmu_update_s1_domain_cd_entry(smmu_domain); - - /* Invalidate TLB entries previously associated with that context */ - arm_smmu_tlb_inv_asid(smmu, asid); - - xa_erase(&arm_smmu_asid_xa, asid); - return NULL; -} - static u64 page_size_to_cd(void) { static_assert(PAGE_SIZE == SZ_4K || PAGE_SIZE == SZ_16K || @@ -187,69 +115,6 @@ void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, } EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_sva_cd); -static struct arm_smmu_ctx_desc *arm_smmu_alloc_shared_cd(struct mm_struct *mm) -{ - u16 asid; - int err = 0; - struct arm_smmu_ctx_desc *cd; - struct arm_smmu_ctx_desc *ret = NULL; - - /* Don't free the mm until we release the ASID */ - mmgrab(mm); - - asid = arm64_mm_context_get(mm); - if (!asid) { - err = -ESRCH; - goto out_drop_mm; - } - - cd = kzalloc(sizeof(*cd), GFP_KERNEL); - if (!cd) { - err = -ENOMEM; - goto out_put_context; - } - - refcount_set(&cd->refs, 1); - - mutex_lock(&arm_smmu_asid_lock); - ret = arm_smmu_share_asid(mm, asid); - if (ret) { - mutex_unlock(&arm_smmu_asid_lock); - goto out_free_cd; - } - - err = xa_insert(&arm_smmu_asid_xa, asid, cd, GFP_KERNEL); - mutex_unlock(&arm_smmu_asid_lock); - - if (err) - goto out_free_asid; - - cd->asid = asid; - cd->mm = mm; - - return cd; - -out_free_asid: - arm_smmu_free_asid(cd); -out_free_cd: - kfree(cd); -out_put_context: - arm64_mm_context_put(mm); -out_drop_mm: - mmdrop(mm); - return err < 0 ? ERR_PTR(err) : ret; -} - -static void arm_smmu_free_shared_cd(struct arm_smmu_ctx_desc *cd) -{ - if (arm_smmu_free_asid(cd)) { - /* Unpin ASID */ - arm64_mm_context_put(cd->mm); - mmdrop(cd->mm); - kfree(cd); - } -} - /* * Cloned from the MAX_TLBI_OPS in arch/arm64/include/asm/tlbflush.h, this * is used as a threshold to replace per-page TLBI commands to issue in the @@ -264,8 +129,8 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, unsigned long start, unsigned long end) { - struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); - struct arm_smmu_domain *smmu_domain = smmu_mn->domain; + struct arm_smmu_domain *smmu_domain = + container_of(mn, struct arm_smmu_domain, mmu_notifier); size_t size; /* @@ -282,34 +147,22 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, size = 0; } - if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) { - if (!size) - arm_smmu_tlb_inv_asid(smmu_domain->smmu, - smmu_mn->cd->asid); - else - arm_smmu_tlb_inv_range_asid(start, size, - smmu_mn->cd->asid, - PAGE_SIZE, false, - smmu_domain); - } + if (!size) + arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_domain->cd.asid); + else + arm_smmu_tlb_inv_range_asid(start, size, smmu_domain->cd.asid, + PAGE_SIZE, false, smmu_domain); - arm_smmu_atc_inv_domain_sva(smmu_domain, mm_get_enqcmd_pasid(mm), start, - size); + arm_smmu_atc_inv_domain(smmu_domain, start, size); } static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) { - struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); - struct arm_smmu_domain *smmu_domain = smmu_mn->domain; + struct arm_smmu_domain *smmu_domain = + container_of(mn, struct arm_smmu_domain, mmu_notifier); struct arm_smmu_master_domain *master_domain; unsigned long flags; - mutex_lock(&sva_lock); - if (smmu_mn->cleared) { - mutex_unlock(&sva_lock); - return; - } - /* * DMA may still be running. Keep the cd valid to avoid C_BAD_CD events, * but disable translation. @@ -321,25 +174,23 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) struct arm_smmu_cd target; struct arm_smmu_cd *cdptr; - cdptr = arm_smmu_get_cd_ptr(master, mm_get_enqcmd_pasid(mm)); + cdptr = arm_smmu_get_cd_ptr(master, master_domain->ssid); if (WARN_ON(!cdptr)) continue; - arm_smmu_make_sva_cd(&target, master, NULL, smmu_mn->cd->asid); - arm_smmu_write_cd_entry(master, mm_get_enqcmd_pasid(mm), cdptr, + arm_smmu_make_sva_cd(&target, master, NULL, + smmu_domain->cd.asid); + arm_smmu_write_cd_entry(master, master_domain->ssid, cdptr, &target); } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid); - arm_smmu_atc_inv_domain_sva(smmu_domain, mm_get_enqcmd_pasid(mm), 0, 0); - - smmu_mn->cleared = true; - mutex_unlock(&sva_lock); + arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_domain->cd.asid); + arm_smmu_atc_inv_domain(smmu_domain, 0, 0); } static void arm_smmu_mmu_notifier_free(struct mmu_notifier *mn) { - kfree(mn_to_smmu(mn)); + kfree(container_of(mn, struct arm_smmu_domain, mmu_notifier)); } static const struct mmu_notifier_ops arm_smmu_mmu_notifier_ops = { @@ -348,115 +199,6 @@ static const struct mmu_notifier_ops arm_smmu_mmu_notifier_ops = { .free_notifier = arm_smmu_mmu_notifier_free, }; -/* Allocate or get existing MMU notifier for this {domain, mm} pair */ -static struct arm_smmu_mmu_notifier * -arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain, - struct mm_struct *mm) -{ - int ret; - struct arm_smmu_ctx_desc *cd; - struct arm_smmu_mmu_notifier *smmu_mn; - - list_for_each_entry(smmu_mn, &smmu_domain->mmu_notifiers, list) { - if (smmu_mn->mn.mm == mm) { - refcount_inc(&smmu_mn->refs); - return smmu_mn; - } - } - - cd = arm_smmu_alloc_shared_cd(mm); - if (IS_ERR(cd)) - return ERR_CAST(cd); - - smmu_mn = kzalloc(sizeof(*smmu_mn), GFP_KERNEL); - if (!smmu_mn) { - ret = -ENOMEM; - goto err_free_cd; - } - - refcount_set(&smmu_mn->refs, 1); - smmu_mn->cd = cd; - smmu_mn->domain = smmu_domain; - smmu_mn->mn.ops = &arm_smmu_mmu_notifier_ops; - - ret = mmu_notifier_register(&smmu_mn->mn, mm); - if (ret) { - kfree(smmu_mn); - goto err_free_cd; - } - - list_add(&smmu_mn->list, &smmu_domain->mmu_notifiers); - return smmu_mn; - -err_free_cd: - arm_smmu_free_shared_cd(cd); - return ERR_PTR(ret); -} - -static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) -{ - struct mm_struct *mm = smmu_mn->mn.mm; - struct arm_smmu_ctx_desc *cd = smmu_mn->cd; - struct arm_smmu_domain *smmu_domain = smmu_mn->domain; - - if (!refcount_dec_and_test(&smmu_mn->refs)) - return; - - list_del(&smmu_mn->list); - - /* - * If we went through clear(), we've already invalidated, and no - * new TLB entry can have been formed. - */ - if (!smmu_mn->cleared) { - arm_smmu_tlb_inv_asid(smmu_domain->smmu, cd->asid); - arm_smmu_atc_inv_domain_sva(smmu_domain, - mm_get_enqcmd_pasid(mm), 0, 0); - } - - /* Frees smmu_mn */ - mmu_notifier_put(&smmu_mn->mn); - arm_smmu_free_shared_cd(cd); -} - -static struct arm_smmu_bond *__arm_smmu_sva_bind(struct device *dev, - struct mm_struct *mm) -{ - int ret; - struct arm_smmu_bond *bond; - struct arm_smmu_master *master = dev_iommu_priv_get(dev); - struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct arm_smmu_domain *smmu_domain; - - if (!(domain->type & __IOMMU_DOMAIN_PAGING)) - return ERR_PTR(-ENODEV); - smmu_domain = to_smmu_domain(domain); - if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) - return ERR_PTR(-ENODEV); - - if (!master || !master->sva_enabled) - return ERR_PTR(-ENODEV); - - bond = kzalloc(sizeof(*bond), GFP_KERNEL); - if (!bond) - return ERR_PTR(-ENOMEM); - - bond->mm = mm; - - bond->smmu_mn = arm_smmu_mmu_notifier_get(smmu_domain, mm); - if (IS_ERR(bond->smmu_mn)) { - ret = PTR_ERR(bond->smmu_mn); - goto err_free_bond; - } - - list_add(&bond->list, &master->bonds); - return bond; - -err_free_bond: - kfree(bond); - return ERR_PTR(ret); -} - bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) { unsigned long reg, fld; @@ -573,11 +315,6 @@ int arm_smmu_master_enable_sva(struct arm_smmu_master *master) int arm_smmu_master_disable_sva(struct arm_smmu_master *master) { mutex_lock(&sva_lock); - if (!list_empty(&master->bonds)) { - dev_err(master->dev, "cannot disable SVA, device is bound\n"); - mutex_unlock(&sva_lock); - return -EBUSY; - } arm_smmu_master_sva_disable_iopf(master); master->sva_enabled = false; mutex_unlock(&sva_lock); @@ -594,66 +331,51 @@ void arm_smmu_sva_notifier_synchronize(void) mmu_notifier_synchronize(); } -void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, - struct device *dev, ioasid_t id) -{ - struct mm_struct *mm = domain->mm; - struct arm_smmu_bond *bond = NULL, *t; - struct arm_smmu_master *master = dev_iommu_priv_get(dev); - - arm_smmu_remove_pasid(master, to_smmu_domain(domain), id); - - mutex_lock(&sva_lock); - list_for_each_entry(t, &master->bonds, list) { - if (t->mm == mm) { - bond = t; - break; - } - } - - if (!WARN_ON(!bond)) { - list_del(&bond->list); - arm_smmu_mmu_notifier_put(bond->smmu_mn); - kfree(bond); - } - mutex_unlock(&sva_lock); -} - static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id) { + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_master *master = dev_iommu_priv_get(dev); - struct mm_struct *mm = domain->mm; - struct arm_smmu_bond *bond; struct arm_smmu_cd target; int ret; - if (mm_get_enqcmd_pasid(mm) != id) + /* Prevent arm_smmu_mm_release from being called while we are attaching */ + if (!mmget_not_zero(domain->mm)) return -EINVAL; - mutex_lock(&sva_lock); - bond = __arm_smmu_sva_bind(dev, mm); - if (IS_ERR(bond)) { - mutex_unlock(&sva_lock); - return PTR_ERR(bond); - } + /* + * This does not need the arm_smmu_asid_lock because SVA domains never + * get reassigned + */ + arm_smmu_make_sva_cd(&target, master, domain->mm, smmu_domain->cd.asid); + ret = arm_smmu_set_pasid(master, smmu_domain, id, &target); - arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); - ret = arm_smmu_set_pasid(master, to_smmu_domain(domain), id, &target); - if (ret) { - list_del(&bond->list); - arm_smmu_mmu_notifier_put(bond->smmu_mn); - kfree(bond); - mutex_unlock(&sva_lock); - return ret; - } - mutex_unlock(&sva_lock); - return 0; + mmput(domain->mm); + return ret; } static void arm_smmu_sva_domain_free(struct iommu_domain *domain) { - kfree(to_smmu_domain(domain)); + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + + /* + * Ensure the ASID is empty in the iommu cache before allowing reuse. + */ + arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_domain->cd.asid); + + /* + * Notice that the arm_smmu_mm_arch_invalidate_secondary_tlbs op can + * still be called/running at this point. We allow the ASID to be + * reused, and if there is a race then it just suffers harmless + * unnecessary invalidation. + */ + xa_erase(&arm_smmu_asid_xa, smmu_domain->cd.asid); + + /* + * Actual free is defered to the SRCU callback + * arm_smmu_mmu_notifier_free() + */ + mmu_notifier_put(&smmu_domain->mmu_notifier); } static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { @@ -667,6 +389,8 @@ struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_domain *smmu_domain; + u32 asid; + int ret; smmu_domain = arm_smmu_domain_alloc(); if (IS_ERR(smmu_domain)) @@ -675,5 +399,22 @@ struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; smmu_domain->smmu = smmu; + ret = xa_alloc(&arm_smmu_asid_xa, &asid, smmu_domain, + XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL); + if (ret) + goto err_free; + + smmu_domain->cd.asid = asid; + smmu_domain->mmu_notifier.ops = &arm_smmu_mmu_notifier_ops; + ret = mmu_notifier_register(&smmu_domain->mmu_notifier, mm); + if (ret) + goto err_asid; + return &smmu_domain->domain; + +err_asid: + xa_erase(&arm_smmu_asid_xa, smmu_domain->cd.asid); +err_free: + kfree(smmu_domain); + return ERR_PTR(ret); } 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 527560b36b3993..26d597f608e3b5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1439,22 +1439,6 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) cd_table->cdtab = NULL; } -bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) -{ - bool free; - struct arm_smmu_ctx_desc *old_cd; - - if (!cd->asid) - return false; - - free = refcount_dec_and_test(&cd->refs); - if (free) { - old_cd = xa_erase(&arm_smmu_asid_xa, cd->asid); - WARN_ON(old_cd != cd); - } - return free; -} - /* Stream table manipulation functions */ static void arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc) @@ -2023,8 +2007,8 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_master *master, return arm_smmu_cmdq_batch_submit(master->smmu, &cmds); } -static int __arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, - ioasid_t ssid, unsigned long iova, size_t size) +int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, + unsigned long iova, size_t size) { struct arm_smmu_master_domain *master_domain; int i; @@ -2062,15 +2046,7 @@ static int __arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, if (!master->ats_enabled) continue; - /* - * Non-zero ssid means SVA is co-opting the S1 domain to issue - * invalidations for SVA PASIDs. - */ - if (ssid != IOMMU_NO_PASID) - arm_smmu_atc_inv_to_cmd(ssid, iova, size, &cmd); - else - arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, - &cmd); + arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, &cmd); for (i = 0; i < master->num_streams; i++) { cmd.atc.sid = master->streams[i].id; @@ -2082,19 +2058,6 @@ static int __arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, return arm_smmu_cmdq_batch_submit(smmu_domain->smmu, &cmds); } -static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, - unsigned long iova, size_t size) -{ - return __arm_smmu_atc_inv_domain(smmu_domain, IOMMU_NO_PASID, iova, - size); -} - -int arm_smmu_atc_inv_domain_sva(struct arm_smmu_domain *smmu_domain, - ioasid_t ssid, unsigned long iova, size_t size) -{ - return __arm_smmu_atc_inv_domain(smmu_domain, ssid, iova, size); -} - /* IO_PGTABLE API */ static void arm_smmu_tlb_inv_context(void *cookie) { @@ -2283,7 +2246,6 @@ struct arm_smmu_domain *arm_smmu_domain_alloc(void) mutex_init(&smmu_domain->init_mutex); INIT_LIST_HEAD(&smmu_domain->devices); spin_lock_init(&smmu_domain->devices_lock); - INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); return smmu_domain; } @@ -2325,7 +2287,7 @@ static void arm_smmu_domain_free_paging(struct iommu_domain *domain) if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { /* Prevent SVA from touching the CD while we're freeing it */ mutex_lock(&arm_smmu_asid_lock); - arm_smmu_free_asid(&smmu_domain->cd); + xa_erase(&arm_smmu_asid_xa, smmu_domain->cd.asid); mutex_unlock(&arm_smmu_asid_lock); } else { struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; @@ -2343,11 +2305,9 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_device *smmu, u32 asid; struct arm_smmu_ctx_desc *cd = &smmu_domain->cd; - refcount_set(&cd->refs, 1); - /* Prevent SVA from modifying the ASID until it is written to the CD */ mutex_lock(&arm_smmu_asid_lock); - ret = xa_alloc(&arm_smmu_asid_xa, &asid, cd, + ret = xa_alloc(&arm_smmu_asid_xa, &asid, smmu_domain, XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL); cd->asid = (u16)asid; mutex_unlock(&arm_smmu_asid_lock); @@ -2834,6 +2794,9 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, /* The core code validates pasid */ + if (smmu_domain->smmu != master->smmu) + return -EINVAL; + if (!master->cd_table.in_ste) return -ENODEV; @@ -2855,9 +2818,14 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, return ret; } -void arm_smmu_remove_pasid(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain, ioasid_t pasid) +static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, + struct iommu_domain *domain) { + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_domain *smmu_domain; + + smmu_domain = to_smmu_domain(domain); + mutex_lock(&arm_smmu_asid_lock); arm_smmu_clear_cd(master, pasid); if (master->ats_enabled) @@ -3128,7 +3096,6 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) master->dev = dev; master->smmu = smmu; - INIT_LIST_HEAD(&master->bonds); dev_iommu_priv_set(dev, master); ret = arm_smmu_insert_master(smmu, master); @@ -3310,12 +3277,6 @@ static int arm_smmu_def_domain_type(struct device *dev) return 0; } -static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, - struct iommu_domain *domain) -{ - arm_smmu_sva_remove_dev_pasid(domain, dev, pasid); -} - static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, .blocked_domain = &arm_smmu_blocked_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 212c18c70fa03e..d175d9eee6c61b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -587,9 +587,6 @@ struct arm_smmu_strtab_l1_desc { struct arm_smmu_ctx_desc { u16 asid; - - refcount_t refs; - struct mm_struct *mm; }; struct arm_smmu_l1_ctx_desc { @@ -712,7 +709,6 @@ struct arm_smmu_master { bool stall_enabled; bool sva_enabled; bool iopf_enabled; - struct list_head bonds; unsigned int ssid_bits; }; @@ -741,7 +737,7 @@ struct arm_smmu_domain { struct list_head devices; spinlock_t devices_lock; - struct list_head mmu_notifiers; + struct mmu_notifier mmu_notifier; }; /* The following are exposed for testing purposes. */ @@ -805,16 +801,13 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, 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); -void arm_smmu_remove_pasid(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain, ioasid_t pasid); void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, size_t granule, bool leaf, struct arm_smmu_domain *smmu_domain); -bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd); -int arm_smmu_atc_inv_domain_sva(struct arm_smmu_domain *smmu_domain, - ioasid_t ssid, unsigned long iova, size_t size); +int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, + unsigned long iova, size_t size); #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); @@ -826,8 +819,6 @@ bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master); void arm_smmu_sva_notifier_synchronize(void); struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct mm_struct *mm); -void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, - struct device *dev, ioasid_t id); #else /* CONFIG_ARM_SMMU_V3_SVA */ static inline bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) { From patchwork Tue Jun 25 12:37:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711080 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 3DEB2C2BBCA for ; Tue, 25 Jun 2024 12:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=B3zCRjUim5TZOGGBb5ABYfvdntY0XNoULhen5NYnvCs=; b=0XjNMFM98LwuHJcnOiRHRMlJUU JGQOYARRtu6pT7k3p1obkF8eXAu9dmeHwRlNKNL4CPwbxBeSX2kI9ifDEzJtcQh9WdZpjAzN1lG6m n0/4irkE8WxWYTK73Y6nHMOZf0eokTgS5jyip3NHj3VMu8fopw6OGDc7tB9oY63So3HnscwFcKnqh JFjsqMHACJyOdAdQsf+/Igrh3HD9c6w9u4yAmvhqDGzI4q0bhx5rSoSRqB2gV0CvKdY4Tfnn/vr27 vJT9IS+8djDctx83uRXvGD9I4G13ve+YFNfINUocxHO4r8m4mmx90mpTgw+1jqHfVl+pHJEjFeQxa K3TpGWyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Rw-00000002oND-1CjM; Tue, 25 Jun 2024 12:39:04 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5R2-00000002nfA-3yCU for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DZsWUV5cGaYiH61Sr7XJ4LufHH+7FUnR8DnVfxZmSZ9NW9w6SWO76iDQIhCRx79MCDCut/YH0ZBARoSLE7ljrm9rWL+Fd1PgCwxYGlH3cJ4esXY9EqioO2CEwwgOs9yCECY65Z4uIUOsxXnFdzbuB1uDWwg7LSySZ64fGSFKLCTAgWlcSyEkDyZxfTnXOVbjhogdT9H7AFSI4ugJEmXGAlzmRjzdol5gvb4ldam5vxiAyljRWy61yTH89YNN2UvjAX5GCJyYFay5j/RBjTqI4RzPz4Y54P/FuSMhl/fafoPMKjoHGY8GWoMgVgiruwOG1renoHEWSfp7XYIqK8W5kg== 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=B3zCRjUim5TZOGGBb5ABYfvdntY0XNoULhen5NYnvCs=; b=Bz4zJQc32odRNyKFHAv9u3xIY2ROR9eaGLU33ZHCC+ubqrsXgEg0q3767imp7lxSt/vbNPmNAgQoxpKxkWypnolBKW9gKH020jbbZK8+ZuKgegHmLmKyjAmy7b0ybsD5CZ3LVKvfg1Pd9kpvPewGsFMWVH5c9niaZUZphLs89GN5tE9GPVwVsB4zCPSILW2rUmHwXza1WBqLsWNak9oMNnbtfgUadkdS68/rDqLJts/xXovuYlhae4B09evHk3VgyVE/88MdaqVUbZQnJqvLlKXzbBqfQE6L4uiaENpsa0NAHU8/XqdoA1IZlyHZZJmwIPb6effzMbzI7ydcfX0IxQ== 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=B3zCRjUim5TZOGGBb5ABYfvdntY0XNoULhen5NYnvCs=; b=NWrV9CKh6EGqwjqmDa1y2RiaNdksxofNWT0LE+lSVyIEVNLO+B+NATyGPEEolLiYwELNCs18ukK7zXvhLuhtvoX5hj4LZCpqEuqh0IBewlpMzs26P1eZZCyHMrxZ3yJ1QdE3VCaJNSnmFEV03LfLcAet3rhjIHtCDg7KviCVTw/2SmgE/iEFFrrejndE9yhd73Vzbc6lnrvMOr7hKEK9+MTofUT4ZXPzccd0izwQV2xyoDvdRQhCwnpQvpZwV5DFFyw3BubANZjsBfysI6ozRyz4Iaa7Pb1B4UJyZoM6plXUAMM30EEWVZU1xiUGu6Dg11d3nx4bIP3gIWjUrDcbOQ== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:52 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:52 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 11/14] iommu/arm-smmu-v3: Allow IDENTITY/BLOCKED to be set while PASID is used Date: Tue, 25 Jun 2024 09:37:42 -0300 Message-ID: <11-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR05CA0038.namprd05.prod.outlook.com (2603:10b6:208:335::19) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: f2041cbe-f284-409a-783f-08dc95139f07 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: TLAqR7TMAeBSWJHLXsEZFG+HSJaXCP3uIDGByPN4V9HFlw9QhuHW177GuAB3yKVArjX9AGaZXO306vxYSatmgmoKWx4+dg7wW5qJeFsIivIca4BZiALOL63SC7Y0v1mCOceG7bqY2tPcYAB+UoLTSn3iucJbVWi+rP4ICfyH59hhLo9pVyqEKmyG7y+QAuYIdSIYYsWNgGWBUprgMbsxB0DqdJXfUbzobGjfRwbSXh5gw0I+m8PF8TKAGJjtGc4FKsWcctAYa0YAFFF6PDeazxLWLwx1JzIFJtr5xRv7cf/MsF8m7gvC8IycNBVT/oXg/1lvx4HZeIwzTIawXqne1ftmyOfe3/OQtqFlu36Y1sqIed7BPxXDuqPvlDnkKXwg55j/WTcL+8T8hc1G9T7Thn8jsspRNvMj3DusfuM0XfCWiGw8mLWku4EeyBDhncoHYnUUhQTKfQT1lbaWz6oXZwcPZIBDcBv4NQLItbbexsNQ9a40ZcDLr3JtmkPrtL2jQKGjVsSQRTQMSrMDUA8elz35Kh04EWt58pDm3FW0a/fo8OLXrXaK1LAb/aDglqh1KQ8VBMn7dHUVW+fY/DFugMh6SNOlWMdojPZz291TyqqbTXeoLxgMeLzrVWdhHMKZRYzFaVbYO12SBu6Zniru0PO01aWwYr2jYoi202AJQG7RHV/IgR9Gp4+UCb0QHZDXwpLhih5dCsTeN4Dd5cllYgpr43z6uoW9HbKrlFuvpG5gONevX1m3objDQXz1zL6dgk2lzQAapZ4j9nXZj1JPY6yFzqg2yGMNrQGRfRIX5bsMJtAcc1jsIb+LqMYg+uMn+5FEZpWdPZxb2V9LALZbY5MlZAMW5lrVbvgvLn3KRjdCWLGlJAvaI5UH3GOUzzpoTzX0DJ461v+lcftVMHLdS6ThCwydasHFFOYad2k17kssftgKaOSoGRAT8bRCRi2hEh8dbSFO46L+AbJKdZCTfL7yXyuHHuO20T11yPKSRaDyaajPZ87tOvNQLpa+9L9toRxiYSZ12qaSz32qjG/iI8KwUSyib/RvadHYCTXoZDky30jfG79EitsNVjEvenCdaWv+YYgFkDuGjKRu8smuuy++e6Ifo2u/Jz/4DUZyyLqPxrh6IVffI5BQD+Oyu9CK+bzxPAGv+Ufov/Xn//+RFFb4hyjFHikk82CnlvmIs9AY1f/kT0mTjKNXnPm+Mc7JfiMdzxtKVFFL2x5+IXcuvk16ahhSoLpMQK3AwtQckNj+aM30aKRAnzGSJ5glnK7Nt/puVZsQMEbfm+fa9tdJ1sfsA8Bk9YdRHcWi5LAbW7U= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1FwqdBpsz/Ach4h0lODWQvksZ6+XmPv6Sz7Xynu5HXqWYr1qh49LqvOzRDDlGireNN9TEfsvfDsWpYeTpy7iFmWKnXUnLJBOf1rE6NxFE5nVEuGnk5POn90qtKzjLmxy7ayoKiXNcfoZ/KryUutszQmCJ2M5C789GIXDqdffEjSes/A61RfGMRVPTRadeeZR7aFXBCHTPS+nvmXlN4bYk+NIZhL2u7/8X/0Wegb0lruqcUF4+taBgxEEBTT+wENzkQOPIqHLT5hepnuKN0op8t2bFU+453EdFRlFSrzEr0gHfv6lSPlCHEBb+z0Bip6uir1+2UFW0g+auBYtoC0H8EN71nuSfmPY0oxEu2fKDbhFwhldSkanNRjl6NmYFXJnFknlWHBxAyr7u6d+Dc2Hr+CXjnaphvEP3h9Di19H3PO3pjOM9ISMABoBK9T0DJvj77vZtGZpfqRSUdWDvHmW/zdoRdL0zAnu6pBBwLFYZP+aQKkdv8zG1TvSVORzfGZFDQEW0pJCZwsf8OTep+DClARJ2dmS8rswTB35rfCN67dohmHf3N5+2hPxNorfkwWNnScPiu5jPDXbnj7xV7dOJeAUvnNnpRsX0HuOuSts6Y+3I39HLEIk46S00T4UP6YoRqeoGss0z5tbqUif7lFNTN98fIT++pqcTg7zkX1ucFiHE/eWnp5HAJr+7W13CzTzyjQifbLoYYbP8GMMCzy8q5Yh1bjEzWxJjQPYNSSSsUMWJsGZrleDVQQZp9paA5sbYWsm20wyHdtlWvEVtntzlUKdsWMx0FktW1nDIQjdvHsud9YOq99fuO371p6zWZo5COMkGBF8bFLVhdFt8i9QmsV8P/P8y/0CLDeXU6pwhXCXKi+vI19qSiQ4uqE+MyP7cMbThIkRLXw/zSoZmsZ7oimWPZ7rTPHV/eKn5bxChpw6bqJ/PpM9a5hIErru1CRqvew1cjthaGWX5tkfFry3jaldyzbCz0Bmzpfwyre2fXbODaBhHABFfU2zNNQ9u5l7MW2b7o9iXZdvmKbSC6K2907WSfEMhwwc63ubgZFqydjaq70g73+mC/d3h96bMxKXQGltJ5VcQQp6N1LYknEe1Za6qOrNu+U48xRlUecZ/sDmsNVIoxDLXBlBwaXHLZEbMWipanKrYtJwj2OPnGvWRTbA3q/lskMXdHozpwSP/5VaIgg3rO4pEvmeKu0aaCXyUQ4NsO2dPekBl+sMsgRCPW0stG+yp0QCVlXRBcJIvkjkh0ZLgdEclRfZyOtji5D2EBS5knATR1rpMrJzIFa26ehj1A99g54yB15AR3H8WJynViVg9gIP21X63vTq8UDFE93rha2qz7s1YRCC+4wR4dukaJu0WwIh7Cpc+t0aG5PUS2DPIjRX3mBXyJ4fHKJv+EXkIdgpv+yzujqnsf2tKM79xPRIVhwOVbIGulquWZtrtl5AxYf6lX78AIVmaD6tYSbz3s+Mv7tnVkr2AYFab8tFnkeLUgWrGHp4zzYUnyEXSZgE1dxD8XetFv+O8edIW//xQ7yj8VGrqYyBoEN/6GpXZLQ22CrP+Pu3UqFx/LZ6JGBJr31XspA9mTmt4Ajo X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2041cbe-f284-409a-783f-08dc95139f07 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:48.6748 (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: 5PRvwTefO0A1drrH8TUaBOWZmO84EyWU0lapnBd/bS2bcv0b8v4O01P/e6UONz2k X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053809_159041_3AD30E61 X-CRM114-Status: GOOD ( 26.82 ) 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 The HW supports this, use the S1DSS bits to configure the behavior of SSID=0 which is the RID's translation. If SSID's are currently being used in the CD table then just update the S1DSS bits in the STE, remove the master_domain and leave ATS alone. For iommufd the driver design has a small problem that all the unused CD table entries are set with V=0 which will generate an event if VFIO userspace tries to use the CD entry. This patch extends this problem to include the RID as well if PASID is being used. For BLOCKED with used PASIDs the F_STREAM_DISABLED (STRTAB_STE_1_S1DSS_TERMINATE) event is generated on untagged traffic and a substream CD table entry with V=0 (removed pasid) will generate C_BAD_CD. Arguably there is no advantage to using S1DSS over the CD entry 0 with V=0. As we don't yet support PASID in iommufd this is a problem to resolve later, possibly by using EPD0 for unused CD table entries instead of V=0, and not using S1DSS for BLOCKED. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 60 +++++++++++++++---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 +- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c index a460b71f585789..d7e022bb9df530 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c @@ -164,7 +164,7 @@ static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste, .smmu = &smmu, }; - arm_smmu_make_cdtable_ste(ste, &master, true); + arm_smmu_make_cdtable_ste(ste, &master, true, STRTAB_STE_1_S1DSS_SSID0); } static void arm_smmu_v3_write_ste_test_bypass_to_abort(struct kunit *test) 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 26d597f608e3b5..10d140a5cd0f38 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -991,6 +991,14 @@ void arm_smmu_get_ste_used(const __le64 *ent, __le64 *used_bits) STRTAB_STE_1_S1STALLD | STRTAB_STE_1_STRW | STRTAB_STE_1_EATS); used_bits[2] |= cpu_to_le64(STRTAB_STE_2_S2VMID); + + /* + * See 13.5 Summary of attribute/permission configuration fields + * for the SHCFG behavior. + */ + if (FIELD_GET(STRTAB_STE_1_S1DSS, le64_to_cpu(ent[1])) == + STRTAB_STE_1_S1DSS_BYPASS) + used_bits[1] |= cpu_to_le64(STRTAB_STE_1_SHCFG); } /* S2 translates */ @@ -1531,7 +1539,8 @@ EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_bypass_ste); VISIBLE_IF_KUNIT void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master, bool ats_enabled) + struct arm_smmu_master *master, bool ats_enabled, + unsigned int s1dss) { struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; struct arm_smmu_device *smmu = master->smmu; @@ -1545,7 +1554,7 @@ void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_0_S1CDMAX, cd_table->s1cdmax)); target->data[1] = cpu_to_le64( - FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | + FIELD_PREP(STRTAB_STE_1_S1DSS, s1dss) | FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | @@ -1556,6 +1565,11 @@ void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_1_EATS, ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + if ((smmu->features & ARM_SMMU_FEAT_ATTR_TYPES_OVR) && + s1dss == STRTAB_STE_1_S1DSS_BYPASS) + target->data[1] |= cpu_to_le64(FIELD_PREP( + STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); + if (smmu->features & ARM_SMMU_FEAT_E2H) { /* * To support BTM the streamworld needs to match the @@ -2579,6 +2593,7 @@ struct arm_smmu_attach_state { /* Inputs */ struct iommu_domain *old_domain; struct arm_smmu_master *master; + bool cd_needs_ats; ioasid_t ssid; /* Resulting state */ bool ats_enabled; @@ -2620,7 +2635,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, */ lockdep_assert_held(&arm_smmu_asid_lock); - if (smmu_domain) { + if (smmu_domain || state->cd_needs_ats) { /* * The SMMU does not support enabling ATS with bypass/abort. * When the STE is in bypass (STE.Config[2:0] == 0b100), ATS @@ -2632,7 +2647,9 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, * tables. */ state->ats_enabled = arm_smmu_ats_supported(master); + } + if (smmu_domain) { master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); if (!master_domain) return -ENOMEM; @@ -2760,7 +2777,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); arm_smmu_write_cd_entry(master, IOMMU_NO_PASID, cdptr, &target_cd); - arm_smmu_make_cdtable_ste(&target, master, state.ats_enabled); + arm_smmu_make_cdtable_ste(&target, master, state.ats_enabled, + STRTAB_STE_1_S1DSS_SSID0); arm_smmu_install_ste_for_dev(master, &target); break; } @@ -2834,8 +2852,10 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, mutex_unlock(&arm_smmu_asid_lock); } -static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, - struct device *dev, struct arm_smmu_ste *ste) +static void arm_smmu_attach_dev_ste(struct iommu_domain *domain, + struct device *dev, + struct arm_smmu_ste *ste, + unsigned int s1dss) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct arm_smmu_attach_state state = { @@ -2844,16 +2864,28 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, .ssid = IOMMU_NO_PASID, }; - if (arm_smmu_ssids_in_use(&master->cd_table)) - return -EBUSY; - /* * Do not allow any ASID to be changed while are working on the STE, * otherwise we could miss invalidations. */ mutex_lock(&arm_smmu_asid_lock); - arm_smmu_attach_prepare(&state, domain); + /* + * If the CD table is not in use we can use the provided STE, otherwise + * we use a cdtable STE with the provided S1DSS. + */ + if (arm_smmu_ssids_in_use(&master->cd_table)) { + /* + * If a CD table has to be present then we need to run with ATS + * on even though the RID will fail ATS queries with UR. This is + * because we have no idea what the PASID's need. + */ + state.cd_needs_ats = true; + arm_smmu_attach_prepare(&state, domain); + arm_smmu_make_cdtable_ste(ste, master, state.ats_enabled, s1dss); + } else { + arm_smmu_attach_prepare(&state, domain); + } arm_smmu_install_ste_for_dev(master, ste); arm_smmu_attach_commit(&state); mutex_unlock(&arm_smmu_asid_lock); @@ -2864,7 +2896,6 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, * descriptor from arm_smmu_share_asid(). */ arm_smmu_clear_cd(master, IOMMU_NO_PASID); - return 0; } static int arm_smmu_attach_dev_identity(struct iommu_domain *domain, @@ -2874,7 +2905,8 @@ static int arm_smmu_attach_dev_identity(struct iommu_domain *domain, struct arm_smmu_master *master = dev_iommu_priv_get(dev); arm_smmu_make_bypass_ste(master->smmu, &ste); - return arm_smmu_attach_dev_ste(domain, dev, &ste); + arm_smmu_attach_dev_ste(domain, dev, &ste, STRTAB_STE_1_S1DSS_BYPASS); + return 0; } static const struct iommu_domain_ops arm_smmu_identity_ops = { @@ -2892,7 +2924,9 @@ static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain, struct arm_smmu_ste ste; arm_smmu_make_abort_ste(&ste); - return arm_smmu_attach_dev_ste(domain, dev, &ste); + arm_smmu_attach_dev_ste(domain, dev, &ste, + STRTAB_STE_1_S1DSS_TERMINATE); + return 0; } static const struct iommu_domain_ops arm_smmu_blocked_ops = { 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 d175d9eee6c61b..30459a800c7b2d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -761,8 +761,8 @@ void arm_smmu_make_abort_ste(struct arm_smmu_ste *target); void arm_smmu_make_bypass_ste(struct arm_smmu_device *smmu, struct arm_smmu_ste *target); void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master, - bool ats_enabled); + struct arm_smmu_master *master, bool ats_enabled, + unsigned int s1dss); void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, From patchwork Tue Jun 25 12:37:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711078 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 DAC41C3064D for ; Tue, 25 Jun 2024 12:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=EcCtlXWAnCRAQD3/Wh7aQFY6FWzz0V0ZSpeFpxu8ghg=; b=BmiwlzYoJCZ+bt0Be6W0HC9J/b X4JhEPyZC/WRNaNkOBQsDqTNnWcbPXMYvExDDWt1Y1IOasqfyVJH8gDYyvcue75rvcZ525d1wZQUl Fvguhm7A2SCaS7hZs2SwUP43YvMC3iWOYOR3rR9wqxBaEZt9dkwbdJmngp0Qd/RKT/FEqwdKKqxlf J81Ha4VtDTC9AZLgriB1aIzluWlEbzymocK891iutCRzd16ssrHLNP30sLCN/15Q2Ul4tjObAIv9Q UEde/hQbB3wXfceAlW+EhNmlt391R2hVpxQR1+Vo4EdTTSlr3S/taJpN1ZvtKz4axsh8B6Qb45pQn Olu+fzUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Rj-00000002oFp-2kM6; Tue, 25 Jun 2024 12:38:51 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5R0-00000002nfA-1bAw for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bp+GlQ3TIBWqNzAbbvY7R/BmAwgCkKIggNR/dYU534RC7IbDUNMUYoJ6HbsfdsdsCz/OKxqGlGEYJ4F8B8VLaLcgo1BwrTz7rPGZLrGyGBsL1HX8zvE8ZURkrWQaa4/gUCwiGOWF8XdOmMze1UHG1pfRVDM5yILdPGMexQqAZoGbZSVbEP9UgLO2Hmzzrnpur2YUdUfcXBs0bFpnMHfawNrfU6ndl2xk3XNthke25L1mDglYhagT8W2/4lmJuwreW3m/uYpdZ1iHtDOnHUP1UjHCyBTO4eeI7mEKS6P5Vx21quNOd3p1F/R/8wbql9jCusBqacyVbJF+aqjQyph6sg== 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=EcCtlXWAnCRAQD3/Wh7aQFY6FWzz0V0ZSpeFpxu8ghg=; b=LNd0i83EYcvk2Aas8V7cjxjbkKeTGDcMitoP48QitOpbNaKkQ6lHocO320DfhsMB7nbnX/XKa16bMgY1L9KsA1O/ylwrBmJdhuL28dGoRCFhfIyyEbu7acauUCA8HQb3hY67jPbYNI6lMdmiVtR5zm85VXhLMnJ+0jWiDDOHFhKezEvGI0Cbn3Anf3OvIc+RlazQGVU2x56AS5cvXvZj7DvvlFisOONWIU4oNGidFKptBBEkCc/RXiCQ6KpMFRxiF9Zn7icWejg88qsmARRfnhZ/+SDp/qI5E5qADj9S+vB2GigayWd33JrbLEj2CUKqaVqDW5fIszSkE/4GeAqurQ== 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=EcCtlXWAnCRAQD3/Wh7aQFY6FWzz0V0ZSpeFpxu8ghg=; b=VBlbUXFgSpM618r6zDLpQFiftX1EjDAcIbOKDAD0IHaz/+ucqxasIz5VMStOpoUcGestz28Rb7ejlChz4UiyI5Ys7KcBrCVI5GgCuTo8oY7OTYDqDSD06rSiZM4IGYAyGgyY4UiylUtx0czaQ4wPkw9Kzf646sw5WTQqkRdvysyEauuuPFLEG29LqssI2w3Oi1JacQaae0sU4b+3HXTIGAbHoYLgawrLvUsTb7m1U/ojmQlMOfzsVKiLfD25mcl5BUEgzE5NgbWDZskuoV1OJwTQGxbKWm8nvaHeoX0CSl+SlazGyMhnT89OD3HfrYVi+jeLIXaPhMA705XJFJZZtg== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:50 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:50 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 12/14] iommu/arm-smmu-v3: Test the STE S1DSS functionality Date: Tue, 25 Jun 2024 09:37:43 -0300 Message-ID: <12-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR05CA0025.namprd05.prod.outlook.com (2603:10b6:208:335::6) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ceba571-560a-477c-3cfe-08dc95139ec8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: Z0ZPZd2272igaLpSpHIrhTaY4mViGJ2x6YcTAI72GroS+A//zO2x9eWU4nxt2rsFfxbSGPPeZLTFNonMD/AyRfbs4+GSY3E84916SP6c5V4k/CnvxCwd17TyWMwyD0eBcXhaNeFSL1vS3sTJJZ1BeETLYwPcQlPHwmYcdmuhjch47NiR7mh58Fiu0aiofgZ8rnpaJag1BruryXDm/gXWaysBNQAmR1xLmPwgNH8xwkOFD0sXCYKjjNhhgmIxlNYRnecfPyYvQK0qydQG0X8C7G6ymu8RiCzGjjMk/t4RHJlXlyxWvHze59kmw3GGwMVBrkcDHUG13wYxyucJIivUEgccRJYN7CTo8Lk75RYjoIUrwHc77iIyAqs/u779sH7PkY7vigXLhVARxSv/D0ogbaQrjgl2SJiytpFvYmnEpgJ2/d3w3gugZ1Uvt8OhUpUNgog9E7YNl2+fYSLpaiXFmg6AXLldJExYyUbihKRfPripJDnI1EgMg1/8TaUEAqymqVyq4z9t/fTsBGU6n5I3KHK1rskC+EDBBfZH7HV7OWIdNE9CwDn7GeliiU2VGFqsRwBMVOOahfabmyHDejyKPzzJSsVMcWGheLlDqrKZRsqAlpfEsQ6Ogod/ClxD+PO/e++PL23SHkHqV2L/ZEyAw0DIj4df9uQlvI8atl4QMgiz4rWmz+mu7WPT2nGL2fH3Y1oxhKQ6e1ZmWPqGS9hYupKn+vSzHBy6RU0mjOElZQHROTwUt8bIwdF7mQ/LFqbA6z66Y5DPdFEK0A3aSTy/I5yDL2/vJWzBl6mkjSdwpD8+pCcMyLvt1ZOYixpihhMAWqu1Cc4JqiupfQi8qYKJ39FOJc2xbY8qiLgphBsInHffUKbHqvn/yUmWtifuLErlKawsHo7FrVGFpbcE2rw/aYY1+WsL0xqKUo21B3Jhe5NWyqe0QCuBuY5njUlyJcSfhdSe20g/QavPeQzPe8P3MaKZfGnzr2uj/KndCEAKArVTu11/eJ+t6NYT/B9b6J/RUPzs7mfKcOZK5EX87TK1Pjal0hh7tW8d4Zo161tOH2E9QeYTYahF7/B9/yfgUCautBIty1AlPyIgiq1eSLyLEUBWD8NWdaeWEkBJCr6JsBWHJCAWktK7jt9zBgWU+wsTUpD01s+6xofHGr8g4OS2QUGMN7EJmHaDQs6PW4JPD6rNBUFOxEFlnCSfQBBJ8R0icKpB+rgzSZE8/DAsDjhQvxYHah46mMall8FzZJJkFYbVov9WNC4tDdCDgB3t7H+BNqC8dR6meQ7E5AuOlli8k3Ss8k2uv03A141pNh1qDLq1qbaMTm/+7Blidim49OqN 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c/56HjAErjId7AkkYrUCstC3dXR33MbN0+KobrXFL7MUDb21rny6I2Plfcgg5lopsGl39c3E182LTU78wU0wl1cIEXXOuGzM+BwKv+vdbeny5itChYjWfofOG2Jy6WXBuFVg1rs+L+FYn00ig7dFFdtcRuJqAbmfR1hKtST1yPtjUmn6Hc6JTgrOfRg4RJbnetEmiXkoz6HjRyi/CHCrOAMhDSaf40L5sxCzIjsAeINidFUuoN9TtnmVWLogPeeSjIkyeACKehIW9fylR8Hq616psOTEWQvljfScswIO2gM0SJJuX6jU4QnKUxQK/UQPMFFl59CBmKV6YXwBHq7kKCIIdfggpBcRDL3aLhLF/ruxXTi300j0j82FPRF/iwDJ/zygpbaC3i/oMEuBmQk2k8xPgH2AVvTXoLZYknSh8pm6gXrY/0XTT+r3d6fxc6HU3gZWeCrTdc51oI0zlRjIGVP9b2p6P64Pksbb+ac5Hcke3IjsGs28WjgK73QRn1tc16r2X/k7FMBJGH5sa9yjKT4LCA6gY9IUizWoeCx0NoksWWrju5PmyqhJO9T4WikStw5ZjGQW85foDf/1QoT0vq/Hdsk/jMEgnEP+uJpm9Ft5Pb9CUzTEFZ1FwFUhRcdnYDSyroQqPoebhPyccu3ZjUlTxfpb9JyIQv4rw5v+RpZff1ew5A9uQbJdju0C/M7wvjI1FPyHcgyFZVMdCkAH2LRBv5HEWUJuFv0D4VNl3hvfjaOzqxzr71eACSPC/YNS06pamwvefAumDWHENSwBEtplwNfMQN5BDC9b/+koACby6gyIdoESjJdOee5SF5ACUFsfvGAJn19r1xL6BzoUxWdZJMI4ei3lUa+883JDijKz42PO+rOd2Q3xamjfKyG3DgPCVd79H0GthgVZxthX52Co57ohVaNeJlv0fPOMMCLW/QmAnChQ4mTd7ipWBHA8M1VD4cw52ETNvfemy7hJZHP9EwLmdRJ3hgjcGToBD9J37HHU4BlGrNY09oYeNiciD8O83XN/TfRRGTb5OAqfFUpVhWt0R4tlcz5jfBfoMbWR/YedlVDE/NImNZxPenGIHGClJ8NRDKa1hL9E/8+Xd7KAHitVNJ8mfM0r2H+dq+7KYjrCPcvsZMKfiANDSDzpVmswjQBQIryiYZXT/fEXA0/rMz4T8Mj2Js6J3BEIiqswGYbA93P9aHHd8PLGlAf1xvqv4guwptSPygOkrvzL3R17OT9G1QxYiImHcUg3hLl6oafzDl52Cisut94HwtVKX5/e/1cz5qdPlRyEjgijDKzdhkGbr2bdHcnCcaoRabEXHYrFTel9WLeEArQQaAG9DTxVKxQOjxaimMvpugOCK0501pjdQa858BACjvn5MWnLKNL1DKQGzUR99wcW0kJp8sUHXW8sDx8EJEoKXTRznRuf4R1mb4U0ZatVp+3H7OsFMC1Z1d1INWrpsRDjQwdbH/sGW+kbbLpd/Olw3nWfaEo/8v3dzTrPO1/Khu1Zzy+6zN962LSyvPImceLezrRZRx/mFzoEF0y7BOV6MVc5jKMru7ldaIvANrtSgsa4pbFvMbmKd+3zQ69NNm4pTg7t X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ceba571-560a-477c-3cfe-08dc95139ec8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:48.1976 (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: FoEz8rCf/AGS/vCNtfH4qstpYiN1GHOH02adH7tFZLbiraSaW7rtcqpnHdtrf7XL X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053806_657636_33035872 X-CRM114-Status: GOOD ( 11.56 ) 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 S1DSS brings in quite a few new transition pairs that are interesting. Test to/from S1DSS_BYPASS <-> S1DSS_SSID0, and BYPASS <-> S1DSS_SSID0. Test a contrived non-hitless flow to make sure that the logic works. Tested-by: Nicolin Chen Signed-off-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 113 +++++++++++++++++- 1 file changed, 108 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c index d7e022bb9df530..e0fce31eba54dd 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c @@ -144,6 +144,14 @@ static void arm_smmu_v3_test_ste_expect_transition( KUNIT_EXPECT_MEMEQ(test, target->data, cur_copy.data, sizeof(cur_copy)); } +static void arm_smmu_v3_test_ste_expect_non_hitless_transition( + struct kunit *test, const struct arm_smmu_ste *cur, + const struct arm_smmu_ste *target, unsigned int num_syncs_expected) +{ + arm_smmu_v3_test_ste_expect_transition(test, cur, target, + num_syncs_expected, false); +} + static void arm_smmu_v3_test_ste_expect_hitless_transition( struct kunit *test, const struct arm_smmu_ste *cur, const struct arm_smmu_ste *target, unsigned int num_syncs_expected) @@ -155,6 +163,7 @@ static void arm_smmu_v3_test_ste_expect_hitless_transition( static const dma_addr_t fake_cdtab_dma_addr = 0xF0F0F0F0F0F0; static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste, + unsigned int s1dss, const dma_addr_t dma_addr) { struct arm_smmu_master master = { @@ -164,7 +173,7 @@ static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste, .smmu = &smmu, }; - arm_smmu_make_cdtable_ste(ste, &master, true, STRTAB_STE_1_S1DSS_SSID0); + arm_smmu_make_cdtable_ste(ste, &master, true, s1dss); } static void arm_smmu_v3_write_ste_test_bypass_to_abort(struct kunit *test) @@ -194,7 +203,8 @@ static void arm_smmu_v3_write_ste_test_cdtable_to_abort(struct kunit *test) { struct arm_smmu_ste ste; - arm_smmu_test_make_cdtable_ste(&ste, fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); arm_smmu_v3_test_ste_expect_hitless_transition(test, &ste, &abort_ste, NUM_EXPECTED_SYNCS(2)); } @@ -203,7 +213,8 @@ static void arm_smmu_v3_write_ste_test_abort_to_cdtable(struct kunit *test) { struct arm_smmu_ste ste; - arm_smmu_test_make_cdtable_ste(&ste, fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); arm_smmu_v3_test_ste_expect_hitless_transition(test, &abort_ste, &ste, NUM_EXPECTED_SYNCS(2)); } @@ -212,7 +223,8 @@ static void arm_smmu_v3_write_ste_test_cdtable_to_bypass(struct kunit *test) { struct arm_smmu_ste ste; - arm_smmu_test_make_cdtable_ste(&ste, fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); arm_smmu_v3_test_ste_expect_hitless_transition(test, &ste, &bypass_ste, NUM_EXPECTED_SYNCS(3)); } @@ -221,11 +233,54 @@ static void arm_smmu_v3_write_ste_test_bypass_to_cdtable(struct kunit *test) { struct arm_smmu_ste ste; - arm_smmu_test_make_cdtable_ste(&ste, fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); arm_smmu_v3_test_ste_expect_hitless_transition(test, &bypass_ste, &ste, NUM_EXPECTED_SYNCS(3)); } +static void arm_smmu_v3_write_ste_test_cdtable_s1dss_change(struct kunit *test) +{ + struct arm_smmu_ste ste; + struct arm_smmu_ste s1dss_bypass; + + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS, + fake_cdtab_dma_addr); + + /* + * Flipping s1dss on a CD table STE only involves changes to the second + * qword of an STE and can be done in a single write. + */ + arm_smmu_v3_test_ste_expect_hitless_transition( + test, &ste, &s1dss_bypass, NUM_EXPECTED_SYNCS(1)); + arm_smmu_v3_test_ste_expect_hitless_transition( + test, &s1dss_bypass, &ste, NUM_EXPECTED_SYNCS(1)); +} + +static void +arm_smmu_v3_write_ste_test_s1dssbypass_to_stebypass(struct kunit *test) +{ + struct arm_smmu_ste s1dss_bypass; + + arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS, + fake_cdtab_dma_addr); + arm_smmu_v3_test_ste_expect_hitless_transition( + test, &s1dss_bypass, &bypass_ste, NUM_EXPECTED_SYNCS(2)); +} + +static void +arm_smmu_v3_write_ste_test_stebypass_to_s1dssbypass(struct kunit *test) +{ + struct arm_smmu_ste s1dss_bypass; + + arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS, + fake_cdtab_dma_addr); + arm_smmu_v3_test_ste_expect_hitless_transition( + test, &bypass_ste, &s1dss_bypass, NUM_EXPECTED_SYNCS(2)); +} + static void arm_smmu_test_make_s2_ste(struct arm_smmu_ste *ste, bool ats_enabled) { @@ -285,6 +340,48 @@ static void arm_smmu_v3_write_ste_test_bypass_to_s2(struct kunit *test) NUM_EXPECTED_SYNCS(2)); } +static void arm_smmu_v3_write_ste_test_s1_to_s2(struct kunit *test) +{ + struct arm_smmu_ste s1_ste; + struct arm_smmu_ste s2_ste; + + arm_smmu_test_make_cdtable_ste(&s1_ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); + arm_smmu_test_make_s2_ste(&s2_ste, true); + arm_smmu_v3_test_ste_expect_hitless_transition(test, &s1_ste, &s2_ste, + NUM_EXPECTED_SYNCS(3)); +} + +static void arm_smmu_v3_write_ste_test_s2_to_s1(struct kunit *test) +{ + struct arm_smmu_ste s1_ste; + struct arm_smmu_ste s2_ste; + + arm_smmu_test_make_cdtable_ste(&s1_ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); + arm_smmu_test_make_s2_ste(&s2_ste, true); + arm_smmu_v3_test_ste_expect_hitless_transition(test, &s2_ste, &s1_ste, + NUM_EXPECTED_SYNCS(3)); +} + +static void arm_smmu_v3_write_ste_test_non_hitless(struct kunit *test) +{ + struct arm_smmu_ste ste; + struct arm_smmu_ste ste_2; + + /* + * Although no flow resembles this in practice, one way to force an STE + * update to be non-hitless is to change its CD table pointer as well as + * s1 dss field in the same update. + */ + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste_2, STRTAB_STE_1_S1DSS_BYPASS, + 0x4B4B4b4B4B); + arm_smmu_v3_test_ste_expect_non_hitless_transition( + test, &ste, &ste_2, NUM_EXPECTED_SYNCS(3)); +} + static void arm_smmu_v3_test_cd_expect_transition( struct kunit *test, const struct arm_smmu_cd *cur, const struct arm_smmu_cd *target, unsigned int num_syncs_expected, @@ -438,10 +535,16 @@ static struct kunit_case arm_smmu_v3_test_cases[] = { KUNIT_CASE(arm_smmu_v3_write_ste_test_abort_to_cdtable), KUNIT_CASE(arm_smmu_v3_write_ste_test_cdtable_to_bypass), KUNIT_CASE(arm_smmu_v3_write_ste_test_bypass_to_cdtable), + KUNIT_CASE(arm_smmu_v3_write_ste_test_cdtable_s1dss_change), + KUNIT_CASE(arm_smmu_v3_write_ste_test_s1dssbypass_to_stebypass), + KUNIT_CASE(arm_smmu_v3_write_ste_test_stebypass_to_s1dssbypass), KUNIT_CASE(arm_smmu_v3_write_ste_test_s2_to_abort), KUNIT_CASE(arm_smmu_v3_write_ste_test_abort_to_s2), KUNIT_CASE(arm_smmu_v3_write_ste_test_s2_to_bypass), KUNIT_CASE(arm_smmu_v3_write_ste_test_bypass_to_s2), + KUNIT_CASE(arm_smmu_v3_write_ste_test_s1_to_s2), + KUNIT_CASE(arm_smmu_v3_write_ste_test_s2_to_s1), + KUNIT_CASE(arm_smmu_v3_write_ste_test_non_hitless), KUNIT_CASE(arm_smmu_v3_write_cd_test_s1_clear), KUNIT_CASE(arm_smmu_v3_write_cd_test_s1_change_asid), KUNIT_CASE(arm_smmu_v3_write_cd_test_sva_clear), From patchwork Tue Jun 25 12:37:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711076 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 0B75AC30658 for ; Tue, 25 Jun 2024 12:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=+X3WjW4RXlZV8/opPZ85LBFlYMENPROAjYdO236yOBE=; b=iDvKfLmkd4Zjmuan1scBW4M/zN kZTp6+kOcean7E4yxqGv7pOPI3xxqgBykvyGDYPD3rwGIskw9CYU4VAjRceFx7CtFL0XJpyag0C88 c3V3DgZX0lxNle+aW61wH5/tfza50SgB/m8jglF7gy04fSNBW/xFI8lsfyvK2hikuiwJ09HHoSvBv ZP9YZFtvrjs2Dpq8hcuKFEXTu6DkdlOBhZjWydjNlS/PjZ98shegv1fZhJnwh/BTsVvij7tT1KsYB TWy9YDyQXRvBSfvVvVgegdBcpagSTpZyk2QjlJYxBR9bmowcymIxuLFUC0cCldtATsbDVu1X8A5CM GpuPhkQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5RZ-00000002o9f-296I; Tue, 25 Jun 2024 12:38:41 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qy-00000002nfA-2MlK for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eVdcUKYE1LHGgKUpeqk6O60z1zCiEQUCbOYSzabRzrwslRUQekwMyxDRbU3MjUJQ5Hw/1wTx0OkjYMG7XkHxm5Q/Y41S/WwsneUC9LvYT6zba24g7CUDfBVGpYpEq3DlvLVyDR+Cp2mLgvuz2dU00oWdHgf3f6iZQDG1n/9gU0f0Y+nT/n2m4aocKzKgqnTmoMSWLJVZo+5ZeyUirSO8UaW6qxTDnztlq5nX59XCqj03XF5MqTZ8v5M7tXyPnEbQ8ie8rTU3nX3qFQGFthM2ZAQFwYphIRWm4P7F2nGQX8Ieq8LcKRotum6KaLedYWn+doHJTehWmeDSo9ASbu29Dg== 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=+X3WjW4RXlZV8/opPZ85LBFlYMENPROAjYdO236yOBE=; b=NeFKEZrAAprlW37EBrDpNShDZaTuhUeR/SLiXWVYEwIfLDQ/mzowUI4nE8CgOSBksauyAt/8fAXUEERSMm4i7TvSzEmrPyvU8jo0efCN99dQ2pBnD4sbHC+nZ4NGBu3fVrhrOLIEjoNJI7uZOgGV2xCfztouy9ttYCusIngV2WVSTCxCTmlFVCQYc40vAwe3srJrLYnigJe0umNW/wGRdoVumN6zb2vbJ+hMPMKbRtTR0EgI9ERt/tW3jrOTQO1fMnEhtPkUxxfFLF/1WMfz+gfrUQuwVkVPDazEzAMUepDbUT+0P9fM33d3jWNY6m6m1AqEz5R/wuKBlB4htLOl1A== 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=+X3WjW4RXlZV8/opPZ85LBFlYMENPROAjYdO236yOBE=; b=BPFGdFPtPtuYKPPDBbG0nA0Z9CGX/uv6QVR7G4+laHdUGi/HEeryh+Z2DOhu0pY8iMyApXtSEmXFH0iZ0MDXaLWAtTLAFwRqVrIlHyf5IbEnA+LFhENi8OfkPtuEUkhOG053P6z9KWAMxYFmxqRjfIlIwSyuA/yQ6mWhHy84D4Jh2xdbIeBQvWvs4GYMIXCcY7JNINSsbOtBThOZDlvtXiBCimWuAySPAUMk5mycrEzta4Y/3KRWSbHd1R2+wQlt55Y4+qnzYCY6oPXH5r6VCYGNnVBBbZQ1yZ7IMENgfQhd0jlHEJPFKi6QLnRh5MpCujPf4N1XFT6VpFobz5L/5w== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:48 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:48 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 13/14] iommu/arm-smmu-v3: Allow a PASID to be set when RID is IDENTITY/BLOCKED Date: Tue, 25 Jun 2024 09:37:44 -0300 Message-ID: <13-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR08CA0028.namprd08.prod.outlook.com (2603:10b6:208:239::33) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: b63a69bd-13e2-4eb6-6d7b-08dc95139dfc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: vjMXXi4tYI7sQIF+0+gGkE4Jbdo3iAqQ+8d4BTwpcVf9lO3UIZGGiM6nAT9xm9CnrNnpCGelRHkNCZUB6BUSC2pwT4ocKOxki3TkYWxsxS/psqgFCETzuYXGGSpf1ph2q9H8pFEGHY3OzLWypJ/+w0HbpfAFY7htpOBvdm66VCxNnzwoB3RuJIl9uWCtxfmfwufBQ0QF10/LjZVLYPNcTJWLmv272W1Ei173ve2/o2y2aIp2sF72mAJ5sZp1nytHIr6rRaUFxqmVwYHe+yKEUhZ0hPotGzqwTYzuzIpJrFa/35JB+cpLcGVz7/8qYjia/uwFA49lTYp8HSEn9XBxQemA/lDtX1XLZ8FjPkUujNWjXAsZNi/I+ZNEt2eSIqdi/zkqGPk58HwZPXhmCLmdrXQiXtAfVsV6NRpmX5ZkQd9F4BosExXAIs5uct0nM8r4A4DmV20R9V6yKJhApxosuw6whPsM/IK1OpDDr82z1+Mh9aJ5rxy2k7p2skR7FasKYG9GPDvtLkB4wnMOgnaOcc8dDYYgDe3TD5r9ill8EfYQtAMJSisqSeM+Y5tAT2YylvP9tI3oiRNz0ni64EBc75LrTq0Xe7YFsn/0Z5a2sZVxVq/xYC9E4LcHF+FaPuDK/V2sJWmwAKYbjV6AUKPxsszGadzP7mHHPK+HW6HKyEOtTEzpXwl4A6a5stHQT/fwP1IAJN/YoCTC7xlEq2YrNC50R6McumB5RTXbNveHgOZ8gU5qgeMtH0k33gLSiIDNeqGAKabG3mjxJfDX5XMCgzdjg5Cm3JfQiIxcwla82in7xCoa3O3lmpSoouefFuCDMR8/67oAUzyacFA2RVZlGDckXl0aUZzeOmP0KU1E16MqNGBiq8Nd6P6NaQNs1eZQWsm5/idRW5yRRBaTDQPRUwBEvLg5TDbSvHuxil6ihsJO8NV9DU1jENFI+xfh8zXpgzjbWaDol8dHHd5KeG56qDMTeOaugCWHlMR/yIP/vHyFZbd5KLeMEM2o1yCUeQiw0dXVtqiAUY9BRTj2qT4ffbdx5/NRZWCmunOhWiHJwzrTkrrUkVYo0kD5BIypfsi2iCj0KO1/R+7oYPAXvzGn4pI9xHbhn5pKLg4S7dEAXykO2CMcf9CHmgB3WYiJmoGtQpv5gfb6AUFGKENFpuUCfcHMoS07AdtMe0sxPDQcjD9Rh1sX08Lwfkygt8f//MSKxMLAtpgTnv8CuoydblRSwZM+rJdET3YWMawSa1oFAKCSWdqjkohzxAvV8KekbjzQyhwMyWshA0xCCGS31JbvpJNyMfIWxXA0W93IyDXQmTk= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Da4q/hgr/7f4QzJNfjN0yZDD+qTbw2U3VXuIUREwh7BzjsT+FiqWIyhEJJMQykTSImvSu3g+8qqYreRiuYvSwKidHtMp9vps5M84LtquedkfUBpY2FyMjuieb7KouPQRra1nRWvHNJT8fCktmcPSGbx/UbJJUDJzaj7F1kIJokfAWYGAmkFcB6o/rbIk7q3vq6QF+4rRDVnIsuLm1gastS1G+frZcmkGWVEnwfMu9d+FPy9wcXwzAxwHoKxN3cotY/tzqgQVfHzLbyOZYczMTLES8Z2hkJm9HaElc28f41HqFpmSWSiQdrX/8YSoon6jCzjn36ug3do84fKh4iEDXy236Dz1PjUe+62nsmlwein9P4iGmdMcK2CkEcUkekvl4+wUgtIBzyq1wQU8jk8oY6libxAqOEp2YMT6sPMftApbJxsdIs6Ui3gVGuIzurF5q+QUdwPYra9+cX8x68sajywv0+/GW8NwCofTXMuTMJYglxKr/C4pb6pUxt8Qs6K/+tLBHTJJhMXIi5brkbeIsjvAxeI/2NpuatysfpNKD+Yy7SYH3doU/I9GfSGoJmyuoYeJ6EBfsbwHU+tzb0asBbGCSDmpHZd9DS8lloIkT8UwBPI87zj9yiL3uglfL5PvvkS9rFUJIJ51nxzE5CFGO5YjgKWWJjLLQFo/61hY2CdrSihD1q4ELzBDM1wqNenaUOXGuBPwri0HwNzycWHPw55hL7ncWmOQYo/UuReRT3KwNh0P6uewvLFj4d7tqJ1QVeYLQ9QQfnC45B9fpMgfYdm2IOSIflYRTw9sUhrABJIHkoFRbJyujnC2aBQ1yAGepOn+v24Tbnvw4lTWc8tIx+vG/8Sxi8+hWaSJuC/S10Q8TEioyM3SGeABC1l60IEqiUGW4dgO4tEvkIVwI2FJU+nNtvGNvqpkbObpk7BEBBF6H/lUA3QtX300WBeKiQAwI51m9HI9Cqhf+iRpwsrgZMm0wAz+Z/mzsXrpR/YeLW5ScUVnjYum2gQ7HKs/4drN6EYSoOeUMeZe3cEoRiK2kwo9ITepLc1onnrDfulYH+YTwPe9slUYaFQIlY+BxXH5MkNxbR0hr2VKZgZ1lwd3mtjFeUoQ6R0IpNUG7k9T3lrgMf7UsJW7ltMGKerwW3gV1rv+TyWnAtH0ea3q+OUYcS42vr30smBj7LLwjNW2Xd2fShl7TOV9pJ908vJvE8Rbv4kWSNuY4BaVUkxAAxxdtxwGyJnRwZyfcGFeRS7jlwRz1bo7EiZRvtNywoYUsMG8Xj5Sabx6KL9D0834SisEIsHv8DPyclxi511et37Mauw77HbHi9WbLPOFRmBPgYQs7JIrBZA9i+eJoj4TXaHClxtWsgggJ7R+JPvzh0fSwbcmQ1vMHgpP9WJn8IBrrPDEoMCCatPKAwVpGbF8vL4Io4d//Oft+1ifSZUZ5fVazwRnETbjJBTRT7gvOXE3U+zN7bzIw6evxFKtpPm63N71g/1tCYm3o4GXlc2SYdxgaG9gzCxTurGgQbXjs92/Qa6aAa96iT+GmNat0tMqCV+csJD1sBmFkG9grqrsGXCwFxwosY1lBbH/w1JKAd0Xxf2R X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b63a69bd-13e2-4eb6-6d7b-08dc95139dfc X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.8234 (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: 7h33LbJiNQdF3HX5RxMH78+hPKe12EHjW04r+fN6jMO5Z3cdhYbVamhj6tSO1yjl X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053804_720818_D767F110 X-CRM114-Status: GOOD ( 21.60 ) 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 Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar 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 10d140a5cd0f38..fbe14466f5f379 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; @@ -2795,10 +2798,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 ats_enabled) +{ + unsigned int s1dss = STRTAB_STE_1_S1DSS_TERMINATE; + struct arm_smmu_ste ste; + + if (master->cd_table.in_ste && master->ste_ats_enabled == ats_enabled) + 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. If 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, ats_enabled, 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 arm_smmu_attach_state state = { .master = master, /* @@ -2815,8 +2844,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) @@ -2828,6 +2859,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.ats_enabled); arm_smmu_attach_commit(&state); @@ -2850,6 +2882,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 (sid_domain->type == IOMMU_DOMAIN_IDENTITY || + sid_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 30459a800c7b2d..cdd426efb384d2 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; From patchwork Tue Jun 25 12:37:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711079 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 32AD3C2BBCA for ; Tue, 25 Jun 2024 12:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=E95aCzlBZGQUhqk24tjR7TaUpY2oFlOq0aA6h/qYFV8=; b=ndQdxI0ihItf9w5md3WokFG8Rf C8Qmqkezt44Te67gj2bZyqzotnOOWQjar2W/YnK3tEgk6Cil14onzvUOPWYgRV09vKyt2OiHUcfYR sIkav/X6ibA1WdRgILux53m1CCZdKFzUEALkDc2E7NRJzCuBgunAcOFB9VcWbvOJnoiuBcSDw7M7J 4MncC2ClTrB/577v99Qim6FqaogPQKJR26LM1Xf6gVpOS/eDMX+EFQmnRJkUp/8ggLX02LqZFRZkA ddLMK5pP0LWU0IFhL9NsICjgbAZRNY0/Lj7SqNIpwhxE7dUm5BA0IGBtVx21rGc8qYXajAR4MZVk2 ZNX0n2ww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Rp-00000002oJg-3x5z; Tue, 25 Jun 2024 12:38:57 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5R2-00000002nk8-1CiL for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eRc/JRkbSbffUuu36IFGwxtlU6MjPfhrO7JRodBLA1RXSKBJp6xCtYTgss6k4vISey5J317N1sr83TcFKjnR2f+NRFmHysn5N7/dU7r/trzYA7AHH/w1mjr2GP9LuVy8GxEgYhZafEcrgVyBSe73ET+80CEzCrcpaY3y08Rp2DLXdrjZFXnLjdDmX6X84+dJ6b4gpBYk2YGhzHiVG4bHE/+YnVsNhR8AdbzKPht9U6Nm8Nu/REWZVQzgDpbkkjyZvr4ODnCnhfJgpuARkEU+BBv2ovLwjNHKc8sMJGxqB0Gr9sSIdqFqADnSX8bNmugUX3WJuw+e+ULfvhTS0lxSug== 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=E95aCzlBZGQUhqk24tjR7TaUpY2oFlOq0aA6h/qYFV8=; b=UIDdbBDUDLsXlMfXEUVTaobLt79lHNn6EjjRM8igObkqr/nEaaLKjdfQpfI3Q1jNv6sygtFSt9Qz4vhtoIw6iDE81ymqzzhR+kNL0JV7rTtfA/B+ta+EIHLpWujv5f8cB3E0rHVYj7kfCQplsJsKAMqUCITIG2aO3ee0dlFvtCQrywaixu8ujIU7kWdNDE5QgnQ8CryHB4dfJz9tpOwHjC4lVz2G+DOEXbjS2pK+5902avhfTgQi1VDTQCkHaHoWnMykLUn105yz6NUO45IGScv/UczxjiZ+//W55O3JCk2WZccuDRK2QHEA6IHLOtjNmLu3ZjZl0LxNepOfdw7+lQ== 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=E95aCzlBZGQUhqk24tjR7TaUpY2oFlOq0aA6h/qYFV8=; b=e2Y9HPN3/3HSZasTmWOzzZhUrFub7RzdXwhb8WwGo4LylH9UlvrjPBdrERUjN9khXfQaBZX7/j1PAmU+o5KUFC9DXtC/YJpMJDlJb27oPwRdvM5b6DI3hEn8RkctWEZ5JzxAOAWcB4qLO2XmUSxt/hk7BPjvfxWXdk4I/uweQWkdm+S0oxOrXrbNxRbETgCDI+56XhifFTIsIwFnyPaRx+92wodFFHHmfuUHmul1btw6e0atUylgh1GGuYh9U80mWvMfJk8986CmtSzqpSTnxEe1w9jBW5aBsbwBZCQBanmlHynH7DmQPtG6U9bOXzYHvh657hBn9KGYg6IZXSF9gw== 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 SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:51 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:51 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 14/14] iommu/arm-smmu-v3: Allow setting a S1 domain to a PASID Date: Tue, 25 Jun 2024 09:37:45 -0300 Message-ID: <14-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR05CA0027.namprd05.prod.outlook.com (2603:10b6:208:335::7) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: 71ce7bd7-31bb-4e34-520d-08dc95139f0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: pKHGIOOMJicn41bpaTJqaeJs5SoSFAUDsb/lsdpLuoZqdWTMD9wDl13WPv9op2LEC2Kd8UEhlMVzW/sMQ34NaLYmHYQwIjmabZxPUMwC5mGjMP2NjdDiqn+fHdqAK4vy7t2euWxnIWnIauSuJYP8ses2/wXEZrbH24Tdb5T5V9lcDiGZpcMgGU7rn6L94AeIuTPupe/D6HU5eB97fRmIPXqRVR0TMzipCAmygeYEMQknniiXBlCgLx+JLmIdVdOIHUUkiX/kI3WqM8uqspjrWhAnm2zJKIb9zakee6lc3K5LVK2cRs/usR7Kvm38QmA0zoO6fPQgTFheTJB2cELkyUJlxqBolENFsh7PRo3gDDwEIuyQ1tnKqGoibWHqWLLmKjIlM9hfvFNfTUt4oD5QpO45gPEd/EBkUUWS0S6gTNHpze35S+V+TkNR+RVrYPZJTYRI6ZbR8W0a3KJLDElR1OqxFRmxJtulvaP0Db592rSFjXzdVzx78nFIAzglje9bxYiwFhmAWbnmZfvyVotKFXYZRiALttdICvZN2tVDx4d9JhtBwl108OkWtgj9YPMffqaoqcqn4Mimk7sCV0WmVHVAV6+8YVolf2HF2SMH746JXuKyy9BBfUH2sc+wrH6aEU80ze9x2T1SRe6VO74HmwL60k2Sitz/baJMMiYXARZIPz/u0XxgCiZcx5/Hbocb/zTcnSWKR4gyKF+K7CjWRB86EWyxCC6mZ2wJZOuIEtJs8Q0haWn7KfdnZa1eGksKEy3f9KSzM/hQdxvAl2JclwEpdapqSrBntSgbIDThMIggLpoGbYBxBKYj6ZNxkdFRaW4T6gUdlhosfTUMwZr647/KvM310zzitJvq6k6OofVy8bh9lsAJKbCnQf4sKMU5IIyh30MAgMlD+JE330OtubTud7ibmiArq0qrawsfx7pCp2vapAhM6M/guk9W68VvnEvsaZ/2u1S9JQFm1bDgWa0McfyhJoX7HWWpEVQ5ZXuJN3I55Iy8/cBdbsGY9H9We7vIsE9l6ILxbVNsB9iLD5VDT2QbgmEv1VmLDrWNKcuyDIz0dCRCfoyaISvioYpgZOyXJx0BFW4TgNO/sVDHBtw2tLLZdHsGXu2yYTphWab7V5sKXv49yTXyhEYZeqWq25askjR8qY3Bnz/g2yHkYxaFYtMQ4VxxU9l6mO9kBNNgKLWTcvNXckC8KAPnqMWIoPyg43zywvv17SxbpGNZB41LOIN3J2vnm3WcDVMXWzw6ioaKI7dFxaP7dkGNPhaVk/G8+tQBDZMsyN43a6D0Ez+j7jGYEIQUbvzTUuwIl2k= 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:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OlAs4fW8IkQ7oxFu3IBPYtgObCgDIRzirnpkTc8PkMvHBhfI5K5R+/voXfMtVrddFix+zup0jeoFlCSrFKLXcq18gzHKDNACEzCzu2tpWyn/XIsCs9qS2uCRF446KrOKJUyUy+qrrHhfNERQQmkVeTG6pv7N9snI9nULoDauDxG9yCD6y0GrkaSoyk58dYoNC90o6uyp+Za7YUZpn7O+UDFjQ/earl4bw5jAB28KLDEbeA1TLrV0as2GuYlCwee44wtUirslxVaV8TiIftAt2/UfoOMRRgkXiQKeJ1zy83bOGzI3mMnp9rrUU4KzFyxxQ6BksWYKxnXEXpqQfiaOAhz4/RzhE77rOpkt4pBVZkVsjn3i/2XpRfxvu0qDFWlNfBcgpIqsojkVsy9rsrEs34BStiFCfFe9h3x5IttVc9NcpYq2TIaPYlefXYuJGhXDizduQjaG//KvtXeGVk7LZzV/8QRrfchs5C5WnLu30s16PdYyZsum4G4xvCSdJdI487HsmFc1A7Ff+/ptlLrImRTKzUNbQpAXTjyvvhImheQkgNmWPz/D+EXNFdVs/xNJ3ht0RYYfnYLN2j/lq/lWz2hLdhJSK5CSrspqsGyl1vYP46y636sFMZ3+0g1M2Y2cqY7+DJmNOBlBr3I6vA/aQXpc0Vj9ITmVKvI9LMbxVIrUGa1JlbhQqgkYL3MwXZatKJxPuVfPD465MFYxliO46Esi/DZab5sjlCg2gQhSQerVK43FsfBgG4QG2wTF/x+2KKjl1m9+6xJWqrOx4mW1aXVUIXEvgQONEtb1lThuMhJZU+9sfcDfE3R1727V14vSWYVcxWnPtbM5sHu/A+oq/TJsCyQWSFCWMaXzkxl+KwKP5Mt5ko0AcXHSeOC+2zbQpObzmc+W+tIKDck85t0+ycfAK/wq7Zs44ojgehMBdyfiU1z/Dgn5qCwG5ieoAT7GwSSw5A9Mn9vX/CxybRXxixPoFMlZTNT2aPAWa3zLVeI2wLRcXd3x879wQQresZbOOIaDUgoClnZirAyjg+r1Ag2v04XvQvxC/oV/N/FjbRF4WYqPMr56UhfE0uQKFtcF7X+BQ438Nv3CmGY4Rse1gOGaTo5abQoeAlgCNiSEG3CvIAZwCBz5JzXm/eoBLSAA4g3RNgfwJhNJIojW3TZhHI9JFzAftV1cJ6TC45UishG/Zbef+kzv5/dfXNrzxOYPfqAug5OTgzb8BUF9b3a/4yc8+Jd2mqRWK667MnH9WNler9rdDQcU6b8ge6b6DLpJzeSIctuzMYcaOMIlu1e3vm4t8NoeGZVLq374+zrIm2xVTkO/qggOwxqjcEKFFE1KZ5n3WKA+RT7xFPTElWx6hpY599T5eayRakDu0qUJvTW95qupw7mkfcito+wztUerjzyHKewbQ51UA+7tRYCjgf+yEp0sKMMoXglUGt3JBvGI3EYNP3kL/cWPL7XxoUYYYnGuGkakdL0aVRpjKpx3VVk1GnlTnVa+mdQjaPzUPrJYR7UuiEO0p4DMIjP7PdfPfIrsu9x8LYAvVvXAdq1D1uDIGRuZPuURfk3T9DyiwZOoESho3teeWmoEEH4AI8d3 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71ce7bd7-31bb-4e34-520d-08dc95139f0e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:48.6318 (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: vzFx5WzXhyqWsCHz/iRRSuVA7absWbOVR/J400Q/C7uNs5S0ZqnjIFGh6jKPrHim X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053808_459479_E5D19D94 X-CRM114-Status: GOOD ( 17.14 ) 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 The SVA cleanup made the SSID logic entirely general so all we need to do is call it with the correct cd table entry for a S1 domain. This is slightly tricky because of the ASID and how the locking works, the simple fix is to just update the ASID once we get the right locks. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 41 ++++++++++++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +- 2 files changed, 41 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 fbe14466f5f379..1e8c996a4be0d2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2798,6 +2798,36 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return 0; } +static int arm_smmu_s1_set_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t id) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_cd target_cd; + int ret = 0; + + mutex_lock(&smmu_domain->init_mutex); + if (!smmu_domain->smmu) + ret = arm_smmu_domain_finalise(smmu_domain, smmu); + else if (smmu_domain->smmu != smmu) + ret = -EINVAL; + mutex_unlock(&smmu_domain->init_mutex); + if (ret) + return ret; + + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) + return -EINVAL; + + /* + * We can read cd.asid outside the lock because arm_smmu_set_pasid() + * will fix it + */ + arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); + return arm_smmu_set_pasid(master, to_smmu_domain(domain), id, + &target_cd); +} + static void arm_smmu_update_ste(struct arm_smmu_master *master, struct iommu_domain *sid_domain, bool ats_enabled) @@ -2825,7 +2855,7 @@ static void arm_smmu_update_ste(struct arm_smmu_master *master, 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 arm_smmu_cd *cd) { struct iommu_domain *sid_domain = iommu_get_domain_for_dev(master->dev); struct arm_smmu_attach_state state = { @@ -2858,6 +2888,14 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, if (ret) goto out_unlock; + /* + * We don't want to obtain to the asid_lock too early, so fix up the + * caller set ASID under the lock in case it changed. + */ + cd->data[0] &= ~cpu_to_le64(CTXDESC_CD_0_ASID); + cd->data[0] |= cpu_to_le64( + FIELD_PREP(CTXDESC_CD_0_ASID, smmu_domain->cd.asid)); + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); arm_smmu_update_ste(master, sid_domain, state.ats_enabled); @@ -3376,6 +3414,7 @@ static struct iommu_ops arm_smmu_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = arm_smmu_attach_dev, + .set_dev_pasid = arm_smmu_s1_set_dev_pasid, .map_pages = arm_smmu_map_pages, .unmap_pages = arm_smmu_unmap_pages, .flush_iotlb_all = arm_smmu_flush_iotlb_all, 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 cdd426efb384d2..91ec2d49ecbf2e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -801,7 +801,7 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, 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 arm_smmu_cd *cd); void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid,