From patchwork Tue Dec 5 19:14:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13480662 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 9A007C4167B for ; Tue, 5 Dec 2023 19:15: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: 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=kQ/b/gL0YAUErCa64Zw8Mh0+vEr7jcyn+LcT1qb0Ios=; b=vRqYsol6Z0Fe89 frA9GWEi3VSMRIKeI6+fFCOdM7v5I9fXbIiecu4jqhjVv/VjpUVuvscHjsbh6mQsFmWkSdbyLmpc2 pdClLVQbFvSTXGAr4FOwLMatiS2iklZtHyvcL1F9lfA3ieYzWpbfOURYKvT46OFa+/HXBfv7rBWYW y5bu14KMemW37nQ8Ks/oDKe6L5kgmxoN2I1FvEL68GkAcMsyEcAejJAR133UblrpzphABzxLafvAJ 0eIfb6Nz/EoEvbdcpcp4KGm4z2YaFLaFbCkwJ6IXvyrs/7gWRaVKxB64gT1pJ3YmAoKlkhcv1m9YE ih89g+MFHX7kjPdDkvlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAat6-008FIp-34; Tue, 05 Dec 2023 19:15:20 +0000 Received: from mail-mw2nam12on20601.outbound.protection.outlook.com ([2a01:111:f400:fe5a::601] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAast-008Ey2-07 for linux-arm-kernel@lists.infradead.org; Tue, 05 Dec 2023 19:15:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bT0oHE2LrpaXLkTWMNw3DVsS41FAH7/WfCv4pVx6LJ3RMo1c6peRk2e4iK3mJDjY5oJxQ15DV+HIeTCSAzqDOW74bXC5UPNKl1u8rbUxdID+eEfN8yr3fpZjhfpXRI33XcKRYh7ofxC0rwW3stkrcbNFQswdbNUqXKaVHmc/Lc4uATsoMJ06B01EV0KBNDIm5+B3acngIcSQZ0n5B5Owtet/ZjRdxF6gR8pODB23yxXNnYWdZvoHeUutgihAp1+foJZQRwpknZvLlFS2P3MSdqQYp6MNiw+MNI9v0HjtUtZERElXYcAcEJwR5ToIqco51hEs1k9uOY+AOhvKDhHnYQ== 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=DIo84qe+Yt6Sh9dIF+rEefWutZVAHA9U9OVGhmn1XWk=; b=lYbOaS8g8qCVK9rvOQHqM5zl6nVvjWi9O+m95n1UvGwSrHh9NvzpzFBNaZ9t0AB7gBOuLG6ZW2NzhMZTSl8QJCSYS7JfvIrWH7zOIr4bqis/8GDlYyje2SfzYxiDSlwVnpAIsg6nil5YnnLbvQ//wZggLuFd1q0Q6DHiIPVPTqm+ZZxlJZ7M5/2kwWkZBs/3ejBvzjsL8NbfSvaaetEezptetMhbllE4rL9GLwaxf5aq5/bUOov3VGFU0c7N4C0BbYll5Cl3bYVZBDhy5OvPIhKGaQLYsrO78x+GidH2lnrI0IZcg1ym/3jZh2+NWpIt0sq/Zgw3eH4vRM/GAIKNzA== 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=DIo84qe+Yt6Sh9dIF+rEefWutZVAHA9U9OVGhmn1XWk=; b=kQdj/E8kFnLIe7STLz1uvEbMUHd9tc65+f8mMRZ/yEKLi+7WXRUUS98M/F3+59NIRvPQgWELLFRkSdfIiLqOruGE8ss2YPnpTgaEaFxBmjlapgZXZuflHHfbtb4XTrSP2nzUvRz9SPOvUKxGXX07Mw6drCKYfsl1O1x1qvTPU6hFn26aNORwK24odIEzk+0qpk6AgXAtThIMEHtg0d63kvpoIklBmUbUYgJkLWoM5S270N4Rvtl3vu0AuS1Zu1muPCGU49GB/Ec/+9NvZDT4SVTcpzky0yIxc8B/arBhCp4Hrju5UXcI77TicZm0rhmHo+Isboy9aZOfSVik0ubsvg== 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 PH7PR12MB6588.namprd12.prod.outlook.com (2603:10b6:510:210::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.34; Tue, 5 Dec 2023 19:14:56 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.7046.034; Tue, 5 Dec 2023 19:14:56 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum Subject: [PATCH v3 10/19] iommu/arm-smmu-v3: Compute the STE only once for each master Date: Tue, 5 Dec 2023 15:14:42 -0400 Message-ID: <10-v3-d794f8d934da+411a-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v3-d794f8d934da+411a-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0040.namprd15.prod.outlook.com (2603:10b6:208:237::9) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH7PR12MB6588:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ade9a41-6413-4d42-138e-08dbf5c67545 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OkqM7HDIMux8hcdGOH7xJiM46URQtMizRUGyJxleGdVKtMzQXoxrz6NfY9dS02m7CMY0GOd7c/0GM60TuVveDG6zm0DMRiL1U+iIvu3RR+ocNMAI9obbn7CyrZzswnAM7oktesT0pgpgdBmuNXje/DWQ4Z7xFz4Whk9W4cnQc3lum8KOMQJTVq0G7sO6VgzOy2P3fia063ItzTeurQvg6GU0FILw6Z7/rGIutpDVM1civMCy8vH2JW4xZn3FqNlbEbsHulvODR2GocNc4i1hFVnkbqa+d45M/L+zTCbkIalDxPxXFPR6MScQMMr3S1vgBEgu6iE37OjgtCF3hi6a+hRi5Ww0qpDSJCrfKMliGZK/MIia5she1UkARetfU4kUGVXHdxMqA1bFcUGrQnSf904Aira1lkviOfKfYv58KdlSQfgaH9210U5nLlKumNF/i8E075S/dqLJ+3JuuoalEsiNPz/JVsZ7EfeD52dbMxWyxb7PoNzpwTUo6MQiKowDrmHTHFYZ2locCZSZm7OnnGzxFln0SambHDgr4CZjX6XoL1nh271q1C/1ju3j1Ste 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)(366004)(136003)(396003)(346002)(376002)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(478600001)(6512007)(6506007)(8936002)(6486002)(2616005)(26005)(6666004)(54906003)(66476007)(110136005)(66556008)(8676002)(66946007)(4326008)(316002)(83380400001)(38100700002)(7416002)(36756003)(5660300002)(2906002)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qgO1PASRBBrtcIZwe6H2uH3qSM/9323Alym+KJAk3Mvwigq9aSgaqw5uLMQEliK/eL8UJZblHxj9es+YxZuSaJB78QfkC4pTnVU841V0vfGUZhoQKMrSs6gY1m5RpV93wXAwqTEd9IRXr/rX2uYWAXTBwj9f2wfML/3rkGAh/VbS/Zjbes9z6x/rlIrR0sEsS6Ouz0ZhHq8/JK8J3PROkz+KgyF/J1ZGx0bl8iuahuBgcWYkWSpQahShSMWlMWcvyevlwZoYe9G8x7pZ5ZtVYHThilEsuaD5wDovYofpU5Ai6yRMu3LweYZPGlCDyEI/E6TAI1EFAAI7+ei5BSjs+KhcFZm+wK98fenwq5ifTXQNTgEqw/ajvhb1Od2ovM0f9QCOtpaxhEDpQ4m+xa6PtRVMkVMymabt50MIB/5vdhmPP1NM+gd14mUCH+G4tTc5Ihg04Fh9Vzvly2q0VFsu2cq/81IbKcgn5uX41czNU9ciUcNWGPRttkzEU9loN1UG/2dCnD/5tr1mGdZdz6AOHUHn9HCYCiMkzF6zjI6fc8jkYCHxfMmPYFCfReZEGT5G0Fa0Z6tLKki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 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2023 19:14:52.3980 (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: ZZttRBBpsX0Qsha/jFPtFY3jU43D00g/uC1akwA3YbjcgLkcymReW57EfLi3L0CS X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6588 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231205_111507_113624_2A02FB2A X-CRM114-Status: GOOD ( 16.16 ) 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 arm_smmu_install_ste_for_dev() iterates over every SID and computes from scratch an identical STE. Every SID should have the same STE contents. Turn this inside out so that the STE is supplied by the caller and arm_smmu_install_ste_for_dev() simply installs it to every SID. This is possible now that the STE generation does not inform what sequence should be used to program it. This allows splitting the STE calculation up according to the call site, which following patches will make use of, and removes the confusing NULL domain special case that only supported arm_smmu_detach_dev(). Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 58 ++++++++------------- 1 file changed, 22 insertions(+), 36 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 c375da195af713..0c1d70b8f325ed 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1535,36 +1535,6 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, STRTAB_STE_3_S2TTB_MASK); } -static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, - struct arm_smmu_ste *dst) -{ - struct arm_smmu_device *smmu = master->smmu; - struct arm_smmu_domain *smmu_domain = master->domain; - struct arm_smmu_ste target = {}; - - if (!smmu_domain) { - if (disable_bypass) - arm_smmu_make_abort_ste(&target); - else - arm_smmu_make_bypass_ste(&target); - arm_smmu_write_ste(smmu, sid, dst, &target); - return; - } - - switch (smmu_domain->stage) { - case ARM_SMMU_DOMAIN_S1: - arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); - break; - case ARM_SMMU_DOMAIN_S2: - arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); - break; - case ARM_SMMU_DOMAIN_BYPASS: - arm_smmu_make_bypass_ste(&target); - break; - } - arm_smmu_write_ste(smmu, sid, dst, &target); -} - static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, unsigned int nent) { @@ -2387,7 +2357,8 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) } } -static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) +static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, + const struct arm_smmu_ste *target) { int i, j; struct arm_smmu_device *smmu = master->smmu; @@ -2404,7 +2375,7 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) if (j < i) continue; - arm_smmu_write_strtab_ent(master, sid, step); + arm_smmu_write_ste(smmu, sid, step, target); } } @@ -2511,6 +2482,7 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) static void arm_smmu_detach_dev(struct arm_smmu_master *master) { unsigned long flags; + struct arm_smmu_ste target; struct arm_smmu_domain *smmu_domain = master->domain; if (!smmu_domain) @@ -2524,7 +2496,11 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) master->domain = NULL; master->ats_enabled = false; - arm_smmu_install_ste_for_dev(master); + if (disable_bypass) + arm_smmu_make_abort_ste(&target); + else + arm_smmu_make_bypass_ste(&target); + arm_smmu_install_ste_for_dev(master, &target); /* * Clearing the CD entry isn't strictly required to detach the domain * since the table is uninstalled anyway, but it helps avoid confusion @@ -2539,6 +2515,7 @@ 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); @@ -2600,7 +2577,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) list_add(&master->domain_head, &smmu_domain->devices); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { + switch (smmu_domain->stage) { + case ARM_SMMU_DOMAIN_S1: if (!master->cd_table.cdtab) { ret = arm_smmu_alloc_cd_tables(master); if (ret) { @@ -2614,9 +2592,17 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = NULL; goto out_list_del; } - } - arm_smmu_install_ste_for_dev(master); + arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); + break; + case ARM_SMMU_DOMAIN_S2: + arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); + break; + case ARM_SMMU_DOMAIN_BYPASS: + arm_smmu_make_bypass_ste(&target); + break; + } + arm_smmu_install_ste_for_dev(master, &target); arm_smmu_enable_ats(master); goto out_unlock;