Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Suzuki K Poulose" <suzuki.poulose@arm.com>
Cc: kvm@vger.kernel.org, "Marc Zyngier" <maz@kernel.org>,
	kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH v18 6/7] firmware: arm_rmm: Ensure the RMM has GPT entries for memory
Date: Sat, 12 Sep 2026 08:46:54 +0000	[thread overview]
Message-ID: <20260912084654.655CF1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260912083611.2513845-7-suzuki.poulose@arm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing forward-progress check on firmware-provided boundaries (`next`) can cause an infinite loop during boot or memory hotplug.
- [High] Sub-page or inverted memblock regions are incorrectly expanded to 1GB blocks, resulting in out-of-bounds firmware queries that can falsely fail RMI initialization.
--

commit 9d5a0191d0b2d820e7529339f354ee6f7cd2d469
Author: Steven Price <steven.price@arm.com>

firmware: arm_rmm: Ensure the RMM has GPT entries for memory

This patch adds checks during initialization and hotplug to ensure that the
firmware correctly tracks memory at fine granularity and manages L1 GPTs. If
the firmware expects the host to manage tracking or GPT memory, the RMM is
deactivated.

> diff --git a/drivers/firmware/arm_rmm/rmi.c b/drivers/firmware/arm_rmm/rmi.c
> index ecc89e91d264d..583e1aca9b15a 100644
> --- a/drivers/firmware/arm_rmm/rmi.c
> +++ b/drivers/firmware/arm_rmm/rmi.c

[ ... ]

