Skip to contentSkip to conversation

Xen netback / netfront improvement

RFC PATCH New Wei Liu 6 participants 42 messages Feb 2, 2012 – Feb 20, 2012

Subsystems (9)
lore
Share & tools
lore

Wei Liu

author
#0 lore raw

RFC PATCH v4 1/1 Xen netback / netfront improvement

Changes in V4:
- Squash several patches
- Per-cpu scratch improvement, guard against race condition, NUMA awared allocation
- Extend xenbus ring mapping interface to benifit all Xen BE / FE
- Remove RX protocol stub patch

Changes in V3:
- Rework of per-cpu scratch space
- Multi page ring support
- Split event channels
- Rx protocol stub
- Fix a minor bug in module_put path

Changes in V2:
- Fix minor bugs in V1
- Embed pending_tx_info into page pool
- Per-cpu scratch space
- Notification code path clean up

This version has been tested by
Konrad Rzeszutek Wilk <[email protected]>

V1:
A new netback implementation which includes three major features:

- Global page pool support
- NAPI + kthread 1:1 model
- Netback internal name changes

This patch series is the foundation of furture work. So it is better to get it right first. Patch 1 and 3 have the real meat.

The first benifit of 1:1 model will be scheduling fairness.

The rational behind a global page pool is that we need to limit overall memory consumed by all vifs.

Utilization of NAPI enables the possibility to mitigate interrupts/events, the code path is cleaned up in a separated patch.

Netback internal changes cleans up the code structure after switching to 1:1 model. It also prepares netback for further code layout changes.

-----

 drivers/block/xen-blkback/xenbus.c    |    8 +-
 drivers/block/xen-blkfront.c          |    5 +-
 drivers/net/xen-netback/Makefile      |    2 +-
 drivers/net/xen-netback/common.h      |  107 +++--
 drivers/net/xen-netback/interface.c   |  230 ++++++--
 drivers/net/xen-netback/netback.c     |  999 +++++++++++++++------------------
 drivers/net/xen-netback/page_pool.c   |  185 ++++++
 drivers/net/xen-netback/page_pool.h   |   66 +++
 drivers/net/xen-netback/xenbus.c      |  178 ++++++-
 drivers/net/xen-netfront.c            |  393 ++++++++++----
 drivers/pci/xen-pcifront.c            |    5 +-
 drivers/scsi/xen-scsiback/common.h    |    3 +-
 drivers/scsi/xen-scsiback/interface.c |    6 +-
 drivers/scsi/xen-scsiback/xenbus.c    |    4 +-
 drivers/scsi/xen-scsifront/xenbus.c   |    5 +-
 drivers/xen/xen-pciback/xenbus.c      |   11 +-
 drivers/xen/xenbus/xenbus_client.c    |  282 +++++++---
 include/xen/xenbus.h                  |   15 +-
 18 files changed, 1646 insertions(+), 858 deletions(-)
author
#1 lore raw

RFC PATCH v4 1/13 netback: page pool version 1

A global page pool. Since we are moving to 1:1 model netback, it is better to limit total RAM consumed by all the vifs.

With this patch, each vif gets page from the pool and puts the page back when it is finished with the page.

This pool is only meant to access via exported interfaces. Internals are subject to change when we discover new requirements for the pool.

Current exported interfaces include:

page_pool_init: pool init
page_pool_destroy: pool destruction
page_pool_get: get a page from pool
page_pool_put: put page back to pool
is_in_pool: tell whether a page belongs to the pool

Current implementation has following defects:
- Global locking
- No starve prevention mechanism / reservation logic

Global locking tends to cause contention on the pool. No reservation logic may cause vif to starve. A possible solution to these two problems will be each vif maintains its local cache and claims a portion of the pool. However the implementation will be tricky when coming to pool management, so let's worry about that later.

---
 drivers/net/xen-netback/Makefile    |    2 +-
 drivers/net/xen-netback/common.h    |    6 +
 drivers/net/xen-netback/netback.c   |  158 ++++++++++++------------------
 drivers/net/xen-netback/page_pool.c |  185 +++++++++++++++++++++++++++++++++++
 drivers/net/xen-netback/page_pool.h |   63 ++++++++++++
 5 files changed, 317 insertions(+), 97 deletions(-)
 create mode 100644 drivers/net/xen-netback/page_pool.c
 create mode 100644 drivers/net/xen-netback/page_pool.h
drivers/net/xen-netback/Makefile +1 -1
index e346e81..dc4b8b1 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_XEN_NETDEV_BACKEND) := xen-netback.o
 
-xen-netback-y := netback.o xenbus.o interface.o
+xen-netback-y := netback.o xenbus.o interface.o page_pool.o
drivers/net/xen-netback/common.h +6 -0
index 94b79c3..288b2f3 100644
@@ -45,6 +45,12 @@
 #include <xen/grant_table.h>
 #include <xen/xenbus.h>
 
