From nobody Mon Feb 9 11:29:45 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=amzn.com ARC-Seal: i=1; a=rsa-sha256; t=1583412404; cv=none; d=zohomail.com; s=zohoarc; b=mVncokVW1adfeAW/xG5CTIvTjipUOEgcOQe8zVPdFF76FAKp7Ra3e3RrTYOI4blebq/KQoZiV67g1Rz1+KujVnRGR7OVkpaICo4lexaLh5SspmACKij/5QIzQM4uNeu0Y7EOK5ay3Dc23+NGXvZTLZnjs2sub1JCo2L4o2KZ+JA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583412404; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CjwEmdpb+uP5CGcuSiHKu2mbmA4jvZwg5mvvhLQX9Jo=; b=HjLLURESM/dwu/yAvHsEcF3CS3WoVv4zlpV0SWC+wGjiZOSzCxTvMeHeA+P+3TzatT7DtLEgeJcoGQzV5rHlo89Vbqk1s2DoMuUXVpb02TSA+tza1noi9hyqam7JSRpnarXy42V70StH5mSS01hGLvOk60KJ8EqesvVacu/CS7Q= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1583412404594880.8431556246118; Thu, 5 Mar 2020 04:46:44 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j9pt8-0000HI-RB; Thu, 05 Mar 2020 12:46:06 +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 1j9pt7-0000GW-5f for xen-devel@lists.xenproject.org; Thu, 05 Mar 2020 12:46:05 +0000 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 43a48d6a-5edf-11ea-a5ab-12813bfff9fa; Thu, 05 Mar 2020 12:45:59 +0000 (UTC) Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 05 Mar 2020 12:45:59 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (Postfix) with ESMTPS id 27C91A221B; Thu, 5 Mar 2020 12:45:54 +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; Thu, 5 Mar 2020 12:45:33 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D32EUB001.ant.amazon.com (10.43.166.125) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 5 Mar 2020 12:45:32 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 5 Mar 2020 12:45:29 +0000 X-Inumbo-ID: 43a48d6a-5edf-11ea-a5ab-12813bfff9fa IronPort-SDR: sKPqtfz/0FyqR4oVGknUH/rjvyq0S+XE3NOP8uztHDCB/hWn79TFU4ycBDWU8yyPQMcNs3KLlc jExnyaJz60Uw== X-IronPort-AV: E=Sophos;i="5.70,518,1574121600"; d="scan'208";a="29429131" From: To: Date: Thu, 5 Mar 2020 12:45:04 +0000 Message-ID: <20200305124504.3564-7-pdurrant@amzn.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200305124504.3564-1-pdurrant@amzn.com> References: <20200305124504.3564-1-pdurrant@amzn.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v3 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Durrant 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/msg020= 18.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 5298d80bd2..741f6dd444 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -1005,6 +1005,8 @@ int domain_relinquish_resources(struct domain *d) BUG(); } =20 + free_shared_info(d); + return 0; } =20 diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index bdcc0d972a..15db476646 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -690,7 +690,6 @@ void arch_domain_destroy(struct domain *d) pv_domain_destroy(d); free_perdomain_mappings(d); =20 - free_shared_info(d); cleanup_domain_irq_mapping(d); =20 psr_domain_free(d); @@ -2245,6 +2244,8 @@ int domain_relinquish_resources(struct domain *d) if ( is_hvm_domain(d) ) hvm_domain_relinquish_resources(d); =20 + free_shared_info(d); + return 0; } =20 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( =20 int alloc_shared_info(struct domain *d, unsigned int memflags) { - if ( (d->shared_info.virt =3D alloc_xenheap_pages(0, memflags)) =3D=3D= NULL ) + struct page_info *pg; + + pg =3D alloc_domheap_page(d, MEMF_no_refcount | memflags); + if ( !pg ) return -ENOMEM; =20 - d->shared_info.mfn =3D 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 =3D page_to_mfn(pg); + d->shared_info.virt =3D __map_domain_page_global(pg); =20 clear_page(d->shared_info.virt); - share_xen_page_with_guest(mfn_to_page(d->shared_info.mfn), d, SHARE_rw= ); =20 return 0; } =20 void free_shared_info(struct domain *d) { + struct page_info *pg; + if ( !d->shared_info.virt ) return; =20 - free_xenheap_page(d->shared_info.virt); + unmap_domain_page_global(d->shared_info.virt); d->shared_info.virt =3D NULL; + + pg =3D mfn_to_page(d->shared_info.mfn); + + put_page_alloc_ref(pg); + put_page_and_type(pg); } =20 /* 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; =20 + /* 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; =20 + if ( d !=3D 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); =20 wc_version =3D &shared_info(d, wc_version); @@ -121,6 +133,9 @@ void update_domain_wallclock_time(struct domain *d) *wc_version =3D version_update_end(*wc_version); =20 spin_unlock(&wc_lock); + unlock: + if ( d !=3D current->domain ) + domain_unlock(d); } =20 /* Set clock to after 00:00:00 UTC, 1 January, 1970. */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel