Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1936804pxb; Mon, 13 Sep 2021 08:31:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcdbqgmpVOPDbN5xTEv+HyVyeeXCwOPaqPnzq90IjRapkBmF9TeG0dylZsCGDTwzoouPy9 X-Received: by 2002:a6b:e604:: with SMTP id g4mr9373938ioh.148.1631547078887; Mon, 13 Sep 2021 08:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631547078; cv=none; d=google.com; s=arc-20160816; b=XcXsYTybgVOrkZCumtusHCrX4rf0HJOHcOA8qnRPxAXuYLhV5G3Ob8B7LPIZotZOuY nQNdQUmOxz8t/v1H9hahwuLE//KU0XXOmyVuKNsTFbFetEmyBAkHgltZduFbxXH9tmlz qfbdlp6os3lELE4gldfqPwXmV/ikm7dDQOc/G4C0E4PrfsT2u4uwpNapkly0CUbIzCJo qazcauPOMnihHjTov9TVdnJxZxHmEqbGoXBNFzmd2pY28RrDBcPZFS9nf14gzTS1Vjd8 yqpJrpHdVXN2WOTzV/FmHZrfpHvB31xTv6x2ivhe6SucEoo8WOliUfbL10FPk3W/Si1z hc+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=32yWz64R7WLX7+LH8BeSfkrB8MowHvI48EMSFoQNUQM=; b=lMU8FkvWGqxwC/H0H6CnAcnMkhenJfXBbcHjxnQe/NKqyCu9s8r9fscavi2UmPxLY1 UpyZFLxqJM+IeO5Zw7hjur8x7lNnrDgldqXWVqcUNIGyvH/V+N1Bh4tHdUFw7AdswkQy tU2cHHobrf65AflrPefL3VEcQyO/735bfRks39l9AHHl6xipHpAo2XMnse3kQHs6vyqJ KtTsXMyiZiry926Rni1DeB15DHk1Vzrt71KUu300kZClFLlPSfDIbBpwpySzEYwTAZbK /SWLokZe5ugpeWfVXk/KyiM47htMgDX+VtPsqVSs/uaTOp1hT8o1BYG3xmN6zvepJXps skww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r199si1091871jac.71.2021.09.13.08.31.06; Mon, 13 Sep 2021 08:31:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343714AbhIMPbI convert rfc822-to-8bit (ORCPT + 99 others); Mon, 13 Sep 2021 11:31:08 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:25284 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245001AbhIMPap (ORCPT ); Mon, 13 Sep 2021 11:30:45 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-59-s7kT8NiFNp-vigLzY9tt5Q-1; Mon, 13 Sep 2021 16:29:28 +0100 X-MC-Unique: s7kT8NiFNp-vigLzY9tt5Q-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 13 Sep 2021 16:29:25 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.023; Mon, 13 Sep 2021 16:29:25 +0100 From: David Laight To: 'Al Viro' , Jens Axboe CC: Linus Torvalds , Pavel Begunkov , Linux Kernel Mailing List , linux-fsdevel Subject: RE: [git pull] iov_iter fixes Thread-Topic: [git pull] iov_iter fixes Thread-Index: AQHXpe6WnyOXE2m/lE6WyXaZJtHW8KuiGVDA Date: Mon, 13 Sep 2021 15:29:25 +0000 Message-ID: References: <5971af96-78b7-8304-3e25-00dc2da3c538@kernel.dk> <88f83037-0842-faba-b68f-1d4574fb45cb@kernel.dk> In-Reply-To: Accept-Language: en-GB, 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro > Sent: 10 September 2021 03:48 > > On Thu, Sep 09, 2021 at 07:35:13PM -0600, Jens Axboe wrote: > > > Yep ok I follow you now. And yes, if we get a partial one but one that > > has more consumed than what was returned, that would not work well. I'm > > guessing that a) we've never seen that, or b) we always end up with > > either correctly advanced OR fully advanced, and the fully advanced case > > would then just return 0 next time and we'd just get a short IO back to > > userspace. > > > > The safer way here would likely be to import the iovec again. We're > > still in the context of the original submission, and the sqe hasn't been > > consumed in the ring yet, so that can be done safely. > > ... until you end up with something assuming that you've got the same > iovec from userland the second time around. > > IOW, generally it's a bad idea to do that kind of re-imports. IIRC the canonical 'import' code is something like: struct iov iov[8], *cache = iov; struct iter; iov_iter_import(&iter, ... , &cache, 8); result = .... if (cache != iov) kfree(cache); return result; The iov[] and 'cache' are always allocated on stack with 'iter'. Now processing the 'iter' advances iter->iov. So to reset you need the start point - which is either 'cache' or 'iov[]'. The outer caller (typically) has this information. But the inner functions don't. Move both 'iov[]' and 'cache' into struct iter and they become available to all the code. It would also simplify the currently horrid boilerplate code that is replicated for every user. You might need a 'offset in current iter->iov[]' but nothing else. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)