Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp1085889imp; Thu, 21 Feb 2019 18:26:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IbtMZNHVOzYZpO3+zcIsjN0UY7maKhm9kZynT5xNqSIoNlrbdaqs1QC+wBe+zDkfSfCqAek X-Received: by 2002:a63:be0a:: with SMTP id l10mr1650666pgf.292.1550802367311; Thu, 21 Feb 2019 18:26:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550802367; cv=none; d=google.com; s=arc-20160816; b=WkjDnGACEpr7B6puxZw+cDNr9pJrC4dy07UDUWc/kLMjSSY1GY2uJHoT4Efcn/NfQv wGp+i/HEkhgMA0pjRrLZ5QPt40czkYK5KjJGrIZehrNkeATG/TjR2LmFPdg5Ny7DfbQq l4CAA9Ol1DGNs9pPMu4lYeZAAVNWK8bizOurTGFUtVpKJLE1a9y8OSqJZ5b3zrG4nLSx 4GkHZSTEh50QdkotWHFYDHTqv6knY1wzIX0m5cLEyrQFlbbuErXlW0wgJ7KwdupFBoZA 12r3SJdHg+EAkTD4MHEdRy/o0giGDrzIqh93Ludg3bD4Qj4gRi0mnLH5D9ZLePoUIsam Fwtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=K5iv9Bqkv57E7th1ubBs8xsOS1vVlvq9MWN2E9Jymdk=; b=gEkkKXWC8DyLtWqMRyziRgq0fvLWb0rC2qFgumxcuDnw9JLrwdatbKlr55YUt/b3ON tjN4IoQ53OCcB09wXflj+54Hhff2EC3vRRJvlG8J1stAUCHkY37/AEJnfcTHaptdSgcf iMVvxJG9xgrRHZkym1NMr8zIsfvmH2gbOkTRYDu+3WrOGcoZoKW2/9D82cXm/1D8R9rT Gih7Ic8WE0HmFn5AU7UUo/aO/67GLQXKfo0zFbXOIfpgF/fGhCwS/cfAgUKMhocf+GSJ /XbnyCH3foTTKjdTM+IeWUvXd46fKG7EkSlf4ZjbPL9RjcJd6KFk6yOarSnsFjj3hBCB CaHA== 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 c7si163840plr.276.2019.02.21.18.25.52; Thu, 21 Feb 2019 18:26:07 -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 S1727111AbfBVCZM (ORCPT + 99 others); Thu, 21 Feb 2019 21:25:12 -0500 Received: from mga01.intel.com ([192.55.52.88]:59159 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726974AbfBVCZK (ORCPT ); Thu, 21 Feb 2019 21:25:10 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2019 18:25:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,397,1544515200"; d="scan'208";a="116855188" Received: from allen-box.sh.intel.com ([10.239.159.136]) by orsmga007.jf.intel.com with ESMTP; 21 Feb 2019 18:25:06 -0800 From: Lu Baolu To: Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede Cc: ashok.raj@intel.com, sanjay.k.kumar@intel.com, jacob.jun.pan@intel.com, kevin.tian@intel.com, Jean-Philippe Brucker , yi.l.liu@intel.com, yi.y.sun@intel.com, peterx@redhat.com, tiwei.bie@intel.com, xin.zeng@intel.com, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [PATCH v7 4/9] iommu/vt-d: Move common code out of iommu_attch_device() Date: Fri, 22 Feb 2019 10:19:22 +0800 Message-Id: <20190222021927.13132-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190222021927.13132-1-baolu.lu@linux.intel.com> References: <20190222021927.13132-1-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This part of code could be used by both normal and aux domain specific attach entries. Hence move them into a common function to avoid duplication. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Signed-off-by: Lu Baolu --- drivers/iommu/intel-iommu.c | 60 ++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index a7e2238f869a..3d83451a414d 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -5054,35 +5054,14 @@ static void intel_iommu_domain_free(struct iommu_domain *domain) domain_exit(to_dmar_domain(domain)); } -static int intel_iommu_attach_device(struct iommu_domain *domain, - struct device *dev) +static int prepare_domain_attach_device(struct iommu_domain *domain, + struct device *dev) { struct dmar_domain *dmar_domain = to_dmar_domain(domain); struct intel_iommu *iommu; int addr_width; u8 bus, devfn; - if (device_is_rmrr_locked(dev)) { - dev_warn(dev, "Device is ineligible for IOMMU domain attach due to platform RMRR requirement. Contact your platform vendor.\n"); - return -EPERM; - } - - /* normally dev is not mapped */ - if (unlikely(domain_context_mapped(dev))) { - struct dmar_domain *old_domain; - - old_domain = find_domain(dev); - if (old_domain) { - rcu_read_lock(); - dmar_remove_one_dev_info(dev); - rcu_read_unlock(); - - if (!domain_type_is_vm_or_si(old_domain) && - list_empty(&old_domain->devices)) - domain_exit(old_domain); - } - } - iommu = device_to_iommu(dev, &bus, &devfn); if (!iommu) return -ENODEV; @@ -5115,7 +5094,40 @@ static int intel_iommu_attach_device(struct iommu_domain *domain, dmar_domain->agaw--; } - return domain_add_dev_info(dmar_domain, dev); + return 0; +} + +static int intel_iommu_attach_device(struct iommu_domain *domain, + struct device *dev) +{ + int ret; + + if (device_is_rmrr_locked(dev)) { + dev_warn(dev, "Device is ineligible for IOMMU domain attach due to platform RMRR requirement. Contact your platform vendor.\n"); + return -EPERM; + } + + /* normally dev is not mapped */ + if (unlikely(domain_context_mapped(dev))) { + struct dmar_domain *old_domain; + + old_domain = find_domain(dev); + if (old_domain) { + rcu_read_lock(); + dmar_remove_one_dev_info(dev); + rcu_read_unlock(); + + if (!domain_type_is_vm_or_si(old_domain) && + list_empty(&old_domain->devices)) + domain_exit(old_domain); + } + } + + ret = prepare_domain_attach_device(domain, dev); + if (ret) + return ret; + + return domain_add_dev_info(to_dmar_domain(domain), dev); } static void intel_iommu_detach_device(struct iommu_domain *domain, -- 2.17.1