From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 F14AFC35646 for ; Fri, 21 Feb 2020 17:04:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C48D8206E2 for ; Fri, 21 Feb 2020 17:04:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AV6Cw8ov" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728056AbgBUREf (ORCPT ); Fri, 21 Feb 2020 12:04:35 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:41486 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728028AbgBUREf (ORCPT ); Fri, 21 Feb 2020 12:04:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=r3W9uQBOJlV/Av1C4P5QJ8rWtko3f0+LGkNeNqVgIXE=; b=AV6Cw8ovuehrTohFGMfQ7n0kse bjrdnD9nESXI0I3PhTjjlM1TLq5ja8b35TsbwUSuOz6O3K1S8kAcssyZP1MCGHcG4kw/lfza5fkeb QOnZfCeaRELcgK09zo2800vd04X5tYSYTSi6pR24Pv7o7U2qmROm4epqCjmdubnrlnmVFNqKTUfNu 87qqVl3NeMxxEMlK1BEUhoafXDd8nMTCXTvOtVD3ptQxLN36wRRJoYUQ/FDv2hQsUqZ5LFEcVCpUg Nt8pMcATyiWCCDn6xIrWVuAgQbk1q7RAv8dNR7WD1b0IYd/UQOWjvoWynx1dI6wC7JPPah9Nr35ng KSATh/Qw==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j5Bj8-0004qU-9u; Fri, 21 Feb 2020 17:04:34 +0000 Date: Fri, 21 Feb 2020 09:04:34 -0800 From: Christoph Hellwig To: Satya Tangirala Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, Barani Muthukumaran , Kuohong Wang , Kim Boojin Subject: Re: [PATCH v7 1/9] block: Keyslot Manager for Inline Encryption Message-ID: <20200221170434.GA438@infradead.org> References: <20200221115050.238976-1-satyat@google.com> <20200221115050.238976-2-satyat@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200221115050.238976-2-satyat@google.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org > +#ifdef CONFIG_PM > +static inline void blk_ksm_set_dev(struct keyslot_manager *ksm, > + struct device *dev) > +{ > + ksm->dev = dev; > +} > + > +/* If there's an underlying device and it's suspended, resume it. */ > +static inline void blk_ksm_pm_get(struct keyslot_manager *ksm) > +{ > + if (ksm->dev) > + pm_runtime_get_sync(ksm->dev); > +} > + > +static inline void blk_ksm_pm_put(struct keyslot_manager *ksm) > +{ > + if (ksm->dev) > + pm_runtime_put_sync(ksm->dev); > +} > +#else /* CONFIG_PM */ > +static inline void blk_ksm_set_dev(struct keyslot_manager *ksm, > + struct device *dev) > +{ > +} > + > +static inline void blk_ksm_pm_get(struct keyslot_manager *ksm) > +{ > +} > + > +static inline void blk_ksm_pm_put(struct keyslot_manager *ksm) > +{ > +} > +#endif /* !CONFIG_PM */ I think no one is hurt by an unused dev field for the non-pm case. I'd suggest to define the field unconditionally, and replace all the above with direct calls below. > +/** > + * blk_ksm_get_slot() - Increment the refcount on the specified slot. > + * @ksm: The keyslot manager that we want to modify. > + * @slot: The slot to increment the refcount of. > + * > + * This function assumes that there is already an active reference to that slot > + * and simply increments the refcount. This is useful when cloning a bio that > + * already has a reference to a keyslot, and we want the cloned bio to also have > + * its own reference. > + * > + * Context: Any context. > + */ > +void blk_ksm_get_slot(struct keyslot_manager *ksm, unsigned int slot) This function doesn't appear to be used at all in the whole series. > +/** > + * blk_ksm_put_slot() - Release a reference to a slot > + * @ksm: The keyslot manager to release the reference from. > + * @slot: The slot to release the reference from. > + * > + * Context: Any context. > + */ > +void blk_ksm_put_slot(struct keyslot_manager *ksm, unsigned int slot) > +{ > + unsigned long flags; > + > + if (WARN_ON(slot >= ksm->num_slots)) > + return; > + > + if (atomic_dec_and_lock_irqsave(&ksm->slots[slot].slot_refs, > + &ksm->idle_slots_lock, flags)) { > + list_add_tail(&ksm->slots[slot].idle_slot_node, > + &ksm->idle_slots); > + spin_unlock_irqrestore(&ksm->idle_slots_lock, flags); > + wake_up(&ksm->idle_slots_wait_queue); > + } Given that blk_ksm_get_slot_for_key returns a signed keyslot that can return errors, and the only callers stores it in a signed variable I think this function should take a signed slot as well, and the check for a non-negative slot should be moved here from the only caller. > diff --git a/include/linux/bio.h b/include/linux/bio.h > index 853d92ceee64..b2103e207ed5 100644 > --- a/include/linux/bio.h > +++ b/include/linux/bio.h > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > > #ifdef CONFIG_BLOCK > /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */ This doesn't belong here, but into the patch that actually requires crypto definitions in bio.h.