From patchwork Thu Mar 25 21:26:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12165009 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 8F85CC433E2 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 648B261A4C for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230467AbhCYV1d (ORCPT ); Thu, 25 Mar 2021 17:27:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230489AbhCYV1L (ORCPT ); Thu, 25 Mar 2021 17:27:11 -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 695B9C06175F for ; Thu, 25 Mar 2021 14:27:11 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v6so7538957ybk.9 for ; Thu, 25 Mar 2021 14:27: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=rUphNMT0sm87MpzUiuuClzpcMsplrJctbX+7T7BgcBI=; b=Z31KaBaf0F337eZVWuVD1HT4Uu9KPoH0PgSCulKvd0aw1lTRFmeEoIvqKRdGQlpyJc SLuEh9pdLGtSpPxur46IC4+LS7M9Q7wee5WpMQRBGYkwc6nV9Q1GZsnByKYAabF+jL1/ JLAj3p8JSxlCOcKbzqJdczpXcGH3dtgVD+waeRvSCaiKXMeapuNi/XaBwSLLSLJ5pzXb qF0hzvaRThCKTBQ5T51EPvZGzDjfrscM9URatMIoj3CPBmomNb63SniIDZLtzW3FHVTP mgtkrjGzTQ+B4PgLCPy3OlY81rzufDO8KFrcYyB9ZxWC6U4GyyzGj4UECEGmLtlSUm7T CC4g== 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=rUphNMT0sm87MpzUiuuClzpcMsplrJctbX+7T7BgcBI=; b=Zf0qqtivE1uBx8+7sLfBXwUjUPYvDmePFsgQn9EE4PGJ8WNG7BY+aKnV5Gp0d6EBrs oYNVJYDrOKuXEjGmFA+FvTMm8T9ukqVL9Kk0yTNV0XVK5cApNvFe63NbMsvLGCGTvFq3 YZJYc7pOQE7TxWhqZcn9dWhEOZPF34VNUEYSskFchzj+PGBK/unqcMYAfFhgb3N27YFX 5sQHbLtbwmrhdPK2yFDoS3+5MdEfIMXo2bycjB2KWSUVlnE3Owbg6asGp7GxE9ci1PJp qYuvCH/LXWdtWLcyiaexwq5+QFlHGnpcSFS3F95hD31by5CWH5xirEf8AkN4OcYtMjDN cZ9g== X-Gm-Message-State: AOAM533wJGXzGKgRByVJOwzGw8905PU7iuWkmlKQyuggVuyWayZmG/Yy AzLDMCVArkPfpVKb0kTJbN7Tazv31RnlUyZ7ELYqwoJvomFOS4BP/Bj76HOuaUDzAwYRI4PAZBP ycuLPPvXm5QZFEH+IAsuLDUxGAOYyWxizqS3LWJZkdGPgSLesWYxNrAMhnoWMtD4+DFeE X-Google-Smtp-Source: ABdhPJxSUh4OHNl49f7VKbtAYjTnF/4KPwbp5X+5mw42hAO4X6wZpuWATUzKmo0HV+mNi0+WWXp4fnPoamM= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a25:d451:: with SMTP id m78mr8877781ybf.105.1616707630557; Thu, 25 Mar 2021 14:27:10 -0700 (PDT) Date: Thu, 25 Mar 2021 21:26:02 +0000 In-Reply-To: <20210325212609.492188-1-satyat@google.com> Message-Id: <20210325212609.492188-2-satyat@google.com> Mime-Version: 1.0 References: <20210325212609.492188-1-satyat@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v2 1/8] 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 --- block/keyslot-manager.c | 13 +++++++++++++ drivers/md/dm-table.c | 11 +---------- include/linux/keyslot-manager.h | 2 ++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c index 2c4a55bea6ca..2a2b1a9785d2 100644 --- a/block/keyslot-manager.c +++ b/block/keyslot-manager.c @@ -437,6 +437,19 @@ void blk_ksm_destroy(struct blk_keyslot_manager *ksm) } EXPORT_SYMBOL_GPL(blk_ksm_destroy); +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 95391f78b8d5..db18a58adad7 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1313,7 +1313,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) @@ -1350,15 +1349,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..5bf0cea20c81 100644 --- a/include/linux/keyslot-manager.h +++ b/include/linux/keyslot-manager.h @@ -117,4 +117,6 @@ bool blk_ksm_is_superset(struct blk_keyslot_manager *ksm_superset, void blk_ksm_update_capabilities(struct blk_keyslot_manager *target_ksm, struct blk_keyslot_manager *reference_ksm); +bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm); + #endif /* __LINUX_KEYSLOT_MANAGER_H */ From patchwork Thu Mar 25 21:26:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12165011 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 7E1A5C433C1 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5176961A45 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230470AbhCYV1e (ORCPT ); Thu, 25 Mar 2021 17:27:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbhCYV1N (ORCPT ); Thu, 25 Mar 2021 17:27:13 -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 ED0EBC06175F for ; Thu, 25 Mar 2021 14:27:12 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id a19so1843422ybg.10 for ; Thu, 25 Mar 2021 14:27:12 -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=sXfRUgmRe7kH6AU5n/x2XWTuNQDYYUL8f3DAKwSKEzw=; b=AnRR1mnKpdEoFdG1gN035lAY93R2KGeI6lEzSv4jdsznjZwNgsmypdE7iioWFPasJ9 kkpo9QDUQhkLE5C/7Im6GCZo6xSTN4rTX93pOPcxYDT55LOOCRgw0oZ5Hl6+jy62ShYu 6OutHCkIzXZoEU0+M0hWhBgE/PbHpI0Tv3Xc20Z50n1j891rZd1mijgvr8lVeuv649yP JGok9RRTZQ8m/AoapgbgajjfTsU+JR+/E5B0C6KuqYkzh7Vh5vYDsWGyARRnQ1bLwF9n 7YhbC+dut7xa7s27Pv/EkiHvBju9UKIIgcaFyDyeJk6LvSYkF5dQX8znbwtFWD0PsWGi 6/1A== 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=sXfRUgmRe7kH6AU5n/x2XWTuNQDYYUL8f3DAKwSKEzw=; b=thu2ff8MXv1VYnx43djvmISHnDvWYxlQkaA9KRrVdj/1wiQuPkb1oMOj8ZInwNsSwZ Mz+zmjigY41q6DHO6jvLuAm8hmdFiOBrGGapNdYHM3Q8zsb39DwryEaODwLRc++2/8hY mry4FV7JyDWGXuQMkxKJcfHVbiAaBv14ceQRf1Ofn79HufdsFt8WPoxdM0voeXHNdPug PvDP0wUTvoaPLjjSVBv5ojvuh0TIOPTcULETAkArndxf0GOF15yjFcuxDDwk9l/OZS/H pctqQDx7W4qyFWEkFfq0yK2rKHmZg+e8dI++P+8xrqhSBLJ/B7d7OuLZsZ9TUMCJJic5 xrpg== X-Gm-Message-State: AOAM5320kMioPeZsT3LNrEGvzBHlq+a/GezX0jkVvUltX7atA3dAUWht s2Tl92UXbhWfX8bbMN0Nxx6K638hxLXQ/A/wq+n6jOSXhxq31eCIV5if+H5a639QRCQ/+gki3uS GMC5bH0W1qeHOe32BwZZbp5pysbozD8uGV9j0FEp/IW2UJnDMmCQ7+dEmDT5kHPVdIJPj X-Google-Smtp-Source: ABdhPJz7DN29DrVMX+YcK1AWw6+N8szReisPV6zaP6Y2M4RZL7AZWIt95VSCM5um9M2HM8lBbP8Iet4DGCA= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a25:a0cd:: with SMTP id i13mr15307478ybm.302.1616707632232; Thu, 25 Mar 2021 14:27:12 -0700 (PDT) Date: Thu, 25 Mar 2021 21:26:03 +0000 In-Reply-To: <20210325212609.492188-1-satyat@google.com> Message-Id: <20210325212609.492188-3-satyat@google.com> Mime-Version: 1.0 References: <20210325212609.492188-1-satyat@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v2 2/8] dm,mmc,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/md/dm-table.c | 3 ++- drivers/mmc/core/crypto.c | 6 ++++-- drivers/scsi/ufs/ufshcd-crypto.c | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index db18a58adad7..1225b9050f29 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1372,7 +1372,8 @@ static void dm_update_keyslot_manager(struct request_queue *q, /* Make the ksm less restrictive */ if (!q->ksm) { - blk_ksm_register(t->ksm, q); + 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); diff --git a/drivers/mmc/core/crypto.c b/drivers/mmc/core/crypto.c index 419a368f8402..616103393557 100644 --- a/drivers/mmc/core/crypto.c +++ b/drivers/mmc/core/crypto.c @@ -21,8 +21,10 @@ 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) { + if (WARN_ON(!blk_ksm_register(&host->ksm, q))) + host->caps2 &= ~MMC_CAP2_CRYPTO; + } } EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue); diff --git a/drivers/scsi/ufs/ufshcd-crypto.c b/drivers/scsi/ufs/ufshcd-crypto.c index d70cdcd35e43..f47a72fefe9e 100644 --- a/drivers/scsi/ufs/ufshcd-crypto.c +++ b/drivers/scsi/ufs/ufshcd-crypto.c @@ -233,6 +233,8 @@ 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) { + if (WARN_ON(!blk_ksm_register(&hba->ksm, q))) + hba->caps &= ~UFSHCD_CAP_CRYPTO; + } } From patchwork Thu Mar 25 21:26:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12165005 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 6189DC433E0 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2773361A1E for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230480AbhCYV1e (ORCPT ); Thu, 25 Mar 2021 17:27:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbhCYV1O (ORCPT ); Thu, 25 Mar 2021 17:27:14 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A01C5C06175F for ; Thu, 25 Mar 2021 14:27:14 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id f20so4935409pgj.6 for ; Thu, 25 Mar 2021 14:27:14 -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=QKM/4VqqpmQG/v1vBmAPZ1ISyc7q5p1Ut3IkXJNTNn8=; b=HnZP67MIz1eIz5tJHXkYxrlB8XA9q1/hNkdl64gZMD8f1fs8z86c1elcZMmZdB/nuX 6P9jm3LlxYD5GOYi1ujnffTpXxivasaXLyKswn65Ol5OPrEAi4wI+/A+FnJp6E0f8D5X 3pyybitU+IYLhnjIw91JgrNv00utQRdL1aJ2lqJk0Oq1pQ/DH9vwu2ndEp9NpmewwOm5 rYqa+yhnRYdPlvSaHasT2eg0tUjqw7DT+LVWuIja4ZNs7XWUzSFNovoUHtL76JTah/x5 LEudfg6bZ1EC6cESObW51z9UUaOazOTGb56yvMbwSYZtgrDGBpxLWOJWOLP9huNS/pv6 Ud3w== 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=QKM/4VqqpmQG/v1vBmAPZ1ISyc7q5p1Ut3IkXJNTNn8=; b=BC8D8pQyPei8vpCDJgYFhrVRMT+mRYA4oktuvDZrcjHxorTMdZSpClOTPs3XmVcpl0 FTe62VsZBRRr+9tLLB2yV8CM3dP/G9lp0/ydJCcXjzE01TxhIyINIqnsIpXRwnZN1mTd QTAwnLnF1nqi+NVYxvq6gwMoEsQOOXd5x+WCamIXQ7zdr7RepqlgvB5i/q8+yTlJS44n 31/Gg7MMwFZNEuGn8strududk5q9PSHfoRITSPTHHnQQOcLLH9JAmkHN1crjFe0XIqte +2jUct6KN4uvDP1fWyn8IkyLRce+YnbTL5ppaXHxVqoG3l6+23tSOmHFB9OLIfKyVXVu hm+w== X-Gm-Message-State: AOAM530yCNtQYS5F+MgFAqmZWc1TttecnfyKVSBtoCnrWvrATZEasfZd A/MEa+W0UCBvYlRU1tW2a9c91LrojL21bSP5COWkpVtndubBvYm5sAO+PWcq15A8CgWlPF4YiG9 jDb/x4zhCU4z8y4KVS9UStbHmh8JPuvBC4qC0hvc72Vr6IqCFaOPHk8VpGg6buj5Ho6Ob X-Google-Smtp-Source: ABdhPJzjoTfGpe0TgBdqASEdyBajTp1H9OebPba0STb+/HWBLKkUrFjrqDgv+AdBd422n4nIJ88hy9WUxEg= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a17:902:56c:b029:e7:1052:a7c6 with SMTP id 99-20020a170902056cb02900e71052a7c6mr11045345plf.75.1616707633890; Thu, 25 Mar 2021 14:27:13 -0700 (PDT) Date: Thu, 25 Mar 2021 21:26:04 +0000 In-Reply-To: <20210325212609.492188-1-satyat@google.com> Message-Id: <20210325212609.492188-4-satyat@google.com> Mime-Version: 1.0 References: <20210325212609.492188-1-satyat@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v2 3/8] 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() should be aligned to blk_crypto_bio_sectors_alignment(). Signed-off-by: Satya Tangirala --- block/blk-crypto-internal.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block/blk-crypto-internal.h b/block/blk-crypto-internal.h index 0d36aae538d7..304e90ed99f5 100644 --- a/block/blk-crypto-internal.h +++ b/block/blk-crypto-internal.h @@ -60,6 +60,19 @@ 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. + */ +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 +106,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 Thu Mar 25 21:26:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12165015 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 B161CC433E4 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75D1961A50 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230484AbhCYV1f (ORCPT ); Thu, 25 Mar 2021 17:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbhCYV1Q (ORCPT ); Thu, 25 Mar 2021 17:27:16 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 939FBC06175F for ; Thu, 25 Mar 2021 14:27:16 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id f8so4052110qtv.22 for ; Thu, 25 Mar 2021 14:27: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=jcwCmvL2zf0lF3Ank04XNaFIuqNE6u2MJVhR/WWQGZc=; b=fUGJmbUcJs9LLuwYxYrtUvHLhM1TcSpAOUXmXU9i7ZnDvC+dagbI2nRWiKwSzhKIn6 J2TpCtBOE35vXBCihxWEoeINPTXBVETVHLvpHO2733KVglleDWVzIJryyi32kWjj+nP6 YWdKtTHMviMBZFfEpcz7H+m/aZzW2qRD0u6jIUMv9IZAR8iixPQJaqco0CUSkUewAmHs X9UEZpJes0lwNIZdwASUbOtV7WpZVWPE2WLSwgNbEhr97VbdgNEr/YGq6BOOoDSZHi7e GeRiDIF/hZPeQo4HSjSsd7RD21QbbVFei8tLUMSo4UI6bfEa9gryrW23GJeBK4/nos4P yC6w== 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=jcwCmvL2zf0lF3Ank04XNaFIuqNE6u2MJVhR/WWQGZc=; b=r9FuUFWa36aPEsNYISEZTtTDpGU4r/zf8QefUZ5PNMrrAFtCGBzmtqJt0S6HZA9JWZ ASkLeYe7/ugzkWqOlRInH5uyAuUqXjhWcXjqh8iAPQBt4FzUf37arCcLw5I/6AH3Anxf qmhEDNcGONsabcBBCqniox8opgz97kr66lbnpj1rhdtKIZpo8uzhF+6xGKydFCRbLhn9 fDqU+43uF35oZ4Ri88V6N32aiovY9MrtksdIsW1A6uT5oJkSi0OVY/84m8MqdjzPjhHZ fddphwhs3uqw2diUI0wheJ0gdC64oMiKhLDpeZhepak9WZq1whIMY2Fh8cU/Iu/DQGOh MeoQ== X-Gm-Message-State: AOAM530648Sfni40M/oRDeJunq3Oa2XzScs02IFpnxpVhTwp2aAClUyb cWpSQogfqs3cOi11aVihBism4KDBpsUom7BAVqaRRhvnGpvmrZtOBY4nGOVZ9Aq0NmXA4iYoCHt GgXsW9xCD9zBUnPSge0fqouZFOHRdwmRYhgukyYQOta0PJ88TwR3VLNiVOSzhOKji+62s X-Google-Smtp-Source: ABdhPJxIQ06W5lmnWE4BuGBz9AJvw51tzkMUBqKwdv/PcZO7ZgbD/Nw38wjPFr6N5rLFbrNgkw8F4v3Hn4I= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a0c:c345:: with SMTP id j5mr10335420qvi.52.1616707635674; Thu, 25 Mar 2021 14:27:15 -0700 (PDT) Date: Thu, 25 Mar 2021 21:26:05 +0000 In-Reply-To: <20210325212609.492188-1-satyat@google.com> Message-Id: <20210325212609.492188-5-satyat@google.com> Mime-Version: 1.0 References: <20210325212609.492188-1-satyat@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v2 4/8] 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/blk.h b/block/blk.h index 3b53e44b967e..5ef207a6d34c 100644 --- a/block/blk.h +++ b/block/blk.h @@ -261,6 +261,18 @@ 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 + * that's constructed/split must be aligned to this value. + */ +static inline unsigned int bio_required_sector_alignment(struct bio *bio) +{ + struct request_queue *q = bio->bi_bdev->bd_disk->queue; + + return max(queue_logical_block_size(q) >> SECTOR_SHIFT, + blk_crypto_bio_sectors_alignment(bio)); +} + /* * 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 Thu Mar 25 21:26:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12165019 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 34759C433EA for ; Thu, 25 Mar 2021 21:28:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1635961A44 for ; Thu, 25 Mar 2021 21:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbhCYV1f (ORCPT ); Thu, 25 Mar 2021 17:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230500AbhCYV1S (ORCPT ); Thu, 25 Mar 2021 17:27:18 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 121FFC06175F for ; Thu, 25 Mar 2021 14:27:18 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id m11so4067458qtx.19 for ; Thu, 25 Mar 2021 14:27: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=MmWYjpGPDbYB5acELUWsO4encrHeC3JnTDUeENwiFbQ=; b=aRFmqGGVBIIha6D3s4IqBdbLQwRZ3iwj2MshJzhp5updTFlT3a7YfSgXP9YhP+KOM9 9IIb5Qq8xF9Aa1spaprur4lJzLKTifN7BDLkHrjxHbTnHTQjqvUGjE/2HVnQ8H+pAypO Mr1yHJr3daM8vJr4sYbI/LTSLNxlW1iMe1xZ8bRDLaLf0suSnCv5etzbLhF6tOoM7qG0 AyWUOWMJGSiscCOWPkjtJ3RfoWCwMXvzDeoypzQIFT4QI0I6BYU4BtZ84vQot6P51z7e PiWQhYOb49pXdgZddaYTGEbH7fOn4vKXPqup23Jhi/Be4/+pB70SQw1DkB7U2RZm9OW2 JiAQ== 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=MmWYjpGPDbYB5acELUWsO4encrHeC3JnTDUeENwiFbQ=; b=snyS5wCaRv+BkaGJDNsoEtOQ2uEyh2FI98/IvPxSbFoyvKPKT9fCYgz+m17kXxNbE3 YUylP8P7YfRpcrpIGt9SG3jnujnJhJGdWgI1AHL+FPcPcSTei991MFS+X7xP8eePXx+J m/WOkfga8qMqGfbBJzL2I96yWRv+nOx/pV7jPhTgTO6RI+wjGs5WUGmpoywTrbMG8hFI FYJnNU74Z7uvy0rVNJ9wR00ozORu0oC2mEqvVxM9hpJ3UvaoW4QMZhoSR5QXkLDOzUsU hztdpn8bEjcPuGYlA7GF2RVYuRSA+5ErS0K6FDz4/FJU6LNILBLGBKgAxOkBeiPv27Pm 7SZA== X-Gm-Message-State: AOAM532n5AJORBC3NM30auOyl0IgvMnPTdTsFlDiKtyMiORe8/UuZOmQ P9aG+AA2WaiEohmPpJmm79Mid8N9GhCcz+4yCRXwZyLI0vKceWwc6NtdoQkYIqe6PFI8bjZL3e4 PHYqTJZjaa3IZhVFFoKipDk18ASj3uU01SxgUWIEu8u80tQtPb0SYE7F76xB611w4NwGB X-Google-Smtp-Source: ABdhPJzb2JV84UZuCYFVQuOhDyKectwGgdGBzSsFi5sLWkxE7uSRixfPRc9GTz+M38Mip7Yj8KVLFO4Io0U= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a0c:ea83:: with SMTP id d3mr2604367qvp.62.1616707637222; Thu, 25 Mar 2021 14:27:17 -0700 (PDT) Date: Thu, 25 Mar 2021 21:26:06 +0000 In-Reply-To: <20210325212609.492188-1-satyat@google.com> Message-Id: <20210325212609.492188-6-satyat@google.com> Mime-Version: 1.0 References: <20210325212609.492188-1-satyat@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v2 5/8] 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(). Signed-off-by: Satya Tangirala --- 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 Thu Mar 25 21:26:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12165017 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 1E6F4C433E6 for ; Thu, 25 Mar 2021 21:28:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0288461A49 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230514AbhCYV1g (ORCPT ); Thu, 25 Mar 2021 17:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230501AbhCYV1T (ORCPT ); Thu, 25 Mar 2021 17:27:19 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABB02C06175F for ; Thu, 25 Mar 2021 14:27:19 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id bt20so4473224qvb.0 for ; Thu, 25 Mar 2021 14:27:19 -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=dUjmY4UWd3q7eixbohcX5KFuYVowgvQqUqs3sF7t9LE=; b=PHOfcspCaLSxOPWiT0PUYJ0/TbzwKQY+raWW2nQ/najal+rd0Pzd+SzzH8ZecubzUj JMvkIodlDPQel5IaNC6Qy5fx57hbh+DsGBXOfb4ypClW1f+dzepwGSj2UA65ZvaAacgb TAIFs5BeKt5eDnX6fOzvGxDp8NMhZUC9OVps3+0qDar/sAg2PyTVTT8QWoGktSiO/1dW EtI9BSI+nVu7nOBVctM9IHjy/Gpjdz5fZad3ZbUXqHvv4xc2g5Z/be30SgB70nvBgCaQ /dFxTQ9lgOhyB9s2L/ada+0H4bSi6UpYGInvhhFF3oWuOYy/uLyJeR8Hz6mNnR4AjO6K S2ow== 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=dUjmY4UWd3q7eixbohcX5KFuYVowgvQqUqs3sF7t9LE=; b=Nb8Pgg+TEhcex6+tF0HiFewEuxp2yoKtrlvjrvifrWcvp1WXLQW1wyENrhgh63TAGl QzJjkKDwmpSZDBUwIxeR0uEHy+wuIEUQJ/vPSxVWiTIsBaKKON5QVdOFz06mMGdbvcV/ QljIKAIkaYu7nx3m2YQXWUrLINmYKM/2NxpZbgTkMOq13QZNSvdYCEtXV/rPYJ8qH3Vb VST0AI8WljD6lXFxgiB/qvYZCWeI3UgmMceDhYtg8FeMeHy1HFi4nSvfSik/GfZctSaH sU3BRz+ZPacA6ojkzcnMa0Xh1Cf0L6kvv2HUkzEpok7EimOy7hmaZNh8Rpo+yODjDwan jh0g== X-Gm-Message-State: AOAM531xMYEvia/INZ0oYFoZI9NtEwWAjgW3Fg/gsF6D0JC2/21LETl1 XhxzPQTerkas/lg0YvSAMoz9cbPVhSqbXMS9NVyGqQLRIjyJo8Gy9Sw/j+Dyvm1HvrvC3w8NyVc 4GONQ4l/kuRkzcV3Wr5FSmznWW7UOuePlrzdeJyEcbUR7v7qRc7lBIk5DUg88SXvrKtVA X-Google-Smtp-Source: ABdhPJwO9cWW0q7qtBIPG5hTf2c6Omk6kEypxSh0Mpl1s1xS7+QtraVXMaH12sHXYXP80LwldbP16YWV5Nc= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a0c:8f09:: with SMTP id z9mr10071688qvd.25.1616707638809; Thu, 25 Mar 2021 14:27:18 -0700 (PDT) Date: Thu, 25 Mar 2021 21:26:07 +0000 In-Reply-To: <20210325212609.492188-1-satyat@google.com> Message-Id: <20210325212609.492188-7-satyat@google.com> Mime-Version: 1.0 References: <20210325212609.492188-1-satyat@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v2 6/8] 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 Reported-by: kernel test robot Reported-by: kernel test robot --- block/keyslot-manager.c | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c index 2a2b1a9785d2..fad6d9c4b649 100644 --- a/block/keyslot-manager.c +++ b/block/keyslot-manager.c @@ -450,12 +450,71 @@ 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 + */ +void blk_ksm_restrict_dus_to_queue_limits(struct blk_keyslot_manager *ksm, + struct queue_limits *limits) +{ + /* 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; + + /* + * 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. + */ + 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. + */ + 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. + */ + 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.\n", + largest_dus); + } +} + 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->limits); + + if (blk_ksm_is_empty(ksm)) + return false; + q->ksm = ksm; return true; } From patchwork Thu Mar 25 21:26:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12165021 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, 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 E0572C433E5 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6D5C61A49 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbhCYV1g (ORCPT ); Thu, 25 Mar 2021 17:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbhCYV1W (ORCPT ); Thu, 25 Mar 2021 17:27:22 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FE86C06175F for ; Thu, 25 Mar 2021 14:27:21 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id o9so4896554pgm.15 for ; Thu, 25 Mar 2021 14:27:21 -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=TnnMN4vSnburpP0p5zfJZ0YTWAM3zr+1yO4sOYNeObw=; b=iDerRLqN0sWzjLVCp6K3+9wTVIJZe/I52K0B0MAzj+s2oWoQiLuRv/6tj2akbgx/DE tklxs/X/ZZ3dc77dCHHSJU0EhzfGBWXKsrPJR+CX/CaqLlfBwgJlDrgIyBGM2bUd+/GG JxxOGWi19FLW2tYu0DPKm4bOqga6AW3MAYdw0EMI/pmPt92phB2b41Jlasrp3xqgdEpV wRbg2n5FUk1uYjjyIx+IpmaKzwleep8ORV5Rl8LawAPTOxET33rR5zBA0q1kyUfwu1hL NkEAkNWCAFAIjFC9fMVr5vm5PmpFTPTyUKmOQVduOcSuk7EPQ2Cg9/x0LOl6mqz5bOgI wL/Q== 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=TnnMN4vSnburpP0p5zfJZ0YTWAM3zr+1yO4sOYNeObw=; b=sm5rDWrucl+3YnXmrNMbhVs194VgtS8xgCrzFjKshNRrUJqY22y8G1hVeeew+C8qjF V51YeDRVhz4FkHHn6Rj9US0s+cL2zqLeQfQYg1ayuU/LduznPRkbJWgtXSlwJvYr/LGT ht/7adqpueIkrsioCyowIXzCfUDU6EJWBkfZ8DXExrANU9vEuDlMxaM7kxtccNppHr5p oL2oGKcs32mEBW7QqPyGDYcMVAcZ/Nds+f8ubexEEdFJQqzuacsF74clu4f53dDf4Kst nsokb46Qk64AtkAJ+I15pRlgfpAqJTvtCFTv7V/6Iu2w2m0YWgOY1OXVoAthjN7hl09l mepA== X-Gm-Message-State: AOAM531kKjNAisLZlzoIXe/465xN1wWdOD36rI0Ut8sjcmr0L11sczuN 7pXfsBqYsvw0AohKRYozkmZTRqgIJipkRWNjoMninvYN1kWnERj3ttvFZNl1gwv9Ea/Zm2FSfoc DN5+g8PmiDKX/DVFkfo65vP9NOUvxuQ2uCNr4qX4FIFU8REU/EhlgqiiHjrokfaRtO37B X-Google-Smtp-Source: ABdhPJy5Mf8TqiV+22r/mFlrkFLXc1kV2/znD6Fm/hdveG/IK+/VGL0qOev5BKQlzB1G/D8b93CG7TxG1XU= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a17:90a:8b97:: with SMTP id z23mr1664117pjn.1.1616707640440; Thu, 25 Mar 2021 14:27:20 -0700 (PDT) Date: Thu, 25 Mar 2021 21:26:08 +0000 In-Reply-To: <20210325212609.492188-1-satyat@google.com> Message-Id: <20210325212609.492188-8-satyat@google.com> Mime-Version: 1.0 References: <20210325212609.492188-1-satyat@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v2 7/8] 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 ffb4aa0ea68b..2903de62aaca 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 Thu Mar 25 21:26:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satya Tangirala X-Patchwork-Id: 12165013 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 BDF1DC433E3 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9473761A45 for ; Thu, 25 Mar 2021 21:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230509AbhCYV1h (ORCPT ); Thu, 25 Mar 2021 17:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbhCYV1Y (ORCPT ); Thu, 25 Mar 2021 17:27:24 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42080C061761 for ; Thu, 25 Mar 2021 14:27:23 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id r18so5023809pfc.17 for ; Thu, 25 Mar 2021 14:27:23 -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=VeqQSH4BAMfamuR0TIVDu2q/mURjw8ysmtF95aAYc5g=; b=iIB/QotjWVxSDIpkUJeHf+48IT7EqDCP7QaLJh6PM3Hv3F8UcFt/7c1mQhoByWDg5w B2UHGD+Tl9Jx/foLXk869SWCL5TI84wfOoQSFaRrWF8nQOV3EMqGDt+FmZ/tEnUhSPDn dgB6JKaUs1NSogJqeqWeQkD6m8ftwSRvlxURDFlo1NDdyLDvyE5DXiI5J53iDrAptWQS OV/7OVzexzU9nL3RGuwfSIuKvdbmnYl+8c2s29BlAUm6jjERXmfoRskDwEwnjldkUvM1 2w/0N6UamJghZiBZyvA5CCsmECbqiSwczQZsiXPOHg+gUaSDmxCwJsP2uznjv7L2nkS5 UwDA== 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=VeqQSH4BAMfamuR0TIVDu2q/mURjw8ysmtF95aAYc5g=; b=T1qnHzPuKM1TsMcbJsrPp6zr/Q0rUJowXC/25+5xPMHx2tmNIuHA1GgtBz47wYaG/u 7fZoj4FLMO6P5f/LS7KDUBmq38p3XAZIv4UhQbw2k//RcKX/SDt/lMra9WoBxROuNHVF AR5FMsFkR9T9OAvnE1YJXIZ0kQkNLHt2SSAwPZFb2Ua4/lsexmBQ0le2a24z+43XEEDs PeVvam9t4wEwlA5lbOflwbOLRSBV/rPwJdEKSz9JKGYWphclFgxWyd4mMjyz7vqyl5aj 7LDNtJpI6sz1F36wmswXh8RVuVhXybzy7zJbEQbWZXkOBqpEYGnL/jmvTxvMxbQo+Qp4 sgHg== X-Gm-Message-State: AOAM531VfSz7bhD74KrYj9DVLU06YVllzDTKTGXJiut4GGFGoMQmIioQ tNQ3PF1gj5cv3xJ4LdXKcufZhDMFVGGPyftk+FG2qAzEuqWM0uUPHCyLMcALnjQhZAMj+R+xN2u VhuXCZsZQfhw9V8l/yodRUrr4kozcy1xmoB0exYS/AIoKQoz8V4gyksdUJiFMxKWyXwmi X-Google-Smtp-Source: ABdhPJx8aHEdvXlb3UgvsOScmw6EfBXxYY/yM5TkRR0f5jYmkvclrzvTBWVREz+Lt00OU3rQNPW32DXzrfk= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a63:c84a:: with SMTP id l10mr9146122pgi.159.1616707642540; Thu, 25 Mar 2021 14:27:22 -0700 (PDT) Date: Thu, 25 Mar 2021 21:26:09 +0000 In-Reply-To: <20210325212609.492188-1-satyat@google.com> Message-Id: <20210325212609.492188-9-satyat@google.com> Mime-Version: 1.0 References: <20210325212609.492188-1-satyat@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v2 8/8] block: add WARN() in 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() if the number of sectors is not aligned. (bounce.c was not updated since it's legacy code that won't interact with inline encryption). 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 26b7f721cda8..cb348f134a15 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1458,6 +1458,7 @@ struct bio *bio_split(struct bio *bio, int sectors, BUG_ON(sectors <= 0); BUG_ON(sectors >= bio_sectors(bio)); + WARN_ON(!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))