From nobody Fri Nov 29 12:35:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1641602991; cv=none; d=zohomail.com; s=zohoarc; b=VCdJD14n2y748xK5cPBh7AKzW7telqX/zj4hHtTy2PHiYwq3wqayxagMe+Zx1elV7umKchEpI67S0Rhx41o4DSclT6S2IPku2pS+4Qoqhwoer8+yFIdDkc7F+IPSoAB/BEU1V1pNUylC4sEliHcXIogJfIoHqlZR14irx4Boj14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641602991; h=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=Cg/0KuHvaF5Txa0aRyRfstZ6qiHJ95oho/J5LeSFfvk=; b=Y7rG5v7FLKlSomPIW3illPLcMnUAlk2Df8yVJxabVqo9QhP2aQ3/eKWy0ppU3PHaI1AfNLuRT5D0hCIwwTExqRb3ddTBXU3haP4oYjjFpq2459lSelFc0hfGAw1BNEcpOxuw9cJ46e9X5VDIBXyT7Xx+HrdgD/r93X9M1W7hVzo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641602991328937.7307445037915; Fri, 7 Jan 2022 16:49:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.254714.436535 (Exim 4.92) (envelope-from ) id 1n5zv8-0007SO-AW; Sat, 08 Jan 2022 00:49:22 +0000 Received: by outflank-mailman (output) from mailman id 254714.436535; Sat, 08 Jan 2022 00:49:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv7-0007Nl-UE; Sat, 08 Jan 2022 00:49:21 +0000 Received: by outflank-mailman (input) for mailman id 254714; Sat, 08 Jan 2022 00:49:20 +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 1n5zv6-000706-1v for xen-devel@lists.xenproject.org; Sat, 08 Jan 2022 00:49:20 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ce8f032a-701c-11ec-81c1-a30af7de8005; Sat, 08 Jan 2022 01:49:17 +0100 (CET) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3C23DB827C0; Sat, 8 Jan 2022 00:49:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82219C36AEF; Sat, 8 Jan 2022 00:49:14 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: ce8f032a-701c-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641602955; bh=5gqnkAJOfXnqVGXZ1qlNwhP+taPqzRbwoAe4Pxn2FBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OyHNvkvda/IppfmN5ffOApPiggGKdA6fHkKcxGtbEGfmCurNqL9cCKuEdWr40fJDA 4oC9SKxj8Ik2xh0JVoU3jItm0cwkfAtmPxE94JyN5/hR0INnezaoHoSj44UoDiCxBa ilacuOy5whBIAbd1PbBP6MByN/c+Bvg92LcxBKpwsYxfDoHmi8TUgrKar2wKndw+Mm eaI2MT5baBcnxq/rxkOJhS60EZMOs1kK4sHnwdWzOZ6CQw+HXjnXmAYfwYPTQle30n bU8I4dUnMqpKdqLfhIckxGT4nfCCw6HZTiZK0TomvlNBzq7MgsZjCG1nLLFIU1oZNa wxR6k7hYry/Vw== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, Bertrand.Marquis@arm.com, Luca Miccio , Stefano Stabellini , Volodymyr Babchuk , Bertrand Marquis , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [XEN PATCH 2/7] xen: introduce _evtchn_alloc_unbound Date: Fri, 7 Jan 2022 16:49:07 -0800 Message-Id: <20220108004912.3820176-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1641602993133100003 Content-Type: text/plain; charset="utf-8" From: Luca Miccio The xenstore event channel will be allocated for dom0less domains. It is necessary to have access to the evtchn_alloc_unbound function to do that. Factor out the part that actually allocates the event channel from evtchn_alloc_unbound and introduce this new function as _evtchn_alloc_unbound. (xsm_evtchn_unbound wouldn't work for a call originated from Xen.) Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Andrew Cooper CC: George Dunlap CC: Jan Beulich CC: Wei Liu --- xen/common/event_channel.c | 49 +++++++++++++++++++++++++------------- xen/include/xen/event.h | 3 +++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index da88ad141a..8a19bbf7ae 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -18,6 +18,7 @@ =20 #include #include +#include #include #include #include @@ -284,11 +285,32 @@ void evtchn_free(struct domain *d, struct evtchn *chn) xsm_evtchn_close_post(chn); } =20 -static int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) +struct evtchn *_evtchn_alloc_unbound(struct domain *d, domid_t remote_dom) { struct evtchn *chn; + int port; + + if ( (port =3D get_free_port(d)) < 0 ) + return ERR_PTR(port); + chn =3D evtchn_from_port(d, port); + + evtchn_write_lock(chn); + + chn->state =3D ECS_UNBOUND; + if ( (chn->u.unbound.remote_domid =3D remote_dom) =3D=3D DOMID_SELF ) + chn->u.unbound.remote_domid =3D current->domain->domain_id; + evtchn_port_init(d, chn); + + evtchn_write_unlock(chn); + + return chn; +} + +static int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) +{ + struct evtchn *chn =3D NULL; struct domain *d; - int port, rc; + int rc; domid_t dom =3D alloc->dom; =20 d =3D rcu_lock_domain_by_any_id(dom); @@ -297,27 +319,22 @@ static int evtchn_alloc_unbound(evtchn_alloc_unbound_= t *alloc) =20 spin_lock(&d->event_lock); =20 - if ( (port =3D get_free_port(d)) < 0 ) - ERROR_EXIT_DOM(port, d); - chn =3D evtchn_from_port(d, port); + chn =3D _evtchn_alloc_unbound(d, alloc->remote_dom); + if ( IS_ERR(chn) ) + { + rc =3D PTR_ERR(chn); + ERROR_EXIT_DOM(rc, d); + } =20 rc =3D xsm_evtchn_unbound(XSM_TARGET, d, chn, alloc->remote_dom); if ( rc ) goto out; =20 - evtchn_write_lock(chn); - - chn->state =3D ECS_UNBOUND; - if ( (chn->u.unbound.remote_domid =3D alloc->remote_dom) =3D=3D DOMID_= SELF ) - chn->u.unbound.remote_domid =3D current->domain->domain_id; - evtchn_port_init(d, chn); - - evtchn_write_unlock(chn); - - alloc->port =3D port; + alloc->port =3D chn->port; =20 out: - check_free_port(d, port); + if ( chn !=3D NULL ) + check_free_port(d, chn->port); spin_unlock(&d->event_lock); rcu_unlock_domain(d); =20 diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 21c95e14fd..6aedbccbf1 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -68,6 +68,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest= ); /* Free an event channel. */ void evtchn_free(struct domain *d, struct evtchn *chn); =20 +/* Create a new event channel port */ +struct evtchn *_evtchn_alloc_unbound(struct domain *d, domid_t remote_dom); + /* Allocate a specific event channel port. */ int evtchn_allocate_port(struct domain *d, unsigned int port); =20 --=20 2.25.1