From nobody Mon Feb 9 07:42:46 2026 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; 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=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1662471715969556.839591137435; Tue, 6 Sep 2022 06:41:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.399873.641250 (Exim 4.92) (envelope-from ) id 1oVYpb-0005BR-9B; Tue, 06 Sep 2022 13:41:35 +0000 Received: by outflank-mailman (output) from mailman id 399873.641250; Tue, 06 Sep 2022 13:41:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oVYpb-0005BK-4b; Tue, 06 Sep 2022 13:41:35 +0000 Received: by outflank-mailman (input) for mailman id 399873; Tue, 06 Sep 2022 13:41:34 +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 1oVYpa-0005BE-Lm for xen-devel@lists.xenproject.org; Tue, 06 Sep 2022 13:41:34 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 9ea8b979-2de9-11ed-a016-b9edf5238543; Tue, 06 Sep 2022 15:41:33 +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 068B61A32; Tue, 6 Sep 2022 06:41:39 -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 68E1C3F7B4; Tue, 6 Sep 2022 06:41:31 -0700 (PDT) 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: 9ea8b979-2de9-11ed-a016-b9edf5238543 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: rahul.singh@arm.com, Stanislav Kinsburskii , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Julien Grall Subject: [PATCH v4 2/7] xen/evtchn: Add an helper to reserve/allocate a port Date: Tue, 6 Sep 2022 14:40:40 +0100 Message-Id: <30832afe5dfe3a1b350c26e40a5c5fbcb93b8c57.1662462034.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1662471717183100001 Content-Type: text/plain; charset="utf-8" From: Stanislav Kinsburskii In a follow-up patch we will want to either reserve or allocate a port for various event channel helpers. A new wrapper is introduced to either reserve a given port or allocate a fresh one if zero. Take the opportunity to replace the open-coded version in evtchn_bind_virq(). Signed-off-by: Stanislav Kinsburskii Signed-off-by: Julien Grall Signed-off-by: Rahul Singh Acked-by: Jan Beulich --- Changes in v4: - Change the Author to Stanislav Kinsburskii Changes in v3: - minor comments in commit msg Changes in v2: - new patch in this version --- xen/common/event_channel.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index f81c229358..565ab71881 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -305,6 +305,18 @@ void evtchn_free(struct domain *d, struct evtchn *chn) xsm_evtchn_close_post(chn); } =20 +static int evtchn_get_port(struct domain *d, evtchn_port_t port) +{ + int rc; + + if ( port !=3D 0 ) + rc =3D evtchn_allocate_port(d, port); + else + rc =3D get_free_port(d); + + return rc ?: port; +} + int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) { struct evtchn *chn; @@ -462,19 +474,10 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn= _port_t port) if ( read_atomic(&v->virq_to_evtchn[virq]) ) ERROR_EXIT(-EEXIST); =20 - if ( port !=3D 0 ) - { - if ( (rc =3D evtchn_allocate_port(d, port)) !=3D 0 ) - ERROR_EXIT(rc); - } - else - { - int alloc_port =3D get_free_port(d); - - if ( alloc_port < 0 ) - ERROR_EXIT(alloc_port); - port =3D alloc_port; - } + port =3D rc =3D evtchn_get_port(d, port); + if ( rc < 0 ) + ERROR_EXIT(rc); + rc =3D 0; =20 chn =3D evtchn_from_port(d, port); =20 --=20 2.25.1