Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp803472pxf; Thu, 25 Mar 2021 14:31:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3hWGNis8xS3aCn+fVtzttcWI1D7r4nuR7SLQvrXatLv5W6QvRZQtPd4ZgYGCXoEdJpckr X-Received: by 2002:a05:6402:1004:: with SMTP id c4mr11452392edu.364.1616707913793; Thu, 25 Mar 2021 14:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616707913; cv=none; d=google.com; s=arc-20160816; b=L0iq3RL7EUJiYa1ReQMmo06RUvuX3O6cD36scIkVSKB5ZnxTJt7Mg9DZce9yoO7L58 Ufp8SEweeRgLUTV8lIFYSyLu0gEeMIOQgQB15hcDRjRhWBwcIKc4azPYISZIbVWSpagb 9WuFSIYy7ZoAfyhy8t0+z/AaPK/2lZ1OwQ50e2tGcYNnnX/VchX5SvdTCpB7jJGHOzzs NdnR/Ae8FuCw8i10IKMtaO9MfT4Lg3zqD+NhKf6JH88tujvGbcq2mlHXo2FBjG+7VF/g DEjm+BtKfMvG9w1HFq4Es3fvnwfEuTmAe9hWTaKXJtJCLxcKEh0fCBpp8NTA4MGKFiFD vKQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=dUjmY4UWd3q7eixbohcX5KFuYVowgvQqUqs3sF7t9LE=; b=fYWEbDCM53ueXtutdG+Ih0bVGgNfZoeW6qMrnFardmZDEbWyTReORw5p1iZ4BCO3Cp F3O+HfmhofrfEQoQEDEISJopjnhy5lXjxZp9/PNh045pPpZVOwzS41XRK6fFsAaoB8eV u+THnIVBMVC79Ov+TILSsLc0IYHkebGGanmONLF13yo9APYt6Gs37pZKqpFG4bSsZPCs WavwySK8U9VfSR6kkIkBbGFXsEjpLpy5D3XzGKzYOk0wWgdjoB1tbYdM8or9mh3vo1Ai AKG9bwjR0qY/jXSTiixxUJJ2x9coJ+cRoDuhsttACyv/MprTs7ZEN0GL+kudWYVVkWfC ks3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PHOfcspC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id da5si864703edb.565.2021.03.25.14.31.31; Thu, 25 Mar 2021 14:31:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PHOfcspC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231180AbhCYV1m (ORCPT + 99 others); Thu, 25 Mar 2021 17:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230505AbhCYV1T (ORCPT ); Thu, 25 Mar 2021 17:27:19 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E747C06174A for ; Thu, 25 Mar 2021 14:27:19 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id u17so4445825qvq.23 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=IgeT/YMV1h0xbRL6PzKNXoYWz71A7BW4YihIMSIlNTcRPeYJYAn0BL9PLBCtFgVsQm rHQcANjS2KvHJdalM4SYpE2p65UX5ltoRMFhAgRXF2V3ft31JyCRkuZv02UF50QZIL/X 0kjMRFQRbRq5m21CGChI95sIYsAlb3QiiVg17j8qzLSNQCWoCzKeingoDQ2p2x3+FF/Y zWRyHS5pf4PLsTcl4vjqAAbrvTrJWDye92lVmQ1bZiobxvJQcjRtD3P6ojd+7gPWpwjU KDB5skNPxlVTCkbHx7NqJSJoBXnazNdhdtB93Q4FjnDG98oJ68TSW6gIribHZv3VMsce fbjg== X-Gm-Message-State: AOAM533gfiTajRHVDGU0rojFokJDQrRHKBKEMriaXYLCVze1fLp57jF6 UxUcsTGjpOOY6Q35sgDn4eb7a2M4w3g= 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 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; } -- 2.31.0.291.g576ba9dcdaf-goog