From nobody Thu Apr 9 13:30:35 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F274634CFB0 for ; Sun, 8 Mar 2026 20:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773003242; cv=none; b=SRQGCCUU97LjM9Vcxro8fsFlMsiFJWgl3Y27PsHAhemMKtZXwR+Dddx5LT44F3dMCESzJZx8epEDnvCAlPlH2dbfywkhp1rD0TeRYUNMZK6bpTQZ14hTv99TCGX4M6FH6xcAi2q1dHBxQRTa2jCzYQ89kl1xeFZY/LkYauEnaCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773003242; c=relaxed/simple; bh=PylX8IEChGBaGlHqXEbfqUg1n2BDvKGc7VXqNccsPWg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=umvQ++nqFt5EzPsfN/ceYLeVVZjdNgm+f3Z0LkgNn9g8q3SxUuHuLSwl2XzoDN8yeo5PGRrhjt/mbWrjjjGMQm72bNottn0FUi2p76TQqckRN/4h4w8yhxqIi6w/lneSGwo+MswvEYNOmjPoVK6JQwIRFjUFPa3NQyANSumc8vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GgRdaOI8; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GgRdaOI8" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-829b2018c94so932309b3a.0 for ; Sun, 08 Mar 2026 13:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773003239; x=1773608039; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TeShWZUkCPM3Ka2Jx58JiwWvMzj51hGgMlQCsJB6FhM=; b=GgRdaOI8PRudmy0iq8OE3OInK4/1aPxbmOSWN6tCCkgcmmwew9he1dGINYqJ53jGmE SLJ2FRd5nCEc09yS4Ci8DUKc8Wkyj7n9HkFMyMz94RbG+fL2aADBiYUqPw17Blfs1JQx 4YOOD0raN/CeXHpTat73UnOF0Gt7pu6S9jxaG66pl0MelfI2J0/QzmUXLMXjPZ9sLWGj DPQyCFSkWHNStAuGxPuXBpnIHZKhVmjrpP1/95JaOjvceIzieDK3EQClYmihbbWZGUHf i1igUTpev7S7BzyJRMiV7LRXGhAkqtOEQ2+G+nv74/6DFZzaE+Ji1jEHa67PtPZ0G0tu a1rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773003239; x=1773608039; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TeShWZUkCPM3Ka2Jx58JiwWvMzj51hGgMlQCsJB6FhM=; b=VemUuyM2eItwEfKciKgRPfNx1avli17QihHXfINxYvF0FMkhjYNAws8ZP4Kinybupb +GVAfbO+qTEf7GcPi6JW+0OYnkfiWpLltl5gA3Gn9CC84ujMZpHqmagR9Mq4tzXMFiuf ZkMvOPPqB7E+0JgnbR1HTQosJcKHcsjnch3f7uJfSeYyD3I65YDHEyw7G3WR8C0M4M+i ZwwSLR8+FGXVOSxHpPn2g0MpVI/MoJOaqEAKwedYauH0ZlYBXExFNVIKaBTPeIArOpCb be/lsgkST5Z/sNYzrHdXutEWVYwLQAVp6DRFBXf/xM9vE7Hfd9tC8SmSmA0YSxCUR787 PSAg== X-Forwarded-Encrypted: i=1; AJvYcCXL3fX3gbrUagTt1J8+zXpVDxPOCQ/uQ8OdbxYCUFhEDeuIP20HxM+qhOmgRl6VEzPGhIPiim2qEc4w500=@vger.kernel.org X-Gm-Message-State: AOJu0YyrIGzQifFCXZV614tKlvVyMLoWIJC+9crDajXAc360oneMlAfk 0uRViY1XdAvnE8mijRP6CRjYW5l2zb9WmkLNwErTnH4wFeHr4+d4aEuP X-Gm-Gg: ATEYQzw2xBf5nZ/BOllzGmlLDvVC8Z5HEq3GoOkuFug+RYGInFiSxBU+CskNyZigj6n XnVXW9c9/7RG3GmGr5iTmnybwGZyu0sqhC5aO626Vn1IQEy2oizYCqNBQolyIKoij2CnPFJwFSY N4zY1ledMXic4VqjISUYRMrvrCDZYFwHtDGSvm7xqa0MnPQelWSrO4OQq1c+aAWlpGG16SHMObX y633kuZsvcQOjlq//UFjSDN5KXX4kGMT6sfp4xGO+LGJ3MmWqi+jQsNX7r9dgQbmku/L4Dw7oFa J+UcJU0tNUaylkuRtG/pt0B0ZxsirS/J1w6wzD7awahFge3RO+uchbnCHncswpJ6KVpdsd29DpW IOuPpiy+55L/GtLPuBEikQQCg2cH47YUKqEiIH7Rq5+ZiVRkOxn5hCnISmrIwtAHrNO76LwlepR 4oEQgE1eDmE3ngqxDnjtsC81c6Qx3EMAGYzdevaoRtNqrTIQjwIt5ojA== X-Received: by 2002:a05:6a00:2346:b0:823:8a5:297f with SMTP id d2e1a72fcca58-829a2de2ab2mr6966782b3a.16.1773003239273; Sun, 08 Mar 2026 13:53:59 -0700 (PDT) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-829a48d3621sm8722968b3a.62.2026.03.08.13.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Mar 2026 13:53:57 -0700 (PDT) From: Rosen Penev To: linux-btrfs@vger.kernel.org Cc: Chris Mason , David Sterba , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH] btrfs: raid56: use kzalloc_flex for rbio Date: Sun, 8 Mar 2026 13:53:40 -0700 Message-ID: <20260308205340.24208-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplifies allocation slightly. Now stripe_pages does not need to be freed separately. Added __counted_by for extra runtime analysis. Signed-off-by: Rosen Penev --- fs/btrfs/raid56.c | 9 ++++----- fs/btrfs/raid56.h | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index baebd9f733e9..d74ae380265e 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -151,7 +151,6 @@ static void free_raid_bio_pointers(struct btrfs_raid_bi= o *rbio) { bitmap_free(rbio->error_bitmap); bitmap_free(rbio->stripe_uptodate_bitmap); - kfree(rbio->stripe_pages); kfree(rbio->bio_paddrs); kfree(rbio->stripe_paddrs); kfree(rbio->finish_pointers); @@ -1070,10 +1069,11 @@ static struct btrfs_raid_bio *alloc_rbio(struct btr= fs_fs_info *fs_info, ASSERT(real_stripes >=3D 2); ASSERT(real_stripes <=3D U8_MAX); =20 - rbio =3D kzalloc_obj(*rbio, GFP_NOFS); + rbio =3D kzalloc_flex(*rbio, stripe_pages, num_pages, GFP_NOFS); if (!rbio) return ERR_PTR(-ENOMEM); - rbio->stripe_pages =3D kzalloc_objs(struct page *, num_pages, GFP_NOFS); + + rbio->nr_pages =3D num_pages; rbio->bio_paddrs =3D kzalloc_objs(phys_addr_t, num_sectors * sector_nsteps, GFP_NOFS); rbio->stripe_paddrs =3D kzalloc_objs(phys_addr_t, @@ -1083,7 +1083,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs= _fs_info *fs_info, rbio->error_bitmap =3D bitmap_zalloc(num_sectors, GFP_NOFS); rbio->stripe_uptodate_bitmap =3D bitmap_zalloc(num_sectors, GFP_NOFS); =20 - if (!rbio->stripe_pages || !rbio->bio_paddrs || !rbio->stripe_paddrs || + if (!rbio->bio_paddrs || !rbio->stripe_paddrs || !rbio->finish_pointers || !rbio->error_bitmap || !rbio->stripe_uptoda= te_bitmap) { free_raid_bio_pointers(rbio); kfree(rbio); @@ -1102,7 +1102,6 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs= _fs_info *fs_info, INIT_LIST_HEAD(&rbio->hash_list); btrfs_get_bioc(bioc); rbio->bioc =3D bioc; - rbio->nr_pages =3D num_pages; rbio->nr_sectors =3D num_sectors; rbio->real_stripes =3D real_stripes; rbio->stripe_npages =3D stripe_npages; diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h index 1f463ecf7e41..dbe6b7a2e194 100644 --- a/fs/btrfs/raid56.h +++ b/fs/btrfs/raid56.h @@ -194,12 +194,6 @@ struct btrfs_raid_bio { * allocated. */ =20 - /* - * Pointers to pages that we allocated for reading/writing stripes - * directly from the disk (including P/Q). - */ - struct page **stripe_pages; - /* Pointers to the sectors in the bio_list, for faster lookup */ phys_addr_t *bio_paddrs; =20 @@ -230,6 +224,12 @@ struct btrfs_raid_bio { * Should only cover data sectors (excluding P/Q sectors). */ unsigned long *csum_bitmap; + + /* + * Pointers to pages that we allocated for reading/writing stripes + * directly from the disk (including P/Q). + */ + struct page *stripe_pages[] __counted_by(nr_pages); }; =20 /* --=20 2.53.0