Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp21651lqg; Thu, 29 Feb 2024 18:13:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2ELV0AgLlg0trxzsk71YSRL7+kf/SP3GUcvIgIm6Hs+v+Evqq7JQLFJ/lRQzZUljsKbmxTIcRl4lNygAGKQq2HPgiU88AHMHoP3SV0w== X-Google-Smtp-Source: AGHT+IEwTcm2Ko0IyPT3sKz61zNM2WPI23w/vHZBhrKkHrAKzkMjkmar9MuCI4rgILwSBPI+VXXg X-Received: by 2002:a17:906:3c10:b0:a43:c0f7:d2cd with SMTP id h16-20020a1709063c1000b00a43c0f7d2cdmr244322ejg.3.1709259235845; Thu, 29 Feb 2024 18:13:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709259235; cv=pass; d=google.com; s=arc-20160816; b=wGI4PXnwq81db7S8glc2srBPXBiG6c9xEzjSRMAr2G/0pCzVKpkA98qWPwj7aA1Jyb h/saRAnCtjSDvhCh2MQpY/uRegcFcOAI1DpsQnnVuuPvKx7O8CHcDc0mj9B/LvMtQJLh DNP/t8KCH1HXynr52Busq4rKgAn+J7u9wdglzf6GbS+pPuNwIFD9lxjIEIWJBVJbddTH fqcCY9XaFOxFK4cdaQ4wgS7ACyjULREjn4e4X5O+vYr7Blj1U9NU/l9OcOOc2TjYbFpG SxQU5nDBq/lZeWazGIU/4fhTbLeagerzA3q2xmH86mR2CZQbT2wG7/WiCund5nqXEueB /2fA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=Ty1NOJAFiEncUFxGQ4KJJf9eh5Z1rU5rO5YoxRVqMwY=; fh=OvHfpCuCg9nEJ0PcxEkrJ2cAnfV9QbcLL6h0mDN/CjA=; b=DlqKI1nIRHKfbOWVnjcPp2CdXxpV+64kprNPr20x8/0dXyv3vJANR2r9wbth0Mz3+X bTLY6H0CEJmjZVjd1/Q51t707n8bOKJCRyGSjZMFAgcUz6eLR0j7RMw8IJTUYxySxvPj zrl2yQfl7G+vz2iLc0gGKSvUfkSWfMOoRhBInN/KiiX2TG2o7TX5+NeYZipZDu7IzM4J +sNmS+QiyPPfqp5PteOejT0dl/k2hk+MkWDRPoWJcNgIt911OMIElO0SUpEYB/Lb52Im lc/tZ7S9UYUPf0x/3sNgSoWRbyn3m+3ZL80pjUKgqEJJwRRJT3fWN0H2w71hu47//bSc DNKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-87820-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87820-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h11-20020a1709062dcb00b00a445904368esi716848eji.986.2024.02.29.18.13.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 18:13:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87820-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-87820-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87820-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 930701F224AF for ; Fri, 1 Mar 2024 02:13:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCA2E3A8D6; Fri, 1 Mar 2024 02:13:41 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D903B2AF0D; Fri, 1 Mar 2024 02:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709259221; cv=none; b=q+y9ccWTEWCyQtdx80k8ss7310sKU3NVfw1mLfrRou0LQcVCHBRELwGh3hkqmF95sbhJilJzwreHpBX7F7UmX5uvl2lxksJpuiu2uOJ0DtwRULDifIVifuPKr2TawwIxLCuNld1l9SpZnHXh5rrySqmmx4/eETLflgEQl6KqpiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709259221; c=relaxed/simple; bh=NPD/17SvfvonoQ1qrXhKNqN7Pwo5QKQggEW33QEBWeY=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=qfD0dyWxVn+SPVk1ebxteC5GsrBUqwysHXMd3MbH7JtV27pGD7vOfgnbfcVJbknQb3aZQIe2v2/9yebX/GJxLYKpZIYhVcJu4mcFInp8eyOBjPxbeO3mYXmS744bksf/iHp0yJDEMlEzImmECECN/PhmCkI7oKJCXiTLf15qZjA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600017.china.huawei.com (7.193.23.234) 在 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.