Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3590709ybz; Mon, 27 Apr 2020 19:15:28 -0700 (PDT) X-Google-Smtp-Source: APiQypImTUiblSJY79exfwe3ijWx2sFWCIHUVN+IUkadczF0lA/pu+aXvrC9NYSv1i/cL7NS5B9K X-Received: by 2002:a05:6402:31b1:: with SMTP id dj17mr20139011edb.146.1588040128589; Mon, 27 Apr 2020 19:15:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588040128; cv=none; d=google.com; s=arc-20160816; b=MA6+LSYaW0yYMal8sMc0BnoTsEOoaos82eMvGD7h5mcRBA7ntzZMkORch+hz00EkIG dtFizF082fn9Ca+Ovrb1RkV9jLmfh7vgx1qw2NnyMWhtt9VLYREguXWAkBF2fD6pSktc Bspzg02chrukLfqvs4e6bCNy0HdlKcheeSx6DiZiltHaGGMvI2sknr90dZAUi0jfArep jasmXflglLzDSdWIOz0c23hwkE09JPv3Um5XxWamjYq8uSgUB8EeiKposhr0t5TK1paY +NrXDtzjpsTjNpJRzvcFVgl+X9tC0Di3+N0injzH09UtFI8uGxz0nENckmvu/fV7Jz7t 5iUQ== 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=dNDHgCC2Tbezyzaz1jik79FYVEDQH+X+/Zl/FX9zdvE=; b=C++8pqKB8+S21oXVQPCuWE6VCkr1n7jjwZ7j5spQV1BjnD/qdDltqQsofD2yHpd880 hS1IqenweaCBJyCs1g4JEAK2nhlYhgAbPcM4xe5W/sP3kWINVG2RXisN8Amo2zFcfN6w vy8bTbzn1jLlqAPIHi/yK3tT2N2YDFDkjBZlk5u/kzezwcA+bpWv32oQRSmqe7INh+bE s7hCqP7TRwzNVENlBgqZyCGxDa8y3mUUJbK1A48yml6VUDwTh73mwEMQb6g3YA1UnG4V eu8cR6NcR0nAndSXeBmubV3uCVxqruOF/4vsvvMBc8qFaIWvyG8B3AU3YgepNhYu25O+ 3LZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KnwnZ++v; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 k15si884093ejs.61.2020.04.27.19.14.52; Mon, 27 Apr 2020 19:15:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=KnwnZ++v; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 S1726272AbgD1COr (ORCPT + 99 others); Mon, 27 Apr 2020 22:14:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726312AbgD1COr (ORCPT ); Mon, 27 Apr 2020 22:14:47 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F7A6C03C1AC for ; Mon, 27 Apr 2020 19:14:47 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id n24so7718133plp.13 for ; Mon, 27 Apr 2020 19:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dNDHgCC2Tbezyzaz1jik79FYVEDQH+X+/Zl/FX9zdvE=; b=KnwnZ++vm3JMJEkBfjFTzuMZedHlKQkCikCMg8o+5SWaFUknNqNFJgJ3P2p9Bu58HM uf017eQcybmhKeNlI5fCSw+3L8DgrWC0bVbQgF+oc8afCfYiOFaqp3b/LyOGYDXw57Uj QuOKGbFyCv2xwx1rc1Vb7FqncrawNMyBdsB/86iAof/qDTTDi8hg+1WYx/5AFR7ebw4n sQ/ZxXJZQZcKzI3CfLRPf/Fz31PKeWGx/2vzUUpwYkPulnIEOq6wrS3fwVu+YWWfJChZ N8ChLbccFNspOjuqbjvUfB4gcGKYV27YIq0wzgMlqrHmCRN1evUqwui+9EvxyLrUj/S8 NQQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dNDHgCC2Tbezyzaz1jik79FYVEDQH+X+/Zl/FX9zdvE=; b=XJl98qAqp6a91D4UoKSSoJQI+cgTn/jtBkP8ZdnxKxYhyWlTrJKQEs7aj0iH2yflYG 6WR/I2cNPrQULw8NSNPKQ1H73VcGrRMnGw6KgmKts+YWldNHNFeRCmvM+EDzOnNu+afi Kv7j5N4OiHDYtR67Hu25WY1GmhscciReEhh8UAe57iZhMqHCT78rh2IFIcbYqEFESup4 U7q3aIWRFTg3lUxFijSx+E3Ak4F8Fqde6cXRLQ8+NwhyuQI/duw3p/Vq5WJG01e6/1qF DOMAFeLm44n/WFvb8BewyBD92c48iHj84Mjns7M2aXQLItGCfvQvj3lyyn2nYgAAnbDx n1Eg== X-Gm-Message-State: AGi0PuawADLENVc4jKB1ELA7uKTObLnsSqIemRUVNRZZrJitQz3SlUli Jj7SajSkRhDrSn7VEzDZh1AM2w== X-Received: by 2002:a17:90a:68cb:: with SMTP id q11mr2161545pjj.15.1588040086489; Mon, 27 Apr 2020 19:14:46 -0700 (PDT) Received: from google.com (56.4.82.34.bc.googleusercontent.com. [34.82.4.56]) by smtp.gmail.com with ESMTPSA id q64sm13385299pfc.112.2020.04.27.19.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2020 19:14:45 -0700 (PDT) Date: Tue, 28 Apr 2020 02:14:41 +0000 From: Satya Tangirala To: Christoph Hellwig 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 , Eric Biggers Subject: Re: [PATCH v10 02/12] block: Keyslot Manager for Inline Encryption Message-ID: <20200428021441.GA52406@google.com> References: <20200408035654.247908-1-satyat@google.com> <20200408035654.247908-3-satyat@google.com> <20200422092250.GA12290@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422092250.GA12290@infradead.org> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, Apr 22, 2020 at 02:22:50AM -0700, Christoph Hellwig wrote: > > +bool blk_ksm_crypto_cfg_supported(struct blk_keyslot_manager *ksm, > > + const struct blk_crypto_config *cfg) > > +{ > > + if (!ksm) > > + return false; > > + return (ksm->crypto_modes_supported[cfg->crypto_mode] & > > + cfg->data_unit_size) && > > + (ksm->max_dun_bytes_supported >= cfg->dun_bytes); > > Nit: why not expand this a bit to be more readable: > > if (!(ksm->crypto_modes_supported[cfg->crypto_mode] & > cfg->data_unit_size)) > return false; > if (ksm->max_dun_bytes_supported < cfg->dun_bytes) > return false; > return true; > > > +int blk_ksm_evict_key(struct blk_keyslot_manager *ksm, > > + const struct blk_crypto_key *key) > > +{ > > + struct blk_ksm_keyslot *slot; > > + int err = 0; > > + > > + blk_ksm_hw_enter(ksm); > > + slot = blk_ksm_find_keyslot(ksm, key); > > + if (!slot) > > + goto out_unlock; > > + > > + if (atomic_read(&slot->slot_refs) != 0) { > > + err = -EBUSY; > > + goto out_unlock; > > + } > > This check looks racy. Yes, this could in theory race with blk_ksm_put_slot (e.g. if it's called while there's still IO in flight/IO that just finished) - But it's currently only called by fscrypt when a key is being destroyed, which only happens after all the inodes using that key are evicted, and no data is in flight, so when this function is called, slot->slot_refs will be 0. In particular, this function should only be called when the key isn't being used for IO anymore. I'll add a WARN_ON_ONCE and also make the assumption clearer. We could also instead make this wait for the slot_refs to become 0 and then evict the key instead of just returning -EBUSY as it does now, but I'm not sure if it's really what we want to do/worth doing right now...