From patchwork Tue Dec 17 22:16:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298975 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 1E5D8921 for ; Tue, 17 Dec 2019 22:20:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 060FC21582 for ; Tue, 17 Dec 2019 22:20:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726290AbfLQWRf (ORCPT ); Tue, 17 Dec 2019 17:17:35 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:43261 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbfLQWRf (ORCPT ); Tue, 17 Dec 2019 17:17:35 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Ma1sQ-1iDauk3LgC-00W0Di; Tue, 17 Dec 2019 23:17:22 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 01/27] pktcdvd: fix regression on 64-bit architectures Date: Tue, 17 Dec 2019 23:16:42 +0100 Message-Id: <20191217221708.3730997-2-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:QMSOPeED49s201CoV/Q/8aHXf5yX2aoiUQkXnT4FSnobAR1P+ZS AjHcXURC1TcBRJslcM0go+hX9iCUkxwOPBvAe3WaNg3lqMqQFjSIfMlrLToOT1N/tCw6hO2 zOwEghWIgnPEe89YRhjL6pmHZYOlIxHRc6VqAA5VLAnaxIqc9epmlzoZE2W28a+I11/E1T8 eN7v7rzsLAL52VPep87VA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:q3r9egq/gLI=:eaRnFNzwV13WGZeABhyoCa kG6pSxM3N1jBbw3ItFcU5G6gCoLl6A20jd6nWRhp35jlLNyqBxWhRYZ8QIRjtnoL5Qk8vjNQm hDtQSpTngcgQO89psiQHtXxIsxlggGZOlPf2yawlOrfLb/SvakZpuY7BQCrV0WRG0LTyw4gvy afJx3VGKecnLAuvMQaV22cGRGlyz9pZfPQG0ygZVSYZV1FiyYh5ZQSX+mer5k6mfvHmkUn+3T YzHfUa+OyIC/Mamfdnu/bjuJG52WXGYFay1onrbGSNYms13077RIudBaIaWiHWBIh+3LJAIHS pKIe4/iNUYIIiYdcFx/p/jkg0JYMmWMKOB++MhNCdcsCKvcboEVQyzF2580ni2QV9L79sfSpp f3M4Cg7b9wWO9696JpTfpFoSCF7L6Ojt2W5tFp+nAn4i7ZHtyNgKpE2PxoI9zyMdm8/88wo5o Ir0gAKQcWJCyrIh461fpNETWT9UdaCZPt5J/vI3O9R4hzGIzm9nS4z55DqcTBmqWc8KQxS+5u xpUha18j3X3Tvf/Ckcq0vJ7SnSm4QOI1m9Hk7Roul2tz5+HL9bXEaJ6O4aBACvZiBAK0NQfO2 55iUqzA2Do9ZUxr07cSZOMz6j2VB80hXlCcQKu0g8HWsp73LJmFQ5VlD7Vm3DZ9R1M+w72zX2 bhQFI10kiVC9sGNSOIemMXU5lYjvDynxia/KafBznmGNhDIkQ5P8QyElg37HCZVjQuxzmKiw9 5U/sNmQG2oheV7assA7oI62z+vjrg2xZC6KBoiGsoM1iB4lNjM9ql5Y7ZR9Ulz5ZtDhCqMlxd ihoE9fwLKdX3XySzRDbM3JoPdOb04RmsNAiVkkeIasEjWfw6dgd8mdLqt5JWldxd3/cM/tc61 af5LnUUHqowZxtUs87eg== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The support for the compat ioctl did not actually do what it was supposed to do because of a typo, instead it broke native support for CDROM_LAST_WRITTEN and CDROM_SEND_PACKET on all architectures with CONFIG_COMPAT enabled. Fixes: 1b114b0817cc ("pktcdvd: add compat_ioctl handler") Signed-off-by: Arnd Bergmann ---- Please apply for v5.5, I just noticed the regression while rebasing some of the patches I created on top. --- drivers/block/pktcdvd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index ee67bf929fac..861fc65a1b75 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2707,7 +2707,7 @@ static const struct block_device_operations pktcdvd_ops = { .release = pkt_close, .ioctl = pkt_ioctl, #ifdef CONFIG_COMPAT - .ioctl = pkt_compat_ioctl, + .compat_ioctl = pkt_compat_ioctl, #endif .check_events = pkt_check_events, }; From patchwork Tue Dec 17 22:16:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298883 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 0457714F6 for ; Tue, 17 Dec 2019 22:18:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E09D924672 for ; Tue, 17 Dec 2019 22:18:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727086AbfLQWSr (ORCPT ); Tue, 17 Dec 2019 17:18:47 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:47933 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726641AbfLQWRo (ORCPT ); Tue, 17 Dec 2019 17:17:44 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MJV5K-1iNTtD2mu8-00JtoE; Tue, 17 Dec 2019 23:17:23 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann , stable@vger.kernel.org, Damien Le Moal Subject: [PATCH v2 02/27] compat_ioctl: block: handle BLKREPORTZONE/BLKRESETZONE Date: Tue, 17 Dec 2019 23:16:43 +0100 Message-Id: <20191217221708.3730997-3-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:g9ac37aU2A7D6GQqud2omy5i2QGTVE1qppkCL5XwIDeUd8bobTc MveRQyw3+9pR5kUrwwKPYkI72gAZcTFNOFPrXHHjoLZDSE//MQTS40wwyPjouH26AbGYVAe jAM7wjF2oIGdwXn7+yQnLwHO5GyBuoGAp+pfHTjpdbXQt7rRjN5nKS181kK7PLyXD7q+Jnk 7vH6FPtRoMkX/848Z91BA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:zG7SE8/0MZM=:KEUrtjVSBoJBU02gLbM6J4 2EagqdafkKPJhjR/Tm0F8ZE1uyWfOhPXtbj8Wi3q3Gozys9rJExO2wo4fo8ZxCs7OxZ1eEZ9J QepdDyiAeclC3QZ/nS2SRQc5KfTpwTH81BOMbRk1pkWO7VBTU+1d7i6HOwYh33TmvPTPsizvs MMVgM2K0tstvZ4ElOoVo5v3o6ev5YpWZCxE8GktYvG0zounkN5I5TObuXVKKerlR6AbILeRZx /SvdM3xC+vzZR3/4WQiVK0BrlEnAgJ7KBwyX6MdtdE4Vvmg6kHUwBOlViwl2zJ9VpG5T9tSMQ ptvWX8OIXgyH32USJldmEISgyLbpyc/eJEzcidHTWP+AeRnZSScA89uCQDZfTfMSjLQK8+D+C OKwhn/bEDCgSv9BBWyaqngtW8TdY26Ab7veXc4nSFkq/LFamorGan0OT77JgAGrbr8TCrZYhS tUPJGutM0iBHjyEkanop9hfxbHlXtYyhsW7onbWfmOTufD/d82/k+BcJLxijM9GtV7irNjQ6R S4AUe9RBV7iJypejiG7xbrn9Ga6alfisodAiti+85iaJubN0gAVQHFirx85oCSZF7amaWoB7G +mTlrAJIOEZZTJxvrpGatRoArgx5Vy27kBC02ny5s8R1qTsSnFQTQfWvl7PfefpvaeIA/i2a0 D6wN5emM0HXJ04BR4P6Rb5hAuUZQbl+72JxXEEg/LLU1GzBkmKmYP3yBes+k1IjkANfSkmKPz SIUNKFKLEMW9a18wGjAEUepv0t21kQ/C1T3JHWUNJ7MndLZoLXEmGzXwk3ZSVBITBQpZm5KOn JLehDsF+wQUW2hMIYQHtMPit53Y2etN3OEtSGjEUcmNbtag1dXyqMvACIelUubtCVGwnnnsOa exU8Q+G3QGndB70dx2Xw== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org These were added to blkdev_ioctl() but not blkdev_compat_ioctl, so add them now. Cc: # v4.10+ Fixes: 3ed05a987e0f ("blk-zoned: implement ioctls") Reviewed-by: Damien Le Moal Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 6ca015f92766..830f91e05fe3 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -354,6 +354,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) * but we call blkdev_ioctl, which gets the lock for us */ case BLKRRPART: + case BLKREPORTZONE: + case BLKRESETZONE: return blkdev_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); case BLKBSZSET_32: From patchwork Tue Dec 17 22:16:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298903 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 A5C291892 for ; Tue, 17 Dec 2019 22:19:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8DE2224679 for ; Tue, 17 Dec 2019 22:19:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726652AbfLQWRm (ORCPT ); Tue, 17 Dec 2019 17:17:42 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:47167 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726616AbfLQWRk (ORCPT ); Tue, 17 Dec 2019 17:17:40 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N7Qt9-1hc4Aj0to5-017p51; Tue, 17 Dec 2019 23:17:24 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann , stable@vger.kernel.org, Damien Le Moal Subject: [PATCH v2 03/27] compat_ioctl: block: handle BLKGETZONESZ/BLKGETNRZONES Date: Tue, 17 Dec 2019 23:16:44 +0100 Message-Id: <20191217221708.3730997-4-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:qZe5YHLKHLHpHJZclyVZA0fCxWsO2YWO0AhXGovOQ1fZAYHfawL PlgMmuwRjxPbewOZKAHylAsdjtO5Fe/LyB5CoqTBmrCuAd/xJZkTNN2Xe6IE5gl9V6JPzSt wvrf4HNaht3Bulo2IXSq2733GPK1CFCKtmRyV0YYyH/U4G/08T9e4oHS3EjXjMzJqv1R6qu YXpz3kgtPpBQ+l8/25RAg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Hk6RW/QL2Xc=:a9P9ugAbeQlBAd8QTVyh2z 5InWQgdBINeinSpZATAEdhQ/i9YNLE4Cs+a4GFKgz8jKOPxplXc0dczKp/R69c5g8upJqXc65 Inze+14ZfZRZaI0BopuCyPY5TUVy08obBhggcQi+WudXUEHWwBsXUFluiycvo4Qaurb+6rEtF wl/PyloS7vvgNbHp3oizoL/VE9M/fDRKOZnJVXS33E5tAxmuyEeS+c06bSgvorA2N0WUlGegL JR96X/5oeTYQNiS6LNCZOFNiaK7DxSoFNL2X//sV4r/tkqil9NVYbVqSA57bXb27MZdAlvzce teYoIFLXA6UzJ6tlnlyGnkX0lzqkCqNUxxn2Vz3OLxiBy708VuKvki7fpMwIoFK5zb8uismKl NVnMG3k+kqutWYugmpAYLlsd46sD0BA3aS7H/7sbtwCkJbLmSHzGzUzT3QwFLvufPwS7gjtVa LkVlGEraoHwX6J/Aq5FlQxnpaZCOZaoD2ipgjveEAiRud97oZd3v0U1P+jQVsZ31Vd+ZmWrGT 99AZMqe5M7rDHP9ViRtLfEhibVOQhXjLSW+6xch6lCzJ219MgwF1MnPomwWr/0C9C2kvM0BuW j5FGSpZiAZjCLNLEkmuBo6gIivj9IxCbQPMRAzV5rRkt2cZS6sEc13znh6WL9OTKMbXBlAoEg 92vBK+F5J4ulrPf/6JaQ+KO+dW1b0XoqtMB47HnrBzadfiYpZbvLrSGZ9glboP6AhZN/k8rL7 bCxTfErhrRnqMpnIuouQQawVleSt5C4nvOHsvTHLrT7EfkeC0Orh2YFb1qjgwN0bBoM067VZr rD9N8ZXHsBYH9Hk++YNJRhYpCVImlVrPMX8irVmtJnFkRUa5wg509PSNNIxy3I6lxJmDXGb5E AEnRWMTVaEAGbAC7t4wA== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org These were added to blkdev_ioctl() in v4.20 but not blkdev_compat_ioctl, so add them now. Cc: # v4.20+ Fixes: 72cd87576d1d ("block: Introduce BLKGETZONESZ ioctl") Fixes: 65e4e3eee83d ("block: Introduce BLKGETNRZONES ioctl") Reviewed-by: Damien Le Moal Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 830f91e05fe3..f5c1140b8624 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -356,6 +356,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) case BLKRRPART: case BLKREPORTZONE: case BLKRESETZONE: + case BLKGETZONESZ: + case BLKGETNRZONES: return blkdev_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); case BLKBSZSET_32: From patchwork Tue Dec 17 22:16:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298977 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 A45E914B7 for ; Tue, 17 Dec 2019 22:22:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B7FC21D7D for ; Tue, 17 Dec 2019 22:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbfLQWWl (ORCPT ); Tue, 17 Dec 2019 17:22:41 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:43763 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725975AbfLQWWk (ORCPT ); Tue, 17 Dec 2019 17:22:40 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N4yyQ-1hiwzo35zY-010xJi; Tue, 17 Dec 2019 23:17:24 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann , Damien Le Moal Subject: [PATCH v2 04/27] compat_ioctl: block: handle add zone open, close and finish ioctl Date: Tue, 17 Dec 2019 23:16:45 +0100 Message-Id: <20191217221708.3730997-5-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:gu/sZ8TIEZHaNMokJWZJ2X/rL2ysrVtrFNyi0SMX6prix2pGIWW bAPVJ8fwpN8E/mH6Nc/QBm6u/qo4Tvn5SQjEffGJQQ0pqczFhRJkII1FGsCprkk0Bm9Mp7S bPZtEphmmlcYdUTV6MyI0eM1M+OkiwJopBU1dcguNoVzj0J/NcGJldmWoOE4st0Vk3Wc+EZ AsAGp/sInmVO2GHX+D+bg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:PZzd4xrTh1k=:O4HFuv5nV8diiq/ph5n5Gr qf4n+7oCpROKsWo1y2SYeW91P85f6Qflgw/6lY7L1mr97wtEbH6FSNZD5YVHljnyqEpuEge/x igMySXnwDbTKop7DCYDSAsYWFVUMr82xvXBwq9CPkuIyH3mWCbap4y+gTZtGuR5UVlO9XD0DX csBbpzz/fdeVdn18z9BVw7IF0cP3xbNq9ATsOs4oO2D23gSuRlETFGY32yYd+mld9NAAfFFID VntMuQCrGbwBsICwhCOcBfGmUQFGHlG8hOaNOHQPQNgbo2l5f0h0uSF0wQCr3UQG1a7jLq0zP E8hunDXra3WNSNh+Fb48UCaYoj1hqmAylf69bDnJJNO1AMGd4ydVAj1sGBqKEjliixmMVBQ6D aybJCJCv/RJiJMT8Lvh3jgCFKX9VURq5G/vMOvSArwRi7Bp1/IQCuAkhvIXPQKed4dFIMy7qj GGZ0FmDM1X/sOr2EDL572pMUoPN8lDpApPfjkar0u31u3tzsmWWpPIIw3DAb9bMOOCIH101zL /z6ilD/gTLCeVqMjNQXZH34TDDsMp8sjlHLXGBmC0jdp8OyQsWNpOL4nOZFdbxPq/nbXE+97f NeW73c8z807bRs9C15zVqFwVrTZHPWYl9fq20EOQG8FStNxQx7028GQpWMPvqxFiZPcpOyUxf a4r8+swDX3SaUnxU5fiwKyqNrx5bfGZ/kl4iNtSz8xpXT68QSSY1JZ4chjAiHdtk0/k+lk1iP +s8EGZZJVn+Hqf8F/NdDYJZM0dpzajmFia1hLchlr6J7nLCK+yEzAdNmhVGQwLPV1hC1U1szV 4PY/3xiTfZkiaDLxyvlIrB5l+LE7JEd/x7p0JTG5Ze7QPa1vX/AeCbYOtkhpJYT5ZwM0lqEUY C1MhosgOmGZqGHhJZDIw== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org These were added to blkdev_ioctl() in linux-5.5 but not blkdev_compat_ioctl, so add them now. Fixes: e876df1fe0ad ("block: add zone open, close and finish ioctl support") Reviewed-by: Damien Le Moal Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index f5c1140b8624..5b13e344229c 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -356,6 +356,9 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) case BLKRRPART: case BLKREPORTZONE: case BLKRESETZONE: + case BLKOPENZONE: + case BLKCLOSEZONE: + case BLKFINISHZONE: case BLKGETZONESZ: case BLKGETNRZONES: return blkdev_ioctl(bdev, mode, cmd, From patchwork Tue Dec 17 22:16:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298945 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 97301921 for ; Tue, 17 Dec 2019 22:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 801E421D7D for ; Tue, 17 Dec 2019 22:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726594AbfLQWRi (ORCPT ); Tue, 17 Dec 2019 17:17:38 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:45633 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726539AbfLQWRh (ORCPT ); Tue, 17 Dec 2019 17:17:37 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MWiUg-1iAIaz11AG-00X7Da; Tue, 17 Dec 2019 23:17:25 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann , stable@vger.kernel.org Subject: [PATCH v2 05/27] compat_ioctl: block: handle Persistent Reservations Date: Tue, 17 Dec 2019 23:16:46 +0100 Message-Id: <20191217221708.3730997-6-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:tx22KhkD8iJEZwgYOFJOPlY7/tV41LHYXsZyhEEBtPVUvOD6tZ9 4vPV9N8E62lgxAxzbfK8VDbGilQv+sX1qrJOYnivJO3Kx7yLG1YXPA9d3OSBQ2Up50TY2P5 E+6JBT8vWfcZROysq2+gDwTDnZCBZvKYpKY5KsUZKiWLRhBcIt0dDmgK7tehattqwqXno49 vXnJSOt2f4OGkue9fXHKg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:7CYFyHsACKo=:iyqLTw2Ohx2BEyJYsY+41B hmwCpRKunMUl5x4CJcPTcGVIU5H44ivCnbINJS9mY+fwQyDURv9WqnbJ8BKVg9OfGh0zuhGuJ E410up0th9p7KZUbMj7TMBh2DwGyF4mvvWKAA5o6lXrfK9JoZrSfUsB5nPW7mNINFtgCVK6q+ C5ho2O5/A5yBtAUmN64W+FrC+/fHoVI0GCjzmZ6hlEzFvDX5SbIAtIxjC99izWWjugaLMyX6N 27qHiPIxK/4sFWFthVGVDijLh8GaQYnfJ/KuesQ+l4IAmo6vDORhk33l5yV66TpT/RIFdEAf0 4x73Z8R6U0zssgg8ECCn3uS0Fp1eZtEiueO2/ZWjZah8FHdlpK6HJFTKGGrCacMXpnFZ+/X0P frWn1az7Dzraw9EtnxDoi208ZXqwffjTDOJX33eDDBpr5XMkE6MOJFeE9QC1vRdQ16xzDDQYy NVuLk3W10H+rnGj5kUVvcfLF5ltPJe/sSH2SKVMSYf+LFg4scM+8xOpJO/ItnkAlPLFKydGy4 kd/OLhf8xRqcbJsgkt9/YxeY59pHHB3USKVHP23C9YP7Q1U+eDd55rOLPsnyfrZ8dfv6EfKuu snRrXg6PaLYh5gnyjsinoeAx2aHPbOYfK5WRUA2j6S2SFX4CJUyC9Ztk3ehYK/ifB9EmYjWhz 6MbLS+22UGdPgqIbcwauE98Q+zazJtoPwRXc0cP9elqDfdSx2iN5iRhOuNIqEUwyIQLcaLens EgMCvwj72YNusvtNS/E1eqcJffNdTWGYofCMPbJZwajFRs3blHACkQPD0KHiboA0h9T3umrqT sEUgKmBzCLZSmf2JYy9Ni4gBWr1RoTw3UHhLFcRICibhg0pKZlgplQlOZ3nROO28SseqNcmVL O9es2vmgaCJxzqdKwRsw== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org These were added to blkdev_ioctl() in linux-5.5 but not blkdev_compat_ioctl, so add them now. Cc: # v4.4+ Fixes: bbd3e064362e ("block: add an API for Persistent Reservations") Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 5b13e344229c..f16ae92065d7 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -408,6 +408,14 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) case BLKTRACETEARDOWN: /* compatible */ ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); return ret; + case IOC_PR_REGISTER: + case IOC_PR_RESERVE: + case IOC_PR_RELEASE: + case IOC_PR_PREEMPT: + case IOC_PR_PREEMPT_ABORT: + case IOC_PR_CLEAR: + return blkdev_ioctl(bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); default: if (disk->fops->compat_ioctl) ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); From patchwork Tue Dec 17 22:16:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298823 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 D22E0921 for ; Tue, 17 Dec 2019 22:17:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA73B24676 for ; Tue, 17 Dec 2019 22:17:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726683AbfLQWRn (ORCPT ); Tue, 17 Dec 2019 17:17:43 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:49705 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbfLQWRk (ORCPT ); Tue, 17 Dec 2019 17:17:40 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MFba4-1iTcQl3JfS-00H5hY; Tue, 17 Dec 2019 23:17:25 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann , Will Deacon Subject: [PATCH v2 06/27] compat: ARM64: always include asm-generic/compat.h Date: Tue, 17 Dec 2019 23:16:47 +0100 Message-Id: <20191217221708.3730997-7-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:KL1ro4KGbRgth3ZyPB/rUAk9SI9caDwc2wmp7lID3j5UJuG/6zE jjRLuKXhvnIFa8qaMfReNfEXctttFgrIVqB/F8fk6VYQq40G8/4HFBUMSIUgljh/CHDrt8Q 69toNQfZopjNWJs7hsjfa6yd254sA/h57NFTXYoc3PkHXFksuk6NUBA9BahejYNLdG0/ZsG N/KriVo2wRDf+NrqqW4hg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:QObuhZbO9AY=:n0QH6H90N+kFOplb/DnWZ7 AlmmIj0UejnAga/WbAExgs2nDVyWB/XfJ7GAn2Q1LEIaRzeMt+5oc3DltGf1LAybWfMe+LsWq qRT0IBjoptB0bN/M4aR7pGKQY9o275avtkdPO4ix1KuMR6QAf7CihdPYXkrrEWtF6y6HbQjGn +j7YNZ4ske8uUFEkTuPGN9vtjsXUD/g++1sMeTvNA0pysgKnDz1AcBec0pa6U2mC56CYbzz2O FAGnT6Rqnp7h8cluJ5tY52HItYlR8nB0dLN3UCUNFh9LKryA1hcvslQubQq5btgxFZ5ufDTtt aF4gllxZynPOzLuJ6cAgQU4GIEsPUXY7UKLnuvQmmrPh425Jxsg8lvAgtx9SBxdBK6Oe+Kgh0 JtarlkrG8OBIigoaX0oxhJDADSiQhBBrun0in9FXXqCqYjv9Q+5TOn6Sgv8bFVs3gmik7UpS9 YpU9Af5Fo18iTuNJYU7DsfcvLLKsd3Dig4yL8fNgjsWED2ZtnqCrtp8PAapztEhl18QRjRmf2 ZgwhrhZLP9qUXMW0EqH5thD1lHVAgMk4h6T7N7lAdvpdXxQ3dLpHb4QYh2d3YdPOZ8aU648pX zpj0K2wvorwOq6gIzurxnQu7AEgQ2rSPqauCjyu4gwNwYXNnsXHoWZtn9HhC4RCP3vcV8Ahq1 sY3YxVYa9uKMpx9ESnHjo0R6GMvaMBdYyb4e0JIsoY27AcD+gO56rXtfn5LzpdRpAuxxUQptk DVbjSB82MpSC8bXKr2ErxNXQ6NDIbDkAA8XwMFByKjYLaRu/w3DUnx9iiq6UBFIIGOIdgjMbw sNM/QJbtJxuaa5VyyvbYnk9ng7001Wn0sqVDJTkJ8VQkBltfwzmRa5Q0WYKHP5MJkQ2WoSspl VXUq4MYIhhGNm4ZWEO0w== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In order to use compat_* type defininitions in device drivers outside of CONFIG_COMPAT, move the inclusion of asm-generic/compat.h ahead of the #ifdef. All other architectures already do this. Acked-by: Will Deacon Signed-off-by: Arnd Bergmann --- arch/arm64/include/asm/compat.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h index b0d53a265f1d..7b4172ce497c 100644 --- a/arch/arm64/include/asm/compat.h +++ b/arch/arm64/include/asm/compat.h @@ -4,6 +4,9 @@ */ #ifndef __ASM_COMPAT_H #define __ASM_COMPAT_H + +#include + #ifdef CONFIG_COMPAT /* @@ -13,8 +16,6 @@ #include #include -#include - #define COMPAT_USER_HZ 100 #ifdef __AARCH64EB__ #define COMPAT_UTS_MACHINE "armv8b\0\0" From patchwork Tue Dec 17 22:16:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298827 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 C034214B7 for ; Tue, 17 Dec 2019 22:17:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A746A2465E for ; Tue, 17 Dec 2019 22:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726726AbfLQWRq (ORCPT ); Tue, 17 Dec 2019 17:17:46 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:59431 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726704AbfLQWRp (ORCPT ); Tue, 17 Dec 2019 17:17:45 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MYeZB-1iClIj1FHX-00VjN7; Tue, 17 Dec 2019 23:17:26 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 07/27] compat: provide compat_ptr() on all architectures Date: Tue, 17 Dec 2019 23:16:48 +0100 Message-Id: <20191217221708.3730997-8-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:JQSrPBZB1v54Yak8eCxwsTN2osR5c2EDNvd2k/ZMRPAcktmSN0p 0fdwV7ZLRKeFe22G22lsYhOVb7fG8iMrKpNMhA31Ai70EsIcBqiwRSIRz0TaOov3uJNwpM8 E7OhyP/EXJFunAt6QnSJpCwKkqFNH7+wrY2aODNXbKUqkd+b5BPWLaLHXbThNqv5JMiq4NG Im68FZLXOCLcTEu9dIi/w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:SU+7KpO9Vlo=:IymVgWc94KXwaMyZQlHkxU BOOd8tlE2cnTW2MvLxOion+33s57k6FjyPd7rKinV0H3dz+KmdD/evvVKhnUMABxn+b00xCuu o/npD4lIIJI4P/kYPC43N0VqKYay/3o1lR6k8gVP4B8BsCGE34HJUOeqMDPvGw2aXU+HaPgVY EZ9F+sG1CluLGd5DLGKDpqEQ9kseqCkQHkxHP4ZoqbTuM+25Im3fouqTeqYgQeNs690gOTXHH x0fnsDxJcFxMpsmhSVWfDw4ONU77MlG692O1y4OjYs2Tvp5a68CsW9vftGnhm94l4dEL/l5bT EWeKpphlgJgYsHcM3bHOXp9MSEc8GyeREGfPcFiGVvXuVAaO7tLlqxTirbh/c/JoLcf7l9yER l7mqFc9qjeWIk5nHLsHKQEBGYTdliY6ouRe5YNNel4VuiNqz9mBhvb42Q5n+PdnPyXgK8w+/h 8S8bzNO9XoOQSGFzDaz9DvBmFMft5VI/Cc0QkPIZOxB8iSDr+NYsfEzkOR2Y97RlTBNpyw0vU iMP3UoVKuxRkIB+2D7XTPvcDh1WJGvjg3yT3UZNaSW86f4seyz0vd0sGVDLNEInJgRadp8VeG YGx4A8+q4/WdWRn9lL06Kami1FMJda5mm350WsvKTFT8Xm3yHDpVh9mKA7k3lF0ZQfaAh76qs PS5g5Rd7T75Z8i5NmvHEKkS8q7PMBzsvMicAg4x7rxxsH7/KDB5sn/7kOuMV1Wpc/6wMgg0xE vm5TLPMfcGfm8wnQ76w09fCVRt6AFS9lsNRTynMX8kM6yTvIOJmiE4h8qXpAFCbKAJCLs/wXg q/KyMKqUtjSx/JJ4+dp90OW3lcafIOkTUavcY+uXgYS9XKscy11asz0jREQHu5j2AowzaVJav 4WLifMKTsbfDkjC9gOMQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In order to avoid needless #ifdef CONFIG_COMPAT checks, move the compat_ptr() definition to linux/compat.h where it can be seen by any file regardless of the architecture. Only s390 needs a special definition, this can use the self-#define trick we have elsewhere. Signed-off-by: Arnd Bergmann --- arch/arm64/include/asm/compat.h | 17 ----------------- arch/mips/include/asm/compat.h | 18 ------------------ arch/parisc/include/asm/compat.h | 17 ----------------- arch/powerpc/include/asm/compat.h | 17 ----------------- arch/powerpc/oprofile/backtrace.c | 2 +- arch/s390/include/asm/compat.h | 6 +----- arch/sparc/include/asm/compat.h | 17 ----------------- arch/x86/include/asm/compat.h | 17 ----------------- include/linux/compat.h | 18 ++++++++++++++++++ 9 files changed, 20 insertions(+), 109 deletions(-) diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h index 7b4172ce497c..935d2aa231bf 100644 --- a/arch/arm64/include/asm/compat.h +++ b/arch/arm64/include/asm/compat.h @@ -114,23 +114,6 @@ typedef u32 compat_sigset_word; #define COMPAT_OFF_T_MAX 0x7fffffff -/* - * A pointer passed in from user mode. This should not - * be used for syscall parameters, just declare them - * as pointers because the syscall entry code will have - * appropriately converted them already. - */ - -static inline void __user *compat_ptr(compat_uptr_t uptr) -{ - return (void __user *)(unsigned long)uptr; -} - -static inline compat_uptr_t ptr_to_compat(void __user *uptr) -{ - return (u32)(unsigned long)uptr; -} - #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current))) #define COMPAT_MINSIGSTKSZ 2048 diff --git a/arch/mips/include/asm/compat.h b/arch/mips/include/asm/compat.h index c99166eadbde..255afcdd79c9 100644 --- a/arch/mips/include/asm/compat.h +++ b/arch/mips/include/asm/compat.h @@ -100,24 +100,6 @@ typedef u32 compat_sigset_word; #define COMPAT_OFF_T_MAX 0x7fffffff -/* - * A pointer passed in from user mode. This should not - * be used for syscall parameters, just declare them - * as pointers because the syscall entry code will have - * appropriately converted them already. - */ - -static inline void __user *compat_ptr(compat_uptr_t uptr) -{ - /* cast to a __user pointer via "unsigned long" makes sparse happy */ - return (void __user *)(unsigned long)(long)uptr; -} - -static inline compat_uptr_t ptr_to_compat(void __user *uptr) -{ - return (u32)(unsigned long)uptr; -} - static inline void __user *arch_compat_alloc_user_space(long len) { struct pt_regs *regs = (struct pt_regs *) diff --git a/arch/parisc/include/asm/compat.h b/arch/parisc/include/asm/compat.h index e03e3c849f40..2f4f66a3bac0 100644 --- a/arch/parisc/include/asm/compat.h +++ b/arch/parisc/include/asm/compat.h @@ -173,23 +173,6 @@ struct compat_shmid64_ds { #define COMPAT_ELF_NGREG 80 typedef compat_ulong_t compat_elf_gregset_t[COMPAT_ELF_NGREG]; -/* - * A pointer passed in from user mode. This should not - * be used for syscall parameters, just declare them - * as pointers because the syscall entry code will have - * appropriately converted them already. - */ - -static inline void __user *compat_ptr(compat_uptr_t uptr) -{ - return (void __user *)(unsigned long)uptr; -} - -static inline compat_uptr_t ptr_to_compat(void __user *uptr) -{ - return (u32)(unsigned long)uptr; -} - static __inline__ void __user *arch_compat_alloc_user_space(long len) { struct pt_regs *regs = ¤t->thread.regs; diff --git a/arch/powerpc/include/asm/compat.h b/arch/powerpc/include/asm/compat.h index 74d0db511099..3e3cdfaa76c6 100644 --- a/arch/powerpc/include/asm/compat.h +++ b/arch/powerpc/include/asm/compat.h @@ -96,23 +96,6 @@ typedef u32 compat_sigset_word; #define COMPAT_OFF_T_MAX 0x7fffffff -/* - * A pointer passed in from user mode. This should not - * be used for syscall parameters, just declare them - * as pointers because the syscall entry code will have - * appropriately converted them already. - */ - -static inline void __user *compat_ptr(compat_uptr_t uptr) -{ - return (void __user *)(unsigned long)uptr; -} - -static inline compat_uptr_t ptr_to_compat(void __user *uptr) -{ - return (u32)(unsigned long)uptr; -} - static inline void __user *arch_compat_alloc_user_space(long len) { struct pt_regs *regs = current->thread.regs; diff --git a/arch/powerpc/oprofile/backtrace.c b/arch/powerpc/oprofile/backtrace.c index 43245f4a9bcb..6ffcb80cf844 100644 --- a/arch/powerpc/oprofile/backtrace.c +++ b/arch/powerpc/oprofile/backtrace.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #define STACK_SP(STACK) *(STACK) diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h index 63b46e30b2c3..9547cd5d6cdc 100644 --- a/arch/s390/include/asm/compat.h +++ b/arch/s390/include/asm/compat.h @@ -177,11 +177,7 @@ static inline void __user *compat_ptr(compat_uptr_t uptr) { return (void __user *)(unsigned long)(uptr & 0x7fffffffUL); } - -static inline compat_uptr_t ptr_to_compat(void __user *uptr) -{ - return (u32)(unsigned long)uptr; -} +#define compat_ptr(uptr) compat_ptr(uptr) #ifdef CONFIG_COMPAT diff --git a/arch/sparc/include/asm/compat.h b/arch/sparc/include/asm/compat.h index 30b1763580b1..40a267b3bd52 100644 --- a/arch/sparc/include/asm/compat.h +++ b/arch/sparc/include/asm/compat.h @@ -125,23 +125,6 @@ typedef u32 compat_sigset_word; #define COMPAT_OFF_T_MAX 0x7fffffff -/* - * A pointer passed in from user mode. This should not - * be used for syscall parameters, just declare them - * as pointers because the syscall entry code will have - * appropriately converted them already. - */ - -static inline void __user *compat_ptr(compat_uptr_t uptr) -{ - return (void __user *)(unsigned long)uptr; -} - -static inline compat_uptr_t ptr_to_compat(void __user *uptr) -{ - return (u32)(unsigned long)uptr; -} - #ifdef CONFIG_COMPAT static inline void __user *arch_compat_alloc_user_space(long len) { diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h index 22c4dfe65992..52e9f3480f69 100644 --- a/arch/x86/include/asm/compat.h +++ b/arch/x86/include/asm/compat.h @@ -177,23 +177,6 @@ typedef struct user_regs_struct compat_elf_gregset_t; (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) #endif -/* - * A pointer passed in from user mode. This should not - * be used for syscall parameters, just declare them - * as pointers because the syscall entry code will have - * appropriately converted them already. - */ - -static inline void __user *compat_ptr(compat_uptr_t uptr) -{ - return (void __user *)(unsigned long)uptr; -} - -static inline compat_uptr_t ptr_to_compat(void __user *uptr) -{ - return (u32)(unsigned long)uptr; -} - static inline void __user *arch_compat_alloc_user_space(long len) { compat_uptr_t sp; diff --git a/include/linux/compat.h b/include/linux/compat.h index 68f79d855c3d..11083d84eb23 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -958,4 +958,22 @@ static inline bool in_compat_syscall(void) { return false; } #endif /* CONFIG_COMPAT */ +/* + * A pointer passed in from user mode. This should not + * be used for syscall parameters, just declare them + * as pointers because the syscall entry code will have + * appropriately converted them already. + */ +#ifndef compat_ptr +static inline void __user *compat_ptr(compat_uptr_t uptr) +{ + return (void __user *)(unsigned long)uptr; +} +#endif + +static inline compat_uptr_t ptr_to_compat(void __user *uptr) +{ + return (u32)(unsigned long)uptr; +} + #endif /* _LINUX_COMPAT_H */ From patchwork Tue Dec 17 22:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298949 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 94F8A14B7 for ; Tue, 17 Dec 2019 22:20:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 694A324650 for ; Tue, 17 Dec 2019 22:20:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727346AbfLQWUD (ORCPT ); Tue, 17 Dec 2019 17:20:03 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:38169 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726565AbfLQWRj (ORCPT ); Tue, 17 Dec 2019 17:17:39 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N6bo8-1hctFg38KU-0185vc; Tue, 17 Dec 2019 23:17:26 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 08/27] compat: scsi: sg: fix v3 compat read/write interface Date: Tue, 17 Dec 2019 23:16:49 +0100 Message-Id: <20191217221708.3730997-9-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:EPgVRxHLVmXq6xV18Ht+/wrImzU2wxByo1tUXVa0LaSS0Tun9rb Uc1alnCqaf3enDvyoANS+9o6zakLERXmmuEXztsCTp13GfgiBuXeR8jX0IlKpanAmMPOqWA IgIBFsbJcd5fe1lM8c2OaGrhNBdk0tKSomd1i3EWYQkZkp1hy5WEi8N1II4JLvGhrBcdAW0 oDgUhAOGBaSxVKe/RbJEg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:P6dApjCTFbs=:9MBkCDnDPmp4VM9Ikqp3lq SU2sCvfOWxk0wq0gm6yls1Me6krnN0BpciuDY9QhkKQRUqOFO8sFGAjGN34N/hIoB9Q+PiSq6 oQxP7C++7OJnoydQ7H/JA3ksD3jV10zJciEn5IZWdyscG86GNIkxC+Zz2TIHIH11WcmwBGeht Y2vkJaROZnUwSgvqOZWp2Ak3pqIrf5nDWxf/kmx2DJVp/WS0wBRRcFP/oNwe65SN6RzAkBIuv XgDTmWi45gcHKI9+gb8Zza9Wec6hcLPcDZy56hLusJP8Cq+h184rs1L/28mje0jUSeRu5DsJX olK1cTlhScBiKVU9yJSXob1XZaBFPm3yVK92NVDpg63ry7oYWGzPZjzXlay2L0HrsKc9oK5j6 Yy0+pBDLdH+jziICwteGxGWSOpQ7wIIfaw1rceeiFeeP6Wr+iJrr1sJXaTBOtSlSYZQL5YPO2 CQnltBuEmfTR3ZybaZE0n2RsNQ4Ni50oJNHSxTa62y3msPziKqonM0MXIwh1ig/4qS+FxT6iz 0bmD9++FKEn81LFze5UUonsQGYF0t6fYlu4IVg+pMtpg12DEmGgIWfTcKaAnCl0i/pDv/X1ex Snx0EEx9jfVwD3PlWwfKkiK7wSZg2a1esBKEz9SPKM+I85vvFp0D0WNmWw+1lb/4VKETmxGuG YdbwI6EGjhVCMgw75nw5K+WjfsOyWcE7RSywgFPdyyrh0kjlCOhMcASpVI6UbFZVtjiLm9pSN rd/gRUkKhufS/zSOYtUzavKTnToYwbyvMFsqD4flfKIbFEUdh/ICpp62xxKaHZvcik6wkMW8G 3hec+15yIC/58C2OGDdPz+T/jedwh2d29hYQYmm77nzp+bzNJLkcdWxrr9Ty2QeXcV+O5Eyc/ YaqwT/oBqIOqkTgYBnMQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In the v5.4 merge window, a cleanup patch from Al Viro conflicted with my rework of the compat handling for sg.c read(). Linus Torvalds did a correct merge but pointed out that the resulting code is still unsatisfactory. I later noticed that the sg_new_read() function still gets the compat mode wrong, when the 'count' argument is large enough to pass a compat_sg_io_hdr object, but not a nativ sg_io_hdr. To address both of these, move the definition of compat_sg_io_hdr into a scsi/sg.h to make it visible to sg.c and rewrite the logic for reading req_pack_id as well as the size check to a simpler version that gets the expected results. Fixes: c35a5cfb4150 ("scsi: sg: sg_read(): simplify reading ->pack_id of userland sg_io_hdr_t") Fixes: 98aaaec4a150 ("compat_ioctl: reimplement SG_IO handling") Signed-off-by: Arnd Bergmann --- block/scsi_ioctl.c | 29 +---------- drivers/scsi/sg.c | 126 +++++++++++++++++++++------------------------ include/scsi/sg.h | 30 +++++++++++ 3 files changed, 90 insertions(+), 95 deletions(-) diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 650bade5ea5a..b61dbf4d8443 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -20,6 +20,7 @@ #include #include #include +#include struct blk_cmd_filter { unsigned long read_ok[BLK_SCSI_CMD_PER_LONG]; @@ -550,34 +551,6 @@ static inline int blk_send_start_stop(struct request_queue *q, return __blk_send_generic(q, bd_disk, GPCMD_START_STOP_UNIT, data); } -#ifdef CONFIG_COMPAT -struct compat_sg_io_hdr { - compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ - compat_int_t dxfer_direction; /* [i] data transfer direction */ - unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ - unsigned char mx_sb_len; /* [i] max length to write to sbp */ - unsigned short iovec_count; /* [i] 0 implies no scatter gather */ - compat_uint_t dxfer_len; /* [i] byte count of data transfer */ - compat_uint_t dxferp; /* [i], [*io] points to data transfer memory - or scatter gather list */ - compat_uptr_t cmdp; /* [i], [*i] points to command to perform */ - compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */ - compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ - compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */ - compat_int_t pack_id; /* [i->o] unused internally (normally) */ - compat_uptr_t usr_ptr; /* [i->o] unused internally */ - unsigned char status; /* [o] scsi status */ - unsigned char masked_status; /* [o] shifted, masked scsi status */ - unsigned char msg_status; /* [o] messaging level data (optional) */ - unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ - unsigned short host_status; /* [o] errors from host adapter */ - unsigned short driver_status; /* [o] errors from software driver */ - compat_int_t resid; /* [o] dxfer_len - actual_transferred */ - compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */ - compat_uint_t info; /* [o] auxiliary information */ -}; -#endif - int put_sg_io_hdr(const struct sg_io_hdr *hdr, void __user *argp) { #ifdef CONFIG_COMPAT diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 160748ad9c0f..eace8886d95a 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -405,6 +405,38 @@ sg_release(struct inode *inode, struct file *filp) return 0; } +static int get_sg_io_pack_id(int *pack_id, void __user *buf, size_t count) +{ + struct sg_header __user *old_hdr = buf; + int reply_len; + + if (count >= SZ_SG_HEADER) { + /* negative reply_len means v3 format, otherwise v1/v2 */ + if (get_user(reply_len, &old_hdr->reply_len)) + return -EFAULT; + + if (reply_len >= 0) + return get_user(*pack_id, &old_hdr->pack_id); + + if (in_compat_syscall() && + count >= sizeof(struct compat_sg_io_hdr)) { + struct compat_sg_io_hdr __user *hp = buf; + + return get_user(*pack_id, &hp->pack_id); + } + + if (count >= sizeof(struct sg_io_hdr)) { + struct sg_io_hdr __user *hp = buf; + + return get_user(*pack_id, &hp->pack_id); + } + } + + /* no valid header was passed, so ignore the pack_id */ + *pack_id = -1; + return 0; +} + static ssize_t sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) { @@ -413,8 +445,8 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) Sg_request *srp; int req_pack_id = -1; sg_io_hdr_t *hp; - struct sg_header *old_hdr = NULL; - int retval = 0; + struct sg_header *old_hdr; + int retval; /* * This could cause a response to be stranded. Close the associated @@ -429,79 +461,34 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_read: count=%d\n", (int) count)); - if (sfp->force_packid && (count >= SZ_SG_HEADER)) { - old_hdr = memdup_user(buf, SZ_SG_HEADER); - if (IS_ERR(old_hdr)) - return PTR_ERR(old_hdr); - if (old_hdr->reply_len < 0) { - if (count >= SZ_SG_IO_HDR) { - /* - * This is stupid. - * - * We're copying the whole sg_io_hdr_t from user - * space just to get the 'pack_id' field. But the - * field is at different offsets for the compat - * case, so we'll use "get_sg_io_hdr()" to copy - * the whole thing and convert it. - * - * We could do something like just calculating the - * offset based of 'in_compat_syscall()', but the - * 'compat_sg_io_hdr' definition is in the wrong - * place for that. - */ - sg_io_hdr_t *new_hdr; - new_hdr = kmalloc(SZ_SG_IO_HDR, GFP_KERNEL); - if (!new_hdr) { - retval = -ENOMEM; - goto free_old_hdr; - } - retval = get_sg_io_hdr(new_hdr, buf); - req_pack_id = new_hdr->pack_id; - kfree(new_hdr); - if (retval) { - retval = -EFAULT; - goto free_old_hdr; - } - } - } else - req_pack_id = old_hdr->pack_id; - } + if (sfp->force_packid) + retval = get_sg_io_pack_id(&req_pack_id, buf, count); + if (retval) + return retval; + srp = sg_get_rq_mark(sfp, req_pack_id); if (!srp) { /* now wait on packet to arrive */ - if (atomic_read(&sdp->detaching)) { - retval = -ENODEV; - goto free_old_hdr; - } - if (filp->f_flags & O_NONBLOCK) { - retval = -EAGAIN; - goto free_old_hdr; - } + if (atomic_read(&sdp->detaching)) + return -ENODEV; + if (filp->f_flags & O_NONBLOCK) + return -EAGAIN; retval = wait_event_interruptible(sfp->read_wait, (atomic_read(&sdp->detaching) || (srp = sg_get_rq_mark(sfp, req_pack_id)))); - if (atomic_read(&sdp->detaching)) { - retval = -ENODEV; - goto free_old_hdr; - } - if (retval) { + if (atomic_read(&sdp->detaching)) + return -ENODEV; + if (retval) /* -ERESTARTSYS as signal hit process */ - goto free_old_hdr; - } - } - if (srp->header.interface_id != '\0') { - retval = sg_new_read(sfp, buf, count, srp); - goto free_old_hdr; + return retval; } + if (srp->header.interface_id != '\0') + return sg_new_read(sfp, buf, count, srp); hp = &srp->header; - if (old_hdr == NULL) { - old_hdr = kmalloc(SZ_SG_HEADER, GFP_KERNEL); - if (! old_hdr) { - retval = -ENOMEM; - goto free_old_hdr; - } - } - memset(old_hdr, 0, SZ_SG_HEADER); + old_hdr = kzalloc(SZ_SG_HEADER, GFP_KERNEL); + if (!old_hdr) + return -ENOMEM; + old_hdr->reply_len = (int) hp->timeout; old_hdr->pack_len = old_hdr->reply_len; /* old, strange behaviour */ old_hdr->pack_id = hp->pack_id; @@ -575,7 +562,12 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp) int err = 0, err2; int len; - if (count < SZ_SG_IO_HDR) { + if (in_compat_syscall()) { + if (count < sizeof(struct compat_sg_io_hdr)) { + err = -EINVAL; + goto err_out; + } + } else if (count < SZ_SG_IO_HDR) { err = -EINVAL; goto err_out; } diff --git a/include/scsi/sg.h b/include/scsi/sg.h index f91bcca604e4..29c7ad04d2e2 100644 --- a/include/scsi/sg.h +++ b/include/scsi/sg.h @@ -68,6 +68,36 @@ typedef struct sg_io_hdr unsigned int info; /* [o] auxiliary information */ } sg_io_hdr_t; /* 64 bytes long (on i386) */ +#if defined(__KERNEL__) +#include + +struct compat_sg_io_hdr { + compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ + compat_int_t dxfer_direction; /* [i] data transfer direction */ + unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ + unsigned char mx_sb_len; /* [i] max length to write to sbp */ + unsigned short iovec_count; /* [i] 0 implies no scatter gather */ + compat_uint_t dxfer_len; /* [i] byte count of data transfer */ + compat_uint_t dxferp; /* [i], [*io] points to data transfer memory + or scatter gather list */ + compat_uptr_t cmdp; /* [i], [*i] points to command to perform */ + compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */ + compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ + compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */ + compat_int_t pack_id; /* [i->o] unused internally (normally) */ + compat_uptr_t usr_ptr; /* [i->o] unused internally */ + unsigned char status; /* [o] scsi status */ + unsigned char masked_status; /* [o] shifted, masked scsi status */ + unsigned char msg_status; /* [o] messaging level data (optional) */ + unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ + unsigned short host_status; /* [o] errors from host adapter */ + unsigned short driver_status; /* [o] errors from software driver */ + compat_int_t resid; /* [o] dxfer_len - actual_transferred */ + compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */ + compat_uint_t info; /* [o] auxiliary information */ +}; +#endif + #define SG_INTERFACE_ID_ORIG 'S' /* Use negative values to flag difference from original sg_header structure */ From patchwork Tue Dec 17 22:16:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298963 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 387FE14F6 for ; Tue, 17 Dec 2019 22:20:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 21D9B2465E for ; Tue, 17 Dec 2019 22:20:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727386AbfLQWUQ (ORCPT ); Tue, 17 Dec 2019 17:20:16 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:58879 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725812AbfLQWRi (ORCPT ); Tue, 17 Dec 2019 17:17:38 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MQvL7-1iMdCi0pIl-00Nzc1; Tue, 17 Dec 2019 23:17:27 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 09/27] compat_ioctl: block: add blkdev_compat_ptr_ioctl Date: Tue, 17 Dec 2019 23:16:50 +0100 Message-Id: <20191217221708.3730997-10-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:mmtIkLxrwk7IQXXnRkJ8B+2FIyyyAbad/kCKhLBtclkyPF95FPH voKZ435khGb/rtE1AmYopeqLW2Enb6KjMU3aHMym/CCIeJ/134i1nElJvTyehEziysCaITM SGbQa8uXWK/Gqpwle4RlSqWWAEeHhE5oGw3U/w5L4R9Gyz1IQ2GtGKJ+dZ+hCIQ41q9oCmS PrBKnTbrQ5fXsSHRxWF0g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:OkErmRAfum4=:bs5oIeyGgjC4U4aWDbZOh/ DKd6onqIBwE2F0QpDgEetsTHqsV3372e0VrgDPYOum5LGyL+OEpI7a6ZuXY9jRiPihpaADr9T Ompi+2P4wiwfsZB77EX0NaNyyQ3d56ZiAiwwnLIhCLKlQ5FcCdYsIcVHg8IVxcKGbsf7WO3HP yS3YOdMtZO54LDweou2QG+Gww28abxwoFWLKKJT+p21mTw+ed/lStSFmes+A4f/PZ8kV8e5mi t4CLRzsQnWIznOyIq/ACNZ0kowqowqANtKXMTlIPWJD8GFj/VP3xHhx4xIlFxoGV9D8VDGWsH k+H6YDRNpvOGm4tc+9hqGTp8tWHdOD0XrxYq3MPpZOfTbCTlreslmPLaaGZt2gzGZCQNIcjCb U3QsQLRZwxaM00qJ68lUE2OlgcF7GehYglqWw0GKSVz5O/BlJA3t2RLJ6WWU1GsqKAk3P65Xf XGdWsPJzhcMWQLKUDTk7DlJr89QMsW1hJBIKo+gZGval4+f9aS/2h/FdqRd2m2xj9lArCuFZW a8R6Jfno0WOYH7FOvtR/c5ZI/nRrk4qK+McQBCuN/Q8F7cquTJNK10Sx1GaXRLmuA976QnXUz TBNZog8h2P+hz/RwrUI+ZDuPwOkbtQ3kD3qoPl9WoczeSVg4mTxXfCTuSjC4nlnVsIl/QY+Kp 6mRU6liGwyZ/RzBwhFt1f0Twtiiktxc0CDwZKi5SjUZAk96OS5OkeAvMkPBFIND/q7H1gAar7 a6CEbahPDVLIuBSAnCHjXF5/z47fABYF9GMYjz7K36x+ubwf/8zsAJ3tCd7oFQYz8NjQi7Trj ns48wnfWSfwgS5/nU/H0tE/3dADWFoNlPT3nMY/eeAgj3xNboPaUo65ErYe/I4V7im3Bu2IbB Ynnhxam78HYgbnMQvjPQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org A lot of block drivers need only a trivial .compat_ioctl callback. Add a helper function that can be set as the callback pointer to only convert the argument using the compat_ptr() conversion and otherwise assume all input and output data is compatible, or handled using in_compat_syscall() checks. This mirrors the compat_ptr_ioctl() helper function used in character devices. Signed-off-by: Arnd Bergmann --- block/ioctl.c | 21 +++++++++++++++++++++ include/linux/blkdev.h | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index 5de98b97af2a..e728331d1a5b 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -285,6 +286,26 @@ int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, */ EXPORT_SYMBOL_GPL(__blkdev_driver_ioctl); +#ifdef CONFIG_COMPAT +/* + * This is the equivalent of compat_ptr_ioctl(), to be used by block + * drivers that implement only commands that are completely compatible + * between 32-bit and 64-bit user space + */ +int blkdev_compat_ptr_ioctl(struct block_device *bdev, fmode_t mode, + unsigned cmd, unsigned long arg) +{ + struct gendisk *disk = bdev->bd_disk; + + if (disk->fops->ioctl) + return disk->fops->ioctl(bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); + + return -ENOIOCTLCMD; +} +EXPORT_SYMBOL(blkdev_compat_ptr_ioctl); +#endif + static int blkdev_pr_register(struct block_device *bdev, struct pr_registration __user *arg) { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 47eb22a3b7f9..3e0408618da7 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1711,6 +1711,13 @@ struct block_device_operations { const struct pr_ops *pr_ops; }; +#ifdef CONFIG_COMPAT +extern int blkdev_compat_ptr_ioctl(struct block_device *, fmode_t, + unsigned int, unsigned long); +#else +#define blkdev_compat_ptr_ioctl NULL +#endif + extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int, unsigned long); extern int bdev_read_page(struct block_device *, sector_t, struct page *); From patchwork Tue Dec 17 22:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298957 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 82E401892 for ; Tue, 17 Dec 2019 22:20:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B04B218AC for ; Tue, 17 Dec 2019 22:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727335AbfLQWUJ (ORCPT ); Tue, 17 Dec 2019 17:20:09 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:60465 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbfLQWRi (ORCPT ); Tue, 17 Dec 2019 17:17:38 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MLz7f-1iPOdC2idl-00Hxzz; Tue, 17 Dec 2019 23:17:27 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 10/27] compat_ioctl: ubd, aoe: use blkdev_compat_ptr_ioctl Date: Tue, 17 Dec 2019 23:16:51 +0100 Message-Id: <20191217221708.3730997-11-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pXgtQR2qBCnSxJSJP7Y8qCzLQ/VoWcKI8ZIUVUSLjozoL96eoEm jS/dQT773HwnIlYtCaz/VwTxsgiorHcK0GE59g6ES4DCAbJYDR1pNRuCqoUrPHL4Ry4d3U7 TBlboU8N5E4h71VTNV7UqnqgBwVPx8dGUD6nhs40UU5t+Hdgl82MsiuumI+NIWKdfJpzvX4 BT+G3Xk7tKgva9zDuTjig== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:3Sn1qxFJj1c=:tUMSxbPiYFrI6EX1e3mwt7 rHN1+PnajD2XFYaIDBNraD9FEMOuqalFH++3MPe70YKbWzHjPVXp2SL1e2amVBuwM/tQF2poX ZAxg9IGxSpByjPBLphmGwJ8tzfMgc23wRM9E/pheclEc7m26cxOfl3TGgSCxXueTFmEB3ohUE 8SFPImb/0CCIBMaoCC2lrjkTXrQWtrhzYfy0hXOg5SKiZCFOn2hsV1NwgrfqVUF2XXM4zDZB3 mFdH5RfFHOMubdOiTJhBtV81Q6rN0AaRiJ2t9RYKpPKv8kBfzJsECcI2K3Wo6P3e84R8oAQ/+ 8TSMWS/N3oAkC0IXVoOtDUhRyPVSZnXGkarWjwRIAkOZ+m1p0E1QXhImXsX71oNmMzdJNOk17 LbnQyUIr+3uUxLO/OKVOqRlfMs0UBbLGTD/7WdEw8jF3Lxy1jW8ohmVl35A9BqT57HpCnJz6H ttP+634RpDmKwCHYo+tJT3VYhKH5pOi7ScDUJPa5Vcaqc6WOgT56/xSvxPWv5SQp/2+TsCOOe YMqIbm2UwTskJlSOMI72+cmdPr+mFZomb7+1H5hjHOuj6HNO9PLZ7KLPCjgs+bJoYdqWKCXFO oAvSVUClMcvqPYvrqNSGkawmqmMsocU5kEZQGQV8/+FbJMXd+iN3AyE4T2iZQrk76Lbci7NCc U4jzy012goNB6UshKCU1nzNVTz2E1LKl7rD8liiurZhA7iCl4VsKQEMOSuS557ulSbEkt+thf sHP2x/MvCyoZiGz5M2N2lUQhAX1hz1I3NDvqZ7pT1wef7kU8blXu2l61NyozCxE59CEaM6fNv MakRtMJYuEDJbktoFgqDV2ycF6ZejToGYzbs6Qj86pA/GACn7UrBO5Uup/i/sqiz9Axo6UzW+ 6CAa68o34dGq7Dc9F0mA== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org These drivers implement the HDIO_GET_IDENTITY and CDROMVOLREAD ioctl commands, which are compatible between 32-bit and 64-bit user space and traditionally handled by compat_blkdev_driver_ioctl(). As a prerequisite to removing that function, make both drivers use blkdev_compat_ptr_ioctl() as their .compat_ioctl callback. Signed-off-by: Arnd Bergmann --- arch/um/drivers/ubd_kern.c | 1 + drivers/block/aoe/aoeblk.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 6627d7c30f37..582eb5b1f09b 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -113,6 +113,7 @@ static const struct block_device_operations ubd_blops = { .open = ubd_open, .release = ubd_release, .ioctl = ubd_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, .getgeo = ubd_getgeo, }; diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c index bd19f8af950b..7b32fb673375 100644 --- a/drivers/block/aoe/aoeblk.c +++ b/drivers/block/aoe/aoeblk.c @@ -329,6 +329,7 @@ static const struct block_device_operations aoe_bdops = { .open = aoeblk_open, .release = aoeblk_release, .ioctl = aoeblk_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, .getgeo = aoeblk_getgeo, .owner = THIS_MODULE, }; From patchwork Tue Dec 17 22:16:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298983 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 73706921 for ; Tue, 17 Dec 2019 22:22:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4797921582 for ; Tue, 17 Dec 2019 22:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726617AbfLQWWk (ORCPT ); Tue, 17 Dec 2019 17:22:40 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:50303 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbfLQWWj (ORCPT ); Tue, 17 Dec 2019 17:22:39 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MJV5K-1iNTt20bmK-00JtoE; Tue, 17 Dec 2019 23:17:28 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 11/27] compat_ioctl: move CDROM_SEND_PACKET handling into scsi Date: Tue, 17 Dec 2019 23:16:52 +0100 Message-Id: <20191217221708.3730997-12-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Mp6Rj1N7d53mOvmoxMfJiXqVy8L4vX/KvDXHNCZwCkj5FtqvPqF LmsoqBqoIPLL7AWulDNY/HeW0lyyWQFtfqHhobt64l7pTViW29nW6M1yeERIiviw+HfvW9Q cTGasJcn8hQNeBqcIHZ3tp1szj6SouCBKTs1wZrLmWyroDrgUBg7FdHwEOUDsQvv9ZRTh/V HOPorWfYSm2xUQnMzZwig== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:0YLBBWODoHM=:uDf/SRKlIUIKgACjezHiKS 5nSxSvF9qoF1iaB0ddvSTisSkno8s9Wk2vTRscWdwMFfHcVcv5uL2dLxFru8slEBa0C3U2AzB +qvKfh/fPsmmkm2x/eslA9pOJUnr6wCQU5MLzCM0fwzyVdsAqEXws3ArzSAMGTULxdNwCl4Kw jzcRXYpbhpYUmZ2AzexKsdTrmKLOFZblJ0whfwdLfYqHbovYis78zMBp/3+pm+Au8g/q+7fQj 2Se9G2tsx/xL4Ppv1Dw05sZaBVH4OHfjgNCv1/TjrRGmi6FlCDpcZCHP3tatmDvdwE/nf08EE +ZKkdw2y4IzjO8AR9efNnYOe2aVtS/xcvN97fzsVDM11AhDI7EY3hhRwXKK9EIh3fTE4+Jiy+ DYuSwqJu+Jv4y0in9PHCLvcHUIqeHiKH5xbb8GDpvHfUrRYxxjxWok+wbAf74aoUVLPHq3hrU 76ULf2FBo4wGrUAX/yrB6gmTUjrQlIyk5xh3BcP5Q4fk/1rTsPVo/6GplaCA2WK1LeAecFioU vsxhBfDw1tqC4rPy1DmGUB9QVAUd755Gu6npvnTHp29MURmGGWdFGvRqmVOlD4zfqYDVE3xsb q5YtAiSaxqrlBRGzLCH6XQuxjnugDwQoos7XnSvuzZEV1UeepTyGsrRQafzB3SBgAy74Jannt aTUkELjMbxJFbK5tZCFiXQNjUT2S8HFPeG8MBbqJYflhP+SrQW3Tdse4n4wv91i8VsBoMFA+2 z5N1q1j5Ucs3O+vRyHlAfia0CCIFDkU4p9pLC49Vw6ZJxFVYj/2S4XrzteXWLuLf594skFg3w xHq1mv+oQ5G0a3hH4R8YBcRABnBxssGrqj5MOVJkubu1LIag86jK0XzsRY4IzUOpJJ6gosCeL dLgbzKKx/LBfJPL/h5tQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org There is only one implementation of this ioctl, so move the handling out of the common block layer code into the place where it's actually needed. It also gets called indirectly through pktcdvd, which needs to be aware of this change. As I noticed, the old implementation of the compat handler failed to convert the structure on the way out, so the updated fields never got written back to user space. This is either not important, or it has never worked and should be fixed now. Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 47 +--------- block/scsi_ioctl.c | 185 ++++++++++++++++++++++++++++------------ drivers/block/pktcdvd.c | 6 +- 3 files changed, 135 insertions(+), 103 deletions(-) diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index f16ae92065d7..578e04f94619 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -102,18 +102,6 @@ struct compat_cdrom_read_audio { compat_caddr_t buf; }; -struct compat_cdrom_generic_command { - unsigned char cmd[CDROM_PACKET_SIZE]; - compat_caddr_t buffer; - compat_uint_t buflen; - compat_int_t stat; - compat_caddr_t sense; - unsigned char data_direction; - compat_int_t quiet; - compat_int_t timeout; - compat_caddr_t reserved[1]; -}; - static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { @@ -141,38 +129,6 @@ static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode, (unsigned long)cdread_audio); } -static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) -{ - struct cdrom_generic_command __user *cgc; - struct compat_cdrom_generic_command __user *cgc32; - u32 data; - unsigned char dir; - int itmp; - - cgc = compat_alloc_user_space(sizeof(*cgc)); - cgc32 = compat_ptr(arg); - - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) || - get_user(data, &cgc32->buffer) || - put_user(compat_ptr(data), &cgc->buffer) || - copy_in_user(&cgc->buflen, &cgc32->buflen, - (sizeof(unsigned int) + sizeof(int))) || - get_user(data, &cgc32->sense) || - put_user(compat_ptr(data), &cgc->sense) || - get_user(dir, &cgc32->data_direction) || - put_user(dir, &cgc->data_direction) || - get_user(itmp, &cgc32->quiet) || - put_user(itmp, &cgc->quiet) || - get_user(itmp, &cgc32->timeout) || - put_user(itmp, &cgc->timeout) || - get_user(data, &cgc32->reserved[0]) || - put_user(compat_ptr(data), &cgc->reserved[0])) - return -EFAULT; - - return __blkdev_driver_ioctl(bdev, mode, cmd, (unsigned long)cgc); -} - struct compat_blkpg_ioctl_arg { compat_int_t op; compat_int_t flags; @@ -224,8 +180,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, return compat_hdio_ioctl(bdev, mode, cmd, arg); case CDROMREADAUDIO: return compat_cdrom_read_audio(bdev, mode, cmd, arg); - case CDROM_SEND_PACKET: - return compat_cdrom_generic_command(bdev, mode, cmd, arg); /* * No handler required for the ones below, we just need to @@ -263,6 +217,7 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, case CDROM_DISC_STATUS: case CDROM_CHANGER_NSLOTS: case CDROM_GET_CAPABILITY: + case CDROM_SEND_PACKET: /* Ignore cdrom.h about these next 5 ioctls, they absolutely do * not take a struct cdrom_read, instead they take a struct cdrom_msf * which is compatible. diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index b61dbf4d8443..b4e73d5dd5c2 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -639,6 +639,136 @@ int get_sg_io_hdr(struct sg_io_hdr *hdr, const void __user *argp) } EXPORT_SYMBOL(get_sg_io_hdr); +#ifdef CONFIG_COMPAT +struct compat_cdrom_generic_command { + unsigned char cmd[CDROM_PACKET_SIZE]; + compat_caddr_t buffer; + compat_uint_t buflen; + compat_int_t stat; + compat_caddr_t sense; + unsigned char data_direction; + compat_int_t quiet; + compat_int_t timeout; + compat_caddr_t reserved[1]; +}; +#endif + +static int scsi_get_cdrom_generic_arg(struct cdrom_generic_command *cgc, + const void __user *arg) +{ +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) { + struct compat_cdrom_generic_command cgc32; + + if (copy_from_user(&cgc32, arg, sizeof(cgc32))) + return -EFAULT; + + *cgc = (struct cdrom_generic_command) { + .buffer = compat_ptr(cgc32.buffer), + .buflen = cgc32.buflen, + .stat = cgc32.stat, + .sense = compat_ptr(cgc32.sense), + .data_direction = cgc32.data_direction, + .quiet = cgc32.quiet, + .timeout = cgc32.timeout, + .reserved[0] = compat_ptr(cgc32.reserved[0]), + }; + memcpy(&cgc->cmd, &cgc32.cmd, CDROM_PACKET_SIZE); + return 0; + } +#endif + if (copy_from_user(cgc, arg, sizeof(*cgc))) + return -EFAULT; + + return 0; +} + +static int scsi_put_cdrom_generic_arg(const struct cdrom_generic_command *cgc, + void __user *arg) +{ +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) { + struct compat_cdrom_generic_command cgc32 = { + .buffer = (uintptr_t)(cgc->buffer), + .buflen = cgc->buflen, + .stat = cgc->stat, + .sense = (uintptr_t)(cgc->sense), + .data_direction = cgc->data_direction, + .quiet = cgc->quiet, + .timeout = cgc->timeout, + .reserved[0] = (uintptr_t)(cgc->reserved[0]), + }; + memcpy(&cgc32.cmd, &cgc->cmd, CDROM_PACKET_SIZE); + + if (copy_to_user(arg, &cgc32, sizeof(cgc32))) + return -EFAULT; + + return 0; + } +#endif + if (copy_to_user(arg, cgc, sizeof(*cgc))) + return -EFAULT; + + return 0; +} + +static int scsi_cdrom_send_packet(struct request_queue *q, + struct gendisk *bd_disk, + fmode_t mode, void __user *arg) +{ + struct cdrom_generic_command cgc; + struct sg_io_hdr hdr; + int err; + + err = scsi_get_cdrom_generic_arg(&cgc, arg); + if (err) + return err; + + cgc.timeout = clock_t_to_jiffies(cgc.timeout); + memset(&hdr, 0, sizeof(hdr)); + hdr.interface_id = 'S'; + hdr.cmd_len = sizeof(cgc.cmd); + hdr.dxfer_len = cgc.buflen; + switch (cgc.data_direction) { + case CGC_DATA_UNKNOWN: + hdr.dxfer_direction = SG_DXFER_UNKNOWN; + break; + case CGC_DATA_WRITE: + hdr.dxfer_direction = SG_DXFER_TO_DEV; + break; + case CGC_DATA_READ: + hdr.dxfer_direction = SG_DXFER_FROM_DEV; + break; + case CGC_DATA_NONE: + hdr.dxfer_direction = SG_DXFER_NONE; + break; + default: + return -EINVAL; + } + + hdr.dxferp = cgc.buffer; + hdr.sbp = cgc.sense; + if (hdr.sbp) + hdr.mx_sb_len = sizeof(struct request_sense); + hdr.timeout = jiffies_to_msecs(cgc.timeout); + hdr.cmdp = ((struct cdrom_generic_command __user*) arg)->cmd; + hdr.cmd_len = sizeof(cgc.cmd); + + err = sg_io(q, bd_disk, &hdr, mode); + if (err == -EFAULT) + return -EFAULT; + + if (hdr.status) + return -EIO; + + cgc.stat = err; + cgc.buflen = hdr.resid; + if (scsi_put_cdrom_generic_arg(&cgc, arg)) + return -EFAULT; + + return err; +} + int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mode, unsigned int cmd, void __user *arg) { @@ -689,60 +819,9 @@ int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mod err = -EFAULT; break; } - case CDROM_SEND_PACKET: { - struct cdrom_generic_command cgc; - struct sg_io_hdr hdr; - - err = -EFAULT; - if (copy_from_user(&cgc, arg, sizeof(cgc))) - break; - cgc.timeout = clock_t_to_jiffies(cgc.timeout); - memset(&hdr, 0, sizeof(hdr)); - hdr.interface_id = 'S'; - hdr.cmd_len = sizeof(cgc.cmd); - hdr.dxfer_len = cgc.buflen; - err = 0; - switch (cgc.data_direction) { - case CGC_DATA_UNKNOWN: - hdr.dxfer_direction = SG_DXFER_UNKNOWN; - break; - case CGC_DATA_WRITE: - hdr.dxfer_direction = SG_DXFER_TO_DEV; - break; - case CGC_DATA_READ: - hdr.dxfer_direction = SG_DXFER_FROM_DEV; - break; - case CGC_DATA_NONE: - hdr.dxfer_direction = SG_DXFER_NONE; - break; - default: - err = -EINVAL; - } - if (err) - break; - - hdr.dxferp = cgc.buffer; - hdr.sbp = cgc.sense; - if (hdr.sbp) - hdr.mx_sb_len = sizeof(struct request_sense); - hdr.timeout = jiffies_to_msecs(cgc.timeout); - hdr.cmdp = ((struct cdrom_generic_command __user*) arg)->cmd; - hdr.cmd_len = sizeof(cgc.cmd); - - err = sg_io(q, bd_disk, &hdr, mode); - if (err == -EFAULT) - break; - - if (hdr.status) - err = -EIO; - - cgc.stat = err; - cgc.buflen = hdr.resid; - if (copy_to_user(arg, &cgc, sizeof(cgc))) - err = -EFAULT; - + case CDROM_SEND_PACKET: + err = scsi_cdrom_send_packet(q, bd_disk, mode, arg); break; - } /* * old junk scsi send command ioctl diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 861fc65a1b75..ab4d3be4b646 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2671,15 +2671,13 @@ static int pkt_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned in case CDROMEJECT: case CDROMMULTISESSION: case CDROMREADTOCENTRY: + case CDROM_SEND_PACKET: /* compat mode handled in scsi_cmd_ioctl */ case SCSI_IOCTL_SEND_COMMAND: return pkt_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); - /* FIXME: no handler so far */ - case CDROM_LAST_WRITTEN: - /* handled in compat_blkdev_driver_ioctl */ - case CDROM_SEND_PACKET: default: + case CDROM_LAST_WRITTEN: return -ENOIOCTLCMD; } } From patchwork Tue Dec 17 22:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298907 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 50C6D921 for ; Tue, 17 Dec 2019 22:19:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 390BF21775 for ; Tue, 17 Dec 2019 22:19:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727128AbfLQWTL (ORCPT ); Tue, 17 Dec 2019 17:19:11 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:53763 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726539AbfLQWRm (ORCPT ); Tue, 17 Dec 2019 17:17:42 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N8GEY-1hdQgS2Y64-014F6s; Tue, 17 Dec 2019 23:17:28 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 12/27] compat_ioctl: move CDROMREADADIO to cdrom.c Date: Tue, 17 Dec 2019 23:16:53 +0100 Message-Id: <20191217221708.3730997-13-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:SEzk2cE2KU/nNwoHfidkX8tSUvACbWH8uSk5lxoIuhKQ5CztWxi bOWwXOzfL6LJLGSTM7iwROz0sna6duXBrCFvKGwnOsrAzq9Tg9pU9s7afIMaCaRpVGbyCN/ XwRKj4yFepn9WVTWTnBK2V3XIX2hZwlo+sFykVTcsN1BtuwMYi2wx4Oohc65URen5wcBFuc kGOwA5NDRqz4uDUVqyHtQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:HlEXxuefKnQ=:q2hK5YnnOvqsUKbyH+4ygI M+1LtTx6gRiGNH5cwDteqBKUew+WRP30dnsjs1CqXSY5tcG2Ji+XYJQ9fg74Lh/YtmFcIiDxi Wd5mr4n7Dob36GOioVZ0rnSOECG1wbZhlMDMr20rDGsI+87xKTZtYTgNG4DHoebf0r++6ZJFx D3cGh07tox4ZvxJp5blgH4rwItQP0lDSge2TLKnrbsF7/Azz4nQHzpzqIvAcOI45ni78YD7Q/ TGeD61+btd80HC99gaucfPqQHmud6suE08GOy/2X/2EzpfSHV2b+FFZHpAVW9n4BYDZY6E/o2 DlvTXTFpcVae8SsQm5vKEwO7KrhOm8iUBoD8hEIHOPuXLmNAMnRjC0z+M6eRZ23vwGbXFthBy SXLwKf4vDWdI1j2I5Hm+RmAuKnEnLqh/CxpZOJL8urWW6jmQD0BCso1Pr42qY6hntHQmClUZe 2uQM56dK/NVQe8Z9OwvO46PA+5OC/sRA2bQu548EgWAO/pLfXGWxOHcED0Wc2he6FlQYVIF1r DM+osZMXSMnLONmXnpSzJYHexkHQwDcD6Ilm4aSR0Bafc4LAqh3U904vhglbnuSXTBy4v28bG k+/bwy8R/clnpebnl0zPoUbXXhF71AMTm5PvJZZ9s1ugzjQwrwmk5VQ9AoKJGWUQSE18oxo0q cEe2qQy9AaufAKJ6c2Fr21LA3uqpwQ2CX1KJDBjvuVzkAhNRXV1iQFElVh1yeR03B+eFTPByi CpcpUkCYw7zZ7MEQQenSPWy/XRHmamdibRDpOvPyV9ZHYarpKVQ/JO/WHS2i2LowlZfjOhW92 9DvUema4JwLbhqhT3zOrL+qYxejCVGAPJhd1tDrKBuLXdyxrDxVziqd7Knxe6ltNa1Gjc+jDU a3jFykHFY1cSFNebaT1Q== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Again, there is only one file that needs this, so move the conversion handler into the native implementation. Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 36 ------------------------------------ drivers/cdrom/cdrom.c | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 578e04f94619..cf136bc2c9fc 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -95,40 +95,6 @@ static int compat_hdio_ioctl(struct block_device *bdev, fmode_t mode, return error; } -struct compat_cdrom_read_audio { - union cdrom_addr addr; - u8 addr_format; - compat_int_t nframes; - compat_caddr_t buf; -}; - -static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) -{ - struct cdrom_read_audio __user *cdread_audio; - struct compat_cdrom_read_audio __user *cdread_audio32; - __u32 data; - void __user *datap; - - cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio)); - cdread_audio32 = compat_ptr(arg); - - if (copy_in_user(&cdread_audio->addr, - &cdread_audio32->addr, - (sizeof(*cdread_audio32) - - sizeof(compat_caddr_t)))) - return -EFAULT; - - if (get_user(data, &cdread_audio32->buf)) - return -EFAULT; - datap = compat_ptr(data); - if (put_user(datap, &cdread_audio->buf)) - return -EFAULT; - - return __blkdev_driver_ioctl(bdev, mode, cmd, - (unsigned long)cdread_audio); -} - struct compat_blkpg_ioctl_arg { compat_int_t op; compat_int_t flags; @@ -178,8 +144,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, case HDIO_GET_ADDRESS: case HDIO_GET_BUSSTATE: return compat_hdio_ioctl(bdev, mode, cmd, arg); - case CDROMREADAUDIO: - return compat_cdrom_read_audio(bdev, mode, cmd, arg); /* * No handler required for the ones below, we just need to diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index eebdcbef0578..48095025e588 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -3017,9 +3017,31 @@ static noinline int mmc_ioctl_cdrom_read_audio(struct cdrom_device_info *cdi, struct cdrom_read_audio ra; int lba; - if (copy_from_user(&ra, (struct cdrom_read_audio __user *)arg, - sizeof(ra))) - return -EFAULT; +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) { + struct compat_cdrom_read_audio { + union cdrom_addr addr; + u8 addr_format; + compat_int_t nframes; + compat_caddr_t buf; + } ra32; + + if (copy_from_user(&ra32, arg, sizeof(ra32))) + return -EFAULT; + + ra = (struct cdrom_read_audio) { + .addr = ra32.addr, + .addr_format = ra32.addr_format, + .nframes = ra32.nframes, + .buf = compat_ptr(ra32.buf), + }; + } else +#endif + { + if (copy_from_user(&ra, (struct cdrom_read_audio __user *)arg, + sizeof(ra))) + return -EFAULT; + } if (ra.addr_format == CDROM_MSF) lba = msf_to_lba(ra.addr.msf.minute, From patchwork Tue Dec 17 22:16:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298893 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 1FF75921 for ; Tue, 17 Dec 2019 22:19:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08509218AC for ; Tue, 17 Dec 2019 22:19:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726710AbfLQWTB (ORCPT ); Tue, 17 Dec 2019 17:19:01 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:42327 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbfLQWRn (ORCPT ); Tue, 17 Dec 2019 17:17:43 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MPGNn-1iJtNk0HCn-00PeZf; Tue, 17 Dec 2019 23:17:29 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 13/27] compat_ioctl: cdrom: handle CDROM_LAST_WRITTEN Date: Tue, 17 Dec 2019 23:16:54 +0100 Message-Id: <20191217221708.3730997-14-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:wpOzJeFufAHUVew0tCAOYce8zMXOPidyJEDHZ6pQ5GaUKg8+CDX h7MBzbcLPVMio9kfQoSfOTfY3vxyKEJ51kkTL2W9m6KoiixxPeES/rPHhLYMS3HLccXegsv k2H3sqymCqH2WEdNBVYO+Pa/7nVD5p4xIpTPyQbpKaEF5BnOtpu5V76Hk5QKEhX0c57O6+9 iqqUYAqmFhuT18BCsoAUg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:CIB+4OQSR64=:WBhyckcX/5l7eAeTjvEoM/ w4upkT4JvAY0/CRT9+NICNrKfxWQgzFpdAAXj+N/219xyoUp3i3ArASxNj5M5wRYKgkvQZQxH CxE3wmmlICtVcCt38Iyj0fCz219veSow7XvDStghM7YdHK3Dyc6tvlWWXjGrbbVRnSjwPfDRg eVtYANDyKpGQXAf9W7W90lMaNv5QMnxNMgyq39t/ISQtLXqABgziP8W2h45E7twP5VBot7roC GL1ML1O03UlrCwfpOAkcgAdPWAHJZqUm3sBBK5njNHfVE35o5IBtcTuXdtKRnOvtk0yQoGDSJ VvyZRKQAB0hgxPqN29PkxvMSJi7nxkkeU4eEQ5e5E0s4OkSUgjPjtxtDSBpGBgdgb26I7jH2L WThg17UcmwvgV1keBdbZ4b/FITTwdodVlLprRQoVJYBHU+DHryNHvKqiVjmu2hjYvq+APMZRQ 8CqFFoQLK9j+/z4XOJvkjTBW3oFG5EyvDNVM6yeAWb/gJ/Q/cK4dMzs8/h2w38PPOyVOH+8CJ GIOD1toGYO9NJ1N9oFYeeglO/lAFX7OvezRPohzgPi2aoCJB6ApyXKb4gonN+8Fv4HMFm0YAn arCC0GtPppbxPq3gxhB8lsLrZSS2AFE+ix/mk7W8HSVu6ItzoancGQHxY/wKZjbbETFZm5fPJ /14Hk/KHBiHbbD+jpVUF0Y+Gf1ti/u7yMF0lQGlVccJE3OH+qD4WefTxzFl5aPUrsX15aFR1w Cc0R5lYy8WI3de9J8he5JIBk4eYo4gSYrrHC7sS4ng7SAXuIfuf+vpYVaZYyqumJzv7yGEiiG i+9Lx5d/5ai3pOwDpQnQJJ3YqYcqWsPmuRATJOiCUiObGVXUhY5YSaDw3y0R2ptIuC1ixKtTh QEy6XnI1qqp/ZZw4o4iQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is the only ioctl command that does not have a proper compat handler. Making the normal implementation do the right thing is actually very simply, so just do that by using an in_compat_syscall() check to avoid the special case in the pkcdvd driver. Signed-off-by: Arnd Bergmann --- drivers/block/pktcdvd.c | 24 +----------------------- drivers/cdrom/cdrom.c | 7 ++++--- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index ab4d3be4b646..5f970a7d32c0 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2663,26 +2663,6 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, return ret; } -#ifdef CONFIG_COMPAT -static int pkt_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) -{ - switch (cmd) { - /* compatible */ - case CDROMEJECT: - case CDROMMULTISESSION: - case CDROMREADTOCENTRY: - case CDROM_SEND_PACKET: /* compat mode handled in scsi_cmd_ioctl */ - case SCSI_IOCTL_SEND_COMMAND: - return pkt_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); - - /* FIXME: no handler so far */ - default: - case CDROM_LAST_WRITTEN: - return -ENOIOCTLCMD; - } -} -#endif - static unsigned int pkt_check_events(struct gendisk *disk, unsigned int clearing) { @@ -2704,9 +2684,7 @@ static const struct block_device_operations pktcdvd_ops = { .open = pkt_open, .release = pkt_close, .ioctl = pkt_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = pkt_compat_ioctl, -#endif + .compat_ioctl = blkdev_compat_ptr_ioctl, .check_events = pkt_check_events, }; diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 48095025e588..faca0f346fff 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -3293,9 +3293,10 @@ static noinline int mmc_ioctl_cdrom_last_written(struct cdrom_device_info *cdi, ret = cdrom_get_last_written(cdi, &last); if (ret) return ret; - if (copy_to_user((long __user *)arg, &last, sizeof(last))) - return -EFAULT; - return 0; + if (in_compat_syscall()) + return put_user(last, (__s32 __user *)arg); + + return put_user(last, (long __user *)arg); } static int mmc_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, From patchwork Tue Dec 17 22:16:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298865 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 F2AE714F6 for ; Tue, 17 Dec 2019 22:18:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DA3E521775 for ; Tue, 17 Dec 2019 22:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbfLQWRx (ORCPT ); Tue, 17 Dec 2019 17:17:53 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:52901 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726744AbfLQWRt (ORCPT ); Tue, 17 Dec 2019 17:17:49 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N63JO-1hbEp725Si-016S2I; Tue, 17 Dec 2019 23:17:29 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 14/27] compat_ioctl: block: handle cdrom compat ioctl in non-cdrom drivers Date: Tue, 17 Dec 2019 23:16:55 +0100 Message-Id: <20191217221708.3730997-15-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:fgECgP85UcsuJjsyAuZL7QHYXHYBEzujC6oqv+TYTA3UFXDQ0+O zy7BYkmbtD/vp8Tk1y4FGXR086ig4FhOi/Rl5dEFBP99TTQ2jhWlrdT8lSSnQknngX1KAB6 I+ogzZX67PGokZ5zfes54eIzqMGogav4wpegt34I+hdR5RPVE6BuP6DYZmUdBpq20dc60rb ROIQeamCDbWQqLST38hUw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:GRelAd88hdg=:yDxJVmxWHvbBFPkEJEmEgE UEJvUfrBcsIZdJ7qfTVCrg1uiVg3njJLZUgTJpKad1/0+ryRGw9lVt3Avgsqio22idIXMjSYk 6zrTwH4axXV4Cl4ve64rU2hWTWiT/olx8jg/SSUSaetzy5RDNf/kR3vv022nW2OozkTrsv2Yv /G/tPFFJ/YBFl9BrRb2jp6K9D5f4ATmf4sld1YkHKSUtY7tHEgC8mVhtoCF92EsLDURoV9VJt rOPjvPYp8I/ZUFiMUOMMlGNUHa6F8+6UvVkrSO1TmPLafk/QSAS4uGvK2jtG4/xE3SPeFk35b FnNQX3FjImzSW8jI1uRA1naRTwsNWeQZWOqgRYbqlziCqvUX/O2q4xWgWF/hso+qX6SFlpKTE gKrZcHUKfFqK//ND+xPaACsxvQ+CNeJ3eLsDDN9dtEZiwd2nVTJ7q695ln4CGsdnBo5b+2fWO qDoIgtssB7L/qaqDin3lV+OxwZKxJCo2TwB8Y8JllsSvRYDjFFCJ1PJbY6hN4DeFWZdoGXHXC dpbdNgG70Q12STFtj0ptYcToUP5JrcHW4zGjaNIEUb9flTkhKGrWUEyYVRgDMFRiJ78qeeGG7 U6OJUSgaYGm37yvkzz1stO8fLt5rQwHkF6HtPm9npdUb53zFh6omU7pXKYtof7ZZi8bTLU06Z EhsMwxi3rstYhU6Jfqyz+YGUlUQIC7EA4tUEB0JowiIEFBwKZH9DDJwFAVchSJ3iJ6bfjciKR 8xWRaCtwhXmQAAbQZiw/69ztEa+l7vwzQQxnVaXo73+DcvjaO2Vr+EYUvfvkw1aQRAZ6QF5bW Tah+sUwg3WYC/0ow8O3EuxAAp19fzZTzbD3gcbp3e2aKDjGK+jphXGvhxn0A7CwGsUys4OFtb zAVZkqDVqwzXkJ9H41qQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Various block drivers implement the CDROMMULTISESSION, CDROM_GET_CAPABILITY, and CDROMEJECT ioctl commands, relying on the block layer to handle compat_ioctl mode for them. Move this into the drivers directly as a preparation for simplifying the block layer later. When only integer arguments or no arguments are passed, the same handler can be used for .ioctl and .compat_ioctl, and when only pointer arguments are passed, the newly added blkdev_compat_ptr_ioctl can be used. Signed-off-by: Arnd Bergmann --- drivers/block/floppy.c | 3 +++ drivers/block/paride/pd.c | 1 + drivers/block/paride/pf.c | 1 + drivers/block/sunvdc.c | 1 + drivers/block/xen-blkfront.c | 1 + 5 files changed, 7 insertions(+) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 485865fd0412..cd3612e4e2e1 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3879,6 +3879,9 @@ static int fd_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int { int drive = (long)bdev->bd_disk->private_data; switch (cmd) { + case CDROMEJECT: /* CD-ROM eject */ + case 0x6470: /* SunOS floppy eject */ + case FDMSGON: case FDMSGOFF: case FDSETEMSGTRESH: diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c index 6f9ad3fc716f..c0967507d085 100644 --- a/drivers/block/paride/pd.c +++ b/drivers/block/paride/pd.c @@ -874,6 +874,7 @@ static const struct block_device_operations pd_fops = { .open = pd_open, .release = pd_release, .ioctl = pd_ioctl, + .compat_ioctl = pd_ioctl, .getgeo = pd_getgeo, .check_events = pd_check_events, .revalidate_disk= pd_revalidate diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c index 6b7d4cab3687..bb09f21ce21a 100644 --- a/drivers/block/paride/pf.c +++ b/drivers/block/paride/pf.c @@ -276,6 +276,7 @@ static const struct block_device_operations pf_fops = { .open = pf_open, .release = pf_release, .ioctl = pf_ioctl, + .compat_ioctl = pf_ioctl, .getgeo = pf_getgeo, .check_events = pf_check_events, }; diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c index 571612e233fe..39aeebc6837d 100644 --- a/drivers/block/sunvdc.c +++ b/drivers/block/sunvdc.c @@ -171,6 +171,7 @@ static const struct block_device_operations vdc_fops = { .owner = THIS_MODULE, .getgeo = vdc_getgeo, .ioctl = vdc_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, }; static void vdc_blk_queue_start(struct vdc_port *port) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index a74d03913822..23c86350a5ab 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -2632,6 +2632,7 @@ static const struct block_device_operations xlvbd_block_fops = .release = blkif_release, .getgeo = blkif_getgeo, .ioctl = blkif_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, }; From patchwork Tue Dec 17 22:16:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298843 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 71DAF14B7 for ; Tue, 17 Dec 2019 22:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5836520716 for ; Tue, 17 Dec 2019 22:18:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726931AbfLQWSP (ORCPT ); Tue, 17 Dec 2019 17:18:15 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:36663 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726865AbfLQWSB (ORCPT ); Tue, 17 Dec 2019 17:18:01 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mn2iP-1i0tG23yJr-00k6zJ; Tue, 17 Dec 2019 23:17:30 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 15/27] compat_ioctl: add scsi_compat_ioctl Date: Tue, 17 Dec 2019 23:16:56 +0100 Message-Id: <20191217221708.3730997-16-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:7+9fPO46Y0HOH2OsOUifwZayoQFbXANj+Oa9VP+1U7rh8ZhZZ8F 3hxCkpaA0NO2kdv6ZjC7Pgek4BhVndAGAH74m7t3INTUHKuOrVeEt1zDk8MHcDHm51AGTFB i36qQDfnTVO+CYDUu1JMmlixsSxong5R851SGfuaWLQN8Xk51RMnN8aiZwuYw/GZ0rdzqWU ivSwaSOO+EgFMWYzMvC3g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:yXc2hnIb6Ew=:BmbRqeeBaGxFN50taxmFBo AY7Ftkhhc9Z2VsPCHIDRN/ZHcQLs60RU/ZEvxvBwZIglimP546GHVde0vtrNsMN2HtblCPxPw rBRQKO2ARkBnklEkN+iMV8MEZhJ8srTpBNGo8nfXETXa7SNAXtW+768+tj9dtTYADhOLIf958 8gTa2Y/MsH++UEcuF1GQfQGgKH0pqtWukenVKl/gFUeDh2sgrNtRNQW9jwS6C+dnOAfguHCH1 ID4Qs/pfPtvcNkWQWOYnC8Cxk0EhwbG3kPjv18zQNtWROCysQsIKEMg+mrkJhhD9kz6QHTcQJ 4Qsm7lKUNqfcqQKd8/ifFRcooygBwXfk0H+pw5ae8EzcVq1VETJSXA34T9Ryrmz53GrgMYoL6 EIFHi7mI4La9/ty+0u/a8wHeKGVttDL80Ve3WItZ2vjoButtXX39HOuDaUWPZnD+owBuSfdhG Qfv/6nqIAQr5JvRqQuDM7oJ55+Eyja+eWaVUfp6XTUoRRVOfW4sY0HhnelNN6575s1Ri+zwmS rgNyU+vhYg3HUOqdkydSJ16lwkzL+ZM8b/ZYMqlil81ogT9V0OHOaMJMboTsf8bUhDIn3UNyd GdrCgPPUYp0N6SRsm9h5v/5lrCmgyINDBzuHm6Aq/2WRJOe179VmvhYwVJ7WoyjKaFx+oQ+Hz +/QDIQBT9HWa4Cc+67t5UsCVSoIAAEb3h0sFHmNakFM/D8ySgTVTW6EUuNTABasAetCKik53V G1D/SAS96Qlaky35Ws5whccdgGnA0xfZYAWRT6trmwdon9U0fcmT9ICdsZ3oRrzZ/tymL4h7Y QG0c9EQ4J1FnZrfxc09XCL1xwnf8QaZGZFuI14EaA3IG+nEKpmEWbKf9yh/ZzGlgoVthHYykV WGe2+u3w+mZZxg6ytwlw== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In order to move the compat handling for SCSI ioctl commands out of fs/compat_ioctl.c into the individual drivers, we need a helper function first to match the native ioctl handler called by sd, sr, st, etc. Signed-off-by: Arnd Bergmann --- drivers/scsi/scsi_ioctl.c | 54 +++++++++++++++++++++++++++++---------- include/scsi/scsi_ioctl.h | 1 + 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c index 57bcd05605bf..8f3af87b6bb0 100644 --- a/drivers/scsi/scsi_ioctl.c +++ b/drivers/scsi/scsi_ioctl.c @@ -189,17 +189,7 @@ static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg) } -/** - * scsi_ioctl - Dispatch ioctl to scsi device - * @sdev: scsi device receiving ioctl - * @cmd: which ioctl is it - * @arg: data associated with ioctl - * - * Description: The scsi_ioctl() function differs from most ioctls in that it - * does not take a major/minor number as the dev field. Rather, it takes - * a pointer to a &struct scsi_device. - */ -int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +static int scsi_ioctl_common(struct scsi_device *sdev, int cmd, void __user *arg) { char scsi_cmd[MAX_COMMAND_SIZE]; struct scsi_sense_hdr sense_hdr; @@ -266,14 +256,50 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) return scsi_ioctl_get_pci(sdev, arg); case SG_SCSI_RESET: return scsi_ioctl_reset(sdev, arg); - default: - if (sdev->host->hostt->ioctl) - return sdev->host->hostt->ioctl(sdev, cmd, arg); } + return -ENOIOCTLCMD; +} + +/** + * scsi_ioctl - Dispatch ioctl to scsi device + * @sdev: scsi device receiving ioctl + * @cmd: which ioctl is it + * @arg: data associated with ioctl + * + * Description: The scsi_ioctl() function differs from most ioctls in that it + * does not take a major/minor number as the dev field. Rather, it takes + * a pointer to a &struct scsi_device. + */ +int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +{ + int ret = scsi_ioctl_common(sdev, cmd, arg); + + if (ret != -ENOIOCTLCMD) + return ret; + + if (sdev->host->hostt->ioctl) + return sdev->host->hostt->ioctl(sdev, cmd, arg); + return -EINVAL; } EXPORT_SYMBOL(scsi_ioctl); +#ifdef CONFIG_COMPAT +int scsi_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +{ + int ret = scsi_ioctl_common(sdev, cmd, arg); + + if (ret != -ENOIOCTLCMD) + return ret; + + if (sdev->host->hostt->compat_ioctl) + return sdev->host->hostt->compat_ioctl(sdev, cmd, arg); + + return ret; +} +EXPORT_SYMBOL(scsi_compat_ioctl); +#endif + /* * We can process a reset even when a device isn't fully operable. */ diff --git a/include/scsi/scsi_ioctl.h b/include/scsi/scsi_ioctl.h index 5101e987c0ef..4fe69d863b5d 100644 --- a/include/scsi/scsi_ioctl.h +++ b/include/scsi/scsi_ioctl.h @@ -44,6 +44,7 @@ typedef struct scsi_fctargaddress { int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev, int cmd, bool ndelay); extern int scsi_ioctl(struct scsi_device *, int, void __user *); +extern int scsi_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg); #endif /* __KERNEL__ */ #endif /* _SCSI_IOCTL_H */ From patchwork Tue Dec 17 22:16:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298917 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 729E7921 for ; Tue, 17 Dec 2019 22:19:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 508E621775 for ; Tue, 17 Dec 2019 22:19:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727208AbfLQWTW (ORCPT ); Tue, 17 Dec 2019 17:19:22 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:34075 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727165AbfLQWTV (ORCPT ); Tue, 17 Dec 2019 17:19:21 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M8QJq-1icvIw1gYq-004PCA; Tue, 17 Dec 2019 23:17:30 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 16/27] compat_ioctl: bsg: add handler Date: Tue, 17 Dec 2019 23:16:57 +0100 Message-Id: <20191217221708.3730997-17-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:CcW0OER95wDXq0YetFdqoTdTEnAWcPISLF3QDQtri9hrxSFvPXG fBdpTLjhv0iKK2rBmn4jyDnjys1/pVoz09rAJLkDNE6wj+fddgYodj6iKfELZj3+/PdHrcO tw2Gy4JzU2ZMgdpd+jxtzid1wBePiv+WmdPlrT6nYzzMvTt7km/aGxMnd97UOOoejnfCoWW 3LytDdHjU3oriRUGkNmhg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Yj2mPlnFp94=:fKjchY6xasw3iPgAiTTlST y2fJLfy8whAQA/X2JktR72kckWBi+i+GEgdIL1mIGmyUXnZeEfx3jWleiclTjPFTEBCBFDJG1 LoMm7vit2smCIWZGk0nKs7UkMSSPS6mvR65hs5LpSANX+RaU3V7ZeKeA2idWlUnrHmUdvvibW +LQWNNSDTYtRkk/PNlXcEA6YkgeLx1SHpOD+VHOB5cmlFFpYGyeM3RLnFFo619lx1X5D4ussB uqqdu+Nw6bQm+WKgAQewdSLPTnLm4UDHvOeL4FglMwkbnotBzQ5uEclxuKlWcJqgGkCI3Wlsa YlrYI4rnIsbPU1T3/dxGG+MXkafh0q8q/Q3x/aJPHzic/vq6ILaZ5oqEB3Jpjm7qZlXfvjiLC KRicjRF7eptVnI8dEu+/dRlm2wIKp5QbMekshiCZ6dMt5Hu70cie3YtrGyG/l3nsFgAOcgEQD 3I9TUzjmYpQ6XfZYgGk1k5Tyv6UhDeccLVyIDIGneWMxwg/8JRCDHiU3nVKTTX2x9JlepYfYA pn44I3n4hpd2M7d/Mozo5exhR/zqgs/OqS5dv2B5egGWjpFEm0cSNddo4KOjqs1VMhFN9IWci rJnQWp8uhzgSp7R2NGiD+cpQpiJDTzFkNYFo+mUeQdwyqECBf/UxeyIC6fgkRO8AbH1jCnRuq Bdk4xAS8wttqqA5ORCTI+u4uCS6TvUopNrl7ez2lDq2Ytoqn9wweQHdfiSMwxQaroKFRt2JO2 sz7QiNH9ux8S3D0ZAMAZXmZ7xZPAQNAqU4s4Spd0Du7vRE8GYvEvbtl0FQCX8LSuIZukuOnaC eAGqMMEkqmSN+sY8xwVupa0n2qbWj21AbUF4pNA9Bw1h4CY3Utti2W04Du/wCUTADSvQkO5Jz Eo+g0fwG0WoTSGpv4V5w== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org bsg_ioctl() calls into scsi_cmd_ioctl() for a couple of generic commands and relies on fs/compat_ioctl.c to handle it correctly in compat mode. Adding a private compat_ioctl() handler avoids that round-trip and lets us get rid of the generic emulation once this is done. Note that bsg implements an SG_IO command that is different from the other drivers and does not need emulation. Signed-off-by: Arnd Bergmann --- block/bsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/bsg.c b/block/bsg.c index 833c44b3d458..d7bae94b64d9 100644 --- a/block/bsg.c +++ b/block/bsg.c @@ -382,6 +382,7 @@ static const struct file_operations bsg_fops = { .open = bsg_open, .release = bsg_release, .unlocked_ioctl = bsg_ioctl, + .compat_ioctl = compat_ptr_ioctl, .owner = THIS_MODULE, .llseek = default_llseek, }; From patchwork Tue Dec 17 22:16:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298857 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 E862E14F6 for ; Tue, 17 Dec 2019 22:18:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D04BE2467B for ; Tue, 17 Dec 2019 22:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbfLQWRy (ORCPT ); Tue, 17 Dec 2019 17:17:54 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:42985 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726704AbfLQWRw (ORCPT ); Tue, 17 Dec 2019 17:17:52 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MPGNn-1iJtNn3lVt-00PeZf; Tue, 17 Dec 2019 23:17:31 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 17/27] compat_ioctl: ide: floppy: add handler Date: Tue, 17 Dec 2019 23:16:58 +0100 Message-Id: <20191217221708.3730997-18-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:YnQrSz5O/D2DBGfbF3Cxsk8pwEEUjT589STUMJGh3yzpShzGnbO UtKl0ZGJsAHThUjdm9r51gvC9l545WINo2a5prkFBHzM+9RQY3Arloots1Xrir/7jn058ZY lY3dvFXWkGkgFTV1afb9NJTxv07jjMP3/LZ84ITxMj0bnoBEEePtmNtjq9iMjF1weBFG1TC CVXMzbb5iVF+fqWiS0O2w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:O/6PR2RnMp8=:5roBt3plMVSEraB1jz2O5h p/M30legg9XR/Y/Kt/C/cwvJgImxkhqYbhnmDZ2jTM2ic2roOHdDCBbJwfOURYUFv0qGwYzWa B2qWZx8aF/jNGciRRonzsvtzrevrh8kgSm8SKRw4Z6HWilgQGzNa0JD2cygphpSkBHxjjTPe0 H6R4AoSx5K3lxdgReJ5SvYGUxJbJUFdmlDojMI8lu4Tix3nugJN5mv6/AeZWrgBiEL+NG06x2 SgnQ2R/DcJgY4NErD0D7vRfFy8nqvisRhkpns9431tOEz0o3rDBPRYcIgj+gshSq2sOxzJo2z h7k/r2KY1WXGuAc75gUQhqPjJKOm2k6nybp1HZs/+ZBZt7R26M699R/3vHkZACKON1XGl+aKr LvnRY6PJsnz4ob7wlAJmOaNdU2cazFj72pim9W9C/KJIazWpDqXAo4BNI11sjQQdRf2fRBuZI NJ/EqqAIZ9wL9g9N0iwnpBrRZy3dHYY4DFnVeu2s3VceoZerOn19nvm43OnFQhc1AkcPHlSmn 5Ba+6ALgh7JeJNL8swznKcGRFu9oSkIixiuTNlJBhb1sr7lI0YaFAkyb2Ut6mRPAOx2Sj2EjE pFuCkh94PX3JIrwC96rcvZOvq400csat6sR/PyNWbUIDzTIjhvN8JQKpi4J8/RmkC1IUh8Htt XXtazTi9tD12OGpO4CotDAU1RxMk7FJ88cSUhUsvMRFvCL4La2Qgh1BiXbZm/PKI53oQA+VqW 2QOEW2x5t7BuvU3oX6EOs0f++xF8S0/BtDzSGXrMNi5xQKnOR6mQVrtiTtrKsGPBvlVOxqZew XHitJ7G+1QtWOXxgkURun9rL+6BVtR84ilhBgmhg/13As5Oka/Y11NCk5RSLTqrNCesFbIn5D Ju2TSq0UrO3DiZI9eDkA== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Rather than relying on fs/compat_ioctl.c, this adds support for a compat_ioctl() callback in the ide-floppy driver directly, which lets it translate the scsi commands. Signed-off-by: Arnd Bergmann --- drivers/ide/ide-floppy.c | 4 ++++ drivers/ide/ide-floppy.h | 2 ++ drivers/ide/ide-floppy_ioctl.c | 36 ++++++++++++++++++++++++++++++++++ drivers/ide/ide-gd.c | 14 +++++++++++++ include/linux/ide.h | 2 ++ 5 files changed, 58 insertions(+) diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c index 1ea2f9e82bf8..1fe1f9d37a51 100644 --- a/drivers/ide/ide-floppy.c +++ b/drivers/ide/ide-floppy.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -546,4 +547,7 @@ const struct ide_disk_ops ide_atapi_disk_ops = { .set_doorlock = ide_set_media_lock, .do_request = ide_floppy_do_request, .ioctl = ide_floppy_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = ide_floppy_compat_ioctl, +#endif }; diff --git a/drivers/ide/ide-floppy.h b/drivers/ide/ide-floppy.h index 13c9b4b6d75e..8505a5f58f4e 100644 --- a/drivers/ide/ide-floppy.h +++ b/drivers/ide/ide-floppy.h @@ -26,6 +26,8 @@ void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *); /* ide-floppy_ioctl.c */ int ide_floppy_ioctl(ide_drive_t *, struct block_device *, fmode_t, unsigned int, unsigned long); +int ide_floppy_compat_ioctl(ide_drive_t *, struct block_device *, fmode_t, + unsigned int, unsigned long); #ifdef CONFIG_IDE_PROC_FS /* ide-floppy_proc.c */ diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c index 40a2ebe34e1d..4fd70f804d6f 100644 --- a/drivers/ide/ide-floppy_ioctl.c +++ b/drivers/ide/ide-floppy_ioctl.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -302,3 +303,38 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev, mutex_unlock(&ide_floppy_ioctl_mutex); return err; } + +#ifdef CONFIG_COMPAT +int ide_floppy_compat_ioctl(ide_drive_t *drive, struct block_device *bdev, + fmode_t mode, unsigned int cmd, unsigned long arg) +{ + struct ide_atapi_pc pc; + void __user *argp = compat_ptr(arg); + int err; + + mutex_lock(&ide_floppy_ioctl_mutex); + if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) { + err = ide_floppy_lockdoor(drive, &pc, arg, cmd); + goto out; + } + + err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp); + if (err != -ENOTTY) + goto out; + + /* + * skip SCSI_IOCTL_SEND_COMMAND (deprecated) + * and CDROM_SEND_PACKET (legacy) ioctls + */ + if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) + err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); + + /* + * there is no generic_ide_compat_ioctl(), that is handled + * through compat_blkdev_ioctl(). + */ +out: + mutex_unlock(&ide_floppy_ioctl_mutex); + return err; +} +#endif diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c index dba9ad5c97b3..1b0270efcce2 100644 --- a/drivers/ide/ide-gd.c +++ b/drivers/ide/ide-gd.c @@ -341,11 +341,25 @@ static int ide_gd_ioctl(struct block_device *bdev, fmode_t mode, return drive->disk_ops->ioctl(drive, bdev, mode, cmd, arg); } +#ifdef CONFIG_COMPAT +static int ide_gd_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj); + ide_drive_t *drive = idkp->drive; + + return drive->disk_ops->compat_ioctl(drive, bdev, mode, cmd, arg); +} +#endif + static const struct block_device_operations ide_gd_ops = { .owner = THIS_MODULE, .open = ide_gd_unlocked_open, .release = ide_gd_release, .ioctl = ide_gd_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = ide_gd_compat_ioctl, +#endif .getgeo = ide_gd_getgeo, .check_events = ide_gd_check_events, .unlock_native_capacity = ide_gd_unlock_native_capacity, diff --git a/include/linux/ide.h b/include/linux/ide.h index 46b771d6999e..06dae6438557 100644 --- a/include/linux/ide.h +++ b/include/linux/ide.h @@ -413,6 +413,8 @@ struct ide_disk_ops { sector_t); int (*ioctl)(struct ide_drive_s *, struct block_device *, fmode_t, unsigned int, unsigned long); + int (*compat_ioctl)(struct ide_drive_s *, struct block_device *, + fmode_t, unsigned int, unsigned long); }; /* ATAPI device flags */ From patchwork Tue Dec 17 22:16:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298935 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 82FE8921 for ; Tue, 17 Dec 2019 22:19:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 603C421582 for ; Tue, 17 Dec 2019 22:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727231AbfLQWTd (ORCPT ); Tue, 17 Dec 2019 17:19:33 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:56131 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbfLQWTc (ORCPT ); Tue, 17 Dec 2019 17:19:32 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MtfVx-1hpnQi1UI3-00v9dR; Tue, 17 Dec 2019 23:17:31 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 18/27] compat_ioctl: scsi: move ioctl handling into drivers Date: Tue, 17 Dec 2019 23:16:59 +0100 Message-Id: <20191217221708.3730997-19-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ACk8mJ6p9pO9XGYZxSQ/tEfqG1zGT1plRpgFkrAt+woRyLkjjDA PdnPnDPYo2/l4TrNF2k2F6g8PbMHStTtQmYhlAA1Bmt1/EFR6jZErQzVWNNtCkbQX9rP/ok 5StFXRjLIf95PnKFPCHXYxPYcOGFSG1KzeQ15ngLplFmpAWRRUTUE/zh2KAihTsKfcsSTVd cL0rT4MiFYVebMALVOB9Q== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:lhFKuqtKylI=:SQj0yQNXIGTjik53OqgUlR RuOBGK3c8w3rpHczLJ082Q8h20U3jYaOqfJ267LzWjDbipCZd3bBH4yh3Tkl/j4b3Qawv7d/2 Q+zpOJsrNehuXMocjuKiqdw1eSGaT1BuacMqb3cFpOqPXFO8l0/xmdPURb0bJM/2xMkCczNQq Iu7Psp6yqcdWQfcvh/VLwGfDIZXU7KvtQGqidLS+AiXC7bphsAJu5F6scR5Ck1Nd1uRMbg/zR dNysKxr5oZWWfac/XnHRZoHSkbFFp1TgTnii6gL2SMFeHdu4FObUVq0Ys99ttc6PMFk/UyQ7i 1iOG23iBP2FVSLcXRGsYJnGWn09S1NXjMQyZ1z0Yjpux75BvkiOvbiKfbUjvM7TUbxp1RO2sA EB1QrMBre+LuIbiPC/lFYwtdvvGL8jwA0kLOkjBxZLWM74Hkht6SBXjBVxe1Sm4wSR6yq9rq6 XHn20+gULJFS+TZdH+93Bf30Mhpqb+xTB9QAJr7S8penGnONShWbBR9+uBzPcyyjcRKY45pTQ KOcHN+ASMJwYc1o6kO8uWcoZcudQ+pgf4bfZuFCuUi3X/Qp7hDlT0Lx3cnsAgbwKgLKohKMg8 P9m1TbMmjJVGIqvH9io4GK1HKEnzgbMgheDYWnYo/2CxfcKRya5w7DfU3SCTQHrkGSLU4/gqf Cg/K/4U3fb8O+UEhnqS4uZFBK7r6GtMEZ3k5Cs0Y5rS3k/I9zklO5WatwSnwK+nFd1oepPo/K GAVhNoLZ7e6bN4ggTS0eqIKIvLk+VwT1VBQ1o0mK818EK37uz1SPpFD3Z9R+mgg7ymIFusaNr +RSoQvZFBl1utv13gQ91OuVpRwGzmtinsPb+Qw9Nvlhf+XSN8wKgZeZhlrdY/y0u2ZMxJ5Td/ hT1VjlFkV1G7E13FztnQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Each driver calling scsi_ioctl() gets an equivalent compat_ioctl() handler that implements the same commands by calling scsi_compat_ioctl(). The scsi_cmd_ioctl() and scsi_cmd_blk_ioctl() functions are compatible at this point, so any driver that calls those can do so for both native and compat mode, with the argument passed through compat_ptr(). With this, we can remove the entries from fs/compat_ioctl.c. The new code is larger, but should be easier to maintain and keep updated with newly added commands. Signed-off-by: Arnd Bergmann --- drivers/block/virtio_blk.c | 3 + drivers/scsi/ch.c | 9 ++- drivers/scsi/sd.c | 50 ++++++-------- drivers/scsi/sg.c | 44 ++++++++----- drivers/scsi/sr.c | 57 ++++++++++++++-- drivers/scsi/st.c | 51 ++++++++------ fs/compat_ioctl.c | 132 +------------------------------------ 7 files changed, 142 insertions(+), 204 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 7ffd719d89de..fbbf18ac1d5d 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -405,6 +405,9 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) static const struct block_device_operations virtblk_fops = { .ioctl = virtblk_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = blkdev_compat_ptr_ioctl, +#endif .owner = THIS_MODULE, .getgeo = virtblk_getgeo, }; diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c index 76751d6c7f0d..ed5f4a6ae270 100644 --- a/drivers/scsi/ch.c +++ b/drivers/scsi/ch.c @@ -872,6 +872,10 @@ static long ch_ioctl_compat(struct file * file, unsigned int cmd, unsigned long arg) { scsi_changer *ch = file->private_data; + int retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd, + file->f_flags & O_NDELAY); + if (retval) + return retval; switch (cmd) { case CHIOGPARAMS: @@ -883,7 +887,7 @@ static long ch_ioctl_compat(struct file * file, case CHIOINITELEM: case CHIOSVOLTAG: /* compatible */ - return ch_ioctl(file, cmd, arg); + return ch_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); case CHIOGSTATUS32: { struct changer_element_status32 ces32; @@ -898,8 +902,7 @@ static long ch_ioctl_compat(struct file * file, return ch_gstatus(ch, ces32.ces_type, data); } default: - // return scsi_ioctl_compat(ch->device, cmd, (void*)arg); - return -ENOIOCTLCMD; + return scsi_compat_ioctl(ch->device, cmd, compat_ptr(arg)); } } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index cea625906440..5afb0046b12a 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1465,13 +1465,12 @@ static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo) * Note: most ioctls are forward onto the block subsystem or further * down in the scsi subsystem. **/ -static int sd_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) +static int sd_ioctl_common(struct block_device *bdev, fmode_t mode, + unsigned int cmd, void __user *p) { struct gendisk *disk = bdev->bd_disk; struct scsi_disk *sdkp = scsi_disk(disk); struct scsi_device *sdp = sdkp->device; - void __user *p = (void __user *)arg; int error; SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp, "sd_ioctl: disk=%s, " @@ -1507,9 +1506,6 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode, break; default: error = scsi_cmd_blk_ioctl(bdev, mode, cmd, p); - if (error != -ENOTTY) - break; - error = scsi_ioctl(sdp, cmd, p); break; } out: @@ -1691,39 +1687,31 @@ static void sd_rescan(struct device *dev) revalidate_disk(sdkp->disk); } +static int sd_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + void __user *p = (void __user *)arg; + int ret; + + ret = sd_ioctl_common(bdev, mode, cmd, p); + if (ret != -ENOTTY) + return ret; + + return scsi_ioctl(scsi_disk(bdev->bd_disk)->device, cmd, p); +} #ifdef CONFIG_COMPAT -/* - * This gets directly called from VFS. When the ioctl - * is not recognized we go back to the other translation paths. - */ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { - struct gendisk *disk = bdev->bd_disk; - struct scsi_disk *sdkp = scsi_disk(disk); - struct scsi_device *sdev = sdkp->device; void __user *p = compat_ptr(arg); - int error; - - error = scsi_verify_blk_ioctl(bdev, cmd); - if (error < 0) - return error; + int ret; - error = scsi_ioctl_block_when_processing_errors(sdev, cmd, - (mode & FMODE_NDELAY) != 0); - if (error) - return error; + ret = sd_ioctl_common(bdev, mode, cmd, p); + if (ret != -ENOTTY) + return ret; - if (is_sed_ioctl(cmd)) - return sed_ioctl(sdkp->opal_dev, cmd, p); - - /* - * Let the static ioctl translation table take care of it. - */ - if (!sdev->host->hostt->compat_ioctl) - return -ENOIOCTLCMD; - return sdev->host->hostt->compat_ioctl(sdev, cmd, p); + return scsi_compat_ioctl(scsi_disk(bdev->bd_disk)->device, cmd, p); } #endif diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index eace8886d95a..bafeaf7b9ad8 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -911,19 +911,14 @@ static int put_compat_request_table(struct compat_sg_req_info __user *o, #endif static long -sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) +sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, + unsigned int cmd_in, void __user *p) { - void __user *p = (void __user *)arg; int __user *ip = p; int result, val, read_only; - Sg_device *sdp; - Sg_fd *sfp; Sg_request *srp; unsigned long iflags; - if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) - return -ENXIO; - SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_ioctl: cmd=0x%x\n", (int) cmd_in)); read_only = (O_RDWR != (filp->f_flags & O_ACCMODE)); @@ -1146,29 +1141,44 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) cmd_in, filp->f_flags & O_NDELAY); if (result) return result; + + return -ENOIOCTLCMD; +} + +static long +sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) +{ + void __user *p = (void __user *)arg; + Sg_device *sdp; + Sg_fd *sfp; + int ret; + + if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) + return -ENXIO; + + ret = sg_ioctl_common(filp, sdp, sfp, cmd_in, p); + if (ret != -ENOIOCTLCMD) + return ret; + return scsi_ioctl(sdp->device, cmd_in, p); } #ifdef CONFIG_COMPAT static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) { + void __user *p = compat_ptr(arg); Sg_device *sdp; Sg_fd *sfp; - struct scsi_device *sdev; + int ret; if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) return -ENXIO; - sdev = sdp->device; - if (sdev->host->hostt->compat_ioctl) { - int ret; - - ret = sdev->host->hostt->compat_ioctl(sdev, cmd_in, (void __user *)arg); - + ret = sg_ioctl_common(filp, sdp, sfp, cmd_in, p); + if (ret != -ENOIOCTLCMD) return ret; - } - - return -ENOIOCTLCMD; + + return scsi_compat_ioctl(sdp->device, cmd_in, p); } #endif diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 4664fdf75c0f..6033a886c42c 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -598,6 +599,55 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, return ret; } +#ifdef CONFIG_COMPAT +static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, + unsigned long arg) +{ + struct scsi_cd *cd = scsi_cd(bdev->bd_disk); + struct scsi_device *sdev = cd->device; + void __user *argp = compat_ptr(arg); + int ret; + + mutex_lock(&sr_mutex); + + ret = scsi_ioctl_block_when_processing_errors(sdev, cmd, + (mode & FMODE_NDELAY) != 0); + if (ret) + goto out; + + scsi_autopm_get_device(sdev); + + /* + * Send SCSI addressing ioctls directly to mid level, send other + * ioctls to cdrom/block level. + */ + switch (cmd) { + case SCSI_IOCTL_GET_IDLUN: + case SCSI_IOCTL_GET_BUS_NUMBER: + ret = scsi_compat_ioctl(sdev, cmd, argp); + goto put; + } + + /* + * CDROM ioctls are handled in the block layer, but + * do the scsi blk ioctls here. + */ + ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); + if (ret != -ENOTTY) + return ret; + + ret = scsi_compat_ioctl(sdev, cmd, argp); + +put: + scsi_autopm_put_device(sdev); + +out: + mutex_unlock(&sr_mutex); + return ret; + +} +#endif + static unsigned int sr_block_check_events(struct gendisk *disk, unsigned int clearing) { @@ -641,12 +691,11 @@ static const struct block_device_operations sr_bdops = .open = sr_block_open, .release = sr_block_release, .ioctl = sr_block_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = sr_block_compat_ioctl, +#endif .check_events = sr_block_check_events, .revalidate_disk = sr_block_revalidate_disk, - /* - * No compat_ioctl for now because sr_block_ioctl never - * seems to pass arbitrary ioctls down to host drivers. - */ }; static int sr_open(struct cdrom_device_info *cdi, int purpose) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 9e3fff2de83e..393f3019ccac 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -3501,7 +3501,7 @@ static int partition_tape(struct scsi_tape *STp, int size) /* The ioctl command */ -static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) +static long st_ioctl_common(struct file *file, unsigned int cmd_in, void __user *p) { int i, cmd_nr, cmd_type, bt; int retval = 0; @@ -3509,7 +3509,6 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) struct scsi_tape *STp = file->private_data; struct st_modedef *STm; struct st_partstat *STps; - void __user *p = (void __user *)arg; if (mutex_lock_interruptible(&STp->lock)) return -ERESTARTSYS; @@ -3824,9 +3823,19 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) } mutex_unlock(&STp->lock); switch (cmd_in) { + case SCSI_IOCTL_STOP_UNIT: + /* unload */ + retval = scsi_ioctl(STp->device, cmd_in, p); + if (!retval) { + STp->rew_at_close = 0; + STp->ready = ST_NO_TAPE; + } + return retval; + case SCSI_IOCTL_GET_IDLUN: case SCSI_IOCTL_GET_BUS_NUMBER: break; + default: if ((cmd_in == SG_IO || cmd_in == SCSI_IOCTL_SEND_COMMAND || @@ -3840,42 +3849,46 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) return i; break; } - retval = scsi_ioctl(STp->device, cmd_in, p); - if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) { /* unload */ - STp->rew_at_close = 0; - STp->ready = ST_NO_TAPE; - } - return retval; + return -ENOTTY; out: mutex_unlock(&STp->lock); return retval; } +static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) +{ + void __user *p = (void __user *)arg; + struct scsi_tape *STp = file->private_data; + int ret; + + ret = st_ioctl_common(file, cmd_in, p); + if (ret != -ENOTTY) + return ret; + + return scsi_ioctl(STp->device, cmd_in, p); +} + #ifdef CONFIG_COMPAT static long st_compat_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) { void __user *p = compat_ptr(arg); struct scsi_tape *STp = file->private_data; - struct scsi_device *sdev = STp->device; - int ret = -ENOIOCTLCMD; + int ret; /* argument conversion is handled using put_user_mtpos/put_user_mtget */ switch (cmd_in) { - case MTIOCTOP: - return st_ioctl(file, MTIOCTOP, (unsigned long)p); case MTIOCPOS32: - return st_ioctl(file, MTIOCPOS, (unsigned long)p); + return st_ioctl_common(file, MTIOCPOS, p); case MTIOCGET32: - return st_ioctl(file, MTIOCGET, (unsigned long)p); + return st_ioctl_common(file, MTIOCGET, p); } - if (sdev->host->hostt->compat_ioctl) { + ret = st_ioctl_common(file, cmd_in, p); + if (ret != -ENOTTY) + return ret; - ret = sdev->host->hostt->compat_ioctl(sdev, cmd_in, (void __user *)arg); - - } - return ret; + return scsi_compat_ioctl(STp->device, cmd_in, p); } #endif diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index 358ea2ecf36b..ab4471f469e6 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c @@ -36,109 +36,11 @@ #include "internal.h" -#ifdef CONFIG_BLOCK -#include -#include -#include -#include -#include -#endif - #include #include #include - -#include - -/* - * simple reversible transform to make our table more evenly - * distributed after sorting. - */ -#define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff) - -#define COMPATIBLE_IOCTL(cmd) XFORM((u32)cmd), -static unsigned int ioctl_pointer[] = { -#ifdef CONFIG_BLOCK -/* Big S */ -COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN) -COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK) -COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK) -COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY) -COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER) -COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND) -COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST) -COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI) -#endif -#ifdef CONFIG_BLOCK -/* SG stuff */ -COMPATIBLE_IOCTL(SG_IO) -COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE) -COMPATIBLE_IOCTL(SG_SET_TIMEOUT) -COMPATIBLE_IOCTL(SG_GET_TIMEOUT) -COMPATIBLE_IOCTL(SG_EMULATED_HOST) -COMPATIBLE_IOCTL(SG_GET_TRANSFORM) -COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE) -COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE) -COMPATIBLE_IOCTL(SG_GET_SCSI_ID) -COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA) -COMPATIBLE_IOCTL(SG_GET_LOW_DMA) -COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID) -COMPATIBLE_IOCTL(SG_GET_PACK_ID) -COMPATIBLE_IOCTL(SG_GET_NUM_WAITING) -COMPATIBLE_IOCTL(SG_SET_DEBUG) -COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE) -COMPATIBLE_IOCTL(SG_GET_COMMAND_Q) -COMPATIBLE_IOCTL(SG_SET_COMMAND_Q) -COMPATIBLE_IOCTL(SG_GET_VERSION_NUM) -COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN) -COMPATIBLE_IOCTL(SG_SCSI_RESET) -COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE) -COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN) -COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN) -#endif -}; - -/* - * Convert common ioctl arguments based on their command number - * - * Please do not add any code in here. Instead, implement - * a compat_ioctl operation in the place that handleÑ• the - * ioctl for the native case. - */ -static long do_ioctl_trans(unsigned int cmd, - unsigned long arg, struct file *file) -{ - return -ENOIOCTLCMD; -} - -static int compat_ioctl_check_table(unsigned int xcmd) -{ -#ifdef CONFIG_BLOCK - int i; - const int max = ARRAY_SIZE(ioctl_pointer) - 1; - - BUILD_BUG_ON(max >= (1 << 16)); - - /* guess initial offset into table, assuming a - normalized distribution */ - i = ((xcmd >> 16) * max) >> 16; - - /* do linear search up first, until greater or equal */ - while (ioctl_pointer[i] < xcmd && i < max) - i++; - - /* then do linear search down */ - while (ioctl_pointer[i] > xcmd && i > 0) - i--; - - return ioctl_pointer[i] == xcmd; -#else - return 0; -#endif -} - COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, compat_ulong_t, arg32) { @@ -216,19 +118,9 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, goto out_fput; } - if (!f.file->f_op->unlocked_ioctl) - goto do_ioctl; - break; - } - - if (compat_ioctl_check_table(XFORM(cmd))) - goto found_handler; - - error = do_ioctl_trans(cmd, arg, f.file); - if (error == -ENOIOCTLCMD) error = -ENOTTY; - - goto out_fput; + goto out_fput; + } found_handler: arg = (unsigned long)compat_ptr(arg); @@ -239,23 +131,3 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, out: return error; } - -static int __init init_sys32_ioctl_cmp(const void *p, const void *q) -{ - unsigned int a, b; - a = *(unsigned int *)p; - b = *(unsigned int *)q; - if (a > b) - return 1; - if (a < b) - return -1; - return 0; -} - -static int __init init_sys32_ioctl(void) -{ - sort(ioctl_pointer, ARRAY_SIZE(ioctl_pointer), sizeof(*ioctl_pointer), - init_sys32_ioctl_cmp, NULL); - return 0; -} -__initcall(init_sys32_ioctl); From patchwork Tue Dec 17 22:17:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298887 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 6280D14F6 for ; Tue, 17 Dec 2019 22:18:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4009721D7D for ; Tue, 17 Dec 2019 22:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727066AbfLQWSr (ORCPT ); Tue, 17 Dec 2019 17:18:47 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:57707 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726656AbfLQWRo (ORCPT ); Tue, 17 Dec 2019 17:17:44 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MZl1l-1iDrlU3PPT-00WpIf; Tue, 17 Dec 2019 23:17:31 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 19/27] compat_ioctl: move sys_compat_ioctl() to ioctl.c Date: Tue, 17 Dec 2019 23:17:00 +0100 Message-Id: <20191217221708.3730997-20-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:uitpeVFCvHeOqyYvOf9VceF0TkY7WDr+aoxiayii8Nsle7oX7c4 tRK0a94PCUH6uhLlvKz+JTH2P5Hn4tAZo7O8EVVZifhaA1VGs0ay1Ld7k3PT6fbHr21oFY3 XfDJX0zycHaRJPsvt1s+0y9gkgyzTrVrCG/aFgHi2jXROje4THWKk8Don6y+d7EWfgZmw+k 4HLFri5/9xxQsbf0VHy4g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:sVRCpX+XGZA=:ZBzw1UJJqSCs3zp91ameci KXBlh9Xa40oyraHgp1AAkgibcSSuAMYnnxdPm59s3JCuj3hQicsBkGRdsYttbK4dpo3xkmhW1 y6wHfgiZVkGHXtPmuWR81JZHd2fXlRbVkVBmX8pSdEEEj5KsOW4mFk0G0yl4Kd7ILhhhniH8C UTQaJl3PdMxI77+Rb3MwaGcTTtuuoTubL18bpBSKIUKj7jtr40dt35GtOpOHuZsm2RQz5AIxi mQInCCSWJIErLmQc3NlhGLp1lyIDMcqLVRUA446pERNbNcp81qvFJjGQ+y/PUpG3zKLsAm26f iKpOiP7sFI4irglSea7jCZzcC1X60oiu5c3IuIAi3N6FcrpHwakYrt8YXVMyV1aW+Zbjw7Tce ounnfsyexFV4e2glN8SsS78BYQRS7IGM78S68cEkPnZJ3C3q9TEahk9DEDYYcf1S7dhR598s+ AoENyPuZROXbicx4qWfLwMdawxzEDJaLYkeusfQEyDJxy99Qz8O8eHBlEWc7Ohji+l9xec88c GaioANanR4VIcTK4vfzhlgRkundMpFpXEN9hyrHPf2PbSCeyhn+34GR/qfnIr1LAqLaOz9nvG 9gRjPimEYwiV+q9DAp68c8njXwRXtR9C7P2b+pJJBNvZ1NxQWOvt4PZqeUEbWDYb2t+K4Pn7N MvPWC2bxrM6OQmCfVkaN22zqQowq1p3T8mtHyTUL+TvX728JEhy6LoTqrpDwrSoqZZ8vaKibu 8c7G/HAnzIsgYRm6qh+aA5rDPmWeDyhSJP8iXJZHKot5g6tkvRwli/79wGGfJ32+PdFJwzxal rVxt1jWN/T2Wa8lAF4xW8xSoNFDs7fdOPINGuBcHz0bJrG4PM8A3RtIbNFDoYnqDw2pxToSVy roQ65vYHMw3pGLUc6BZQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The rest of the fs/compat_ioctl.c file is no longer useful now, so move the actual syscall as planned. Signed-off-by: Arnd Bergmann --- fs/Makefile | 2 +- fs/compat_ioctl.c | 133 ---------------------------------------------- fs/ioctl.c | 90 +++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 134 deletions(-) delete mode 100644 fs/compat_ioctl.c diff --git a/fs/Makefile b/fs/Makefile index 1148c555c4d3..98be354fdb61 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -37,7 +37,7 @@ obj-$(CONFIG_FS_DAX) += dax.o obj-$(CONFIG_FS_ENCRYPTION) += crypto/ obj-$(CONFIG_FS_VERITY) += verity/ obj-$(CONFIG_FILE_LOCKING) += locks.o -obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o +obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o obj-$(CONFIG_BINFMT_EM86) += binfmt_em86.o obj-$(CONFIG_BINFMT_MISC) += binfmt_misc.o diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c deleted file mode 100644 index ab4471f469e6..000000000000 --- a/fs/compat_ioctl.c +++ /dev/null @@ -1,133 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * ioctl32.c: Conversion between 32bit and 64bit native ioctls. - * - * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com) - * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) - * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs - * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz) - * - * These routines maintain argument size conversion between 32bit and 64bit - * ioctls. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "internal.h" - -#include -#include - -#include - -COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, - compat_ulong_t, arg32) -{ - unsigned long arg = arg32; - struct fd f = fdget(fd); - int error = -EBADF; - if (!f.file) - goto out; - - /* RED-PEN how should LSM module know it's handling 32bit? */ - error = security_file_ioctl(f.file, cmd, arg); - if (error) - goto out_fput; - - switch (cmd) { - /* these are never seen by ->ioctl(), no argument or int argument */ - case FIOCLEX: - case FIONCLEX: - case FIFREEZE: - case FITHAW: - case FICLONE: - goto do_ioctl; - /* these are never seen by ->ioctl(), pointer argument */ - case FIONBIO: - case FIOASYNC: - case FIOQSIZE: - case FS_IOC_FIEMAP: - case FIGETBSZ: - case FICLONERANGE: - case FIDEDUPERANGE: - goto found_handler; - /* - * The next group is the stuff handled inside file_ioctl(). - * For regular files these never reach ->ioctl(); for - * devices, sockets, etc. they do and one (FIONREAD) is - * even accepted in some cases. In all those cases - * argument has the same type, so we can handle these - * here, shunting them towards do_vfs_ioctl(). - * ->compat_ioctl() will never see any of those. - */ - /* pointer argument, never actually handled by ->ioctl() */ - case FIBMAP: - goto found_handler; - /* handled by some ->ioctl(); always a pointer to int */ - case FIONREAD: - goto found_handler; - /* these get messy on amd64 due to alignment differences */ -#if defined(CONFIG_X86_64) - case FS_IOC_RESVSP_32: - case FS_IOC_RESVSP64_32: - error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg)); - goto out_fput; - case FS_IOC_UNRESVSP_32: - case FS_IOC_UNRESVSP64_32: - error = compat_ioctl_preallocate(f.file, FALLOC_FL_PUNCH_HOLE, - compat_ptr(arg)); - goto out_fput; - case FS_IOC_ZERO_RANGE_32: - error = compat_ioctl_preallocate(f.file, FALLOC_FL_ZERO_RANGE, - compat_ptr(arg)); - goto out_fput; -#else - case FS_IOC_RESVSP: - case FS_IOC_RESVSP64: - case FS_IOC_UNRESVSP: - case FS_IOC_UNRESVSP64: - case FS_IOC_ZERO_RANGE: - goto found_handler; -#endif - - default: - if (f.file->f_op->compat_ioctl) { - error = f.file->f_op->compat_ioctl(f.file, cmd, arg); - if (error != -ENOIOCTLCMD) - goto out_fput; - } - - error = -ENOTTY; - goto out_fput; - } - - found_handler: - arg = (unsigned long)compat_ptr(arg); - do_ioctl: - error = do_vfs_ioctl(f.file, fd, cmd, arg); - out_fput: - fdput(f); - out: - return error; -} diff --git a/fs/ioctl.c b/fs/ioctl.c index 2f5e4e5b97e1..8f22f7817edb 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -788,4 +788,94 @@ long compat_ptr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return file->f_op->unlocked_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); } EXPORT_SYMBOL(compat_ptr_ioctl); + +COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, + compat_ulong_t, arg32) +{ + unsigned long arg = arg32; + struct fd f = fdget(fd); + int error = -EBADF; + if (!f.file) + goto out; + + /* RED-PEN how should LSM module know it's handling 32bit? */ + error = security_file_ioctl(f.file, cmd, arg); + if (error) + goto out_fput; + + switch (cmd) { + /* these are never seen by ->ioctl(), no argument or int argument */ + case FIOCLEX: + case FIONCLEX: + case FIFREEZE: + case FITHAW: + case FICLONE: + goto do_ioctl; + /* these are never seen by ->ioctl(), pointer argument */ + case FIONBIO: + case FIOASYNC: + case FIOQSIZE: + case FS_IOC_FIEMAP: + case FIGETBSZ: + case FICLONERANGE: + case FIDEDUPERANGE: + goto found_handler; + /* + * The next group is the stuff handled inside file_ioctl(). + * For regular files these never reach ->ioctl(); for + * devices, sockets, etc. they do and one (FIONREAD) is + * even accepted in some cases. In all those cases + * argument has the same type, so we can handle these + * here, shunting them towards do_vfs_ioctl(). + * ->compat_ioctl() will never see any of those. + */ + /* pointer argument, never actually handled by ->ioctl() */ + case FIBMAP: + goto found_handler; + /* handled by some ->ioctl(); always a pointer to int */ + case FIONREAD: + goto found_handler; + /* these get messy on amd64 due to alignment differences */ +#if defined(CONFIG_X86_64) + case FS_IOC_RESVSP_32: + case FS_IOC_RESVSP64_32: + error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg)); + goto out_fput; + case FS_IOC_UNRESVSP_32: + case FS_IOC_UNRESVSP64_32: + error = compat_ioctl_preallocate(f.file, FALLOC_FL_PUNCH_HOLE, + compat_ptr(arg)); + goto out_fput; + case FS_IOC_ZERO_RANGE_32: + error = compat_ioctl_preallocate(f.file, FALLOC_FL_ZERO_RANGE, + compat_ptr(arg)); + goto out_fput; +#else + case FS_IOC_RESVSP: + case FS_IOC_RESVSP64: + case FS_IOC_UNRESVSP: + case FS_IOC_UNRESVSP64: + case FS_IOC_ZERO_RANGE: + goto found_handler; +#endif + + default: + if (f.file->f_op->compat_ioctl) { + error = f.file->f_op->compat_ioctl(f.file, cmd, arg); + if (error != -ENOIOCTLCMD) + goto out_fput; + } + error = -ENOTTY; + goto out_fput; + } + + found_handler: + arg = (unsigned long)compat_ptr(arg); + do_ioctl: + error = do_vfs_ioctl(f.file, fd, cmd, arg); + out_fput: + fdput(f); + out: + return error; +} #endif From patchwork Tue Dec 17 22:17:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298851 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 1774E921 for ; Tue, 17 Dec 2019 22:18:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E00C32467B for ; Tue, 17 Dec 2019 22:18:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbfLQWS1 (ORCPT ); Tue, 17 Dec 2019 17:18:27 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:55579 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbfLQWR5 (ORCPT ); Tue, 17 Dec 2019 17:17:57 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MRCBm-1iMMMC1ATk-00NAX4; Tue, 17 Dec 2019 23:17:32 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 20/27] compat_ioctl: simplify the implementation Date: Tue, 17 Dec 2019 23:17:01 +0100 Message-Id: <20191217221708.3730997-21-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:uK/YvNPT87O8gnoGWXh+F6Kwe06h+iVKNBQ7Vn492sB4NIm5fiO u8phscXPcsvZTLm/r6hUxiXDYINp6z+whQ1Kudg6IF96I27vCuUYSzL5m5paSXGTuUhVM67 783MX/6yKk1S7cJuTYhsnTyaN2T3Gikmuj1K9bzg4mqhdupgj1VF45J8exygF1mRvh7Khau s2UeQsmlK13ufWeKFxOLA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:enayNnzw2bY=:vxJr0zRZN5ttbUOCvy6+qe fo2wmFEaqJxAjt+Uqf3aCl9PpBwrGBXg7NF1bjjsxL3elMwpKU8EXa+6q8gLmkR2OCuv2s1aP 0sJFtYHrnUiGOfWpErlI+70B/6NM9rdPn+aKlGOD9Ob4gIIjIJ0bUVWcta5nut4HWg8QkiGyJ pV5CS1m3ZQMHpiMlNKmuA9Xd/uPT3oICXmtFEJBs7EcAzayCFhZdoXLajzLG+JPBAoYiE0BrA CQjBJ604Z98+aNfysExq3uUQKUu3ALpOzPB4GNTO1FCf3+ZMyGhARyXsjwdkYJr5QY0sPiKPu /3w2ZWx0bI3n30YePES8AesJ2Sk9FQYyMZIyUnI32CxNwJuVnp/ivJB7lTwSPp+7Nxw4ItMWH KGoO4wVkjmOZQAWhNpmcqLTCRKqLi2efjJWM9Lzcj9yPq+rNT31461M/KU/xyXznWJHKC0gs+ lUUH7Xt8xYJVfECf2MU4mwnnGbGDic0LxVXfPFGxtU/OmvxIrHDpqChzmz1Dp3T/FedGvuWda Jv1jAcAdivxNqSvjoqdK7sdvnBivzWvF3axmubM4LbSfAnh/D+bBFI/M4YYdXecwnN4IOCg3g 4dMa6xcR24YDKz4Rx0/qOftVjLb65DIPx79dpf86XSx6fWoOTmrJSE7b+g/2H2MrgVM+5fCj/ vG3V5ALBDGmkFfVrX4z3jRqcRFU/jiE2PytJMv3xVzoSvfiMPBI9mRnHFUTPETM8kk6fkpWJN 7ht0v41VoSm08w9B6Yhlbr0Ngh27Vls0LFT/uzzklooVGg/lnHKwXM6Ik76tiZybo2AdJ1M8H qIkrTFBpyQOjItD1QsZ2/DjmHkmDnSCuVfr7f7seSKSY0+J86+8ugV2f48ieJ00lZxntTu/Tu pQoNPCjuXQatKrHZfnEQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Now that both native and compat ioctl syscalls are in the same file, a couple of simplifications can be made, bringing the implementation closer together: - do_vfs_ioctl(), ioctl_preallocate(), and compat_ioctl_preallocate() can become static, allowing the compiler to optimize better - slightly update the coding style for consistency between the functions. - rather than listing each command in two switch statements for the compat case, just call a single function that has all the common commands. As a side-effect, FS_IOC_RESVSP/FS_IOC_RESVSP64 are now available to x86 compat tasks, along with FS_IOC_RESVSP_32/FS_IOC_RESVSP64_32. This is harmless for i386 emulation, and can be considered a bugfix for x32 emulation, which never supported these in the past. Signed-off-by: Arnd Bergmann --- fs/internal.h | 6 -- fs/ioctl.c | 157 +++++++++++++++++------------------------ include/linux/falloc.h | 2 - include/linux/fs.h | 4 -- 4 files changed, 64 insertions(+), 105 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 4a7da1df573d..d46247850ad7 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -180,11 +180,5 @@ extern void mnt_pin_kill(struct mount *m); */ extern const struct dentry_operations ns_dentry_operations; -/* - * fs/ioctl.c - */ -extern int do_vfs_ioctl(struct file *file, unsigned int fd, unsigned int cmd, - unsigned long arg); - /* direct-io.c: */ int sb_init_dio_done_wq(struct super_block *sb); diff --git a/fs/ioctl.c b/fs/ioctl.c index 8f22f7817edb..7c9a5df5a597 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -467,7 +467,7 @@ EXPORT_SYMBOL(generic_block_fiemap); * Only the l_start, l_len and l_whence fields of the 'struct space_resv' * are used here, rest are ignored. */ -int ioctl_preallocate(struct file *filp, int mode, void __user *argp) +static int ioctl_preallocate(struct file *filp, int mode, void __user *argp) { struct inode *inode = file_inode(filp); struct space_resv sr; @@ -495,8 +495,8 @@ int ioctl_preallocate(struct file *filp, int mode, void __user *argp) /* on ia32 l_start is on a 32-bit boundary */ #if defined CONFIG_COMPAT && defined(CONFIG_X86_64) /* just account for different alignment */ -int compat_ioctl_preallocate(struct file *file, int mode, - struct space_resv_32 __user *argp) +static int compat_ioctl_preallocate(struct file *file, int mode, + struct space_resv_32 __user *argp) { struct inode *inode = file_inode(file); struct space_resv_32 sr; @@ -521,11 +521,9 @@ int compat_ioctl_preallocate(struct file *file, int mode, } #endif -static int file_ioctl(struct file *filp, unsigned int cmd, - unsigned long arg) +static int file_ioctl(struct file *filp, unsigned int cmd, int __user *p) { struct inode *inode = file_inode(filp); - int __user *p = (int __user *)arg; switch (cmd) { case FIBMAP: @@ -542,7 +540,7 @@ static int file_ioctl(struct file *filp, unsigned int cmd, return ioctl_preallocate(filp, FALLOC_FL_ZERO_RANGE, p); } - return vfs_ioctl(filp, cmd, arg); + return -ENOIOCTLCMD; } static int ioctl_fionbio(struct file *filp, int __user *argp) @@ -661,53 +659,48 @@ static int ioctl_file_dedupe_range(struct file *file, } /* - * When you add any new common ioctls to the switches above and below - * please update compat_sys_ioctl() too. - * * do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d. * It's just a simple helper for sys_ioctl and compat_sys_ioctl. + * + * When you add any new common ioctls to the switches above and below, + * please ensure they have compatible arguments in compat mode. */ -int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, - unsigned long arg) +static int do_vfs_ioctl(struct file *filp, unsigned int fd, + unsigned int cmd, unsigned long arg) { - int error = 0; void __user *argp = (void __user *)arg; struct inode *inode = file_inode(filp); switch (cmd) { case FIOCLEX: set_close_on_exec(fd, 1); - break; + return 0; case FIONCLEX: set_close_on_exec(fd, 0); - break; + return 0; case FIONBIO: - error = ioctl_fionbio(filp, argp); - break; + return ioctl_fionbio(filp, argp); case FIOASYNC: - error = ioctl_fioasync(fd, filp, argp); - break; + return ioctl_fioasync(fd, filp, argp); case FIOQSIZE: if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) { loff_t res = inode_get_bytes(inode); - error = copy_to_user(argp, &res, sizeof(res)) ? - -EFAULT : 0; - } else - error = -ENOTTY; - break; + return copy_to_user(argp, &res, sizeof(res)) ? + -EFAULT : 0; + } + + return -ENOTTY; case FIFREEZE: - error = ioctl_fsfreeze(filp); - break; + return ioctl_fsfreeze(filp); case FITHAW: - error = ioctl_fsthaw(filp); - break; + return ioctl_fsthaw(filp); case FS_IOC_FIEMAP: return ioctl_fiemap(filp, argp); @@ -716,6 +709,7 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, /* anon_bdev filesystems may not have a block size */ if (!inode->i_sb->s_blocksize) return -EINVAL; + return put_user(inode->i_sb->s_blocksize, (int __user *)argp); case FICLONE: @@ -729,24 +723,30 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, default: if (S_ISREG(inode->i_mode)) - error = file_ioctl(filp, cmd, arg); - else - error = vfs_ioctl(filp, cmd, arg); + return file_ioctl(filp, cmd, argp); break; } - return error; + + return -ENOIOCTLCMD; } int ksys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { - int error; struct fd f = fdget(fd); + int error; if (!f.file) return -EBADF; + error = security_file_ioctl(f.file, cmd, arg); - if (!error) - error = do_vfs_ioctl(f.file, fd, cmd, arg); + if (error) + goto out; + + error = do_vfs_ioctl(f.file, fd, cmd, arg); + if (error == -ENOIOCTLCMD) + error = vfs_ioctl(f.file, cmd, arg); + +out: fdput(f); return error; } @@ -790,92 +790,63 @@ long compat_ptr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) EXPORT_SYMBOL(compat_ptr_ioctl); COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, - compat_ulong_t, arg32) + compat_ulong_t, arg) { - unsigned long arg = arg32; struct fd f = fdget(fd); - int error = -EBADF; + int error; + if (!f.file) - goto out; + return -EBADF; /* RED-PEN how should LSM module know it's handling 32bit? */ error = security_file_ioctl(f.file, cmd, arg); if (error) - goto out_fput; + goto out; switch (cmd) { - /* these are never seen by ->ioctl(), no argument or int argument */ - case FIOCLEX: - case FIONCLEX: - case FIFREEZE: - case FITHAW: + /* FICLONE takes an int argument, so don't use compat_ptr() */ case FICLONE: - goto do_ioctl; - /* these are never seen by ->ioctl(), pointer argument */ - case FIONBIO: - case FIOASYNC: - case FIOQSIZE: - case FS_IOC_FIEMAP: - case FIGETBSZ: - case FICLONERANGE: - case FIDEDUPERANGE: - goto found_handler; - /* - * The next group is the stuff handled inside file_ioctl(). - * For regular files these never reach ->ioctl(); for - * devices, sockets, etc. they do and one (FIONREAD) is - * even accepted in some cases. In all those cases - * argument has the same type, so we can handle these - * here, shunting them towards do_vfs_ioctl(). - * ->compat_ioctl() will never see any of those. - */ - /* pointer argument, never actually handled by ->ioctl() */ - case FIBMAP: - goto found_handler; - /* handled by some ->ioctl(); always a pointer to int */ - case FIONREAD: - goto found_handler; - /* these get messy on amd64 due to alignment differences */ + error = ioctl_file_clone(f.file, arg, 0, 0, 0); + break; + #if defined(CONFIG_X86_64) + /* these get messy on amd64 due to alignment differences */ case FS_IOC_RESVSP_32: case FS_IOC_RESVSP64_32: error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg)); - goto out_fput; + break; case FS_IOC_UNRESVSP_32: case FS_IOC_UNRESVSP64_32: error = compat_ioctl_preallocate(f.file, FALLOC_FL_PUNCH_HOLE, compat_ptr(arg)); - goto out_fput; + break; case FS_IOC_ZERO_RANGE_32: error = compat_ioctl_preallocate(f.file, FALLOC_FL_ZERO_RANGE, compat_ptr(arg)); - goto out_fput; -#else - case FS_IOC_RESVSP: - case FS_IOC_RESVSP64: - case FS_IOC_UNRESVSP: - case FS_IOC_UNRESVSP64: - case FS_IOC_ZERO_RANGE: - goto found_handler; + break; #endif + /* + * everything else in do_vfs_ioctl() takes either a compatible + * pointer argument or no argument -- call it with a modified + * argument. + */ default: - if (f.file->f_op->compat_ioctl) { + error = do_vfs_ioctl(f.file, fd, cmd, + (unsigned long)compat_ptr(arg)); + if (error != -ENOIOCTLCMD) + break; + + if (f.file->f_op->compat_ioctl) error = f.file->f_op->compat_ioctl(f.file, cmd, arg); - if (error != -ENOIOCTLCMD) - goto out_fput; - } - error = -ENOTTY; - goto out_fput; + if (error == -ENOIOCTLCMD) + error = -ENOTTY; + break; } - found_handler: - arg = (unsigned long)compat_ptr(arg); - do_ioctl: - error = do_vfs_ioctl(f.file, fd, cmd, arg); - out_fput: - fdput(f); out: + fdput(f); + return error; } #endif diff --git a/include/linux/falloc.h b/include/linux/falloc.h index 8bf3d79f3e82..f3f0b97b1675 100644 --- a/include/linux/falloc.h +++ b/include/linux/falloc.h @@ -51,8 +51,6 @@ struct space_resv_32 { #define FS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct space_resv_32) #define FS_IOC_ZERO_RANGE_32 _IOW ('X', 57, struct space_resv_32) -int compat_ioctl_preallocate(struct file *, int, struct space_resv_32 __user *); - #endif #endif /* _FALLOC_H_ */ diff --git a/include/linux/fs.h b/include/linux/fs.h index 98e0349adb52..daf570bca42a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2552,10 +2552,6 @@ extern int finish_open(struct file *file, struct dentry *dentry, int (*open)(struct inode *, struct file *)); extern int finish_no_open(struct file *file, struct dentry *dentry); -/* fs/ioctl.c */ - -extern int ioctl_preallocate(struct file *filp, int mode, void __user *argp); - /* fs/dcache.c */ extern void __init vfs_caches_init_early(void); extern void __init vfs_caches_init(void); From patchwork Tue Dec 17 22:17:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298915 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 DFC4514F6 for ; Tue, 17 Dec 2019 22:19:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6E2921775 for ; Tue, 17 Dec 2019 22:19:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727185AbfLQWTS (ORCPT ); Tue, 17 Dec 2019 17:19:18 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:46933 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727165AbfLQWTO (ORCPT ); Tue, 17 Dec 2019 17:19:14 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MKKhF-1iOrCN359b-00Looj; Tue, 17 Dec 2019 23:17:32 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 21/27] compat_ioctl: move cdrom commands into cdrom.c Date: Tue, 17 Dec 2019 23:17:02 +0100 Message-Id: <20191217221708.3730997-22-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xQtqzDF0k6u89EQieIQzUB9hiVcXtS5mjt2hY+zFGQb8APrgaxJ mBUBNv6HQTyWI67r5klVxNs8hbG34FMJ6V4H1OIknx+iXFwtjM25VsaYwp88i2z0nwoWi1I TnTgZeCsnC1aCMB9hk8IaX2/KgLUhBCJxsDWxtft0DzXyc+PzBt+rt/ZuyVMomqnjviYnh3 YoVR+mpglYKYjo8U/jGGw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:TNPJQbvKd+U=:MpWDPVhy5y+i9LqCtJmTmu 6rkUBZ4gXyXzKxtB/tFOl7A5y+hEU4TED8JWQgJ2isNp9eMh71mKG0ZTXIyBVqnnXnMz6ZzIk cwvQVxdoM+OkoUPEH1AYuTpfGTDFlhX2aT8My3SbrLvONUjOt1Hi+uGLtQLiEWiNwwzBA6y5Y OLncZQuRAq4yIMRZwN4zswmQICGt5DTcjgOVX2OJ0/K7oBUaMb2Y+5HmGwa9AfZ3dum3zZiKW 3MaW8IaqB5h2v6ACeBBi/0QlBlk6qGM0Z2Vg6BrD70OhREPIuMlRysYUqSNl95+7DG1t5u07q VW0nT2wuOQOG7RKpg2DPN21t+mxmPuLYr7s2N5UKormAGysU37nm2O0cy3fFk+MtxdRRmy5hv haQ8FdrRKHA9ki+wiEo9W+axXfVz+bXL9Jy/casciu5wxQ7BpJ+SSwXul3TO3V1GiKV5lmq+6 xtGhudSAjpl3JVNugwDKiMJ49ijrh7OPKH8VWZg+qGoDsgAbzlGz7IjBRi/CO5mjKcFnK1LM6 /XS+6SYCp8MXbznn5MWAXS/5jtS4I9Tx5P/s9iv3UvGtwtS1iHQWBeVaIANpFvAT88NhXM+Yy EzBJWS3cGVKhUfx12Lcn4EmBc+xHaAPxbnHEM/RatnKc5dl86+m/bNfr9hkerJCTuNhoiHqeh laVSWhnadCyCeXocU6Lice+7EZ7oTmJaCG71UKBydjRa3XbXT2sQUXnNE5OH79/SQlPyJFZYd 1F7Y8cf2R3Jhx0GLvVBIsTPJhewRJxdITcP7GijENBG6TY3lfjWdVNgrCqIomX9LjVyS9ki2v M2jchqHAy81dGqM3yECcIr+jfNeu98PEf1uSEeZGzI+CcHemHpYaJ/sGQyc4m1HMNwSTQ8cfR lXW2ZFqZ+z3qFEY+ixDg== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org There is no need for the special cases for the cdrom ioctls any more now, so make sure that each cdrom driver has a .compat_ioctl() callback and calls cdrom_compat_ioctl() directly there. Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 45 -------------------------------------- drivers/block/paride/pcd.c | 3 +++ drivers/cdrom/gdrom.c | 3 +++ drivers/ide/ide-cd.c | 36 ++++++++++++++++++++++++++++++ drivers/scsi/sr.c | 10 +++------ 5 files changed, 45 insertions(+), 52 deletions(-) diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index cf136bc2c9fc..7cb534d6e767 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -159,42 +159,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, case HDIO_DRIVE_CMD: /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */ case 0x330: - /* CDROM stuff */ - case CDROMPAUSE: - case CDROMRESUME: - case CDROMPLAYMSF: - case CDROMPLAYTRKIND: - case CDROMREADTOCHDR: - case CDROMREADTOCENTRY: - case CDROMSTOP: - case CDROMSTART: - case CDROMEJECT: - case CDROMVOLCTRL: - case CDROMSUBCHNL: - case CDROMMULTISESSION: - case CDROM_GET_MCN: - case CDROMRESET: - case CDROMVOLREAD: - case CDROMSEEK: - case CDROMPLAYBLK: - case CDROMCLOSETRAY: - case CDROM_DISC_STATUS: - case CDROM_CHANGER_NSLOTS: - case CDROM_GET_CAPABILITY: - case CDROM_SEND_PACKET: - /* Ignore cdrom.h about these next 5 ioctls, they absolutely do - * not take a struct cdrom_read, instead they take a struct cdrom_msf - * which is compatible. - */ - case CDROMREADMODE2: - case CDROMREADMODE1: - case CDROMREADRAW: - case CDROMREADCOOKED: - case CDROMREADALL: - /* DVD ioctls */ - case DVD_READ_STRUCT: - case DVD_WRITE_STRUCT: - case DVD_AUTH: arg = (unsigned long)compat_ptr(arg); /* These intepret arg as an unsigned long, not as a pointer, * so we must not do compat_ptr() conversion. */ @@ -210,15 +174,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, case HDIO_SET_ACOUSTIC: case HDIO_SET_BUSSTATE: case HDIO_SET_ADDRESS: - case CDROMEJECT_SW: - case CDROM_SET_OPTIONS: - case CDROM_CLEAR_OPTIONS: - case CDROM_SELECT_SPEED: - case CDROM_SELECT_DISC: - case CDROM_MEDIA_CHANGED: - case CDROM_DRIVE_STATUS: - case CDROM_LOCKDOOR: - case CDROM_DEBUG: break; default: /* unknown ioctl number */ diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c index 636bfea2de6f..117cfc8cd05a 100644 --- a/drivers/block/paride/pcd.c +++ b/drivers/block/paride/pcd.c @@ -275,6 +275,9 @@ static const struct block_device_operations pcd_bdops = { .open = pcd_block_open, .release = pcd_block_release, .ioctl = pcd_block_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = blkdev_compat_ptr_ioctl, +#endif .check_events = pcd_block_check_events, }; diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c index 5b21dc421c94..886b2638c730 100644 --- a/drivers/cdrom/gdrom.c +++ b/drivers/cdrom/gdrom.c @@ -518,6 +518,9 @@ static const struct block_device_operations gdrom_bdops = { .release = gdrom_bdops_release, .check_events = gdrom_bdops_check_events, .ioctl = gdrom_bdops_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = blkdev_compat_ptr_ioctl, +#endif }; static irqreturn_t gdrom_command_interrupt(int irq, void *dev_id) diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index 9d117936bee1..2de6e8ace957 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c @@ -25,6 +25,7 @@ #define IDECD_VERSION "5.00" +#include #include #include #include @@ -1710,6 +1711,38 @@ static int idecd_ioctl(struct block_device *bdev, fmode_t mode, return ret; } +#ifdef CONFIG_COMPAT +static int idecd_locked_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info); + int err; + + switch (cmd) { + case CDROMSETSPINDOWN: + return idecd_set_spindown(&info->devinfo, arg); + case CDROMGETSPINDOWN: + return idecd_get_spindown(&info->devinfo, arg); + default: + break; + } + + return cdrom_ioctl(&info->devinfo, bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); +} + +static int idecd_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + int ret; + + mutex_lock(&ide_cd_mutex); + ret = idecd_locked_compat_ioctl(bdev, mode, cmd, arg); + mutex_unlock(&ide_cd_mutex); + + return ret; +} +#endif static unsigned int idecd_check_events(struct gendisk *disk, unsigned int clearing) @@ -1732,6 +1765,9 @@ static const struct block_device_operations idecd_ops = { .open = idecd_open, .release = idecd_release, .ioctl = idecd_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = idecd_compat_ioctl, +#endif .check_events = idecd_check_events, .revalidate_disk = idecd_revalidate_disk }; diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 6033a886c42c..0fbb8fe6e521 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -628,13 +628,9 @@ static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsign goto put; } - /* - * CDROM ioctls are handled in the block layer, but - * do the scsi blk ioctls here. - */ - ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); - if (ret != -ENOTTY) - return ret; + ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, (unsigned long)argp); + if (ret != -ENOSYS) + goto put; ret = scsi_compat_ioctl(sdev, cmd, argp); From patchwork Tue Dec 17 22:17:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298845 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 11F97921 for ; Tue, 17 Dec 2019 22:18:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E421920716 for ; Tue, 17 Dec 2019 22:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726853AbfLQWR7 (ORCPT ); Tue, 17 Dec 2019 17:17:59 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:49789 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbfLQWR4 (ORCPT ); Tue, 17 Dec 2019 17:17:56 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M9WmQ-1ie1lZ0nQ4-005V7i; Tue, 17 Dec 2019 23:17:33 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 22/27] compat_ioctl: scsi: handle HDIO commands from drivers Date: Tue, 17 Dec 2019 23:17:03 +0100 Message-Id: <20191217221708.3730997-23-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pSOIrqA4qJmN8oxuhXgjjmKQ4BKDNp8za+fcHrSHtYc7EmHxMCJ ttBmqAyhcKzs6ALP6XaKjK1eJRepY36qUdiG1Ymlv2tcIEYRshLq2jDytMfphz3+jMw7eED id44i00bAoVEZGiADfmkRWGK5ysYfQDl/ODvN/WylYpI/Cktg36r4HXzmChOoQKwPNw7hC/ O3MQzKNY2II5A2Xp9GQdg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Xn6+UU1gPkE=:Bv08/Fta262/hxm73yaJG7 y492BZ90Db600sYHwNqoIUQnWSm/atwksEsV1xp4NNp+CuzOfClXWkCfHdzavBqpGJCXYsADl vsmudpY7oDIEyFAjmwugJe7iYi4PjkrHdo5qZkpsN8w1DKViflSW2rPR2e5voJyJ9rox3y7iN plV4XfZj1mR3aln6NxFOC1UypUU90Ai+Cb6ebfnlEtP2XU6jXiXSJURAAK2v1MIUWklgOS+93 zfO79A0IX1aK6C0kywszdTyW8pWLpkHrMHazzve/V23DJfGKpYm/he8UEA0WHkmJYk8GuYHt4 kQxgpRdDZ7qUhlolIqv4eHS0sJ6gCxZb+xys2yDg3btFd+ZCKP2KXfpl1CPzp7MDxtQg0UQjo lKszOsvC3Q3ebmbqqaGdKnNmL+twKhlgxfXxc/kfcwIJ3xdo2j81H5rL0+fySEJrkup0JhbBc V9sX9uZEwtJxBF0KiPsIEmU7b2TJya1sdrM3dhSEriIPs0ATUHlFQerrOAYD8MoEbfcoMlcgz CeS7mhMKIjLCtQiyeOl4ZHCycZ5y4wVJJD/IXMu+J8tPrVU3F+6UeGGxgjukY6zzcK/CwUy9s AuB708Q3h1gujO3R0e0382zazvQo+ZbVSzds+5y6Mp5DgXoXRnjaSHH2w0sT6RP5iZMYOwlNe VS9VHsWdnczFV8kUE5ATZeyFAVeYgyjqQ5ptFuFU00D7Y1Tt7pyJE2f+3FEX26n40HkD/eivx xV4aJqVGW+KCy4QWKcu49XXy8bUUPvMiBKyWbdVFQCO3a9iGlYg9bSJaA7BeGjPCfdHTW7fgl CpIl21r4ov345QUtxFOnW8wJaGmk2O1kY3SohSN4rBQibpmDdrMyaZUAn81EfAk6wWFFR3TrJ SXCRbLBNlUDixrQa7A5Q== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The ata_sas_scsi_ioctl() function implements a number of HDIO_* commands for SCSI devices, it is used by all libata drivers as well as a few drivers that support SAS attached SATA drives. The only command that is not safe for compat ioctls here is HDIO_GET_32BIT. Change the implementation to check for in_compat_syscall() in order to do both cases correctly, and change all callers to use it as both native and compat callback pointers, including the indirect callers through sas_ioctl and ata_scsi_ioctl. Signed-off-by: Arnd Bergmann --- drivers/ata/libata-scsi.c | 9 +++++++++ drivers/scsi/aic94xx/aic94xx_init.c | 3 +++ drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 3 +++ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 3 +++ drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 +++ drivers/scsi/ipr.c | 3 +++ drivers/scsi/isci/init.c | 3 +++ drivers/scsi/mvsas/mv_init.c | 3 +++ drivers/scsi/pm8001/pm8001_init.c | 3 +++ include/linux/libata.h | 6 ++++++ 10 files changed, 39 insertions(+) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 58e09ffe8b9c..eb2eb599e602 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -17,6 +17,7 @@ * - http://www.t13.org/ */ +#include #include #include #include @@ -761,6 +762,10 @@ static int ata_ioc32(struct ata_port *ap) return 0; } +/* + * This handles both native and compat commands, so anything added + * here must have a compatible argument, or check in_compat_syscall() + */ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev, unsigned int cmd, void __user *arg) { @@ -773,6 +778,10 @@ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev, spin_lock_irqsave(ap->lock, flags); val = ata_ioc32(ap); spin_unlock_irqrestore(ap->lock, flags); +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) + return put_user(val, (compat_ulong_t __user *)arg); +#endif return put_user(val, (unsigned long __user *)arg); case HDIO_SET_32BIT: diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c index f5781e31f57c..d022407e5645 100644 --- a/drivers/scsi/aic94xx/aic94xx_init.c +++ b/drivers/scsi/aic94xx/aic94xx_init.c @@ -54,6 +54,9 @@ static struct scsi_host_template aic94xx_sht = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .track_queue_depth = 1, }; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c index 3af53cc42bd6..fa25766502a2 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c @@ -1772,6 +1772,9 @@ static struct scsi_host_template sht_v1_hw = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = host_attrs_v1_hw, .host_reset = hisi_sas_host_reset, }; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index 61b1e2693b08..545eaff5f3ee 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -3551,6 +3551,9 @@ static struct scsi_host_template sht_v2_hw = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = host_attrs_v2_hw, .host_reset = hisi_sas_host_reset, }; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index bf5d5f138437..fa05e612d85a 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -3075,6 +3075,9 @@ static struct scsi_host_template sht_v3_hw = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = host_attrs_v3_hw, .tag_alloc_policy = BLK_TAG_ALLOC_RR, .host_reset = hisi_sas_host_reset, diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c index 079c04bc448a..ae45cbe98ae2 100644 --- a/drivers/scsi/ipr.c +++ b/drivers/scsi/ipr.c @@ -6727,6 +6727,9 @@ static struct scsi_host_template driver_template = { .name = "IPR", .info = ipr_ioa_info, .ioctl = ipr_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = ipr_ioctl, +#endif .queuecommand = ipr_queuecommand, .eh_abort_handler = ipr_eh_abort, .eh_device_reset_handler = ipr_eh_dev_reset, diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c index 1727d0c71b12..b48aac8dfcb8 100644 --- a/drivers/scsi/isci/init.c +++ b/drivers/scsi/isci/init.c @@ -168,6 +168,9 @@ static struct scsi_host_template isci_sht = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = isci_host_attrs, .track_queue_depth = 1, }; diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c index da719b0694dc..7af9173c4925 100644 --- a/drivers/scsi/mvsas/mv_init.c +++ b/drivers/scsi/mvsas/mv_init.c @@ -47,6 +47,9 @@ static struct scsi_host_template mvs_sht = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = mvst_host_attrs, .track_queue_depth = 1, }; diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c index ff618ad80ebd..3c6076e4c6d2 100644 --- a/drivers/scsi/pm8001/pm8001_init.c +++ b/drivers/scsi/pm8001/pm8001_init.c @@ -101,6 +101,9 @@ static struct scsi_host_template pm8001_sht = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = pm8001_host_attrs, .track_queue_depth = 1, }; diff --git a/include/linux/libata.h b/include/linux/libata.h index d3bbfddf616a..e68d05febe5a 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1109,6 +1109,11 @@ extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_op extern int ata_scsi_detect(struct scsi_host_template *sht); extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd, void __user *arg); +#ifdef CONFIG_COMPAT +#define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl, +#else +#define ATA_SCSI_COMPAT_IOCTL /* empty */ +#endif extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd); extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev, unsigned int cmd, void __user *arg); @@ -1340,6 +1345,7 @@ extern struct device_attribute *ata_common_sdev_attrs[]; .module = THIS_MODULE, \ .name = drv_name, \ .ioctl = ata_scsi_ioctl, \ + ATA_SCSI_COMPAT_IOCTL \ .queuecommand = ata_scsi_queuecmd, \ .can_queue = ATA_DEF_QUEUE, \ .tag_alloc_policy = BLK_TAG_ALLOC_RR, \ From patchwork Tue Dec 17 22:17:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298835 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 C3C4E14B7 for ; Tue, 17 Dec 2019 22:18:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97F3521D7D for ; Tue, 17 Dec 2019 22:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726907AbfLQWSH (ORCPT ); Tue, 17 Dec 2019 17:18:07 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:57385 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbfLQWSG (ORCPT ); Tue, 17 Dec 2019 17:18:06 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N6KQZ-1haxi02lkf-016j9T; Tue, 17 Dec 2019 23:17:33 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 23/27] compat_ioctl: move HDIO ioctl handling into drivers/ide Date: Tue, 17 Dec 2019 23:17:04 +0100 Message-Id: <20191217221708.3730997-24-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:/D1NP1hHpImcePmuJVorHaYd+oDnC0KYUns7AoRctoy/PRF56ag 9CgmMYuITFsdIlxRzHhQw8J1VfVcH6qQTsSkVNSAlsbyOfutTv/edqbEYMOgCnp0U2Iivk5 RQMhbBYtKLGmtbrm/n2NmsF6GdzfsRJe2Abcs0dmzn44BXZxnoMvi/3wH+hJDPM0jt6Kk2B Yc0JDsAWtxde8ZW02TWyA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:mSJF4exvfz4=:IusaUtG2jlMz6UDm/jSETr jkTYpg/QbJX4045dxbyAekcKRxji0NTwSyXV3k2jEd0N+iLvSLGbydTPfU7n+6APT7yGbwL+q Z+NMWhyp6cVzcv774FSjhYztehuFbu8mXbf8+URht4tTFtQk12D/SDb5Ysqrgbn8IUqnyoamL VpEVog+mtaT5tEr4k+AVwVjdc4d66QNblgdEGqsVqi8yMMYOoEbt+S0fOda3/ivT+M7vdlggI CWgbM40EGeunX6VOZ9MRReJBIU4asG98vjlgzegPQ1BjfrJFlBk8GNBbTU0Rwx+v5tzJriAcD 5UAykD51fauLiZMHIVibtrY+iifPIPSXK+KnaaeIzJc8m8QjMQd4h58IlX5YPWfrPHolJpnNa kTuOfF9PP8tUD4WkWP443G/EZGrcm/aTUd3471GLc6lJgSSKgjs4ATaDCmM4hrZbhxUz0J/VV oUz2DX0hXb2OfBCoy1aeFyxZx9QoYNnTMDStrQFS+rv7O0PQtwwOv8HdfbknFF3kxXR7rOAAw uTnd8+r/g0BfajCRelRjhBr503Xmwwo+ksDxn3aIkRVjhlFPsTxSutl3fVFLVGcVWLHtJEVLE dBH39ye5Ku2ygusz1U4maVq1Ct6Magh1iW8FdyoinP9bAhkxmaUk4QY8T3TUO8Eh1C7YFWSmT SmGVqc+bBjukHhVQhA7ZVXM09KJ2+FlbFWGk39XISFdIrJwAUsfNwdmRXTCZmSF9hLnXBVSuW auquuH2DQWeU7A7gssPRpz78B/qUIFnGRITAIH+ghbZsGGzfzOXTw9EkbILQfQoX2o8fOuWWv SMGfy7BT4zkosYRSgm7PcmVcixITBdfq2o09So9KrVKf+uqYOOcTech+yDS7wCtYc7bu3Gt46 OIAarc6M/aawxtr2aWJw== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Most of the HDIO ioctls are only used by the obsolete drivers/ide subsystem, these can be handled by changing ide_cmd_ioctl() to be aware of compat mode and doing the correct transformations in place and using it as both native and compat handlers for all drivers. The SCSI drivers implementing the same commands are already doing this in the drivers, so the compat_blkdev_driver_ioctl() function is no longer needed now. The BLKSECTSET and HDIO_GETGEO_BIG ioctls are not implemented in any driver any more and no longer need any conversion. Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 75 ---------------------------------- drivers/ide/ide-cd.c | 15 +++---- drivers/ide/ide-disk.c | 1 + drivers/ide/ide-floppy_ioctl.c | 7 ++-- drivers/ide/ide-ioctls.c | 44 ++++++++++++-------- drivers/ide/ide-tape.c | 11 +++++ 6 files changed, 51 insertions(+), 102 deletions(-) diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 7cb534d6e767..765aa5357655 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -77,24 +77,6 @@ static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, return ret; } -static int compat_hdio_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) -{ - unsigned long __user *p; - int error; - - p = compat_alloc_user_space(sizeof(unsigned long)); - error = __blkdev_driver_ioctl(bdev, mode, - cmd, (unsigned long)p); - if (error == 0) { - unsigned int __user *uvp = compat_ptr(arg); - unsigned long v; - if (get_user(v, p) || put_user(v, uvp)) - error = -EFAULT; - } - return error; -} - struct compat_blkpg_ioctl_arg { compat_int_t op; compat_int_t flags; @@ -128,61 +110,6 @@ static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, #define BLKBSZSET_32 _IOW(0x12, 113, int) #define BLKGETSIZE64_32 _IOR(0x12, 114, int) -static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, - unsigned cmd, unsigned long arg) -{ - switch (cmd) { - case HDIO_GET_UNMASKINTR: - case HDIO_GET_MULTCOUNT: - case HDIO_GET_KEEPSETTINGS: - case HDIO_GET_32BIT: - case HDIO_GET_NOWERR: - case HDIO_GET_DMA: - case HDIO_GET_NICE: - case HDIO_GET_WCACHE: - case HDIO_GET_ACOUSTIC: - case HDIO_GET_ADDRESS: - case HDIO_GET_BUSSTATE: - return compat_hdio_ioctl(bdev, mode, cmd, arg); - - /* - * No handler required for the ones below, we just need to - * convert arg to a 64 bit pointer. - */ - case BLKSECTSET: - /* - * 0x03 -- HD/IDE ioctl's used by hdparm and friends. - * Some need translations, these do not. - */ - case HDIO_GET_IDENTITY: - case HDIO_DRIVE_TASK: - case HDIO_DRIVE_CMD: - /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */ - case 0x330: - arg = (unsigned long)compat_ptr(arg); - /* These intepret arg as an unsigned long, not as a pointer, - * so we must not do compat_ptr() conversion. */ - case HDIO_SET_MULTCOUNT: - case HDIO_SET_UNMASKINTR: - case HDIO_SET_KEEPSETTINGS: - case HDIO_SET_32BIT: - case HDIO_SET_NOWERR: - case HDIO_SET_DMA: - case HDIO_SET_PIO_MODE: - case HDIO_SET_NICE: - case HDIO_SET_WCACHE: - case HDIO_SET_ACOUSTIC: - case HDIO_SET_BUSSTATE: - case HDIO_SET_ADDRESS: - break; - default: - /* unknown ioctl number */ - return -ENOIOCTLCMD; - } - - return __blkdev_driver_ioctl(bdev, mode, cmd, arg); -} - /* Most of the generic ioctls are handled in the normal fallback path. This assumes the blkdev's low level compat_ioctl always returns ENOIOCTLCMD for unknown ioctls. */ @@ -293,8 +220,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) default: if (disk->fops->compat_ioctl) ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); - if (ret == -ENOIOCTLCMD) - ret = compat_blkdev_driver_ioctl(bdev, mode, cmd, arg); return ret; } } diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index 2de6e8ace957..284a7a5bad54 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c @@ -1711,7 +1711,6 @@ static int idecd_ioctl(struct block_device *bdev, fmode_t mode, return ret; } -#ifdef CONFIG_COMPAT static int idecd_locked_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { @@ -1727,8 +1726,12 @@ static int idecd_locked_compat_ioctl(struct block_device *bdev, fmode_t mode, break; } - return cdrom_ioctl(&info->devinfo, bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); + err = generic_ide_ioctl(info->drive, bdev, cmd, arg); + if (err == -EINVAL) + err = cdrom_ioctl(&info->devinfo, bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); + + return err; } static int idecd_compat_ioctl(struct block_device *bdev, fmode_t mode, @@ -1742,7 +1745,6 @@ static int idecd_compat_ioctl(struct block_device *bdev, fmode_t mode, return ret; } -#endif static unsigned int idecd_check_events(struct gendisk *disk, unsigned int clearing) @@ -1765,9 +1767,8 @@ static const struct block_device_operations idecd_ops = { .open = idecd_open, .release = idecd_release, .ioctl = idecd_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = idecd_compat_ioctl, -#endif + .compat_ioctl = IS_ENABLED(CONFIG_COMPAT) ? + idecd_compat_ioctl : NULL, .check_events = idecd_check_events, .revalidate_disk = idecd_revalidate_disk }; diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c index 197912af5c2f..1d3407d7e095 100644 --- a/drivers/ide/ide-disk.c +++ b/drivers/ide/ide-disk.c @@ -794,4 +794,5 @@ const struct ide_disk_ops ide_ata_disk_ops = { .set_doorlock = ide_disk_set_doorlock, .do_request = ide_do_rw_disk, .ioctl = ide_disk_ioctl, + .compat_ioctl = ide_disk_ioctl, }; diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c index 4fd70f804d6f..39a790ac6cc3 100644 --- a/drivers/ide/ide-floppy_ioctl.c +++ b/drivers/ide/ide-floppy_ioctl.c @@ -329,10 +329,9 @@ int ide_floppy_compat_ioctl(ide_drive_t *drive, struct block_device *bdev, if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); - /* - * there is no generic_ide_compat_ioctl(), that is handled - * through compat_blkdev_ioctl(). - */ + if (err == -ENOTTY) + err = generic_ide_ioctl(drive, bdev, cmd, arg); + out: mutex_unlock(&ide_floppy_ioctl_mutex); return err; diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c index d48c17003874..f6497c817493 100644 --- a/drivers/ide/ide-ioctls.c +++ b/drivers/ide/ide-ioctls.c @@ -3,11 +3,20 @@ * IDE ioctls handling. */ +#include #include #include #include #include +static int put_user_long(long val, unsigned long arg) +{ + if (in_compat_syscall()) + return put_user(val, (compat_long_t __user *)compat_ptr(arg)); + + return put_user(val, (long __user *)arg); +} + static const struct ide_ioctl_devset ide_ioctl_settings[] = { { HDIO_GET_32BIT, HDIO_SET_32BIT, &ide_devset_io_32bit }, { HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, &ide_devset_keepsettings }, @@ -37,7 +46,7 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev, mutex_lock(&ide_setting_mtx); err = ds->get(drive); mutex_unlock(&ide_setting_mtx); - return err >= 0 ? put_user(err, (long __user *)arg) : err; + return err >= 0 ? put_user_long(err, arg) : err; set_val: if (bdev != bdev->bd_contains) @@ -56,7 +65,7 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev, EXPORT_SYMBOL_GPL(ide_setting_ioctl); static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd, - unsigned long arg) + void __user *argp) { u16 *id = NULL; int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142; @@ -77,7 +86,7 @@ static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd, memcpy(id, drive->id, size); ata_id_to_hd_driveid(id); - if (copy_to_user((void __user *)arg, id, size)) + if (copy_to_user(argp, id, size)) rc = -EFAULT; kfree(id); @@ -87,10 +96,10 @@ static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd, static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg) { - return put_user((!!(drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) + return put_user_long((!!(drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) << IDE_NICE_DSC_OVERLAP) | (!!(drive->dev_flags & IDE_DFLAG_NICE1) - << IDE_NICE_1), (long __user *)arg); + << IDE_NICE_1), arg); } static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg) @@ -115,7 +124,7 @@ static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg) return 0; } -static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) +static int ide_cmd_ioctl(ide_drive_t *drive, void __user *argp) { u8 *buf = NULL; int bufsize = 0, err = 0; @@ -123,7 +132,7 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) struct ide_cmd cmd; struct ide_taskfile *tf = &cmd.tf; - if (NULL == (void *) arg) { + if (NULL == argp) { struct request *rq; rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0); @@ -135,7 +144,7 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) return err; } - if (copy_from_user(args, (void __user *)arg, 4)) + if (copy_from_user(args, argp, 4)) return -EFAULT; memset(&cmd, 0, sizeof(cmd)); @@ -181,19 +190,18 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) args[1] = tf->error; args[2] = tf->nsect; abort: - if (copy_to_user((void __user *)arg, &args, 4)) + if (copy_to_user(argp, &args, 4)) err = -EFAULT; if (buf) { - if (copy_to_user((void __user *)(arg + 4), buf, bufsize)) + if (copy_to_user((argp + 4), buf, bufsize)) err = -EFAULT; kfree(buf); } return err; } -static int ide_task_ioctl(ide_drive_t *drive, unsigned long arg) +static int ide_task_ioctl(ide_drive_t *drive, void __user *p) { - void __user *p = (void __user *)arg; int err = 0; u8 args[7]; struct ide_cmd cmd; @@ -237,6 +245,10 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, unsigned int cmd, unsigned long arg) { int err; + void __user *argp = (void __user *)arg; + + if (in_compat_syscall()) + argp = compat_ptr(arg); err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_ioctl_settings); if (err != -EOPNOTSUPP) @@ -247,7 +259,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, case HDIO_GET_IDENTITY: if (bdev != bdev->bd_contains) return -EINVAL; - return ide_get_identity_ioctl(drive, cmd, arg); + return ide_get_identity_ioctl(drive, cmd, argp); case HDIO_GET_NICE: return ide_get_nice_ioctl(drive, arg); case HDIO_SET_NICE: @@ -265,11 +277,11 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, case HDIO_DRIVE_CMD: if (!capable(CAP_SYS_RAWIO)) return -EACCES; - return ide_cmd_ioctl(drive, arg); + return ide_cmd_ioctl(drive, argp); case HDIO_DRIVE_TASK: if (!capable(CAP_SYS_RAWIO)) return -EACCES; - return ide_task_ioctl(drive, arg); + return ide_task_ioctl(drive, argp); case HDIO_DRIVE_RESET: if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -277,7 +289,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, case HDIO_GET_BUSSTATE: if (!capable(CAP_SYS_ADMIN)) return -EACCES; - if (put_user(BUSSTATE_ON, (long __user *)arg)) + if (put_user_long(BUSSTATE_ON, arg)) return -EFAULT; return 0; case HDIO_SET_BUSSTATE: diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index 3e7482695f77..6f26634b22bb 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c @@ -1945,11 +1945,22 @@ static int idetape_ioctl(struct block_device *bdev, fmode_t mode, return err; } +static int idetape_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + if (cmd == 0x0340 || cmd == 0x350) + arg = (unsigned long)compat_ptr(arg); + + return idetape_ioctl(bdev, mode, cmd, arg); +} + static const struct block_device_operations idetape_block_ops = { .owner = THIS_MODULE, .open = idetape_open, .release = idetape_release, .ioctl = idetape_ioctl, + .compat_ioctl = IS_ENABLED(CONFIG_COMPAT) ? + idetape_compat_ioctl : NULL, }; static int ide_tape_probe(ide_drive_t *drive) From patchwork Tue Dec 17 22:17:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298929 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 45587921 for ; Tue, 17 Dec 2019 22:19:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D9212064B for ; Tue, 17 Dec 2019 22:19:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727276AbfLQWTd (ORCPT ); Tue, 17 Dec 2019 17:19:33 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:58457 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726808AbfLQWTd (ORCPT ); Tue, 17 Dec 2019 17:19:33 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MHX7f-1iTskR0T7B-00DVzz; Tue, 17 Dec 2019 23:17:34 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 24/27] compat_ioctl: block: move blkdev_compat_ioctl() into ioctl.c Date: Tue, 17 Dec 2019 23:17:05 +0100 Message-Id: <20191217221708.3730997-25-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:PSAD9bl0CFKl/aF5LKUPzusxXoxLYNJ5KzrK6e2MQW/9n3CWnjv YS4eBKkXR1HztidqHI91DDyXR/AQfN87JIhMu94SIu4GxAELbMeRJVmpCa6nOBSmtEasanl AZE7bG2pC1HRVU9ryXnwF5XG5ymueLsxU/kTFX+LrhBBYUcVVHLF2nZI3tqzs9q4fJz9dmN zRS+YuAuqB0r/0v+rTEpA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:gbhqN5RdKj0=:BWK8lhBEG/MD40PIuhTUnG YyDSCscLh9YKImGCbbZipadpWoCh10HeOaNyzo1PaxTLF4rN9pzZYFp2t5ntmeiTZbHfoaCe0 3cotpxM/Eb1shhdcImLbF6GRrJqKUhruGnep5BCSyf/MuVThSQ/DxzWt3EUmiC6cvZ8YBSQJy ZnHHZtrS70kowS/WIyRQCz5g5ypBBZmXHSGE+8V49MJQrGY5kbb1bqG2yXzBrLwovSWJ7M2vy dKtq4nrrHcA7Htra+aDTXJqavU1ul99amdZ81t9xuwOLlTdGKGGgoLtX7dNYOuJ7KVJ5ph2Ko IGFwCNKZH50bZi+DbHiIv6INtG3I8jNzZ0wBwBsvexAcg5kbjDi65qJuTe3dH7jK9gUrwn0cX kumKT2I94RYeeO6mhl+lBdau2ppo8YOslhuObl62S7i861y4voirlm9eDKPMAPPtdTJ7XAjdv fTdeoH+aDVL3CbwAeipSQYE3gUixsRGuKHk425h4PZaJkwF+oCitrM0pdzBl37vnOB1YuVJxc XkEk6OgqxwypuyZCSmMUr3ujKwTRYAo6MbFj7oJEwCT9nezvq+Psdjwngb2/L1/3286e3Hwol 3DBrkgZZHpDeoGEZmkr/KEUKaGF+FTytTvUB3JPeerPi5484jRWVYGD+UYWzfBKsgzZvG4IjE maAvR5WrNc2Vc49PSNk0aTOAj8D4j5F1m8cPzHI69Do/3WHA6hivRG41ihl1/YJmdDT42kkLO FEG24mrkj42RCIc0k7ZJpc6oVx06fi5a8KDd+Oorx655Y5+EeN3NGq2OX0imStKFInD0flEqo WpoBJAHn0Pu3+DST8DW+Ow28tRRW5Q/l6gfIoqa42qGwDHFyprv4yld/kyZop0h+oPHh9pO4c XaD08gxbDhYNk5xezrZg== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Having both in the same file allows a number of simplifications to the compat path, and makes it more likely that changes to the native path get applied to the compat version as well. Signed-off-by: Arnd Bergmann --- block/Makefile | 1 - block/compat_ioctl.c | 225 ------------------------------------------- block/ioctl.c | 219 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 226 deletions(-) delete mode 100644 block/compat_ioctl.c diff --git a/block/Makefile b/block/Makefile index 205a5f2fef17..1f70c73ea83d 100644 --- a/block/Makefile +++ b/block/Makefile @@ -25,7 +25,6 @@ obj-$(CONFIG_MQ_IOSCHED_KYBER) += kyber-iosched.o bfq-y := bfq-iosched.o bfq-wf2q.o bfq-cgroup.o obj-$(CONFIG_IOSCHED_BFQ) += bfq.o -obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o obj-$(CONFIG_BLK_CMDLINE_PARSER) += cmdline-parser.o obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o obj-$(CONFIG_BLK_MQ_PCI) += blk-mq-pci.o diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c deleted file mode 100644 index 765aa5357655..000000000000 --- a/block/compat_ioctl.c +++ /dev/null @@ -1,225 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int compat_put_ushort(unsigned long arg, unsigned short val) -{ - return put_user(val, (unsigned short __user *)compat_ptr(arg)); -} - -static int compat_put_int(unsigned long arg, int val) -{ - return put_user(val, (compat_int_t __user *)compat_ptr(arg)); -} - -static int compat_put_uint(unsigned long arg, unsigned int val) -{ - return put_user(val, (compat_uint_t __user *)compat_ptr(arg)); -} - -static int compat_put_long(unsigned long arg, long val) -{ - return put_user(val, (compat_long_t __user *)compat_ptr(arg)); -} - -static int compat_put_ulong(unsigned long arg, compat_ulong_t val) -{ - return put_user(val, (compat_ulong_t __user *)compat_ptr(arg)); -} - -static int compat_put_u64(unsigned long arg, u64 val) -{ - return put_user(val, (compat_u64 __user *)compat_ptr(arg)); -} - -struct compat_hd_geometry { - unsigned char heads; - unsigned char sectors; - unsigned short cylinders; - u32 start; -}; - -static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, - struct compat_hd_geometry __user *ugeo) -{ - struct hd_geometry geo; - int ret; - - if (!ugeo) - return -EINVAL; - if (!disk->fops->getgeo) - return -ENOTTY; - - memset(&geo, 0, sizeof(geo)); - /* - * We need to set the startsect first, the driver may - * want to override it. - */ - geo.start = get_start_sect(bdev); - ret = disk->fops->getgeo(bdev, &geo); - if (ret) - return ret; - - ret = copy_to_user(ugeo, &geo, 4); - ret |= put_user(geo.start, &ugeo->start); - if (ret) - ret = -EFAULT; - - return ret; -} - -struct compat_blkpg_ioctl_arg { - compat_int_t op; - compat_int_t flags; - compat_int_t datalen; - compat_caddr_t data; -}; - -static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32) -{ - struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); - compat_caddr_t udata; - compat_int_t n; - int err; - - err = get_user(n, &ua32->op); - err |= put_user(n, &a->op); - err |= get_user(n, &ua32->flags); - err |= put_user(n, &a->flags); - err |= get_user(n, &ua32->datalen); - err |= put_user(n, &a->datalen); - err |= get_user(udata, &ua32->data); - err |= put_user(compat_ptr(udata), &a->data); - if (err) - return err; - - return blkdev_ioctl(bdev, mode, cmd, (unsigned long)a); -} - -#define BLKBSZGET_32 _IOR(0x12, 112, int) -#define BLKBSZSET_32 _IOW(0x12, 113, int) -#define BLKGETSIZE64_32 _IOR(0x12, 114, int) - -/* Most of the generic ioctls are handled in the normal fallback path. - This assumes the blkdev's low level compat_ioctl always returns - ENOIOCTLCMD for unknown ioctls. */ -long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) -{ - int ret = -ENOIOCTLCMD; - struct inode *inode = file->f_mapping->host; - struct block_device *bdev = inode->i_bdev; - struct gendisk *disk = bdev->bd_disk; - fmode_t mode = file->f_mode; - loff_t size; - unsigned int max_sectors; - - /* - * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have - * to updated it before every ioctl. - */ - if (file->f_flags & O_NDELAY) - mode |= FMODE_NDELAY; - else - mode &= ~FMODE_NDELAY; - - switch (cmd) { - case HDIO_GETGEO: - return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); - case BLKPBSZGET: - return compat_put_uint(arg, bdev_physical_block_size(bdev)); - case BLKIOMIN: - return compat_put_uint(arg, bdev_io_min(bdev)); - case BLKIOOPT: - return compat_put_uint(arg, bdev_io_opt(bdev)); - case BLKALIGNOFF: - return compat_put_int(arg, bdev_alignment_offset(bdev)); - case BLKDISCARDZEROES: - return compat_put_uint(arg, 0); - case BLKFLSBUF: - case BLKROSET: - case BLKDISCARD: - case BLKSECDISCARD: - case BLKZEROOUT: - /* - * the ones below are implemented in blkdev_locked_ioctl, - * but we call blkdev_ioctl, which gets the lock for us - */ - case BLKRRPART: - case BLKREPORTZONE: - case BLKRESETZONE: - case BLKOPENZONE: - case BLKCLOSEZONE: - case BLKFINISHZONE: - case BLKGETZONESZ: - case BLKGETNRZONES: - return blkdev_ioctl(bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); - case BLKBSZSET_32: - return blkdev_ioctl(bdev, mode, BLKBSZSET, - (unsigned long)compat_ptr(arg)); - case BLKPG: - return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg)); - case BLKRAGET: - case BLKFRAGET: - if (!arg) - return -EINVAL; - return compat_put_long(arg, - (bdev->bd_bdi->ra_pages * PAGE_SIZE) / 512); - case BLKROGET: /* compatible */ - return compat_put_int(arg, bdev_read_only(bdev) != 0); - case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ - return compat_put_int(arg, block_size(bdev)); - case BLKSSZGET: /* get block device hardware sector size */ - return compat_put_int(arg, bdev_logical_block_size(bdev)); - case BLKSECTGET: - max_sectors = min_t(unsigned int, USHRT_MAX, - queue_max_sectors(bdev_get_queue(bdev))); - return compat_put_ushort(arg, max_sectors); - case BLKROTATIONAL: - return compat_put_ushort(arg, - !blk_queue_nonrot(bdev_get_queue(bdev))); - case BLKRASET: /* compatible, but no compat_ptr (!) */ - case BLKFRASET: - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; - return 0; - case BLKGETSIZE: - size = i_size_read(bdev->bd_inode); - if ((size >> 9) > ~0UL) - return -EFBIG; - return compat_put_ulong(arg, size >> 9); - - case BLKGETSIZE64_32: - return compat_put_u64(arg, i_size_read(bdev->bd_inode)); - - case BLKTRACESETUP32: - case BLKTRACESTART: /* compatible */ - case BLKTRACESTOP: /* compatible */ - case BLKTRACETEARDOWN: /* compatible */ - ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); - return ret; - case IOC_PR_REGISTER: - case IOC_PR_RESERVE: - case IOC_PR_RELEASE: - case IOC_PR_PREEMPT: - case IOC_PR_PREEMPT_ABORT: - case IOC_PR_CLEAR: - return blkdev_ioctl(bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); - default: - if (disk->fops->compat_ioctl) - ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); - return ret; - } -} diff --git a/block/ioctl.c b/block/ioctl.c index e728331d1a5b..f8c4e2649335 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -269,6 +269,38 @@ static int put_u64(unsigned long arg, u64 val) return put_user(val, (u64 __user *)arg); } +#ifdef CONFIG_COMPAT +static int compat_put_ushort(unsigned long arg, unsigned short val) +{ + return put_user(val, (unsigned short __user *)compat_ptr(arg)); +} + +static int compat_put_int(unsigned long arg, int val) +{ + return put_user(val, (compat_int_t __user *)compat_ptr(arg)); +} + +static int compat_put_uint(unsigned long arg, unsigned int val) +{ + return put_user(val, (compat_uint_t __user *)compat_ptr(arg)); +} + +static int compat_put_long(unsigned long arg, long val) +{ + return put_user(val, (compat_long_t __user *)compat_ptr(arg)); +} + +static int compat_put_ulong(unsigned long arg, compat_ulong_t val) +{ + return put_user(val, (compat_ulong_t __user *)compat_ptr(arg)); +} + +static int compat_put_u64(unsigned long arg, u64 val) +{ + return put_user(val, (compat_u64 __user *)compat_ptr(arg)); +} +#endif + int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, unsigned long arg) { @@ -476,6 +508,44 @@ static int blkdev_getgeo(struct block_device *bdev, return 0; } +#ifdef CONFIG_COMPAT +struct compat_hd_geometry { + unsigned char heads; + unsigned char sectors; + unsigned short cylinders; + u32 start; +}; + +static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, + struct compat_hd_geometry __user *ugeo) +{ + struct hd_geometry geo; + int ret; + + if (!ugeo) + return -EINVAL; + if (!disk->fops->getgeo) + return -ENOTTY; + + memset(&geo, 0, sizeof(geo)); + /* + * We need to set the startsect first, the driver may + * want to override it. + */ + geo.start = get_start_sect(bdev); + ret = disk->fops->getgeo(bdev, &geo); + if (ret) + return ret; + + ret = copy_to_user(ugeo, &geo, 4); + ret |= put_user(geo.start, &ugeo->start); + if (ret) + ret = -EFAULT; + + return ret; +} +#endif + /* set the logical block size */ static int blkdev_bszset(struct block_device *bdev, fmode_t mode, int __user *argp) @@ -604,3 +674,152 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, } } EXPORT_SYMBOL_GPL(blkdev_ioctl); + +#ifdef CONFIG_COMPAT +struct compat_blkpg_ioctl_arg { + compat_int_t op; + compat_int_t flags; + compat_int_t datalen; + compat_caddr_t data; +}; + +static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32) +{ + struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); + compat_caddr_t udata; + compat_int_t n; + int err; + + err = get_user(n, &ua32->op); + err |= put_user(n, &a->op); + err |= get_user(n, &ua32->flags); + err |= put_user(n, &a->flags); + err |= get_user(n, &ua32->datalen); + err |= put_user(n, &a->datalen); + err |= get_user(udata, &ua32->data); + err |= put_user(compat_ptr(udata), &a->data); + if (err) + return err; + + return blkdev_ioctl(bdev, mode, cmd, (unsigned long)a); +} + +#define BLKBSZGET_32 _IOR(0x12, 112, int) +#define BLKBSZSET_32 _IOW(0x12, 113, int) +#define BLKGETSIZE64_32 _IOR(0x12, 114, int) + +/* Most of the generic ioctls are handled in the normal fallback path. + This assumes the blkdev's low level compat_ioctl always returns + ENOIOCTLCMD for unknown ioctls. */ +long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) +{ + int ret = -ENOIOCTLCMD; + struct inode *inode = file->f_mapping->host; + struct block_device *bdev = inode->i_bdev; + struct gendisk *disk = bdev->bd_disk; + fmode_t mode = file->f_mode; + loff_t size; + unsigned int max_sectors; + + /* + * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have + * to updated it before every ioctl. + */ + if (file->f_flags & O_NDELAY) + mode |= FMODE_NDELAY; + else + mode &= ~FMODE_NDELAY; + + switch (cmd) { + case HDIO_GETGEO: + return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); + case BLKPBSZGET: + return compat_put_uint(arg, bdev_physical_block_size(bdev)); + case BLKIOMIN: + return compat_put_uint(arg, bdev_io_min(bdev)); + case BLKIOOPT: + return compat_put_uint(arg, bdev_io_opt(bdev)); + case BLKALIGNOFF: + return compat_put_int(arg, bdev_alignment_offset(bdev)); + case BLKDISCARDZEROES: + return compat_put_uint(arg, 0); + case BLKFLSBUF: + case BLKROSET: + case BLKDISCARD: + case BLKSECDISCARD: + case BLKZEROOUT: + /* + * the ones below are implemented in blkdev_locked_ioctl, + * but we call blkdev_ioctl, which gets the lock for us + */ + case BLKRRPART: + case BLKREPORTZONE: + case BLKRESETZONE: + case BLKOPENZONE: + case BLKCLOSEZONE: + case BLKFINISHZONE: + case BLKGETZONESZ: + case BLKGETNRZONES: + return blkdev_ioctl(bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); + case BLKBSZSET_32: + return blkdev_ioctl(bdev, mode, BLKBSZSET, + (unsigned long)compat_ptr(arg)); + case BLKPG: + return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg)); + case BLKRAGET: + case BLKFRAGET: + if (!arg) + return -EINVAL; + return compat_put_long(arg, + (bdev->bd_bdi->ra_pages * PAGE_SIZE) / 512); + case BLKROGET: /* compatible */ + return compat_put_int(arg, bdev_read_only(bdev) != 0); + case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ + return compat_put_int(arg, block_size(bdev)); + case BLKSSZGET: /* get block device hardware sector size */ + return compat_put_int(arg, bdev_logical_block_size(bdev)); + case BLKSECTGET: + max_sectors = min_t(unsigned int, USHRT_MAX, + queue_max_sectors(bdev_get_queue(bdev))); + return compat_put_ushort(arg, max_sectors); + case BLKROTATIONAL: + return compat_put_ushort(arg, + !blk_queue_nonrot(bdev_get_queue(bdev))); + case BLKRASET: /* compatible, but no compat_ptr (!) */ + case BLKFRASET: + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; + return 0; + case BLKGETSIZE: + size = i_size_read(bdev->bd_inode); + if ((size >> 9) > ~0UL) + return -EFBIG; + return compat_put_ulong(arg, size >> 9); + + case BLKGETSIZE64_32: + return compat_put_u64(arg, i_size_read(bdev->bd_inode)); + + case BLKTRACESETUP32: + case BLKTRACESTART: /* compatible */ + case BLKTRACESTOP: /* compatible */ + case BLKTRACETEARDOWN: /* compatible */ + ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); + return ret; + case IOC_PR_REGISTER: + case IOC_PR_RESERVE: + case IOC_PR_RELEASE: + case IOC_PR_PREEMPT: + case IOC_PR_PREEMPT_ABORT: + case IOC_PR_CLEAR: + return blkdev_ioctl(bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); + default: + if (disk->fops->compat_ioctl) + ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); + return ret; + } +} +#endif From patchwork Tue Dec 17 22:17:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298873 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 D72E714F6 for ; Tue, 17 Dec 2019 22:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BDEF721582 for ; Tue, 17 Dec 2019 22:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726754AbfLQWRx (ORCPT ); Tue, 17 Dec 2019 17:17:53 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:42629 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726733AbfLQWRs (ORCPT ); Tue, 17 Dec 2019 17:17:48 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mzhf5-1hlv0p2OMj-00vgXP; Tue, 17 Dec 2019 23:17:34 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 25/27] compat_ioctl: block: simplify compat_blkpg_ioctl() Date: Tue, 17 Dec 2019 23:17:06 +0100 Message-Id: <20191217221708.3730997-26-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:u56YlEGvfOa9zyhVPxWeQqyyoHmVfXUnvL4Wd9qSUxbgXqKfNbk iDq+NFs5bgKJDjeu7lGnuYYHi3u/BRMa/UcOlmalAwI2H3P5YhBTDahqHW/DAc+lt0Hhgw4 vLYECIgCJZGl+I7guuXe2oI+wxIscuJl80F0kddfubjLPvNRRB6U0/XdvmrbKjjNezmZ9j2 9+jZtiIYRPvS3t58syV5w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:BsIoG4Z5w2Y=:A1Ag1+Uyp7HVkUxJlC4qWg rhyX78tMCYlnIGy3LuqwuziiIzcT3YTTOH4OX9r4adRYRTBfULoxLMOyRTwe4mlEM/nSYZt74 zNhRZR0aLBvuasUfLWWwm6CZBaUyCFlSIjhdixhboNw7av3BKYmf0czmbvkn4uQQVi9gwMeuY OoFqlXqocn9lHT7Mv1ozdaVpy3H9Sd9l8Qm3Iu9Nno5pJiwxXDGHf56JqEg+s3NLZfNqA6OZ0 Bn1lWTMLw4GqZmwyBG25tUUwh9JPPF2vONgMwIPwsb30VFL1bHu+azoMlyH1N646Ri5FpMVaD sHiMAC4L8cuxOrI3y6HmNpvnq1zzEauJA9El76OrQ0olKbn9U8Tjot97/cpUT5qeNTT0UasMk SIHAH/9XHerjD5sCDID0BhGaszJXf/toBnQVWzrYW0oA0MH67RWlY4fcp9lw7bFKUFttz+CLB q8VUfzeAqNWTqX0qE0dfDZlH3pL9QavtoP2qL32K7hUEQX6d7CdlpWednik//c9xm3Qye5+eq R3An18Y9fn5EZjy/oseZH5rpfGEW6gn91At2RmvlzAF0ou/9QmIdlwesXBix/D+wQ7J8gqwAV ZDCeSNLRMn+zLi76kfK45CX0rm+BWmG2AldhjSgNCABc3PIQhQqt4XRYSBc8jgf/cKt2KOQIO Djm8Jgi/L/VxcQ8K2eJU88hhhU40z+cS1T8Cd8VT2FVdnetClznvBoWmLmrbQ51yyGc3ITrfQ ug2bg5CRthgohTeHncxRK4/NnXb+TyvDGEdlOaf3rGnz1aheRruKAV1I30N/3aSlk2bQkhEGl 0VmiHbbdZZUE2KUIiovszFRvIWeQSr+Sih1AaBqeWqs2OjM/GyTpU9x9fQm0EB+PFl4lZFvcE XJZWwiN8A8nAoene4fsw== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org There is no need to go through a compat_alloc_user_space() copy any more, just wrap the function in a small helper that works the same way for native and compat mode. Signed-off-by: Arnd Bergmann --- block/ioctl.c | 74 ++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index f8c4e2649335..d6911a1149f5 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -12,12 +12,12 @@ #include #include -static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user *arg) +static int blkpg_do_ioctl(struct block_device *bdev, + struct blkpg_partition __user *upart, int op) { struct block_device *bdevp; struct gendisk *disk; struct hd_struct *part, *lpart; - struct blkpg_ioctl_arg a; struct blkpg_partition p; struct disk_part_iter piter; long long start, length; @@ -25,9 +25,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user if (!capable(CAP_SYS_ADMIN)) return -EACCES; - if (copy_from_user(&a, arg, sizeof(struct blkpg_ioctl_arg))) - return -EFAULT; - if (copy_from_user(&p, a.data, sizeof(struct blkpg_partition))) + if (copy_from_user(&p, upart, sizeof(struct blkpg_partition))) return -EFAULT; disk = bdev->bd_disk; if (bdev != bdev->bd_contains) @@ -35,7 +33,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user partno = p.pno; if (partno <= 0) return -EINVAL; - switch (a.op) { + switch (op) { case BLKPG_ADD_PARTITION: start = p.start >> 9; length = p.length >> 9; @@ -156,6 +154,39 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user } } +static int blkpg_ioctl(struct block_device *bdev, + struct blkpg_ioctl_arg __user *arg) +{ + struct blkpg_partition __user *udata; + int op; + + if (get_user(op, &arg->op) || get_user(udata, &arg->data)) + return -EFAULT; + + return blkpg_do_ioctl(bdev, udata, op); +} + +#ifdef CONFIG_COMPAT +struct compat_blkpg_ioctl_arg { + compat_int_t op; + compat_int_t flags; + compat_int_t datalen; + compat_caddr_t data; +}; + +static int compat_blkpg_ioctl(struct block_device *bdev, + struct compat_blkpg_ioctl_arg __user *arg) +{ + compat_caddr_t udata; + int op; + + if (get_user(op, &arg->op) || get_user(udata, &arg->data)) + return -EFAULT; + + return blkpg_do_ioctl(bdev, compat_ptr(udata), op); +} +#endif + static int blkdev_reread_part(struct block_device *bdev) { int ret; @@ -676,35 +707,6 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, EXPORT_SYMBOL_GPL(blkdev_ioctl); #ifdef CONFIG_COMPAT -struct compat_blkpg_ioctl_arg { - compat_int_t op; - compat_int_t flags; - compat_int_t datalen; - compat_caddr_t data; -}; - -static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32) -{ - struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); - compat_caddr_t udata; - compat_int_t n; - int err; - - err = get_user(n, &ua32->op); - err |= put_user(n, &a->op); - err |= get_user(n, &ua32->flags); - err |= put_user(n, &a->flags); - err |= get_user(n, &ua32->datalen); - err |= put_user(n, &a->datalen); - err |= get_user(udata, &ua32->data); - err |= put_user(compat_ptr(udata), &a->data); - if (err) - return err; - - return blkdev_ioctl(bdev, mode, cmd, (unsigned long)a); -} - #define BLKBSZGET_32 _IOR(0x12, 112, int) #define BLKBSZSET_32 _IOW(0x12, 113, int) #define BLKGETSIZE64_32 _IOR(0x12, 114, int) @@ -767,7 +769,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) return blkdev_ioctl(bdev, mode, BLKBSZSET, (unsigned long)compat_ptr(arg)); case BLKPG: - return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg)); + return compat_blkpg_ioctl(bdev, compat_ptr(arg)); case BLKRAGET: case BLKFRAGET: if (!arg) From patchwork Tue Dec 17 22:17:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298861 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 01CC314F6 for ; Tue, 17 Dec 2019 22:18:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE28B24682 for ; Tue, 17 Dec 2019 22:18:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbfLQWRy (ORCPT ); Tue, 17 Dec 2019 17:17:54 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:44153 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbfLQWRs (ORCPT ); Tue, 17 Dec 2019 17:17:48 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MJV5K-1iNTt905Tk-00JtoE; Tue, 17 Dec 2019 23:17:35 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 26/27] compat_ioctl: simplify up block/ioctl.c Date: Tue, 17 Dec 2019 23:17:07 +0100 Message-Id: <20191217221708.3730997-27-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:PSc7cpxTcwWHoTLJDUDon6vPuqxjQAgXgZKbCrNZoO2KElfQx2l FcINrO/ELAkuOfoyfqWTVT4i4v5sM8sF+KUFa2LjvArRvPR3zjWSQRKEBViXYCp9Qc4zzr1 ysea+zdVUJZM2T9fsMB403F/yO2EQ7KlltB4m2/O8/8tEMGjRUjvlvbOzb2rbnsTWtBCHza A5vXksHicMt2jaaVRI9kg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:/yc9ooJVqPo=:WUDNd8mE+eIpSCOHgfIZNk mEqCkSvWvZRzjTM5MyLgkTuTmBJ/rbk6fkV2LLFwXXW8nO5kcf+jXoyN0OiZ5jK9gDdBEgkR8 NoPIoGtBxVIp+zyqc30bztU2JbA3gPNjyZ0fHAHYs9o2yL6CRgsqVO/otIkLBx9f1qgkwKGxt nH1EVeBNK/970m9LbxdnvGdzn0qoz2Hc+uteoLkHz9orS2FbRtcmZN0v9u4UZTWDqkq0wt/zC nEETluikOUayjSRc4aPltRnBn1VQqFXDEvG0f1SJWoE6IhKJc0Y74ZC3WazKktnccUv/YKfYe H5SzvJnQ5MstqY3aeTtaZRREA+X/IbO3qaYNXYc29nzvoVDoZS6arUBetleMLszj9xhVlD8j5 FJqSubrCY08MgkhReUBFTK3otgK78/TEXeebVNHoMHF1KKzrkRO8JkkoXIiO9vCwe7I4D0gWh D1hZrrpzOORV4oJxjeps2cnDTAM44Td+Ybe63drNBGDC29Xn0DBIHbTZ9O2cd5hY9NTYFt/8f Zl75ZsPKznWCouvfgwXgZaMchV0+BpcF5co62WLlADcpFhmj5mX4ROzGqBZb+S0IXVTqkre7N JrJ2uEGi0j59hHZ9nBKleu1+tfMsLkpZ6/hisbT91ihKNhmiJBuS+heC5yxKO5OTcHB6+PI/K 0RjP9Th5ir5d3mD88fqgvTx0n6f2fvQgbXMkjVw3RoKWRIEufC5OsspTIxvqKGNsXCis/rAfW JVku8g+PC2wz56oGfhHIr+7nmBECBy6WBiJBGtAUAXj1d+9hPJaA+bBXAIp4xRMKGefH7ve1u u8uz4SZo9pfROgRssLrely3RCP/A+dvJ2GaDzMukeRWa7a1SaS/IruR1sr5a4wTMUbL2sbuQC TcCih08baW6RxrNoSHMw== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Having separate implementations of blkdev_ioctl() often leads to these getting out of sync, despite the comment at the top. Since most of the ioctl commands are compatible, and we try very hard not to add any new incompatible ones, move all the common bits into a shared function and leave only the ones that are historically different in separate functions for native/compat mode. To deal with the compat_ptr() conversion, pass both the integer argument and the pointer argument into the new blkdev_common_ioctl() and make sure to always use the correct one of these. blkdev_ioctl() is now only kept as a separate exported interfact for drivers/char/raw.c, which lacks a compat_ioctl variant. We should probably either move raw.c to staging if there are no more users, or export blkdev_compat_ioctl() as well. Signed-off-by: Arnd Bergmann --- block/ioctl.c | 269 ++++++++++++++++++++++---------------------------- 1 file changed, 117 insertions(+), 152 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index d6911a1149f5..127194b9f9bd 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -270,65 +270,45 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, BLKDEV_ZERO_NOUNMAP); } -static int put_ushort(unsigned long arg, unsigned short val) +static int put_ushort(unsigned short __user *argp, unsigned short val) { - return put_user(val, (unsigned short __user *)arg); + return put_user(val, argp); } -static int put_int(unsigned long arg, int val) +static int put_int(int __user *argp, int val) { - return put_user(val, (int __user *)arg); + return put_user(val, argp); } -static int put_uint(unsigned long arg, unsigned int val) +static int put_uint(unsigned int __user *argp, unsigned int val) { - return put_user(val, (unsigned int __user *)arg); + return put_user(val, argp); } -static int put_long(unsigned long arg, long val) +static int put_long(long __user *argp, long val) { - return put_user(val, (long __user *)arg); + return put_user(val, argp); } -static int put_ulong(unsigned long arg, unsigned long val) +static int put_ulong(unsigned long __user *argp, unsigned long val) { - return put_user(val, (unsigned long __user *)arg); + return put_user(val, argp); } -static int put_u64(unsigned long arg, u64 val) +static int put_u64(u64 __user *argp, u64 val) { - return put_user(val, (u64 __user *)arg); + return put_user(val, argp); } #ifdef CONFIG_COMPAT -static int compat_put_ushort(unsigned long arg, unsigned short val) +static int compat_put_long(compat_long_t *argp, long val) { - return put_user(val, (unsigned short __user *)compat_ptr(arg)); + return put_user(val, argp); } -static int compat_put_int(unsigned long arg, int val) +static int compat_put_ulong(compat_ulong_t *argp, compat_ulong_t val) { - return put_user(val, (compat_int_t __user *)compat_ptr(arg)); -} - -static int compat_put_uint(unsigned long arg, unsigned int val) -{ - return put_user(val, (compat_uint_t __user *)compat_ptr(arg)); -} - -static int compat_put_long(unsigned long arg, long val) -{ - return put_user(val, (compat_long_t __user *)compat_ptr(arg)); -} - -static int compat_put_ulong(unsigned long arg, compat_ulong_t val) -{ - return put_user(val, (compat_ulong_t __user *)compat_ptr(arg)); -} - -static int compat_put_u64(unsigned long arg, u64 val) -{ - return put_user(val, (compat_u64 __user *)compat_ptr(arg)); + return put_user(val, argp); } #endif @@ -547,9 +527,10 @@ struct compat_hd_geometry { u32 start; }; -static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, - struct compat_hd_geometry __user *ugeo) +static int compat_hdio_getgeo(struct block_device *bdev, + struct compat_hd_geometry __user *ugeo) { + struct gendisk *disk = bdev->bd_disk; struct hd_geometry geo; int ret; @@ -603,13 +584,13 @@ static int blkdev_bszset(struct block_device *bdev, fmode_t mode, } /* - * always keep this in sync with compat_blkdev_ioctl() + * Common commands that are handled the same way on native and compat + * user space. Note the separate arg/argp parameters that are needed + * to deal with the compat_ptr() conversion. */ -int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, - unsigned long arg) +static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, + unsigned cmd, unsigned long arg, void __user *argp) { - void __user *argp = (void __user *)arg; - loff_t size; unsigned int max_sectors; switch (cmd) { @@ -632,60 +613,39 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, case BLKFINISHZONE: return blkdev_zone_mgmt_ioctl(bdev, mode, cmd, arg); case BLKGETZONESZ: - return put_uint(arg, bdev_zone_sectors(bdev)); + return put_uint(argp, bdev_zone_sectors(bdev)); case BLKGETNRZONES: - return put_uint(arg, blkdev_nr_zones(bdev->bd_disk)); - case HDIO_GETGEO: - return blkdev_getgeo(bdev, argp); - case BLKRAGET: - case BLKFRAGET: - if (!arg) - return -EINVAL; - return put_long(arg, (bdev->bd_bdi->ra_pages*PAGE_SIZE) / 512); + return put_uint(argp, blkdev_nr_zones(bdev->bd_disk)); case BLKROGET: - return put_int(arg, bdev_read_only(bdev) != 0); - case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */ - return put_int(arg, block_size(bdev)); + return put_int(argp, bdev_read_only(bdev) != 0); case BLKSSZGET: /* get block device logical block size */ - return put_int(arg, bdev_logical_block_size(bdev)); + return put_int(argp, bdev_logical_block_size(bdev)); case BLKPBSZGET: /* get block device physical block size */ - return put_uint(arg, bdev_physical_block_size(bdev)); + return put_uint(argp, bdev_physical_block_size(bdev)); case BLKIOMIN: - return put_uint(arg, bdev_io_min(bdev)); + return put_uint(argp, bdev_io_min(bdev)); case BLKIOOPT: - return put_uint(arg, bdev_io_opt(bdev)); + return put_uint(argp, bdev_io_opt(bdev)); case BLKALIGNOFF: - return put_int(arg, bdev_alignment_offset(bdev)); + return put_int(argp, bdev_alignment_offset(bdev)); case BLKDISCARDZEROES: - return put_uint(arg, 0); + return put_uint(argp, 0); case BLKSECTGET: max_sectors = min_t(unsigned int, USHRT_MAX, queue_max_sectors(bdev_get_queue(bdev))); - return put_ushort(arg, max_sectors); + return put_ushort(argp, max_sectors); case BLKROTATIONAL: - return put_ushort(arg, !blk_queue_nonrot(bdev_get_queue(bdev))); + return put_ushort(argp, !blk_queue_nonrot(bdev_get_queue(bdev))); case BLKRASET: case BLKFRASET: if(!capable(CAP_SYS_ADMIN)) return -EACCES; bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; return 0; - case BLKBSZSET: - return blkdev_bszset(bdev, mode, argp); - case BLKPG: - return blkpg_ioctl(bdev, argp); case BLKRRPART: return blkdev_reread_part(bdev); - case BLKGETSIZE: - size = i_size_read(bdev->bd_inode); - if ((size >> 9) > ~0UL) - return -EFBIG; - return put_ulong(arg, size >> 9); - case BLKGETSIZE64: - return put_u64(arg, i_size_read(bdev->bd_inode)); case BLKTRACESTART: case BLKTRACESTOP: - case BLKTRACESETUP: case BLKTRACETEARDOWN: return blk_trace_ioctl(bdev, cmd, argp); case IOC_PR_REGISTER: @@ -701,12 +661,67 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, case IOC_PR_CLEAR: return blkdev_pr_clear(bdev, argp); default: - return __blkdev_driver_ioctl(bdev, mode, cmd, arg); + return -ENOIOCTLCMD; } } -EXPORT_SYMBOL_GPL(blkdev_ioctl); + +/* + * Always keep this in sync with compat_blkdev_ioctl() + * to handle all incompatible commands in both functions. + * + * New commands must be compatible and go into blkdev_common_ioctl + */ +int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, + unsigned long arg) +{ + int ret; + loff_t size; + void __user *argp = (void __user *)arg; + + switch (cmd) { + /* These need separate implementations for the data structure */ + case HDIO_GETGEO: + return blkdev_getgeo(bdev, argp); + case BLKPG: + return blkpg_ioctl(bdev, argp); + + /* Compat mode returns 32-bit data instead of 'long' */ + case BLKRAGET: + case BLKFRAGET: + if (!argp) + return -EINVAL; + return put_long(argp, (bdev->bd_bdi->ra_pages*PAGE_SIZE) / 512); + case BLKGETSIZE: + size = i_size_read(bdev->bd_inode); + if ((size >> 9) > ~0UL) + return -EFBIG; + return put_ulong(argp, size >> 9); + + /* The data is compatible, but the command number is different */ + case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */ + return put_int(argp, block_size(bdev)); + case BLKBSZSET: + return blkdev_bszset(bdev, mode, argp); + case BLKGETSIZE64: + return put_u64(argp, i_size_read(bdev->bd_inode)); + + /* Incompatible alignment on i386 */ + case BLKTRACESETUP: + return blk_trace_ioctl(bdev, cmd, argp); + default: + break; + } + + ret = blkdev_common_ioctl(bdev, mode, cmd, arg, argp); + if (ret == -ENOIOCTLCMD) + return __blkdev_driver_ioctl(bdev, mode, cmd, arg); + + return ret; +} +EXPORT_SYMBOL_GPL(blkdev_ioctl); /* for /dev/raw */ #ifdef CONFIG_COMPAT + #define BLKBSZGET_32 _IOR(0x12, 112, int) #define BLKBSZSET_32 _IOW(0x12, 113, int) #define BLKGETSIZE64_32 _IOR(0x12, 114, int) @@ -716,13 +731,13 @@ EXPORT_SYMBOL_GPL(blkdev_ioctl); ENOIOCTLCMD for unknown ioctls. */ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) { - int ret = -ENOIOCTLCMD; + int ret; + void __user *argp = compat_ptr(arg); struct inode *inode = file->f_mapping->host; struct block_device *bdev = inode->i_bdev; struct gendisk *disk = bdev->bd_disk; fmode_t mode = file->f_mode; loff_t size; - unsigned int max_sectors; /* * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have @@ -734,94 +749,44 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) mode &= ~FMODE_NDELAY; switch (cmd) { + /* These need separate implementations for the data structure */ case HDIO_GETGEO: - return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); - case BLKPBSZGET: - return compat_put_uint(arg, bdev_physical_block_size(bdev)); - case BLKIOMIN: - return compat_put_uint(arg, bdev_io_min(bdev)); - case BLKIOOPT: - return compat_put_uint(arg, bdev_io_opt(bdev)); - case BLKALIGNOFF: - return compat_put_int(arg, bdev_alignment_offset(bdev)); - case BLKDISCARDZEROES: - return compat_put_uint(arg, 0); - case BLKFLSBUF: - case BLKROSET: - case BLKDISCARD: - case BLKSECDISCARD: - case BLKZEROOUT: - /* - * the ones below are implemented in blkdev_locked_ioctl, - * but we call blkdev_ioctl, which gets the lock for us - */ - case BLKRRPART: - case BLKREPORTZONE: - case BLKRESETZONE: - case BLKOPENZONE: - case BLKCLOSEZONE: - case BLKFINISHZONE: - case BLKGETZONESZ: - case BLKGETNRZONES: - return blkdev_ioctl(bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); - case BLKBSZSET_32: - return blkdev_ioctl(bdev, mode, BLKBSZSET, - (unsigned long)compat_ptr(arg)); + return compat_hdio_getgeo(bdev, argp); case BLKPG: - return compat_blkpg_ioctl(bdev, compat_ptr(arg)); + return compat_blkpg_ioctl(bdev, argp); + + /* Compat mode returns 32-bit data instead of 'long' */ case BLKRAGET: case BLKFRAGET: - if (!arg) + if (!argp) return -EINVAL; - return compat_put_long(arg, + return compat_put_long(argp, (bdev->bd_bdi->ra_pages * PAGE_SIZE) / 512); - case BLKROGET: /* compatible */ - return compat_put_int(arg, bdev_read_only(bdev) != 0); - case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ - return compat_put_int(arg, block_size(bdev)); - case BLKSSZGET: /* get block device hardware sector size */ - return compat_put_int(arg, bdev_logical_block_size(bdev)); - case BLKSECTGET: - max_sectors = min_t(unsigned int, USHRT_MAX, - queue_max_sectors(bdev_get_queue(bdev))); - return compat_put_ushort(arg, max_sectors); - case BLKROTATIONAL: - return compat_put_ushort(arg, - !blk_queue_nonrot(bdev_get_queue(bdev))); - case BLKRASET: /* compatible, but no compat_ptr (!) */ - case BLKFRASET: - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; - return 0; case BLKGETSIZE: size = i_size_read(bdev->bd_inode); if ((size >> 9) > ~0UL) return -EFBIG; - return compat_put_ulong(arg, size >> 9); + return compat_put_ulong(argp, size >> 9); + /* The data is compatible, but the command number is different */ + case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ + return put_int(argp, bdev_logical_block_size(bdev)); + case BLKBSZSET_32: + return blkdev_bszset(bdev, mode, argp); case BLKGETSIZE64_32: - return compat_put_u64(arg, i_size_read(bdev->bd_inode)); + return put_u64(argp, i_size_read(bdev->bd_inode)); + /* Incompatible alignment on i386 */ case BLKTRACESETUP32: - case BLKTRACESTART: /* compatible */ - case BLKTRACESTOP: /* compatible */ - case BLKTRACETEARDOWN: /* compatible */ - ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); - return ret; - case IOC_PR_REGISTER: - case IOC_PR_RESERVE: - case IOC_PR_RELEASE: - case IOC_PR_PREEMPT: - case IOC_PR_PREEMPT_ABORT: - case IOC_PR_CLEAR: - return blkdev_ioctl(bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); + return blk_trace_ioctl(bdev, cmd, argp); default: - if (disk->fops->compat_ioctl) - ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); - return ret; + break; } + + ret = blkdev_common_ioctl(bdev, mode, cmd, arg, argp); + if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl) + ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); + + return ret; } #endif From patchwork Tue Dec 17 22:17:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11298909 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 DC00C14F6 for ; Tue, 17 Dec 2019 22:19:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B0D6821775 for ; Tue, 17 Dec 2019 22:19:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727148AbfLQWTM (ORCPT ); Tue, 17 Dec 2019 17:19:12 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:37289 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbfLQWTL (ORCPT ); Tue, 17 Dec 2019 17:19:11 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MUXh8-1iGuJ51tR2-00QWZS; Tue, 17 Dec 2019 23:17:35 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Ben Hutchings , linux-doc@vger.kernel.org, corbet@lwn.net, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 27/27] Documentation: document ioctl interfaces better Date: Tue, 17 Dec 2019 23:17:08 +0100 Message-Id: <20191217221708.3730997-28-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191217221708.3730997-1-arnd@arndb.de> References: <20191217221708.3730997-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:8tW/r52hvfNOEZl1WWrXLsD17pNONxauwO7dPhEDVrEw3kNuL7z IXZZg+A7l6N3v5JfsZS7pQF0AUwC/zif6XF4hJTU/aQ5MqAYz7kCbVw177pXy/zticcsE1s QHqIifY6CcVz4kqmZhRoyPK/Viq1pgVoOnN+j9OGkEb07n14JjBLduBFKbBfxQfgwdITv0N HVu3bO762YQn1UILnHPkQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:A4PK+//HA2s=:Cs4X/p8qr+Ea3Qt18U6i+y T5KG1wqBLjS3dSyhUDAVKuYKUplMefw3WfMHMnDX8vn4+bbG7AcdXkoMsRAo6kd7lsN4GV2JL Ic5i1relVarommCWBIleIXuW/JMmtllCvkpWoHm3JsW28YSw3NYVKMSU9q+X+ZiL6BNSG+FTS JtspZY160vZtCwLXUzXQxqMLUbtKfOgV6hpJlOeFFJGAILNFq/97dXR6ziX3oi9rUfAPSDsc0 3Q32Z0yZt+cHN7Acx9nGtEthkMIZt6xcQ3/Ie94HxRJ/HiRc83vVMoHNUAOmQkM7IUxKFFiht X1mTIfYkXAJkWo/8NjXFQkL3l+yVfUnLz5L2/2z6kwvda+ZkGPchTmQ5F1fG0UYuD02Zyj0qi bbVMRgZIqQcSRNzGvTBvXcfLIJLNVchUZmhTg9Bp9lYPtPAc+2wGsgBfFYYwzxNahxZSqgcsG p+ekXyxHOQ/h9CGfMcDwrxadceo2IOQ2Mpad1e/dHjoRRnuXivWuqLqo80Bq9k55Ov8g98Q1a TZM17zSbQwjkLagkCZFks+0wToa8cUNMZXuFB9Ya32glfx9Dkh2u8ssP/LPRqkwzI6PuUifTO JJBN/6etrjwKWK2nU07RKrnmwmC0MX2bJ90vpO6W4DaQn8ww/iY64FVUzaeEJofEEgpO1jCYt jKXZNslKGyq26H4vrlebtPI/pOAH5LXwTdzfUI0igK5LmuaPP9leobbOPD0o1E9GZSFsEVYC1 CWUrJ6D8Hq8HNO4mUVZkdXd6BLlRzHd2RA44zZoaiiUeDDbKkgvtJPG7XcwS1xraiuL3yNmRD em/9nH/tiZjZZEaTGgpeLT84EWe6rcMs+wF9GDeksl5mMwx4TlYQFKKUfhjkfG6gmS7TiRBDH Faiw4UKM+MW4KL0lqcwQ== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Documentation/process/botching-up-ioctls.rst was orignally written as a blog post for DRM driver writers, so it it misses some points while going into a lot of detail on others. Try to provide a replacement that addresses typical issues across a wider range of subsystems, and follows the style of the core-api documentation better. Signed-off-by: Arnd Bergmann --- Documentation/core-api/index.rst | 1 + Documentation/core-api/ioctl.rst | 248 +++++++++++++++++++++++++++++++ 2 files changed, 249 insertions(+) create mode 100644 Documentation/core-api/ioctl.rst diff --git a/Documentation/core-api/index.rst b/Documentation/core-api/index.rst index ab0eae1c153a..3f28b2f668be 100644 --- a/Documentation/core-api/index.rst +++ b/Documentation/core-api/index.rst @@ -39,6 +39,7 @@ Core utilities ../RCU/index gcc-plugins symbol-namespaces + ioctl Interfaces for kernel debugging diff --git a/Documentation/core-api/ioctl.rst b/Documentation/core-api/ioctl.rst new file mode 100644 index 000000000000..99892f96c5cb --- /dev/null +++ b/Documentation/core-api/ioctl.rst @@ -0,0 +1,248 @@ +====================== +ioctl based interfaces +====================== + +ioctl() is the most common way for applications to interface +with device drivers. It is flexible and easily extended by adding new +commands and can be passed through character devices, block devices as +well as sockets and other special file descriptors. + +However, it is also very easy to get ioctl command definitions wrong, +and hard to fix them later without breaking existing applications, +so this documentation tries to help developers get it right. + +Command number definitions +========================== + +The command number, or request number, is the second argument passed to +the ioctl system call. While this can be any 32-bit number that uniquely +identifies an action for a particular driver, there are a number of +conventions around defining them. + +``include/uapi/asm-generic/ioctl.h`` provides four macros for defining +ioctl commands that follow modern conventions: ``_IO``, ``_IOR``, +``_IOW``, and ``_IORW``. These should be used for all new commands, +with the correct parameters: + +_IO/_IOR/_IOW/_IOWR + The macro name determines whether the argument is used for passing + data into kernel (_IOW), from the kernel (_IOR), both (_IOWR) or is + not a pointer (_IO). It is possible but not recommended to pass an + integer value instead of a pointer with _IO. + +type + An 8-bit number, often a character literal, specific to a subsystem + or driver, and listed in :doc:`../userspace-api/ioctl/ioctl-number` + +nr + An 8-bit number identifying the specific command, unique for a give + value of 'type' + +data_type + The name of the data type pointed to by the argument, the command number + encodes the ``sizeof(data_type)`` value in a 13-bit or 14-bit integer, + leading to a limit of 8191 bytes for the maximum size of the argument. + Note: do not pass sizeof(data_type) type into _IOR/IOW, as that will + lead to encoding sizeof(sizeof(data_type)), i.e. sizeof(size_t). + + +Interface versions +================== + +Some subsystems use version numbers in data structures to overload +commands with different interpretations of the argument. + +This is generally a bad idea, since changes to existing commands tend +to break existing applications. + +A better approach is to add a new ioctl command with a new number. The +old command still needs to be implemented in the kernel for compatibility, +but this can be a wrapper around the new implementation. + +Return code +=========== + +ioctl commands can return negative error codes as documented in errno(3), +these get turned into errno values in user space. On success, the return +code should be zero. It is also possible but not recommended to return +a positive 'long' value. + +When the ioctl callback is called with an unknown command number, the +handler returns either -ENOTTY or -ENOIOCTLCMD, which also results in +-ENOTTY being returned from the system call. Some subsystems return +-ENOSYS or -EINVAL here for historic reasons, but this is wrong. + +Prior to Linux-5.5, compat_ioctl handlers were required to return +-ENOIOCTLCMD in order to use the fallback conversion into native +commands. As all subsystems are now responsible for handling compat +mode themselves, this is no longer needed, but it may be important to +consider when backporting bug fixes to older kernels. + +Timestamps +========== + +Traditionally, timestamps and timeout values are passed as ``struct +timespec`` or ``struct timeval``, but these are problematic because of +incompatible definitions of these structures in user space after the +move to 64-bit time_t. + +The __kernel_timespec type can be used instead to be embedded in other +data structures when separate second/nanosecond values are desired, +or passed to user space directly. This is still not ideal though, +as the structure matches neither the kernel's timespec64 nor the user +space timespec exactly. The get_timespec64() and put_timespec64() helper +functions can be used to ensure that the layout remains compatible with +user space and the padding is treated correctly. + +As it is cheap to convert seconds to nanoseconds, but the opposite +requires an expensive 64-bit division, a simple __u64 nanosecond value +can be simpler and more efficient. + +Timeout values and timestamps should ideally use CLOCK_MONOTONIC time, +as returned by ktime_get_ns() or ktime_get_ts64(). Unlike +CLOCK_REALTIME, this makes the timestamps immune from jumping backwards +or forwards due to leap second adjustments and clock_settime() calls. + +ktime_get_real_ns() can be used for CLOCK_REALTIME timestamps that +need to be persistent across a reboot or between multiple machines. + +32-bit compat mode +================== + +In order to support 32-bit user space running on a 64-bit machine, each +subsystem or driver that implements an ioctl callback handler must also +implement the corresponding compat_ioctl handler. + +As long as all the rules for data structures are followed, this is as +easy as setting the .compat_ioctl pointer to a helper function such as +compat_ptr_ioctl() or blkdev_compat_ptr_ioctl(). + +compat_ptr() +------------ + +On the s/390 architecture, 31-bit user space has ambiguous representations +for data pointers, with the upper bit being ignored. When running such +a process in compat mode, the compat_ptr() helper must be used to +clear the upper bit of a compat_uptr_t and turn it into a valid 64-bit +pointer. On other architectures, this macro only performs a cast to a +``void __user *`` pointer. + +In an compat_ioctl() callback, the last argument is an unsigned long, +which can be interpreted as either a pointer or a scalar depending on +the command. If it is a scalar, then compat_ptr() must not be used, to +ensure that the 64-bit kernel behaves the same way as a 32-bit kernel +for arguments with the upper bit set. + +The compat_ptr_ioctl() helper can be used in place of a custom +compat_ioctl file operation for drivers that only take arguments that +are pointers to compatible data structures. + +Structure layout +---------------- + +Compatible data structures have the same layout on all architectures, +avoiding all problematic members: + +* ``long`` and ``unsigned long`` are the size of a register, so + they can be either 32-bit or 64-bit wide and cannot be used in portable + data structures. Fixed-length replacements are ``__s32``, ``__u32``, + ``__s64`` and ``__u64``. + +* Pointers have the same problem, in addition to requiring the + use of compat_ptr(). The best workaround is to use ``__u64`` + in place of pointers, which requires a cast to ``uintptr_t`` in user + space, and the use of u64_to_user_ptr() in the kernel to convert + it back into a user pointer. + +* On the x86-32 (i386) architecture, the alignment of 64-bit variables + is only 32-bit, but they are naturally aligned on most other + architectures including x86-64. This means a structure like:: + + struct foo { + __u32 a; + __u64 b; + __u32 c; + }; + + has four bytes of padding between a and b on x86-64, plus another four + bytes of padding at the end, but no padding on i386, and it needs a + compat_ioctl conversion handler to translate between the two formats. + + To avoid this problem, all structures should have their members + naturally aligned, or explicit reserved fields added in place of the + implicit padding. + +* On ARM OABI user space, 16-bit member variables have 32-bit + alignment, making them incompatible with modern EABI kernels. + Conversely, on the m68k architecture, struct members are not + guaranteed to have an alignment greater than 16-bit. + These rarely cause problems as neither ARM-OABI nor m68k are + supported by any compat mode, but for consistency, it is best + to completely avoid 16-bit member variables. + + +* Bitfields and enums generally work as one would expect them to, + but some properties of them are implementation-defined, so it is better + to avoid them completely in ioctl interfaces. + +* ``char`` members can be either signed or unsigned, depending on + the architecture, so the __u8 and __s8 types should be used for 8-bit + integer values, though char arrays are clearer for fixed-length strings. + +Information leaks +================= + +Uninitialized data must not be copied back to user space, as this can +cause an information leak, which can be used to defeat kernel address +space layout randomization (KASLR), helping in an attack. + +As explained for the compat mode, it is best to not avoid any implicit +padding in data structures, but if there is already padding in existing +structures, the kernel driver must be careful to zero out the padding +using memset() or similar before copying it to user space. + +Subsystem abstractions +====================== + +While some device drivers implement their own ioctl function, most +subsystems implement the same command for multiple drivers. Ideally the +subsystem has an .ioctl() handler that copies the arguments from and +to user space, passing them into subsystem specific callback functions +through normal kernel pointers. + +This helps in various ways: + +* Applications written for one driver are more likely to work for + another one in the same subsystem if there are no subtle differences + in the user space ABI. + +* The complexity of user space access and data structure layout is done + in one place, reducing the potential for implementation bugs. + +* It is more likely to be reviewed by experienced developers + that can spot problems in the interface when the ioctl is shared + between multiple drivers than when it is only used in a single driver. + +Alternatives to ioctl +===================== + +There are many cases in which ioctl is not the best solution for a +problem. Alternatives include: + +* System calls are a better choice for a system-wide feature that + is not tied to a physical device or constrained by the file system + permissions of a character device node + +* netlink is the preferred way of configuring any network related + objects through sockets. + +* debugfs is used for ad-hoc interfaces for debugging functionality + that does not need to be exposed as a stable interface to applications. + +* sysfs is a good way to expose the state of an in-kernel object + that is not tied to a file descriptor. + +* configfs can be used for more complex configuration than sysfs + +* A custom file system can provide extra flexibility with a simple + user interface but add a lot of complexity to the implementation.