From patchwork Wed Jun 22 14:37:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12890915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 13E34C43334 for ; Wed, 22 Jun 2022 14:39:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.353979.580992 (Exim 4.92) (envelope-from ) id 1o41VL-0004Q3-3V; Wed, 22 Jun 2022 14:38:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 353979.580992; Wed, 22 Jun 2022 14:38:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41VL-0004Pw-0b; Wed, 22 Jun 2022 14:38:51 +0000 Received: by outflank-mailman (input) for mailman id 353979; Wed, 22 Jun 2022 14:38:50 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41VJ-0004Nu-Ub for xen-devel@lists.xenproject.org; Wed, 22 Jun 2022 14:38:49 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 06943b83-f239-11ec-b725-ed86ccbb4733; Wed, 22 Jun 2022 16:38:48 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B8737D6E; Wed, 22 Jun 2022 07:38:48 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5333D3F792; Wed, 22 Jun 2022 07:38:47 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 06943b83-f239-11ec-b725-ed86ccbb4733 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 1/8] xen/evtchn: make evtchn_bind_interdomain global Date: Wed, 22 Jun 2022 15:37:58 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Event channel support will be added for dom0less domains to allocate static event channel. It is necessary to have access to the evtchn_bind_interdomain function to do that, so make evtchn_bind_interdomain global and also make it __must_check. Signed-off-by: Rahul Singh --- xen/common/event_channel.c | 2 +- xen/include/xen/event.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index e60cd98d75..8cbe9681da 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -347,7 +347,7 @@ static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn) evtchn_write_unlock(rchn); } -static int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) +int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) { struct evtchn *lchn, *rchn; struct domain *ld = current->domain, *rd; diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index f3021fe304..61615ebbe3 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -74,6 +74,9 @@ int evtchn_allocate_port(struct domain *d, unsigned int port); /* Allocate a new event channel */ int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc); +/* Bind an event channel port to interdomain */ +int __must_check evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind); + /* Unmask a local event-channel port. */ int evtchn_unmask(unsigned int port); From patchwork Wed Jun 22 14:37:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12890916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 20095C433EF for ; Wed, 22 Jun 2022 14:39:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.353984.581003 (Exim 4.92) (envelope-from ) id 1o41Vf-0004vZ-CO; Wed, 22 Jun 2022 14:39:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 353984.581003; Wed, 22 Jun 2022 14:39:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41Vf-0004vS-8r; Wed, 22 Jun 2022 14:39:11 +0000 Received: by outflank-mailman (input) for mailman id 353984; Wed, 22 Jun 2022 14:39:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41Ve-0003uL-Ax for xen-devel@lists.xenproject.org; Wed, 22 Jun 2022 14:39:10 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 1334c710-f239-11ec-bd2d-47488cf2e6aa; Wed, 22 Jun 2022 16:39:09 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DDD55D6E; Wed, 22 Jun 2022 07:39:08 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 64ECE3F792; Wed, 22 Jun 2022 07:39:07 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1334c710-f239-11ec-bd2d-47488cf2e6aa From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH 2/8] xen/evtchn: modify evtchn_alloc_unbound to allocate specified port Date: Wed, 22 Jun 2022 15:37:59 +0100 Message-Id: <5ea66595248c41a011ac465bfabd7a7a40dcd565.1655903088.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 evtchn_alloc_unbound() always allocates the next available port. Static event channel support for dom0less domains requires allocating a specified port. Modify the evtchn_alloc_unbound() to accept the port number as an argument and allocate the specified port if available. If the port number argument is zero, the next available port will be allocated. Signed-off-by: Rahul Singh --- xen/arch/arm/domain_build.c | 2 +- xen/common/event_channel.c | 26 +++++++++++++++++++++----- xen/include/xen/event.h | 3 ++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 7ddd16c26d..5f97d9d181 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -3171,7 +3171,7 @@ static int __init alloc_xenstore_evtchn(struct domain *d) alloc.dom = d->domain_id; alloc.remote_dom = hardware_domain->domain_id; - rc = evtchn_alloc_unbound(&alloc); + rc = evtchn_alloc_unbound(&alloc, 0); if ( rc ) { printk("Failed allocating event channel for domain\n"); diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 8cbe9681da..80a88c1544 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -290,11 +290,15 @@ void evtchn_free(struct domain *d, struct evtchn *chn) xsm_evtchn_close_post(chn); } -int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) +/* + * If port is zero get the next free port and allocate. If port is non-zero + * allocate the specified port. + */ +int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, evtchn_port_t port) { struct evtchn *chn; struct domain *d; - int port, rc; + int rc; domid_t dom = alloc->dom; d = rcu_lock_domain_by_any_id(dom); @@ -303,8 +307,20 @@ int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) spin_lock(&d->event_lock); - if ( (port = get_free_port(d)) < 0 ) - ERROR_EXIT_DOM(port, d); + if ( port != 0 ) + { + if ( (rc = evtchn_allocate_port(d, port)) != 0 ) + ERROR_EXIT_DOM(rc, d); + } + else + { + int alloc_port = get_free_port(d); + + if ( alloc_port < 0 ) + ERROR_EXIT_DOM(alloc_port, d); + port = alloc_port; + } + chn = evtchn_from_port(d, port); rc = xsm_evtchn_unbound(XSM_TARGET, d, chn, alloc->remote_dom); @@ -1206,7 +1222,7 @@ long cf_check do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) struct evtchn_alloc_unbound alloc_unbound; if ( copy_from_guest(&alloc_unbound, arg, 1) != 0 ) return -EFAULT; - rc = evtchn_alloc_unbound(&alloc_unbound); + rc = evtchn_alloc_unbound(&alloc_unbound, 0); if ( !rc && __copy_to_guest(arg, &alloc_unbound, 1) ) rc = -EFAULT; /* Cleaning up here would be a mess! */ break; diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 61615ebbe3..48820e393e 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -72,7 +72,8 @@ void evtchn_free(struct domain *d, struct evtchn *chn); int evtchn_allocate_port(struct domain *d, unsigned int port); /* Allocate a new event channel */ -int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc); +int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, + evtchn_port_t port); /* Bind an event channel port to interdomain */ int __must_check evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind); From patchwork Wed Jun 22 14:38:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12890917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BABFFC433EF for ; Wed, 22 Jun 2022 14:39:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.353991.581015 (Exim 4.92) (envelope-from ) id 1o41Vs-0005MV-Mf; Wed, 22 Jun 2022 14:39:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 353991.581015; Wed, 22 Jun 2022 14:39:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41Vs-0005ML-Gz; Wed, 22 Jun 2022 14:39:24 +0000 Received: by outflank-mailman (input) for mailman id 353991; Wed, 22 Jun 2022 14:39:23 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41Vr-0003uL-29 for xen-devel@lists.xenproject.org; Wed, 22 Jun 2022 14:39:23 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 1acf1757-f239-11ec-bd2d-47488cf2e6aa; Wed, 22 Jun 2022 16:39:22 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 96CD0D6E; Wed, 22 Jun 2022 07:39:21 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 389E93F792; Wed, 22 Jun 2022 07:39:20 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1acf1757-f239-11ec-bd2d-47488cf2e6aa From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 3/8] xen/evtchn: modify evtchn_bind_interdomain to allocate specified port Date: Wed, 22 Jun 2022 15:38:00 +0100 Message-Id: <08fab20e71d280396d7b65397339ad9d9ab96d5c.1655903088.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 evtchn_bind_interdomain() always allocates the next available local port. Static event channel support for dom0less domains requires allocating a specified port. Modify the evtchn_bind_interdomain to accept the port number as an argument and allocate the specified port if available. If the port number argument is zero, the next available port will be allocated. Signed-off-by: Rahul Singh --- xen/common/event_channel.c | 26 +++++++++++++++++++++----- xen/include/xen/event.h | 3 ++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 80a88c1544..bf5dc2c8ad 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -363,11 +363,16 @@ static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn) evtchn_write_unlock(rchn); } -int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) +/* + * If lport is zero get the next free port and allocate. If port is non-zero + * allocate the specified lport. + */ +int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, + evtchn_port_t lport) { struct evtchn *lchn, *rchn; struct domain *ld = current->domain, *rd; - int lport, rc; + int rc; evtchn_port_t rport = bind->remote_port; domid_t rdom = bind->remote_dom; @@ -387,8 +392,19 @@ int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) spin_lock(&ld->event_lock); } - if ( (lport = get_free_port(ld)) < 0 ) - ERROR_EXIT(lport); + if ( lport != 0 ) + { + if ( (rc = evtchn_allocate_port(ld, lport)) != 0 ) + ERROR_EXIT_DOM(rc, ld); + } + else + { + int alloc_port = get_free_port(ld); + + if ( alloc_port < 0 ) + ERROR_EXIT_DOM(alloc_port, ld); + lport = alloc_port; + } lchn = evtchn_from_port(ld, lport); rchn = _evtchn_from_port(rd, rport); @@ -1232,7 +1248,7 @@ long cf_check do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) struct evtchn_bind_interdomain bind_interdomain; if ( copy_from_guest(&bind_interdomain, arg, 1) != 0 ) return -EFAULT; - rc = evtchn_bind_interdomain(&bind_interdomain); + rc = evtchn_bind_interdomain(&bind_interdomain, 0); if ( !rc && __copy_to_guest(arg, &bind_interdomain, 1) ) rc = -EFAULT; /* Cleaning up here would be a mess! */ break; diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 48820e393e..6e26879793 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -76,7 +76,8 @@ int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, evtchn_port_t port); /* Bind an event channel port to interdomain */ -int __must_check evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind); +int __must_check evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, + evtchn_port_t port); /* Unmask a local event-channel port. */ int evtchn_unmask(unsigned int port); From patchwork Wed Jun 22 14:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12890918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 46892C43334 for ; Wed, 22 Jun 2022 14:39:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.353996.581025 (Exim 4.92) (envelope-from ) id 1o41W6-0005t7-SI; Wed, 22 Jun 2022 14:39:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 353996.581025; Wed, 22 Jun 2022 14:39:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41W6-0005sy-PB; Wed, 22 Jun 2022 14:39:38 +0000 Received: by outflank-mailman (input) for mailman id 353996; Wed, 22 Jun 2022 14:39:37 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41W5-0004Nu-8j for xen-devel@lists.xenproject.org; Wed, 22 Jun 2022 14:39:37 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 22c34c83-f239-11ec-b725-ed86ccbb4733; Wed, 22 Jun 2022 16:39:35 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 05ACAD6E; Wed, 22 Jun 2022 07:39:36 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9B2E13F792; Wed, 22 Jun 2022 07:39:34 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 22c34c83-f239-11ec-b725-ed86ccbb4733 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 4/8] xen/evtchn: modify evtchn_bind_interdomain to pass domain as argument Date: Wed, 22 Jun 2022 15:38:01 +0100 Message-Id: <037b30aa5186cff516f8acf17a3a465663a8194a.1655903088.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 evtchn_bind_interdomain() finds the local domain from "current->domain" pointer. evtchn_bind_interdomain() will be called from the XEN to support static event channel during domain creation. "current" pointer is not valid at that time, therefore modify the evtchn_bind_interdomain() to pass domain as an argument. Signed-off-by: Rahul Singh --- xen/common/event_channel.c | 6 +++--- xen/include/xen/event.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index bf5dc2c8ad..84f0055a5a 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -367,11 +367,11 @@ static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn) * If lport is zero get the next free port and allocate. If port is non-zero * allocate the specified lport. */ -int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, +int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, struct domain *ld, evtchn_port_t lport) { struct evtchn *lchn, *rchn; - struct domain *ld = current->domain, *rd; + struct domain *rd; int rc; evtchn_port_t rport = bind->remote_port; domid_t rdom = bind->remote_dom; @@ -1248,7 +1248,7 @@ long cf_check do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) struct evtchn_bind_interdomain bind_interdomain; if ( copy_from_guest(&bind_interdomain, arg, 1) != 0 ) return -EFAULT; - rc = evtchn_bind_interdomain(&bind_interdomain, 0); + rc = evtchn_bind_interdomain(&bind_interdomain, current->domain, 0); if ( !rc && __copy_to_guest(arg, &bind_interdomain, 1) ) rc = -EFAULT; /* Cleaning up here would be a mess! */ break; diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 6e26879793..8eae9984a9 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -77,6 +77,7 @@ int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, /* Bind an event channel port to interdomain */ int __must_check evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, + struct domain *ld, evtchn_port_t port); /* Unmask a local event-channel port. */ From patchwork Wed Jun 22 14:38:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12890919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 450C6C433EF for ; Wed, 22 Jun 2022 14:40:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.354002.581035 (Exim 4.92) (envelope-from ) id 1o41WO-0006VI-4a; Wed, 22 Jun 2022 14:39:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 354002.581035; Wed, 22 Jun 2022 14:39:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41WO-0006VB-1r; Wed, 22 Jun 2022 14:39:56 +0000 Received: by outflank-mailman (input) for mailman id 354002; Wed, 22 Jun 2022 14:39:54 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41WM-0004Nu-OP for xen-devel@lists.xenproject.org; Wed, 22 Jun 2022 14:39:54 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 2cc5fc79-f239-11ec-b725-ed86ccbb4733; Wed, 22 Jun 2022 16:39:52 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C111ED6E; Wed, 22 Jun 2022 07:39:52 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 482D03F792; Wed, 22 Jun 2022 07:39:51 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2cc5fc79-f239-11ec-b725-ed86ccbb4733 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH 5/8] xen/evtchn: don't close the static event channel. Date: Wed, 22 Jun 2022 15:38:02 +0100 Message-Id: <91656930b5bfd49e40ff5a9d060d7643e6311f4f.1655903088.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Guest can request the Xen to close the event channels. Ignore the request from guest to close the static channels as static event channels should not be closed. Add the new bool variable "is_static" in "struct evtchn" to mark the event channel static when creating the event channel. Signed-off-by: Rahul Singh --- xen/arch/arm/domain_build.c | 2 +- xen/common/event_channel.c | 15 +++++++++++---- xen/include/xen/event.h | 4 ++-- xen/include/xen/sched.h | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 5f97d9d181..89195b042c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -3171,7 +3171,7 @@ static int __init alloc_xenstore_evtchn(struct domain *d) alloc.dom = d->domain_id; alloc.remote_dom = hardware_domain->domain_id; - rc = evtchn_alloc_unbound(&alloc, 0); + rc = evtchn_alloc_unbound(&alloc, 0, false); if ( rc ) { printk("Failed allocating event channel for domain\n"); diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 84f0055a5a..cedc98ccaf 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -294,7 +294,8 @@ void evtchn_free(struct domain *d, struct evtchn *chn) * If port is zero get the next free port and allocate. If port is non-zero * allocate the specified port. */ -int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, evtchn_port_t port) +int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, evtchn_port_t port, + bool is_static) { struct evtchn *chn; struct domain *d; @@ -330,6 +331,7 @@ int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, evtchn_port_t port) evtchn_write_lock(chn); chn->state = ECS_UNBOUND; + chn->is_static = is_static; if ( (chn->u.unbound.remote_domid = alloc->remote_dom) == DOMID_SELF ) chn->u.unbound.remote_domid = current->domain->domain_id; evtchn_port_init(d, chn); @@ -368,7 +370,7 @@ static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn) * allocate the specified lport. */ int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, struct domain *ld, - evtchn_port_t lport) + evtchn_port_t lport, bool is_static) { struct evtchn *lchn, *rchn; struct domain *rd; @@ -423,6 +425,7 @@ int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, struct domain *ld, lchn->u.interdomain.remote_dom = rd; lchn->u.interdomain.remote_port = rport; lchn->state = ECS_INTERDOMAIN; + lchn->is_static = is_static; evtchn_port_init(ld, lchn); rchn->u.interdomain.remote_dom = ld; @@ -659,6 +662,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest) rc = -EINVAL; goto out; } + /* Guest cannot close a static event channel. */ + if ( chn1->is_static && guest ) + goto out; switch ( chn1->state ) { @@ -1238,7 +1244,7 @@ long cf_check do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) struct evtchn_alloc_unbound alloc_unbound; if ( copy_from_guest(&alloc_unbound, arg, 1) != 0 ) return -EFAULT; - rc = evtchn_alloc_unbound(&alloc_unbound, 0); + rc = evtchn_alloc_unbound(&alloc_unbound, 0, false); if ( !rc && __copy_to_guest(arg, &alloc_unbound, 1) ) rc = -EFAULT; /* Cleaning up here would be a mess! */ break; @@ -1248,7 +1254,8 @@ long cf_check do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) struct evtchn_bind_interdomain bind_interdomain; if ( copy_from_guest(&bind_interdomain, arg, 1) != 0 ) return -EFAULT; - rc = evtchn_bind_interdomain(&bind_interdomain, current->domain, 0); + rc = evtchn_bind_interdomain(&bind_interdomain, current->domain, + 0, false); if ( !rc && __copy_to_guest(arg, &bind_interdomain, 1) ) rc = -EFAULT; /* Cleaning up here would be a mess! */ break; diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 8eae9984a9..71ad4c5bfd 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -73,12 +73,12 @@ int evtchn_allocate_port(struct domain *d, unsigned int port); /* Allocate a new event channel */ int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, - evtchn_port_t port); + evtchn_port_t port, bool is_static); /* Bind an event channel port to interdomain */ int __must_check evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, struct domain *ld, - evtchn_port_t port); + evtchn_port_t port, bool is_static); /* Unmask a local event-channel port. */ int evtchn_unmask(unsigned int port); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 463d41ffb6..da823c8091 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -119,6 +119,7 @@ struct evtchn unsigned char priority; /* FIFO event channels only. */ unsigned short notify_vcpu_id; /* VCPU for local delivery notification */ uint32_t fifo_lastq; /* Data for identifying last queue. */ + bool is_static; /* Static event channels. */ #ifdef CONFIG_XSM union { From patchwork Wed Jun 22 14:38:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12890931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C8B45CCA47D for ; Wed, 22 Jun 2022 14:48:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.354039.581080 (Exim 4.92) (envelope-from ) id 1o41eo-0001Mk-4M; Wed, 22 Jun 2022 14:48:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 354039.581080; Wed, 22 Jun 2022 14:48:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41en-0001Mb-WA; Wed, 22 Jun 2022 14:48:37 +0000 Received: by outflank-mailman (input) for mailman id 354039; Wed, 22 Jun 2022 14:48:36 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41WV-0003uL-0k for xen-devel@lists.xenproject.org; Wed, 22 Jun 2022 14:40:03 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 323eee82-f239-11ec-bd2d-47488cf2e6aa; Wed, 22 Jun 2022 16:40:01 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0A0F0D6E; Wed, 22 Jun 2022 07:40:01 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A02233F792; Wed, 22 Jun 2022 07:39:59 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 323eee82-f239-11ec-bd2d-47488cf2e6aa From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 6/8] xen/evtchn: don't set notification in evtchn_bind_interdomain() Date: Wed, 22 Jun 2022 15:38:03 +0100 Message-Id: <0cb096d37f2ac6cb7c5aa04cad7ad5377a0934db.1655903088.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 evtchn_bind_interdomain() sets the notification on the local port to handle the lost notification on remote unbound port. Static event-channel will be created during domain creation, there is no need to set the notification as remote domain is not alive. Signed-off-by: Rahul Singh --- xen/common/event_channel.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index cedc98ccaf..420d18b986 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -435,8 +435,13 @@ int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind, struct domain *ld, /* * We may have lost notifications on the remote unbound port. Fix that up * here by conservatively always setting a notification on the local port. + * + * There is no need to set the notification if event channel is created in + * Xen because domain is not created at this time and no chance of lost + * notification. */ - evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn); + if ( !is_static ) + evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn); double_evtchn_unlock(lchn, rchn); From patchwork Wed Jun 22 14:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12890930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A49F5C43334 for ; Wed, 22 Jun 2022 14:48:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.354040.581085 (Exim 4.92) (envelope-from ) id 1o41eo-0001Q8-Eo; Wed, 22 Jun 2022 14:48:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 354040.581085; Wed, 22 Jun 2022 14:48:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41eo-0001PI-8i; Wed, 22 Jun 2022 14:48:38 +0000 Received: by outflank-mailman (input) for mailman id 354040; Wed, 22 Jun 2022 14:48:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41Wh-0004Nu-UO for xen-devel@lists.xenproject.org; Wed, 22 Jun 2022 14:40:16 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 398cbf7a-f239-11ec-b725-ed86ccbb4733; Wed, 22 Jun 2022 16:40:13 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5A1F41477; Wed, 22 Jun 2022 07:40:14 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 302303F792; Wed, 22 Jun 2022 07:40:13 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 398cbf7a-f239-11ec-b725-ed86ccbb4733 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH 7/8] xen: introduce xen-evtchn dom0less property Date: Wed, 22 Jun 2022 15:38:04 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Introduce a new sub-node under /chosen node to establish static event channel communication between domains on dom0less systems. An event channel will be created beforehand to allow the domains to send notifications to each other. Signed-off-by: Rahul Singh --- docs/misc/arm/device-tree/booting.txt | 62 +++++++++++- xen/arch/arm/domain_build.c | 139 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/domain.h | 1 + xen/arch/arm/include/asm/setup.h | 1 + xen/arch/arm/setup.c | 2 + 5 files changed, 204 insertions(+), 1 deletion(-) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-tree/booting.txt index 98253414b8..83e914b505 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -212,7 +212,7 @@ with the following properties: enable only selected interfaces. Under the "xen,domain" compatible node, one or more sub-nodes are present -for the DomU kernel and ramdisk. +for the DomU kernel, ramdisk and static event channel. The kernel sub-node has the following properties: @@ -254,11 +254,42 @@ The ramdisk sub-node has the following properties: property because it will be created by the UEFI stub on boot. This option is needed only when UEFI boot is used. +The static event channel sub-node has the following properties: + +- compatible + + "xen,evtchn" + +- xen,evtchn + + The property is tuples of two numbers + (local-evtchn link-to-foreign-evtchn) where: + + local-evtchn is an integer value that will be used to allocate local port + for a domain to send and receive event notifications to/from the remote + domain. Maximum supported value is 2^17 for FIFO ABI and 4096 for 2L ABI. + + link-to-foreign-evtchn is a single phandle to a remote evtchn to which + local-evtchn will be connected. Example ======= chosen { + + module@0 { + compatible = "multiboot,kernel", "multiboot,module"; + xen,uefi-binary = "..."; + bootargs = "..."; + + /* one sub-node per local event channel */ + ec1: evtchn@1 { + compatible = "xen,evtchn-v1"; + /* local-evtchn link-to-foreign-evtchn */ + xen,evtchn = <0xa &ec2>; + }; + }; + domU1 { compatible = "xen,domain"; #address-cells = <0x2>; @@ -277,6 +308,23 @@ chosen { compatible = "multiboot,ramdisk", "multiboot,module"; reg = <0x0 0x4b000000 0xffffff>; }; + + /* one sub-node per local event channel */ + ec2: evtchn@2 { + compatible = "xen,evtchn-v1"; + /* local-evtchn link-to-foreign-evtchn */ + xen,evtchn = <0xa &ec1>; + }; + + ec3: evtchn@3 { + compatible = "xen,evtchn-v1"; + xen,evtchn = <0xb &ec5>; + }; + + ec4: evtchn@4 { + compatible = "xen,evtchn-v1"; + xen,evtchn = <0xc &ec6>; + }; }; domU2 { @@ -296,6 +344,18 @@ chosen { compatible = "multiboot,ramdisk", "multiboot,module"; reg = <0x0 0x4d000000 0xffffff>; }; + + /* one sub-node per local event channel */ + ec5: evtchn@5 { + compatible = "xen,evtchn-v1"; + /* local-evtchn link-to-foreign-evtchn */ + xen,evtchn = <0xb &ec3>; + }; + + ec6: evtchn@6 { + compatible = "xen,evtchn-v1"; + xen,evtchn = <0xd &ec4>; + }; }; }; diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 89195b042c..8925f0d80c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -3052,6 +3052,144 @@ void __init evtchn_allocate(struct domain *d) d->arch.hvm.params[HVM_PARAM_CALLBACK_IRQ] = val; } +static int __init allocate_domain_evtchn(const struct dt_device_node *node) +{ + const void *prop = NULL; + const __be32 *cell; + uint32_t len, domU1_port, domU2_port, remote_phandle; + const struct dt_device_node *evtchn_node, *remote_node; + struct evtchn_alloc_unbound alloc_unbound; + struct evtchn_bind_interdomain bind_interdomain; + int rc; + + dt_for_each_child_node(node, evtchn_node) + { + struct domain *d, *d1 = NULL, *d2 = NULL; + + if ( !dt_device_is_compatible(evtchn_node, "xen,evtchn-v1") ) + continue; + + prop = dt_get_property(evtchn_node, "xen,evtchn", &len); + /* If the property is not found, return without errors */ + if ( !prop ) + return 0; + + if ( !len ) + { + printk(XENLOG_ERR "xen,evtchn property cannot be empty.\n"); + return -EINVAL; + } + + cell = (const __be32 *)prop; + domU1_port = dt_next_cell(1, &cell); + remote_phandle = dt_next_cell(1, &cell); + + remote_node = dt_find_node_by_phandle(remote_phandle); + if ( !remote_node ) + { + printk(XENLOG_ERR + "evtchn: could not find remote evtchn phandle\n"); + return -EINVAL; + } + + prop = dt_get_property(remote_node, "xen,evtchn", &len); + /* If the property is not found, return without errors */ + if ( !prop ) + return 0; + + if ( !len ) + { + printk(XENLOG_ERR "xen,evtchn property cannot be empty.\n"); + return -EINVAL; + } + + cell = (const __be32 *)prop; + domU2_port = dt_next_cell(1, &cell); + remote_phandle = dt_next_cell(1, &cell); + + if ( evtchn_node->phandle != remote_phandle ) + { + printk(XENLOG_ERR "xen,evtchn property is not setup correctly.\n"); + return -EINVAL; + } + + for_each_domain ( d ) + { + if ( d->arch.node == node ) + { + d1 = d; + continue; + } + if ( d->arch.node == dt_get_parent(remote_node) ) + d2 = d; + } + + if ( d1 == NULL ) + { + if ( dt_device_is_compatible(node, "multiboot,kernel") ) + d1 = hardware_domain; + else + { + printk(XENLOG_ERR "evtchn: could not find domain\n" ); + return -EINVAL; + } + } + + if ( d2 == NULL ) + { + if ( dt_device_is_compatible(dt_get_parent(remote_node), + "multiboot,kernel") ) + d2 = hardware_domain; + else + { + printk(XENLOG_ERR "evtchn: could not find domain\n" ); + return -EINVAL; + } + } + + alloc_unbound.dom = d1->domain_id; + alloc_unbound.remote_dom = d2->domain_id; + + rc = evtchn_alloc_unbound(&alloc_unbound, domU1_port, true); + if ( rc < 0 && rc != -EBUSY ) + { + printk(XENLOG_ERR + "evtchn_alloc_unbound() failure (Error %d) \n", rc); + return rc; + } + + bind_interdomain.remote_dom = d1->domain_id; + bind_interdomain.remote_port = domU1_port; + + rc = evtchn_bind_interdomain(&bind_interdomain, d2, domU2_port, true); + if ( rc < 0 && rc != -EBUSY ) + { + printk(XENLOG_ERR + "evtchn_bind_interdomain() failure (Error %d) \n", rc); + return rc; + } + } + + return 0; +} + +void __init allocate_static_evtchn(void) +{ + struct dt_device_node *node; + const struct dt_device_node *chosen = dt_find_node_by_path("/chosen"); + + BUG_ON(chosen == NULL); + dt_for_each_child_node(chosen, node) + { + if ( dt_device_is_compatible(node, "xen,domain") || + dt_device_is_compatible(node, "multiboot,kernel") ) + { + if ( allocate_domain_evtchn(node) != 0 ) + panic("Could not set up domains evtchn\n"); + } + } +} + static void __init find_gnttab_region(struct domain *d, struct kernel_info *kinfo) { @@ -3358,6 +3496,7 @@ void __init create_domUs(void) panic("Error creating domain %s\n", dt_node_name(node)); d->is_console = true; + d->arch.node = node; if ( construct_domU(d, node) != 0 ) panic("Could not set up domain %s\n", dt_node_name(node)); diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index ed63c2b6f9..7c22cbabcc 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -104,6 +104,7 @@ struct arch_domain #endif bool directmap; + struct dt_device_node *node; } __cacheline_aligned; struct arch_vcpu diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 2bb01ecfa8..bac876e68e 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -106,6 +106,7 @@ int acpi_make_efi_nodes(void *fdt, struct membank tbl_add[]); void create_domUs(void); void create_dom0(void); +void allocate_static_evtchn(void); void discard_initial_modules(void); void fw_unreserved_regions(paddr_t s, paddr_t e, diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 05d97a1cfb..0936db58b2 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1046,6 +1046,8 @@ void __init start_xen(unsigned long boot_phys_offset, if ( acpi_disabled ) create_domUs(); + allocate_static_evtchn(); + /* * This needs to be called **before** heap_init_late() so modules * will be scrubbed (unless suppressed). From patchwork Wed Jun 22 14:38:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12890929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8FB76C43334 for ; Wed, 22 Jun 2022 14:48:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.354034.581069 (Exim 4.92) (envelope-from ) id 1o41eh-00012G-Mr; Wed, 22 Jun 2022 14:48:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 354034.581069; Wed, 22 Jun 2022 14:48:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41eh-000129-IP; Wed, 22 Jun 2022 14:48:31 +0000 Received: by outflank-mailman (input) for mailman id 354034; Wed, 22 Jun 2022 14:48:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o41X5-0004Nu-3S for xen-devel@lists.xenproject.org; Wed, 22 Jun 2022 14:40:39 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 476aff44-f239-11ec-b725-ed86ccbb4733; Wed, 22 Jun 2022 16:40:36 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 85593D6E; Wed, 22 Jun 2022 07:40:37 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7739C3F792; Wed, 22 Jun 2022 07:40:36 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 476aff44-f239-11ec-b725-ed86ccbb4733 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH 8/8] xen/arm: introduce new xen,enhanced property value Date: Wed, 22 Jun 2022 15:38:05 +0100 Message-Id: <67a86c52dfdcd5dd1f56ac3442089012aba09ff6.1655903088.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Introduce a new "xen,enhanced" dom0less property value "evtchn" to enable/disable event-channel interfaces for dom0less guests. The configurable option is for domUs only. For dom0 we always set the corresponding property in the Xen code to true. Signed-off-by: Rahul Singh --- xen/arch/arm/domain_build.c | 149 ++++++++++++++++-------------- xen/arch/arm/include/asm/kernel.h | 3 + 2 files changed, 82 insertions(+), 70 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 8925f0d80c..a1c1ab5877 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1396,85 +1396,92 @@ static int __init make_hypervisor_node(struct domain *d, if ( res ) return res; - if ( !opt_ext_regions ) - { - printk(XENLOG_INFO "%pd: extended regions support is disabled\n", d); - nr_ext_regions = 0; - } - else if ( is_32bit_domain(d) ) - { - printk(XENLOG_WARNING - "%pd: extended regions not supported for 32-bit guests\n", d); - nr_ext_regions = 0; - } - else + if ( kinfo->dom0less_enhanced ) { - ext_regions = xzalloc(struct meminfo); - if ( !ext_regions ) - return -ENOMEM; - - if ( is_domain_direct_mapped(d) ) + if ( !opt_ext_regions ) { - if ( !is_iommu_enabled(d) ) - res = find_unallocated_memory(kinfo, ext_regions); - else - res = find_memory_holes(kinfo, ext_regions); + printk(XENLOG_INFO + "%pd: extended regions support is disabled\n", d); + nr_ext_regions = 0; } - else + else if ( is_32bit_domain(d) ) { - res = find_domU_holes(kinfo, ext_regions); + printk(XENLOG_WARNING + "%pd: extended regions not supported for 32-bit guests\n", d); + nr_ext_regions = 0; } + else + { + ext_regions = xzalloc(struct meminfo); + if ( !ext_regions ) + return -ENOMEM; - if ( res ) - printk(XENLOG_WARNING "%pd: failed to allocate extended regions\n", - d); - nr_ext_regions = ext_regions->nr_banks; - } + if ( is_domain_direct_mapped(d) ) + { + if ( !is_iommu_enabled(d) ) + res = find_unallocated_memory(kinfo, ext_regions); + else + res = find_memory_holes(kinfo, ext_regions); + } + else + { + res = find_domU_holes(kinfo, ext_regions); + } - reg = xzalloc_array(__be32, (nr_ext_regions + 1) * (addrcells + sizecells)); - if ( !reg ) - { - xfree(ext_regions); - return -ENOMEM; - } + if ( res ) + printk(XENLOG_WARNING + "%pd: failed to allocate extended regions\n", d); + nr_ext_regions = ext_regions->nr_banks; + } - /* reg 0 is grant table space */ - cells = ®[0]; - dt_child_set_range(&cells, addrcells, sizecells, - kinfo->gnttab_start, kinfo->gnttab_size); - /* reg 1...N are extended regions */ - for ( i = 0; i < nr_ext_regions; i++ ) - { - u64 start = ext_regions->bank[i].start; - u64 size = ext_regions->bank[i].size; + reg = xzalloc_array(__be32, (nr_ext_regions + 1) * (addrcells + sizecells)); + if ( !reg ) + { + xfree(ext_regions); + return -ENOMEM; + } - printk("%pd: extended region %d: %#"PRIx64"->%#"PRIx64"\n", - d, i, start, start + size); + /* reg 0 is grant table space */ + cells = ®[0]; + dt_child_set_range(&cells, addrcells, sizecells, + kinfo->gnttab_start, kinfo->gnttab_size); + /* reg 1...N are extended regions */ + for ( i = 0; i < nr_ext_regions; i++ ) + { + u64 start = ext_regions->bank[i].start; + u64 size = ext_regions->bank[i].size; - dt_child_set_range(&cells, addrcells, sizecells, start, size); - } + printk("%pd: extended region %d: %#"PRIx64"->%#"PRIx64"\n", + d, i, start, start + size); - res = fdt_property(fdt, "reg", reg, - dt_cells_to_size(addrcells + sizecells) * - (nr_ext_regions + 1)); - xfree(ext_regions); - xfree(reg); + dt_child_set_range(&cells, addrcells, sizecells, start, size); + } - if ( res ) - return res; + res = fdt_property(fdt, "reg", reg, + dt_cells_to_size(addrcells + sizecells) * + (nr_ext_regions + 1)); + xfree(ext_regions); + xfree(reg); - BUG_ON(d->arch.evtchn_irq == 0); + if ( res ) + return res; + } - /* - * Interrupt event channel upcall: - * - Active-low level-sensitive - * - All CPUs - * TODO: Handle properly the cpumask; - */ - set_interrupt(intr, d->arch.evtchn_irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW); - res = fdt_property_interrupts(kinfo, &intr, 1); - if ( res ) - return res; + if ( kinfo->dom0less_evtchn ) + { + BUG_ON(d->arch.evtchn_irq == 0); + + /* + * Interrupt event channel upcall: + * - Active-low level-sensitive + * - All CPUs + * TODO: Handle properly the cpumask; + */ + set_interrupt(intr, d->arch.evtchn_irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW); + res = fdt_property_interrupts(kinfo, &intr, 1); + if ( res ) + return res; + } res = fdt_end_node(fdt); @@ -2891,7 +2898,7 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) goto err; } - if ( kinfo->dom0less_enhanced ) + if ( kinfo->dom0less_enhanced || kinfo->dom0less_evtchn ) { ret = make_hypervisor_node(d, kinfo, addrcells, sizecells); if ( ret ) @@ -3346,11 +3353,11 @@ static int __init construct_domU(struct domain *d, rc == -ENODATA || (rc == 0 && !strcmp(dom0less_enhanced, "enabled")) ) { - if ( hardware_domain ) - kinfo.dom0less_enhanced = true; - else - panic("Tried to use xen,enhanced without dom0\n"); + kinfo.dom0less_enhanced = true; + kinfo.dom0less_evtchn = true; } + else if ( rc == 0 && !strcmp(dom0less_enhanced, "evtchn") ) + kinfo.dom0less_evtchn = true; if ( vcpu_create(d, 0) == NULL ) return -ENOMEM; @@ -3529,6 +3536,8 @@ static int __init construct_dom0(struct domain *d) kinfo.unassigned_mem = dom0_mem; kinfo.d = d; + kinfo.dom0less_enhanced = true; + kinfo.dom0less_evtchn = true; rc = kernel_probe(&kinfo, NULL); if ( rc < 0 ) diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/kernel.h index c4dc039b54..7cff19b997 100644 --- a/xen/arch/arm/include/asm/kernel.h +++ b/xen/arch/arm/include/asm/kernel.h @@ -39,6 +39,9 @@ struct kernel_info { /* Enable PV drivers */ bool dom0less_enhanced; + /* Enable event-channel interface */ + bool dom0less_evtchn; + /* GIC phandle */ uint32_t phandle_gic;