From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 E2BFF33B940 for ; Sun, 8 Mar 2026 21:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773004747; cv=none; b=W44+VKX8sCDH2re9wjapKLtUuuXBe/5JsmpXqEqA9iOdyy5Y35Tolwq7XWH7j6+5w/ZYLROGTe92vRlmi1SEXQZpvAdCIl9zfHh10UmpyklpL9gUMGotdstK0R2VL9DlDyIZ5ADUBKuaNfiV0ak5xUg+VV60/jvXy8yaDqkyT/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773004747; c=relaxed/simple; bh=hJZwWH3dKh30jrXu06PNPZiH2Rh0RzlXVIiHGznX3so=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YLJQebQK8q/hIROBvr53Ja5Vpn8tysErdEpO4gnB7fFYyBSIpB0C7UBP1sVdX+ttGlruIm+Qhwra8GlyOcFVB2YIG6JMG4e/vUzsp/bWSyztfV3pHKaC1ro+/Y+1VKu/pezBGlHf2I+ML9L3hiB+/5mUSxozM2UGz4DHEBsysdA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=I5Q+sO+t; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="I5Q+sO+t" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-48534237460so9347015e9.3 for ; Sun, 08 Mar 2026 14:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1773004743; x=1773609543; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=3+z4CqEO/7VS22glAthUPXJPXHmHHuhnxWXDV7aa870=; b=I5Q+sO+tzowKZlxEklJp7Jbsv9jjHKkU7PS/feE930Ie5i8xVmXJ9Ct3ljz0xv+zAO ygugOnGxJFoY16fk8fZSwHuWuBJOCSUgG8MuPmcHKCb+zw/k9JwvlGkeuSKKRAq9Zxte T2hPkeWc0IsiJYhjcfzAGAusG8hJwrJ9kPo02CWRmWbC/9FntTUwoH4ZlOrj2FOEUn5J 2FLf22JNsTqA6lwEZHxX/o+GmYKAQrHrcsTRm32uKbENtYAGoKuEibKOxMUzsYErxIiQ 63jOKGJ44PFw7Xd5LfrQL7ufCggB+jLyVOWA54hYv8Efwzdtud63d862Ou7Yp+BxE8Q3 tN8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773004743; x=1773609543; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3+z4CqEO/7VS22glAthUPXJPXHmHHuhnxWXDV7aa870=; b=QBLiWNK4rm0KpZmcOqcq+/DE10u35FyqzWUDHc4v871GcrdyysM5UdsotSovtH8ht8 oGy8cSy9Xv6zoPWZ8mTEgUVinU7Ubk8Z+JCcQagdeyXF6jKOuLQXG7F8ezeO083FCTao tsQBSApg89abiQvdpw8N490rh7ls9pvJsEju15gkcGY/LSk5OyATTkq/yuAj3O1XeZNw fSvuugs/VdsVMuPsFoAgIjtbJB/JaBdHIFu64Z/9DVh9lFll+ADUnkT2Ap08qjZCdR3n hwbymBmo1cOcGe6xOwNdKqZ1Jn6gZKOJ+HmezUC0UGtqoUGX3u45GUY5ydacAcadfaYe 0FGQ== X-Forwarded-Encrypted: i=1; AJvYcCVs7rvnlU+SupUXDrOkcu73kfNgGPPWUgKwnU8+jHP/8L3t0108zdXsWlwu+mg1lpDGZlojAWtI7lMuOjc=@vger.kernel.org X-Gm-Message-State: AOJu0YxiDvf9NyoUhFQmQrDkSwA0oRQXBhl4Y83os/4YnUr7KwcBH8zP sxaTb/TVN1UyxA/QFkERzeesC3TJWCADzQUYzAF8g0PCdBbpApYSzKB8AnzOXa6f0ws= X-Gm-Gg: ATEYQzw+B9g+wz5M4APAkgtdL6S4gL7B723Gdmn/PJ9pVbqdKzoAVEL4EwQyAA9q+GD yPr077UibK7TtgPl5L0GMUnNPsxzFjdJI407i7t1R73l2RmS/+5Wva39odR+2D+EYoZ64JiQ6tM 2LV1Uw55el9WW/UPNaav+yJP4PZECz+BzRjrnaOe0v1x1kAtSUHP2U8+IP5OeWtlVKhN+BBuc9n m+JKAIl0aS+L4EGjXdh+XieSu55/Gey4uffSfx+4uhkwuACwn0HEv8wboxy/0ChG209cuO9wjVM gfwTaRTyUX9Jab4fY24awInvPRyiPm0Lr37ahF669V1hQiyzoBpjb/tT+KxhM298Phw9QtBCg6y hvFJWTjRemDO8aLWz7qmC3roY2Znd7nqN5+FJ2QhWY1ngTCyRe9FT3R437Nry36TqzV/KO81ga9 /1/hF4Cv4SyDk/WthQEE8UMfNEXtcLgI0GnF4180uzsCVN9zpoBAk= X-Received: by 2002:a05:600c:45d1:b0:483:a361:41a5 with SMTP id 5b1f17b1804b1-4852697866fmr159410045e9.30.1773004743052; Sun, 08 Mar 2026 14:19:03 -0700 (PDT) Received: from ?IPV6:2403:580d:fda1::299? (2403-580d-fda1--299.ip6.aussiebb.net. [2403:580d:fda1::299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ae840b6639sm123685335ad.86.2026.03.08.14.18.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Mar 2026 14:19:01 -0700 (PDT) Message-ID: Date: Mon, 9 Mar 2026 07:48:56 +1030 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] btrfs: raid56: use kzalloc_flex for rbio To: Rosen Penev , linux-btrfs@vger.kernel.org Cc: Chris Mason , David Sterba , Kees Cook , "Gustavo A. R. Silva" , open list , open "list:KERNEL" HARDENING "(not" covered by other "areas):Keyword:b__counted_by(_le|_be)?b" References: <20260308205340.24208-1-rosenp@gmail.com> Content-Language: en-US From: Qu Wenruo Autocrypt: addr=wqu@suse.com; keydata= xsBNBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBOLK79H3tmUtz6b 9Imuj0ZyEsa76Xg9PX9Hn2myKj1hfWGS+5og9Va4hrwQC8ipjXik6NKR5GDV+hOZkktU81G5 gkQtGB9jOAYRs86QG/b7PtIlbd3+pppT0gaS+wvwMs8cuNG+Pu6KO1oC4jgdseFLu7NpABEB AAHNGFF1IFdlbnJ1byA8d3F1QHN1c2UuY29tPsLAlAQTAQgAPgIbAwULCQgHAgYVCAkKCwIE FgIDAQIeAQIXgBYhBC3fcuWlpVuonapC4cI9kfOhJf6oBQJnEXVgBQkQ/lqxAAoJEMI9kfOh Jf6o+jIH/2KhFmyOw4XWAYbnnijuYqb/obGae8HhcJO2KIGcxbsinK+KQFT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<20260308205340.24208-1-rosenp@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2026/3/9 07:23, Rosen Penev 写道: > Simplifies allocation slightly. Now stripe_pages does not need to be > freed separately. > > Added __counted_by for extra runtime analysis. If that's the only variable sized member this will be a good change. Unfortunately there are too many pointers for variable sized members, all around the old @stripe_pages pointer. Treating @stripe_pages differently from other doesn't seem good to expandability nor readability. Thanks, Qu > > 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_bio *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 btrfs_fs_info *fs_info, > ASSERT(real_stripes >= 2); > ASSERT(real_stripes <= U8_MAX); > > - rbio = kzalloc_obj(*rbio, GFP_NOFS); > + rbio = kzalloc_flex(*rbio, stripe_pages, num_pages, GFP_NOFS); > if (!rbio) > return ERR_PTR(-ENOMEM); > - rbio->stripe_pages = kzalloc_objs(struct page *, num_pages, GFP_NOFS); > + > + rbio->nr_pages = num_pages; > rbio->bio_paddrs = kzalloc_objs(phys_addr_t, > num_sectors * sector_nsteps, GFP_NOFS); > rbio->stripe_paddrs = 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 = bitmap_zalloc(num_sectors, GFP_NOFS); > rbio->stripe_uptodate_bitmap = bitmap_zalloc(num_sectors, GFP_NOFS); > > - 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_uptodate_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 = bioc; > - rbio->nr_pages = num_pages; > rbio->nr_sectors = num_sectors; > rbio->real_stripes = real_stripes; > rbio->stripe_npages = 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. > */ > > - /* > - * 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; > > @@ -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); > }; > > /*