Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20976421rwd; Thu, 29 Jun 2023 09:16:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlE4CWn3dA1Vsw1ZqvOhDYV4LDwlIPjlrtsQX+Z4XyQ/pCzelUFwlJElb8usG5pz2Zzvwwbd X-Received: by 2002:a62:7b42:0:b0:67e:bf65:ae68 with SMTP id w63-20020a627b42000000b0067ebf65ae68mr442001pfc.3.1688055416779; Thu, 29 Jun 2023 09:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688055416; cv=none; d=google.com; s=arc-20160816; b=PI1tCPpS3prTaiJ216XInHjrDRRUjzEo9q4dk0rBFdk5pjErUIwANx1Rv2Cj6tfmNu h/RSG9M+ctANpVCxx+Cw8jB3bFdmZDTXL6BsnpLl6oW1gIoLJdq5yP0ePThXygbMVv8R +Y466SY0YAalkAff6rkRCnTlwEt6XzBk/V3N+bzGlSZI4B30JAHByQb+OqFqLMBbdZAf Es72WsbXc5Rr6kJDtClE4WrAGgRMsgx0G+JVawUdqzjZpChO34/Y3gnJ1h1kZeYxROlz QKEjglWzfs6TVERCkn2BaxF/2cC479FARMUGd3v4Rlinxc3d+3EvBhlG8HURCLbxNuDK RkwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3Z3zds3w9hnn1aKA+gIsfyCkarSbCV9k9F4EHWrb6Jc=; fh=9CODZcCcuayZVwB+fdCmfBVKz2+hrXabBJhoJhqrCbs=; b=RCV5xCUwe/5XLkluiLG4rSb/ong8bp9JO3nGMy0KHMbPLixiwBSQEciTeZJPYvKduu 4k4lP6SjZ3Xd7Z47B7l/2oA5nGaq3YJ23png555ecaj6010n8yjPU0tdaqRSSC1SgX3k dbQET8f+nMP4nss/9AXw6DjU2gPX9r87IyHB55xDufHn9tiiTw4dTg1aVfBhIXLwxm3z gvxwFpSR85suhQJ0sEHj6V7yptaSOPYloZpHyZnRuRdLP7S+08K/gRMiuXMbJkDoIZFv steuHyZCvc2q9PCcQk6g+wca+pXFD5E1DvkllWu1mNrdCi0vIkBnZid5FCkNftXAgXOe g3xg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k6-20020a6568c6000000b0055b12580c3esi4152234pgt.449.2023.06.29.09.16.32; Thu, 29 Jun 2023 09:16:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232088AbjF2Pqn (ORCPT + 99 others); Thu, 29 Jun 2023 11:46:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjF2Pql (ORCPT ); Thu, 29 Jun 2023 11:46:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E68062D4E for ; Thu, 29 Jun 2023 08:46:39 -0700 (PDT) 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 6866DC14; Thu, 29 Jun 2023 08:47:23 -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 769FB3F64C; Thu, 29 Jun 2023 08:46:38 -0700 (PDT) From: Rahul Singh To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: rahul.singh@arm.com, Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Samuel Holland , David Woodhouse , Jane Malalane Subject: [PATCH v2] xen/evtchn: Introduce new IOCTL to bind static evtchn Date: Thu, 29 Jun 2023 16:46:18 +0100 Message-Id: <764d561e3aecb7e63e8601dc50aaef9fc40834e4.1688051342.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Xen 4.17 supports the creation of static evtchns. To allow user space application to bind static evtchns introduce new ioctl "IOCTL_EVTCHN_BIND_STATIC". Existing IOCTL doing more than binding that’s why we need to introduce the new IOCTL to only bind the static event channels. Also, static evtchns to be available for use during the lifetime of the guest. When the application exits, __unbind_from_irq() ends up being called from release() file operations because of that static evtchns are getting closed. To avoid closing the static event channel, add the new bool variable "is_static" in "struct irq_info" to mark the event channel static when creating the event channel to avoid closing the static evtchn. Signed-off-by: Rahul Singh --- v2: * Use bool in place u8 to define is_static variable. * Avoid closing the static evtchns in error path. --- drivers/xen/events/events_base.c | 7 +++++-- drivers/xen/evtchn.c | 30 ++++++++++++++++++++++-------- include/uapi/xen/evtchn.h | 9 +++++++++ include/xen/events.h | 2 +- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c index c7715f8bd452..5d3b5c7cfe64 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -112,6 +112,7 @@ struct irq_info { unsigned int irq_epoch; /* If eoi_cpu valid: irq_epoch of event */ u64 eoi_time; /* Time in jiffies when to EOI. */ raw_spinlock_t lock; + bool is_static; /* Is event channel static */ union { unsigned short virq; @@ -982,7 +983,8 @@ static void __unbind_from_irq(unsigned int irq) unsigned int cpu = cpu_from_irq(irq); struct xenbus_device *dev; - xen_evtchn_close(evtchn); + if (!info->is_static) + xen_evtchn_close(evtchn); switch (type_from_irq(irq)) { case IRQT_VIRQ: @@ -1574,7 +1576,7 @@ int xen_set_irq_priority(unsigned irq, unsigned priority) } EXPORT_SYMBOL_GPL(xen_set_irq_priority); -int evtchn_make_refcounted(evtchn_port_t evtchn) +int evtchn_make_refcounted(evtchn_port_t evtchn, bool is_static) { int irq = get_evtchn_to_irq(evtchn); struct irq_info *info; @@ -1590,6 +1592,7 @@ int evtchn_make_refcounted(evtchn_port_t evtchn) WARN_ON(info->refcnt != -1); info->refcnt = 1; + info->is_static = is_static; return 0; } diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c index c99415a70051..e6d2303478b2 100644 --- a/drivers/xen/evtchn.c +++ b/drivers/xen/evtchn.c @@ -366,7 +366,8 @@ static int evtchn_resize_ring(struct per_user_data *u) return 0; } -static int evtchn_bind_to_user(struct per_user_data *u, evtchn_port_t port) +static int evtchn_bind_to_user(struct per_user_data *u, evtchn_port_t port, + bool is_static) { struct user_evtchn *evtchn; struct evtchn_close close; @@ -402,14 +403,16 @@ static int evtchn_bind_to_user(struct per_user_data *u, evtchn_port_t port) if (rc < 0) goto err; - rc = evtchn_make_refcounted(port); + rc = evtchn_make_refcounted(port, is_static); return rc; err: /* bind failed, should close the port now */ - close.port = port; - if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0) - BUG(); + if (!is_static) { + close.port = port; + if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0) + BUG(); + } del_evtchn(u, evtchn); return rc; } @@ -456,7 +459,7 @@ static long evtchn_ioctl(struct file *file, if (rc != 0) break; - rc = evtchn_bind_to_user(u, bind_virq.port); + rc = evtchn_bind_to_user(u, bind_virq.port, false); if (rc == 0) rc = bind_virq.port; break; @@ -482,7 +485,7 @@ static long evtchn_ioctl(struct file *file, if (rc != 0) break; - rc = evtchn_bind_to_user(u, bind_interdomain.local_port); + rc = evtchn_bind_to_user(u, bind_interdomain.local_port, false); if (rc == 0) rc = bind_interdomain.local_port; break; @@ -507,7 +510,7 @@ static long evtchn_ioctl(struct file *file, if (rc != 0) break; - rc = evtchn_bind_to_user(u, alloc_unbound.port); + rc = evtchn_bind_to_user(u, alloc_unbound.port, false); if (rc == 0) rc = alloc_unbound.port; break; @@ -536,6 +539,17 @@ static long evtchn_ioctl(struct file *file, break; } + case IOCTL_EVTCHN_BIND_STATIC: { + struct ioctl_evtchn_bind bind; + + rc = -EFAULT; + if (copy_from_user(&bind, uarg, sizeof(bind))) + break; + + rc = evtchn_bind_to_user(u, bind.port, true); + break; + } + case IOCTL_EVTCHN_NOTIFY: { struct ioctl_evtchn_notify notify; struct user_evtchn *evtchn; diff --git a/include/uapi/xen/evtchn.h b/include/uapi/xen/evtchn.h index 7fbf732f168f..aef2b75f3413 100644 --- a/include/uapi/xen/evtchn.h +++ b/include/uapi/xen/evtchn.h @@ -101,4 +101,13 @@ struct ioctl_evtchn_restrict_domid { domid_t domid; }; +/* + * Bind statically allocated @port. + */ +#define IOCTL_EVTCHN_BIND_STATIC \ + _IOC(_IOC_NONE, 'E', 7, sizeof(struct ioctl_evtchn_bind)) +struct ioctl_evtchn_bind { + unsigned int port; +}; + #endif /* __LINUX_PUBLIC_EVTCHN_H__ */ diff --git a/include/xen/events.h b/include/xen/events.h index ac1281c5ead6..377ad7e391e8 100644 --- a/include/xen/events.h +++ b/include/xen/events.h @@ -69,7 +69,7 @@ int xen_set_irq_priority(unsigned irq, unsigned priority); /* * Allow extra references to event channels exposed to userspace by evtchn */ -int evtchn_make_refcounted(evtchn_port_t evtchn); +int evtchn_make_refcounted(evtchn_port_t evtchn, bool is_static); int evtchn_get(evtchn_port_t evtchn); void evtchn_put(evtchn_port_t evtchn); base-commit: 3a8a670eeeaa40d87bd38a587438952741980c18 -- 2.25.1