All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/12] linux-user: Add support for real time clock and
@ 2020-01-15 15:53 Filip Bozuta
  2020-01-15 15:53 ` [PATCH 01/12] linux-user: Add support for enabling/disabling RTC features using ioctls Filip Bozuta
                   ` (12 more replies)
  0 siblings, 13 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This series covers following RTC and sound timer ioctls:

  RTC ioctls(22):

    * RTC_AIE_ON          * RTC_ALM_SET         * RTC_WKALM_SET
    * RTC_AIE_OFF         * RTC_ALM_READ        * RTC_WKALM_RD
    * RTC_UIE_ON          * RTC_RD_TIME         * RTC_PLL_GET
    * RTC_UIE_OFF         * RTC_SET_TIME        * RTC_PLL_SET
    * RTC_PIE_ON          * RTC_IRQP_READ       * RTC_VL_READ
    * RTC_PIE_OFF         * RTC_IRQP_SET        * RTC_VL_CLR
    * RTC_WIE_ON          * RTC_EPOCH_READ
    * RTC_WIE_OFF         * RTC_EPOCH_SET

  Sound timer ioctls(14):

    * SNDRV_TIMER_IOCTL_PVERSION          * SNDRV_TIMER_IOCTL_INFO
    * SNDRV_TIMER_IOCTL_NEXT_DEVICE       * SNDRV_TIMER_IOCTL_PARAMS
    * SNDRV_TIMER_IOCTL_TREAD             * SNDRV_TIMER_IOCTL_STATUS
    * SNDRV_TIMER_IOCTL_GINFO             * SNDRV_TIMER_IOCTL_START
    * SNDRV_TIMER_IOCTL_GPARAMS           * SNDRV_TIMER_IOCTL_STOP
    * SNDRV_TIMER_IOCTL_GSTATUS           * SNDRV_TIMER_IOCTL_CONTINUE
    * SNDRV_TIMER_IOCTL_SELECT            * SNDRV_TIMER_IOCTL_PAUSE

The functionalities of individual ioctls were described in this series
patch commit messages.

Testing method for RTC ioctls:

    Mini test programs were written for each ioctl. Those programs were
    compiled (sometimes using cross-compilers) for the following
    architectures:

        * Intel 64-bit (little endian)
        * Power pc 32-bit (big endian)
        * Power pc 64-bit (big endian)

    The corresponding native programs were executed without using
    QEMU on following hosts:

        * Intel Core i7-4790K (x86_64 host)
        * Power 7447A (ppc32 host)

    All applicable compiled programs were in turn executed through QEMU
    and the results obtained were the same ones gotten for native
    execution.

    Example of a test program:

        For ioctl RTC_RD_TIME the following test program was used:

        #include <stdio.h>
        #include <stdlib.h>
        #include <linux/rtc.h>
        #include <fcntl.h>
        #include <linux/input.h>
        #include <sys/types.h>
        #include <unistd.h>

        #define ERROR -1

        int main()
        {

            int fd = open("/dev/rtc", O_RDWR | O_NONBLOCK);

            if(fd == ERROR)
            {
                perror("open");
                return -1;
            }

            struct rtc_time cur_time;

            if(ioctl(fd, RTC_RD_TIME, &cur_time) < 0)
            {
                perror("ioctl");
                return -1;
            }

            printf("Second: %d, Minute: %d, Hour: %d, Day: %d, Month: %d, Year: %d,",
                cur_time.tm_sec, cur_time.tm_min, cur_time.tm_hour, 
                cur_time.tm_mday, cur_time.tm_mon, cur_time.tm_year);

            return 0;
        }

    Limitations of testing:

        The test host pc that was used for testing (intel pc) has RTC
        that doesn't support all RTC features that are accessible
        through ioctls. This means that testing can't discover
        functionality errors related to the third argument of ioctls
        that are used for features which are not supported. For example,
        running the test program for ioctl RTC_EPOCH_READ gives
        the error output: inappropriate ioctl for device. As expected,
        the same output was obtained through QEMU which means that this
        ioctl is recognized in QEMU but doesn't really do anything
        because it is not supported in the host computer's RTC.

        Conclusion: Some RTC ioctls need to be tested on computers
        that support their functionalities so that it can be inferred
        that they are really supported in QEMU. In absence of such
        test hosts, the specifications of those ioctls need to be
        carefully checked manually and the implementations should be
        updated accordingly.

Testing method for sound timer ioctls:

    The alsa ioctl test suite, that can be found on github
    ("https://github.com/alsa-project/alsa-utils"), was used the test
    the implemented ioctls. The file "timer.c", located in this test
    suite, contains test functions that are used to test alsa timer
    ioctls. This file was compiled (sometimes using cross-compilers) 
    for the following architectures:

        * Intel 64-bit (little endian)
        * Power pc 32-bit (big endian)
        * Power pc 64-bit (big endian)

    The corresponding compiled test files were executed without using
    QEMU on following hosts:

        * Intel Core i7-4790K (x86_64 host)
        * Power 7447A (ppc32 host)

    The corresponding native compiled test files were executed without using
    QEMU on following hosts:

        * Intel Core i7-4790K (x86_64 host)
        * Power 7447A (ppc32 host)

    All compiled test files were in turn executed through QEMU
    and the results obtained were the same ones gotten for native
    execution.

    Also, mini test programs were written to test further functionalities
    of individual ioctls. Those programs were, like the file "timer.c",
    compiled for different architectures and were executed both natively
    and thgrough QEMU to compare the results.

    Example of a test program:

        For ioctl SNDRV_TIMER_IOCTL_GINFO the following test program was used:

        #include <stdio.h>
        #include <stdlib.h>
        #include <sys/types.h>
        #include <fcntl.h>
        #include <sys/ioctl.h>
        #include <sound/asound.h>

        #define ERROR -1

        int main()
        {
            int fd = open("/dev/snd/timer", O_RDWR);

            if(fd == ERROR)
            {
                perror("open");
                return -1;
            }

            struct snd_timer_id id = {SNDRV_TIMER_CLASS_GLOBAL, 
                                      SNDRV_TIMER_SCLASS_NONE, -1, 
                                      SNDRV_TIMER_GLOBAL_SYSTEM, 0};

            struct snd_timer_ginfo ginfo;
            ginfo.tid = id;

            if(ioctl(fd, SNDRV_TIMER_IOCTL_GINFO, &ginfo) == ERROR)
            {
                perror("ioctl");
                return -1;
            }

            printf("flags: %u\n", ginfo.flags);
            printf("card: %d\n", ginfo.card);
            printf("id: %s\n", ginfo.id);
            printf("name: %s\n", ginfo.name);
            printf("reserved0: %lu\n", ginfo.reserved0);
            printf("resolution: %lu\n", ginfo.resolution);
            printf("resolution_min: %lu\n", ginfo.resolution_min);
            printf("reolution_max: %lu\n", ginfo.resolution_max);
            printf("clients: %u\n", ginfo.clients);
            printf("reserved: %s\n", ginfo.reserved);

            return 0;
        }

v6:

    * fixed one patch by adding a case statement for 'unsigned long'
      to recognize two ioctls that are implemented in that patch

    * changed patch descriptions a little bit so that they are more
      comprehensible

v5:

    * added support for alsa sound timer ioctls

v4:

    * changed patch descriptions so that they are better
      formatted and more comprehensible

v3:

    * changed two instances of MK_PTR(TYPE_ULONG) to TYPE_ULONG

v2:

    * added description of each ioctl in patches
    * wrote a more detailed cover letter with description of testing
    * changed one instance of TYPE_INT to MK_PTR(TYPE_INT)

Filip Bozuta (12):
  linux-user: Add support for enabling/disabling RTC features using
    ioctls
  linux-user: Add support for getting/setting RTC time and alarm using
    ioctls
  linux-user: Add support for getting/setting RTC periodic interrupt and
    epoch using ioctls
  linux-user: Add support for getting/setting RTC wakeup alarm using
    ioctls
  linux-user: Add support for getting/setting RTC PLL correction using
    ioctls
  linux-user: Add support for read/clear RTC voltage low detector using
    ioctls
  linux-user: Add support for getting alsa timer version and id
  linux-user: Add support for setting alsa timer enhanced read using
    ioctl
  linux-user: Add support for getting/setting specified alsa timer
    parameters using ioctls
  linux-user: Add support for selecting alsa timer using ioctl
  linux-user: Add support for getting/setting selected alsa timer
    parameters using ioctls
  linux-user: Add support for selected alsa timer instructions using
    ioctls

 linux-user/ioctls.h        |  45 +++++++++++++++++
 linux-user/syscall.c       |   3 ++
 linux-user/syscall_defs.h  | 121 +++++++++++++++++++++++++++++++++++++++++++++
 linux-user/syscall_types.h |  91 ++++++++++++++++++++++++++++++++++
 4 files changed, 260 insertions(+)

-- 
2.7.4



^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 01/12] linux-user: Add support for enabling/disabling RTC features using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 02/12] linux-user: Add support for getting/setting RTC time and alarm " Filip Bozuta
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

RTC_AIE_ON, RTC_AIE_OFF - Alarm interrupt enabling on/off

    Enable or disable the alarm interrupt, for RTCs that support
    alarms.  The third ioctl's argument is ignored.

RTC_UIE_ON, RTC_UIE_OFF - Update interrupt enabling on/off

    Enable or disable the interrupt on every clock update, for
    RTCs that support this once-per-second interrupt. The third
    ioctl's argument is ignored.

RTC_PIE_ON, RTC_PIE_OFF - Periodic interrupt enabling on/off

    Enable or disable the periodic interrupt, for RTCs that sup‐
    port these periodic interrupts. The third ioctl's argument
    is ignored. Only a privileged process (i.e., one having the
    CAP_SYS_RESOURCE capability) can enable the periodic interrupt
    if the frequency is currently set above the value specified in
    /proc/sys/dev/rtc/max-user-freq.

RTC_WIE_ON, RTC_WIE_OFF - Watchdog interrupt enabling on/off

    Enable or disable the Watchdog interrupt, for RTCs that sup-
    port this Watchdog interrupt. The third ioctl's argument is
    ignored.

Implementation notes:

    Since all of involved ioctls have NULL as their third argument,
    their implementation was straightforward.

    The line '#include <linux/rtc.h>' was added to recognize
    preprocessor definitions for these ioctls. This needs to be
    done only once in this series of commits. Also, the content
    of this file (with respect to ioctl definitions) remained
    unchanged for a long time, therefore there is no need to
    worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h       |  9 +++++++++
 linux-user/syscall.c      |  1 +
 linux-user/syscall_defs.h | 10 ++++++++++
 3 files changed, 20 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index c6b9d6a..97741c7 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -69,6 +69,15 @@
      IOCTL(KDSETLED, 0, TYPE_INT)
      IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT)
 
+     IOCTL(RTC_AIE_ON, 0, TYPE_NULL)
+     IOCTL(RTC_AIE_OFF, 0, TYPE_NULL)
+     IOCTL(RTC_UIE_ON, 0, TYPE_NULL)
+     IOCTL(RTC_UIE_OFF, 0, TYPE_NULL)
+     IOCTL(RTC_PIE_ON, 0, TYPE_NULL)
+     IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
+     IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
+     IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+
      IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
      IOCTL(BLKRRPART, 0, TYPE_NULL)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce399a5..74c3c08 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -107,6 +107,7 @@
 #include <netpacket/packet.h>
 #include <linux/netlink.h>
 #include <linux/if_alg.h>
