From patchwork Wed Sep 7 16:27:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Singh X-Patchwork-Id: 12969230 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 3F00FC54EE9 for ; Wed, 7 Sep 2022 16:29:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.402041.644028 (Exim 4.92) (envelope-from ) id 1oVxvX-0007UV-BL; Wed, 07 Sep 2022 16:29:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 402041.644028; Wed, 07 Sep 2022 16:29:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oVxvX-0007UO-7E; Wed, 07 Sep 2022 16:29:23 +0000 Received: by outflank-mailman (input) for mailman id 402041; Wed, 07 Sep 2022 16:29:21 +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 1oVxvV-000682-QW for xen-devel@lists.xenproject.org; Wed, 07 Sep 2022 16:29:21 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 39d1e955-2eca-11ed-a016-b9edf5238543; Wed, 07 Sep 2022 18:29:20 +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 99B98106F; Wed, 7 Sep 2022 09:29:26 -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 1FDA63F71A; Wed, 7 Sep 2022 09:29:19 -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: 39d1e955-2eca-11ed-a016-b9edf5238543 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: Stanislav Kinsburskii , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Julien Grall Subject: [PATCH v5 2/7] xen/evtchn: Add an helper to reserve/allocate a port Date: Wed, 7 Sep 2022 17:27:33 +0100 Message-Id: <11ffc2554cc30c0764b8645905983772417e5d70.1662563170.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 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 v5: - no changes 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); } +static int evtchn_get_port(struct domain *d, evtchn_port_t port) +{ + int rc; + + if ( port != 0 ) + rc = evtchn_allocate_port(d, port); + else + rc = 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); - if ( port != 0 ) - { - if ( (rc = evtchn_allocate_port(d, port)) != 0 ) - ERROR_EXIT(rc); - } - else - { - int alloc_port = get_free_port(d); - - if ( alloc_port < 0 ) - ERROR_EXIT(alloc_port); - port = alloc_port; - } + port = rc = evtchn_get_port(d, port); + if ( rc < 0 ) + ERROR_EXIT(rc); + rc = 0; chn = evtchn_from_port(d, port);