From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 B5B0142E018 for ; Fri, 10 Jul 2026 13:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783689832; cv=none; b=ajVR28fksSds4R39/izxk9IzauR3yeee/OXI5MCCDP1w8dn05Zq86DHUQQONXJ/hgRpaIgT9sPobN946ZNGpj1RNJZG0Zg3mwypUV1G0UzFaChGe8WwbNRCZLBCp56WXjbjuQv22OLiGhr8/oc9mnwnPpRsShdhD2fXAaMFz9T4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783689832; c=relaxed/simple; bh=9jdOtd0+F2HnuqXRVnhc6kV1s/ixcwmEXsxUb82eCkw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RagApMl63JWs+Oj7VzqKRPbpxsocWv4fBcASAGG3Yo7eAAKQFGrKGAYjwK9anGd071xxTy7otNc8xB5pKSpv8TYGB8rVGzVn26qYTsbLyHIeBse6N+HBdc/bCoIlVCoN4k76qZKnh046VhU4IjxYoShdRANdqDpAJ9RpqOxYjNI= 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=pz4c/Qei; arc=none smtp.client-ip=209.85.215.177 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="pz4c/Qei" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-ca913a601fbso658894a12.3 for ; Fri, 10 Jul 2026 06:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783689830; x=1784294630; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=11naR69H888D+qtYxFBRHYHQt2DJDb8Xz+8TAT38yxY=; b=pz4c/QeikGZV0A+uJ5JfVCBWIth5QsHQ0VupW0NMXlzAyey44hog8lTZdUzxNNkdto DhrpQpzexkX6RqheMkA5VEzUIVrbLyC8oTT1XlsIANH39i5ZSdLXaqaam+Byd38QkXQc dy+ndFxgbYqzkLmdm8O60B2HcsnHsg0nbBo7ACkqEfe3FVaxyPrNXGBqTHwAGWLrBD+Q gb72JhQdKyK8s/cjpu1JywzZrPQDhFh8bcv9IiGBZLAosOxPMqAN6cfGXzWA6ktE2VeE kbqlNoAKqcYhfh3TL3WQKOSqjHH0KnnCCV/hc3MceaQGykUVBPo1i3RWrHxAInQR9PNZ SprA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783689830; x=1784294630; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=11naR69H888D+qtYxFBRHYHQt2DJDb8Xz+8TAT38yxY=; b=sLjyz+cE8Y/I5WTarKZjyHaiJHG20iuVGUJiIhACFu5+OIfK2mdcDN/DgNSTbsT+OT QOYZ6ZyPqrDEpTfJIN0gxTXkGJYfYL49U/rHsopldabZYdKul0vrWfg0+MSxJbFj4xM9 /nEvBW3TVCrlXAgf904BCCc7g60fzQYbyE9378+SDIzW1UE35a3PammVOueH9sdWJa1V UVWB7aQuTLR+FbM4M7mlDZn51ejIyy0tI1pK/KZ7Yj7PE7SUx1fGoryMZVgkMPCbzZ02 ZEaqGoV+7XyIKNI79i+yx4bcE9VYD6oAGfN9GWSfWlxbOJsZSqDnXIx8vMGEs3Z2ceUR EYxA== X-Forwarded-Encrypted: i=1; AHgh+RoHu+MngXrjMDm74JMIdhQjYBRPQC+DVJojWjgLhYsQyTvVA64YEmsxXshtxEUAMBU6m/SUOiAoebZ74kg=@vger.kernel.org X-Gm-Message-State: AOJu0YyvKExKcFkncPxVUAwAhL+LXkITcsOyiZzxIUgxzrajJFnvlRXE awXEIv/cb8diV05Ky4VMwcBr43ECu3HNWh8KTiEiXzFVoTnkGlvgu2BxwZQJsACwcaXmeA== X-Gm-Gg: AfdE7cmkFaIZ3Jhxxx6q26Jq7DB1C6ruYNibZulQaGXj6KGsokb+3aYiK8wfPvY+Zu+ reEyQmTBewyl4CIK6jztvgFgDAuaYXZ2ohAKE9tuuiFV8t11BpvAiwhVMEmgyVbdNPE4GgMwFx4 37aBiIIQSZ3RE3CqHHjGZw3otF+Byv8kEpW+iSc1knbARyQB9W1VBUrzMSf13W3+XMJzc56SEnT pslcHcKidBwZtR2WI3DgFkZvfMxNXfPaUKt0C+a0LT+aMPmxJaA5W3cbGQ4m8Wkyn882Cq8fsZX YDambt1uCbqbyqJsrGiqSrqCjBmDzkWS15X3oNjWUZNYcC2mKNYHG5ofvAFAM7P7Q7if/PZ5+mL C0mx0SBtqmZwPgnhDBxtsTjktZWLml/QBXJoK4q4S1i3fUFcDfJBDjFqbP9IUGZUWk+nIv9579b hqTL4+kxgpk5TRuuivCgUKxFomWWdTVBfCGNrgbMaZRpsPZywE5sA9fLVa5SgEVpf3GAzYFgIYG nTqG9Q= X-Received: by 2002:a05:6a21:1f88:b0:3bf:9bfd:ca95 with SMTP id adf61e73a8af0-3c0bcce7f31mr12749554637.34.1783689830035; Fri, 10 Jul 2026 06:23:50 -0700 (PDT) Received: from research02.. ([2601:1c1:8700:f5b:fe34:97ff:fea3:c147]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ca5b3b251eesm4903776a12.31.2026.07.10.06.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 06:23:49 -0700 (PDT) From: Hiroshi Nishida To: Song Liu , Yu Kuai Cc: Li Nan , Xiao Ni , linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Hiroshi Nishida Subject: [PATCH 1/6] md/raid5: size the worker group array by nr_node_ids Date: Fri, 10 Jul 2026 06:23:41 -0700 Message-ID: <20260710132346.7295-2-nishidafmly@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710132346.7295-1-nishidafmly@gmail.com> References: <20260710132346.7295-1-nishidafmly@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit alloc_thread_groups() sizes conf->worker_groups[] by num_possible_nodes() -- the number of possible NUMA nodes -- but raid5_wakeup_stripe_thread() indexes it by cpu_to_group(cpu), i.e. cpu_to_node(cpu), which is a node id. When the node map is sparse (for example possible nodes 0 and 2) the node count is 2 while the largest node id is 2, so the index reaches worker_groups[2] on a two-element array -- an out-of-bounds access. This has stayed latent because worker groups are only allocated when group_thread_cnt is non-zero, and the historical default is 0. Size the array by nr_node_ids -- one past the largest possible node id -- so that indexing by cpu_to_node() is always in bounds. On a dense node map nr_node_ids equals num_possible_nodes() and nothing changes; on a sparse map the array just gains the unused id slots it needs. Fixes: 851c30c9badf ("raid5: offload stripe handle to workqueue") Signed-off-by: Hiroshi Nishida --- drivers/md/raid5.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 0c5c9fb0606e..d8807114a693 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7322,7 +7322,13 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt, int *group_cnt, *worker_groups = NULL; return 0; } - *group_cnt = num_possible_nodes(); + /* + * worker_groups is indexed by cpu_to_group() == cpu_to_node(), a node + * id, so it must have room for the largest possible id. Size it by + * nr_node_ids (one past that id), not num_possible_nodes(), which is + * only the node count and is smaller on a sparse node map. + */ + *group_cnt = nr_node_ids; size = sizeof(struct r5worker) * cnt; workers = kcalloc(size, *group_cnt, GFP_NOIO); *worker_groups = kzalloc_objs(struct r5worker_group, *group_cnt, -- 2.43.0