linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Xiaoming Ni <nixiaoming@huawei.com>,
	Chen Huang <chenhuang5@huawei.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: Wed, 23 Jun 2021 12:51:32 +0100	[thread overview]
Message-ID: <YNMgRJrNNomLXf3M@casper.infradead.org> (raw)
In-Reply-To: <20210623093220.GA3718@arm.com>

On Wed, Jun 23, 2021 at 10:32:21AM +0100, Catalin Marinas wrote:
> On Wed, Jun 23, 2021 at 04:27:37AM +0000, Al Viro wrote:
> > On Wed, Jun 23, 2021 at 11:24:54AM +0800, Xiaoming Ni wrote:
> > > On 2021/6/23 10:50, Al Viro wrote:
> > > > On Wed, Jun 23, 2021 at 10:39:31AM +0800, Chen Huang wrote:
> > > > 
> > > > > Then when kernel handles the alignment_fault, it will not panic. As the
> > > > > arm64 memory model spec said, when the address is not a multiple of the
> > > > > element size, the access is unaligned. Unaligned accesses are allowed to
> > > > > addresses marked as Normal, but not to Device regions. An unaligned access
> > > > > to a Device region will trigger an exception (alignment fault).
> > > > > 	
> > > > > do_alignment_fault
> > > > >      do_bad_area
> > > > > 	__do_kernel_fault
> > > > >             fixup_exception
> > > > > 
> > > > > But that fixup cann't handle the unaligned copy, so the
> > > > > copy_page_from_iter_atomic returns 0 and traps in loop.
> > > > 
> > > > Looks like you need to fix your raw_copy_from_user(), then...
> > > 
> > > Exit loop when iov_iter_copy_from_user_atomic() returns 0.
> > > This should solve the problem, too, and it's easier.
> > 
> > It might be easier, but it's not going to work correctly.
> > If the page gets evicted by memory pressure, you are going
> > to get spurious short write.
> > 
> > Besides, it's simply wrong - write(2) does *NOT* require an
> > aligned source.  It (and raw_copy_from_user()) should act the
> > same way memcpy(3) does.
> 
> On arm64, neither memcpy() nor raw_copy_from_user() are expected to work
> on Device mappings, we have memcpy_fromio() for this but only for
> ioremap(). There's no (easy) way to distinguish in the write() syscall
> how the source buffer is mapped. generic_perform_write() does an
> iov_iter_fault_in_readable() check but that's not sufficient and it also
> breaks the cases where you can get intra-page faults (arm64 MTE or SPARC
> ADI). I think in the general case it's racy anyway (another thread doing
> an mprotect(PROT_NONE) after the readable check passed).
> 
> So I think generic_perform_write() returning -EFAULT if copied == 0
> would make sense (well, unless it breaks other cases I'm not aware of).

It does break other cases -- that's what happens if the page has gone
missing after being faulted in.  You need to fix your copy_from_user().


  reply	other threads:[~2021-06-23 11:52 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23  2:39 [BUG] arm64: an infinite loop in generic_perform_write() 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 [this message]
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
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=YNMgRJrNNomLXf3M@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuang5@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nixiaoming@huawei.com \
    --cc=rdunlap@infradead.org \
    --cc=sfr@canb.auug.org.au \
    --cc=viro@zeniv.linux.org.uk \
    --cc=will@kernel.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).