Skip to contentSkip to conversation

hpet header sanitization

PATCH In review Randy.Dunlap 6 participants 13 messages Mar 21, 2006 – Mar 23, 2006 Hpet: High Precision Event Timers driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hpet header sanitization

From: Randy Dunlap <[email protected]>

Add __KERNEL__ block.
Use __KERNEL__ to allow ioctl interface to be usable.

---
 include/linux/hpet.h |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)
include/linux/hpet.h +20 -16
@@ -3,6 +3,8 @@
 
 #include <linux/compiler.h>
 
+#ifdef __KERNEL__
+
 /*
  * Offsets into HPET Registers
  */
@@ -85,22 +87,6 @@ struct hpet {
 #define	Tn_FSB_INT_ADDR_SHIFT		(32UL)
 #define	Tn_FSB_INT_VAL_MASK		(0x00000000ffffffffULL)
 
-struct hpet_info {
-	unsigned long hi_ireqfreq;	/* Hz */
-	unsigned long hi_flags;	/* information */
-	unsigned short hi_hpet;
-	unsigned short hi_timer;
-};
-
-#define	HPET_INFO_PERIODIC	0x0001	/* timer is periodic */
-
-#define	HPET_IE_ON	_IO('h', 0x01)	/* interrupt on */
-#define	HPET_IE_OFF	_IO('h', 0x02)	/* interrupt off */
-#define	HPET_INFO	_IOR('h', 0x03, struct hpet_info)
-#define	HPET_EPI	_IO('h', 0x04)	/* enable periodic */
-#define	HPET_DPI	_IO('h', 0x05)	/* disable periodic */
-#define	HPET_IRQFREQ	_IOW('h', 0x6, unsigned long)	/* IRQFREQ usec */
-
 /*
  * exported interfaces
  */
@@ -133,4 +119,22 @@ int hpet_register(struct hpet_task *, in
 int hpet_unregister(struct hpet_task *);
 int hpet_control(struct hpet_task *, unsigned int, unsigned long);
 
+#endif /* __KERNEL__ */
+
+struct hpet_info {
+	unsigned long hi_ireqfreq;	/* Hz */
+	unsigned long hi_flags;	/* information */
+	unsigned short hi_hpet;
+	unsigned short hi_timer;
+};
+
+#define	HPET_INFO_PERIODIC	0x0001	/* timer is periodic */
+
+#define	HPET_IE_ON	_IO('h', 0x01)	/* interrupt on */
+#define	HPET_IE_OFF	_IO('h', 0x02)	/* interrupt off */
+#define	HPET_INFO	_IOR('h', 0x03, struct hpet_info)
+#define	HPET_EPI	_IO('h', 0x04)	/* enable periodic */
+#define	HPET_DPI	_IO('h', 0x05)	/* disable periodic */
+#define	HPET_IRQFREQ	_IOW('h', 0x6, unsigned long)	/* IRQFREQ usec */
+
 #endif				/* !__HPET__ */

---

#1 lore raw
Quoted 5 lines · Randy.Dunlap

From: Randy Dunlap <[email protected]>

Add __KERNEL__ block.
Use __KERNEL__ to allow ioctl interface to be usable.

hm, why?

My general approach to __KERNEL__ fixes is to not support new includers of kernel headers but to accept patches which fix up existing applications of __KERNEL__.

It's basically a compromise between the dont-include-kernel-headers-from-userspace fundamentalists and the but-i-want-my-stuff-to-work pragmatists ;)

But hpet.h never had __KERNEL__, so there's no regression here.

That being said, it looks like a sensible change - let's see if we can sneak it in without the fundies noticing.

oops.

#2 lore raw
Quoted 8 lines · On Tue, 21 Mar 2006 16:13:03 -0800 Andrew Morton wrote:
Quoted 5 lines · Randy.Dunlap

From: Randy Dunlap <[email protected]>

Add __KERNEL__ block.
Use __KERNEL__ to allow ioctl interface to be usable.

hm, why?

because there is a test/example source file in (inside) Documentation/hpet.txt that won't build otherwise. And because hpet.h contains _userspace_ ioctl interface struct and macros...

Quoted 4 lines

My general approach to __KERNEL__ fixes is to not support new includers of kernel headers but to accept patches which fix up existing applications of __KERNEL__.

Quoted 8 lines

It's basically a compromise between the dont-include-kernel-headers-from-userspace fundamentalists and the but-i-want-my-stuff-to-work pragmatists ;)

But hpet.h never had __KERNEL__, so there's no regression here.

That being said, it looks like a sensible change - let's see if we can sneak it in without the fundies noticing.

---
~Randy

#3 lore raw
Quoted 9 lines · Randy.Dunlap
Quoted 7 lines · On Tue, 21 Mar 2006 16:13:03 -0800 Andrew Morton wrote:
Quoted 5 lines · Randy.Dunlap

From: Randy Dunlap <[email protected]>

Add __KERNEL__ block.
Use __KERNEL__ to allow ioctl interface to be usable.

Quoted 6 lines
Quoted 1 line

hm, why?

because there is a test/example source file in (inside) Documentation/hpet.txt that won't build otherwise. And because hpet.h contains _userspace_ ioctl interface struct and macros...

then please split the header in 2 parts; one for the kernel and one for userspace

either put both here, or move the kernel one to the directory where the source code is

#4 lore raw
Quoted 12 lines · On Wed, 22 Mar 2006 10:02:19 +0100 Arjan van de Ven wrote:
Quoted 11 lines · Randy.Dunlap
Quoted 8 lines · On Tue, 21 Mar 2006 16:13:03 -0800 Andrew Morton wrote:
Quoted 5 lines · Randy.Dunlap

From: Randy Dunlap <[email protected]>

Add __KERNEL__ block.
Use __KERNEL__ to allow ioctl interface to be usable.

hm, why?

Quoted 8 lines
Quoted 4 lines

because there is a test/example source file in (inside) Documentation/hpet.txt that won't build otherwise. And because hpet.h contains _userspace_ ioctl interface struct and macros...

then please split the header in 2 parts; one for the kernel and one for userspace

so would you tell me what the purpose (use) of __KERNEL__ is meant to be, please?

Fortunately there are only about 165 header files in include/ that use both __KERNEL__ and _IO() macros (out of 5425 header files).

Quoted 2 lines

either put both here, or move the kernel one to the directory where the source code is

---
~Randy

#5 lore raw
Quoted 20 lines · Randy.Dunlap
Quoted 18 lines · On Wed, 22 Mar 2006 10:02:19 +0100 Arjan van de Ven wrote:
Quoted 15 lines · Randy.Dunlap
Quoted 8 lines · On Tue, 21 Mar 2006 16:13:03 -0800 Andrew Morton wrote:
Quoted 5 lines · Randy.Dunlap

From: Randy Dunlap <[email protected]>

Add __KERNEL__ block.
Use __KERNEL__ to allow ioctl interface to be usable.

hm, why?

because there is a test/example source file in (inside) Documentation/hpet.txt that won't build otherwise. And because hpet.h contains _userspace_ ioctl interface struct and macros...

Quoted 5 lines
Quoted 2 lines

then please split the header in 2 parts; one for the kernel and one for userspace

so would you tell me what the purpose (use) of __KERNEL__ is meant to be, please?

for legacy headers.. the same ;)
Thats no reason to fix up new cases... things should get better not just get a small rubber bandaid...

#6 lore raw
Quoted 21 lines · On Wed, 22 Mar 2006 21:08:02 +0100 Arjan van de Ven wrote:
Quoted 20 lines · Randy.Dunlap
Quoted 18 lines · On Wed, 22 Mar 2006 10:02:19 +0100 Arjan van de Ven wrote:
Quoted 15 lines · Randy.Dunlap
Quoted 8 lines · On Tue, 21 Mar 2006 16:13:03 -0800 Andrew Morton wrote:
Quoted 5 lines · Randy.Dunlap

From: Randy Dunlap <[email protected]>

Add __KERNEL__ block.
Use __KERNEL__ to allow ioctl interface to be usable.

hm, why?

because there is a test/example source file in (inside) Documentation/hpet.txt that won't build otherwise. And because hpet.h contains _userspace_ ioctl interface struct and macros...

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

then please split the header in 2 parts; one for the kernel and one for userspace

so would you tell me what the purpose (use) of __KERNEL__ is meant to be, please?

for legacy headers.. the same ;)

