From patchwork Fri Feb 28 13:27:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11412263 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 935EF1395 for ; Fri, 28 Feb 2020 13:29:38 +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 6414D246A8 for ; Fri, 28 Feb 2020 13:29:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="iKDrsps5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6414D246A8 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.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 1j7fgg-0006Q6-0h; Fri, 28 Feb 2020 13:28:18 +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 1j7fge-0006Pu-SI for xen-devel@lists.xenproject.org; Fri, 28 Feb 2020 13:28:16 +0000 X-Inumbo-ID: 2be6c91e-5a2e-11ea-993b-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2be6c91e-5a2e-11ea-993b-12813bfff9fa; Fri, 28 Feb 2020 13:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582896495; x=1614432495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CRxmGjVAt9sHh2hAJkmrZyAPX/LtvzvpSoGA012X7iQ=; b=iKDrsps5yU/6/7UlQ1XBkQ1GBDLHNgLXnyJuEItLb2HvN42uJtzztJ7S eSvRegzp8YZdII3Fno2GGMgjnUZBuAZT8L+lxrVOaK9Ob1vcX6p0g+Zmk pdckhn9PyXr7yjUK9j+sPXkV1QMooO37Iyzd9VrnXINbn1xsprNtP9xIP A=; IronPort-SDR: 6dbgpjqf9BF4fzBWxqUneo2EJTUqCh/jvHkLreXhvb1KtnEjjNeFsmPpTSg1xQKj8pj5HY9fJa Ps3h/KqC7hgg== X-IronPort-AV: E=Sophos;i="5.70,496,1574121600"; d="scan'208";a="28113496" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-55156cd4.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 28 Feb 2020 13:28:12 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-55156cd4.us-west-2.amazon.com (Postfix) with ESMTPS id 5CED9A2D30; Fri, 28 Feb 2020 13:28:11 +0000 (UTC) Received: from EX13D32EUC001.ant.amazon.com (10.43.164.159) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 28 Feb 2020 13:28:10 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D32EUC001.ant.amazon.com (10.43.164.159) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 28 Feb 2020 13:28:08 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 28 Feb 2020 13:28:00 +0000 From: Paul Durrant To: Date: Fri, 28 Feb 2020 13:27:44 +0000 Message-ID: <20200228132749.2929-2-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228132749.2929-1-pdurrant@amazon.com> References: <20200228132749.2929-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 1/6] domain: introduce alloc/free_shared_info() helpers... X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Paul Durrant , Ian Jackson , George Dunlap , Jan Beulich , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" ... and save the MFN. This patch modifies the 'shared_info' field of struct domain to be a structure comprising an MFN and a virtual address. Allocations are still done from xenheap, so the virtual address still equates to virt_to_mfn() called on the MFN but subsequent patch will change this. Hence the need to save the MFN. NOTE: Whist defining the new helpers, virt_to_mfn() in common/domain.c is made type safe. The definition of nmi_reason() in asm-x86/shared.h is also re- flowed to avoid overly long lines. Signed-off-by: Paul Durrant Reviewed-by: Julien Grall --- Cc: Stefano Stabellini Cc: Volodymyr Babchuk Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Wei Liu Cc: "Roger Pau Monné" --- xen/arch/arm/domain.c | 8 ++------ xen/arch/arm/mm.c | 2 +- xen/arch/x86/domain.c | 11 ++++------- xen/arch/x86/mm.c | 2 +- xen/arch/x86/pv/dom0_build.c | 2 +- xen/arch/x86/pv/shim.c | 2 +- xen/common/domain.c | 26 ++++++++++++++++++++++++++ xen/common/domctl.c | 2 +- xen/common/time.c | 4 ++-- xen/include/asm-x86/shared.h | 15 ++++++++------- xen/include/xen/domain.h | 3 +++ xen/include/xen/sched.h | 5 ++++- xen/include/xen/shared.h | 2 +- 13 files changed, 55 insertions(+), 29 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index aa3df3b3ba..2cbcdaac08 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -690,13 +690,9 @@ int arch_domain_create(struct domain *d, if ( (rc = p2m_init(d)) != 0 ) goto fail; - rc = -ENOMEM; - if ( (d->shared_info = alloc_xenheap_pages(0, 0)) == NULL ) + if ( (rc = alloc_shared_info(d, 0)) != 0 ) goto fail; - clear_page(d->shared_info); - share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw); - switch ( config->arch.gic_version ) { case XEN_DOMCTL_CONFIG_GIC_V2: @@ -767,7 +763,7 @@ void arch_domain_destroy(struct domain *d) p2m_teardown(d); domain_vgic_free(d); domain_vuart_free(d); - free_xenheap_page(d->shared_info); + free_shared_info(d); #ifdef CONFIG_ACPI free_xenheap_pages(d->arch.efi_acpi_table, get_order_from_bytes(d->arch.efi_acpi_len)); diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 727107eefa..2bb592101d 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1424,7 +1424,7 @@ int xenmem_add_to_physmap_one( if ( idx != 0 ) return -EINVAL; - mfn = virt_to_mfn(d->shared_info); + mfn = d->shared_info.mfn; t = p2m_ram_rw; break; diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index fe63c23676..eb7b0fc51c 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -612,12 +612,9 @@ int arch_domain_create(struct domain *d, * The shared_info machine address must fit in a 32-bit field within a * 32-bit guest's start_info structure. Hence we specify MEMF_bits(32). */ - if ( (d->shared_info = alloc_xenheap_pages(0, MEMF_bits(32))) == NULL ) + if ( (rc = alloc_shared_info(d, MEMF_bits(32))) != 0 ) goto fail; - clear_page(d->shared_info); - share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw); - if ( (rc = init_domain_irq_mapping(d)) != 0 ) goto fail; @@ -665,7 +662,7 @@ int arch_domain_create(struct domain *d, psr_domain_free(d); iommu_domain_destroy(d); cleanup_domain_irq_mapping(d); - free_xenheap_page(d->shared_info); + free_shared_info(d); xfree(d->arch.cpuid); xfree(d->arch.msr); if ( paging_initialised ) @@ -694,7 +691,7 @@ void arch_domain_destroy(struct domain *d) pv_domain_destroy(d); free_perdomain_mappings(d); - free_xenheap_page(d->shared_info); + free_shared_info(d); cleanup_domain_irq_mapping(d); psr_domain_free(d); @@ -720,7 +717,7 @@ void arch_domain_unpause(struct domain *d) int arch_domain_soft_reset(struct domain *d) { - struct page_info *page = virt_to_page(d->shared_info), *new_page; + struct page_info *page = mfn_to_page(d->shared_info.mfn), *new_page; int ret = 0; struct domain *owner; mfn_t mfn; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 70b87c4830..5067125cbb 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4538,7 +4538,7 @@ int xenmem_add_to_physmap_one( { case XENMAPSPACE_shared_info: if ( idx == 0 ) - mfn = virt_to_mfn(d->shared_info); + mfn = d->shared_info.mfn; break; case XENMAPSPACE_grant_table: rc = gnttab_map_frame(d, idx, gpfn, &mfn); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 5678da782d..dc16ef2e79 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -743,7 +743,7 @@ int __init dom0_construct_pv(struct domain *d, clear_page(si); si->nr_pages = nr_pages; - si->shared_info = virt_to_maddr(d->shared_info); + si->shared_info = mfn_to_maddr(d->shared_info.mfn); if ( !pv_shim ) si->flags = SIF_PRIVILEGED | SIF_INITDOMAIN; diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index d86e2de118..f512809dad 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -282,7 +282,7 @@ static void write_start_info(struct domain *d) snprintf(si->magic, sizeof(si->magic), "xen-3.0-x86_%s", is_pv_32bit_domain(d) ? "32p" : "64"); si->nr_pages = domain_tot_pages(d); - si->shared_info = virt_to_maddr(d->shared_info); + si->shared_info = mfn_to_maddr(d->shared_info.mfn); si->flags = 0; BUG_ON(xen_hypercall_hvm_get_param(HVM_PARAM_STORE_PFN, &si->store_mfn)); BUG_ON(xen_hypercall_hvm_get_param(HVM_PARAM_STORE_EVTCHN, ¶m)); diff --git a/xen/common/domain.c b/xen/common/domain.c index 6ad458fa6b..ba7a905258 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -47,6 +47,10 @@ #include #endif +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn(v) _mfn(__virt_to_mfn(v)) + /* Linux config option: propageted to domain0 */ /* xen_processor_pmbits: xen control Cx, Px, ... */ unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX; @@ -1644,6 +1648,28 @@ int continue_hypercall_on_cpu( return 0; } +int alloc_shared_info(struct domain *d, unsigned int memflags) +{ + if ( (d->shared_info.virt = alloc_xenheap_pages(0, memflags)) == NULL ) + return -ENOMEM; + + d->shared_info.mfn = virt_to_mfn(d->shared_info.virt); + + clear_page(d->shared_info.virt); + share_xen_page_with_guest(mfn_to_page(d->shared_info.mfn), d, SHARE_rw); + + return 0; +} + +void free_shared_info(struct domain *d) +{ + if ( !d->shared_info.virt ) + return; + + free_xenheap_page(d->shared_info.virt); + d->shared_info.virt = NULL; +} + /* * Local variables: * mode: C diff --git a/xen/common/domctl.c b/xen/common/domctl.c index a69b3b59a8..81f18e63a7 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -196,7 +196,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info) info->outstanding_pages = d->outstanding_pages; info->shr_pages = atomic_read(&d->shr_pages); info->paged_pages = atomic_read(&d->paged_pages); - info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info)); + info->shared_info_frame = mfn_to_gmfn(d, mfn_x(d->shared_info.mfn)); BUG_ON(SHARED_M2P(info->shared_info_frame)); info->cpupool = cpupool_get_id(d); diff --git a/xen/common/time.c b/xen/common/time.c index 82336e2d5a..58fa9abc40 100644 --- a/xen/common/time.c +++ b/xen/common/time.c @@ -110,9 +110,9 @@ void update_domain_wallclock_time(struct domain *d) shared_info(d, wc_nsec) = wc_nsec; #ifdef CONFIG_X86 if ( likely(!has_32bit_shinfo(d)) ) - d->shared_info->native.wc_sec_hi = sec >> 32; + d->shared_info.virt->native.wc_sec_hi = sec >> 32; else - d->shared_info->compat.arch.wc_sec_hi = sec >> 32; + d->shared_info.virt->compat.arch.wc_sec_hi = sec >> 32; #else shared_info(d, wc_sec_hi) = sec >> 32; #endif diff --git a/xen/include/asm-x86/shared.h b/xen/include/asm-x86/shared.h index af5d959d04..d4588e08a6 100644 --- a/xen/include/asm-x86/shared.h +++ b/xen/include/asm-x86/shared.h @@ -1,24 +1,25 @@ #ifndef __XEN_X86_SHARED_H__ #define __XEN_X86_SHARED_H__ -#define nmi_reason(d) (!has_32bit_shinfo(d) ? \ - (u32 *)&(d)->shared_info->native.arch.nmi_reason : \ - (u32 *)&(d)->shared_info->compat.arch.nmi_reason) +#define nmi_reason(d) \ + (!has_32bit_shinfo(d) ? \ + (u32 *)&(d)->shared_info.virt->native.arch.nmi_reason : \ + (u32 *)&(d)->shared_info.virt->compat.arch.nmi_reason) #define GET_SET_SHARED(type, field) \ static inline type arch_get_##field(const struct domain *d) \ { \ return !has_32bit_shinfo(d) ? \ - d->shared_info->native.arch.field : \ - d->shared_info->compat.arch.field; \ + d->shared_info.virt->native.arch.field : \ + d->shared_info.virt->compat.arch.field; \ } \ static inline void arch_set_##field(struct domain *d, \ type val) \ { \ if ( !has_32bit_shinfo(d) ) \ - d->shared_info->native.arch.field = val; \ + d->shared_info.virt->native.arch.field = val; \ else \ - d->shared_info->compat.arch.field = val; \ + d->shared_info.virt->compat.arch.field = val; \ } #define GET_SET_VCPU(type, field) \ diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 7e51d361de..740e2032ad 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -130,4 +130,7 @@ struct vnuma_info { void vnuma_destroy(struct vnuma_info *vnuma); +int alloc_shared_info(struct domain *d, unsigned int memflags); +void free_shared_info(struct domain *d); + #endif /* __XEN_DOMAIN_H__ */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 3a4f43098c..f41d0ad2a0 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -346,7 +346,10 @@ struct domain unsigned int max_vcpus; struct vcpu **vcpu; - shared_info_t *shared_info; /* shared data area */ + struct { + mfn_t mfn; + shared_info_t *virt; + } shared_info; /* shared data area */ spinlock_t domain_lock; diff --git a/xen/include/xen/shared.h b/xen/include/xen/shared.h index a411a8a3e3..57b2ff1e34 100644 --- a/xen/include/xen/shared.h +++ b/xen/include/xen/shared.h @@ -43,7 +43,7 @@ typedef struct vcpu_info vcpu_info_t; extern vcpu_info_t dummy_vcpu_info; -#define shared_info(d, field) __shared_info(d, (d)->shared_info, field) +#define shared_info(d, field) __shared_info(d, (d)->shared_info.virt, field) #define vcpu_info(v, field) __vcpu_info(v, (v)->vcpu_info, field) #endif /* __XEN_SHARED_H__ */ From patchwork Fri Feb 28 13:27:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11412255 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 7D5A91395 for ; Fri, 28 Feb 2020 13:29:27 +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 5A0D62469D for ; Fri, 28 Feb 2020 13:29:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="HpjPcDNd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A0D62469D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.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 1j7fgr-0006Se-Fk; Fri, 28 Feb 2020 13:28:29 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j7fgq-0006SR-Ti for xen-devel@lists.xenproject.org; Fri, 28 Feb 2020 13:28:28 +0000 X-Inumbo-ID: 33e3572c-5a2e-11ea-9c17-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 33e3572c-5a2e-11ea-9c17-bc764e2007e4; Fri, 28 Feb 2020 13:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582896508; x=1614432508; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IIPO1W2DLOiz3N+ViDmVAGukygPguvOI3oWjQG1Lv4Y=; b=HpjPcDNdWy4p8HJlqpkRaibqqmnhwUY28V9Jocl5luOrlbyHT5rwwJcU H1RrbPxUaFbotzktVMd0yUjrh+N9ix+3upkhWJqjbwNf9xKi2SyhVUAlF 0k0HHDKFx/C3Pled98wSTA8U7ETGSqBGYWqUgbPxGRLvld/97GcaP3KEF w=; IronPort-SDR: vVEokuDxccK8SkLKiE57P7eK2rBJ8ByHHn1dO9+b4ID6nrwBHg+956DFgsYij6KisgqCrYIEG/ 9tpx6+zw/mSw== X-IronPort-AV: E=Sophos;i="5.70,496,1574121600"; d="scan'208";a="29495744" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-55156cd4.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 28 Feb 2020 13:28:27 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-55156cd4.us-west-2.amazon.com (Postfix) with ESMTPS id A89BBA2D35; Fri, 28 Feb 2020 13:28:26 +0000 (UTC) Received: from EX13D32EUC002.ant.amazon.com (10.43.164.94) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 28 Feb 2020 13:28:12 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D32EUC002.ant.amazon.com (10.43.164.94) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 28 Feb 2020 13:28:11 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 28 Feb 2020 13:28:09 +0000 From: Paul Durrant To: Date: Fri, 28 Feb 2020 13:27:45 +0000 Message-ID: <20200228132749.2929-3-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228132749.2929-1-pdurrant@amazon.com> References: <20200228132749.2929-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 2/6] x86 / p2m: remove page_list check in p2m_alloc_table X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Andrew Cooper , Paul Durrant , George Dunlap , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" There does not seem to be any justification for refusing to create the domain's p2m table simply because it may have assigned pages. Particularly it prevents the prior allocation of PGC_extra pages. Signed-off-by: Paul Durrant --- Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap Cc: Wei Liu Cc: "Roger Pau Monné" v2: - New in v2 --- xen/arch/x86/mm/p2m.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 3719deae77..9fd4b115be 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -695,14 +695,6 @@ int p2m_alloc_table(struct p2m_domain *p2m) p2m_lock(p2m); - if ( p2m_is_hostp2m(p2m) - && !page_list_empty(&d->page_list) ) - { - P2M_ERROR("dom %d already has memory allocated\n", d->domain_id); - p2m_unlock(p2m); - return -EINVAL; - } - if ( pagetable_get_pfn(p2m_get_pagetable(p2m)) != 0 ) { P2M_ERROR("p2m already allocated for this domain\n"); From patchwork Fri Feb 28 13:27:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11412265 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 9A80B1871 for ; Fri, 28 Feb 2020 13:29:38 +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 76FF8246AF for ; Fri, 28 Feb 2020 13:29:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="VkwCIlgT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76FF8246AF Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.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 1j7fgw-0006UG-OS; Fri, 28 Feb 2020 13:28:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j7fgv-0006Tz-QF for xen-devel@lists.xenproject.org; Fri, 28 Feb 2020 13:28:33 +0000 X-Inumbo-ID: 345865b2-5a2e-11ea-9c17-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 345865b2-5a2e-11ea-9c17-bc764e2007e4; Fri, 28 Feb 2020 13:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582896509; x=1614432509; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FLFrd5BqWuxEnRZrNNFJx3LfPVqiZQmgQS2zwXc0o+s=; b=VkwCIlgT9zJM8ZUkYc5IBNxIKuDWxepOUTCkYMhcfgzp6WbsS+6Pnw/d YuUzbdm8AuzUd1RN3WV/Nx+mJ3Q618xLcYgyNQEOMXGd/+G31IstOx28K z6CooZmtPeMStcSSt+SOUEaqmAfQ4mwDvQQfCQ6PeX6F5IexGR9JNpqCl U=; IronPort-SDR: VgJRPltPgwCTLWq6D22IzOdTtCkp1dQ+toI0h13nXaS/3QpcCJoOxWUW0y7CtL77IJeTTIE4X0 m03iW6Ri7V/w== X-IronPort-AV: E=Sophos;i="5.70,496,1574121600"; d="scan'208";a="28113527" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-5bdc5131.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 28 Feb 2020 13:28:28 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-5bdc5131.us-west-2.amazon.com (Postfix) with ESMTPS id 65FA2A2A3C; Fri, 28 Feb 2020 13:28:27 +0000 (UTC) Received: from EX13D32EUB001.ant.amazon.com (10.43.166.125) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 28 Feb 2020 13:28:14 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D32EUB001.ant.amazon.com (10.43.166.125) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 28 Feb 2020 13:28:13 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 28 Feb 2020 13:28:11 +0000 From: Paul Durrant To: Date: Fri, 28 Feb 2020 13:27:46 +0000 Message-ID: <20200228132749.2929-4-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228132749.2929-1-pdurrant@amazon.com> References: <20200228132749.2929-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 3/6] x86 / pv: do not treat PGC_extra pages as RAM when constructing dom0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Paul Durrant , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The walk of page_list in dom0_construct_pv() should ignore PGC_extra pages as they are only created for special purposes and, if mapped, will be mapped explicitly for whatever purpose is relevant. Signed-off-by: Paul Durrant --- Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monné" v2: - New in v2 --- xen/arch/x86/pv/dom0_build.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index dc16ef2e79..f8f1bbe2f4 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -792,6 +792,10 @@ int __init dom0_construct_pv(struct domain *d, { mfn = mfn_x(page_to_mfn(page)); BUG_ON(SHARED_M2P(get_gpfn_from_mfn(mfn))); + + if ( page->count_info & PGC_extra ) + continue; + if ( get_gpfn_from_mfn(mfn) >= count ) { BUG_ON(is_pv_32bit_domain(d)); From patchwork Fri Feb 28 13:27:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11412279 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 E7113159A for ; Fri, 28 Feb 2020 13:29:53 +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 C414D2469D for ; Fri, 28 Feb 2020 13:29:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="GiEKiV9L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C414D2469D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.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 1j7fh5-0006Y9-Ck; Fri, 28 Feb 2020 13:28:43 +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 1j7fh4-0006XP-3l for xen-devel@lists.xenproject.org; Fri, 28 Feb 2020 13:28:42 +0000 X-Inumbo-ID: 3c671fb4-5a2e-11ea-993b-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3c671fb4-5a2e-11ea-993b-12813bfff9fa; Fri, 28 Feb 2020 13:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582896522; x=1614432522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VwUop21K3G8ExpStnABalvSNIyzshZ8JYuHGn+3MCPA=; b=GiEKiV9LJcgU83WxE9c7OkeB05AXQeUoGDnMV4bb7XfXirhagzlVRnJP I/A1jY82Ei83O59sc66RGOEaDpvWopQd8RzpBQMqBj0ijgobTeGDyRAYw f67MbqW0D2degiDkwvkiuJV4kEIB2OIG1g035r1UtdIyaf4AG+L2Q5/br 4=; IronPort-SDR: +rW9OhTk3zour0JUluQuwudaGWZqiw0GGl7kPZrM7OJaAfjaUKDIwentlCitfqdaTnJIdzn7fJ OwRz/JkVlulQ== X-IronPort-AV: E=Sophos;i="5.70,496,1574121600"; d="scan'208";a="19026438" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 28 Feb 2020 13:28:29 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com (Postfix) with ESMTPS id 1A48AA2C09; Fri, 28 Feb 2020 13:28:28 +0000 (UTC) Received: from EX13D32EUC003.ant.amazon.com (10.43.164.24) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 28 Feb 2020 13:28:16 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D32EUC003.ant.amazon.com (10.43.164.24) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 28 Feb 2020 13:28:14 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 28 Feb 2020 13:28:13 +0000 From: Paul Durrant To: Date: Fri, 28 Feb 2020 13:27:47 +0000 Message-ID: <20200228132749.2929-5-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228132749.2929-1-pdurrant@amazon.com> References: <20200228132749.2929-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 4/6] x86 / ioreq: use a MEMF_no_refcount allocation for server pages... X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Paul Durrant , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" ... now that it is safe to assign them. This avoids relying on libxl (or whatever toolstack is in use) setting max_pages up with sufficient 'slop' to allow all necessary ioreq server pages to be allocated. Signed-off-by: Paul Durrant --- Cc: Paul Durrant Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monné" v2: - New in v2 --- xen/arch/x86/hvm/ioreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/ioreq.c b/xen/arch/x86/hvm/ioreq.c index f8a5c81546..648ef9137f 100644 --- a/xen/arch/x86/hvm/ioreq.c +++ b/xen/arch/x86/hvm/ioreq.c @@ -375,7 +375,7 @@ static int hvm_alloc_ioreq_mfn(struct hvm_ioreq_server *s, bool buf) return 0; } - page = alloc_domheap_page(s->target, 0); + page = alloc_domheap_page(s->target, MEMF_no_refcount); if ( !page ) return -ENOMEM; From patchwork Fri Feb 28 13:27:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11412261 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 31F4D159A for ; Fri, 28 Feb 2020 13:29:38 +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 0E950246A8 for ; Fri, 28 Feb 2020 13:29:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="fJ1Php6x" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E950246A8 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.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 1j7fh2-0006W9-3Y; Fri, 28 Feb 2020 13:28:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j7fh0-0006Vl-RA for xen-devel@lists.xenproject.org; Fri, 28 Feb 2020 13:28:38 +0000 X-Inumbo-ID: 35e9853c-5a2e-11ea-9c17-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 35e9853c-5a2e-11ea-9c17-bc764e2007e4; Fri, 28 Feb 2020 13:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582896511; x=1614432511; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WhTNN0R27UQjOPzb2OK0Dk7NZgFZy+DofdnG+jWhKuQ=; b=fJ1Php6xmAsFQatxkm3uHQR6UvGwIWZQiMLzjk3OIOmkt2ITekFxlOWR YVOY0Wg5x4aB589uGTxJtMs1sl+Fqh3pdNzVQ4Uza7ygxFFvj0mxwOzLc ITtPjM6zIcVdi9oace6axKbIvJ4Vy8ctGFrSqRD7qqf4JddFYKa7IuIs2 Y=; IronPort-SDR: AKRM8/cEZRc1/JFrA02LtgTdktB4Nivls4ATyK8B8eYuAyAGK7nTBTZcwZNiU78uoMbipic69x 0+yxr7B+x6sA== X-IronPort-AV: E=Sophos;i="5.70,496,1574121600"; d="scan'208";a="29495757" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 28 Feb 2020 13:28:30 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com (Postfix) with ESMTPS id B5AFFA259E; Fri, 28 Feb 2020 13:28:29 +0000 (UTC) Received: from EX13D32EUB001.ant.amazon.com (10.43.166.125) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 28 Feb 2020 13:28:18 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D32EUB001.ant.amazon.com (10.43.166.125) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 28 Feb 2020 13:28:17 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 28 Feb 2020 13:28:15 +0000 From: Paul Durrant To: Date: Fri, 28 Feb 2020 13:27:48 +0000 Message-ID: <20200228132749.2929-6-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228132749.2929-1-pdurrant@amazon.com> References: <20200228132749.2929-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 5/6] mm: add 'is_special_page' macro... X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Paul Durrant , Ian Jackson , George Dunlap , Tim Deegan , Tamas K Lengyel , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" ... to cover xenheap and PGC_extra pages. PGC_extra pages are intended to hold data structures that are associated with a domain and my be mapped by that domain. They should not be treated as 'normal' guest pages (i.e. RAM or page tables). Hence, in many cases where code currently tests is_xen_heap_page() it should also check for the PGC_extra bit in 'count_info'. This patch therefore defines is_special_page() to cover both cases and converts tests if is_xen_heap_page() to is_special_page() where appropriate. Signed-off-by: Paul Durrant --- Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monné" Cc: George Dunlap Cc: Ian Jackson Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tamas K Lengyel Cc: Tim Deegan v2: - New in v2 --- xen/arch/x86/domctl.c | 2 +- xen/arch/x86/mm.c | 9 ++++----- xen/arch/x86/mm/altp2m.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 2 +- xen/arch/x86/mm/shadow/common.c | 13 ++++++++----- xen/include/xen/mm.h | 3 +++ 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index ed86762fa6..add70126b9 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -394,7 +394,7 @@ long arch_do_domctl( page = get_page_from_gfn(d, gfn, &t, P2M_ALLOC); if ( unlikely(!page) || - unlikely(is_xen_heap_page(page)) ) + unlikely(is_special_page(page)) ) { if ( unlikely(p2m_is_broken(t)) ) type = XEN_DOMCTL_PFINFO_BROKEN; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 5067125cbb..051ea5ebd6 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -1012,7 +1012,7 @@ get_page_from_l1e( unsigned long cacheattr = pte_flags_to_cacheattr(l1f); int err; - if ( is_xen_heap_page(page) ) + if ( is_special_page(page) ) { if ( write ) put_page_type(page); @@ -2445,7 +2445,7 @@ static int cleanup_page_mappings(struct page_info *page) { page->count_info &= ~PGC_cacheattr_mask; - BUG_ON(is_xen_heap_page(page)); + BUG_ON(is_special_page(page)); rc = update_xen_mappings(mfn, 0); } @@ -2475,7 +2475,7 @@ static int cleanup_page_mappings(struct page_info *page) rc = rc2; } - if ( likely(!is_xen_heap_page(page)) ) + if ( likely(!is_special_page(page)) ) { ASSERT((page->u.inuse.type_info & (PGT_type_mask | PGT_count_mask)) == PGT_writable_page); @@ -4214,8 +4214,7 @@ int steal_page( if ( !(owner = page_get_owner_and_reference(page)) ) goto fail; - if ( owner != d || is_xen_heap_page(page) || - (page->count_info & PGC_extra) ) + if ( owner != d || is_special_page(page) ) goto fail_put; /* diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c index 50768f2547..c091b03ea3 100644 --- a/xen/arch/x86/mm/altp2m.c +++ b/xen/arch/x86/mm/altp2m.c @@ -77,7 +77,7 @@ int altp2m_vcpu_enable_ve(struct vcpu *v, gfn_t gfn) * pageable() predicate for this, due to it having the same properties * that we want. */ - if ( !p2m_is_pageable(p2mt) || is_xen_heap_page(pg) ) + if ( !p2m_is_pageable(p2mt) || is_special_page(pg) ) { rc = -EINVAL; goto err; diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 3835bc928f..c14a724c6d 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -842,7 +842,7 @@ static int nominate_page(struct domain *d, gfn_t gfn, /* Skip xen heap pages */ page = mfn_to_page(mfn); - if ( !page || is_xen_heap_page(page) ) + if ( !page || is_special_page(page) ) goto out; /* Check if there are mem_access/remapped altp2m entries for this page */ diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c index cba3ab1eba..e835940d86 100644 --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -2087,19 +2087,22 @@ static int sh_remove_all_mappings(struct domain *d, mfn_t gmfn, gfn_t gfn) * The qemu helper process has an untyped mapping of this dom's RAM * and the HVM restore program takes another. * Also allow one typed refcount for - * - Xen heap pages, to match share_xen_page_with_guest(), - * - ioreq server pages, to match prepare_ring_for_helper(). + * - special pages, which are explicitly referenced and mapped by + * Xen. + * - ioreq server pages, which may be special pages or normal + * guest pages with an extra reference taken by + * prepare_ring_for_helper(). */ if ( !(shadow_mode_external(d) && (page->count_info & PGC_count_mask) <= 3 && ((page->u.inuse.type_info & PGT_count_mask) - == (is_xen_heap_page(page) || + == (is_special_page(page) || (is_hvm_domain(d) && is_ioreq_server_page(d, page))))) ) printk(XENLOG_G_ERR "can't find all mappings of mfn %"PRI_mfn - " (gfn %"PRI_gfn"): c=%lx t=%lx x=%d i=%d\n", + " (gfn %"PRI_gfn"): c=%lx t=%lx s=%d i=%d\n", mfn_x(gmfn), gfn_x(gfn), page->count_info, page->u.inuse.type_info, - !!is_xen_heap_page(page), + !!is_special_page(page), (is_hvm_domain(d) && is_ioreq_server_page(d, page))); } diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index d0d095d9c7..3a57c9177f 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -285,6 +285,9 @@ extern struct domain *dom_cow; #include +#define is_special_page(page) \ + (is_xen_heap_page(page) || ((page)->count_info & PGC_extra)) + #ifndef page_list_entry struct page_list_head { From patchwork Fri Feb 28 13:27:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11412275 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 A16CA1395 for ; Fri, 28 Feb 2020 13:29:44 +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 7E27C2469D for ; Fri, 28 Feb 2020 13:29:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="nmYGeE6+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E27C2469D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.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 1j7fh6-0006Z5-Nu; Fri, 28 Feb 2020 13:28:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j7fh5-0006YY-RH for xen-devel@lists.xenproject.org; Fri, 28 Feb 2020 13:28:43 +0000 X-Inumbo-ID: 378785ec-5a2e-11ea-9c17-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 378785ec-5a2e-11ea-9c17-bc764e2007e4; Fri, 28 Feb 2020 13:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582896514; x=1614432514; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=phoXTUtAHRHXArw7m39GSHUeuSya0ISgmTzsTs02scs=; b=nmYGeE6++Ll14yD6OLxnAufaHfKlBJFof77qgStm29oiR6fuJn3kJHYO Qb2ZsgJsXW2BUArChDFRIwiZCLiChgNPgrPUUNHPA04n772ppr1ytHFwF Hx2oIYpKjA8bxLzqdvbJSHi49hps2i/UYKQBwBYtz0QpuBBSrtHJfZy+E E=; IronPort-SDR: GTwRUKqrSQIgRLdvGaTY1V0xTJzoOhGIFfUGrXweKbQexgMFTydlbExOKJ9NuIpO12eivvx54s 8NjG3FFcrjgA== X-IronPort-AV: E=Sophos;i="5.70,496,1574121600"; d="scan'208";a="29495763" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-87a10be6.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 28 Feb 2020 13:28:33 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-87a10be6.us-west-2.amazon.com (Postfix) with ESMTPS id 4EFC0A3157; Fri, 28 Feb 2020 13:28:32 +0000 (UTC) Received: from EX13D32EUC004.ant.amazon.com (10.43.164.121) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 28 Feb 2020 13:28:20 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D32EUC004.ant.amazon.com (10.43.164.121) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 28 Feb 2020 13:28:19 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 28 Feb 2020 13:28:17 +0000 From: Paul Durrant To: Date: Fri, 28 Feb 2020 13:27:49 +0000 Message-ID: <20200228132749.2929-7-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228132749.2929-1-pdurrant@amazon.com> References: <20200228132749.2929-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 6/6] domain: use PGC_extra domheap page for shared_info X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Paul Durrant , Ian Jackson , George Dunlap , Jan Beulich , Volodymyr Babchuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently shared_info is a shared xenheap page but shared xenheap pages complicate future plans for live-update of Xen so it is desirable to, where possible, not use them [1]. This patch therefore converts shared_info into a PGC_extra domheap page. This does entail freeing shared_info during domain_relinquish_resources() rather than domain_destroy() so care is needed to avoid de-referencing a NULL shared_info pointer hence some extra checks of 'is_dying' are needed. NOTE: For Arm, the call to free_shared_info() in arch_domain_destroy() is left in place since it is idempotent and called in the error path for arch_domain_create(). [1] See https://lists.xenproject.org/archives/html/xen-devel/2020-02/msg02018.html Signed-off-by: Paul Durrant --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Volodymyr Babchuk Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Wei Liu v2: - Addressed comments from Julien - Expanded the commit comment to explain why this patch is wanted --- xen/arch/arm/domain.c | 2 ++ xen/arch/x86/domain.c | 3 ++- xen/common/domain.c | 28 ++++++++++++++++++++++++---- xen/common/event_channel.c | 3 +++ xen/common/time.c | 15 +++++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 2cbcdaac08..3904519256 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -1006,6 +1006,8 @@ int domain_relinquish_resources(struct domain *d) BUG(); } + free_shared_info(d); + return 0; } diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index eb7b0fc51c..3ad532eccf 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -691,7 +691,6 @@ void arch_domain_destroy(struct domain *d) pv_domain_destroy(d); free_perdomain_mappings(d); - free_shared_info(d); cleanup_domain_irq_mapping(d); psr_domain_free(d); @@ -2246,6 +2245,8 @@ int domain_relinquish_resources(struct domain *d) if ( is_hvm_domain(d) ) hvm_domain_relinquish_resources(d); + free_shared_info(d); + return 0; } diff --git a/xen/common/domain.c b/xen/common/domain.c index ba7a905258..886206f648 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1650,24 +1650,44 @@ int continue_hypercall_on_cpu( int alloc_shared_info(struct domain *d, unsigned int memflags) { - if ( (d->shared_info.virt = alloc_xenheap_pages(0, memflags)) == NULL ) + struct page_info *pg; + + pg = alloc_domheap_page(d, MEMF_no_refcount | memflags); + if ( !pg ) return -ENOMEM; - d->shared_info.mfn = virt_to_mfn(d->shared_info.virt); + if ( !get_page_and_type(pg, d, PGT_writable_page) ) + { + /* + * The domain should not be running at this point so there is + * no way we should reach this error path. + */ + ASSERT_UNREACHABLE(); + return -ENODATA; + } + + d->shared_info.mfn = page_to_mfn(pg); + d->shared_info.virt = __map_domain_page_global(pg); clear_page(d->shared_info.virt); - share_xen_page_with_guest(mfn_to_page(d->shared_info.mfn), d, SHARE_rw); return 0; } void free_shared_info(struct domain *d) { + struct page_info *pg; + if ( !d->shared_info.virt ) return; - free_xenheap_page(d->shared_info.virt); + unmap_domain_page_global(d->shared_info.virt); d->shared_info.virt = NULL; + + pg = mfn_to_page(d->shared_info.mfn); + + put_page_alloc_ref(pg); + put_page_and_type(pg); } /* diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index e86e2bfab0..a17422284d 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -1325,6 +1325,9 @@ void evtchn_destroy(struct domain *d) { unsigned int i; + /* This must be done before shared_info is freed */ + BUG_ON(!d->shared_info.virt); + /* After this barrier no new event-channel allocations can occur. */ BUG_ON(!d->is_dying); spin_barrier(&d->event_lock); diff --git a/xen/common/time.c b/xen/common/time.c index 58fa9abc40..ada02faf07 100644 --- a/xen/common/time.c +++ b/xen/common/time.c @@ -99,6 +99,18 @@ void update_domain_wallclock_time(struct domain *d) uint32_t *wc_version; uint64_t sec; + if ( d != current->domain ) + { + /* + * We need to check is_dying here as, if it is set, the + * shared_info may have been freed. To do this safely we need + * hold the domain lock. + */ + domain_lock(d); + if ( d->is_dying ) + goto unlock; + } + spin_lock(&wc_lock); wc_version = &shared_info(d, wc_version); @@ -121,6 +133,9 @@ void update_domain_wallclock_time(struct domain *d) *wc_version = version_update_end(*wc_version); spin_unlock(&wc_lock); + unlock: + if ( d != current->domain ) + domain_unlock(d); } /* Set clock to after 00:00:00 UTC, 1 January, 1970. */