Skip to contentSkip to conversation

xen-evtchn misc fixes

PATCH In review Wei Liu 2 participants 7 messages Feb 18, 2013 – Feb 19, 2013 Xen hypervisor interface

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover xen-evtchn misc fixes

Two misc fixes for Xen evtchn driver. The first one is a reposted version of a bug fix, the second one is comment and output adjustment.

author
#1 lore raw

PATCH 1/2 xen: close evtchn port if binding to irq fails

---
 drivers/xen/evtchn.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/xen/evtchn.c +10 -0
index b1f60a0..b2db77e 100644
@@ -269,6 +269,14 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)
 				       u->name, (void *)(unsigned long)port);
 	if (rc >= 0)
 		rc = evtchn_make_refcounted(port);
+	else {
+		/* bind failed, should close the port now */
+		struct evtchn_close close;
+		close.port = port;
+		if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
+			BUG();
+		set_port_user(port, NULL);
+	}
 
 	return rc;
 }
@@ -277,6 +285,8 @@ static void evtchn_unbind_from_user(struct per_user_data *u, int port)
 {
 	int irq = irq_from_evtchn(port);
 
+	BUG_ON(irq < 0);
+
 	unbind_from_irqhandler(irq, (void *)(unsigned long)port);
 
 	set_port_user(port, NULL);
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 1/2] xen: close evtchn port if binding to irq fails

Quoted 1 line · Wei Liu

I thought we had discussed doing this check in the user of this as well?

Quoted 35 lines
---
 drivers/xen/evtchn.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/xen/evtchn.c +10 -0
index b1f60a0..b2db77e 100644
@@ -269,6 +269,14 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)
 				       u->name, (void *)(unsigned long)port);
 	if (rc >= 0)
 		rc = evtchn_make_refcounted(port);
+	else {
+		/* bind failed, should close the port now */
+		struct evtchn_close close;
+		close.port = port;
+		if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
+			BUG();
+		set_port_user(port, NULL);
+	}
 
 	return rc;
 }
@@ -277,6 +285,8 @@ static void evtchn_unbind_from_user(struct per_user_data *u, int port)
 {
 	int irq = irq_from_evtchn(port);
 
+	BUG_ON(irq < 0);
+
 	unbind_from_irqhandler(irq, (void *)(unsigned long)port);
 
 	set_port_user(port, NULL);
Signature · 1 line
1.7.10.4
author
#3 lore raw

Re: [PATCH 1/2] xen: close evtchn port if binding to irq fails

Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Wei Liu

I thought we had discussed doing this check in the user of this as well?

Hah? I remember Jan's comment on the port == 0 case and your suggestion to add BUG_ON() in the unbind path. Did I miss anything?

Wei.

Quoted 35 lines
Quoted 35 lines
---
 drivers/xen/evtchn.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/xen/evtchn.c +10 -0
index b1f60a0..b2db77e 100644
@@ -269,6 +269,14 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)
 				       u->name, (void *)(unsigned long)port);
 	if (rc >= 0)
 		rc = evtchn_make_refcounted(port);
+	else {
+		/* bind failed, should close the port now */
+		struct evtchn_close close;
+		close.port = port;
+		if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
+			BUG();
+		set_port_user(port, NULL);
+	}
 
 	return rc;
 }
@@ -277,6 +285,8 @@ static void evtchn_unbind_from_user(struct per_user_data *u, int port)
 {
 	int irq = irq_from_evtchn(port);
 
+	BUG_ON(irq < 0);
+
 	unbind_from_irqhandler(irq, (void *)(unsigned long)port);
 
 	set_port_user(port, NULL);
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [PATCH 1/2] xen: close evtchn port if binding to irq fails

Quoted 10 lines · Wei Liu
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Wei Liu

I thought we had discussed doing this check in the user of this as well?

Hah? I remember Jan's comment on the port == 0 case and your suggestion to add BUG_ON() in the unbind path. Did I miss anything?

This patch by itself is fine. I thought that we had chatted of adding a check in evtchn_bind_to_user to check the return value and so something about it. But the more I think about this - it makes less sense than doing it here.

So this patch is good - putting it on my 3.9 list.

Quoted 41 lines

Wei.

Quoted 35 lines
Quoted 35 lines
---
 drivers/xen/evtchn.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/xen/evtchn.c +10 -0
index b1f60a0..b2db77e 100644
@@ -269,6 +269,14 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)
 				       u->name, (void *)(unsigned long)port);
 	if (rc >= 0)
 		rc = evtchn_make_refcounted(port);
+	else {
+		/* bind failed, should close the port now */
+		struct evtchn_close close;
+		close.port = port;
+		if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
+			BUG();
+		set_port_user(port, NULL);
+	}
 
 	return rc;
 }
@@ -277,6 +285,8 @@ static void evtchn_unbind_from_user(struct per_user_data *u, int port)
 {
 	int irq = irq_from_evtchn(port);
 
+	BUG_ON(irq < 0);
+
 	unbind_from_irqhandler(irq, (void *)(unsigned long)port);
 
 	set_port_user(port, NULL);
Signature · 1 line
1.7.10.4
author
#5 lore raw

Re: [PATCH 1/2] xen: close evtchn port if binding to irq fails

In reply to Konrad Rzeszutek Wilk
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Wei Liu

I thought we had discussed doing this check in the user of this as well?

User of this? I presume you mean the binding path? The patch also does this. The first patch issues close hypercall in the unbind path, but this patch issues hypercall in the bind path, and adds BUG_ON in the unbind path.

As for port == 0, this cannot happend, so I remove the port == 0 case.

Wei.

Quoted 35 lines
Quoted 35 lines
---
 drivers/xen/evtchn.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/xen/evtchn.c +10 -0
index b1f60a0..b2db77e 100644
@@ -269,6 +269,14 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)
 				       u->name, (void *)(unsigned long)port);
 	if (rc >= 0)
 		rc = evtchn_make_refcounted(port);
+	else {
+		/* bind failed, should close the port now */
+		struct evtchn_close close;
+		close.port = port;
+		if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
+			BUG();
+		set_port_user(port, NULL);
+	}
 
 	return rc;
 }
@@ -277,6 +285,8 @@ static void evtchn_unbind_from_user(struct per_user_data *u, int port)
 {
 	int irq = irq_from_evtchn(port);
 
+	BUG_ON(irq < 0);
+
 	unbind_from_irqhandler(irq, (void *)(unsigned long)port);
 
 	set_port_user(port, NULL);
Signature · 1 line
1.7.10.4
author
#6 lore raw

PATCH 2/2 xen-evtchn: correct comment and error output

In reply to Wei Liu

The evtchn device has been moved to /dev/xen. Also change log level to KERN_ERR as other xen drivers.

---
 drivers/xen/evtchn.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/evtchn.c +2 -2
index b2db77e..45c8efa 100644
@@ -544,10 +544,10 @@ static int __init evtchn_init(void)
 
 	spin_lock_init(&port_user_lock);
 
-	/* Create '/dev/misc/evtchn'. */
+	/* Create '/dev/xen/evtchn'. */
 	err = misc_register(&evtchn_miscdev);
 	if (err != 0) {
-		printk(KERN_ALERT "Could not register /dev/misc/evtchn\n");
+		printk(KERN_ERR "Could not register /dev/xen/evtchn\n");
 		return err;
 	}
 
Signature · 1 line
1.7.10.4