+struct pending_tx_info {
+	struct xen_netif_tx_request req;
+	struct xenvif *vif;
+};
+typedef unsigned int pending_ring_idx_t;
+
 struct xen_netbk;
 
 struct xenvif {
drivers/net/xen-netback/netback.c +62 -96

323 lines not on this page · raw message

drivers/net/xen-netback/page_pool.c new file +185 -0

185 lines not on this page · raw message

drivers/net/xen-netback/page_pool.h new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#2 lore raw

Re: [RFC PATCH V4 01/13] netback: page pool version 1

Quoted 27 lines · Wei Liu

A global page pool. Since we are moving to 1:1 model netback, it is better to limit total RAM consumed by all the vifs.

With this patch, each vif gets page from the pool and puts the page back when it is finished with the page.

This pool is only meant to access via exported interfaces. Internals are subject to change when we discover new requirements for the pool.

Current exported interfaces include:

page_pool_init: pool init
page_pool_destroy: pool destruction
page_pool_get: get a page from pool
page_pool_put: put page back to pool
is_in_pool: tell whether a page belongs to the pool

Current implementation has following defects:
- Global locking
- No starve prevention mechanism / reservation logic

Global locking tends to cause contention on the pool. No reservation logic may cause vif to starve. A possible solution to these two problems will be each vif maintains its local cache and claims a portion of the pool. However the implementation will be tricky when coming to pool management, so let's worry about that later.

Quoted 4 lines

---

Hmm, this kind of stuff should be discussed on lkml.

I doubt we want yet another memory allocator, with a global lock (contended), and no NUMA properties.

Quoted 12 lines
drivers/net/xen-netback/page_pool.c new file +12 -0
+int page_pool_init()
+{
+	int cpus = 0;
+	int i;
+
+	cpus = num_online_cpus();
+	pool_size = cpus * ENTRIES_PER_CPU;
+
+	pool = vzalloc(sizeof(struct page_pool_entry) * pool_size);
+
+	if (!pool)
+		return -ENOMEM;

drivers/net/xen-netback/page_pool.c line 161

Quoted 10 lines
drivers/net/xen-netback/page_pool.c new file +10 -0
+
+	for (i = 0; i < pool_size - 1; i++)
+		pool[i].u.fl = i+1;
+	pool[pool_size-1].u.fl = INVALID_ENTRY;
+	free_count = pool_size;
+	free_head = 0;
+
+	return 0;
+}
+

num_online_cpus() disease once again.

code depending on num_online_cpus() is always suspicious.

#3 lore raw

Re: [RFC PATCH V4 01/13] netback: page pool version 1

Quoted 5 lines

Hmm, this kind of stuff should be discussed on lkml.

I doubt we want yet another memory allocator, with a global lock (contended), and no NUMA properties.

That should be fixed. Are there any existing memory pools that could be used instead? I (And I think everybody) is all for using the existing APIs if they can do the job. I was lookign a bit at the dmapool code, but that requires something we don't have - the 'struct device'. We could manufacture a fake one, but that just stinks of hack.

It [pagepool] also should use the shrinker API I think.

author
#4 lore raw

Re: [RFC PATCH V4 01/13] netback: page pool version 1

Quoted 12 lines · Konrad Rzeszutek Wilk
Quoted 5 lines

Hmm, this kind of stuff should be discussed on lkml.

I doubt we want yet another memory allocator, with a global lock (contended), and no NUMA properties.

That should be fixed. Are there any existing memory pools that could be used instead? I (And I think everybody) is all for using the existing APIs if they can do the job. I was lookign a bit at the dmapool code, but that requires something we don't have - the 'struct device'. We could manufacture a fake one, but that just stinks of hack.

I've been thinking about this for a long time, so any recommendation is welcomed.

It is not my intention to write yet another memory allocator. What I need is a data structure to track pages owned by netback.

Let me state the requirements of this data structure:
1. limits overall memory used by all vifs (this could also be met by the underlying allocator)
2. provides function to tell whether a particular page is mapped from foreign domain -- is_in_pool() is a surrogate for that
3. provides function to back-reference owner vif of the page

To achieve requirement 2, page pool manipulates page->mapping field. To achieve requirement 3, page pool maintains idx <-> vif relationship internally.

I think I can use mempool internally for page allocation. But I still need a data structure to meet other requirements.

Quoted 1 line

It [pagepool] also should use the shrinker API I think.

This is doable, but let's make everybody happy with the page pool design and implementation first.

Wei.

author
#5 lore raw

RFC PATCH v4 2/13 netback: add module unload function.

In reply to Wei Liu

Enables users to unload netback module.

---
 drivers/net/xen-netback/common.h  |    1 +
 drivers/net/xen-netback/netback.c |   14 ++++++++++++++
 drivers/net/xen-netback/xenbus.c  |    5 +++++
 3 files changed, 20 insertions(+), 0 deletions(-)
drivers/net/xen-netback/common.h +1 -0
index 288b2f3..372c7f5 100644
@@ -126,6 +126,7 @@ void xenvif_get(struct xenvif *vif);
 void xenvif_put(struct xenvif *vif);
 
 int xenvif_xenbus_init(void);
+void xenvif_xenbus_exit(void);
 
 int xenvif_schedulable(struct xenvif *vif);
 
drivers/net/xen-netback/netback.c +14 -0
index d11205f..3059684 100644
@@ -1670,5 +1670,19 @@ failed_init:
 
 module_init(netback_init);
 
+static void __exit netback_exit(void)
+{
+	int i;
+	xenvif_xenbus_exit();
+	for (i = 0; i < xen_netbk_group_nr; i++) {
+		struct xen_netbk *netbk = &xen_netbk[i];
+		del_timer_sync(&netbk->net_timer);
+		kthread_stop(netbk->task);
+	}
+	vfree(xen_netbk);
+	page_pool_destroy();
+}
+module_exit(netback_exit);
+
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_ALIAS("xen-backend:vif");
drivers/net/xen-netback/xenbus.c +5 -0
index 410018c..65d14f2 100644
@@ -485,3 +485,8 @@ int xenvif_xenbus_init(void)
 {
 	return xenbus_register_backend(&netback_driver);
 }
+
+void xenvif_xenbus_exit(void)
+{
+	return xenbus_unregister_driver(&netback_driver);
+}
Signature · 1 line
1.7.2.5
#6 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 28 lines · Wei Liu

Enables users to unload netback module.

---
 drivers/net/xen-netback/common.h  |    1 +
 drivers/net/xen-netback/netback.c |   14 ++++++++++++++
 drivers/net/xen-netback/xenbus.c  |    5 +++++
 3 files changed, 20 insertions(+), 0 deletions(-)
drivers/net/xen-netback/common.h +1 -0
index 288b2f3..372c7f5 100644
@@ -126,6 +126,7 @@ void xenvif_get(struct xenvif *vif);
 void xenvif_put(struct xenvif *vif);
 
 int xenvif_xenbus_init(void);
+void xenvif_xenbus_exit(void);
 
 int xenvif_schedulable(struct xenvif *vif);
 
drivers/net/xen-netback/netback.c +0 -0
index d11205f..3059684 100644

drivers/net/xen-netback/netback.c failed_init: · line 1672

Quoted 3 lines
drivers/net/xen-netback/netback.c +0 -0
@@ -1670,5 +1670,19 @@ failed_init:
 
 module_init(netback_init);
 

While reviewing this code, I can see current netback_init() is buggy.

It assumes all online cpus xen_netbk_group_nr are numbered from 0 to xen_netbk_group_nr-1

This is not right.

Instead of using :

xen_netbk = vzalloc(sizeof(struct xen_netbk) * xen_netbk_group_nr);

You should use a percpu variable to get proper NUMA properties.

And instead of looping like :

for (group = 0; group < xen_netbk_group_nr; group++) {

You must use :

for_each_online_cpu(cpu) {
	...
}

[ and also use kthread_create_on_node() instead of kthread_create() ]

author
#7 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 35 lines · Eric Dumazet
Quoted 28 lines · Wei Liu

Enables users to unload netback module.

---
 drivers/net/xen-netback/common.h  |    1 +
 drivers/net/xen-netback/netback.c |   14 ++++++++++++++
 drivers/net/xen-netback/xenbus.c  |    5 +++++
 3 files changed, 20 insertions(+), 0 deletions(-)
drivers/net/xen-netback/common.h +1 -0
index 288b2f3..372c7f5 100644
@@ -126,6 +126,7 @@ void xenvif_get(struct xenvif *vif);
 void xenvif_put(struct xenvif *vif);
 
 int xenvif_xenbus_init(void);
+void xenvif_xenbus_exit(void);
 
 int xenvif_schedulable(struct xenvif *vif);
 
drivers/net/xen-netback/netback.c +0 -0
index d11205f..3059684 100644

drivers/net/xen-netback/netback.c failed_init: · line 1672

Quoted 3 lines
drivers/net/xen-netback/netback.c +0 -0
@@ -1670,5 +1670,19 @@ failed_init:
 
 module_init(netback_init);
 

While reviewing this code, I can see current netback_init() is buggy.

Quoted 5 lines

It assumes all online cpus xen_netbk_group_nr are numbered from 0 to xen_netbk_group_nr-1

This is not right.

You're right about this.

But this part is destined to get wiped out (in the very near future?) -- see following patches. So I don't think it is worthy to fix this.

Wei.

Quoted 20 lines

Instead of using :

xen_netbk = vzalloc(sizeof(struct xen_netbk) * xen_netbk_group_nr);

You should use a percpu variable to get proper NUMA properties.

And instead of looping like :

for (group = 0; group < xen_netbk_group_nr; group++) {

You must use :

for_each_online_cpu(cpu) {
	...
}

[ and also use kthread_create_on_node() instead of kthread_create() ]

#8 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 5 lines · Wei Liu

You're right about this.

But this part is destined to get wiped out (in the very near future?) -- see following patches. So I don't think it is worthy to fix this.

Before adding new bugs, you must fix previous ones.

Do you think stable teams will do the backport of all your upcoming patches ?

#9 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 9 lines · Eric Dumazet
Quoted 5 lines · Wei Liu

You're right about this.

But this part is destined to get wiped out (in the very near future?) -- see following patches. So I don't think it is worthy to fix this.

Before adding new bugs, you must fix previous ones.

I've never heard of this requirement before! It's a wonder anyone ever gets anything done.

Anyway, I think it would be reasonable to just remove the kthread_bind call from this loop. We don't actually want/need a thread per online CPU in any strict sense, we just want there to be some number of worker threads available and ~numcpus at start of day is a good enough approximation for that number. There have been patches floating around in the past which make the number of groups a module parameter which would also be a reasonable thing to dig out if we weren't just about to remove all this code anyway.

So removing the kthread_bind is good enough for the short term, and for stable if people feel that is necessary, and we can continue in mainline with the direction Wei's patches are taking us.

Ian.

#10 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 23 lines · Ian Campbell
Quoted 9 lines · Eric Dumazet
Quoted 5 lines · Wei Liu

You're right about this.

But this part is destined to get wiped out (in the very near future?) -- see following patches. So I don't think it is worthy to fix this.

Before adding new bugs, you must fix previous ones.

I've never heard of this requirement before! It's a wonder anyone ever gets anything done.

Anyway, I think it would be reasonable to just remove the kthread_bind call from this loop. We don't actually want/need a thread per online CPU in any strict sense, we just want there to be some number of worker threads available and ~numcpus at start of day is a good enough approximation for that number. There have been patches floating around in the past which make the number of groups a module parameter which would also be a reasonable thing to dig out if we weren't just about to remove all this code anyway.

Quoted 4 lines

So removing the kthread_bind is good enough for the short term, and for stable if people feel that is necessary, and we can continue in mainline with the direction Wei's patches are taking us.

That sounds a right fix.

Why do think its not reasonable that I ask a bug fix ?

Next time, dont bother send patches for review if you dont want reviewers.

#11 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 6 lines · Eric Dumazet

That sounds a right fix.

Why do think its not reasonable that I ask a bug fix ?

Next time, dont bother send patches for review if you dont want reviewers.

FYI, here the trace you can get right now with this bug :

[ 1180.114682] WARNING: at arch/x86/kernel/smp.c:120 native_smp_send_reschedule+0x5b/0x60()
[ 1180.114685] Hardware name: ProLiant BL460c G6
[ 1180.114686] Modules linked in: ipmi_devintf nfsd exportfs ipmi_si hpilo bnx2x crc32c libcrc32c mdio [last unloaded: scsi_wait_scan]
[ 1180.114697] Pid: 7, comm: migration/1 Not tainted 3.3.0-rc2+ #609
[ 1180.114699] Call Trace:
[ 1180.114701]  <IRQ>  [<ffffffff81037adf>] warn_slowpath_common+0x7f/0xc0
[ 1180.114708]  [<ffffffff81037b3a>] warn_slowpath_null+0x1a/0x20
[ 1180.114711]  [<ffffffff8101ecfb>] native_smp_send_reschedule+0x5b/0x60
[ 1180.114715]  [<ffffffff810744ec>] trigger_load_balance+0x28c/0x370
[ 1180.114720]  [<ffffffff8106be14>] scheduler_tick+0x114/0x160
[ 1180.114724]  [<ffffffff8104956e>] update_process_times+0x6e/0x90
[ 1180.114729]  [<ffffffff8108c614>] tick_sched_timer+0x64/0xc0
[ 1180.114733]  [<ffffffff8105fe54>] __run_hrtimer+0x84/0x1f0
[ 1180.114736]  [<ffffffff8108c5b0>] ? tick_nohz_handler+0xf0/0xf0
[ 1180.114739]  [<ffffffff8103f271>] ? __do_softirq+0x101/0x240
[ 1180.114742]  [<ffffffff81060783>] hrtimer_interrupt+0xf3/0x220
[ 1180.114747]  [<ffffffff810a90b0>] ? queue_stop_cpus_work+0x100/0x100
[ 1180.114751]  [<ffffffff8171ee09>] smp_apic_timer_interrupt+0x69/0x99
[ 1180.114754]  [<ffffffff8171dd4b>] apic_timer_interrupt+0x6b/0x70
[ 1180.114756]  <EOI>  [<ffffffff810a9143>] ? stop_machine_cpu_stop+0x93/0xc0
[ 1180.114761]  [<ffffffff810a8da7>] cpu_stopper_thread+0xd7/0x1a0
[ 1180.114766]  [<ffffffff81713dc7>] ? __schedule+0x3a7/0x7e0
[ 1180.114768]  [<ffffffff81064058>] ? __wake_up_common+0x58/0x90
[ 1180.114771]  [<ffffffff810a8cd0>] ? cpu_stop_signal_done+0x40/0x40
[ 1180.114773]  [<ffffffff8105b5c3>] kthread+0x93/0xa0
[ 1180.114776]  [<ffffffff8171e594>] kernel_thread_helper+0x4/0x10
[ 1180.114779]  [<ffffffff8105b530>] ? kthread_freezable_should_stop+0x80/0x80
[ 1180.114781]  [<ffffffff8171e590>] ? gs_change+0xb/0xb
#12 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

In reply to Eric Dumazet
Quoted 24 lines · Eric Dumazet
Quoted 23 lines · Ian Campbell
Quoted 9 lines · Eric Dumazet
Quoted 5 lines · Wei Liu

You're right about this.

But this part is destined to get wiped out (in the very near future?) -- see following patches. So I don't think it is worthy to fix this.

Before adding new bugs, you must fix previous ones.

I've never heard of this requirement before! It's a wonder anyone ever gets anything done.

Anyway, I think it would be reasonable to just remove the kthread_bind call from this loop. We don't actually want/need a thread per online CPU in any strict sense, we just want there to be some number of worker threads available and ~numcpus at start of day is a good enough approximation for that number. There have been patches floating around in the past which make the number of groups a module parameter which would also be a reasonable thing to dig out if we weren't just about to remove all this code anyway.

Quoted 8 lines
Quoted 4 lines

So removing the kthread_bind is good enough for the short term, and for stable if people feel that is necessary, and we can continue in mainline with the direction Wei's patches are taking us.

That sounds a right fix.

Why do think its not reasonable that I ask a bug fix ?

I don't think it is at all unreasonable to ask for bug fixes but in this case Wei's series is removing the code in question (which would also undoubtedly fix the bug).

As it happens the fix turns out to be simple but if it were complex I would perhaps have disagreed more strongly about spending effort fixing code that is removed 2 patches later, although obviously that would have depended on the specifics of the fix in that case.

Quoted 2 lines

Next time, dont bother send patches for review if you dont want reviewers.

The review which you are doing is certainly very much appreciated, I'm sorry if my disagreement over this one point gave/gives the impression that it is not.

Ian.

#13 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 1 line · Ian Campbell

On Thu, 2012-02-02 at 20:34 +0000, Eric Dumazet wrote:

[...]

Quoted 9 lines

I don't think it is at all unreasonable to ask for bug fixes but in this case Wei's series is removing the code in question (which would also undoubtedly fix the bug).

As it happens the fix turns out to be simple but if it were complex I would perhaps have disagreed more strongly about spending effort fixing code that is removed 2 patches later, although obviously that would have depended on the specifics of the fix in that case.

Lots of people are relying on git bisect. If you introduce build failures or known bugs into any point in history, you take away from the value in git bisect. Sure, it happens by accident, but it shouldn't ever be done knowingly.

Paul.

Quoted 14 lines
Quoted 3 lines

Next time, dont bother send patches for review if you dont want reviewers.

The review which you are doing is certainly very much appreciated, I'm sorry if my disagreement over this one point gave/gives the impression that it is not.

Ian.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#14 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 15 lines · Paul Gortmaker
Quoted 1 line · Ian Campbell

On Thu, 2012-02-02 at 20:34 +0000, Eric Dumazet wrote:

[...]

Quoted 9 lines

I don't think it is at all unreasonable to ask for bug fixes but in this case Wei's series is removing the code in question (which would also undoubtedly fix the bug).

As it happens the fix turns out to be simple but if it were complex I would perhaps have disagreed more strongly about spending effort fixing code that is removed 2 patches later, although obviously that would have depended on the specifics of the fix in that case.

Quoted 4 lines

Lots of people are relying on git bisect. If you introduce build failures or known bugs into any point in history, you take away from the value in git bisect. Sure, it happens by accident, but it shouldn't ever be done knowingly.

Sure. In this case the bug has been there since 2.6.39, it isn't introduced by this series.

Ian.

#15 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 16 lines · Ian Campbell
Quoted 15 lines · Paul Gortmaker
Quoted 1 line · Ian Campbell

On Thu, 2012-02-02 at 20:34 +0000, Eric Dumazet wrote:

[...]

Quoted 9 lines

I don't think it is at all unreasonable to ask for bug fixes but in this case Wei's series is removing the code in question (which would also undoubtedly fix the bug).

As it happens the fix turns out to be simple but if it were complex I would perhaps have disagreed more strongly about spending effort fixing code that is removed 2 patches later, although obviously that would have depended on the specifics of the fix in that case.

Quoted 8 lines
Quoted 4 lines

Lots of people are relying on git bisect. If you introduce build failures or known bugs into any point in history, you take away from the value in git bisect. Sure, it happens by accident, but it shouldn't ever be done knowingly.

Sure. In this case the bug has been there since 2.6.39, it isn't introduced by this series.

We are stuck right now with a bug introduced in 2.6.39, (IP redirects), and because fix was done in 3.1, we are unable to provide a fix fo stable 3.0 kernel.

Something that takes 15 minutes to fix now, can take several days of work later.

#16 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

Quoted 26 lines · Eric Dumazet
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Paul Gortmaker
Quoted 1 line · Ian Campbell

On Thu, 2012-02-02 at 20:34 +0000, Eric Dumazet wrote:

[...]

Quoted 9 lines

I don't think it is at all unreasonable to ask for bug fixes but in this case Wei's series is removing the code in question (which would also undoubtedly fix the bug).

As it happens the fix turns out to be simple but if it were complex I would perhaps have disagreed more strongly about spending effort fixing code that is removed 2 patches later, although obviously that would have depended on the specifics of the fix in that case.

Quoted 8 lines
Quoted 4 lines

Lots of people are relying on git bisect. If you introduce build failures or known bugs into any point in history, you take away from the value in git bisect. Sure, it happens by accident, but it shouldn't ever be done knowingly.

Sure. In this case the bug has been there since 2.6.39, it isn't introduced by this series.

Quoted 6 lines

We are stuck right now with a bug introduced in 2.6.39, (IP redirects), and because fix was done in 3.1, we are unable to provide a fix fo stable 3.0 kernel.

Something that takes 15 minutes to fix now, can take several days of work later.

Sure.

Here is the patch. I've compile tested it but not run it yet since I'm supposed to be packing for a trip, I'll be back on Wednesday. It seems straight forward enough though.

8<--------------------------------

From 6f3d3068f6e049c2d810f9fc667d57667bea77dc Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Fri, 3 Feb 2012 07:47:23 +0000
Subject: [PATCH] xen: netback: do not bind netback threads to specific CPUs

netback_init does not take proper account of which CPUs is online. However we don't require a thread per CPU, just a pool of worker threads, of which the number of CPUs at start of day is as good a number as any.

Therefore do not bind netback threads to particular CPUs.

---
 drivers/net/xen-netback/netback.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/net/xen-netback/netback.c +0 -2
index 59effac..31ad3ee 100644
@@ -1670,8 +1670,6 @@ static int __init netback_init(void)
 			goto failed_init;
 		}
 
-		kthread_bind(netbk->task, group);
-
 		INIT_LIST_HEAD(&netbk->net_schedule_list);
 
 		spin_lock_init(&netbk->net_schedule_list_lock);
Signature · 1 line
1.7.2.5
author
#17 lore raw

Re: [RFC PATCH V4 02/13] netback: add module unload function.

In reply to Eric Dumazet
Quoted 10 lines · Eric Dumazet

We are stuck right now with a bug introduced in 2.6.39, (IP redirects), and because fix was done in 3.1, we are unable to provide a fix fo stable 3.0 kernel.

Something that takes 15 minutes to fix now, can take several days of work later.

You're right.

Will stick Ian's patch in front of my next series. Thanks for your effort in reviewing.

Wei.

author
#18 lore raw

RFC PATCH v4 3/13 netback: add module get/put operations along with vif connect/disconnect.

In reply to Wei Liu

If there is vif running and user unloads netback, it will certainly cause problems -- guest's network interface just mysteriously stops working.

disconnect function may get called by the generic framework even before vif connects.

---
 drivers/net/xen-netback/interface.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
drivers/net/xen-netback/interface.c +11 -1
index 1825629..4795c0f 100644
@@ -312,6 +312,8 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 	if (vif->irq)
 		return 0;
 
+	__module_get(THIS_MODULE);
+
 	err = xen_netbk_map_frontend_rings(vif, tx_ring_ref, rx_ring_ref);
 	if (err < 0)
 		goto err;
@@ -339,12 +341,15 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 err_unmap:
 	xen_netbk_unmap_frontend_rings(vif);
 err:
+	module_put(THIS_MODULE);
 	return err;
 }
 
 void xenvif_disconnect(struct xenvif *vif)
 {
 	struct net_device *dev = vif->dev;
+	int need_module_put = 0;
+
 	if (netif_carrier_ok(dev)) {
 		rtnl_lock();
 		netif_carrier_off(dev); /* discard queued packets */
@@ -359,12 +364,17 @@ void xenvif_disconnect(struct xenvif *vif)
 
 	del_timer_sync(&vif->credit_timeout);
 
-	if (vif->irq)
+	if (vif->irq) {
 		unbind_from_irqhandler(vif->irq, vif);
+		need_module_put = 1;
+	}
 
 	unregister_netdev(vif->dev);
 
 	xen_netbk_unmap_frontend_rings(vif);
 
 	free_netdev(vif->dev);
+
+	if (need_module_put)
+		module_put(THIS_MODULE);
 }
Signature · 1 line
1.7.2.5
author
#19 lore raw

RFC PATCH v4 4/13 netback: switch to NAPI + kthread model

In reply to Wei Liu

This patch implements 1:1 model netback. We utilizes NAPI and kthread to do the weight-lifting job:

- NAPI is used for guest side TX (host side RX)
- kthread is used for guest side RX (host side TX)

This model provides better scheduling fairness among vifs. It also lays the foundation for future work.

Changes in V4:

Remove unwanted notification generation during NAPI processing.

In original implementation, tx_build_gops tends to update req_event pointer every time it sees tx error or finish one batch. Remove those code to only update req_event pointer when we really want to shut down NAPI.

---
 drivers/net/xen-netback/common.h    |   36 ++--
 drivers/net/xen-netback/interface.c |   95 ++++++---
 drivers/net/xen-netback/netback.c   |  381 +++++++++++------------------------
 drivers/net/xen-netback/xenbus.c    |    1 -
 4 files changed, 195 insertions(+), 318 deletions(-)
drivers/net/xen-netback/common.h +15 -21
index 372c7f5..1e4d462 100644
@@ -47,7 +47,6 @@
 
 struct pending_tx_info {
 	struct xen_netif_tx_request req;
-	struct xenvif *vif;
 };
 typedef unsigned int pending_ring_idx_t;
 
@@ -61,14 +60,17 @@ struct xenvif {
 	/* Reference to netback processing backend. */
 	struct xen_netbk *netbk;
 
+	/* Use NAPI for guest TX */
+	struct napi_struct napi;
+	/* Use kthread for guest RX */
+	struct task_struct *task;
+	wait_queue_head_t wq;
+
 	u8               fe_dev_addr[6];
 
 	/* Physical parameters of the comms window. */
 	unsigned int     irq;
 
-	/* List of frontends to notify after a batch of frames sent. */
-	struct list_head notify_list;
-
 	/* The shared rings and indexes. */
 	struct xen_netif_tx_back_ring tx;
 	struct xen_netif_rx_back_ring rx;
@@ -99,11 +101,7 @@ struct xenvif {
 	unsigned long rx_gso_checksum_fixup;
 
 	/* Miscellaneous private stuff. */
-	struct list_head schedule_list;
-	atomic_t         refcnt;
 	struct net_device *dev;
-
-	wait_queue_head_t waiting_to_free;
 };
 
 static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
@@ -122,9 +120,6 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 		   unsigned long rx_ring_ref, unsigned int evtchn);
 void xenvif_disconnect(struct xenvif *vif);
 
-void xenvif_get(struct xenvif *vif);
-void xenvif_put(struct xenvif *vif);
-
 int xenvif_xenbus_init(void);
 void xenvif_xenbus_exit(void);
 
@@ -140,18 +135,8 @@ int xen_netbk_map_frontend_rings(struct xenvif *vif,
 				 grant_ref_t tx_ring_ref,
 				 grant_ref_t rx_ring_ref);
 
-/* (De)Register a xenvif with the netback backend. */
-void xen_netbk_add_xenvif(struct xenvif *vif);
-void xen_netbk_remove_xenvif(struct xenvif *vif);
-
-/* (De)Schedule backend processing for a xenvif */
-void xen_netbk_schedule_xenvif(struct xenvif *vif);
-void xen_netbk_deschedule_xenvif(struct xenvif *vif);
-
 /* Check for SKBs from frontend and schedule backend processing */
 void xen_netbk_check_rx_xenvif(struct xenvif *vif);
-/* Receive an SKB from the frontend */
-void xenvif_receive_skb(struct xenvif *vif, struct sk_buff *skb);
 
 /* Queue an SKB for transmission to the frontend */
 void xen_netbk_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb);
@@ -161,4 +146,13 @@ void xenvif_notify_tx_completion(struct xenvif *vif);
 /* Returns number of ring slots required to send an skb to the frontend */
 unsigned int xen_netbk_count_skb_slots(struct xenvif *vif, struct sk_buff *skb);
 
+/* Allocate and free xen_netbk structure */
+struct xen_netbk *xen_netbk_alloc_netbk(struct xenvif *vif);
+void xen_netbk_free_netbk(struct xen_netbk *netbk);
+
+int xen_netbk_tx_action(struct xen_netbk *netbk, int budget);
+void xen_netbk_rx_action(struct xen_netbk *netbk);
+
+int xen_netbk_kthread(void *data);
+
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +64 -31

180 lines not on this page · raw message

drivers/net/xen-netback/netback.c +116 -265

666 lines not on this page · raw message

drivers/net/xen-netback/xenbus.c +0 -1
index 65d14f2..f1e89ca 100644
@@ -387,7 +387,6 @@ static void connect(struct backend_info *be)
 	netif_wake_queue(be->vif->dev);
 }
 
