Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2111268ybv; Fri, 21 Feb 2020 09:05:12 -0800 (PST) X-Google-Smtp-Source: APXvYqyAf3+Il/wSh70vDExca/UnJgl8du7mDaYJXCTKeRbx6f44KL4qe3FTslNQyPs8KhyV6U5g X-Received: by 2002:a9d:66c1:: with SMTP id t1mr26283603otm.73.1582304712647; Fri, 21 Feb 2020 09:05:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582304712; cv=none; d=google.com; s=arc-20160816; b=nA1/5C072pk4NCV9PYRmbCMYcg/lBZRTdQnZx7yomjGnVF4IBTvEzQQfO6ECQA+I3P pQVEleQYn0lxwMc0c4g1qJH/nqMkJVM5mqO8DPe+bJ8TLtG1YfIrdGFj1KkwizzUncl4 JQM7ljFMeXpc8F0KyQwhkdRqGN4rj1mWNbDXb3Q6cvdQfLyFOV23rJGMkXhUXajkEMH+ RUWRP67mMrz1FrWuDVNeKIsS8owuuOTthikgMRrwmMCHl/OeBcIb0ZPeXsuoeihLtn18 4wquJgBCylJNemDK8ld70MG7TM/9yJ777F5BPB8JlTAkGmK1lEjZHJxuwmM9U8jE0m6N i61Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=r3W9uQBOJlV/Av1C4P5QJ8rWtko3f0+LGkNeNqVgIXE=; b=RBTphhrMvdTGKPgYLPvjH50jX2R8k9lMFUeeHOLnEcnnx6XE3ydidnj8nX3twarrPE Sq2ha05TAQZXrm5FaiwgrpqH439TfGK6FPAPhe2FkZ4/BD+poYhypNjho6Dl9hjxSyJ7 Vo8e2fLWphPzohlZXVc/wFQbHAVuZ3DcJ1LUeEuPr/7JVdCOK6kBZ37V6EKZMFRBLM2T 8a+9XjgrMwAnrNbXplo9XdSBuMw61MnCzVzRD050xPEDMwCsii1gaIamnryoXirOCKdt 2iFw7blsR1YCxDaoScbeaZyOuX6YENhTjYYa+64jKkStdca48gIy467gvsdufNMMR5QT 4LRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AV6Cw8ov; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i20si1684426otk.270.2020.02.21.09.04.52; Fri, 21 Feb 2020 09:05:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AV6Cw8ov; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728071AbgBUREf (ORCPT + 99 others); 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-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@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.