Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2969943rdb; Tue, 6 Feb 2024 03:26:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IF37MFD57hfxpO0s32ZZFRMV90MXFRmLmpCfwDz9XKEsqnAsgbuyyFm0Id6lHM5hktB59Qc X-Received: by 2002:a17:90a:69a4:b0:296:6eeb:ca2b with SMTP id s33-20020a17090a69a400b002966eebca2bmr2197060pjj.26.1707218774573; Tue, 06 Feb 2024 03:26:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707218774; cv=pass; d=google.com; s=arc-20160816; b=GxeUAQG1HcCO02Hu1xcFmEhH7jMsdruXx7hJm4l2rN1bL+L2xJSjSfRyqQoeQoPNDJ wRrVkW2EwihlxOJkPlKuerct2Sjs3pa7EU0aG2+F9QutT5oW3Rp2slk99E8Rw95p85Wf /ucupopJDxMwU3C3b9VlceWE1Utt/wCrIum+2jxx5pXMfPYmcqRTf7KWqFLsFQnkl/BV B7HHg9FcTrL/mGHRMYAWT6sBnkDgADnUrCQwpPTDcYw4aKq3aYe8mRnFzAU+JRd670zs 4ptpGBAZ0ne5+mjkutEjjW7NtDo3RnSlfJ9CGfZtAAvAkfVNkcqB/HixmcfSBW/gPr/Y 2f7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=tRK63h9Z5GGvvcVUDvg/7+LLJBt23wX9onR5VI9VSFk=; fh=uysQfIiIeIsHaXf8gpePblE/2mUL9XAXsQGj1Ln3fdY=; b=KD4NcFivDhGWG62IDjMkD8cCQt8J427sNROsMpvOa10/shJZnMbWgepYRxWLrHZNkR 4a72GC3BAt6d6RU3QVk7eR5yDcgvUAHfyEn9v7MFYDUuIW0a77JZenUhW/NVjCo0gQ0Z k4kwChJ4IQZmGHrJYAUZ91aI7VhX5DhFrnXdweFcdPheup2j+VxlZ6gldA0NZmYbyCeY fOLKusazUmFYdYw2BXZ6MjksqLX/RKtELxYbyIlXum+XD4llWNN3JSM1T+EFyuCR0PkG j+1eWZZQ9Ai8qcfxDrRLcFRZhXy7CoTdhiIDLP9CRPgchZxL3t18B+oBwetTA7jQmoQE 8S8g==; 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-54766-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUKm3Q6A4I1zCwMkZNaPZrh0tbU5cwjgCgp5gB5U6cEGM+mIpuyRzBuYAT+LWYCNxsTl9KflNk6LRly56FZR92lXqQ1PhX+fN9L0o/gvQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n11-20020a17090ade8b00b0029688bdcda8si992762pjv.99.2024.02.06.03.26.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:26:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54766-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-54766-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54766-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 EF22228718F for ; Tue, 6 Feb 2024 11:26:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1C0312FF7B; Tue, 6 Feb 2024 11:25:09 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA3E912EBEB for ; Tue, 6 Feb 2024 11:25:06 +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=1707218709; cv=none; b=a37uW8eTybJAguu5POKA6nhmgRlpZ5ghbjv+ysocmeqX+ETG2wdUAStZyA3rBOEhB9444EGhLzZpw1AVLkY5ZPfNviZXObrdcQwzWLZYs4SG6ZiW8v9Q3rzi9/5txmxk4F7Mue5ZfIGVK1SC0ykNxjX8z0EnGwAuoO/hufSRi5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707218709; c=relaxed/simple; bh=UqecmSij6jUkv/J1hyJQV+i6fQZsP3djMdtLCY2IesY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AI4jhnQ15MESoXqZIOtPQLhI01BcCa4L9G+61Eo28dMxP0f2oittr9jF2VgdJGXkCjPvqyGerNLLhePW+3wqy9SKRGk9rBH88sUSID4oIyb1ap3JmBzY7hCOM6/QM9KNLZ7Z2kUeT74bzSCShr6FXywHI1f4GKdVfy88cC2RAEc= 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 CB9CD1FB; Tue, 6 Feb 2024 03:25:48 -0800 (PST) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 02F873F762; Tue, 6 Feb 2024 03:25:04 -0800 (PST) Message-ID: <879751d4-486c-4d5e-b9b3-60e8822ff3fb@arm.com> Date: Tue, 6 Feb 2024 11:25:03 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure Content-Language: en-GB To: John Garry , 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 References: <6041982e-3c65-497f-b7bf-3ac444fa3623@oracle.com> From: Robin Murphy In-Reply-To: <6041982e-3c65-497f-b7bf-3ac444fa3623@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 06/02/2024 11:01 am, John Garry wrote: > On 05/02/2024 15:32, Robin Murphy wrote: >> 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 > > Regardless of a couple of minor comments, below, FWIW: > Reviewed-by: John Garry Thanks! >> --- >>   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); > > Maybe can use KMEM_CACHE(), but it would mean that the name would change. Oh, I never came across that before. On reflection, I am inclined to think that the "iommu_" names are usefully informative to userspace, and it's not worth churning the structure names themselves just to save a couple of lines here. >> +        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)); > > Maybe can use pr_fmt with "iova". That one I did consider, but since we now have just this one print and no imminent reason to add more, I figured I'd just stick it inline, and we can factor out a pr_fmt in future if we ever have cause to. Cheers, Robin. > >> +            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); >