* [PATCH v3 07/26] compat_ioctl: move rtc handling into rtc-dev.c
2019-04-16 20:19 [PATCH v3 00/26] compat_ioctl: cleanups Arnd Bergmann
@ 2019-04-16 20:19 ` Arnd Bergmann
2019-04-16 22:33 ` [PATCH v3 00/26] compat_ioctl: cleanups Douglas Gilbert
1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-04-16 20:19 UTC (permalink / raw)
To: Alexander Viro
Cc: linux-fsdevel, y2038, linux-kernel, Arnd Bergmann,
Alexandre Belloni, Alessandro Zummo, linux-rtc
We no longer need the rtc compat handling to be in common code, now that
all drivers are either moved to the rtc-class framework, or (rarely)
exist in drivers/char for architectures without compat mode (m68k,
alpha and ia64, respectively).
I checked the list of ioctl commands in drivers, and the ones that are
not already handled are all compatible, again with the one exception of
m68k driver, which implements RTC_PLL_GET and RTC_PLL_SET, but has no
compat mode.
Since the ioctl commands are either compatible or differ in both structure
and command code between 32-bit and 64-bit, we can merge the compat
handler into the native one and just implement the two common compat
commands (RTC_IRQP_READ, RTC_IRQP_SET) there. The result is a slight
change in behavior, as a native 64-bit process will now also handle the
32-bit commands (RTC_IRQP_SET32/RTC_IRQP_SET).
The old conversion handler also deals with RTC_EPOCH_READ and
RTC_EPOCH_SET, which are not handled in rtc-dev.c but only in a single
device driver (rtc-vr41xx), so I'm adding the compat version in the same
place. I don't expect other drivers to need those commands in the future.
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: merge compat handler into ioctl function to avoid the
compat_alloc_user_space() roundtrip, based on feedback
from Al Viro.
---
drivers/rtc/dev.c | 13 ++++++++-
drivers/rtc/rtc-vr41xx.c | 10 +++++++
fs/compat_ioctl.c | 61 ++--------------------------------------
3 files changed, 25 insertions(+), 59 deletions(-)
diff --git a/drivers/rtc/dev.c b/drivers/rtc/dev.c
index 1d006ef4bb57..a63779ccc8aa 100644
--- a/drivers/rtc/dev.c
+++ b/drivers/rtc/dev.c
@@ -13,6 +13,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/compat.h>
#include <linux/module.h>
#include <linux/rtc.h>
#include <linux/sched/signal.h>
@@ -359,10 +360,19 @@ static long rtc_dev_ioctl(struct file *file,
mutex_unlock(&rtc->ops_lock);
return rtc_update_irq_enable(rtc, 0);
+#ifdef CONFIG_64BIT
+#define RTC_IRQP_SET32 _IOW('p', 0x0c, __u32)
+#define RTC_IRQP_READ32 _IOR('p', 0x0b, __u32)
+ case RTC_IRQP_SET32:
+ err = rtc_irq_set_freq(rtc, arg);
+ break;
+ case RTC_IRQP_READ32:
+ err = put_user(rtc->irq_freq, (unsigned int __user *)uarg);
+ break;
+#endif
case RTC_IRQP_SET:
err = rtc_irq_set_freq(rtc, arg);
break;
-
case RTC_IRQP_READ:
err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
break;
@@ -434,6 +444,7 @@ static const struct file_operations rtc_dev_fops = {
.read = rtc_dev_read,
.poll = rtc_dev_poll,
.unlocked_ioctl = rtc_dev_ioctl,
+ .compat_ioctl = compat_ptr_ioctl,
.open = rtc_dev_open,
.release = rtc_dev_release,
.fasync = rtc_dev_fasync,
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index e66d0f63cee2..62c16a3b2d5c 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <linux/compat.h>
#include <linux/err.h>
#include <linux/fs.h>
#include <linux/init.h>
@@ -79,6 +80,10 @@ static void __iomem *rtc2_base;
#define rtc2_read(offset) readw(rtc2_base + (offset))
#define rtc2_write(offset, value) writew((value), rtc2_base + (offset))
+/* 32-bit compat for ioctls that nobody else uses */
+#define RTC_EPOCH_READ32 _IOR('p', 0x0d, __u32)
+#define RTC_EPOCH_SET32 _IOW('p', 0x0e, __u32)
+
static unsigned long epoch = 1970; /* Jan 1 1970 00:00:00 */
static DEFINE_SPINLOCK(rtc_lock);
@@ -192,6 +197,11 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
switch (cmd) {
case RTC_EPOCH_READ:
return put_user(epoch, (unsigned long __user *)arg);
+#ifdef CONFIG_64BIT
+ case RTC_EPOCH_READ32:
+ return put_user(epoch, (unsigned int __user *)arg);
+ case RTC_EPOCH_SET32:
+#endif
case RTC_EPOCH_SET:
/* Doesn't support before 1900 */
if (arg < 1900)
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index e6dbd956cf66..fee116e822d8 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -32,7 +32,6 @@
#include <linux/vt_kern.h>
#include <linux/raw.h>
#include <linux/blkdev.h>
-#include <linux/rtc.h>
#include <linux/pci.h>
#include <linux/serial.h>
#include <linux/ctype.h>
@@ -343,37 +342,6 @@ static int mt_ioctl_trans(struct file *file,
#define HCIUARTSETFLAGS _IOW('U', 203, int)
#define HCIUARTGETFLAGS _IOR('U', 204, int)
-#define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
-#define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
-#define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
-#define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
-
-static int rtc_ioctl(struct file *file,
- unsigned cmd, void __user *argp)
-{
- unsigned long __user *valp = compat_alloc_user_space(sizeof(*valp));
- int ret;
-
- if (valp == NULL)
- return -EFAULT;
- switch (cmd) {
- case RTC_IRQP_READ32:
- case RTC_EPOCH_READ32:
- ret = do_ioctl(file, (cmd == RTC_IRQP_READ32) ?
- RTC_IRQP_READ : RTC_EPOCH_READ,
- (unsigned long)valp);
- if (ret)
- return ret;
- return convert_in_user(valp, (unsigned int __user *)argp);
- case RTC_IRQP_SET32:
- return do_ioctl(file, RTC_IRQP_SET, (unsigned long)argp);
- case RTC_EPOCH_SET32:
- return do_ioctl(file, RTC_EPOCH_SET, (unsigned long)argp);
- }
-
- return -ENOIOCTLCMD;
-}
-
/* on ia32 l_start is on a 32-bit boundary */
#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
struct space_resv_32 {
@@ -457,21 +425,6 @@ COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
/* Big V (don't complain on serial console) */
IGNORE_IOCTL(VT_OPENQRY)
IGNORE_IOCTL(VT_GETMODE)
-/* Little p (/dev/rtc, /dev/envctrl, etc.) */
-COMPATIBLE_IOCTL(RTC_AIE_ON)
-COMPATIBLE_IOCTL(RTC_AIE_OFF)
-COMPATIBLE_IOCTL(RTC_UIE_ON)
-COMPATIBLE_IOCTL(RTC_UIE_OFF)
-COMPATIBLE_IOCTL(RTC_PIE_ON)
-COMPATIBLE_IOCTL(RTC_PIE_OFF)
-COMPATIBLE_IOCTL(RTC_WIE_ON)
-COMPATIBLE_IOCTL(RTC_WIE_OFF)
-COMPATIBLE_IOCTL(RTC_ALM_SET)
-COMPATIBLE_IOCTL(RTC_ALM_READ)
-COMPATIBLE_IOCTL(RTC_RD_TIME)
-COMPATIBLE_IOCTL(RTC_SET_TIME)
-COMPATIBLE_IOCTL(RTC_WKALM_SET)
-COMPATIBLE_IOCTL(RTC_WKALM_RD)
/*
* These two are only for the sbus rtc driver, but
* hwclock tries them on every rtc device first when
@@ -806,24 +759,16 @@ IGNORE_IOCTL(FBIOGCURSOR32)
static long do_ioctl_trans(unsigned int cmd,
unsigned long arg, struct file *file)
{
- void __user *argp = compat_ptr(arg);
-
switch (cmd) {
#ifdef CONFIG_BLOCK
case SG_IO:
- return sg_ioctl_trans(file, cmd, argp);
+ return sg_ioctl_trans(file, cmd, compat_ptr(arg));
case SG_GET_REQUEST_TABLE:
- return sg_grt_trans(file, cmd, argp);
+ return sg_grt_trans(file, cmd, compat_ptr(arg));
case MTIOCGET32:
case MTIOCPOS32:
- return mt_ioctl_trans(file, cmd, argp);
+ return mt_ioctl_trans(file, cmd, compat_ptr(arg));
#endif
- /* Not implemented in the native kernel */
- case RTC_IRQP_READ32:
- case RTC_IRQP_SET32:
- case RTC_EPOCH_READ32:
- case RTC_EPOCH_SET32:
- return rtc_ioctl(file, cmd, argp);
}
/*
--
2.20.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 00/26] compat_ioctl: cleanups
2019-04-16 20:19 [PATCH v3 00/26] compat_ioctl: cleanups Arnd Bergmann
2019-04-16 20:19 ` [PATCH v3 07/26] compat_ioctl: move rtc handling into rtc-dev.c Arnd Bergmann
@ 2019-04-16 22:33 ` Douglas Gilbert
1 sibling, 0 replies; 3+ messages in thread
From: Douglas Gilbert @ 2019-04-16 22:33 UTC (permalink / raw)
To: Arnd Bergmann, Alexander Viro
Cc: linux-fsdevel, y2038, linux-kernel, David S. Miller,
Greg Kroah-Hartman, Karsten Keil, James E.J. Bottomley,
Martin K. Petersen, Marcel Holtmann, netdev, devel,
linux-integrity, qat-linux, linux-crypto, linux-media, dri-devel,
linux1394-devel, amd-gfx, linux-input, linux-usb,
linux-arm-kernel, linux-ide, linux-iio, linux-rdma, linuxppc-dev,
linux-mtd, linux-ppp, linux-nvme, platform-driver-x86,
linux-remoteproc, linux-rtc, linux-s390, sparclinux, linux-scsi,
linux-fbdev, linux-btrfs, ceph-devel, linux-bluetooth,
linux-wireless, alsa-devel
On 2019-04-16 4:19 p.m., Arnd Bergmann wrote:
> Hi Al,
>
> It took me way longer than I had hoped to revisit this series, see
> https://lore.kernel.org/lkml/20180912150142.157913-1-arnd@arndb.de/
> for the previously posted version.
>
> I've come to the point where all conversion handlers and most
> COMPATIBLE_IOCTL() entries are gone from this file, but for
> now, this series only has the parts that have either been reviewed
> previously, or that are simple enough to include.
>
> The main missing piece is the SG_IO/SG_GET_REQUEST_TABLE conversion.
> I'll post the patches I made for that later, as they need more
> testing and review from the scsi maintainers.
Perhaps you could look at the document in this url:
http://sg.danny.cz/sg/sg_v40.html
It is work-in-progress to modernize the SCSI generic driver. It
extends ioctl(sg_fd, SG_IO, &pt_obj) to additionally accept the sg v4
interface as defined in include/uapi/linux/bsg.h . Currently only the
bsg driver uses the sg v4 interface. Since struct sg_io_v4 is all
explicitly sized integers, I'm guessing it is immune "compat" problems.
[I can see no reference to bsg nor struct sg_io_v4 in the current
fs/compat_ioctl.c file.]
Other additions described in the that document are these new ioctls:
- SG_IOSUBMIT ultimately to replace write(sg_fd, ...)
- SG_IORECEIVE to replace read(sg_fd, ...)
- SG_IOABORT abort SCSI cmd in progress; new functionality
- SG_SET_GET_EXTENDED has associated struct sg_extended_info
The first three take a pointer to a struct sg_io_hdr (v3 interface) or
a struct sg_io_v4 object. Both objects start with a 32 bit integer:
'S' identifies the v3 interface while 'Q' identifies the v4 interface.
The SG_SET_GET_EXTENDED ioctl takes a pointer to a struct
sg_extended_info object which contains explicitly sized integers so it
may also be immune from "compat" problems. The ioctls section (13) of
that document referenced above has a table showing how many "sets and
gets" are hiding in the SG_SET_GET_EXTENDED ioctl.
BTW No change is proposed for this case:
ioctl(normal_block_device, SG_IO, &sg_v3_obj)
which is handled by block/scsi_ioctl.c
This would be a good time for me to address any "compat" concerns in the
proposed sg driver update.
Doug Gilbert
> I hope you can still take these for the coming merge window, unless
> new problems come up.
>
> Arnd
>
> Arnd Bergmann (26):
> compat_ioctl: pppoe: fix PPPOEIOCSFWD handling
> compat_ioctl: move simple ppp command handling into driver
> compat_ioctl: avoid unused function warning for do_ioctl
> compat_ioctl: move PPPIOCSCOMPRESS32 to ppp-generic.c
> compat_ioctl: move PPPIOCSPASS32/PPPIOCSACTIVE32 to ppp_generic.c
> compat_ioctl: handle PPPIOCGIDLE for 64-bit time_t
> compat_ioctl: move rtc handling into rtc-dev.c
> compat_ioctl: add compat_ptr_ioctl()
> compat_ioctl: move drivers to compat_ptr_ioctl
> compat_ioctl: use correct compat_ptr() translation in drivers
> ceph: fix compat_ioctl for ceph_dir_operations
> compat_ioctl: move more drivers to compat_ptr_ioctl
> compat_ioctl: move tape handling into drivers
> compat_ioctl: move ATYFB_CLK handling to atyfb driver
> compat_ioctl: move isdn/capi ioctl translation into driver
> compat_ioctl: move rfcomm handlers into driver
> compat_ioctl: move hci_sock handlers into driver
> compat_ioctl: remove HCIUART handling
> compat_ioctl: remove HIDIO translation
> compat_ioctl: remove translation for sound ioctls
> compat_ioctl: remove IGNORE_IOCTL()
> compat_ioctl: remove /dev/random commands
> compat_ioctl: remove joystick ioctl translation
> compat_ioctl: remove PCI ioctl translation
> compat_ioctl: remove /dev/raw ioctl translation
> compat_ioctl: remove last RAID handling code
>
> Documentation/networking/ppp_generic.txt | 2 +
> arch/um/drivers/hostaudio_kern.c | 1 +
> drivers/android/binder.c | 2 +-
> drivers/char/ppdev.c | 12 +-
> drivers/char/random.c | 1 +
> drivers/char/tpm/tpm_vtpm_proxy.c | 12 +-
> drivers/crypto/qat/qat_common/adf_ctl_drv.c | 2 +-
> drivers/dma-buf/dma-buf.c | 4 +-
> drivers/dma-buf/sw_sync.c | 2 +-
> drivers/dma-buf/sync_file.c | 2 +-
> drivers/firewire/core-cdev.c | 12 +-
> drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +-
> drivers/hid/hidraw.c | 4 +-
> drivers/hid/usbhid/hiddev.c | 11 +-
> drivers/hwtracing/stm/core.c | 12 +-
> drivers/ide/ide-tape.c | 31 +-
> drivers/iio/industrialio-core.c | 2 +-
> drivers/infiniband/core/uverbs_main.c | 4 +-
> drivers/isdn/capi/capi.c | 31 +
> drivers/isdn/i4l/isdn_ppp.c | 14 +-
> drivers/media/rc/lirc_dev.c | 4 +-
> drivers/mfd/cros_ec_dev.c | 4 +-
> drivers/misc/cxl/flash.c | 8 +-
> drivers/misc/genwqe/card_dev.c | 23 +-
> drivers/misc/mei/main.c | 22 +-
> drivers/misc/vmw_vmci/vmci_host.c | 2 +-
> drivers/mtd/ubi/cdev.c | 36 +-
> drivers/net/ppp/ppp_generic.c | 99 +++-
> drivers/net/ppp/pppoe.c | 7 +
> drivers/net/ppp/pptp.c | 3 +
> drivers/net/tap.c | 12 +-
> drivers/nvdimm/bus.c | 4 +-
> drivers/nvme/host/core.c | 2 +-
> drivers/pci/switch/switchtec.c | 2 +-
> drivers/platform/x86/wmi.c | 2 +-
> drivers/rpmsg/rpmsg_char.c | 4 +-
> drivers/rtc/dev.c | 13 +-
> drivers/rtc/rtc-vr41xx.c | 10 +
> drivers/s390/char/tape_char.c | 41 +-
> drivers/sbus/char/display7seg.c | 2 +-
> drivers/sbus/char/envctrl.c | 4 +-
> drivers/scsi/3w-xxxx.c | 4 +-
> drivers/scsi/cxlflash/main.c | 2 +-
> drivers/scsi/esas2r/esas2r_main.c | 2 +-
> drivers/scsi/megaraid/megaraid_mm.c | 28 +-
> drivers/scsi/osst.c | 34 +-
> drivers/scsi/pmcraid.c | 4 +-
> drivers/scsi/st.c | 35 +-
> drivers/staging/android/ion/ion.c | 4 +-
> drivers/staging/pi433/pi433_if.c | 12 +-
> drivers/staging/vme/devices/vme_user.c | 2 +-
> drivers/tee/tee_core.c | 2 +-
> drivers/usb/class/cdc-wdm.c | 2 +-
> drivers/usb/class/usbtmc.c | 4 +-
> drivers/usb/core/devio.c | 16 +-
> drivers/usb/gadget/function/f_fs.c | 12 +-
> drivers/vfio/vfio.c | 39 +-
> drivers/vhost/net.c | 12 +-
> drivers/vhost/scsi.c | 12 +-
> drivers/vhost/test.c | 12 +-
> drivers/vhost/vsock.c | 12 +-
> drivers/video/fbdev/aty/atyfb_base.c | 12 +-
> drivers/virt/fsl_hypervisor.c | 2 +-
> fs/btrfs/super.c | 2 +-
> fs/ceph/dir.c | 1 +
> fs/ceph/file.c | 2 +-
> fs/compat_ioctl.c | 602 +-------------------
> fs/fat/file.c | 13 +-
> fs/fuse/dev.c | 2 +-
> fs/notify/fanotify/fanotify_user.c | 2 +-
> fs/userfaultfd.c | 2 +-
> include/linux/fs.h | 7 +
> include/linux/if_pppox.h | 2 +
> include/linux/mtio.h | 58 ++
> include/uapi/linux/ppp-ioctl.h | 2 +
> include/uapi/linux/ppp_defs.h | 14 +
> net/bluetooth/hci_sock.c | 21 +-
> net/bluetooth/rfcomm/sock.c | 14 +-
> net/l2tp/l2tp_ppp.c | 3 +
> net/rfkill/core.c | 2 +-
> sound/core/oss/pcm_oss.c | 4 +
> sound/oss/dmasound/dmasound_core.c | 2 +
> 82 files changed, 452 insertions(+), 1034 deletions(-)
> create mode 100644 include/linux/mtio.h
>
^ permalink raw reply [flat|nested] 3+ messages in thread