Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422713AbXBAJjm (ORCPT ); Thu, 1 Feb 2007 04:39:42 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1422716AbXBAJjk (ORCPT ); Thu, 1 Feb 2007 04:39:40 -0500 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:35802 "EHLO ecfrec.frec.bull.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422713AbXBAJjL convert rfc822-to-8bit (ORCPT ); Thu, 1 Feb 2007 04:39:11 -0500 Date: Thu, 1 Feb 2007 10:26:40 +0100 From: =?ISO-8859-1?Q?S=E9bastien_Dugu=E9?= To: linux-kernel Cc: Andrew Morton , linux-aio , Bharata B Rao , Christoph Hellwig , Suparna Bhattacharya , Ulrich Drepper , Zach Brown , Oleg Nesterov , Badari Pulavarty , Benjamin LaHaise , Jean Pierre Dion Subject: [PATCH -mm 1/7][AIO] - Rework compat_sys_io_submit Message-ID: <20070201102640.2bdd6f37@frecb000686> In-Reply-To: <20070201102252.240130c6@frecb000686> References: <20070201102252.240130c6@frecb000686> X-Mailer: Sylpheed-Claws 2.6.0 (GTK+ 2.8.20; i486-pc-linux-gnu) Mime-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on ECN002/FR/BULL(Release 5.0.12 |February 13, 2003) at 01/02/2007 10:40:00, Serialize by Router on ECN002/FR/BULL(Release 5.0.12 |February 13, 2003) at 01/02/2007 10:40:06, Serialize complete at 01/02/2007 10:40:06 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2866 Lines: 112 From: S?bastien Dugu? compat_sys_io_submit() cleanup Cleanup compat_sys_io_submit by duplicating some of the native syscall logic in the compat layer and directly calling io_submit_one() instead of fooling the syscall into thinking it is called from a native 64-bit caller. This eliminates: - the overhead of copying the nr iocb pointers on the userspace stack - the PAGE_SIZE/(sizeof(void *)) limit on the number of iocbs that can be submitted. This is also needed for the completion notification patch to avoid having to rewrite each iocb on the caller stack for io_submit_one() to find the sigevents. compat.c | 61 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 27 deletions(-) Signed-off-by: S?bastien Dugu? Index: linux-2.6.20-rc6-mm3/fs/compat.c =================================================================== --- linux-2.6.20-rc6-mm3.orig/fs/compat.c 2007-01-30 10:05:08.000000000 +0100 +++ linux-2.6.20-rc6-mm3/fs/compat.c 2007-01-30 11:30:29.000000000 +0100 @@ -644,40 +644,47 @@ out: return ret; } -static inline long -copy_iocb(long nr, u32 __user *ptr32, struct iocb __user * __user *ptr64) -{ - compat_uptr_t uptr; - int i; - - for (i = 0; i < nr; ++i) { - if (get_user(uptr, ptr32 + i)) - return -EFAULT; - if (put_user(compat_ptr(uptr), ptr64 + i)) - return -EFAULT; - } - return 0; -} - -#define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *)) - asmlinkage long compat_sys_io_submit(aio_context_t ctx_id, int nr, u32 __user *iocb) { - struct iocb __user * __user *iocb64; - long ret; + struct kioctx *ctx; + long ret = 0; + int i; if (unlikely(nr < 0)) return -EINVAL; - if (nr > MAX_AIO_SUBMITS) - nr = MAX_AIO_SUBMITS; - - iocb64 = compat_alloc_user_space(nr * sizeof(*iocb64)); - ret = copy_iocb(nr, iocb, iocb64); - if (!ret) - ret = sys_io_submit(ctx_id, nr, iocb64); - return ret; + if (unlikely(!access_ok(VERIFY_READ, iocb, (nr * sizeof(u32))))) + return -EFAULT; + + ctx = lookup_ioctx(ctx_id); + if (unlikely(!ctx)) + return -EINVAL; + + for (i=0; i