Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1632487ybh; Thu, 16 Jul 2020 18:36:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAh9XzTIw+xPFebVUAFSys0GFMXDVpm/RLNnZ99EGbScZ6LmT4O9VMyDo4GEBuHvHBj+BR X-Received: by 2002:a05:6402:1777:: with SMTP id da23mr6917054edb.260.1594949766627; Thu, 16 Jul 2020 18:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594949766; cv=none; d=google.com; s=arc-20160816; b=Otlp2R0Ll1ZykDIaGSkWNAUF2BeEyFMg2g9L9YXPj5ucTOh5vVXyVu7yKLvVA987NN 20/lL+Vuvfgvv7TIWmzi1AsWqz+FX9KNy24iXnUoTYTnPwGB+ZS7PDI8WKmh/Cxqml00 BNGiMGdfLCpTlZVnaY2ido06SXuH1f6oE6XXjDsJ56P2tslD9xda5gEoG9/FpdN2rHq3 DWcT2SlpgZMvMp3dS12wIWKmPsrk9wyZXzcS85gogmddG45aGvgrvM3gwZI3AWC7DHTk bZtDaheVTPCM+E7HME4FWVaaLaJlhC05fCz5caz+PqjhbEbneq1rprjlwAe28iUVAKJq aMeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=zp9IyNE/WOqMjmmUo5OQb7An9Jck4EABFW2ZtXIp0J8=; b=JlWs+MAxNJyMdkdOB1w7p3lOIeHkoyUKUt/Ca/91t8mEILQYXjp9qWOdRPfIDvbWhW 6uLJEvAaZe1XRd9mnhaA3uARqGkjXWhX0oj+fIu/du2goctKWZ13VRKUHh5U6ktUG1oi 98hPcm+UNXMwRlutifoAz96iWjovUhYalOHRuQaEzD6VAOUP0+cscDXPSmkyDQs00bQz FBy9m1wIf2bGL51G2H2jQMlF5/seGO1nZbXVxbyrljWdb1lLzMfYVARlwoqpTjDGoSdA H58OncMrqSdXbHOo8h8n+/yK1qjTTH/qKujmLpKwZzIspRhX6MuFzmrNeXzv0+bzU8YB 2GCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EcPT5iw6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f13si4346118edy.576.2020.07.16.18.35.40; Thu, 16 Jul 2020 18:36:06 -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=@google.com header.s=20161025 header.b=EcPT5iw6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726905AbgGQBfc (ORCPT + 99 others); Thu, 16 Jul 2020 21:35:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726858AbgGQBfa (ORCPT ); Thu, 16 Jul 2020 21:35:30 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5264C061755 for ; Thu, 16 Jul 2020 18:35:29 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 124so9689649ybb.5 for ; Thu, 16 Jul 2020 18:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=zp9IyNE/WOqMjmmUo5OQb7An9Jck4EABFW2ZtXIp0J8=; b=EcPT5iw6xeAfEjdlPbda6DoINJs/j9jKP2TGre8RBeZXNcyIRuqos8GS/JPjNxyyMj aARz+rkyGL52RWpzFM5BJ3zkR/4wfsdnrw+1luAFREm/VEQT+l2s5cpIKsr+5uKeFMH4 WY51ds7oCW7o+7bxVZeVdvBRNakPa9eZZmcbTSZ4YdYGuLV6Q/SugNCpoAJkT93/jfJb IGJddYgCOXxJUJ+GqNK5dO62cUYyve5r5yM+KtVqyAb2Zs2BUOSmw7Fs3p41vxvgdu5b 24MANUxf9LZQryIjThNYfZtFGr6rsTY31QgdC5WUa3iwxTm6vikksUZPQJEA49/6nHBM jWDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zp9IyNE/WOqMjmmUo5OQb7An9Jck4EABFW2ZtXIp0J8=; b=uW9kPrsSlmfOuVZtVtFmDx/zKwv/IWiUsy2OhlI/wpCFycucBBPzGn2dhqV0VRFBb5 HSLYoN6MFXiL2wx4Kfqhxm2QRQMvZSSA2FkXa7gor/1wJ3tKKtzhso26txJQ3boxC2KF WT3916TFjXV4I2FGDeTa02RkAcx655id5CUQlX6ouTf/SxoX8jtf1+mtdK439WLeHak7 xefU9aIwQMjOEdv3s/b7HWRaCChsWyccNpKZrLvaZmStHWuuR8K2r4ttN1lIg/WuaMVX EjAjFq8XWyfSovNeZCcqjwEYPWDc1A4MnU5FmQaGrBx28478fEvSx2TlMjsYUld3FT1u +bXw== X-Gm-Message-State: AOAM530wy4XQTqs9fnXMdE8ocOJ1D/w6hjHCRIZZcy3xw6SmIjbn1OPE 0f/91f4naEb8XCyVPgRKJaw/CdYZXco= X-Received: by 2002:a25:e481:: with SMTP id b123mr9697382ybh.126.1594949728932; Thu, 16 Jul 2020 18:35:28 -0700 (PDT) Date: Fri, 17 Jul 2020 01:35:13 +0000 In-Reply-To: <20200717013518.59219-1-satyat@google.com> Message-Id: <20200717013518.59219-3-satyat@google.com> Mime-Version: 1.0 References: <20200717013518.59219-1-satyat@google.com> X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH v2 2/7] direct-io: add support for fscrypt using blk-crypto From: Satya Tangirala To: linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Eric Biggers , Satya Tangirala Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Set bio crypt contexts on bios by calling into fscrypt when required, and explicitly check for DUN continuity when adding pages to the bio. (While DUN continuity is usually implied by logical block contiguity, this is not the case when using certain fscrypt IV generation methods like IV_INO_LBLK_32). Signed-off-by: Eric Biggers Co-developed-by: Satya Tangirala Signed-off-by: Satya Tangirala --- fs/direct-io.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index 6d5370eac2a8..f27f7e3780ee 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -411,6 +412,7 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, sector_t first_sector, int nr_vecs) { struct bio *bio; + struct inode *inode = dio->inode; /* * bio_alloc() is guaranteed to return a bio when allowed to sleep and @@ -418,6 +420,9 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, */ bio = bio_alloc(GFP_KERNEL, nr_vecs); + fscrypt_set_bio_crypt_ctx(bio, inode, + sdio->cur_page_fs_offset >> inode->i_blkbits, + GFP_KERNEL); bio_set_dev(bio, bdev); bio->bi_iter.bi_sector = first_sector; bio_set_op_attrs(bio, dio->op, dio->op_flags); @@ -782,9 +787,17 @@ static inline int dio_send_cur_page(struct dio *dio, struct dio_submit *sdio, * current logical offset in the file does not equal what would * be the next logical offset in the bio, submit the bio we * have. + * + * When fscrypt inline encryption is used, data unit number + * (DUN) contiguity is also required. Normally that's implied + * by logical contiguity. However, certain IV generation + * methods (e.g. IV_INO_LBLK_32) don't guarantee it. So, we + * must explicitly check fscrypt_mergeable_bio() too. */ if (sdio->final_block_in_bio != sdio->cur_page_block || - cur_offset != bio_next_offset) + cur_offset != bio_next_offset || + !fscrypt_mergeable_bio(sdio->bio, dio->inode, + cur_offset >> dio->inode->i_blkbits)) dio_bio_submit(dio, sdio); } -- 2.28.0.rc0.105.gf9edc3c819-goog