Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1020191lqd; Thu, 25 Apr 2024 03:53:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHdj73ZOta4eO1LUBRGYiOQrMMgnctkvbAHzGsNn0eRL7qfk7Fp9n/y+5pKigbDKj+3KyByVr/xBEulc9jYO9XaMDYWcGWDVMAgQnyog== X-Google-Smtp-Source: AGHT+IEtwDmd2kJQqFX4aE7PuNf8+Blow+tXZfn6/57UhignZhtJvAuL9vIkE7rGwUN5QwIZ63RX X-Received: by 2002:a50:d607:0:b0:56e:32fb:bc7 with SMTP id x7-20020a50d607000000b0056e32fb0bc7mr3419445edi.36.1714042406582; Thu, 25 Apr 2024 03:53:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714042406; cv=pass; d=google.com; s=arc-20160816; b=bcOIJKg1hj0XOVDzabTX971VceHga84pGrGn55+UcLEtReJDqXKD2oTUmB77tEQeQK otupPVCMYgUJSN8Z7uPaDS1nqQVnRJa2hQoVSDpHMlIA+HP6a0U1W+G/aSVDyc/10dX0 h92+AW5JnAFFbQg6TwClqVp9U8M7vx+uxRjO4HwcU+h5PaSRWSEtL0LXr0E8N9ah2kBu qKdIP/xQo+8NiPrxrOzgR6pVNwFkJ38Pl+G8IoJ77Sq92V/0L18Bwp7QNNN3jrJto/pp fUwwYoSVQAy8R7cq65rPcUO1Hvd9S5ztqJupsfKe0pLr32DwaJZk0FAdzN4eWwyVGSLT +jzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=RnFD2yrW+dujNJCCoAKDdGTeQEmE1Y583ML4hI1aGwM=; fh=uF75vjQPb2X6A37eGoKLYtRqTW1kTtfiV5eCTkMYfL4=; b=ooot7v2/1HuKGWxYDbMSImwtSbnuw3BwDJJK9IKw1IG9ous78xYqFu73Fa3xzSx/Dt l8eZ/NDJoEbEL2DoGXV1tkKGp2ONpWWNHjBdrLWWGAOw6vlzu+uopZv0W7xoPPfEKldH UzhYHK334hGBKlILJUqKlN0w6bPIgJ1zXgJi16HvOoEKfha+A+yQWvq5himKVEz/1Pjs qA7QgVI+C6ovGghn3lx0DfedBUtQ4d51t4yGNzb7QO1N4Sz1Haa8fxVQU3dw0ZAPLisZ GSnD5ANgzrZwH0TyXkolUJVa2wGKaXnhG1suPf08Y89OY+K9oi2UxTZTqng9kGQxsqF9 DkeA==; 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-158416-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158416-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t7-20020a508d47000000b005721f309dddsi3554359edt.98.2024.04.25.03.53.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 03:53:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158416-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-158416-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158416-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 526B21F22E3F for ; Thu, 25 Apr 2024 10:53:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8612022625; Thu, 25 Apr 2024 10:52:42 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC9E42C182 for ; Thu, 25 Apr 2024 10:52:39 +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=1714042362; cv=none; b=cpTgRM33zm82pX0dB9SOVR4pgOSRRrSEjAaaDfmUsVqJwCYn9nLX/Tf/6NBkTMd/7S/HpMVLq/iWwueiKRSI9J0aLM9Lw4ar0UDrbvaorajA6B27Xa4Ro71KSdkRaUXdSJAHK9QAe67T1CMuPvTyyUQ+V1gHB/rjGTRyFfLN1hk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714042362; c=relaxed/simple; bh=Ar1GqtbHV7TvYScxEgkS4ik5kDQlPzxCfA0GlbTjt+w=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NQITheqAIhFE85bElxwa2FxrBh6bALCagNtqdmLp+NikxruXC0NHnBwm61jjSG/3AK/o/X/jSZncQxgq9W2I0oglGMXSYcyPQ8a7aDQycWjeWjWB47wZTVFwdD664DlgjTyfxSha+Zw7BlKGpy+9n3ifKXdl7peuyJMT1ObiM/4= 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 6D9E71007; Thu, 25 Apr 2024 03:53:07 -0700 (PDT) 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 6CBBC3F7BD; Thu, 25 Apr 2024 03:52:38 -0700 (PDT) Message-ID: Date: Thu, 25 Apr 2024 11:52:36 +0100 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 v2 1/1] iommu/amd: Fix memory leak in alloc_pci_segment() To: "Kun(llfl)" , Joerg Roedel , Vasant Hegde Cc: Suravee Suthikulpanit , Will Deacon , iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: From: Robin Murphy Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 25/04/2024 11:17 am, Kun(llfl) wrote: > Fix the memory leak issue that occurs when resource allocation fails in > alloc_pci_segment(). The dev_table, alias_table, and rlookup_table were > introduced individually in three commits. But they all fail to release > allocated resources when other allocations fail. As far as I can tell the returned error should end up being handled in state_next(), which *will* then clean these up again, at least in the !irq_remapping_enabled path. If there's any cleanup missing from the other path, then I think it should be fixed there, since it may well represent more than just these particular allocations. Thanks, Robin. > Fixes: 04230c119930 ("iommu/amd: Introduce per PCI segment device table") > Fixes: 99fc4ac3d297 ("iommu/amd: Introduce per PCI segment alias_table"), > Fixes: eda797a27795 ("iommu/amd: Introduce per PCI segment rlookup table"). > Reported-by: Xuchun Shang > Signed-off-by: Kun(llfl) > --- > drivers/iommu/amd/init.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c > index ac6754a85f35..4ce567f39473 100644 > --- a/drivers/iommu/amd/init.c > +++ b/drivers/iommu/amd/init.c > @@ -1642,13 +1642,22 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, > list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list); > > if (alloc_dev_table(pci_seg)) > - return NULL; > + goto alloc_dev_fail; > if (alloc_alias_table(pci_seg)) > - return NULL; > + goto alloc_alias_fail; > if (alloc_rlookup_table(pci_seg)) > - return NULL; > + goto alloc_rlookup_fail; > > return pci_seg; > + > +alloc_rlookup_fail: > + free_rlookup_table(pci_seg); > +alloc_alias_fail: > + free_alias_table(pci_seg); > +alloc_dev_fail: > + free_dev_table(pci_seg); > + kfree(pci_seg); > + return NULL; > } > > static struct amd_iommu_pci_seg *__init get_pci_segment(u16 id,