Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1003836rdg; Fri, 11 Aug 2023 07:01:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGL1g9/zVfbQ/rROo7zbAqypV4/Sn6nt7jlZlYI0fEJMTbsbP0lXLAaHhLir62fHgllavxK X-Received: by 2002:a17:902:d715:b0:1b8:88c5:2d2f with SMTP id w21-20020a170902d71500b001b888c52d2fmr1928033ply.64.1691762505171; Fri, 11 Aug 2023 07:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691762505; cv=none; d=google.com; s=arc-20160816; b=QlzdCX55921uUZVXcy9xP96T05/RABeE71OPfvSKE6BjhgJwD/uj2wsQQVovXtMCbf gObTJQxscaqlFv8atKtxPfLK7XtrU19g5cYyFw1s/QuD/6+fCoLN2bPs7YPjeMnOyvtU NgTnm3qu0dQmLk7pdndokD2jWVyXfBHNU07cZOqLcUnDL00qKZGKOVmOAsBxY3vQU92k WRWlw/oTxStcg6DKl703PNPqx4zND+p1QFFBjMKSOU+obxZrfQc79n/viI0/CMOxAUtT GPb5dCFYBKs+3ST4R1AW85RcRN6n7A/pvuWADePTKRIu+QyvmQADdk4PcCJbQQjXCc+T mKmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=KsobTWFmr3nAvhZD4rrcjYG6TZr85yQWwwElQIN0d4Y=; fh=pAAvxXwL4kmtw0rVHEVlGH87z7KcefSmJB6En4gLWj8=; b=h8HNYEsgv8Qy609naYlxp3DIdSQ62WKr9ANe+DKaR++CRRYok7SzGZFTkdl/l3QWWY 5s2cQiZ/UYGrQkwP8aJyU0UQAIU1f0ByZMeFCV4z4O32lEWvW0kY+/MuZTbafriPKNX3 2UwpuGY0iD5Lu+Ce0uAB6iQx4Uc9MpCnyh/GUAP5289/yggHEsv5+LlAuNcZJLzK9uzK MZ1EGed1Y2uWenyusHhHEDI9EluqVKjfyCp0485I8DzMgcDft6cDRAQIa0WLrf2NnlUm vK1GXlXCforpkx9hLuHQbY6mgfsTKKPh7xwYsTAOgfQlc06qKV8EROy1ad8+7vb16Cxa qIBQ== 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=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a170903110400b001bbd2aba533si3521431plh.42.2023.08.11.07.01.30; Fri, 11 Aug 2023 07:01:45 -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=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235794AbjHKNcu (ORCPT + 99 others); Fri, 11 Aug 2023 09:32:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233800AbjHKNct (ORCPT ); Fri, 11 Aug 2023 09:32:49 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7728B30D4 for ; Fri, 11 Aug 2023 06:32:48 -0700 (PDT) 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 9C66E113E; Fri, 11 Aug 2023 06:33:30 -0700 (PDT) Received: from [10.57.1.174] (unknown [10.57.1.174]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8E63A3F6C4; Fri, 11 Aug 2023 06:32:46 -0700 (PDT) Message-ID: <9582503d-6d48-e5e8-6eb0-a170eb0c1150@arm.com> Date: Fri, 11 Aug 2023 14:32:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RESEND PATCH 1/2] iommu/iova: Add check for cpu_rcache in free_iova_rcaches Content-Language: en-GB To: Zhang Zekun , joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, baolu.lu@linux.intel.com, robh@kernel.org, nicolinc@nvidia.com, john.g.garry@oracle.com, kevin.tian@intel.com References: <20230811130246.42719-1-zhangzekun11@huawei.com> <20230811130246.42719-2-zhangzekun11@huawei.com> From: Robin Murphy In-Reply-To: <20230811130246.42719-2-zhangzekun11@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 On 2023-08-11 14:02, Zhang Zekun wrote: > free_iova_rcaches() needs to check if cpu_rcache->loaded and > cpu_rcache->prev is NULL before freeing them. Why? iova_magazine_free() is just kfree(), and kfree(NULL) is perfectly valid, specifically to avoid having to make cleanup paths all fiddly and overcomplicated like this. Thanks, Robin. > 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);