From patchwork Thu Mar 15 15:08:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10284723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 986F260386 for ; Thu, 15 Mar 2018 15:08:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E37328B0B for ; Thu, 15 Mar 2018 15:08:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82C6828B1F; Thu, 15 Mar 2018 15:08:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35D0128B0B for ; Thu, 15 Mar 2018 15:08:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752667AbeCOPIh (ORCPT ); Thu, 15 Mar 2018 11:08:37 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:4231 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752797AbeCOPIa (ORCPT ); Thu, 15 Mar 2018 11:08:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1521127618; x=1552663618; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=68juIPkTd3olZxdD36guX84/TB2nJ2QFqPbRbPOYNbM=; b=Gd17/uyuD0/oYMKIU6vLaA4Be6TGPevlcAa+uXTGDs40g1/4Sk/gGdgO U0wxXw9ytlvrDXvAqBTUWT3L+Gin1dMJuHokjiaERdpxtInlQCfVVR5dB Ajn7LcoNfPJV11CeopGzgeXD6VA3GvtGIjx/6jqR2x1A+keXfijQffyae UZse+GHPWEhZONfm7cGWoo60EDm2y0dLu5GfG61qGKfiWh3B7dTvXgXHy 1c7kr5CZGxEl+zpQGhqLm5d4VNwh2JC/FtcXXWIg+a2SoOCq5DoTT/TsU 9ViNq/nY+SKWxSs9bVTANe5hbU5VS+E48gjGU5pnR3Y8m2GFGpLuj7OvG Q==; X-IronPort-AV: E=Sophos;i="5.47,471,1515427200"; d="scan'208";a="170233281" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Mar 2018 23:26:39 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 15 Mar 2018 08:01:15 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.171.236]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2018 08:08:18 -0700 From: Bart Van Assche To: Michael Lyle , Kent Overstreet , Coly Li Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche Subject: [PATCH 15/16] bcache: Fix an endianness bug Date: Thu, 15 Mar 2018 08:08:13 -0700 Message-Id: <20180315150814.9412-16-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180315150814.9412-1-bart.vanassche@wdc.com> References: <20180315150814.9412-1-bart.vanassche@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ensure that byte swapping occurs on big endian architectures when reading or writing the superblock. Signed-off-by: Bart Van Assche --- drivers/md/bcache/bcache.h | 12 ++++++++++++ drivers/md/bcache/super.c | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 72b1ea4576d9..50ddc78596bf 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -784,6 +784,18 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k, bch_crc64(p, q - p); \ }) +/* + * Variant of csum_set() for data structures in which (i)->keys has type + * __le16. + */ +#define csum_set_le(i) ({ \ + const void *p = (void *)(i) + sizeof(uint64_t); \ + const void *q = bkey_idx((struct bkey *)(i)->d, \ + le16_to_cpu((i)->keys)); \ + \ + bch_crc64(p, q - p); \ +}) + /* Error handling macros */ #define btree_bug(b, ...) \ diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 39bec137f636..31d700aecd56 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -110,7 +110,7 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev, goto err; err = "Bad checksum"; - if (s->csum != csum_set(s)) + if (s->csum != csum_set_le(s)) goto err; err = "Bad UUID"; @@ -236,7 +236,7 @@ static void __write_super(struct cache_sb *sb, struct bio *bio) for (i = 0; i < sb->keys; i++) out->d[i] = cpu_to_le64(sb->d[i]); - out->csum = csum_set(out); + out->csum = csum_set_le(out); pr_debug("ver %llu, flags %llu, seq %llu", sb->version, sb->flags, sb->seq);