diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-06 21:31:36 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-06 21:31:36 -0500 |
commit | 06d381484fe8fb1ba2996c22e89595a273e3634c (patch) | |
tree | 0d39c57cb8c501341ab8ed1d740f076b0b8c0bd0 /drivers | |
parent | 5d5a8d2d9d6cca979efe4fe1552d787fdc542603 (diff) | |
parent | c9d6369978411f690513994e6e53e2e6410874a4 (diff) |
Merge branch 'stable/vmalloc-3.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen
* 'stable/vmalloc-3.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen:
net: xen-netback: use API provided by xenbus module to map rings
block: xen-blkback: use API provided by xenbus module to map rings
xen: use generic functions instead of xen_{alloc, free}_vm_area()
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/xen-blkback/common.h | 5 | ||||
-rw-r--r-- | drivers/block/xen-blkback/xenbus.c | 54 | ||||
-rw-r--r-- | drivers/net/xen-netback/common.h | 11 | ||||
-rw-r--r-- | drivers/net/xen-netback/netback.c | 80 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_client.c | 6 |
5 files changed, 33 insertions, 123 deletions
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index de09f525d6c1..dfb1b3a43a5d 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h | |||
@@ -170,7 +170,7 @@ struct xen_blkif { | |||
170 | enum blkif_protocol blk_protocol; | 170 | enum blkif_protocol blk_protocol; |
171 | enum blkif_backend_type blk_backend_type; | 171 | enum blkif_backend_type blk_backend_type; |
172 | union blkif_back_rings blk_rings; | 172 | union blkif_back_rings blk_rings; |
173 | struct vm_struct *blk_ring_area; | 173 | void *blk_ring; |
174 | /* The VBD attached to this interface. */ | 174 | /* The VBD attached to this interface. */ |
175 | struct xen_vbd vbd; | 175 | struct xen_vbd vbd; |
176 | /* Back pointer to the backend_info. */ | 176 | /* Back pointer to the backend_info. */ |
@@ -198,9 +198,6 @@ struct xen_blkif { | |||
198 | int st_wr_sect; | 198 | int st_wr_sect; |
199 | 199 | ||
200 | wait_queue_head_t waiting_to_free; | 200 | wait_queue_head_t waiting_to_free; |
201 | |||
202 | grant_handle_t shmem_handle; | ||
203 | grant_ref_t shmem_ref; | ||
204 | }; | 201 | }; |
205 | 202 | ||
206 | 203 | ||
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 2c008afe63d9..f759ad4584c3 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c | |||
@@ -122,38 +122,6 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) | |||
122 | return blkif; | 122 | return blkif; |
123 | } | 123 | } |
124 | 124 | ||
125 | static int map_frontend_page(struct xen_blkif *blkif, unsigned long shared_page) | ||
126 | { | ||
127 | struct gnttab_map_grant_ref op; | ||
128 | |||
129 | gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr, | ||
130 | GNTMAP_host_map, shared_page, blkif->domid); | ||
131 | |||
132 | if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)) | ||
133 | BUG(); | ||
134 | |||
135 | if (op.status) { | ||
136 | DPRINTK("Grant table operation failure !\n"); | ||
137 | return op.status; | ||
138 | } | ||
139 | |||
140 | blkif->shmem_ref = shared_page; | ||
141 | blkif->shmem_handle = op.handle; | ||
142 | |||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | static void unmap_frontend_page(struct xen_blkif *blkif) | ||
147 | { | ||
148 | struct gnttab_unmap_grant_ref op; | ||
149 | |||
150 | gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr, | ||
151 | GNTMAP_host_map, blkif->shmem_handle); | ||
152 | |||
153 | if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)) | ||
154 | BUG(); | ||
155 | } | ||
156 | |||
157 | static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, | 125 | static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, |
158 | unsigned int evtchn) | 126 | unsigned int evtchn) |
159 | { | 127 | { |
@@ -163,35 +131,29 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, | |||
163 | if (blkif->irq) | 131 | if (blkif->irq) |
164 | return 0; | 132 | return 0; |
165 | 133 | ||
166 | blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE); | 134 | err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring); |
167 | if (!blkif->blk_ring_area) | 135 | if (err < 0) |
168 | return -ENOMEM; | ||
169 | |||
170 | err = map_frontend_page(blkif, shared_page); | ||
171 | if (err) { | ||
172 | free_vm_area(blkif->blk_ring_area); | ||
173 | return err; | 136 | return err; |
174 | } | ||
175 | 137 | ||
176 | switch (blkif->blk_protocol) { | 138 | switch (blkif->blk_protocol) { |
177 | case BLKIF_PROTOCOL_NATIVE: | 139 | case BLKIF_PROTOCOL_NATIVE: |
178 | { | 140 | { |
179 | struct blkif_sring *sring; | 141 | struct blkif_sring *sring; |
180 | sring = (struct blkif_sring *)blkif->blk_ring_area->addr; | 142 | sring = (struct blkif_sring *)blkif->blk_ring; |
181 | BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE); | 143 | BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE); |
182 | break; | 144 | break; |
183 | } | 145 | } |
184 | case BLKIF_PROTOCOL_X86_32: | 146 | case BLKIF_PROTOCOL_X86_32: |
185 | { | 147 | { |
186 | struct blkif_x86_32_sring *sring_x86_32; | 148 | struct blkif_x86_32_sring *sring_x86_32; |
187 | sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring_area->addr; | 149 | sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring; |
188 | BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE); | 150 | BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE); |
189 | break; | 151 | break; |
190 | } | 152 | } |
191 | case BLKIF_PROTOCOL_X86_64: | 153 | case BLKIF_PROTOCOL_X86_64: |
192 | { | 154 | { |
193 | struct blkif_x86_64_sring *sring_x86_64; | 155 | struct blkif_x86_64_sring *sring_x86_64; |
194 | sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring_area->addr; | 156 | sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring; |
195 | BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE); | 157 | BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE); |
196 | break; | 158 | break; |
197 | } | 159 | } |
@@ -203,8 +165,7 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, | |||
203 | xen_blkif_be_int, 0, | 165 | xen_blkif_be_int, 0, |
204 | "blkif-backend", blkif); | 166 | "blkif-backend", blkif); |
205 | if (err < 0) { | 167 | if (err < 0) { |
206 | unmap_frontend_page(blkif); | 168 | xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring); |
207 | free_vm_area(blkif->blk_ring_area); | ||
208 | blkif->blk_rings.common.sring = NULL; | 169 | blkif->blk_rings.common.sring = NULL; |
209 | return err; | 170 | return err; |
210 | } | 171 | } |
@@ -230,8 +191,7 @@ static void xen_blkif_disconnect(struct xen_blkif *blkif) | |||
230 | } | 191 | } |
231 | 192 | ||
232 | if (blkif->blk_rings.common.sring) { | 193 | if (blkif->blk_rings.common.sring) { |
233 | unmap_frontend_page(blkif); | 194 | xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring); |
234 | free_vm_area(blkif->blk_ring_area); | ||
235 | blkif->blk_rings.common.sring = NULL; | 195 | blkif->blk_rings.common.sring = NULL; |
236 | } | 196 | } |
237 | } | 197 | } |
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h index 161f207786a4..94b79c3338c4 100644 --- a/drivers/net/xen-netback/common.h +++ b/drivers/net/xen-netback/common.h | |||
@@ -58,10 +58,6 @@ struct xenvif { | |||
58 | u8 fe_dev_addr[6]; | 58 | u8 fe_dev_addr[6]; |
59 | 59 | ||
60 | /* Physical parameters of the comms window. */ | 60 | /* Physical parameters of the comms window. */ |
61 | grant_handle_t tx_shmem_handle; | ||
62 | grant_ref_t tx_shmem_ref; | ||
63 | grant_handle_t rx_shmem_handle; | ||
64 | grant_ref_t rx_shmem_ref; | ||
65 | unsigned int irq; | 61 | unsigned int irq; |
66 | 62 | ||
67 | /* List of frontends to notify after a batch of frames sent. */ | 63 | /* List of frontends to notify after a batch of frames sent. */ |
@@ -70,8 +66,6 @@ struct xenvif { | |||
70 | /* The shared rings and indexes. */ | 66 | /* The shared rings and indexes. */ |
71 | struct xen_netif_tx_back_ring tx; | 67 | struct xen_netif_tx_back_ring tx; |
72 | struct xen_netif_rx_back_ring rx; | 68 | struct xen_netif_rx_back_ring rx; |
73 | struct vm_struct *tx_comms_area; | ||
74 | struct vm_struct *rx_comms_area; | ||
75 | 69 | ||
76 | /* Frontend feature information. */ | 70 | /* Frontend feature information. */ |
77 | u8 can_sg:1; | 71 | u8 can_sg:1; |
@@ -106,6 +100,11 @@ struct xenvif { | |||
106 | wait_queue_head_t waiting_to_free; | 100 | wait_queue_head_t waiting_to_free; |
107 | }; | 101 | }; |
108 | 102 | ||
103 | static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif) | ||
104 | { | ||
105 | return to_xenbus_device(vif->dev->dev.parent); | ||
106 | } | ||
107 | |||
109 | #define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) | 108 | #define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) |
110 | #define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) | 109 | #define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) |
111 | 110 | ||
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c index d5508957200e..0cb594c86090 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c | |||
@@ -1589,88 +1589,42 @@ static int xen_netbk_kthread(void *data) | |||
1589 | 1589 | ||
1590 | void xen_netbk_unmap_frontend_rings(struct xenvif *vif) | 1590 | void xen_netbk_unmap_frontend_rings(struct xenvif *vif) |
1591 | { | 1591 | { |
1592 | struct gnttab_unmap_grant_ref op; | 1592 | if (vif->tx.sring) |
1593 | 1593 | xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif), | |
1594 | if (vif->tx.sring) { | 1594 | vif->tx.sring); |
1595 | gnttab_set_unmap_op(&op, (unsigned long)vif->tx_comms_area->addr, | 1595 | if (vif->rx.sring) |
1596 | GNTMAP_host_map, vif->tx_shmem_handle); | 1596 | xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif), |
1597 | 1597 | vif->rx.sring); | |
1598 | if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)) | ||
1599 | BUG(); | ||
1600 | } | ||
1601 | |||
1602 | if (vif->rx.sring) { | ||
1603 | gnttab_set_unmap_op(&op, (unsigned long)vif->rx_comms_area->addr, | ||
1604 | GNTMAP_host_map, vif->rx_shmem_handle); | ||
1605 | |||
1606 | if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)) | ||
1607 | BUG(); | ||
1608 | } | ||
1609 | if (vif->rx_comms_area) | ||
1610 | free_vm_area(vif->rx_comms_area); | ||
1611 | if (vif->tx_comms_area) | ||
1612 | free_vm_area(vif->tx_comms_area); | ||
1613 | } | 1598 | } |
1614 | 1599 | ||
1615 | int xen_netbk_map_frontend_rings(struct xenvif *vif, | 1600 | int xen_netbk_map_frontend_rings(struct xenvif *vif, |
1616 | grant_ref_t tx_ring_ref, | 1601 | grant_ref_t tx_ring_ref, |
1617 | grant_ref_t rx_ring_ref) | 1602 | grant_ref_t rx_ring_ref) |
1618 | { | 1603 | { |
1619 | struct gnttab_map_grant_ref op; | 1604 | void *addr; |
1620 | struct xen_netif_tx_sring *txs; | 1605 | struct xen_netif_tx_sring *txs; |
1621 | struct xen_netif_rx_sring *rxs; | 1606 | struct xen_netif_rx_sring *rxs; |
1622 | 1607 | ||
1623 | int err = -ENOMEM; | 1608 | int err = -ENOMEM; |
1624 | 1609 | ||
1625 | vif->tx_comms_area = alloc_vm_area(PAGE_SIZE); | 1610 | err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif), |
1626 | if (vif->tx_comms_area == NULL) | 1611 | tx_ring_ref, &addr); |
1612 | if (err) | ||
1627 | goto err; | 1613 | goto err; |
1628 | 1614 | ||
1629 | vif->rx_comms_area = alloc_vm_area(PAGE_SIZE); | 1615 | txs = (struct xen_netif_tx_sring *)addr; |
1630 | if (vif->rx_comms_area == NULL) | ||
1631 | goto err; | ||
1632 | |||
1633 | gnttab_set_map_op(&op, (unsigned long)vif->tx_comms_area->addr, | ||
1634 | GNTMAP_host_map, tx_ring_ref, vif->domid); | ||
1635 | |||
1636 | if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)) | ||
1637 | BUG(); | ||
1638 | |||
1639 | if (op.status) { | ||
1640 | netdev_warn(vif->dev, | ||
1641 | "failed to map tx ring. err=%d status=%d\n", | ||
1642 | err, op.status); | ||
1643 | err = op.status; | ||
1644 | goto err; | ||
1645 | } | ||
1646 | |||
1647 | vif->tx_shmem_ref = tx_ring_ref; | ||
1648 | vif->tx_shmem_handle = op.handle; | ||
1649 | |||
1650 | txs = (struct xen_netif_tx_sring *)vif->tx_comms_area->addr; | ||
1651 | BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE); | 1616 | BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE); |
1652 | 1617 | ||
1653 | gnttab_set_map_op(&op, (unsigned long)vif->rx_comms_area->addr, | 1618 | err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif), |
1654 | GNTMAP_host_map, rx_ring_ref, vif->domid); | 1619 | rx_ring_ref, &addr); |
1655 | 1620 | if (err) | |
1656 | if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)) | ||
1657 | BUG(); | ||
1658 | |||
1659 | if (op.status) { | ||
1660 | netdev_warn(vif->dev, | ||
1661 | "failed to map rx ring. err=%d status=%d\n", | ||
1662 | err, op.status); | ||
1663 | err = op.status; | ||
1664 | goto err; | 1621 | goto err; |
1665 | } | ||
1666 | |||
1667 | vif->rx_shmem_ref = rx_ring_ref; | ||
1668 | vif->rx_shmem_handle = op.handle; | ||
1669 | vif->rx_req_cons_peek = 0; | ||
1670 | 1622 | ||
1671 | rxs = (struct xen_netif_rx_sring *)vif->rx_comms_area->addr; | 1623 | rxs = (struct xen_netif_rx_sring *)addr; |
1672 | BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE); | 1624 | BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE); |
1673 | 1625 | ||
1626 | vif->rx_req_cons_peek = 0; | ||
1627 | |||
1674 | return 0; | 1628 | return 0; |
1675 | 1629 | ||
1676 | err: | 1630 | err: |
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index cdacf923e073..229d3adce85d 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c | |||
@@ -443,7 +443,7 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr) | |||
443 | 443 | ||
444 | *vaddr = NULL; | 444 | *vaddr = NULL; |
445 | 445 | ||
446 | area = xen_alloc_vm_area(PAGE_SIZE); | 446 | area = alloc_vm_area(PAGE_SIZE); |
447 | if (!area) | 447 | if (!area) |
448 | return -ENOMEM; | 448 | return -ENOMEM; |
449 | 449 | ||
@@ -453,7 +453,7 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr) | |||
453 | BUG(); | 453 | BUG(); |
454 | 454 | ||
455 | if (op.status != GNTST_okay) { | 455 | if (op.status != GNTST_okay) { |
456 | xen_free_vm_area(area); | 456 | free_vm_area(area); |
457 | xenbus_dev_fatal(dev, op.status, | 457 | xenbus_dev_fatal(dev, op.status, |
458 | "mapping in shared page %d from domain %d", | 458 | "mapping in shared page %d from domain %d", |
459 | gnt_ref, dev->otherend_id); | 459 | gnt_ref, dev->otherend_id); |
@@ -552,7 +552,7 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr) | |||
552 | BUG(); | 552 | BUG(); |
553 | 553 | ||
554 | if (op.status == GNTST_okay) | 554 | if (op.status == GNTST_okay) |
555 | xen_free_vm_area(area); | 555 | free_vm_area(area); |
556 | else | 556 | else |
557 | xenbus_dev_error(dev, op.status, | 557 | xenbus_dev_error(dev, op.status, |
558 | "unmapping page at handle %d error %d", | 558 | "unmapping page at handle %d error %d", |