linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Stafford Horne <shorne@gmail.com>
Cc: Jonas Bonn <jonas@southpole.se>,
	LKML <linux-kernel@vger.kernel.org>,
	openrisc@lists.librecores.org, Greentime Hu <green.hu@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [OpenRISC] [PATCH v2 3/3] openrisc: Fix issue with get_user for 64-bit values
Date: Sun, 6 Sep 2020 02:22:28 +0200	[thread overview]
Message-ID: <20200906002228.mrbs7pdyrf5ooi3c@ltop.local> (raw)
In-Reply-To: <20200905213408.GI3562056@lianli.shorne-pla.net>

On Sun, Sep 06, 2020 at 06:34:08AM +0900, Stafford Horne wrote:
> On Sat, Sep 05, 2020 at 03:57:14PM +0200, Luc Van Oostenryck wrote:
> > On Sat, Sep 05, 2020 at 10:19:35PM +0900, Stafford Horne wrote:
> > 
> > Hi,
> > 
> > The change for 64-bit get_user() looks good to me.
> > But I wonder, given that openrisc is big-endian, what will happen
> > you have the opposite situation:
> > 	u32 *ptr;
> > 	u64 val;
> > 	...
> > 	get_user(val, ptr);
> > 
> > Won't you end with the value in the most significant part of
> > the register pair?
> 
> Hi Luc,
> 
> The get_user function uses the size of the ptr to determine how to do the load ,
> so this case would not use the 64-bit pair register logic.  I think it should be
> ok, the end result would be the same as c code:
> 
>   var = *ptr;

Hi,

Sorry to insist but both won't give the same result.
The problem comes from the output part of the asm: "=r" (x).

The following code:
	u32 getp(u32 *ptr)
	{
		u64 val;
		val = *ptr;
		return val;
	}
will compile to something like:
	getp:
		l.jr	r9
		l.lwz	r11, 0(r3)

The load is written to r11, which is what is returned. OK.

But the get_user() code with a u32 pointer *and* a u64 destination
is equivalent to something like:
	u32 getl(u32 *ptr)
	{
		u64 val;

		asm("l.lwz %0,0(%1)" : "=r"(val) : "r"(ptr));
		return val;
	}
and this compiles to:
	getl:
		l.lwz	r17,0(r3)
		l.jr	r9
		l.or	r11, r19, r19

The load is written to r17 but what is returned is the content of r19.
Not good.

I think that, in the get_user() code:
* if the pointer is a pointer to a 64-bit quantity, then variable
  used in as the output in the asm needs to be a 64-bit variable
* if the pointer is a pointer to a 32-bit quantity, then variable
  used in as the output in the asm needs to be a 64-bit variable
At least one way to guarantee this is to use a temporary variable
that matches the size of the pointer.

-- Luc

  reply	other threads:[~2020-09-06  0:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-05 13:19 [PATCH v2 0/3] OpenRISC fixes for 5.9 Stafford Horne
2020-09-05 13:19 ` [PATCH v2 1/3] openrisc: Reserve memblock for initrd Stafford Horne
2020-09-05 13:25   ` Stafford Horne
2020-09-06  6:15   ` Mike Rapoport
2020-09-05 13:19 ` [PATCH v2 2/3] openrisc: Fix cache API compile issue when not inlining Stafford Horne
2020-09-05 13:19 ` [PATCH v2 3/3] openrisc: Fix issue with get_user for 64-bit values Stafford Horne
2020-09-05 13:57   ` Luc Van Oostenryck
2020-09-05 21:34     ` Stafford Horne
2020-09-06  0:22       ` Luc Van Oostenryck [this message]
2020-09-06 21:00         ` [OpenRISC] " Stafford Horne
2020-09-05 13:24 ` [PATCH v2 0/3] OpenRISC fixes for 5.9 Stafford Horne

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=20200906002228.mrbs7pdyrf5ooi3c@ltop.local \
    --to=luc.vanoostenryck@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=green.hu@gmail.com \
    --cc=jonas@southpole.se \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openrisc@lists.librecores.org \
    --cc=shorne@gmail.com \
    /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).