Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1345033rdg; Fri, 11 Aug 2023 19:57:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTaEO6OMgF2Yes457aIztZR9EIkhF9crTq6CA5YKfxAQex2A4rH0kGsyGCmWTHUdHcUZVU X-Received: by 2002:a17:902:e5c8:b0:1b9:cb8b:3bd3 with SMTP id u8-20020a170902e5c800b001b9cb8b3bd3mr3807415plf.31.1691809073478; Fri, 11 Aug 2023 19:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691809073; cv=none; d=google.com; s=arc-20160816; b=XPC9S28p9iJUx1oZrdJOWysIxnZ9Vcg/+q/Xaac3CCTFJ3EYyKNbizqiV1SLOGZZ+/ U3nRph93n+HZLoSB2yFmef4tBGh5MgzDfKavH2KtiQ2NS7OcDkVECz2xt59Qqh1gctRY A2up170u20sqzFjZdy+tkZ6VTqxEnRCRCJPiCXFsCGldf3P2PLRO2MNUMoxTwQbnxsZV 05+TUJSq5uQ5DAsQtxLTvGvManJ8zPyHoGkutoSVeqnr//Nz5er7upW1245RcU9IBgjK MFM80WRELPyMu2dV82P/ICcaAX9LFXvSJ9KaT8ncDA8zEa2Z8pF3KjXNuoHtPWaD6KyN YY1Q== 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:subject:user-agent:mime-version:date:message-id; bh=rPWdoMbe3KLxCXL01wu/yUO0GyPwELEqIT70dOjRvs8=; fh=Xdy2AwuHmcr+zywxcFCip9uP5RLnGpJ9LG0YHZbME/4=; b=uiuSNuZNBUJAvQtKWPIiyyviH5OG8fDq1SbI+yVDhaZxMXE5eFNiz1zatQDMmnaljy pVAORgzDchS5+ehzvGaGc3FOJF0J+LF+UulzNYPqsin3iaotcSg754akBuA8D64V85Jl di3ckHBOSCfDyofFyrBGV4AsP/ff00ASLWetJyumkqW13aFh+D+Rr8U46Ot2yeWpDjcq +ZFQfhzEKyAmsVAnxhjdNj2REyelM8vjaZ7OObsCKAMnPPjviEXr4Dk9dsBYjwOXncq+ RCHowzYIqsaik0uCUFM3zTzXpXgkGr4oQvs9IOeQ8nVlb9oVZvGXEOHLXQwwAgMUpkxa 7SyQ== 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 q20-20020a170902e31400b001b02e8d8976si3657292plc.300.2023.08.11.19.57.41; Fri, 11 Aug 2023 19:57:53 -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 S234166AbjHLCV4 (ORCPT + 99 others); Fri, 11 Aug 2023 22:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbjHLCVz (ORCPT ); Fri, 11 Aug 2023 22:21:55 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1188122 for ; Fri, 11 Aug 2023 19:21:54 -0700 (PDT) Received: from kwepemi500019.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RN4B10YCTzTmCx; Sat, 12 Aug 2023 10:19:53 +0800 (CST) Received: from [10.174.176.82] (10.174.176.82) 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; Sat, 12 Aug 2023 10:21:51 +0800 Message-ID: <6ab1684e-fc81-9840-7973-87966e4284e8@huawei.com> Date: Sat, 12 Aug 2023 10:21:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.1 Subject: Re: [RESEND PATCH 1/2] iommu/iova: Add check for cpu_rcache in free_iova_rcaches To: Robin Murphy CC: , , , , , , , , References: <20230811130246.42719-1-zhangzekun11@huawei.com> <20230811130246.42719-2-zhangzekun11@huawei.com> <9582503d-6d48-e5e8-6eb0-a170eb0c1150@arm.com> From: "zhangzekun (A)" In-Reply-To: <9582503d-6d48-e5e8-6eb0-a170eb0c1150@arm.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.176.82] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500019.china.huawei.com (7.221.188.117) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, 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 在 2023/8/11 21:32, Robin Murphy 写道: > 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. > Hi, Robin Thanks for your review, I have missed that kfree() can handle NULL and it is safe to iterate through all cpus, because __alloc_percpu() will alloc a zero-filled area, and pointers passed to kfree() will be either NULL or a vaild one. There is no need to add check before these pointers. Thanks, Zekun