Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1003466rdg; Fri, 11 Aug 2023 07:01:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUnkOOfF2pqAriU7AFXeyf15KQVaMKqYxkDy9GPnZI/oHyF59x+ucKADe2L1NTWPFSW0mQ X-Received: by 2002:a17:90b:e8b:b0:263:e133:b9c9 with SMTP id fv11-20020a17090b0e8b00b00263e133b9c9mr1276178pjb.34.1691762480718; Fri, 11 Aug 2023 07:01:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691762480; cv=none; d=google.com; s=arc-20160816; b=mXqQ7oVQK/rFp/h8fkwcdiOt4zMWTw8IFMKNUHfPIi0t8BKiNeLDLzYYi1RK6dGkIm MxwBC0sYcIqXDHzQEkhLSM/h9o52j0DAj24OI20We17O9WDKZkGo53PBYFhCtuw+z7Ie Fam2RFjWhSSuXfj2+SBLXfb8i/l8+423qr5esINyxoajxFXXqy2Fbl3JiPoJ7wFn1m+R YLuM0/wllSxCZZ7Bsp6Lf0VaePViXiJ2CjcwLsxfHozgFMsG1DIzfoHsaTvPV6TOXUo/ kaLzHDnbv4G3G1VDIjd4FR8lIV1FmpxF3oIbrdredWfrXrMR01PuXxfiTqYTm8Px5zyQ HsXg== 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=j+d8Qji3Kd78Y5wikuIe56W4rxsMj0I3YfL77K4ftaQ=; b=swc6XhiFlxqcC0dfQ5mLfbiHuw0wkPoYlQ6byzbCRWPYayjNllxOIc7GoZyldaj0+d +4FAE2u1dlkrM2wRSrSO/sE8aAJWjz2ZS7sysANpZmDtlyfK7IkPsdJKGM5lHf3+xHAE /T/LxaG6zIFna7Gqjz5YOjCbZINKZ2oj6Izz6oi3Xmi6aTPPYqw3lbLxrsQP9JkTUKN+ +nUTva/9lI07LnWg5tkVtifT0vFRLXUcNdx3qW6yask0mpYziY4FaoZwEBco0zJNJJmY ru0jNyt9yEbfCWuIcBt/THVCXjbzqpa1K3y8Ahpg+ylFxVU4NYvxVd3koh3QOeJYEcEp gLCQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a17090b078c00b00263deaac48esi3474998pjz.8.2023.08.11.07.01.06; Fri, 11 Aug 2023 07:01:20 -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 S234022AbjHKNLO (ORCPT + 99 others); Fri, 11 Aug 2023 09:11:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbjHKNLL (ORCPT ); Fri, 11 Aug 2023 09:11:11 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC84518B for ; Fri, 11 Aug 2023 06:11:09 -0700 (PDT) Received: from kwepemi500019.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RMkcb0k0TzqSg0; Fri, 11 Aug 2023 21:08:15 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemi500019.china.huawei.com (7.221.188.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 11 Aug 2023 21:11:06 +0800 From: Zhang Zekun To: , , CC: , , , , , , Subject: [RESEND PATCH 1/2] iommu/iova: Add check for cpu_rcache in free_iova_rcaches Date: Fri, 11 Aug 2023 21:02:45 +0800 Message-ID: <20230811130246.42719-2-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230811130246.42719-1-zhangzekun11@huawei.com> References: <20230811130246.42719-1-zhangzekun11@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.208] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500019.china.huawei.com (7.221.188.117) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 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); -- 2.17.1