From: Robin Murphy <robin.murphy@arm.com>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chen Huang <chenhuang5@huawei.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Matthew Wilcox <willy@infradead.org>,
Christoph Hellwig <hch@infradead.org>,
Mark Rutland <mark.rutland@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Randy Dunlap <rdunlap@infradead.org>,
Will Deacon <will@kernel.org>,
Linux ARM <linux-arm-kernel@lists.infradead.org>,
linux-mm <linux-mm@kvack.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] arm64: an infinite loop in generic_perform_write()
Date: Tue, 6 Jul 2021 20:15:47 +0100 [thread overview]
Message-ID: <dd30df30-5271-2724-48eb-9f47c5f3e1aa@arm.com> (raw)
In-Reply-To: <20210706175052.GD15218@arm.com>
On 2021-07-06 18:50, Catalin Marinas wrote:
> On Mon, Jun 28, 2021 at 05:22:30PM +0100, Robin Murphy wrote:
>> diff --git a/arch/arm64/lib/copy_to_user.S b/arch/arm64/lib/copy_to_user.S
>> index 043da90f5dd7..cfb598ae4812 100644
>> --- a/arch/arm64/lib/copy_to_user.S
>> +++ b/arch/arm64/lib/copy_to_user.S
>> @@ -32,7 +32,7 @@
>> .endm
>> .macro strh1 reg, ptr, val
>> - user_ldst 9998f, sttrh, \reg, \ptr, \val
>> + user_ldst 9997f, sttrh, \reg, \ptr, \val
>> .endm
>> .macro ldr1 reg, ptr, val
>> @@ -40,7 +40,7 @@
>> .endm
>> .macro str1 reg, ptr, val
>> - user_ldst 9998f, sttr, \reg, \ptr, \val
>> + user_ldst 9997f, sttr, \reg, \ptr, \val
>> .endm
>> .macro ldp1 reg1, reg2, ptr, val
>> @@ -48,12 +48,14 @@
>> .endm
>> .macro stp1 reg1, reg2, ptr, val
>> - user_stp 9998f, \reg1, \reg2, \ptr, \val
>> + user_stp 9997f, \reg1, \reg2, \ptr, \val
>> .endm
>> end .req x5
>> +srcin .req x15
>> SYM_FUNC_START(__arch_copy_to_user)
>> add end, x0, x2
>> + mov srcin, x1
>> #include "copy_template.S"
>> mov x0, #0
>> ret
>> @@ -62,6 +64,12 @@ EXPORT_SYMBOL(__arch_copy_to_user)
>> .section .fixup,"ax"
>> .align 2
>> +9997: cmp dst, dstin
>> + b.ne 9998f
>> + // Before being absolutely sure we couldn't copy anything, try harder
>> + ldrb tmp1w, [srcin]
>> +USER(9998f, sttrb tmp1w, [dstin])
>> + add dst, dstin, #1
>> 9998: sub x0, end, dst // bytes not copied
>> ret
>> .previous
>
> I think it's worth doing the copy_to_user() fallback in a loop until it
> faults or hits the end of the buffer. This would solve the problem we
> currently have with writing more bytes than actually reported. The
> copy_from_user() is not necessary, a byte would suffice.
The thing is, we don't really have that problem since the set_fs cleanup
removed IMP-DEF STP behaviour from the picture - even with the current
mess we could perfectly well know which of the two STTRs faulted if we
just put a little more effort in. Even, at worst, simply this:
diff --git a/arch/arm64/include/asm/asm-uaccess.h
b/arch/arm64/include/asm/asm-uaccess.h
index ccedf548dac9..7513758bab3a 100644
--- a/arch/arm64/include/asm/asm-uaccess.h
+++ b/arch/arm64/include/asm/asm-uaccess.h
@@ -74,8 +74,9 @@ alternative_else_nop_endif
.macro user_stp l, reg1, reg2, addr, post_inc
8888: sttr \reg1, [\addr];
-8889: sttr \reg2, [\addr, #8];
- add \addr, \addr, \post_inc;
+ add \addr, \addr, \post_inc / 2;
+8889: sttr \reg2, [\addr];
+ add \addr, \addr, \post_inc / 2;
_asm_extable 8888b,\l;
_asm_extable 8889b,\l;
But yuck... If you think the potential under-reporting is worth fixing
right now, rather than just letting it disappear in a future rewrite,
then I'd still rather do it by passing the actual fault address to the
current copy_to_user fixup. A retry loop could still technically
under-report if the page disappears (or tag changes) between faulting on
the second word of a pair and retrying from the first, so we'd want to
pin the initial fault down to a single access anyway. All the loop would
achieve after that is potentially fill in an extra 1-7 bytes right up to
the offending page/tag boundary for the sake of being nice, which I
remain unconvinced is worth the bother :)
Cheers,
Robin.
next prev parent reply other threads:[~2021-07-06 19:15 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-23 2:39 Chen Huang
2021-06-23 2:50 ` Al Viro
2021-06-23 3:24 ` Xiaoming Ni
2021-06-23 4:27 ` Al Viro
2021-06-23 9:32 ` Catalin Marinas
2021-06-23 11:51 ` Matthew Wilcox
2021-06-23 13:04 ` Al Viro
2021-06-23 13:22 ` Mark Rutland
2021-06-24 3:10 ` Chen Huang
2021-06-24 3:24 ` Matthew Wilcox
2021-06-24 3:52 ` Chen Huang
2021-06-24 7:04 ` Christoph Hellwig
2021-06-24 11:15 ` Matthew Wilcox
2021-06-24 13:22 ` Robin Murphy
2021-06-24 16:27 ` Al Viro
2021-06-24 16:38 ` Robin Murphy
2021-06-24 16:39 ` Al Viro
2021-06-24 17:24 ` Robin Murphy
2021-06-24 18:55 ` Catalin Marinas
2021-06-24 20:36 ` Robin Murphy
2021-06-25 10:39 ` Catalin Marinas
2021-06-28 16:22 ` Robin Murphy
2021-06-29 8:30 ` Catalin Marinas
2021-06-29 10:01 ` Robin Murphy
2021-07-06 17:50 ` Catalin Marinas
2021-07-06 19:15 ` Robin Murphy [this message]
2021-07-07 9:55 ` David Laight
2021-07-07 11:04 ` Robin Murphy
2021-07-07 12:50 ` Catalin Marinas
2021-06-24 15:09 ` Catalin Marinas
2021-06-24 16:17 ` Al Viro
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=dd30df30-5271-2724-48eb-9f47c5f3e1aa@arm.com \
--to=robin.murphy@arm.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=chenhuang5@huawei.com \
--cc=hch@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mark.rutland@arm.com \
--cc=rdunlap@infradead.org \
--cc=sfr@canb.auug.org.au \
--cc=viro@zeniv.linux.org.uk \
--cc=will@kernel.org \
--cc=willy@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
all inboxes | Powered by JetHome®