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=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 D8E0AC433B4 for ; Mon, 26 Apr 2021 19:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A02006115B for ; Mon, 26 Apr 2021 19:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239904AbhDZTDd (ORCPT ); Mon, 26 Apr 2021 15:03:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45742 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236542AbhDZTDc (ORCPT ); Mon, 26 Apr 2021 15:03:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619463770; h=from:from: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=ouGZBrLLWit6/ZcOCgBmqDAJzjKl2dpVcZkTyeLSBYo=; b=UaKPBLGlulw8usBvnFSBcsomiGesJhBqB0JotOgbxmK35yirHGi4WdOO4osqTshVVIrpM5 Iwv6qs5AulTLVy5p8T+9R1EAUJ8VJT7HAE1vvt1eOBT89aIWzvrCRpu+8WSYf32LySFxzq D7HUBlPvtP7VrOqInkyAAsFg35Gxc3g= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-OiKe6vZZM6KZhLbcrCi4Kw-1; Mon, 26 Apr 2021 15:02:48 -0400 X-MC-Unique: OiKe6vZZM6KZhLbcrCi4Kw-1 Received: by mail-qt1-f198.google.com with SMTP id d10-20020a05622a100ab02901b8224bae03so16591925qte.2 for ; Mon, 26 Apr 2021 12:02:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=ouGZBrLLWit6/ZcOCgBmqDAJzjKl2dpVcZkTyeLSBYo=; b=jLY4HUO8W4EgergfOsHBnvPd64VvPgQg7vv7XOmBJe5YrrQpdiVLWzx64ln74T+iAu L6/uC892YtRL24O3tnCC4PGhPn5GrMRpbyWC0Lt5NZJ8P+UJo0yQVeCYBaC2hkJV37/Y WRwaBxRAXGTFA45kaFUTerumLdrFU5omOJxD0X9Lo2W6WFzPrydxwxTqiqbuNxkZNtsS jgPsRaeY3zNXOyQg4qki06cQ53AiCQKeDiirWuUClAAG9Ct1W+TfBxfDeBhfo9rpb4sS gaNK02lKOtDk8+IpRpxcz24jURxMChrTksW8NdzgJo2g8o12L5zq2dwpSBXKpmnLERE/ gdLg== X-Gm-Message-State: AOAM531i3CH1uVWfobPAz1YYkEWfI/NRORZLsyCsiXgdTN8MYWegvfB+ Fmy19s3MdgtnspIsMIywKreUVI4hedmr3aYTah6m5Au+9pnSm8R5P+RZZ6OVO+KOwcTjZnBVtL0 Yor5uL5b+/TH2bAGhgWZ6+w== X-Received: by 2002:a05:6214:12ab:: with SMTP id w11mr2594688qvu.14.1619463768342; Mon, 26 Apr 2021 12:02:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGCsMCqX/N3XGxXqCeA/FOnTSmKwq96TpGbwn+GxMf4WVXk/guJWr0j2oTl477h4kubLqiGw== X-Received: by 2002:a05:6214:12ab:: with SMTP id w11mr2594656qvu.14.1619463768135; Mon, 26 Apr 2021 12:02:48 -0700 (PDT) Received: from [192.168.1.180] (68-20-15-154.lightspeed.rlghnc.sbcglobal.net. [68.20.15.154]) by smtp.gmail.com with ESMTPSA id c17sm11477744qtd.71.2021.04.26.12.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 12:02:47 -0700 (PDT) Message-ID: <9e5744b2b647a8ff9cdea6efb58c39adde48f7f0.camel@redhat.com> Subject: Re: [PATCH] iov_iter: Four fixes for ITER_XARRAY From: Jeff Layton To: David Howells , Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Dave Wysochanski , Marc Dionne , "Matthew Wilcox (Oracle)" , Christoph Hellwig , linux-mm@kvack.org, linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs-developer@lists.sourceforge.net, Trond Myklebust , Anna Schumaker , Steve French , Dominique Martinet , linux-kernel@vger.kernel.org Date: Mon, 26 Apr 2021 15:02:46 -0400 In-Reply-To: <3545034.1619392490@warthog.procyon.org.uk> References: <161918448151.3145707.11541538916600921083.stgit@warthog.procyon.org.uk> <161918446704.3145707.14418606303992174310.stgit@warthog.procyon.org.uk> <3545034.1619392490@warthog.procyon.org.uk> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.0 (3.40.0-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org On Mon, 2021-04-26 at 00:14 +0100, David Howells wrote: > Hi Al, > > I think this patch should include all the fixes necessary. I could merge > it in, but I think it might be better to tag it on the end as an additional > patch. > > David > --- > iov_iter: Four fixes for ITER_XARRAY > > Fix four things[1] in the patch that adds ITER_XARRAY[2]: > >  (1) Remove the address_space struct predeclaration. This is a holdover >      from when it was ITER_MAPPING. > >  (2) Fix _copy_mc_to_iter() so that the xarray segment updates count and >      iov_offset in the iterator before returning. > >  (3) Fix iov_iter_alignment() to not loop in the xarray case. Because the >      middle pages are all whole pages, only the end pages need be >      considered - and this can be reduced to just looking at the start >      position in the xarray and the iteration size. > >  (4) Fix iov_iter_advance() to limit the size of the advance to no more >      than the remaining iteration size. > > Reported-by: Al Viro > Signed-off-by: David Howells > Link: https://lore.kernel.org/r/YIVrJT8GwLI0Wlgx@zeniv-ca.linux.org.uk [1] > Link: https://lore.kernel.org/r/161918448151.3145707.11541538916600921083.stgit@warthog.procyon.org.uk [2] > --- >  include/linux/uio.h | 1 - >  lib/iov_iter.c | 5 +++++ >  2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/include/linux/uio.h b/include/linux/uio.h > index 5f5ffc45d4aa..d3ec87706d75 100644 > --- a/include/linux/uio.h > +++ b/include/linux/uio.h > @@ -10,7 +10,6 @@ >  #include >   > > > >  struct page; > -struct address_space; >  struct pipe_inode_info; >   > > > >  struct kvec { > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 44fa726a8323..61228a6c69f8 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -791,6 +791,8 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i) >   curr_addr = (unsigned long) from; >   bytes = curr_addr - s_addr - rem; >   rcu_read_unlock(); > + i->iov_offset += bytes; > + i->count -= bytes; >   return bytes; >   } >   }) > @@ -1147,6 +1149,7 @@ void iov_iter_advance(struct iov_iter *i, size_t size) >   return; >   } >   if (unlikely(iov_iter_is_xarray(i))) { > + size = min(size, i->count); >   i->iov_offset += size; >   i->count -= size; >   return; > @@ -1346,6 +1349,8 @@ unsigned long iov_iter_alignment(const struct iov_iter *i) >   return size | i->iov_offset; >   return size; >   } > + if (unlikely(iov_iter_is_xarray(i))) > + return (i->xarray_start + i->iov_offset) | i->count; >   iterate_all_kinds(i, size, v, >   (res |= (unsigned long)v.iov_base | v.iov_len, 0), >   res |= v.bv_offset | v.bv_len, > I did a test run with your v7 pile, this patch, and my ceph fscache rework patches and it did fine. You can add: Tested-by: Jeff Layton 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 7AF25C43460 for ; Mon, 26 Apr 2021 19:02:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E1E9761166 for ; Mon, 26 Apr 2021 19:02:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E1E9761166 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2FAA16B0036; Mon, 26 Apr 2021 15:02:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AA896B006E; Mon, 26 Apr 2021 15:02:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 125AD6B0070; Mon, 26 Apr 2021 15:02:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id E58346B0036 for ; Mon, 26 Apr 2021 15:02:51 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9491A180AD81D for ; Mon, 26 Apr 2021 19:02:51 +0000 (UTC) X-FDA: 78075440142.04.886ECEC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 2F59FF4 for ; Mon, 26 Apr 2021 19:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619463770; h=from:from: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=ouGZBrLLWit6/ZcOCgBmqDAJzjKl2dpVcZkTyeLSBYo=; b=UaKPBLGlulw8usBvnFSBcsomiGesJhBqB0JotOgbxmK35yirHGi4WdOO4osqTshVVIrpM5 Iwv6qs5AulTLVy5p8T+9R1EAUJ8VJT7HAE1vvt1eOBT89aIWzvrCRpu+8WSYf32LySFxzq D7HUBlPvtP7VrOqInkyAAsFg35Gxc3g= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-269-E72yz3deNdi71xKOyaawWg-1; Mon, 26 Apr 2021 15:02:48 -0400 X-MC-Unique: E72yz3deNdi71xKOyaawWg-1 Received: by mail-qk1-f198.google.com with SMTP id d185-20020ae9efc20000b02902e45ca32479so5121809qkg.21 for ; Mon, 26 Apr 2021 12:02:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=ouGZBrLLWit6/ZcOCgBmqDAJzjKl2dpVcZkTyeLSBYo=; b=uZyUeMu7e0HVMgoKJMnJ++5mwTvqErybvB90+6dD9k93jV4dSUT12cpAEZPuPv90qb M+2g7/PBgto7gleDTuwfeto5Kqs+pxwT1suzDs6Daf1xzeKz26e6iZrY1icfdMEMCanO aH0/KoQKHA47Wcp68iyvEqmK8hQymTqHoi1pL0Y02NzAanfO0J+qFdS+bg02kKdDGmej 6fSGe269z7OZGqCa3v8uGmQcG+7QnX79FmI0gfYTOkJ86SfslCGCyHQWuRmIWMRsNSX6 QguMLh1pAB4NjZc+F3cn0JsrZ6qIQgNTAf5rpsy9um6WXWzl4+FMU3+25JOJfOkNW3JN oP2A== X-Gm-Message-State: AOAM530pudvfrc/8SCkV8WqxoMFlGdP3SeXPv6z3VZ2X1UzPyZowlniL 8Sw8+R5M5HTUw084Pm1Go5jcb7BPOkLxxXJKfakQSZ1+HscYgS/1RezgmtJBdHwrbn5nwj9cgFf sAtAZNo+jCp8= X-Received: by 2002:a05:6214:12ab:: with SMTP id w11mr2594683qvu.14.1619463768330; Mon, 26 Apr 2021 12:02:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGCsMCqX/N3XGxXqCeA/FOnTSmKwq96TpGbwn+GxMf4WVXk/guJWr0j2oTl477h4kubLqiGw== X-Received: by 2002:a05:6214:12ab:: with SMTP id w11mr2594656qvu.14.1619463768135; Mon, 26 Apr 2021 12:02:48 -0700 (PDT) Received: from [192.168.1.180] (68-20-15-154.lightspeed.rlghnc.sbcglobal.net. [68.20.15.154]) by smtp.gmail.com with ESMTPSA id c17sm11477744qtd.71.2021.04.26.12.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 12:02:47 -0700 (PDT) Message-ID: <9e5744b2b647a8ff9cdea6efb58c39adde48f7f0.camel@redhat.com> Subject: Re: [PATCH] iov_iter: Four fixes for ITER_XARRAY From: Jeff Layton To: David Howells , Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Dave Wysochanski , Marc Dionne , "Matthew Wilcox (Oracle)" , Christoph Hellwig , linux-mm@kvack.org, linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs-developer@lists.sourceforge.net, Trond Myklebust , Anna Schumaker , Steve French , Dominique Martinet , linux-kernel@vger.kernel.org Date: Mon, 26 Apr 2021 15:02:46 -0400 In-Reply-To: <3545034.1619392490@warthog.procyon.org.uk> References: <161918448151.3145707.11541538916600921083.stgit@warthog.procyon.org.uk> <161918446704.3145707.14418606303992174310.stgit@warthog.procyon.org.uk> <3545034.1619392490@warthog.procyon.org.uk> User-Agent: Evolution 3.40.0 (3.40.0-1.fc34) MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jlayton@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2F59FF4 X-Stat-Signature: u1s74daxac34um6rcf4eemejwmaydxdy Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619463762-64155 Content-Transfer-Encoding: quoted-printable 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 Mon, 2021-04-26 at 00:14 +0100, David Howells wrote: > Hi Al, >=20 > I think this patch should include all the fixes necessary. I could mer= ge > it in, but I think it might be better to tag it on the end as an additi= onal > patch. >=20 > David > --- > iov_iter: Four fixes for ITER_XARRAY >=20 > Fix four things[1] in the patch that adds ITER_XARRAY[2]: >=20 > =C2=A0(1) Remove the address_space struct predeclaration. This is a ho= ldover > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0from when it was ITER_MAPPING. >=20 > =C2=A0(2) Fix _copy_mc_to_iter() so that the xarray segment updates cou= nt and > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0iov_offset in the iterator before returni= ng. >=20 > =C2=A0(3) Fix iov_iter_alignment() to not loop in the xarray case. Bec= ause the > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0middle pages are all whole pages, only th= e end pages need be > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0considered - and this can be reduced to j= ust looking at the start > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0position in the xarray and the iteration = size. >=20 > =C2=A0(4) Fix iov_iter_advance() to limit the size of the advance to no= more > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0than the remaining iteration size. >=20 > Reported-by: Al Viro > Signed-off-by: David Howells > Link: https://lore.kernel.org/r/YIVrJT8GwLI0Wlgx@zeniv-ca.linux.org.uk = [1] > Link: https://lore.kernel.org/r/161918448151.3145707.115415389166009210= 83.stgit@warthog.procyon.org.uk [2] > --- > =C2=A0include/linux/uio.h | 1 - > =C2=A0lib/iov_iter.c | 5 +++++ > =C2=A02 files changed, 5 insertions(+), 1 deletion(-) >=20 > diff --git a/include/linux/uio.h b/include/linux/uio.h > index 5f5ffc45d4aa..d3ec87706d75 100644 > --- a/include/linux/uio.h > +++ b/include/linux/uio.h > @@ -10,7 +10,6 @@ > =C2=A0#include > =C2=A0 >=20 >=20 >=20 > =C2=A0struct page; > -struct address_space; > =C2=A0struct pipe_inode_info; > =C2=A0 >=20 >=20 >=20 > =C2=A0struct kvec { > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 44fa726a8323..61228a6c69f8 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -791,6 +791,8 @@ size_t _copy_mc_to_iter(const void *addr, size_t by= tes, struct iov_iter *i) > =C2=A0 curr_addr =3D (unsigned long) from; > =C2=A0 bytes =3D curr_addr - s_addr - rem; > =C2=A0 rcu_read_unlock(); > + i->iov_offset +=3D bytes; > + i->count -=3D bytes; > =C2=A0 return bytes; > =C2=A0 } > =C2=A0 }) > @@ -1147,6 +1149,7 @@ void iov_iter_advance(struct iov_iter *i, size_t = size) > =C2=A0 return; > =C2=A0 } > =C2=A0 if (unlikely(iov_iter_is_xarray(i))) { > + size =3D min(size, i->count); > =C2=A0 i->iov_offset +=3D size; > =C2=A0 i->count -=3D size; > =C2=A0 return; > @@ -1346,6 +1349,8 @@ unsigned long iov_iter_alignment(const struct iov= _iter *i) > =C2=A0 return size | i->iov_offset; > =C2=A0 return size; > =C2=A0 } > + if (unlikely(iov_iter_is_xarray(i))) > + return (i->xarray_start + i->iov_offset) | i->count; > =C2=A0 iterate_all_kinds(i, size, v, > =C2=A0 (res |=3D (unsigned long)v.iov_base | v.iov_len, 0), > =C2=A0 res |=3D v.bv_offset | v.bv_len, >=20 I did a test run with your v7 pile, this patch, and my ceph fscache rework patches and it did fine. You can add: Tested-by: Jeff Layton