Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Magnus Lindholm" <linmag7@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v2 5/6] sparc64: add M3000 Oberon PCIe support
Date: Sun, 11 Oct 2026 20:09:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-167446@kernel.org> (raw)
In-Reply-To: <20261011195729.981243-6-linmag7@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mm: dma_4u_free_coherent leaves stale IOMMU mappings on non-Oberon platforms
- [Medium] sparc64: missing check for irq_alloc() failure in build_irq() corrupts IRQ 0
- [Low] sparc/pci: missing NULL check for 'reg' property array in DT initializers
--

commit 789a2867a71401d078d82b2a2031ee8cc4266973
Author: Magnus Lindholm <linmag7@gmail.com>

sparc64: add M3000 Oberon PCIe support

This commit adds support for the Fujitsu M3000 Oberon PCIe bridge. It
preserves firmware link setup, handles IOTSB cache line flushes for DVMA
translations, and routes legacy interrupts using the bridge's ten-bit
target ID.

> diff --git a/arch/sparc/kernel/iommu.c b/arch/sparc/kernel/iommu.c
> index 7613ab0ffb89d..9132f0535ce43 100644
> --- a/arch/sparc/kernel/iommu.c
> +++ b/arch/sparc/kernel/iommu.c

[ ... ]

> @@ -253,6 +281,15 @@ static void dma_4u_free_coherent(struct device *dev, size_t size,
>  	npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT;
>  	iommu = dev->archdata.iommu;
>  
> +	if (iommu->iommu_cache_flush) {
> +		iopte_t *base = iommu->page_table +
> +			((dvma - iommu->tbl.table_map_base) >> IO_PAGE_SHIFT);
> +		unsigned long i;
> +
> +		for (i = 0; i < npages; i++)
> +			iopte_make_dummy(iommu, base + i);
> +		iommu_sync_mapping(iommu, base, npages);
> +	}
>  	iommu_tbl_range_free(&iommu->tbl, dvma, npages, IOMMU_ERROR_CODE);

[Severity: High]
Does this leave stale IOMMU mappings on non-Oberon platforms?

When dma_4u_free_coherent() frees memory, the hardware IOMMU page table
entries (IOPTEs) mapping that memory need to be invalidated before the
physical pages are returned to the kernel allocator.

By guarding the iopte_make_dummy() loop with if (iommu->iommu_cache_flush),
this clears the hardware translation only for Oberon. For other SPARC64
platforms, the hardware IOMMU entries remain valid, potentially allowing
a malfunctioning or malicious device to perform a DMA use-after-free and
corrupt newly re-allocated kernel memory.

> diff --git a/arch/sparc/kernel/irq_64.c b/arch/sparc/kernel/irq_64.c
> index 3f55c69d5f3bc..b0f3b26656d46 100644
> --- a/arch/sparc/kernel/irq_64.c
> +++ b/arch/sparc/kernel/irq_64.c

[ ... ]

> @@ -642,6 +661,17 @@ unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
>  	return irq;
>  }
>  
> +unsigned int oberon_build_irq(int inofixup, unsigned long iclr,
> +			      unsigned long imap)
> +{
> +	unsigned int irq = build_irq(inofixup, iclr, imap);
> +	struct irq_handler_data *data = irq_get_handler_data(irq);
> +
> +	if (data)
> +		data->oberon = true;
> +	return irq;
> +}

[Severity: Medium]
Is there a missing check for an irq_alloc() failure here?

The newly introduced oberon_build_irq() wrapper calls build_irq().
If irq_alloc() fails during device initialization or under extreme resource
pressure, it returns 0. build_irq() does not check for this 0 return
value and proceeds to use it as a valid IRQ.

This would cause irq_set_chip_and_handler_name() and irq_get_handler_data()
to operate on IRQ 0. Since IRQ 0 is bound to the system timer interrupt
on SPARC64, could this corrupt the system timer and lead to a system hang?

> diff --git a/arch/sparc/kernel/prom_irqtrans.c b/arch/sparc/kernel/prom_irqtrans.c
> index 5752bfd73ac0c..60fd6b0f47e13 100644
> --- a/arch/sparc/kernel/prom_irqtrans.c
> +++ b/arch/sparc/kernel/prom_irqtrans.c

[ ... ]

> @@ -553,6 +556,7 @@ static void __init fire_irq_trans_init(struct device_node *dp)
>  	regs = of_get_property(dp, "reg", NULL);
>  	dp->irq_trans->data = irq_data;
>  
> +	irq_data->oberon = of_device_is_compatible(dp, "pciex108e,80f8");
>  	irq_data->pbm_regs = regs[0].phys_addr;
>  	irq_data->portid = of_getintprop_default(dp, "portid", 0);
>  }

[Severity: Low]
Does this code need a NULL check for the 'reg' property?

of_get_property() can return NULL if the property is missing or malformed.
This would lead to a NULL pointer dereference when accessing
regs[0].phys_addr.

While SPARC OpenBoot PROM typically guarantees the presence of 'reg'
properties for PCI root nodes, making this mostly theoretical in practice,
it appears to violate the API contract. Other sibling drivers enforce
this check. Should we add a NULL check in fire_irq_trans_init() and
pci_fire_pbm_init() to protect the new Oberon PCIe bridge compatibility?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261011195729.981243-1-linmag7@gmail.com?part=5

  reply	other threads:[~2026-10-11 20:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 19:55 [PATCH v2 0/6] sparc64: add Fujitsu M3000 support Magnus Lindholm
2026-10-11 19:55 ` [PATCH v2 1/6] sparc64: return from the generic clear_page implementation Magnus Lindholm
2026-10-11 20:01   ` sashiko-bot
2026-10-11 19:55 ` [PATCH v2 2/6] sparc64: honor queued spinlock layout in secondary startup Magnus Lindholm
2026-10-11 20:05   ` sashiko-bot
2026-10-11 19:55 ` [PATCH v2 3/6] sparc64: avoid huge kernel PUD mappings on sun4u Magnus Lindholm
2026-10-11 20:04   ` sashiko-bot
2026-10-11 19:55 ` [PATCH v2 4/6] sparc64: add SPARC64 VII CPU, MMU and SMP support Magnus Lindholm
2026-10-11 20:09   ` sashiko-bot
2026-10-12  7:34   ` kernel test robot
2026-10-11 19:55 ` [PATCH v2 5/6] sparc64: add M3000 Oberon PCIe support Magnus Lindholm
2026-10-11 20:09   ` sashiko-bot [this message]
2026-10-11 19:55 ` [PATCH v2 6/6] hvc: add an M3000 firmware console backend Magnus Lindholm
2026-10-11 20:05   ` sashiko-bot
2026-10-12  6:46   ` Jiri Slaby
2026-10-12 14:57     ` Magnus Lindholm

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=sashiko-outbox-167446@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linmag7@gmail.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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