-
 static int connect_rings(struct backend_info *be)
 {
 	struct xenvif *vif = be->vif;
Signature · 1 line
1.7.2.5
author
#20 lore raw

RFC PATCH v4 5/13 netback: switch to per-cpu scratch space.

In reply to Wei Liu

In the 1:1 model, given that there are maximum nr_online_cpus netbacks running, we can use per-cpu scratch space, thus shrinking size of struct xen_netbk.

Changes in V4:

Carefully guard against CPU hotplug race condition. NAPI and kthread will bail when scratch spaces are not available.

Scratch space allocation is NUMA awared.

---
 drivers/net/xen-netback/common.h  |   15 ++
 drivers/net/xen-netback/netback.c |  261 ++++++++++++++++++++++++++++++-------
 2 files changed, 229 insertions(+), 47 deletions(-)
drivers/net/xen-netback/common.h +15 -0
index 1e4d462..65df480 100644
@@ -45,6 +45,21 @@
 #include <xen/grant_table.h>
 #include <xen/xenbus.h>
 
+#define DRV_NAME "netback: "
+
+struct netbk_rx_meta {
+	int id;
+	int size;
+	int gso_size;
+};
+
+#define MAX_PENDING_REQS 256
+
+/* Discriminate from any valid pending_idx value. */
+#define INVALID_PENDING_IDX 0xFFFF
+
+#define MAX_BUFFER_OFFSET PAGE_SIZE
+
 struct pending_tx_info {
 	struct xen_netif_tx_request req;
 };
drivers/net/xen-netback/netback.c +214 -47

414 lines not on this page · raw message

Signature · 1 line
1.7.2.5
author
#21 lore raw

RFC PATCH v4 6/13 netback: melt xen_netbk into xenvif

In reply to Wei Liu

In the 1:1 model, there is no need to keep xen_netbk and xenvif separated.

---
 drivers/net/xen-netback/common.h    |   35 +++---
 drivers/net/xen-netback/interface.c |   36 +++---
 drivers/net/xen-netback/netback.c   |  219 +++++++++++++----------------------
 drivers/net/xen-netback/page_pool.c |   10 +-
 drivers/net/xen-netback/page_pool.h |   13 ++-
 5 files changed, 124 insertions(+), 189 deletions(-)
drivers/net/xen-netback/common.h +16 -19
index 65df480..ea91bb6 100644
@@ -46,6 +46,7 @@
 #include <xen/xenbus.h>
 
 #define DRV_NAME "netback: "
+#include "page_pool.h"
 
 struct netbk_rx_meta {
 	int id;
@@ -53,28 +54,21 @@ struct netbk_rx_meta {
 	int gso_size;
 };
 
-#define MAX_PENDING_REQS 256
-
 /* Discriminate from any valid pending_idx value. */
 #define INVALID_PENDING_IDX 0xFFFF
 
 #define MAX_BUFFER_OFFSET PAGE_SIZE
 
-struct pending_tx_info {
-	struct xen_netif_tx_request req;
-};
-typedef unsigned int pending_ring_idx_t;
+#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE)
+#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)
 
-struct xen_netbk;
+#define MAX_PENDING_REQS 256
 
 struct xenvif {
 	/* Unique identifier for this interface. */
 	domid_t          domid;
 	unsigned int     handle;
 
-	/* Reference to netback processing backend. */
-	struct xen_netbk *netbk;
-
 	/* Use NAPI for guest TX */
 	struct napi_struct napi;
 	/* Use kthread for guest RX */
@@ -117,6 +111,16 @@ struct xenvif {
 
 	/* Miscellaneous private stuff. */
 	struct net_device *dev;
+
+	struct sk_buff_head rx_queue;
+	struct sk_buff_head tx_queue;
+
+	idx_t mmap_pages[MAX_PENDING_REQS];
+
+	pending_ring_idx_t pending_prod;
+	pending_ring_idx_t pending_cons;
+
+	u16 pending_ring[MAX_PENDING_REQS];
 };
 
 static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
@@ -124,9 +128,6 @@ static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
 	return to_xenbus_device(vif->dev->dev.parent);
 }
 
-#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE)
-#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)
-
 struct xenvif *xenvif_alloc(struct device *parent,
 			    domid_t domid,
 			    unsigned int handle);
@@ -161,12 +162,8 @@ void xenvif_notify_tx_completion(struct xenvif *vif);
 /* Returns number of ring slots required to send an skb to the frontend */
 unsigned int xen_netbk_count_skb_slots(struct xenvif *vif, struct sk_buff *skb);
 
-/* Allocate and free xen_netbk structure */
-struct xen_netbk *xen_netbk_alloc_netbk(struct xenvif *vif);
-void xen_netbk_free_netbk(struct xen_netbk *netbk);
-
-int xen_netbk_tx_action(struct xen_netbk *netbk, int budget);
-void xen_netbk_rx_action(struct xen_netbk *netbk);
+int xen_netbk_tx_action(struct xenvif *vif, int budget);
+void xen_netbk_rx_action(struct xenvif *vif);
 
 int xen_netbk_kthread(void *data);
 
drivers/net/xen-netback/interface.c +16 -20
index 1d9688a..9b7d596 100644
@@ -55,9 +55,6 @@ static irqreturn_t xenvif_interrupt(int irq, void *dev_id)
 {
 	struct xenvif *vif = dev_id;
 
-	if (vif->netbk == NULL)
-		return IRQ_NONE;
-
 	if (xenvif_rx_schedulable(vif))
 		netif_wake_queue(vif->dev);
 
@@ -72,7 +69,7 @@ static int xenvif_poll(struct napi_struct *napi, int budget)
 	struct xenvif *vif = container_of(napi, struct xenvif, napi);
 	int work_done;
 
-	work_done = xen_netbk_tx_action(vif->netbk, budget);
+	work_done = xen_netbk_tx_action(vif, budget);
 
 	if (work_done < budget) {
 		int more_to_do = 0;
@@ -96,7 +93,8 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	BUG_ON(skb->dev != dev);
 
-	if (vif->netbk == NULL)
+	/* Drop the packet if vif is not ready */
+	if (vif->task == NULL)
 		goto drop;
 
 	/* Drop the packet if the target domain has no receive buffers. */
@@ -253,6 +251,7 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
 	int err;
 	struct net_device *dev;
 	struct xenvif *vif;
+	int i;
 	char name[IFNAMSIZ] = {};
 
 	snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
@@ -267,7 +266,6 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
 	vif = netdev_priv(dev);
 	vif->domid  = domid;
 	vif->handle = handle;
-	vif->netbk = NULL;
 
 	vif->can_sg = 1;
 	vif->csum = 1;
@@ -286,6 +284,17 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
 
 	dev->tx_queue_len = XENVIF_QUEUE_LENGTH;
 
+	skb_queue_head_init(&vif->rx_queue);
+	skb_queue_head_init(&vif->tx_queue);
+
+	vif->pending_cons = 0;
+	vif->pending_prod = MAX_PENDING_REQS;
+	for (i = 0; i < MAX_PENDING_REQS; i++)
+		vif->pending_ring[i] = i;
+
+	for (i = 0; i < MAX_PENDING_REQS; i++)
+		vif->mmap_pages[i] = INVALID_ENTRY;
+
 	/*
 	 * Initialise a dummy MAC address. We choose the numerically
 	 * largest non-broadcast address to prevent the address getting
@@ -333,14 +342,6 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 	vif->irq = err;
 	disable_irq(vif->irq);
 
-	vif->netbk = xen_netbk_alloc_netbk(vif);
-	if (!vif->netbk) {
-		pr_warn("Could not allocate xen_netbk\n");
-		err = -ENOMEM;
-		goto err_unbind;
-	}
-
-
 	init_waitqueue_head(&vif->wq);
 	vif->task = kthread_create(xen_netbk_kthread,
 				   (void *)vif,
@@ -348,7 +349,7 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 	if (IS_ERR(vif->task)) {
 		pr_warn("Could not create kthread\n");
 		err = PTR_ERR(vif->task);
-		goto err_free_netbk;
+		goto err_unbind;
 	}
 
 	rtnl_lock();
@@ -363,8 +364,6 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 	wake_up_process(vif->task);
 
 	return 0;
-err_free_netbk:
-	xen_netbk_free_netbk(vif->netbk);
 err_unbind:
 	unbind_from_irqhandler(vif->irq, vif);
 err_unmap:
@@ -390,9 +389,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	if (vif->task)
 		kthread_stop(vif->task);
 
-	if (vif->netbk)
-		xen_netbk_free_netbk(vif->netbk);
-
 	netif_napi_del(&vif->napi);
 
 	del_timer_sync(&vif->credit_timeout);
drivers/net/xen-netback/netback.c +79 -140

541 lines not on this page · raw message

drivers/net/xen-netback/page_pool.c +5 -5
index 294f48b..ce00a93 100644
@@ -102,7 +102,7 @@ int is_in_pool(struct page *page, int *pidx)
 	return get_page_ext(page, pidx);
 }
 
-struct page *page_pool_get(struct xen_netbk *netbk, int *pidx)
+struct page *page_pool_get(struct xenvif *vif, int *pidx)
 {
 	int idx;
 	struct page *page;
@@ -118,7 +118,7 @@ struct page *page_pool_get(struct xen_netbk *netbk, int *pidx)
 	}
 
 	set_page_ext(page, idx);
-	pool[idx].u.netbk = netbk;
+	pool[idx].u.vif = vif;
 	pool[idx].page = page;
 
 	*pidx = idx;
@@ -131,7 +131,7 @@ void page_pool_put(int idx)
 	struct page *page = pool[idx].page;
 
 	pool[idx].page = NULL;
-	pool[idx].u.netbk = NULL;
+	pool[idx].u.vif = NULL;
 	page->mapping = 0;
 	put_page(page);
 	put_free_entry(idx);
@@ -174,9 +174,9 @@ struct page *to_page(int idx)
 	return pool[idx].page;
 }
 
-struct xen_netbk *to_netbk(int idx)
+struct xenvif *to_vif(int idx)
 {
-	return pool[idx].u.netbk;
+	return pool[idx].u.vif;
 }
 
 struct pending_tx_info *to_txinfo(int idx)
drivers/net/xen-netback/page_pool.h +8 -5
index 572b037..efae17c 100644
@@ -27,7 +27,10 @@
 #ifndef __PAGE_POOL_H__
 #define __PAGE_POOL_H__
 
-#include "common.h"
+struct pending_tx_info {
+	struct xen_netif_tx_request req;
+};
+typedef unsigned int pending_ring_idx_t;
 
 typedef uint32_t idx_t;
 
@@ -38,8 +41,8 @@ struct page_pool_entry {
 	struct page *page;
 	struct pending_tx_info tx_info;
 	union {
-		struct xen_netbk *netbk;
-		idx_t             fl;
+		struct xenvif *vif;
+		idx_t          fl;
 	} u;
 };
 
@@ -52,12 +55,12 @@ int  page_pool_init(void);
 void page_pool_destroy(void);
 
 
-struct page *page_pool_get(struct xen_netbk *netbk, int *pidx);
+struct page *page_pool_get(struct xenvif *vif, int *pidx);
 void         page_pool_put(int idx);
 int          is_in_pool(struct page *page, int *pidx);
 
 struct page            *to_page(int idx);
-struct xen_netbk       *to_netbk(int idx);
+struct xenvif          *to_vif(int idx);
 struct pending_tx_info *to_txinfo(int idx);
 
 #endif /* __PAGE_POOL_H__ */
Signature · 1 line
1.7.2.5
author
#22 lore raw

RFC PATCH v4 7/13 netback: alter internal function/structure names.

In reply to Wei Liu

Since we've melted xen_netbk into xenvif, so it is better to give functions clearer names.

---
 drivers/net/xen-netback/common.h    |   26 ++--
 drivers/net/xen-netback/interface.c |   20 ++--
 drivers/net/xen-netback/netback.c   |  210 +++++++++++++++++-----------------
 3 files changed, 128 insertions(+), 128 deletions(-)
drivers/net/xen-netback/common.h +13 -13
index ea91bb6..b7d4442 100644
@@ -48,7 +48,7 @@
 #define DRV_NAME "netback: "
 #include "page_pool.h"
 
-struct netbk_rx_meta {
+struct xenvif_rx_meta {
 	int id;
 	int size;
 	int gso_size;
@@ -141,30 +141,30 @@ void xenvif_xenbus_exit(void);
 
 int xenvif_schedulable(struct xenvif *vif);
 
-int xen_netbk_rx_ring_full(struct xenvif *vif);
+int xenvif_rx_ring_full(struct xenvif *vif);
 
-int xen_netbk_must_stop_queue(struct xenvif *vif);
+int xenvif_must_stop_queue(struct xenvif *vif);
 
 /* (Un)Map communication rings. */
-void xen_netbk_unmap_frontend_rings(struct xenvif *vif);
-int xen_netbk_map_frontend_rings(struct xenvif *vif,
-				 grant_ref_t tx_ring_ref,
-				 grant_ref_t rx_ring_ref);
+void xenvif_unmap_frontend_rings(struct xenvif *vif);
+int xenvif_map_frontend_rings(struct xenvif *vif,
+			      grant_ref_t tx_ring_ref,
+			      grant_ref_t rx_ring_ref);
 
 /* Check for SKBs from frontend and schedule backend processing */
-void xen_netbk_check_rx_xenvif(struct xenvif *vif);
+void xenvif_check_rx_xenvif(struct xenvif *vif);
 
 /* Queue an SKB for transmission to the frontend */
-void xen_netbk_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb);
+void xenvif_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb);
 /* Notify xenvif that ring now has space to send an skb to the frontend */
 void xenvif_notify_tx_completion(struct xenvif *vif);
 
 /* Returns number of ring slots required to send an skb to the frontend */
-unsigned int xen_netbk_count_skb_slots(struct xenvif *vif, struct sk_buff *skb);
+unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb);
 
-int xen_netbk_tx_action(struct xenvif *vif, int budget);
-void xen_netbk_rx_action(struct xenvif *vif);
+int xenvif_tx_action(struct xenvif *vif, int budget);
+void xenvif_rx_action(struct xenvif *vif);
 
-int xen_netbk_kthread(void *data);
+int xenvif_kthread(void *data);
 
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +10 -10
index 9b7d596..b2bde8f 100644
@@ -48,7 +48,7 @@ int xenvif_schedulable(struct xenvif *vif)
 
 static int xenvif_rx_schedulable(struct xenvif *vif)
 {
-	return xenvif_schedulable(vif) && !xen_netbk_rx_ring_full(vif);
+	return xenvif_schedulable(vif) && !xenvif_rx_ring_full(vif);
 }
 
 static irqreturn_t xenvif_interrupt(int irq, void *dev_id)
@@ -69,7 +69,7 @@ static int xenvif_poll(struct napi_struct *napi, int budget)
 	struct xenvif *vif = container_of(napi, struct xenvif, napi);
 	int work_done;
 
-	work_done = xen_netbk_tx_action(vif, budget);
+	work_done = xenvif_tx_action(vif, budget);
 
 	if (work_done < budget) {
 		int more_to_do = 0;
@@ -102,12 +102,12 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		goto drop;
 
 	/* Reserve ring slots for the worst-case number of fragments. */
-	vif->rx_req_cons_peek += xen_netbk_count_skb_slots(vif, skb);
+	vif->rx_req_cons_peek += xenvif_count_skb_slots(vif, skb);
 
-	if (vif->can_queue && xen_netbk_must_stop_queue(vif))
+	if (vif->can_queue && xenvif_must_stop_queue(vif))
 		netif_stop_queue(dev);
 
-	xen_netbk_queue_tx_skb(vif, skb);
+	xenvif_queue_tx_skb(vif, skb);
 
 	return NETDEV_TX_OK;
 
@@ -133,7 +133,7 @@ static void xenvif_up(struct xenvif *vif)
 {
 	napi_enable(&vif->napi);
 	enable_irq(vif->irq);
-	xen_netbk_check_rx_xenvif(vif);
+	xenvif_check_rx_xenvif(vif);
 }
 
 static void xenvif_down(struct xenvif *vif)
@@ -330,7 +330,7 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 
 	__module_get(THIS_MODULE);
 
-	err = xen_netbk_map_frontend_rings(vif, tx_ring_ref, rx_ring_ref);
+	err = xenvif_map_frontend_rings(vif, tx_ring_ref, rx_ring_ref);
 	if (err < 0)
 		goto err;
 
@@ -343,7 +343,7 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 	disable_irq(vif->irq);
 
 	init_waitqueue_head(&vif->wq);
-	vif->task = kthread_create(xen_netbk_kthread,
+	vif->task = kthread_create(xenvif_kthread,
 				   (void *)vif,
 				   "vif%d.%d", vif->domid, vif->handle);
 	if (IS_ERR(vif->task)) {
@@ -367,7 +367,7 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
 err_unbind:
 	unbind_from_irqhandler(vif->irq, vif);
 err_unmap:
-	xen_netbk_unmap_frontend_rings(vif);
+	xenvif_unmap_frontend_rings(vif);
 err:
 	module_put(THIS_MODULE);
 	return err;
@@ -400,7 +400,7 @@ void xenvif_disconnect(struct xenvif *vif)
 
 	unregister_netdev(vif->dev);
 
-	xen_netbk_unmap_frontend_rings(vif);
+	xenvif_unmap_frontend_rings(vif);
 
 	free_netdev(vif->dev);
 
drivers/net/xen-netback/netback.c +105 -105

565 lines not on this page · raw message

Signature · 1 line
1.7.2.5
author
#23 lore raw

RFC PATCH v4 8/13 xenbus_client: extend interface to support mapping / unmapping of multi page ring.

In reply to Wei Liu
---
 drivers/xen/xenbus/xenbus_client.c |  282 +++++++++++++++++++++++++-----------
 include/xen/xenbus.h               |   15 ++-
 2 files changed, 206 insertions(+), 91 deletions(-)
drivers/xen/xenbus/xenbus_client.c +196 -86
index 566d2ad..d73b9c6 100644
@@ -53,14 +53,16 @@ struct xenbus_map_node {
 		struct vm_struct *area; /* PV */
 		struct page *page;     /* HVM */
 	};
-	grant_handle_t handle;
+	grant_handle_t handle[XENBUS_MAX_RING_PAGES];
+	unsigned int   nr_handles;
 };
 
 static DEFINE_SPINLOCK(xenbus_valloc_lock);
 static LIST_HEAD(xenbus_valloc_pages);
 
 struct xenbus_ring_ops {
-	int (*map)(struct xenbus_device *dev, int gnt, void **vaddr);
+	int (*map)(struct xenbus_device *dev, int gnt[], int nr_gnts,
+		   void **vaddr);
 	int (*unmap)(struct xenbus_device *dev, void *vaddr);
 };
 
@@ -356,17 +358,38 @@ static void xenbus_switch_fatal(struct xenbus_device *dev, int depth, int err,
 /**
  * xenbus_grant_ring
  * @dev: xenbus device
- * @ring_mfn: mfn of ring to grant
-
- * Grant access to the given @ring_mfn to the peer of the given device.  Return
- * 0 on success, or -errno on error.  On error, the device will switch to
- * XenbusStateClosing, and the error will be saved in the store.
+ * @vaddr: starting virtual address of the ring
+ * @nr_pages: number of page to be granted
+ * @grefs: grant reference array to be filled in
+ * Grant access to the given @vaddr to the peer of the given device.
+ * Then fill in @grefs with grant references.  Return 0 on success, or
+ * -errno on error.  On error, the device will switch to
+ * XenbusStateClosing, and the first error will be saved in the store.
  */
-int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn)
+int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
+		      int nr_pages, int grefs[])
 {
-	int err = gnttab_grant_foreign_access(dev->otherend_id, ring_mfn, 0);
-	if (err < 0)
-		xenbus_dev_fatal(dev, err, "granting access to ring page");
+	int i;
+	int err;
+
+	for (i = 0; i < nr_pages; i++) {
+		unsigned long addr = (unsigned long)vaddr +
+			(PAGE_SIZE * i);
+		err = gnttab_grant_foreign_access(dev->otherend_id,
+						  virt_to_mfn(addr), 0);
+		if (err < 0) {
+			xenbus_dev_fatal(dev, err,
+					 "granting access to ring page");
+			goto fail;
+		}
+		grefs[i] = err;
+	}
+
+	return 0;
+
+fail:
+	for ( ; i >= 0; i--)
+		gnttab_end_foreign_access_ref(grefs[i], 0);
 	return err;
 }
 EXPORT_SYMBOL_GPL(xenbus_grant_ring);
@@ -447,7 +470,8 @@ EXPORT_SYMBOL_GPL(xenbus_free_evtchn);
 /**
  * xenbus_map_ring_valloc
  * @dev: xenbus device
- * @gnt_ref: grant reference
+ * @gnt_ref: grant reference array
+ * @nr_grefs: number of grant reference
  * @vaddr: pointer to address to be filled out by mapping
  *
  * Based on Rusty Russell's skeleton driver's map_page.
@@ -458,52 +482,74 @@ EXPORT_SYMBOL_GPL(xenbus_free_evtchn);
  * or -ENOMEM on error. If an error is returned, device will switch to
  * XenbusStateClosing and the error message will be saved in XenStore.
  */
-int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
+int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref[],
+			   int nr_grefs, void **vaddr)
 {
-	return ring_ops->map(dev, gnt_ref, vaddr);
+	return ring_ops->map(dev, gnt_ref, nr_grefs, vaddr);
 }
 EXPORT_SYMBOL_GPL(xenbus_map_ring_valloc);
 
+static int __xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev,
+					struct xenbus_map_node *node);
+
 static int xenbus_map_ring_valloc_pv(struct xenbus_device *dev,
-				     int gnt_ref, void **vaddr)
+				     int gnt_ref[], int nr_grefs, void **vaddr)
 {
-	struct gnttab_map_grant_ref op = {
-		.flags = GNTMAP_host_map | GNTMAP_contains_pte,
-		.ref   = gnt_ref,
-		.dom   = dev->otherend_id,
-	};
+	struct gnttab_map_grant_ref op[XENBUS_MAX_RING_PAGES];
 	struct xenbus_map_node *node;
 	struct vm_struct *area;
-	pte_t *pte;
+	pte_t *pte[XENBUS_MAX_RING_PAGES];
+	int i;
+	int err = 0;
 
 	*vaddr = NULL;
 
+	if (nr_grefs > XENBUS_MAX_RING_PAGES)
+		return -EINVAL;
+
 	node = kzalloc(sizeof(*node), GFP_KERNEL);
 	if (!node)
 		return -ENOMEM;
 
-	area = alloc_vm_area(PAGE_SIZE, &pte);
+	area = alloc_vm_area(PAGE_SIZE * nr_grefs, pte);
 	if (!area) {
 		kfree(node);
 		return -ENOMEM;
 	}
 
-	op.host_addr = arbitrary_virt_to_machine(pte).maddr;
+	for (i = 0; i < nr_grefs; i++) {
+		op[i].flags = GNTMAP_host_map | GNTMAP_contains_pte,
+		op[i].ref   = gnt_ref[i],
+		op[i].dom   = dev->otherend_id,
+		op[i].host_addr = arbitrary_virt_to_machine(pte[i]).maddr;
+	};
 
-	if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
+	if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, op, nr_grefs))
 		BUG();
 
