From: Narayana Murty N <nnmlinux@linux.ibm.com>
To: Sourabh Jain <sourabhjain@linux.ibm.com>,
Mahesh J Salgaonkar <mahesh@linux.ibm.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
"Oliver O'Halloran" <oohall@gmail.com>,
Timothy Pearson <tpearson@raptorengineering.com>,
Alex Williamson <alex@shazbot.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Christophe Leroy <chleroy@kernel.org>,
Ritesh Harjani <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, sbhat@linux.ibm.com, harshpb@linux.ibm.com
Subject: Re: [PATCH v6 4/5] vfio/spapr_tce: Normalize EEH IOA error injection addresses
Date: Fri, 20 Nov 2026 13:06:18 +0530 [thread overview]
Message-ID: <1b52c142-116c-4a9e-af19-578a9a71e3f3@linux.ibm.com> (raw)
In-Reply-To: <518b5813-ab4e-413e-9820-556888216090@linux.ibm.com>
On 19/11/26 1:05 AM, Sourabh Jain wrote:
> I'm finding this commit message a bit difficult to follow.
> Could you please rework it to make the changes and their purpose clearer?
>
Agreed. I'll rework the commit message to focus on why address
translation is needed in the VFIO EEH path.
> On 23/10/26 13:06, Narayana Murty N wrote:
>> VFIO_EEH_PE_INJECT_ERR receives a target address from userspace. For
>> userspace such as QEMU, this address may be derived from the host Linux
>> BAR resource. The platform EEH backends, however, expect the PCI/IOA
>> bus address used by firmware error-injection interfaces.
>>
>> Normalize IOA/MMIO error-injection addresses in the sPAPR VFIO EEH
>> ioctl path before dispatching to eeh_pe_inject_err(). If the supplied
>> address is already a PCI bus BAR address it is left unchanged. If it is
>> a Linux resource address, translate it to the corresponding PCI bus
>> address using the BAR-relative offset.
>>
>> Normalization applies only to EEH_ERR_TYPE_32 and EEH_ERR_TYPE_64 error
>> types whose error function targets a memory or IO BAR (load/store memory
>> and load/store IO functions, func 0-3 and 6-9). Config-space functions
>> carry PCI config register offsets and DMA functions carry IOVA/TCE
>> addresses; these address domains are not PCI BAR addresses and must not
>> be translated. Applying BAR normalization to them would incorrectly
>> return -EINVAL, blocking injection entirely for those function codes.
>>
>> An address and mask pair of zero represents a no-address injection
>> (e.g. a function-level error with no specific IOA target) and is passed
>> through without BAR translation.
>>
>> Only standard BARs (BAR0..BAR5) are searched; ROM and bridge resources
>> are not IOA bus-error targets. Unassigned or disabled BARs are skipped:
>> pci_resource_len() returns 0 for zero-initialized BARs, and the
>> IORESOURCE_UNSET and IORESOURCE_DISABLED flags are checked explicitly to
>> avoid false matches against unassigned resources. Hold
>> pci_rescan_remove_lock while traversing PE devices and their BAR
>> resources to prevent PCI device removal from racing the lookup.
>>
>> A pr_debug() is emitted if the address cannot be matched to any BAR, to
>> aid debugging without producing noise in the normal path.
> Which address are you referring to?
>
The target address supplied by userspace through
VFIO_EEH_PE_INJECT_ERR, which may be a Linux resource address or
a PCI bus address.
I'll make this explicit in the commit message.
>
>>
>> Keep the helper local to VFIO so the address semantics of other
>> in-kernel EEH callers remain unchanged.
>
> Which helper are you referring to?
>
I was referring to vfio_spapr_eeh_normalize_addr().
The intention is to keep the resource-to-bus address translation
local to the VFIO path without changing the address semantics of
other EEH callers.
>
>>
>> Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
>> ---
>> drivers/vfio/vfio_iommu_spapr_tce.c | 140 ++++++++++++++++++++++++++++
>> 1 file changed, 140 insertions(+)
>>
>> diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/
>> vfio_iommu_spapr_tce.c
>> index 1c0eec228cc6..d831adaa69fb 100644
>> --- a/drivers/vfio/vfio_iommu_spapr_tce.c
>> +++ b/drivers/vfio/vfio_iommu_spapr_tce.c
>> @@ -774,6 +774,131 @@ static long
>> tce_iommu_create_default_window(struct tce_container *container)
>> return ret;
>> }
>> +/*
>> + * eeh_func_needs_bar_addr - return true for error functions whose addr
>> + * argument is a PCI MMIO or IO BAR address.
>> + *
>> + * Memory and IO load/store functions target specific BAR addresses.
>> + * Config-space functions carry PCI config register offsets, and DMA
>> + * functions carry IOVA/TCE addresses; neither requires BAR translation.
>> + */
>> +static bool eeh_func_needs_bar_addr(int func)
>> +{
>> + switch (func) {
>> + case EEH_ERR_FUNC_LD_MEM_ADDR:
>> + case EEH_ERR_FUNC_LD_MEM_DATA:
>> + case EEH_ERR_FUNC_LD_IO_ADDR:
>> + case EEH_ERR_FUNC_LD_IO_DATA:
>> + case EEH_ERR_FUNC_ST_MEM_ADDR:
>> + case EEH_ERR_FUNC_ST_MEM_DATA:
>> + case EEH_ERR_FUNC_ST_IO_ADDR:
>> + case EEH_ERR_FUNC_ST_IO_DATA:
>> + return true;
>> + default:
>> + return false;
>> + }
>> +}
>> +
>> +static int vfio_spapr_eeh_normalize_addr(struct eeh_pe *pe,
>> + unsigned long addr,
>> + unsigned long mask,
> Do we really need mask argument?
>
The mask argument is currently used only to identify the no-address
injection case where both addr and mask are zero.
I'll move that check to the ioctl caller and remove the mask
argument from the normalization helper.
>> + unsigned long *normalized)
>
> Too much in a single function. Can you split this function as suggested
> for validate_addr_mask_in_pe() in 2/5.
>
Agreed. I'll separate the per-device BAR matching and address.
> - Sourabh Jain
>
>> +{
>> + struct pci_bus_region region;
>> + struct eeh_dev *edev, *tmp;
>> + struct pci_dev *pdev;
>> + struct resource *res;
>> + resource_size_t pci_start, pci_len;
>> + resource_size_t res_start, res_len;
>> + resource_size_t offset;
>> + int bar, rc = -EINVAL;
>> +
>> + if (!pe || !normalized)
>> + return -EINVAL;
>> +
>> + /*
>> + * addr == 0 and mask == 0 indicates a no-address injection (e.g.
>> + * function-level error with no specific IOA target). No BAR
>> + * translation needed.
>> + */
>> + if (!addr && !mask) {
>> + *normalized = addr;
>> + return 0;
>> + }
>> +
>> + /*
>> + * Walk standard BARs (BAR0..BAR5) of all devices in the PE.
>> + * Hold pci_rescan_remove_lock to protect pdev lifetime during the
>> + * traversal: pci_stop_and_remove_bus_device() requires this lock.
>> + * ROM and bridge resources are not IOA bus-error targets, so the
>> + * search is limited to PCI_STD_NUM_BARS.
>> + */
>> + pci_lock_rescan_remove();
>> + eeh_pe_for_each_dev(pe, edev, tmp) {
>> + pdev = eeh_dev_to_pci_dev(edev);
>> + if (!pdev)
>> + continue;
>> +
>> + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
>> + res = &pdev->resource[bar];
>> +
>> + /*
>> + * Skip unassigned or disabled BARs. On pseries,
>> + * pcibios_fixup_resources() zero-bases unassigned BARs
>> + * (start=0, end=size-1) and sets IORESOURCE_UNSET.
>> + * Use pci_resource_len() which returns 0 when end==0.
>> + */
>> + if (!pci_resource_len(pdev, bar))
>> + continue;
>> +
>> + if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
>> + continue;
>> +
>> + if (res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
>> + continue;
>> +
>> + pcibios_resource_to_bus(pdev->bus, ®ion, res);
>> +
>> + pci_start = region.start;
>> + pci_len = pci_resource_len(pdev, bar);
>> +
>> + /*
>> + * Case 1: userspace already supplied PCI/IOA
>> + * bus address.
>> + */
>> + if ((resource_size_t)addr >= pci_start &&
>> + ((resource_size_t)addr - pci_start) < pci_len) {
>> + *normalized = addr;
>> + rc = 0;
>> + goto done;
>> + }
>> +
>> + /*
>> + * Case 2: userspace supplied Linux resource/CPU
>> + * address. Convert it back to PCI/IOA bus address
>> + * before calling the platform EEH backend.
>> + */
>> + res_start = res->start;
>> + res_len = pci_resource_len(pdev, bar);
>> +
>> + if ((resource_size_t)addr >= res_start &&
>> + ((resource_size_t)addr - res_start) < res_len) {
>> + offset = (resource_size_t)addr - res_start;
>> + *normalized = region.start + offset;
>> + rc = 0;
>> + goto done;
>> + }
>> + }
>> + }
>> +done:
>> + pci_unlock_rescan_remove();
>> +
>> + if (rc)
>> + pr_debug("vfio EEH: addr=0x%lx not found in any PCI bus BAR
>> of PE\n",
>> + addr);
>> + return rc;
>> +}
>> +
>> static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group,
>> unsigned long arg)
>> {
>> @@ -818,6 +943,21 @@ static long vfio_spapr_ioctl_eeh_pe_op(struct
>> iommu_group *group,
>> if (copy_from_user(&op, (void __user *)arg, minsz))
>> return -EFAULT;
>> + if ((op.err.type == EEH_ERR_TYPE_32 ||
>> + op.err.type == EEH_ERR_TYPE_64) &&
>> + eeh_func_needs_bar_addr(op.err.func)) {
>> + unsigned long normalized;
>> + int ret;
>> +
>> + ret = vfio_spapr_eeh_normalize_addr(pe, op.err.addr,
>> + op.err.mask,
>> + &normalized);
>> + if (ret)
>> + return ret;
>> +
>> + op.err.addr = normalized;
>> + }
>> +
>> return eeh_pe_inject_err(pe, op.err.type, op.err.func,
>> op.err.addr, op.err.mask);
>> default:
Thanks,
Narayana Murty.
>
next prev parent reply other threads:[~2026-11-20 7:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 7:36 [PATCH v6 0/5] powerpc: Add RTAS based error injection support for pSeries Narayana Murty N
2026-10-23 7:36 ` [PATCH v6 1/5] powerpc/rtas: Handle ibm,open-errinjct return format Narayana Murty N
2026-11-18 11:13 ` Sourabh Jain
2026-11-20 4:36 ` Narayana Murty N
2026-10-23 7:36 ` [PATCH v6 2/5] powerpc/pseries/eeh: Add RTAS error injection helpers Narayana Murty N
2026-11-18 16:43 ` Sourabh Jain
2026-11-20 7:19 ` Narayana Murty N
2026-10-23 7:36 ` [PATCH v6 3/5] powerpc/pseries/eeh: Implement RTAS-based EEH error injection Narayana Murty N
2026-11-18 19:14 ` Sourabh Jain
2026-11-20 7:32 ` Narayana Murty N
2026-10-23 7:36 ` [PATCH v6 4/5] vfio/spapr_tce: Normalize EEH IOA error injection addresses Narayana Murty N
2026-11-18 19:35 ` Sourabh Jain
2026-11-20 7:36 ` Narayana Murty N [this message]
2026-10-23 7:36 ` [PATCH v6 5/5] powerpc/powernv/eeh: Map generic EEH error types to OPAL Narayana Murty N
2026-11-18 19:41 ` Sourabh Jain
2026-11-20 7:39 ` Narayana Murty N
2026-11-10 19:21 ` [PATCH v6 0/5] powerpc: Add RTAS based error injection support for pSeries tasmiya
2026-11-20 7:40 ` Narayana Murty N
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=1b52c142-116c-4a9e-af19-578a9a71e3f3@linux.ibm.com \
--to=nnmlinux@linux.ibm.com \
--cc=alex@shazbot.org \
--cc=chleroy@kernel.org \
--cc=harshpb@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mahesh@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=oohall@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=sbhat@linux.ibm.com \
--cc=sourabhjain@linux.ibm.com \
--cc=sshegde@linux.ibm.com \
--cc=tpearson@raptorengineering.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
all inboxes | Powered by JetHome®