Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2474293rdb; Mon, 5 Feb 2024 07:40:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDc3ribL1AM+027rR1of/pHPHT3E8mHwpRAtS8BrF71DwzVxqsAy6++mktRBMZOUSA8VCm X-Received: by 2002:a17:90a:6c63:b0:296:6931:e70c with SMTP id x90-20020a17090a6c6300b002966931e70cmr43831pjj.19.1707147635013; Mon, 05 Feb 2024 07:40:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707147634; cv=pass; d=google.com; s=arc-20160816; b=F1c9HgOrr3VAjxKQ9vzXDfyURNevHAQU2XCYV1CfseymrQBwrDL51NuInHhAxeWMpz v2bCoSP3W7sWNBQsG629f7ChkBBF7+HTzRkvdKB1wmYbJIw1Rf04h+dbHl5ql+HoMyhR RA8S2cGTHjWT9k9oj6nOBCEgttr0AgdJ9qEr8RvPMZVnFhb1HmNdcrx/QNITLzgxM+iE mLLZbEaYNOu2IXnQeZK9UyYwtLRGY6yl63PuntWzGGPmpvhvKanvepgTxnv24QAa3cZA 4MU4+MJLOevmCYZo3XxQdTLf0qxRjcR+znF+zHLmeyYrFP1B5upNpVB8v2KVafwnry3y ItWQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=yY+4M7kMt2BVJso2Lto96zv05XHdud4jM/u756+6AO4=; fh=wt8CaJk3YmMTjRRInKN+lJml1f59czVR+Hw6MKb+RiA=; b=FXYuqJYyhzV0qXffqjufocjG35yp2zjrtdWzWJskoebCKY7WQb7u2xwXKY2kuVQQtx pPdG3g+6RYcbDlaL2pFAEXQJLcGqW4bXYO7U9xEXPNt95AfjS7wvULjHm7rHfqrAFhrR 2Dab9mRHVb8x6ymvHLYx0GExysqesLTbF2TOid1eJw3dtiaWnRoCo9l3AQtXwpN+XPjC TuTuKzJfmkoOWvgigeF7GUk7XNOQ1M8GI+eEP4cjz6FvfN+ACyp0Ikgy4oRRutGM74UH 5BdDOopLhb5J/QSSfS7PYBtTEsLYFnha/PRuKX5JED+0LWksE7l8F+8kYs56kzpuG1+q NQlg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-52916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCUj4cZ3Ent3+FBSzWaYa9+biVF7yJJNyDqyFscFS2r3nGiOuBHjkm4fPbpQHH4lrcPThowCUjeTbYNGMZMCL/tVmnP465TMhMI14uxzsw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i10-20020a17090adc0a00b00296377bb025si4721549pjv.55.2024.02.05.07.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 07:40:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-52916-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0F801289B43 for ; Mon, 5 Feb 2024 15:33:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 180483D3AE; Mon, 5 Feb 2024 15:32:51 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 082503A1DE for ; Mon, 5 Feb 2024 15:32:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707147170; cv=none; b=r8plPvrbMbw4u1EXr9V3ij9UIw5YiZD9z0W0UyTDg/+d0M5hPCw0yreJN9t1OYjjbTCDXJRMlhOOlfMfpZC68IMv0DRouMl+Rwb4+qbxac4Ujr6zVWeOy3qQYftdrxNCt2uIX1gs/ocb1uW49NDBr7nmcsU7Sq9bxg1S7CAMpmg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707147170; c=relaxed/simple; bh=M6yxaufXQSaUctlg9rkP73rx1vbqTh2nUd3NBrS+Se8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NkBfw+TqNdEqpsRDcbhiMFp6W5CPPvkHrm+jhUEwuhyt6vsdfcIBT6UvYB5xlqB4T7zan4gd1WuLL/HIEdrTE3Z2gPkIDAZTLWZKdsLJUjRQcy9ndSG/guk0544IoknHaOdFeJOjJIFMimB1aaLztC1fa+XFZR4thiIf0rDrzRU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 36CBDDA7; Mon, 5 Feb 2024 07:33:30 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6A7DF3F5A1; Mon, 5 Feb 2024 07:32:46 -0800 (PST) From: Robin Murphy To: joro@8bytes.org Cc: will@kernel.org, pasha.tatashin@soleen.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, rientjes@google.com, yosryahmed@google.com, john.g.garry@oracle.com Subject: [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure Date: Mon, 5 Feb 2024 15:32:39 +0000 Message-Id: X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Failure handling in iova_cache_get() is a little messy, and we'd like to add some more to it, so let's tidy up a bit first. By leaving the hotplug handler until last we can take advantage of kmem_cache_destroy() being NULL-safe to have a single cleanup label. We can also improve the error reporting, noting that kmem_cache_create() already screams if it fails, so that one is redundant. Signed-off-by: Robin Murphy --- drivers/iommu/iova.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index d30e453d0fb4..cf95001d85c0 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -254,26 +254,20 @@ static void free_iova_mem(struct iova *iova) int iova_cache_get(void) { + int err = -ENOMEM; + mutex_lock(&iova_cache_mutex); if (!iova_cache_users) { - int ret; + iova_cache = kmem_cache_create("iommu_iova", sizeof(struct iova), 0, + SLAB_HWCACHE_ALIGN, NULL); + if (!iova_cache) + goto out_err; - ret = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD, "iommu/iova:dead", NULL, - iova_cpuhp_dead); - if (ret) { - mutex_unlock(&iova_cache_mutex); - pr_err("Couldn't register cpuhp handler\n"); - return ret; - } - - iova_cache = kmem_cache_create( - "iommu_iova", sizeof(struct iova), 0, - SLAB_HWCACHE_ALIGN, NULL); - if (!iova_cache) { - cpuhp_remove_multi_state(CPUHP_IOMMU_IOVA_DEAD); - mutex_unlock(&iova_cache_mutex); - pr_err("Couldn't create iova cache\n"); - return -ENOMEM; + err = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD, "iommu/iova:dead", + NULL, iova_cpuhp_dead); + if (err) { + pr_err("IOVA: Couldn't register cpuhp handler: %pe\n", ERR_PTR(err)); + goto out_err; } } @@ -281,6 +275,11 @@ int iova_cache_get(void) mutex_unlock(&iova_cache_mutex); return 0; + +out_err: + kmem_cache_destroy(iova_cache); + mutex_unlock(&iova_cache_mutex); + return err; } EXPORT_SYMBOL_GPL(iova_cache_get); -- 2.39.2.101.g768bb238c484.dirty