Linux SNPS ARC Archive on lore.kernel.org
 help / color / Atom feed
From: Vineet Gupta <vineetg76@gmail.com>
To: Alistair Francis <alistair.francis@wdc.com>, libc-alpha@sourceware.org
Cc: alistair23@gmail.com, arcml <linux-snps-arc@lists.infradead.org>
Subject: Re: [PATCH v2 4/6] linux: Use long time_t __getitimer/__setitimer
Date: Tue, 11 Feb 2020 12:02:26 -0800
Message-ID: <9b03cfdb-b8b2-a8f6-329f-5fbd38cd9ed8@gmail.com> (raw)
In-Reply-To: <20200210174325.6566-5-alistair.francis@wdc.com>

Hi Alistair,

On 2/10/20 9:43 AM, Alistair Francis wrote:
> The Linux kernel expects itimerval to use a 32-bit time_t, even on archs
> with a 64-bit time_t (like RV32). To address this let's convert
> itimerval to/from 32-bit and 64-bit to ensure the kernel always gets
> a 32-bit time_t.
> 
> While we are converting these functions let's also convert them to be
> the y2038 safe versions. This means there is a *64 function that is
> called by a backwards compatible wrapper.
> ---

> +
> +int
> +__setitimer64 (__itimer_which_t which,
> +               const struct __itimerval64 *restrict new_value,
> +               struct __itimerval64 *restrict old_value)
> +{
> +  struct __itimerval32 new_value_32;
> +
> +  if (! in_time_t_range (new_value->it_interval.tv_sec))
> +  {
> +    __set_errno (EOVERFLOW);
> +    return -1;
> +  }
> +  new_value_32.it_interval
> +    = valid_timeval64_to_timeval32 (new_value->it_interval);
> +
> +  if (! in_time_t_range (new_value->it_value.tv_sec))
> +  {
> +    __set_errno (EOVERFLOW);
> +    return -1;
> +  }
> +  new_value_32.it_value
> +    = valid_timeval64_to_timeval32 (new_value->it_value);
> +
> +  if (old_value == NULL)
> +    return INLINE_SYSCALL_CALL (setitimer, which, &new_value_32, NULL);
> +
> +  struct __itimerval32 old_value_32;
> +  if (INLINE_SYSCALL_CALL (setitimer, which, &new_value_32, &old_value_32) == -1)
> +    return -1;
> +
> +  /* Write all fields of 'old_value' regardless of overflow.  */
> +  old_value->it_interval
> +     = valid_timeval32_to_timeval64 (old_value_32.it_interval);
> +  old_value->it_value
> +     = valid_timeval32_to_timeval64 (old_value_32.it_value);
> +  return 0;
> +}
> +
> +#if __TIMESIZE != 64
> +int
> +__setitimer (__itimer_which_t which,
> +             const struct itimerval *restrict new_value,
> +             struct itimerval *restrict old_value)
> +{
> +  int ret;
> +  struct __itimerval64 new64, old64;
> +
> +  new64.it_interval
> +    = valid_timeval_to_timeval64 (new_value->it_interval);
> +  new64.it_value
> +    = valid_timeval_to_timeval64 (new_value->it_value);
> +
> +  ret = __setitimer64 (which, &new64, &old64);
> +
> +  if (ret != 0)
> +    return ret;

I tested ARC port over your v1 next branch and it works fine in general. I still
had 32-bit time_t so you have some more test coverage ;-)

The glibc testsuite had some new failures, some of them are coming from the
unchecked @old_value dereference (which would not hit for 64-bit time_t).

Care to fix it please.

> +
> +  old_value->it_interval
> +    = valid_timeval64_to_timeval (old64.it_interval);
> +  old_value->it_value
> +    = valid_timeval64_to_timeval (old64.it_value);
> +
> +  return ret;
> +}
> +#endif
> +weak_alias (__setitimer, setitimer)
Thx,
-Vineet

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

       reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200210174325.6566-1-alistair.francis@wdc.com>
     [not found] ` <20200210174325.6566-5-alistair.francis@wdc.com>
2020-02-11 20:02   ` Vineet Gupta [this message]
2020-02-11 21:30     ` Alistair Francis

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9b03cfdb-b8b2-a8f6-329f-5fbd38cd9ed8@gmail.com \
    --to=vineetg76@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=alistair23@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-snps-arc@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux SNPS ARC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-snps-arc/0 linux-snps-arc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-snps-arc linux-snps-arc/ https://lore.kernel.org/linux-snps-arc \
		linux-snps-arc@lists.infradead.org
	public-inbox-index linux-snps-arc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-snps-arc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git