Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5373722ybv; Mon, 17 Feb 2020 18:40:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxmBZBzI3EM7xSGNnnPUYaP1tmOzQr2oXuqd5KBy063ao+ox861jACGzcYH2aE4eoejrQvo X-Received: by 2002:a9d:2c2a:: with SMTP id f39mr13934189otb.301.1581993609116; Mon, 17 Feb 2020 18:40:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581993609; cv=none; d=google.com; s=arc-20160816; b=QPbQ8NhQh80VzNzz5N6FnpbhQhi4E1Fk65AD6emLhIs54g9Oq4oMzruNVvhCSwoZc3 JNhoy4Grorb4gcQ0lg4STD51F6qHYD9ece/j3oOf/QfE7GbboFJpyKGGObeTiqPcDKaR CQtjEd9HHNp85q7/b6DrQho4bkRKIJvG1uhsTS+6jL8+aTs+iT7NelwTbiV5FtHM/Oct JKaLupUMcTeVDFpRWo0DEssJOR0Z8R9ajIbAHnbothg0Ga7HaiY4OWDhX5v9bbVJjkbI nw8iqrL8ExAmfZiz0WLw4zAtvvTwH45zXq2VJxTfhwOBVZ26voQNfsjqHoVjQqCHIszt Bvsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=vN+eIL5Hhd+nnLeZLP8U3hgJnV+tIRgeVsrxthQl0ig=; b=FE13xCMUU09wsN9legKsSwg4vu7zO8mwVV1nBwkO3H5MSH1CJzBg0d4GPPG1Ou9FPx 9v6dCua+bTHxYG6eTveXWYbnYrMNSOy2R5lfq8xeom/Jf2D80n0QP9cdFmiKXfFth2Kq ziCmjLl/QFZ+ixUZxjRcHNefDV++BlUf7TuZRZrz5uMXGd3JU2EJIupqWzc2x3Vs3zEj dYdH3npAT59W9xyFIM2L/HXN05oAXm72DVj5Edb2WiHn2/m3R3Yom39E1072q8/amdE4 woAvwQiX/LqqgJWoNTXckDY7Hthv6eOjadOju+SsELBJIkxZE4XTYZNYnEPHH+iYQHGn phxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7si1060659otf.87.2020.02.17.18.39.56; Mon, 17 Feb 2020 18:40:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726340AbgBRCiR (ORCPT + 99 others); Mon, 17 Feb 2020 21:38:17 -0500 Received: from mga14.intel.com ([192.55.52.115]:56191 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726171AbgBRCiR (ORCPT ); Mon, 17 Feb 2020 21:38:17 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Feb 2020 18:38:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,454,1574150400"; d="scan'208";a="407934661" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.254.210.1]) ([10.254.210.1]) by orsmga005.jf.intel.com with ESMTP; 17 Feb 2020 18:38:15 -0800 Subject: Re: [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping() To: Joerg Roedel , David Woodhouse Cc: jroedel@suse.de, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20200217193858.26990-1-joro@8bytes.org> <20200217193858.26990-4-joro@8bytes.org> From: Lu Baolu Message-ID: <83b21e50-9097-06db-d404-8fe400134bac@linux.intel.com> Date: Tue, 18 Feb 2020 10:38:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200217193858.26990-4-joro@8bytes.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Joerg, Thanks for doing this. On 2020/2/18 3:38, Joerg Roedel wrote: > From: Joerg Roedel > > The attachment of deferred devices needs to happen before the check > whether the device is identity mapped or not. Otherwise the check will > return wrong results, cause warnings boot failures in kdump kernels, like > > WARNING: CPU: 0 PID: 318 at ../drivers/iommu/intel-iommu.c:592 domain_get_iommu+0x61/0x70 > > [...] > > Call Trace: > __intel_map_single+0x55/0x190 > intel_alloc_coherent+0xac/0x110 > dmam_alloc_attrs+0x50/0xa0 > ahci_port_start+0xfb/0x1f0 [libahci] > ata_host_start.part.39+0x104/0x1e0 [libata] > > With the earlier check the kdump boot succeeds and a crashdump is written. > > Signed-off-by: Joerg Roedel > --- > drivers/iommu/intel-iommu.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c > index 42cdcce1602e..32f43695a22b 100644 > --- a/drivers/iommu/intel-iommu.c > +++ b/drivers/iommu/intel-iommu.c > @@ -2541,9 +2541,6 @@ static void do_deferred_attach(struct device *dev) > > static struct dmar_domain *deferred_attach_domain(struct device *dev) > { > - if (unlikely(attach_deferred(dev))) > - do_deferred_attach(dev); > - This should also be moved to the call place of deferred_attach_domain() in bounce_map_single(). bounce_map_single() assumes that devices always use DMA domain, so it doesn't call iommu_need_mapping(). We could do_deferred_attach() there manually. Best regards, baolu > return find_domain(dev); > } > > @@ -3595,6 +3592,9 @@ static bool iommu_need_mapping(struct device *dev) > if (iommu_dummy(dev)) > return false; > > + if (unlikely(attach_deferred(dev))) > + do_deferred_attach(dev); > + > ret = identity_mapping(dev); > if (ret) { > u64 dma_mask = *dev->dma_mask; >