From patchwork Thu Jan 29 23:13:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tadeusz Struk X-Patchwork-Id: 5745821 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7D5D69F38B for ; Thu, 29 Jan 2015 23:18:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AA1F42024D for ; Thu, 29 Jan 2015 23:18:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F35B201F4 for ; Thu, 29 Jan 2015 23:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932318AbbA2XRb (ORCPT ); Thu, 29 Jan 2015 18:17:31 -0500 Received: from mga11.intel.com ([192.55.52.93]:19336 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932315AbbA2XRa (ORCPT ); Thu, 29 Jan 2015 18:17:30 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 29 Jan 2015 15:17:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,488,1418112000"; d="scan'208";a="519900406" Received: from tstruk-mobl1.intel.com (HELO [127.0.1.1]) ([134.134.171.155]) by orsmga003.jf.intel.com with ESMTP; 29 Jan 2015 15:10:01 -0800 Subject: [PATCH 1/3] net: socket: enable async read and write To: herbert@gondor.apana.org.au From: Tadeusz Struk Cc: linux-crypto@vger.kernel.org, netdev@vger.kernel.org, davem@davemloft.net, qat-linux@intel.com, linux-kernel@vger.kernel.org Date: Thu, 29 Jan 2015 15:13:45 -0800 Message-ID: <20150129231345.25156.51764.stgit@tstruk-mobl1> In-Reply-To: <20150129231338.25156.65450.stgit@tstruk-mobl1> References: <20150129231338.25156.65450.stgit@tstruk-mobl1> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP AIO read or write are not currently supported on sockets. This patch enables real socket async read/write. Please note - this patch is generated against cryptodev. Signed-off-by: Tadeusz Struk --- include/net/sock.h | 2 ++ net/socket.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 10 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/net/sock.h b/include/net/sock.h index 2210fec..2c7d160 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1397,6 +1397,8 @@ static inline struct kiocb *siocb_to_kiocb(struct sock_iocb *si) return si->kiocb; } +void sock_aio_complete(struct kiocb *iocb, long res, long res2); + struct socket_alloc { struct socket socket; struct inode vfs_inode; diff --git a/net/socket.c b/net/socket.c index a2c33a4..368fa9f 100644 --- a/net/socket.c +++ b/net/socket.c @@ -866,14 +866,25 @@ static ssize_t sock_splice_read(struct file *file, loff_t *ppos, return sock->ops->splice_read(sock, ppos, pipe, len, flags); } +void sock_aio_complete(struct kiocb *iocb, long res, long res2) +{ + struct sock_iocb *siocb = kiocb_to_siocb(iocb); + + kfree(siocb); + aio_complete(iocb, res, res2); +} +EXPORT_SYMBOL(sock_aio_complete); + static struct sock_iocb *alloc_sock_iocb(struct kiocb *iocb, struct sock_iocb *siocb) { - if (!is_sync_kiocb(iocb)) - BUG(); + if (!siocb) + siocb = kmalloc(sizeof(*siocb), GFP_KERNEL); - siocb->kiocb = iocb; - iocb->private = siocb; + if (siocb) { + siocb->kiocb = iocb; + iocb->private = siocb; + } return siocb; } @@ -901,7 +912,8 @@ static ssize_t do_sock_read(struct msghdr *msg, struct kiocb *iocb, static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, loff_t pos) { - struct sock_iocb siocb, *x; + struct sock_iocb siocb, *x = NULL; + int ret; if (pos != 0) return -ESPIPE; @@ -909,11 +921,18 @@ static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, if (iocb->ki_nbytes == 0) /* Match SYS5 behaviour */ return 0; + if (is_sync_kiocb(iocb)) + x = &siocb; - x = alloc_sock_iocb(iocb, &siocb); + x = alloc_sock_iocb(iocb, x); if (!x) return -ENOMEM; - return do_sock_read(&x->async_msg, iocb, iocb->ki_filp, iov, nr_segs); + ret = do_sock_read(&x->async_msg, iocb, iocb->ki_filp, iov, nr_segs); + + if (!is_sync_kiocb(iocb) && ret != -EIOCBQUEUED) + kfree(x); + + return ret; } static ssize_t do_sock_write(struct msghdr *msg, struct kiocb *iocb, @@ -942,16 +961,25 @@ static ssize_t do_sock_write(struct msghdr *msg, struct kiocb *iocb, static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, loff_t pos) { - struct sock_iocb siocb, *x; + struct sock_iocb siocb, *x = NULL; + int ret; if (pos != 0) return -ESPIPE; - x = alloc_sock_iocb(iocb, &siocb); + if (is_sync_kiocb(iocb)) + x = &siocb; + + x = alloc_sock_iocb(iocb, x); if (!x) return -ENOMEM; - return do_sock_write(&x->async_msg, iocb, iocb->ki_filp, iov, nr_segs); + ret = do_sock_write(&x->async_msg, iocb, iocb->ki_filp, iov, nr_segs); + + if (!is_sync_kiocb(iocb) && ret != -EIOCBQUEUED) + kfree(x); + + return ret; } /*