From patchwork Mon Jul 31 12:06:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Mueller X-Patchwork-Id: 9871715 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 11339602F0 for ; Mon, 31 Jul 2017 12:11:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02187285CF for ; Mon, 31 Jul 2017 12:11:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAEAC285CD; Mon, 31 Jul 2017 12:11:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FC0F285CD for ; Mon, 31 Jul 2017 12:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752138AbdGaMLp (ORCPT ); Mon, 31 Jul 2017 08:11:45 -0400 Received: from mail.eperm.de ([89.247.134.16]:60878 "EHLO mail.eperm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752192AbdGaMLh (ORCPT ); Mon, 31 Jul 2017 08:11:37 -0400 Received: from positron.chronox.de (mail.eperm.de [89.247.134.16]) by mail.eperm.de (Postfix) with ESMTPA id 21259181442E; Mon, 31 Jul 2017 14:11:35 +0200 (CEST) From: Stephan =?ISO-8859-1?Q?M=FCller?= To: herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org Subject: [PATCH 04/16] crypto: AF_ALG - consolidate RX buffer service functions Date: Mon, 31 Jul 2017 14:06:50 +0200 Message-ID: <2741770.xU8IAUYmGv@positron.chronox.de> In-Reply-To: <4570630.RBIQc1aA22@positron.chronox.de> References: <4570630.RBIQc1aA22@positron.chronox.de> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Consolidate the common functions verifying the RX buffers: * skcipher_rcvbuf, aead_rcvbuf ==> af_alg_rcvbuf * skcipher_readable, aead_readable ==> af_alg_readable Signed-off-by: Stephan Mueller --- crypto/algif_aead.c | 16 +--------------- crypto/algif_skcipher.c | 16 +--------------- include/crypto/if_alg.h | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c index c923ce29bfe3..cdcf186296bd 100644 --- a/crypto/algif_aead.c +++ b/crypto/algif_aead.c @@ -47,20 +47,6 @@ struct aead_tfm { struct crypto_skcipher *null_tfm; }; -static inline int aead_rcvbuf(struct sock *sk) -{ - struct alg_sock *ask = alg_sk(sk); - struct af_alg_ctx *ctx = ask->private; - - return max_t(int, max_t(int, sk->sk_rcvbuf & PAGE_MASK, PAGE_SIZE) - - ctx->rcvused, 0); -} - -static inline bool aead_readable(struct sock *sk) -{ - return PAGE_SIZE <= aead_rcvbuf(sk); -} - static inline bool aead_sufficient_data(struct sock *sk) { struct alg_sock *ask = alg_sk(sk); @@ -655,7 +641,7 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg, size_t seglen; /* limit the amount of readable buffers */ - if (!aead_readable(sk)) + if (!af_alg_readable(sk)) break; if (!ctx->used) { diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index a5c6643f2abe..081df927fb8b 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -44,20 +44,6 @@ struct skcipher_tfm { bool has_key; }; -static inline int skcipher_rcvbuf(struct sock *sk) -{ - struct alg_sock *ask = alg_sk(sk); - struct af_alg_ctx *ctx = ask->private; - - return max_t(int, max_t(int, sk->sk_rcvbuf & PAGE_MASK, PAGE_SIZE) - - ctx->rcvused, 0); -} - -static inline bool skcipher_readable(struct sock *sk) -{ - return PAGE_SIZE <= skcipher_rcvbuf(sk); -} - static int skcipher_alloc_tsgl(struct sock *sk) { struct alg_sock *ask = alg_sk(sk); @@ -532,7 +518,7 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg, size_t seglen; /* limit the amount of readable buffers */ - if (!skcipher_readable(sk)) + if (!af_alg_readable(sk)) break; if (!ctx->used) { diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index 79d215f65acf..e1ac57c32d85 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -214,4 +214,30 @@ static inline bool af_alg_writable(struct sock *sk) return PAGE_SIZE <= af_alg_sndbuf(sk); } +/** + * Size of available buffer used by kernel for the RX user space operation. + * + * @sk socket of connection to user space + * @return number of bytes still available + */ +static inline int af_alg_rcvbuf(struct sock *sk) +{ + struct alg_sock *ask = alg_sk(sk); + struct af_alg_ctx *ctx = ask->private; + + return max_t(int, max_t(int, sk->sk_rcvbuf & PAGE_MASK, PAGE_SIZE) - + ctx->rcvused, 0); +} + +/** + * Can the RX buffer still be written to? + * + * @sk socket of connection to user space + * @return true => writable, false => not writable + */ +static inline bool af_alg_readable(struct sock *sk) +{ + return PAGE_SIZE <= af_alg_rcvbuf(sk); +} + #endif /* _CRYPTO_IF_ALG_H */