Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp735271pxu; Thu, 15 Oct 2020 15:25:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0G7RGoGtxu6pE56kqvpRcQOUrU+MKA/8a/c0/zezbyhW3GDI4A+e4nugC0PliCBcKLpsJ X-Received: by 2002:aa7:d781:: with SMTP id s1mr730032edq.102.1602800724581; Thu, 15 Oct 2020 15:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602800724; cv=none; d=google.com; s=arc-20160816; b=UQR3L2YETbvcHLP1GzSgQV8/E1hNrFdtCGXNd0WCRq+VZQ7tCNpnZixlSHZm/AlQB8 6RdfND2H7CsNKSoeyLzaQVn0z9Ha4JMhcldhRZsnZw38tiOBHs3zwxcQWfKcEpec47OB UwexfCDcbas9Fz9hHmg0vhDTqwslGz2s4LmIxbs10b53ARRL7IOU7RRcMSjYQCiqdQPJ h/G5djCeIUsmI1FSY8kFaSU/CvJUpOZVHJ7FHV9h7Vj4y31Z8Odf/ODPZM9z0Nh8diSp cXPBuFRVhohGH8o8HYOnulFgBDt+rzRMw69arFerH73LH+GREgXvXuceOtCt8bAqVcgT VF6g== 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:sender:dkim-signature; bh=ch6nvSub6LPLhqFDO+1Ngo8vwhJFQ7f44Mxixhhd0C0=; b=sSLRrLPLOAVjRZaUmScEFzSj1Qyo/ej6kQdgjxtnEYIXbSB3HG35I/vA8yI3TpUnwW MGny1RrLIBVBBYJij46CQ/AR64/SbSRSqfepxhktKb7bpHADMUFiLXRE2AoZLc7fxQIi mZiK3EiGVSIk5G24f+o7tMm1U568777mfhJ7kDesFXAL8FHxMf4x/gG61mlwHpWZGxAf QHqo3588TPcyjkEiv9rG5TkHEkUAtr/xjWNghKARlRcSSKRIqp0yQeSBISYbZhXPCIG1 /4ifg6/okiT/Trwa80uyWqfAMHVtk8oS+883K/ZyuPIzY+sLw8yAJAHVibWB73XP97xk DDfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=erKXgeEJ; 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 y20si260749ejj.185.2020.10.15.15.25.02; Thu, 15 Oct 2020 15:25:24 -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=erKXgeEJ; 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 S1731479AbgJOVqo (ORCPT + 99 others); Thu, 15 Oct 2020 17:46:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731432AbgJOVqn (ORCPT ); Thu, 15 Oct 2020 17:46:43 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0008FC0613D2 for ; Thu, 15 Oct 2020 14:46:40 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id 97so81555plb.4 for ; Thu, 15 Oct 2020 14:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=ch6nvSub6LPLhqFDO+1Ngo8vwhJFQ7f44Mxixhhd0C0=; b=erKXgeEJdd65aOt7EvfIQrxEVMZDG6HulO74oHjfoANkWKvJnE49mXrq+Hsptz3+Ga FxTzPcfQyOceq3aIFKmQSMq5SSM0AgEtQ7K34yAU/dBuPTorhKqCxpI2iO9EWwXi/Bt/ +uRsCiu8JT9QqCuMPIxooBMbVg2Ufs/lmX9nFS1zqJpr81ZwA8hQrgcB6V2+T4JbUYEi SrH4a1yeX+iE3V11cxOaHeaLHrNQtRZ52oCRqKocsGHY+9GZnJJZwy2Sg0f2Bfygwev+ yfKVoSDTZARjHUj2javmg2ADI3z8nFeVKPtCDc1lJ6Qi6t382sWcsB2cBKiL4+77SqOV AfSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ch6nvSub6LPLhqFDO+1Ngo8vwhJFQ7f44Mxixhhd0C0=; b=mWQ1tv6/MKIHzZ5Bmy/s1txbOtLp+Oho8WxWmSKcez7IYuo8pHlY3CJEiOccqqRvYg NV0bCKTx1W6QllqL9Uoe0ZE63zYifIde4J2PVEtRyCD8JqW9RFbkYc4am996+pDjOCEL c/ngl+cRqOAbta8ayzy/eOxhK4C6x/DT3a/QXYM6iW8eA4tC68v9cU4I4Qonp81HpIQx I7V9aGAYX8L5UgTnbbjgdZJtf1M1RhpJJTD+jRoX5iSiQgPAcFswp7Rms4Otz06St4mZ ih4xf2IwjtPHEq6T3LsX0khSKSZF0/H54HVym7ta6jry3Tbou9EApovjYAxQe+yMLdFP Axcg== X-Gm-Message-State: AOAM531NlxqNjKpLAXl80b/if8FxRaNH2uAhbhJ2/ILLEqRz7KWcGZfl WZVTUD7MN2iK3d32pOIigEF1Qvt5yGE= Sender: "satyat via sendgmr" X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a17:90a:940c:: with SMTP id r12mr78628pjo.1.1602798400036; Thu, 15 Oct 2020 14:46:40 -0700 (PDT) Date: Thu, 15 Oct 2020 21:46:29 +0000 In-Reply-To: <20201015214632.41951-1-satyat@google.com> Message-Id: <20201015214632.41951-2-satyat@google.com> Mime-Version: 1.0 References: <20201015214632.41951-1-satyat@google.com> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog Subject: [PATCH v2 1/4] block: keyslot-manager: Introduce passthrough keyslot manager From: Satya Tangirala To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Cc: Jens Axboe , Alasdair Kergon , Mike Snitzer , Eric Biggers , Satya Tangirala Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The device mapper may map over devices that have inline encryption capabilities, and to make use of those capabilities, the DM device must itself advertise those inline encryption capabilities. One way to do this would be to have the DM device set up a keyslot manager with a "sufficiently large" number of keyslots, but that would use a lot of memory. Also, the DM device itself has no "keyslots", and it doesn't make much sense to talk about "programming a key into a DM device's keyslot manager", so all that extra memory used to represent those keyslots is just wasted. All a DM device really needs to be able to do is advertise the crypto capabilities of the underlying devices in a coherent manner and expose a way to evict keys from the underlying devices. There are also devices with inline encryption hardware that do not have a limited number of keyslots. One can send a raw encryption key along with a bio to these devices (as opposed to typical inline encryption hardware that require users to first program a raw encryption key into a keyslot, and send the index of that keyslot along with the bio). These devices also only need the same things from the keyslot manager that DM devices need - a way to advertise crypto capabilities and potentially a way to expose a function to evict keys from hardware. So we introduce a "passthrough" keyslot manager that provides a way to represent a keyslot manager that doesn't have just a limited number of keyslots, and for which do not require keys to be programmed into keyslots. DM devices can set up a passthrough keyslot manager in their request queues, and advertise appropriate crypto capabilities based on those of the underlying devices. Blk-crypto does not attempt to program keys into any keyslots in the passthrough keyslot manager. Instead, if/when the bio is resubmitted to the underlying device, blk-crypto will try to program the key into the underlying device's keyslot manager. Signed-off-by: Satya Tangirala --- block/keyslot-manager.c | 41 +++++++++++++++++++++++++++++++++ include/linux/keyslot-manager.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c index 35abcb1ec051..5ad476dafeab 100644 --- a/block/keyslot-manager.c +++ b/block/keyslot-manager.c @@ -62,6 +62,11 @@ static inline void blk_ksm_hw_exit(struct blk_keyslot_manager *ksm) pm_runtime_put_sync(ksm->dev); } +static inline bool blk_ksm_is_passthrough(struct blk_keyslot_manager *ksm) +{ + return ksm->num_slots == 0; +} + /** * blk_ksm_init() - Initialize a keyslot manager * @ksm: The keyslot_manager to initialize. @@ -198,6 +203,10 @@ blk_status_t blk_ksm_get_slot_for_key(struct blk_keyslot_manager *ksm, int err; *slot_ptr = NULL; + + if (blk_ksm_is_passthrough(ksm)) + return BLK_STS_OK; + down_read(&ksm->lock); slot = blk_ksm_find_and_grab_keyslot(ksm, key); up_read(&ksm->lock); @@ -318,6 +327,16 @@ int blk_ksm_evict_key(struct blk_keyslot_manager *ksm, struct blk_ksm_keyslot *slot; int err = 0; + if (blk_ksm_is_passthrough(ksm)) { + if (ksm->ksm_ll_ops.keyslot_evict) { + blk_ksm_hw_enter(ksm); + err = ksm->ksm_ll_ops.keyslot_evict(ksm, key, -1); + blk_ksm_hw_exit(ksm); + return err; + } + return 0; + } + blk_ksm_hw_enter(ksm); slot = blk_ksm_find_keyslot(ksm, key); if (!slot) @@ -353,6 +372,9 @@ void blk_ksm_reprogram_all_keys(struct blk_keyslot_manager *ksm) { unsigned int slot; + if (blk_ksm_is_passthrough(ksm)) + return; + /* This is for device initialization, so don't resume the device */ down_write(&ksm->lock); for (slot = 0; slot < ksm->num_slots; slot++) { @@ -394,3 +416,22 @@ void blk_ksm_unregister(struct request_queue *q) { q->ksm = NULL; } + +/** + * blk_ksm_init_passthrough() - Init a passthrough keyslot manager + * @ksm: The keyslot manager to init + * + * Initialize a passthrough keyslot manager. + * Called by e.g. storage drivers to set up a keyslot manager in their + * request_queue, when the storage driver wants to manage its keys by itself. + * This is useful for inline encryption hardware that doesn't have the concept + * of keyslots, and for layered devices. + * + * See blk_ksm_init() for more details about the parameters. + */ +void blk_ksm_init_passthrough(struct blk_keyslot_manager *ksm) +{ + memset(ksm, 0, sizeof(*ksm)); + init_rwsem(&ksm->lock); +} +EXPORT_SYMBOL_GPL(blk_ksm_init_passthrough); diff --git a/include/linux/keyslot-manager.h b/include/linux/keyslot-manager.h index 18f3f5346843..323e15dd6fa7 100644 --- a/include/linux/keyslot-manager.h +++ b/include/linux/keyslot-manager.h @@ -103,4 +103,6 @@ void blk_ksm_reprogram_all_keys(struct blk_keyslot_manager *ksm); void blk_ksm_destroy(struct blk_keyslot_manager *ksm); +void blk_ksm_init_passthrough(struct blk_keyslot_manager *ksm); + #endif /* __LINUX_KEYSLOT_MANAGER_H */ -- 2.29.0.rc1.297.gfa9743e501-goog