Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1566659lqz; Mon, 1 Apr 2024 09:58:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUt5wtTAzow98pZPJHZlh3svOJgnsjc7KyTN3Ztg1HjYO9Y6SIb4a1IXVPTd0Qsb8ymKzn8JKoC7h4+wk/C6mcGCGiwoWi8yMBVoDQrGQ== X-Google-Smtp-Source: AGHT+IHmis6yuyMKL8ZDdUSARmaPPpRU2h2t9PwNFL4tzz3kj5TrLJbCpOQ8jzS/ldVzdmpeQm2g X-Received: by 2002:a17:902:d48d:b0:1e1:5502:18cf with SMTP id c13-20020a170902d48d00b001e1550218cfmr9963141plg.69.1711990688361; Mon, 01 Apr 2024 09:58:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711990688; cv=pass; d=google.com; s=arc-20160816; b=qilbwKdIMqJpbBes3UYNohRQcksv96rQGlU72WfOhHIlHhhdFDX2RaX26I5irSEBHZ BALwk75UHTNkFz9ZtmxuN7U2vZEemZZ6u/Gmc0kHEWv3mVLEsocTouhHyrjGPR+Q0S6v 3pz72xw5Mrx+NWYPpEmUBx9HpPRW2uFEOLu2Iblzj9UKnluLISTj4aHHerfqbnPQ4ML8 Z/DPXozslkAmUWkhMEFVRZTL4GuOGeDF9K2aDhMWueKILSWhZSLI0Zug/7v9VonWuAbF WBEeUczHoFZQlYFTfVsJXu/W/B7wRUSnfKMZ9Ntj7ISHTXZXKIHCljrp0k8FrV66A7/N FdOA== 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:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=km4fprVI1kdl9zyi99KU40jbKi3UZCjHcOCOiwECwkI=; fh=aMa8McUncL6U+PuZGhHUFTO+Z5jW1kJhFPHAEAcJ86g=; b=uKf9BJvM3hnPPmAnYo0yzTFg20d/Y9UFq2hgsy6ZJNqebOgCkKFIN33wN7totyyyLV 6C84kcm4C/DvF3qivrffmioGR0euwhUDu72pO+JQZJOhKA/KR1RtGplPWHs8RFy++hpS QPp46mgtA315Xqrw59IRd797IM0okfEWcAk3t1h4Fu0udeHr3jiku5IZ7M83wkBddjUM wyvZbbCQPjEojQaYnJNKuZ8e8T0Qbbn+ZQJNxLv+RUoDy1qK6AkqdUyatAOR15tIBmMS AN0hAv9bLGSEvEtvUDZaB6bEr8/0UV/FhIa5a4gBTni8bYO5ZT4+uGRO8LnwKRa+t51Z rl1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-126881-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126881-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l10-20020a170902f68a00b001e02a1ad629si9792032plg.1.2024.04.01.09.58.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 09:58:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-126881-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-126881-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126881-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 58427B20912 for ; Mon, 1 Apr 2024 16:57:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31664482EF; Mon, 1 Apr 2024 16:57:20 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04529481B8 for ; Mon, 1 Apr 2024 16:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711990639; cv=none; b=NX1WiwgXl89AwTw4dnyyM/KjHR5TzCCxrayVaC6Q3muxDsljzzdc3QFEBt1oJMJPiEM4LnPiHmqZ5GkrMOb70YP51n+u67HRgrZvvB+92xSLVIhnKDPx+5DiA8POXuOzeimpKDinEMJIjjUHbMni5M/mqAcfR3FMxLt/K8zL47M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711990639; c=relaxed/simple; bh=Q1GiDPsmOA9yFoE9UumeRh3CLhd1FXbZpuCn264ms8c=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EOoUBsECQ4Gjv02QKr0Y4flJvBFfhoc5fsytV4rXDlHAQkWnMQCPCo+KSJZCunARxLv6PUWDx9fm2m5+mWkEVbSf0eEHw3sCkA7NavGJNCB0d1/xe50IZCUhd4YdCG8BKp6r6I78hMRyTJmwb8D7YYN3sd2eWkZ4M+zFAtBBO0k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4V7cCp0fbxz6K5t9; Tue, 2 Apr 2024 00:39:02 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 92DB71400D1; Tue, 2 Apr 2024 00:40:12 +0800 (CST) Received: from localhost (10.48.156.172) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 1 Apr 2024 17:40:11 +0100 Date: Mon, 1 Apr 2024 17:40:09 +0100 From: Jonathan Cameron To: Aleksandr Aprelkov CC: Will Deacon , Robin Murphy , Joerg Roedel , Jason Gunthorpe , "Nicolin Chen" , Michael Shavit , Lu Baolu , Marc Zyngier , , , Subject: Re: [PATCH] iommu/arm-smmu-v3: Free MSIs in case of ENOMEM Message-ID: <20240401174009.00003644@Huawei.com> In-Reply-To: <20240329095133.576605-1-aaprelkov@usergate.com> References: <20240329095133.576605-1-aaprelkov@usergate.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500005.china.huawei.com (7.191.163.240) On Fri, 29 Mar 2024 16:51:33 +0700 Aleksandr Aprelkov wrote: > If devm_add_action() returns ENOMEM, then MSIs allocated but > not freed on teardown. > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Fixes: 166bdbd23161 ("iommu/arm-smmu: Add support for MSI on SMMUv3") > Signed-off-by: Aleksandr Aprelkov I've not checked this is an actual bug (though it looks like one from the context of the patch - the comment below is just about how you fix it. > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > index 41f93c3ab160..136d0cdce6a9 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -3402,7 +3402,12 @@ static void arm_smmu_setup_msis(struct arm_smmu_device *smmu) > smmu->priq.q.irq = msi_get_virq(dev, PRIQ_MSI_INDEX); > > /* Add callback to free MSIs on teardown */ > - devm_add_action(dev, arm_smmu_free_msis, dev); > + ret = devm_add_action(dev, arm_smmu_free_msis, dev); Use devm_add_action_or_reset() which exists to solve the case of devm registration failing. > + if (ret) { > + dev_warn(dev, "failed to add free MSIs callback - falling back to wired irqs\n"); > + arm_smmu_free_msis(dev); > + return; > + } > } > > static void arm_smmu_setup_unique_irqs(struct arm_smmu_device *smmu)