Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1791472imi; Sat, 23 Jul 2022 18:23:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s2MCvP6aHJERdO4WkzDdrjceZMFLaCAE4L82khEC7WCaC7Av19g+AG9ywJ8gObvBHVQqV8 X-Received: by 2002:a05:6402:b37:b0:43b:c447:17cf with SMTP id bo23-20020a0564020b3700b0043bc44717cfmr6441202edb.280.1658625816696; Sat, 23 Jul 2022 18:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658625816; cv=none; d=google.com; s=arc-20160816; b=Bzfgavx46oWnHNNg+uRItv8uYSOSGQH/z/xxEqOwwHxcGEiXb2I1SEU4rYuM1Cd/XQ /+k/AGeEscTxzESK6Ov4drELUq2wgoXv7PICo+Q9X4b28fC0yFg2SClCJg8r0Pbt4sQ0 iWMMCmiv2/bH/S0+70Til/YNQNuIIQiZ3W0kiQylQOybWEZuTm60u0BjGSlZwI+qHrz+ H3EYqziVCCo+WUymT5Wg2sUljZmvfVyzrB0f/CWz5PUV4reEYfI3k/POTNCo5Rk7+hyQ SCC6RW8esmtb47d1HNr/6VzWxapbFxEHIv6d7/aVgoXX2doDXlbs3Kn6v1ZYALDJX16C 4F7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GCHxbZJ0RrbE8rppIVx8p8pp4VieOhv6CIhqSUNQCI8=; b=qIqDNX4/8f7cHnvIguCpCzqofjEH4sgZkELaDzshHvPJpvb4UfR0kcR6yXswXHEJob NNRnEqkOW1ORfbe3lMqyg5BjwWERkDUnoM5zAnhwqgCeiSSPEC5aIasnGyDG7H4dD80e T03W8361DxWRNLYBupqCR4uaJxFU303ZEfh1ignLtumtWyGWi3Oz9+E3xZPESQKgWEjc pdS62q+r+OiNWQ6TQGkMqcYq6wT7ea1sTX2uIjofM0y2ZNxrIgBP1t7G5TUW3ay3Qtq2 lchN3IhC7yEuAj/Y1XogeR6Mi31ZRRgYqDHNztMhvaW42xLbAataFWh8e2qI4abtV8fa 49hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (bad format) header.i=@dorminy.me header.s=mail header.b=K407mVNV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=dorminy.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020aa7c0c8000000b0043be98925a2si486992edp.499.2022.07.23.18.23.11; Sat, 23 Jul 2022 18:23:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=neutral (bad format) header.i=@dorminy.me header.s=mail header.b=K407mVNV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=dorminy.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239622AbiGXAzT (ORCPT + 99 others); Sat, 23 Jul 2022 20:55:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239460AbiGXAzF (ORCPT ); Sat, 23 Jul 2022 20:55:05 -0400 Received: from box.fidei.email (box.fidei.email [IPv6:2605:2700:0:2:a800:ff:feba:dc44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAB1F1A3B9; Sat, 23 Jul 2022 17:54:53 -0700 (PDT) Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id 20B9980BB8; Sat, 23 Jul 2022 20:54:52 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1658624093; bh=tQkA6kJ/fCFGZgvfYo9gPeiRaxwV0FytgcRAx/xmXQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K407mVNVxWm2FHWCSlWISp7jXve+ywEy0YTTGzp+IFTXp8JHnmGpbT5KU5vjKRlD8 AsvvOs34OZXjZ6w3658tqnGgq9QWxcT0WmwqXdY79vaoeO3MWuBRDLqN8cnxgoZZbR j6y40xoDbc49XcdrFE2fFwuog2sXHeputxqTCZQX9tBDEupOyIQfdO1LsOQfspUj7d HaH7GSIDjNzBb2eUy0vWxxDaas9ZiKfaNbXV2oGt26jSGzyJQ00yo9JNm1lEztQu3s 5cT59UrfJkmL9vAPqv+RQOJaB0MBPCENaKMQm3TPh8ggODzaC5Cx4RiA3zl/0bGJ8C sgcqj9Z7vVNcQ== From: Sweet Tea Dorminy To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, osandov@osandov.com, kernel-team@fb.com Cc: Sweet Tea Dorminy Subject: [PATCH RFC v2 13/16] btrfs: reuse encrypted filename hash when possible. Date: Sat, 23 Jul 2022 20:53:58 -0400 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Omar Sandoval For encrypted fscrypt_names, we can reuse fscrypt's precomputed hash of the encrypted name to generate our own hash, instead of rehashing the unencrypted name (which may not be possible if it's a nokey name). Signed-off-by: Omar Sandoval Signed-off-by: Sweet Tea Dorminy --- fs/btrfs/ctree.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 9fab4d33a326..30f390c01943 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2773,7 +2773,10 @@ static inline void btrfs_crc32c_final(u32 crc, u8 *result) static inline u64 btrfs_name_hash(const struct fscrypt_name *name) { - return crc32c((u32)~1, fname_name(name), fname_len(name)); + if (fname_name(name)) + return crc32c((u32)~1, fname_name(name), fname_len(name)); + else + return name->hash | ((u64)name->minor_hash << 32); } /* @@ -2782,8 +2785,20 @@ static inline u64 btrfs_name_hash(const struct fscrypt_name *name) static inline u64 btrfs_extref_hash(u64 parent_objectid, const struct fscrypt_name *name) { - return (u64) crc32c(parent_objectid, fname_name(name), - fname_len(name)); + /* + * If the name is encrypted and we don't have the key, we can use the + * fscrypt-provided hash instead of the normal name, and do the steps + * of crc32c() manually. Else, just hash the name, parent objectid, + * and name length. + */ + if (fname_name(name)) + return (u64) crc32c(parent_objectid, fname_name(name), + fname_len(name)); + else + return (__crc32c_le_combine(parent_objectid, + name->hash, + fname_len(name)) ^ + __crc32c_le_shift(~1, fname_len(name))); } static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) -- 2.35.1