From patchwork Fri Sep 18 09:54:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11784469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A27F3618 for ; Fri, 18 Sep 2020 09:56:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 66BE021D20 for ; Fri, 18 Sep 2020 09:56:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1Zj9Tva9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66BE021D20 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arndb.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=w+G7ef54Q9vTmOhhkjYW91tkNO0n2EsrhzF3kzKF/f0=; b=1Zj9Tva9ds+cqmMUiq7bjt8Ce LUqshJ5k4Il6/ZY5nppB5bqHanEMpeVLs6IK+BB9hKCWrS9+N2WgT4Iy0ZoJ5q0+jtW5I/sRa+act 5aOCbD7a3bGpo/VH/UuQntp20RGe/9sU+zIB8SCMiWzCnFCUtB9ZmY3rI1NhQuzuEmDm9Mf1K/cw9 vKs+y7q56r1OhZFdKK4dIT98tSnIV52EXafLhM2Ucu0QDR8egsX2FUkxqxChiVcCqbZfNJ0/8zRCC 3H+uIstpilPF4mzypzQFdg7dyxdikdppMqyyzMorLsTHexp8u6WTFd5rrsJwuSSK66ripA7LfwnFo izmgKQ+Mg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJD6m-0000aM-Pu; Fri, 18 Sep 2020 09:55:12 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJD6e-0000XP-PI; Fri, 18 Sep 2020 09:55:06 +0000 Received: from threadripper.lan ([149.172.98.151]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1MZCSt-1jxbbx2VX7-00V5LE; Fri, 18 Sep 2020 11:54:52 +0200 From: Arnd Bergmann To: linux-rpi-kernel@lists.infradead.org, nsaenzjulienne@suse.de Subject: [PATCH 1/5] staging: vchiq: rework compat handling Date: Fri, 18 Sep 2020 11:54:37 +0200 Message-Id: <20200918095441.1446041-2-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200918095441.1446041-1-arnd@arndb.de> References: <20200918095441.1446041-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:AXDyUvFJw2DyJsOPhLYVgH/4OvJMTVEn+LtheYL0JPjwAHUp0Du +vAy5Q2G6zyNv7kxlcE6R6Dj9BG6c4YA4EwD3JYS64j/PJwTEsvrexvnOxMkmqQxLRdxK6T QZcxsWVEMnqHmtr++uZsCLntjAay1e+ZkQszrXYEX88CrCfoxtVPgloLoB8eWuTiGueP2s/ vwaRLl9DGj1xCTUVbYWfw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:hncp2bSKLws=:88OagQPM7B75K8RNpdMKx8 JiTt1Ww4rF4Ilx5rugsUk7vxZuHsMDsn3nL/E4chBg0r9Tk8wo5Z7xN4a4NbAoQ6ifXfRrLqs AKQhgTWwn9SdljJaMumjOF07WUMg4NbRMz5ueHhYNQy9KPf+3bVXNp7g7RMvEBq6crrBwQCz7 1IYxw+qo+VtQzMwtrz+oCxsfO9b87lUFuwn6Mw3ZFXD0df4J9jty74Yrb346vlNTditskRC56 FbHoK/79WrZHqWzlFZ9M+CCmgibl6I9N9LEPj+W8H23xUVj8JgKCrF7u/NurwRBof+TqdZ8Pu 21xs2XJ9wOKpuLjUpz61hnwRjuVgCZuPC8FX+wXTeV9rUw1qxS+XdsKXmSliXGX83NEG5qs1m 6jT/5ir4hir4WwLqyLLlHrwyzNhlgOzhALw7l6staPfGz2COcqxHNc72vPy5RrhzsY5EdMr0Y Jd4yxml0DYvt7Ll7WN5oTrZklU/b7Rm7FNk4EusebTttWuiN3TGbLdHjQXu7ZgGYyjiRfDcDX 2D/PHMNgNRhGfXVF5ugl0Pqkbt6n5lRzqDGPWjoACuS0ooi2SzC85wJOenYM9jaoonolqYUTR Tp7NDjpvLgXVWPQCQFzk/tuAxfR+whBh6tPMpsctDmp73kmYYVlZcGfwmUW+sBMmgFiadMBXj avAYO/Mb1tMggM/l+4J/pAXdlV8N9H6ndnaC5YYEyMu0LuW5+VhYyW3UjzVFK9zujKLbxgWKs 5l9DozeHVO06VuK+REUiwA0clhnVJIvGh7BCDO+rkCDeFT0wjRqBO2CBTtTFI881HhGHIlUg0 HPauzL39bvgpaBDsDemduwCdQsF1sWdW1sVGDoVz8gU04tE1ha53/InuFiw9KcKhTUQNrZq X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200918_055505_047764_EEB24DA6 X-CRM114-Status: GOOD ( 20.14 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.72.192.75 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.72.192.75 listed in wl.mailspike.net] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, stefan.wahren@i2se.com, Arnd Bergmann , gregkh@linuxfoundation.org, marcgonzalez@google.com, linux-kernel@vger.kernel.org, hch@lst.de, bcm-kernel-feedback-list@broadcom.com, jamal.k.shareef@gmail.com, inf.braun@fau.de, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The compat handlers for VCHIQ_IOC_QUEUE_MESSAGE32 and VCHIQ_IOC_GET_CONFIG32 can simply call the underlying implementations that are already separate functions rather than using copy_in_user to simulate the native 64-bit interface for the full ioctl handler. vchiq_ioc_queue_message gets a small update to the calling conventions to simplify the compat version by directly returning a normal errno value. Signed-off-by: Arnd Bergmann --- .../interface/vchiq_arm/vchiq_arm.c | 109 +++++++++--------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index d4d811884861..56a38bec848a 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -765,12 +765,13 @@ static ssize_t vchiq_ioc_copy_element_data(void *context, void *dest, * vchiq_ioc_queue_message * **************************************************************************/ -static enum vchiq_status +static int vchiq_ioc_queue_message(unsigned int handle, struct vchiq_element *elements, unsigned long count) { struct vchiq_io_copy_callback_context context; + enum vchiq_status status = VCHIQ_SUCCESS; unsigned long i; size_t total_size = 0; @@ -785,8 +786,14 @@ vchiq_ioc_queue_message(unsigned int handle, total_size += elements[i].size; } - return vchiq_queue_message(handle, vchiq_ioc_copy_element_data, - &context, total_size); + status = vchiq_queue_message(handle, vchiq_ioc_copy_element_data, + &context, total_size); + + if (status == VCHIQ_ERROR) + return -EIO; + else if (status == VCHIQ_RETRY) + return -EINTR; + return 0; } /**************************************************************************** @@ -1020,9 +1027,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (copy_from_user(elements, args.elements, args.count * sizeof(struct vchiq_element)) == 0) - status = vchiq_ioc_queue_message - (args.handle, - elements, args.count); + ret = vchiq_ioc_queue_message(args.handle, elements, + args.count); else ret = -EFAULT; } else { @@ -1550,55 +1556,53 @@ struct vchiq_queue_message32 { static long vchiq_compat_ioctl_queue_message(struct file *file, unsigned int cmd, - unsigned long arg) + struct vchiq_queue_message32 __user *arg) { - struct vchiq_queue_message __user *args; - struct vchiq_element __user *elements; + struct vchiq_queue_message args; struct vchiq_queue_message32 args32; - unsigned int count; - - if (copy_from_user(&args32, - (struct vchiq_queue_message32 __user *)arg, - sizeof(args32))) - return -EFAULT; - - args = compat_alloc_user_space(sizeof(*args) + - (sizeof(*elements) * MAX_ELEMENTS)); + struct vchiq_service *service; + int ret; - if (!args) + if (copy_from_user(&args32, arg, sizeof(args32))) return -EFAULT; - if (put_user(args32.handle, &args->handle) || - put_user(args32.count, &args->count) || - put_user(compat_ptr(args32.elements), &args->elements)) - return -EFAULT; + args = (struct vchiq_queue_message) { + .handle = args32.handle, + .count = args32.count, + .elements = compat_ptr(args32.elements), + }; if (args32.count > MAX_ELEMENTS) return -EINVAL; - if (args32.elements && args32.count) { - struct vchiq_element32 tempelement32[MAX_ELEMENTS]; + service = find_service_for_instance(file->private_data, args.handle); + if (!service) + return -EINVAL; - elements = (struct vchiq_element __user *)(args + 1); + if (args32.elements && args32.count) { + struct vchiq_element32 element32[MAX_ELEMENTS]; + struct vchiq_element elements[MAX_ELEMENTS]; + unsigned int count; - if (copy_from_user(&tempelement32, - compat_ptr(args32.elements), - sizeof(tempelement32))) + if (copy_from_user(&element32, args.elements, + sizeof(element32))) { + unlock_service(service); return -EFAULT; + } for (count = 0; count < args32.count; count++) { - if (put_user(compat_ptr(tempelement32[count].data), - &elements[count].data) || - put_user(tempelement32[count].size, - &elements[count].size)) - return -EFAULT; + elements[count].data = + compat_ptr(element32[count].data); + elements[count].size = element32[count].size; } - - if (put_user(elements, &args->elements)) - return -EFAULT; + ret = vchiq_ioc_queue_message(args.handle, elements, + args.count); + } else { + ret = -EINVAL; } + unlock_service(service); - return vchiq_ioctl(file, VCHIQ_IOC_QUEUE_MESSAGE, (unsigned long)args); + return ret; } struct vchiq_queue_bulk_transfer32 { @@ -1866,35 +1870,34 @@ struct vchiq_get_config32 { static long vchiq_compat_ioctl_get_config(struct file *file, unsigned int cmd, - unsigned long arg) + struct vchiq_get_config32 __user *arg) { - struct vchiq_get_config __user *args; struct vchiq_get_config32 args32; + struct vchiq_config config; + void __user *ptr; - args = compat_alloc_user_space(sizeof(*args)); - if (!args) - return -EFAULT; - - if (copy_from_user(&args32, - (struct vchiq_get_config32 __user *)arg, - sizeof(args32))) + if (copy_from_user(&args32, arg, sizeof(args32))) return -EFAULT; + if (args32.config_size > sizeof(config)) + return -EINVAL; - if (put_user(args32.config_size, &args->config_size) || - put_user(compat_ptr(args32.pconfig), &args->pconfig)) + vchiq_get_config(&config); + ptr = compat_ptr(args32.pconfig); + if (copy_to_user(ptr, &config, args32.config_size)) return -EFAULT; - return vchiq_ioctl(file, VCHIQ_IOC_GET_CONFIG, (unsigned long)args); + return 0; } static long vchiq_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { + void __user *argp = compat_ptr(arg); switch (cmd) { case VCHIQ_IOC_CREATE_SERVICE32: return vchiq_compat_ioctl_create_service(file, cmd, arg); case VCHIQ_IOC_QUEUE_MESSAGE32: - return vchiq_compat_ioctl_queue_message(file, cmd, arg); + return vchiq_compat_ioctl_queue_message(file, cmd, argp); case VCHIQ_IOC_QUEUE_BULK_TRANSMIT32: case VCHIQ_IOC_QUEUE_BULK_RECEIVE32: return vchiq_compat_ioctl_queue_bulk(file, cmd, arg); @@ -1903,9 +1906,9 @@ vchiq_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case VCHIQ_IOC_DEQUEUE_MESSAGE32: return vchiq_compat_ioctl_dequeue_message(file, cmd, arg); case VCHIQ_IOC_GET_CONFIG32: - return vchiq_compat_ioctl_get_config(file, cmd, arg); + return vchiq_compat_ioctl_get_config(file, cmd, argp); default: - return vchiq_ioctl(file, cmd, arg); + return vchiq_ioctl(file, cmd, (unsigned long)argp); } }