From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 E982033D51F for ; Sun, 8 Mar 2026 21:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773004746; cv=none; b=qsqac+nXalb+8Ge5oRBzGOkcmvShKnQfAeRd0UNLKU5UMZLFqOpH55jew6YrXkyte1rikb+ka/gAxSUhvRKwCgvI+k0YBGbLdG6pvgkq/9CPVICcEeNHqSgvwuEdrN9iN9HO2F/93czJxvjS+dh8ooD+QE2Ixa23gdbWk6tSZOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773004746; c=relaxed/simple; bh=hJZwWH3dKh30jrXu06PNPZiH2Rh0RzlXVIiHGznX3so=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RR2afrQcJz/47BAZjkSqQWm5XKGY27u2hEgYmTu1xFqFI+XAKoYDNaPPDDlrUkGQ6vT9C1rlj31urDgHTIYQLQR21hw4PsNcCvcxG4M3VJffSZfqDS+CKuHUUlWG0OgrLoIJfpCeBiTcvBK2uvEpRf6jZHqppJE1+FglNJx9M4I= 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.45 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-f45.google.com with SMTP id 5b1f17b1804b1-4806cc07ce7so127445625e9.1 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=cfBlYcrFsrsUu6093iHSyDoZi9zM7faGE2+7DTLCJNX8smjBJ2CnKcAvHUANQEBXrG W2/Ir+QKLTDirtA6DrHHUPzSqPfR+lRYDSMFbCdO2GV3qzhQWHkZkRNllyMJRFnOJUhs j67Ofas8K4UrNZNz1dzYpLUqGjfoHyp+Ltly9qXhIJms4/n+GCBEzCbpes+9j0suX51l OeBG5HI1bRdszaIolgERvx5Avdi39KXOPFDSkGEuJJ/77ZTZ6/E5Td/ac1Ytrd25hRZQ cM42Mrx6UHVDhUzM30ZLOWqBfwZ6ob8d0ZVwWqJFPx/jAM6kUkU/5pwuwSdMxXjjcjCi 2yGw== X-Forwarded-Encrypted: i=1; AJvYcCVKyPei/vT++qo5779v4ed3Ac9HWQ0LoyOBUBM94/fN1ChWHiB6hCKTZvCzxj+wpCtEyx8vEEwFFmdU9UYqRmY=@vger.kernel.org X-Gm-Message-State: AOJu0YzWuItj+gYnxBoAbJs59xqS/UBOLt1tDSWJUkDGXIaCINXLbsPO BdJ/xmtkF5olzwTqFlOZqrd9poS/j4nLyuHGEkbzYtqszFafzxJNlN06w+03QVi42nk= X-Gm-Gg: ATEYQzwTB4PF3GNNDd0IW+kekrmplCsbqGPrJyq44317Q5KoQJv9+vavAL2+3FEdZyI /fJb2/hls9h2FgVQARo8kAVnvlbBDI3Wv0KUtqlypAHjNrjcVVgFu56gaoe2fhhvaX8be+mXfOv LY6J7TV0yjETtxpsgblZ3pAjHLEGY9LMDh0meUeHmC5ZFmnsCTbZJmaSGIvoRpopuQqNKu+mqgA udwJCcxFWgxqoxY5rNWk9lRbXHCw4JAutqGnqEtTzIonwbN7218ChNi37KP4/cbun85qxmVHpcy K4R+7e81bIsKx1tzhQe2ZJRQRTl2L7fzFFZjnrBsPClkljC4z/NsJimyLi8IH2xyxJK6IOK1Qjx u6kMih0JKnlOOSAAeGaQT8lnAnhQSGGfKfJSYrWAatOgXuruAkbjUL/0F5UdejaZCgDFcyIvFtW HzKd+q+3qaRFBIIwzE6HvpvN/T54C0Tn/A/oFMm8XYLw2NonJ6JOA= 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-hardening@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/obGae8HhcJO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QnotJH8= In-Reply-To: <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); > }; > > /*