Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752643AbdHDNJf (ORCPT ); Fri, 4 Aug 2017 09:09:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58418 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752458AbdHDNJe (ORCPT ); Fri, 4 Aug 2017 09:09:34 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E62554DB13 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=bhe@redhat.com Date: Fri, 4 Aug 2017 21:09:29 +0800 From: Baoquan He To: Joerg Roedel Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 06/13] iommu/amd: copy old trans table from old kernel Message-ID: <20170804130929.GN1874@x1> References: <1501587449-9817-1-git-send-email-bhe@redhat.com> <1501587449-9817-7-git-send-email-bhe@redhat.com> <20170804122116.GU3431@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170804122116.GU3431@suse.de> User-Agent: Mutt/1.7.0 (2016-08-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 04 Aug 2017 13:09:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1528 Lines: 50 On 08/04/17 at 02:21pm, Joerg Roedel wrote: > On Tue, Aug 01, 2017 at 07:37:22PM +0800, Baoquan He wrote: > > static void init_device_table_dma(void) > > { > > @@ -2137,9 +2140,49 @@ static void early_enable_iommu(struct amd_iommu *iommu) > > static void early_enable_iommus(void) > > { > > struct amd_iommu *iommu; > > + bool is_pre_disabled = false; > > > > - for_each_iommu(iommu) > > - early_enable_iommu(iommu); > > + for_each_iommu(iommu) { > > + if (!translation_pre_enabled(iommu)) { > > + is_pre_disabled = true; > > + break; > > + } > > + } > > I think this could be easier if you make 'is_pre_disabled' a global state > bool variable with reversed meaning and initialize it with 'true'. > Basically > > static bool __init amd_iommu_pre_enabled = true; > > And set this variable to 'false' when you find a already disabled IOMMU > during initialization. Then you can remove the code above. Great idea, will change as you suggested. Thanks. > > > + > > + if (is_pre_disabled) { > > + for_each_iommu(iommu) > > + early_enable_iommu(iommu); > > return > } > > > + } else { > > And remove this to get rid of one indendation level for the code below. > > > + pr_warn("Translation is already enabled - trying to copy translation structures\n"); > > + if (copy_device_table()) { > > Seeing how the return value of copy_device_table() is used, it makes > sense to change its return-type to bool. This way it is also easier to > see which one is the sucess and which one the failure case. >