-	if (op.status != GNTST_okay) {
-		free_vm_area(area);
-		kfree(node);
-		xenbus_dev_fatal(dev, op.status,
+	node->nr_handles = nr_grefs;
+	node->area = area;
+
+	for (i = 0; i < nr_grefs; i++) {
+		if (op[i].status != GNTST_okay) {
+			err = op[i].status;
+			node->handle[i] = INVALID_GRANT_HANDLE;
+			continue;
+		}
+		node->handle[i] = op[i].handle;
+	}
+
+	if (err != 0) {
+		for (i = 0; i < nr_grefs; i++)
+			xenbus_dev_fatal(dev, op[i].status,
 				 "mapping in shared page %d from domain %d",
-				 gnt_ref, dev->otherend_id);
-		return op.status;
+				 gnt_ref[i], dev->otherend_id);
+
+		__xenbus_unmap_ring_vfree_pv(dev, node);
+
+		return err;
 	}
 
-	node->handle = op.handle;
-	node->area = area;
 
 	spin_lock(&xenbus_valloc_lock);
 	list_add(&node->next, &xenbus_valloc_pages);
@@ -514,28 +560,34 @@ static int xenbus_map_ring_valloc_pv(struct xenbus_device *dev,
 }
 
 static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,
-				      int gnt_ref, void **vaddr)
+				      int gnt_ref[], int nr_grefs, void **vaddr)
 {
 	struct xenbus_map_node *node;
 	int err;
 	void *addr;
 
+	if (nr_grefs > XENBUS_MAX_RING_PAGES)
+		return -EINVAL;
+
 	*vaddr = NULL;
 
 	node = kzalloc(sizeof(*node), GFP_KERNEL);
 	if (!node)
 		return -ENOMEM;
 
-	err = alloc_xenballooned_pages(1, &node->page, false /* lowmem */);
+	err = alloc_xenballooned_pages(nr_grefs, &node->page,
+				       false /* lowmem */);
 	if (err)
 		goto out_err;
 
 	addr = pfn_to_kaddr(page_to_pfn(node->page));
 
-	err = xenbus_map_ring(dev, gnt_ref, &node->handle, addr);
+	err = xenbus_map_ring(dev, gnt_ref, nr_grefs, node->handle, addr);
 	if (err)
 		goto out_err;
 
+	node->nr_handles = nr_grefs;
+
 	spin_lock(&xenbus_valloc_lock);
 	list_add(&node->next, &xenbus_valloc_pages);
 	spin_unlock(&xenbus_valloc_lock);
@@ -544,7 +596,7 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,
 	return 0;
 
  out_err:
-	free_xenballooned_pages(1, &node->page);
+	free_xenballooned_pages(nr_grefs, &node->page);
 	kfree(node);
 	return err;
 }
@@ -553,36 +605,52 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,
 /**
  * xenbus_map_ring
  * @dev: xenbus device
- * @gnt_ref: grant reference
- * @handle: pointer to grant handle to be filled
+ * @gnt_ref: grant reference array
+ * @nr_grefs: number of grant reference
+ * @handle: pointer to grant handle array to be filled, mind the size
  * @vaddr: address to be mapped to
  *
- * Map a page of memory into this domain from another domain's grant table.
+ * Map pages of memory into this domain from another domain's grant table.
  * xenbus_map_ring does not allocate the virtual address space (you must do
- * this yourself!). It only maps in the page to the specified address.
+ * this yourself!). It only maps in the pages to the specified address.
  * Returns 0 on success, and GNTST_* (see xen/include/interface/grant_table.h)
  * or -ENOMEM on error. If an error is returned, device will switch to
- * XenbusStateClosing and the error message will be saved in XenStore.
+ * XenbusStateClosing and the last error message will be saved in XenStore.
  */
-int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
-		    grant_handle_t *handle, void *vaddr)
+int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref[], int nr_grefs,
+		    grant_handle_t handle[], void *vaddr)
 {
-	struct gnttab_map_grant_ref op;
-
-	gnttab_set_map_op(&op, (phys_addr_t)vaddr, GNTMAP_host_map, gnt_ref,
-			  dev->otherend_id);
+	struct gnttab_map_grant_ref op[XENBUS_MAX_RING_PAGES];
+	int i;
+	int err = GNTST_okay;	/* 0 */
+
+	for (i = 0; i < nr_grefs; i++) {
+		unsigned long addr = (unsigned long)vaddr +
+			(PAGE_SIZE * i);
+		gnttab_set_map_op(&op[i], (phys_addr_t)addr,
+				  GNTMAP_host_map, gnt_ref[i],
+				  dev->otherend_id);
+	}
 
-	if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
+	if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, op, nr_grefs))
 		BUG();
 
-	if (op.status != GNTST_okay) {
-		xenbus_dev_fatal(dev, op.status,
+
+	for (i = 0; i < nr_grefs; i++) {
+		if (op[i].status != GNTST_okay) {
+			err = op[i].status;
+			xenbus_dev_fatal(dev, err,
 				 "mapping in shared page %d from domain %d",
-				 gnt_ref, dev->otherend_id);
-	} else
-		*handle = op.handle;
+				 gnt_ref[i], dev->otherend_id);
+			handle[i] = INVALID_GRANT_HANDLE;
+		} else
+			handle[i] = op[i].handle;
+	}
+
+	if (err != GNTST_okay)
+		xenbus_unmap_ring(dev, handle, nr_grefs, vaddr);
 
-	return op.status;
+	return err;
 }
 EXPORT_SYMBOL_GPL(xenbus_map_ring);
 
@@ -605,13 +673,53 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
 }
 EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfree);
 
+static int __xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev,
+					struct xenbus_map_node *node)
+{
+	struct gnttab_unmap_grant_ref op[XENBUS_MAX_RING_PAGES];
+	unsigned int level;
+	int i, j;
+	int err = GNTST_okay;
+
+	j = 0;
+	for (i = 0; i < node->nr_handles; i++) {
+		unsigned long vaddr = (unsigned long)node->area->addr +
+			(PAGE_SIZE * i);
+		if (node->handle[i] != INVALID_GRANT_HANDLE) {
+			memset(&op[j], 0, sizeof(op[0]));
+			op[j].host_addr = arbitrary_virt_to_machine(
+				lookup_address(vaddr, &level)).maddr;
+			op[j].handle = node->handle[i];
+			j++;
+			node->handle[i] = INVALID_GRANT_HANDLE;
+		}
+	}
+
+	if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, op, j))
+		BUG();
+
+	node->nr_handles = 0;
+
+	for (i = 0; i < j; i++) {
+		if (op[i].status != GNTST_okay) {
+			err = op[i].status;
+			xenbus_dev_error(dev, err,
+				 "unmapping page %d at handle %d error %d",
+				 i, op[i].handle, err);
+		}
+	}
+
+	if (err == GNTST_okay)
+		free_vm_area(node->area);
+
+	kfree(node);
+
+	return err;
+}
+
 static int xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev, void *vaddr)
 {
 	struct xenbus_map_node *node;
-	struct gnttab_unmap_grant_ref op = {
-		.host_addr = (unsigned long)vaddr,
-	};
-	unsigned int level;
 
 	spin_lock(&xenbus_valloc_lock);
 	list_for_each_entry(node, &xenbus_valloc_pages, next) {
@@ -630,29 +738,14 @@ static int xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev, void *vaddr)
 		return GNTST_bad_virt_addr;
 	}
 
-	op.handle = node->handle;
-	op.host_addr = arbitrary_virt_to_machine(
-		lookup_address((unsigned long)vaddr, &level)).maddr;
-
-	if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
-		BUG();
-
-	if (op.status == GNTST_okay)
-		free_vm_area(node->area);
-	else
-		xenbus_dev_error(dev, op.status,
-				 "unmapping page at handle %d error %d",
-				 node->handle, op.status);
-
-	kfree(node);
-	return op.status;
+	return __xenbus_unmap_ring_vfree_pv(dev, node);
 }
 
 static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr)
 {
 	int rv;
 	struct xenbus_map_node *node;
-	void *addr;
+	void *addr = NULL;
 
 	spin_lock(&xenbus_valloc_lock);
 	list_for_each_entry(node, &xenbus_valloc_pages, next) {
@@ -672,10 +765,10 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr)
 		return GNTST_bad_virt_addr;
 	}
 
-	rv = xenbus_unmap_ring(dev, node->handle, addr);
+	rv = xenbus_unmap_ring(dev, node->handle, node->nr_handles, addr);
 
 	if (!rv)
-		free_xenballooned_pages(1, &node->page);
+		free_xenballooned_pages(node->nr_handles, &node->page);
 	else
 		WARN(1, "Leaking %p\n", vaddr);
 
@@ -687,6 +780,7 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr)
  * xenbus_unmap_ring
  * @dev: xenbus device
  * @handle: grant handle
+ * @nr_handles: number of grant handle
  * @vaddr: addr to unmap
  *
  * Unmap a page of memory in this domain that was imported from another domain.
@@ -694,21 +788,37 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr)
  * (see xen/include/interface/grant_table.h).
  */
 int xenbus_unmap_ring(struct xenbus_device *dev,
-		      grant_handle_t handle, void *vaddr)
+		      grant_handle_t handle[], int nr_handles,
+		      void *vaddr)
 {
-	struct gnttab_unmap_grant_ref op;
-
-	gnttab_set_unmap_op(&op, (phys_addr_t)vaddr, GNTMAP_host_map, handle);
+	struct gnttab_unmap_grant_ref op[XENBUS_MAX_RING_PAGES];
+	int i, j;
+	int err = GNTST_okay;
+
+	j = 0;
+	for (i = 0; i < nr_handles; i++) {
+		unsigned long addr = (unsigned long)vaddr +
+			(PAGE_SIZE * i);
+		if (handle[i] != INVALID_GRANT_HANDLE) {
+			gnttab_set_unmap_op(&op[j++], (phys_addr_t)addr,
+					    GNTMAP_host_map, handle[i]);
+			handle[i] = INVALID_GRANT_HANDLE;
+		}
+	}
 
-	if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
+	if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, op, j))
 		BUG();
 
-	if (op.status != GNTST_okay)
-		xenbus_dev_error(dev, op.status,
+	for (i = 0; i < j; i++) {
+		if (op[i].status != GNTST_okay) {
+			err = op[i].status;
+			xenbus_dev_error(dev, err,
 				 "unmapping page at handle %d error %d",
-				 handle, op.status);
+				 handle[i], err);
+		}
+	}
 
-	return op.status;
+	return err;
 }
 EXPORT_SYMBOL_GPL(xenbus_unmap_ring);
 
include/xen/xenbus.h +10 -5
index e8c599b..284647f 100644
@@ -46,6 +46,10 @@
 #include <xen/interface/io/xenbus.h>
 #include <xen/interface/io/xs_wire.h>
 
+#define XENBUS_MAX_RING_PAGE_ORDER 2
+#define XENBUS_MAX_RING_PAGES      4
+#define INVALID_GRANT_HANDLE       (~0U)
+
 /* Register callback to watch this node. */
 struct xenbus_watch
 {
@@ -195,15 +199,16 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
 			 const char *pathfmt, ...);
 
 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
-int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
+int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
+		      int nr_pages, int grefs[]);
 int xenbus_map_ring_valloc(struct xenbus_device *dev,
-			   int gnt_ref, void **vaddr);
-int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
-			   grant_handle_t *handle, void *vaddr);
+			   int gnt_ref[], int nr_grefs, void **vaddr);
+int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref[], int nr_grefs,
+			   grant_handle_t handle[], void *vaddr);
 
 int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
 int xenbus_unmap_ring(struct xenbus_device *dev,
-		      grant_handle_t handle, void *vaddr);
+		      grant_handle_t handle[], int nr_handles, void *vaddr);
 
 int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
 int xenbus_bind_evtchn(struct xenbus_device *dev, int remote_port, int *port);
Signature · 1 line
1.7.2.5
#24 lore raw

Re: [RFC PATCH V4 08/13] xenbus_client: extend interface to support mapping / unmapping of multi page ring.

Quoted 1 line · Wei Liu

So this does the job but with this patch you introduce a compile bisection bug, which is a not good. The way around is that in this patch you also introduce temporary scaffolding so that the drivers can build. Something as simple as an function that calls the new version, but has the right arguments. Then the next patch (the one that actually does change the backends, will back that wrapper out).

author
#25 lore raw

Re: [RFC PATCH V4 08/13] xenbus_client: extend interface to support mapping / unmapping of multi page ring.

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

So this does the job but with this patch you introduce a compile bisection bug, which is a not good. The way around is that in this patch you also introduce temporary scaffolding so that the drivers can build. Something as simple as an function that calls the new version, but has the right arguments. Then the next patch (the one that actually does change the backends, will back that wrapper out).

How about squashing these two patches. The changes in backends are trivial.

Wei.

#26 lore raw

Re: [RFC PATCH V4 08/13] xenbus_client: extend interface to support mapping / unmapping of multi page ring.

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

So this does the job but with this patch you introduce a compile bisection bug, which is a not good. The way around is that in this patch you also introduce temporary scaffolding so that the drivers can build. Something as simple as an function that calls the new version, but has the right arguments. Then the next patch (the one that actually does change the backends, will back that wrapper out).

Quoted 2 lines

How about squashing these two patches. The changes in backends are trivial.

That could be done as well.

#27 lore raw

Re: [RFC PATCH V4 08/13] xenbus_client: extend interface to support mapping / unmapping of multi page ring.

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

So this does the job but with this patch you introduce a compile bisection bug, which is a not good. The way around is that in this patch you also introduce temporary scaffolding so that the drivers can build. Something as simple as an function that calls the new version, but has the right arguments. Then the next patch (the one that actually does change the backends, will back that wrapper out).

Quoted 2 lines

How about squashing these two patches. The changes in backends are trivial.

One thing I forgot to mention is that since the backends touch different subsystems maintainers tree - you will need to get Acks from all of them on a single patch. That should not be an technical issue - except that some maintainers can take longer to respond - so your whole patchset might be delayed by that.

author
#28 lore raw

Re: [RFC PATCH V4 08/13] xenbus_client: extend interface to support mapping / unmapping of multi page ring.

Quoted 5 lines · Konrad Rzeszutek Wilk

One thing I forgot to mention is that since the backends touch different subsystems maintainers tree - you will need to get Acks from all of them on a single patch. That should not be an technical issue - except that some maintainers can take longer to respond - so your whole patchset might be delayed by that.

Sure, that's not a big problem.

Wei.

author
#29 lore raw

RFC PATCH v4 9/13 Bundle fix for xen backends and frontends

In reply to Wei Liu
---
 drivers/block/xen-blkback/xenbus.c    |    8 +++++---
 drivers/block/xen-blkfront.c          |    5 +++--
 drivers/net/xen-netback/netback.c     |    4 ++--
 drivers/net/xen-netfront.c            |    9 +++++----
 drivers/pci/xen-pcifront.c            |    5 +++--
 drivers/scsi/xen-scsiback/common.h    |    3 ++-
 drivers/scsi/xen-scsiback/interface.c |    6 ++++--
 drivers/scsi/xen-scsiback/xenbus.c    |    4 ++--
 drivers/scsi/xen-scsifront/xenbus.c   |    5 +++--
 drivers/xen/xen-pciback/xenbus.c      |   11 ++++++-----
 10 files changed, 35 insertions(+), 25 deletions(-)