"the same" as what? I'm not understanding these partial sentences.

Quoted 2 lines

Thats no reason to fix up new cases... things should get better not just get a small rubber bandaid...

Yes, I'm not disagreeing with the no-bandaids part. I just haven't read that __KERNEL__ is legacy only.

---
~Randy

#7 lore raw
In reply to Randy.Dunlap

include/linux/hpet.h int hpet_register(struct hpet_task *, in · line 138

Quoted 6 lines · Randy.Dunlap
include/linux/hpet.h +6 -0
+#define        HPET_IE_ON      _IO('h', 0x01)  /* interrupt on */
+#define        HPET_IE_OFF     _IO('h', 0x02)  /* interrupt off */
+#define        HPET_INFO       _IOR('h', 0x03, struct hpet_info)
+#define        HPET_EPI        _IO('h', 0x04)  /* enable periodic */
+#define        HPET_DPI        _IO('h', 0x05)  /* disable periodic */
+#define        HPET_IRQFREQ    _IOW('h', 0x6, unsigned long)   /* IRQFREQ usec */

By the way, HPET_INFO and HPET_IRQFREQ don't work for 32 bit user space, the driver needs a compat_ioctl() method to handle those.

	Arnd <><
maintainer
#8 lore raw
Quoted 10 lines · Arnd Bergmann

include/linux/hpet.h int hpet_register(struct hpet_task *, in · line 138

Quoted 6 lines · Randy.Dunlap
include/linux/hpet.h +6 -0
+#define        HPET_IE_ON      _IO('h', 0x01)  /* interrupt on */
+#define        HPET_IE_OFF     _IO('h', 0x02)  /* interrupt off */
+#define        HPET_INFO       _IOR('h', 0x03, struct hpet_info)
+#define        HPET_EPI        _IO('h', 0x04)  /* enable periodic */
+#define        HPET_DPI        _IO('h', 0x05)  /* disable periodic */
+#define        HPET_IRQFREQ    _IOW('h', 0x6, unsigned long)   /* IRQFREQ usec */

By the way, HPET_INFO and HPET_IRQFREQ don't work for 32 bit user space, the driver needs a compat_ioctl() method to handle those.

There isn't any program (except the example in the docs) that uses any of these ioctls, and I'm writing patches to make this device available through portable timer APIs like hrtimer/POSIX clocks/ALSA that are much easier to use besides, so I think it would be a good idea to just schedule these ioctls for removal.

Clemens

#9 lore raw
Quoted 12 lines · On Wed, 22 Mar 2006 12:14:46 +0100 Clemens Ladisch wrote:
Quoted 10 lines · Arnd Bergmann

include/linux/hpet.h int hpet_register(struct hpet_task *, in · line 138

Quoted 6 lines · Randy.Dunlap
include/linux/hpet.h +6 -0
+#define        HPET_IE_ON      _IO('h', 0x01)  /* interrupt on */
+#define        HPET_IE_OFF     _IO('h', 0x02)  /* interrupt off */
+#define        HPET_INFO       _IOR('h', 0x03, struct hpet_info)
+#define        HPET_EPI        _IO('h', 0x04)  /* enable periodic */
+#define        HPET_DPI        _IO('h', 0x05)  /* disable periodic */
+#define        HPET_IRQFREQ    _IOW('h', 0x6, unsigned long)   /* IRQFREQ usec */

By the way, HPET_INFO and HPET_IRQFREQ don't work for 32 bit user space, the driver needs a compat_ioctl() method to handle those.

Quoted 5 lines

There isn't any program (except the example in the docs) that uses any of these ioctls, and I'm writing patches to make this device available through portable timer APIs like hrtimer/POSIX clocks/ALSA that are much easier to use besides, so I think it would be a good idea to just schedule these ioctls for removal.

How do you (or can you) know that there are no programs that use that ioctl? Yes, scheduling for removal would be OK.

---
~Randy

maintainer
#10 lore raw
Quoted 9 lines · Randy.Dunlap
Quoted 5 lines · On Wed, 22 Mar 2006 12:14:46 +0100 Clemens Ladisch wrote:

There isn't any program (except the example in the docs) that uses any of these ioctls, and I'm writing patches to make this device available through portable timer APIs like hrtimer/POSIX clocks/ALSA that are much easier to use besides, so I think it would be a good idea to just schedule these ioctls for removal.

How do you (or can you) know that there are no programs that use that ioctl?

Because most parts of hpet.c were orignially written on an emulator and were so buggy as to be effectively unusable until recently.

Additionally, there aren't many BIOSes out there that manage to initialize the third HPET timer (the one used by these ioctls) correctly, or that bother to enable the HPET device at all. (This seems to be changing due to the Windows Vista logo requirements.)

Regards,
Clemens

#11 lore raw
In reply to Clemens Ladisch
Quoted 5 lines · Clemens Ladisch

There isn't any program (except the example in the docs) that uses any of these ioctls, and I'm writing patches to make this device available through portable timer APIs like hrtimer/POSIX clocks/ALSA that are much easier to use besides, so I think it would be a good idea to just schedule these ioctls for removal.

Ok, in that case I guess all of the header file should be wrapped inside #ifdef __KERNEL__. Until now it was not possible to include that header file in order to get the ioctl definition. It would be somewhat counterproductive to schedule the user interface for removal while at the same time making it easier to use it.

Also, I don't see any user of the ioctl function in the kernel, although it's exported. Are there any out-of-tree users?

	Arnd <><
#12 lore raw
Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Clemens Ladisch

There isn't any program (except the example in the docs) that uses any of these ioctls, and I'm writing patches to make this device available through portable timer APIs like hrtimer/POSIX clocks/ALSA that are much easier to use besides, so I think it would be a good idea to just schedule these ioctls for removal.

Quoted 8 lines

Ok, in that case I guess all of the header file should be wrapped inside #ifdef __KERNEL__. Until now it was not possible to include that header file in order to get the ioctl definition. It would be somewhat counterproductive to schedule the user interface for removal while at the same time making it easier to use it.

Also, I don't see any user of the ioctl function in the kernel, although it's exported. Are there any out-of-tree users?

hmm there used to be (in s390 iirc ;) but now it's a good opportunity for Adrian to do a cleanup patch for it