Wind River Support Network

HomeDefectsLIN1023-6485
Fixed

LIN1023-6485 : hpet(ioctl) driver does not work with 32bit application

Created: Jun 4, 2024    Updated: Sep 24, 2024
Resolved Date: Aug 11, 2024
Found In Version: 10.23.30.7
Fix Version: 10.23.30.13
Severity: Severe
Applicable for: Wind River Linux LTS 23
Component/s: Kernel

Description

"unsigned long" is 64bit on 64bit application.
But, "unsigned long" is 32bit on 32bit application.

that caused hpet(ioctl) driver does not work with 32bit application.

include/uapi/linux/hpet.h

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  0x0010  /* periodic-capable comparator */

#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 */

I think shoud be add HPET_INFO32 and HPET_IRQFREQ32 on hpet.h.
eg,

--- a/include/uapi/linux/hpet.h
+++ b/include/uapi/linux/hpet.h
@@ -12,14 +12,23 @@ struct hpet_info {
 	unsigned short hi_timer;
 };
 
+struct compact_hpet_info {
+	u32 hi_ireqfreq;	/* Hz */
+	u32 hi_flags;	/* information */
+	u16 hi_hpet;
+	u16 hi_timer;
+};
+
 #define HPET_INFO_PERIODIC	0x0010	/* periodic-capable comparator */
 
 #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_INFO32	_IOR('h', 0x03, struct compact_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 */
+#define	HPET_IRQFREQ32	_IOW('h', 0x6, u32)	/* IRQFREQ usec */


 

 

Steps to Reproduce

1. setup

$ ./wrlinux-x/setup.sh --machines intel-x86-64 --dl-layers
$ . ./environment-setup-x86_64-wrlinuxsdk-linux
$ . ./oe-init-build-env


2. adding multilib
conf/local.conf

+ AVAILTUNES += "x86 x86-64"
+ MULTILIBS = "multilib:lib32"
+ DEFAULTTUNE:virtclass-multilib-lib32 = "x86"

+ IMAGE_INSTALL:append = " lib32-glibc"
+ TOOLCHAIN_TARGET_TASK:append = " lib32-glibc"


3. build wrlinux-image-std and sdk

$ bitbake wrlinux-image-std
$ bitbake wrlinux-image-std -c populate_sdk


4. install sdk and copy hpet_example application

$ ./x86_64-buildtools-nativesdk-standalone-10.23.30.7.sh
$ cd <sdk-install>
$ cp <build>/tmp-glibc/work-shared/intel-x86-64/kernel-source/samples/timers/hpet_example.c .


5. build hpet_example with 64bit

$ cd <sdk-install>
$ . ./environment-setup-corei7-64-wrs-linux
$ $CC -ggdb -I usr/include hpet_example.c -m64 -o hpet_example-64.out
$ sudo cp hpet_example-64.out <target-rootfs>/root/


6. build hpet_example with 32bit

$ cd <sdk-install>
$ . ./environment-setup-corei7-64-wrs-linux
$ $CC -ggdb -I usr/include hpet_example.c -m32 -o hpet_example-32.out
$ sudo cp hpet_example-32.out <target-rootfs>/root/


7. testing hpet_example-64.out and hpet_example-32.out on WRL-LTS23

*64bit: hpet_example-64.out works good*

root@intel-x86-64:~# file hpet_example-64.out
hpet_example-64.out: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter 
/lib64/ld-linux-x86-64.so.2, BuildID[sha1]=dc3cefe0d0dc17bdcc0b73a8c05aeeb2c92e7d5c, for GNU/Linux 3.2.0, with
 debug_info, not stripped
root@intel-x86-64:~#
root@intel-x86-64:~# ldd hpet_example-64.out
        linux-vdso.so.1 (0x00007ffdd0bbf000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f57e68fe000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f57e6ae2000)
root@intel-x86-64:~#
root@intel-x86-64:~# ./hpet_example-64.out poll /dev/hpet 1 2
-hpet: executing poll
hpet_poll: info.hi_flags 0x0
hpet_poll: expired time = 0xf425b
hpet_poll: revents = 0x1
hpet_poll: data 0x1
hpet_poll: expired time = 0xf4231
hpet_poll: revents = 0x1
hpet_poll: data 0x1
root@intel-x86-64:~#


*32bit: hpet_example-32.out does not work*

root@intel-x86-64:~# file hpet_example-32.out 
hpet_example-32.out: ELF 32-bit LSB pie executable, Intel 80386, version 1 (SYSV), dynamically linked, interpr
eter /lib/ld-linux.so.2, BuildID[sha1]=6195729621734f143f23d5b6709d8159b273d672, for GNU/Linux 3.2.0, with deb
ug_info, not stripped
root@intel-x86-64:~#
root@intel-x86-64:~# ldd hpet_example-32.out
        linux-gate.so.1 (0xf7f43000)
        libc.so.6 => /lib/libc.so.6 (0xf7d12000)
        /lib/ld-linux.so.2 (0xf7f45000)
root@intel-x86-64:~#
root@intel-x86-64:~# ./hpet_example-32.out poll /dev/hpet 1 2
-hpet: executing poll
hpet_poll: HPET_IRQFREQ failed
root@intel-x86-64:~# 

Live chat
Online