mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Clément Léger" <cleger@rivosinc.com>
To: David Laight <David.Laight@ACULAB.COM>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	"linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	Ben Dooks <ben.dooks@codethink.co.uk>,
	kernel test robot <lkp@intel.com>
Subject: Re: [PATCH v2] riscv: fix incorrect use of __user pointer
Date: Mon, 27 Nov 2023 11:24:25 +0100	[thread overview]
Message-ID: <9cb1fadf-bb83-4e9f-9c29-bff53e30b0c6@rivosinc.com> (raw)
In-Reply-To: <bf7dfadfc8a94e3f810a8ba238f77543@AcuMS.aculab.com>



On 25/11/2023 16:37, David Laight wrote:
> ...
>> @@ -491,7 +486,7 @@ int handle_misaligned_load(struct pt_regs *regs)
>>
>>  	val.data_u64 = 0;
>>  	for (i = 0; i < len; i++) {
>> -		if (load_u8(regs, (void *)(addr + i), &val.data_bytes[i]))
>> +		if (load_u8(regs, addr + i, &val.data_bytes[i]))
>>  			return -1;
>>  	}
> 
> I'd really have thought that you'd want to pull the kernel/user
> check way outside the loop?

Hi David,

I hope the compiler is able to extract that 'if' out of the loop since
regs isn't modified in the loop. Nevertheless, that could be more
"clear" if put outside indeed.

> In any case, for a misaligned read why not just read (addr & ~7)[0]
> and (if needed) (addr & ~7)[1] and then ahift and or together?

Makes sense, the original code was like that but probably copy/pasted
from openSBI I guess. (?)

Let's keep that for the moment (this patch is about fixing wrong __user
address space). I will try to submit another series using what you proposed.

Regards,

Clément

> 
> clang will do it for misaligned structure members with known
> misalignment, but it is almost certainly also better for reads
> with unknown misalignment.
> 
> 	David
> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)

  reply	other threads:[~2023-11-27 10:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-24 11:38 Clément Léger
2023-11-25  6:22 ` Christoph Hellwig
2023-11-25 15:37 ` David Laight
2023-11-27 10:24   ` Clément Léger [this message]
2023-11-27 10:35     ` David Laight
2023-11-27 10:37       ` Clément Léger
2023-11-27 10:51         ` David Laight
2023-11-27 12:02 ` Ben Dooks
2023-11-27 12:46   ` Clément Léger
2023-11-27 12:57     ` Clément Léger

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=9cb1fadf-bb83-4e9f-9c29-bff53e30b0c6@rivosinc.com \
    --to=cleger@rivosinc.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=aou@eecs.berkeley.edu \
    --cc=ben.dooks@codethink.co.uk \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=lkp@intel.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.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

all inboxes | Powered by JetHome®