From patchwork Tue Jul 11 02:54:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhangzekun (A)" X-Patchwork-Id: 118225 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp222454vqm; Mon, 10 Jul 2023 20:44:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlHEg6cn3evSIyHxCn9/wK/eTpGiPrjV7Y5/i17duPnEioLUfZBJ7z5NStQD29tlhnp0xeHR X-Received: by 2002:a05:6358:3423:b0:129:c007:9c93 with SMTP id h35-20020a056358342300b00129c0079c93mr9142945rwd.21.1689047071138; Mon, 10 Jul 2023 20:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689047071; cv=none; d=google.com; s=arc-20160816; b=TKwW96JZd9j/lN2X8dc+jt2MxmCOIMLr0llPyESifkzoiVzLiP7c0VUmOaTnfHkidx lkr0p9gRuiT4i3iDexBv/8AXx/h40XsK2aq2mo+mfu+Q5QwG8z8yPrZDm7lD3arZptkS /qz1vfgnjUlvXBRdMwc9sdaFLGvCr2RQ/u2V2YZ/+l9c5jH388Fr3hnpYH+h0GJBkFSa PxSGtLk306Fcc9rVkLoz8o28ZIo85BHq1qva8Tdpt8CJ/4KzOXhcUFF5aBNGl8yGHoqG g0DCHcgLVW7t/Mkws360lxdbB0H5mctk6ciQgES1tUgbBuKrBZmLbDqPZSCCcXawPuid QHqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=9/U+pD5oRHnqpzvvvJZGZULfZp9IgaQsblFITN+uEmE=; fh=iSjQBVrAVFI/9+Bb0JBpjDMqV7UrVmYB2fvUWhoGx5E=; b=DzIeKYaUohCzTOGhayNc0Ri5pxGfEilEX2Oebh63xmsDR9xTrTNfcv/lLqKIftQm8h HO1Gx0diko3YY6gy4dKfANytXVzaVHVFI18KnSglPLrhdeIDgCJgHfTGBdcMvw5UCpC7 RHirurp2IaptcdBLj9gokgIlTLVpaznlkCh36021UeJcjO1oDYYha7rwdOvIeAYJuKGu oJGfkMEs2DBz/JTHqZJdd/ntGL6gOw6U8jzi4lvwIrwrsE8Tm0L1Ys0Ost5dTHVpw6Sl vBPkCsVDLt1SiOl0LxfIOzkXWUx+C6G9WR2ZDCTGTHgMwVyyXO49bh13T4yfREO7IQDY kFbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 7-20020a630907000000b0055386e1eb92si681971pgj.422.2023.07.10.20.44.18; Mon, 10 Jul 2023 20:44:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231208AbjGKDFb (ORCPT + 99 others); Mon, 10 Jul 2023 23:05:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231195AbjGKDE7 (ORCPT ); Mon, 10 Jul 2023 23:04:59 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EACC10EF for ; Mon, 10 Jul 2023 20:03:45 -0700 (PDT) Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R0Qfk6hSjz1FDn8; Tue, 11 Jul 2023 11:03:10 +0800 (CST) Received: from huawei.com (10.175.112.208) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 11 Jul 2023 11:03:43 +0800 From: Zhang Zekun To: , , , , CC: , , , , Subject: [PATCH -next 1/2] iommu/iova: Add check for cpu_rcache in free_iova_rcaches Date: Tue, 11 Jul 2023 10:54:51 +0800 Message-ID: <20230711025452.35475-2-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230711025452.35475-1-zhangzekun11@huawei.com> References: <20230711025452.35475-1-zhangzekun11@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.208] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500022.china.huawei.com (7.185.36.66) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771094221706369882 X-GMAIL-MSGID: 1771094221706369882 free_iova_rcaches() needs to check if cpu_rcache->loaded and cpu_rcache->prev is NULL before freeing them. Because iova_domain_init_rcaches() may fail to alloc magazine for cpu_rcache->loaded and cpu_rcache->prev, but they will be freed for all cpus. Fixes: 32e92d9f6f87 ("iommu/iova: Separate out rcache init") Signed-off-by: Zhang Zekun --- drivers/iommu/iova.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 10b964600948..3c784a28e9ed 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -746,8 +746,12 @@ int iova_domain_init_rcaches(struct iova_domain *iovad) spin_lock_init(&cpu_rcache->lock); cpu_rcache->loaded = iova_magazine_alloc(GFP_KERNEL); + if (!cpu_rcache->loaded) { + ret = -ENOMEM; + goto out_err; + } cpu_rcache->prev = iova_magazine_alloc(GFP_KERNEL); - if (!cpu_rcache->loaded || !cpu_rcache->prev) { + if (!cpu_rcache->prev) { ret = -ENOMEM; goto out_err; } @@ -903,7 +907,11 @@ static void free_iova_rcaches(struct iova_domain *iovad) break; for_each_possible_cpu(cpu) { cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); + if (!cpu_rcache->loaded) + break; iova_magazine_free(cpu_rcache->loaded); + if (!cpu_rcache->prev) + break; iova_magazine_free(cpu_rcache->prev); } free_percpu(rcache->cpu_rcaches);