From patchwork Wed Dec 11 20:42: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: 181326 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1043915ile; Wed, 11 Dec 2019 12:47:20 -0800 (PST) X-Google-Smtp-Source: APXvYqxvmHcdZY/eEwuH6HFvzKOzae/FROt50MRzFhkwSy4kT2hGdSXoDhj89p75KVLCLWBJ1jI9 X-Received: by 2002:a05:6830:681:: with SMTP id q1mr3631756otr.162.1576097240712; Wed, 11 Dec 2019 12:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097240; cv=none; d=google.com; s=arc-20160816; b=zFVU3bspD9g8IogyAi9lK04aneH4CEwd//HspnfJ5KSonpap+gERN7jW5unFETWwdZ o98bkDIx7INV+fx41Gv8paoSqufaIJ0bmcp34JmZDBguSKVEVpPs0Ig+yNCZnhmUmDil 8M4/fdtbon1TcRy+FthnBgToROEsZhg2q51JDmGQqXcTdgCZ67QzeXzHEnIb+XGTvkY7 bwH4bB2g8G1g2vd+cEHDY3eofG1lTLzElXRGHgBSVYSZlLYfeQj12OJcP0XOtwB/mzfh CfAALMv7vmSxqiqosf4RK5MeVVP61vGHKob6z1ZM+P/n8xq6/KoTls3by1Z4Dn/+wCTB 24cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=iNYEmTBE6u1vLAzLj9HVPquZ2gpryVAt0RfSPbEOp/4=; b=Ow7x4Rx1DU0lT14jSNNZsjvfFOHvO/kp3GFiAHL+HXNyL7CdQj6QGxBz2ZFi7bpAo+ VmIcISqEjWCVLNFsCpanyMN0XA7+KNVo/LNEm/IwpGBnL1Zltq8X4nJjZWARVyZwoi+I 4JUjZdvXe0xhvyse7MxOmx+lhIkuzpWJq0/dCx1wa6HUdQ4u4MNYK0rwmQjgLrz81pf0 agmy9X1UBf15j8jktpBBamumuzuZe8aYY+aDsTLZhHpGSp84TN1g6jdIMdOgPf7bQTId AGezER0fjOgsG01O7Z1cnPHpaxmx/RyHg9vwusimdmhSa3xYV2afPwNDLfmevcUQ7KVq 9A8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14si1687082otq.37.2019.12.11.12.47.20; Wed, 11 Dec 2019 12:47:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726847AbfLKUrT (ORCPT + 27 others); Wed, 11 Dec 2019 15:47:19 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:39917 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUrR (ORCPT ); Wed, 11 Dec 2019 15:47:17 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mo73N-1hvNrF2EZP-00pfdu; Wed, 11 Dec 2019 21:46:42 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Denis Efremov , Tim Waugh , Boris Ostrovsky , Juergen Gross , Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Stefano Stabellini , Hannes Reinecke , Damien Le Moal , Bart Van Assche , linux-block@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH 11/24] compat_ioctl: block: handle cdrom compat ioctl in non-cdrom drivers Date: Wed, 11 Dec 2019 21:42:45 +0100 Message-Id: <20191211204306.1207817-12-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191211204306.1207817-1-arnd@arndb.de> References: <20191211204306.1207817-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:J/m2/bKJ2+pQDxQ1q226bByLe0vDPb/F2fJ3RpYYYVapImzb8aV HWSvDBZiFBEiHXWH/xWL1jk4hQERohAteHEMq2lpbMCC2anNojNV6PsQ+gg2WufxemHktc1 LyPWs3HbVs920rfFkymL5JQsEGJs//HvxV5XmvoL8txVyvk9ot9sTr81q1MSSw2dd/7OnwF PZSWIVICg0YVKDXL6K7dQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:DV6o32cCptM=:l/Of3UL40h1Gs6yrtcWn+e 4767u/NI/4g42ftlcB1rmhfV1JWoVD4LaYYo0JaTG5s6dC/UvDLk5wUO/rzT35d0X74aGK/vw ZzuO5Sfiuyu3sh/R3qDuNr/OBJp8ZGii/aLBpIMxXHpzZMFfmKfvecMGNOmA+Gq50FsJkxQaR A2zIFRydZ47PpZefsLdEoTKcgvLPHb7Tm2GNslBvrDX6Rr0I67QRiTc3YLRBlX9ynDTUJXLwo LnOc0sqAlB/PtptI8I5TK/uxN/S5T//2LOTZDmsxpeWiocQBjRJO14A5K7cMEnIY5B+RHLxek gAAdg/nxcAUOceYLoJ1sP19//eXcqy50vqxRWFQNMqWG97Ve3eZdRRqduUhY+3JgZoF6FO6ZM aKBa4A1eJ/aKXU76mR9r9lvT4iABkg+0Sm/Cve2dyCTvhA7VAI7sksverbtJVW/2KJprZ72MV 08/bikqWwwtd6GA0LKYzaRw/wNglfuToitJxn/a5LHf8tW2PKFth3O94FGIpiM3E4sXQBfAhr 2WjnWXsWaxPtkJ6iijJeH9BfwCpmm5Qh4ConI9X0elJLxTbPZOGVFZPZQd+f07OvVTik2n8Fb 6OrV2ynOjoohTm2MB0FpMDmjqPLVBSRArhIsvcb7uccbkHxfyKOs863DIYP3ChrqLvP1P/eck R9A8Rw1bnHmWjp3UtoQC5renptBxT3Jkw9nS5C4tvW1jF0+DYl6fBO8tXkud7GXVPsmUnHc72 x+rBx1bA9kL3BV/2+7ZL27IZYx33bCjbMjeNGZFuOk5xhCQCnVUQDJicSDSNQwZCX7+86Y4eQ GEH8mehP/lSQ9dzTDymYLxem9zZdxhtFq5yFvsTCm1McKxM6Nf3brzo9Rm1bSQ/dHk1u2HGUz KOjNZeK9kNw+4KJDAdxQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. Since some of these commands need a compat_ptr() conversion, introduce a blkdev_compat_ptr_ioctl() helper function that can be used as the .compat_ioctl callback for those drivers that only support compatible commands. The actual CD-ROM drivers that call cdrom_ioctl() are converted in a separate patch. Signed-off-by: Arnd Bergmann --- block/ioctl.c | 21 +++++++++++++++++++++ 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 + include/linux/blkdev.h | 7 +++++++ 7 files changed, 35 insertions(+) -- 2.20.0 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/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, }; 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 *);