drivers/block/xen-blkback/xenbus.c +5 -3
index 9e9c8a1..ef7e88b 100644
@@ -122,7 +122,8 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
 	return blkif;
 }
 
-static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
+static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page[],
+			 int nr_pages,
 			 unsigned int evtchn)
 {
 	int err;
@@ -131,7 +132,8 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
 	if (blkif->irq)
 		return 0;
 
-	err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring);
+	err = xenbus_map_ring_valloc(blkif->be->dev, shared_page,
+				     nr_pages, &blkif->blk_ring);
 	if (err < 0)
 		return err;
 
@@ -779,7 +781,7 @@ static int connect_ring(struct backend_info *be)
 		ring_ref, evtchn, be->blkif->blk_protocol, protocol);
 
 	/* Map the shared frame, irq etc. */
-	err = xen_blkif_map(be->blkif, ring_ref, evtchn);
+	err = xen_blkif_map(be->blkif, &ring_ref, 1, evtchn);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "mapping ring-ref %lu port %u",
 				 ring_ref, evtchn);
drivers/block/xen-blkfront.c +3 -2
index 2f22874..2c6443a 100644
@@ -827,6 +827,7 @@ static int setup_blkring(struct xenbus_device *dev,
 {
 	struct blkif_sring *sring;
 	int err;
+	int grefs[1];
 
 	info->ring_ref = GRANT_INVALID_REF;
 
@@ -840,13 +841,13 @@ static int setup_blkring(struct xenbus_device *dev,
 
 	sg_init_table(info->sg, BLKIF_MAX_SEGMENTS_PER_REQUEST);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(info->ring.sring));
+	err = xenbus_grant_ring(dev, info->ring.sring, 1, grefs);
 	if (err < 0) {
 		free_page((unsigned long)sring);
 		info->ring.sring = NULL;
 		goto fail;
 	}
-	info->ring_ref = err;
+	info->ring_ref = grefs[0];
 
 	err = xenbus_alloc_evtchn(dev, &info->evtchn);
 	if (err)
drivers/net/xen-netback/netback.c +2 -2
index 384f4e5..cb1a661 100644
@@ -1440,7 +1440,7 @@ int xenvif_map_frontend_rings(struct xenvif *vif,
 	int err = -ENOMEM;
 
 	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
-				     tx_ring_ref, &addr);
+				     &tx_ring_ref, 1, &addr);
 	if (err)
 		goto err;
 
@@ -1448,7 +1448,7 @@ int xenvif_map_frontend_rings(struct xenvif *vif,
 	BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
 
 	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
-				     rx_ring_ref, &addr);
+				     &rx_ring_ref, 1, &addr);
 	if (err)
 		goto err;
 
drivers/net/xen-netfront.c +5 -4
index 01f589d..b7ff815 100644
@@ -1482,6 +1482,7 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	struct xen_netif_tx_sring *txs;
 	struct xen_netif_rx_sring *rxs;
 	int err;
+	int grefs[1];
 	struct net_device *netdev = info->netdev;
 
 	info->tx_ring_ref = GRANT_INVALID_REF;
@@ -1505,13 +1506,13 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	SHARED_RING_INIT(txs);
 	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(txs));
+	err = xenbus_grant_ring(dev, txs, 1, grefs);
 	if (err < 0) {
 		free_page((unsigned long)txs);
 		goto fail;
 	}
 
-	info->tx_ring_ref = err;
+	info->tx_ring_ref = grefs[0];
 	rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
 	if (!rxs) {
 		err = -ENOMEM;
@@ -1521,12 +1522,12 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	SHARED_RING_INIT(rxs);
 	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
+	err = xenbus_grant_ring(dev, rxs, 1, grefs);
 	if (err < 0) {
 		free_page((unsigned long)rxs);
 		goto fail;
 	}
-	info->rx_ring_ref = err;
+	info->rx_ring_ref = grefs[0];
 
 	err = xenbus_alloc_evtchn(dev, &info->evtchn);
 	if (err)
drivers/pci/xen-pcifront.c +3 -2
index 7cf3d2f..394c926 100644
@@ -767,12 +767,13 @@ static int pcifront_publish_info(struct pcifront_device *pdev)
 {
 	int err = 0;
 	struct xenbus_transaction trans;
+	int grefs[1];
 
-	err = xenbus_grant_ring(pdev->xdev, virt_to_mfn(pdev->sh_info));
+	err = xenbus_grant_ring(pdev->xdev, pdev->sh_info, 1, grefs);
 	if (err < 0)
 		goto out;
 
-	pdev->gnt_ref = err;
+	pdev->gnt_ref = grefs[0];
 
 	err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn);
 	if (err)
drivers/scsi/xen-scsiback/common.h +2 -1
index dafa79e..4d13617 100644
@@ -150,7 +150,8 @@ typedef struct {
 
 irqreturn_t scsiback_intr(int, void *);
 int scsiback_init_sring(struct vscsibk_info *info,
-		unsigned long ring_ref, unsigned int evtchn);
+			int ring_ref[], int nr_refs,
+			unsigned int evtchn);
 int scsiback_schedule(void *data);
 
 
drivers/scsi/xen-scsiback/interface.c +4 -2
index 663568e..fad0a63 100644
@@ -60,7 +60,8 @@ struct vscsibk_info *vscsibk_info_alloc(domid_t domid)
 }
 
 int scsiback_init_sring(struct vscsibk_info *info,
-		unsigned long ring_ref, unsigned int evtchn)
+			int ring_ref[], int nr_refs,
+			unsigned int evtchn)
 {
 	struct vscsiif_sring *sring;
 	int err;
@@ -73,7 +74,8 @@ int scsiback_init_sring(struct vscsibk_info *info,
 		return -1;
 	}
 
-	err = xenbus_map_ring_valloc(info->dev, ring_ref, &info->ring_area);
+	err = xenbus_map_ring_valloc(info->dev, ring_ref, nr_refs,
+				     &info->ring_area);
 	if (err < 0)
 		return -ENOMEM;
 
drivers/scsi/xen-scsiback/xenbus.c +2 -2
index 2869f89..81d5598 100644
@@ -60,7 +60,7 @@ static int __vscsiif_name(struct backend_info *be, char *buf)
 static int scsiback_map(struct backend_info *be)
 {
 	struct xenbus_device *dev = be->dev;
-	unsigned long ring_ref = 0;
+	int ring_ref = 0;
 	unsigned int evtchn = 0;
 	int err;
 	char name[TASK_COMM_LEN];
@@ -72,7 +72,7 @@ static int scsiback_map(struct backend_info *be)
 		xenbus_dev_fatal(dev, err, "reading %s ring", dev->otherend);
 		return err;
 	}
-	err = scsiback_init_sring(be->info, ring_ref, evtchn);
+	err = scsiback_init_sring(be->info, &ring_ref, 1, evtchn);
 	if (err)
 		return err;
 
drivers/scsi/xen-scsifront/xenbus.c +3 -2
index bc5c289..8726410 100644
@@ -60,6 +60,7 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *info)
 	struct xenbus_device *dev = info->dev;
 	struct vscsiif_sring *sring;
 	int err = -ENOMEM;
+	int grefs[1];
 
 
 	info->ring_ref = GRANT_INVALID_REF;
@@ -73,14 +74,14 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *info)
 	SHARED_RING_INIT(sring);
 	FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(sring));
+	err = xenbus_grant_ring(dev, sring, 1, grefs);
 	if (err < 0) {
 		free_page((unsigned long) sring);
 		info->ring.sring = NULL;
 		xenbus_dev_fatal(dev, err, "fail to grant shared ring (Front to Back)");
 		goto free_sring;
 	}
-	info->ring_ref = err;
+	info->ring_ref = grefs[0];
 
 	err = xenbus_alloc_evtchn(dev, &info->evtchn);
 	if (err)
drivers/xen/xen-pciback/xenbus.c +6 -5
index 5a42ae7..0d8a98c 100644
@@ -98,17 +98,18 @@ static void free_pdev(struct xen_pcibk_device *pdev)
 	kfree(pdev);
 }
 
-static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref,
-			     int remote_evtchn)
+static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref[],
+			       int nr_grefs,
+			       int remote_evtchn)
 {
 	int err = 0;
 	void *vaddr;
 
 	dev_dbg(&pdev->xdev->dev,
 		"Attaching to frontend resources - gnt_ref=%d evtchn=%d\n",
-		gnt_ref, remote_evtchn);
+		gnt_ref[0], remote_evtchn);
 
-	err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, &vaddr);
+	err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, nr_grefs, &vaddr);
 	if (err < 0) {
 		xenbus_dev_fatal(pdev->xdev, err,
 				"Error mapping other domain page in ours.");
@@ -172,7 +173,7 @@ static int xen_pcibk_attach(struct xen_pcibk_device *pdev)
 		goto out;
 	}
 
-	err = xen_pcibk_do_attach(pdev, gnt_ref, remote_evtchn);
+	err = xen_pcibk_do_attach(pdev, &gnt_ref, 1, remote_evtchn);
 	if (err)
 		goto out;
 
Signature · 1 line
1.7.2.5
#30 lore raw

Re: [RFC PATCH V4 09/13] Bundle fix for xen backends and frontends

Quoted 12 lines · Wei Liu
---
 drivers/block/xen-blkback/xenbus.c    |    8 +++++---
 drivers/block/xen-blkfront.c          |    5 +++--
 drivers/net/xen-netback/netback.c     |    4 ++--
 drivers/net/xen-netfront.c            |    9 +++++----
 drivers/pci/xen-pcifront.c            |    5 +++--
 drivers/scsi/xen-scsiback/common.h    |    3 ++-
 drivers/scsi/xen-scsiback/interface.c |    6 ++++--
 drivers/scsi/xen-scsiback/xenbus.c    |    4 ++--
 drivers/scsi/xen-scsifront/xenbus.c   |    5 +++--

Heheh. If you could seperate the scsi[back|front] from this patchset that would be great. The reason is that SCSI front/back aren't yet ready for upstream.

Quoted 276 lines
 drivers/xen/xen-pciback/xenbus.c      |   11 ++++++-----
 10 files changed, 35 insertions(+), 25 deletions(-)
drivers/block/xen-blkback/xenbus.c +5 -3
index 9e9c8a1..ef7e88b 100644
@@ -122,7 +122,8 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
 	return blkif;
 }
 
-static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
+static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page[],
+			 int nr_pages,
 			 unsigned int evtchn)
 {
 	int err;
@@ -131,7 +132,8 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
 	if (blkif->irq)
 		return 0;
 
-	err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring);
+	err = xenbus_map_ring_valloc(blkif->be->dev, shared_page,
+				     nr_pages, &blkif->blk_ring);
 	if (err < 0)
 		return err;
 
@@ -779,7 +781,7 @@ static int connect_ring(struct backend_info *be)
 		ring_ref, evtchn, be->blkif->blk_protocol, protocol);
 
 	/* Map the shared frame, irq etc. */
-	err = xen_blkif_map(be->blkif, ring_ref, evtchn);
+	err = xen_blkif_map(be->blkif, &ring_ref, 1, evtchn);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "mapping ring-ref %lu port %u",
 				 ring_ref, evtchn);
drivers/block/xen-blkfront.c +3 -2
index 2f22874..2c6443a 100644
@@ -827,6 +827,7 @@ static int setup_blkring(struct xenbus_device *dev,
 {
 	struct blkif_sring *sring;
 	int err;
+	int grefs[1];
 
 	info->ring_ref = GRANT_INVALID_REF;
 
@@ -840,13 +841,13 @@ static int setup_blkring(struct xenbus_device *dev,
 
 	sg_init_table(info->sg, BLKIF_MAX_SEGMENTS_PER_REQUEST);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(info->ring.sring));
+	err = xenbus_grant_ring(dev, info->ring.sring, 1, grefs);
 	if (err < 0) {
 		free_page((unsigned long)sring);
 		info->ring.sring = NULL;
 		goto fail;
 	}
-	info->ring_ref = err;
+	info->ring_ref = grefs[0];
 
 	err = xenbus_alloc_evtchn(dev, &info->evtchn);
 	if (err)
drivers/net/xen-netback/netback.c +2 -2
index 384f4e5..cb1a661 100644
@@ -1440,7 +1440,7 @@ int xenvif_map_frontend_rings(struct xenvif *vif,
 	int err = -ENOMEM;
 
 	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
-				     tx_ring_ref, &addr);
+				     &tx_ring_ref, 1, &addr);
 	if (err)
 		goto err;
 
@@ -1448,7 +1448,7 @@ int xenvif_map_frontend_rings(struct xenvif *vif,
 	BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
 
 	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
-				     rx_ring_ref, &addr);
+				     &rx_ring_ref, 1, &addr);
 	if (err)
 		goto err;
 
drivers/net/xen-netfront.c +5 -4
index 01f589d..b7ff815 100644
@@ -1482,6 +1482,7 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	struct xen_netif_tx_sring *txs;
 	struct xen_netif_rx_sring *rxs;
 	int err;
+	int grefs[1];
 	struct net_device *netdev = info->netdev;
 
 	info->tx_ring_ref = GRANT_INVALID_REF;
@@ -1505,13 +1506,13 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	SHARED_RING_INIT(txs);
 	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(txs));
+	err = xenbus_grant_ring(dev, txs, 1, grefs);
 	if (err < 0) {
 		free_page((unsigned long)txs);
 		goto fail;
 	}
 
-	info->tx_ring_ref = err;
+	info->tx_ring_ref = grefs[0];
 	rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
 	if (!rxs) {
 		err = -ENOMEM;
@@ -1521,12 +1522,12 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	SHARED_RING_INIT(rxs);
 	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
+	err = xenbus_grant_ring(dev, rxs, 1, grefs);
 	if (err < 0) {
 		free_page((unsigned long)rxs);
 		goto fail;
 	}
-	info->rx_ring_ref = err;
+	info->rx_ring_ref = grefs[0];
 
 	err = xenbus_alloc_evtchn(dev, &info->evtchn);
 	if (err)
drivers/pci/xen-pcifront.c +3 -2
index 7cf3d2f..394c926 100644
@@ -767,12 +767,13 @@ static int pcifront_publish_info(struct pcifront_device *pdev)
 {
 	int err = 0;
 	struct xenbus_transaction trans;
+	int grefs[1];
 
-	err = xenbus_grant_ring(pdev->xdev, virt_to_mfn(pdev->sh_info));
+	err = xenbus_grant_ring(pdev->xdev, pdev->sh_info, 1, grefs);
 	if (err < 0)
 		goto out;
 
-	pdev->gnt_ref = err;
+	pdev->gnt_ref = grefs[0];
 
 	err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn);
 	if (err)
drivers/scsi/xen-scsiback/common.h +2 -1
index dafa79e..4d13617 100644
@@ -150,7 +150,8 @@ typedef struct {
 
 irqreturn_t scsiback_intr(int, void *);
 int scsiback_init_sring(struct vscsibk_info *info,
-		unsigned long ring_ref, unsigned int evtchn);
+			int ring_ref[], int nr_refs,
+			unsigned int evtchn);
 int scsiback_schedule(void *data);
 
 
drivers/scsi/xen-scsiback/interface.c +4 -2
index 663568e..fad0a63 100644
@@ -60,7 +60,8 @@ struct vscsibk_info *vscsibk_info_alloc(domid_t domid)
 }
 
 int scsiback_init_sring(struct vscsibk_info *info,
-		unsigned long ring_ref, unsigned int evtchn)
+			int ring_ref[], int nr_refs,
+			unsigned int evtchn)
 {
 	struct vscsiif_sring *sring;
 	int err;
@@ -73,7 +74,8 @@ int scsiback_init_sring(struct vscsibk_info *info,
 		return -1;
 	}
 
-	err = xenbus_map_ring_valloc(info->dev, ring_ref, &info->ring_area);
+	err = xenbus_map_ring_valloc(info->dev, ring_ref, nr_refs,
+				     &info->ring_area);
 	if (err < 0)
 		return -ENOMEM;
 
drivers/scsi/xen-scsiback/xenbus.c +2 -2
index 2869f89..81d5598 100644
@@ -60,7 +60,7 @@ static int __vscsiif_name(struct backend_info *be, char *buf)
 static int scsiback_map(struct backend_info *be)
 {
 	struct xenbus_device *dev = be->dev;
-	unsigned long ring_ref = 0;
+	int ring_ref = 0;
 	unsigned int evtchn = 0;
 	int err;
 	char name[TASK_COMM_LEN];
@@ -72,7 +72,7 @@ static int scsiback_map(struct backend_info *be)
 		xenbus_dev_fatal(dev, err, "reading %s ring", dev->otherend);
 		return err;
 	}
-	err = scsiback_init_sring(be->info, ring_ref, evtchn);
+	err = scsiback_init_sring(be->info, &ring_ref, 1, evtchn);
 	if (err)
 		return err;
 
drivers/scsi/xen-scsifront/xenbus.c +3 -2
index bc5c289..8726410 100644
@@ -60,6 +60,7 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *info)
 	struct xenbus_device *dev = info->dev;
 	struct vscsiif_sring *sring;
 	int err = -ENOMEM;
+	int grefs[1];
 
 
 	info->ring_ref = GRANT_INVALID_REF;
@@ -73,14 +74,14 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *info)
 	SHARED_RING_INIT(sring);
 	FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(sring));
+	err = xenbus_grant_ring(dev, sring, 1, grefs);
 	if (err < 0) {
 		free_page((unsigned long) sring);
 		info->ring.sring = NULL;
 		xenbus_dev_fatal(dev, err, "fail to grant shared ring (Front to Back)");
 		goto free_sring;
 	}
-	info->ring_ref = err;
+	info->ring_ref = grefs[0];
 
 	err = xenbus_alloc_evtchn(dev, &info->evtchn);
 	if (err)
