From patchwork Thu May 2 12:29:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10926709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAC001398 for ; Thu, 2 May 2019 12:31:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9D7328E21 for ; Thu, 2 May 2019 12:31:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE10128E2D; Thu, 2 May 2019 12:31:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4E82A28E21 for ; Thu, 2 May 2019 12:31:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hMAqM-0006DY-FT; Thu, 02 May 2019 12:29:42 +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 1hMAqK-0006DQ-VG for xen-devel@lists.xenproject.org; Thu, 02 May 2019 12:29:40 +0000 X-Inumbo-ID: ecfe490c-6cd5-11e9-a4e7-b3b4f6c183f9 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ecfe490c-6cd5-11e9-a4e7-b3b4f6c183f9; Thu, 02 May 2019 12:29:28 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Thu, 02 May 2019 06:29:26 -0600 Message-Id: <5CCAE2A5020000780022B35E@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Thu, 02 May 2019 06:29:25 -0600 From: "Jan Beulich" To: "xen-devel" Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH] x86/HVM: p2m_ram_ro is incompatible with device pass-through 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: George Dunlap , Andrew Cooper , Paul Durrant , Wei Liu , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The write-discard property of the type can't be represented in IOMMU page table entries. Make sure the respective checks / tracking can't race, by utilizing the domain lock. The other sides of the sharing/ paging/log-dirty exclusion checks should subsequently perhaps also be put under that lock then. Take the opportunity and also convert neighboring bool_t to bool in struct hvm_domain. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/dm.c +++ b/xen/arch/x86/hvm/dm.c @@ -255,16 +255,32 @@ static int set_mem_type(struct domain *d mem_type = array_index_nospec(data->mem_type, ARRAY_SIZE(memtype)); - if ( mem_type == HVMMEM_ioreq_server ) + switch ( mem_type ) { unsigned int flags; + case HVMMEM_ioreq_server: if ( !hap_enabled(d) ) return -EOPNOTSUPP; /* Do not change to HVMMEM_ioreq_server if no ioreq server mapped. */ if ( !p2m_get_ioreq_server(d, &flags) ) return -EINVAL; + + break; + + case HVMMEM_ram_ro: + /* p2m_ram_ro can't be represented in IOMMU mappings. */ + domain_lock(d); + if ( has_iommu_pt(d) ) + rc = -EXDEV; + d->arch.hvm.p2m_ram_ro_used = true; + domain_unlock(d); + + if ( rc ) + return rc; + + break; } while ( iter < data->nr ) --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1450,17 +1450,36 @@ static int assign_device(struct domain * if ( !iommu_enabled || !hd->platform_ops ) return 0; - /* Prevent device assign if mem paging or mem sharing have been - * enabled for this domain */ - if ( unlikely(d->arch.hvm.mem_sharing_enabled || - vm_event_check_ring(d->vm_event_paging) || + domain_lock(d); + + /* + * Prevent device assignment if any of + * - mem paging + * - mem sharing + * - the p2m_ram_ro type + * - global log-dirty mode + * are in use by this domain. + */ + if ( unlikely(vm_event_check_ring(d->vm_event_paging) || +#ifdef CONFIG_HVM + (is_hvm_domain(d) && + (d->arch.hvm.mem_sharing_enabled || + d->arch.hvm.p2m_ram_ro_used)) || +#endif p2m_get_hostp2m(d)->global_logdirty) ) + { + domain_unlock(d); return -EXDEV; + } if ( !pcidevs_trylock() ) + { + domain_unlock(d); return -ERESTART; + } rc = iommu_construct(d); + domain_unlock(d); if ( rc ) { pcidevs_unlock(); --- a/xen/include/asm-x86/hvm/domain.h +++ b/xen/include/asm-x86/hvm/domain.h @@ -156,10 +156,11 @@ struct hvm_domain { struct viridian_domain *viridian; - bool_t hap_enabled; - bool_t mem_sharing_enabled; - bool_t qemu_mapcache_invalidate; - bool_t is_s3_suspended; + bool hap_enabled; + bool mem_sharing_enabled; + bool p2m_ram_ro_used; + bool qemu_mapcache_invalidate; + bool is_s3_suspended; /* * TSC value that VCPUs use to calculate their tsc_offset value.