From patchwork Mon Feb 5 15:32:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 13545691 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A00AC4828D for ; Mon, 5 Feb 2024 15:32:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 584646B0080; Mon, 5 Feb 2024 10:32:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5359E6B0082; Mon, 5 Feb 2024 10:32:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 275226B0083; Mon, 5 Feb 2024 10:32:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0DA6B6B0080 for ; Mon, 5 Feb 2024 10:32:50 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D07D5A183A for ; Mon, 5 Feb 2024 15:32:49 +0000 (UTC) X-FDA: 81758142858.23.8849425 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf05.hostedemail.com (Postfix) with ESMTP id 36E1410000C for ; Mon, 5 Feb 2024 15:32:48 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf05.hostedemail.com: domain of robin.murphy@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=robin.murphy@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707147168; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yY+4M7kMt2BVJso2Lto96zv05XHdud4jM/u756+6AO4=; b=Kt0VtsXUlfBb81FzfrplvuzEQIdTZR5tuq4T9Yr165ZqW6hmiWdODiGvUdoY2CC0xsLyL8 YmzDJnMKkia8/RPka2/fI7NQ3MPwCyMQ4WNt4rPSzecd5pAidN5tF1ZVz9myFYGZe7eKMe U65maGW9kE3E4nxhClapP20uGTiLehQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf05.hostedemail.com: domain of robin.murphy@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=robin.murphy@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707147168; a=rsa-sha256; cv=none; b=GEzgRiu8c3LheBRVpmWfQC4sWAghilNykAupzwp6r1JwVsaB9IJXcREt8RfkNvRZfVHM/u 3RynwrMVT6hTIo7PlxGPidkTliSygFLgEzInPGDgfLLxDjwBzRIinSafZwK2R4kZ7V8mpb mxeSiBwfBSZp/pYOhexoeb4sbjM1soE= 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: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 36E1410000C X-Stat-Signature: 69o7ezzocz8d799bjwn6ngwcd8kzuzup X-HE-Tag: 1707147168-446324 X-HE-Meta: U2FsdGVkX1/uPhVBu0l9lcSbz+MUeHndHM1svwDeCABCDWPc+ZeVjkrnJ7UnYEASAl+rL9M77oDYdD67I4HHpD9uXU5ubJdJndBBmbgf5dEEuUxPjq5o9UlbakgPw7PkYg6QnCnBpP74B6k9zTonIsFsIW57hmpbJJXfTyIkzqdvKBERBp4+mDNosIbTUoeIpg7elE4/P+JMQjnu4ngCnBGW6t/but1EDZQvM6nDyuqT8xlcAtb7BECGJlHSmm8V9irk5pzo6K67eUvmQJDtdTjLTo8YrEeizYMEF5C0yBm1ghpSNpNWOi/QBvTQVPDpkLoiOzVQklMe++/iQt7vu8X8s7KOmBUAsuhkGNUDgHCJ58NHkSd2OZ0y/FiXUgBGgbu3yvmM0BkSJzpYXOp3vf5p+Nw+56J03+6fvKGUArhMmHdYVvyk1U74pk/qnpr0+9ZwtKa+scqYxWVJzfkj0zidpxxmRgaz+EkDAnVNKa1UjKcylLHIyB+Oq/4rdxXwZ7H18y/H88iwuReJjZH64zBSrlzvK0JWJ36sh0CZdgQmaMDJD+wJb9SmsJWsDTO0Lh1q9v9kl7BscDF+uwzIKHU3wTP9SDlPJxOl3mD3iPmu26/6fEpOu/ubdbdRo5YwumGXZyePELsNvs8vvkBIvQLSC+3cTC7bWFtO52MRBXE38csjD6655PNKXAoI+mxng1N85YCaURNYkzSJrNLLE/Oxy5M8w05bPb+uyGZspKLn6eW6sbRZIGZYopvq4YsOjkmdiY2hYoOzyPx0oh3n9FFrK6OMgK1apIqvXCvR9q9d1Wa1MoELP6y3ucKa5O44ShgJDQKHyAlc0JXE/5Lr56ghrwuy9pxRKxyrozFy7QY7kTRGtIDw16K8azYv1wTiP2LXX9lTPvamGpcLlYSbe8zAdH4+iwjvmiYyxWzBdPjn/vxXmz332eP4nPH20d+XdbeyBCd8qxw+AS8u0fH udVaQsXo sw09m+qgvClctXrXn4u0R39vBnls7WlyIeT6RqblRhkpFi5g1gTUfKr4a8QoLsh55fnKasEj8cQble1sMmfXbe17UG4zPSR/t45oKxiUqZaGTTjtqtv1xoNT8QRrwit+hNZxBL6tInjpt5ER/IsXzzh3cS94hcCkM4JQUqvc6lR2F7W7mz7xF4j3D8d7pXf2Pes/ObrFKzerimRE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: David Rientjes Reviewed-by: Pasha Tatashin Reviewed-by: John Garry Reviewed-by: Jerry Snitselaar --- 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);