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 D268CC49EA5 for ; Thu, 24 Jun 2021 16:38:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6CF0613D8 for ; Thu, 24 Jun 2021 16:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231321AbhFXQlC (ORCPT ); Thu, 24 Jun 2021 12:41:02 -0400 Received: from foss.arm.com ([217.140.110.172]:33856 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbhFXQlB (ORCPT ); Thu, 24 Jun 2021 12:41:01 -0400 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 5DF24ED1; Thu, 24 Jun 2021 09:38:42 -0700 (PDT) Received: from [10.57.9.136] (unknown [10.57.9.136]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6DEA03F719; Thu, 24 Jun 2021 09:38:40 -0700 (PDT) Subject: Re: [BUG] arm64: an infinite loop in generic_perform_write() To: Al Viro Cc: Matthew Wilcox , Christoph Hellwig , Chen Huang , Mark Rutland , Andrew Morton , Stephen Rothwell , Randy Dunlap , Catalin Marinas , Will Deacon , Linux ARM , linux-mm , open list References: <20210623132223.GA96264@C02TD0UTHF1T.local> <1c635945-fb25-8871-7b34-f475f75b2caf@huawei.com> <27fbb8c1-2a65-738f-6bec-13f450395ab7@arm.com> From: Robin Murphy Message-ID: <7896a3c7-2e14-d0f4-dbb9-286b6f7181b5@arm.com> Date: Thu, 24 Jun 2021 17:38:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-06-24 17:27, Al Viro wrote: > On Thu, Jun 24, 2021 at 02:22:27PM +0100, Robin Murphy wrote: > >> FWIW I think the only way to make the kernel behaviour any more robust here >> would be to make the whole uaccess API more expressive, such that rather >> than simply saying "I only got this far" it could actually differentiate >> between stopping due to a fault which may be recoverable and worth retrying, >> and one which definitely isn't. > > ... and propagate that "more expressive" information through what, 3 or 4 > levels in the call chain? > > From include/linux/uaccess.h: > > * If raw_copy_{to,from}_user(to, from, size) returns N, size - N bytes starting > * at to must become equal to the bytes fetched from the corresponding area > * starting at from. All data past to + size - N must be left unmodified. > * > * If copying succeeds, the return value must be 0. If some data cannot be > * fetched, it is permitted to copy less than had been fetched; the only > * hard requirement is that not storing anything at all (i.e. returning size) > * should happen only when nothing could be copied. In other words, you don't > * have to squeeze as much as possible - it is allowed, but not necessary. > > arm64 instances violate the aforementioned hard requirement. Please, fix > it there; it's not hard. All you need is an exception handler in .Ltiny15 > that would fall back to (short) byte-by-byte copy if the faulting address > happened to be unaligned. Or just do one-byte copy, not that it had been > considerably cheaper than a loop. Will be cheaper than propagating that extra > information up the call chain, let alone paying for extra ->write_begin() > and ->write_end() for single byte in generic_perform_write(). And what do we do if we then continue to fault with an external abort because whatever it is that warranted being mapped as Device-type memory in the first place doesn't support byte accesses? Robin.