Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp166786ybh; Mon, 20 Jul 2020 13:15:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9J+4sJGRulnmI8DE7VJwJAw7vdAoVaCHISSTsrf0Gv48gGpDJufqD7k0DO/xYg28njn8O X-Received: by 2002:aa7:c504:: with SMTP id o4mr22577941edq.311.1595276100408; Mon, 20 Jul 2020 13:15:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595276100; cv=none; d=google.com; s=arc-20160816; b=jAB60ED+dl0FMQQcrOFQPE/WqMrM23Ja8kI2epqCCtLsqepnU1w6j5cAlMp65BVWg2 EMlIz8ydC72tTwPfjvxMVxOsYM2tosQt+EL5xOtdxazoDIHhYGcx33q8iEINjHsRnUpe WxOPHb06HNpycUcq6JdnVKL/uVgIPA/pH1tWnjBOFVcFBr2JVFOmGXr2LoWmgZfBJGPb tlyBMNcwtxjTzMy+ptLyuuA5paYnVWOOUqQliwKp+2jLVCRy+GOewBad9d7XBZPU297T 14Pp0CPIgpg83wpgFvi99fktTzUXY77cls5+lEcN8XZ1ucObFd0slqkUHffpMWHl1fwH YTbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=EsGMGhzKIpTaob8DadHHmrZfJzdmog+xLTQECJDRdFI=; b=EeF1tS5PJ4VMJjZH3Lln+w/Vx5zKCwkExQoKuqvAf25BJ6qv3WmQopWRxMs6/OrifM NRjbGtMzfCBfeY0GeBEDTBHp7gOV2SyiWGeAoGtErUWtxI+5ar2tVTnM3Mn9W2GGgLjP V7VjQ/iptOKH/+kuXE9Ts0r44aCjHltZIADbjgR/MtqgznP66QJkLHXSFlmd/b7YJBnN Gd1VRNdXrnqXvWwyiV1FaPwSPjWsCZhCg4P/0Ehl1x8LhX4Oem/I9u7euOWTPghBMMbj fjFWNLabTkGfwaTwH6cncWncTqjbdqpn5AnQk1DDv4Rm7/kkGy0j0K87TvxiQFfguTZA Xuzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PPMtmi5E; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ss22si11396696ejb.530.2020.07.20.13.14.29; Mon, 20 Jul 2020 13:15:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PPMtmi5E; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729897AbgGTUOG (ORCPT + 99 others); Mon, 20 Jul 2020 16:14:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:53894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727123AbgGTUOG (ORCPT ); Mon, 20 Jul 2020 16:14:06 -0400 Received: from gmail.com (unknown [104.132.1.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 680AD2080D; Mon, 20 Jul 2020 20:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595276045; bh=wDxijBprww99JyKZ7zq1b0Bm+gBJfpxa+gZiTN2MMac=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PPMtmi5EfngGRLVXC4qUYRQ1gdrrDIyuG8biGtRFAryZ0R9CC8s/0ZXIdD+Ovfbla JnQVA+559vhRMT7XehRKOYcnDREV63fo/E7ZW17Y80AOMn3OmELWauhiaC/+dIA1E8 5l8h0NDI2Cq1StzoLJGfBfBTNTRRaqlHa6Pc2oyE= Date: Mon, 20 Jul 2020 13:14:04 -0700 From: Eric Biggers To: Satya Tangirala Cc: linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Subject: Re: [PATCH v3 1/7] fscrypt: Add functions for direct I/O support Message-ID: <20200720201404.GJ1292162@gmail.com> References: <20200717014540.71515-1-satyat@google.com> <20200717014540.71515-2-satyat@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200717014540.71515-2-satyat@google.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, Jul 17, 2020 at 01:45:34AM +0000, Satya Tangirala wrote: > From: Eric Biggers > > Introduce fscrypt_dio_supported() to check whether a direct I/O request > is unsupported due to encryption constraints, and > fscrypt_limit_io_pages() to check how many pages may be added to a bio > being prepared for direct I/O. > > The IV_INO_LBLK_32 fscrypt policy introduced the possibility that DUNs > in logically continuous file blocks might wrap from 0xffffffff to 0. > Since this was particularly difficult to handle when block_size != > PAGE_SIZE, fscrypt only supports blk-crypto en/decryption with > the IV_INO_LBLK_32 policy when block_size == PAGE_SIZE, and ensures that > the DUN never wraps around within any submitted bio. > fscrypt_limit_io_pages() can be used to determine the number of logically > contiguous blocks/pages that may be added to the bio without causing the > DUN to wrap around within the bio. This is an alternative to calling > fscrypt_mergeable_bio() on each page in a range of logically contiguous > pages. This is a bit hard to read, especially the second paragraph. How about: "Introduce fscrypt_dio_supported() to check whether a direct I/O request is unsupported due to encryption constraints. Also introduce fscrypt_limit_io_pages() to limit how many pages can be added to a bio being prepared for direct I/O. This is needed for the iomap direct I/O implementation to avoid DUN wraparound in the middle of a bio (which is possible with the IV_INO_LBLK_32 IV generation method). Elsewhere fscrypt_mergeable_bio() is used for this, but iomap operates on logical ranges directly and thus needs doesn't have a chance to call fscrypt_mergeable_bio() on every block or page. So we need a function which limits a logical range in one go." In particular, the detail about PAGE_SIZE better belongs in the code, I think. > +/** > + * fscrypt_limit_io_pages() - limit I/O pages to avoid discontiguous DUNs > + * @inode: the file on which I/O is being done > + * @pos: the file position (in bytes) at which the I/O is being done > + * @nr_pages: the number of pages we want to submit starting at @pos > + * > + * Determine the limit to the number of pages that can be submitted in the bio > + * targeting @pos without causing a data unit number (DUN) discontinuity. > + * > + * For IV generation methods that can't cause DUN wraparounds > + * within logically continuous data blocks, the maximum number of pages is > + * simply @nr_pages. For those IV generation methods that *might* cause DUN > + * wraparounds, the returned number of pages is the largest possible number of > + * pages (less than @nr_pages) that can be added to the bio without causing a > + * DUN wraparound within the bio. How about replacing the second paragraph here with: * This is normally just @nr_pages, as normally the DUNs just increment along * with the logical blocks. (Or the file is not encrypted.) * * In rare cases, fscrypt can be using an IV generation method that allows the * DUN to wrap around within logically continuous blocks, and that wraparound * will occur. If this happens, a value less than @nr_pages will be returned so * that the wraparound doesn't occur in the middle of the bio. Note that we * only support block_size == PAGE_SIZE (and page-aligned DIO) in such cases.