From 535f8d65d808421a6e1730990e39d41885b1f951 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 12 Nov 2005 12:10:54 -0800 Subject: [SPARC]: Fix RTC compat ioctl kernel log spam. On Fri, Nov 11, 2005 at 12:58:40PM -0800, David S. Miller wrote: > > This change: > > diff-tree 8ca2bdc7a98b9584ac5f640761501405154171c7 (from feee207e44d3643d19e648aAuthor: Christoph Hellwig > Date: Wed Nov 9 12:07:18 2005 -0800 > > [SPARC] sbus rtc: implement ->compat_ioctl > > Signed-off-by: Christoph Hellwig > Signed-off-by: David S. Miller > > results in the console now getting spewed on sparc64 systems > with messages like: > > [ 11.968298] ioctl32(hwclock:464): Unknown cmd fd(3) cmd(401c7014){00} arg(efc > What's happening is hwclock tries first the SBUS rtc device ioctls > then the normal rtc driver ones. > > So things actually worked better when we had the SBUS rtc compat ioctl > directly handled via the generic compat ioctl code. > > There are _so_ many rtc drivers in the kernel implementing the > generic rtc ioctls that I don't think putting a ->compat_ioctl > into all of them to fix this problem is feasible. Unless we > write a single rtc_compat_ioctl(), export it to modules, and hook > it into all of those somehow. > > But even that doesn't appear to have any pretty implementation. > > Any better ideas? We had similar problems with other ioctls where userspace did things like that. What we did there was to put the compat handler to generic code. The patch below does that, adding a big comment about what's going on and removing the COMPAT_IOCTL entires for these on powerpc that not only weren't ever useful but are duplicated now aswell. Signed-off-by: Christoph Hellwig Signed-off-by: David S. Miller --- arch/powerpc/kernel/ioctl32.c | 4 ---- drivers/sbus/char/rtc.c | 22 ---------------------- include/linux/compat_ioctl.h | 8 ++++++++ 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/arch/powerpc/kernel/ioctl32.c b/arch/powerpc/kernel/ioctl32.c index 3fa6a93adbd00..0fa3d27fef013 100644 --- a/arch/powerpc/kernel/ioctl32.c +++ b/arch/powerpc/kernel/ioctl32.c @@ -40,10 +40,6 @@ IOCTL_TABLE_START #define DECLARES #include "compat_ioctl.c" -/* Little p (/dev/rtc, /dev/envctrl, etc.) */ -COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */ -COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */ - IOCTL_TABLE_END int ioctl_table_size = ARRAY_SIZE(ioctl_start); diff --git a/drivers/sbus/char/rtc.c b/drivers/sbus/char/rtc.c index 5774bdd0e26fa..9b988baf0b519 100644 --- a/drivers/sbus/char/rtc.c +++ b/drivers/sbus/char/rtc.c @@ -210,27 +210,6 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, } } -static long rtc_compat_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - int rval = -ENOIOCTLCMD; - - switch (cmd) { - /* - * These two are specific to this driver, the generic rtc ioctls - * are hanlded elsewhere. - */ - case RTCGET: - case RTCSET: - lock_kernel(); - rval = rtc_ioctl(file->f_dentry->d_inode, file, cmd, arg); - unlock_kernel(); - break; - } - - return rval; -} - static int rtc_open(struct inode *inode, struct file *file) { int ret; @@ -258,7 +237,6 @@ static struct file_operations rtc_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .ioctl = rtc_ioctl, - .compat_ioctl = rtc_compat_ioctl, .open = rtc_open, .release = rtc_release, }; diff --git a/include/linux/compat_ioctl.h b/include/linux/compat_ioctl.h index 2209ad3499a3b..174f3379e5d9a 100644 --- a/include/linux/compat_ioctl.h +++ b/include/linux/compat_ioctl.h @@ -259,6 +259,14 @@ 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 + * running on sparc. On other architectures the entries + * are useless but harmless. + */ +COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */ +COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */ /* Little m */ COMPATIBLE_IOCTL(MTIOCTOP) /* Socket level stuff */ -- cgit 1.2.3-korg From 9ffb83bcc5c5337f980dc0576bf13ac9bd4fd33d Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 12 Nov 2005 12:11:12 -0800 Subject: [SBUSFB]: implement ->compat_ioctl This patch adds a new function, sbusfb_compat_ioctl() to drivers/video/sbuslib.c and uses it as compat_ioctl in all sbus fb drivers This remove the last per-arch compat ioctl bits in arch/sparc64/kernel/ioctl32.c so it would be nice if people could test if this actually copiles and works and if yes apply it :) Signed-off-by: Christoph Hellwig Signed-off-by: David S. Miller --- arch/sparc64/kernel/ioctl32.c | 92 ------------------------------------ drivers/video/bw2.c | 3 ++ drivers/video/cg14.c | 3 ++ drivers/video/cg3.c | 3 ++ drivers/video/cg6.c | 3 ++ drivers/video/ffb.c | 3 ++ drivers/video/leo.c | 3 ++ drivers/video/p9100.c | 3 ++ drivers/video/sbuslib.c | 107 ++++++++++++++++++++++++++++++++++++++++++ drivers/video/sbuslib.h | 2 + drivers/video/tcx.c | 3 ++ 11 files changed, 133 insertions(+), 92 deletions(-) diff --git a/arch/sparc64/kernel/ioctl32.c b/arch/sparc64/kernel/ioctl32.c index e62214354bb52..196b208665a22 100644 --- a/arch/sparc64/kernel/ioctl32.c +++ b/arch/sparc64/kernel/ioctl32.c @@ -12,86 +12,10 @@ #define INCLUDES #include "compat_ioctl.c" #include -#include - -/* Use this to get at 32-bit user passed pointers. - * See sys_sparc32.c for description about it. - */ -#define A(__x) compat_ptr(__x) #define CODE #include "compat_ioctl.c" -struct fbcmap32 { - int index; /* first element (0 origin) */ - int count; - u32 red; - u32 green; - u32 blue; -}; - -#define FBIOPUTCMAP32 _IOW('F', 3, struct fbcmap32) -#define FBIOGETCMAP32 _IOW('F', 4, struct fbcmap32) - -static int fbiogetputcmap(unsigned int fd, unsigned int cmd, unsigned long arg) -{ - struct fbcmap32 __user *argp = (void __user *)arg; - struct fbcmap __user *p = compat_alloc_user_space(sizeof(*p)); - u32 addr; - int ret; - - ret = copy_in_user(p, argp, 2 * sizeof(int)); - ret |= get_user(addr, &argp->red); - ret |= put_user(compat_ptr(addr), &p->red); - ret |= get_user(addr, &argp->green); - ret |= put_user(compat_ptr(addr), &p->green); - ret |= get_user(addr, &argp->blue); - ret |= put_user(compat_ptr(addr), &p->blue); - if (ret) - return -EFAULT; - return sys_ioctl(fd, (cmd == FBIOPUTCMAP32) ? FBIOPUTCMAP_SPARC : FBIOGETCMAP_SPARC, (unsigned long)p); -} - -struct fbcursor32 { - short set; /* what to set, choose from the list above */ - short enable; /* cursor on/off */ - struct fbcurpos pos; /* cursor position */ - struct fbcurpos hot; /* cursor hot spot */ - struct fbcmap32 cmap; /* color map info */ - struct fbcurpos size; /* cursor bit map size */ - u32 image; /* cursor image bits */ - u32 mask; /* cursor mask bits */ -}; - -#define FBIOSCURSOR32 _IOW('F', 24, struct fbcursor32) -#define FBIOGCURSOR32 _IOW('F', 25, struct fbcursor32) - -static int fbiogscursor(unsigned int fd, unsigned int cmd, unsigned long arg) -{ - struct fbcursor __user *p = compat_alloc_user_space(sizeof(*p)); - struct fbcursor32 __user *argp = (void __user *)arg; - compat_uptr_t addr; - int ret; - - ret = copy_in_user(p, argp, - 2 * sizeof (short) + 2 * sizeof(struct fbcurpos)); - ret |= copy_in_user(&p->size, &argp->size, sizeof(struct fbcurpos)); - ret |= copy_in_user(&p->cmap, &argp->cmap, 2 * sizeof(int)); - ret |= get_user(addr, &argp->cmap.red); - ret |= put_user(compat_ptr(addr), &p->cmap.red); - ret |= get_user(addr, &argp->cmap.green); - ret |= put_user(compat_ptr(addr), &p->cmap.green); - ret |= get_user(addr, &argp->cmap.blue); - ret |= put_user(compat_ptr(addr), &p->cmap.blue); - ret |= get_user(addr, &argp->mask); - ret |= put_user(compat_ptr(addr), &p->mask); - ret |= get_user(addr, &argp->image); - ret |= put_user(compat_ptr(addr), &p->image); - if (ret) - return -EFAULT; - return sys_ioctl (fd, FBIOSCURSOR, (unsigned long)p); -} - #define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL((cmd),sys_ioctl) #define HANDLE_IOCTL(cmd,handler) { (cmd), (ioctl_trans_handler_t)(handler), NULL }, #define IOCTL_TABLE_START \ @@ -103,22 +27,6 @@ IOCTL_TABLE_START #include #define DECLARES #include "compat_ioctl.c" -COMPATIBLE_IOCTL(FBIOGTYPE) -COMPATIBLE_IOCTL(FBIOSATTR) -COMPATIBLE_IOCTL(FBIOGATTR) -COMPATIBLE_IOCTL(FBIOSVIDEO) -COMPATIBLE_IOCTL(FBIOGVIDEO) -COMPATIBLE_IOCTL(FBIOGCURSOR32) /* This is not implemented yet. Later it should be converted... */ -COMPATIBLE_IOCTL(FBIOSCURPOS) -COMPATIBLE_IOCTL(FBIOGCURPOS) -COMPATIBLE_IOCTL(FBIOGCURMAX) -/* Little k */ -/* Little v, the video4linux ioctls */ -/* And these ioctls need translation */ -/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */ -HANDLE_IOCTL(FBIOPUTCMAP32, fbiogetputcmap) -HANDLE_IOCTL(FBIOGETCMAP32, fbiogetputcmap) -HANDLE_IOCTL(FBIOSCURSOR32, fbiogscursor) #if 0 HANDLE_IOCTL(RTC32_IRQP_READ, do_rtc_ioctl) HANDLE_IOCTL(RTC32_IRQP_SET, do_rtc_ioctl) diff --git a/drivers/video/bw2.c b/drivers/video/bw2.c index f53bf3ba12789..d3728f60961e7 100644 --- a/drivers/video/bw2.c +++ b/drivers/video/bw2.c @@ -51,6 +51,9 @@ static struct fb_ops bw2_ops = { .fb_imageblit = cfb_imageblit, .fb_mmap = bw2_mmap, .fb_ioctl = bw2_ioctl, +#ifdef CONFIG_COMPAT + .fb_compat_ioctl = sbusfb_compat_ioctl, +#endif }; /* OBio addresses for the bwtwo registers */ diff --git a/drivers/video/cg14.c b/drivers/video/cg14.c index 030d4b13b1c20..1bed50f2a2767 100644 --- a/drivers/video/cg14.c +++ b/drivers/video/cg14.c @@ -49,6 +49,9 @@ static struct fb_ops cg14_ops = { .fb_imageblit = cfb_imageblit, .fb_mmap = cg14_mmap, .fb_ioctl = cg14_ioctl, +#ifdef CONFIG_COMPAT + .fb_compat_ioctl = sbusfb_compat_ioctl, +#endif }; #define CG14_MCR_INTENABLE_SHIFT 7 diff --git a/drivers/video/cg3.c b/drivers/video/cg3.c index b94eee8c42d5d..a1354e7e0513e 100644 --- a/drivers/video/cg3.c +++ b/drivers/video/cg3.c @@ -50,6 +50,9 @@ static struct fb_ops cg3_ops = { .fb_imageblit = cfb_imageblit, .fb_mmap = cg3_mmap, .fb_ioctl = cg3_ioctl, +#ifdef CONFIG_COMPAT + .fb_compat_ioctl = sbusfb_compat_ioctl, +#endif }; diff --git a/drivers/video/cg6.c b/drivers/video/cg6.c index 414c4409e9246..9debe642fd2f8 100644 --- a/drivers/video/cg6.c +++ b/drivers/video/cg6.c @@ -54,6 +54,9 @@ static struct fb_ops cg6_ops = { .fb_sync = cg6_sync, .fb_mmap = cg6_mmap, .fb_ioctl = cg6_ioctl, +#ifdef CONFIG_COMPAT + .fb_compat_ioctl = sbusfb_compat_ioctl, +#endif }; /* Offset of interesting structures in the OBIO space */ diff --git a/drivers/video/ffb.c b/drivers/video/ffb.c index 04417dc16c2e3..2584daec7bbf2 100644 --- a/drivers/video/ffb.c +++ b/drivers/video/ffb.c @@ -57,6 +57,9 @@ static struct fb_ops ffb_ops = { .fb_sync = ffb_sync, .fb_mmap = ffb_mmap, .fb_ioctl = ffb_ioctl, +#ifdef CONFIG_COMPAT + .fb_compat_ioctl = sbusfb_compat_ioctl, +#endif }; /* Register layout and definitions */ diff --git a/drivers/video/leo.c b/drivers/video/leo.c index 84a7fe435bb82..376d4a171ec7b 100644 --- a/drivers/video/leo.c +++ b/drivers/video/leo.c @@ -51,6 +51,9 @@ static struct fb_ops leo_ops = { .fb_imageblit = cfb_imageblit, .fb_mmap = leo_mmap, .fb_ioctl = leo_ioctl, +#ifdef CONFIG_COMPAT + .fb_compat_ioctl = sbusfb_compat_ioctl, +#endif }; #define LEO_OFF_LC_SS0_KRN 0x00200000UL diff --git a/drivers/video/p9100.c b/drivers/video/p9100.c index 9aaf65fb623ae..18bcda23d2cf7 100644 --- a/drivers/video/p9100.c +++ b/drivers/video/p9100.c @@ -48,6 +48,9 @@ static struct fb_ops p9100_ops = { .fb_imageblit = cfb_imageblit, .fb_mmap = p9100_mmap, .fb_ioctl = p9100_ioctl, +#ifdef CONFIG_COMPAT + .fb_compat_ioctl = sbusfb_compat_ioctl, +#endif }; /* P9100 control registers */ diff --git a/drivers/video/sbuslib.c b/drivers/video/sbuslib.c index 34f72edba820e..646c43f921c55 100644 --- a/drivers/video/sbuslib.c +++ b/drivers/video/sbuslib.c @@ -3,6 +3,7 @@ * Copyright (C) 2003 David S. Miller (davem@redhat.com) */ +#include #include #include #include @@ -182,3 +183,109 @@ int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg, }; } EXPORT_SYMBOL(sbusfb_ioctl_helper); + +#ifdef CONFIG_COMPAT +struct fbcmap32 { + int index; /* first element (0 origin) */ + int count; + u32 red; + u32 green; + u32 blue; +}; + +#define FBIOPUTCMAP32 _IOW('F', 3, struct fbcmap32) +#define FBIOGETCMAP32 _IOW('F', 4, struct fbcmap32) + +static int fbiogetputcmap(struct file *file, struct fb_info *info, + unsigned int cmd, unsigned long arg) +{ + struct fbcmap32 __user *argp = (void __user *)arg; + struct fbcmap __user *p = compat_alloc_user_space(sizeof(*p)); + u32 addr; + int ret; + + ret = copy_in_user(p, argp, 2 * sizeof(int)); + ret |= get_user(addr, &argp->red); + ret |= put_user(compat_ptr(addr), &p->red); + ret |= get_user(addr, &argp->green); + ret |= put_user(compat_ptr(addr), &p->green); + ret |= get_user(addr, &argp->blue); + ret |= put_user(compat_ptr(addr), &p->blue); + if (ret) + return -EFAULT; + return info->fbops->fb_ioctl(file->f_dentry->d_inode, file, + (cmd == FBIOPUTCMAP32) ? + FBIOPUTCMAP_SPARC : FBIOGETCMAP_SPARC, + (unsigned long)p, info); +} + +struct fbcursor32 { + short set; /* what to set, choose from the list above */ + short enable; /* cursor on/off */ + struct fbcurpos pos; /* cursor position */ + struct fbcurpos hot; /* cursor hot spot */ + struct fbcmap32 cmap; /* color map info */ + struct fbcurpos size; /* cursor bit map size */ + u32 image; /* cursor image bits */ + u32 mask; /* cursor mask bits */ +}; + +#define FBIOSCURSOR32 _IOW('F', 24, struct fbcursor32) +#define FBIOGCURSOR32 _IOW('F', 25, struct fbcursor32) + +static int fbiogscursor(struct file *file, struct fb_info *info, + unsigned long arg) +{ + struct fbcursor __user *p = compat_alloc_user_space(sizeof(*p)); + struct fbcursor32 __user *argp = (void __user *)arg; + compat_uptr_t addr; + int ret; + + ret = copy_in_user(p, argp, + 2 * sizeof (short) + 2 * sizeof(struct fbcurpos)); + ret |= copy_in_user(&p->size, &argp->size, sizeof(struct fbcurpos)); + ret |= copy_in_user(&p->cmap, &argp->cmap, 2 * sizeof(int)); + ret |= get_user(addr, &argp->cmap.red); + ret |= put_user(compat_ptr(addr), &p->cmap.red); + ret |= get_user(addr, &argp->cmap.green); + ret |= put_user(compat_ptr(addr), &p->cmap.green); + ret |= get_user(addr, &argp->cmap.blue); + ret |= put_user(compat_ptr(addr), &p->cmap.blue); + ret |= get_user(addr, &argp->mask); + ret |= put_user(compat_ptr(addr), &p->mask); + ret |= get_user(addr, &argp->image); + ret |= put_user(compat_ptr(addr), &p->image); + if (ret) + return -EFAULT; + return info->fbops->fb_ioctl(file->f_dentry->d_inode, file, + FBIOSCURSOR, (unsigned long)p, info); +} + +long sbusfb_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long arg, struct fb_info *info) +{ + switch (cmd) { + case FBIOGTYPE: + case FBIOSATTR: + case FBIOGATTR: + case FBIOSVIDEO: + case FBIOGVIDEO: + case FBIOGCURSOR32: /* This is not implemented yet. + Later it should be converted... */ + case FBIOSCURPOS: + case FBIOGCURPOS: + case FBIOGCURMAX: + return info->fbops->fb_ioctl(file->f_dentry->d_inode, + file, cmd, arg, info); + case FBIOPUTCMAP32: + return fbiogetputcmap(file, info, cmd, arg); + case FBIOGETCMAP32: + return fbiogetputcmap(file, info, cmd, arg); + case FBIOSCURSOR32: + return fbiogscursor(file, info, arg); + default: + return -ENOIOCTLCMD; + } +} +EXPORT_SYMBOL(sbusfb_compat_ioctl); +#endif diff --git a/drivers/video/sbuslib.h b/drivers/video/sbuslib.h index a6aa33ba09d6e..b470e52ce9e2f 100644 --- a/drivers/video/sbuslib.h +++ b/drivers/video/sbuslib.h @@ -20,5 +20,7 @@ extern int sbusfb_mmap_helper(struct sbus_mmap_map *map, int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg, struct fb_info *info, int type, int fb_depth, unsigned long fb_size); +long sbusfb_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long arg, struct fb_info *info); #endif /* _SBUSLIB_H */ diff --git a/drivers/video/tcx.c b/drivers/video/tcx.c index 59fff29bc02e5..fe4f63f3849d5 100644 --- a/drivers/video/tcx.c +++ b/drivers/video/tcx.c @@ -52,6 +52,9 @@ static struct fb_ops tcx_ops = { .fb_imageblit = cfb_imageblit, .fb_mmap = tcx_mmap, .fb_ioctl = tcx_ioctl, +#ifdef CONFIG_COMPAT + .fb_compat_ioctl = sbusfb_compat_ioctl, +#endif }; /* THC definitions */ -- cgit 1.2.3-korg