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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 42606C07E9E for ; Wed, 7 Jul 2021 11:04:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CF5A361CB2 for ; Wed, 7 Jul 2021 11:04:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF5A361CB2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 58D676B0036; Wed, 7 Jul 2021 07:04:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5646F6B005D; Wed, 7 Jul 2021 07:04:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 405EF6B006C; Wed, 7 Jul 2021 07:04:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 1F49E6B0036 for ; Wed, 7 Jul 2021 07:04:35 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F364C8249980 for ; Wed, 7 Jul 2021 11:04:32 +0000 (UTC) X-FDA: 78335508384.29.0288F7D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 8964C5005D60 for ; Wed, 7 Jul 2021 11:04:32 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D4FCB1042; Wed, 7 Jul 2021 04:04:31 -0700 (PDT) Received: from [10.57.35.192] (unknown [10.57.35.192]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A85FD3F5A1; Wed, 7 Jul 2021 04:04:29 -0700 (PDT) Subject: Re: [BUG] arm64: an infinite loop in generic_perform_write() To: David Laight , Catalin Marinas Cc: Chen Huang , Al Viro , Matthew Wilcox , Christoph Hellwig , Mark Rutland , Andrew Morton , Stephen Rothwell , Randy Dunlap , Will Deacon , Linux ARM , linux-mm , open list References: <1c635945-fb25-8871-7b34-f475f75b2caf@huawei.com> <27fbb8c1-2a65-738f-6bec-13f450395ab7@arm.com> <20210624185554.GC25097@arm.com> <20210625103905.GA20835@arm.com> <7f14271a-9b2f-1afc-3caf-c4e5b36efa73@arm.com> <20210706175052.GD15218@arm.com> <4a1473fc5af9496e9c8ed02c7f631d72@AcuMS.aculab.com> From: Robin Murphy Message-ID: <9bda45b9-5384-fc14-1bc5-be00d07d4350@arm.com> Date: Wed, 7 Jul 2021 12:04:25 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <4a1473fc5af9496e9c8ed02c7f631d72@AcuMS.aculab.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of robin.murphy@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=robin.murphy@arm.com; dmarc=pass (policy=none) header.from=arm.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8964C5005D60 X-Stat-Signature: frcqmd43rtnc97bkn18i34e9mhqfdwtn X-HE-Tag: 1625655872-134680 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 2021-07-07 10:55, David Laight wrote: >>> 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 > ... > > There is a much more interesting case though. > It is possible for userspace to have supplied a misaligned > buffer that is mmapped to an IO address that doesn't support > misaligned accesses even though normal memory does support them. Er, yes, that's where this whole thing started - don't worry, I haven't forgotten. > So the 'byte retry' loop would work for the entire buffer. Indeed it might in certain cases, but is that (unlikely) possibility worth our while? What it boils down to is maintaining complexity in the kernel purely to humour broken userspace doing a nonsensical thing, when it's equally valid to just return a short read/write and let said broken userspace take responsibility for retrying the remainder of said nonsensical thing by itself. If userspace has managed to get its hands on an mmap of something without Normal memory semantics, I would expect it to know what it's doing... Thanks, Robin.