drivers/xen/xen-pciback/xenbus.c +6 -5
index 5a42ae7..0d8a98c 100644
@@ -98,17 +98,18 @@ static void free_pdev(struct xen_pcibk_device *pdev)
 	kfree(pdev);
 }
 
-static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref,
-			     int remote_evtchn)
+static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref[],
+			       int nr_grefs,
+			       int remote_evtchn)
 {
 	int err = 0;
 	void *vaddr;
 
 	dev_dbg(&pdev->xdev->dev,
 		"Attaching to frontend resources - gnt_ref=%d evtchn=%d\n",
-		gnt_ref, remote_evtchn);
+		gnt_ref[0], remote_evtchn);
 
-	err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, &vaddr);
+	err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, nr_grefs, &vaddr);
 	if (err < 0) {
 		xenbus_dev_fatal(pdev->xdev, err,
 				"Error mapping other domain page in ours.");
@@ -172,7 +173,7 @@ static int xen_pcibk_attach(struct xen_pcibk_device *pdev)
 		goto out;
 	}
 
-	err = xen_pcibk_do_attach(pdev, gnt_ref, remote_evtchn);
+	err = xen_pcibk_do_attach(pdev, &gnt_ref, 1, remote_evtchn);
 	if (err)
 		goto out;
 
Signature · 1 line
1.7.2.5
author
#31 lore raw

RFC PATCH v4 10/13 netback: multi page ring support

In reply to Wei Liu

Extend netback to support multi page ring.

---
 drivers/net/xen-netback/common.h    |   35 +++++++---
 drivers/net/xen-netback/interface.c |   43 ++++++++++--
 drivers/net/xen-netback/netback.c   |   74 ++++++++------------
 drivers/net/xen-netback/xenbus.c    |  129 +++++++++++++++++++++++++++++++++--
 4 files changed, 213 insertions(+), 68 deletions(-)
drivers/net/xen-netback/common.h +26 -9
index b7d4442..1bb16ec 100644
@@ -59,10 +59,18 @@ struct xenvif_rx_meta {
 
 #define MAX_BUFFER_OFFSET PAGE_SIZE
 
-#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE)
-#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)
+#define NETBK_TX_RING_SIZE(_nr_pages)					\
+	(__CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE * (_nr_pages)))
+#define NETBK_RX_RING_SIZE(_nr_pages)					\
+	(__CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE * (_nr_pages)))
 
-#define MAX_PENDING_REQS 256
+#define NETBK_MAX_RING_PAGE_ORDER XENBUS_MAX_RING_PAGE_ORDER
+#define NETBK_MAX_RING_PAGES      (1U << NETBK_MAX_RING_PAGE_ORDER)
+
+#define NETBK_MAX_TX_RING_SIZE NETBK_TX_RING_SIZE(NETBK_MAX_RING_PAGES)
+#define NETBK_MAX_RX_RING_SIZE NETBK_RX_RING_SIZE(NETBK_MAX_RING_PAGES)
+
+#define MAX_PENDING_REQS NETBK_MAX_TX_RING_SIZE
 
 struct xenvif {
 	/* Unique identifier for this interface. */
@@ -83,6 +91,8 @@ struct xenvif {
 	/* The shared rings and indexes. */
 	struct xen_netif_tx_back_ring tx;
 	struct xen_netif_rx_back_ring rx;
+	int nr_tx_handles;
+	int nr_rx_handles;
 
 	/* Frontend feature information. */
 	u8 can_sg:1;
@@ -132,8 +142,10 @@ struct xenvif *xenvif_alloc(struct device *parent,
 			    domid_t domid,
 			    unsigned int handle);
 
-int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
-		   unsigned long rx_ring_ref, unsigned int evtchn);
+int xenvif_connect(struct xenvif *vif,
+		   unsigned long tx_ring_ref[], unsigned int tx_ring_order,
+		   unsigned long rx_ring_ref[], unsigned int rx_ring_order,
+		   unsigned int evtchn);
 void xenvif_disconnect(struct xenvif *vif);
 
 int xenvif_xenbus_init(void);
@@ -146,10 +158,12 @@ int xenvif_rx_ring_full(struct xenvif *vif);
 int xenvif_must_stop_queue(struct xenvif *vif);
 
 /* (Un)Map communication rings. */
-void xenvif_unmap_frontend_rings(struct xenvif *vif);
-int xenvif_map_frontend_rings(struct xenvif *vif,
-			      grant_ref_t tx_ring_ref,
-			      grant_ref_t rx_ring_ref);
+void xenvif_unmap_frontend_ring(struct xenvif *vif, void *addr);
+int xenvif_map_frontend_ring(struct xenvif *vif,
+			     void **vaddr,
+			     int domid,
+			     int ring_ref[],
+			     unsigned int  ring_ref_count);
 
 /* Check for SKBs from frontend and schedule backend processing */
 void xenvif_check_rx_xenvif(struct xenvif *vif);
@@ -167,4 +181,7 @@ void xenvif_rx_action(struct xenvif *vif);
 
 int xenvif_kthread(void *data);
 
+extern unsigned int MODPARM_netback_max_tx_ring_page_order;
+extern unsigned int MODPARM_netback_max_rx_ring_page_order;
+
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +35 -8

75 lines not on this page · raw message

drivers/net/xen-netback/netback.c +30 -44

131 lines not on this page · raw message

drivers/net/xen-netback/xenbus.c +122 -7

161 lines not on this page · raw message

Signature · 1 line
1.7.2.5
author
#32 lore raw

RFC PATCH v4 11/13 netback: split event channels support

In reply to Wei Liu

Originally, netback and netfront only use one event channel to do tx / rx notification. This may cause unnecessary wake-up of NAPI / kthread.

When guest tx is completed, netback will only notify tx_irq.

If feature-split-event-channels ==0, rx_irq = tx_irq, so RX protocol will just work as expected.

---
 drivers/net/xen-netback/common.h    |    7 ++-
 drivers/net/xen-netback/interface.c |   82 +++++++++++++++++++++++++++--------
 drivers/net/xen-netback/netback.c   |    4 +-
 drivers/net/xen-netback/xenbus.c    |   51 +++++++++++++++++----
 4 files changed, 111 insertions(+), 33 deletions(-)
drivers/net/xen-netback/common.h +4 -3
index 1bb16ec..a0497fc 100644
@@ -85,8 +85,9 @@ struct xenvif {
 
 	u8               fe_dev_addr[6];
 
-	/* Physical parameters of the comms window. */
-	unsigned int     irq;
+	/* When feature-split-event-channels = 0, tx_irq = rx_irq */
+	unsigned int tx_irq;
+	unsigned int rx_irq;
 
 	/* The shared rings and indexes. */
 	struct xen_netif_tx_back_ring tx;
@@ -145,7 +146,7 @@ struct xenvif *xenvif_alloc(struct device *parent,
 int xenvif_connect(struct xenvif *vif,
 		   unsigned long tx_ring_ref[], unsigned int tx_ring_order,
 		   unsigned long rx_ring_ref[], unsigned int rx_ring_order,
-		   unsigned int evtchn);
+		   unsigned int tx_evtchn, unsigned int rx_evtchn);
 void xenvif_disconnect(struct xenvif *vif);
 
 int xenvif_xenbus_init(void);
drivers/net/xen-netback/interface.c +64 -18

141 lines not on this page · raw message

drivers/net/xen-netback/netback.c +2 -2
index 60c8951..957cf9d 100644
@@ -622,7 +622,7 @@ void xenvif_rx_action(struct xenvif *vif)
 	}
 
 	if (need_to_notify)
-		notify_remote_via_irq(vif->irq);
+		notify_remote_via_irq(vif->rx_irq);
 
 	if (!skb_queue_empty(&vif->rx_queue))
 		xenvif_kick_thread(vif);
@@ -1392,7 +1392,7 @@ static void make_tx_response(struct xenvif *vif,
 	vif->tx.rsp_prod_pvt = ++i;
 	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->tx, notify);
 	if (notify)
-		notify_remote_via_irq(vif->irq);
+		notify_remote_via_irq(vif->tx_irq);
 }
 
 static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
drivers/net/xen-netback/xenbus.c +41 -10

78 lines not on this page · raw message

Signature · 1 line
1.7.2.5
author
#33 lore raw

RFC PATCH v4 12/13 netfront: multi page ring support.

In reply to Wei Liu
---
 drivers/net/xen-netfront.c |  228 ++++++++++++++++++++++++++++++--------------
 1 files changed, 156 insertions(+), 72 deletions(-)
