Lines Matching refs:sk
106 static inline int skcipher_sndbuf(struct sock *sk) in skcipher_sndbuf() argument
108 struct alg_sock *ask = alg_sk(sk); in skcipher_sndbuf()
111 return max_t(int, max_t(int, sk->sk_sndbuf & PAGE_MASK, PAGE_SIZE) - in skcipher_sndbuf()
115 static inline bool skcipher_writable(struct sock *sk) in skcipher_writable() argument
117 return PAGE_SIZE <= skcipher_sndbuf(sk); in skcipher_writable()
120 static int skcipher_alloc_sgl(struct sock *sk) in skcipher_alloc_sgl() argument
122 struct alg_sock *ask = alg_sk(sk); in skcipher_alloc_sgl()
132 sgl = sock_kmalloc(sk, sizeof(*sgl) + in skcipher_alloc_sgl()
150 static void skcipher_pull_sgl(struct sock *sk, int used, int put) in skcipher_pull_sgl() argument
152 struct alg_sock *ask = alg_sk(sk); in skcipher_pull_sgl()
183 sock_kfree_s(sk, sgl, in skcipher_pull_sgl()
192 static void skcipher_free_sgl(struct sock *sk) in skcipher_free_sgl() argument
194 struct alg_sock *ask = alg_sk(sk); in skcipher_free_sgl()
197 skcipher_pull_sgl(sk, ctx->used, 1); in skcipher_free_sgl()
200 static int skcipher_wait_for_wmem(struct sock *sk, unsigned flags) in skcipher_wait_for_wmem() argument
209 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); in skcipher_wait_for_wmem()
214 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); in skcipher_wait_for_wmem()
216 if (sk_wait_event(sk, &timeout, skcipher_writable(sk))) { in skcipher_wait_for_wmem()
221 finish_wait(sk_sleep(sk), &wait); in skcipher_wait_for_wmem()
226 static void skcipher_wmem_wakeup(struct sock *sk) in skcipher_wmem_wakeup() argument
230 if (!skcipher_writable(sk)) in skcipher_wmem_wakeup()
234 wq = rcu_dereference(sk->sk_wq); in skcipher_wmem_wakeup()
239 sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN); in skcipher_wmem_wakeup()
243 static int skcipher_wait_for_data(struct sock *sk, unsigned flags) in skcipher_wait_for_data() argument
245 struct alg_sock *ask = alg_sk(sk); in skcipher_wait_for_data()
255 sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); in skcipher_wait_for_data()
260 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); in skcipher_wait_for_data()
262 if (sk_wait_event(sk, &timeout, ctx->used)) { in skcipher_wait_for_data()
267 finish_wait(sk_sleep(sk), &wait); in skcipher_wait_for_data()
269 sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); in skcipher_wait_for_data()
274 static void skcipher_data_wakeup(struct sock *sk) in skcipher_data_wakeup() argument
276 struct alg_sock *ask = alg_sk(sk); in skcipher_data_wakeup()
284 wq = rcu_dereference(sk->sk_wq); in skcipher_data_wakeup()
289 sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT); in skcipher_data_wakeup()
296 struct sock *sk = sock->sk; in skcipher_sendmsg() local
297 struct alg_sock *ask = alg_sk(sk); in skcipher_sendmsg()
335 lock_sock(sk); in skcipher_sendmsg()
373 if (!skcipher_writable(sk)) { in skcipher_sendmsg()
374 err = skcipher_wait_for_wmem(sk, msg->msg_flags); in skcipher_sendmsg()
379 len = min_t(unsigned long, len, skcipher_sndbuf(sk)); in skcipher_sendmsg()
381 err = skcipher_alloc_sgl(sk); in skcipher_sendmsg()
425 skcipher_data_wakeup(sk); in skcipher_sendmsg()
426 release_sock(sk); in skcipher_sendmsg()
434 struct sock *sk = sock->sk; in skcipher_sendpage() local
435 struct alg_sock *ask = alg_sk(sk); in skcipher_sendpage()
443 lock_sock(sk); in skcipher_sendpage()
450 if (!skcipher_writable(sk)) { in skcipher_sendpage()
451 err = skcipher_wait_for_wmem(sk, flags); in skcipher_sendpage()
456 err = skcipher_alloc_sgl(sk); in skcipher_sendpage()
476 skcipher_data_wakeup(sk); in skcipher_sendpage()
477 release_sock(sk); in skcipher_sendpage()
502 struct sock *sk = sock->sk; in skcipher_recvmsg_async() local
503 struct alg_sock *ask = alg_sk(sk); in skcipher_recvmsg_async()
531 lock_sock(sk); in skcipher_recvmsg_async()
547 err = skcipher_wait_for_data(sk, flags); in skcipher_recvmsg_async()
608 skcipher_pull_sgl(sk, used, 0); in skcipher_recvmsg_async()
628 skcipher_wmem_wakeup(sk); in skcipher_recvmsg_async()
629 release_sock(sk); in skcipher_recvmsg_async()
638 struct sock *sk = sock->sk; in skcipher_recvmsg_sync() local
639 struct alg_sock *ask = alg_sk(sk); in skcipher_recvmsg_sync()
652 lock_sock(sk); in skcipher_recvmsg_sync()
655 err = skcipher_wait_for_data(sk, flags); in skcipher_recvmsg_sync()
697 skcipher_pull_sgl(sk, used, 1); in skcipher_recvmsg_sync()
704 skcipher_wmem_wakeup(sk); in skcipher_recvmsg_sync()
705 release_sock(sk); in skcipher_recvmsg_sync()
721 struct sock *sk = sock->sk; in skcipher_poll() local
722 struct alg_sock *ask = alg_sk(sk); in skcipher_poll()
726 sock_poll_wait(file, sk_sleep(sk), wait); in skcipher_poll()
732 if (skcipher_writable(sk)) in skcipher_poll()
766 struct sock *sk = sock->sk; in skcipher_check_key() local
767 struct alg_sock *ask = alg_sk(sk); in skcipher_check_key()
769 lock_sock(sk); in skcipher_check_key()
793 release_sock(sk); in skcipher_check_key()
895 static void skcipher_wait(struct sock *sk) in skcipher_wait() argument
897 struct alg_sock *ask = alg_sk(sk); in skcipher_wait()
905 static void skcipher_sock_destruct(struct sock *sk) in skcipher_sock_destruct() argument
907 struct alg_sock *ask = alg_sk(sk); in skcipher_sock_destruct()
912 skcipher_wait(sk); in skcipher_sock_destruct()
914 skcipher_free_sgl(sk); in skcipher_sock_destruct()
915 sock_kzfree_s(sk, ctx->iv, crypto_skcipher_ivsize(tfm)); in skcipher_sock_destruct()
916 sock_kfree_s(sk, ctx, ctx->len); in skcipher_sock_destruct()
917 af_alg_release_parent(sk); in skcipher_sock_destruct()
920 static int skcipher_accept_parent_nokey(void *private, struct sock *sk) in skcipher_accept_parent_nokey() argument
923 struct alg_sock *ask = alg_sk(sk); in skcipher_accept_parent_nokey()
928 ctx = sock_kmalloc(sk, len, GFP_KERNEL); in skcipher_accept_parent_nokey()
932 ctx->iv = sock_kmalloc(sk, crypto_skcipher_ivsize(skcipher), in skcipher_accept_parent_nokey()
935 sock_kfree_s(sk, ctx, len); in skcipher_accept_parent_nokey()
957 sk->sk_destruct = skcipher_sock_destruct; in skcipher_accept_parent_nokey()
962 static int skcipher_accept_parent(void *private, struct sock *sk) in skcipher_accept_parent() argument
969 return skcipher_accept_parent_nokey(private, sk); in skcipher_accept_parent()