From patchwork Wed Jun 14 23:40:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Halcrow X-Patchwork-Id: 9787627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7040460325 for ; Wed, 14 Jun 2017 23:40:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 635131FF4A for ; Wed, 14 Jun 2017 23:40:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57C3028528; Wed, 14 Jun 2017 23:40:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E62041FF4A for ; Wed, 14 Jun 2017 23:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752832AbdFNXk5 (ORCPT ); Wed, 14 Jun 2017 19:40:57 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:35533 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752808AbdFNXky (ORCPT ); Wed, 14 Jun 2017 19:40:54 -0400 Received: by mail-pg0-f45.google.com with SMTP id k71so6722665pgd.2 for ; Wed, 14 Jun 2017 16:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=xpz/sP5JkqlgYXRMBaFRX95MxkY1B4jwDH8w+En6Ft0=; b=kcDbwNkabJGJQ3ociD5llCWio1DjR0ba2OHaB5donvwIdrXYhqJDoHaTpDlMSLTGF/ jOu5oqW0kO4waSQh0UUk9qiP31aDvc3Ov3N42VssLsE8089ksKLuwnFisQsopsvn+fPM 3mVOibAaCNR9gvnDn8n+PSBf673ZY+g4SjJmaXoSWAJZ7orJisgULS3ZfDmOyzoUWuEP BSVfPrOtNK0Ifc4VRA4AHQqJUqETjS3JMxEDeWRLDqEgbhQE61U7T/KESWHWkwp81Ith DqK1kqBezUOZKi8XlaF5h0ZDdYsmi+70CDFjaPpOwR8ifYroCfeAhSZFv7zxXy4xtADi yygA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=xpz/sP5JkqlgYXRMBaFRX95MxkY1B4jwDH8w+En6Ft0=; b=qCY2cTNM8rcKwR8a/AekdMcaYgvjMH9N4JU3acC3oiF9+DH1PHKUPAof6QyTxciqH1 YnUsjr6tjQhdKBeP7zr6CgJ4aDf2GVzT4sYQaPqJjUkOqxP2ga4g2ofTkXdoFM3CSNNx 8c458KmpyYxmV+VhAJWItzaZeaty18bPn8iqs5X3xOlBiOGdyIB6EXqmSJpTkWbqZLrC QyyiBufbZZY3rFqdZ5FMgN4I1+0yvDOtEDgympqHNuMH79/HhXc6VHpg3AKcVp+t3LnA Zgw7U16Ja/uAhNDn0nWRhRQ1VLvLWavFtNQjiaLRWEfA+0oj4u5bm7hAd7EScxZaSsHz 9Ocg== X-Gm-Message-State: AKS2vOxU2OWut2Q2uUWlljj6ZmeCw6KhvPMHa0Ts26tAVfDbgE9EbAim 8BeOkXdS40sR6CyS X-Received: by 10.84.208.102 with SMTP id f35mr2761631plh.92.1497483653321; Wed, 14 Jun 2017 16:40:53 -0700 (PDT) Received: from mhalcrow-linux.kir.corp.google.com ([100.66.175.61]) by smtp.gmail.com with ESMTPSA id z66sm2141286pfl.13.2017.06.14.16.40.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 16:40:52 -0700 (PDT) From: Michael Halcrow To: Michael Halcrow , "Theodore Y . Ts'o" , Eric Biggers , Jaegeuk Kim , linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, linux-ext4@vger.kernel.org, Tyler Hicks Subject: [RFC PATCH 2/4] dm-crypt: Skip encryption of file system-encrypted blocks Date: Wed, 14 Jun 2017 16:40:38 -0700 Message-Id: <20170614234040.4326-3-mhalcrow@google.com> X-Mailer: git-send-email 2.13.1.518.g3df882009-goog In-Reply-To: <20170614234040.4326-1-mhalcrow@google.com> References: <20170614234040.4326-1-mhalcrow@google.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP File systems can encrypt some of their data blocks with their own encryption keys, and for those blocks another round of encryption at the dm-crypt layer may be redundant, depending on the keys being used. This patch enables dm-crypt to observe the REQ_NOENCRYPT flag as an indicator that a bio request should bypass the dm-crypt encryption queue. By default dm-crypt will ignore this request flag from the file system. The user must set the allow_encrypt_override option to enable this functionality. Once the dm-crypt has been used with the allow_encrypt_override option for any given block device, it must continue to be used with the option to avoid the possibility of data corruption. Signed-off-by: Michael Halcrow --- drivers/md/dm-crypt.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index ebf9e72d479b..14ca8a6de3d9 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -125,7 +125,8 @@ struct iv_tcw_private { * and encrypts / decrypts at the same time. */ enum flags { DM_CRYPT_SUSPENDED, DM_CRYPT_KEY_VALID, - DM_CRYPT_SAME_CPU, DM_CRYPT_NO_OFFLOAD }; + DM_CRYPT_SAME_CPU, DM_CRYPT_NO_OFFLOAD, + DM_CRYPT_ENCRYPT_OVERRIDE }; enum cipher_flags { CRYPT_MODE_INTEGRITY_AEAD, /* Use authenticated mode for cihper */ @@ -2572,6 +2573,8 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar cc->sector_shift = __ffs(cc->sector_size) - SECTOR_SHIFT; } else if (!strcasecmp(opt_string, "iv_large_sectors")) set_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); + else if (!strcasecmp(opt_string, "allow_encrypt_override")) + set_bit(DM_CRYPT_ENCRYPT_OVERRIDE, &cc->flags); else { ti->error = "Invalid feature arguments"; return -EINVAL; @@ -2770,12 +2773,15 @@ static int crypt_map(struct dm_target *ti, struct bio *bio) struct crypt_config *cc = ti->private; /* - * If bio is REQ_PREFLUSH or REQ_OP_DISCARD, just bypass crypt queues. + * If bio is REQ_PREFLUSH, REQ_NOENCRYPT, or REQ_OP_DISCARD, + * just bypass crypt queues. * - for REQ_PREFLUSH device-mapper core ensures that no IO is in-flight * - for REQ_OP_DISCARD caller must use flush if IO ordering matters */ - if (unlikely(bio->bi_opf & REQ_PREFLUSH || - bio_op(bio) == REQ_OP_DISCARD)) { + if (unlikely(bio->bi_opf & REQ_PREFLUSH) || + (unlikely(bio->bi_opf & REQ_NOENCRYPT) && + test_bit(DM_CRYPT_ENCRYPT_OVERRIDE, &cc->flags)) || + bio_op(bio) == REQ_OP_DISCARD) { bio->bi_bdev = cc->dev->bdev; if (bio_sectors(bio)) bio->bi_iter.bi_sector = cc->start + @@ -2862,6 +2868,7 @@ static void crypt_status(struct dm_target *ti, status_type_t type, num_feature_args += test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags); num_feature_args += cc->sector_size != (1 << SECTOR_SHIFT); num_feature_args += test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); + num_feature_args += test_bit(DM_CRYPT_ENCRYPT_OVERRIDE, &cc->flags); if (cc->on_disk_tag_size) num_feature_args++; if (num_feature_args) { @@ -2878,6 +2885,8 @@ static void crypt_status(struct dm_target *ti, status_type_t type, DMEMIT(" sector_size:%d", cc->sector_size); if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags)) DMEMIT(" iv_large_sectors"); + if (test_bit(DM_CRYPT_ENCRYPT_OVERRIDE, &cc->flags)) + DMEMIT(" allow_encrypt_override"); } break;