mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] xen/evtchn: Introduce new IOCTL to bind static evtchn
@ 2023-07-18 11:31 Rahul Singh
  2023-07-18 14:50 ` Oleksandr Tyshchenko
  2023-07-27  5:54 ` Juergen Gross
  0 siblings, 2 replies; 5+ messages in thread
From: Rahul Singh @ 2023-07-18 11:31 UTC (permalink / raw)
  To: xen-devel, linux-kernel
  Cc: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
	Boris Ostrovsky, David Woodhouse, Jane Malalane

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.

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.

Also, take this opportunity to remove the open-coded version of the
evtchn close in drivers/xen/evtchn.c file and use xen_evtchn_close().

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
---
v3:
 * Remove the open-coded version of the evtchn close in drivers/xen/evtchn.c
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 | 16 +++++----------
 drivers/xen/evtchn.c             | 35 ++++++++++++++++++++++++--------
 include/uapi/xen/evtchn.h        |  9 ++++++++
 include/xen/events.h             | 11 +++++++++-
 4 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index c7715f8bd452..3bdd5b59661d 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;
@@ -815,15 +816,6 @@ static void xen_free_irq(unsigned irq)
 	irq_free_desc(irq);
 }
 
-static void xen_evtchn_close(evtchn_port_t port)
-{
-	struct evtchn_close close;
-
-	close.port = port;
-	if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
-		BUG();
-}
-
 /* Not called for lateeoi events. */
 static void event_handler_exit(struct irq_info *info)
 {
@@ -982,7 +974,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 +1567,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 +1583,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..9139a7364df5 100644
--- a/drivers/xen/evtchn.c
+++ b/drivers/xen/evtchn.c
@@ -366,10 +366,10 @@ 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;
 	int rc = 0;
 
 	/*
@@ -402,14 +402,14 @@ 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)
+		xen_evtchn_close(port);
+
 	del_evtchn(u, evtchn);
 	return rc;
 }
@@ -456,7 +456,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 +482,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 +507,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 +536,23 @@ static long evtchn_ioctl(struct file *file,
 		break;
 	}
 
+	case IOCTL_EVTCHN_BIND_STATIC: {
+		struct ioctl_evtchn_bind bind;
+		struct user_evtchn *evtchn;
+
+		rc = -EFAULT;
+		if (copy_from_user(&bind, uarg, sizeof(bind)))
+			break;
+
+		rc = -EISCONN;
+		evtchn = find_evtchn(u, bind.port);
+		if (evtchn)
+			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..95970a2f7695 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);
 
@@ -141,4 +141,13 @@ void xen_init_IRQ(void);
 
 irqreturn_t xen_debug_interrupt(int irq, void *dev_id);
 
+static inline void xen_evtchn_close(evtchn_port_t port)
+{
+	struct evtchn_close close;
+
+	close.port = port;
+	if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
+		BUG();
+}
+
 #endif	/* _XEN_EVENTS_H */

base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] xen/evtchn: Introduce new IOCTL to bind static evtchn
  2023-07-18 11:31 [PATCH v3] xen/evtchn: Introduce new IOCTL to bind static evtchn Rahul Singh
@ 2023-07-18 14:50 ` Oleksandr Tyshchenko
  2023-07-20  0:22   ` Stefano Stabellini
  2023-07-27  5:54 ` Juergen Gross
  1 sibling, 1 reply; 5+ messages in thread
From: Oleksandr Tyshchenko @ 2023-07-18 14:50 UTC (permalink / raw)
  To: Rahul Singh, xen-devel, linux-kernel
  Cc: Juergen Gross, Stefano Stabellini, Boris Ostrovsky,
	David Woodhouse, Jane Malalane



On 18.07.23 14:31, Rahul Singh wrote:


Hello Rahul


> 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.
> 
> 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.
> 
> Also, take this opportunity to remove the open-coded version of the
> evtchn close in drivers/xen/evtchn.c file and use xen_evtchn_close().
> 
> Signed-off-by: Rahul Singh <rahul.singh@arm.com>
> ---
> v3:
>   * Remove the open-coded version of the evtchn close in drivers/xen/evtchn.c

Thanks!

Looks like there is one unmentioned change in change-log since v2:
* Make sure that evtchn hasn't been added yet before binding it in 
evtchn_ioctl():case IOCTL_EVTCHN_BIND_STATIC

Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

> v2:
>   * Use bool in place u8 to define is_static variable.
>   * Avoid closing the static evtchns in error path.
> ---

[snip]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] xen/evtchn: Introduce new IOCTL to bind static evtchn
  2023-07-18 14:50 ` Oleksandr Tyshchenko
