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=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 AE81DC433E8 for ; Wed, 22 Jul 2020 09:27:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B19520729 for ; Wed, 22 Jul 2020 09:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731448AbgGVJ1j convert rfc822-to-8bit (ORCPT ); Wed, 22 Jul 2020 05:27:39 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:44912 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731338AbgGVJ1h (ORCPT ); Wed, 22 Jul 2020 05:27:37 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-127-Z0VvaxF8OUCPOnK0zoEJlw-1; Wed, 22 Jul 2020 10:27:33 +0100 X-MC-Unique: Z0VvaxF8OUCPOnK0zoEJlw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 22 Jul 2020 10:27:32 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Wed, 22 Jul 2020 10:27:32 +0100 From: David Laight To: 'Al Viro' , Linus Torvalds CC: "linux-kernel@vger.kernel.org" , "linux-arch@vger.kernel.org" Subject: RE: [PATCH 04/18] csum_and_copy_..._user(): pass 0xffffffff instead of 0 as initial sum Thread-Topic: [PATCH 04/18] csum_and_copy_..._user(): pass 0xffffffff instead of 0 as initial sum Thread-Index: AQHWX51MlcPCEWebQUuN/OB/armWnKkTU0Fg Date: Wed, 22 Jul 2020 09:27:32 +0000 Message-ID: <2d85ebb8ea2248c8a14f038a0c60297e@AcuMS.aculab.com> References: <20200721202425.GA2786714@ZenIV.linux.org.uk> <20200721202549.4150745-1-viro@ZenIV.linux.org.uk> <20200721202549.4150745-4-viro@ZenIV.linux.org.uk> In-Reply-To: <20200721202549.4150745-4-viro@ZenIV.linux.org.uk> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro > Sent: 21 July 2020 21:26 > Preparation for the change of calling conventions; right now all > callers pass 0 as initial sum. Passing 0xffffffff instead yields > the values comparable mod 0xffff and guarantees that 0 will not > be returned on success. > > Signed-off-by: Al Viro > --- > lib/iov_iter.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 7405922caaec..d5b7e204fea6 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -1451,7 +1451,7 @@ size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, > int err = 0; > next = csum_and_copy_from_user(v.iov_base, > (to += v.iov_len) - v.iov_len, > - v.iov_len, 0, &err); > + v.iov_len, ~0U, &err); > if (!err) { > sum = csum_block_add(sum, next, off); > off += v.iov_len; Can't you remove the csum_block_add() by passing the old 'sum' in instead of the ~0U ? You'll need to keep track of whether the buffer fragment is odd/even aligned. After an odd length fragment a bswap32() or 8 bit rotate will fix things (and maybe one right at the end). David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)