From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12A23C48BC2 for ; Wed, 23 Jun 2021 11:52:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B15C961076 for ; Wed, 23 Jun 2021 11:52:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B15C961076 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 783FA6B0011; Wed, 23 Jun 2021 07:52:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 733E36B0036; Wed, 23 Jun 2021 07:52:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D47E6B006C; Wed, 23 Jun 2021 07:52:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 26FE46B0011 for ; Wed, 23 Jun 2021 07:52:31 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 57B3F250B7 for ; Wed, 23 Jun 2021 11:52:31 +0000 (UTC) X-FDA: 78284826102.07.43FBC87 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id E4133C0201C6 for ; Wed, 23 Jun 2021 11:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/GACbFUQBsL3k4dufWqeympRiym3hWqjCaP9FTsmnJ4=; b=U9X4VQnXQPkXPJ39J6DWS3cOey d2rYg1uiuzUSKa2STWp7meESuGlq97IGwyOpE3fq9roWMn8HAmCHcE9Tki8Bnmn5yBw8z86WX4Osm DGW9oFDxxAKNwb6xcjLoKMFkSksdyCUhhM9v9huiN7qL3Gm2gx+EguwtsIjvGChIHzrJS10YYW+mm VsDukwoGemLtc6Ow1A4va747/uqarC5Pb5Fi+KPQ8uUugl2djIan4bZoXh6uHMArR5e6WjVljIAay D2ynNMwyscuEqSe8mZC5SaboEUwGzdkLHrW9ZylVI+Ipg1GjOELfFAqTwBxR3x1TxmKHyWLAdqeob 7Z/YtKmg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1lw1Po-00FNnk-3j; Wed, 23 Jun 2021 11:51:38 +0000 Date: Wed, 23 Jun 2021 12:51:32 +0100 From: Matthew Wilcox To: Catalin Marinas Cc: Al Viro , Xiaoming Ni , Chen Huang , Andrew Morton , Stephen Rothwell , Randy Dunlap , Will Deacon , Linux ARM , linux-mm , open list Subject: Re: [BUG] arm64: an infinite loop in generic_perform_write() Message-ID: References: <92fa298d-9d88-0ca4-40d9-13690dcd42f9@huawei.com> <20210623093220.GA3718@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210623093220.GA3718@arm.com> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E4133C0201C6 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=U9X4VQnX; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Stat-Signature: ygt731jbmcka3syp79ohu9rb7jhkffp1 X-HE-Tag: 1624449150-117507 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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().