@ 2023-07-20  0:22   ` Stefano Stabellini
  0 siblings, 0 replies; 5+ messages in thread
From: Stefano Stabellini @ 2023-07-20  0:22 UTC (permalink / raw)
  To: Oleksandr Tyshchenko
  Cc: Rahul Singh, xen-devel, linux-kernel, Juergen Gross,
	Stefano Stabellini, Boris Ostrovsky, David Woodhouse,
	Jane Malalane

[-- Attachment #1: Type: text/plain, Size: 1510 bytes --]

On Tue, 18 Jul 2023, Oleksandr Tyshchenko wrote:
> On 18.07.23 14:31, Rahul Singh wrote:
> 
> 
> Hello Rahul
> 
> 
> > 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.
> > 
> > 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.
> > 
> > Also, take this opportunity to remove the open-coded version of the
> > evtchn close in drivers/xen/evtchn.c file and use xen_evtchn_close().
> > 
> > Signed-off-by: Rahul Singh <rahul.singh@arm.com>
> > ---
> > v3:
> >   * Remove the open-coded version of the evtchn close in drivers/xen/evtchn.c
> 
> Thanks!
> 
> Looks like there is one unmentioned change in change-log since v2:
> * Make sure that evtchn hasn't been added yet before binding it in 
> evtchn_ioctl():case IOCTL_EVTCHN_BIND_STATIC
> 
> Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

Acked-by: Stefano Stabellini <sstabellini@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] xen/evtchn: Introduce new IOCTL to bind static evtchn
  2023-07-18 11:31 [PATCH v3] xen/evtchn: Introduce new IOCTL to bind static evtchn Rahul Singh
  2023-07-18 14:50 ` Oleksandr Tyshchenko
@ 2023-07-27  5:54 ` Juergen Gross
  2023-07-27  8:27   ` Rahul Singh
  1 sibling, 1 reply; 5+ messages in thread
From: Juergen Gross @ 2023-07-27  5:54 UTC (permalink / raw)
  To: Rahul Singh, xen-devel, linux-kernel
  Cc: Stefano Stabellini, Oleksandr Tyshchenko, Boris Ostrovsky,
	David Woodhouse, Jane Malalane


[-- Attachment #1.1.1: Type: text/plain, Size: 1046 bytes --]

On 18.07.23 13:31, Rahul Singh wrote:
> 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.
> 
> 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.
> 
> Also, take this opportunity to remove the open-coded version of the
> evtchn close in drivers/xen/evtchn.c file and use xen_evtchn_close().
> 
> Signed-off-by: Rahul Singh <rahul.singh@arm.com>

Pushed to xen/tip.git for-linus-6.5a


Juergen


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] xen/evtchn: Introduce new IOCTL to bind static evtchn
  2023-07-27  5:54 ` Juergen Gross
@ 2023-07-27  8:27   ` Rahul Singh
  0 siblings, 0 replies; 5+ messages in thread
From: Rahul Singh @ 2023-07-27  8:27 UTC (permalink / raw)
  To: Juergen Gross
  Cc: Xen-devel, linux-kernel, Stefano Stabellini,
	Oleksandr Tyshchenko, Boris Ostrovsky, David Woodhouse,
	Jane Malalane

HI Juergen,

> On 27 Jul 2023, at 6:54 am, Juergen Gross <jgross@suse.com> wrote:
> 
> On 18.07.23 13:31, Rahul Singh wrote:
>> 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.
>> 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.
>> Also, take this opportunity to remove the open-coded version of the
>> evtchn close in drivers/xen/evtchn.c file and use xen_evtchn_close().
>> Signed-off-by: Rahul Singh <rahul.singh@arm.com>
> 
> Pushed to xen/tip.git for-linus-6.5a

Thanks.

Regards,
Rahul


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-27  8:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 11:31 [PATCH v3] xen/evtchn: Introduce new IOCTL to bind static evtchn Rahul Singh
2023-07-18 14:50 ` Oleksandr Tyshchenko
2023-07-20  0:22   ` Stefano Stabellini
2023-07-27  5:54 ` Juergen Gross
2023-07-27  8:27   ` Rahul Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®