Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>
Cc: Richard Weinberger <richard@nod.at>,
	 Vignesh Raghavendra <vigneshr@ti.com>,
	 Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>,
	Luca Ceresoli <luca.ceresoli@bootlin.com>,
	linux-mtd@lists.infradead.org,  linux-kernel@vger.kernel.org
Subject: Re: [RFC] mtd: virt-concat: define duplicate partition handling
Date: Fri, 24 Jul 2026 11:39:01 +0200	[thread overview]
Message-ID: <874ihosp56.fsf@bootlin.com> (raw)
In-Reply-To: <20260722041925.31407-1-pengpeng@iscas.ac.cn> (Pengpeng Hou's message of "Wed, 22 Jul 2026 12:19:25 +0800")

Hi Pengpeng,

On 22/07/2026 at 12:19:25 +08, Pengpeng Hou <pengpeng@iscas.ac.cn> wrote:

> mtd_device_parse_register() contains compatibility handling for drivers that
> 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 call
> 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 configured
> slots were already populated, the append is out of bounds. If other members
> 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 returning
>     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 the
> 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 should
> 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èl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2026-07-24  9:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  4:19 [RFC] mtd: virt-concat: define duplicate partition handling Pengpeng Hou
2026-07-24  9:39 ` Miquel Raynal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874ihosp56.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=amit.kumar-mahapatra@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=pengpeng@iscas.ac.cn \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox