Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3595140imw; Thu, 7 Jul 2022 04:36:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tRS5KpY+Cn3d+2R6kYA3wZhRHCZxu45R3PS/GxnXq1c1h5MGdZK/v2cz01NLwOzWpWfSXe X-Received: by 2002:a17:906:8a78:b0:72b:1b79:d61b with SMTP id hy24-20020a1709068a7800b0072b1b79d61bmr155301ejc.309.1657193773282; Thu, 07 Jul 2022 04:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657193773; cv=none; d=google.com; s=arc-20160816; b=a1a6mSeXbYI+MuTotEfKEuk6Z2qdalJY7x9iMHm6IhNaMVT4rYchPuizAle49PNncc 0ycmN2yUHG7ZD5Oe+Z6h9OD0Gp7M0iwfRomuZprzkY/t/G+fme0SVkTlmUdxIQ8XKFN2 j6F6P/McNvMagAoA0dEboZo9r4z9GCDqufNHjS0fe20CjjRRivD/CA0brn3f6fpropR4 oxlty6qfUvDzzwjLMXqJ9YsYibJv2SYBRQKp0wZJRrgv0/IQBsRLy40hoIgxXRbHSTcz 4Qqw+CxLX+QKDMLusybfR9W+Ag64ud8FV8gPbMhiPTpXrlSMywknI76is/2swZbZCYYb sJmw== 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=UKe+G3dOC+/MJKIpM4GCDkhkJB6Lhcm1gCQhn0LoJ+8=; b=CnmMX0T8gdD8qvWEyBU+9WuHa0kUhVJWC9drBCKre8Js5scCi6fxI2xiGoQNmFJ/a9 I24cNvs/FY/Svh0oMhHUvtGgBJz9EpfXL+cVmgf23O4/RF49ZNEJCEH2kRzzh1e5XHCM f6Qd9oh23C9JG9IaO2HsmhnNbSX0HpB6pgCNCXnNyUrzOKx+XNW1foNMjAyaiptQQYrr F6Bk0RWiC/TqzfqZaqTiUxWNHaST4pdL0N+/8NwFtlhMXKNlgWmd+ZenCzBtZk8G/1Lk SwqbOkEVteWGEdUhANLeX1H3rNIzn8QJ4YPpHF6lwxzsuy8erVt46Qh0mHaaNXnoPRLj Ayag== 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 sc25-20020a1709078a1900b0072639dcac43si1743752ejc.1009.2022.07.07.04.35.46; Thu, 07 Jul 2022 04:36:13 -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 S234977AbiGGK6o (ORCPT + 99 others); Thu, 7 Jul 2022 06:58:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbiGGK6l (ORCPT ); Thu, 7 Jul 2022 06:58:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 793A94D4D7; Thu, 7 Jul 2022 03:58:40 -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 946BC1063; Thu, 7 Jul 2022 03:58:40 -0700 (PDT) Received: from [10.57.85.108] (unknown [10.57.85.108]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 524513F66F; Thu, 7 Jul 2022 03:58:38 -0700 (PDT) Message-ID: <569e97f6-f78c-1eae-1023-2d5e2df2d40f@arm.com> Date: Thu, 7 Jul 2022 11:58:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3 04/15] iommu: Move bus setup to IOMMU device registration Content-Language: en-GB To: "Tian, Kevin" , "joro@8bytes.org" Cc: "will@kernel.org" , "iommu@lists.linux.dev" , "linux-arm-kernel@lists.infradead.org" , "baolu.lu@linux.intel.com" , "suravee.suthikulpanit@amd.com" , "vasant.hegde@amd.com" , "mjrosato@linux.ibm.com" , "gerald.schaefer@linux.ibm.com" , "schnelle@linux.ibm.com" , "linux-s390@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <5b9b608af21b3c4353af042355973bac55397962.1657034828.git.robin.murphy@arm.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,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 On 2022-07-07 07:51, Tian, Kevin wrote: >> From: Robin Murphy >> Sent: Wednesday, July 6, 2022 1:08 AM >> >> @@ -202,12 +210,32 @@ int iommu_device_register(struct iommu_device >> *iommu, >> spin_lock(&iommu_device_lock); >> list_add_tail(&iommu->list, &iommu_device_list); >> spin_unlock(&iommu_device_lock); >> + >> + for (int i = 0; i < ARRAY_SIZE(iommu_buses); i++) { >> + struct bus_type *bus = iommu_buses[i]; >> + int err; >> + >> + if (bus->iommu_ops && bus->iommu_ops != ops) { >> + err = -EBUSY; >> + } else { >> + bus->iommu_ops = ops; >> + err = bus_iommu_probe(bus); >> + } >> + if (err) { >> + iommu_device_unregister(iommu); >> + return err; >> + } >> + } >> + > > Probably move above into a new function bus_iommu_probe_all(): > > /* probe all buses for devices associated with this iommu */ > err = bus_iommu_probe_all(); > if (err) { > iommu_device_unregister(iommu); > return err; > } > > Just my personal preference on leaving logic in iommu_device_register() > more relevant to the iommu instance itself. On reflection I think it makes sense to pull the iommu_device_unregister() out of the loop anyway - I think that's really a left-over from between v1 and v2 when that error case briefly jumped to another cleanup loop, before I realised it was actually trivial for iommu_device_unregister() to clean up for itself. However I now see I've also missed another opportunity, and the -EBUSY case should be hoisted out of the loop as well, since checking iommu_buses[0] is sufficient. Then it's hopefully much clearer that once the bus ops go away we'll be left with just a single extra line for the loop, as in iommu_device_unregister(). Does that sound reasonable? > Apart from that: > > Reviewed-by: Kevin Tian Thanks! (and for the others as well) Robin.