Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp351533pxb; Wed, 14 Apr 2021 17:32:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPOJHf9ghVkO9dbc9IV4rFWGudtr7WodXIbjn6cP72l09mGa4Wjf7cuZIUdeDkJKW3cHro X-Received: by 2002:a17:90a:a103:: with SMTP id s3mr838517pjp.158.1618446758450; Wed, 14 Apr 2021 17:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618446758; cv=none; d=google.com; s=arc-20160816; b=Hgr6QGBCn4Ct78sgClqvTerwPUQSqq7ssawXOmTJYCNQ3kJwBRq8Z6wIGUmNj0pnBy 3DXPVXGwfzBgvK27GrOdxgnr25XZ/BBLhmmjodc18wJKgFix9eRc93wHYIFErv+Hsjk5 qL0Aivn3I/XMK0hErSEwlLuQCaRvG48wXADvnXkT3gWkFTPKN2llew4QNwI4NCUIIAWz eGtjmUlIJfUwl1En83lu+gVnZYIL5eyk/nRokhD4umC4hkn4vqlO1Bkdubct7zsskN5x jFvIOI7FFagP9Fd9vumkSfrHj7RI/fziQ8CE29fWTU1mNqlyVmI4mQ6akZChuC+yZAjt LDHQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=2KiHr0vfQJQQ+PvAKoD/YKqqPnBAcq9Q1/oCxyZGb4w=; b=YigZrQ4UtghnO3kTH/3emx7xapQJmUSopPHZcqHiUOZ4v8hbGhK6NPOjU2jrGaGMoo MWMf46Y9sQs4rzj66AJ9ALYV2y5uGdxdZFgECVLE+g9ZE3IkF/FdIXjS+ERjmKs1UpL5 wWngJWGi4rNPHFKfbhPm9dtf8LRxrIVH0HQSX9MSDqUVueQUoTbI4S7vb4q2R2PNKs+k ctvxarjmlSS/fbSCfG3gNq+/F3Yl7c+eXRukRndPQdA5ojvNwL+NLw6kNR4bI6nbVhYd JrhL55Vi+IcHDJHd4in4Exhha+DV/Z34zsLHIheWmTEHz+5B+4RgH+WfgLdbhC64EdFr 8m7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DMiddRMT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j11si1393859plx.104.2021.04.14.17.32.26; Wed, 14 Apr 2021 17:32:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@kernel.org header.s=k20201202 header.b=DMiddRMT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352246AbhDNP31 (ORCPT + 99 others); Wed, 14 Apr 2021 11:29:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:48016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350223AbhDNP3M (ORCPT ); Wed, 14 Apr 2021 11:29:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A122D61158; Wed, 14 Apr 2021 15:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618414130; bh=VOjjidsArMWHVu6+STthr6t7XDFmwhg8C/WgwQsOgao=; h=From:To:Cc:Subject:Date:From; b=DMiddRMTdBxF2WA+pSHF0xc1KgYlNzxRuGZTT1AtS3/gVz/BMF6a3M18AuP5l0pKy VnoMbAi30WmQhjunDjVhIMdeUwMzeSvc6/P6PosBb05jZizgFajzJuqY4DWMr8Kfty NDvbDpT8/uXGzjxNxA6ATE6RJMz7W2xI3qbzS9OqEyF9dnLVfTTGayPaQGkig61jfi yNRhi+e130pPjy0Q4vBOqmpZ5PAe3EeBC+3nIvHsVVfrM7TKbZjU3Jf3+939QOUHmg HwCE3Sc6v5mhI3JAOqPWiSXDFuLcVpX2B/A0Vw0KrO5TMTqYssB/KdhjScZAvhnLBx v8C4yC75MfMeg== From: Jaegeuk Kim To: dm-devel@redhat.com Cc: gregkh@linuxfoundation.org, snitzer@redhat.com, kernel-team@android.com, linux-kernel@vger.kernel.org, agk@redhat.com, Jaegeuk Kim , stable@vger.kernel.org Subject: [PATCH RESEND] dm verity: fix not aligned logical block size of RS roots IO Date: Wed, 14 Apr 2021 08:28:28 -0700 Message-Id: <20210414152828.760900-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jaegeuk Kim commit df7b59ba9245 ("dm verity: fix FEC for RS roots unaligned to block size") made dm_bufio->block_size 1024, if f->roots is 2. But, that gives the below EIO if the logical block size of the device is 4096, given v->data_dev_block_bits=12. E sd 0 : 0:0:0: [sda] tag#30 request not aligned to the logical block size E blk_update_request: I/O error, dev sda, sector 10368424 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0 E device-mapper: verity-fec: 254:8: FEC 9244672: parity read failed (block 18056): -5 Let's use f->roots for dm_bufio iff it's aligned to v->data_dev_block_bits. Fixes: df7b59ba9245 ("dm verity: fix FEC for RS roots unaligned to block size") Cc: stable@vger.kernel.org Signed-off-by: Jaegeuk Kim --- drivers/md/dm-verity-fec.c | 11 ++++++++--- drivers/md/dm-verity-fec.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index 66f4c6398f67..cea2b3789736 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -65,7 +65,7 @@ static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index, u8 *res; position = (index + rsb) * v->fec->roots; - block = div64_u64_rem(position, v->fec->roots << SECTOR_SHIFT, &rem); + block = div64_u64_rem(position, v->fec->io_size, &rem); *offset = (unsigned)rem; res = dm_bufio_read(v->fec->bufio, block, buf); @@ -154,7 +154,7 @@ static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio, /* read the next block when we run out of parity bytes */ offset += v->fec->roots; - if (offset >= v->fec->roots << SECTOR_SHIFT) { + if (offset >= v->fec->io_size) { dm_bufio_release(buf); par = fec_read_parity(v, rsb, block_offset, &offset, &buf); @@ -742,8 +742,13 @@ int verity_fec_ctr(struct dm_verity *v) return -E2BIG; } + if ((f->roots << SECTOR_SHIFT) & ((1 << v->data_dev_block_bits) - 1)) + f->io_size = 1 << v->data_dev_block_bits; + else + f->io_size = v->fec->roots << SECTOR_SHIFT; + f->bufio = dm_bufio_client_create(f->dev->bdev, - f->roots << SECTOR_SHIFT, + f->io_size, 1, 0, NULL, NULL); if (IS_ERR(f->bufio)) { ti->error = "Cannot initialize FEC bufio client"; diff --git a/drivers/md/dm-verity-fec.h b/drivers/md/dm-verity-fec.h index 42fbd3a7fc9f..3c46c8d61883 100644 --- a/drivers/md/dm-verity-fec.h +++ b/drivers/md/dm-verity-fec.h @@ -36,6 +36,7 @@ struct dm_verity_fec { struct dm_dev *dev; /* parity data device */ struct dm_bufio_client *data_bufio; /* for data dev access */ struct dm_bufio_client *bufio; /* for parity data access */ + size_t io_size; /* IO size for roots */ sector_t start; /* parity data start in blocks */ sector_t blocks; /* number of blocks covered */ sector_t rounds; /* number of interleaving rounds */ -- 2.31.1.295.g9ea45b61b8-goog