+#include <linux/rtc.h>
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 98c2119..f91579a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED        0x4B32	/* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT     0x4B4E
 
+/* real time clock ioctls */
+#define TARGET_RTC_AIE_ON           TARGET_IO('p', 0x01)
+#define TARGET_RTC_AIE_OFF          TARGET_IO('p', 0x02)
+#define TARGET_RTC_UIE_ON           TARGET_IO('p', 0x03)
+#define TARGET_RTC_UIE_OFF          TARGET_IO('p', 0x04)
+#define TARGET_RTC_PIE_ON           TARGET_IO('p', 0x05)
+#define TARGET_RTC_PIE_OFF          TARGET_IO('p', 0x06)
+#define TARGET_RTC_WIE_ON           TARGET_IO('p', 0x0f)
+#define TARGET_RTC_WIE_OFF          TARGET_IO('p', 0x10)
+
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||    \
        defined(TARGET_XTENSA)
 #define TARGET_FIOGETOWN       TARGET_IOR('f', 123, int)
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 02/12] linux-user: Add support for getting/setting RTC time and alarm using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
  2020-01-15 15:53 ` [PATCH 01/12] linux-user: Add support for enabling/disabling RTC features using ioctls Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch " Filip Bozuta
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

RTC_RD_TIME - Getting RTC time

    Returns this RTC's time in the following structure:

        struct rtc_time {
            int tm_sec;
            int tm_min;
            int tm_hour;
            int tm_mday;
            int tm_mon;
            int tm_year;
            int tm_wday;     /* unused */
            int tm_yday;     /* unused */
            int tm_isdst;    /* unused */
        };

    The fields in this structure have the same meaning and ranges
    as the tm structure described in gmtime man page. A pointer
    to this structure should be passed as the third ioctl's argument.

RTC_SET_TIME - Setting RTC time

    Sets this RTC's time to the time specified by the rtc_time
    structure pointed to by the third ioctl's argument. To set
    the RTC's time the process must be privileged (i.e., have the
    CAP_SYS_TIME capability).

RTC_ALM_READ, RTC_ALM_SET - Getting/Setting alarm time

    Read and set the alarm time, for RTCs that support alarms.
    The alarm interrupt must be separately enabled or disabled
    using the RTC_AIE_ON, RTC_AIE_OFF requests. The third
    ioctl's argument is a pointer to a rtc_time structure. Only
    the tm_sec, tm_min, and tm_hour fields of this structure are
    used.

Implementation notes:

    All ioctls in this patch have pointer to a structure rtc_time
    as their third argument. That is the reason why corresponding
    definition is added in linux-user/syscall_types.h. Since all
    elements of this structure are of type 'int', the rest of the
    implementation is straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h        |  4 ++++
 linux-user/syscall_defs.h  |  4 ++++
 linux-user/syscall_types.h | 11 +++++++++++
 3 files changed, 19 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 97741c7..f472794 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -77,6 +77,10 @@
      IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
      IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
      IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+     IOCTL(RTC_ALM_READ, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+     IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+     IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+     IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
 
      IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f91579a..f0bf09d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -772,6 +772,10 @@ struct target_pollfd {
 #define TARGET_RTC_PIE_OFF          TARGET_IO('p', 0x06)
 #define TARGET_RTC_WIE_ON           TARGET_IO('p', 0x0f)
 #define TARGET_RTC_WIE_OFF          TARGET_IO('p', 0x10)
+#define TARGET_RTC_ALM_READ         TARGET_IOR('p', 0x08, struct rtc_time)
+#define TARGET_RTC_ALM_SET          TARGET_IOW('p', 0x07, struct rtc_time)
+#define TARGET_RTC_RD_TIME          TARGET_IOR('p', 0x09, struct rtc_time)
+#define TARGET_RTC_SET_TIME         TARGET_IOW('p', 0x0a, struct rtc_time)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||    \
        defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e36983..a35072a 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -255,6 +255,17 @@ STRUCT(blkpg_partition,
        MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */
        MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
 
+STRUCT(rtc_time,
+       TYPE_INT, /* tm_sec */
+       TYPE_INT, /* tm_min */
+       TYPE_INT, /* tm_hour */
+       TYPE_INT, /* tm_mday */
+       TYPE_INT, /* tm_mon */
+       TYPE_INT, /* tm_year */
+       TYPE_INT, /* tm_wday */
+       TYPE_INT, /* tm_yday */
+       TYPE_INT) /* tm_isdst */
+
 STRUCT(blkpg_ioctl_arg,
        TYPE_INT, /* op */
        TYPE_INT, /* flags */
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
  2020-01-15 15:53 ` [PATCH 01/12] linux-user: Add support for enabling/disabling RTC features using ioctls Filip Bozuta
  2020-01-15 15:53 ` [PATCH 02/12] linux-user: Add support for getting/setting RTC time and alarm " Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 16:46   ` Laurent Vivier
  2020-01-15 15:53 ` [PATCH 04/12] linux-user: Add support for getting/setting RTC wakeup alarm " Filip Bozuta
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate

    Read and set the frequency for periodic interrupts, for RTCs
    that support periodic interrupts. The periodic interrupt must
    be separately enabled or disabled using the RTC_PIE_ON,
    RTC_PIE_OFF requests. The third ioctl's argument is an
    unsigned long * or an unsigned long, respectively. The value
    is the frequency in interrupts per second. The set of allow‐
    able frequencies is the multiples of two in the range 2 to
    8192. Only a privileged process (i.e., one having the
    CAP_SYS_RESOURCE capability) can set frequencies above the
    value specified in /proc/sys/dev/rtc/max-user-freq. (This
    file contains the value 64 by default.)

RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch

    Many RTCs encode the year in an 8-bit register which is either
    interpreted as an 8-bit binary number or as a BCD number. In
    both cases, the number is interpreted relative to this RTC's
    Epoch. The RTC's Epoch is initialized to 1900 on most systems
    but on Alpha and MIPS it might also be initialized to 1952,
    1980, or 2000, depending on the value of an RTC register for
    the year. With some RTCs, these operations can be used to
    read or to set the RTC's Epoch, respectively. The third
    ioctl's argument is an unsigned long * or an unsigned long,
    respectively, and the value returned (or assigned) is the
    Epoch. To set the RTC's Epoch the process must be privileged
    (i.e., have the CAP_SYS_TIME capability).

Implementation notes:

    All ioctls in this patch have a pointer to 'ulong' as their
    third argument. That is the reason why corresponding parts
    of added code in linux-user/syscall_defs.h contain special
    handling related to 'ulong' type: they use 'abi_ulong' type
    to make sure that ioctl's code is calculated correctly for
    both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
    is used for the similar reason in linux-user/ioctls.h.
    Because ioctls RTC_IRQP_SET and RTC_EPOCH_SET are ioctls of
    type IOW(writing type) that have unsigned long as their
    third argument, a case statement for "TYPE_ULONG" was added
    in the appropriate place for function "abi_ulong do_ioctl"
    in file "syscall.c". There were no implemented ioctls of
    type IOW with unsigned long as third argument before this
    patch, which is the reason why this case statement was added
    now for the first time.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h       | 4 ++++
 linux-user/syscall.c      | 1 +
 linux-user/syscall_defs.h | 4 ++++
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f472794..accbdee 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
      IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
      IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
      IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+     IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+     IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
+     IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+     IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
 
      IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 74c3c08..c0b7314 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5175,6 +5175,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
         break;
     case TYPE_PTRVOID:
     case TYPE_INT:
+    case TYPE_ULONG:
         ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg));
         break;
     case TYPE_PTR:
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f0bf09d..bbfa935 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_SET          TARGET_IOW('p', 0x07, struct rtc_time)
 #define TARGET_RTC_RD_TIME          TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME         TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READ        TARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET         TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ       TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SET        TARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||    \
        defined(TARGET_XTENSA)
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 04/12] linux-user: Add support for getting/setting RTC wakeup alarm using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (2 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch " Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 05/12] linux-user: Add support for getting/setting RTC PLL correction " Filip Bozuta
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

RTC_WKALM_SET, RTC_WKALM_GET - Getting/Setting wakeup alarm

    Some RTCs support a more powerful alarm interface, using these
    ioctls to read or write the RTC's alarm time (respectively)
    with this structure:

        struct rtc_wkalrm {
            unsigned char enabled;
            unsigned char pending;
            struct rtc_time time;
        };

    The enabled flag is used to enable or disable the alarm
    interrupt, or to read its current status; when using these
    calls, RTC_AIE_ON and RTC_AIE_OFF are not used. The pending
    flag is used by RTC_WKALM_RD to report a pending interrupt
    (so it's mostly useless on Linux, except when talking to the
    RTC managed by EFI firmware). The time field is as used with
    RTC_ALM_READ and RTC_ALM_SET except that the tm_mday, tm_mon,
    and tm_year fields are also valid. A pointer to this structure
    should be passed as the third ioctl's argument.

Implementation notes:

    All ioctls in this patch have a pointer to a structure
    rtc_wkalrm as their third argument. That is the reason why
    corresponding definition is added in linux-user/syscall_types.h.
    Since all  elements of this structure are either of type
    'unsigned char' or 'struct rtc_time' (that was covered in one
    of previous patches), the rest of the implementation is
    straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h        | 2 ++
 linux-user/syscall_defs.h  | 2 ++
 linux-user/syscall_types.h | 5 +++++
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index accbdee..b09396e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -85,6 +85,8 @@
      IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
      IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
      IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
+     IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+     IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
 
      IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index bbfa935..37504a2 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -780,6 +780,8 @@ struct target_pollfd {
 #define TARGET_RTC_IRQP_SET         TARGET_IOW('p', 0x0c, abi_ulong)
 #define TARGET_RTC_EPOCH_READ       TARGET_IOR('p', 0x0d, abi_ulong)
 #define TARGET_RTC_EPOCH_SET        TARGET_IOW('p', 0x0e, abi_ulong)
+#define TARGET_RTC_WKALM_RD         TARGET_IOR('p', 0x10, struct rtc_wkalrm)
+#define TARGET_RTC_WKALM_SET        TARGET_IOW('p', 0x0f, struct rtc_wkalrm)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||    \
        defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index a35072a..820bc8e 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -266,6 +266,11 @@ STRUCT(rtc_time,
        TYPE_INT, /* tm_yday */
        TYPE_INT) /* tm_isdst */
 
+STRUCT(rtc_wkalrm,
+       TYPE_CHAR, /* enabled */
+       TYPE_CHAR, /* pending */
+       MK_STRUCT(STRUCT_rtc_time)) /* time */
+
 STRUCT(blkpg_ioctl_arg,
        TYPE_INT, /* op */
        TYPE_INT, /* flags */
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 05/12] linux-user: Add support for getting/setting RTC PLL correction using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (3 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 04/12] linux-user: Add support for getting/setting RTC wakeup alarm " Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 06/12] linux-user: Add support for read/clear RTC voltage low detector " Filip Bozuta
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

RTC_PLL_GET - Getting PLL correction

    Read the PLL correction for RTCs that support PLL. The PLL correction
    is returned in the following structure:

        struct rtc_pll_info {
            int pll_ctrl;        /* placeholder for fancier control */
            int pll_value;       /* get/set correction value */
            int pll_max;         /* max +ve (faster) adjustment value */
            int pll_min;         /* max -ve (slower) adjustment value */
            int pll_posmult;     /* factor for +ve correction */
            int pll_negmult;     /* factor for -ve correction */
            long pll_clock;      /* base PLL frequency */
        };

    A pointer to this structure should be passed as the third
    ioctl's argument.

RTC_PLL_SET - Setting PLL correction

    Sets the PLL correction for RTCs that support PLL. The PLL correction
    that is set is specified by the rtc_pll_info structure pointed to by
    the third ioctl's' argument.

Implementation notes:

    All ioctls in this patch have a pointer to a structure rtc_pll_info
    as their third argument. All elements of this structure are of
    type 'int', except the last one that is of type 'long'. That is
    the reason why a separate target structure (target_rtc_pll_info)
    is defined in linux-user/syscall_defs. The rest of the
    implementation is straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h        |  2 ++
 linux-user/syscall_defs.h  | 14 ++++++++++++++
 linux-user/syscall_types.h |  9 +++++++++
 3 files changed, 25 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index b09396e..0a4e3f1 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -87,6 +87,8 @@
      IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
      IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
      IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+     IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+     IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
 
      IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 37504a2..8370f41 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED        0x4B32	/* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT     0x4B4E
 
+struct target_rtc_pll_info {
+    int pll_ctrl;
+    int pll_value;
+    int pll_max;
+    int pll_min;
+    int pll_posmult;
+    int pll_negmult;
+    abi_long pll_clock;
+};
+
 /* real time clock ioctls */
 #define TARGET_RTC_AIE_ON           TARGET_IO('p', 0x01)
 #define TARGET_RTC_AIE_OFF          TARGET_IO('p', 0x02)
@@ -782,6 +792,10 @@ struct target_pollfd {
 #define TARGET_RTC_EPOCH_SET        TARGET_IOW('p', 0x0e, abi_ulong)
 #define TARGET_RTC_WKALM_RD         TARGET_IOR('p', 0x10, struct rtc_wkalrm)
 #define TARGET_RTC_WKALM_SET        TARGET_IOW('p', 0x0f, struct rtc_wkalrm)
+#define TARGET_RTC_PLL_GET          TARGET_IOR('p', 0x11,                      \
+                                               struct target_rtc_pll_info)
+#define TARGET_RTC_PLL_SET          TARGET_IOW('p', 0x12,                      \
+                                               struct target_rtc_pll_info)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||    \
        defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 820bc8e..4027272 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -271,6 +271,15 @@ STRUCT(rtc_wkalrm,
        TYPE_CHAR, /* pending */
        MK_STRUCT(STRUCT_rtc_time)) /* time */
 
+STRUCT(rtc_pll_info,
+       TYPE_INT, /* pll_ctrl */
+       TYPE_INT, /* pll_value */
+       TYPE_INT, /* pll_max */
+       TYPE_INT, /* pll_min */
+       TYPE_INT, /* pll_posmult */
+       TYPE_INT, /* pll_negmult */
+       TYPE_LONG) /* pll_clock */
+
 STRUCT(blkpg_ioctl_arg,
        TYPE_INT, /* op */
        TYPE_INT, /* flags */
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 06/12] linux-user: Add support for read/clear RTC voltage low detector using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (4 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 05/12] linux-user: Add support for getting/setting RTC PLL correction " Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 07/12] linux-user: Add support for getting alsa timer version and id Filip Bozuta
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

RTC_VL_READ - Read voltage low detection information

    Read the voltage low for RTCs that support voltage low.
    The third ioctl's' argument points to an int in which
    the voltage low is returned.

RTC_VL_CLR - Clear voltage low information

    Clear the information about voltage low for RTCs that
    support voltage low. The third ioctl(2) argument is
    ignored.

Implementation notes:

    Since one ioctl has a pointer to 'int' as its third agrument,
    and another ioctl has NULL as its third argument, their
    implementation was straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h       | 2 ++
 linux-user/syscall_defs.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 0a4e3f1..1f1f3e6 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -89,6 +89,8 @@
      IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
      IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
      IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+     IOCTL(RTC_VL_READ, IOC_R, MK_PTR(TYPE_INT))
+     IOCTL(RTC_VL_CLR, 0, TYPE_NULL)
 
      IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 8370f41..af4f366 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -796,6 +796,8 @@ struct target_rtc_pll_info {
                                                struct target_rtc_pll_info)
 #define TARGET_RTC_PLL_SET          TARGET_IOW('p', 0x12,                      \
                                                struct target_rtc_pll_info)
+#define TARGET_RTC_VL_READ          TARGET_IOR('p', 0x13, int)
+#define TARGET_RTC_VL_CLR           TARGET_IO('p', 0x14)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||    \
        defined(TARGET_XTENSA)
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 07/12] linux-user: Add support for getting alsa timer version and id
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (5 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 06/12] linux-user: Add support for read/clear RTC voltage low detector " Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl Filip Bozuta
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_PVERSION - Getting the sound timer version

    Read the sound timer version. The third ioctl's argument is
    a pointer to an int in which the specified timers version
    is returned.

SNDRV_TIMER_IOCTL_NEXT_DEVICE - Getting id information about next timer

    Read id information about the next timer device from the sound timer
    device list. The id infomration is returned in the following structure:

        struct snd_timer_id {
            int dev_class;    /* timer device class number */
            int dev_sclass;   /* slave device class number (unused) */
            int card;         /* card number */
            int device;       /* device number */
            int subdevice;    /* sub-device number */
        };

    The devices in the sound timer device list are arranged by the fields
    of this structure respectively (first by dev_class number, then by
    card number, ...). A pointer to this structure should be passed as
    the third ioctl's argument. Before calling the ioctl, the parameters
    of this structure should be initialized in relation to the next timer
    device which information is to be obtained. For example, if a wanted
    timer device has the device class number equal to or bigger then 2,
    the field dev_class should be initialized to 2. After the ioctl call,
    the structure fields are filled with values from the next device in
    the sound timer device list. If there is no next device in the list,
    the structure is filled with "zero" id values (in that case all
    fields are filled with value -1).

Implementation notes:

    The ioctl 'SNDRV_TIMER_IOCTL_NEXT_DEVICE' has a pointer to a
    'struct snd_timer_id' as its third argument. That is the reason why
    corresponding definition is added in 'linux-user/syscall_types.h'.
    Since all elements of this structure are of type 'int', the rest of
    the implementation was straightforward.

    The line '#include <linux/rtc.h>' was added to recognize
    preprocessor definitions for these ioctls. This needs to be
    done only once in this series of commits. Also, the content
    of this file (with respect to ioctl definitions) remained
    unchanged for a long time, therefore there is no need to
    worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h        | 4 ++++
 linux-user/syscall.c       | 1 +
 linux-user/syscall_defs.h  | 5 +++++
 linux-user/syscall_types.h | 7 +++++++
 4 files changed, 17 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 1f1f3e6..ed1bd4c 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -449,6 +449,10 @@
   IOCTL(SOUND_MIXER_WRITE_LOUD, IOC_W, MK_PTR(TYPE_INT))
   IOCTL(SOUND_MIXER_WRITE_RECSRC, IOC_W, MK_PTR(TYPE_INT))
 
+  IOCTL(SNDRV_TIMER_IOCTL_PVERSION, IOC_R, MK_PTR(TYPE_INT))
+  IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
+        MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
+
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(HDIO_GET_MULTCOUNT, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c0b7314..022d064 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -108,6 +108,7 @@
 #include <linux/netlink.h>
 #include <linux/if_alg.h>
 #include <linux/rtc.h>
+#include <sound/asound.h>
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index af4f366..7409021 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2425,6 +2425,11 @@ struct target_statfs64 {
 
 #define TARGET_SOUND_MIXER_WRITE_RECSRC	TARGET_MIXER_WRITE(SOUND_MIXER_RECSRC)
 
+/* alsa timer ioctls */
+#define TARGET_SNDRV_TIMER_IOCTL_PVERSION     TARGET_IOR('T', 0x00, int)
+#define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,                     \
+                                                          struct snd_timer_id)
+
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTH    TARGET_IORU('r', 1)
 #define TARGET_VFAT_IOCTL_READDIR_SHORT   TARGET_IORU('r', 2)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4027272..2f4cd78 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -83,6 +83,13 @@ STRUCT(buffmem_desc,
 STRUCT(mixer_info,
        MK_ARRAY(TYPE_CHAR, 16), MK_ARRAY(TYPE_CHAR, 32), TYPE_INT, MK_ARRAY(TYPE_INT, 10))
 
+STRUCT(snd_timer_id,
+       TYPE_INT, /* dev_class */
+       TYPE_INT, /* dev_sclass */
+       TYPE_INT, /* card */
+       TYPE_INT, /* device */
+       TYPE_INT) /* subdevice */
+
 /* loop device ioctls */
 STRUCT(loop_info,
        TYPE_INT,                 /* lo_number */
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (6 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 07/12] linux-user: Add support for getting alsa timer version and id Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 16:18   ` Arnd Bergmann
  2020-01-15 15:53 ` [PATCH 09/12] linux-user: Add support for getting/setting specified alsa timer parameters using ioctls Filip Bozuta
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionality of following ioctl:

SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read

    Sets enhanced time read which is used for reading time with timestamps
    and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
    reading is set if the third argument is different than 0, otherwise normal
    time reading is set.

Implementation notes:

    Because the implemented ioctl has 'int' as its third argument, the
    implementation was straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h       | 1 +
 linux-user/syscall_defs.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index ed1bd4c..9106773 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -452,6 +452,7 @@
   IOCTL(SNDRV_TIMER_IOCTL_PVERSION, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
         MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
+  IOCTL(SNDRV_TIMER_IOCTL_TREAD, IOC_W, MK_PTR(TYPE_INT))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 7409021..8d505c1 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2429,6 +2429,7 @@ struct target_statfs64 {
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION     TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,                     \
                                                           struct snd_timer_id)
+#define TARGET_SNDRV_TIMER_IOCTL_TREAD        TARGET_IOW('T', 0x02, int)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTH    TARGET_IORU('r', 1)
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 09/12] linux-user: Add support for getting/setting specified alsa timer parameters using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (7 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 10/12] linux-user: Add support for selecting alsa timer using ioctl Filip Bozuta
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_GINFO - Getting information about specified timer

    Read information about the specified timer. The information about the
    timer is returned in the following structure:

        struct snd_timer_ginfo {
            struct snd_timer_id tid;      /* requested timer ID */
            unsigned int flags;           /* timer flags - SNDRV_TIMER_FLG_* */
            int card;                     /* card number */
            unsigned char id[64];         /* timer identification */
            unsigned char name[80];       /* timer name */
            unsigned long reserved0;      /* reserved for future use */
            unsigned long resolution;     /* average period resolution in ns */
            unsigned long resolution_min; /* minimal period resolution in ns */
            unsigned long resolution_max; /* maximal period resolution in ns */
            unsigned int clients;         /* active timer clients */
            unsigned char reserved[32];   /* reserved */
        };

    A pointer to this structure should be passed as the third ioctl's argument.
    Before calling the ioctl, the field "tid" should be initialized with the id
    information for the timer which information is to be obtained. After the
    ioctl call, the rest of the structure fields are filled with values from
    the timer device with the specified id. If there is no device with the
    specified id, the error ENODEV ("No such device") is returned.

SNDRV_TIMER_IOCTL_GPARAMS - Setting precise period duration

    Sets timer precise period duration numerator and denominator in seconds. The
    period duration is set in the following structure:

        struct snd_timer_gparams {
            struct snd_timer_id tid;    /* requested timer ID */
            unsigned long period_num;   /* period duration - numerator */
            unsigned long period_den;   /* period duration - denominator */
            unsigned char reserved[32]; /* reserved */
        };

    A pointer to this structure should be passed as the third ioctl's argument.
    Before calling the ioctl, the field "tid" should be initialized with the id
    information for the timer which period duration is to be set. Also, the
    fileds "period_num" and "period_den" should be filled with the period
    duration numerator and denominator values that are to be set respectively.
    If there is no device with the specified id, the error ENODEV ("No such
    device") is returned.

SNDRV_TIMER_IOCTL_GSTATUS - Getting current period resolution

    Read timer current period resolution in nanoseconds and period resolution
    numerator and denominator in seconds. The period resolution information is
    returned in the following structure:

    struct snd_timer_gstatus {
        struct snd_timer_id tid;        /* requested timer ID */
        unsigned long resolution;       /* current period resolution in ns */
        unsigned long resolution_num;   /* period resolution - numerator */
        unsigned long resolution_den;   /* period resolution - denominator */
        unsigned char reserved[32];     /* reserved for future use */
    };

    A pointer to this structure should be passed as the third ioctl's argument.
    Before calling the ioctl, the field "tid" should be initialized with the id
    information for the timer which period resolution is to be obtained. After
    the ioctl call, the rest of the structure fields are filled with values
    from the timer device with the specified id. If there is no device with the
    specified id, the error ENODEV ("No such device") is returned.

Implementation notes:

    All ioctls in this patch have pointer to some kind of a structure as their
    third argument. That is the reason why corresponding definitions were added
    in 'linux-user/syscall_types.h'. All of these strcutures have some fields
    that are of type 'unsigned long'. That is the reason why separate target
    structures were defined in 'linux-user/syscall_defs.h'. Also, all of the
    structures have a field with type 'struct snd_timer_id' which is the reason
    why a separate target structure 'struct target_snd_timer_id' was also
    defined. The rest of the implementation was straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h        |  6 ++++++
 linux-user/syscall_defs.h  | 43 +++++++++++++++++++++++++++++++++++++++++++
 linux-user/syscall_types.h | 26 ++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 9106773..989eb9b 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -453,6 +453,12 @@
   IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
         MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
   IOCTL(SNDRV_TIMER_IOCTL_TREAD, IOC_W, MK_PTR(TYPE_INT))
+  IOCTL(SNDRV_TIMER_IOCTL_GINFO, IOC_RW,
+        MK_PTR(MK_STRUCT(STRUCT_snd_timer_ginfo)))
+  IOCTL(SNDRV_TIMER_IOCTL_GPARAMS, IOC_W,
+        MK_PTR(MK_STRUCT(STRUCT_snd_timer_gparams)))
+  IOCTL(SNDRV_TIMER_IOCTL_GSTATUS, IOC_RW,
+        MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 8d505c1..4d4dad3 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2425,11 +2425,54 @@ struct target_statfs64 {
 
 #define TARGET_SOUND_MIXER_WRITE_RECSRC	TARGET_MIXER_WRITE(SOUND_MIXER_RECSRC)
 
+struct target_snd_timer_id {
+    int dev_class;
+    int dev_sclass;
+    int card;
+    int device;
+    int subdevice;
+};
+
+struct target_snd_timer_ginfo {
+    struct target_snd_timer_id tid;
+    unsigned int flags;
+    int card;
+    unsigned char id[64];
+    unsigned char name[80];
+    abi_ulong reserved0;
+    abi_ulong resolution;
+    abi_ulong resolution_min;
+    abi_ulong resolution_max;
+    unsigned int clients;
+    unsigned char reserved[32];
+};
+
+struct target_snd_timer_gparams {
+    struct target_snd_timer_id tid;
+    abi_ulong period_num;
+    abi_ulong period_den;
+    unsigned char reserved[32];
+};
+
+struct target_snd_timer_gstatus {
+    struct target_snd_timer_id tid;
+    abi_ulong resolution;
+    abi_ulong resolution_num;
+    abi_ulong resolution_den;
+    unsigned char reserved[32];
+};
+
 /* alsa timer ioctls */
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION     TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,                     \
                                                           struct snd_timer_id)
 #define TARGET_SNDRV_TIMER_IOCTL_TREAD        TARGET_IOW('T', 0x02, int)
+#define TARGET_SNDRV_TIMER_IOCTL_GINFO        TARGET_IOWR('T', 0x03,                     \
+                                                          struct target_snd_timer_ginfo)
+#define TARGET_SNDRV_TIMER_IOCTL_GPARAMS      TARGET_IOW('T', 0x04,                      \
+                                                         struct target_snd_timer_gparams)
+#define TARGET_SNDRV_TIMER_IOCTL_GSTATUS      TARGET_IOWR('T', 0x05,                     \
+                                                          struct target_snd_timer_gstatus)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTH    TARGET_IORU('r', 1)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 2f4cd78..4e90716 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -90,6 +90,32 @@ STRUCT(snd_timer_id,
        TYPE_INT, /* device */
        TYPE_INT) /* subdevice */
 
+STRUCT(snd_timer_ginfo,
+       MK_STRUCT(STRUCT_snd_timer_id), /* tid */
+       TYPE_INT, /* flags */
+       TYPE_INT, /* card */
+       MK_ARRAY(TYPE_CHAR, 64), /* id */
+       MK_ARRAY(TYPE_CHAR, 80), /* name */
+       TYPE_ULONG, /* reserved0 */
+       TYPE_ULONG, /* resolution */
+       TYPE_ULONG, /* resolution_min */
+       TYPE_ULONG, /* resolution_max */
+       TYPE_INT, /* clients */
+       MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
+
+STRUCT(snd_timer_gparams,
+       MK_STRUCT(STRUCT_snd_timer_id), /* tid */
+       TYPE_ULONG, /* period_num */
+       TYPE_ULONG, /* period_den */
+       MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
+
+STRUCT(snd_timer_gstatus,
+       MK_STRUCT(STRUCT_snd_timer_id), /* tid */
+       TYPE_ULONG, /* resolution */
+       TYPE_ULONG, /* resolution_num */
+       TYPE_ULONG, /* resolution_den */
+       MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
+
 /* loop device ioctls */
 STRUCT(loop_info,
        TYPE_INT,                 /* lo_number */
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 10/12] linux-user: Add support for selecting alsa timer using ioctl
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (8 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 09/12] linux-user: Add support for getting/setting specified alsa timer parameters using ioctls Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 11/12] linux-user: Add support for getting/setting selected alsa timer parameters using ioctls Filip Bozuta
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionality of following ioctl:

SNDRV_TIMER_IOCTL_SELECT - Selecting timer

    Selects the timer which id is specified. The timer id is specified in the
    following strcuture:

    struct snd_timer_select {
        struct snd_timer_id id;         /* timer ID */
        unsigned char reserved[32];     /* reserved */
    };

    A pointer to this structure should be passed as the third ioctl's argument.
    Before calling the ioctl, the field "tid" should be initialized with the id
    information for the timer which is to be selected. If there is no timer
    device with the specified id, the error ENODEV ("No such device") is
    returned.

Implementation notes:

    Ioctl implemented in this patch has a pointer to a
    'struct snd_timer_select' as its third argument.
    That is the reason why a corresponding definition
    was added in 'linux-user/syscall_types.h'. The rest
    of the implementation was straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h        | 2 ++
 linux-user/syscall_defs.h  | 7 +++++++
 linux-user/syscall_types.h | 4 ++++
 3 files changed, 13 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 989eb9b..7652117 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -459,6 +459,8 @@
         MK_PTR(MK_STRUCT(STRUCT_snd_timer_gparams)))
   IOCTL(SNDRV_TIMER_IOCTL_GSTATUS, IOC_RW,
         MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
+  IOCTL(SNDRV_TIMER_IOCTL_SELECT, IOC_W,
+        MK_PTR(MK_STRUCT(STRUCT_snd_timer_select)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 4d4dad3..9a33b71 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2462,6 +2462,11 @@ struct target_snd_timer_gstatus {
     unsigned char reserved[32];
 };
 
+struct target_snd_timer_select {
+    struct target_snd_timer_id id;
+    unsigned char reserved[32];
+};
+
 /* alsa timer ioctls */
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION     TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,                     \
@@ -2473,6 +2478,8 @@ struct target_snd_timer_gstatus {
                                                          struct target_snd_timer_gparams)
 #define TARGET_SNDRV_TIMER_IOCTL_GSTATUS      TARGET_IOWR('T', 0x05,                     \
                                                           struct target_snd_timer_gstatus)
+#define TARGET_SNDRV_TIMER_IOCTL_SELECT       TARGET_IOW('T', 0x10,                      \
+                                                         struct target_snd_timer_select)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTH    TARGET_IORU('r', 1)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e90716..767632d 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -116,6 +116,10 @@ STRUCT(snd_timer_gstatus,
        TYPE_ULONG, /* resolution_den */
        MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
 
+STRUCT(snd_timer_select,
+       MK_STRUCT(STRUCT_snd_timer_id), /* id */
+       MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
+
 /* loop device ioctls */
 STRUCT(loop_info,
        TYPE_INT,                 /* lo_number */
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 11/12] linux-user: Add support for getting/setting selected alsa timer parameters using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (9 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 10/12] linux-user: Add support for selecting alsa timer using ioctl Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 15:53 ` [PATCH 12/12] linux-user: Add support for selected alsa timer instructions " Filip Bozuta
  2020-01-15 16:35 ` [PATCH 00/12] linux-user: Add support for real time clock and Laurent Vivier
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_INFO - Getting information about selected timer

    Read information about the selected timer. The information is returned in
    the following structure:

    struct snd_timer_info {
        unsigned int flags;         /* timer flags - SNDRV_TIMER_FLG_* */
        int card;                   /* card number */
        unsigned char id[64];       /* timer identificator */
        unsigned char name[80];     /* timer name */
        unsigned long reserved0;    /* reserved for future use */
        unsigned long resolution;   /* average period resolution in ns */
        unsigned char reserved[64]; /* reserved for future use */
    };

    A pointer to this structure should be passed as the third ioctl's argument.
    Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
    called first to select the timer which information is to be obtained. If no
    timer is selected, the error EBADFD ("File descriptor in bad shape") is
    returned.

SNDRV_TIMER_IOCTL_PARAMS - Setting parameters for selected timer

    Sets parameters for the selected timer. The paramaters are set in the
    following structure:

    struct snd_timer_params {
        unsigned int flags;         /* flags - SNDRV_TIMER_PSFLG_* */
        unsigned int ticks;         /* requested resolution in ticks */
        unsigned int queue_size;    /* total size of queue (32-1024) */
        unsigned int reserved0;     /* reserved, was: failure locations */
        unsigned int filter;        /* event filter */
        unsigned char reserved[60]; /* reserved */
    };

    A pointer to this structure should be passed as the third ioctl's argument.
    Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
    called first to select the timer which parameters are to be set. If no
    timer is selected, the error EBADFD ("File descriptor in bad shape") is
    returned.

SNDRV_TIMER_IOCTL_STATUS - Getting status of selected timer

    Read status of the selected timer. The status of the timer is returned in
    the following structure:

    struct snd_timer_status {
        struct timespec tstamp;     /* Timestamp - last update */
        unsigned int resolution;    /* current period resolution in ns */
        unsigned int lost;          /* counter of master tick lost */
        unsigned int overrun;       /* count of read queue overruns */
        unsigned int queue;         /* used queue size */
        unsigned char reserved[64]; /* reserved */
    };

    A pointer to this structure should be passed as the third ioctl's argument.
    Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
    called first to select the timer which status is to be obtained. If no
    timer is selected, the error EBADFD ("File descriptor in bad shape") is
    returned.

Implementation notes:

    All ioctls in this patch have pointer to some kind of a structure
    as their third argument. That is the reason why corresponding
    definitions were added in 'linux-user/syscall_types.h'. Structure
    'snd_timer_status' has field of type 'struct timespec' which is why
    a corresponding definition of that structure was also added in
    'linux-user/syscall_types.h'. All of these strucutures have some
    fields that are of type 'unsigned long'. That is the reason why
    separate target structures were defined in 'linux-user/syscall_defs.h'.
    Structure 'struct timespec' already had a separate target definition
    so that definition was used to define a target structure for
    'snd_timer_status'. The rest of the implementation was straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h        |  5 +++++
 linux-user/syscall_defs.h  | 25 +++++++++++++++++++++++++
 linux-user/syscall_types.h | 29 +++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 7652117..43e7e5d 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -461,6 +461,11 @@
         MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
   IOCTL(SNDRV_TIMER_IOCTL_SELECT, IOC_W,
         MK_PTR(MK_STRUCT(STRUCT_snd_timer_select)))
+  IOCTL(SNDRV_TIMER_IOCTL_INFO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_snd_timer_info)))
+  IOCTL(SNDRV_TIMER_IOCTL_PARAMS, IOC_W,
+        MK_PTR(MK_STRUCT(STRUCT_snd_timer_params)))
+  IOCTL(SNDRV_TIMER_IOCTL_STATUS, IOC_R,
+        MK_PTR(MK_STRUCT(STRUCT_snd_timer_status)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 9a33b71..d76124d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2467,6 +2467,25 @@ struct target_snd_timer_select {
     unsigned char reserved[32];
 };
 
+struct target_snd_timer_info {
+    unsigned int flags;
+    int card;
+    unsigned char id[64];
+    unsigned char name[80];
+    abi_ulong reserved0;
+    abi_ulong resolution;
+    unsigned char reserved[64];
+};
+
+struct target_snd_timer_status {
+    struct target_timespec tstamp;
+    unsigned int resolution;
+    unsigned int lost;
+    unsigned int overrun;
+    unsigned int queue;
+    unsigned char reserved[64];
+};
+
 /* alsa timer ioctls */
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION     TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,                     \
@@ -2480,6 +2499,12 @@ struct target_snd_timer_select {
                                                           struct target_snd_timer_gstatus)
 #define TARGET_SNDRV_TIMER_IOCTL_SELECT       TARGET_IOW('T', 0x10,                      \
                                                          struct target_snd_timer_select)
+#define TARGET_SNDRV_TIMER_IOCTL_INFO         TARGET_IOR('T', 0x11,                      \
+                                                         struct target_snd_timer_info)
+#define TARGET_SNDRV_TIMER_IOCTL_PARAMS       TARGET_IOW('T', 0x12,                      \
+                                                         struct snd_timer_params)
+#define TARGET_SNDRV_TIMER_IOCTL_STATUS       TARGET_IOR('T', 0x14,                      \
+                                                         struct target_snd_timer_status)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTH    TARGET_IORU('r', 1)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 767632d..fbc4be7 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -120,6 +120,35 @@ STRUCT(snd_timer_select,
        MK_STRUCT(STRUCT_snd_timer_id), /* id */
        MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
 
+STRUCT(snd_timer_info,
+       TYPE_INT, /* flags */
+       TYPE_INT, /* card */
+       MK_ARRAY(TYPE_CHAR, 64), /* id */
+       MK_ARRAY(TYPE_CHAR, 80), /* name */
+       TYPE_ULONG, /* reserved0 */
+       TYPE_ULONG, /* resolution */
+       MK_ARRAY(TYPE_CHAR, 64)) /* reserved */
+
+STRUCT(snd_timer_params,
+       TYPE_INT, /* flags */
+       TYPE_INT, /* ticks */
+       TYPE_INT, /* queue_size */
+       TYPE_INT, /* reserved0 */
+       TYPE_INT, /* filter */
+       MK_ARRAY(TYPE_CHAR, 60)) /* reserved */
+
+STRUCT(timespec,
+       TYPE_LONG, /* tv_sec */
+       TYPE_LONG) /* tv_nsec */
+
+STRUCT(snd_timer_status,
+       MK_STRUCT(STRUCT_timespec), /* tstamp */
+       TYPE_INT, /* resolution */
+       TYPE_INT, /* lost */
+       TYPE_INT, /* overrun */
+       TYPE_INT, /* queue */
+       MK_ARRAY(TYPE_CHAR, 64)) /* reserved */
+
 /* loop device ioctls */
 STRUCT(loop_info,
        TYPE_INT,                 /* lo_number */
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 12/12] linux-user: Add support for selected alsa timer instructions using ioctls
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (10 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 11/12] linux-user: Add support for getting/setting selected alsa timer parameters using ioctls Filip Bozuta
@ 2020-01-15 15:53 ` Filip Bozuta
  2020-01-15 16:35 ` [PATCH 00/12] linux-user: Add support for real time clock and Laurent Vivier
  12 siblings, 0 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, laurent,
	jcmvbkbc, amarkovic, philmd

This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_START - Start selected alsa timer

    Starts the timer device that is selected. The third ioctl's argument is
    ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
    should be called first to select the timer that is to be started. If no
    timer is selected, the error EBADFD ("File descriptor in bad shape")
    is returned.

SNDRV_TIMER_IOCTL_STOP - Stop selected alsa timer

    Stops the timer device that is selected. The third ioctl's argument is
    ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
    should be called first to select the timer that is to be stopped. If no
    timer is selected, the error EBADFD ("File descriptor in bad shape")
    is returned.

SNDRV_TIMER_IOCTL_CONTINUE - Continue selected alsa timer

    Continues the timer device that is selected. The third ioctl's argument is
    ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
    should be called first to select the timer that is to be continued. If no
    timer is selected, the error EBADFD ("File descriptor in bad shape")
    is returned.

SNDRV_TIMER_IOCTL_PAUSE - Pause selected alsa timer

    Pauses the timer device that is selected. The third ioctl's argument is
    ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
    should be called first to select the timer that is to be paused. If no
    timer is selected, the error EBADFD ("File descriptor in bad shape")
    is returned.

Implementation notes:

    Since all of the implemented ioctls have NULL as their third argument,
    their implementation was straightforward.

Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
---
 linux-user/ioctls.h       | 4 ++++
 linux-user/syscall_defs.h | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 43e7e5d..75a2f0e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -466,6 +466,10 @@
         MK_PTR(MK_STRUCT(STRUCT_snd_timer_params)))
   IOCTL(SNDRV_TIMER_IOCTL_STATUS, IOC_R,
         MK_PTR(MK_STRUCT(STRUCT_snd_timer_status)))
+  IOCTL(SNDRV_TIMER_IOCTL_START, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_STOP, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_CONTINUE, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_PAUSE, 0, TYPE_NULL)
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index d76124d..311aec0 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2505,6 +2505,10 @@ struct target_snd_timer_status {
                                                          struct snd_timer_params)
 #define TARGET_SNDRV_TIMER_IOCTL_STATUS       TARGET_IOR('T', 0x14,                      \
                                                          struct target_snd_timer_status)
+#define TARGET_SNDRV_TIMER_IOCTL_START        TARGET_IO('T', 0xa0)
+#define TARGET_SNDRV_TIMER_IOCTL_STOP         TARGET_IO('T', 0xa1)
+#define TARGET_SNDRV_TIMER_IOCTL_CONTINUE     TARGET_IO('T', 0xa2)
+#define TARGET_SNDRV_TIMER_IOCTL_PAUSE        TARGET_IO('T', 0xa3)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTH    TARGET_IORU('r', 1)
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 15:53 ` [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl Filip Bozuta
@ 2020-01-15 16:18   ` Arnd Bergmann
  2020-01-15 16:32     ` Laurent Vivier
  0 siblings, 1 reply; 35+ messages in thread
From: Arnd Bergmann @ 2020-01-15 16:18 UTC (permalink / raw)
  To: Filip Bozuta
  Cc: Peter Maydell, Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Laurent Vivier, Max Filippov,
	amarkovic, philmd

On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta <Filip.Bozuta@rt-rk.com> wrote:
>
> This patch implements functionality of following ioctl:
>
> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
>
>     Sets enhanced time read which is used for reading time with timestamps
>     and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
>     reading is set if the third argument is different than 0, otherwise normal
>     time reading is set.
>
> Implementation notes:
>
>     Because the implemented ioctl has 'int' as its third argument, the
>     implementation was straightforward.
>
> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>

I think this one is wrong when you go between 32-bit and 64-bit
targets, and it gets worse with the kernel patches that just got
merged for linux-5.5, which extends the behavior to deal with
64-bit time_t on 32-bit architectures.

Please have a look at
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859

       Arnd


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 16:18   ` Arnd Bergmann
@ 2020-01-15 16:32     ` Laurent Vivier
  2020-01-15 16:37       ` Arnd Bergmann
  0 siblings, 1 reply; 35+ messages in thread
From: Laurent Vivier @ 2020-01-15 16:32 UTC (permalink / raw)
  To: Arnd Bergmann, Filip Bozuta
  Cc: Peter Maydell, Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Max Filippov, amarkovic, philmd

Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta <Filip.Bozuta@rt-rk.com> wrote:
>>
>> This patch implements functionality of following ioctl:
>>
>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
>>
>>     Sets enhanced time read which is used for reading time with timestamps
>>     and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
>>     reading is set if the third argument is different than 0, otherwise normal
>>     time reading is set.
>>
>> Implementation notes:
>>
>>     Because the implemented ioctl has 'int' as its third argument, the
>>     implementation was straightforward.
>>
>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
> 
> I think this one is wrong when you go between 32-bit and 64-bit

kernel uses an "int" and "int" is always 32bit.
The problem is most likely with timespec I think.

> targets, and it gets worse with the kernel patches that just got
> merged for linux-5.5, which extends the behavior to deal with
> 64-bit time_t on 32-bit architectures.
> 
> Please have a look at
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859
> 
>        Arnd
> 

Yes, we already had the same kind of problem with SIOCGSTAMP and
SIOCGSTAMPNS.

Do the kernel patches add new ioctl numbers to differentiate 32bit and
64bit time_t?

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 00/12] linux-user: Add support for real time clock and
  2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
                   ` (11 preceding siblings ...)
  2020-01-15 15:53 ` [PATCH 12/12] linux-user: Add support for selected alsa timer instructions " Filip Bozuta
@ 2020-01-15 16:35 ` Laurent Vivier
  12 siblings, 0 replies; 35+ messages in thread
From: Laurent Vivier @ 2020-01-15 16:35 UTC (permalink / raw)
  To: Filip Bozuta, qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, jcmvbkbc,
	amarkovic, philmd

Hi Filip,

for the next time, please add the version number in the subject of all
the patches of the series, for instance:

  [PATCH v6 XX/12]

Thanks,
Laurent

Le 15/01/2020 à 16:53, Filip Bozuta a écrit :
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> This series covers following RTC and sound timer ioctls:
> 
>   RTC ioctls(22):
> 
>     * RTC_AIE_ON          * RTC_ALM_SET         * RTC_WKALM_SET
>     * RTC_AIE_OFF         * RTC_ALM_READ        * RTC_WKALM_RD
>     * RTC_UIE_ON          * RTC_RD_TIME         * RTC_PLL_GET
>     * RTC_UIE_OFF         * RTC_SET_TIME        * RTC_PLL_SET
>     * RTC_PIE_ON          * RTC_IRQP_READ       * RTC_VL_READ
>     * RTC_PIE_OFF         * RTC_IRQP_SET        * RTC_VL_CLR
>     * RTC_WIE_ON          * RTC_EPOCH_READ
>     * RTC_WIE_OFF         * RTC_EPOCH_SET
> 
>   Sound timer ioctls(14):
> 
>     * SNDRV_TIMER_IOCTL_PVERSION          * SNDRV_TIMER_IOCTL_INFO
>     * SNDRV_TIMER_IOCTL_NEXT_DEVICE       * SNDRV_TIMER_IOCTL_PARAMS
>     * SNDRV_TIMER_IOCTL_TREAD             * SNDRV_TIMER_IOCTL_STATUS
>     * SNDRV_TIMER_IOCTL_GINFO             * SNDRV_TIMER_IOCTL_START
>     * SNDRV_TIMER_IOCTL_GPARAMS           * SNDRV_TIMER_IOCTL_STOP
>     * SNDRV_TIMER_IOCTL_GSTATUS           * SNDRV_TIMER_IOCTL_CONTINUE
>     * SNDRV_TIMER_IOCTL_SELECT            * SNDRV_TIMER_IOCTL_PAUSE
> 
> The functionalities of individual ioctls were described in this series
> patch commit messages.
> 
> Testing method for RTC ioctls:
> 
>     Mini test programs were written for each ioctl. Those programs were
>     compiled (sometimes using cross-compilers) for the following
>     architectures:
> 
>         * Intel 64-bit (little endian)
>         * Power pc 32-bit (big endian)
>         * Power pc 64-bit (big endian)
> 
>     The corresponding native programs were executed without using
>     QEMU on following hosts:
> 
>         * Intel Core i7-4790K (x86_64 host)
>         * Power 7447A (ppc32 host)
> 
>     All applicable compiled programs were in turn executed through QEMU
>     and the results obtained were the same ones gotten for native
>     execution.
> 
>     Example of a test program:
> 
>         For ioctl RTC_RD_TIME the following test program was used:
> 
>         #include <stdio.h>
>         #include <stdlib.h>
>         #include <linux/rtc.h>
>         #include <fcntl.h>
>         #include <linux/input.h>
>         #include <sys/types.h>
>         #include <unistd.h>
> 
>         #define ERROR -1
> 
>         int main()
>         {
> 
>             int fd = open("/dev/rtc", O_RDWR | O_NONBLOCK);
> 
>             if(fd == ERROR)
>             {
>                 perror("open");
>                 return -1;
>             }
> 
>             struct rtc_time cur_time;
> 
>             if(ioctl(fd, RTC_RD_TIME, &cur_time) < 0)
>             {
>                 perror("ioctl");
>                 return -1;
>             }
> 
>             printf("Second: %d, Minute: %d, Hour: %d, Day: %d, Month: %d, Year: %d,",
>                 cur_time.tm_sec, cur_time.tm_min, cur_time.tm_hour, 
>                 cur_time.tm_mday, cur_time.tm_mon, cur_time.tm_year);
> 
>             return 0;
>         }
> 
>     Limitations of testing:
> 
>         The test host pc that was used for testing (intel pc) has RTC
>         that doesn't support all RTC features that are accessible
>         through ioctls. This means that testing can't discover
>         functionality errors related to the third argument of ioctls
>         that are used for features which are not supported. For example,
>         running the test program for ioctl RTC_EPOCH_READ gives
>         the error output: inappropriate ioctl for device. As expected,
>         the same output was obtained through QEMU which means that this
>         ioctl is recognized in QEMU but doesn't really do anything
>         because it is not supported in the host computer's RTC.
> 
>         Conclusion: Some RTC ioctls need to be tested on computers
>         that support their functionalities so that it can be inferred
>         that they are really supported in QEMU. In absence of such
>         test hosts, the specifications of those ioctls need to be
>         carefully checked manually and the implementations should be
>         updated accordingly.
> 
> Testing method for sound timer ioctls:
> 
>     The alsa ioctl test suite, that can be found on github
>     ("https://github.com/alsa-project/alsa-utils"), was used the test
>     the implemented ioctls. The file "timer.c", located in this test
>     suite, contains test functions that are used to test alsa timer
>     ioctls. This file was compiled (sometimes using cross-compilers) 
>     for the following architectures:
> 
>         * Intel 64-bit (little endian)
>         * Power pc 32-bit (big endian)
>         * Power pc 64-bit (big endian)
> 
>     The corresponding compiled test files were executed without using
>     QEMU on following hosts:
> 
>         * Intel Core i7-4790K (x86_64 host)
>         * Power 7447A (ppc32 host)
> 
>     The corresponding native compiled test files were executed without using
>     QEMU on following hosts:
> 
>         * Intel Core i7-4790K (x86_64 host)
>         * Power 7447A (ppc32 host)
> 
>     All compiled test files were in turn executed through QEMU
>     and the results obtained were the same ones gotten for native
>     execution.
> 
>     Also, mini test programs were written to test further functionalities
>     of individual ioctls. Those programs were, like the file "timer.c",
>     compiled for different architectures and were executed both natively
>     and thgrough QEMU to compare the results.
> 
>     Example of a test program:
> 
>         For ioctl SNDRV_TIMER_IOCTL_GINFO the following test program was used:
> 
>         #include <stdio.h>
>         #include <stdlib.h>
>         #include <sys/types.h>
>         #include <fcntl.h>
>         #include <sys/ioctl.h>
>         #include <sound/asound.h>
> 
>         #define ERROR -1
> 
>         int main()
>         {
>             int fd = open("/dev/snd/timer", O_RDWR);
> 
>             if(fd == ERROR)
>             {
>                 perror("open");
>                 return -1;
>             }
> 
>             struct snd_timer_id id = {SNDRV_TIMER_CLASS_GLOBAL, 
>                                       SNDRV_TIMER_SCLASS_NONE, -1, 
>                                       SNDRV_TIMER_GLOBAL_SYSTEM, 0};
> 
>             struct snd_timer_ginfo ginfo;
>             ginfo.tid = id;
> 
>             if(ioctl(fd, SNDRV_TIMER_IOCTL_GINFO, &ginfo) == ERROR)
>             {
>                 perror("ioctl");
>                 return -1;
>             }
> 
>             printf("flags: %u\n", ginfo.flags);
>             printf("card: %d\n", ginfo.card);
>             printf("id: %s\n", ginfo.id);
>             printf("name: %s\n", ginfo.name);
>             printf("reserved0: %lu\n", ginfo.reserved0);
>             printf("resolution: %lu\n", ginfo.resolution);
>             printf("resolution_min: %lu\n", ginfo.resolution_min);
>             printf("reolution_max: %lu\n", ginfo.resolution_max);
>             printf("clients: %u\n", ginfo.clients);
>             printf("reserved: %s\n", ginfo.reserved);
> 
>             return 0;
>         }
> 
> v6:
> 
>     * fixed one patch by adding a case statement for 'unsigned long'
>       to recognize two ioctls that are implemented in that patch
> 
>     * changed patch descriptions a little bit so that they are more
>       comprehensible
> 
> v5:
> 
>     * added support for alsa sound timer ioctls
> 
> v4:
> 
>     * changed patch descriptions so that they are better
>       formatted and more comprehensible
> 
> v3:
> 
>     * changed two instances of MK_PTR(TYPE_ULONG) to TYPE_ULONG
> 
> v2:
> 
>     * added description of each ioctl in patches
>     * wrote a more detailed cover letter with description of testing
>     * changed one instance of TYPE_INT to MK_PTR(TYPE_INT)
> 
> Filip Bozuta (12):
>   linux-user: Add support for enabling/disabling RTC features using
>     ioctls
>   linux-user: Add support for getting/setting RTC time and alarm using
>     ioctls
>   linux-user: Add support for getting/setting RTC periodic interrupt and
>     epoch using ioctls
>   linux-user: Add support for getting/setting RTC wakeup alarm using
>     ioctls
>   linux-user: Add support for getting/setting RTC PLL correction using
>     ioctls
>   linux-user: Add support for read/clear RTC voltage low detector using
>     ioctls
>   linux-user: Add support for getting alsa timer version and id
>   linux-user: Add support for setting alsa timer enhanced read using
>     ioctl
>   linux-user: Add support for getting/setting specified alsa timer
>     parameters using ioctls
>   linux-user: Add support for selecting alsa timer using ioctl
>   linux-user: Add support for getting/setting selected alsa timer
>     parameters using ioctls
>   linux-user: Add support for selected alsa timer instructions using
>     ioctls
> 
>  linux-user/ioctls.h        |  45 +++++++++++++++++
>  linux-user/syscall.c       |   3 ++
>  linux-user/syscall_defs.h  | 121 +++++++++++++++++++++++++++++++++++++++++++++
>  linux-user/syscall_types.h |  91 ++++++++++++++++++++++++++++++++++
>  4 files changed, 260 insertions(+)
> 



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 16:32     ` Laurent Vivier
@ 2020-01-15 16:37       ` Arnd Bergmann
  2020-01-15 19:17         ` Filip Bozuta
  0 siblings, 1 reply; 35+ messages in thread
From: Arnd Bergmann @ 2020-01-15 16:37 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Peter Maydell, Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Filip Bozuta, Max Filippov,
	amarkovic, philmd

On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
>
> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
> > On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta <Filip.Bozuta@rt-rk.com> wrote:
> >>
> >> This patch implements functionality of following ioctl:
> >>
> >> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
> >>
> >>     Sets enhanced time read which is used for reading time with timestamps
> >>     and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
> >>     reading is set if the third argument is different than 0, otherwise normal
> >>     time reading is set.
> >>
> >> Implementation notes:
> >>
> >>     Because the implemented ioctl has 'int' as its third argument, the
> >>     implementation was straightforward.
> >>
> >> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
> >
> > I think this one is wrong when you go between 32-bit and 64-bit
>
> kernel uses an "int" and "int" is always 32bit.
> The problem is most likely with timespec I think.
>
> > targets, and it gets worse with the kernel patches that just got
> > merged for linux-5.5, which extends the behavior to deal with
> > 64-bit time_t on 32-bit architectures.
> >
> > Please have a look at
> > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859
>
> Yes, we already had the same kind of problem with SIOCGSTAMP and
> SIOCGSTAMPNS.
>
> Do the kernel patches add new ioctl numbers to differentiate 32bit and
> 64bit time_t?

Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
is a pure 'int' that decides what format you get when you 'read' from the
same file descriptor.

For emulating 64-bit on 32-bit kernels, you have to use the new
SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
64-bit kernels, you probably have to return -ENOTTY to
SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
emulate the read() behavior.
When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
you can translate that into the 64-bit
SNDRV_TIMER_IOCTL_TREAD_OLD.

     Arnd


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls
  2020-01-15 15:53 ` [PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch " Filip Bozuta
@ 2020-01-15 16:46   ` Laurent Vivier
  0 siblings, 0 replies; 35+ messages in thread
From: Laurent Vivier @ 2020-01-15 16:46 UTC (permalink / raw)
  To: Filip Bozuta, qemu-devel
  Cc: peter.maydell, berrange, arnd, richard.henderson, jcmvbkbc,
	amarkovic, philmd

Le 15/01/2020 à 16:53, Filip Bozuta a écrit :
> This patch implements functionalities of following ioctls:
> 
> RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate
> 
>     Read and set the frequency for periodic interrupts, for RTCs
>     that support periodic interrupts. The periodic interrupt must
>     be separately enabled or disabled using the RTC_PIE_ON,
>     RTC_PIE_OFF requests. The third ioctl's argument is an
>     unsigned long * or an unsigned long, respectively. The value
>     is the frequency in interrupts per second. The set of allow‐
>     able frequencies is the multiples of two in the range 2 to
>     8192. Only a privileged process (i.e., one having the
>     CAP_SYS_RESOURCE capability) can set frequencies above the
>     value specified in /proc/sys/dev/rtc/max-user-freq. (This
>     file contains the value 64 by default.)
> 
> RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch
> 
>     Many RTCs encode the year in an 8-bit register which is either
>     interpreted as an 8-bit binary number or as a BCD number. In
>     both cases, the number is interpreted relative to this RTC's
>     Epoch. The RTC's Epoch is initialized to 1900 on most systems
>     but on Alpha and MIPS it might also be initialized to 1952,
>     1980, or 2000, depending on the value of an RTC register for
>     the year. With some RTCs, these operations can be used to
>     read or to set the RTC's Epoch, respectively. The third
>     ioctl's argument is an unsigned long * or an unsigned long,
>     respectively, and the value returned (or assigned) is the
>     Epoch. To set the RTC's Epoch the process must be privileged
>     (i.e., have the CAP_SYS_TIME capability).
> 
> Implementation notes:
> 
>     All ioctls in this patch have a pointer to 'ulong' as their
>     third argument. That is the reason why corresponding parts
>     of added code in linux-user/syscall_defs.h contain special
>     handling related to 'ulong' type: they use 'abi_ulong' type
>     to make sure that ioctl's code is calculated correctly for
>     both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
>     is used for the similar reason in linux-user/ioctls.h.
>     Because ioctls RTC_IRQP_SET and RTC_EPOCH_SET are ioctls of
>     type IOW(writing type) that have unsigned long as their
>     third argument, a case statement for "TYPE_ULONG" was added
>     in the appropriate place for function "abi_ulong do_ioctl"
>     in file "syscall.c". There were no implemented ioctls of
>     type IOW with unsigned long as third argument before this
>     patch, which is the reason why this case statement was added
>     now for the first time.
> 
> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
> ---
>  linux-user/ioctls.h       | 4 ++++
>  linux-user/syscall.c      | 1 +
>  linux-user/syscall_defs.h | 4 ++++
>  3 files changed, 9 insertions(+)
> 
...
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 74c3c08..c0b7314 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -5175,6 +5175,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
>          break;
>      case TYPE_PTRVOID:
>      case TYPE_INT:
> +    case TYPE_ULONG:
>          ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg));
>          break;
>      case TYPE_PTR:

I think this can go in a separate patch as it's a fix.

You should also add TYPE_LONG.

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 16:37       ` Arnd Bergmann
@ 2020-01-15 19:17         ` Filip Bozuta
  2020-01-15 19:51           ` Arnd Bergmann
  2020-01-15 21:52           ` Laurent Vivier
  0 siblings, 2 replies; 35+ messages in thread
From: Filip Bozuta @ 2020-01-15 19:17 UTC (permalink / raw)
  To: Arnd Bergmann, Laurent Vivier
  Cc: Peter Maydell, Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Max Filippov, amarkovic, philmd


On 15.1.20. 17:37, Arnd Bergmann wrote:
> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta <Filip.Bozuta@rt-rk.com> wrote:
>>>> This patch implements functionality of following ioctl:
>>>>
>>>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
>>>>
>>>>      Sets enhanced time read which is used for reading time with timestamps
>>>>      and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
>>>>      reading is set if the third argument is different than 0, otherwise normal
>>>>      time reading is set.
>>>>
>>>> Implementation notes:
>>>>
>>>>      Because the implemented ioctl has 'int' as its third argument, the
>>>>      implementation was straightforward.
>>>>
>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
>>> I think this one is wrong when you go between 32-bit and 64-bit
>> kernel uses an "int" and "int" is always 32bit.
>> The problem is most likely with timespec I think.
>>
>>> targets, and it gets worse with the kernel patches that just got
>>> merged for linux-5.5, which extends the behavior to deal with
>>> 64-bit time_t on 32-bit architectures.
>>>
>>> Please have a look at
>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859
>> Yes, we already had the same kind of problem with SIOCGSTAMP and
>> SIOCGSTAMPNS.
>>
>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
>> 64bit time_t?
> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
> is a pure 'int' that decides what format you get when you 'read' from the
> same file descriptor.
>
> For emulating 64-bit on 32-bit kernels, you have to use the new
> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
> 64-bit kernels, you probably have to return -ENOTTY to
> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
> emulate the read() behavior.
> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
> you can translate that into the 64-bit
> SNDRV_TIMER_IOCTL_TREAD_OLD.
>
>       Arnd


Thank you for bringing this up to my attention. Unfortunately i have 
some duties of academic nature in next month so i won't have much time 
fix this bug. I will try to fix this as soon as possible.

Best regards,

Filip Bozuta



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 19:17         ` Filip Bozuta
@ 2020-01-15 19:51           ` Arnd Bergmann
  2020-01-15 21:30             ` Laurent Vivier
  2020-01-15 21:52           ` Laurent Vivier
  1 sibling, 1 reply; 35+ messages in thread
From: Arnd Bergmann @ 2020-01-15 19:51 UTC (permalink / raw)
  To: Filip Bozuta
  Cc: Peter Maydell, Daniel P. Berrangé,
	Richard Henderson, Laurent Vivier, qemu-devel, Max Filippov,
	amarkovic, philmd

On Wed, Jan 15, 2020 at 8:17 PM Filip Bozuta <Filip.Bozuta@rt-rk.com> wrote:
> On 15.1.20. 17:37, Arnd Bergmann wrote:
> > On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
> >> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
> >>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta <Filip.Bozuta@rt-rk.com> wrote:
> >> Do the kernel patches add new ioctl numbers to differentiate 32bit and
> >> 64bit time_t?
> >
> > Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
> > is a pure 'int' that decides what format you get when you 'read' from the
> > same file descriptor.
> >
> > For emulating 64-bit on 32-bit kernels, you have to use the new
> > SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
> > 64-bit kernels, you probably have to return -ENOTTY to
> > SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
> > emulate the read() behavior.
> > When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
> > you can translate that into the 64-bit
> > SNDRV_TIMER_IOCTL_TREAD_OLD.

>
> Thank you for bringing this up to my attention. Unfortunately i have
> some duties of academic nature in next month so i won't have much time
> fix this bug. I will try to fix this as soon as possible.

One more thing: I just realized it gets worse when emulating cross-endian,
as then even without calling SNDRV_TIMER_IOCTL_TREAD, reading
data from /dev/snd/timer requires byteswapping the two words.

     Arnd


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 19:51           ` Arnd Bergmann
@ 2020-01-15 21:30             ` Laurent Vivier
  0 siblings, 0 replies; 35+ messages in thread
From: Laurent Vivier @ 2020-01-15 21:30 UTC (permalink / raw)
  To: Arnd Bergmann, Filip Bozuta
  Cc: Peter Maydell, Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Max Filippov, amarkovic, philmd

Le 15/01/2020 à 20:51, Arnd Bergmann a écrit :
> On Wed, Jan 15, 2020 at 8:17 PM Filip Bozuta <Filip.Bozuta@rt-rk.com> wrote:
>> On 15.1.20. 17:37, Arnd Bergmann wrote:
>>> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
>>>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
>>>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta <Filip.Bozuta@rt-rk.com> wrote:
>>>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
>>>> 64bit time_t?
>>>
>>> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
>>> is a pure 'int' that decides what format you get when you 'read' from the
>>> same file descriptor.
>>>
>>> For emulating 64-bit on 32-bit kernels, you have to use the new
>>> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
>>> 64-bit kernels, you probably have to return -ENOTTY to
>>> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
>>> emulate the read() behavior.
>>> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
>>> you can translate that into the 64-bit
>>> SNDRV_TIMER_IOCTL_TREAD_OLD.
> 
>>
>> Thank you for bringing this up to my attention. Unfortunately i have
>> some duties of academic nature in next month so i won't have much time
>> fix this bug. I will try to fix this as soon as possible.
> 
> One more thing: I just realized it gets worse when emulating cross-endian,
> as then even without calling SNDRV_TIMER_IOCTL_TREAD, reading
> data from /dev/snd/timer requires byteswapping the two words.

We already have this case with netlink and we are able to translate data
on the fly.

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 19:17         ` Filip Bozuta
  2020-01-15 19:51           ` Arnd Bergmann
@ 2020-01-15 21:52           ` Laurent Vivier
  2020-01-16  2:49             ` Aleksandar Markovic
  1 sibling, 1 reply; 35+ messages in thread
From: Laurent Vivier @ 2020-01-15 21:52 UTC (permalink / raw)
  To: Filip Bozuta, Arnd Bergmann
  Cc: Peter Maydell, Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Max Filippov, amarkovic, philmd

Le 15/01/2020 à 20:17, Filip Bozuta a écrit :
> 
> On 15.1.20. 17:37, Arnd Bergmann wrote:
>> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
>>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
>>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta
>>>> <Filip.Bozuta@rt-rk.com> wrote:
>>>>> This patch implements functionality of following ioctl:
>>>>>
>>>>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
>>>>>
>>>>>      Sets enhanced time read which is used for reading time with
>>>>> timestamps
>>>>>      and events. The third ioctl's argument is a pointer to an
>>>>> 'int'. Enhanced
>>>>>      reading is set if the third argument is different than 0,
>>>>> otherwise normal
>>>>>      time reading is set.
>>>>>
>>>>> Implementation notes:
>>>>>
>>>>>      Because the implemented ioctl has 'int' as its third argument,
>>>>> the
>>>>>      implementation was straightforward.
>>>>>
>>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
>>>> I think this one is wrong when you go between 32-bit and 64-bit
>>> kernel uses an "int" and "int" is always 32bit.
>>> The problem is most likely with timespec I think.
>>>
>>>> targets, and it gets worse with the kernel patches that just got
>>>> merged for linux-5.5, which extends the behavior to deal with
>>>> 64-bit time_t on 32-bit architectures.
>>>>
>>>> Please have a look at
>>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859
>>>>
>>> Yes, we already had the same kind of problem with SIOCGSTAMP and
>>> SIOCGSTAMPNS.
>>>
>>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
>>> 64bit time_t?
>> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
>> is a pure 'int' that decides what format you get when you 'read' from the
>> same file descriptor.
>>
>> For emulating 64-bit on 32-bit kernels, you have to use the new
>> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
>> 64-bit kernels, you probably have to return -ENOTTY to
>> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
>> emulate the read() behavior.
>> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
>> you can translate that into the 64-bit
>> SNDRV_TIMER_IOCTL_TREAD_OLD.
>>
>>       Arnd
> 
> 
> Thank you for bringing this up to my attention. Unfortunately i have
> some duties of academic nature in next month so i won't have much time
> fix this bug. I will try to fix this as soon as possible.

Could you at least to try to have a mergeable series before you have to
stop to work on this?

You can only manage the case before the change reported by Arnd (I will
manage the new case myself later).

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-15 21:52           ` Laurent Vivier
@ 2020-01-16  2:49             ` Aleksandar Markovic
  2020-01-16 11:27               ` Aleksandar Markovic
  0 siblings, 1 reply; 35+ messages in thread
From: Aleksandar Markovic @ 2020-01-16  2:49 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Peter Maydell, Daniel P. Berrangé,
	Arnd Bergmann, Richard Henderson, qemu-devel, Filip Bozuta,
	Max Filippov, amarkovic, philmd

[-- Attachment #1: Type: text/plain, Size: 4315 bytes --]

On Wednesday, January 15, 2020, Laurent Vivier <laurent@vivier.eu> wrote:

> Le 15/01/2020 à 20:17, Filip Bozuta a écrit :
> >
> > On 15.1.20. 17:37, Arnd Bergmann wrote:
> >> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu>
> wrote:
> >>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
> >>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta
> >>>> <Filip.Bozuta@rt-rk.com> wrote:
> >>>>> This patch implements functionality of following ioctl:
> >>>>>
> >>>>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
> >>>>>
> >>>>>      Sets enhanced time read which is used for reading time with
> >>>>> timestamps
> >>>>>      and events. The third ioctl's argument is a pointer to an
> >>>>> 'int'. Enhanced
> >>>>>      reading is set if the third argument is different than 0,
> >>>>> otherwise normal
> >>>>>      time reading is set.
> >>>>>
> >>>>> Implementation notes:
> >>>>>
> >>>>>      Because the implemented ioctl has 'int' as its third argument,
> >>>>> the
> >>>>>      implementation was straightforward.
> >>>>>
> >>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
> >>>> I think this one is wrong when you go between 32-bit and 64-bit
> >>> kernel uses an "int" and "int" is always 32bit.
> >>> The problem is most likely with timespec I think.
> >>>
> >>>> targets, and it gets worse with the kernel patches that just got
> >>>> merged for linux-5.5, which extends the behavior to deal with
> >>>> 64-bit time_t on 32-bit architectures.
> >>>>
> >>>> Please have a look at
> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-n
> ext.git/log/?h=80fe7430c70859
> >>>>
> >>> Yes, we already had the same kind of problem with SIOCGSTAMP and
> >>> SIOCGSTAMPNS.
> >>>
> >>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
> >>> 64bit time_t?
> >> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
> >> is a pure 'int' that decides what format you get when you 'read' from
> the
> >> same file descriptor.
> >>
> >> For emulating 64-bit on 32-bit kernels, you have to use the new
> >> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
> >> 64-bit kernels, you probably have to return -ENOTTY to
> >> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
> >> emulate the read() behavior.
> >> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
> >> you can translate that into the 64-bit
> >> SNDRV_TIMER_IOCTL_TREAD_OLD.
> >>
> >>       Arnd
> >
> >
> > Thank you for bringing this up to my attention. Unfortunately i have
> > some duties of academic nature in next month so i won't have much time
> > fix this bug. I will try to fix this as soon as possible.
>
> Could you at least to try to have a mergeable series before you have to
> stop to work on this?
>
> You can only manage the case before the change reported by Arnd (I will
> manage the new case myself later).
>
>
Hi, all.

Sorry for interjecting myself into this discussion, but I just want to let
you know about some related practicalities.

Filip is a student that is from time to time (usually between two exam
seasons) an intern in our company, working 4 hours each work day. He spent
his internship in different teams in prevous years, and, from around
mid-October 2019, was appointed to QEMU team. After some introductory
tasks, he was assigned his main task: linux-user support for RTCs and ALSA
timers. This series is the result of his work, and, to my great pleasure,
is virtually entirely his independant work. I am positive he can complete
the series by himself, even in the light of additional complexities
mentioned in this thread.

However, his exam season just started (Jan. 15th), and lasts till Feb.
15th. Our policy, in general, is not to burden the students during exam
seasons, and that is why we can't expect prompt updates from him for the
time being.

In view of this, Laurent, please take Filip's status into consideration. As
far as mergeability is concerned, my impression is that patches 1-6 and 13
are ready for merging, while patches 7-12 would require some additional
(netlink-support-like) work, that would unfortunately be possible only
after Feb. 15th.

Best wishes,
Aleksandar




Thanks,
> Laurent
>
>
>

[-- Attachment #2: Type: text/html, Size: 5951 bytes --]

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-16  2:49             ` Aleksandar Markovic
@ 2020-01-16 11:27               ` Aleksandar Markovic
  2020-01-16 12:00                   ` Arnd Bergmann
  0 siblings, 1 reply; 35+ messages in thread
From: Aleksandar Markovic @ 2020-01-16 11:27 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Peter Maydell, Daniel P. Berrangé,
	Arnd Bergmann, Richard Henderson, qemu-devel, Filip Bozuta,
	Max Filippov, amarkovic, philmd

[-- Attachment #1: Type: text/plain, Size: 4940 bytes --]

On Thursday, January 16, 2020, Aleksandar Markovic <
aleksandar.m.mail@gmail.com> wrote:

>
>
> On Wednesday, January 15, 2020, Laurent Vivier <laurent@vivier.eu> wrote:
>
>> Le 15/01/2020 à 20:17, Filip Bozuta a écrit :
>> >
>> > On 15.1.20. 17:37, Arnd Bergmann wrote:
>> >> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu>
>> wrote:
>> >>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
>> >>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta
>> >>>> <Filip.Bozuta@rt-rk.com> wrote:
>> >>>>> This patch implements functionality of following ioctl:
>> >>>>>
>> >>>>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
>> >>>>>
>> >>>>>      Sets enhanced time read which is used for reading time with
>> >>>>> timestamps
>> >>>>>      and events. The third ioctl's argument is a pointer to an
>> >>>>> 'int'. Enhanced
>> >>>>>      reading is set if the third argument is different than 0,
>> >>>>> otherwise normal
>> >>>>>      time reading is set.
>> >>>>>
>> >>>>> Implementation notes:
>> >>>>>
>> >>>>>      Because the implemented ioctl has 'int' as its third argument,
>> >>>>> the
>> >>>>>      implementation was straightforward.
>> >>>>>
>> >>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
>> >>>> I think this one is wrong when you go between 32-bit and 64-bit
>> >>> kernel uses an "int" and "int" is always 32bit.
>> >>> The problem is most likely with timespec I think.
>> >>>
>> >>>> targets, and it gets worse with the kernel patches that just got
>> >>>> merged for linux-5.5, which extends the behavior to deal with
>> >>>> 64-bit time_t on 32-bit architectures.
>> >>>>
>> >>>> Please have a look at
>> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-n
>> ext.git/log/?h=80fe7430c70859
>> >>>>
>> >>> Yes, we already had the same kind of problem with SIOCGSTAMP and
>> >>> SIOCGSTAMPNS.
>> >>>
>> >>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
>> >>> 64bit time_t?
>> >> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
>> >> is a pure 'int' that decides what format you get when you 'read' from
>> the
>> >> same file descriptor.
>> >>
>> >> For emulating 64-bit on 32-bit kernels, you have to use the new
>> >> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
>> >> 64-bit kernels, you probably have to return -ENOTTY to
>> >> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
>> >> emulate the read() behavior.
>> >> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
>> >> you can translate that into the 64-bit
>> >> SNDRV_TIMER_IOCTL_TREAD_OLD.
>> >>
>> >>       Arnd
>> >
>> >
>> > Thank you for bringing this up to my attention. Unfortunately i have
>> > some duties of academic nature in next month so i won't have much time
>> > fix this bug. I will try to fix this as soon as possible.
>>
>> Could you at least to try to have a mergeable series before you have to
>> stop to work on this?
>>
>> You can only manage the case before the change reported by Arnd (I will
>> manage the new case myself later).
>>
>>
> Hi, all.
>
> Sorry for interjecting myself into this discussion, but I just want to let
> you know about some related practicalities.
>
> Filip is a student that is from time to time (usually between two exam
> seasons) an intern in our company, working 4 hours each work day. He spent
> his internship in different teams in prevous years, and, from around
> mid-October 2019, was appointed to QEMU team. After some introductory
> tasks, he was assigned his main task: linux-user support for RTCs and ALSA
> timers. This series is the result of his work, and, to my great pleasure,
> is virtually entirely his independant work. I am positive he can complete
> the series by himself, even in the light of additional complexities
> mentioned in this thread.
>
> However, his exam season just started (Jan. 15th), and lasts till Feb.
> 15th. Our policy, in general, is not to burden the students during exam
> seasons, and that is why we can't expect prompt updates from him for the
> time being.
>
> In view of this, Laurent, please take Filip's status into consideration.
> As far as mergeability is concerned, my impression is that patches 1-6 and
> 13 are ready for merging, while patches 7-12 would require some additional
> (netlink-support-like) work, that would unfortunately be possible only
> after Feb. 15th.
>
> Best wishes,
> Aleksandar
>
>
>
Laurent, hi again.

I am not completely familiar with all details of Filip's work, since, as I
said, he had large degree of independance (which was intentional, and is a
desired and good thing IMHO), but taking a closer look, a question starting
lingering: Do we need special handling od read() even for RTC devices - not
only ALSA timer devices?

Best regards,
Aleksandar


>
>
> Thanks,
>> Laurent
>>
>>
>>

[-- Attachment #2: Type: text/html, Size: 6810 bytes --]

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-16 11:27               ` Aleksandar Markovic
@ 2020-01-16 12:00                   ` Arnd Bergmann
  0 siblings, 0 replies; 35+ messages in thread
From: Arnd Bergmann @ 2020-01-16 12:00 UTC (permalink / raw)
  To: Aleksandar Markovic
  Cc: Laurent Vivier, Filip Bozuta, Peter Maydell,
	Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Max Filippov, amarkovic, philmd,
	Alexandre Belloni, linux-rtc

On Thu, Jan 16, 2020 at 12:27 PM Aleksandar Markovic
<aleksandar.m.mail@gmail.com> wrote:
> On Thursday, January 16, 2020, Aleksandar Markovic <aleksandar.m.mail@gmail.com> wrote:
>> On Wednesday, January 15, 2020, Laurent Vivier <laurent@vivier.eu> wrote:
>>> Le 15/01/2020 à 20:17, Filip Bozuta a écrit :
>>> > On 15.1.20. 17:37, Arnd Bergmann wrote:
>>> >> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
>>> >>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
>>> >>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta
>>> >>>> <Filip.Bozuta@rt-rk.com> wrote:
>>> >>>>> This patch implements functionality of following ioctl:
>>> >>>>>
>>> >>>>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
>>> >>>>>
>>> >>>>>      Sets enhanced time read which is used for reading time with
>>> >>>>> timestamps
>>> >>>>>      and events. The third ioctl's argument is a pointer to an
>>> >>>>> 'int'. Enhanced
>>> >>>>>      reading is set if the third argument is different than 0,
>>> >>>>> otherwise normal
>>> >>>>>      time reading is set.
>>> >>>>>
>>> >>>>> Implementation notes:
>>> >>>>>
>>> >>>>>      Because the implemented ioctl has 'int' as its third argument,
>>> >>>>> the
>>> >>>>>      implementation was straightforward.
>>> >>>>>
>>> >>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
>>> >>>> I think this one is wrong when you go between 32-bit and 64-bit
>>> >>> kernel uses an "int" and "int" is always 32bit.
>>> >>> The problem is most likely with timespec I think.
>>> >>>
>>> >>>> targets, and it gets worse with the kernel patches that just got
>>> >>>> merged for linux-5.5, which extends the behavior to deal with
>>> >>>> 64-bit time_t on 32-bit architectures.
>>> >>>>
>>> >>>> Please have a look at
>>> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859
>>> >>>>
>>> >>> Yes, we already had the same kind of problem with SIOCGSTAMP and
>>> >>> SIOCGSTAMPNS.
>>> >>>
>>> >>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
>>> >>> 64bit time_t?
>>> >> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
>>> >> is a pure 'int' that decides what format you get when you 'read' from the
>>> >> same file descriptor.
>>> >>
>>> >> For emulating 64-bit on 32-bit kernels, you have to use the new
>>> >> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
>>> >> 64-bit kernels, you probably have to return -ENOTTY to
>>> >> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
>>> >> emulate the read() behavior.
>>> >> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
>>> >> you can translate that into the 64-bit
>>> >> SNDRV_TIMER_IOCTL_TREAD_OLD.
>>> >
>>> > Thank you for bringing this up to my attention. Unfortunately i have
>>> > some duties of academic nature in next month so i won't have much time
>>> > fix this bug. I will try to fix this as soon as possible.
>>>
>>> Could you at least to try to have a mergeable series before you have to
>>> stop to work on this?
>>>
>>> You can only manage the case before the change reported by Arnd (I will
>>> manage the new case myself later).

>>
>> Sorry for interjecting myself into this discussion, but I just want to let you know about some related practicalities.
>>
>> Filip is a student that is from time to time (usually between two exam seasons) an intern in our company, working 4 hours each work day. He spent his internship in different teams in prevous years, and, from around mid-October 2019, was appointed to QEMU team. After some introductory tasks, he was assigned his main task: linux-user support for RTCs and ALSA timers. This series is the result of his work, and, to my great pleasure, is virtually entirely his independant work. I am positive he can complete the series by himself, even in the light of additional complexities mentioned in this thread.
>>
>> However, his exam season just started (Jan. 15th), and lasts till Feb. 15th. Our policy, in general, is not to burden the students during exam seasons, and that is why we can't expect prompt updates from him for the time being.
>>
>> In view of this, Laurent, please take Filip's status into consideration. As far as mergeability is concerned, my impression is that patches 1-6 and 13 are ready for merging, while patches 7-12 would require some additional (netlink-support-like) work, that would unfortunately be possible only after Feb. 15th.
>>

> Laurent, hi again.
>
> I am not completely familiar with all details of Filip's work, since, as I said, he had
> large degree of independance (which was intentional, and is a desired and good
> thing IMHO), but taking a closer look, a question starting lingering: Do we need
> special handling od read() even for RTC devices - not only ALSA timer devices?

Adding Alexandre Belloni and the RTC list to Cc for more expertise. Alexandre,
this question is about how qemu-user should emulate the rtc ioctl interface when
running a user binary for a foreign architecture. The ioctl emulation seems fine
to me, but read() from /dev/rtc is probably not.

As I understand it, reading from /dev/rtc is one of the more obscure features.
This would return either 32 bits or 64 bits of structured data from the kernel,
depending on how much data was requested and whether the kernel runs
as 64 bit. A 32-bit process running on a 64-bit kernel will get the correct
result when it asks for 4 bytes, but probably not when it asks for 8 bytes.
(we could fix this with an explict check for in_compat_syscall() in the kernel
function).

A process running on qemu with the opposite endianess will always get the
wrong result (unless the kernel returns 0), and emulating 64-bit task on
a 32-bit kernel will result in only four bytes to be read, which also likely
results in incorrect behavior.

       Arnd

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
@ 2020-01-16 12:00                   ` Arnd Bergmann
  0 siblings, 0 replies; 35+ messages in thread
From: Arnd Bergmann @ 2020-01-16 12:00 UTC (permalink / raw)
  To: Aleksandar Markovic
  Cc: linux-rtc, Peter Maydell, Alexandre Belloni,
	Daniel P. Berrangé,
	Richard Henderson, Laurent Vivier, Filip Bozuta, qemu-devel,
	Max Filippov, amarkovic, philmd

On Thu, Jan 16, 2020 at 12:27 PM Aleksandar Markovic
<aleksandar.m.mail@gmail.com> wrote:
> On Thursday, January 16, 2020, Aleksandar Markovic <aleksandar.m.mail@gmail.com> wrote:
>> On Wednesday, January 15, 2020, Laurent Vivier <laurent@vivier.eu> wrote:
>>> Le 15/01/2020 à 20:17, Filip Bozuta a écrit :
>>> > On 15.1.20. 17:37, Arnd Bergmann wrote:
>>> >> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
>>> >>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
>>> >>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta
>>> >>>> <Filip.Bozuta@rt-rk.com> wrote:
>>> >>>>> This patch implements functionality of following ioctl:
>>> >>>>>
>>> >>>>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
>>> >>>>>
>>> >>>>>      Sets enhanced time read which is used for reading time with
>>> >>>>> timestamps
>>> >>>>>      and events. The third ioctl's argument is a pointer to an
>>> >>>>> 'int'. Enhanced
>>> >>>>>      reading is set if the third argument is different than 0,
>>> >>>>> otherwise normal
>>> >>>>>      time reading is set.
>>> >>>>>
>>> >>>>> Implementation notes:
>>> >>>>>
>>> >>>>>      Because the implemented ioctl has 'int' as its third argument,
>>> >>>>> the
>>> >>>>>      implementation was straightforward.
>>> >>>>>
>>> >>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
>>> >>>> I think this one is wrong when you go between 32-bit and 64-bit
>>> >>> kernel uses an "int" and "int" is always 32bit.
>>> >>> The problem is most likely with timespec I think.
>>> >>>
>>> >>>> targets, and it gets worse with the kernel patches that just got
>>> >>>> merged for linux-5.5, which extends the behavior to deal with
>>> >>>> 64-bit time_t on 32-bit architectures.
>>> >>>>
>>> >>>> Please have a look at
>>> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859
>>> >>>>
>>> >>> Yes, we already had the same kind of problem with SIOCGSTAMP and
>>> >>> SIOCGSTAMPNS.
>>> >>>
>>> >>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
>>> >>> 64bit time_t?
>>> >> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
>>> >> is a pure 'int' that decides what format you get when you 'read' from the
>>> >> same file descriptor.
>>> >>
>>> >> For emulating 64-bit on 32-bit kernels, you have to use the new
>>> >> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
>>> >> 64-bit kernels, you probably have to return -ENOTTY to
>>> >> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
>>> >> emulate the read() behavior.
>>> >> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
>>> >> you can translate that into the 64-bit
>>> >> SNDRV_TIMER_IOCTL_TREAD_OLD.
>>> >
>>> > Thank you for bringing this up to my attention. Unfortunately i have
>>> > some duties of academic nature in next month so i won't have much time
>>> > fix this bug. I will try to fix this as soon as possible.
>>>
>>> Could you at least to try to have a mergeable series before you have to
>>> stop to work on this?
>>>
>>> You can only manage the case before the change reported by Arnd (I will
>>> manage the new case myself later).

>>
>> Sorry for interjecting myself into this discussion, but I just want to let you know about some related practicalities.
>>
>> Filip is a student that is from time to time (usually between two exam seasons) an intern in our company, working 4 hours each work day. He spent his internship in different teams in prevous years, and, from around mid-October 2019, was appointed to QEMU team. After some introductory tasks, he was assigned his main task: linux-user support for RTCs and ALSA timers. This series is the result of his work, and, to my great pleasure, is virtually entirely his independant work. I am positive he can complete the series by himself, even in the light of additional complexities mentioned in this thread.
>>
>> However, his exam season just started (Jan. 15th), and lasts till Feb. 15th. Our policy, in general, is not to burden the students during exam seasons, and that is why we can't expect prompt updates from him for the time being.
>>
>> In view of this, Laurent, please take Filip's status into consideration. As far as mergeability is concerned, my impression is that patches 1-6 and 13 are ready for merging, while patches 7-12 would require some additional (netlink-support-like) work, that would unfortunately be possible only after Feb. 15th.
>>

> Laurent, hi again.
>
> I am not completely familiar with all details of Filip's work, since, as I said, he had
> large degree of independance (which was intentional, and is a desired and good
> thing IMHO), but taking a closer look, a question starting lingering: Do we need
> special handling od read() even for RTC devices - not only ALSA timer devices?

Adding Alexandre Belloni and the RTC list to Cc for more expertise. Alexandre,
this question is about how qemu-user should emulate the rtc ioctl interface when
running a user binary for a foreign architecture. The ioctl emulation seems fine
to me, but read() from /dev/rtc is probably not.

As I understand it, reading from /dev/rtc is one of the more obscure features.
This would return either 32 bits or 64 bits of structured data from the kernel,
depending on how much data was requested and whether the kernel runs
as 64 bit. A 32-bit process running on a 64-bit kernel will get the correct
result when it asks for 4 bytes, but probably not when it asks for 8 bytes.
(we could fix this with an explict check for in_compat_syscall() in the kernel
function).

A process running on qemu with the opposite endianess will always get the
wrong result (unless the kernel returns 0), and emulating 64-bit task on
a 32-bit kernel will result in only four bytes to be read, which also likely
results in incorrect behavior.

       Arnd


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-16 12:00                   ` Arnd Bergmann
@ 2020-01-17 20:50                     ` Aleksandar Markovic
  -1 siblings, 0 replies; 35+ messages in thread
From: Aleksandar Markovic @ 2020-01-17 20:50 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Laurent Vivier, Filip Bozuta, Peter Maydell,
	Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Max Filippov, amarkovic, philmd,
	Alexandre Belloni, linux-rtc

On Thu, Jan 16, 2020 at 1:00 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Thu, Jan 16, 2020 at 12:27 PM Aleksandar Markovic
> <aleksandar.m.mail@gmail.com> wrote:
> > On Thursday, January 16, 2020, Aleksandar Markovic <aleksandar.m.mail@gmail.com> wrote:
> >> On Wednesday, January 15, 2020, Laurent Vivier <laurent@vivier.eu> wrote:
> >>> Le 15/01/2020 à 20:17, Filip Bozuta a écrit :
> >>> > On 15.1.20. 17:37, Arnd Bergmann wrote:
> >>> >> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
> >>> >>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
> >>> >>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta
> >>> >>>> <Filip.Bozuta@rt-rk.com> wrote:
> >>> >>>>> This patch implements functionality of following ioctl:
> >>> >>>>>
> >>> >>>>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
> >>> >>>>>
> >>> >>>>>      Sets enhanced time read which is used for reading time with
> >>> >>>>> timestamps
> >>> >>>>>      and events. The third ioctl's argument is a pointer to an
> >>> >>>>> 'int'. Enhanced
> >>> >>>>>      reading is set if the third argument is different than 0,
> >>> >>>>> otherwise normal
> >>> >>>>>      time reading is set.
> >>> >>>>>
> >>> >>>>> Implementation notes:
> >>> >>>>>
> >>> >>>>>      Because the implemented ioctl has 'int' as its third argument,
> >>> >>>>> the
> >>> >>>>>      implementation was straightforward.
> >>> >>>>>
> >>> >>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
> >>> >>>> I think this one is wrong when you go between 32-bit and 64-bit
> >>> >>> kernel uses an "int" and "int" is always 32bit.
> >>> >>> The problem is most likely with timespec I think.
> >>> >>>
> >>> >>>> targets, and it gets worse with the kernel patches that just got
> >>> >>>> merged for linux-5.5, which extends the behavior to deal with
> >>> >>>> 64-bit time_t on 32-bit architectures.
> >>> >>>>
> >>> >>>> Please have a look at
> >>> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859
> >>> >>>>
> >>> >>> Yes, we already had the same kind of problem with SIOCGSTAMP and
> >>> >>> SIOCGSTAMPNS.
> >>> >>>
> >>> >>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
> >>> >>> 64bit time_t?
> >>> >> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
> >>> >> is a pure 'int' that decides what format you get when you 'read' from the
> >>> >> same file descriptor.
> >>> >>
> >>> >> For emulating 64-bit on 32-bit kernels, you have to use the new
> >>> >> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
> >>> >> 64-bit kernels, you probably have to return -ENOTTY to
> >>> >> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
> >>> >> emulate the read() behavior.
> >>> >> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
> >>> >> you can translate that into the 64-bit
> >>> >> SNDRV_TIMER_IOCTL_TREAD_OLD.
> >>> >
> >>> > Thank you for bringing this up to my attention. Unfortunately i have
> >>> > some duties of academic nature in next month so i won't have much time
> >>> > fix this bug. I will try to fix this as soon as possible.
> >>>
> >>> Could you at least to try to have a mergeable series before you have to
> >>> stop to work on this?
> >>>
> >>> You can only manage the case before the change reported by Arnd (I will
> >>> manage the new case myself later).
>
> >>
> >> Sorry for interjecting myself into this discussion, but I just want to let you know about some related practicalities.
> >>
> >> Filip is a student that is from time to time (usually between two exam seasons) an intern in our company, working 4 hours each work day. He spent his internship in different teams in prevous years, and, from around mid-October 2019, was appointed to QEMU team. After some introductory tasks, he was assigned his main task: linux-user support for RTCs and ALSA timers. This series is the result of his work, and, to my great pleasure, is virtually entirely his independant work. I am positive he can complete the series by himself, even in the light of additional complexities mentioned in this thread.
> >>
> >> However, his exam season just started (Jan. 15th), and lasts till Feb. 15th. Our policy, in general, is not to burden the students during exam seasons, and that is why we can't expect prompt updates from him for the time being.
> >>
> >> In view of this, Laurent, please take Filip's status into consideration. As far as mergeability is concerned, my impression is that patches 1-6 and 13 are ready for merging, while patches 7-12 would require some additional (netlink-support-like) work, that would unfortunately be possible only after Feb. 15th.
> >>
>
> > Laurent, hi again.
> >
> > I am not completely familiar with all details of Filip's work, since, as I said, he had
> > large degree of independance (which was intentional, and is a desired and good
> > thing IMHO), but taking a closer look, a question starting lingering: Do we need
> > special handling od read() even for RTC devices - not only ALSA timer devices?
>
> Adding Alexandre Belloni and the RTC list to Cc for more expertise. Alexandre,
> this question is about how qemu-user should emulate the rtc ioctl interface when
> running a user binary for a foreign architecture. The ioctl emulation seems fine
> to me, but read() from /dev/rtc is probably not.
>
> As I understand it, reading from /dev/rtc is one of the more obscure features.
> This would return either 32 bits or 64 bits of structured data from the kernel,
> depending on how much data was requested and whether the kernel runs
> as 64 bit. A 32-bit process running on a 64-bit kernel will get the correct
> result when it asks for 4 bytes, but probably not when it asks for 8 bytes.
> (we could fix this with an explict check for in_compat_syscall() in the kernel
> function).
>
> A process running on qemu with the opposite endianess will always get the
> wrong result (unless the kernel returns 0), and emulating 64-bit task on
> a 32-bit kernel will result in only four bytes to be read, which also likely
> results in incorrect behavior.
>


Alexandre (and Arnd too, or any other person knowledgeable in the area),

I just need to clarify a couple of details with you, please.

Firstly, here is what man page rtc(4) says:

"The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.) device can be opened
only once (until it is closed) and it is read-only. On read(2) and
select(2) the calling process is blocked until the next interrupt from
that RTC is received. Following the interrupt, the process can read a
long integer, of which the least significant byte contains a bit mask
encoding the types of interrupt that occurred, while the remaining 3
bytes contain the number of interrupts since the last read(2)."

So, it looks read() will always return only 4 bytes of useful info
(regardless of host being 32-bit/64-bit).

My questions are:

- Is the description in man page genuinely accurate?

- To me (but I am really an outsider to using RTC in applications),
this feature (blocking read()/select()) even looks very nice and
convenient, in all fairness. But I would like to ask you: Is this
feature used rarely or frequently by other libraries/tools/etc.? In
other words, is the feature "obscure" or "crucial" part of RTC kernel
support? Or, something in between?

- Does MC146818 support this feature?

Thanks a lot in advance for any response!

Aleksandar

P.S. for Arnd: I sent this message only to you, by mistake, around 15
min ago. Now I include everybody.

>        Arnd

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
@ 2020-01-17 20:50                     ` Aleksandar Markovic
  0 siblings, 0 replies; 35+ messages in thread
From: Aleksandar Markovic @ 2020-01-17 20:50 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-rtc, Peter Maydell, Alexandre Belloni,
	Daniel P. Berrangé,
	Richard Henderson, Laurent Vivier, Filip Bozuta, qemu-devel,
	Max Filippov, amarkovic, philmd

On Thu, Jan 16, 2020 at 1:00 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Thu, Jan 16, 2020 at 12:27 PM Aleksandar Markovic
> <aleksandar.m.mail@gmail.com> wrote:
> > On Thursday, January 16, 2020, Aleksandar Markovic <aleksandar.m.mail@gmail.com> wrote:
> >> On Wednesday, January 15, 2020, Laurent Vivier <laurent@vivier.eu> wrote:
> >>> Le 15/01/2020 à 20:17, Filip Bozuta a écrit :
> >>> > On 15.1.20. 17:37, Arnd Bergmann wrote:
> >>> >> On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier <laurent@vivier.eu> wrote:
> >>> >>> Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :
> >>> >>>> On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta
> >>> >>>> <Filip.Bozuta@rt-rk.com> wrote:
> >>> >>>>> This patch implements functionality of following ioctl:
> >>> >>>>>
> >>> >>>>> SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read
> >>> >>>>>
> >>> >>>>>      Sets enhanced time read which is used for reading time with
> >>> >>>>> timestamps
> >>> >>>>>      and events. The third ioctl's argument is a pointer to an
> >>> >>>>> 'int'. Enhanced
> >>> >>>>>      reading is set if the third argument is different than 0,
> >>> >>>>> otherwise normal
> >>> >>>>>      time reading is set.
> >>> >>>>>
> >>> >>>>> Implementation notes:
> >>> >>>>>
> >>> >>>>>      Because the implemented ioctl has 'int' as its third argument,
> >>> >>>>> the
> >>> >>>>>      implementation was straightforward.
> >>> >>>>>
> >>> >>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@rt-rk.com>
> >>> >>>> I think this one is wrong when you go between 32-bit and 64-bit
> >>> >>> kernel uses an "int" and "int" is always 32bit.
> >>> >>> The problem is most likely with timespec I think.
> >>> >>>
> >>> >>>> targets, and it gets worse with the kernel patches that just got
> >>> >>>> merged for linux-5.5, which extends the behavior to deal with
> >>> >>>> 64-bit time_t on 32-bit architectures.
> >>> >>>>
> >>> >>>> Please have a look at
> >>> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859
> >>> >>>>
> >>> >>> Yes, we already had the same kind of problem with SIOCGSTAMP and
> >>> >>> SIOCGSTAMPNS.
> >>> >>>
> >>> >>> Do the kernel patches add new ioctl numbers to differentiate 32bit and
> >>> >>> 64bit time_t?
> >>> >> Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
> >>> >> is a pure 'int' that decides what format you get when you 'read' from the
> >>> >> same file descriptor.
> >>> >>
> >>> >> For emulating 64-bit on 32-bit kernels, you have to use the new
> >>> >> SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
> >>> >> 64-bit kernels, you probably have to return -ENOTTY to
> >>> >> SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
> >>> >> emulate the read() behavior.
> >>> >> When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
> >>> >> you can translate that into the 64-bit
> >>> >> SNDRV_TIMER_IOCTL_TREAD_OLD.
> >>> >
> >>> > Thank you for bringing this up to my attention. Unfortunately i have
> >>> > some duties of academic nature in next month so i won't have much time
> >>> > fix this bug. I will try to fix this as soon as possible.
> >>>
> >>> Could you at least to try to have a mergeable series before you have to
> >>> stop to work on this?
> >>>
> >>> You can only manage the case before the change reported by Arnd (I will
> >>> manage the new case myself later).
>
> >>
> >> Sorry for interjecting myself into this discussion, but I just want to let you know about some related practicalities.
> >>
> >> Filip is a student that is from time to time (usually between two exam seasons) an intern in our company, working 4 hours each work day. He spent his internship in different teams in prevous years, and, from around mid-October 2019, was appointed to QEMU team. After some introductory tasks, he was assigned his main task: linux-user support for RTCs and ALSA timers. This series is the result of his work, and, to my great pleasure, is virtually entirely his independant work. I am positive he can complete the series by himself, even in the light of additional complexities mentioned in this thread.
> >>
> >> However, his exam season just started (Jan. 15th), and lasts till Feb. 15th. Our policy, in general, is not to burden the students during exam seasons, and that is why we can't expect prompt updates from him for the time being.
> >>
> >> In view of this, Laurent, please take Filip's status into consideration. As far as mergeability is concerned, my impression is that patches 1-6 and 13 are ready for merging, while patches 7-12 would require some additional (netlink-support-like) work, that would unfortunately be possible only after Feb. 15th.
> >>
>
> > Laurent, hi again.
> >
> > I am not completely familiar with all details of Filip's work, since, as I said, he had
> > large degree of independance (which was intentional, and is a desired and good
> > thing IMHO), but taking a closer look, a question starting lingering: Do we need
> > special handling od read() even for RTC devices - not only ALSA timer devices?
>
> Adding Alexandre Belloni and the RTC list to Cc for more expertise. Alexandre,
> this question is about how qemu-user should emulate the rtc ioctl interface when
> running a user binary for a foreign architecture. The ioctl emulation seems fine
> to me, but read() from /dev/rtc is probably not.
>
> As I understand it, reading from /dev/rtc is one of the more obscure features.
> This would return either 32 bits or 64 bits of structured data from the kernel,
> depending on how much data was requested and whether the kernel runs
> as 64 bit. A 32-bit process running on a 64-bit kernel will get the correct
> result when it asks for 4 bytes, but probably not when it asks for 8 bytes.
> (we could fix this with an explict check for in_compat_syscall() in the kernel
> function).
>
> A process running on qemu with the opposite endianess will always get the
> wrong result (unless the kernel returns 0), and emulating 64-bit task on
> a 32-bit kernel will result in only four bytes to be read, which also likely
> results in incorrect behavior.
>


Alexandre (and Arnd too, or any other person knowledgeable in the area),

I just need to clarify a couple of details with you, please.

Firstly, here is what man page rtc(4) says:

"The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.) device can be opened
only once (until it is closed) and it is read-only. On read(2) and
select(2) the calling process is blocked until the next interrupt from
that RTC is received. Following the interrupt, the process can read a
long integer, of which the least significant byte contains a bit mask
encoding the types of interrupt that occurred, while the remaining 3
bytes contain the number of interrupts since the last read(2)."

So, it looks read() will always return only 4 bytes of useful info
(regardless of host being 32-bit/64-bit).

My questions are:

- Is the description in man page genuinely accurate?

- To me (but I am really an outsider to using RTC in applications),
this feature (blocking read()/select()) even looks very nice and
convenient, in all fairness. But I would like to ask you: Is this
feature used rarely or frequently by other libraries/tools/etc.? In
other words, is the feature "obscure" or "crucial" part of RTC kernel
support? Or, something in between?

- Does MC146818 support this feature?

Thanks a lot in advance for any response!

Aleksandar

P.S. for Arnd: I sent this message only to you, by mistake, around 15
min ago. Now I include everybody.

>        Arnd


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-17 20:50                     ` Aleksandar Markovic
@ 2020-01-17 21:45                       ` Arnd Bergmann
  -1 siblings, 0 replies; 35+ messages in thread
From: Arnd Bergmann @ 2020-01-17 21:45 UTC (permalink / raw)
  To: Aleksandar Markovic
  Cc: Laurent Vivier, Filip Bozuta, Peter Maydell,
	Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Max Filippov, amarkovic, philmd,
	Alexandre Belloni, linux-rtc

On Fri, Jan 17, 2020 at 9:50 PM Aleksandar Markovic
<aleksandar.m.mail@gmail.com> wrote:

> Alexandre (and Arnd too, or any other person knowledgeable in the area),
>
> I just need to clarify a couple of details with you, please.
>
> Firstly, here is what man page rtc(4) says:
>
> "The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.) device can be opened
> only once (until it is closed) and it is read-only. On read(2) and
> select(2) the calling process is blocked until the next interrupt from
> that RTC is received. Following the interrupt, the process can read a
> long integer, of which the least significant byte contains a bit mask
> encoding the types of interrupt that occurred, while the remaining 3
> bytes contain the number of interrupts since the last read(2)."
>
> So, it looks read() will always return only 4 bytes of useful info
> (regardless of host being 32-bit/64-bit).

It says "long integer", which is 64-bit on a 64-bit machine.

> My questions are:
>
> - Is the description in man page genuinely accurate?

Starting with linux-2.6.18, there is another possibility: If an
application asks for exactly four bytes on a 64-bit kernel,
it gets the lower four bytes, as it would on a 32-bit kernel.

This is a hack that was introduced for running 32-bit compat
tasks.

For any other size less than sizeof(long), the kernel reports
an EINVAL error, and for anything larger or equal to sizeof(long)
it attempts to output a long word.

> - To me (but I am really an outsider to using RTC in applications),
> this feature (blocking read()/select()) even looks very nice and
> convenient, in all fairness. But I would like to ask you: Is this
> feature used rarely or frequently by other libraries/tools/etc.? In
> other words, is the feature "obscure" or "crucial" part of RTC kernel
> support? Or, something in between?

> - Does MC146818 support this feature?

No idea, I'll leave these for Alexandre or someone else to answer.

      Arnd

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
@ 2020-01-17 21:45                       ` Arnd Bergmann
  0 siblings, 0 replies; 35+ messages in thread
From: Arnd Bergmann @ 2020-01-17 21:45 UTC (permalink / raw)
  To: Aleksandar Markovic
  Cc: linux-rtc, Peter Maydell, Alexandre Belloni,
	Daniel P. Berrangé,
	Richard Henderson, Laurent Vivier, Filip Bozuta, qemu-devel,
	Max Filippov, amarkovic, philmd

On Fri, Jan 17, 2020 at 9:50 PM Aleksandar Markovic
<aleksandar.m.mail@gmail.com> wrote:

> Alexandre (and Arnd too, or any other person knowledgeable in the area),
>
> I just need to clarify a couple of details with you, please.
>
> Firstly, here is what man page rtc(4) says:
>
> "The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.) device can be opened
> only once (until it is closed) and it is read-only. On read(2) and
> select(2) the calling process is blocked until the next interrupt from
> that RTC is received. Following the interrupt, the process can read a
> long integer, of which the least significant byte contains a bit mask
> encoding the types of interrupt that occurred, while the remaining 3
> bytes contain the number of interrupts since the last read(2)."
>
> So, it looks read() will always return only 4 bytes of useful info
> (regardless of host being 32-bit/64-bit).

It says "long integer", which is 64-bit on a 64-bit machine.

> My questions are:
>
> - Is the description in man page genuinely accurate?

Starting with linux-2.6.18, there is another possibility: If an
application asks for exactly four bytes on a 64-bit kernel,
it gets the lower four bytes, as it would on a 32-bit kernel.

This is a hack that was introduced for running 32-bit compat
tasks.

For any other size less than sizeof(long), the kernel reports
an EINVAL error, and for anything larger or equal to sizeof(long)
it attempts to output a long word.

> - To me (but I am really an outsider to using RTC in applications),
> this feature (blocking read()/select()) even looks very nice and
> convenient, in all fairness. But I would like to ask you: Is this
> feature used rarely or frequently by other libraries/tools/etc.? In
> other words, is the feature "obscure" or "crucial" part of RTC kernel
> support? Or, something in between?

> - Does MC146818 support this feature?

No idea, I'll leave these for Alexandre or someone else to answer.

      Arnd


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
  2020-01-17 20:50                     ` Aleksandar Markovic
@ 2020-01-17 21:54                       ` Alexandre Belloni
  -1 siblings, 0 replies; 35+ messages in thread
From: Alexandre Belloni @ 2020-01-17 21:54 UTC (permalink / raw)
  To: Aleksandar Markovic
  Cc: Arnd Bergmann, Laurent Vivier, Filip Bozuta, Peter Maydell,
	Daniel P. Berrangé,
	Richard Henderson, qemu-devel, Max Filippov, amarkovic, philmd,
	linux-rtc

Hi,

Quick answers to your very good questions below:

On 17/01/2020 21:50:34+0100, Aleksandar Markovic wrote:
> Alexandre (and Arnd too, or any other person knowledgeable in the area),
> 
> I just need to clarify a couple of details with you, please.
> 
> Firstly, here is what man page rtc(4) says:
> 
> "The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.) device can be opened
> only once (until it is closed) and it is read-only. On read(2) and
> select(2) the calling process is blocked until the next interrupt from
> that RTC is received. Following the interrupt, the process can read a
> long integer, of which the least significant byte contains a bit mask
> encoding the types of interrupt that occurred, while the remaining 3
> bytes contain the number of interrupts since the last read(2)."
> 
> So, it looks read() will always return only 4 bytes of useful info
> (regardless of host being 32-bit/64-bit).
> 
> My questions are:
> 
> - Is the description in man page genuinely accurate?
> 

It is accurate. It is a mask of:

#define RTC_IRQF 0x80   /* Any of the following is active */
#define RTC_PF 0x40     /* Periodic interrupt */
#define RTC_AF 0x20     /* Alarm interrupt */
#define RTC_UF 0x10     /* Update interrupt for 1Hz RTC */

Which will most likely be RTC_IRQF | RTC_AF.

> - To me (but I am really an outsider to using RTC in applications),
> this feature (blocking read()/select()) even looks very nice and
> convenient, in all fairness. But I would like to ask you: Is this
> feature used rarely or frequently by other libraries/tools/etc.? In
> other words, is the feature "obscure" or "crucial" part of RTC kernel
> support? Or, something in between?
> 

Nobody is actually using the return value.

> - Does MC146818 support this feature?
> 

This feature is implemented in the RTC core so it is supported by all
RTCs that have alarms.

Internally, the value is an unsigned long and it is casted properly by
put_user in rtc_dev_read:

https://elixir.bootlin.com/linux/v5.4/source/drivers/rtc/dev.c#L178

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl
@ 2020-01-17 21:54                       ` Alexandre Belloni
  0 siblings, 0 replies; 35+ messages in thread
From: Alexandre Belloni @ 2020-01-17 21:54 UTC (permalink / raw)
  To: Aleksandar Markovic
  Cc: linux-rtc, Peter Maydell, Daniel P. Berrangé,
	Arnd Bergmann, Richard Henderson, Laurent Vivier, Filip Bozuta,
	qemu-devel, Max Filippov, amarkovic, philmd

Hi,

Quick answers to your very good questions below:

On 17/01/2020 21:50:34+0100, Aleksandar Markovic wrote:
> Alexandre (and Arnd too, or any other person knowledgeable in the area),
> 
> I just need to clarify a couple of details with you, please.
> 
> Firstly, here is what man page rtc(4) says:
> 
> "The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.) device can be opened
> only once (until it is closed) and it is read-only. On read(2) and
> select(2) the calling process is blocked until the next interrupt from
> that RTC is received. Following the interrupt, the process can read a
> long integer, of which the least significant byte contains a bit mask
> encoding the types of interrupt that occurred, while the remaining 3
> bytes contain the number of interrupts since the last read(2)."
> 
> So, it looks read() will always return only 4 bytes of useful info
> (regardless of host being 32-bit/64-bit).
> 
> My questions are:
> 
> - Is the description in man page genuinely accurate?
> 

It is accurate. It is a mask of:

#define RTC_IRQF 0x80   /* Any of the following is active */
#define RTC_PF 0x40     /* Periodic interrupt */
#define RTC_AF 0x20     /* Alarm interrupt */
#define RTC_UF 0x10     /* Update interrupt for 1Hz RTC */

Which will most likely be RTC_IRQF | RTC_AF.

> - To me (but I am really an outsider to using RTC in applications),
> this feature (blocking read()/select()) even looks very nice and
> convenient, in all fairness. But I would like to ask you: Is this
> feature used rarely or frequently by other libraries/tools/etc.? In
> other words, is the feature "obscure" or "crucial" part of RTC kernel
> support? Or, something in between?
> 

Nobody is actually using the return value.

> - Does MC146818 support this feature?
> 

This feature is implemented in the RTC core so it is supported by all
RTCs that have alarms.

Internally, the value is an unsigned long and it is casted properly by
put_user in rtc_dev_read:

https://elixir.bootlin.com/linux/v5.4/source/drivers/rtc/dev.c#L178

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 00/12] linux-user: Add support for real time clock and
  2020-01-14 12:39 ` Philippe Mathieu-Daudé
@ 2020-01-14 12:47   ` Laurent Vivier
  0 siblings, 0 replies; 35+ messages in thread
From: Laurent Vivier @ 2020-01-14 12:47 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Filip Bozuta, qemu-devel; +Cc: riku.voipio

Le 14/01/2020 à 13:39, Philippe Mathieu-Daudé a écrit :
> Hi Filip,
> 
> This is v5.
> 
> On 1/9/20 1:59 PM, Filip Bozuta wrote:
>> MIME-Version: 1.0
>> Content-Type: text/plain; charset=UTF-8
>> Content-Transfer-Encoding: 8bit
>>
>> This series covers following RTC and sound timer ioctls:
>>
>>    RTC ioctls(22):
>>
>>      * RTC_AIE_ON          * RTC_ALM_SET         * RTC_WKALM_SET
>>      * RTC_AIE_OFF         * RTC_ALM_READ        * RTC_WKALM_RD
>>      * RTC_UIE_ON          * RTC_RD_TIME         * RTC_PLL_GET
>>      * RTC_UIE_OFF         * RTC_SET_TIME        * RTC_PLL_SET
>>      * RTC_PIE_ON          * RTC_IRQP_READ       * RTC_VL_READ
>>      * RTC_PIE_OFF         * RTC_IRQP_SET        * RTC_VL_CLR
>>      * RTC_WIE_ON          * RTC_EPOCH_READ
>>      * RTC_WIE_OFF         * RTC_EPOCH_SET
>>
>>    Sound timer ioctls(14):
>>
>>      * SNDRV_TIMER_IOCTL_PVERSION          * SNDRV_TIMER_IOCTL_INFO
>>      * SNDRV_TIMER_IOCTL_NEXT_DEVICE       * SNDRV_TIMER_IOCTL_PARAMS
>>      * SNDRV_TIMER_IOCTL_TREAD             * SNDRV_TIMER_IOCTL_STATUS
>>      * SNDRV_TIMER_IOCTL_GINFO             * SNDRV_TIMER_IOCTL_START
>>      * SNDRV_TIMER_IOCTL_GPARAMS           * SNDRV_TIMER_IOCTL_STOP
>>      * SNDRV_TIMER_IOCTL_GSTATUS           * SNDRV_TIMER_IOCTL_CONTINUE
>>      * SNDRV_TIMER_IOCTL_SELECT            * SNDRV_TIMER_IOCTL_PAUSE
>>
>> The functionalities of individual ioctls were described in this series
>> patch commit messages.
>>
>> Testing method for RTC ioctls:
>>
>>      Mini test programs were written for each ioctl. Those programs were
>>      compiled (sometimes using cross-compilers) for the following
>>      architectures:
>>
>>          * Intel 64-bit (little endian)
>>          * Power pc 32-bit (big endian)
>>          * Power pc 64-bit (big endian)
>>
>>      The corresponding native programs were executed without using
>>      QEMU on following hosts:
>>
>>          * Intel Core i7-4790K (x86_64 host)
>>          * Power 7447A (ppc32 host)
>>
>>      All applicable compiled programs were in turn executed through QEMU
>>      and the results obtained were the same ones gotten for native
>>      execution.
>>
>>      Example of a test program:
>>
>>          For ioctl RTC_RD_TIME the following test program was used:
>>
>>          #include <stdio.h>
>>          #include <stdlib.h>
>>          #include <linux/rtc.h>
>>          #include <fcntl.h>
>>          #include <linux/input.h>
>>          #include <sys/types.h>
>>          #include <unistd.h>
>>
>>          #define ERROR -1
>>
>>          int main()
>>          {
>>
>>              int fd = open("/dev/rtc", O_RDWR | O_NONBLOCK);
>>
>>              if(fd == ERROR)
>>              {
>>                  perror("open");
>>                  return -1;
>>              }
>>
>>              struct rtc_time cur_time;
>>
>>              if(ioctl(fd, RTC_RD_TIME, &cur_time) < 0)
>>              {
>>                  perror("ioctl");
>>                  return -1;
>>              }
>>
>>              printf("Second: %d, Minute: %d, Hour: %d, Day: %d, Month:
>> %d, Year: %d,",
>>                  cur_time.tm_sec, cur_time.tm_min, cur_time.tm_hour,
>>                  cur_time.tm_mday, cur_time.tm_mon, cur_time.tm_year);
>>
>>              return 0;
>>          }
>>
>>      Limitations of testing:
>>
>>          The test host pc that was used for testing (intel pc) has RTC
>>          that doesn't support all RTC features that are accessible
>>          through ioctls. This means that testing can't discover
>>          functionality errors related to the third argument of ioctls
>>          that are used for features which are not supported. For example,
>>          running the test program for ioctl RTC_EPOCH_READ gives
>>          the error output: inappropriate ioctl for device. As expected,
>>          the same output was obtained through QEMU which means that this
>>          ioctl is recognized in QEMU but doesn't really do anything
>>          because it is not supported in the host computer's RTC.
>>
>>          Conclusion: Some RTC ioctls need to be tested on computers
>>          that support their functionalities so that it can be inferred
>>          that they are really supported in QEMU. In absence of such
>>          test hosts, the specifications of those ioctls need to be
>>          carefully checked manually and the implementations should be
>>          updated accordingly.
> 
> We should be able to check if the host supports these features and run
> your different tests.
> Can you add them in the repository? Maybe under tests/tcg/multiarch/.
> 

I agree with Philippe. If you provide the test we will also be able to
run non-regression tests. You can add them in a separate patch if it's
easier for you.

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 00/12] linux-user: Add support for real time clock and
  2020-01-09 12:59 Filip Bozuta
@ 2020-01-14 12:39 ` Philippe Mathieu-Daudé
  2020-01-14 12:47   ` Laurent Vivier
  0 siblings, 1 reply; 35+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-14 12:39 UTC (permalink / raw)
  To: Filip Bozuta, qemu-devel; +Cc: riku.voipio, laurent

Hi Filip,

This is v5.

On 1/9/20 1:59 PM, Filip Bozuta wrote:
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> This series covers following RTC and sound timer ioctls:
> 
>    RTC ioctls(22):
> 
>      * RTC_AIE_ON          * RTC_ALM_SET         * RTC_WKALM_SET
>      * RTC_AIE_OFF         * RTC_ALM_READ        * RTC_WKALM_RD
>      * RTC_UIE_ON          * RTC_RD_TIME         * RTC_PLL_GET
>      * RTC_UIE_OFF         * RTC_SET_TIME        * RTC_PLL_SET
>      * RTC_PIE_ON          * RTC_IRQP_READ       * RTC_VL_READ
>      * RTC_PIE_OFF         * RTC_IRQP_SET        * RTC_VL_CLR
>      * RTC_WIE_ON          * RTC_EPOCH_READ
>      * RTC_WIE_OFF         * RTC_EPOCH_SET
> 
>    Sound timer ioctls(14):
> 
>      * SNDRV_TIMER_IOCTL_PVERSION          * SNDRV_TIMER_IOCTL_INFO
>      * SNDRV_TIMER_IOCTL_NEXT_DEVICE       * SNDRV_TIMER_IOCTL_PARAMS
>      * SNDRV_TIMER_IOCTL_TREAD             * SNDRV_TIMER_IOCTL_STATUS
>      * SNDRV_TIMER_IOCTL_GINFO             * SNDRV_TIMER_IOCTL_START
>      * SNDRV_TIMER_IOCTL_GPARAMS           * SNDRV_TIMER_IOCTL_STOP
>      * SNDRV_TIMER_IOCTL_GSTATUS           * SNDRV_TIMER_IOCTL_CONTINUE
>      * SNDRV_TIMER_IOCTL_SELECT            * SNDRV_TIMER_IOCTL_PAUSE
> 
> The functionalities of individual ioctls were described in this series
> patch commit messages.
> 
> Testing method for RTC ioctls:
> 
>      Mini test programs were written for each ioctl. Those programs were
>      compiled (sometimes using cross-compilers) for the following
>      architectures:
> 
>          * Intel 64-bit (little endian)
>          * Power pc 32-bit (big endian)
>          * Power pc 64-bit (big endian)
> 
>      The corresponding native programs were executed without using
>      QEMU on following hosts:
> 
>          * Intel Core i7-4790K (x86_64 host)
>          * Power 7447A (ppc32 host)
> 
>      All applicable compiled programs were in turn executed through QEMU
>      and the results obtained were the same ones gotten for native
>      execution.
> 
>      Example of a test program:
> 
>          For ioctl RTC_RD_TIME the following test program was used:
> 
>          #include <stdio.h>
>          #include <stdlib.h>
>          #include <linux/rtc.h>
>          #include <fcntl.h>
>          #include <linux/input.h>
>          #include <sys/types.h>
>          #include <unistd.h>
> 
>          #define ERROR -1
> 
>          int main()
>          {
> 
>              int fd = open("/dev/rtc", O_RDWR | O_NONBLOCK);
> 
>              if(fd == ERROR)
>              {
>                  perror("open");
>                  return -1;
>              }
> 
>              struct rtc_time cur_time;
> 
>              if(ioctl(fd, RTC_RD_TIME, &cur_time) < 0)
>              {
>                  perror("ioctl");
>                  return -1;
>              }
> 
>              printf("Second: %d, Minute: %d, Hour: %d, Day: %d, Month: %d, Year: %d,",
>                  cur_time.tm_sec, cur_time.tm_min, cur_time.tm_hour,
>                  cur_time.tm_mday, cur_time.tm_mon, cur_time.tm_year);
> 
>              return 0;
>          }
> 
>      Limitations of testing:
> 
>          The test host pc that was used for testing (intel pc) has RTC
>          that doesn't support all RTC features that are accessible
>          through ioctls. This means that testing can't discover
>          functionality errors related to the third argument of ioctls
>          that are used for features which are not supported. For example,
>          running the test program for ioctl RTC_EPOCH_READ gives
>          the error output: inappropriate ioctl for device. As expected,
>          the same output was obtained through QEMU which means that this
>          ioctl is recognized in QEMU but doesn't really do anything
>          because it is not supported in the host computer's RTC.
> 
>          Conclusion: Some RTC ioctls need to be tested on computers
>          that support their functionalities so that it can be inferred
>          that they are really supported in QEMU. In absence of such
>          test hosts, the specifications of those ioctls need to be
>          carefully checked manually and the implementations should be
>          updated accordingly.

We should be able to check if the host supports these features and run 
your different tests.
Can you add them in the repository? Maybe under tests/tcg/multiarch/.

> Testing method for sound timer ioctls:
> 
>      The alsa ioctl test suite, that can be found on github
>      ("https://github.com/alsa-project/alsa-utils"), was used the test
>      the implemented ioctls. The file "timer.c", located in this test
>      suite, contains test functions that are used to test alsa timer
>      ioctls. This file was compiled (sometimes using cross-compilers)
>      for the following architectures:
> 
>          * Intel 64-bit (little endian)
>          * Power pc 32-bit (big endian)
>          * Power pc 64-bit (big endian)
> 
>      The corresponding compiled test files were executed without using
>      QEMU on following hosts:
> 
>          * Intel Core i7-4790K (x86_64 host)
>          * Power 7447A (ppc32 host)
> 
>      The corresponding native compiled test files were executed without using
>      QEMU on following hosts:
> 
>          * Intel Core i7-4790K (x86_64 host)
>          * Power 7447A (ppc32 host)
> 
>      All compiled test files were in turn executed through QEMU
>      and the results obtained were the same ones gotten for native
>      execution.
> 
>      Also, mini test programs were written to test further functionalities
>      of individual ioctls. Those programs were, like the file "timer.c",
>      compiled for different architectures and were executed both natively
>      and thgrough QEMU to compare the results.
> 
>      Example of a test program:
> 
>          For ioctl SNDRV_TIMER_IOCTL_GINFO the following test program was used:
> 
>          #include <stdio.h>
>          #include <stdlib.h>
>          #include <sys/types.h>
>          #include <fcntl.h>
>          #include <sys/ioctl.h>
>          #include <sound/asound.h>
> 
>          #define ERROR -1
> 
>          int main()
>          {
>              int fd = open("/dev/snd/timer", O_RDWR);
> 
>              if(fd == ERROR)
>              {
>                  perror("open");
>                  return -1;
>              }
> 
>              struct snd_timer_id id = {SNDRV_TIMER_CLASS_GLOBAL,
>                                        SNDRV_TIMER_SCLASS_NONE, -1,
>                                        SNDRV_TIMER_GLOBAL_SYSTEM, 0};
> 
>              struct snd_timer_ginfo ginfo;
>              ginfo.tid = id;
> 
>              if(ioctl(fd, SNDRV_TIMER_IOCTL_GINFO, &ginfo) == ERROR)
>              {
>                  perror("ioctl");
>                  return -1;
>              }
> 
>              printf("flags: %u\n", ginfo.flags);
>              printf("card: %d\n", ginfo.card);
>              printf("id: %s\n", ginfo.id);
>              printf("name: %s\n", ginfo.name);
>              printf("reserved0: %lu\n", ginfo.reserved0);
>              printf("resolution: %lu\n", ginfo.resolution);
>              printf("resolution_min: %lu\n", ginfo.resolution_min);
>              printf("reolution_max: %lu\n", ginfo.resolution_max);
>              printf("clients: %u\n", ginfo.clients);
>              printf("reserved: %s\n", ginfo.reserved);
> 
>              return 0;
>          }
> 
> v5:
> 
>      * added support for alsa sound timer ioctls
> 
> v4:
> 
>      * changed patch descriptions so that they are better
>        formatted and more cemprehensible
> 
> v3:
> 
>      * changed two instances of MK_PTR(TYPE_ULONG) to TYPE_ULONG
> 
> v2:
> 
>      * added description of each ioctl in patches
>      * wrote a more detailed cover letter with description of testing
>      * changed one instance of TYPE_INT to MK_PTR(TYPE_INT)
> 
> 
> Filip Bozuta (12):
>    linux-user: Add support for enabling/disabling RTC features using
>      ioctls
>    linux-user: Add support for getting/setting RTC time and alarm using
>      ioctls
>    linux-user: Add support for getting/setting RTC periodic interrupt and
>      epoch using ioctls
>    linux-user: Add support for getting/setting RTC wakeup alarm using
>      ioctls
>    linux-user: Add support for getting/setting RTC PLL correction using
>      ioctls
>    linux-user: Add support for read/clear RTC voltage low detector using
>      ioctls
>    linux-user: Add support for getting alsa timer version and id
>    linux-user: Add support for setting alsa timer enhanced read using
>      ioctl
>    linux-user: Add support for getting/setting specified alsa timer
>      parameters using ioctls
>    linux-user: Add support for selecting alsa timer using ioctl
>    linux-user: Add support for getting/setting selected alsa timer
>      parameters using ioctls
>    linux-user: Add support for selected alsa timer instructions using
>      ioctls
> 
>   linux-user/ioctls.h        |  45 +++++++++++++++++
>   linux-user/syscall.c       |   2 +
>   linux-user/syscall_defs.h  | 121 +++++++++++++++++++++++++++++++++++++++++++++
>   linux-user/syscall_types.h |  91 ++++++++++++++++++++++++++++++++++
>   4 files changed, 259 insertions(+)
> 



^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 00/12] linux-user: Add support for real time clock and
@ 2020-01-09 12:59 Filip Bozuta
  2020-01-14 12:39 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 35+ messages in thread
From: Filip Bozuta @ 2020-01-09 12:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, laurent

MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This series covers following RTC and sound timer ioctls:

  RTC ioctls(22):

    * RTC_AIE_ON          * RTC_ALM_SET         * RTC_WKALM_SET
    * RTC_AIE_OFF         * RTC_ALM_READ        * RTC_WKALM_RD
    * RTC_UIE_ON          * RTC_RD_TIME         * RTC_PLL_GET
    * RTC_UIE_OFF         * RTC_SET_TIME        * RTC_PLL_SET
    * RTC_PIE_ON          * RTC_IRQP_READ       * RTC_VL_READ
    * RTC_PIE_OFF         * RTC_IRQP_SET        * RTC_VL_CLR
    * RTC_WIE_ON          * RTC_EPOCH_READ
    * RTC_WIE_OFF         * RTC_EPOCH_SET

  Sound timer ioctls(14):

    * SNDRV_TIMER_IOCTL_PVERSION          * SNDRV_TIMER_IOCTL_INFO
    * SNDRV_TIMER_IOCTL_NEXT_DEVICE       * SNDRV_TIMER_IOCTL_PARAMS
    * SNDRV_TIMER_IOCTL_TREAD             * SNDRV_TIMER_IOCTL_STATUS
    * SNDRV_TIMER_IOCTL_GINFO             * SNDRV_TIMER_IOCTL_START
    * SNDRV_TIMER_IOCTL_GPARAMS           * SNDRV_TIMER_IOCTL_STOP
    * SNDRV_TIMER_IOCTL_GSTATUS           * SNDRV_TIMER_IOCTL_CONTINUE
    * SNDRV_TIMER_IOCTL_SELECT            * SNDRV_TIMER_IOCTL_PAUSE

The functionalities of individual ioctls were described in this series
patch commit messages.

Testing method for RTC ioctls:

    Mini test programs were written for each ioctl. Those programs were
    compiled (sometimes using cross-compilers) for the following
    architectures:

        * Intel 64-bit (little endian)
        * Power pc 32-bit (big endian)
        * Power pc 64-bit (big endian)

    The corresponding native programs were executed without using
    QEMU on following hosts:

        * Intel Core i7-4790K (x86_64 host)
        * Power 7447A (ppc32 host)

    All applicable compiled programs were in turn executed through QEMU
    and the results obtained were the same ones gotten for native
    execution.

    Example of a test program:

        For ioctl RTC_RD_TIME the following test program was used:

        #include <stdio.h>
        #include <stdlib.h>
        #include <linux/rtc.h>
        #include <fcntl.h>
        #include <linux/input.h>
        #include <sys/types.h>
        #include <unistd.h>

        #define ERROR -1

        int main()
        {

            int fd = open("/dev/rtc", O_RDWR | O_NONBLOCK);

            if(fd == ERROR)
            {
                perror("open");
                return -1;
            }

            struct rtc_time cur_time;

            if(ioctl(fd, RTC_RD_TIME, &cur_time) < 0)
            {
                perror("ioctl");
                return -1;
            }

            printf("Second: %d, Minute: %d, Hour: %d, Day: %d, Month: %d, Year: %d,",
                cur_time.tm_sec, cur_time.tm_min, cur_time.tm_hour, 
                cur_time.tm_mday, cur_time.tm_mon, cur_time.tm_year);

            return 0;
        }

    Limitations of testing:

        The test host pc that was used for testing (intel pc) has RTC
        that doesn't support all RTC features that are accessible
        through ioctls. This means that testing can't discover
        functionality errors related to the third argument of ioctls
        that are used for features which are not supported. For example,
        running the test program for ioctl RTC_EPOCH_READ gives
        the error output: inappropriate ioctl for device. As expected,
        the same output was obtained through QEMU which means that this
        ioctl is recognized in QEMU but doesn't really do anything
        because it is not supported in the host computer's RTC.

        Conclusion: Some RTC ioctls need to be tested on computers
        that support their functionalities so that it can be inferred
        that they are really supported in QEMU. In absence of such
        test hosts, the specifications of those ioctls need to be
        carefully checked manually and the implementations should be
        updated accordingly.

Testing method for sound timer ioctls:

    The alsa ioctl test suite, that can be found on github
    ("https://github.com/alsa-project/alsa-utils"), was used the test
    the implemented ioctls. The file "timer.c", located in this test
    suite, contains test functions that are used to test alsa timer
    ioctls. This file was compiled (sometimes using cross-compilers) 
    for the following architectures:

        * Intel 64-bit (little endian)
        * Power pc 32-bit (big endian)
        * Power pc 64-bit (big endian)

    The corresponding compiled test files were executed without using
    QEMU on following hosts:

        * Intel Core i7-4790K (x86_64 host)
        * Power 7447A (ppc32 host)

    The corresponding native compiled test files were executed without using
    QEMU on following hosts:

        * Intel Core i7-4790K (x86_64 host)
        * Power 7447A (ppc32 host)

    All compiled test files were in turn executed through QEMU
    and the results obtained were the same ones gotten for native
    execution.

    Also, mini test programs were written to test further functionalities
    of individual ioctls. Those programs were, like the file "timer.c",
    compiled for different architectures and were executed both natively
    and thgrough QEMU to compare the results.

    Example of a test program:

        For ioctl SNDRV_TIMER_IOCTL_GINFO the following test program was used:

        #include <stdio.h>
        #include <stdlib.h>
        #include <sys/types.h>
        #include <fcntl.h>
        #include <sys/ioctl.h>
        #include <sound/asound.h>

        #define ERROR -1

        int main()
        {
            int fd = open("/dev/snd/timer", O_RDWR);

            if(fd == ERROR)
            {
                perror("open");
                return -1;
            }

            struct snd_timer_id id = {SNDRV_TIMER_CLASS_GLOBAL, 
                                      SNDRV_TIMER_SCLASS_NONE, -1, 
                                      SNDRV_TIMER_GLOBAL_SYSTEM, 0};

            struct snd_timer_ginfo ginfo;
            ginfo.tid = id;

            if(ioctl(fd, SNDRV_TIMER_IOCTL_GINFO, &ginfo) == ERROR)
            {
                perror("ioctl");
                return -1;
            }

            printf("flags: %u\n", ginfo.flags);
            printf("card: %d\n", ginfo.card);
            printf("id: %s\n", ginfo.id);
            printf("name: %s\n", ginfo.name);
            printf("reserved0: %lu\n", ginfo.reserved0);
            printf("resolution: %lu\n", ginfo.resolution);
            printf("resolution_min: %lu\n", ginfo.resolution_min);
            printf("reolution_max: %lu\n", ginfo.resolution_max);
            printf("clients: %u\n", ginfo.clients);
            printf("reserved: %s\n", ginfo.reserved);

            return 0;
        }

v5:

    * added support for alsa sound timer ioctls

v4:

    * changed patch descriptions so that they are better
      formatted and more cemprehensible

v3:

    * changed two instances of MK_PTR(TYPE_ULONG) to TYPE_ULONG

v2:

    * added description of each ioctl in patches
    * wrote a more detailed cover letter with description of testing
    * changed one instance of TYPE_INT to MK_PTR(TYPE_INT)


Filip Bozuta (12):
  linux-user: Add support for enabling/disabling RTC features using
    ioctls
  linux-user: Add support for getting/setting RTC time and alarm using
    ioctls
  linux-user: Add support for getting/setting RTC periodic interrupt and
    epoch using ioctls
  linux-user: Add support for getting/setting RTC wakeup alarm using
    ioctls
  linux-user: Add support for getting/setting RTC PLL correction using
    ioctls
  linux-user: Add support for read/clear RTC voltage low detector using
    ioctls
  linux-user: Add support for getting alsa timer version and id
  linux-user: Add support for setting alsa timer enhanced read using
    ioctl
  linux-user: Add support for getting/setting specified alsa timer
    parameters using ioctls
  linux-user: Add support for selecting alsa timer using ioctl
  linux-user: Add support for getting/setting selected alsa timer
    parameters using ioctls
  linux-user: Add support for selected alsa timer instructions using
    ioctls

 linux-user/ioctls.h        |  45 +++++++++++++++++
 linux-user/syscall.c       |   2 +
 linux-user/syscall_defs.h  | 121 +++++++++++++++++++++++++++++++++++++++++++++
 linux-user/syscall_types.h |  91 ++++++++++++++++++++++++++++++++++
 4 files changed, 259 insertions(+)

-- 
2.7.4



^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2020-01-17 22:06 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 15:53 [PATCH 00/12] linux-user: Add support for real time clock and Filip Bozuta
2020-01-15 15:53 ` [PATCH 01/12] linux-user: Add support for enabling/disabling RTC features using ioctls Filip Bozuta
2020-01-15 15:53 ` [PATCH 02/12] linux-user: Add support for getting/setting RTC time and alarm " Filip Bozuta
2020-01-15 15:53 ` [PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch " Filip Bozuta
2020-01-15 16:46   ` Laurent Vivier
2020-01-15 15:53 ` [PATCH 04/12] linux-user: Add support for getting/setting RTC wakeup alarm " Filip Bozuta
2020-01-15 15:53 ` [PATCH 05/12] linux-user: Add support for getting/setting RTC PLL correction " Filip Bozuta
2020-01-15 15:53 ` [PATCH 06/12] linux-user: Add support for read/clear RTC voltage low detector " Filip Bozuta
2020-01-15 15:53 ` [PATCH 07/12] linux-user: Add support for getting alsa timer version and id Filip Bozuta
2020-01-15 15:53 ` [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl Filip Bozuta
2020-01-15 16:18   ` Arnd Bergmann
2020-01-15 16:32     ` Laurent Vivier
2020-01-15 16:37       ` Arnd Bergmann
2020-01-15 19:17         ` Filip Bozuta
2020-01-15 19:51           ` Arnd Bergmann
2020-01-15 21:30             ` Laurent Vivier
2020-01-15 21:52           ` Laurent Vivier
2020-01-16  2:49             ` Aleksandar Markovic
2020-01-16 11:27               ` Aleksandar Markovic
2020-01-16 12:00                 ` Arnd Bergmann
2020-01-16 12:00                   ` Arnd Bergmann
2020-01-17 20:50                   ` Aleksandar Markovic
2020-01-17 20:50                     ` Aleksandar Markovic
2020-01-17 21:45                     ` Arnd Bergmann
2020-01-17 21:45                       ` Arnd Bergmann
2020-01-17 21:54                     ` Alexandre Belloni
2020-01-17 21:54                       ` Alexandre Belloni
2020-01-15 15:53 ` [PATCH 09/12] linux-user: Add support for getting/setting specified alsa timer parameters using ioctls Filip Bozuta
2020-01-15 15:53 ` [PATCH 10/12] linux-user: Add support for selecting alsa timer using ioctl Filip Bozuta
2020-01-15 15:53 ` [PATCH 11/12] linux-user: Add support for getting/setting selected alsa timer parameters using ioctls Filip Bozuta
2020-01-15 15:53 ` [PATCH 12/12] linux-user: Add support for selected alsa timer instructions " Filip Bozuta
2020-01-15 16:35 ` [PATCH 00/12] linux-user: Add support for real time clock and Laurent Vivier
  -- strict thread matches above, loose matches on Subject: below --
2020-01-09 12:59 Filip Bozuta
2020-01-14 12:39 ` Philippe Mathieu-Daudé
2020-01-14 12:47   ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.