From mboxrd@z Thu Jan 1 00:00:00 1970 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 5B6C3CE7B09 for ; Fri, 6 Sep 2024 13:23:42 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ndoe+jggZegMqqcw6iIAw3CEtYeGnFcOdhVufXf0JO4=; b=3R8GeBL3x/LmByi6SBYmSCW9vi rDLefEibIPli0qrSEFQOdthIOQDUaAr2sHY4G7TTisvKrtFwflzA/DCDxnRwwpi2zermoQAqNeB3g gEFgp7pQAdXmw7RfxMgs5lqnvPq85cepA7ZUTO3BMq8X+Ox+rLfmH0Gb8F67ksXSI8rx2BmBEeveR lEx6a//DJy8R2liylLxIC7SeNKAdSkE13qjv/E5Xi8v9zsUJ/yGiADGwwMqDz5olQEQdhNi/aUL6n ZOX0GtU7HyVJH1yYY4H0kYTjfsOUYeuLoz3tOC+O1oen4RFc+xiPC44Cj7iVbFjAXtDCDrc9ZRtNT EskQdEYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smYvy-0000000CKFU-3jVs; Fri, 06 Sep 2024 13:23:30 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smYuz-0000000CK5x-0Mud for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 13:22:30 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C19FC5C5A72; Fri, 6 Sep 2024 13:22:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29ECEC4CEC4; Fri, 6 Sep 2024 13:22:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725628948; bh=eG+K9U2FPeMI2cKAx5U5Lhi1CeOmU3bujeYYMdm/q6E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AU8L3ybYUfNUEZduNf/LmtCvO8PERSS1csPoSJxkkvRp/kuT4s6F6FpF6hf2iB0Bn nSjli2BsAxUFaUv7CUmKNgoejuQpBNiAFFczsR5tb2AI+FxZBqPscrfEfcFJbTR8ST fjsO9n916x5oIVFyEc8AbbWY7Z1oOywHv8qKphuCSnDeXyy/+A1IXrM9nOTpUwtwX9 bH7TpNQ56NJWIBCX2h94o8dnW0nqlsdpjNe3JFpSLJddTqcP6l6lo+RShqj1cUrVUn Z45mfZjy88TBC7JjgaiPTRBWNkOGb+5RuBfLrrDaFy0PoAJ2iEEzPU63JTlqxbOiyW O083wHyUd6Ebg== Date: Fri, 6 Sep 2024 14:22:22 +0100 From: Will Deacon To: Jason Gunthorpe Cc: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: Re: [PATCH v3 9/9] iommu/arm-smmu-v3: Reorganize struct arm_smmu_ctx_desc_cfg Message-ID: <20240906132222.GD16959@willie-the-truck> References: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> <9-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_062229_286141_FF2A28E4 X-CRM114-Status: GOOD ( 14.03 ) 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 On Tue, Aug 06, 2024 at 08:31:23PM -0300, Jason Gunthorpe wrote: > @@ -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; Why inline the error path here? Sure, I get that it works both ways, but it seems a little gratuitous to me. Will