linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: gangchen@rdamicro.com (陈刚(Gangchen))
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/1] ARM : missing corrupted reg in __do_div_asm
Date: Thu, 31 Mar 2016 07:56:05 +0000	[thread overview]
Message-ID: <56FCD815.7000503@rdamicro.com> (raw)
In-Reply-To: <20160330140718.GG3701@e103592.cambridge.arm.com>

On 03/30/2016 10:07 PM, Dave Martin wrote:
> On Wed, Mar 30, 2016 at 03:27:01AM +0000, ??(Gangchen) wrote:
>> On 03/29/2016 06:56 PM, Dave Martin wrote:
>>> On Tue, Mar 29, 2016 at 11:34:18AM +0100, Russell King - ARM Linux wrote:
>>>> On Tue, Mar 29, 2016 at 11:26:05AM +0100, Dave Martin wrote:
>>>>> On Tue, Mar 29, 2016 at 12:19:49PM +0200, Arnd Bergmann wrote:
>>>>>> On Monday 28 March 2016 12:19:03 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.
>>>>>>>
>>>>>>> Signed-off-by: Chen Gang <gangchen@rdamicro.com>
>>>>>>> Signed-off-by: Chen Gang <chengang.beijing@gmail.com>
>>>>>>> ---
>>>>>> How did you find this? Did you run into this problem on a live system
>>>>>> or see it through inspection?
>>>>>>
>>>>>>>    arch/arm/include/asm/div64.h | 6 ++++--
>>>>>>>    1 file changed, 4 insertions(+), 2 deletions(-)
>>>>>>>
>>>>>>> diff --git a/arch/arm/include/asm/div64.h b/arch/arm/include/asm/div64.h
>>>>>>> index e1f0776..1a6e91a 100644
>>>>>>> --- a/arch/arm/include/asm/div64.h
>>>>>>> +++ b/arch/arm/include/asm/div64.h
>>>>>>> @@ -35,12 +35,14 @@ static inline uint32_t __div64_32(uint64_t *n, uint32_t base)
>>>>>>>           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("%3", "r0")
>>>>>>> +               __asmeq("%4", "r4")
>>>>>>>                   __asmeq("%2", "r0")
>>>>>>> -               __asmeq("%3", "r4")
>>>>>>>                   "bl     __do_div64"
>>>>>>> -               : "=r" (__rem), "=r" (__res)
>>>>>>> +               : "=r" (__rem), "=r" (__res), "=r" (__clobber)
>>>>>>>                   : "r" (__n), "r" (__base)
>>>>>>>                   : "ip", "lr", "cc");
>>>>>>>           *n = __res;
>>>>>> Doesn't the clobber normally go in the third line along with
>>>>>> "ip" and "lr"?
>>>>> Since __xl is not used for any real argument to the asm, I think
>>>>> we can just add __xl to the clobber list directly, without needing
>>>>> to introduce an extra register variable ... no?
>>>> No, you can't.  The clobber list is not allowed to specify registers
>>>> that may be used for input or output operands, and since __xl may be
>>>> r0, and __n _is_ r0, you can't specify r0 in the clobber list.
>>> Hmm, you're right -- in which case the change looks reasonable.
>>>
>>> I wonder whether the following would be cleaner than having these
>>> aliased arguments:
>>>
>>> 	asm(	/* ... */
>>> 		"bl	__do_div64"
>>> 		: "+r" (__n), "=r" (__res)
>>> 		: "r" (__base)
>>> 		: "ip", "lr", "cc");
>>> 	*n = __res;
>>> 	return __n >> 32;
>>>
>>> (providing that GCC doesn't make a mess of the "easy" shift).
>> I tried your proposal. It didn't make any difference: this is inline
>> function and gcc just ignores your trick.
> What doesn't work for you when using this method?
>
> Why does the fact that this is an inline function make a difference?
With the help of other colleagues, I understand your proposal now.
I create a patch and I can verify that it works!

Should I submit it, as it seems better than this one I sent?

Cheers ---Dave

  reply	other threads:[~2016-03-31  7:56 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-28  4:19 [PATCH 1/1] ARM : missing corrupted reg in __do_div_asm 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) [this message]
2016-03-31 10:30               ` Dave Martin
2016-03-31 11:20                 ` 陈刚(Gangchen)
2016-03-31 11:41                   ` Dave Martin
2016-04-01  4:22                     ` [PATCH V3 1/1] ARM : missing corrupted reg in __div64_32 chengang
2016-04-01  8:56                       ` Dave Martin
2016-04-01 10:28                         ` [PATCH V4 " chengang
2016-04-01 11:03                           ` Dave Martin
2016-04-01 11:25                             ` [PATCH V5 " chengang
2016-04-01 11:34                               ` Dave P Martin
2016-04-01 11:35                             ` [PATCH V4 " 陈刚(Gangchen)
2016-03-31 11:41                 ` [PATCH v2 " Chen Gang
2016-03-29 10:58       ` [PATCH 1/1] ARM : missing corrupted reg in __do_div_asm 陈刚(Gangchen)
     [not found] </home/gachen/Re: [PATCH 1_1] ARM:r0 is also corrupted after calling __do_div64..eml>
2015-06-02  6:13 ` Chen Gang
2015-06-08  5:30   ` Chen Gang
2015-06-09 13:09   ` Russell King - ARM Linux
2015-06-28 11:29     ` Chen Gang

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=56FCD815.7000503@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).