Message ID | 20230522212114.gonna.589-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1733430vqo; Mon, 22 May 2023 14:38:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71Dk03Sq2kSxZTDbPyPR516JA+b7FlLmn/+NUplbEHmKwD+Fm7XhM4aJLOc8oSksA3zKLe X-Received: by 2002:a17:90b:3798:b0:253:74f8:1e31 with SMTP id mz24-20020a17090b379800b0025374f81e31mr11108611pjb.39.1684791532229; Mon, 22 May 2023 14:38:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684791532; cv=none; d=google.com; s=arc-20160816; b=VCs7UEq8wCj3x6aqlNyA0JE0L98PTWcMByxAbcXg6Bi0lSTZ8KJ8DjVXzssQLc8BKR bdC0Pi9YK7ukPO5NK8aXtsHHrpPME5TEEyv6LdRk1jyRYqt+4QhI9Vd5eDA5KcQ2NmAs uYkTET+ebV3GDH3wYwTPMAvJHzrcUSMeg3EsZq6W4YgdKjmbR/93uqwVFTg0JbBDhkvj VpDpsCcNOMNX+zi9is3uJbLPsykfFd8Nreu0Rj5AYWQR1/HrDSEce1PJAYv/uyz2qfff elVI9IvMXtryY6AlbQtM6sg3E/DVWNJKmweZb4tYHtZIR3NjmL+SojdyLuXghP4VTsur 3Lwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=EtWptAsa4eS8Kz5UJ2iVjBJtBMlQ0SUqdqNlkHKBLEs=; b=OPi0rd6GOJKAwBrGuCEax+OylXJEpZjjRyjgIbJONpkmRpESLFRhX+19JQoGUWdR8o JKgrwCYEQfq79cB9yd9NbvwyJ+nIN28WbkDcTwirXJYYFn9Ew8MTmkQ1UPYWm1neO02g S654jmqLJIFi/56WR/4Jl74zSTDmh+7XRpCa2L/dZ6ZiHJ9FurKIrt/LGV7PafBQroa0 +TxiqVLgJoyvjSn5E8o61UWKG0Gmqs/XGU5nIbIo/f73HC3RNIuJNVa0ItbycGqwgrBT Joj1b4bMEQzlhB54l/tNjiJZCoWbiZWMhKCHmF51K57pIO7MOijW2X7oRQYIqHuWdDv9 qoIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JIq7ayuh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gw17-20020a17090b0a5100b00250bbca6fdfsi5191398pjb.105.2023.05.22.14.38.40; Mon, 22 May 2023 14:38:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JIq7ayuh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233761AbjEVVVU (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Mon, 22 May 2023 17:21:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231577AbjEVVVS (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 22 May 2023 17:21:18 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2FC9C for <linux-kernel@vger.kernel.org>; Mon, 22 May 2023 14:21:17 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1ae4c5e1388so63042455ad.1 for <linux-kernel@vger.kernel.org>; Mon, 22 May 2023 14:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1684790477; x=1687382477; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EtWptAsa4eS8Kz5UJ2iVjBJtBMlQ0SUqdqNlkHKBLEs=; b=JIq7ayuhUCPY+jd41Z0soEOBn/LFyKyWmnktUDKUkFjbcodRiaN8GF9yRYnWncUysg JMis495bRgGRsJPACvfNdeWyPpeRvfE+6TCQlXMJSjY4oCQAKJ2NcKfPCjEzu8E/qn+d 4O2sTSDN8hdrY3dVMXBStxPpbdjTlpkZ95Wb4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684790477; x=1687382477; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EtWptAsa4eS8Kz5UJ2iVjBJtBMlQ0SUqdqNlkHKBLEs=; b=eM61pE/ltRPUR6mXR3hqTHhCmtUI8ZeCp6Db1xiGqMQg+YWwOE2raI+i7nMYRmWMuj +K34gLrcLWoiKqOf+1ijX51WTd71o3++TAo89mOmapdOsjMc/O9jtt9vrVMU6ZukDHBl ww2qNjzSo+qgbsmxtLunWUn0oIOu5/yeLUXchfk4u57v7dWajLs1RZuZ0epGhrmla3gR COiXo3d78RfVBeDd3tWn3/G2CT8yeifItioLSUorwiennouQQrej7qVyppR0cvugK/nH 4jsB+4vAOvNtC3Ar8/Cg2cFC74m7FH2y6FiWyf5s6tBw32IQvZ5I9Qk6tiI8Q72RvnHI HF6w== X-Gm-Message-State: AC+VfDyS/xHKRGqtYalEp96fBnYHBtBa11DTlpqIe1AQNYFe547vBeKj 7a3PW9pxYojb7AeYvPTJdGsmHA== X-Received: by 2002:a17:903:48a:b0:1ae:52ea:5fa6 with SMTP id jj10-20020a170903048a00b001ae52ea5fa6mr11039976plb.8.1684790477220; Mon, 22 May 2023 14:21:17 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id o18-20020a170902d4d200b001ae44e2f425sm5239217plg.223.2023.05.22.14.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 14:21:16 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Song Liu <song@kernel.org> Cc: Kees Cook <keescook@chromium.org>, Christoph Hellwig <hch@infradead.org>, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2] md/raid5: Convert stripe_head's "dev" to flexible array member Date: Mon, 22 May 2023 14:21:15 -0700 Message-Id: <20230522212114.gonna.589-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2398; h=from:subject:message-id; bh=fm/ezGihLT88LzMah4Fd0e38oNOXvo+hj+2PCvpzioM=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBka9zLVXP5GF5nusCTtCCpiPzdqxuZYP1lhGnV3/nP RaabgLaJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZGvcywAKCRCJcvTf3G3AJqLNEA CQhGxdsHJfIqJXnwaI/TKJqp1MlIRzOzuHQNQKFtG4lEGw33c0Z9FoyV3oXosgTp/gW+KVRR2Fp7Bn x4Ca7pXIy0HGuOLJlMhQJXKh3AfnPuibkkQVSpnvWqCjTcGz/mBhQOt+Q11QIAYdp+bL/n25kQV2Pm VuS3s0lLyhnltc6DArfq/ujY8mva8GUWZJ2i881mp2oL+BIgS7/4/HvvbcPj9tPQUXtKZv7UnVwFiK LhH/HXhio18g9cdQ9xgpsohuY0bjXL/Ij86RbwWRD3fhS6P7ndkUBXvFi3Fu4niWIWMKweZl6DdNnG 8nbNPhPd8QOCpREE2CfIW8irzwtgQo4wb6/xB1kaXjfnFb38T0HkDUP4lM4C5nOybf+CQiiEWJByHc Oo1q75O2wAAHLf7SG8kDsGKMyjXi4bKdFn8HW4qfaVITrNJIyayw8icR2WPeO+TAdMor4B+NDvJjtV 4YXgUxNr7U8KyTfeqSKfIP1/HJw20rOeFjeMwHSfHDtl5CMx6NzT9TceqDuw1TY/DnG7lPGP74L/JW 4he8eKVFBT/URlGL4CRj2P4gKD/FDj2Y6zVlR724kQKFHneEoSdRF0y40JyVXPD4Ixd+FvjxffTOYA K/6TvPUHFv6VKillKK3lpunJgPFx//uKrg35R9Fb1vkkMbmlz5+t0KQk4fOw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766631965665630067?= X-GMAIL-MSGID: =?utf-8?q?1766631965665630067?= |
Series |
[v2] md/raid5: Convert stripe_head's "dev" to flexible array member
|
|
Commit Message
Kees Cook
May 22, 2023, 9:21 p.m. UTC
Replace old-style 1-element array of "dev" in struct stripe_head with
modern C99 flexible array. In the future, we can additionally annotate
it with the run-time size, found in the "disks" member.
Cc: Christoph Hellwig <hch@infradead.org>
Cc: linux-raid@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
It looks like this memory calculation:
memory = conf->min_nr_stripes * (sizeof(struct stripe_head) +
max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
... was already buggy (i.e. it included the single "dev" bytes in the
result). However, I'm not entirely sure if that is the right analysis,
since "dev" is not related to struct bio nor PAGE_SIZE?
v1: https://lore.kernel.org/all/20230517233313.never.130-kees@kernel.org/
v2: use new struct_size_t() helper from
https://lore.kernel.org/lkml/20230522211810.never.421-kees@kernel.org/
---
drivers/md/raid5.c | 4 ++--
drivers/md/raid5.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
Comments
On Mon, May 22, 2023 at 02:21:15PM -0700, Kees Cook wrote: > - } dev[1]; /* allocated with extra space depending of RAID geometry */ > + } dev[]; /* allocated with extra space depending of RAID geometry */ I still think this should be: /* allocated depending of RAID geometry */ now or dropped entirely, as the extra only made sense when it always had that magic one. The actual code changes looks good to me: Reviewed-by: Christoph Hellwig <hch@lst.de>
On Mon, May 22, 2023 at 2:21 PM Kees Cook <keescook@chromium.org> wrote: > > Replace old-style 1-element array of "dev" in struct stripe_head with > modern C99 flexible array. In the future, we can additionally annotate > it with the run-time size, found in the "disks" member. > > Cc: Christoph Hellwig <hch@infradead.org> > Cc: linux-raid@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> > --- > It looks like this memory calculation: > > memory = conf->min_nr_stripes * (sizeof(struct stripe_head) + > max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; > > ... was already buggy (i.e. it included the single "dev" bytes in the > result). However, I'm not entirely sure if that is the right analysis, > since "dev" is not related to struct bio nor PAGE_SIZE? > > v1: https://lore.kernel.org/all/20230517233313.never.130-kees@kernel.org/ > v2: use new struct_size_t() helper from > https://lore.kernel.org/lkml/20230522211810.never.421-kees@kernel.org/ LTGM. Thanks! I will hold this for a while until struct_size_t() merged. Song
On Tue, May 23, 2023 at 10:43:52AM -0700, Song Liu wrote: > On Mon, May 22, 2023 at 2:21 PM Kees Cook <keescook@chromium.org> wrote: > > > > Replace old-style 1-element array of "dev" in struct stripe_head with > > modern C99 flexible array. In the future, we can additionally annotate > > it with the run-time size, found in the "disks" member. > > > > Cc: Christoph Hellwig <hch@infradead.org> > > Cc: linux-raid@vger.kernel.org > > Signed-off-by: Kees Cook <keescook@chromium.org> > > --- > > It looks like this memory calculation: > > > > memory = conf->min_nr_stripes * (sizeof(struct stripe_head) + > > max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; > > > > ... was already buggy (i.e. it included the single "dev" bytes in the > > result). However, I'm not entirely sure if that is the right analysis, > > since "dev" is not related to struct bio nor PAGE_SIZE? > > > > v1: https://lore.kernel.org/all/20230517233313.never.130-kees@kernel.org/ > > v2: use new struct_size_t() helper from > > https://lore.kernel.org/lkml/20230522211810.never.421-kees@kernel.org/ > > LTGM. Thanks! Thanks! > I will hold this for a while until struct_size_t() merged. Since my tree will introduce struct_size_t(), I will just carry it there.
On Tue, May 30, 2023 at 4:00 PM Kees Cook <keescook@chromium.org> wrote: > > On Tue, May 23, 2023 at 10:43:52AM -0700, Song Liu wrote: > > On Mon, May 22, 2023 at 2:21 PM Kees Cook <keescook@chromium.org> wrote: > > > > > > Replace old-style 1-element array of "dev" in struct stripe_head with > > > modern C99 flexible array. In the future, we can additionally annotate > > > it with the run-time size, found in the "disks" member. > > > > > > Cc: Christoph Hellwig <hch@infradead.org> > > > Cc: linux-raid@vger.kernel.org > > > Signed-off-by: Kees Cook <keescook@chromium.org> > > > --- > > > It looks like this memory calculation: > > > > > > memory = conf->min_nr_stripes * (sizeof(struct stripe_head) + > > > max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; > > > > > > ... was already buggy (i.e. it included the single "dev" bytes in the > > > result). However, I'm not entirely sure if that is the right analysis, > > > since "dev" is not related to struct bio nor PAGE_SIZE? > > > > > > v1: https://lore.kernel.org/all/20230517233313.never.130-kees@kernel.org/ > > > v2: use new struct_size_t() helper from > > > https://lore.kernel.org/lkml/20230522211810.never.421-kees@kernel.org/ > > > > LTGM. Thanks! > > Thanks! > > > I will hold this for a while until struct_size_t() merged. > > Since my tree will introduce struct_size_t(), I will just carry it > there. Sounds good! You can add Acked-by: Song Liu <song@kernel.org> Thanks, Song
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 4739ed891e75..64865f9dd3f5 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2433,7 +2433,7 @@ static int grow_stripes(struct r5conf *conf, int num) conf->active_name = 0; sc = kmem_cache_create(conf->cache_name[conf->active_name], - sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), + struct_size_t(struct stripe_head, dev, devs), 0, 0, NULL); if (!sc) return 1; @@ -2559,7 +2559,7 @@ static int resize_stripes(struct r5conf *conf, int newsize) /* Step 1 */ sc = kmem_cache_create(conf->cache_name[1-conf->active_name], - sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), + struct_size_t(struct stripe_head, dev, newsize), 0, 0, NULL); if (!sc) return -ENOMEM; diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h index e873938a6125..6cfc74162b41 100644 --- a/drivers/md/raid5.h +++ b/drivers/md/raid5.h @@ -268,7 +268,7 @@ struct stripe_head { unsigned long flags; u32 log_checksum; unsigned short write_hint; - } dev[1]; /* allocated with extra space depending of RAID geometry */ + } dev[]; /* allocated with extra space depending of RAID geometry */ }; /* stripe_head_state - collects and tracks the dynamic state of a stripe_head