From patchwork Tue Oct 1 08:28:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11168221 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 905261599 for ; Tue, 1 Oct 2019 08:29:49 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6B54321783 for ; Tue, 1 Oct 2019 08:29:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="U7+SKkzb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B54321783 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFDWG-0007Zt-8B; Tue, 01 Oct 2019 08:28:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFDWF-0007Zm-DH for xen-devel@lists.xenproject.org; Tue, 01 Oct 2019 08:28:27 +0000 X-Inumbo-ID: 6f9d7416-e425-11e9-96f4-12813bfff9fa Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by localhost (Halon) with ESMTPS id 6f9d7416-e425-11e9-96f4-12813bfff9fa; Tue, 01 Oct 2019 08:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1569918506; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=blPZs7U2JM4O6k6nBMNKdwPphdgEJHB3IGwWcUJP3fA=; b=U7+SKkzbTT2+5OWewY4G75/5xBMmud16MYEBiGxs4HPBFKIykztPGtrq SL3dv7oZ5cxMNtqZWcuSlNTAy8t4UdVATtbs0StopNc8q593F04tMyrQD E9tPn100hqGrElXvUpvbSWh2TG0x1uYtZRT7jz4ZvJkwATLsEVLRL1R9R Q=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 6oCxCUHSDgAgbxgvN1R2szSz4405WtpopLrJ8E2JbfcFw1BUPcjxdDLc2tN5SnYhmy7jnXp/UJ pHpaJ8zSkaITivTwokF6lp1enk/DjMUN64vVe6LEOVjp9w+E8VEImceTBxcBI2DGXr0YkhLQ8r B9F5Zi+t4f/vEl5cmMzW9ViSKng6YXDezL2uk+texLegvD2xV+HPXDgl/VUlsSRIIOSMR7YXrH aiGJdVy/dgeh/MmbpdymeZa3/TN7XRz4nErcuxhym12wkJlB6KGKMLDGO6ilQ2D8haQTqBLEFU R2s= X-SBRS: 2.7 X-MesageID: 6299397 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,570,1559534400"; d="scan'208";a="6299397" From: Paul Durrant To: Date: Tue, 1 Oct 2019 09:28:18 +0100 Message-ID: <20191001082818.34233-1-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH-for-4.13] x86/mm: don't needlessly veto migration X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Wei Liu , George Dunlap , Andrew Cooper , Paul Durrant , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Now that xl.cfg has an option to explicitly enable IOMMU mappings for a domain, migration may be needlessly vetoed due to the check of is_iommu_enabled() in paging_log_dirty_enable(). There is actually no need to prevent logdirty from being enabled unless devices are assigned to a domain and that domain is sharing HAP mappings with the IOMMU (in which case disabling write permissions in the P2M may cause DMA faults). This patch therefore reverts commit 37201c62 "make logdirty and iommu mutually exclusive" and replaces it with checks to ensure that, if iommu_use_hap_pt() is true, that logdirty and device assignment are mutually exclusive. NOTE: While in the neighbourhood, the bool_t parameter type in paging_log_dirty_enable() is replaced with a bool and the format of the comment in assign_device() is fixed. Signed-off-by: Paul Durrant --- Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monné" Cc: Juergen Gross --- xen/arch/x86/mm/hap/hap.c | 2 +- xen/arch/x86/mm/paging.c | 8 ++++---- xen/drivers/passthrough/pci.c | 10 +++++++--- xen/include/asm-x86/paging.h | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 412a442b6a..3d93f3451c 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -71,7 +71,7 @@ int hap_track_dirty_vram(struct domain *d, if ( !paging_mode_log_dirty(d) ) { - rc = paging_log_dirty_enable(d, 0); + rc = paging_log_dirty_enable(d, false); if ( rc ) goto out; } diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index d9a52c4db4..240f6f93fb 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -209,15 +209,15 @@ static int paging_free_log_dirty_bitmap(struct domain *d, int rc) return rc; } -int paging_log_dirty_enable(struct domain *d, bool_t log_global) +int paging_log_dirty_enable(struct domain *d, bool log_global) { int ret; - if ( is_iommu_enabled(d) && log_global ) + if ( has_arch_pdevs(d) && iommu_use_hap_pt(d) && log_global ) { /* * Refuse to turn on global log-dirty mode - * if the domain is using the IOMMU. + * if the domain is sharing the P2M with the IOMMU. */ return -EINVAL; } @@ -727,7 +727,7 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc, break; /* Else fall through... */ case XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY: - return paging_log_dirty_enable(d, 1); + return paging_log_dirty_enable(d, true); case XEN_DOMCTL_SHADOW_OP_OFF: if ( (rc = paging_log_dirty_disable(d, resuming)) != 0 ) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 7deef2f12b..9614dca8c1 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1486,11 +1486,15 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) if ( !is_iommu_enabled(d) ) return 0; - /* Prevent device assign if mem paging or mem sharing have been - * enabled for this domain */ + /* + * Prevent device assign if mem paging or mem sharing have been + * enabled for this domain, or logdirty is enabled and the P2M is + * shared with the IOMMU. + */ if ( unlikely(d->arch.hvm.mem_sharing_enabled || vm_event_check_ring(d->vm_event_paging) || - p2m_get_hostp2m(d)->global_logdirty) ) + (p2m_get_hostp2m(d)->global_logdirty && + iommu_use_hap_pt(d))) ) return -EXDEV; if ( !pcidevs_trylock() ) diff --git a/xen/include/asm-x86/paging.h b/xen/include/asm-x86/paging.h index ab7887f23c..8c2027c791 100644 --- a/xen/include/asm-x86/paging.h +++ b/xen/include/asm-x86/paging.h @@ -157,7 +157,7 @@ void paging_log_dirty_range(struct domain *d, uint8_t *dirty_bitmap); /* enable log dirty */ -int paging_log_dirty_enable(struct domain *d, bool_t log_global); +int paging_log_dirty_enable(struct domain *d, bool log_global); /* log dirty initialization */ void paging_log_dirty_init(struct domain *d, const struct log_dirty_ops *ops);