Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3208458rdh; Thu, 28 Sep 2023 06:00:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH97YKLZpnF6WizZKe9aYTwelVs/H1PhqWQQ/yG5CKKCZq1B4vNLeRKcw9QQXJDM3gRKRtb X-Received: by 2002:a17:90a:53c2:b0:274:9823:b481 with SMTP id y60-20020a17090a53c200b002749823b481mr1056943pjh.9.1695906058152; Thu, 28 Sep 2023 06:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695906058; cv=none; d=google.com; s=arc-20160816; b=tcuGbe5cuxuiWBX3to2qoRHLq75eeTfSm0qlSQpSxc/gaWwrJH26PcmArVPJ3NOZTw MIM3kTIwRRN9sqQL/+Ng1PxctC3+kvh+nlEboABJmZwRqlnuN2F+ExttTdx83X9wMYVE P7W40Mmqhjp3X7rUUc9CDl4s3yIP2esBKHkjffj0VjiRzl2upYSWsSTfNcXLObOCnen7 AF2iVk/RxvHrnFUbTTmeXR+DH6RJGKJA+YlY01Ddf8oDuYSg8K6A71cQBWdz8a2iQDMV /w41s5TUZfDm+GktXn2FOf0R52Ow/BV9mWIX+/SBWFP8Qx2+jraK9xDYTQe1psugFCpq GoZQ== 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:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=CI9W3n5tq7LUNG7D7Ognv7Qc/uAQJ7j4lnv3V13h1i8=; fh=Zyzwj1kurtID2H6g1oMMLXAFK9ds4vWe8bIPVMVvnx8=; b=yqOUachORxFY6FcNwPBUg8rxXLpD6LSAf2EtCtg34y1E3Ag6iQ2Uwsoj6EV2bcymKf Ld3QB/qFyXZZWqLegiRzCuNXCSbHyvtVZycnvGYjRsWdZ5GGxQntsc2k5946Bmp5GAL8 F/vAbESNtGiZ6CtSSwSOIIp3P7F5SWf5HgLUMhuAVkQgoflKxBVgZfQIKqloFeKfWBlJ DaTynPLhiXZV3dQ7cAKIt3nuYV4hI9oBxMGNa6LkL3nGQM5MhgnSLFHN81Qu/3nYCCqk aNkE4t5UTSNGB3RDZoSHaVgjSd+UnDPWl4Z+1e25PFljpxWcJRf6TQXcba4/UOfgEeQt CCuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BSvzKdzm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id j24-20020a17090ae61800b0027491203b43si4950338pjy.189.2023.09.28.06.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 06:00:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BSvzKdzm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B9E2F803FF90; Wed, 27 Sep 2023 18:37:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229554AbjI1Bgz (ORCPT + 99 others); Wed, 27 Sep 2023 21:36:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjI1Bgy (ORCPT ); Wed, 27 Sep 2023 21:36:54 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0647BB for ; Wed, 27 Sep 2023 18:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695865012; x=1727401012; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=k2IBvK6ZA6AxFCZCz+4sX+cJsNm9cNzhfSFcC+S7MHU=; b=BSvzKdzmkvFosb1uGAfg8ntSqZ/i0HvNP+Uz5A9hWsJwlP91IC8aH2Am qBYV2QCEtfWTYxqvuCEkGqwSyc3sHv41F2Da0zkQFVo7NKv5euaCXus/5 zfCvwGN4QmHva3pIMgKyFlL5/i1xw3AAxunn37MjMxVXJIImdDPiNJCKD Alwks1FzrRVYtbwrsS+R0vnnmqRtSbHbbUC4eX8FM6xMl11gusPBuvjQs VLObHmlgBgZtIT2sY11MTKkKzJ8v9KkXrrZrXArdRgZA2mqL/mpDS74wh iHG63pkjMTcn1hx7dc2bZ4Kl3PPG0YkoT60s1pG1ZWusyG/rjRh04phJe Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="379240974" X-IronPort-AV: E=Sophos;i="6.03,182,1694761200"; d="scan'208";a="379240974" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2023 18:36:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="778746235" X-IronPort-AV: E=Sophos;i="6.03,182,1694761200"; d="scan'208";a="778746235" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by orsmga008.jf.intel.com with ESMTP; 27 Sep 2023 18:36:44 -0700 Message-ID: <7c7b8981-022c-2fa8-7ee5-9c97d8e17862@linux.intel.com> Date: Thu, 28 Sep 2023 09:33:29 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Cc: baolu.lu@linux.intel.com, robin.murphy@arm.com, jgg@nvidia.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu: Sanity check on param list for iommu_get_resv_regions Content-Language: en-US To: Dawei Li , joro@8bytes.org, will@kernel.org References: From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 27 Sep 2023 18:37:06 -0700 (PDT) On 9/27/23 10:25 PM, Dawei Li wrote: > In iommu_get_resv_regions(), param list is an argument supplied by caller, > into which callee is supposed to insert resv regions. > > In other words, this 'list' argument is expected to be an empty list, > so make an explicit annotation on it. > > Signed-off-by: Dawei Li > --- > drivers/iommu/iommu.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 1ecac2b5c54f..a01c4a7a9d19 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -813,7 +813,7 @@ int iommu_get_group_resv_regions(struct iommu_group *group, > > mutex_lock(&group->mutex); > for_each_group_device(group, device) { > - struct list_head dev_resv_regions; > + LIST_HEAD(dev_resv_regions); > > /* > * Non-API groups still expose reserved_regions in sysfs, > @@ -822,7 +822,6 @@ int iommu_get_group_resv_regions(struct iommu_group *group, > if (!device->dev->iommu) > break; > > - INIT_LIST_HEAD(&dev_resv_regions); > iommu_get_resv_regions(device->dev, &dev_resv_regions); > ret = iommu_insert_device_resv_regions(&dev_resv_regions, head); > iommu_put_resv_regions(device->dev, &dev_resv_regions); > @@ -1061,12 +1060,11 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain, > struct device *dev) > { > struct iommu_resv_region *entry; > - struct list_head mappings; > unsigned long pg_size; > + LIST_HEAD(mappings); > int ret = 0; > > pg_size = domain->pgsize_bitmap ? 1UL << __ffs(domain->pgsize_bitmap) : 0; > - INIT_LIST_HEAD(&mappings); > > if (WARN_ON_ONCE(iommu_is_dma_domain(domain) && !pg_size)) > return -EINVAL; > @@ -2813,6 +2811,9 @@ void iommu_get_resv_regions(struct device *dev, struct list_head *list) > { > const struct iommu_ops *ops = dev_iommu_ops(dev); > > + if (WARN_ON(!list_empty(list))) > + return; I don't understand why the input list *must* be empty. This interface has already been exported, so please update the comment to explain this new requirement. > + > if (ops->get_resv_regions) > ops->get_resv_regions(dev, list); > } Best regards, baolu