From patchwork Fri Jun 4 19:58:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300659 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 9110FC4743E for ; Fri, 4 Jun 2021 20:00:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AEFC613EC for ; Fri, 4 Jun 2021 20:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231374AbhFDUCQ (ORCPT ); Fri, 4 Jun 2021 16:02:16 -0400 Received: from mail-yb1-f201.google.com ([209.85.219.201]:45736 "EHLO mail-yb1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbhFDUCL (ORCPT ); Fri, 4 Jun 2021 16:02:11 -0400 Received: by mail-yb1-f201.google.com with SMTP id d63-20020a254f420000b02904f91ef33453so13129179ybb.12 for ; Fri, 04 Jun 2021 13:00:11 -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=wt2qxnxy/b8IZ2QO+GAswkwuO0WmiwjICqpUWuqeT7k=; b=BfgL5Q+yv1Gzkf9o/f8X1rtUSSA6murv+6sH8j0ykCJia1piKw55urpOJDjgFIA3d/ w5f5IcTOuWS+JBGTk+bguWV5C12rMZXZtB0xm7lZDCQUJOpo3W/o3HhYzRCz+j3nd4Na 2MG4BJwFIlnlVeOPF1RTCXrVb+lxsdrYUGneWMEAB5qYNO9WJg90ztm3pH6jIb1q9pRB y8gfQ8jdWPSXMskZmMcnFpdu5RwSp207haB+zUlq0h3mhcegzHaqlHMHliNz9P6/0j9b nH0IJycwD2kbfSUwzBN/MhBwvwxPBtL6vmgkKmEvT4RMFHgdXsacye8S76Y6+Yqvmgn/ 14Ag== 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=wt2qxnxy/b8IZ2QO+GAswkwuO0WmiwjICqpUWuqeT7k=; b=DArE3e4DZPg2MDGxcrD/R5x6Ko8XyAqbPIeBn86OQ1neCqsVegZBiieSR03ro7PKg8 QAkjZR9JZZfFemUupdJFDzrJVY/h4WHoDZY9i7JOUoxJWVSfp5P5w8oDewGY58xey5CO sKJJIKJPaJmE5rm4TuJ5osbbFcIFIi/fSUqWnRvi+Boc5khPWL+u5C6+PSzia5LOG8yt Jc8wCKyW+plS/3VOrZmMt+AgSmDEbviHp9jyCafrcQHIBvWILz3yLVlz+SPYfCPwNnr3 qOT7hKqxpSjnoa7iyp4EZ+DlsPMCbgAC/dkUe4rUq99MqFpymTSDkHlsZX4UPmQu/nDS cybg== X-Gm-Message-State: AOAM530Kk6aH79SmiNIZmWx37jDRTpkFkPrYPJKViqidxdGABHRZW8UR LO7xEI++6HBfZSEvH58OhzZhQ8uhxs8l55kC58WLYI2cw7hkIoxpX0PPy7xg/J7Nd0y1f+I2Jji Mzm/DBRFw1togqM/z2hSZ8J023yqtx96eZQtPLDwww5OLP4jylj5IPC18BFs+UBlrxus4 X-Google-Smtp-Source: ABdhPJyLk0AvyZyFGRqqG2Cq3AZd0VBGrOlLaB7qb3b7G+q4lx5yzm3JQXDwZUkv/saaoV5YgDjx1rjc46E= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a05:6902:1343:: with SMTP id g3mr7100296ybu.283.1622836750940; Fri, 04 Jun 2021 12:59:10 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:51 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-2-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 01/10] block: introduce blk_ksm_is_empty() From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This function checks if a given keyslot manager supports any encryption mode/data unit size combination (and returns true if there is no such supported combination). Helps clean up code a little. Signed-off-by: Satya Tangirala Reviewed-by: Eric Biggers --- block/keyslot-manager.c | 21 +++++++++++++++++++++ drivers/md/dm-table.c | 11 +---------- include/linux/keyslot-manager.h | 2 ++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c index 2c4a55bea6ca..88211581141a 100644 --- a/block/keyslot-manager.c +++ b/block/keyslot-manager.c @@ -437,6 +437,27 @@ void blk_ksm_destroy(struct blk_keyslot_manager *ksm) } EXPORT_SYMBOL_GPL(blk_ksm_destroy); +/** + * blk_ksm_is_empty() - Checks if the keyslot manager has any crypto + * capabilities at all. + * @ksm: The input keyslot manager to check + * + * Return: true if @ksm doesn't have any crypto capabilities at all, and + * false otherwise. + */ +bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ksm->crypto_modes_supported); i++) { + if (ksm->crypto_modes_supported[i]) + return false; + } + + return true; +} +EXPORT_SYMBOL_GPL(blk_ksm_is_empty); + bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q) { if (blk_integrity_queue_supports_integrity(q)) { diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index ee47a332b462..29cbfc3e3c4b 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1295,7 +1295,6 @@ static int dm_table_construct_keyslot_manager(struct dm_table *t) struct blk_keyslot_manager *ksm; struct dm_target *ti; unsigned int i; - bool ksm_is_empty = true; dksm = kmalloc(sizeof(*dksm), GFP_KERNEL); if (!dksm) @@ -1332,15 +1331,7 @@ static int dm_table_construct_keyslot_manager(struct dm_table *t) * If the new KSM doesn't actually support any crypto modes, we may as * well represent it with a NULL ksm. */ - ksm_is_empty = true; - for (i = 0; i < ARRAY_SIZE(ksm->crypto_modes_supported); i++) { - if (ksm->crypto_modes_supported[i]) { - ksm_is_empty = false; - break; - } - } - - if (ksm_is_empty) { + if (blk_ksm_is_empty(ksm)) { dm_destroy_keyslot_manager(ksm); ksm = NULL; } diff --git a/include/linux/keyslot-manager.h b/include/linux/keyslot-manager.h index a27605e2f826..0f09b4f310f7 100644 --- a/include/linux/keyslot-manager.h +++ b/include/linux/keyslot-manager.h @@ -106,6 +106,8 @@ void blk_ksm_reprogram_all_keys(struct blk_keyslot_manager *ksm); void blk_ksm_destroy(struct blk_keyslot_manager *ksm); +bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm); + void blk_ksm_intersect_modes(struct blk_keyslot_manager *parent, const struct blk_keyslot_manager *child); From patchwork Fri Jun 4 19:58:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300645 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 41B98C4743E for ; Fri, 4 Jun 2021 19:59:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DFD8613F8 for ; Fri, 4 Jun 2021 19:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbhFDUBA (ORCPT ); Fri, 4 Jun 2021 16:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbhFDUBA (ORCPT ); Fri, 4 Jun 2021 16:01:00 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8727BC061767 for ; Fri, 4 Jun 2021 12:59:13 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 22-20020a250d160000b0290532b914c9f4so13154341ybn.9 for ; Fri, 04 Jun 2021 12:59:13 -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=08ngW/6ouUjDi/wpMdVaPAEKWapsl3xNTLfVKkU+m5Y=; b=JDRTNf9J3ToOzwgDWEPGtKVPxO+kW3G7lO/Ja39i6iJVtmjdTC6z7d4SG0Nk34X17w Uw6MyFloGKyph4f73tQ88uuoVLDriLqHxKZJFNgWvRoLVOe7pkFv0xbugv+Y54ulivvF oZ2LTT+KwbktGUmNj8H3DGivs/PFnvronFpDpFHPCKdD94HrBZB63hP3V1YUeuqrlxw5 VYGnxk+HH1++nT9zCh06Epc8xwbafe+8z5LV+5IKPfxX4XgOwUw9mdneMs/OPiMOqh2f mp/X0H0zkSjdfyWIfyFpV71FW39Rx0gLE1lzDE3RLp8AoDURCdiK3ZLZqLzNC8HLOJxE NF0A== 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=08ngW/6ouUjDi/wpMdVaPAEKWapsl3xNTLfVKkU+m5Y=; b=WJtpQXCu9eMNMBaOtExhSfaQ1PGqiXYTk85acc3woaKibo/LlhhJgVAKj0wSJTmLMc 9ZmACCdeByzPXFDk86QLwyUHipqznb6uyttKjGBqglYpb3QSTd8Tfr+xCvGxch5YL3Ob wPtkRZWmfoqg/ZXLNSmcYc5vHjUJOVNXUQApa9z0k5zfJJZKLiIhQZvptt5A4uGyn0hf pg1iekWKMy/w+VaCIGU/gAePG0RXz5PFZ3C77TuYsG+B+kBRHdDx20XJROoN/Lcr9aj3 SmhjbvXt6T9uCGBI7SamQhoERO+05vA7qtEPTGiZeD/f8wOerQpVLr6ZAYDYgROZ9Obb sHQg== X-Gm-Message-State: AOAM532+sxf2OsSr1Mcf1Lj887heNk/ZsTESzF2DDferYeQRzhdylL/Z jbcoA/Mn/SmafP0EDYq4MWhAB41KmfRMP+n8aul/qWLBy6EWgl7sZ1gqgN2df5yVrwDAoc8AVHd OdQe6x5eIygPO7PnVGbKyhwlQEcAiS4TMeIt4VMvrrB/OYWZl518H+OHc9qQjjKtuo054 X-Google-Smtp-Source: ABdhPJySrTkm2ZZQhHIET6BVacdS/IIJwe+EXCFPY8X8aCXyuEC7h3HWa6Hi7G41FKirusQld9i5BZkyqos= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a25:6b42:: with SMTP id o2mr7686789ybm.244.1622836752705; Fri, 04 Jun 2021 12:59:12 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:52 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-3-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 02/10] block: blk-crypto: introduce blk_crypto_bio_sectors_alignment() From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The size of any bio must be aligned to the data unit size of the bio crypt context (if it exists) of that bio. This must also be ensured whenever a bio is split. Introduce blk_crypto_bio_sectors_alignment() that returns the required alignment in sectors. The number of sectors passed to any call of bio_split() must be aligned to blk_crypto_bio_sectors_alignment(). Signed-off-by: Satya Tangirala --- block/blk-crypto-internal.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/block/blk-crypto-internal.h b/block/blk-crypto-internal.h index 0d36aae538d7..7f1535cc7e7c 100644 --- a/block/blk-crypto-internal.h +++ b/block/blk-crypto-internal.h @@ -60,6 +60,21 @@ static inline bool blk_crypto_rq_is_encrypted(struct request *rq) return rq->crypt_ctx; } +/* + * Returns the alignment requirement for the number of sectors in this bio based + * on its bi_crypt_context. Any bios split from this bio must follow this + * alignment requirement as well. Note that a bio must contain a whole number of + * crypto data units (which is selected by the submitter of bio), since + * encryption/decryption can only be performed on a complete crypto data unit. + */ +static inline unsigned int blk_crypto_bio_sectors_alignment(struct bio *bio) +{ + if (!bio_has_crypt_ctx(bio)) + return 1; + return bio->bi_crypt_context->bc_key->crypto_cfg.data_unit_size >> + SECTOR_SHIFT; +} + #else /* CONFIG_BLK_INLINE_ENCRYPTION */ static inline bool bio_crypt_rq_ctx_compatible(struct request *rq, @@ -93,6 +108,11 @@ static inline bool blk_crypto_rq_is_encrypted(struct request *rq) return false; } +static inline unsigned int blk_crypto_bio_sectors_alignment(struct bio *bio) +{ + return 1; +} + #endif /* CONFIG_BLK_INLINE_ENCRYPTION */ void __bio_crypt_advance(struct bio *bio, unsigned int bytes); From patchwork Fri Jun 4 19:58:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300651 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 374D2C4743C for ; Fri, 4 Jun 2021 19:59:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2063F613F8 for ; Fri, 4 Jun 2021 19:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231147AbhFDUBP (ORCPT ); Fri, 4 Jun 2021 16:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231265AbhFDUBN (ORCPT ); Fri, 4 Jun 2021 16:01:13 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CD74C061767 for ; Fri, 4 Jun 2021 12:59:15 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id w130-20020a25df880000b02905327e5d7f43so13190329ybg.3 for ; Fri, 04 Jun 2021 12:59:15 -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=R3HMBFHospGnC9Opd1R53FLCvcJarpfKxQXd852tZKY=; b=o/e7RzBLKivm9MR0djmqRPiA7UqgFavlq7CZ6C7ujUQ4xJW9sKCvusYV8Wjv7azcNF GSRJO+oc7exvTHwGRccUsla+3cH6Shf4/mQDAFh9WuieKusx6AvCPFT6Mkzfa7Dbeucr PQNp/k/I52NavAo4qdqzFqBlFvxbHC5pXqZYRWw+PNyReppr7DMFz7PiVFXbtiB2ypiI xb+/l9Ws5QmVb1kNKnTCCUcdGwMPTr+vsHmSDpmwIRr/45Dr4tzkwhKOlyDodWPZVGjW ROv294W4itIH06Hmj6Ky0PXe7RWcKIL20UnO75KjzvtIaj+KEWiaOhB8PBIMk4feF6a9 dsnQ== 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=R3HMBFHospGnC9Opd1R53FLCvcJarpfKxQXd852tZKY=; b=l6uuVVEb18DgwD5Iif1zNlHU9P4se4x/MHRNxNc8Kfe6WrXv5lsGypyYUrV8saYnpa ARlAFfhjKQlspKC7qnyzX08v7EFsDzce6O570mtQgb2uMpl/+A6X36BCSd8WvAmA5aor a4L0tYVNhbVxcBEcbICRXnZ88dRh4e2+5No3VHwaqFOTXmCjVOHJfFq4akrl+WMer1sE PyhpTqPwtbPUBMiO2C+t2O1x3o8W+oC2j52S+mVy1J8mSMUMG4XddTQ7PILiGjSUwYgB oLczxvc+oXqIT1MZhWqsbNmsIbNeRRZWUYIIro8NuWBt7wEgoSz2uQbHSP9D1lesDPnT WPZA== X-Gm-Message-State: AOAM5302d50L4LknNJxs8H1qmWjdPOH83OUmOPEUxdgRoxB2EPGvD7oD zPh4wdySAl13Cfhx3eqIaXzipGGt2al+mfhw6mYfIrRVtsBOY4jkBUFWaM9yXseLBzHUT9HQrPT 3C7dtCx/HeX6WZyKhFfeUx44s7cnnOrMtED+QSsgEXge7mxG44ti8T4x7sFzcthWeLpKh X-Google-Smtp-Source: ABdhPJzFZypqjRzJtlE+aOSTEjYGKn65clE50NBU5ELxH8iIHgXb/wJcszapXniKS65VqovIMY2D3B1Zvrs= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a5b:34a:: with SMTP id q10mr7679716ybp.224.1622836754233; Fri, 04 Jun 2021 12:59:14 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:53 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-4-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 03/10] block: introduce bio_required_sector_alignment() From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This function returns the required alignment for the number of sectors in a bio. In particular, the number of sectors passed to bio_split() must be aligned to this value. Signed-off-by: Satya Tangirala --- block/blk.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/blk.h b/block/blk.h index 8b3591aee0a5..c8dcad7dde81 100644 --- a/block/blk.h +++ b/block/blk.h @@ -262,6 +262,20 @@ static inline unsigned int bio_allowed_max_sectors(struct request_queue *q) return round_down(UINT_MAX, queue_logical_block_size(q)) >> 9; } +/* + * The required sector alignment for a bio. The number of sectors in any bio + * must be aligned to this value. + */ +static inline unsigned int bio_required_sector_alignment(struct bio *bio) +{ + unsigned int alignmask = + (bdev_logical_block_size(bio->bi_bdev) >> SECTOR_SHIFT) - 1; + + alignmask |= blk_crypto_bio_sectors_alignment(bio) - 1; + + return alignmask + 1; +} + /* * The max bio size which is aligned to q->limits.discard_granularity. This * is a hint to split large discard bio in generic block layer, then if device From patchwork Fri Jun 4 19:58:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300655 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 0A108C4743D for ; Fri, 4 Jun 2021 20:00:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE00B61407 for ; Fri, 4 Jun 2021 20:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230421AbhFDUCJ (ORCPT ); Fri, 4 Jun 2021 16:02:09 -0400 Received: from mail-yb1-f202.google.com ([209.85.219.202]:57064 "EHLO mail-yb1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231363AbhFDUCD (ORCPT ); Fri, 4 Jun 2021 16:02:03 -0400 Received: by mail-yb1-f202.google.com with SMTP id m205-20020a25d4d60000b029052a8de1fe41so13098494ybf.23 for ; Fri, 04 Jun 2021 13:00:16 -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=CrvB+067/I+CxLLg5RI6y2+/auWfNk2l0qpau+BMbco=; b=K3j5LwA4O8C/vL99eQGQ0tGLMUIZpSoXyyrsmYczwJFjEtEXne1IRUnR1Tmeecqq3f CKDu3ca7OKlE4hozFKVOA2tgtpIW9mwzj+Ykf4tS1w6le5spKOHwnUhciOQXa1LQ+fkD Fl7oQg1vxQmJSZDSDjR/62PqI5sGiLG/rjBILcpSeCxjzXIWBdgzlaS/9cRsCerSIS7A 8C46TVhK+bEMbWW2yVrl4z3hZp01Z9+TNVOxUdnL6btYGTwYDGWoAbaeKRgrx2L4bBkw KVPRQNmjxiRdE6ewFIPTop8MTUD86m1zZ9Qt+dR+y7gPhcJKP2WesNdZ3vi8SIJqyEIJ usVg== 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=CrvB+067/I+CxLLg5RI6y2+/auWfNk2l0qpau+BMbco=; b=Alkjjr4UVgDlw+eSFW1bvB8yZUIQ8JrwMHH206rkuqip6lROk8VMGjkJLNdjFNprHi AgAzIC1yPrPJuRS5K+q3WiOyfQtBlcjyKQ4hTpCDb2wNSHFLXTW2EMlKlFYdUyf+oBP2 99BCUUr1r3S1sCCqGjKysnWbJYWR1toykjY+9Ic0Pr326Iw8WkvRcrDID/B0ksLlFYB/ TObkQacZTzCdK31UUZm2dnqhtguIhX64tlXNjJGFnBb9zQ8Enpn/RSL4RmIMzuwIz+Tg on8D0aM0EwWBoY8s01lAGkSij99UsSab3Sky2K0prb4ZfUBuaGn6NeN7378zRGhSv2lG bI2g== X-Gm-Message-State: AOAM53029OFVZdmRjUEDOjdQA8vqUNUdl5dz21J49V0DHyiI5fNhTvVJ YAGndqmKO8CA2lKEsoNJIdrsdZwAXgiMLnws+VrcGKLXmGfyhebYyUluc0FST2NHSkA+wMCSxbv fu9lpBhyBYlXBQxH80ImU5lX+Ix85E6jRLAwDfPqcU4Ne2SVidn2rUKjUTcmiBhLi5onC X-Google-Smtp-Source: ABdhPJwRpwAf7i+p+qPOvbpLnxp6faKw5GUkn35qPs//LLow4O922a8pO0+n/57Cx+JXfX6OXE4kFyKGRr4= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a25:824f:: with SMTP id d15mr7687638ybn.273.1622836755998; Fri, 04 Jun 2021 12:59:15 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:54 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-5-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 04/10] block: respect bio_required_sector_alignment() in blk-crypto-fallback From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Make blk_crypto_split_bio_if_needed() respect bio_required_sector_alignment() when calling bio_split(). Without this, blk-crypto-fallback could possibly split a bio in the middle of a data unit, and the resulting bios can no longer be encrypted (since encryption can only be done on complete crypto data units). Signed-off-by: Satya Tangirala Reviewed-by: Eric Biggers --- block/blk-crypto-fallback.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c index c322176a1e09..85c813ef670b 100644 --- a/block/blk-crypto-fallback.c +++ b/block/blk-crypto-fallback.c @@ -19,6 +19,7 @@ #include #include +#include "blk.h" #include "blk-crypto-internal.h" static unsigned int num_prealloc_bounce_pg = 32; @@ -225,6 +226,8 @@ static bool blk_crypto_split_bio_if_needed(struct bio **bio_ptr) if (num_sectors < bio_sectors(bio)) { struct bio *split_bio; + num_sectors = round_down(num_sectors, + bio_required_sector_alignment(bio)); split_bio = bio_split(bio, num_sectors, GFP_NOIO, &crypto_bio_split); if (!split_bio) { From patchwork Fri Jun 4 19:58:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300657 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 12F99C4743C for ; Fri, 4 Jun 2021 20:00:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E30C4613F8 for ; Fri, 4 Jun 2021 20:00:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231437AbhFDUCP (ORCPT ); Fri, 4 Jun 2021 16:02:15 -0400 Received: from mail-yb1-f202.google.com ([209.85.219.202]:42840 "EHLO mail-yb1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231376AbhFDUCE (ORCPT ); Fri, 4 Jun 2021 16:02:04 -0400 Received: by mail-yb1-f202.google.com with SMTP id 22-20020a250d160000b0290532b914c9f4so13154626ybn.9 for ; Fri, 04 Jun 2021 13:00:18 -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=wJJSAHsgrNVobsA6v1QNlZBTtRzVhTXm7J8/hbunSiM=; b=s/9Q7No1v6Rq6WtoRwX3CpJFU8g8xp+FzjfQ9jgfe08+uLbq5ptD0+orOP8d4+DTH2 EIHIhsd3aLBlX5u7+FC9U3Zt8PhgKwvqRLeK9GZ2O7tabix7hYUZ01hRJaKfZ1cPN9eR d9fq52P4+I5QQpJGtNQhRJwF6VRYAKB6a3L2HSBPMZM3N9qbZNCqwLClIO7hUHwBRP59 77OQrv/ctBX9liw3F1TEV1IZGuLVrk0i0Uimbo4O8Bybsy2Brrd8MONws0MIwjDnD/2v pZeZC6j4h34HjAZ4sNBrRkWIQfnJKhtSi3xoHZ3ieYnkF8nTDzXLELE3h1Yw0Uw9ydPG cOVw== 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=wJJSAHsgrNVobsA6v1QNlZBTtRzVhTXm7J8/hbunSiM=; b=pvzdHuO0Sljr3Nl2ziMlnEwOwsvyWJHvGIqbolzTrHfr9lNBnGzMa86omUJD0EhuNq ppWFg2cZXbZypKUPCIOzjwOY8dGYRb8sZCddVMwU8B2yRQ1T2iJN/hWb1A1pXXEcDIlE MfujFIrNKONLUeFOp18Gql3OWXE4/fXUGHIKifNxBZ4XlaoEUjkWfX0+3WiSltLPnPj0 Uie5ylRlX8+zNtP80wpDtt/8md0deNahOZcJk+AqozZU5lqUSEg7/EOXVqZyxkfNKOzZ +sbkve8SxB6V9nTxmNYCAoJgl45CU4TqrZ5LlK+sm48TzVzc9y0hTnyNbezwI5lNkFK2 weZA== X-Gm-Message-State: AOAM5337Zbj74mRSqXJ+ACW+otGUXBqJ4YUYb+Zfmx34kYkHmVkx6SEP 43vrHg0csJtmI+ZD+VjUnTaPMnP54qIbckTh1+hadTjV0GB10ToDV0hLAqbhbUEkaHCLbz6EeWc 7u9SpRWROIkTvhInjJ1jiFCtwvGgt3BbGuvEBpbdj7U+RO28n0uHwWRk68ikZJE6c7oVN X-Google-Smtp-Source: ABdhPJy1fd7m8zrrg5pm8rmkbKphbHnv06LKzft+zyB6KJv2i8ydmxtr0oBXWXUy2thxIc8ZE+zR1SP9dYA= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a25:b009:: with SMTP id q9mr7530652ybf.506.1622836757710; Fri, 04 Jun 2021 12:59:17 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:55 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-6-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 05/10] block: keyslot-manager: introduce blk_ksm_restrict_dus_to_queue_limits() From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Not all crypto data unit sizes might be supported by the block layer due to certain queue limits. This new function checks the queue limits and appropriately modifies the keyslot manager to reflect only the supported crypto data unit sizes. blk_ksm_register() runs any given ksm through this function before actually registering the ksm with a queue. Signed-off-by: Satya Tangirala --- block/keyslot-manager.c | 91 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c index 88211581141a..6a355867be59 100644 --- a/block/keyslot-manager.c +++ b/block/keyslot-manager.c @@ -458,12 +458,103 @@ bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm) } EXPORT_SYMBOL_GPL(blk_ksm_is_empty); +/* + * Restrict the supported data unit sizes of the ksm based on the request queue + * limits + */ +static void +blk_ksm_restrict_dus_to_queue_limits(struct blk_keyslot_manager *ksm, + struct request_queue *q) +{ + /* The largest possible data unit size we support is PAGE_SIZE. */ + unsigned long largest_dus = PAGE_SIZE; + unsigned int dus_allowed_mask; + int i; + bool dus_was_restricted = false; + struct queue_limits *limits = &q->limits; + + /* + * If the queue doesn't support SG gaps, a bio might get split in the + * middle of a data unit. So require SG gap support for inline + * encryption for any data unit size larger than a single sector. + * + * A crypto data unit might straddle an SG gap, and only a single sector + * of that data unit might be before the gap - the block layer will need + * to split that bio at the gap, which will result in an incomplete + * crypto data unit unless the crypto data unit size is a single sector. + */ + if (limits->virt_boundary_mask) + largest_dus = SECTOR_SIZE; + + /* + * If the queue has chunk_sectors, the bio might be split within a data + * unit if the data unit size is larger than a single sector. So only + * support a single sector data unit size in this case. + * + * Just like the SG gap case above, a crypto data unit might straddle a + * chunk sector boundary, and in the worst case, only a single sector of + * the data unit might be before/after the boundary. + */ + if (limits->chunk_sectors) + largest_dus = SECTOR_SIZE; + + /* + * Any bio sent to the queue must be allowed to contain at least a + * data_unit_size worth of data. Since each segment in a bio contains + * at least a SECTOR_SIZE worth of data, it's sufficient that + * queue_max_segments(q) * SECTOR_SIZE >= data_unit_size. So disable + * all data_unit_sizes not satisfiable. + * + * We assume the worst case of only SECTOR_SIZE bytes of data in each + * segment since users of the block layer are free to construct bios + * with such segments. + */ + largest_dus = min(largest_dus, + 1UL << (fls(limits->max_segments) - 1 + SECTOR_SHIFT)); + + /* Clear all unsupported data unit sizes. */ + dus_allowed_mask = (largest_dus << 1) - 1; + for (i = 0; i < ARRAY_SIZE(ksm->crypto_modes_supported); i++) { + if (ksm->crypto_modes_supported[i] & (~dus_allowed_mask)) + dus_was_restricted = true; + ksm->crypto_modes_supported[i] &= dus_allowed_mask; + } + + if (dus_was_restricted) { + pr_warn("Disallowed use of encryption data unit sizes above %lu bytes with inline encryption hardware because of device request queue limits on device %s.\n", + largest_dus, q->backing_dev_info->dev_name); + } +} + +/** + * blk_ksm_register() - Sets the queue's keyslot manager to the provided ksm, if + * compatible + * @ksm: The ksm to register + * @q: The request_queue to register the ksm to + * + * Checks if the keyslot manager provided is compatible with the request queue + * (i.e. the queue shouldn't also support integrity). After that, the crypto + * capabilities of the given keyslot manager are restricted to what the queue + * can support based on it's limits. Note that if @ksm doesn't support any + * crypto capabilities after the capability restriction, the queue's ksm is + * set to NULL, instead of being set to a pointer to the now "empty" @ksm. + * + * Return: true if @q's ksm is set to the provided @ksm, false otherwise + * (including the case when @ksm becomes "empty" due to crypto + * capability restrictions) + */ bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q) { if (blk_integrity_queue_supports_integrity(q)) { pr_warn("Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n"); return false; } + + blk_ksm_restrict_dus_to_queue_limits(ksm, q); + + if (blk_ksm_is_empty(ksm)) + return false; + q->ksm = ksm; return true; } From patchwork Fri Jun 4 19:58:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300647 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 C4FD0C4743D for ; Fri, 4 Jun 2021 19:59:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9385613AD for ; Fri, 4 Jun 2021 19:59:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231260AbhFDUBH (ORCPT ); Fri, 4 Jun 2021 16:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbhFDUBG (ORCPT ); Fri, 4 Jun 2021 16:01:06 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3444EC061768 for ; Fri, 4 Jun 2021 12:59:20 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id lb17-20020a17090b4a51b029016bc5d1a583so2676762pjb.4 for ; Fri, 04 Jun 2021 12:59:20 -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=kd1E77D6aPxR9eaBjS43P1vtWPIox0q43LsvhH1VUfg=; b=slBbxZ7y6pnAglU6rF2VZ7Pn/uFpNALrK5ZbJmvrcqUfyvWtXQ4DJzEXClxVSHSKV3 j0rQodPMbpzXNW3zZ5ZPmY/UAaEYEl43nnkF6gvU2QI00dCLmKbZ89OHwqY+6EaXkFIL nsKVawzGjmYw2Y61BKJx9hPcsO5o0kGVoiCvlvwSuDWWw0l2XZiTOxCEVtik8mj/x484 1++e5KQki6hBpinevssj6mAO8A7nwvBuJcb25kB+ff++tObZaFuKQ/OYy3Esgx4SV8ke /lWfjoDmxGeuuQ1sarp1OGCXpsd2Q1r9oDF0ys16ljSPzBvyJa2FSgJe0dD1ds3XxGA3 e8Hg== 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=kd1E77D6aPxR9eaBjS43P1vtWPIox0q43LsvhH1VUfg=; b=Am5bw15zl0eKb08x4eHa5o25477Hs9txPazI80lA6jLxztVoKCfGiR5VbntRO9d2A7 N8AUUHYZ9qG1tt6yKQbVZbhiIaRx8r57xKAkY7MA9vf0LSMkWqb8mtSKPQbwI/QEPpF1 l1IEAbp8xDNh69s8LPTUp4eo5i6XIrTPi/n4UFBHUA6eGhplEaxu5gp/0ZVgsdNh67LT xQ4Hs7qcYSMqNYTeph6grb+4Bu03MW4uxMt+e44d2i3iN5XGTBoPPisG+DLuEpNAuBRX XHdSx9ppUOxf3LsaLpKe+aVAhG9MH+YrOCXKzHihvlmw1u/6aSZTmsxf0KINal4wD6X/ s1Wg== X-Gm-Message-State: AOAM531tdTbIw33jyWFxnxZdhPZpkt5BuEm4ry/kKoedCoLQErr6LCCv 4YexwNQxs/DwyuEM+aFduBvSnDGgkQ8KU5VJBdh7VGLQ4bKqa5de1o2BE1TJjaY21OpikO6ayp7 Qyk2/NSX9otZJ64gFqS2/ij2uSvY1SX8c6TYEWC5bEvga8tfVnn9vafxrgY+lTeLFroES X-Google-Smtp-Source: ABdhPJyFd5ZwvoVxCS1V14luiBtciIHgcOru+4XK3wB3hc+geHyGYCQsnOy5fsYAo81EETM/7MtLS2AJewc= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a62:380b:0:b029:2e9:9eb1:ba71 with SMTP id f11-20020a62380b0000b02902e99eb1ba71mr6023434pfa.80.1622836759568; Fri, 04 Jun 2021 12:59:19 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:56 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-7-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 06/10] ufshcd: handle error from blk_ksm_register() From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Handle any error from blk_ksm_register() in the callers. Previously, the callers ignored the return value because blk_ksm_register() wouldn't fail as long as the request_queue didn't have integrity support too, but as this is no longer the case, it's safer for the callers to just handle the return value appropriately. Signed-off-by: Satya Tangirala --- drivers/scsi/ufs/ufshcd-crypto.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd-crypto.c b/drivers/scsi/ufs/ufshcd-crypto.c index d70cdcd35e43..0fcf9d6752f8 100644 --- a/drivers/scsi/ufs/ufshcd-crypto.c +++ b/drivers/scsi/ufs/ufshcd-crypto.c @@ -233,6 +233,15 @@ void ufshcd_init_crypto(struct ufs_hba *hba) void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba, struct request_queue *q) { - if (hba->caps & UFSHCD_CAP_CRYPTO) - blk_ksm_register(&hba->ksm, q); + if (hba->caps & UFSHCD_CAP_CRYPTO) { + /* + * This WARN_ON should never trigger since &hba->ksm won't be + * "empty" (i.e. will support at least 1 crypto capability), a + * UFS device's request queue doesn't support integrity, and + * it also satisfies all the block layer constraints (i.e. + * supports SG gaps, doesn't have chunk sectors, has a + * sufficiently large supported max_segments per bio) + */ + WARN_ON(!blk_ksm_register(&hba->ksm, q)); + } } From patchwork Fri Jun 4 19:58:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300661 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 68B07C4743C for ; Fri, 4 Jun 2021 20:00:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 518BE613F8 for ; Fri, 4 Jun 2021 20:00:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231443AbhFDUCV (ORCPT ); Fri, 4 Jun 2021 16:02:21 -0400 Received: from mail-yb1-f201.google.com ([209.85.219.201]:51885 "EHLO mail-yb1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231384AbhFDUCV (ORCPT ); Fri, 4 Jun 2021 16:02:21 -0400 Received: by mail-yb1-f201.google.com with SMTP id d6-20020a2568060000b0290535b52251cfso13146594ybc.18 for ; Fri, 04 Jun 2021 13:00:34 -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=pgZaEyBtBsTzFRJDI8Jnnog0gKADt58CJnoqBCP+in8=; b=uUV7BqO4f+Zte/lFb383yyVYOK3VdXuD3Okwqz87OPd2B5NgUxxaz3ZxJyVyMfYOgY 9ZE5AgKFLwNVu2wqFDTPs77c+t9PbozjYepuv1BD8/amxLlelOC4N762wZRM75mO3lVR +zfxCnxGAMJfSJ+A4aHfeATlTMM2VyItnu3Pr7UzFN7nJKdf26X8LdHY/maLK/99t0zt s4kaQhIr6a1YQEvCT11A5fhX0e19eKkFow3v7vcMQe0ZzksnSRmGjvJfxgn55pbpOshX 84Qx/HB6cA9Sgnjpc1iG4+8J+p/foxRGtsH8ebHDgiauvDmr3kFmyDKFIgNT+WaUMdE9 BzDA== 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=pgZaEyBtBsTzFRJDI8Jnnog0gKADt58CJnoqBCP+in8=; b=PbbriIjT1iqNTyc/9sDD23VEbsVsO9GEUpFkO6yZGSbU5X90bPCwBU6yix8sHRmJE6 iOq9z+Ok8XV034T5yeeTdd1kS17gpFy+7ETJtJiM+yVZ4KzZv7fbAhZpEzZIMzTyWjJj VkHSRRhzhF4z3Xmxg8B1FCUI2U0UT+ht4IgdQ+EgKfKnZ9AAoZFFuGKi72SQULs7+8gy SCXhuxd/H6qdDPh3taKlXrx/vVukFZHJRPi9hVLEDxdoKpCKr6ZJqKz2cLiwLVIYEavF ETP+pwreKOPU9ZEUxSKJ96BzRumAjEfWyPu205RVyw3n39b6q1Wn7fjgNh5HZqwDV294 B2Hw== X-Gm-Message-State: AOAM530yKGs0ykuGGbzCGZfkNRzQWx9AUDqPj1bA3QZ2gyG+E9DPTt6K 2NXpC6JswUF8PQpTfxg8hfxYVgfDBoOmT7CB6kkvLD97mdFzV681nolxx0Sv7tmX8u6ZfMASzoJ eG76Ue7wsuwJRNMQdJC99N9n1x3hnUWGmiu4u8wx6RtOCOLCkBgFn2kGAe8IkvlHgB3Sk X-Google-Smtp-Source: ABdhPJy3hxJvjiN/TAAfv2M9Py0zD+C14+X3vu2qbb0PQB99gWO5CrTeHtdS1YqnXjKPQIXY/tSGHL83z8c= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a25:4d04:: with SMTP id a4mr7276497ybb.311.1622836774525; Fri, 04 Jun 2021 12:59:34 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:57 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-8-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 07/10] mmc: handle error from blk_ksm_register() From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Handle any error from blk_ksm_register() in the callers. Previously, the callers ignored the return value because blk_ksm_register() wouldn't fail as long as the request_queue didn't have integrity support too, but as this is no longer the case, it's safer for the callers to just handle the return value appropriately. Signed-off-by: Satya Tangirala --- drivers/mmc/core/crypto.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/crypto.c b/drivers/mmc/core/crypto.c index 419a368f8402..cccd8c7d7e7a 100644 --- a/drivers/mmc/core/crypto.c +++ b/drivers/mmc/core/crypto.c @@ -21,8 +21,17 @@ void mmc_crypto_set_initial_state(struct mmc_host *host) void mmc_crypto_setup_queue(struct request_queue *q, struct mmc_host *host) { - if (host->caps2 & MMC_CAP2_CRYPTO) - blk_ksm_register(&host->ksm, q); + if (host->caps2 & MMC_CAP2_CRYPTO) { + /* + * This WARN_ON should never trigger since &host->ksm won't be + * "empty" (i.e. will support at least 1 crypto capability), an + * MMC device's request queue doesn't support integrity, and + * it also satisfies all the block layer constraints (i.e. + * supports SG gaps, doesn't have chunk sectors, has a + * sufficiently large supported max_segments per bio) + */ + WARN_ON(!blk_ksm_register(&host->ksm, q)); + } } EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue); From patchwork Fri Jun 4 19:58:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300663 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 51DEEC4743E for ; Fri, 4 Jun 2021 20:00:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A43261407 for ; Fri, 4 Jun 2021 20:00:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231384AbhFDUCX (ORCPT ); Fri, 4 Jun 2021 16:02:23 -0400 Received: from mail-pj1-f73.google.com ([209.85.216.73]:56177 "EHLO mail-pj1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbhFDUCX (ORCPT ); Fri, 4 Jun 2021 16:02:23 -0400 Received: by mail-pj1-f73.google.com with SMTP id y17-20020a17090aa411b02901649daab2b1so5790027pjp.5 for ; Fri, 04 Jun 2021 13:00:36 -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=jBlEUGbY3b8g6dIjXWcbrWjBefIWreF/HXMBvYwoDp0=; b=jm8my7TF16J35qoVRbezLA3WooLXFZjasFcGwe7I9POWEyg8Ps/qcqZ2Yo/kVEVBsL p0eD8bDMQyqeOLCDxgv+pxoDtS3tSNses9uWQt+gM7oDVKmYBB86WkVjfJCprWJ+BhVj IVwCghFtTXluOmuABGDvnPlr5fzxFUchsBtHr2zdBnCB19P9YGaq5PclLTQ/HO3HiX3p m7i/9v5ucfa7dotnV/gz/N5cINZ/bi0+xG6g45QuKLDLlYk+/UYMtygawoY4tI5L1KiN Lwsdeh5imCR+xDI5XJRQk/S2+VZa5wMa6cHDSh8DiG7TuI+MidIOI9DXDCpNXLdozuis 0OeQ== 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=jBlEUGbY3b8g6dIjXWcbrWjBefIWreF/HXMBvYwoDp0=; b=QCg1q+5SaVyDJTJNChwZHC5u5rQm2hx2OVHnuVoxehz845VjN9hE+NknV1CzTjKJQN KJk+eXF59eU9L/SqKHhfx2O+ZHRG4uyZBK4CpZ40qBZ0cV1+OqX9qr53C2mNwmO3QuUl UIfi+NiwfOEiy46Y4Sl30DMZWfVUrljnek7RATawDBH6EZbT9BnuoTXHhdV7V1/8Oayl 8Dwo9FT3Hj6s468e2rCmkLxCRL0asN5uwLFJuWLCoD1YFlUWjz+X1VyQ6IyR8KCn8m8i MHPDpj+2PFJ3WogQft0kysVmwYJt8WuSmE1I1r6WOguguZJAkDAYuWt0nnOoFy313EtG Jsuw== X-Gm-Message-State: AOAM532OEhiGyxxKokvBnYovLewdHOynOVAymYPHhPuZ0cROpq+OuJun j4DTISAwSEbRwXDO7Renpt3GgQLH+NBnJieh221Mp4HRJEqerI9x6rL6WYZivgtf8UXV0PqokWY odNKQHBLWtYrEAdCaGxKD4wwGLbXJ/lrsbWt4+bdVIT7yNMeTSBdlgNPs6jnOtuqhrlQL X-Google-Smtp-Source: ABdhPJybK+Y+9fdHsla3It3WXjr5AOT/z7ea31AoJVRgzJKgiqpfrCt0fg3QxTSDhnBOdYvRVjuAHbqoA5o= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:aa7:9d92:0:b029:2e9:dcf0:a2ef with SMTP id f18-20020aa79d920000b02902e9dcf0a2efmr5949723pfq.46.1622836776394; Fri, 04 Jun 2021 12:59:36 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:58 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-9-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 08/10] dm: handle error from blk_ksm_register() From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Handle any error from blk_ksm_register() in the callers. Previously, the callers ignored the return value because blk_ksm_register() wouldn't fail as long as the request_queue didn't have integrity support too, but as this is no longer the case, it's safer for the callers to just handle the return value appropriately. Signed-off-by: Satya Tangirala --- drivers/md/dm-table.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 29cbfc3e3c4b..e44f304b5c1a 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1354,7 +1354,21 @@ static void dm_update_keyslot_manager(struct request_queue *q, /* Make the ksm less restrictive */ if (!q->ksm) { - blk_ksm_register(t->ksm, q); + /* + * This WARN_ON should never trigger since t->ksm isn't be + * "empty" (i.e. will support at least 1 crypto capability), the + * request queue doesn't support integrity (since + * dm_table_construct_keyslot_manager() checks that), and + * it also satisfies all the block layer constraints + * "sufficiently" (as in the constraints of the DM device's + * request queue won't preclude any of the intersection of the + * supported capabilities of the underlying devices, since if + * some capability were precluded by the DM device's request + * queue's constraints, that capability would also have been + * precluded by one of the child device's request queues) + */ + if (WARN_ON(!blk_ksm_register(t->ksm, q))) + dm_destroy_keyslot_manager(t->ksm); } else { blk_ksm_update_capabilities(q->ksm, t->ksm); dm_destroy_keyslot_manager(t->ksm); From patchwork Fri Jun 4 19:58:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300653 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 1FE2DC4743D for ; Fri, 4 Jun 2021 19:59:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECCF4613FE for ; Fri, 4 Jun 2021 19:59:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231296AbhFDUB0 (ORCPT ); Fri, 4 Jun 2021 16:01:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231280AbhFDUB0 (ORCPT ); Fri, 4 Jun 2021 16:01:26 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D09AC061767 for ; Fri, 4 Jun 2021 12:59:39 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id f8-20020a17090a9b08b0290153366612f7so5808654pjp.1 for ; Fri, 04 Jun 2021 12:59:39 -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=RhhC1LCT8rPaij2tSlm0EtMdQdPIQzsHGIcTpwsWNJI=; b=O5mhaoiyKYAf2FfzdD/uW/qz8fTJnrej2bs/W7+lu74g5LgAj7VlgD7D4tFnxJb3he FQbQj+/C80HEGpU5SqGAk3NUW++OIXrCIruLKlmdOOq72YQ1ivruOsm625RttnnlH3jv dfOUu+3qLLNLfHZ40l4Mwrt9XygrfzDx6yNyNIlRu3H88Bmztyfi2DqV5KaZIsQww/Ni b47SNv6Pj/chBs7UKNLalXZDEhy8yL/fyVuuuVyjt6fW74CcqxSweP3GgM+1j977nB2z 4HaEp6V3+5ZgX4f78Sb8QxR0LAfzDLfZ9I6sF0rVsIp2r2k0qtRiGOHtnKwH+Cqv0btx GV3A== 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=RhhC1LCT8rPaij2tSlm0EtMdQdPIQzsHGIcTpwsWNJI=; b=HvFgkxZKQfM3qCptmfIO3Cu2pBk/4CkFt0z1rC0qjsdTabCq8/0Q/Nxt9x7Grqxbaw mELXPXa0UVmc1Di/kbmF4W3fCN5zyNkEzBcgRWzfUXtRLAaZ3mOSDK2mIA5Tx9XELwDf pkY52hfDyRPg/u56nkt7iMVm5rliEwtdvKJCKlsH3fmT+8LFnbkgVi3ZAdtbNL1Qk79p OfcQt/RIFI1olzRBBxlDC5Feu4eYz1wuXEqvEcHrTR2xRJVi5r1xEdlbR2o7A0XmJnyY mDGxZnxFaBGZAE6CpS3DTG8yfijvSryHf94k44Zsb3Z5Puj8nJ/szowxKUXr8LLIHtFi h2Fg== X-Gm-Message-State: AOAM533HVQiWLtHp/tWX1pVkky0XpZJ6O8YsMsn1rA6+/LGU9KGCudh2 wptDWzljq1vgyw6IffR+N/euUxVEu6vsD+GXKJxk3+YV//68/sofc6ii8/0tZJBY92lI8Qlkgaz toCKZbnYIvCZKsvXhC1h5jo+qhHg4+dfV9qtt2NGfB+h0fhyikSX5k7z4U0gFtUIoGJnZ X-Google-Smtp-Source: ABdhPJx1/zbo9ivQFwgi7Hpi4EofsvvDKRafsmvEDyXZ3uBeDnv6H1UMIk6kN5bWlssKX/hbIujAVa0yiXM= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a17:902:a5c9:b029:f7:9f7e:aa2f with SMTP id t9-20020a170902a5c9b02900f79f7eaa2fmr5978686plq.54.1622836778802; Fri, 04 Jun 2021 12:59:38 -0700 (PDT) Date: Fri, 4 Jun 2021 19:58:59 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-10-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 09/10] blk-merge: Ensure bios aren't split in middle of a crypto data unit From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Update get_max_io_size() to return a value aligned to bio_required_sector_alignment(). With this change, and the changes to blk_ksm_register() that restrict the supported data unit sizes based on the queue's limits, blk_bio_segment_split() won't split bios in the middle of a data unit anymore Signed-off-by: Satya Tangirala --- block/blk-merge.c | 49 ++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 4d97fb6dd226..00266e4ab05f 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -135,27 +135,39 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q, /* * Return the maximum number of sectors from the start of a bio that may be - * submitted as a single request to a block device. If enough sectors remain, - * align the end to the physical block size. Otherwise align the end to the - * logical block size. This approach minimizes the number of non-aligned - * requests that are submitted to a block device if the start of a bio is not - * aligned to a physical block boundary. + * submitted as a single request to a block device. Tries to align the end to + * the physical block size, while also aligning the returned number of sectors + * to bio_required_sector_alignment(). This approach minimizes the number of + * non-aligned requests that are submitted to a block device if the start of a + * bio is not aligned to a physical block boundary. + * + * More clearly, there are two conditions we're interested in satisfying. + * + * Condition 1) We absolutely must have @return divisible by the + * bio_required_sector_alignment(bio). + * + * Condition 2) *If possible*, while still satisfying Condition 1, we would like + * to have start_offset + @return divisible by physical block size in sectors + * (pbs). */ static inline unsigned get_max_io_size(struct request_queue *q, struct bio *bio) { - unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector, 0); - unsigned max_sectors = sectors; - unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT; - unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT; - unsigned start_offset = bio->bi_iter.bi_sector & (pbs - 1); - - max_sectors += start_offset; - max_sectors &= ~(pbs - 1); - if (max_sectors > start_offset) - return max_sectors - start_offset; - - return sectors & ~(lbs - 1); + unsigned int start_offset = bio->bi_iter.bi_sector; + unsigned int sectors = blk_max_size_offset(q, start_offset, 0); + unsigned int pbs = queue_physical_block_size(q) >> SECTOR_SHIFT; + unsigned int req_sector_align = bio_required_sector_alignment(bio); + unsigned int pbs_aligned_sector = round_down(start_offset + sectors, pbs); + + /* + * If we can return a pbs aligned endpoint while satisfying Condition 1, + * then do so. + */ + if (pbs_aligned_sector > start_offset && + IS_ALIGNED(pbs_aligned_sector - start_offset, req_sector_align)) + return pbs_aligned_sector - start_offset; + + return round_down(sectors, req_sector_align); } static inline unsigned get_max_segment_size(const struct request_queue *q, @@ -235,6 +247,7 @@ static bool bvec_split_segs(const struct request_queue *q, * following is guaranteed for the cloned bio: * - That it has at most get_max_io_size(@q, @bio) sectors. * - That it has at most queue_max_segments(@q) segments. + * - That the number of sectors is aligned to bio_required_sector_alignment(@bio). * * Except for discard requests the cloned bio will point at the bi_io_vec of * the original bio. It is the responsibility of the caller to ensure that the @@ -286,7 +299,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, * big IO can be trival, disable iopoll when split needed. */ bio->bi_opf &= ~REQ_HIPRI; - + sectors = round_down(sectors, bio_required_sector_alignment(bio)); return bio_split(bio, sectors, GFP_NOIO, bs); } From patchwork Fri Jun 4 19:59:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12300665 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 EFFBDC4743D for ; Fri, 4 Jun 2021 20:00:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D94FF613EC for ; Fri, 4 Jun 2021 20:00:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230443AbhFDUCi (ORCPT ); Fri, 4 Jun 2021 16:02:38 -0400 Received: from mail-qv1-f74.google.com ([209.85.219.74]:44575 "EHLO mail-qv1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbhFDUCh (ORCPT ); Fri, 4 Jun 2021 16:02:37 -0400 Received: by mail-qv1-f74.google.com with SMTP id i16-20020a0cf4900000b029022023514900so3063331qvm.11 for ; Fri, 04 Jun 2021 13:00:40 -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=iozWCMAtYKCt6ZARG1CR093QIL86BP6w5zG4UHfXEaY=; b=b/kMgaiP4rlyi9fuWXIOgNTdRw55igKDtzrELiZWocSzKWGap6DizpaWVP+Lfjm+ln /cPr3m1S2oel7iIXg+Fk1im2HQZ2fT67rNzIKydVKheLsJS5z0Sf8Z0B0XuEu3tiJKRF qIfcfJdTI5zlglUpYLUxdazXc+jaV+Mq6y5HSNYZwrQF+g9FE3xoes7rwLqulvdfgzg4 xWn2ABcu9/h2szpHEjkSJlWQ3x7adfX2f/3z+4j8fq/yb4kHyqujPx1VhNW2EgQytzMK NiROUYq89hZBQ0UzVhNsA1gPWgP5kviimgtGgAwZgHSfdPSTtqeMZ3dQUNuD+625uC/d Y2Mw== 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=iozWCMAtYKCt6ZARG1CR093QIL86BP6w5zG4UHfXEaY=; b=G3EuVvZsfwDLIJ2kdFD6Pu88g4Sbj1ZWs/yCWjoLn1nQEGITnEpIcpCYeTOCwkIwfi eRca5TZOPh/vB7fMI/vt6muGyMnlh8NxZyHyUNQR7iFLBC6kRm+AygAqAnCXnpjnR5L5 9bqVabAVhET95f9Wc0/TUyOyUxBsEBi6yN4c6C/aXmB69KNClOF/FzgnM/KtKAnMYuo7 4LlTKRgL06s6MJTQ2Xey1gSGcWmltjoALKYpxoYY6oP2Jm4i/a5vTvk2+YGCAM8zCdZ1 x/8gAmzNEk9mX1y2PGRJW2568mbVe0XaipTp3rDDpn4jqJFF3/7lFB60eLvavo1pvJmJ HHeQ== X-Gm-Message-State: AOAM5331PnNdcZgVMoBRAkoonTfgh2AuLPjWm7SjR0DA/wBCgfYpM6xL 64gTwrgqokwKDYuPKs76S/XkJVkMvFh9Fg57OftEcia2KajXDL2NkloOzBnuvhSO2IYFlP3FqNz YvA9D5Mab6dCVO3S0VwRc0iKKnUW709SCDH6QSo4D6Z4hKp5310DnumoBA1WkfZUSlbb6 X-Google-Smtp-Source: ABdhPJxOCXfXppSqFV4bTzkHDML8kpyuDCPBL7nXZkg5gEUEj9B5DzrhhwOgM13tbDILoEWyZdZmaQq+gIs= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a05:6214:62a:: with SMTP id a10mr6531397qvx.5.1622836780529; Fri, 04 Jun 2021 12:59:40 -0700 (PDT) Date: Fri, 4 Jun 2021 19:59:00 +0000 In-Reply-To: <20210604195900.2096121-1-satyat@google.com> Message-Id: <20210604195900.2096121-11-satyat@google.com> Mime-Version: 1.0 References: <20210604195900.2096121-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 10/10] block: add WARN_ON_ONCE() to bio_split() for sector alignment From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Eric Biggers , Satya Tangirala Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The number of sectors passed to bio_split() should be aligned to bio_required_sector_alignment(). All callers (other than bounce.c) have been updated to ensure this, so add a WARN_ON_ONCE() if the number of sectors is not aligned. (bounce.c was not updated since it's legacy code - any device that enables bounce buffering won't declare inline encryption support, so bounce.c will never see a bio with an encryption context). Signed-off-by: Satya Tangirala --- block/bio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/bio.c b/block/bio.c index 44205dfb6b60..32f75f31bb5c 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1436,6 +1436,7 @@ struct bio *bio_split(struct bio *bio, int sectors, BUG_ON(sectors <= 0); BUG_ON(sectors >= bio_sectors(bio)); + WARN_ON_ONCE(!IS_ALIGNED(sectors, bio_required_sector_alignment(bio))); /* Zone append commands cannot be split */ if (WARN_ON_ONCE(bio_op(bio) == REQ_OP_ZONE_APPEND))