From patchwork Thu Jun 13 08:48:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 804059 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 7CC7B140383; Thu, 13 Jun 2024 08:48:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268532; cv=none; b=JL+gJxeAeVAwEK06gkGlNiiKv/ECiqHqXVrGyo1bMQwZRA4pfsphsHHIN78nRzwGnGX3aaixcQfJINZMA+gLCRX4P9tW03Dyr25lML+epBJ0V+0jtIkiWy0W/+KmQ7Kvffym4LndmPLXuJGcD0K57L0zdDrBze91kWnAKSRqzJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268532; c=relaxed/simple; bh=yY0uNbPQOrufhgaQFeATHZ7HMCnS3ncNTc56pLNjK4I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WTv6VqO8vLACAJ2f52CqaymoOJSjke4KOfjbmcE33wVmZmW/PsHpBhrr3n+vS3BpNfr/jgfTWoFL7Kqws+yws1NunRO1R9aF3DKOJNgbePPPiPcxrEbhnr/AiEUcZrra+D3lkPf3dU0BnB7oNeAxF/XwHStN5BOM/AjStoBzGwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=I7LXmgpQ; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="I7LXmgpQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Ru6e7QlCJJG/gBR+o3ggbDTJvKsMm+SRm2m/B6Mvy6c=; b=I7LXmgpQPJq0TW6SDVCQG+b7jq gGB5H/z2MbKT4p1ezib//uSwoqZDdJ2wub196VzhGlmy2nfmJyw4mG6RgRJF7mSww+BnTf0lnzyGq aM1vSjmSSWZDLlH8lq58pYAQjQW34vNKg1v9NxJgv3SzbR04kw3WBv0D6qZHPJd8URhnI/99oy0/d EoOEh6gQQPIXxIcW3RcHK/lqMUPE2EgWJE4TVBXm7gbRZXAjnhp/vZ6F9h4spVcQMsTG42pry/IrO hMoMPs8/VeEOdBXk9FtTN7pivCxquv5pq2/Gcq/a994Bs3wX09UQO3GYMfLlOmaoS+a/EuaIlfnfe 6yc1coPA==; Received: from 2a02-8389-2341-5b80-034b-6bc2-b258-c831.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:34b:6bc2:b258:c831] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHg8S-0000000Fmzb-4BDW; Thu, 13 Jun 2024 08:48:45 +0000 From: Christoph Hellwig To: Jens Axboe , "Martin K. Petersen" Cc: Mike Snitzer , Mikulas Patocka , Song Liu , Yu Kuai , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Keith Busch , Sagi Grimberg , Chaitanya Kulkarni , linux-block@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, nvdimm@lists.linux.dev, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org Subject: [PATCH 01/12] block: initialize integrity buffer to zero before writing it to media Date: Thu, 13 Jun 2024 10:48:11 +0200 Message-ID: <20240613084839.1044015-2-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240613084839.1044015-1-hch@lst.de> References: <20240613084839.1044015-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Metadata added by bio_integrity_prep is using plain kmalloc, which leads to random kernel memory being written media. For PI metadata this is limited to the app tag that isn't used by kernel generated metadata, but for non-PI metadata the entire buffer leaks kernel memory. Fix this by adding the __GFP_ZERO flag to allocations for writes. Fixes: 7ba1ba12eeef ("block: Block layer data integrity support") Signed-off-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Reviewed-by: Kanchan Joshi --- block/bio-integrity.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 2e3e8e04961eae..af7f71d16114de 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -432,6 +432,7 @@ bool bio_integrity_prep(struct bio *bio) unsigned long start, end; unsigned int len, nr_pages; unsigned int bytes, offset, i; + gfp_t gfp = GFP_NOIO; if (!bi) return true; @@ -454,11 +455,19 @@ bool bio_integrity_prep(struct bio *bio) if (!bi->profile->generate_fn || !(bi->flags & BLK_INTEGRITY_GENERATE)) return true; + + /* + * Zero the memory allocated to not leak uninitialized kernel + * memory to disk. For PI this only affects the app tag, but + * for non-integrity metadata it affects the entire metadata + * buffer. + */ + gfp |= __GFP_ZERO; } /* Allocate kernel buffer for protection data */ len = bio_integrity_bytes(bi, bio_sectors(bio)); - buf = kmalloc(len, GFP_NOIO); + buf = kmalloc(len, gfp); if (unlikely(buf == NULL)) { printk(KERN_ERR "could not allocate integrity buffer\n"); goto err_end_io; From patchwork Thu Jun 13 08:48:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 804058 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 358301419AA; Thu, 13 Jun 2024 08:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268538; cv=none; b=opbtkWvBTefyP0Mpq6jL4LYOjFH7s1mn5zQKiWKp6mwpoNOrIuHsXFq5tvHC21yGMGNwuijoR1H6dwa1RPTnEOiICzFQ0z5gF/yQaBSEo9fMgS4des1SJ8dzJBqkuvkPn+k9ZtKbBeZwlpkdPyQZRM8OvwrwhwKjt7Vr6hrBfnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268538; c=relaxed/simple; bh=+BjGuLr/gI1Gue5e119TjF+mdnq/PomOY8egq7ncYII=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r19v/C6UoyhfDpFwItI7lbuPN0mDVaDr6nkfWjiKme0RIfsoS9aa/LMpRTRmUYmBGESdYPvcQZZSj/Anj2W+D5mkhWEBWojfioBqAfbd2+lNXD5pfdhU9lePlthNzwuzhP0NBZ8+kEE8Om6Qhd05wZdhodjcjL7bDtsxIqHtX0M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=5ELtCIzd; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="5ELtCIzd" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=mKcyvM4r/2P84aZxmwMfKhF19qmlYUHCRYKugbswj8M=; b=5ELtCIzdPynKEeaB9S+3gwH71W uRLgl5l6+5E3kdFTLMN0ijMGlQkr8YZCZMCPTvND2vFNh0E/0EZsOyz6cN4Z7K+F8G65VIF5Mi6Jl NXcMgn046y08IE1GGU8nA/iE3A1Mm3Atpj5d9Va/2F1dVByHKHVmqZKGa1zjRWyyk7bDM4Gn2a3yd pBZhbvKoYtT/j0SssDzMkg4nHdLkZd6GLSplvObAFkC9Bwn1+R9l4IUM8DJpHeVhBTLeD2Of+PJou j4MChGJUw/Fiu8ukjaV4ehDnbIhUdEFGfT4LgiVbPT17KuTeWtkv45FWUZsREt9HFEpp/8ApWUkt1 uWMDwVhw==; Received: from 2a02-8389-2341-5b80-034b-6bc2-b258-c831.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:34b:6bc2:b258:c831] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHg8Z-0000000Fn3n-0mAX; Thu, 13 Jun 2024 08:48:51 +0000 From: Christoph Hellwig To: Jens Axboe , "Martin K. Petersen" Cc: Mike Snitzer , Mikulas Patocka , Song Liu , Yu Kuai , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Keith Busch , Sagi Grimberg , Chaitanya Kulkarni , linux-block@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, nvdimm@lists.linux.dev, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org Subject: [PATCH 03/12] md/raid1: don't free conf on raid0_run failure Date: Thu, 13 Jun 2024 10:48:13 +0200 Message-ID: <20240613084839.1044015-4-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240613084839.1044015-1-hch@lst.de> References: <20240613084839.1044015-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html The core md code calls the ->free method which already frees conf. Fixes: 07f1a6850c5d ("md/raid1: fail run raid1 array when active disk less than one") Signed-off-by: Christoph Hellwig Reviewed-by: Martin K. Petersen --- drivers/md/raid1.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 7b8a71ca66dde0..1f321826ef02ba 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -3204,7 +3204,6 @@ static int raid1_set_limits(struct mddev *mddev) return queue_limits_set(mddev->gendisk->queue, &lim); } -static void raid1_free(struct mddev *mddev, void *priv); static int raid1_run(struct mddev *mddev) { struct r1conf *conf; @@ -3238,7 +3237,7 @@ static int raid1_run(struct mddev *mddev) if (!mddev_is_dm(mddev)) { ret = raid1_set_limits(mddev); if (ret) - goto abort; + return ret; } mddev->degraded = 0; @@ -3252,8 +3251,7 @@ static int raid1_run(struct mddev *mddev) */ if (conf->raid_disks - mddev->degraded < 1) { md_unregister_thread(mddev, &conf->thread); - ret = -EINVAL; - goto abort; + return -EINVAL; } if (conf->raid_disks - mddev->degraded == 1) @@ -3277,14 +3275,8 @@ static int raid1_run(struct mddev *mddev) md_set_array_sectors(mddev, raid1_size(mddev, 0, 0)); ret = md_integrity_register(mddev); - if (ret) { + if (ret) md_unregister_thread(mddev, &mddev->thread); - goto abort; - } - return 0; - -abort: - raid1_free(mddev, conf); return ret; } From patchwork Thu Jun 13 08:48:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 804057 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 46F8913D638; Thu, 13 Jun 2024 08:49:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268545; cv=none; b=INYJ8+RwbU338eW5Aim5kOIt/dozD9bWO6ofWOIV128c4ry46TuLo+YAPzQOrW++PZz/G7Rc4WhD0n+8cgGFWsUqwqKqGhx+lStTKb30AeXVjkQHaQJBKn95EmB2tV6tdzGTTVG8YZKVgjZFK0bF1a1Dyar5nofHp99vuPhZjXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268545; c=relaxed/simple; bh=F/1MQQShDSJD/gK5N087qOaFVu6MoKFEJeyGdkcOB8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fh57HWF4ZgvpUHBIkwZ7AIYn+VoJwVpz1xYzZv9eJVI7pm+RvgfzhkHUfC9R9QFkiVM/H96EAZjRm8s0rY5Khd3m3xzt7hu+O8FPgt9NVnXJxJxhU0aoNe9rPDZK+irsG8GkwkIq9QUbBZPFoMwU6wyVxIJL8FP7RyXHMtGNBWE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=a7W96mMd; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="a7W96mMd" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=nGuyiOBl2Ykuy06sJ8icqZroFJnpajRcLePB5KOCozE=; b=a7W96mMd/zBl3x3qK5ae2iE5mh dBVk1vNXaNs0MDmg9UOZhMMIKrC6JnQ6SRiVZbmcOy4NAAEx+ARH4L8Ip1VIRjbaf3Ft/k4U7ihep 5CkeEKPoMmcpFfdCo5laEVxeskKQSFjwk1Jz+8iKSDgNSzR/PfpNuNfzPxSNMp1ucA7W47ZUXw5Jm 83qC0kql2NHEklgzn1r+wboWzOBrvHUV6Mja0ZPlCNK+Pi/YbdLunhWrJ8D8HP4I88ffCV2Vh/P3x s3MXBV1D02jAZ9GIVCk80I6Kc1svMCD7UwegtJnTM/5xtCMNhHyFOuW/AvNGOfvW2yaVozvL0x2VH DRsgX6XQ==; Received: from 2a02-8389-2341-5b80-034b-6bc2-b258-c831.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:34b:6bc2:b258:c831] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHg8h-0000000Fn9v-3LCS; Thu, 13 Jun 2024 08:49:00 +0000 From: Christoph Hellwig To: Jens Axboe , "Martin K. Petersen" Cc: Mike Snitzer , Mikulas Patocka , Song Liu , Yu Kuai , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Keith Busch , Sagi Grimberg , Chaitanya Kulkarni , linux-block@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, nvdimm@lists.linux.dev, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH 06/12] block: remove the blk_flush_integrity call in blk_integrity_unregister Date: Thu, 13 Jun 2024 10:48:16 +0200 Message-ID: <20240613084839.1044015-7-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240613084839.1044015-1-hch@lst.de> References: <20240613084839.1044015-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Now that there are no indirect calls for PI processing there is no way to dereference a NULL pointer here. Additionally drivers now always freeze the queue (or in case of stacking drivers use their internal equivalent) around changing the integrity profile. This is effectively a revert of commit 3df49967f6f1 ("block: flush the integrity workqueue in blk_integrity_unregister"). Signed-off-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Reviewed-by: Hannes Reinecke --- block/blk-integrity.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index 17d37badfbb8bc..24f04575096d39 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -401,8 +401,6 @@ void blk_integrity_unregister(struct gendisk *disk) if (!bi->tuple_size) return; - /* ensure all bios are off the integrity workqueue */ - blk_flush_integrity(); blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, disk->queue); memset(bi, 0, sizeof(*bi)); } From patchwork Thu Jun 13 08:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 804056 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 90F611428F2; Thu, 13 Jun 2024 08:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268548; cv=none; b=dz8y3+dFXfiD1sFxwyklY5mqO6wWZ4489M4bj4RplbTrCye7zQzNhiQVBBUswlRNkHcPv+dxDtBjoq61hE1PQgoP/1CsjLRQeD/+kTOk6sHo04hwhSgXEwZqf3hvSwG11rRGyV/+ctuARkhHiUiCJ5623+uLeLPorT2cbARwCtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268548; c=relaxed/simple; bh=BlQKMerwA89F/RkwnTZ6g2HUBDiUK7Q7iJvZm7kDq3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KiaaLOG8AnqKWxafhwUtL4aYLX41MC87izqs/a0yhIWZajRx9giy4TzSPplEEu2iRfBTJ2Q7zfGg5PIeJQD6JkbegS2kn2KHt9MooLnkpaQ73782u1fXx+6PivND+ZampHjWeVkI+jSKzvrEivdyTiXwVLCcfElzr7PZpzkCP74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=WfOVLHNE; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="WfOVLHNE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=MkqWB307uYilO32w43UhOiqouC5dD/MHs5vGR6/rVlA=; b=WfOVLHNEY/NCiJE2oBgYCPd3tg OOMdttEU9jkmGntkWzb//pPfwDlK4TeqAacAW6AUgWoXEh4eN3PUxb1mcMIdRfaqHL8p0ZXFkgLUw CvoZ76+SbGEhavfS7uhoAQnplOZ93pxq4L7wIqYYc1S3YSmeA7RM2vkd+EB1BLrYDgtc1ucaI2tKO oWM+RV3avUPY3R66wWIeKsJIiutWYXvt0VfCMllTU1WA6z976fpll14oA5ztTgow9e6AH+F+QB4bn IZ+rAEOgxfWPEinmoNaHzjZTSHHHdxxcNPjL0AbC9pF8vTVAXdhFJSH7CqHNpA51Yyd4K+6zKGqnB ggUcvwSA==; Received: from 2a02-8389-2341-5b80-034b-6bc2-b258-c831.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:34b:6bc2:b258:c831] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHg8k-0000000FnBe-1BuJ; Thu, 13 Jun 2024 08:49:02 +0000 From: Christoph Hellwig To: Jens Axboe , "Martin K. Petersen" Cc: Mike Snitzer , Mikulas Patocka , Song Liu , Yu Kuai , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Keith Busch , Sagi Grimberg , Chaitanya Kulkarni , linux-block@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, nvdimm@lists.linux.dev, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH 07/12] block: factor out flag_{store,show} helper for integrity Date: Thu, 13 Jun 2024 10:48:17 +0200 Message-ID: <20240613084839.1044015-8-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240613084839.1044015-1-hch@lst.de> References: <20240613084839.1044015-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Factor the duplicate code for the generate and verify attributes into common helpers. Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Chaitanya Kulkarni Reviewed-by: Martin K. Petersen Reviewed-by: Hannes Reinecke --- block/blk-integrity.c | 53 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index 24f04575096d39..24671d9f90a124 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -243,6 +243,28 @@ const char *blk_integrity_profile_name(struct blk_integrity *bi) } EXPORT_SYMBOL_GPL(blk_integrity_profile_name); +static ssize_t flag_store(struct device *dev, struct device_attribute *attr, + const char *page, size_t count, unsigned char flag) +{ + struct blk_integrity *bi = dev_to_bi(dev); + char *p = (char *) page; + unsigned long val = simple_strtoul(p, &p, 10); + + if (val) + bi->flags |= flag; + else + bi->flags &= ~flag; + return count; +} + +static ssize_t flag_show(struct device *dev, struct device_attribute *attr, + char *page, unsigned char flag) +{ + struct blk_integrity *bi = dev_to_bi(dev); + + return sysfs_emit(page, "%d\n", !!(bi->flags & flag)); +} + static ssize_t format_show(struct device *dev, struct device_attribute *attr, char *page) { @@ -275,49 +297,26 @@ static ssize_t read_verify_store(struct device *dev, struct device_attribute *attr, const char *page, size_t count) { - struct blk_integrity *bi = dev_to_bi(dev); - char *p = (char *) page; - unsigned long val = simple_strtoul(p, &p, 10); - - if (val) - bi->flags |= BLK_INTEGRITY_VERIFY; - else - bi->flags &= ~BLK_INTEGRITY_VERIFY; - - return count; + return flag_store(dev, attr, page, count, BLK_INTEGRITY_VERIFY); } static ssize_t read_verify_show(struct device *dev, struct device_attribute *attr, char *page) { - struct blk_integrity *bi = dev_to_bi(dev); - - return sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_VERIFY)); + return flag_show(dev, attr, page, BLK_INTEGRITY_VERIFY); } static ssize_t write_generate_store(struct device *dev, struct device_attribute *attr, const char *page, size_t count) { - struct blk_integrity *bi = dev_to_bi(dev); - - char *p = (char *) page; - unsigned long val = simple_strtoul(p, &p, 10); - - if (val) - bi->flags |= BLK_INTEGRITY_GENERATE; - else - bi->flags &= ~BLK_INTEGRITY_GENERATE; - - return count; + return flag_store(dev, attr, page, count, BLK_INTEGRITY_GENERATE); } static ssize_t write_generate_show(struct device *dev, struct device_attribute *attr, char *page) { - struct blk_integrity *bi = dev_to_bi(dev); - - return sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_GENERATE)); + return flag_show(dev, attr, page, BLK_INTEGRITY_GENERATE); } static ssize_t device_is_integrity_capable_show(struct device *dev, From patchwork Thu Jun 13 08:48:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 804055 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 52C3213777D; Thu, 13 Jun 2024 08:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268554; cv=none; b=PjBCGw++OY/Jbx9R8i7eizDh7sfOk1esXSHm5qJbs2Xzj0latF77vKgVUHMk7ID+3618Lu9eNkQV/GWcYbPRkC/uPlt+wFwswrg0sBlx6tY76boPXWUSR8F833nGa6PzPcPSkZUy+9kDlItfS2SMt9nhSIQtbDfye/ta97wQ3hQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268554; c=relaxed/simple; bh=3exPUCi+/EMwTyBUUWevL8vomgI5Z1iHcLCKhyuuNXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qiP4sXMMKZWOA/GMoJe5JuS+tAyjAf3wUcL+n1pJtVuFea7ziF5/2vlvbxeqkIyCR+tI2NsivYlT95R4OwAzhIZ9qLyJdAAOrxKg2Ms3MPT3JrftslAWIOrkvossFt48V5M87iQEJ+s6DlAbWnuqbSs2C4DjHcsp8/BH2oZGIWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=tiIrbk7o; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="tiIrbk7o" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=8PfoG5qTEAstoOabcoSjpYBwXPNcAMnJBPyc+pbMqJU=; b=tiIrbk7oHxoSl6ZApNv8fQocn1 aJ0mHijmRlh0jvrQiGPLpcrk8fNDNpjNDX1D6t4OxV6oCEqLb8X02hxEc/RMniCzLoJb4xDfKPPER FmSr7ZhQXDcwPrGmJsMS2cq7YyIOp2i1ccIVjwARo8VX7aMtYnIRYj/ivMzvw5m65XmFXSUJgagcP JjOLPbtNeJ8bgyV6ctSyz7rbTbEdUbLhTpd8BjW8Zqw7pjUW3ugc9ep1weAsooLyi1H1zWYMHIXCI 5T9FmOaeuJq1K5pgWxv+wkCP97zvBVOwl9EyllXwm6oXILU58sViC75XMCLv04tPuUZFjPrheO9Ob GUvKg1Cw==; Received: from 2a02-8389-2341-5b80-034b-6bc2-b258-c831.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:34b:6bc2:b258:c831] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHg8p-0000000FnG1-2lkQ; Thu, 13 Jun 2024 08:49:08 +0000 From: Christoph Hellwig To: Jens Axboe , "Martin K. Petersen" Cc: Mike Snitzer , Mikulas Patocka , Song Liu , Yu Kuai , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Keith Busch , Sagi Grimberg , Chaitanya Kulkarni , linux-block@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, nvdimm@lists.linux.dev, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH 09/12] block: don't require stable pages for non-PI metadata Date: Thu, 13 Jun 2024 10:48:19 +0200 Message-ID: <20240613084839.1044015-10-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240613084839.1044015-1-hch@lst.de> References: <20240613084839.1044015-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Non-PI metadata doesn't contain checksums and thus doesn't require stable pages. Signed-off-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Reviewed-by: Hannes Reinecke --- block/blk-integrity.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index 58760a6d6b2209..1d2d371cd632d3 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -379,7 +379,8 @@ void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template bi->tag_size = template->tag_size; bi->pi_offset = template->pi_offset; - blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue); + if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE) + blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue); #ifdef CONFIG_BLK_INLINE_ENCRYPTION if (disk->queue->crypto_profile) { @@ -404,7 +405,8 @@ void blk_integrity_unregister(struct gendisk *disk) if (!bi->tuple_size) return; - blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, disk->queue); + if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE) + blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, disk->queue); memset(bi, 0, sizeof(*bi)); } EXPORT_SYMBOL(blk_integrity_unregister); From patchwork Thu Jun 13 08:48:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 804054 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 7E9F714388E; Thu, 13 Jun 2024 08:49:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268560; cv=none; b=BXkxIBDAaANc4f/LrX8upO7d8sjj7+zhUJGeUocTmcMBzeZE8QIsudOQfkYiJcdFvda3K9fa4XlXDDGY5ykRhwWGgv/lcLbZnbpZBYcjfLrJY6fWSfmTofc1hyER8rJTZeSVSDAs5ghb8VlMXc4EHFtkTuVg5TsnZB1Um/q2hvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268560; c=relaxed/simple; bh=Z0Lov3g13FFaDmPBtAU06q40Kc9A43XCMnGtpk71Y58=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QfGffZVuyBSdYQwSRBWxj6RTqytd3G/EUXmRdBouGsx8wdjq8D7SmnMaNeiK3ycD+6MUiD6rIExk3avnKvxDhhpUVjWVh3fervgZI6DINFEEUrXdKpeeRaZTJAzdt99oFk0MekrUXOmvHVSJwXXRpcaqE6BYrFmRqGwVdQVa8lY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=0oWk5wE6; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="0oWk5wE6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=pYlsmuvMM1MaWDK5cL1mDNEG3F0fYwnedRts7Sa9qrU=; b=0oWk5wE6xY+6S6Qx/mbU/NIBbW fw8bJwX0iGWI3xi5BS9lf3FkM+Sw71f6BHuzo731b82i8FFyXK4Lu2fNE5MMr6vMDCleC7IBL6uJD tZ+TFq+JHiUlSMZzt4naZ/ZgKBRKubVHKIv0BtzspenjTKUANu661/LaCz0H21rLKVB8UblSvkpmW xmPqxxCDIUnih7/3i15LDGtxPOMzjXamnVVAh3BC3uveRtHZhQ1zm8ZYuOM/C4uHzeHUE4y+qkZl+ Z0attPoD+Saqk82PpQRWT0j2a5gqUYzK4uerP95bq2mE64L9je5WwvZ2dWgp+b0ZvgvZQbQrKutMd tV/v0sgg==; Received: from 2a02-8389-2341-5b80-034b-6bc2-b258-c831.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:34b:6bc2:b258:c831] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHg8v-0000000FnLU-34bH; Thu, 13 Jun 2024 08:49:14 +0000 From: Christoph Hellwig To: Jens Axboe , "Martin K. Petersen" Cc: Mike Snitzer , Mikulas Patocka , Song Liu , Yu Kuai , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Keith Busch , Sagi Grimberg , Chaitanya Kulkarni , linux-block@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, nvdimm@lists.linux.dev, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH 11/12] block: invert the BLK_INTEGRITY_{GENERATE, VERIFY} flags Date: Thu, 13 Jun 2024 10:48:21 +0200 Message-ID: <20240613084839.1044015-12-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240613084839.1044015-1-hch@lst.de> References: <20240613084839.1044015-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Invert the flags so that user set values will be able to persist revalidating the integrity information once we switch the integrity information to queue_limits. Signed-off-by: Christoph Hellwig Reviewed-by: Chaitanya Kulkarni Reviewed-by: Hannes Reinecke Reviewed-by: Martin K. Petersen --- block/bio-integrity.c | 4 ++-- block/blk-integrity.c | 18 +++++++++--------- include/linux/blk-integrity.h | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 31dbc2853f92e3..173ffd4d623788 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -448,10 +448,10 @@ bool bio_integrity_prep(struct bio *bio) return true; if (bio_data_dir(bio) == READ) { - if (!(bi->flags & BLK_INTEGRITY_VERIFY)) + if (bi->flags & BLK_INTEGRITY_NOVERIFY) return true; } else { - if (!(bi->flags & BLK_INTEGRITY_GENERATE)) + if (bi->flags & BLK_INTEGRITY_NOGENERATE) return true; /* diff --git a/block/blk-integrity.c b/block/blk-integrity.c index bec0d1df387ce9..b37b8855eed147 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -254,10 +254,11 @@ static ssize_t flag_store(struct device *dev, struct device_attribute *attr, if (err) return err; + /* the flags are inverted vs the values in the sysfs files */ if (val) - bi->flags |= flag; - else bi->flags &= ~flag; + else + bi->flags |= flag; return count; } @@ -266,7 +267,7 @@ static ssize_t flag_show(struct device *dev, struct device_attribute *attr, { struct blk_integrity *bi = dev_to_bi(dev); - return sysfs_emit(page, "%d\n", !!(bi->flags & flag)); + return sysfs_emit(page, "%d\n", !(bi->flags & flag)); } static ssize_t format_show(struct device *dev, struct device_attribute *attr, @@ -301,26 +302,26 @@ static ssize_t read_verify_store(struct device *dev, struct device_attribute *attr, const char *page, size_t count) { - return flag_store(dev, attr, page, count, BLK_INTEGRITY_VERIFY); + return flag_store(dev, attr, page, count, BLK_INTEGRITY_NOVERIFY); } static ssize_t read_verify_show(struct device *dev, struct device_attribute *attr, char *page) { - return flag_show(dev, attr, page, BLK_INTEGRITY_VERIFY); + return flag_show(dev, attr, page, BLK_INTEGRITY_NOVERIFY); } static ssize_t write_generate_store(struct device *dev, struct device_attribute *attr, const char *page, size_t count) { - return flag_store(dev, attr, page, count, BLK_INTEGRITY_GENERATE); + return flag_store(dev, attr, page, count, BLK_INTEGRITY_NOGENERATE); } static ssize_t write_generate_show(struct device *dev, struct device_attribute *attr, char *page) { - return flag_show(dev, attr, page, BLK_INTEGRITY_GENERATE); + return flag_show(dev, attr, page, BLK_INTEGRITY_NOGENERATE); } static ssize_t device_is_integrity_capable_show(struct device *dev, @@ -371,8 +372,7 @@ void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template struct blk_integrity *bi = &disk->queue->integrity; bi->csum_type = template->csum_type; - bi->flags = BLK_INTEGRITY_VERIFY | BLK_INTEGRITY_GENERATE | - template->flags; + bi->flags = template->flags; bi->interval_exp = template->interval_exp ? : ilog2(queue_logical_block_size(disk->queue)); bi->tuple_size = template->tuple_size; diff --git a/include/linux/blk-integrity.h b/include/linux/blk-integrity.h index 56ce1ae355805d..bafa01d4e7f95b 100644 --- a/include/linux/blk-integrity.h +++ b/include/linux/blk-integrity.h @@ -7,8 +7,8 @@ struct request; enum blk_integrity_flags { - BLK_INTEGRITY_VERIFY = 1 << 0, - BLK_INTEGRITY_GENERATE = 1 << 1, + BLK_INTEGRITY_NOVERIFY = 1 << 0, + BLK_INTEGRITY_NOGENERATE = 1 << 1, BLK_INTEGRITY_DEVICE_CAPABLE = 1 << 2, BLK_INTEGRITY_REF_TAG = 1 << 3, };