All of lore.kernel.org
 help / color / mirror / Atom feed
From: gangchen@rdamicro.com (Chen Gang)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/1] ARM : missing corrupted reg in __do_div_asm
Date: Mon, 08 Jun 2015 13:30:18 +0800	[thread overview]
Message-ID: <5575286A.1080002@rdamicro.com> (raw)
In-Reply-To: <1433225609-7148-1-git-send-email-gangchen@rdamicro.com>

Hi,

     I tried to make a test program to illustrate the patch.

Without the patch, the log shows
"[250970.715392] remains1 is 2, remains2 is 0"
And the remains2 is wrong

With the patch, the log is
"[250977.724181] remains1 is 2, remains2 is 4".
now both remains1 and remains2 are correct.

I compared the output assembly and it showed in the faulty version,
r0 ( I am using little endian system) is not reload after the
first do_div and before the second do_div call in function mydiv64.



Br, Chen Gang

#include <asm/div64.h>
#include <linux/init.h>
#include <linux/printk.h>

typedef unsigned long long ull;

void mydiv64(ull tt, unsigned base1, unsigned base2,
         unsigned *rems1, unsigned *rems2)
{
     ull t = tt;
     *rems1 = do_div(t, base1);
     *rems2 = do_div(tt, base2);
     return ;
}

static int __init div_test(void)
{
     ull t;
     unsigned int remains1;
     unsigned int remains2;
     unsigned base1, base2;

     t = 100;
     base1 = 7;
     base2 = 8;

     mydiv64(t, base1, base2, &remains1, &remains2);
     printk(KERN_ERR"remains1 is %d, remains2 is %d\n",
             remains1, remains2);

     return -1;
}

static void __exit div_test_exit(void)
{
}

module_init(div_test);
module_exit(div_test_exit);

On 06/02/2015 02:13 PM, Chen Gang wrote:
> __xl (r0 in little endian system, or R1 in big endian system) is corrupted
> after calling __do_div64 and compiler is not informed about this in
> macro __do_div_asm. If n is used again afterwards, __xl won't be
> reloaded and n will contain incorrect value.
> ---
>   arch/arm/include/asm/div64.h | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm/include/asm/div64.h b/arch/arm/include/asm/div64.h
> index 662c7bd..fa9489e 100644
> --- a/arch/arm/include/asm/div64.h
> +++ b/arch/arm/include/asm/div64.h
> @@ -34,12 +34,14 @@
>   	register unsigned long long __n   asm("r0") = n;	\
>   	register unsigned long long __res asm("r2");		\
>   	register unsigned int __rem       asm(__xh);		\
> +	register unsigned int __clobber   asm(__xl);		\
>   	asm(	__asmeq("%0", __xh)				\
> -		__asmeq("%1", "r2")				\
> -		__asmeq("%2", "r0")				\
> -		__asmeq("%3", "r4")				\
> +		__asmeq("%1", __xl)				\
> +		__asmeq("%2", "r2")				\
> +		__asmeq("%3", "r0")				\
> +		__asmeq("%4", "r4")				\
>   		"bl	__do_div64"				\
> -		: "=r" (__rem), "=r" (__res)			\
> +		: "=r" (__rem), "=r" (__clobber), "=r" (__res)  \
>   		: "r" (__n), "r" (__base)			\
>   		: "ip", "lr", "cc");				\
>   	n = __res;						\

  reply	other threads:[~2015-06-08  5:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] </home/gachen/Re: [PATCH 1_1] ARM:r0 is also corrupted after calling __do_div64..eml>
2015-06-02  6:13 ` [PATCH 1/1] ARM : missing corrupted reg in __do_div_asm Chen Gang
2015-06-08  5:30   ` Chen Gang [this message]
2015-06-09 13:09   ` Russell King - ARM Linux
2015-06-19 11:28     ` [PATCH v2 " Chen Gang
2015-06-28 11:29     ` [PATCH " Chen Gang
2016-03-28  4:19 Chen Gang
2016-03-29 10:19 ` Arnd Bergmann
2016-03-29 10:26   ` Dave Martin
2016-03-29 10:34     ` Russell King - ARM Linux
2016-03-29 10:56       ` Dave Martin
2016-03-30  3:27         ` 陈刚(Gangchen)
2016-03-30 14:07           ` Dave Martin
2016-03-31  7:56             ` 陈刚(Gangchen)
2016-03-31 10:30               ` Dave Martin
2016-03-31 11:20                 ` 陈刚(Gangchen)
2016-03-31 11:41                   ` Dave Martin
2016-03-29 10:58       ` 陈刚(Gangchen)

Reply instructions:

You may reply publicly 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=5575286A.1080002@rdamicro.com \
    --to=gangchen@rdamicro.com \
    --cc=linux-arm-kernel@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.