Lines Matching full:map
101 struct sock_mapping *map; in pvcalls_enter_sock() local
107 map = (struct sock_mapping *)sock->sk->sk_send_head; in pvcalls_enter_sock()
108 if (map == NULL) in pvcalls_enter_sock()
112 atomic_inc(&map->refcount); in pvcalls_enter_sock()
113 return map; in pvcalls_enter_sock()
118 struct sock_mapping *map; in pvcalls_exit_sock() local
120 map = (struct sock_mapping *)sock->sk->sk_send_head; in pvcalls_exit_sock()
121 atomic_dec(&map->refcount); in pvcalls_exit_sock()
134 static bool pvcalls_front_write_todo(struct sock_mapping *map) in pvcalls_front_write_todo() argument
136 struct pvcalls_data_intf *intf = map->active.ring; in pvcalls_front_write_todo()
151 static bool pvcalls_front_read_todo(struct sock_mapping *map) in pvcalls_front_read_todo() argument
153 struct pvcalls_data_intf *intf = map->active.ring; in pvcalls_front_read_todo()
189 struct sock_mapping *map = (struct sock_mapping *)(uintptr_t) in pvcalls_front_event_handler() local
193 (void *)&map->passive.flags); in pvcalls_front_event_handler()
201 (void *)&map->passive.flags); in pvcalls_front_event_handler()
228 static void free_active_ring(struct sock_mapping *map);
231 struct sock_mapping *map) in pvcalls_front_destroy_active() argument
235 unbind_from_irqhandler(map->active.irq, map); in pvcalls_front_destroy_active()
239 if (!list_empty(&map->list)) in pvcalls_front_destroy_active()
240 list_del_init(&map->list); in pvcalls_front_destroy_active()
245 gnttab_end_foreign_access(map->active.ring->ref[i], NULL); in pvcalls_front_destroy_active()
246 gnttab_end_foreign_access(map->active.ref, NULL); in pvcalls_front_destroy_active()
247 free_active_ring(map); in pvcalls_front_destroy_active()
251 struct sock_mapping *map) in pvcalls_front_free_map() argument
253 pvcalls_front_destroy_active(bedata, map); in pvcalls_front_free_map()
255 kfree(map); in pvcalls_front_free_map()
260 struct sock_mapping *map = sock_map; in pvcalls_front_conn_handler() local
262 if (map == NULL) in pvcalls_front_conn_handler()
265 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_conn_handler()
273 struct sock_mapping *map = NULL; in pvcalls_front_socket() local
294 map = kzalloc_obj(*map); in pvcalls_front_socket()
295 if (map == NULL) { in pvcalls_front_socket()
304 kfree(map); in pvcalls_front_socket()
316 sock->sk->sk_send_head = (void *)map; in pvcalls_front_socket()
317 list_add_tail(&map->list, &bedata->socket_mappings); in pvcalls_front_socket()
322 req->u.socket.id = (uintptr_t) map; in pvcalls_front_socket()
346 static void free_active_ring(struct sock_mapping *map) in free_active_ring() argument
348 if (!map->active.ring) in free_active_ring()
351 free_pages_exact(map->active.data.in, in free_active_ring()
352 PAGE_SIZE << map->active.ring->ring_order); in free_active_ring()
353 free_page((unsigned long)map->active.ring); in free_active_ring()
356 static int alloc_active_ring(struct sock_mapping *map) in alloc_active_ring() argument
360 map->active.ring = (struct pvcalls_data_intf *) in alloc_active_ring()
362 if (!map->active.ring) in alloc_active_ring()
365 map->active.ring->ring_order = PVCALLS_RING_ORDER; in alloc_active_ring()
371 map->active.data.in = bytes; in alloc_active_ring()
372 map->active.data.out = bytes + in alloc_active_ring()
378 free_active_ring(map); in alloc_active_ring()
382 static int create_active(struct sock_mapping *map, evtchn_port_t *evtchn) in create_active() argument
388 init_waitqueue_head(&map->active.inflight_conn_req); in create_active()
390 bytes = map->active.data.in; in create_active()
392 map->active.ring->ref[i] = gnttab_grant_foreign_access( in create_active()
396 map->active.ref = gnttab_grant_foreign_access( in create_active()
398 pfn_to_gfn(virt_to_pfn((void *)map->active.ring)), 0); in create_active()
404 0, "pvcalls-frontend", map); in create_active()
410 map->active.irq = irq; in create_active()
411 map->active_socket = true; in create_active()
412 mutex_init(&map->active.in_mutex); in create_active()
413 mutex_init(&map->active.out_mutex); in create_active()
427 struct sock_mapping *map = NULL; in pvcalls_front_connect() local
435 map = pvcalls_enter_sock(sock); in pvcalls_front_connect()
436 if (IS_ERR(map)) in pvcalls_front_connect()
437 return PTR_ERR(map); in pvcalls_front_connect()
440 ret = alloc_active_ring(map); in pvcalls_front_connect()
445 ret = create_active(map, &evtchn); in pvcalls_front_connect()
447 free_active_ring(map); in pvcalls_front_connect()
456 pvcalls_front_destroy_active(NULL, map); in pvcalls_front_connect()
464 req->u.connect.id = (uintptr_t)map; in pvcalls_front_connect()
467 req->u.connect.ref = map->active.ref; in pvcalls_front_connect()
471 map->sock = sock; in pvcalls_front_connect()
546 struct sock_mapping *map; in pvcalls_front_sendmsg() local
554 map = pvcalls_enter_sock(sock); in pvcalls_front_sendmsg()
555 if (IS_ERR(map)) in pvcalls_front_sendmsg()
556 return PTR_ERR(map); in pvcalls_front_sendmsg()
558 mutex_lock(&map->active.out_mutex); in pvcalls_front_sendmsg()
559 if ((flags & MSG_DONTWAIT) && !pvcalls_front_write_todo(map)) { in pvcalls_front_sendmsg()
560 mutex_unlock(&map->active.out_mutex); in pvcalls_front_sendmsg()
569 sent = __write_ring(map->active.ring, in pvcalls_front_sendmsg()
570 &map->active.data, &msg->msg_iter, in pvcalls_front_sendmsg()
575 notify_remote_via_irq(map->active.irq); in pvcalls_front_sendmsg()
582 mutex_unlock(&map->active.out_mutex); in pvcalls_front_sendmsg()
641 struct sock_mapping *map; in pvcalls_front_recvmsg() local
646 map = pvcalls_enter_sock(sock); in pvcalls_front_recvmsg()
647 if (IS_ERR(map)) in pvcalls_front_recvmsg()
648 return PTR_ERR(map); in pvcalls_front_recvmsg()
650 mutex_lock(&map->active.in_mutex); in pvcalls_front_recvmsg()
654 while (!(flags & MSG_DONTWAIT) && !pvcalls_front_read_todo(map)) { in pvcalls_front_recvmsg()
655 wait_event_interruptible(map->active.inflight_conn_req, in pvcalls_front_recvmsg()
656 pvcalls_front_read_todo(map)); in pvcalls_front_recvmsg()
658 ret = __read_ring(map->active.ring, &map->active.data, in pvcalls_front_recvmsg()
662 notify_remote_via_irq(map->active.irq); in pvcalls_front_recvmsg()
668 mutex_unlock(&map->active.in_mutex); in pvcalls_front_recvmsg()
677 struct sock_mapping *map = NULL; in pvcalls_front_bind() local
684 map = pvcalls_enter_sock(sock); in pvcalls_front_bind()
685 if (IS_ERR(map)) in pvcalls_front_bind()
686 return PTR_ERR(map); in pvcalls_front_bind()
698 map->sock = sock; in pvcalls_front_bind()
700 req->u.bind.id = (uintptr_t)map; in pvcalls_front_bind()
704 init_waitqueue_head(&map->passive.inflight_accept_req); in pvcalls_front_bind()
706 map->active_socket = false; in pvcalls_front_bind()
722 map->passive.status = PVCALLS_STATUS_BIND; in pvcalls_front_bind()
731 struct sock_mapping *map; in pvcalls_front_listen() local
735 map = pvcalls_enter_sock(sock); in pvcalls_front_listen()
736 if (IS_ERR(map)) in pvcalls_front_listen()
737 return PTR_ERR(map); in pvcalls_front_listen()
740 if (map->passive.status != PVCALLS_STATUS_BIND) { in pvcalls_front_listen()
755 req->u.listen.id = (uintptr_t) map; in pvcalls_front_listen()
772 map->passive.status = PVCALLS_STATUS_LISTEN; in pvcalls_front_listen()
782 struct sock_mapping *map; in pvcalls_front_accept() local
788 map = pvcalls_enter_sock(sock); in pvcalls_front_accept()
789 if (IS_ERR(map)) in pvcalls_front_accept()
790 return PTR_ERR(map); in pvcalls_front_accept()
793 if (map->passive.status != PVCALLS_STATUS_LISTEN) { in pvcalls_front_accept()
804 (void *)&map->passive.flags)) { in pvcalls_front_accept()
805 req_id = READ_ONCE(map->passive.inflight_req_id); in pvcalls_front_accept()
808 map2 = map->passive.accept_map; in pvcalls_front_accept()
815 if (wait_event_interruptible(map->passive.inflight_accept_req, in pvcalls_front_accept()
817 (void *)&map->passive.flags))) { in pvcalls_front_accept()
826 (void *)&map->passive.flags); in pvcalls_front_accept()
833 (void *)&map->passive.flags); in pvcalls_front_accept()
843 (void *)&map->passive.flags); in pvcalls_front_accept()
852 (void *)&map->passive.flags); in pvcalls_front_accept()
864 req->u.accept.id = (uintptr_t) map; in pvcalls_front_accept()
868 map->passive.accept_map = map2; in pvcalls_front_accept()
877 WRITE_ONCE(map->passive.inflight_req_id, req_id); in pvcalls_front_accept()
895 map->passive.inflight_req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
897 (void *)&map->passive.flags); in pvcalls_front_accept()
906 map->passive.inflight_req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
908 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, (void *)&map->passive.flags); in pvcalls_front_accept()
909 wake_up(&map->passive.inflight_accept_req); in pvcalls_front_accept()
918 struct sock_mapping *map, in pvcalls_front_poll_passive() argument
925 (void *)&map->passive.flags)) { in pvcalls_front_poll_passive()
926 uint32_t req_id = READ_ONCE(map->passive.inflight_req_id); in pvcalls_front_poll_passive()
932 poll_wait(file, &map->passive.inflight_accept_req, wait); in pvcalls_front_poll_passive()
937 (void *)&map->passive.flags)) in pvcalls_front_poll_passive()
947 (void *)&map->passive.flags)) { in pvcalls_front_poll_passive()
961 req->u.poll.id = (uintptr_t) map; in pvcalls_front_poll_passive()
975 struct sock_mapping *map, in pvcalls_front_poll_active() argument
980 struct pvcalls_data_intf *intf = map->active.ring; in pvcalls_front_poll_active()
985 poll_wait(file, &map->active.inflight_conn_req, wait); in pvcalls_front_poll_active()
986 if (pvcalls_front_write_todo(map)) in pvcalls_front_poll_active()
988 if (pvcalls_front_read_todo(map)) in pvcalls_front_poll_active()
1000 struct sock_mapping *map; in pvcalls_front_poll() local
1003 map = pvcalls_enter_sock(sock); in pvcalls_front_poll()
1004 if (IS_ERR(map)) in pvcalls_front_poll()
1008 if (map->active_socket) in pvcalls_front_poll()
1009 ret = pvcalls_front_poll_active(file, bedata, map, wait); in pvcalls_front_poll()
1011 ret = pvcalls_front_poll_passive(file, bedata, map, wait); in pvcalls_front_poll()
1020 struct sock_mapping *map; in pvcalls_front_release() local
1027 map = pvcalls_enter_sock(sock); in pvcalls_front_release()
1028 if (IS_ERR(map)) { in pvcalls_front_release()
1029 if (PTR_ERR(map) == -ENOTCONN) in pvcalls_front_release()
1048 req->u.release.id = (uintptr_t)map; in pvcalls_front_release()
1059 if (map->active_socket) { in pvcalls_front_release()
1064 map->active.ring->in_error = -EBADF; in pvcalls_front_release()
1065 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_release()
1073 while (atomic_read(&map->refcount) > 1) in pvcalls_front_release()
1076 pvcalls_front_free_map(bedata, map); in pvcalls_front_release()
1079 wake_up(&map->passive.inflight_accept_req); in pvcalls_front_release()
1081 while (atomic_read(&map->refcount) > 1) in pvcalls_front_release()
1085 list_del(&map->list); in pvcalls_front_release()
1087 if (READ_ONCE(map->passive.inflight_req_id) != PVCALLS_INVALID_ID && in pvcalls_front_release()
1088 READ_ONCE(map->passive.inflight_req_id) != 0) { in pvcalls_front_release()
1090 map->passive.accept_map); in pvcalls_front_release()
1092 kfree(map); in pvcalls_front_release()
1109 struct sock_mapping *map = NULL, *n; in pvcalls_front_remove() local
1117 list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { in pvcalls_front_remove()
1118 map->sock->sk->sk_send_head = NULL; in pvcalls_front_remove()
1119 if (map->active_socket) { in pvcalls_front_remove()
1120 map->active.ring->in_error = -EBADF; in pvcalls_front_remove()
1121 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_remove()
1128 list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { in pvcalls_front_remove()
1129 if (map->active_socket) { in pvcalls_front_remove()
1131 pvcalls_front_free_map(bedata, map); in pvcalls_front_remove()
1133 list_del(&map->list); in pvcalls_front_remove()
1134 kfree(map); in pvcalls_front_remove()