[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9cb1fadf-bb83-4e9f-9c29-bff53e30b0c6@rivosinc.com>
Date: Mon, 27 Nov 2023 11:24:25 +0100
From: Clément Léger <cleger@...osinc.com>
To: David Laight <David.Laight@...LAB.COM>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
"linux-riscv@...ts.infradead.org" <linux-riscv@...ts.infradead.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Cc: Christoph Hellwig <hch@...radead.org>,
Ben Dooks <ben.dooks@...ethink.co.uk>,
kernel test robot <lkp@...el.com>
Subject: Re: [PATCH v2] riscv: fix incorrect use of __user pointer
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)
Powered by blists - more mailing lists