drivers/net/xen-netfront.c +156 -72
index b7ff815..a1cfb24 100644
@@ -66,9 +66,18 @@ struct netfront_cb {
 
 #define GRANT_INVALID_REF	0
 
-#define NET_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE)
-#define NET_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)
-#define TX_MAX_TARGET min_t(int, NET_TX_RING_SIZE, 256)
+#define XENNET_MAX_RING_PAGE_ORDER 2
+#define XENNET_MAX_RING_PAGES      (1U << XENNET_MAX_RING_PAGE_ORDER)
+
+#define NET_TX_RING_SIZE(_nr_pages)					\
+	__CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE * (_nr_pages))
+#define NET_RX_RING_SIZE(_nr_pages)					\
+	__CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE * (_nr_pages))
+
+#define XENNET_MAX_TX_RING_SIZE NET_TX_RING_SIZE(XENNET_MAX_RING_PAGES)
+#define XENNET_MAX_RX_RING_SIZE NET_RX_RING_SIZE(XENNET_MAX_RING_PAGES)
+
+#define TX_MAX_TARGET XENNET_MAX_TX_RING_SIZE
 
 struct netfront_stats {
 	u64			rx_packets;
@@ -84,12 +93,19 @@ struct netfront_info {
 
 	struct napi_struct napi;
 
+	/* Statistics */
+	struct netfront_stats __percpu *stats;
+
+	unsigned long rx_gso_checksum_fixup;
+
 	unsigned int evtchn;
 	struct xenbus_device *xbdev;
 
 	spinlock_t   tx_lock;
 	struct xen_netif_tx_front_ring tx;
-	int tx_ring_ref;
+	int tx_ring_ref[XENNET_MAX_RING_PAGES];
+	int tx_ring_page_order;
+	int tx_ring_pages;
 
 	/*
 	 * {tx,rx}_skbs store outstanding skbuffs. Free tx_skb entries
@@ -103,36 +119,33 @@ struct netfront_info {
 	union skb_entry {
 		struct sk_buff *skb;
 		unsigned long link;
-	} tx_skbs[NET_TX_RING_SIZE];
+	} tx_skbs[XENNET_MAX_TX_RING_SIZE];
 	grant_ref_t gref_tx_head;
-	grant_ref_t grant_tx_ref[NET_TX_RING_SIZE];
+	grant_ref_t grant_tx_ref[XENNET_MAX_TX_RING_SIZE];
 	unsigned tx_skb_freelist;
 
 	spinlock_t   rx_lock ____cacheline_aligned_in_smp;
 	struct xen_netif_rx_front_ring rx;
-	int rx_ring_ref;
+	int rx_ring_ref[XENNET_MAX_RING_PAGES];
+	int rx_ring_page_order;
+	int rx_ring_pages;
 
 	/* Receive-ring batched refills. */
 #define RX_MIN_TARGET 8
 #define RX_DFL_MIN_TARGET 64
-#define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
+#define RX_MAX_TARGET XENNET_MAX_RX_RING_SIZE
 	unsigned rx_min_target, rx_max_target, rx_target;
 	struct sk_buff_head rx_batch;
 
 	struct timer_list rx_refill_timer;
 
-	struct sk_buff *rx_skbs[NET_RX_RING_SIZE];
+	struct sk_buff *rx_skbs[XENNET_MAX_RX_RING_SIZE];
 	grant_ref_t gref_rx_head;
-	grant_ref_t grant_rx_ref[NET_RX_RING_SIZE];
-
-	unsigned long rx_pfn_array[NET_RX_RING_SIZE];
-	struct multicall_entry rx_mcl[NET_RX_RING_SIZE+1];
-	struct mmu_update rx_mmu[NET_RX_RING_SIZE];
-
-	/* Statistics */
-	struct netfront_stats __percpu *stats;
+	grant_ref_t grant_rx_ref[XENNET_MAX_RX_RING_SIZE];
 
-	unsigned long rx_gso_checksum_fixup;
+	unsigned long rx_pfn_array[XENNET_MAX_RX_RING_SIZE];
+	struct multicall_entry rx_mcl[XENNET_MAX_RX_RING_SIZE+1];
+	struct mmu_update rx_mmu[XENNET_MAX_RX_RING_SIZE];
 };
 
 struct netfront_rx_info {
@@ -170,15 +183,15 @@ static unsigned short get_id_from_freelist(unsigned *head,
 	return id;
 }
 
-static int xennet_rxidx(RING_IDX idx)
+static int xennet_rxidx(RING_IDX idx, struct netfront_info *info)
 {
-	return idx & (NET_RX_RING_SIZE - 1);
+	return idx & (NET_RX_RING_SIZE(info->rx_ring_pages) - 1);
 }
 
 static struct sk_buff *xennet_get_rx_skb(struct netfront_info *np,
 					 RING_IDX ri)
 {
-	int i = xennet_rxidx(ri);
+	int i = xennet_rxidx(ri, np);
 	struct sk_buff *skb = np->rx_skbs[i];
 	np->rx_skbs[i] = NULL;
 	return skb;
@@ -187,7 +200,7 @@ static struct sk_buff *xennet_get_rx_skb(struct netfront_info *np,
 static grant_ref_t xennet_get_rx_ref(struct netfront_info *np,
 					    RING_IDX ri)
 {
-	int i = xennet_rxidx(ri);
+	int i = xennet_rxidx(ri, np);
 	grant_ref_t ref = np->grant_rx_ref[i];
 	np->grant_rx_ref[i] = GRANT_INVALID_REF;
 	return ref;
@@ -300,7 +313,7 @@ no_skb:
 
 		skb->dev = dev;
 
-		id = xennet_rxidx(req_prod + i);
+		id = xennet_rxidx(req_prod + i, np);
 
 		BUG_ON(np->rx_skbs[id]);
 		np->rx_skbs[id] = skb;
@@ -596,7 +609,7 @@ static int xennet_close(struct net_device *dev)
 static void xennet_move_rx_slot(struct netfront_info *np, struct sk_buff *skb,
 				grant_ref_t ref)
 {
-	int new = xennet_rxidx(np->rx.req_prod_pvt);
+	int new = xennet_rxidx(np->rx.req_prod_pvt, np);
 
 	BUG_ON(np->rx_skbs[new]);
 	np->rx_skbs[new] = skb;
@@ -1089,7 +1102,7 @@ static void xennet_release_tx_bufs(struct netfront_info *np)
 	struct sk_buff *skb;
 	int i;
 
-	for (i = 0; i < NET_TX_RING_SIZE; i++) {
+	for (i = 0; i < NET_TX_RING_SIZE(np->tx_ring_pages); i++) {
 		/* Skip over entries which are actually freelist references */
 		if (skb_entry_is_link(&np->tx_skbs[i]))
 			continue;
@@ -1123,7 +1136,7 @@ static void xennet_release_rx_bufs(struct netfront_info *np)
 
 	spin_lock_bh(&np->rx_lock);
 
-	for (id = 0; id < NET_RX_RING_SIZE; id++) {
+	for (id = 0; id < NET_RX_RING_SIZE(np->rx_ring_pages); id++) {
 		ref = np->grant_rx_ref[id];
 		if (ref == GRANT_INVALID_REF) {
 			unused++;
@@ -1305,13 +1318,13 @@ static struct net_device * __devinit xennet_create_dev(struct xenbus_device *dev
 
 	/* Initialise tx_skbs as a free chain containing every entry. */
 	np->tx_skb_freelist = 0;
-	for (i = 0; i < NET_TX_RING_SIZE; i++) {
+	for (i = 0; i < XENNET_MAX_TX_RING_SIZE; i++) {
 		skb_entry_set_link(&np->tx_skbs[i], i+1);
 		np->grant_tx_ref[i] = GRANT_INVALID_REF;
 	}
 
 	/* Clear out rx_skbs */
-	for (i = 0; i < NET_RX_RING_SIZE; i++) {
+	for (i = 0; i < XENNET_MAX_RX_RING_SIZE; i++) {
 		np->rx_skbs[i] = NULL;
 		np->grant_rx_ref[i] = GRANT_INVALID_REF;
 	}
@@ -1409,13 +1422,6 @@ static int __devinit netfront_probe(struct xenbus_device *dev,
 	return err;
 }
 
-static void xennet_end_access(int ref, void *page)
-{
-	/* This frees the page as a side-effect */
-	if (ref != GRANT_INVALID_REF)
-		gnttab_end_foreign_access(ref, 0, (unsigned long)page);
-}
-
 static void xennet_disconnect_backend(struct netfront_info *info)
 {
 	/* Stop old i/f to prevent errors whilst we rebuild the state. */
@@ -1429,12 +1435,12 @@ static void xennet_disconnect_backend(struct netfront_info *info)
 		unbind_from_irqhandler(info->netdev->irq, info->netdev);
 	info->evtchn = info->netdev->irq = 0;
 
-	/* End access and free the pages */
-	xennet_end_access(info->tx_ring_ref, info->tx.sring);
-	xennet_end_access(info->rx_ring_ref, info->rx.sring);
+	xenbus_unmap_ring_vfree(info->xbdev, (void *)info->tx.sring);
+	free_pages((unsigned long)info->tx.sring, info->tx_ring_page_order);
+
+	xenbus_unmap_ring_vfree(info->xbdev, (void *)info->rx.sring);
+	free_pages((unsigned long)info->rx.sring, info->rx_ring_page_order);
 
-	info->tx_ring_ref = GRANT_INVALID_REF;
-	info->rx_ring_ref = GRANT_INVALID_REF;
 	info->tx.sring = NULL;
 	info->rx.sring = NULL;
 }
@@ -1482,11 +1488,14 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	struct xen_netif_tx_sring *txs;
 	struct xen_netif_rx_sring *rxs;
 	int err;
-	int grefs[1];
 	struct net_device *netdev = info->netdev;
+	unsigned int max_tx_ring_page_order, max_rx_ring_page_order;
+	int i;
 
-	info->tx_ring_ref = GRANT_INVALID_REF;
-	info->rx_ring_ref = GRANT_INVALID_REF;
+	for (i = 0; i < XENNET_MAX_RING_PAGES; i++) {
+		info->tx_ring_ref[i] = GRANT_INVALID_REF;
+		info->rx_ring_ref[i] = GRANT_INVALID_REF;
+	}
 	info->rx.sring = NULL;
 	info->tx.sring = NULL;
 	netdev->irq = 0;
@@ -1497,50 +1506,91 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		goto fail;
 	}
 
-	txs = (struct xen_netif_tx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			   "max-tx-ring-page-order", "%u",
+			   &max_tx_ring_page_order);
+	if (err < 0) {
+		info->tx_ring_page_order = 0;
+		dev_info(&dev->dev, "single tx ring\n");
+	} else {
+		info->tx_ring_page_order = max_tx_ring_page_order;
+		dev_info(&dev->dev, "multi page tx ring, order = %d\n",
+			 max_tx_ring_page_order);
+	}
+	info->tx_ring_pages = (1U << info->tx_ring_page_order);
+
+	txs = (struct xen_netif_tx_sring *)
+		__get_free_pages(__GFP_ZERO | GFP_NOIO | __GFP_HIGH,
+				 info->tx_ring_page_order);
 	if (!txs) {
 		err = -ENOMEM;
 		xenbus_dev_fatal(dev, err, "allocating tx ring page");
 		goto fail;
 	}
 	SHARED_RING_INIT(txs);
-	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
+	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE * info->tx_ring_pages);
+
+	err = xenbus_grant_ring(dev, txs, info->tx_ring_pages,
+				info->tx_ring_ref);
+
+	if (err < 0)
+		goto grant_tx_ring_fail;
 
-	err = xenbus_grant_ring(dev, txs, 1, grefs);
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			   "max-rx-ring-page-order", "%u",
+			   &max_rx_ring_page_order);
 	if (err < 0) {
-		free_page((unsigned long)txs);
-		goto fail;
+		info->rx_ring_page_order = 0;
+		dev_info(&dev->dev, "single rx ring\n");
+	} else {
+		info->rx_ring_page_order = max_rx_ring_page_order;
+		dev_info(&dev->dev, "multi page rx ring, order = %d\n",
+			 max_rx_ring_page_order);
 	}
+	info->rx_ring_pages = (1U << info->rx_ring_page_order);
 
-	info->tx_ring_ref = grefs[0];
-	rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
+	rxs = (struct xen_netif_rx_sring *)
+		__get_free_pages(__GFP_ZERO | GFP_NOIO | __GFP_HIGH,
+				 info->rx_ring_page_order);
 	if (!rxs) {
 		err = -ENOMEM;
 		xenbus_dev_fatal(dev, err, "allocating rx ring page");
-		goto fail;
+		goto alloc_rx_ring_fail;
 	}
 	SHARED_RING_INIT(rxs);
-	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
+	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE * info->rx_ring_pages);
 
-	err = xenbus_grant_ring(dev, rxs, 1, grefs);
-	if (err < 0) {
-		free_page((unsigned long)rxs);
-		goto fail;
-	}
-	info->rx_ring_ref = grefs[0];
+	err = xenbus_grant_ring(dev, rxs, info->rx_ring_pages,
+				info->rx_ring_ref);
+
+	if (err < 0)
+		goto grant_rx_ring_fail;
+
+	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE * info->rx_ring_pages);
 
 	err = xenbus_alloc_evtchn(dev, &info->evtchn);
 	if (err)
-		goto fail;
+		goto alloc_evtchn_fail;
 
 	err = bind_evtchn_to_irqhandler(info->evtchn, xennet_interrupt,
 					0, netdev->name, netdev);
 	if (err < 0)
-		goto fail;
+		goto bind_fail;
 	netdev->irq = err;
+
 	return 0;
 
- fail:
+bind_fail:
+	xenbus_free_evtchn(dev, info->evtchn);
+alloc_evtchn_fail:
+	xenbus_unmap_ring_vfree(info->xbdev, (void *)info->rx.sring);
+grant_rx_ring_fail:
+	free_pages((unsigned long)info->rx.sring, info->rx_ring_page_order);
+alloc_rx_ring_fail:
+	xenbus_unmap_ring_vfree(info->xbdev, (void *)info->tx.sring);
+grant_tx_ring_fail:
+	free_pages((unsigned long)info->tx.sring, info->tx_ring_page_order);
+fail:
 	return err;
 }
 
@@ -1551,6 +1601,7 @@ static int talk_to_netback(struct xenbus_device *dev,
 	const char *message;
 	struct xenbus_transaction xbt;
 	int err;
+	int i;
 
 	/* Create shared ring, alloc event channel. */
 	err = setup_netfront(dev, info);
@@ -1564,18 +1615,50 @@ again:
 		goto destroy_ring;
 	}
 
-	err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref", "%u",
-			    info->tx_ring_ref);
-	if (err) {
-		message = "writing tx ring-ref";
-		goto abort_transaction;
+	if (info->tx_ring_page_order == 0)
+		err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref", "%u",
+				    info->tx_ring_ref[0]);
+	else {
+		err = xenbus_printf(xbt, dev->nodename, "tx-ring-order", "%u",
+				    info->tx_ring_page_order);
+		if (err) {
+			message = "writing tx ring-ref";
+			goto abort_transaction;
+		}
+		for (i = 0; i < info->tx_ring_pages; i++) {
+			char name[sizeof("tx-ring-ref")+2];
+			snprintf(name, sizeof(name), "tx-ring-ref%u", i);
+			err = xenbus_printf(xbt, dev->nodename, name, "%u",
+					    info->tx_ring_ref[i]);
+			if (err) {
+				message = "writing tx ring-ref";
+				goto abort_transaction;
+			}
+		}
 	}
-	err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref", "%u",
-			    info->rx_ring_ref);
-	if (err) {
-		message = "writing rx ring-ref";
-		goto abort_transaction;
+
+	if (info->rx_ring_page_order == 0)
+		err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref", "%u",
+				    info->rx_ring_ref[0]);
+	else {
+		err = xenbus_printf(xbt, dev->nodename, "rx-ring-order", "%u",
+				    info->rx_ring_page_order);
+		if (err) {
+			message = "writing tx ring-ref";
+			goto abort_transaction;
+		}
+		for (i = 0; i < info->rx_ring_pages; i++) {
+			char name[sizeof("rx-ring-ref")+2];
+			snprintf(name, sizeof(name), "rx-ring-ref%u", i);
+			err = xenbus_printf(xbt, dev->nodename, name, "%u",
+					    info->rx_ring_ref[i]);
+			if (err) {
+				message = "writing rx ring-ref";
+				goto abort_transaction;
+			}
+		}
 	}
+
 	err = xenbus_printf(xbt, dev->nodename,
 			    "event-channel", "%u", info->evtchn);
 	if (err) {
@@ -1662,7 +1745,8 @@ static int xennet_connect(struct net_device *dev)
 	xennet_release_tx_bufs(np);
 
 	/* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
-	for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
+	for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE(np->rx_ring_pages);
+	     i++) {
 		skb_frag_t *frag;
 		const struct page *page;
 		if (!np->rx_skbs[i])
Signature · 1 line
1.7.2.5
#34 lore raw

Re: [RFC PATCH V4 12/13] netfront: multi page ring support.

Quoted 2 lines · Wei Liu

It also needs this:

Quoted 1 line

From 4cf97c025792cf073edc4d312b962ecc0b3b67ab Mon Sep 17 00:00:00 2001

From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 15 Feb 2012 17:39:46 -0500
Subject: [PATCH] xen/net: Don't try to use all of the rings if we are not
built for it.

Otherwise we end up:

BUG: unable to handle kernel paging request at ffff88004000c0c8
IP: [<ffffffff810f1ee4>] free_one_page+0x144/0x410

PGD 1806063 PUD 0
22:22:34 tst007 logger: /etc/xen/scripts/vif-bridge: offline XENBUS_PATH=backend/vif/1/0 00 [#1] SMP
CPU 0

Modules linked in:

Pid: 17, comm: xenwatch Not tainted 3.2.0upstream #2 Xen HVM domU

RIP: 0010:[<ffffffff810f1ee4>]  [<ffffffff810f1ee4>] free_one_page+0x144/0x410
RSP: 0018:ffff88003bea3c40  EFLAGS: 00010046
.. snip.
Call Trace:
 [<ffffffff810f2c7f>] __free_pages_ok+0x9f/0xe0
 [<ffffffff810f4eab>] __free_pages+0x1b/0x40
 [<ffffffff810f4f1a>] free_pages+0x4a/0x60
 [<ffffffff8138b33d>] xennet_disconnect_backend+0xbd/0x130
 [<ffffffff8138bd88>] talk_to_netback+0x8e8/0x1160
 [<ffffffff812f4e28>] ? xenbus_gather+0xd8/0x170
 [<ffffffff8138e3bd>] netback_changed+0xcd/0x550
 [<ffffffff812f5bb8>] xenbus_otherend_changed+0xa8/0xb0
---
 drivers/net/xen-netfront.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/net/xen-netfront.c +13 -1
index 0223552..1eadd90 100644
@@ -29,6 +29,8 @@
  * IN THE SOFTWARE.
  */
 
+#define DEBUG 1
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
@@ -66,7 +68,7 @@ struct netfront_cb {
 
 #define GRANT_INVALID_REF	0
 
-#define XENNET_MAX_RING_PAGE_ORDER 2
+#define XENNET_MAX_RING_PAGE_ORDER 4
 #define XENNET_MAX_RING_PAGES      (1U << XENNET_MAX_RING_PAGE_ORDER)
 
 #define NET_TX_RING_SIZE(_nr_pages)					\
@@ -1611,6 +1613,11 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		info->tx_ring_page_order = 0;
 		dev_info(&dev->dev, "single tx ring\n");
 	} else {
+		if (max_tx_ring_page_order > XENNET_MAX_RING_PAGE_ORDER) {
+			dev_warn(&dev->dev, "Backend can do %d pages but we can only do %d!\n",
+				max_tx_ring_page_order, XENNET_MAX_RING_PAGE_ORDER);
+			max_tx_ring_page_order = XENNET_MAX_RING_PAGE_ORDER;
+		}
 		info->tx_ring_page_order = max_tx_ring_page_order;
 		dev_info(&dev->dev, "multi page tx ring, order = %d\n",
 			 max_tx_ring_page_order);
@@ -1642,6 +1649,11 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		dev_info(&dev->dev, "single rx ring\n");
 	} else {
 		info->rx_ring_page_order = max_rx_ring_page_order;
+		if (max_rx_ring_page_order > XENNET_MAX_RING_PAGE_ORDER) {
+			dev_warn(&dev->dev, "Backend can do %d pages but we can only do %d!\n",
+				max_rx_ring_page_order, XENNET_MAX_RING_PAGE_ORDER);
+			max_rx_ring_page_order = XENNET_MAX_RING_PAGE_ORDER;
+		}
 		dev_info(&dev->dev, "multi page rx ring, order = %d\n",
 			 max_rx_ring_page_order);
 	}
Signature · 1 line
1.7.9.48.g85da4d
maintainer
#35 lore raw

Re: [RFC PATCH V4 12/13] netfront: multi page ring support.

From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 15 Feb 2012 17:42:53 -0500

drivers/net/xen-netfront.c line 36

Quoted 9 lines
drivers/net/xen-netfront.c +2 -0
@@ -29,6 +29,8 @@
  * IN THE SOFTWARE.
  */
 
+#define DEBUG 1
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>

This is never appropriate.

#36 lore raw

Re: [RFC PATCH V4 12/13] netfront: multi page ring support.

Quoted 7 lines · David Miller

From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 15 Feb 2012 17:42:53 -0500

Quoted 4 lines
drivers/net/xen-netfront.c +0 -0
@@ -29,6 +29,8 @@
  * IN THE SOFTWARE.
  */
 
Quoted 7 lines

drivers/net/xen-netfront.c line 36

Quoted 5 lines
drivers/net/xen-netfront.c +2 -0
+#define DEBUG 1
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>

This is never appropriate.

HA! No it is not. Thanks for spotting it.

I was thinking that Liu would actually squash the fix the patch I responded to.

author
#37 lore raw

Re: [RFC PATCH V4 12/13] netfront: multi page ring support.

In reply to Konrad Rzeszutek Wilk
Quoted 55 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Wei Liu

It also needs this:

From 4cf97c025792cf073edc4d312b962ecc0b3b67ab Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 15 Feb 2012 17:39:46 -0500
Subject: [PATCH] xen/net: Don't try to use all of the rings if we are not
built for it.

Otherwise we end up:

BUG: unable to handle kernel paging request at ffff88004000c0c8
IP: [<ffffffff810f1ee4>] free_one_page+0x144/0x410

PGD 1806063 PUD 0
22:22:34 tst007 logger: /etc/xen/scripts/vif-bridge: offline XENBUS_PATH=backend/vif/1/0 00 [#1] SMP
CPU 0

Modules linked in:

Pid: 17, comm: xenwatch Not tainted 3.2.0upstream #2 Xen HVM domU

RIP: 0010:[<ffffffff810f1ee4>]  [<ffffffff810f1ee4>] free_one_page+0x144/0x410
RSP: 0018:ffff88003bea3c40  EFLAGS: 00010046
.. snip.
Call Trace:
 [<ffffffff810f2c7f>] __free_pages_ok+0x9f/0xe0
 [<ffffffff810f4eab>] __free_pages+0x1b/0x40
 [<ffffffff810f4f1a>] free_pages+0x4a/0x60
 [<ffffffff8138b33d>] xennet_disconnect_backend+0xbd/0x130
 [<ffffffff8138bd88>] talk_to_netback+0x8e8/0x1160
 [<ffffffff812f4e28>] ? xenbus_gather+0xd8/0x170
 [<ffffffff8138e3bd>] netback_changed+0xcd/0x550
 [<ffffffff812f5bb8>] xenbus_otherend_changed+0xa8/0xb0
---
 drivers/net/xen-netfront.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/net/xen-netfront.c +2 -0
index 0223552..1eadd90 100644
@@ -29,6 +29,8 @@
  * IN THE SOFTWARE.
  */
 
+#define DEBUG 1
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>

drivers/net/xen-netfront.c struct netfront_cb { · line 71

Quoted 5 lines
drivers/net/xen-netfront.c +1 -1
@@ -66,7 +68,7 @@ struct netfront_cb {
 
 #define GRANT_INVALID_REF	0
 
-#define XENNET_MAX_RING_PAGE_ORDER 2
+#define XENNET_MAX_RING_PAGE_ORDER 4

I guess this is you tuning with page order? And here is not the only one place you changed?

As a matter of fact, in the previous patch 8 I encode hard limit 2 on the ring page order, your change here will stop FE / BE from connecting.

I think I will also need to change this to something like

  #define XENNET_MAX_RING_PAGE_ORDER XENBUS_MAX_RING_PAGE_ORDER

to remind people to modify that value.

Quoted 17 lines
drivers/net/xen-netfront.c +5 -0
 #define XENNET_MAX_RING_PAGES      (1U << XENNET_MAX_RING_PAGE_ORDER)
 
 #define NET_TX_RING_SIZE(_nr_pages)					\
@@ -1611,6 +1613,11 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		info->tx_ring_page_order = 0;
 		dev_info(&dev->dev, "single tx ring\n");
 	} else {
+		if (max_tx_ring_page_order > XENNET_MAX_RING_PAGE_ORDER) {
+			dev_warn(&dev->dev, "Backend can do %d pages but we can only do %d!\n",
+				max_tx_ring_page_order, XENNET_MAX_RING_PAGE_ORDER);
+			max_tx_ring_page_order = XENNET_MAX_RING_PAGE_ORDER;
+		}
 		info->tx_ring_page_order = max_tx_ring_page_order;
 		dev_info(&dev->dev, "multi page tx ring, order = %d\n",
 			 max_tx_ring_page_order);
@@ -1642,6 +1649,11 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		dev_info(&dev->dev, "single rx ring\n");

drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1659

Quoted 10 lines
drivers/net/xen-netfront.c +5 -0
 	} else {
 		info->rx_ring_page_order = max_rx_ring_page_order;
+		if (max_rx_ring_page_order > XENNET_MAX_RING_PAGE_ORDER) {
+			dev_warn(&dev->dev, "Backend can do %d pages but we can only do %d!\n",
+				max_rx_ring_page_order, XENNET_MAX_RING_PAGE_ORDER);
+			max_rx_ring_page_order = XENNET_MAX_RING_PAGE_ORDER;
+		}
 		dev_info(&dev->dev, "multi page rx ring, order = %d\n",
 			 max_rx_ring_page_order);
 	}

Thanks for this, I will squash it into my patch.

Wei.

author
#38 lore raw

Re: [RFC PATCH V4 12/13] netfront: multi page ring support.

Quoted 65 lines · Wei Liu (Intern)
Quoted 55 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Wei Liu

It also needs this:

From 4cf97c025792cf073edc4d312b962ecc0b3b67ab Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 15 Feb 2012 17:39:46 -0500
Subject: [PATCH] xen/net: Don't try to use all of the rings if we are not
built for it.

Otherwise we end up:

BUG: unable to handle kernel paging request at ffff88004000c0c8
IP: [<ffffffff810f1ee4>] free_one_page+0x144/0x410

PGD 1806063 PUD 0
22:22:34 tst007 logger: /etc/xen/scripts/vif-bridge: offline XENBUS_PATH=backend/vif/1/0 00 [#1] SMP
CPU 0

Modules linked in:

Pid: 17, comm: xenwatch Not tainted 3.2.0upstream #2 Xen HVM domU

RIP: 0010:[<ffffffff810f1ee4>]  [<ffffffff810f1ee4>] free_one_page+0x144/0x410
RSP: 0018:ffff88003bea3c40  EFLAGS: 00010046
.. snip.
Call Trace:
 [<ffffffff810f2c7f>] __free_pages_ok+0x9f/0xe0
 [<ffffffff810f4eab>] __free_pages+0x1b/0x40
 [<ffffffff810f4f1a>] free_pages+0x4a/0x60
 [<ffffffff8138b33d>] xennet_disconnect_backend+0xbd/0x130
 [<ffffffff8138bd88>] talk_to_netback+0x8e8/0x1160
 [<ffffffff812f4e28>] ? xenbus_gather+0xd8/0x170
 [<ffffffff8138e3bd>] netback_changed+0xcd/0x550
 [<ffffffff812f5bb8>] xenbus_otherend_changed+0xa8/0xb0
---
 drivers/net/xen-netfront.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/net/xen-netfront.c +2 -0
index 0223552..1eadd90 100644
@@ -29,6 +29,8 @@
  * IN THE SOFTWARE.
  */
 
+#define DEBUG 1
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>

drivers/net/xen-netfront.c struct netfront_cb { · line 71

Quoted 5 lines
drivers/net/xen-netfront.c +1 -1
@@ -66,7 +68,7 @@ struct netfront_cb {
 
 #define GRANT_INVALID_REF	0
 
-#define XENNET_MAX_RING_PAGE_ORDER 2
+#define XENNET_MAX_RING_PAGE_ORDER 4

I guess this is you tuning with page order? And here is not the only one place you changed?

Quoted 9 lines

As a matter of fact, in the previous patch 8 I encode hard limit 2 on the ring page order, your change here will stop FE / BE from connecting.

I think I will also need to change this to something like

  #define XENNET_MAX_RING_PAGE_ORDER XENBUS_MAX_RING_PAGE_ORDER

to remind people to modify that value.

To be more precise on this, tangling with RING_PAGE_ORDER will not affect FE, because the mapping is done in BE. However if you make RING_PAGE_ORDER larger than BE limit, it will fail.

So the above #define is actually asking people playing with FE to check BE limit. :-(

Wei.

#39 lore raw

Re: [RFC PATCH V4 12/13] netfront: multi page ring support.

Quoted 16 lines
Quoted 6 lines

drivers/net/xen-netfront.c struct netfront_cb { · line 71

Quoted 2 lines
drivers/net/xen-netfront.c +1 -1
-#define XENNET_MAX_RING_PAGE_ORDER 2
+#define XENNET_MAX_RING_PAGE_ORDER 4

I guess this is you tuning with page order? And here is not the only one place you changed?

Quoted 9 lines

As a matter of fact, in the previous patch 8 I encode hard limit 2 on the ring page order, your change here will stop FE / BE from connecting.

I think I will also need to change this to something like

  #define XENNET_MAX_RING_PAGE_ORDER XENBUS_MAX_RING_PAGE_ORDER

to remind people to modify that value.

Quoted 6 lines

To be more precise on this, tangling with RING_PAGE_ORDER will not affect FE, because the mapping is done in BE. However if you make RING_PAGE_ORDER larger than BE limit, it will fail.

So the above #define is actually asking people playing with FE to check BE limit. :-(

Say that in two years we decide that the ring order in the FE should be 256, and we also change that in the backend. Some customers might still be running with the old backends which advertise only 4.

Or vice-versa. The users run a brand new BE which advertises 256 and the user is running a frontend that can only do 4. It (frontend) should be able to safely negotiate the proper minimum value.

#40 lore raw

Re: [RFC PATCH V4 12/13] netfront: multi page ring support.

In reply to Wei Liu
Quoted 57 lines · Wei Liu
Quoted 56 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Wei Liu

It also needs this:

From 4cf97c025792cf073edc4d312b962ecc0b3b67ab Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 15 Feb 2012 17:39:46 -0500
Subject: [PATCH] xen/net: Don't try to use all of the rings if we are not
built for it.

Otherwise we end up:

BUG: unable to handle kernel paging request at ffff88004000c0c8
IP: [<ffffffff810f1ee4>] free_one_page+0x144/0x410

PGD 1806063 PUD 0
22:22:34 tst007 logger: /etc/xen/scripts/vif-bridge: offline XENBUS_PATH=backend/vif/1/0 00 [#1] SMP
CPU 0

Modules linked in:

Pid: 17, comm: xenwatch Not tainted 3.2.0upstream #2 Xen HVM domU

RIP: 0010:[<ffffffff810f1ee4>]  [<ffffffff810f1ee4>] free_one_page+0x144/0x410
RSP: 0018:ffff88003bea3c40  EFLAGS: 00010046
.. snip.
Call Trace:
 [<ffffffff810f2c7f>] __free_pages_ok+0x9f/0xe0
 [<ffffffff810f4eab>] __free_pages+0x1b/0x40
 [<ffffffff810f4f1a>] free_pages+0x4a/0x60
 [<ffffffff8138b33d>] xennet_disconnect_backend+0xbd/0x130
 [<ffffffff8138bd88>] talk_to_netback+0x8e8/0x1160
 [<ffffffff812f4e28>] ? xenbus_gather+0xd8/0x170
 [<ffffffff8138e3bd>] netback_changed+0xcd/0x550
 [<ffffffff812f5bb8>] xenbus_otherend_changed+0xa8/0xb0
---
 drivers/net/xen-netfront.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/net/xen-netfront.c +2 -0
index 0223552..1eadd90 100644
@@ -29,6 +29,8 @@
  * IN THE SOFTWARE.
  */
 
+#define DEBUG 1
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
@@ -66,7 +68,7 @@ struct netfront_cb {
 
Quoted 7 lines

drivers/net/xen-netfront.c struct netfront_cb { · line 71

Quoted 4 lines
drivers/net/xen-netfront.c +1 -1
 #define GRANT_INVALID_REF	0
 
-#define XENNET_MAX_RING_PAGE_ORDER 2
+#define XENNET_MAX_RING_PAGE_ORDER 4

I guess this is you tuning with page order? And here is not the only one place you changed?

Yup. Was playing with it and saw this blow up.

Quoted 3 lines

As a matter of fact, in the previous patch 8 I encode hard limit 2 on the ring page order, your change here will stop FE / BE from connecting.

I think it will work OK - it will just use up to 4 instead of the default two.

Quoted 6 lines

I think I will also need to change this to something like

  #define XENNET_MAX_RING_PAGE_ORDER XENBUS_MAX_RING_PAGE_ORDER

to remind people to modify that value.

<nods>

Quoted 22 lines
Quoted 22 lines
drivers/net/xen-netfront.c +7 -0
 #define XENNET_MAX_RING_PAGES      (1U << XENNET_MAX_RING_PAGE_ORDER)
 
 #define NET_TX_RING_SIZE(_nr_pages)					\
@@ -1611,6 +1613,11 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		info->tx_ring_page_order = 0;
 		dev_info(&dev->dev, "single tx ring\n");
 	} else {
+		if (max_tx_ring_page_order > XENNET_MAX_RING_PAGE_ORDER) {
+			dev_warn(&dev->dev, "Backend can do %d pages but we can only do %d!\n",
+				max_tx_ring_page_order, XENNET_MAX_RING_PAGE_ORDER);
+			max_tx_ring_page_order = XENNET_MAX_RING_PAGE_ORDER;
+		}
 		info->tx_ring_page_order = max_tx_ring_page_order;
 		dev_info(&dev->dev, "multi page tx ring, order = %d\n",
 			 max_tx_ring_page_order);
@@ -1642,6 +1649,11 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		dev_info(&dev->dev, "single rx ring\n");
 	} else {
 		info->rx_ring_page_order = max_rx_ring_page_order;
+		if (max_rx_ring_page_order > XENNET_MAX_RING_PAGE_ORDER) {
+			dev_warn(&dev->dev, "Backend can do %d pages but we can only do %d!\n",
Quoted 8 lines

drivers/net/xen-netfront.c static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info) · line 1659

Quoted 6 lines
drivers/net/xen-netfront.c +3 -0
+				max_rx_ring_page_order, XENNET_MAX_RING_PAGE_ORDER);
+			max_rx_ring_page_order = XENNET_MAX_RING_PAGE_ORDER;
+		}
 		dev_info(&dev->dev, "multi page rx ring, order = %d\n",
 			 max_rx_ring_page_order);
 	}

Thanks for this, I will squash it into my patch.

Thanks.

Quoted 3 lines

Wei.

author
#41 lore raw

RFC PATCH v4 13/13 netfront: split event channels support.

In reply to Wei Liu

If this feature is not activated, rx_irq = tx_irq. See corresponding netback change log for details.

---
 drivers/net/xen-netfront.c |  178 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 145 insertions(+), 33 deletions(-)
drivers/net/xen-netfront.c +145 -33
index a1cfb24..9d70665 100644
@@ -98,7 +98,9 @@ struct netfront_info {
 
 	unsigned long rx_gso_checksum_fixup;
 
-	unsigned int evtchn;
+	unsigned int tx_evtchn, rx_evtchn;
+	unsigned int tx_irq, rx_irq;
+
 	struct xenbus_device *xbdev;
 
 	spinlock_t   tx_lock;
@@ -342,7 +344,7 @@ no_skb:
  push:
 	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->rx, notify);
 	if (notify)
-		notify_remote_via_irq(np->netdev->irq);
+		notify_remote_via_irq(np->rx_irq);
 }
 
 static int xennet_open(struct net_device *dev)
@@ -575,7 +577,7 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->tx, notify);
 	if (notify)
-		notify_remote_via_irq(np->netdev->irq);
+		notify_remote_via_irq(np->tx_irq);
 
 	u64_stats_update_begin(&stats->syncp);
 	stats->tx_bytes += skb->len;
@@ -1240,22 +1242,36 @@ static int xennet_set_features(struct net_device *dev, u32 features)
 	return 0;
 }
 
-static irqreturn_t xennet_interrupt(int irq, void *dev_id)
+static irqreturn_t xennet_tx_interrupt(int irq, void *dev_id)
 {
-	struct net_device *dev = dev_id;
-	struct netfront_info *np = netdev_priv(dev);
+	struct netfront_info *np = dev_id;
+	struct net_device *dev = np->netdev;
 	unsigned long flags;
 
 	spin_lock_irqsave(&np->tx_lock, flags);
+	xennet_tx_buf_gc(dev);
+	spin_unlock_irqrestore(&np->tx_lock, flags);
 
-	if (likely(netif_carrier_ok(dev))) {
-		xennet_tx_buf_gc(dev);
-		/* Under tx_lock: protects access to rx shared-ring indexes. */
-		if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
-			napi_schedule(&np->napi);
-	}
+	return IRQ_HANDLED;
+}
 
-	spin_unlock_irqrestore(&np->tx_lock, flags);
+static irqreturn_t xennet_rx_interrupt(int irq, void *dev_id)
+{
+	struct netfront_info *np = dev_id;
+	struct net_device *dev = np->netdev;
+
+	if (likely(netif_carrier_ok(dev) &&
+		   RING_HAS_UNCONSUMED_RESPONSES(&np->rx)))
+		napi_schedule(&np->napi);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t xennet_interrupt(int irq, void *dev_id)
+{
+	xennet_tx_interrupt(irq, dev_id);
+
+	xennet_rx_interrupt(irq, dev_id);
 
 	return IRQ_HANDLED;
 }
@@ -1431,9 +1447,15 @@ static void xennet_disconnect_backend(struct netfront_info *info)
 	spin_unlock_irq(&info->tx_lock);
 	spin_unlock_bh(&info->rx_lock);
 
-	if (info->netdev->irq)
-		unbind_from_irqhandler(info->netdev->irq, info->netdev);
-	info->evtchn = info->netdev->irq = 0;
+	if (info->tx_irq && (info->tx_irq == info->rx_irq))
+		unbind_from_irqhandler(info->tx_irq, info);
+	if (info->tx_irq && (info->tx_irq != info->rx_irq)) {
+		unbind_from_irqhandler(info->tx_irq, info);
+		unbind_from_irqhandler(info->rx_irq, info);
+	}
+
+	info->tx_evtchn = info->tx_irq = 0;
+	info->rx_evtchn = info->rx_irq = 0;
 
 	xenbus_unmap_ring_vfree(info->xbdev, (void *)info->tx.sring);
 	free_pages((unsigned long)info->tx.sring, info->tx_ring_page_order);
@@ -1483,11 +1505,80 @@ static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
 	return 0;
 }
 
+static int setup_netfront_single(struct netfront_info *info)
+{
+	int err;
+
+	err = xenbus_alloc_evtchn(info->xbdev, &info->tx_evtchn);
+
+	if (err < 0)
+		goto fail;
+
+	err = bind_evtchn_to_irqhandler(info->tx_evtchn,
+					xennet_interrupt,
+					0, info->netdev->name, info);
+	if (err < 0)
+		goto bind_fail;
+	info->rx_evtchn = info->tx_evtchn;
+	info->rx_irq = info->tx_irq = err;
+	dev_info(&info->xbdev->dev, "single event channel, irq = %d\n",
+		 info->tx_irq);
+
+	return 0;
+
+bind_fail:
+	xenbus_free_evtchn(info->xbdev, info->tx_evtchn);
+fail:
+	return err;
+}
+
+static int setup_netfront_split(struct netfront_info *info)
+{
+	int err;
+
+	err = xenbus_alloc_evtchn(info->xbdev, &info->tx_evtchn);
+	if (err)
+		goto fail;
+	err = xenbus_alloc_evtchn(info->xbdev, &info->rx_evtchn);
+	if (err)
+		goto alloc_rx_evtchn_fail;
+
+	err = bind_evtchn_to_irqhandler(info->tx_evtchn,
+					xennet_tx_interrupt,
+					0, info->netdev->name, info);
+	if (err < 0)
+		goto bind_tx_fail;
+	info->tx_irq = err;
+	err = bind_evtchn_to_irqhandler(info->rx_evtchn,
+					xennet_rx_interrupt,
+					0, info->netdev->name, info);
+	if (err < 0)
+		goto bind_rx_fail;
+
+	info->rx_irq = err;
+	dev_info(&info->xbdev->dev, "split event channels,"
+		 " tx_irq = %d, rx_irq = %d\n",
+		 info->tx_irq, info->rx_irq);
+
+
+	return 0;
+
+bind_rx_fail:
+	unbind_from_irqhandler(info->tx_irq, info);
+bind_tx_fail:
+	xenbus_free_evtchn(info->xbdev, info->rx_evtchn);
+alloc_rx_evtchn_fail:
+	xenbus_free_evtchn(info->xbdev, info->tx_evtchn);
+fail:
+	return err;
+}
+
 static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 {
 	struct xen_netif_tx_sring *txs;
 	struct xen_netif_rx_sring *rxs;
 	int err;
+	unsigned int feature_split_evtchn;
 	struct net_device *netdev = info->netdev;
 	unsigned int max_tx_ring_page_order, max_rx_ring_page_order;
 	int i;
@@ -1507,6 +1598,13 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	}
 
 	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			   "feature-split-event-channels", "%u",
+			   &feature_split_evtchn);
+
+	if (err < 0)
+		feature_split_evtchn = 0;
+
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
 			   "max-tx-ring-page-order", "%u",
 			   &max_tx_ring_page_order);
 	if (err < 0) {
@@ -1568,21 +1666,17 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 
 	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE * info->rx_ring_pages);
 
-	err = xenbus_alloc_evtchn(dev, &info->evtchn);
-	if (err)
-		goto alloc_evtchn_fail;
+	if (!feature_split_evtchn)
+		err = setup_netfront_single(info);
+	else
+		err = setup_netfront_split(info);
 
-	err = bind_evtchn_to_irqhandler(info->evtchn, xennet_interrupt,
-					0, netdev->name, netdev);
-	if (err < 0)
-		goto bind_fail;
-	netdev->irq = err;
+	if (err)
+		goto setup_evtchn_failed;
 
 	return 0;
 
-bind_fail:
-	xenbus_free_evtchn(dev, info->evtchn);
-alloc_evtchn_fail:
+setup_evtchn_failed:
 	xenbus_unmap_ring_vfree(info->xbdev, (void *)info->rx.sring);
 grant_rx_ring_fail:
 	free_pages((unsigned long)info->rx.sring, info->rx_ring_page_order);
@@ -1659,11 +1753,27 @@ again:
 		}
 	}
 
-	err = xenbus_printf(xbt, dev->nodename,
-			    "event-channel", "%u", info->evtchn);
-	if (err) {
-		message = "writing event-channel";
-		goto abort_transaction;
+
+	if (info->tx_evtchn == info->rx_evtchn) {
+		err = xenbus_printf(xbt, dev->nodename,
+				    "event-channel", "%u", info->tx_evtchn);
+		if (err) {
+			message = "writing event-channel";
+			goto abort_transaction;
+		}
+	} else {
+		err = xenbus_printf(xbt, dev->nodename,
+				    "event-channel-tx", "%u", info->tx_evtchn);
+		if (err) {
+			message = "writing event-channel-tx";
+			goto abort_transaction;
+		}
+		err = xenbus_printf(xbt, dev->nodename,
+				    "event-channel-rx", "%u", info->rx_evtchn);
+		if (err) {
+			message = "writing event-channel-rx";
+			goto abort_transaction;
+		}
 	}
 
 	err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
@@ -1777,7 +1887,9 @@ static int xennet_connect(struct net_device *dev)
 	 * packets.
 	 */
 	netif_carrier_on(np->netdev);
-	notify_remote_via_irq(np->netdev->irq);
+	notify_remote_via_irq(np->tx_irq);
+	if (np->tx_irq != np->rx_irq)
+		notify_remote_via_irq(np->rx_irq);
 	xennet_tx_buf_gc(dev);
 	xennet_alloc_rx_buffers(dev);
 
Signature · 1 line
1.7.2.5