From patchwork Fri Jan 26 18:15:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13533243 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 A2717C47422 for ; Fri, 26 Jan 2024 19:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uUWA51tjWVLAXkyFXFDfAFVvFo+bMrcQJbWoTt0qpMU=; b=u2AtJf/pTPUSDn QW4yq6HwLNueFLxqSPM1LwHg8kHv6CGrxv2UxAXtR0vrTj/LrQ4sWTNhBTaG8I1pXbGB0EKwupKzP Je9keYtB7bee3N9og89IdkZZXX7mYgwzyQpljFFPhI6qHtMjKhP7k3x2bQ/jH6a7t0qnhlzcJi8OA KQZfBACyJCWzFnapc8hWpJxtwsm654VDSTUUwpHUcn45wCRKTDyXRWrbk8pN5v8XQGi2fPxs1wYcu VAPPTyMZQ5OKtg5ClNiT1TV7+9Z9qnQ2IKKZUa/NzePzd3kpjnz9+vfyht4LsJIhre94h+cTB1PMR fJWDPqyziizQq5UCYW/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTRkC-00000005C1i-0F8n; Fri, 26 Jan 2024 19:20:04 +0000 Received: from mail-bn1nam02on20600.outbound.protection.outlook.com ([2a01:111:f403:2407::600] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQkC-000000051ef-22M7 for linux-arm-kernel@lists.infradead.org; Fri, 26 Jan 2024 18:16:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LuayLAXZ7zmaFNjxKOyQ9fWSo8Skgwwc0NXiKDL1vFAu8J+6yX12sURGfbpDXb1jtz+J91iZKJblZ5xw52NmOj/mPwqC4RCFTIHYWbg0kAEufoXy5ASJopsH/I4eGdrUgDtJjhELnK+p4GjE5UI2/FpIdFUsa8xdTDcMV0yWbbwb3gRABFbtTX8KyjcLXfSN1SZhiR5zcCWuFIk6f00GHGCEt/ailSODmEOyiGRzNLIXYfIm5ZW72ksd3c+5co6cTg5kM66R7K04GIx4MVAREtwhPWEl4+n1j06na5Q3141uMSh/S5QnMGzl93OGZBBEObOPM/kn0fzvU0Kjr/5Ovw== 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=EAI10d1ZqPf6FpJhcLv8dUhoBM6CfFKGFC/Kx3f70lc=; b=hZCSB0ckQJaV7SrHijqN44gHX6Xlo7Txy1NsAFKdV0Bow6ggow1OZFMyFiyvXRKN14CglfGppThIsX31Vjq6jHSP+tkdj33ApITkRWQLWbWmbIW18L1RM6/Yv4M4j8KluakLo0hhk5zRnkum8vBsAIaEGtuw62udWfekJmbp0Q6zGEXXt/QtA6mRo3MeDUx64njwlvwVbB06PZqSIk5VR03HFIJ+8Rwnpf1WyoJG/dNGxFHijVWD0+p083K5CCDmobWuQCshIJSAszT2fiRDHooJ1fPRVKB0Ec8knvfAjD2LKz2fWYQEoze02EOvTqQ/+CTvDcF90IA7VQgB6ARi8g== 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=EAI10d1ZqPf6FpJhcLv8dUhoBM6CfFKGFC/Kx3f70lc=; b=e7FELPIeCMMksX5FbHUOGlBjqBps1xzyvTH8eNFqhOQpt6laLB2D4/o6khNeW0TQKKsHYD2FPQSAlxwUs3XJr8sISnUxyD/Eh11mJWP5VFKRFx+6ItmOpzOWS+0GFN94ldcuSFM2PiXw5tGw1vc6IwPhzorzykEsKo1kCFwrzjfkfRbGRqQiofrfWw9cQuURDGawN8rcm/c/MxpsUCHdO9Nv6HupM5kMddvJrpmXPmObIMNIE2McqrsWRR28z7jlggZOTM0Efe0EqFEw2wvtGTlX+gCzAzkPP1NjjvSJHkVXT0mCMJ8ognQTkX55JFBt0dqbTTixJ3Jy9yAJAhULUg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CH0PR12MB5186.namprd12.prod.outlook.com (2603:10b6:610:b9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.28; Fri, 26 Jan 2024 18:15:42 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7228.022; Fri, 26 Jan 2024 18:15:42 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v4 17/27] iommu/arm-smmu-v3: Thread SSID through the arm_smmu_attach_*() interface Date: Fri, 26 Jan 2024 14:15:19 -0400 Message-ID: <17-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: SN7PR18CA0028.namprd18.prod.outlook.com (2603:10b6:806:f3::11) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH0PR12MB5186:EE_ X-MS-Office365-Filtering-Correlation-Id: f3c7c6b8-6867-4c6b-e847-08dc1e9aca0a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z5Jpqq94yXBEFshrR30jSjTL3Vug4nikrZYmANMoMxFOF07qtIA2zUX6oBN5LCaGdXBwTtEiYFVE/X/Q8p8Oqc6IN2DBMiqNDv5CzJb3hjx36PYw8u39IQrtiPLnDinvyApN2CjkQPJId02r8zDPFgUsE1eNej0KLQoK9Nur6bL87aAHhEDDeNdJi2QAtt19xCcHVSF5UO/s7+YRLNXmGDWoCx/zLd62LNQN4h5PQYdiEAVuzZL6SNrtu8wckJYD9NJ452fzkrflLmkVeD0f9VckU+C5ftxWi1ZWOl9d/r9Oqgo9QswGg+BeqD4bg5XolkZw0/PJpn3Zwn1axF0PWnMuZ7q/y+qt/qGPtj28wfVUY8QwR9hi0bOB8aAKYDs/2MecsqGZonorfumumc693BJR4DwRSKnJ6U9y++T68jihYkZEQi41qJ3y/hwqtrKJYtE1GqfW6cJ1V7NQmUct3dbFvDbrQAYWtRT+1e5AGBZVXaXks0rS2P0KurgOYrU09L8LIst0mVOJbXOJRXlBrwLm6UWkj5YcP7qV4yS7ZHeBog1kLzlEm+Q3yCDmpQ3Y X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(136003)(346002)(366004)(396003)(376002)(230922051799003)(186009)(64100799003)(451199024)(1800799012)(83380400001)(36756003)(86362001)(8936002)(8676002)(4326008)(5660300002)(26005)(2616005)(38100700002)(316002)(66946007)(54906003)(110136005)(66556008)(2906002)(7416002)(41300700001)(6506007)(66476007)(6512007)(6486002)(6666004)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gbbJG9P3LpR+e2SNP2nmCeN9U9mzHxszWo/aenckQXnNGjFHyxk4QGAR/dA2RC5cQlE+UfvRQ7yuZ1qvn576T+0D+wxIKV/p78kZagmSJ+ymEe5hVxes8/tG1hAotfDq9MpQVgktjeb4/jsrf9rGH6jAXvrv63gvlSypNj7g6D7bl3b0HAQWQGSDxpqOgkwyCeZS9v1rCmuJ6pqbtfyVro+IRrgMF9Ie/oCEwF6HbhgfCTXVwNvUoGSzsuINCzRly5/x6tI4gQngFIvozq5dsN4maVtPtYnEGvY7M6N44O3OQGbdEdO4ztt6gfL4QT00OT3UZaitYDF6PaTgkaRpn/dfV4OV356KQgvnVB26yEkK4S3PSL897E1swYfaLZwK8qoYdmYK0fskx2TQpXfRcZV6+vXfCqCOYexwtQ+dp0lIpinH+Vgc98Af93OTbqHN0QvW+M2LEPMt/LC0GpzxPC+5FOKesN60bci/zMz7xXrVDQ2VEOGt4sKN7naV7KySnUEMohm0UghGiB3UnP6UxFCCXIJuQL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Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3c7c6b8-6867-4c6b-e847-08dc1e9aca0a X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:15:34.4350 (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: jltUHbsdPCFSHmUT6GXjct4dlbRC/I/mxLTppTjeBBpb3WhAUOC8pSvYYLgAB23n X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5186 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240126_101600_659111_0991CD81 X-CRM114-Status: GOOD ( 14.98 ) 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. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 28 +++++++++++++-------- 1 file changed, 17 insertions(+), 11 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 0c134d535401e5..21b0ab9c2ba763 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2013,13 +2013,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++) { @@ -2506,7 +2507,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); } @@ -2593,7 +2594,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; @@ -2603,8 +2605,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); @@ -2617,6 +2618,7 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, struct attach_state { bool want_ats; bool disable_ats; + ioasid_t ssid; }; /* @@ -2648,6 +2650,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_master *master, if (!master_domain) return -ENOMEM; master_domain->master = master; + master_domain->ssid = state->ssid; /* * During prepare we want the current smmu_domain and new @@ -2700,12 +2703,15 @@ static void arm_smmu_attach_commit(struct arm_smmu_master *master, * SMMU is translating for the new domain and both the old&new * domain will issue invalidations. */ - arm_smmu_atc_inv_master(master); + if (state->want_ats) + arm_smmu_atc_inv_master(master, state->ssid); + else + arm_smmu_atc_inv_master(master, IOMMU_NO_PASID); } master->ats_enabled = state->want_ats; - arm_smmu_remove_master_domain(master, - iommu_get_domain_for_dev(master->dev)); + arm_smmu_remove_master_domain( + master, iommu_get_domain_for_dev(master->dev), state->ssid); } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) @@ -2715,7 +2721,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 attach_state state = {}; + struct attach_state state = {.ssid = IOMMU_NO_PASID}; struct arm_smmu_master *master; struct arm_smmu_cd *cdptr; @@ -2815,7 +2821,7 @@ 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 attach_state state = {}; + struct attach_state state = {.ssid = IOMMU_NO_PASID}; if (arm_smmu_ssids_in_use(&master->cd_table)) return -EBUSY;