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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34745C48BF6 for ; Fri, 1 Mar 2024 02:13:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFBA66B00AC; Thu, 29 Feb 2024 21:13:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AAAAC6B00AD; Thu, 29 Feb 2024 21:13:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99A1E6B00AE; Thu, 29 Feb 2024 21:13:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8B4EF6B00AC for ; Thu, 29 Feb 2024 21:13:37 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 67E58140382 for ; Fri, 1 Mar 2024 02:13:37 +0000 (UTC) X-FDA: 81846848874.26.E7BE448 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf26.hostedemail.com (Postfix) with ESMTP id A2512140003 for ; Fri, 1 Mar 2024 02:13:34 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709259215; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ty1NOJAFiEncUFxGQ4KJJf9eh5Z1rU5rO5YoxRVqMwY=; b=2/k6vaGEe3YMO1mUR7zV1kWkIxO0tcympIGmj7ufzql5GfV90JdM6fOnhr2YFiHRrau1ug P2iPxBEjDBkb8kVYoXLpn01q4QMYh3Ul9MMGPSLuhSrUfAxTzZAtAxLBpmu2mzUHZYWu4A EeQNnVVmaCDmEAO8iNNEQnX9tNhvVk8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709259215; a=rsa-sha256; cv=none; b=HMf6/bjuAZTs2asCkidXci99TXZ7opvn3pBo+73oLMUdfJJuzCsI5cm4mTwqQVbAaAxh8P 7lblf5zMUE3hIOON0i7UtSJ2RJmfsSe1I3yc8Mu7TTpz2EY5WOVqvYjzIDsglL2Jsowm4b Xz2f4Kt5CvBJk6eQRtanS8OUvAYx9EU= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TmBQn5z23z1h142; Fri, 1 Mar 2024 10:11:13 +0800 (CST) Received: from kwepemm600017.china.huawei.com (unknown [7.193.23.234]) by mail.maildlp.com (Postfix) with ESMTPS id 15F1D1A016B; Fri, 1 Mar 2024 10:13:30 +0800 (CST) Received: from [10.174.179.234] (10.174.179.234) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 1 Mar 2024 10:13:28 +0800 Message-ID: <8d49ad72-4d51-27b9-1c0e-0948942f8027@huawei.com> Date: Fri, 1 Mar 2024 10:13:28 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [bug report] dead loop in generic_perform_write() //Re: [PATCH v7 07/12] iov_iter: Convert iterate*() to inline funcs To: Linus Torvalds , Al Viro CC: David Howells , Jens Axboe , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , , , , , , Kefeng Wang References: <20230925120309.1731676-1-dhowells@redhat.com> <20230925120309.1731676-8-dhowells@redhat.com> <4e80924d-9c85-f13a-722a-6a5d2b1c225a@huawei.com> From: Tong Tiangen In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.234] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600017.china.huawei.com (7.193.23.234) X-Rspamd-Queue-Id: A2512140003 X-Rspam-User: X-Stat-Signature: jqiswbrzcnwmtr4si3hukrqxy774f1e1 X-Rspamd-Server: rspam01 X-HE-Tag: 1709259214-12644 X-HE-Meta: U2FsdGVkX18iZAnm0XQtpGI1JN0RSSR4EkYcKZDdW1JB2TsismaCmgtX8XSbPK0twuhr/ZOjYH+blRqDoE4NVAkSu7IdhXq7DoXtGIUABpcXr6xlhmdphTSLNZX9H853SlII6UfxmgLqcHSCvL5lKksB1pQNeVT6UzhApobLKzIbqZ6Xb/KWk63rlUxEp3z/PhGvfu8LtueAFGHmoMO+uwL1TVGY9mT3wvZF6Ni1Tlmz9oc09CyBJ/fPharDbxpZI7MbNFqFtrYHylDxI4onR4LpwqvffDZO4nmHafhKOpY3Bery2IeNsseG8OoyHS4FpbB1P9RCdnf0YyJeExHB+wOWUBL5J+0Pp0NRgs7oCQ8oHC9bTz/cBwJmD9NtCi4qVo3t22qaqDYifOI6jXW30BwuE6DPpfSt5Iz6onRXM3HJA49mh656/n3HzUuS1FbX/23798L9Im9w3wDwIoOYGEUxK23WaJqVyfaS9K7JHidGPLl4xqfLp7tJjZk2kCTT9uuXmkPk0PTos9cgVadolJ77DcHXka2X9kn1q/JdFdtiQftxC3mZBxvzlk/+B6ftEGNyPpd+j6tGLWVVt2sH95uN+GommJ/X8JKdYySQCvhpNUYRyOJAxAxxo8QAkFMdckHXhb+mXh4V0OApxbk+McRGjIA0Oc0Jd1f/EZxZ8T5pcIR7/+nKWRzyA6ZjOM0Ch/i8GlIm5A7TzJNC1rSXy01VzQnfPb90fulrXo20YvF4XX3Tk9/q4hYYD/orSR+rWR74433Sa0x/TA6AigC6FlgHx2JUJSxO98lQFMwZRyotRY+hYFd5mr5BgsBSUCAcqKLUtWMyRMFCdu44kB4JQy7lqJXDVdSDFNOHAY3qEOJq5enQD41VcY6DTnaEYK2EwZ7GY9NVSvBQO3pCAGhYtzV4TPQE1/CW514U/wiw2FV0302qO4/qNFtPNmqGuFxQZf/kqki9tsw0LbJl4+A M2/FmjYf K4V6I7DqOBF1EYW2HORuqVvpsLdnUsMo8u1J/RpC19QCnwIU7sQ/ufT32Ce6GVbLG6FmkEVQ+kneJN8PaEyISObtgqA2um+45Te5vKF6fpJ0cseYM6EtcYMsQ4BttIbx2P7LeeqIn4huMhrXUf+oz/fQ8EtQr3QcmdG1SUYkOSNWVKQaGewj8whW0fjGsKQHxKwZ99d5hqTOPqpiAFQzEiCGPBojyjQFv53JX 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: List-Subscribe: List-Unsubscribe: 在 2024/3/1 1:32, Linus Torvalds 写道: > On Thu, 29 Feb 2024 at 00:13, Tong Tiangen wrote: >> >> See the logic before this patch, always success (((void)(K),0)) is >> returned for three types: ITER_BVEC, ITER_KVEC and ITER_XARRAY. > > No, look closer. > > Yes, the iterate_and_advance() macro does that "((void)(K),0)" to make > the compiler generate better code for those cases (because then the > compiler can see that the return value is a compile-time zero), but > notice how _copy_mc_to_iter() didn't use that macro back then. It used > the unvarnished __iterate_and_advance() exactly so that the MC copy > case would *not* get that "always return zero" behavior. > > That goes back to (in a different form) at least commit 1b4fb5ffd79b > ("iov_iter: teach iterate_{bvec,xarray}() about possible short > copies"). > > But hardly anybody ever tests this machine-check special case code, so > who knows when it broke again. > > I'm just looking at the source code, and with all the macro games it's > *really* hard to follow, so I may well be missing something. > >> Maybe we're all gonna fix it back? as follows: > > No. We could do it for the kvec and xarray case, just to get better > code generation again (not that I looked at it, so who knows), but the > one case that actually uses memcpy_from_iter_mc() needs to react to a > short write. > > One option might be to make a failed memcpy_from_iter_mc() set another > flag in the iter, and then make fault_in_iov_iter_readable() test that > flag and return 'len' if that flag is set. > > Something like that (wild handwaving) should get the right error handling. > > The simpler alternative is maybe something like the attached. > COMPLETELY UNTESTED. Maybe I've confused myself with all the different > indiraction mazes in the iov_iter code. > > Linus Hi Linus: The method in the attachment i have tested before is feasible and can solve this deadloop problem. I also have some confusion about the iov_iter code. Let's take a look at manitainer's comments to see whether there are more comprehensive considerations. Thanks, Tong.