Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2406344lqp; Sun, 24 Mar 2024 18:13:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXZ98lRAf1WLyKL/0e9QTKTs5RwHUx8RcIsR3UC5Nc/mL87Yq24Sd6ZKvLWAHT/j7wDTxUx47WBUFKgeCeIGpV70Tt8upHC4PwWMvoG8g== X-Google-Smtp-Source: AGHT+IFpi52GEFlwelMQDhGcy4jdrMS/Q/HQjVy9oBf//8FYHInl/l5joMQDSoJuJqqsM0dhwCgz X-Received: by 2002:a05:6512:2112:b0:513:c195:1c56 with SMTP id q18-20020a056512211200b00513c1951c56mr3332219lfr.16.1711329189300; Sun, 24 Mar 2024 18:13:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711329189; cv=pass; d=google.com; s=arc-20160816; b=bGUy98hndvQ+JgIXofAhbe16XNwPjjrEiPFxarQkx7H5yy4mxuonsrUbylEinZ3EwE CNfQuYThEJtCpKpurzO14CSkbm2kaeiyGoihNKyqR9VGyFapcmwseXPKPZEvMh4NxpFE lBdkGF32DRyAegmGw1QU+ArCspkxKZBP2jps6ctkomlxKh+lhjSxmKpile9n7KfJ8u0N 3QyLp3DPaz+vv2ZYdwWrkzS9GClb73HNs1o6TyX9L1iCRXS6Ck+hyjkLuc+gFSJoTVni LvbmSsriPNiUXm8aAvBSg6/uEOHVT82KnR0jwBynbX8Pa9bzcN6vQMEM3DuzAhEOK90c BwmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gKU5bAyluHXVsqRGNeGdlBQGgfrco7lzng1DMmYbgBc=; fh=gztaZlEV/IhaCTI9OXrOTx7G3T0xX7o1SJxZFm84PTI=; b=xQ9wqNY4nkimTTmvd9iPd/4mPwxTZK7wtz3K34DB92VU+ib/VnyPMHV8jC1lJvN5yH MAHR+xWZr8n4mFWNPAmvi3uNDY7nm/s1cnWfFNFUeP+n0nsy49GaVaPhSoFbEbS40PGT wCdXuJTEqaXMf478OxkeGc9Z3TcX2QJdl5FOk0+rGGEgSoqXNBPhNb6nwwWpp4otct+e xknhwsTQL3eUsIoTqH4KGyZOR1ghEBWPaZDLqXnvewyKFTP9L9PWMELcVsMSzUeEXx4j Ft559wcEQ71MX6/zm0i52b4zRPZAQIwkEC9l4nBzD8zKn/Y1BvAdmCgqTNweN13k+i6+ rzTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jiMpYpoe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113602-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z4-20020a170906270400b00a474be847e1si1322195ejc.758.2024.03.24.18.13.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:13:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113602-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jiMpYpoe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113602-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0BF5B1F23751 for ; Mon, 25 Mar 2024 01:13:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31194762E4; Sun, 24 Mar 2024 22:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jiMpYpoe" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 411D77581B; Sun, 24 Mar 2024 22:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320406; cv=none; b=Fda5Wj7W8e8xyxwGjVR5NrGmN8/SyIfmze229tubEBL7oLlDz3q/6BNbonx4+1bK1BbvWuFmPsowFNBHFr3wcc/0K4Uc6ZCBS0UixMOmSdxxvaZNicoEFw2iOmnpG4624u24+nCfTsocifY4XjqvhFxFe9bQ1hOhyumI7XZg7Jk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320406; c=relaxed/simple; bh=1Lo6Urn3Mv3fd/2tVEgj2VG1n18ktolTzgOlzxqx0Vs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R70gpgaJ60WJO6tNDqyvBV7IJ3th8YWMqc7Vuytz/ayw1E9AlVLo7zmQwOciF+5YWFLpfnuNsoTibW8i8hSzBgCNTOTWeKpEX5E+7N8DTFQCnUuDJhQ8o/II8hh2mGgiBlkDP1iRvsBfNTuyF1DEgx9bQKC5E2KESsF4gxurcyE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jiMpYpoe; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DCD2C433F1; Sun, 24 Mar 2024 22:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320406; bh=1Lo6Urn3Mv3fd/2tVEgj2VG1n18ktolTzgOlzxqx0Vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jiMpYpoe/HPul2kweKqFc7gRPLMrgsd6WgD5/e3FbBN0FPzoHuSltAB/lYH+EHe1r SuoUV2yAcsHFYSzWwSJ0GJjFjfcNGF5hL6nxru+YId3QEJmwu/zsL9KXgfAaC3lhyW dF/tBtxLNV78TiuxwvOLaoBY+TEoD3eYRhl727UyDTv0h3wQr5bQwdiAM/7PFik3Bi jElDC4/c6j10ZomYovvqqqfFogSHPBWQNa0PD3ilcRax/f9mHaEBWuGjGDaOBB7r86 VwprWFEHh0Lw8F/3nBLq7/qgVDhoMXxKWuT6VgCcaedvJmZUSVeLSsyPiRSJYOq0P6 CBXdr9wvqtxxw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mikulas Patocka , Mike Snitzer , Sasha Levin Subject: [PATCH 6.8 712/715] dm-integrity: align the outgoing bio in integrity_recheck Date: Sun, 24 Mar 2024 18:34:51 -0400 Message-ID: <20240324223455.1342824-713-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Mikulas Patocka [ Upstream commit b4d78cfeb30476239cf08f4f40afc095c173d6e3 ] It is possible to set up dm-integrity with smaller sector size than the logical sector size of the underlying device. In this situation, dm-integrity guarantees that the outgoing bios have the same alignment as incoming bios (so, if you create a filesystem with 4k block size, dm-integrity would send 4k-aligned bios to the underlying device). This guarantee was broken when integrity_recheck was implemented. integrity_recheck sends bio that is aligned to ic->sectors_per_block. So if we set up integrity with 512-byte sector size on a device with logical block size 4k, we would be sending unaligned bio. This triggered a bug in one of our internal tests. This commit fixes it by determining the actual alignment of the incoming bio and then makes sure that the outgoing bio in integrity_recheck has the same alignment. Fixes: c88f5e553fe3 ("dm-integrity: recheck the integrity tag after a failure") Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm-integrity.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 92bed6ce17931..47cf1ab34941f 100644 --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -1699,7 +1699,6 @@ static noinline void integrity_recheck(struct dm_integrity_io *dio, char *checks struct bio_vec bv; sector_t sector, logical_sector, area, offset; struct page *page; - void *buffer; get_area_and_offset(ic, dio->range.logical_sector, &area, &offset); dio->metadata_block = get_metadata_sector_and_offset(ic, area, offset, @@ -1708,13 +1707,14 @@ static noinline void integrity_recheck(struct dm_integrity_io *dio, char *checks logical_sector = dio->range.logical_sector; page = mempool_alloc(&ic->recheck_pool, GFP_NOIO); - buffer = page_to_virt(page); __bio_for_each_segment(bv, bio, iter, dio->bio_details.bi_iter) { unsigned pos = 0; do { + sector_t alignment; char *mem; + char *buffer = page_to_virt(page); int r; struct dm_io_request io_req; struct dm_io_region io_loc; @@ -1727,6 +1727,14 @@ static noinline void integrity_recheck(struct dm_integrity_io *dio, char *checks io_loc.sector = sector; io_loc.count = ic->sectors_per_block; + /* Align the bio to logical block size */ + alignment = dio->range.logical_sector | bio_sectors(bio) | (PAGE_SIZE >> SECTOR_SHIFT); + alignment &= -alignment; + io_loc.sector = round_down(io_loc.sector, alignment); + io_loc.count += sector - io_loc.sector; + buffer += (sector - io_loc.sector) << SECTOR_SHIFT; + io_loc.count = round_up(io_loc.count, alignment); + r = dm_io(&io_req, 1, &io_loc, NULL, IOPRIO_DEFAULT); if (unlikely(r)) { dio->bi_status = errno_to_blk_status(r); -- 2.43.0