netback.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925
  1. /*
  2. * Back-end of the driver for virtual network devices. This portion of the
  3. * driver exports a 'unified' network-device interface that can be accessed
  4. * by any operating system that implements a compatible front end. A
  5. * reference front-end implementation can be found in:
  6. * drivers/net/xen-netfront.c
  7. *
  8. * Copyright (c) 2002-2005, K A Fraser
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation; or, when distributed
  13. * separately from the Linux kernel or incorporated into other
  14. * software packages, subject to the following license:
  15. *
  16. * Permission is hereby granted, free of charge, to any person obtaining a copy
  17. * of this source file (the "Software"), to deal in the Software without
  18. * restriction, including without limitation the rights to use, copy, modify,
  19. * merge, publish, distribute, sublicense, and/or sell copies of the Software,
  20. * and to permit persons to whom the Software is furnished to do so, subject to
  21. * the following conditions:
  22. *
  23. * The above copyright notice and this permission notice shall be included in
  24. * all copies or substantial portions of the Software.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  29. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  31. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  32. * IN THE SOFTWARE.
  33. */
  34. #include "common.h"
  35. #include <linux/kthread.h>
  36. #include <linux/if_vlan.h>
  37. #include <linux/udp.h>
  38. #include <net/tcp.h>
  39. #include <net/ip6_checksum.h>
  40. #include <xen/xen.h>
  41. #include <xen/events.h>
  42. #include <xen/interface/memory.h>
  43. #include <asm/xen/hypercall.h>
  44. #include <asm/xen/page.h>
  45. /* Provide an option to disable split event channels at load time as
  46. * event channels are limited resource. Split event channels are
  47. * enabled by default.
  48. */
  49. bool separate_tx_rx_irq = 1;
  50. module_param(separate_tx_rx_irq, bool, 0644);
  51. /*
  52. * This is the maximum slots a skb can have. If a guest sends a skb
  53. * which exceeds this limit it is considered malicious.
  54. */
  55. #define FATAL_SKB_SLOTS_DEFAULT 20
  56. static unsigned int fatal_skb_slots = FATAL_SKB_SLOTS_DEFAULT;
  57. module_param(fatal_skb_slots, uint, 0444);
  58. /*
  59. * To avoid confusion, we define XEN_NETBK_LEGACY_SLOTS_MAX indicating
  60. * the maximum slots a valid packet can use. Now this value is defined
  61. * to be XEN_NETIF_NR_SLOTS_MIN, which is supposed to be supported by
  62. * all backend.
  63. */
  64. #define XEN_NETBK_LEGACY_SLOTS_MAX XEN_NETIF_NR_SLOTS_MIN
  65. /*
  66. * If head != INVALID_PENDING_RING_IDX, it means this tx request is head of
  67. * one or more merged tx requests, otherwise it is the continuation of
  68. * previous tx request.
  69. */
  70. static inline int pending_tx_is_head(struct xenvif *vif, RING_IDX idx)
  71. {
  72. return vif->pending_tx_info[idx].head != INVALID_PENDING_RING_IDX;
  73. }
  74. static void xenvif_idx_release(struct xenvif *vif, u16 pending_idx,
  75. u8 status);
  76. static void make_tx_response(struct xenvif *vif,
  77. struct xen_netif_tx_request *txp,
  78. s8 st);
  79. static inline int tx_work_todo(struct xenvif *vif);
  80. static inline int rx_work_todo(struct xenvif *vif);
  81. static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
  82. u16 id,
  83. s8 st,
  84. u16 offset,
  85. u16 size,
  86. u16 flags);
  87. static inline unsigned long idx_to_pfn(struct xenvif *vif,
  88. u16 idx)
  89. {
  90. return page_to_pfn(vif->mmap_pages[idx]);
  91. }
  92. static inline unsigned long idx_to_kaddr(struct xenvif *vif,
  93. u16 idx)
  94. {
  95. return (unsigned long)pfn_to_kaddr(idx_to_pfn(vif, idx));
  96. }
  97. /* This is a miniumum size for the linear area to avoid lots of
  98. * calls to __pskb_pull_tail() as we set up checksum offsets. The
  99. * value 128 was chosen as it covers all IPv4 and most likely
  100. * IPv6 headers.
  101. */
  102. #define PKT_PROT_LEN 128
  103. static u16 frag_get_pending_idx(skb_frag_t *frag)
  104. {
  105. return (u16)frag->page_offset;
  106. }
  107. static void frag_set_pending_idx(skb_frag_t *frag, u16 pending_idx)
  108. {
  109. frag->page_offset = pending_idx;
  110. }
  111. static inline pending_ring_idx_t pending_index(unsigned i)
  112. {
  113. return i & (MAX_PENDING_REQS-1);
  114. }
  115. static inline pending_ring_idx_t nr_pending_reqs(struct xenvif *vif)
  116. {
  117. return MAX_PENDING_REQS -
  118. vif->pending_prod + vif->pending_cons;
  119. }
  120. static int max_required_rx_slots(struct xenvif *vif)
  121. {
  122. int max = DIV_ROUND_UP(vif->dev->mtu, PAGE_SIZE);
  123. /* XXX FIXME: RX path dependent on MAX_SKB_FRAGS */
  124. if (vif->can_sg || vif->gso_mask || vif->gso_prefix_mask)
  125. max += MAX_SKB_FRAGS + 1; /* extra_info + frags */
  126. return max;
  127. }
  128. int xenvif_rx_ring_full(struct xenvif *vif)
  129. {
  130. RING_IDX peek = vif->rx_req_cons_peek;
  131. RING_IDX needed = max_required_rx_slots(vif);
  132. return ((vif->rx.sring->req_prod - peek) < needed) ||
  133. ((vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) < needed);
  134. }
  135. int xenvif_must_stop_queue(struct xenvif *vif)
  136. {
  137. if (!xenvif_rx_ring_full(vif))
  138. return 0;
  139. vif->rx.sring->req_event = vif->rx_req_cons_peek +
  140. max_required_rx_slots(vif);
  141. mb(); /* request notification /then/ check the queue */
  142. return xenvif_rx_ring_full(vif);
  143. }
  144. /*
  145. * Returns true if we should start a new receive buffer instead of
  146. * adding 'size' bytes to a buffer which currently contains 'offset'
  147. * bytes.
  148. */
  149. static bool start_new_rx_buffer(int offset, unsigned long size, int head)
  150. {
  151. /* simple case: we have completely filled the current buffer. */
  152. if (offset == MAX_BUFFER_OFFSET)
  153. return true;
  154. /*
  155. * complex case: start a fresh buffer if the current frag
  156. * would overflow the current buffer but only if:
  157. * (i) this frag would fit completely in the next buffer
  158. * and (ii) there is already some data in the current buffer
  159. * and (iii) this is not the head buffer.
  160. *
  161. * Where:
  162. * - (i) stops us splitting a frag into two copies
  163. * unless the frag is too large for a single buffer.
  164. * - (ii) stops us from leaving a buffer pointlessly empty.
  165. * - (iii) stops us leaving the first buffer
  166. * empty. Strictly speaking this is already covered
  167. * by (ii) but is explicitly checked because
  168. * netfront relies on the first buffer being
  169. * non-empty and can crash otherwise.
  170. *
  171. * This means we will effectively linearise small
  172. * frags but do not needlessly split large buffers
  173. * into multiple copies tend to give large frags their
  174. * own buffers as before.
  175. */
  176. if ((offset + size > MAX_BUFFER_OFFSET) &&
  177. (size <= MAX_BUFFER_OFFSET) && offset && !head)
  178. return true;
  179. return false;
  180. }
  181. struct xenvif_count_slot_state {
  182. unsigned long copy_off;
  183. bool head;
  184. };
  185. unsigned int xenvif_count_frag_slots(struct xenvif *vif,
  186. unsigned long offset, unsigned long size,
  187. struct xenvif_count_slot_state *state)
  188. {
  189. unsigned count = 0;
  190. offset &= ~PAGE_MASK;
  191. while (size > 0) {
  192. unsigned long bytes;
  193. bytes = PAGE_SIZE - offset;
  194. if (bytes > size)
  195. bytes = size;
  196. if (start_new_rx_buffer(state->copy_off, bytes, state->head)) {
  197. count++;
  198. state->copy_off = 0;
  199. }
  200. if (state->copy_off + bytes > MAX_BUFFER_OFFSET)
  201. bytes = MAX_BUFFER_OFFSET - state->copy_off;
  202. state->copy_off += bytes;
  203. offset += bytes;
  204. size -= bytes;
  205. if (offset == PAGE_SIZE)
  206. offset = 0;
  207. state->head = false;
  208. }
  209. return count;
  210. }
  211. /*
  212. * Figure out how many ring slots we're going to need to send @skb to
  213. * the guest. This function is essentially a dry run of
  214. * xenvif_gop_frag_copy.
  215. */
  216. unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb)
  217. {
  218. struct xenvif_count_slot_state state;
  219. unsigned int count;
  220. unsigned char *data;
  221. unsigned i;
  222. state.head = true;
  223. state.copy_off = 0;
  224. /* Slot for the first (partial) page of data. */
  225. count = 1;
  226. /* Need a slot for the GSO prefix for GSO extra data? */
  227. if (skb_shinfo(skb)->gso_size)
  228. count++;
  229. data = skb->data;
  230. while (data < skb_tail_pointer(skb)) {
  231. unsigned long offset = offset_in_page(data);
  232. unsigned long size = PAGE_SIZE - offset;
  233. if (data + size > skb_tail_pointer(skb))
  234. size = skb_tail_pointer(skb) - data;
  235. count += xenvif_count_frag_slots(vif, offset, size, &state);
  236. data += size;
  237. }
  238. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  239. unsigned long size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
  240. unsigned long offset = skb_shinfo(skb)->frags[i].page_offset;
  241. count += xenvif_count_frag_slots(vif, offset, size, &state);
  242. }
  243. return count;
  244. }
  245. struct netrx_pending_operations {
  246. unsigned copy_prod, copy_cons;
  247. unsigned meta_prod, meta_cons;
  248. struct gnttab_copy *copy;
  249. struct xenvif_rx_meta *meta;
  250. int copy_off;
  251. grant_ref_t copy_gref;
  252. };
  253. static struct xenvif_rx_meta *get_next_rx_buffer(struct xenvif *vif,
  254. struct netrx_pending_operations *npo)
  255. {
  256. struct xenvif_rx_meta *meta;
  257. struct xen_netif_rx_request *req;
  258. req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
  259. meta = npo->meta + npo->meta_prod++;
  260. meta->gso_type = XEN_NETIF_GSO_TYPE_NONE;
  261. meta->gso_size = 0;
  262. meta->size = 0;
  263. meta->id = req->id;
  264. npo->copy_off = 0;
  265. npo->copy_gref = req->gref;
  266. return meta;
  267. }
  268. /*
  269. * Set up the grant operations for this fragment. If it's a flipping
  270. * interface, we also set up the unmap request from here.
  271. */
  272. static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
  273. struct netrx_pending_operations *npo,
  274. struct page *page, unsigned long size,
  275. unsigned long offset, int *head)
  276. {
  277. struct gnttab_copy *copy_gop;
  278. struct xenvif_rx_meta *meta;
  279. unsigned long bytes;
  280. int gso_type;
  281. /* Data must not cross a page boundary. */
  282. BUG_ON(size + offset > PAGE_SIZE<<compound_order(page));
  283. meta = npo->meta + npo->meta_prod - 1;
  284. /* Skip unused frames from start of page */
  285. page += offset >> PAGE_SHIFT;
  286. offset &= ~PAGE_MASK;
  287. while (size > 0) {
  288. BUG_ON(offset >= PAGE_SIZE);
  289. BUG_ON(npo->copy_off > MAX_BUFFER_OFFSET);
  290. bytes = PAGE_SIZE - offset;
  291. if (bytes > size)
  292. bytes = size;
  293. if (start_new_rx_buffer(npo->copy_off, bytes, *head)) {
  294. /*
  295. * Netfront requires there to be some data in the head
  296. * buffer.
  297. */
  298. BUG_ON(*head);
  299. meta = get_next_rx_buffer(vif, npo);
  300. }
  301. if (npo->copy_off + bytes > MAX_BUFFER_OFFSET)
  302. bytes = MAX_BUFFER_OFFSET - npo->copy_off;
  303. copy_gop = npo->copy + npo->copy_prod++;
  304. copy_gop->flags = GNTCOPY_dest_gref;
  305. copy_gop->len = bytes;
  306. copy_gop->source.domid = DOMID_SELF;
  307. copy_gop->source.u.gmfn = virt_to_mfn(page_address(page));
  308. copy_gop->source.offset = offset;
  309. copy_gop->dest.domid = vif->domid;
  310. copy_gop->dest.offset = npo->copy_off;
  311. copy_gop->dest.u.ref = npo->copy_gref;
  312. npo->copy_off += bytes;
  313. meta->size += bytes;
  314. offset += bytes;
  315. size -= bytes;
  316. /* Next frame */
  317. if (offset == PAGE_SIZE && size) {
  318. BUG_ON(!PageCompound(page));
  319. page++;
  320. offset = 0;
  321. }
  322. /* Leave a gap for the GSO descriptor. */
  323. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
  324. gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
  325. else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  326. gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
  327. else
  328. gso_type = XEN_NETIF_GSO_TYPE_NONE;
  329. if (*head && ((1 << gso_type) & vif->gso_mask))
  330. vif->rx.req_cons++;
  331. *head = 0; /* There must be something in this buffer now. */
  332. }
  333. }
  334. /*
  335. * Prepare an SKB to be transmitted to the frontend.
  336. *
  337. * This function is responsible for allocating grant operations, meta
  338. * structures, etc.
  339. *
  340. * It returns the number of meta structures consumed. The number of
  341. * ring slots used is always equal to the number of meta slots used
  342. * plus the number of GSO descriptors used. Currently, we use either
  343. * zero GSO descriptors (for non-GSO packets) or one descriptor (for
  344. * frontend-side LRO).
  345. */
  346. static int xenvif_gop_skb(struct sk_buff *skb,
  347. struct netrx_pending_operations *npo)
  348. {
  349. struct xenvif *vif = netdev_priv(skb->dev);
  350. int nr_frags = skb_shinfo(skb)->nr_frags;
  351. int i;
  352. struct xen_netif_rx_request *req;
  353. struct xenvif_rx_meta *meta;
  354. unsigned char *data;
  355. int head = 1;
  356. int old_meta_prod;
  357. int gso_type;
  358. int gso_size;
  359. old_meta_prod = npo->meta_prod;
  360. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) {
  361. gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
  362. gso_size = skb_shinfo(skb)->gso_size;
  363. } else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) {
  364. gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
  365. gso_size = skb_shinfo(skb)->gso_size;
  366. } else {
  367. gso_type = XEN_NETIF_GSO_TYPE_NONE;
  368. gso_size = 0;
  369. }
  370. /* Set up a GSO prefix descriptor, if necessary */
  371. if ((1 << gso_type) & vif->gso_prefix_mask) {
  372. req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
  373. meta = npo->meta + npo->meta_prod++;
  374. meta->gso_type = gso_type;
  375. meta->gso_size = gso_size;
  376. meta->size = 0;
  377. meta->id = req->id;
  378. }
  379. req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
  380. meta = npo->meta + npo->meta_prod++;
  381. if ((1 << gso_type) & vif->gso_mask) {
  382. meta->gso_type = gso_type;
  383. meta->gso_size = gso_size;
  384. } else {
  385. meta->gso_type = XEN_NETIF_GSO_TYPE_NONE;
  386. meta->gso_size = 0;
  387. }
  388. meta->size = 0;
  389. meta->id = req->id;
  390. npo->copy_off = 0;
  391. npo->copy_gref = req->gref;
  392. data = skb->data;
  393. while (data < skb_tail_pointer(skb)) {
  394. unsigned int offset = offset_in_page(data);
  395. unsigned int len = PAGE_SIZE - offset;
  396. if (data + len > skb_tail_pointer(skb))
  397. len = skb_tail_pointer(skb) - data;
  398. xenvif_gop_frag_copy(vif, skb, npo,
  399. virt_to_page(data), len, offset, &head);
  400. data += len;
  401. }
  402. for (i = 0; i < nr_frags; i++) {
  403. xenvif_gop_frag_copy(vif, skb, npo,
  404. skb_frag_page(&skb_shinfo(skb)->frags[i]),
  405. skb_frag_size(&skb_shinfo(skb)->frags[i]),
  406. skb_shinfo(skb)->frags[i].page_offset,
  407. &head);
  408. }
  409. return npo->meta_prod - old_meta_prod;
  410. }
  411. /*
  412. * This is a twin to xenvif_gop_skb. Assume that xenvif_gop_skb was
  413. * used to set up the operations on the top of
  414. * netrx_pending_operations, which have since been done. Check that
  415. * they didn't give any errors and advance over them.
  416. */
  417. static int xenvif_check_gop(struct xenvif *vif, int nr_meta_slots,
  418. struct netrx_pending_operations *npo)
  419. {
  420. struct gnttab_copy *copy_op;
  421. int status = XEN_NETIF_RSP_OKAY;
  422. int i;
  423. for (i = 0; i < nr_meta_slots; i++) {
  424. copy_op = npo->copy + npo->copy_cons++;
  425. if (copy_op->status != GNTST_okay) {
  426. netdev_dbg(vif->dev,
  427. "Bad status %d from copy to DOM%d.\n",
  428. copy_op->status, vif->domid);
  429. status = XEN_NETIF_RSP_ERROR;
  430. }
  431. }
  432. return status;
  433. }
  434. static void xenvif_add_frag_responses(struct xenvif *vif, int status,
  435. struct xenvif_rx_meta *meta,
  436. int nr_meta_slots)
  437. {
  438. int i;
  439. unsigned long offset;
  440. /* No fragments used */
  441. if (nr_meta_slots <= 1)
  442. return;
  443. nr_meta_slots--;
  444. for (i = 0; i < nr_meta_slots; i++) {
  445. int flags;
  446. if (i == nr_meta_slots - 1)
  447. flags = 0;
  448. else
  449. flags = XEN_NETRXF_more_data;
  450. offset = 0;
  451. make_rx_response(vif, meta[i].id, status, offset,
  452. meta[i].size, flags);
  453. }
  454. }
  455. struct skb_cb_overlay {
  456. int meta_slots_used;
  457. };
  458. static void xenvif_kick_thread(struct xenvif *vif)
  459. {
  460. wake_up(&vif->wq);
  461. }
  462. void xenvif_rx_action(struct xenvif *vif)
  463. {
  464. s8 status;
  465. u16 flags;
  466. struct xen_netif_rx_response *resp;
  467. struct sk_buff_head rxq;
  468. struct sk_buff *skb;
  469. LIST_HEAD(notify);
  470. int ret;
  471. int nr_frags;
  472. int count;
  473. unsigned long offset;
  474. struct skb_cb_overlay *sco;
  475. int need_to_notify = 0;
  476. struct netrx_pending_operations npo = {
  477. .copy = vif->grant_copy_op,
  478. .meta = vif->meta,
  479. };
  480. skb_queue_head_init(&rxq);
  481. count = 0;
  482. while ((skb = skb_dequeue(&vif->rx_queue)) != NULL) {
  483. vif = netdev_priv(skb->dev);
  484. nr_frags = skb_shinfo(skb)->nr_frags;
  485. sco = (struct skb_cb_overlay *)skb->cb;
  486. sco->meta_slots_used = xenvif_gop_skb(skb, &npo);
  487. count += nr_frags + 1;
  488. __skb_queue_tail(&rxq, skb);
  489. /* Filled the batch queue? */
  490. /* XXX FIXME: RX path dependent on MAX_SKB_FRAGS */
  491. if (count + MAX_SKB_FRAGS >= XEN_NETIF_RX_RING_SIZE)
  492. break;
  493. }
  494. BUG_ON(npo.meta_prod > ARRAY_SIZE(vif->meta));
  495. if (!npo.copy_prod)
  496. return;
  497. BUG_ON(npo.copy_prod > MAX_GRANT_COPY_OPS);
  498. gnttab_batch_copy(vif->grant_copy_op, npo.copy_prod);
  499. while ((skb = __skb_dequeue(&rxq)) != NULL) {
  500. sco = (struct skb_cb_overlay *)skb->cb;
  501. vif = netdev_priv(skb->dev);
  502. if ((1 << vif->meta[npo.meta_cons].gso_type) &
  503. vif->gso_prefix_mask) {
  504. resp = RING_GET_RESPONSE(&vif->rx,
  505. vif->rx.rsp_prod_pvt++);
  506. resp->flags = XEN_NETRXF_gso_prefix | XEN_NETRXF_more_data;
  507. resp->offset = vif->meta[npo.meta_cons].gso_size;
  508. resp->id = vif->meta[npo.meta_cons].id;
  509. resp->status = sco->meta_slots_used;
  510. npo.meta_cons++;
  511. sco->meta_slots_used--;
  512. }
  513. vif->dev->stats.tx_bytes += skb->len;
  514. vif->dev->stats.tx_packets++;
  515. status = xenvif_check_gop(vif, sco->meta_slots_used, &npo);
  516. if (sco->meta_slots_used == 1)
  517. flags = 0;
  518. else
  519. flags = XEN_NETRXF_more_data;
  520. if (skb->ip_summed == CHECKSUM_PARTIAL) /* local packet? */
  521. flags |= XEN_NETRXF_csum_blank | XEN_NETRXF_data_validated;
  522. else if (skb->ip_summed == CHECKSUM_UNNECESSARY)
  523. /* remote but checksummed. */
  524. flags |= XEN_NETRXF_data_validated;
  525. offset = 0;
  526. resp = make_rx_response(vif, vif->meta[npo.meta_cons].id,
  527. status, offset,
  528. vif->meta[npo.meta_cons].size,
  529. flags);
  530. if ((1 << vif->meta[npo.meta_cons].gso_type) &
  531. vif->gso_mask) {
  532. struct xen_netif_extra_info *gso =
  533. (struct xen_netif_extra_info *)
  534. RING_GET_RESPONSE(&vif->rx,
  535. vif->rx.rsp_prod_pvt++);
  536. resp->flags |= XEN_NETRXF_extra_info;
  537. gso->u.gso.type = vif->meta[npo.meta_cons].gso_type;
  538. gso->u.gso.size = vif->meta[npo.meta_cons].gso_size;
  539. gso->u.gso.pad = 0;
  540. gso->u.gso.features = 0;
  541. gso->type = XEN_NETIF_EXTRA_TYPE_GSO;
  542. gso->flags = 0;
  543. }
  544. xenvif_add_frag_responses(vif, status,
  545. vif->meta + npo.meta_cons + 1,
  546. sco->meta_slots_used);
  547. RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->rx, ret);
  548. if (ret)
  549. need_to_notify = 1;
  550. xenvif_notify_tx_completion(vif);
  551. npo.meta_cons += sco->meta_slots_used;
  552. dev_kfree_skb(skb);
  553. }
  554. if (need_to_notify)
  555. notify_remote_via_irq(vif->rx_irq);
  556. /* More work to do? */
  557. if (!skb_queue_empty(&vif->rx_queue))
  558. xenvif_kick_thread(vif);
  559. }
  560. void xenvif_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb)
  561. {
  562. skb_queue_tail(&vif->rx_queue, skb);
  563. xenvif_kick_thread(vif);
  564. }
  565. void xenvif_check_rx_xenvif(struct xenvif *vif)
  566. {
  567. int more_to_do;
  568. RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, more_to_do);
  569. if (more_to_do)
  570. napi_schedule(&vif->napi);
  571. }
  572. static void tx_add_credit(struct xenvif *vif)
  573. {
  574. unsigned long max_burst, max_credit;
  575. /*
  576. * Allow a burst big enough to transmit a jumbo packet of up to 128kB.
  577. * Otherwise the interface can seize up due to insufficient credit.
  578. */
  579. max_burst = RING_GET_REQUEST(&vif->tx, vif->tx.req_cons)->size;
  580. max_burst = min(max_burst, 131072UL);
  581. max_burst = max(max_burst, vif->credit_bytes);
  582. /* Take care that adding a new chunk of credit doesn't wrap to zero. */
  583. max_credit = vif->remaining_credit + vif->credit_bytes;
  584. if (max_credit < vif->remaining_credit)
  585. max_credit = ULONG_MAX; /* wrapped: clamp to ULONG_MAX */
  586. vif->remaining_credit = min(max_credit, max_burst);
  587. }
  588. static void tx_credit_callback(unsigned long data)
  589. {
  590. struct xenvif *vif = (struct xenvif *)data;
  591. tx_add_credit(vif);
  592. xenvif_check_rx_xenvif(vif);
  593. }
  594. static void xenvif_tx_err(struct xenvif *vif,
  595. struct xen_netif_tx_request *txp, RING_IDX end)
  596. {
  597. RING_IDX cons = vif->tx.req_cons;
  598. do {
  599. make_tx_response(vif, txp, XEN_NETIF_RSP_ERROR);
  600. if (cons == end)
  601. break;
  602. txp = RING_GET_REQUEST(&vif->tx, cons++);
  603. } while (1);
  604. vif->tx.req_cons = cons;
  605. }
  606. static void xenvif_fatal_tx_err(struct xenvif *vif)
  607. {
  608. netdev_err(vif->dev, "fatal error; disabling device\n");
  609. xenvif_carrier_off(vif);
  610. }
  611. static int xenvif_count_requests(struct xenvif *vif,
  612. struct xen_netif_tx_request *first,
  613. struct xen_netif_tx_request *txp,
  614. int work_to_do)
  615. {
  616. RING_IDX cons = vif->tx.req_cons;
  617. int slots = 0;
  618. int drop_err = 0;
  619. int more_data;
  620. if (!(first->flags & XEN_NETTXF_more_data))
  621. return 0;
  622. do {
  623. struct xen_netif_tx_request dropped_tx = { 0 };
  624. if (slots >= work_to_do) {
  625. netdev_err(vif->dev,
  626. "Asked for %d slots but exceeds this limit\n",
  627. work_to_do);
  628. xenvif_fatal_tx_err(vif);
  629. return -ENODATA;
  630. }
  631. /* This guest is really using too many slots and
  632. * considered malicious.
  633. */
  634. if (unlikely(slots >= fatal_skb_slots)) {
  635. netdev_err(vif->dev,
  636. "Malicious frontend using %d slots, threshold %u\n",
  637. slots, fatal_skb_slots);
  638. xenvif_fatal_tx_err(vif);
  639. return -E2BIG;
  640. }
  641. /* Xen network protocol had implicit dependency on
  642. * MAX_SKB_FRAGS. XEN_NETBK_LEGACY_SLOTS_MAX is set to
  643. * the historical MAX_SKB_FRAGS value 18 to honor the
  644. * same behavior as before. Any packet using more than
  645. * 18 slots but less than fatal_skb_slots slots is
  646. * dropped
  647. */
  648. if (!drop_err && slots >= XEN_NETBK_LEGACY_SLOTS_MAX) {
  649. if (net_ratelimit())
  650. netdev_dbg(vif->dev,
  651. "Too many slots (%d) exceeding limit (%d), dropping packet\n",
  652. slots, XEN_NETBK_LEGACY_SLOTS_MAX);
  653. drop_err = -E2BIG;
  654. }
  655. if (drop_err)
  656. txp = &dropped_tx;
  657. memcpy(txp, RING_GET_REQUEST(&vif->tx, cons + slots),
  658. sizeof(*txp));
  659. /* If the guest submitted a frame >= 64 KiB then
  660. * first->size overflowed and following slots will
  661. * appear to be larger than the frame.
  662. *
  663. * This cannot be fatal error as there are buggy
  664. * frontends that do this.
  665. *
  666. * Consume all slots and drop the packet.
  667. */
  668. if (!drop_err && txp->size > first->size) {
  669. if (net_ratelimit())
  670. netdev_dbg(vif->dev,
  671. "Invalid tx request, slot size %u > remaining size %u\n",
  672. txp->size, first->size);
  673. drop_err = -EIO;
  674. }
  675. first->size -= txp->size;
  676. slots++;
  677. if (unlikely((txp->offset + txp->size) > PAGE_SIZE)) {
  678. netdev_err(vif->dev, "Cross page boundary, txp->offset: %x, size: %u\n",
  679. txp->offset, txp->size);
  680. xenvif_fatal_tx_err(vif);
  681. return -EINVAL;
  682. }
  683. more_data = txp->flags & XEN_NETTXF_more_data;
  684. if (!drop_err)
  685. txp++;
  686. } while (more_data);
  687. if (drop_err) {
  688. xenvif_tx_err(vif, first, cons + slots);
  689. return drop_err;
  690. }
  691. return slots;
  692. }
  693. static struct page *xenvif_alloc_page(struct xenvif *vif,
  694. u16 pending_idx)
  695. {
  696. struct page *page;
  697. page = alloc_page(GFP_ATOMIC|__GFP_COLD);
  698. if (!page)
  699. return NULL;
  700. vif->mmap_pages[pending_idx] = page;
  701. return page;
  702. }
  703. static struct gnttab_copy *xenvif_get_requests(struct xenvif *vif,
  704. struct sk_buff *skb,
  705. struct xen_netif_tx_request *txp,
  706. struct gnttab_copy *gop)
  707. {
  708. struct skb_shared_info *shinfo = skb_shinfo(skb);
  709. skb_frag_t *frags = shinfo->frags;
  710. u16 pending_idx = *((u16 *)skb->data);
  711. u16 head_idx = 0;
  712. int slot, start;
  713. struct page *page;
  714. pending_ring_idx_t index, start_idx = 0;
  715. uint16_t dst_offset;
  716. unsigned int nr_slots;
  717. struct pending_tx_info *first = NULL;
  718. /* At this point shinfo->nr_frags is in fact the number of
  719. * slots, which can be as large as XEN_NETBK_LEGACY_SLOTS_MAX.
  720. */
  721. nr_slots = shinfo->nr_frags;
  722. /* Skip first skb fragment if it is on same page as header fragment. */
  723. start = (frag_get_pending_idx(&shinfo->frags[0]) == pending_idx);
  724. /* Coalesce tx requests, at this point the packet passed in
  725. * should be <= 64K. Any packets larger than 64K have been
  726. * handled in xenvif_count_requests().
  727. */
  728. for (shinfo->nr_frags = slot = start; slot < nr_slots;
  729. shinfo->nr_frags++) {
  730. struct pending_tx_info *pending_tx_info =
  731. vif->pending_tx_info;
  732. page = alloc_page(GFP_ATOMIC|__GFP_COLD);
  733. if (!page)
  734. goto err;
  735. dst_offset = 0;
  736. first = NULL;
  737. while (dst_offset < PAGE_SIZE && slot < nr_slots) {
  738. gop->flags = GNTCOPY_source_gref;
  739. gop->source.u.ref = txp->gref;
  740. gop->source.domid = vif->domid;
  741. gop->source.offset = txp->offset;
  742. gop->dest.domid = DOMID_SELF;
  743. gop->dest.offset = dst_offset;
  744. gop->dest.u.gmfn = virt_to_mfn(page_address(page));
  745. if (dst_offset + txp->size > PAGE_SIZE) {
  746. /* This page can only merge a portion
  747. * of tx request. Do not increment any
  748. * pointer / counter here. The txp
  749. * will be dealt with in future
  750. * rounds, eventually hitting the
  751. * `else` branch.
  752. */
  753. gop->len = PAGE_SIZE - dst_offset;
  754. txp->offset += gop->len;
  755. txp->size -= gop->len;
  756. dst_offset += gop->len; /* quit loop */
  757. } else {
  758. /* This tx request can be merged in the page */
  759. gop->len = txp->size;
  760. dst_offset += gop->len;
  761. index = pending_index(vif->pending_cons++);
  762. pending_idx = vif->pending_ring[index];
  763. memcpy(&pending_tx_info[pending_idx].req, txp,
  764. sizeof(*txp));
  765. /* Poison these fields, corresponding
  766. * fields for head tx req will be set
  767. * to correct values after the loop.
  768. */
  769. vif->mmap_pages[pending_idx] = (void *)(~0UL);
  770. pending_tx_info[pending_idx].head =
  771. INVALID_PENDING_RING_IDX;
  772. if (!first) {
  773. first = &pending_tx_info[pending_idx];
  774. start_idx = index;
  775. head_idx = pending_idx;
  776. }
  777. txp++;
  778. slot++;
  779. }
  780. gop++;
  781. }
  782. first->req.offset = 0;
  783. first->req.size = dst_offset;
  784. first->head = start_idx;
  785. vif->mmap_pages[head_idx] = page;
  786. frag_set_pending_idx(&frags[shinfo->nr_frags], head_idx);
  787. }
  788. BUG_ON(shinfo->nr_frags > MAX_SKB_FRAGS);
  789. return gop;
  790. err:
  791. /* Unwind, freeing all pages and sending error responses. */
  792. while (shinfo->nr_frags-- > start) {
  793. xenvif_idx_release(vif,
  794. frag_get_pending_idx(&frags[shinfo->nr_frags]),
  795. XEN_NETIF_RSP_ERROR);
  796. }
  797. /* The head too, if necessary. */
  798. if (start)
  799. xenvif_idx_release(vif, pending_idx, XEN_NETIF_RSP_ERROR);
  800. return NULL;
  801. }
  802. static int xenvif_tx_check_gop(struct xenvif *vif,
  803. struct sk_buff *skb,
  804. struct gnttab_copy **gopp)
  805. {
  806. struct gnttab_copy *gop = *gopp;
  807. u16 pending_idx = *((u16 *)skb->data);
  808. struct skb_shared_info *shinfo = skb_shinfo(skb);
  809. struct pending_tx_info *tx_info;
  810. int nr_frags = shinfo->nr_frags;
  811. int i, err, start;
  812. u16 peek; /* peek into next tx request */
  813. /* Check status of header. */
  814. err = gop->status;
  815. if (unlikely(err))
  816. xenvif_idx_release(vif, pending_idx, XEN_NETIF_RSP_ERROR);
  817. /* Skip first skb fragment if it is on same page as header fragment. */
  818. start = (frag_get_pending_idx(&shinfo->frags[0]) == pending_idx);
  819. for (i = start; i < nr_frags; i++) {
  820. int j, newerr;
  821. pending_ring_idx_t head;
  822. pending_idx = frag_get_pending_idx(&shinfo->frags[i]);
  823. tx_info = &vif->pending_tx_info[pending_idx];
  824. head = tx_info->head;
  825. /* Check error status: if okay then remember grant handle. */
  826. do {
  827. newerr = (++gop)->status;
  828. if (newerr)
  829. break;
  830. peek = vif->pending_ring[pending_index(++head)];
  831. } while (!pending_tx_is_head(vif, peek));
  832. if (likely(!newerr)) {
  833. /* Had a previous error? Invalidate this fragment. */
  834. if (unlikely(err))
  835. xenvif_idx_release(vif, pending_idx,
  836. XEN_NETIF_RSP_OKAY);
  837. continue;
  838. }
  839. /* Error on this fragment: respond to client with an error. */
  840. xenvif_idx_release(vif, pending_idx, XEN_NETIF_RSP_ERROR);
  841. /* Not the first error? Preceding frags already invalidated. */
  842. if (err)
  843. continue;
  844. /* First error: invalidate header and preceding fragments. */
  845. pending_idx = *((u16 *)skb->data);
  846. xenvif_idx_release(vif, pending_idx, XEN_NETIF_RSP_OKAY);
  847. for (j = start; j < i; j++) {
  848. pending_idx = frag_get_pending_idx(&shinfo->frags[j]);
  849. xenvif_idx_release(vif, pending_idx,
  850. XEN_NETIF_RSP_OKAY);
  851. }
  852. /* Remember the error: invalidate all subsequent fragments. */
  853. err = newerr;
  854. }
  855. *gopp = gop + 1;
  856. return err;
  857. }
  858. static void xenvif_fill_frags(struct xenvif *vif, struct sk_buff *skb)
  859. {
  860. struct skb_shared_info *shinfo = skb_shinfo(skb);
  861. int nr_frags = shinfo->nr_frags;
  862. int i;
  863. for (i = 0; i < nr_frags; i++) {
  864. skb_frag_t *frag = shinfo->frags + i;
  865. struct xen_netif_tx_request *txp;
  866. struct page *page;
  867. u16 pending_idx;
  868. pending_idx = frag_get_pending_idx(frag);
  869. txp = &vif->pending_tx_info[pending_idx].req;
  870. page = virt_to_page(idx_to_kaddr(vif, pending_idx));
  871. __skb_fill_page_desc(skb, i, page, txp->offset, txp->size);
  872. skb->len += txp->size;
  873. skb->data_len += txp->size;
  874. skb->truesize += txp->size;
  875. /* Take an extra reference to offset xenvif_idx_release */
  876. get_page(vif->mmap_pages[pending_idx]);
  877. xenvif_idx_release(vif, pending_idx, XEN_NETIF_RSP_OKAY);
  878. }
  879. }
  880. static int xenvif_get_extras(struct xenvif *vif,
  881. struct xen_netif_extra_info *extras,
  882. int work_to_do)
  883. {
  884. struct xen_netif_extra_info extra;
  885. RING_IDX cons = vif->tx.req_cons;
  886. do {
  887. if (unlikely(work_to_do-- <= 0)) {
  888. netdev_err(vif->dev, "Missing extra info\n");
  889. xenvif_fatal_tx_err(vif);
  890. return -EBADR;
  891. }
  892. memcpy(&extra, RING_GET_REQUEST(&vif->tx, cons),
  893. sizeof(extra));
  894. if (unlikely(!extra.type ||
  895. extra.type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
  896. vif->tx.req_cons = ++cons;
  897. netdev_err(vif->dev,
  898. "Invalid extra type: %d\n", extra.type);
  899. xenvif_fatal_tx_err(vif);
  900. return -EINVAL;
  901. }
  902. memcpy(&extras[extra.type - 1], &extra, sizeof(extra));
  903. vif->tx.req_cons = ++cons;
  904. } while (extra.flags & XEN_NETIF_EXTRA_FLAG_MORE);
  905. return work_to_do;
  906. }
  907. static int xenvif_set_skb_gso(struct xenvif *vif,
  908. struct sk_buff *skb,
  909. struct xen_netif_extra_info *gso)
  910. {
  911. if (!gso->u.gso.size) {
  912. netdev_err(vif->dev, "GSO size must not be zero.\n");
  913. xenvif_fatal_tx_err(vif);
  914. return -EINVAL;
  915. }
  916. switch (gso->u.gso.type) {
  917. case XEN_NETIF_GSO_TYPE_TCPV4:
  918. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  919. break;
  920. case XEN_NETIF_GSO_TYPE_TCPV6:
  921. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
  922. break;
  923. default:
  924. netdev_err(vif->dev, "Bad GSO type %d.\n", gso->u.gso.type);
  925. xenvif_fatal_tx_err(vif);
  926. return -EINVAL;
  927. }
  928. skb_shinfo(skb)->gso_size = gso->u.gso.size;
  929. /* Header must be checked, and gso_segs computed. */
  930. skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
  931. skb_shinfo(skb)->gso_segs = 0;
  932. return 0;
  933. }
  934. static inline int maybe_pull_tail(struct sk_buff *skb, unsigned int len,
  935. unsigned int max)
  936. {
  937. if (skb_headlen(skb) >= len)
  938. return 0;
  939. /* If we need to pullup then pullup to the max, so we
  940. * won't need to do it again.
  941. */
  942. if (max > skb->len)
  943. max = skb->len;
  944. if (__pskb_pull_tail(skb, max - skb_headlen(skb)) == NULL)
  945. return -ENOMEM;
  946. if (skb_headlen(skb) < len)
  947. return -EPROTO;
  948. return 0;
  949. }
  950. /* This value should be large enough to cover a tagged ethernet header plus
  951. * maximally sized IP and TCP or UDP headers.
  952. */
  953. #define MAX_IP_HDR_LEN 128
  954. static int checksum_setup_ip(struct xenvif *vif, struct sk_buff *skb,
  955. int recalculate_partial_csum)
  956. {
  957. unsigned int off;
  958. bool fragment;
  959. int err;
  960. fragment = false;
  961. err = maybe_pull_tail(skb,
  962. sizeof(struct iphdr),
  963. MAX_IP_HDR_LEN);
  964. if (err < 0)
  965. goto out;
  966. if (ip_hdr(skb)->frag_off & htons(IP_OFFSET | IP_MF))
  967. fragment = true;
  968. off = ip_hdrlen(skb);
  969. err = -EPROTO;
  970. if (fragment)
  971. goto out;
  972. switch (ip_hdr(skb)->protocol) {
  973. case IPPROTO_TCP:
  974. err = maybe_pull_tail(skb,
  975. off + sizeof(struct tcphdr),
  976. MAX_IP_HDR_LEN);
  977. if (err < 0)
  978. goto out;
  979. if (!skb_partial_csum_set(skb, off,
  980. offsetof(struct tcphdr, check))) {
  981. err = -EPROTO;
  982. goto out;
  983. }
  984. if (recalculate_partial_csum)
  985. tcp_hdr(skb)->check =
  986. ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  987. ip_hdr(skb)->daddr,
  988. skb->len - off,
  989. IPPROTO_TCP, 0);
  990. break;
  991. case IPPROTO_UDP:
  992. err = maybe_pull_tail(skb,
  993. off + sizeof(struct udphdr),
  994. MAX_IP_HDR_LEN);
  995. if (err < 0)
  996. goto out;
  997. if (!skb_partial_csum_set(skb, off,
  998. offsetof(struct udphdr, check))) {
  999. err = -EPROTO;
  1000. goto out;
  1001. }
  1002. if (recalculate_partial_csum)
  1003. udp_hdr(skb)->check =
  1004. ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  1005. ip_hdr(skb)->daddr,
  1006. skb->len - off,
  1007. IPPROTO_UDP, 0);
  1008. break;
  1009. default:
  1010. goto out;
  1011. }
  1012. err = 0;
  1013. out:
  1014. return err;
  1015. }
  1016. /* This value should be large enough to cover a tagged ethernet header plus
  1017. * an IPv6 header, all options, and a maximal TCP or UDP header.
  1018. */
  1019. #define MAX_IPV6_HDR_LEN 256
  1020. #define OPT_HDR(type, skb, off) \
  1021. (type *)(skb_network_header(skb) + (off))
  1022. static int checksum_setup_ipv6(struct xenvif *vif, struct sk_buff *skb,
  1023. int recalculate_partial_csum)
  1024. {
  1025. int err;
  1026. u8 nexthdr;
  1027. unsigned int off;
  1028. unsigned int len;
  1029. bool fragment;
  1030. bool done;
  1031. fragment = false;
  1032. done = false;
  1033. off = sizeof(struct ipv6hdr);
  1034. err = maybe_pull_tail(skb, off, MAX_IPV6_HDR_LEN);
  1035. if (err < 0)
  1036. goto out;
  1037. nexthdr = ipv6_hdr(skb)->nexthdr;
  1038. len = sizeof(struct ipv6hdr) + ntohs(ipv6_hdr(skb)->payload_len);
  1039. while (off <= len && !done) {
  1040. switch (nexthdr) {
  1041. case IPPROTO_DSTOPTS:
  1042. case IPPROTO_HOPOPTS:
  1043. case IPPROTO_ROUTING: {
  1044. struct ipv6_opt_hdr *hp;
  1045. err = maybe_pull_tail(skb,
  1046. off +
  1047. sizeof(struct ipv6_opt_hdr),
  1048. MAX_IPV6_HDR_LEN);
  1049. if (err < 0)
  1050. goto out;
  1051. hp = OPT_HDR(struct ipv6_opt_hdr, skb, off);
  1052. nexthdr = hp->nexthdr;
  1053. off += ipv6_optlen(hp);
  1054. break;
  1055. }
  1056. case IPPROTO_AH: {
  1057. struct ip_auth_hdr *hp;
  1058. err = maybe_pull_tail(skb,
  1059. off +
  1060. sizeof(struct ip_auth_hdr),
  1061. MAX_IPV6_HDR_LEN);
  1062. if (err < 0)
  1063. goto out;
  1064. hp = OPT_HDR(struct ip_auth_hdr, skb, off);
  1065. nexthdr = hp->nexthdr;
  1066. off += ipv6_authlen(hp);
  1067. break;
  1068. }
  1069. case IPPROTO_FRAGMENT: {
  1070. struct frag_hdr *hp;
  1071. err = maybe_pull_tail(skb,
  1072. off +
  1073. sizeof(struct frag_hdr),
  1074. MAX_IPV6_HDR_LEN);
  1075. if (err < 0)
  1076. goto out;
  1077. hp = OPT_HDR(struct frag_hdr, skb, off);
  1078. if (hp->frag_off & htons(IP6_OFFSET | IP6_MF))
  1079. fragment = true;
  1080. nexthdr = hp->nexthdr;
  1081. off += sizeof(struct frag_hdr);
  1082. break;
  1083. }
  1084. default:
  1085. done = true;
  1086. break;
  1087. }
  1088. }
  1089. err = -EPROTO;
  1090. if (!done || fragment)
  1091. goto out;
  1092. switch (nexthdr) {
  1093. case IPPROTO_TCP:
  1094. err = maybe_pull_tail(skb,
  1095. off + sizeof(struct tcphdr),
  1096. MAX_IPV6_HDR_LEN);
  1097. if (err < 0)
  1098. goto out;
  1099. if (!skb_partial_csum_set(skb, off,
  1100. offsetof(struct tcphdr, check))) {
  1101. err = -EPROTO;
  1102. goto out;
  1103. }
  1104. if (recalculate_partial_csum)
  1105. tcp_hdr(skb)->check =
  1106. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  1107. &ipv6_hdr(skb)->daddr,
  1108. skb->len - off,
  1109. IPPROTO_TCP, 0);
  1110. break;
  1111. case IPPROTO_UDP:
  1112. err = maybe_pull_tail(skb,
  1113. off + sizeof(struct udphdr),
  1114. MAX_IPV6_HDR_LEN);
  1115. if (err < 0)
  1116. goto out;
  1117. if (!skb_partial_csum_set(skb, off,
  1118. offsetof(struct udphdr, check))) {
  1119. err = -EPROTO;
  1120. goto out;
  1121. }
  1122. if (recalculate_partial_csum)
  1123. udp_hdr(skb)->check =
  1124. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  1125. &ipv6_hdr(skb)->daddr,
  1126. skb->len - off,
  1127. IPPROTO_UDP, 0);
  1128. break;
  1129. default:
  1130. goto out;
  1131. }
  1132. err = 0;
  1133. out:
  1134. return err;
  1135. }
  1136. static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
  1137. {
  1138. int err = -EPROTO;
  1139. int recalculate_partial_csum = 0;
  1140. /* A GSO SKB must be CHECKSUM_PARTIAL. However some buggy
  1141. * peers can fail to set NETRXF_csum_blank when sending a GSO
  1142. * frame. In this case force the SKB to CHECKSUM_PARTIAL and
  1143. * recalculate the partial checksum.
  1144. */
  1145. if (skb->ip_summed != CHECKSUM_PARTIAL && skb_is_gso(skb)) {
  1146. vif->rx_gso_checksum_fixup++;
  1147. skb->ip_summed = CHECKSUM_PARTIAL;
  1148. recalculate_partial_csum = 1;
  1149. }
  1150. /* A non-CHECKSUM_PARTIAL SKB does not require setup. */
  1151. if (skb->ip_summed != CHECKSUM_PARTIAL)
  1152. return 0;
  1153. if (skb->protocol == htons(ETH_P_IP))
  1154. err = checksum_setup_ip(vif, skb, recalculate_partial_csum);
  1155. else if (skb->protocol == htons(ETH_P_IPV6))
  1156. err = checksum_setup_ipv6(vif, skb, recalculate_partial_csum);
  1157. return err;
  1158. }
  1159. static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
  1160. {
  1161. u64 now = get_jiffies_64();
  1162. u64 next_credit = vif->credit_window_start +
  1163. msecs_to_jiffies(vif->credit_usec / 1000);
  1164. /* Timer could already be pending in rare cases. */
  1165. if (timer_pending(&vif->credit_timeout))
  1166. return true;
  1167. /* Passed the point where we can replenish credit? */
  1168. if (time_after_eq64(now, next_credit)) {
  1169. vif->credit_window_start = now;
  1170. tx_add_credit(vif);
  1171. }
  1172. /* Still too big to send right now? Set a callback. */
  1173. if (size > vif->remaining_credit) {
  1174. vif->credit_timeout.data =
  1175. (unsigned long)vif;
  1176. vif->credit_timeout.function =
  1177. tx_credit_callback;
  1178. mod_timer(&vif->credit_timeout,
  1179. next_credit);
  1180. vif->credit_window_start = next_credit;
  1181. return true;
  1182. }
  1183. return false;
  1184. }
  1185. static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
  1186. {
  1187. struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
  1188. struct sk_buff *skb;
  1189. int ret;
  1190. while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
  1191. < MAX_PENDING_REQS) &&
  1192. (skb_queue_len(&vif->tx_queue) < budget)) {
  1193. struct xen_netif_tx_request txreq;
  1194. struct xen_netif_tx_request txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];
  1195. struct page *page;
  1196. struct xen_netif_extra_info extras[XEN_NETIF_EXTRA_TYPE_MAX-1];
  1197. u16 pending_idx;
  1198. RING_IDX idx;
  1199. int work_to_do;
  1200. unsigned int data_len;
  1201. pending_ring_idx_t index;
  1202. if (vif->tx.sring->req_prod - vif->tx.req_cons >
  1203. XEN_NETIF_TX_RING_SIZE) {
  1204. netdev_err(vif->dev,
  1205. "Impossible number of requests. "
  1206. "req_prod %d, req_cons %d, size %ld\n",
  1207. vif->tx.sring->req_prod, vif->tx.req_cons,
  1208. XEN_NETIF_TX_RING_SIZE);
  1209. xenvif_fatal_tx_err(vif);
  1210. continue;
  1211. }
  1212. work_to_do = RING_HAS_UNCONSUMED_REQUESTS(&vif->tx);
  1213. if (!work_to_do)
  1214. break;
  1215. idx = vif->tx.req_cons;
  1216. rmb(); /* Ensure that we see the request before we copy it. */
  1217. memcpy(&txreq, RING_GET_REQUEST(&vif->tx, idx), sizeof(txreq));
  1218. /* Credit-based scheduling. */
  1219. if (txreq.size > vif->remaining_credit &&
  1220. tx_credit_exceeded(vif, txreq.size))
  1221. break;
  1222. vif->remaining_credit -= txreq.size;
  1223. work_to_do--;
  1224. vif->tx.req_cons = ++idx;
  1225. memset(extras, 0, sizeof(extras));
  1226. if (txreq.flags & XEN_NETTXF_extra_info) {
  1227. work_to_do = xenvif_get_extras(vif, extras,
  1228. work_to_do);
  1229. idx = vif->tx.req_cons;
  1230. if (unlikely(work_to_do < 0))
  1231. break;
  1232. }
  1233. ret = xenvif_count_requests(vif, &txreq, txfrags, work_to_do);
  1234. if (unlikely(ret < 0))
  1235. break;
  1236. idx += ret;
  1237. if (unlikely(txreq.size < ETH_HLEN)) {
  1238. netdev_dbg(vif->dev,
  1239. "Bad packet size: %d\n", txreq.size);
  1240. xenvif_tx_err(vif, &txreq, idx);
  1241. break;
  1242. }
  1243. /* No crossing a page as the payload mustn't fragment. */
  1244. if (unlikely((txreq.offset + txreq.size) > PAGE_SIZE)) {
  1245. netdev_err(vif->dev,
  1246. "txreq.offset: %x, size: %u, end: %lu\n",
  1247. txreq.offset, txreq.size,
  1248. (txreq.offset&~PAGE_MASK) + txreq.size);
  1249. xenvif_fatal_tx_err(vif);
  1250. break;
  1251. }
  1252. index = pending_index(vif->pending_cons);
  1253. pending_idx = vif->pending_ring[index];
  1254. data_len = (txreq.size > PKT_PROT_LEN &&
  1255. ret < XEN_NETBK_LEGACY_SLOTS_MAX) ?
  1256. PKT_PROT_LEN : txreq.size;
  1257. skb = alloc_skb(data_len + NET_SKB_PAD + NET_IP_ALIGN,
  1258. GFP_ATOMIC | __GFP_NOWARN);
  1259. if (unlikely(skb == NULL)) {
  1260. netdev_dbg(vif->dev,
  1261. "Can't allocate a skb in start_xmit.\n");
  1262. xenvif_tx_err(vif, &txreq, idx);
  1263. break;
  1264. }
  1265. /* Packets passed to netif_rx() must have some headroom. */
  1266. skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
  1267. if (extras[XEN_NETIF_EXTRA_TYPE_GSO - 1].type) {
  1268. struct xen_netif_extra_info *gso;
  1269. gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO - 1];
  1270. if (xenvif_set_skb_gso(vif, skb, gso)) {
  1271. /* Failure in xenvif_set_skb_gso is fatal. */
  1272. kfree_skb(skb);
  1273. break;
  1274. }
  1275. }
  1276. /* XXX could copy straight to head */
  1277. page = xenvif_alloc_page(vif, pending_idx);
  1278. if (!page) {
  1279. kfree_skb(skb);
  1280. xenvif_tx_err(vif, &txreq, idx);
  1281. break;
  1282. }
  1283. gop->source.u.ref = txreq.gref;
  1284. gop->source.domid = vif->domid;
  1285. gop->source.offset = txreq.offset;
  1286. gop->dest.u.gmfn = virt_to_mfn(page_address(page));
  1287. gop->dest.domid = DOMID_SELF;
  1288. gop->dest.offset = txreq.offset;
  1289. gop->len = txreq.size;
  1290. gop->flags = GNTCOPY_source_gref;
  1291. gop++;
  1292. memcpy(&vif->pending_tx_info[pending_idx].req,
  1293. &txreq, sizeof(txreq));
  1294. vif->pending_tx_info[pending_idx].head = index;
  1295. *((u16 *)skb->data) = pending_idx;
  1296. __skb_put(skb, data_len);
  1297. skb_shinfo(skb)->nr_frags = ret;
  1298. if (data_len < txreq.size) {
  1299. skb_shinfo(skb)->nr_frags++;
  1300. frag_set_pending_idx(&skb_shinfo(skb)->frags[0],
  1301. pending_idx);
  1302. } else {
  1303. frag_set_pending_idx(&skb_shinfo(skb)->frags[0],
  1304. INVALID_PENDING_IDX);
  1305. }
  1306. vif->pending_cons++;
  1307. request_gop = xenvif_get_requests(vif, skb, txfrags, gop);
  1308. if (request_gop == NULL) {
  1309. kfree_skb(skb);
  1310. xenvif_tx_err(vif, &txreq, idx);
  1311. break;
  1312. }
  1313. gop = request_gop;
  1314. __skb_queue_tail(&vif->tx_queue, skb);
  1315. vif->tx.req_cons = idx;
  1316. if ((gop-vif->tx_copy_ops) >= ARRAY_SIZE(vif->tx_copy_ops))
  1317. break;
  1318. }
  1319. return gop - vif->tx_copy_ops;
  1320. }
  1321. static int xenvif_tx_submit(struct xenvif *vif)
  1322. {
  1323. struct gnttab_copy *gop = vif->tx_copy_ops;
  1324. struct sk_buff *skb;
  1325. int work_done = 0;
  1326. while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
  1327. struct xen_netif_tx_request *txp;
  1328. u16 pending_idx;
  1329. unsigned data_len;
  1330. pending_idx = *((u16 *)skb->data);
  1331. txp = &vif->pending_tx_info[pending_idx].req;
  1332. /* Check the remap error code. */
  1333. if (unlikely(xenvif_tx_check_gop(vif, skb, &gop))) {
  1334. netdev_dbg(vif->dev, "netback grant failed.\n");
  1335. skb_shinfo(skb)->nr_frags = 0;
  1336. kfree_skb(skb);
  1337. continue;
  1338. }
  1339. data_len = skb->len;
  1340. memcpy(skb->data,
  1341. (void *)(idx_to_kaddr(vif, pending_idx)|txp->offset),
  1342. data_len);
  1343. if (data_len < txp->size) {
  1344. /* Append the packet payload as a fragment. */
  1345. txp->offset += data_len;
  1346. txp->size -= data_len;
  1347. } else {
  1348. /* Schedule a response immediately. */
  1349. xenvif_idx_release(vif, pending_idx,
  1350. XEN_NETIF_RSP_OKAY);
  1351. }
  1352. if (txp->flags & XEN_NETTXF_csum_blank)
  1353. skb->ip_summed = CHECKSUM_PARTIAL;
  1354. else if (txp->flags & XEN_NETTXF_data_validated)
  1355. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1356. xenvif_fill_frags(vif, skb);
  1357. if (skb_is_nonlinear(skb) && skb_headlen(skb) < PKT_PROT_LEN) {
  1358. int target = min_t(int, skb->len, PKT_PROT_LEN);
  1359. __pskb_pull_tail(skb, target - skb_headlen(skb));
  1360. }
  1361. skb->dev = vif->dev;
  1362. skb->protocol = eth_type_trans(skb, skb->dev);
  1363. skb_reset_network_header(skb);
  1364. if (checksum_setup(vif, skb)) {
  1365. netdev_dbg(vif->dev,
  1366. "Can't setup checksum in net_tx_action\n");
  1367. kfree_skb(skb);
  1368. continue;
  1369. }
  1370. skb_probe_transport_header(skb, 0);
  1371. vif->dev->stats.rx_bytes += skb->len;
  1372. vif->dev->stats.rx_packets++;
  1373. work_done++;
  1374. netif_receive_skb(skb);
  1375. }
  1376. return work_done;
  1377. }
  1378. /* Called after netfront has transmitted */
  1379. int xenvif_tx_action(struct xenvif *vif, int budget)
  1380. {
  1381. unsigned nr_gops;
  1382. int work_done;
  1383. if (unlikely(!tx_work_todo(vif)))
  1384. return 0;
  1385. nr_gops = xenvif_tx_build_gops(vif, budget);
  1386. if (nr_gops == 0)
  1387. return 0;
  1388. gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
  1389. work_done = xenvif_tx_submit(vif);
  1390. return work_done;
  1391. }
  1392. static void xenvif_idx_release(struct xenvif *vif, u16 pending_idx,
  1393. u8 status)
  1394. {
  1395. struct pending_tx_info *pending_tx_info;
  1396. pending_ring_idx_t head;
  1397. u16 peek; /* peek into next tx request */
  1398. BUG_ON(vif->mmap_pages[pending_idx] == (void *)(~0UL));
  1399. /* Already complete? */
  1400. if (vif->mmap_pages[pending_idx] == NULL)
  1401. return;
  1402. pending_tx_info = &vif->pending_tx_info[pending_idx];
  1403. head = pending_tx_info->head;
  1404. BUG_ON(!pending_tx_is_head(vif, head));
  1405. BUG_ON(vif->pending_ring[pending_index(head)] != pending_idx);
  1406. do {
  1407. pending_ring_idx_t index;
  1408. pending_ring_idx_t idx = pending_index(head);
  1409. u16 info_idx = vif->pending_ring[idx];
  1410. pending_tx_info = &vif->pending_tx_info[info_idx];
  1411. make_tx_response(vif, &pending_tx_info->req, status);
  1412. /* Setting any number other than
  1413. * INVALID_PENDING_RING_IDX indicates this slot is
  1414. * starting a new packet / ending a previous packet.
  1415. */
  1416. pending_tx_info->head = 0;
  1417. index = pending_index(vif->pending_prod++);
  1418. vif->pending_ring[index] = vif->pending_ring[info_idx];
  1419. peek = vif->pending_ring[pending_index(++head)];
  1420. } while (!pending_tx_is_head(vif, peek));
  1421. put_page(vif->mmap_pages[pending_idx]);
  1422. vif->mmap_pages[pending_idx] = NULL;
  1423. }
  1424. static void make_tx_response(struct xenvif *vif,
  1425. struct xen_netif_tx_request *txp,
  1426. s8 st)
  1427. {
  1428. RING_IDX i = vif->tx.rsp_prod_pvt;
  1429. struct xen_netif_tx_response *resp;
  1430. int notify;
  1431. resp = RING_GET_RESPONSE(&vif->tx, i);
  1432. resp->id = txp->id;
  1433. resp->status = st;
  1434. if (txp->flags & XEN_NETTXF_extra_info)
  1435. RING_GET_RESPONSE(&vif->tx, ++i)->status = XEN_NETIF_RSP_NULL;
  1436. vif->tx.rsp_prod_pvt = ++i;
  1437. RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->tx, notify);
  1438. if (notify)
  1439. notify_remote_via_irq(vif->tx_irq);
  1440. }
  1441. static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
  1442. u16 id,
  1443. s8 st,
  1444. u16 offset,
  1445. u16 size,
  1446. u16 flags)
  1447. {
  1448. RING_IDX i = vif->rx.rsp_prod_pvt;
  1449. struct xen_netif_rx_response *resp;
  1450. resp = RING_GET_RESPONSE(&vif->rx, i);
  1451. resp->offset = offset;
  1452. resp->flags = flags;
  1453. resp->id = id;
  1454. resp->status = (s16)size;
  1455. if (st < 0)
  1456. resp->status = (s16)st;
  1457. vif->rx.rsp_prod_pvt = ++i;
  1458. return resp;
  1459. }
  1460. static inline int rx_work_todo(struct xenvif *vif)
  1461. {
  1462. return !skb_queue_empty(&vif->rx_queue);
  1463. }
  1464. static inline int tx_work_todo(struct xenvif *vif)
  1465. {
  1466. if (likely(RING_HAS_UNCONSUMED_REQUESTS(&vif->tx)) &&
  1467. (nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
  1468. < MAX_PENDING_REQS))
  1469. return 1;
  1470. return 0;
  1471. }
  1472. void xenvif_unmap_frontend_rings(struct xenvif *vif)
  1473. {
  1474. if (vif->tx.sring)
  1475. xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
  1476. vif->tx.sring);
  1477. if (vif->rx.sring)
  1478. xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
  1479. vif->rx.sring);
  1480. }
  1481. int xenvif_map_frontend_rings(struct xenvif *vif,
  1482. grant_ref_t tx_ring_ref,
  1483. grant_ref_t rx_ring_ref)
  1484. {
  1485. void *addr;
  1486. struct xen_netif_tx_sring *txs;
  1487. struct xen_netif_rx_sring *rxs;
  1488. int err = -ENOMEM;
  1489. err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
  1490. tx_ring_ref, &addr);
  1491. if (err)
  1492. goto err;
  1493. txs = (struct xen_netif_tx_sring *)addr;
  1494. BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
  1495. err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
  1496. rx_ring_ref, &addr);
  1497. if (err)
  1498. goto err;
  1499. rxs = (struct xen_netif_rx_sring *)addr;
  1500. BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE);
  1501. vif->rx_req_cons_peek = 0;
  1502. return 0;
  1503. err:
  1504. xenvif_unmap_frontend_rings(vif);
  1505. return err;
  1506. }
  1507. int xenvif_kthread(void *data)
  1508. {
  1509. struct xenvif *vif = data;
  1510. while (!kthread_should_stop()) {
  1511. wait_event_interruptible(vif->wq,
  1512. rx_work_todo(vif) ||
  1513. kthread_should_stop());
  1514. if (kthread_should_stop())
  1515. break;
  1516. if (rx_work_todo(vif))
  1517. xenvif_rx_action(vif);
  1518. cond_resched();
  1519. }
  1520. return 0;
  1521. }
  1522. static int __init netback_init(void)
  1523. {
  1524. int rc = 0;
  1525. if (!xen_domain())
  1526. return -ENODEV;
  1527. if (fatal_skb_slots < XEN_NETBK_LEGACY_SLOTS_MAX) {
  1528. pr_info("fatal_skb_slots too small (%d), bump it to XEN_NETBK_LEGACY_SLOTS_MAX (%d)\n",
  1529. fatal_skb_slots, XEN_NETBK_LEGACY_SLOTS_MAX);
  1530. fatal_skb_slots = XEN_NETBK_LEGACY_SLOTS_MAX;
  1531. }
  1532. rc = xenvif_xenbus_init();
  1533. if (rc)
  1534. goto failed_init;
  1535. return 0;
  1536. failed_init:
  1537. return rc;
  1538. }
  1539. module_init(netback_init);
  1540. static void __exit netback_fini(void)
  1541. {
  1542. xenvif_xenbus_fini();
  1543. }
  1544. module_exit(netback_fini);
  1545. MODULE_LICENSE("Dual BSD/GPL");
  1546. MODULE_ALIAS("xen-backend:vif");