> +static int rmi_verify_memory_tracking(phys_addr_t start, phys_addr_t end)
> +{
> +	while (start < end) {
> +		unsigned long ret, category, state, next;
> +
> +		ret = rmi_granule_tracking_get(start, end, &category, &state, &next);
> +		if (ret != RMI_SUCCESS)
> +			return -ENOMEM;
> +
> +		if (state != RMI_TRACKING_FINE ||
> +		    category != RMI_MEM_CATEGORY_CONVENTIONAL) {
> +			/* TODO: Set granule tracking in this case */
> +			pr_err("Granule tracking for region isn't fine/conventional: %llx-%lx\n",
> +			       start, next);
> +			return -ENODEV;
> +		}
> +		start = next;
                ^^^^^^^^^^^^

[Severity: High]
Are we missing a forward-progress check here?

If a buggy or malicious firmware returns a next boundary where next <= start,
this loop will never terminate, resulting in a permanent kernel hang during
boot or memory hotplug.

The pre-existing rmi_undelegate_range() handles this exact scenario with:

    if (WARN_ON(out_top <= phys))
        return -ENXIO;

Could we add a similar validation check here to verify next > start?

> +	}
> +
> +	return 0;
> +}
> +
> +/*
> + * We do not support creating L1 GPTs yet. So, make sure that
> + * all the regions are managed by the firmware.
> + */
> +static int rmi_verify_gpt_firmware_managed(phys_addr_t start, phys_addr_t end)
> +{
> +	unsigned long l0gpt_sz;
> +	unsigned long next, par_state;
> +
> +	l0gpt_sz = 1UL << (30 + FIELD_GET(RMI_FEATURE_REGISTER_1_L0GPTSZ,
> +					  rmi_feat_reg(1)));
> +	start = ALIGN_DOWN(start, l0gpt_sz);
> +	end = ALIGN(end, l0gpt_sz);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^

[Severity: High]
Does this alignment expansion cause issues if the incoming range is inverted?

As noted below in rmi_init_metadata(), if an inverted range (where
start > end) is passed in, this alignment expands it into a massive block.

For example, if start=0x2000 and end=0x1000, and l0gpt_sz is 1GB, this expands
to start=0 and end=1GB. The start < end loop condition then evaluates to true,
and we end up querying the firmware for a 1GB block that might not be managed
by firmware, falsely failing initialization.

> +
> +	while (start < end) {
> +		long ret = rmi_gpt_info(start, end, &next, &par_state);
> +
> +		if (ret != RMI_SUCCESS)
> +			return -ENOMEM;
> +
> +		if (par_state != RMI_GPT_PAR_PLAT) {
> +			pr_err("GPT for the region is not managed by firmware %llx-%lx\n",
> +				start, next);
> +			return -ENOMEM;
> +		}
> +		start = next;
                ^^^^^^^^^^^^

[Severity: High]
Similar to rmi_verify_memory_tracking(), is a forward-progress check
needed here to prevent an infinite loop if the firmware returns a boundary
where next <= start?

> +	}
> +
> +	return 0;
> +}
> +
> +static int rmi_prepare_memory(phys_addr_t start, phys_addr_t end)
> +{
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[Severity: High]
Should there be an if (start >= end) return 0; check here?

This would protect downstream logic and prevent empty or inverted regions from
reaching the alignment expansion in rmi_verify_gpt_firmware_managed().

> +	int ret;
> +
> +	ret = rmi_verify_memory_tracking(start, end);
> +	if (ret)
> +		return ret;
> +
> +	return rmi_verify_gpt_firmware_managed(start, end);
> +}
> +
> +static int rmi_init_metadata(void)
> +{
> +	phys_addr_t start, end;
> +	struct memblock_region *r;
> +
> +	for_each_mem_region(r) {
> +		int ret;
> +
> +		/* Firmware-reserved NOMAP regions are not usable system RAM */
> +		if (memblock_is_nomap(r))
> +			continue;
> +
> +		start = memblock_region_memory_base_pfn(r) << PAGE_SHIFT;
> +		end = memblock_region_memory_end_pfn(r) << PAGE_SHIFT;
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[Severity: High]
Does this calculate an inverted range (start > end) for unaligned memblock
regions smaller than a page?

memblock_region_memory_base_pfn() rounds up, while
memblock_region_memory_end_pfn() rounds down. For small, unaligned memory
regions, this yields start > end.

This inverted range then flows into rmi_prepare_memory() and gets
incorrectly expanded to a full 1GB block in
rmi_verify_gpt_firmware_managed(), leading to a fatal initialization failure.

> +
> +		ret = rmi_prepare_memory(start, end);
> +		if (ret)
> +			return ret;
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260912083611.2513845-1-suzuki.poulose@arm.com?part=6

  reply	other threads:[~2026-09-12  8:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12  8:36 [PATCH v18 0/7] firmware: arm_rmm: Add RMM v2.0 base RMI support Suzuki K Poulose
2026-09-12  8:36 ` [PATCH v18 1/7] firmware: arm_rmm: Add SMC definitions for calling the RMM Suzuki K Poulose
2026-09-12  8:45   ` sashiko-bot
2026-09-12  9:04     ` Suzuki K Poulose
2026-09-12  8:36 ` [PATCH v18 2/7] firmware: arm_rmm: Check for RMI support at init Suzuki K Poulose
2026-09-12  8:36 ` [PATCH v18 3/7] firmware: arm_rmm: Configure the RMM with the host's page size Suzuki K Poulose
2026-09-12  8:36 ` [PATCH v18 4/7] firmware: arm_rmm: Add support for SRO Suzuki K Poulose
2026-09-12  8:48   ` sashiko-bot
2026-09-12 10:28     ` Suzuki K Poulose
2026-09-12  8:36 ` [PATCH v18 5/7] firmware: arm_rmm: Activate the RMM Suzuki K Poulose
2026-09-12  8:36 ` [PATCH v18 6/7] firmware: arm_rmm: Ensure the RMM has GPT entries for memory Suzuki K Poulose
2026-09-12  8:46   ` sashiko-bot [this message]
2026-09-13  6:59     ` Suzuki K Poulose
2026-09-12  8:36 ` [PATCH v18 7/7] firmware: arm_rmm: Add wrappers for Realm related RMI commands Suzuki K Poulose

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=20260912084654.655CF1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=suzuki.poulose@arm.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