From patchwork Tue Aug 6 23:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755489 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 5B92EC52D6F for ; Tue, 6 Aug 2024 23:36: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=CfyBdVA/x16kGwnKRbwfMRQ5CJ0bzDTpS4paTmqFNMc=; b=ZEisgvEQNyyqCqfZEMFHb1Lp1p W8BmWcb3eL75RcsYTtsd2OFnsNy/xMf7OSJj2+wApTw2+ei5kOevnPWmNmoPJepYNMvns5HTao+by IpQFs/4VXRb9ZXKvRZKIczOMxdtl925YhjTLf6DIGTVmzXWkqjY0LkeGaK6qc9QgdsWijVgBSjxdO Hb8jRnviYiJbRAoFh0HXDbatGQYAnfWlHE5KPBlc4h3U7xWnBgLrPzFm1JjQDQlqQMfCuNnDaNY79 6kwxhlxgZDBMmDUfvS117G8FXvz36ovEciLL0kCY3AH+iAWbU4OzChRo/mhVYLZFQ5Izbl/fVwqiR ng6MIyIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTjQ-00000003Kxx-1L48; Tue, 06 Aug 2024 23:36:44 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTeh-00000003Jil-03x0 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lAv2AsHA1NiHKtFYW70xkPWbbVc0KgJN289DERCPioFFhF6OfQnIbulBmSQd/n6Rgvq1sRShdyFnRrAnnP9CEadpPRbTethWNhi8jsHA/P2iZiYZ4/v7TrZn9mvxRejmE65MkYzV8QjQYQOvUosmO0/laERvwIFZz6Tt/F5iraNVL2vm/YpidD4rQZZd3DR3+sLEitLMWxzgjHknkWMotvS1IdK+9xLWsw4qkcYV/74vP1TKXgGyho43yDLq92aonV0+1feJy2Ay5TB2em+bFqqIq/73evGZdzSQIit2Fv7NctmqZhFcqp4XJZrXCU+0tUB3Lr9w/Bu2P8NxEZSHIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=CfyBdVA/x16kGwnKRbwfMRQ5CJ0bzDTpS4paTmqFNMc=; b=kxKYlvvofUgp/dyWOXYlAxIvoaLoAP3tu0PIicQA0BDwvdKT6eKrVoMVa2M6hFRwrLDWVp2NrLtDsTVhHOUhAKpQXBWCHfgVLsX5xgl7gnWflFoG81xtkUKkqxzootRWE+NBYhbDYfA1C+pXAYOQn7i1OvjqqHUzw7ArnrldOswgV8vX6Yj/Sk5Gr8lu4pk8eym7kdIe25xebpJCFDHEIfV3BcgJnukfgTaehw2+S1UoEIm/68X+wFADBMOl+MdshIajoPzIR8hNS0yGZChEgNph5RwZRxqcpGBNAVm8utwpKd80Zv8QODeowj1WQQIj2ShT81VO/ykxZnhxK75nsQ== 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=CfyBdVA/x16kGwnKRbwfMRQ5CJ0bzDTpS4paTmqFNMc=; b=m+pAYo2StUWh/voimbRoFdZMl7grkZ5de2PHSr2JfjqU92mf+lwsJSBEeX9wWJlF9XP+jPJmFT+xG83HNbcTqvq1qBY/Dqxrnu5ArgzZZXYDGDjX/tLjMvPakUbV1OtO0WTSisxDe0hj3j5oYZLcdbpCUbopjV6ADNghkMnVKEeFjH6R5p1teBLz3ELyg4bwkRdCUX+ab+P6GA71+b60coD+ivwUbht8/QRdse4BPMcNVUXWUzzBOssWQt+GgZOhY3BzQM5s8hY1CgJKUPRJ372lbV6iKHFKhsMMpf0Jw5C4+JAE029F3cEOmSt529PkeBufX90q/IH7tAuOzxEh+Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by PH0PR12MB7839.namprd12.prod.outlook.com (2603:10b6:510:286::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Tue, 6 Aug 2024 23:31:32 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 1/9] iommu/arm-smmu-v3: Use the new rb tree helpers Date: Tue, 6 Aug 2024 20:31:15 -0300 Message-ID: <1-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0089.namprd03.prod.outlook.com (2603:10b6:408:fc::34) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|PH0PR12MB7839:EE_ X-MS-Office365-Filtering-Correlation-Id: 94bf0f7b-5870-4a0d-e50a-08dcb66fe49b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: rff6NF0ATZ//aEyoITPVxfCq6QqAMKMW6xzH849PtqTA1gx6SyxqrOyUm7TRMPp0tsBWh1kHnlpVhWdp9YQM7JNu4EFmbKvnYrGuqsa255m59ZtjM0V/7tmv3ydQZsjRWquy49eGB1GslaOI+UawLSPvmTDP4WkPu85HPCQbn7mdjfmGc+g3T43WAgnM0OEKwNmEDfRi22Ue2uQQu9LjtTKrMevupFoxHGD4n8RZp/qAjbFrOUFIUe3D2LUyyQ5ZFVF9rs6Y2kNjtBcI5GZzJWReOmI27ANQF44D37lo/dZ/JKwR3Bokd/JHylmPEFwpXOfGs8yMtcyyUg/FcCFfes1pbhuOTXTpgd4CNzRuTci4r+P6NH9QT/24y9Lo+N+9eBoSrdzsiYvIpIhyQ9UgdAhDnISRfOfPP/pcs2C+/zQKwxrpG5hdyVO5hOR2qhatTxuIqC/mHZ3R157KcGLykkK8XXyeey0HdD2JngdWskzPP556K9MuIAB4zr+I46iWQU98kWw+bPuNQBA0+edH4YvenzL72Cj77lr2yssI3Q5r1AR+SRpN6j5e8W3wjGuJEJ8LGkRMNQ+epiFYo8klf8YZAe0jQKkQGAqhqrZwftEnpxpRqzmcNmxH3soOA4t2H444nNxX35/01iRzncIu4PyU7MJU38Ps/CD9Uk7laCt7vwA7/MAWqN3Wl+FUQw4p/gbkUzgDqr2TeTXOAwZLhihVfA/ynjAappwHuvFHF8MTQf9pOL4TJb27iFoMEyDMQcEOn9Txvdg8z5yWmRKE5UY1oABeeg5biioEf69Ar/SUWbrMJxAAAN6IfIOC9rp+QWK0m6wml9WJ1GeVUGOpEBbhQ8yrkcfatgW+IGnGbCapud1lTXVWlkxeZqsO6lUYaxfnktB/sRm7xGrPrc1hdG/xWOZ9aPSs6YXhEWARrTGEqD7nWdiL0hphz6Rp6pZX4E+XB0Grombn2D/rxAw7YgNUNN2CTXwjm0xHNyM+kYW1whoZCYfghlXr6u/ZGCtWL0D1liEhiyvZ2r0L9pEajI1F2WsWv2+hl06qISE9cg3gEzoJlG4lZcPlVj/1YejD9N99xhNLlYNG+Gpn3HARYzhDWae7dUH904j4Mmrh/1T6YDp7ZY5z01VPzvF5xK2wExJuKPPfVPH81clGt5WCpK3ktQQbFQbUmX47S+8OQymt94ForTW2/g5cc9WOBsEr2L/Gp61JT0xlDRZd8WCDIkdyn91TbXOpwYfbZSr15+vnmOwZ7G1x2ixEeAz5xnTxbrOWJG6Sh/Zeadn/CLenQILdP0OY4G6ci+U13ZDx3DEOa2NhVz91ckDUNhGryrriBnzbd15TOX8qRN3KhL/AzA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1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TgHzSPfLGs9nhtMczQ/52l3IBkP7K4ygtwuOuvqlYystbwrQhhwEU3TSW+UQo17HSqNqUNh9lGPgXGgd7xWj6LxAgS486IuNLtZPWQBXDaqlPuNfBt4QWP7Bg9eJr7u2tdTdV8WOVf1RBzZg093lyEhLNja/ABWfvEeZeNsURvs9pMGsVMqiNbUQSaygQ58o0RPr/iUeRYBOqBM41uH1oTSV+F2lKGnhNeB9wvsZ8QIfTWjGvdJ9Yoo2++ZCAZa0Hith8TTn5XOdHuUPyNmN7InGPXl1nVShjuw6YR9bYfBeygC/4pKLQhZEjcphhh6QVHInjzy10YkxguD7WDvbPwkWUDup7ISabZlYNvF1jCusTSTn79RMlcOw9qvgCKyeS+8Ex8oY104ykIXLdl4nGTXeclO9tbuIReXpBhae9m+Qbd+71GH6Zxd/hch3JY+G74so4IHNxL129ikr/omk0iQMdl2uTMNFPqtlO7t1CMzsqBs0M8ZVzJqkBfClZluiAw3NTKQV4Xj2E70doMA2g9v48pY5+n1yyMTlp4m1ZaKP57SaNkXk98cWk= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94bf0f7b-5870-4a0d-e50a-08dcb66fe49b X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:27.3678 (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: VpXrTgTz5jadElhcvFdxY/VfL7yE1lU/gMIOUgmduBMMDMWdBp2OJjuHizPHpodQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163151_086854_2E1A83AC X-CRM114-Status: GOOD ( 14.89 ) 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 Since v5.12 the rbtree has gained some simplifying helpers aimed at making rb tree users write less convoluted boiler plate code. Instead the caller provides a single comparison function and the helpers generate the prior open-coded stuff. Update smmu->streams to use rb_find_add() and rb_find(). Tested-by: Nicolin Chen Reviewed-by: Mostafa Saleh Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 68 ++++++++++----------- 1 file changed, 31 insertions(+), 37 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 a31460f9f3d421..b80f3359a8d12b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1696,26 +1696,37 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return 0; } +static int arm_smmu_streams_cmp_key(const void *lhs, const struct rb_node *rhs) +{ + struct arm_smmu_stream *stream_rhs = + rb_entry(rhs, struct arm_smmu_stream, node); + const u32 *sid_lhs = lhs; + + if (*sid_lhs < stream_rhs->id) + return -1; + if (*sid_lhs > stream_rhs->id) + return 1; + return 0; +} + +static int arm_smmu_streams_cmp_node(struct rb_node *lhs, + const struct rb_node *rhs) +{ + return arm_smmu_streams_cmp_key( + &rb_entry(lhs, struct arm_smmu_stream, node)->id, rhs); +} + static struct arm_smmu_master * arm_smmu_find_master(struct arm_smmu_device *smmu, u32 sid) { struct rb_node *node; - struct arm_smmu_stream *stream; lockdep_assert_held(&smmu->streams_mutex); - node = smmu->streams.rb_node; - while (node) { - stream = rb_entry(node, struct arm_smmu_stream, node); - if (stream->id < sid) - node = node->rb_right; - else if (stream->id > sid) - node = node->rb_left; - else - return stream->master; - } - - return NULL; + node = rb_find(&sid, &smmu->streams, arm_smmu_streams_cmp_key); + if (!node) + return NULL; + return rb_entry(node, struct arm_smmu_stream, node)->master; } /* IRQ and event handlers */ @@ -3173,8 +3184,6 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, { int i; int ret = 0; - struct arm_smmu_stream *new_stream, *cur_stream; - struct rb_node **new_node, *parent_node = NULL; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(master->dev); master->streams = kcalloc(fwspec->num_ids, sizeof(*master->streams), @@ -3185,9 +3194,9 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, mutex_lock(&smmu->streams_mutex); for (i = 0; i < fwspec->num_ids; i++) { + struct arm_smmu_stream *new_stream = &master->streams[i]; u32 sid = fwspec->ids[i]; - new_stream = &master->streams[i]; new_stream->id = sid; new_stream->master = master; @@ -3196,28 +3205,13 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, break; /* Insert into SID tree */ - new_node = &(smmu->streams.rb_node); - while (*new_node) { - cur_stream = rb_entry(*new_node, struct arm_smmu_stream, - node); - parent_node = *new_node; - if (cur_stream->id > new_stream->id) { - new_node = &((*new_node)->rb_left); - } else if (cur_stream->id < new_stream->id) { - new_node = &((*new_node)->rb_right); - } else { - dev_warn(master->dev, - "stream %u already in tree\n", - cur_stream->id); - ret = -EINVAL; - break; - } - } - if (ret) + if (rb_find_add(&new_stream->node, &smmu->streams, + arm_smmu_streams_cmp_node)) { + dev_warn(master->dev, "stream %u already in tree\n", + sid); + ret = -EINVAL; break; - - rb_link_node(&new_stream->node, parent_node, new_node); - rb_insert_color(&new_stream->node, &smmu->streams); + } } if (ret) { From patchwork Tue Aug 6 23:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755481 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 3DEE1C52D6F for ; Tue, 6 Aug 2024 23:35:19 +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=T1E03LnkCmgGfrA4V3+dB592/Pxr4UaQifcRBwkPyNI=; b=czmo24F6Nzb0HgO+w6qkrw92qU oZcfaPVbO3JVTGfZvmdWq8E8iHZOFvkjxzNHF2kP2tmuiXGpJG4Srxni1igAuxzXRNUGbVy9FCpgU hLNVjdRgjBxSmLcwAvBEFSLPnlaDzJ9cwradtbmN74Bb/6xDZoxrsJpDn65SbJIfJo8p7OYnlHHwM E8/+xu4jIRLgdmQCWZ9xwh1iofFncmPInCwSXg27V8SSMFuy0okXqxSOlZOI8vU2SrTluvPtczUB2 y8OdcGi4/kzKaZKmhZSWsutPF5DkGKB+wXQLnUBAkRN7AErC5A89zmrbH4scvTGCVcRL3CNMusJak LW3RsjiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTho-00000003KU4-49ux; Tue, 06 Aug 2024 23:35:04 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTef-00000003Jil-1KH4 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LfvgOwgBGQ4wBybqY1J04NDF5tg4HKEmJh2DCZ4NrGsyRh+RwyEWDV2cSGR5iN8ANny4PaI0c1FpnzJPHxbVFEvulW71NtJSZ9dzwCcrmg98DwPXpMZWA4IHx5wiWibhbHF+a8Oo5nYaum1UjuPT4SmSWVfLzJWiCxNKxtuntJqwKPqPfbotd5q4owKX8YniZ+lwJdvlOYydF4T+zzLTA2hdC46ys+Azy9bT5jp9c9+lOTxeChJafp/MIGgTOlnRTJ7J1ZTBICd303Q7AgvkbyPwOkpEmqKltbPFZ0Lq9F/Sgm3NTGMFsX8yVvrEz+1HmfeTmrQDcdh+nNSUF3mo1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=T1E03LnkCmgGfrA4V3+dB592/Pxr4UaQifcRBwkPyNI=; b=jJqhe5MKyyNnIewFo8RYIf1lml1DIKQN6pSEIx6N03Fiffqz4mSJbWKt0edKoRKOQA730uyXDFkN2A4rDlTbHW5OL60kAB+p7QdbRj0qMz3xkbkI1hpvX8+l2KXADlfefPXnw7mxS/soCvOSG80onoqYVd+vLJWFrYWaBs4Jg8ZoeNq82hep8rNwPtM/wsPmWDyvUIyJv1tGFDq0vz2REixvzP2V0Bx1+BJoqBMwtyhwrW0fXc9M5+icUuG1P/GltIU3+tlH13FCKYZgxqKAUIpyrPDsSlR7rPPIwo+fooDPZYae8YezK4auZuljL6dTZuof7uXuP+qnjRLmXz1v3A== 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=T1E03LnkCmgGfrA4V3+dB592/Pxr4UaQifcRBwkPyNI=; b=FXcFX37dTDMfhuTpTYqgXqVGKduURIvbukVq5qMphgvXqegVJaZ2WsPLmuPXUb+19M1Fci4b9JxM4HglCebXiJkMjffKhqgwhlZD29SFwtz6JKs8604z6UqGtNNp8cL3g99PwMl2XGNx1jGvmORIiKIk/KTqO+iWDB2+o7XXiOgFu5u1SY30Iak0ToSpeGr0lofE3Fnn9gEJ2iW0Aii3pbwtKPW9/oi6lZTcpCGxV/vwbUBe6KK6OVD1jnX9Re3CRwBmNDeVkcDrOWVgEFXO9V7XAFFx4FB14x9cGubRiNXjtFufyNcKDAZeLJf2eajgcE32ZDGXNKfUHfCsfvNpFg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by PH0PR12MB7839.namprd12.prod.outlook.com (2603:10b6:510:286::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Tue, 6 Aug 2024 23:31:31 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:31 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 2/9] iommu/arm-smmu-v3: Add arm_smmu_strtab_l1/2_idx() Date: Tue, 6 Aug 2024 20:31:16 -0300 Message-ID: <2-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0409.namprd03.prod.outlook.com (2603:10b6:408:111::24) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|PH0PR12MB7839:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e0dc7b4-258f-4d87-44fd-08dcb66fe391 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: U8cDEOgUgoYbwqfZaDGzfSK4VGKdpHRPbG0cxVgpZMKwDb6eJIknWYzPabHt5T/b+Bj9/qJz9jaa3wLhlqSOXyXFxEQEdSkQI+GhuVQPQKVTGHJr9EpUZR7pSCtWmUSEfgJDIAymQMyCjQYCiPO5J96Oshy4NY4me/kRFLAI6e8ZHj/0Ug8/a6qubNeD1K5huqhbfoVXr3fr7TjNh0q/Srlv3bkUeCeQx0KBV1PxjlExV0UkUuJ8fAHp5989auPcxCl2OfLUY8lnPoh3bI672T1qnSMGRemXlnsSNewsZSi/z4Bc796qswosTXasRKGQ5mg853d/snSTegU9tlZUUvAdE0V8br4tFDrWyf2V/TRFmC/To8KO0skZKwA0kPnzjZ1vUCuMKkHmpDuWR2Y10dn3E7Ak69IMh7+907+VZ8Wd80EzAOkWR9+86owBsVe6acFRH9FjZ4joGeug6mbsVD5k7XpYUOE5FeuDNncE8x59edtAR4jNPBLWGl68sT2M/m2Nb7hM1PSFILB9ycNrVU4dJFW7yqqKeKOqmvBR7LZ2nk9xwqgdsJJ+IK4t6bfq29ZfPFpEdSWVMmhprYfGyZNff7eaUbhZXUDzZJN/bhrFNRuo/Zjadj0BcnBZO2zyqJPw3IP8EOi579M49//NCWkUcaj7xXXtUgUtaSUtmkJl45sk2ujtftcEbB3tO2K/uDw4vHKN3JJD/FX7pFvNzydAdq0/5zob2cC3liQw6st/6zfIe/jerbP87zR5KI97ZwfIRSZuNXl+O48qc+8puUBszjSWrIcmcTUMiHIGtuAevoSYYweaCtVNlyI0tcPLPKZgiojKWco7Qwn1KoShBdmDCQVy/MQ3sITlWgqPzLM2cHOJOyKkvcjnuf+V21ePUyvd5yQbJjckRnErB89XRLv73h5kWEnTf3qecAJAYcOSHNk6RTxYa/BXOxV7ByVGuol7PYpxzWPhCHR6ds8fjgLzMbyiKy/7oEjCGwY803YFyW68OrLRYgl/jO5+1TRL2m04mJcBHu/oO52AqkQq+j4F/1AoeEThb+GdT08gyEn7XUUjbUeIz3upQF7SSmxMY6hY/gkfr10dETuTmqylPiT/KnyyGTngzzNbE56gV/cE5kuDduGJzOQwwllVJahzxHJAQ/EgtF0rK+Jk7PYCxaZrK52ekO9I2PLBq/M0ao0irElTpPgs82cFEN3NOoekZdRuGIW9/JR9NtPTrGIZuieNbJIl/a5dKGqBUL6J/VYcUVxZx8GKZ6xOQaRosKoC7l1l31n9ITcNuKfp3Psysgh4nFXRteXKvmSDpMxHlhCe6lGpwzMvowpegR8x99PAONgXUXfR6EUKuY2QjvLruQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RT5S42n+eE6NRLjXfJIRfVBHegp2Wf3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KNmh3QrFwrjVeWfataDCwNWCE0Ze0C0SfVElLZK7tdi3/+WXVSBa4HTdsJ/3hT6ki1sE5EZzxyaqJQ50Zhi1DxxEqZaSwR28CslArybinmjKl6ZLaL984eqWTWzGBFjxzsDALsvaXzeeB+rZxl5pFu0a9Dryv/CtmSnFXln2wEXLHfU9Hoa5XcFud7gk0jG7Iis82EBwvsDQ4FPB9OKcrGAqIbuMH8LT3Wg4IfffsH3oMn3IbZMtD6v7hOZRk7enKilRL5WBPJRE9/79RlNsMkswXectEHwzTYh6MbD7+smP2Cbqf5XwaeqvXo5QqT8e6uIqo1VXrfZ/KZy8VcblGIhcXiTFauCJGzFykdMtLjDcG0OHJWkqMTwBxIOpzx64ZRXy8WOiGskl9Sx3oZ2PiNUYyYqNSrQt3IUqinIEa8nA4xOyp5DyXEn38tF9yHMOGHQVDPEalYsJNmOw= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e0dc7b4-258f-4d87-44fd-08dcb66fe391 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:25.6138 (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: hMUFlc4EIYzPq3lNHBtHPcvoaHmmj0nKlNXkYsW/an1cpzwp6ye3wa3+GQZ0UiuC X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163149_381690_8F27E46F X-CRM114-Status: GOOD ( 16.33 ) 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 Don't open code the calculations of the indexes for each level, provide two functions to do that math and call them in all the places. Update all the places computing indexes. Calculate the L1 table size directly based on the max required index from the cap. Remove STRTAB_L1_SZ_SHIFT in favour of STRTAB_NUM_L2_STES. Use STRTAB_NUM_L2_STES to replace remaining open coded 1 << STRTAB_SPLIT. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 51 +++++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 14 +++++- 2 files changed, 35 insertions(+), 30 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 b80f3359a8d12b..a695e5f8fc2880 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1670,20 +1670,17 @@ static void arm_smmu_init_initial_stes(struct arm_smmu_ste *strtab, static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) { - size_t size; - void *strtab; dma_addr_t l2ptr_dma; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - struct arm_smmu_strtab_l1_desc *desc = &cfg->l1_desc[sid >> STRTAB_SPLIT]; + struct arm_smmu_strtab_l1_desc *desc = + &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)]; if (desc->l2ptr) return 0; - size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3); - strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS]; - - desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &l2ptr_dma, - GFP_KERNEL); + desc->l2ptr = dmam_alloc_coherent( + smmu->dev, STRTAB_NUM_L2_STES * sizeof(struct arm_smmu_ste), + &l2ptr_dma, GFP_KERNEL); if (!desc->l2ptr) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", @@ -1691,8 +1688,9 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_initial_stes(desc->l2ptr, 1 << STRTAB_SPLIT); - arm_smmu_write_strtab_l1_desc(strtab, l2ptr_dma); + arm_smmu_init_initial_stes(desc->l2ptr, STRTAB_NUM_L2_STES); + arm_smmu_write_strtab_l1_desc(&cfg->strtab[arm_smmu_strtab_l1_idx(sid)], + l2ptr_dma); return 0; } @@ -2449,12 +2447,9 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { - unsigned int idx1, idx2; - /* Two-level walk */ - idx1 = (sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS; - idx2 = sid & ((1 << STRTAB_SPLIT) - 1); - return &cfg->l1_desc[idx1].l2ptr[idx2]; + return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)] + .l2ptr[arm_smmu_strtab_l2_idx(sid)]; } else { /* Simple linear lookup */ return (struct arm_smmu_ste *)&cfg @@ -3158,12 +3153,10 @@ struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid) { - unsigned long limit = smmu->strtab_cfg.num_l1_ents; - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) - limit *= 1UL << STRTAB_SPLIT; - - return sid < limit; + return arm_smmu_strtab_l1_idx(sid) < + smmu->strtab_cfg.num_l1_ents; + return sid < smmu->strtab_cfg.num_l1_ents; } static int arm_smmu_init_sid_strtab(struct arm_smmu_device *smmu, u32 sid) @@ -3602,19 +3595,18 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { void *strtab; u64 reg; - u32 size, l1size; + u32 l1size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; + unsigned int last_sid_idx = + arm_smmu_strtab_l1_idx((1 << smmu->sid_bits) - 1); /* Calculate the L1 size, capped to the SIDSIZE. */ - size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3); - size = min(size, smmu->sid_bits - STRTAB_SPLIT); - cfg->num_l1_ents = 1 << size; - - size += STRTAB_SPLIT; - if (size < smmu->sid_bits) + cfg->num_l1_ents = min(last_sid_idx + 1, STRTAB_MAX_L1_ENTRIES); + if (cfg->num_l1_ents <= last_sid_idx) dev_warn(smmu->dev, "2-level strtab only covers %u/%u bits of SID\n", - size, smmu->sid_bits); + ilog2(cfg->num_l1_ents * STRTAB_NUM_L2_STES), + smmu->sid_bits); l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, @@ -3629,7 +3621,8 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) /* Configure strtab_base_cfg for 2 levels */ reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL); - reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, size); + reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, + ilog2(cfg->num_l1_ents) + STRTAB_SPLIT); reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); cfg->strtab_base_cfg = reg; 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 14bca41a981b43..45ec88c9aa355f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -202,7 +202,6 @@ * 2lvl: 128k L1 entries, * 256 lazy entries per table (each table covers a PCI bus) */ -#define STRTAB_L1_SZ_SHIFT 20 #define STRTAB_SPLIT 8 #define STRTAB_L1_DESC_DWORDS 1 @@ -215,6 +214,19 @@ struct arm_smmu_ste { __le64 data[STRTAB_STE_DWORDS]; }; +#define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT) +#define STRTAB_MAX_L1_ENTRIES (1 << 17) + +static inline u32 arm_smmu_strtab_l1_idx(u32 sid) +{ + return sid / STRTAB_NUM_L2_STES; +} + +static inline u32 arm_smmu_strtab_l2_idx(u32 sid) +{ + return sid % STRTAB_NUM_L2_STES; +} + #define STRTAB_STE_0_V (1UL << 0) #define STRTAB_STE_0_CFG GENMASK_ULL(3, 1) #define STRTAB_STE_0_CFG_ABORT 0 From patchwork Tue Aug 6 23:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755490 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 9EA3EC52D6F for ; Tue, 6 Aug 2024 23:37:31 +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=KZZoo2aiGFcC8GHomd95Q5u1fLWQlnX/Du5UTasLzFw=; b=S/EANL17WPQ9idpMIk3en4hk7t WG+fTfIvQXNZ2ka5EWAZhwaZg87f1K6bmR9MPg/ppPUmfGMzthbgpapNOnA+0qrD9H31t07fBRKqd FJkpm5zuAynSZyShvnKmav7Cf51VFHzPOiNQgpc4OjX7fts9MdCnIPgeZo0M/8Ci5jv6TMmgCMUAN Pf7tCb6yRD1l8cPFzT36JnZTyI6LNTahcQBmdlUKhsh97YPs+KqSnmpy1yG+5P+k/fIYevnDoy8N3 O+E4NjcUH4n0x+4t6tQYb5hSGN9YFdozJW1dT5SJQhOq885YbEUh4GBKmmqyctTyYji97YuVYPmMY Ija3CctQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTjx-00000003L8P-3PbA; Tue, 06 Aug 2024 23:37:18 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTeh-00000003Jej-0nbG for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qxg9Y3tWusQX/WIxIpAUZeXyw5S/xHDm20Lt43GhAmjcUEOhJxev4zpmc64KD/LFe0/S0A+glx6n2ZMqQ8pD9GlnKwJO7vd44x+LJ3gT5Mtk6EDhsUecfEqQxCrg3OqKg6XikDgTbD1/LGXy0JU/t2JQGHQGS8m1o6wk+r9rao/OSKd1/P02aJVvcModZW905MFAWxwCigQzZf+mJXRUdJIW446YfvbaF13Y3NQiYrioFsnfwHo7U5OAjyhgY/zBYOeTHAyal91I/q83ld9KfEHPczuWI8yKP5oEfJ6iUkMq4TOsAH0wVxj87YzzkDfR31QvUoa6zat1QidRTm6e4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=KZZoo2aiGFcC8GHomd95Q5u1fLWQlnX/Du5UTasLzFw=; b=LxF3iJk0lZZRSgju+ihe6UVdUadViP0ZSdk7EgJQ7kx4Bv3+v5D4efJ/d7Njgl7hDhYaPhuBjnUkS3vjCCeBVn7+De677Ndfyx50Q2pmSEuWetfN1U5UFXfSBivR5xGrefAjzZe+j0KcyAa+uSUQ9pWo5YrbsV6yOToEMWsIjhRRYVjx4XOWY7clnS+uXg3ix48ahVoVQ9FPIoxHS+FhFWjtDeAVI4iq1UWYzmvGlY26y7ZljA8/PTbG7607GizUwXh1yYxkLhPQzwGytKbG9T+UvlGu+FHe0iU4JjWPrvN7+4nj0BCLpTy8zgSqNVmqlMObDbO4BSR4eGUh6btsnw== 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=KZZoo2aiGFcC8GHomd95Q5u1fLWQlnX/Du5UTasLzFw=; b=rSeq7ns3YR4xSIgnUMS3kkiWesnAdQVbqUOlLiAcU86rx5FlF4AjvWxs+MBzvTJFhkHWX+rpOhWwy/V01XO2N1+0cD4dxBcDv06vIbCdD80OvcOyCSJOfFx2cUaeFwmbPxQo7ZwXvtZRrYOmyvwF0suA7MuQMGGMMRbv4gGx7psKqfiYlI5rv6IXMQH/MKLi/rC+9JK3Uh2nrJIuEabXjyuA/mfjdAQYID5UnAN7SNhK5ENTfKDwy+JeYqnKth9wNQPuoxmLiA9alnq37AFdqRibBmwi/QMGh34QZ2H1km2HYVLPIKpKbsWl7VIWbTYolcsKW39LNBMg4Qplns4JNw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 23:31:29 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 3/9] iommu/arm-smmu-v3: Add types for each level of the 2 level stream table Date: Tue, 6 Aug 2024 20:31:17 -0300 Message-ID: <3-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0097.namprd03.prod.outlook.com (2603:10b6:408:fd::12) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e256306-6d11-4138-2189-08dcb66fe351 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1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VJqdyv1ZJDoqSOY95hlqyGtYJnBQilJdCifMXKu1Zn60QbX0Ri4L9czwRGW25TUNDdmiJ/UCaGAl7qKNAlmDAUTg5qrZIVzFVYN0aGWwf0trEDfwmIr4Y/8YeEtEyxIcKz1kkSHbWubAAitXLZ5Nj9/gLCKXldcysZhU4VZ8C+rklm0zG6YMMVZz5EBoqsRnjb07w8a8AkG1k9Y8I9F8nVqw7RrREmQjiIraFuTeMVIy3X/apUrLQPWcVsfCzcF3OdLWZh9kAYMSq5xIbcdQpeX5eaSOj8MtxaPafQV+Tv2FOWdzlABHPGc53ddkna42uWtKg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8YzzTKxtUTZ2e2ZrSedLsTopgNg9lrmWblBSaytYpusqFgtww6gVn8BgbIQ0x9rQCAd5GHQaQVAJxTIGeyA27JFkZgwVbTeAMHYoQ8Lf9jRX8U6cptYTqH/nkS1xc7fsBj8MOWTCaERs8vbZQvteeVrcPAJy9I04Nf+u1C89TSF3NHnijJIu5K9rWPBjCdSvq7zZzbgINLEHzB0mi4IHg/9RQunIqDREpFbp8+jPBQyqtrGbcGkyzTxgGdeKsT76hE/SuhPCaS1CPCGLBiDXsov2LDDIyllNQKPue626oJIFX4Dqp21iadMnjhaASxGpljUEszyTb/Yye83448hLA3onR172VC4KtRau4wPVTyWRf0qO6PsgLxfb/GdUJXr6TS4gAWmvfD/gIhOUM1EPkRHqdD2J9kpY2d0lsqrR2ZwqzZoE9efhyTrRV/PB4engpx9xJ6BHR51fQDkNwJOxCAe6lHlmasXfk6QDhuEmD/2649MME3tTZj6Db2m69QINhiKxzCIUNUjQ0qD0C4KuPN4rCDBrN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ossTenant-Network-Message-Id: 4e256306-6d11-4138-2189-08dcb66fe351 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:25.2023 (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: UfJ93bj14vWS5tSXYxNha9OuwXdpGdCgaLLFgRYX3UsEHKX5g2TdhV63iUBugfFl X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163151_256645_94C0BE2D X-CRM114-Status: GOOD ( 14.10 ) 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 types struct arm_smmu_strtab_l1 and l2 to represent the HW layout of the descriptors, and use them in most places, following patches will get the remaing places. The size of the l1 and l2 HW allocations are sizeof(struct arm_smmu_strtab_l1/2). This provides some more clarity than having raw __le64 *'s and sizes computed via macros. Remove STRTAB_L1_DESC_DWORDS. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 +++++++++++---------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 10 ++++++++-- 2 files changed, 20 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 a695e5f8fc2880..7a2d102fc11eb0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1458,7 +1458,8 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) } /* Stream table manipulation functions */ -static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) +static void arm_smmu_write_strtab_l1_desc(struct arm_smmu_strtab_l1 *dst, + dma_addr_t l2ptr_dma) { u64 val = 0; @@ -1466,7 +1467,7 @@ static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; /* The HW has 64 bit atomicity with stores to the L2 STE table */ - WRITE_ONCE(*dst, cpu_to_le64(val)); + WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); } struct arm_smmu_ste_writer { @@ -1678,9 +1679,8 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) if (desc->l2ptr) return 0; - desc->l2ptr = dmam_alloc_coherent( - smmu->dev, STRTAB_NUM_L2_STES * sizeof(struct arm_smmu_ste), - &l2ptr_dma, GFP_KERNEL); + desc->l2ptr = dmam_alloc_coherent(smmu->dev, sizeof(*desc->l2ptr), + &l2ptr_dma, GFP_KERNEL); if (!desc->l2ptr) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", @@ -1688,9 +1688,11 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_initial_stes(desc->l2ptr, STRTAB_NUM_L2_STES); - arm_smmu_write_strtab_l1_desc(&cfg->strtab[arm_smmu_strtab_l1_idx(sid)], - l2ptr_dma); + arm_smmu_init_initial_stes(desc->l2ptr->stes, STRTAB_NUM_L2_STES); + arm_smmu_write_strtab_l1_desc( + (struct arm_smmu_strtab_l1 *)&cfg + ->strtab[arm_smmu_strtab_l1_idx(sid)], + l2ptr_dma); return 0; } @@ -2449,7 +2451,7 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { /* Two-level walk */ return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)] - .l2ptr[arm_smmu_strtab_l2_idx(sid)]; + .l2ptr->stes[arm_smmu_strtab_l2_idx(sid)]; } else { /* Simple linear lookup */ return (struct arm_smmu_ste *)&cfg @@ -3608,7 +3610,7 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) ilog2(cfg->num_l1_ents * STRTAB_NUM_L2_STES), smmu->sid_bits); - l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); + l1size = cfg->num_l1_ents * sizeof(struct arm_smmu_strtab_l1); strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, GFP_KERNEL); if (!strtab) { 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 45ec88c9aa355f..3a8a459f899fd8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -204,7 +204,6 @@ */ #define STRTAB_SPLIT 8 -#define STRTAB_L1_DESC_DWORDS 1 #define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0) #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6) @@ -215,6 +214,13 @@ struct arm_smmu_ste { }; #define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT) +struct arm_smmu_strtab_l2 { + struct arm_smmu_ste stes[STRTAB_NUM_L2_STES]; +}; + +struct arm_smmu_strtab_l1 { + __le64 l2ptr; +}; #define STRTAB_MAX_L1_ENTRIES (1 << 17) static inline u32 arm_smmu_strtab_l1_idx(u32 sid) @@ -597,7 +603,7 @@ struct arm_smmu_priq { /* High-level stream table and context descriptor structures */ struct arm_smmu_strtab_l1_desc { - struct arm_smmu_ste *l2ptr; + struct arm_smmu_strtab_l2 *l2ptr; }; struct arm_smmu_ctx_desc { From patchwork Tue Aug 6 23:31:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755479 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 B58CAC49EA1 for ; Tue, 6 Aug 2024 23:34:12 +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=bjpq912QHSJ+k3bzBg5GnE73iFdknyO5U374443igcg=; b=iFai8ORRL2//u3vee41bco5Wqw NwMKLlutcBsiTTpln8tDh4WIJnvMI3tzZIcKLvBI2tFbw2lIBmbVsGthCZfJXCoHz6+M/w+82lKnJ +JXGZ8jHzx8wdcrpy10AnZW7213bMtfTGHs6aG6ICJVzuwQaU4g6gDNnVSPtleburOtgCrug+qh1P mwIDHXR67ZiO4EWW88cTzbD1rgoBlYnZHViScymIka3QTnVx6jrbU0LVdi+B9SRolSk1AaAzfEKZH mElVlQnZMF+/k5SiV6yhui+I8aO2hqN29or1rES0arSRenYZG1MsK+fpN4Ew4GkP9mN6DVCrPE8Eg 8jtpafnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTgk-00000003KCG-2PSk; Tue, 06 Aug 2024 23:33:58 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTec-00000003Jej-0SPI for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lCUHTcgCkDeFs1MtB0a6V844FmwEI1UcO5jl3ofj0lqkJSgWQ+wII5aYKEG8EJh3iJvYRdcq2LrM5qT3QRRzXCNbVksxyhKSZZHgXIgUc48FjiO2o+EP0UJ1qatv591XVTQJblTgAE5pEflPdEq1I9DLBbDfAZluBLghJdPaVyuKTNorIUPRo3oaWmoj9LWP9QJfyFMm1vSqGUFh7rjUMB3QJZaZnV4srYHajNwtM9LyYFZJXvj0i2vzlmGqSdnNtjcPa9/BdYL11AL6tGapFef/8HzQEy7qVNErpd/z57uyCwNKwsKhoD9mrjfJyDnJA7XvyENSut4sXq/KvXArng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=bjpq912QHSJ+k3bzBg5GnE73iFdknyO5U374443igcg=; b=RRYrRguBPzQaduTtKcWlj4a4br/rBW3u7xTms7+Pf4/sibSOXv0kLYpImCLcBezcXZzgcWkJ9EJq/juQaeRYRV45Du/pGtvNLC6VdQrsNq/4yt3wizHmPCFfIx/lRZAC8periG3dJo4mzo3gbmIsmGejTZT3xHxQSn9lt3Cuu1ov5rS9zOAcmQSMCVnZ4OGseWdtvWyv7eafP18q4CUqm5FCBfEFk7v1SqpYZ9bdaqB8Vzbz4LtzMTZ0KwRgHoxv1pU6QCfLGS/ehWRG2+m3bDg0niAvlwjk4M4eOtz27PMX0rPH6SSdUGToS4nenhZD76nOXLvKHZzG5HQzt4M1yg== 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=bjpq912QHSJ+k3bzBg5GnE73iFdknyO5U374443igcg=; b=TxAooxyC0i4sCPR4oWa2cpBizml2xtWVcUjhrBEyfa7lu6xsKPm09wxaZ9O4fzYTBA73qHKDjSV/MRn2uaE+oFM/OKYVdQKz3EnLOHP9ygfiYRpATMH5R9YN5tF4MFDaCHd/NKO1go2bManil2iYnTYcHZ70q6ZFVh7FRvtSHGGzTpMrXum9DXu80YzC5VTqoB/G7/fglEkJJJWX/YIlvkNnAB/m8WxjakgR80JD462FdMq70VBDJwgLz/ph+mtY6bqz+jAsZbETkWknHB/+ageUzMudeviw2fAH5XMpKJ1KyKiXmXUEosABfQKqM/BpJ939jbn1YZMPDGGSLzlhHA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 23:31:28 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:28 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 4/9] iommu/arm-smmu-v3: Reorganize struct arm_smmu_strtab_cfg Date: Tue, 6 Aug 2024 20:31:18 -0300 Message-ID: <4-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0091.namprd03.prod.outlook.com (2603:10b6:408:fd::6) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 97a99ca5-f5d2-4851-33d6-08dcb66fe32f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: rRAGOqGuZKGsosYgQTfvHtoo2COnU+XEayjPmPWw232WZIsNwYGBKC+DgIR2fZpjV1cg/zxqXeqnzIqL3OLr6qrypYFvB4oCCyQ7VXSh66k0auXbRrYV6qyFhVtR93wapHlBPjpTsMC+E0vmS5s7GANGhCykGUStDNBYWGdnLW3D7IdbT4dmHuKjLS0yyDfqzxgQ0nbK/tbd8mfaJslNt0FiAHSC9reWTdvCiA8TF/M2iJ9ObpaW5UEf9B/TqxrHblHiX+tCZ2sHesyFYZ4uqetUBy2m54ni5luBzvn+/zLNq+NhAks3MtSFta28v9Wnwu1+Sx1/Egy1C43tTderzodGVhCan/1CIbpwc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V:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U9lU/g1+PWA16YpzPwP1XIzaJwXVViQopcAd1sYt93/91UKy6VoyQYHTRzXCqRs6moO24HcccapHZNnlD8bZhuViNdPelvhRwP+pACgYRknKM335jr/kwgCGJFrC41pjYpZtpn++EJHyJ6iPDdke4/mqa71liSB5GMSl3n3XM6RcXHs+zFRBiq4RES9YSccOTJQSGdAaHiMZz2ZGl/loqlHripsV9aEsymMTzfpNcLnC5kn620fQ+8p9VE6kJUXDrmBIjnSRbNzxAZ0HURuF7OCx0Kw9JaYsaJq31DSEQZfNWkbBXBvPjFEacVibzRM5aqZcbgW2DIKCIB62RcKhvVH78nkx3Qq0JdcO6gbLTqClMmiZzVrTg6jHkZIOnYaltOORmyhcRi0ndxwkO5wtqEQx84KoNN3+WAuYLTCh2vpGXOxaPeBnm5LOa/W7cZr4RDWGPHz2lR/O2t+L/rds0ozLNUjuTN2MI5zlLv8Inm2vqnEBXQKUfiyNgJuS10QOk4U+IGw7fO6cFOwoa9wuNC5dBPK/xRxOVjOwNH/JNrRNhcye5GSzYzM6O9JAMhEd0r6oe/vgttchjodSt7OVpYZ2i3CSv45wajxCG6dSjMGl79Q0alcehHaoZU8rUpROcfIhsgr7g8yOw311flec5AMJzolKF1NrEPHbVYwyCykBkrTbqW9HZUvYqfhXbWYPiLFPISlROkYcX9QEoXsmGt6IIgqICi20UmtdNcBaU22ML8BIyT/a700azNTNOS/rWy0aGfkvsIWOAYgZfK5R8PJP59setu3N0Lj/HJPRddm3fw/rKiCwjQ8/qoYZXk4FDvwSsmZjh6PMy8W1DNFbrNPKAkOB3Z8svAr9tgHiM6n+Cw2Ks2ftRGnvcSUOmOZsH93NXaJHhG5p832mkJ3GkJncMWBacdtjWMVml+pa+RqvJGgs1mmTW9UZOHx9g1O/EnE13z0TJp1sMRrpvfF27i303TimAeSIcunmfkjKhzBQKhjJv2TaftSpecebE0Bw3PC/0AjPOpodbRXNLq5BfDpLUDBoM10P2LpB4D9VMTh+sjd6HMxZ5V5mTUA19tWhPY5Cqt+7rJVE33Tu4gvRA9apA9qn08eR5MTIyzoSYTTX8YhcBlIz2O5s4tqXCk/MHq+iBVPHDok3WNdMjeZt8dbXaxBEhdR/dVxqNsyhuMdrdclyf5T1faFP/cv2LM32QuDgNXr0YpDNSGoVy+c0Alp6khb/RIaAJ7FOlwKMWmXDgFB3GulcRuf4+//ox9/JxWSUQDDFKpTUhfEAy8h/uT9l2geyKmtuTyrtXP6pzeQVMrBle8lSM4zwBOwFbepgWjNP8k5DEGOa8NuD2qcnAcUOqzsn/hCWTzBjq1PsMukWOvVrkKQ6+KhMwMY8wA3Hi9GSkgDQCaxrAX4c3cIl3QSlV9516WodWcXz/aJ36QZCfzy7xRq4ZDZsfGs6foicxy08cV+hvIz2fGaYt+2GYUmrpKK+9QehBvIUFwsOkBrspr47aF6FKzyQ1LDj+PQK5bC+gQzGkGXoB6EHOdPLgcQrYecE46IUakXFFFbPND3AxMkUpuV/6290UeGAcRpC X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97a99ca5-f5d2-4851-33d6-08dcb66fe32f X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:25.0634 (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: hwSgZvVgHNyhTnUN0sUTgiLE0RJSqXR8sZOhZIez4FnN4b3ygme6/2goP5yd2bFV X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163146_213684_488D1BA3 X-CRM114-Status: GOOD ( 15.79 ) 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 members here are being used for both the linear and the 2 level case, with the meaning of each item slightly different in the two cases. Split it into a clean union where both cases have their own struct with their own logical names and correct types. Adjust all the users to detect linear/2lvl and use the right sub structure and types consistently. Remove STRTAB_STE_DWORDS by changing the last places to use sizeof(struct arm_smmu_ste). Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 77 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 26 +++---- 2 files changed, 50 insertions(+), 53 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 7a2d102fc11eb0..9b1f947102a554 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1673,26 +1673,25 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) { dma_addr_t l2ptr_dma; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - struct arm_smmu_strtab_l1_desc *desc = - &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)]; + struct arm_smmu_strtab_l2 **l2table = + &cfg->l2.l2ptrs[arm_smmu_strtab_l1_idx(sid)]; - if (desc->l2ptr) + if (*l2table) return 0; - desc->l2ptr = dmam_alloc_coherent(smmu->dev, sizeof(*desc->l2ptr), - &l2ptr_dma, GFP_KERNEL); - if (!desc->l2ptr) { + *l2table = dmam_alloc_coherent(smmu->dev, sizeof(**l2table), + &l2ptr_dma, GFP_KERNEL); + if (!*l2table) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", sid); return -ENOMEM; } - arm_smmu_init_initial_stes(desc->l2ptr->stes, STRTAB_NUM_L2_STES); + arm_smmu_init_initial_stes((*l2table)->stes, + ARRAY_SIZE((*l2table)->stes)); arm_smmu_write_strtab_l1_desc( - (struct arm_smmu_strtab_l1 *)&cfg - ->strtab[arm_smmu_strtab_l1_idx(sid)], - l2ptr_dma); + &cfg->l2.l1tab[arm_smmu_strtab_l1_idx(sid)], l2ptr_dma); return 0; } @@ -2450,12 +2449,11 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { /* Two-level walk */ - return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)] - .l2ptr->stes[arm_smmu_strtab_l2_idx(sid)]; + return &cfg->l2.l2ptrs[arm_smmu_strtab_l1_idx(sid)] + ->stes[arm_smmu_strtab_l2_idx(sid)]; } else { /* Simple linear lookup */ - return (struct arm_smmu_ste *)&cfg - ->strtab[sid * STRTAB_STE_DWORDS]; + return &cfg->linear.table[sid]; } } @@ -3157,8 +3155,8 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid) { if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) return arm_smmu_strtab_l1_idx(sid) < - smmu->strtab_cfg.num_l1_ents; - return sid < smmu->strtab_cfg.num_l1_ents; + smmu->strtab_cfg.l2.num_l1_ents; + return sid < smmu->strtab_cfg.linear.num_ents; } static int arm_smmu_init_sid_strtab(struct arm_smmu_device *smmu, u32 sid) @@ -3595,7 +3593,6 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu) static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { - void *strtab; u64 reg; u32 l1size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; @@ -3603,34 +3600,33 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) arm_smmu_strtab_l1_idx((1 << smmu->sid_bits) - 1); /* Calculate the L1 size, capped to the SIDSIZE. */ - cfg->num_l1_ents = min(last_sid_idx + 1, STRTAB_MAX_L1_ENTRIES); - if (cfg->num_l1_ents <= last_sid_idx) + cfg->l2.num_l1_ents = min(last_sid_idx + 1, STRTAB_MAX_L1_ENTRIES); + if (cfg->l2.num_l1_ents <= last_sid_idx) dev_warn(smmu->dev, "2-level strtab only covers %u/%u bits of SID\n", - ilog2(cfg->num_l1_ents * STRTAB_NUM_L2_STES), + ilog2(cfg->l2.num_l1_ents * STRTAB_NUM_L2_STES), smmu->sid_bits); - l1size = cfg->num_l1_ents * sizeof(struct arm_smmu_strtab_l1); - strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, - GFP_KERNEL); - if (!strtab) { + l1size = cfg->l2.num_l1_ents * sizeof(struct arm_smmu_strtab_l1); + cfg->l2.l1tab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->l2.l1_dma, + GFP_KERNEL); + if (!cfg->l2.l1tab) { dev_err(smmu->dev, "failed to allocate l1 stream table (%u bytes)\n", l1size); return -ENOMEM; } - cfg->strtab = strtab; /* Configure strtab_base_cfg for 2 levels */ reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL); reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, - ilog2(cfg->num_l1_ents) + STRTAB_SPLIT); + ilog2(cfg->l2.num_l1_ents) + STRTAB_SPLIT); reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); cfg->strtab_base_cfg = reg; - cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents, - sizeof(*cfg->l1_desc), GFP_KERNEL); - if (!cfg->l1_desc) + cfg->l2.l2ptrs = devm_kcalloc(smmu->dev, cfg->l2.num_l1_ents, + sizeof(*cfg->l2.l2ptrs), GFP_KERNEL); + if (!cfg->l2.l2ptrs) return -ENOMEM; return 0; @@ -3638,29 +3634,27 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) { - void *strtab; u64 reg; u32 size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - size = (1 << smmu->sid_bits) * (STRTAB_STE_DWORDS << 3); - strtab = dmam_alloc_coherent(smmu->dev, size, &cfg->strtab_dma, - GFP_KERNEL); - if (!strtab) { + size = (1 << smmu->sid_bits) * sizeof(struct arm_smmu_ste); + cfg->linear.table = dmam_alloc_coherent( + smmu->dev, size, &cfg->linear.ste_dma, GFP_KERNEL); + if (!cfg->linear.table) { dev_err(smmu->dev, "failed to allocate linear stream table (%u bytes)\n", size); return -ENOMEM; } - cfg->strtab = strtab; - cfg->num_l1_ents = 1 << smmu->sid_bits; + cfg->linear.num_ents = 1 << smmu->sid_bits; /* Configure strtab_base_cfg for a linear table covering all SIDs */ reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_LINEAR); reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); cfg->strtab_base_cfg = reg; - arm_smmu_init_initial_stes(strtab, cfg->num_l1_ents); + arm_smmu_init_initial_stes(cfg->linear.table, cfg->linear.num_ents); return 0; } @@ -3669,16 +3663,17 @@ static int arm_smmu_init_strtab(struct arm_smmu_device *smmu) u64 reg; int ret; - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { ret = arm_smmu_init_strtab_2lvl(smmu); - else + reg = smmu->strtab_cfg.l2.l1_dma & STRTAB_BASE_ADDR_MASK; + } else { ret = arm_smmu_init_strtab_linear(smmu); - + reg = smmu->strtab_cfg.linear.ste_dma & STRTAB_BASE_ADDR_MASK; + } if (ret) return ret; /* Set the strtab base address */ - reg = smmu->strtab_cfg.strtab_dma & STRTAB_BASE_ADDR_MASK; reg |= STRTAB_BASE_RA; smmu->strtab_cfg.strtab_base = reg; 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 3a8a459f899fd8..18e85fc936876b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -207,10 +207,8 @@ #define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0) #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6) -#define STRTAB_STE_DWORDS 8 - struct arm_smmu_ste { - __le64 data[STRTAB_STE_DWORDS]; + __le64 data[8]; }; #define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT) @@ -602,10 +600,6 @@ struct arm_smmu_priq { }; /* High-level stream table and context descriptor structures */ -struct arm_smmu_strtab_l1_desc { - struct arm_smmu_strtab_l2 *l2ptr; -}; - struct arm_smmu_ctx_desc { u16 asid; }; @@ -638,11 +632,19 @@ struct arm_smmu_s2_cfg { }; struct arm_smmu_strtab_cfg { - __le64 *strtab; - dma_addr_t strtab_dma; - struct arm_smmu_strtab_l1_desc *l1_desc; - unsigned int num_l1_ents; - + union { + struct { + struct arm_smmu_ste *table; + dma_addr_t ste_dma; + unsigned int num_ents; + } linear; + struct { + struct arm_smmu_strtab_l1 *l1tab; + struct arm_smmu_strtab_l2 **l2ptrs; + dma_addr_t l1_dma; + unsigned int num_l1_ents; + } l2; + }; u64 strtab_base; u32 strtab_base_cfg; }; From patchwork Tue Aug 6 23:31: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: 13755477 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 B41EEC49EA1 for ; Tue, 6 Aug 2024 23:33: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=eTIaufYQU3zDrM7K23leywVCts6C0HkFhyG20Z30FYE=; b=0OSbuocusjly+UGMXGKvDVRA8H 9+I+nDrjQS5u9Jnjrcd0J4J/p+kANtQBIdsPeDyBzki+r3usGDfsS3BRUysz0RLMMd8LQr6qcqdXl 8GCvtgIuhLjZt4gX/ciIFoXPncvTB15GTKkrgCJo06TBIreKpi45+3IrzHX5w8uDpT0fUlDXdJfin IqvlB1w4rF4mjTeHXgvj6mvjqwOWG7FI9sMs8UsSsS5A/gxw5LMMppTRKlFjRIHmteKaX5/8sJmuN 7JFD0Q4FvC+Es2JBKZAbygyjtmbmZCYgpfVH75BwoKgytEbFASxKGN/H6PvKVxpzPc2w83TxLQUoN rUtbtf9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTfg-00000003JuW-2PEb; Tue, 06 Aug 2024 23:32:52 +0000 Received: from mail-dm6nam10on2062c.outbound.protection.outlook.com ([2a01:111:f400:7e88::62c] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTeZ-00000003Jdz-3Q27 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uuY3nz52TkJFLrH7QBsq+ZPP4QD71+8xpoEvW5WXexYD4PgRGPPPH7paJFCRDo7TDYRdBRQrSaiTmji6ZIyxV48HBa47eGQRaWaJUWoNt26ZuePHqPT4ZjFtxMWnau3Ewq2LnTNZ7flqdiBTj/tOUIpGuQtxT5T1Gt9t4SE87JZjVHHx7bP/R7R4Up6pJ4MuGPOuYLfvxf4vmBHNXsvacU64RLzKpMrJg8WJeAgaSZc/6ytiljtstSardmStKR8A/qeozY+O2d0RVXo39Ta/E4f1xNQHc8p8xxgZnAftG+Xq/x+cgjgVnz4U3h4Fwew2MDGijTWzDtPsyZHpgYbRaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=eTIaufYQU3zDrM7K23leywVCts6C0HkFhyG20Z30FYE=; b=gMjldxlIFjSKKKkdqoNMN0/n9xDsZIaBECeEgTxUdileLy8ug5jHr6IQNQ2tnW4anONO8c/CTu2IU/kPL9nx3yO3Nsf52k5XJOSo/8s5hBUXgatGByF/9T37D7xmuZH9LKibm3mMaG2XOa/QbS3tFo98+/4nIMwboGkdjHma7KpbDMM60VWJQrXKQ4gphrUDyAFiTzHiebkuAUjNxwNUPtnLvnYu4oUT5kxVj0lnWsfb1q3NLZYNX6CyqFvNGh3HGuVOg8gLFGMTzbUZos9jXo1QxIHsPMVPYSKG+a1GHSyion1OYUr0zAWrTP+AcyWYVR1gIn1RBy3QZOC6lU/pwA== 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=eTIaufYQU3zDrM7K23leywVCts6C0HkFhyG20Z30FYE=; b=SENN47ByIIowDz1xQlnaHVAUexaUC921lyvicCYf6gYYmR13CCydkUKUvmJ1th40jC5NtFk39ISQy4bBDozZGs92YPo+WLhl73mPOZPPe+qDYaz4mfUKBiVJ84OLy9m+ZbYvht2/RuZcCe1LL5uBMtuv90vwsVscNlbM5ClVyFR7vBRRivwf/w6O5jaT0iOKTgi7Jze07OLHfK/4ZtsKSDBFkH1mATZfrkaBXCxYMkgtGeJTds+KazLgirWxso1yEjc0DheIqFrA99qAAOR8VV7hyc+QjKEsaQqfEXbredtJ7cAM94wbTXeFv76OQFIoYgAFUJrpaEM2YluiSZY1cw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by PH0PR12MB7839.namprd12.prod.outlook.com (2603:10b6:510:286::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Tue, 6 Aug 2024 23:31:30 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 5/9] iommu/arm-smmu-v3: Remove strtab_base/cfg Date: Tue, 6 Aug 2024 20:31:19 -0300 Message-ID: <5-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN8PR04CA0042.namprd04.prod.outlook.com (2603:10b6:408:d4::16) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|PH0PR12MB7839:EE_ X-MS-Office365-Filtering-Correlation-Id: 50748a40-0002-4e78-8d6c-08dcb66fe354 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: HxJ1ypotUlyVWeXGyx88YdKMR1sOVzVnp2yVHVvYRmSW9ordaFyQORGsqrTeidDjEDNNbiC0+pniKseNVrxXoMZybPOfocBHTWP2ycKDhTzi2OUGjcdp0rKX08og1AxuAhjFRQWrr4XcV9IVTGmm3t7eXBQGn8qj/tUf8+T8aTq/n01ck/nmvAEXt86lbPPr3zUF/WF+vTff8uhEWjD1INCJaQmi7GAnhNRuqh8ER4OGELT0IJSvQaNh8k+MMap9LrK/PDZPJWUQb76BBA6g00+Od/qoGXL2JrVScRzjws/HFmRyhhD3D5XVTQmVWbQlBl/hftUUYXknNTTSges/ZzC6fHn/YvTGc5My6adUHCkq6+o5nc+MkmeDU/LwK22mITaelDLJng2Q7MWa09TlfRFq3NvZAf3VY6NIHLZpq5gx2sgHEDVnD8vgTTKxVfL+nAhjOMDqZaqOtBS6Lo43wIbHtsVpVsNYZ5CbGYs5FeweJ3jZrgpdCYtP7AGyQTWfkRnOgocK32pcJsh07K1v5xkDFgZ0qSs7Plvh03ZhQj+SSUPb8BIICbdawCZW2JaNrze6cz40VnWgm1Dg3ytPOPqT43t2wa62f02nEdCkPhy0Vn2X61cUjuTXCup0wfDEWD+cxsZHVz/d50E0ypgslLxoPSRjcVhil2g89DjfP0hFsbagwac32iJu6eL3QJg/JEqZNF8Dwaa8N0JPurB2xOsMMD7GjXrj16CL5trY35w3ERAONWPrzO8gIGcFS4cJqmnyMjkksCphRMG53N8Ww5aG3i8xb5c45S48tti/Pu7nQY2R/aWg5tzyqgpCaXy8VS8E8U87ZKMNx56H9FD+JEkpE/XOHLc4CCaPy6YN6VTmad/krSwIqNdGufkhyz4jQTn159dEHw1hDkRGEtWJoYFOCTZHmsEitmmLd3a3GqSdYzCgYm4oQiH7ZOnwBC+Z3BORYETcU7oYwQ8CiIW1fEVRswNnd2mho1s1bO1OuEhlvFjCY0WbmMVxptFVcxDd4yClxoUgFmBDuO8EE37eco3vR0cqLLSs7RvW7GzkGrOHiGWVmg+VJMZUYXrnVTgwJhquD5uA3j8zbwy857wdR8VsiudelqPF6oxYFa8gbca6ub3pOY1gmO4CG6hDw0JPcVE0pZdyyEDTqLknnnif8BKDxkP3r6YKsTl8Eyoasaz90IknAqyWPGu4TsuDe4n/nUL08BetWx74XTzGbtkRozwZeoo9ov2pN9jdvIEl4HEmwvMvpNokXGLgvd4yp48g64insySrAJzmzAUjszWig5q6xUnRqZCfHK/jd4Bjh/phT1sdxWaymFXrUYY2p57qwB80zWnUFrRKMrK6QQoSeg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F0n4P87du42UMTsn7UXdp8edYF507PNnYB6xZhlDOBRumzHPEGZdklnkyu6688CfOPSSoD13K+ZAw9DdUV7uJIv0FfJoSM88d4rmH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ktNmuLf0xYwxT4woQ93rWGPsnFTjoBz0QXTVEqmfzrkiMINSTT2JWff4+5h9Kcp5MOancnqkuZx3KOYTrYQqNg+3RpWiboVfxEWNkXf6E1uK+66TZCmNCivCSdG/T+g/iIYFG21cEgo4zj+YXxh87aJX7W+jAZNQ9XaMQ7GNle8LS+IMhvGrBIBH9OGSC2B46IftDeciD9RzFDHsNRoywK7bdb8LnJExL0iDE6+t8tJvJUW8UXlDxiABBFcX8nAPBKVXs3MB/5CD04EfEXl+mhl3qIa+wL8kYRYr0kTvxj/I7D/qgOJEP9CXQldoJtZVWYi6g66qLFVt2MpbuMFLKQixSo4TpEtYQe+GIrNrmLkGonPQdHelvPagJM+ukOsPbV+jgb8824WZzlA= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50748a40-0002-4e78-8d6c-08dcb66fe354 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:25.2211 (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: 9ODLmSM556CjhHBD8//7WqUpjkHOWAYQkefmEq1YCYrGIikG0OiezPxDlOwZzj3A X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163143_882912_8B3BC933 X-CRM114-Status: GOOD ( 14.51 ) 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 These values can be computed from the other values already stored in the config. Move the calculation to arm_smmu_write_strtab() and do it directly before writing the registers. This moves all the logic to calculate the two registers into one function from three and saves an unimportant 16 bytes from the arm_smmu_device. Suggested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 55 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 - 2 files changed, 27 insertions(+), 30 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 9b1f947102a554..95bd4a36268c00 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3593,7 +3593,6 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu) static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { - u64 reg; u32 l1size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; unsigned int last_sid_idx = @@ -3617,13 +3616,6 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) return -ENOMEM; } - /* Configure strtab_base_cfg for 2 levels */ - reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL); - reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, - ilog2(cfg->l2.num_l1_ents) + STRTAB_SPLIT); - reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); - cfg->strtab_base_cfg = reg; - cfg->l2.l2ptrs = devm_kcalloc(smmu->dev, cfg->l2.num_l1_ents, sizeof(*cfg->l2.l2ptrs), GFP_KERNEL); if (!cfg->l2.l2ptrs) @@ -3634,7 +3626,6 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) { - u64 reg; u32 size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; @@ -3649,34 +3640,21 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) } cfg->linear.num_ents = 1 << smmu->sid_bits; - /* Configure strtab_base_cfg for a linear table covering all SIDs */ - reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_LINEAR); - reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); - cfg->strtab_base_cfg = reg; - arm_smmu_init_initial_stes(cfg->linear.table, cfg->linear.num_ents); return 0; } static int arm_smmu_init_strtab(struct arm_smmu_device *smmu) { - u64 reg; int ret; - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) ret = arm_smmu_init_strtab_2lvl(smmu); - reg = smmu->strtab_cfg.l2.l1_dma & STRTAB_BASE_ADDR_MASK; - } else { + else ret = arm_smmu_init_strtab_linear(smmu); - reg = smmu->strtab_cfg.linear.ste_dma & STRTAB_BASE_ADDR_MASK; - } if (ret) return ret; - /* Set the strtab base address */ - reg |= STRTAB_BASE_RA; - smmu->strtab_cfg.strtab_base = reg; - ida_init(&smmu->vmid_map); return 0; @@ -3885,6 +3863,30 @@ static int arm_smmu_device_disable(struct arm_smmu_device *smmu) return ret; } +static void arm_smmu_write_strtab(struct arm_smmu_device *smmu) +{ + struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; + dma_addr_t dma; + u32 reg; + + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { + reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, + STRTAB_BASE_CFG_FMT_2LVL) | + FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, + ilog2(cfg->l2.num_l1_ents) + STRTAB_SPLIT) | + FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); + dma = cfg->l2.l1_dma; + } else { + reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, + STRTAB_BASE_CFG_FMT_LINEAR) | + FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); + dma = cfg->linear.ste_dma; + } + writeq_relaxed((dma & STRTAB_BASE_ADDR_MASK) | STRTAB_BASE_RA, + smmu->base + ARM_SMMU_STRTAB_BASE); + writel_relaxed(reg, smmu->base + ARM_SMMU_STRTAB_BASE_CFG); +} + static int arm_smmu_device_reset(struct arm_smmu_device *smmu) { int ret; @@ -3920,10 +3922,7 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu) writel_relaxed(reg, smmu->base + ARM_SMMU_CR2); /* Stream table */ - writeq_relaxed(smmu->strtab_cfg.strtab_base, - smmu->base + ARM_SMMU_STRTAB_BASE); - writel_relaxed(smmu->strtab_cfg.strtab_base_cfg, - smmu->base + ARM_SMMU_STRTAB_BASE_CFG); + arm_smmu_write_strtab(smmu); /* Command queue */ writeq_relaxed(smmu->cmdq.q.q_base, smmu->base + ARM_SMMU_CMDQ_BASE); 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 18e85fc936876b..be931616d9a27e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -645,8 +645,6 @@ struct arm_smmu_strtab_cfg { unsigned int num_l1_ents; } l2; }; - u64 strtab_base; - u32 strtab_base_cfg; }; /* An SMMUv3 instance */ From patchwork Tue Aug 6 23:31:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755476 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 F042CC49EA1 for ; Tue, 6 Aug 2024 23:32:31 +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=prsWV50SKiIwgOQZkGv6ZIkbClrt2zSdiRSUQUzexYI=; b=FKZSSw0BpBjSz55Je2758nXpeF DUu0R0/TyjEdSkcS3EmJURgtePkKpykFpPQMSq/lH4VQO/CbNqqPwN21yX9jssc7coVDw0NBjQ7N8 0D18yEkaVc+48Bj8RHIFHNomb7OHulwzt/UsxlSk6T0PSSU5tydqBZbgbHoT62PE0aXL7c74q0YLe EWhITx6uNTpnU9QpmpQNr59xQXslzAq9wljs34PSAMz8U/ooBAun5n4J8mCwGxaicj9ZzCX7RldcR 6dMQopC/1UQsiJeIGvRl4zpPQyPkUUbAQV3h3ee1q+yiumpAUaln0K+RUVffTv8XWDAkLy3AQGPH/ noaK9hQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTf9-00000003JnD-0Lmi; Tue, 06 Aug 2024 23:32:19 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTea-00000003Jej-0Kla for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oDv8QBYvB9npyub9rpag1jaB8cIEIoD/L2RwQye7Osc+AEa+LFpEeOFY77OXF7uQWZVWqhSZaIRxGaY5tFZcNXe0bxfPMAXaHF59NeoGdckNPuBlCn0ycwmimp7z4A1a3cnaDoF1CiGjFHm+pMPog1zOHwxn1VBWik/Udm7e1bjLJnD2HitTwwCiRuSWuP2cWIig1o8eUuntlRTFwA9WQTwWyccnO+tffuOFBL9XpQAXXI819f63YMc+1kgA2Zt7YplRDjP9++na1arf76ceGdL4wHHm8uD3Yx7irRRewGm2lsUdUelfpJJs5JI8v0wXkP366fHfznAGvE4/AidhRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=prsWV50SKiIwgOQZkGv6ZIkbClrt2zSdiRSUQUzexYI=; b=SRBtkmdmilU7mmNol6/P5RvIu/mYcqPUd1kDRpRdCKaJPgFrYslcGMdQkCPu5OeEOnQdwp/1MXCl0vI6ReO71KVO/6bktiUwkFMu9GRu5q8gj1xY+x1dfsIRB9PXdYuAUpF4xaGTjMW/LlHHllmRBIr3rJz58IRmGnOA5GsgZo3emjdcBlzNYRHLXYxR73RXyBERLlTIoUbzakw2AGJoRrXD1Nkb8EI8S1XyXIEtTvUvDIwvLd1Qg+s+55cBIzgCGqMJbmbH83wv5Gjpu+uoztpXHVwyzbfrmEPgWRcvz7dVib2CpDYEim9HIrsnby64OAYC80rBa7pI2EJC0cqDzw== 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=prsWV50SKiIwgOQZkGv6ZIkbClrt2zSdiRSUQUzexYI=; b=lVewv+O6liAIMlipNmL2FmWN0dhyoKJNx0o79Yfjaft4vDvQKmdlAadZlRRgHE8+5Mv3rgrvIpYjCVn53CmxdjAvroOaImpbTjiCdn4CurWUAh6DyyHOs2GLEDDC9vHKfDxniRDXVGtwP+RjoAU0OGl3kGPTaeIR2dVAvZ8FV/UhNg3l6P7aMsTUJ1GX155wJCNz3a8WSgOWUOJg0+/OEhYY6hKk3/TD27aBJG3vSazXU7ZJq+tFn+NEu6MPOM7w8iyinI/tDIQI9IKkKyCLTzSPk7Xe3AseHWZovWcDVgEZ1250FU8iDYN7t0jNeLGgBnPIQEzjXLEnPKDEZVk5hA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 23:31:27 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:25 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 6/9] iommu/arm-smmu-v3: Do not use devm for the cd table allocations Date: Tue, 6 Aug 2024 20:31:20 -0300 Message-ID: <6-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0394.namprd03.prod.outlook.com (2603:10b6:408:111::9) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 3995bef0-3dd3-4a1b-706b-08dcb66fe32b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: tE52CdduFYyFJABkDz3FK7vLLDshxsu+CO/dvRC0ETybEZHO+8SwDfmyrBc0axGkSHqIdxhC5Aezrz5yb6Syd7Dxxdoz1k88xCd9CTIhobDNa+lZFmxu5h8nPBRjwqj7AhtrhLelA37q82okModVJKpjW56/Qh19FUtO/HTRDuZSlqG4wOpzTnNUmyEJRUIb1A7vZ8n+mHfEjMmrrTSNO/LeNE9Z6dg3fEpMmffuJtlCgnAk7H/fTBrFjb2hoLzGiXyFMvdwoWekFgwCjGo2UHYiU2Fr4BlXNUNa6/hb0FkY7S1U3AqpixZSAamOGoG2h4Is3QwzcEMNT7QHI1IILBK6CdXVa/2pp03eJ6VvgvTkWIAyiXyYbtJSn5sAmAxqzhJzT8ZktrzH+ljPl1SMv3H/aY3P5D9j07h5hz43ZqRlB+CA0vFuCPjbbizRR3Eby8xga8WibfrR5jsLlI/bDjg9IVBq0KwVUyr/t6lZML6hurd8TzSS5xCTOffhx4RJQEbVjd658FxDzLL6WadEuPilC3kv73REKNL16dJ77Yj0RizRS3pa9BHLaLBzRaPZYfJ03vaa9jIzL3cF32zrWLgvjLFUPG1CHkvaGgIgrtcXq4kGKF1tC7YrPXwpx6VSRxDvxeGcUF5ENsl7FAOJDgic20/mwhJh8m8AltOCn9tFLlyjO8DwM7KGklKGPDAUvgfElTHbaEZVvrosaLMoZF573ZpgLyDlFknnxoNNW6o4/AlcM2TvPtW7pGcGsxrb/U3nk/l88RdIr+V802dP1xR2/mgKdhyfOy+rTDropaNvA6kQQKYNXX4608NQsRwKkYIoOYMPwaVZw9CQyvEBXvbDFNwkWrS3xnXKIcmZv1CLjXO/aFVzL9l9Th8n+iG+kst0IepE3u6x0PPRb/UYqk4MPNavVsYqV0JlwvpA84vckZMiZbewytJK3n2aautJvTVIO11a193+4tv6ZgOrJXoh+0YCkMgjMAQJMxLcCaVahb2P0wd4nuB4OXzbSZww3/A8e/Qr++3uQ/3Q7nsNEsQIYiOGaYgqCnj4qJv6eOQL8Cr0+aIIJdCIlVLuxZmiwLQsJkxnGSREVnm2v7xKrUF+k0O5e0LR3iIAyBPnJDDmxjvqy53oIX5K+ECbePGzLpvrlKf6oRrPCud47rKLakx3ayxVBESXRQcl34yIcBfdZ6Sx/gipctAlEb9X3+aBndYW7Iy7CRAJyhce5G4diQAJPza54XkIa+V0PpGqrYdxfbJlAWpd0EuZTBJbpK7bwPMb4j/eTAyLVNrHmZF10vT8EIKi8TwL/ZAWJBNwDYagypYQfFTTNA8JVplAJrITEUlhlfcFc3D0KvwexotfEQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FBjXTh8kvuuMy9kFI15wjiiqM2oj5f5lvUeNvgQSX32DsiX6H5TK7KG0H4D+/12vpgQbijz+FszlZKGLfq2LxFrrgWe12FRYVelIUzzYmsDbD7z3G1PF3NEwd/IP0X2q6LniF/tol4ci5+PRzRo8556gPZwaMuYT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VFUjntigiTbHx+HZSTTTHxUQFPPhiGtQHXfJcwSLwTe640ctQNjwhiFi2+zEn8oiyliMvTd3P/tpL/UhAuAETmeeblbwwYQcGch7n8CUY69H/qU9p/CPUiddOLH8U6fm+csywa7eCzrCHm8IUEAj4HVR3HiMgzrY+QpiBuSqsuMP5ZjQQIugyDlTau3vGw62hHfFZwBeNUAXadSns/ed/Dl1TD4/0xA5w7ccvNroaLuOQu/UzEgc1c2Aii0Ci4a1zTsOsji+yTSO1Cpp1d4auaEaKPFYrqN5GSZpRhD9oNL5Sc8ofIXIAe8rTd/9KAU6jNsSQ3lJd7v9d5DxwJCFeAIsetR/uKv3j X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3995bef0-3dd3-4a1b-706b-08dcb66fe32b X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:24.9847 (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: HWHkMujcjC5ibGpFFpLFtgeBDtY1i7DEPRNOtk/QRYagYPsBYyzrocA0wcYk0/sP X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163144_133074_2B7F0315 X-CRM114-Status: GOOD ( 10.31 ) 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 master->cd_table is entirely contained within the struct arm_smmu_master which is guaranteed to be freed by the core code under arm_smmu_release_device(). There is no reason to use devm here, arm_smmu_free_cd_tables() is reliably called to free the CD related memory. Remove it and save some memory. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 30 ++++++++++----------- 1 file changed, 14 insertions(+), 16 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 95bd4a36268c00..e6607d9d590c4d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1184,8 +1184,8 @@ static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, { size_t size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - l1_desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, - &l1_desc->l2ptr_dma, GFP_KERNEL); + l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size, + &l1_desc->l2ptr_dma, GFP_KERNEL); if (!l1_desc->l2ptr) { dev_warn(smmu->dev, "failed to allocate context descriptor table\n"); @@ -1399,17 +1399,17 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES); - cd_table->l1_desc = devm_kcalloc(smmu->dev, cd_table->num_l1_ents, - sizeof(*cd_table->l1_desc), - GFP_KERNEL); + cd_table->l1_desc = kcalloc(cd_table->num_l1_ents, + sizeof(*cd_table->l1_desc), + GFP_KERNEL); if (!cd_table->l1_desc) return -ENOMEM; l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); } - cd_table->cdtab = dmam_alloc_coherent(smmu->dev, l1size, &cd_table->cdtab_dma, - GFP_KERNEL); + cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size, + &cd_table->cdtab_dma, GFP_KERNEL); if (!cd_table->cdtab) { dev_warn(smmu->dev, "failed to allocate context descriptor\n"); ret = -ENOMEM; @@ -1420,7 +1420,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) err_free_l1: if (cd_table->l1_desc) { - devm_kfree(smmu->dev, cd_table->l1_desc); + kfree(cd_table->l1_desc); cd_table->l1_desc = NULL; } return ret; @@ -1440,21 +1440,19 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) if (!cd_table->l1_desc[i].l2ptr) continue; - dmam_free_coherent(smmu->dev, size, - cd_table->l1_desc[i].l2ptr, - cd_table->l1_desc[i].l2ptr_dma); + dma_free_coherent(smmu->dev, size, + cd_table->l1_desc[i].l2ptr, + cd_table->l1_desc[i].l2ptr_dma); } - devm_kfree(smmu->dev, cd_table->l1_desc); - cd_table->l1_desc = NULL; + kfree(cd_table->l1_desc); l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); } else { l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); } - dmam_free_coherent(smmu->dev, l1size, cd_table->cdtab, cd_table->cdtab_dma); - cd_table->cdtab_dma = 0; - cd_table->cdtab = NULL; + dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, + cd_table->cdtab_dma); } /* Stream table manipulation functions */ From patchwork Tue Aug 6 23:31:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755483 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 7BB5AC49EA1 for ; Tue, 6 Aug 2024 23:36:21 +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=P6/FJ2tOwiz4XcawISnzVitqeIGHke3n2G5zNAU8e3I=; b=qYSre1x+IluJQ13mNbIkTz6Xp3 cUum0GFzWZawF8umj8vCn32mSig0C+RbCQiVDeBdW9M6d23wAE0B18N5cv1vmn+F0DhRukWLFAXiu wtgmty58P87x92FWmgK0AFCiX+gAObU0M5eTe3SjHWjpjj7Zx3aqBHGfha5PvcLnezQidQP7yzMcN NeE/0UXapRiCW9A5z0qV4uwZQSUx43Qm9iqKSc+dIPONk8KGzzqbnuKzTi9LC9hkj/qPOdsenqkCp SM/GEdQGho40Jn0ISPnOpkHxAglHMN8nQm8liPievrArvES+eJL2uc3CkdyFkKRjQNH/uZG01hB5g PUa9v7Zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTip-00000003Kh9-2WjT; Tue, 06 Aug 2024 23:36:07 +0000 Received: from mail-dm6nam10on2062c.outbound.protection.outlook.com ([2a01:111:f400:7e88::62c] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTef-00000003Jdz-3Hm5 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ljaWTSEPYJLmsCfqyEPqp7MQMkVX39Pbmkyc5f1jD/dhId8WfrbAHZL6RyU+UDH8gSXN4+kZxUEUPNaTKjq1YMrIOf3lVmVfWHRIOWxW2x74nKFpi+qysTTd2Hy2jwA9AsFGrZv2ychbQa1yUCk/hVx1Gdrib9S+LqeYJZ4X3eoZK2m/EfRl3ZiZjsVqGFxWoEluGrWaJfbovRXabV8R99a7jbfeenkykYCcHr8W1ShcPArjZU3Y5WOk/oL38nNpNwWXoN5TW84X50bpsiMW4wXfHtWq1KGiM/hWzQPZjSv7EwowqHQjOc7Z8LLHgw8VZZwxwEGhyjx//4lqzI5dMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=P6/FJ2tOwiz4XcawISnzVitqeIGHke3n2G5zNAU8e3I=; b=NtN4bJGaqFgz4/bV4n9FB8QaloJV4Ddv75q2HIEG3L37TZKW40Hmm9kwq5ZVm9cL06BYeKo1RAL4ZuPwhOuXWoOk5/XGEHBh+4GoBXjWzeyQ1210G+hs7Ois4muIE6Ism0X/mnoZSb6deZwe995UpbfgAOZenoC2vV3p3EkGnB++iO5LeKnWdNF5n7i6p+djeQhRh7r11ADzEVX3oWUG7edkvGA5N4wBLknzBwr4oqSUyMte5xBePaOa2I7q/XucBtH4UUEPLvo5aHUybQqwfC7JzngDlrzZ+5FuVeqmViVUx2kOBuJ9cwmpwVvyyr1mwVGCbeff8UHmc+ZAWiciyg== 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=P6/FJ2tOwiz4XcawISnzVitqeIGHke3n2G5zNAU8e3I=; b=qIRoGeHvwLMlGYGPlrsu6Ig8XDneNd57I8H+ilOLJt05Em9Lq9vICnIDb9Efz+4qwmhDt9e20j4fkhRA7vfgbME95YyOOojst+BH0JH/mD6IlhTZvQx4gL7JQDWwsZjXyuhceNaIgHwIKQt+7PQ8IGrhZpiiAh5xjb+5zOuKzG5jZvKSBvw6ZMiynThTO+w3Qm5avUFtjOED5eojVYw9zTUskEz0LjKIeU9I4YaYG413VYgS2YlBorKYdp36mOl4zJXRsP4rZlLtOjbqvw/qKevahUNptyHWr0iO3iBbrNRNI4BixyEp6zzKOw7p7gtL1WCNF75iba2HeS2J+THzIw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by PH0PR12MB7839.namprd12.prod.outlook.com (2603:10b6:510:286::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Tue, 6 Aug 2024 23:31:32 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 7/9] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Date: Tue, 6 Aug 2024 20:31:21 -0300 Message-ID: <7-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN8PR04CA0056.namprd04.prod.outlook.com (2603:10b6:408:d4::30) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|PH0PR12MB7839:EE_ X-MS-Office365-Filtering-Correlation-Id: 1261e25d-fe55-4d26-3852-08dcb66fe497 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: hZQ1vOL6xLGriLhMRaF67dQkQZkubwPHu7kxtmg+fEkNL/fXZmyoEagYo1uil04vqy3csBk+N4hgnhSSgr+XT5Hb1wNopaOrbbB8IVPBwNhc/e7WD/eYcp29L5TX0RZXjmDVhoEOVk4+91K39izoaRBd6RYZm/rBYtAQ2AA85OJ47tGqDYslFMFPZ9hXZCL7mMq1uBsEaMy9DPNsTxWDR6y7reBfqW6jIdutwJr/syT4/uEZFU+PCHCmnMveDoD9Zmu7Jeq2kpbHjpJx7ZkhqZDjQ8h5fIaY0okPe9H2m52t5Z6xg7GPW9iJGON9ntbwFRwqW87qwj4qWVqW/iTUHxiL9uSbUz2BSP1SckOkBpEy+AFBgXOU0BVwF/8u0IZKw/gpkY3Xd7kQ9l5SM9tI+S+pd1GAKgbWNo1vStqSi3ZXyXxVkcMPgfBjuCLhjkGjeiAxNYOqrwozCdnCcoALeHN9QfVxB1bojcLBaxPYIIx9mxbPcGF40pQZZehxL34jTQozleExsSaOquQI+8iO4hKIhAp8xDcW43Mnn8ESFYjOeMe86FRyH4noZ7cnA9KqIMeMPZVOrBJEH6yRLig6DlzjCGrniqPXYmsOYE+qBGqhvooiVmeLxK81UbHlYShSe8BOYnf14n2/Hm+BvYj1E7XeD1G4Gl8+hrpy+tZ9MJLyvt8MEx65dDLLtnFfZ0wTCKN4IpFnHdPXYY6np7+IMD0VsDVs+OFCOYclA28sdXq6yIH4AQQf8sAd0YjNhUCP7d+SBZm25ZY5hqivgMfylXEBOea6g6x6exniR0EMHzxFdRWNG4rfEbWK7ObTi7RGsLZX5EK0OGPg+MDzNrzmpsj8rb1Zx8jYmRI9MTmOdi1Zs8Hs0rp5TvlnKgX8QQQpFNs/vefdsytFOGsim38ZvY1fzVS3Ce3u6FIq/tlDnH69jMc3VtKXIfoTHD3pKe7E57qhXET8aKlAW2SXeVP8abVVhEfHxJSU/oksWhwzImh//NuNvJpmgbgpdMbxgLUGbV9agO9WqeGIbqvaryFjCZPAslx+2gr13RNppCd/HXlrNTMjNyKWjH0zJpOJPHMZuDbeCnBWKQ99MKGhQBoj0cHJTVANBeiGnDkS601yeZoqFjfyggRok8ebg3IjAQk/YWmQwFlYVE1hrE8MV5eJSqJvOjhrxWWxFqSU3Gn9gLNmqVDJJajCtQl8zYPnnYriF3+HJnie8Ns4Gj1VIXwyl8WJeSNNRvHqRecuakCRcEyZU118bxOJpN0o8GUPa1EIdP9IaOHNay22N6fMPb1KwheMFThtz7An3IKruIhFXErlBvyDqo+qw9gYO4CEAeHORnkYks8w+G/sdC9MSaVW6g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jAiEpWDa6jux+F81gdSt/+jtmYmn4oQOFwu9FXOPRjqangHe4qrO/3ukS0ZTZOQgN3S/AxiePF9BmMQTtA7VSnP1EEsmP+7n08NBpwGVnN7ENelgucrUt5J9jfo3arcvrNk0Xm/BS242UeE0X3KaiYNCxlZFzrEhAwA6yxIbEH7KhBm95lV9CYMQ2gwfDO4mXxP+MH+3kc/YH++FxzfOwc5+7Z9EkwfMVVOJ1K4XPDeWqSL/JTJgL5lLFLKeGWKrt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qMsKHmv1dNKJcaNkACgTwqbvGz0/ak8+PAr4UVZ/TIAEZlY7nxcqxg0Du36wsoNoYSe3gsFGEsA8VXzFRQGSCRxqwlqMXeNgdGguvqIruyxcaAZi85xF1omuUZVQaDaGVC/60p2zHz3qpXIcabDlAf6g4d/AZUiMZCSR5/7vMwrWlgU5J5GeG2a1wRTTb43k01YOKP9PCzq+26EF+eiRXn7fHGzqOQjxPaflFAjkXMNKrGM= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1261e25d-fe55-4d26-3852-08dcb66fe497 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:27.3322 (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: thLLt6fSwq5/22IhvbqiiivOZLi28L6FnVISR8eiyf+85TZFUMfn2BgXha1rYOpn X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163149_923644_2680031E X-CRM114-Status: GOOD ( 14.17 ) 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 top of the 2 level CD table is (at most) 1024 entries big, and two high order allocations are required. One of __le64 which is programmed into the HW (8k) and one of struct arm_smmu_l1_ctx_desc which holds the CPU pointer (16k). There are two copies of the l2ptr_dma, one is stored in the struct arm_smmu_l1_ctx_desc, and another is encoded in the __le64 for the HW to use. Instead of storing two copies just decode the value from the __le64. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen 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 | 1 - 2 files changed, 17 insertions(+), 25 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 e6607d9d590c4d..d23a845ad82223 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1179,31 +1179,19 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, arm_smmu_cmdq_batch_submit(smmu, &cmds); } -static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, - struct arm_smmu_l1_ctx_desc *l1_desc) +static void arm_smmu_write_cd_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) { - size_t size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - - l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size, - &l1_desc->l2ptr_dma, GFP_KERNEL); - if (!l1_desc->l2ptr) { - dev_warn(smmu->dev, - "failed to allocate context descriptor table\n"); - return -ENOMEM; - } - return 0; -} - -static void arm_smmu_write_cd_l1_desc(__le64 *dst, - struct arm_smmu_l1_ctx_desc *l1_desc) -{ - u64 val = (l1_desc->l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | - CTXDESC_L1_DESC_V; + u64 val = (l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | CTXDESC_L1_DESC_V; /* The HW has 64 bit atomicity with stores to the L2 CD table */ WRITE_ONCE(*dst, cpu_to_le64(val)); } +static dma_addr_t arm_smmu_cd_l1_get_desc(const __le64 *src) +{ + return le64_to_cpu(*src) & CTXDESC_L1_DESC_L2PTR_MASK; +} + struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid) { @@ -1243,13 +1231,17 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, l1_desc = &cd_table->l1_desc[idx]; if (!l1_desc->l2ptr) { - __le64 *l1ptr; + dma_addr_t l2ptr_dma; - if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc)) + l1_desc->l2ptr = dma_alloc_coherent( + smmu->dev, + CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd), + &l2ptr_dma, GFP_KERNEL); + if (!l1_desc->l2ptr) return NULL; - l1ptr = cd_table->cdtab + idx * CTXDESC_L1_DESC_DWORDS; - arm_smmu_write_cd_l1_desc(l1ptr, l1_desc); + arm_smmu_write_cd_l1_desc(&cd_table->cdtab[idx], + l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1442,7 +1434,8 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) dma_free_coherent(smmu->dev, size, cd_table->l1_desc[i].l2ptr, - cd_table->l1_desc[i].l2ptr_dma); + arm_smmu_cd_l1_get_desc( + &cd_table->cdtab[i])); } kfree(cd_table->l1_desc); 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 be931616d9a27e..68841ba3c2e789 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -606,7 +606,6 @@ struct arm_smmu_ctx_desc { struct arm_smmu_l1_ctx_desc { struct arm_smmu_cd *l2ptr; - dma_addr_t l2ptr_dma; }; struct arm_smmu_ctx_desc_cfg { From patchwork Tue Aug 6 23:31:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755480 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 233E3C49EA1 for ; Tue, 6 Aug 2024 23:34:41 +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=B++ncH0RJ+pDAVZWs0XZHrEN9RctEPrhMdjP7SgL2qY=; b=qFmJHRd1JoWWomtiwfjver4CWb cnsiiFHlcGU6nxLmOFA06gZVISkze+/eHnRH8s8odTXU3FKz/eEGsenT5UZMD0QXQK45p2Ad2Zy+o SZTBkSyDwAmpLmdHogZ0PQAblL0D1kWQjC0Eah2Ex2Z1te4hKZxO82e6wd6uaL0jlqXThM8wl1FkY oNHad9E4YVvbjQnU4Q35kli1GJVbvq4zlbwWMIuvs75f33T3oSGvOcXY/lLVSRmYDik5uMeurLgjQ OJ14KwlbHIJYXm9TvCF9VVnRjHGrfVK6a2zvjVidstQ7gIYfku7iFNSTCF+hx1A2XYqLuebrBEY9e iGvr++NA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbThG-00000003KJl-1pR7; Tue, 06 Aug 2024 23:34:30 +0000 Received: from mail-dm6nam10on2062c.outbound.protection.outlook.com ([2a01:111:f400:7e88::62c] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTed-00000003Jdz-3wE2 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sAUwrS5fXCzOnVmBdVXDle5ZrBV6CPM5UCurRw6IFEP7J+u90WxRLXKVOqu4N7HAaZUlsGsEp3Z0Zfr25twFiExhb6HET1DKiPgkLJMiiQLYQYt+i/CeQ2d1njBjUa6HuRUzVY4jy5qdQwOCN/xdW6y6XGBVLDb1HUbWFGT/NkAXUA+cp1brGYDFv0rqPp+fZN7RVyViPZTwNhBy1SD5xFUhE8oQ4Qs1KshyTS8QTrOqTzce4KN5nBlXfpl5Ed20LFIIkB6PlbuYyOwQEcB5BAHSNxngzrgr4WGcBM+d5Hq6WcBi34/pR0bkvy/I8YNho/jexRpGYs3kvhAYk12UIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=B++ncH0RJ+pDAVZWs0XZHrEN9RctEPrhMdjP7SgL2qY=; b=qGofdVtK46IThGmpiUo+xLbVn33htxObK8HSIWKf6iONHp6DpiE4u1b5AGsEZRlkUzcELS1l4qX3xA4FSmGkMLgI6jePfAQD/syXtFzyVBk/xrODKFLRpHy/TMcneRfKbtc4jI76l8PwvHzCOjP2Cvo+BkXr5Gde4UfRv6CJZFRsBQh9M4xQgf3eQBA6LFD+3vm8qpBadplohv+FkmEmWJqxxX+BImZUNrjtsmIX+9Mzl49KpBJTYiot/Zr17QnSunjqUWj+7xaLGBjtH5YfkgsDJBrveIrFyGkDgqMolc/C1lf9urthmO9pSKnAji6HgNEUq036S0f33ZkNjtTcRQ== 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=B++ncH0RJ+pDAVZWs0XZHrEN9RctEPrhMdjP7SgL2qY=; b=EV9VqhzTuJTb+JWt7djkI4+CdsctD/fjYBSps+TdEOD5qfOxlBftovzZLNcV3bFY0X2aH1NgVDyHNgEeSFtw6jvCK2wl4p9f12PC4qDL9et8pSojfqUcH6NLCZ5kd2cIUapcqeoYobvx4+wb2caQrjRxy43hNS4LN06S0+IGQ2UldTeBaJZib1ZaaD9HW3L6DidGllWCx+4fRgRFWhl4g9bWeODdSX3ytmKJQtH+pkv2omNcepljOZf8cLC+Ck+LJrKIj2swmiQc/giEe0wx9rO1XNzQQON5Kmivw854vVIGPFpjg92PS7gTnfrrra4qMqFocQKkuCMUoUVNhsZIxA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by PH0PR12MB7839.namprd12.prod.outlook.com (2603:10b6:510:286::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Tue, 6 Aug 2024 23:31:31 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:31 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 8/9] iommu/arm-smmu-v3: Add types for each level of the CD table Date: Tue, 6 Aug 2024 20:31:22 -0300 Message-ID: <8-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0108.namprd03.prod.outlook.com (2603:10b6:408:fd::23) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|PH0PR12MB7839:EE_ X-MS-Office365-Filtering-Correlation-Id: d584257e-83d0-4c39-8487-08dcb66fe467 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: NQh5NkbPzCqkzBB1YbrfnHMz7J8XJ08F/g4xnZnBCOqSLFm0TW2FoPh/619m6d01+noyVg+FBlSw46hS4mMbocsapYcPnHZ0//Sm8LOok7XgWllwirELzgE2+wf//zmmHqTAo3Ckj4Rm2AccBq3ygb+/4OPjnRauiSIN94BQyb5ox9WseatL5DBujPPnWiFJXZ5tvhnNS3noRcHQYa1C3EpGC/iHApIyPyRWrU5kuSuO27mqYmvzlBw0kCaI/by/lqps78tGD3j/5gKPFDTSgj/3MBeWQ8ZY+++xgvq1KyVLAqKARSchDUqChvt6IINNjCRxlml1tTz46laoYG5exOMKgA0OnfbprqaQSyN5xFr/B8XtnNQYUXLb0LXQRjO0BlIi7LN3AK0ERHSeY6Uy3ygWfk2mfHqeFMDNm4He9+a7/ZAvqDxcJpU2QmNP2dBzF0um8P5yU2rW8xBE+/etFcDNezjOwuSpa8KY9pJktLQFARavh93tLLxeaw4/1YHDdPT0ceop1ySWe5zpNjQOkbWQkB59LYH4NLZZBkUfXPPC7wGS2FRuJozvmu1JE3BFYQpMLRrtoJl93A9ohufWI5GtYK9SdOiTWuEF0ERhWX3hd6gEQ0Xw964E9WnJ/jXLC2jRw9REmASiqMvsCMs9YgzFIbc+Tt7Di8cwo148z4e4JtrDPHoqtcH9zXShIVzxDRHWXvdIaCUgn+TCXZjP/I6c1qW78fScS6SWazyxKw7109rdPRfHMpyGrDXX/AW3hH7slAd0+Sy5xwCsd2pEaOeGs9TA2TlZ9Nq9cmZ1G2Wbwg6JqtlAE8X2UcOWSVLluCw3sxSt8Oc7bHMXTuv5cOMLyYnZ78HCz1bToG3gDPoM87bQBvC6sWIlwxYSfhbMhWOQOrjMkRHnTu1VsU/OVg2NIXx0p8RmWIqYWRLqVQIbi3s3SIvtIgrOl1BocRXfCqZyR6fqF7wh+bEk6T6XLe0YRkxagHsfEsBnmvJ+ZWifGZKi0bf94ciz71QiegTkI++8nuwsES+9/mwcC2rZ/FEYuRfAHDyrEqvoumJWNMf7ziyEih6PfFAB/jxBVCj9XDeOq/jwuaNN9lsIoWtJDiZFm71uSJ7wWQ+FIYNV9PZkFJm8KIvwHQbvBUA8YZtqhyMT5ZcnbLPv/80vlYeWkUEvUDwWsUIzXHkxZnClW72NT8G9e2iCjt8hLZca3jU7tHXd7hrOwtrLSO2Uf2nX+6iY5PrNHHUSli8sBQdhRkHb924DV+UfOS4S55nIE9xDGkJqC/FalewXmM1skRpQM7a8ePMngiBgsyzGS+xkLQawEJrcQuz7+9as8ZJimdYGEynrQy58cG4ZGJSsbCrgJA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HocpmVn0Y2i7koyrz6NeYSShnvXfg9jl2/C0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vzE3sOgp5R6p/hQZaVicOEquDeZ9qprzKeUxGZfLT0M/HJKHvjM/jdpLkk8IfEh3Nso7jZhPe27Y+vXfmkugfuqrUwKX6ih11g9jT6Y4uUIruC0izTBZCmUIf/GHtOjXBbDEFOZL1ddh+2tN4G7WDr5/SN6vGIWufYwTc3E2eptzJC8sED+u35MlVhzdiX38BB6yKcrpLpGTMSwd7nVmRRoY8rikJJkakJdYIe9Z9x+e0SM9+kikYEYcHkaKNDt2YEBXZaB9n3kNC8aWEyCVre/ttsmsIMY4g+byA/nW/z2O/c48fQdGCKXHykK8LHOIP+QpOCVlLjReEaVU4NrOPkqIulpBZEd/d8nFk4Wep5TBKaNsXQY8qOmZTBCuU0tUluQUbTGRO6W6H+1r9+Ay7cVmIKt3EOGeEX+7cTlnumJeP7ID+txaY0456VU9esa6xNC163O+ina9jbO2bhc= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d584257e-83d0-4c39-8487-08dcb66fe467 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:27.0595 (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: wx38eVY+/ElkzUKcG2lHR/vyi6i2wC1IKtFBNJfPfinBbEkqPUQ4CBdzUIumLjTT X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163148_023456_12F78A9F X-CRM114-Status: GOOD ( 15.11 ) 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 As well as indexing helpers arm_smmu_cdtab_l1/2_idx(). Remove CTXDESC_L1_DESC_DWORDS and CTXDESC_CD_DWORDS replacing them all with type specific calculations. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 46 +++++++++++---------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 27 +++++++++--- 2 files changed, 46 insertions(+), 27 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 d23a845ad82223..70b37d7f0e245d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1179,17 +1179,18 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, arm_smmu_cmdq_batch_submit(smmu, &cmds); } -static void arm_smmu_write_cd_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) +static void arm_smmu_write_cd_l1_desc(struct arm_smmu_cdtab_l1 *dst, + dma_addr_t l2ptr_dma) { u64 val = (l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | CTXDESC_L1_DESC_V; /* The HW has 64 bit atomicity with stores to the L2 CD table */ - WRITE_ONCE(*dst, cpu_to_le64(val)); + WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); } -static dma_addr_t arm_smmu_cd_l1_get_desc(const __le64 *src) +static dma_addr_t arm_smmu_cd_l1_get_desc(const struct arm_smmu_cdtab_l1 *src) { - return le64_to_cpu(*src) & CTXDESC_L1_DESC_L2PTR_MASK; + return le64_to_cpu(src->l2ptr) & CTXDESC_L1_DESC_L2PTR_MASK; } struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, @@ -1202,13 +1203,12 @@ struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, return NULL; if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR) - return (struct arm_smmu_cd *)(cd_table->cdtab + - ssid * CTXDESC_CD_DWORDS); + return &((struct arm_smmu_cd *)cd_table->cdtab)[ssid]; - l1_desc = &cd_table->l1_desc[ssid / CTXDESC_L2_ENTRIES]; + l1_desc = &cd_table->l1_desc[arm_smmu_cdtab_l1_idx(ssid)]; if (!l1_desc->l2ptr) return NULL; - return &l1_desc->l2ptr[ssid % CTXDESC_L2_ENTRIES]; + return &l1_desc->l2ptr->cds[arm_smmu_cdtab_l2_idx(ssid)]; } static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, @@ -1226,7 +1226,7 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, } if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_64K_L2) { - unsigned int idx = ssid / CTXDESC_L2_ENTRIES; + unsigned int idx = arm_smmu_cdtab_l1_idx(ssid); struct arm_smmu_l1_ctx_desc *l1_desc; l1_desc = &cd_table->l1_desc[idx]; @@ -1240,8 +1240,10 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, if (!l1_desc->l2ptr) return NULL; - arm_smmu_write_cd_l1_desc(&cd_table->cdtab[idx], - l2ptr_dma); + arm_smmu_write_cd_l1_desc( + &((struct arm_smmu_cdtab_l1 *) + cd_table->cdtab)[idx], + l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1385,7 +1387,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) cd_table->s1fmt = STRTAB_STE_0_S1FMT_LINEAR; cd_table->num_l1_ents = max_contexts; - l1size = max_contexts * (CTXDESC_CD_DWORDS << 3); + l1size = max_contexts * sizeof(struct arm_smmu_cd); } else { cd_table->s1fmt = STRTAB_STE_0_S1FMT_64K_L2; cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, @@ -1397,7 +1399,8 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) if (!cd_table->l1_desc) return -ENOMEM; - l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size = cd_table->num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1); } cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size, @@ -1421,27 +1424,28 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) { int i; - size_t size, l1size; + size_t l1size; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; if (cd_table->l1_desc) { - size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - for (i = 0; i < cd_table->num_l1_ents; i++) { if (!cd_table->l1_desc[i].l2ptr) continue; - dma_free_coherent(smmu->dev, size, + dma_free_coherent(smmu->dev, + sizeof(*cd_table->l1_desc[i].l2ptr), cd_table->l1_desc[i].l2ptr, - arm_smmu_cd_l1_get_desc( - &cd_table->cdtab[i])); + arm_smmu_cd_l1_get_desc(&( + (struct arm_smmu_cdtab_l1 *) + cd_table->cdtab)[i])); } kfree(cd_table->l1_desc); - l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size = cd_table->num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1); } else { - l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); + l1size = cd_table->num_l1_ents * sizeof(struct arm_smmu_cd); } dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, 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 68841ba3c2e789..681804a3f86bec 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -296,16 +296,31 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) */ #define CTXDESC_L2_ENTRIES 1024 -#define CTXDESC_L1_DESC_DWORDS 1 #define CTXDESC_L1_DESC_V (1UL << 0) #define CTXDESC_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 12) -#define CTXDESC_CD_DWORDS 8 - struct arm_smmu_cd { - __le64 data[CTXDESC_CD_DWORDS]; + __le64 data[8]; }; +struct arm_smmu_cdtab_l2 { + struct arm_smmu_cd cds[CTXDESC_L2_ENTRIES]; +}; + +struct arm_smmu_cdtab_l1 { + __le64 l2ptr; +}; + +static inline unsigned int arm_smmu_cdtab_l1_idx(unsigned int ssid) +{ + return ssid / CTXDESC_L2_ENTRIES; +} + +static inline unsigned int arm_smmu_cdtab_l2_idx(unsigned int ssid) +{ + return ssid % CTXDESC_L2_ENTRIES; +} + #define CTXDESC_CD_0_TCR_T0SZ GENMASK_ULL(5, 0) #define CTXDESC_CD_0_TCR_TG0 GENMASK_ULL(7, 6) #define CTXDESC_CD_0_TCR_IRGN0 GENMASK_ULL(9, 8) @@ -336,7 +351,7 @@ struct arm_smmu_cd { * When the SMMU only supports linear context descriptor tables, pick a * reasonable size limit (64kB). */ -#define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / (CTXDESC_CD_DWORDS << 3)) +#define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / sizeof(struct arm_smmu_cd)) /* Command queue */ #define CMDQ_ENT_SZ_SHIFT 4 @@ -605,7 +620,7 @@ struct arm_smmu_ctx_desc { }; struct arm_smmu_l1_ctx_desc { - struct arm_smmu_cd *l2ptr; + struct arm_smmu_cdtab_l2 *l2ptr; }; struct arm_smmu_ctx_desc_cfg { From patchwork Tue Aug 6 23:31:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755482 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 B7CAAC52D6F for ; Tue, 6 Aug 2024 23:35:46 +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=avacmMrQ5myRDCNuypGXcU1mUVf8sauVWQzFhQgoo4o=; b=c2jZu9Epp6y87NUq0TGt4XWSoy 5zqcxnqwWc7sWBRJ349Eo2GGKp6FUc3/bxXfQXpbmfvzGdLiO3TI3Z+R0RT7JWMV/oUlmaB5Yciux Ziu8jcM6ijvoQ3qgt+7zukH2bpyZmSWNaasfC+QewrxW7dRf7xexVyEN27u61TvQ1iZC5FdezPpqy bqOITWMbgvfrQ4PUit6lf3ddVvZsohHmjoRywjH5O8nf+dGglVvOXsiUKyKqLjTRgAGmzYO8RZYMZ S2+EViCDfsI5JN0HCbx3s1OHnIwLHQTa5sQ8jq4OI4nQpeZ4jhVzulARDyuAbhd3lbFzqsmPYp88d +kSBHgpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTiJ-00000003KYn-1r39; Tue, 06 Aug 2024 23:35:35 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTef-00000003Jej-1f7G for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ltgEMeE3eQVBWIXlVrvE+b5IQ68jBXW6A4wrKBn5cTsZFHAkX58Wq9TA4rcTPN8RiAkjTE5TvGaDhXZw35ss5ZX/8pO75wwnfOp5wmBJBTmXLVZn63Sf/dldNmK/WRgaA/3Ib1wD+1gryyRdOxaPAFtPHL30ADrOkBQw6za5Sf4BX287Q+gLoXd7rgyMxoQTifKnEPLUgUpGSeoLfa4Kg7VXLB3OTRzX4mEvChqj9hYrSNf0q80dtwX7ZBaqnUoZ3r6qydacrkbNxAexiKsI1VtoK9u/WHR9gCx4euo8VmTUl/co0T66DGt/N35rh6CBOx/k5wcS39D7RWxO5dzUdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=avacmMrQ5myRDCNuypGXcU1mUVf8sauVWQzFhQgoo4o=; b=MSQzFPeWFdAyZEbHiGiVrSuKDnDYalCT4Q2MfIdyfEjAegVvst7PV70Xd8cKxFJNGEvxCEkOuZczNVstWzwKBAu54j7b0icOPy9up6pnShFD4mqLBU2ncyvLo07xkqr8tNhIH7aUpRAiiqpkQs1TmGkAACMjNa7lVC5/vqLArs6/CeeMw234Iz7bLGGA9xGbr909lGa7BTWjl7DRJs1J49C52f6sObyJiiVoi23dcThqrAsTilN3ceFX3VCzQKKiw/XrJVLvuufiyC0MzZwo0HC04tlAr1DkrYiWECjpY4ntxuIiRUKTkXwM4VhuWOJsG9SastdVLIvqI79LPasR2A== 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=avacmMrQ5myRDCNuypGXcU1mUVf8sauVWQzFhQgoo4o=; b=HInd/qodDRFjO2oMqtys3ulw0zU4QcHRJ8Ud3Y/a/ObmfdlGcdJagdylnmWWGkUuS1woJad5/PPFOVFKxeYJsRSWo+E049iSLYjrbYY4Wng7A54TjRP/1U+901QpYMWe43leO6eiXUcPqHgv0RhvDUDS85u+58Bnb7ZH/Ywx+Gk1h9LZqlckjDZNIcVEARJELQeIKgT6q953wvstnNodvu9h2pxmnyvdblGU8eqMQUnBekTqsq0oIVtw0G+kutoOBYOx6baRJ5MVQdR4L5hs+JUfOHLnFVAFnczrInyg4Aj6CpSnrkbrWnbmEpYK6fVSL+ZU6CV5hgQWClSYNP+jug== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 23:31:29 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 9/9] iommu/arm-smmu-v3: Reorganize struct arm_smmu_ctx_desc_cfg Date: Tue, 6 Aug 2024 20:31:23 -0300 Message-ID: <9-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0410.namprd03.prod.outlook.com (2603:10b6:408:111::25) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: afca6dc3-d63f-46c6-b202-08dcb66fe342 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: N4rrqHRTCglOh/bOy55zC6OepBVees8eNT3BQK3X3P5hLTFSgcnDcqX8oJ2oV1siRLOBSIBCA26D8kAHfmjgceA+zQhSEmYm3Bdxuo0U7TlsSNrLClEbMbX5MHb7fHDNrSJ9XfIpYehQcXtsOWYYrl6Bwk6t2/TCCIaAEThs5uTX0lRtoJT7smU7WJSjlP8VEDdGahRlpp6oJmcjOS6l1Zjt8UesbgdXehcWojpCq/zNpuRGb5E0Mkd+/T2+3nHtkJ9AlN2mI8qqosnB7/mgEWRYQpqdIx/lp2Qi04FpwQpeN58qFas4QxxdLdMcW82qEtDptqHOY+WRcdRQQXmjJAk2/pwJVk9xiabCE3lgFHVsQn29i+193dRZ7Vom6ab9BvnQZCu/nY8UhDsRCCMI/eOjP4ZdsdHz97CNJUFmFquTQjLxybawTfTc9TknPf7FstYq20ym77/n8dAIsjLP1td4GmzAcwuA5IQ4104lEXZtc7RQo8C37OGz7o2NqB6cZYIextsgrW6pXb/LZRok+QR3TuVkPol0WXk7nAT720oohYPrpnqz0hrndcZLQSs/YHobrPSU4tRfkFiNdbAcF4CbtAKpL/IG6GWecBJpHZkqPn54vrgfj5ivESOvPfTrcPpHd79jM16L02HwcxEmJqPCwREhTAWeeUvY1XTIUwOvb8Cxv7MJdQfcgtxX7psODXLjBKuNsoufWKtGRZeB9HBi2MtMA6OXQt2beOnwnMLYVTWJV5zbDEeXru+FMXpZnGXZjyMV5N1Bn6Yz3psZUq6v+XGDfuLhMawIaMqaxIdHJnDcp6G6J4WjQJ5H62HWyDmJUAGaKQn6JH1ulCyutB4mda1DfCfWbIz0wBOhlBNXSTKIJ2B1jgvxKOP9dnKVQjuFX2TL0YrLK4DveM1raB2pFULauD3NVg4WFID/KBvkGFAWTaRnHFMg8tyzIOaBsnG7BPV7byU2KTR0q5+pOAhQNxor8VlsVT8rYKh3R08+AmFNA0NoyFjPFzaT2aRHXBGaDorgjuQL/gpNBqVbQF9D1hDuLmK512l7AwOWd8soYYwB7nbi8WcMEdvoBu1YSwt4qKCfJ9xBl1u9XcKUtyJSwml/iZzc7AntJC2xVDKVNg5oOJ858+1idJlcTKJhzE6X+wLr/1dM9iG5KkTyvRsEgpuOatLhV8eOP4LsvBu0vfCkReNNqmZwhkVm1jyuGXA9e3YepFkEqm9Naf6oSRVgvb1J8s0tnfJLq8XBy79+gQ9Rut2oW8H829POhvL6EcNLggDEgs5H+kdC4mePf5A2xPRj0fQLJIoXGJ2lFlM4P8heN1B1JoiF0kaWmV9APOP9lEM23fSJB9Pc6T8vMg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sgfWjqYYRo1JadIcLyXxiLGEUaVh3O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dITdZVUlE/86MQ2HdZMsPX64qXECR0muLOrzpF4zERS0hW2GWFRQNngJeb2DC5NknsH1P+rS4lAz4ACALHkIFgaGclfNsUcWcpTP7pZuZp6PpSU1MR6ENyzfRmHZ9UqbsZZ4ZktAgKvzKXyAWLgHl/rmnLOiMXONa8nQbDXWmv4IZEfCb0MY8gpxOZGVplGzKtAOzqGCsjVUkHbPCVPjsct21+XL4QoBE2HT8bBbDqgbumqDdc23g/VbSdeNp+I9he08W0/cs8oWOQXfvs1bdqofTbEEyLk0Pn9x2PO0Ptcd+XZ7Ez7fqC62dH9XGOonvTGf7dBQh6hqdldwrpM3VPIfOIHlwwcj3zdilLma+8RCHYKnMGLXW187jsI/SO8/0PYwAotRaa662RVYfXvPe9hTF8FdiMB9C2+61yr/HL0+SVfFDdJQDXKcGkYBj66UplWcgNXrKN7xZB7OZTSg1CZvNG/J1oXm7CYpeRZrpZt7GfjSeRLjk1 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: afca6dc3-d63f-46c6-b202-08dcb66fe342 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:25.1948 (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: MF9OSrz3FQdiFk9yDjKnxCpJxdxtlgLTncFNIXmTFNKuOAQXwxzzL+fQjP64wAoI X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163149_504432_46AB7D1A X-CRM114-Status: GOOD ( 17.50 ) 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 members here are being used for both the linear and the 2 level case, with the meaning of each item slightly different in the two cases. Split it into a clean union where both cases have their own struct with their own logical names and correct types. Adjust all the users to detect linear/2lvl and use the right sub structure and types consistently. Remove CTXDESC_CD_DWORDS by changing the last places to use sizeof(struct arm_smmu_cd). Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 119 +++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 24 ++-- 2 files changed, 71 insertions(+), 72 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 70b37d7f0e245d..e5db5325f7eaed 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1196,19 +1196,19 @@ static dma_addr_t arm_smmu_cd_l1_get_desc(const struct arm_smmu_cdtab_l1 *src) struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid) { - struct arm_smmu_l1_ctx_desc *l1_desc; + struct arm_smmu_cdtab_l2 *l2; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; - if (!cd_table->cdtab) + if (!arm_smmu_cdtab_allocated(cd_table)) return NULL; if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR) - return &((struct arm_smmu_cd *)cd_table->cdtab)[ssid]; + return &cd_table->linear.table[ssid]; - l1_desc = &cd_table->l1_desc[arm_smmu_cdtab_l1_idx(ssid)]; - if (!l1_desc->l2ptr) + l2 = cd_table->l2.l2ptrs[arm_smmu_cdtab_l1_idx(ssid)]; + if (!l2) return NULL; - return &l1_desc->l2ptr->cds[arm_smmu_cdtab_l2_idx(ssid)]; + return &l2->cds[arm_smmu_cdtab_l2_idx(ssid)]; } static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, @@ -1220,30 +1220,25 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, might_sleep(); iommu_group_mutex_assert(master->dev); - if (!cd_table->cdtab) { + if (!arm_smmu_cdtab_allocated(cd_table)) { if (arm_smmu_alloc_cd_tables(master)) return NULL; } if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_64K_L2) { unsigned int idx = arm_smmu_cdtab_l1_idx(ssid); - struct arm_smmu_l1_ctx_desc *l1_desc; + struct arm_smmu_cdtab_l2 **l2ptr = &cd_table->l2.l2ptrs[idx]; - l1_desc = &cd_table->l1_desc[idx]; - if (!l1_desc->l2ptr) { + if (!*l2ptr) { dma_addr_t l2ptr_dma; - l1_desc->l2ptr = dma_alloc_coherent( - smmu->dev, - CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd), - &l2ptr_dma, GFP_KERNEL); - if (!l1_desc->l2ptr) + *l2ptr = dma_alloc_coherent(smmu->dev, sizeof(**l2ptr), + &l2ptr_dma, GFP_KERNEL); + if (!*l2ptr) return NULL; - arm_smmu_write_cd_l1_desc( - &((struct arm_smmu_cdtab_l1 *) - cd_table->cdtab)[idx], - l2ptr_dma); + arm_smmu_write_cd_l1_desc(&cd_table->l2.l1tab[idx], + l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1363,7 +1358,7 @@ void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid) struct arm_smmu_cd target = {}; struct arm_smmu_cd *cdptr; - if (!master->cd_table.cdtab) + if (!arm_smmu_cdtab_allocated(&master->cd_table)) return; cdptr = arm_smmu_get_cd_ptr(master, ssid); if (WARN_ON(!cdptr)) @@ -1373,8 +1368,6 @@ void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid) static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) { - int ret; - size_t l1size; size_t max_contexts; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; @@ -1385,71 +1378,67 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) || max_contexts <= CTXDESC_L2_ENTRIES) { cd_table->s1fmt = STRTAB_STE_0_S1FMT_LINEAR; - cd_table->num_l1_ents = max_contexts; + cd_table->linear.num_ents = max_contexts; - l1size = max_contexts * sizeof(struct arm_smmu_cd); + cd_table->linear.table = dma_alloc_coherent( + smmu->dev, max_contexts * sizeof(struct arm_smmu_cd), + &cd_table->cdtab_dma, GFP_KERNEL); + if (!cd_table->linear.table) + return -ENOMEM; } else { cd_table->s1fmt = STRTAB_STE_0_S1FMT_64K_L2; - cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, - CTXDESC_L2_ENTRIES); + cd_table->l2.num_l1_ents = + DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES); - cd_table->l1_desc = kcalloc(cd_table->num_l1_ents, - sizeof(*cd_table->l1_desc), - GFP_KERNEL); - if (!cd_table->l1_desc) + cd_table->l2.l2ptrs = kcalloc(cd_table->l2.num_l1_ents, + sizeof(*cd_table->l2.l2ptrs), + GFP_KERNEL); + if (!cd_table->l2.l2ptrs) return -ENOMEM; - l1size = cd_table->num_l1_ents * - sizeof(struct arm_smmu_cdtab_l1); + cd_table->l2.l1tab = dma_alloc_coherent( + smmu->dev, + cd_table->l2.num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1), + &cd_table->cdtab_dma, GFP_KERNEL); + if (!cd_table->l2.l1tab) { + kfree(cd_table->l2.l2ptrs); + cd_table->l2.l2ptrs = NULL; + return -ENOMEM; + } } - - cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size, - &cd_table->cdtab_dma, GFP_KERNEL); - if (!cd_table->cdtab) { - dev_warn(smmu->dev, "failed to allocate context descriptor\n"); - ret = -ENOMEM; - goto err_free_l1; - } - return 0; - -err_free_l1: - if (cd_table->l1_desc) { - kfree(cd_table->l1_desc); - cd_table->l1_desc = NULL; - } - return ret; } static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) { int i; - size_t l1size; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; - if (cd_table->l1_desc) { - for (i = 0; i < cd_table->num_l1_ents; i++) { - if (!cd_table->l1_desc[i].l2ptr) + if (cd_table->s1fmt != STRTAB_STE_0_S1FMT_LINEAR) { + for (i = 0; i < cd_table->l2.num_l1_ents; i++) { + if (!cd_table->l2.l2ptrs[i]) continue; dma_free_coherent(smmu->dev, - sizeof(*cd_table->l1_desc[i].l2ptr), - cd_table->l1_desc[i].l2ptr, - arm_smmu_cd_l1_get_desc(&( - (struct arm_smmu_cdtab_l1 *) - cd_table->cdtab)[i])); + sizeof(*cd_table->l2.l2ptrs[i]), + cd_table->l2.l2ptrs[i], + arm_smmu_cd_l1_get_desc( + &cd_table->l2.l1tab[i])); } - kfree(cd_table->l1_desc); + kfree(cd_table->l2.l2ptrs); - l1size = cd_table->num_l1_ents * - sizeof(struct arm_smmu_cdtab_l1); + dma_free_coherent(smmu->dev, + cd_table->l2.num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1), + cd_table->l2.l1tab, cd_table->cdtab_dma); } else { - l1size = cd_table->num_l1_ents * sizeof(struct arm_smmu_cd); + dma_free_coherent(smmu->dev, + cd_table->linear.num_ents * + sizeof(struct arm_smmu_cd), + cd_table->linear.table, cd_table->cdtab_dma); } - - dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, - cd_table->cdtab_dma); } /* Stream table manipulation functions */ @@ -3299,7 +3288,7 @@ static void arm_smmu_release_device(struct device *dev) arm_smmu_disable_pasid(master); arm_smmu_remove_master(master); - if (master->cd_table.cdtab) + if (arm_smmu_cdtab_allocated(&master->cd_table)) arm_smmu_free_cd_tables(master); kfree(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 681804a3f86bec..8851a7abb5f0f3 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -619,15 +619,19 @@ struct arm_smmu_ctx_desc { u16 asid; }; -struct arm_smmu_l1_ctx_desc { - struct arm_smmu_cdtab_l2 *l2ptr; -}; - struct arm_smmu_ctx_desc_cfg { - __le64 *cdtab; + union { + struct { + struct arm_smmu_cd *table; + unsigned int num_ents; + } linear; + struct { + struct arm_smmu_cdtab_l1 *l1tab; + struct arm_smmu_cdtab_l2 **l2ptrs; + unsigned int num_l1_ents; + } l2; + }; 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; @@ -635,6 +639,12 @@ struct arm_smmu_ctx_desc_cfg { u8 s1cdmax; }; +static inline bool +arm_smmu_cdtab_allocated(struct arm_smmu_ctx_desc_cfg *cfg) +{ + return cfg->linear.table || cfg->l2.l1tab; +} + /* 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) {