From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A24D73515DC for ; Fri, 24 Jul 2026 09:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784885951; cv=none; b=sAFxSyjTe9Ozzj3gP0dTVq5I5KvwbRiUplErrRxJQanY7dzsLITL0EMQ5qEcwdxnPuB7oLW7xOgHPpOfZMRyAWzT+iDf+Zt0vZ6uuZOf+AucXqxMtRk7t/E10c80L8tl/x4NTMGCLSxuQWVQPJGqz++7YKhFAXwLgXaqlL63OQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784885951; c=relaxed/simple; bh=lPJYcrX6dxMqm5hFji5LRI5ysW2zacRXgeyN12rBzNM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=BK2ne0VOWFp35mJWKvUPM+dz3IXcaNv7cjHa1oOIehlE+uSiBpg3aiiOWsOa+3lVAZRU6j5Pi+c3JxcEYaDHk2FQmels6jvI1PsnK5sB0YzssYyKUwphKrcMv7M4X9AKf9tnl3XLvm6N0kNsWsKwlALVuc/FpmObBTv5wzNiFJA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=PhkQHF76; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="PhkQHF76" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id BEABC1A11E0; Fri, 24 Jul 2026 09:39:06 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8B38F60395; Fri, 24 Jul 2026 09:39:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A26FA11C11DD9; Fri, 24 Jul 2026 11:39:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1784885945; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=A27jFx12vXNfjqH81hfxNYD7vviQVQL2KMKHCn7ENQs=; b=PhkQHF76iDWeAc/yIL0oAMk9si6TAkOpEkfCminZH90M0OrakeDBQs5z+RcUCSswqer+SM sifbA+TlFcuiAeXoE5Bgsrjf6dkFEcDtA4YXnVtdOLSfUkofFS9vEeow7+HDVC/mE2PgAF Xnbp5x5L1d5gCP/rFO7lFz9zxX9HSgtlD4CRJL0pMA85zZ3pJ4fkHxuPjgsX4qMeoGHO/W f34VcwRJBruNvVXK5XQgm5Fm+eZ4eY4Bupkjm+dBichPKyXkGrXaI6H1NaBSXD+fuCh1LN m8pnvEs2kNSX9umJfx5Et7D89RK4Fm6JzENQ+2BVWDP9/e/dUj1NQ6yEQoGSoA== From: Miquel Raynal To: Pengpeng Hou Cc: Richard Weinberger , Vignesh Raghavendra , Amit Kumar Mahapatra , Luca Ceresoli , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RFC] mtd: virt-concat: define duplicate partition handling In-Reply-To: <20260722041925.31407-1-pengpeng@iscas.ac.cn> (Pengpeng Hou's message of "Wed, 22 Jul 2026 12:19:25 +0800") References: <20260722041925.31407-1-pengpeng@iscas.ac.cn> User-Agent: mu4e 1.12.12; emacs 30.2 Date: Fri, 24 Jul 2026 11:39:01 +0200 Message-ID: <874ihosp56.fsf@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Hi Pengpeng, On 22/07/2026 at 12:19:25 +08, Pengpeng Hou wrote: > mtd_device_parse_register() contains compatibility handling for drivers t= hat > call it more than once, while its comment notes that partition parsing can > register the same partitions again. Is this feature really relevant? Who uses that? > When CONFIG_MTD_PARTITIONED_MASTER is disabled and the first call finds > partitions, the master itself is not registered before parsing. A later c= all > can therefore reach partition parsing again. > > With CONFIG_MTD_VIRT_CONCAT, each newly allocated partition whose OF node > belongs to a virtual concatenation reaches mtd_virt_concat_add(). That > function appends the partition based only on the OF node and increments > num_subdev without checking whether the node was already added or whether > the fixed subdev[] array is full. > > A repeated parse can therefore append the same node again. If all configu= red > slots were already populated, the append is out of bounds. If other membe= rs > are still missing, the duplicate can make num_subdev reach the configured > count with the wrong membership. > > A local bounds check does not seem sufficient for a correct patch: > > - concat_node_list and the concat population state are global, but node > creation, addition, join creation and destruction have no common > serialization. But aren't these operations serialized just because of how the MTD core is designed? > - mtd_virt_concat_add() returns bool. false means both "not a concat > member" and "not added". Returning false for a duplicate makes > add_mtd_partitions() register it as an ordinary partition, while retu= rning > true without storing it would leak the newly allocated partition. > - join creation and destruction call back into MTD registration helpers= , so > a driver-global mutex must have a carefully defined scope to avoid > recursive locking. > > My current view is that the fix needs both a serialization contract for t= he > global virtual-concat state and a tri-state add result, so the caller can > distinguish "not a member" from a duplicate or capacity error and free the > new partition on error. > > Would you prefer this serialization to live inside mtd_virt_concat, or sh= ould > the MTD registration layer serialize the node-create/partition-add/join > transaction? I have not attached a patch because choosing either scope > without agreement would encode a new lifetime and error-handling contract. If it is specific to the virt concat layer, I would try to keep the changes contained in the virt concat driver. Thanks, Miqu=C3=A8l