The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Narayana Murty N <nnmlinux@linux.ibm.com>
To: Sourabh Jain <sourabhjain@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 2/5] powerpc/pseries/eeh: Add RTAS error injection helpers
Date: Fri, 20 Nov 2026 12:49:28 +0530	[thread overview]
Message-ID: <a149f6b8-2aba-4e99-a64a-ef9ec7f0d449@linux.ibm.com> (raw)
In-Reply-To: <864398a6-8a74-43df-9594-452a9edd99e9@linux.ibm.com>

Hi Sourabh,

On 18/11/26 10:13 PM, Sourabh Jain wrote:
> Hello Narayana,
> 
> The commit message contains several implementation details that make it 
> difficult to
> understand the actual purpose of this patch. Could you simplify and 
> restructure it to
> focus on the functionality being introduced and why it is needed?
> 
Sure. I'll merge this patch with 3/5 and rework the commit message.
This will also address the unused static functions reported by Sashiko.
> On 23/10/26 13:06, Narayana Murty N wrote:
>> Prepare the pSeries EEH backend for RTAS error injection by adding
>> helpers that:
>>
>>    * map generic EEH error types to RTAS/PAPR error types;
>>    * validate IOA addresses against the target PE.
>>
>> Define pr_fmt unconditionally at the top of eeh_pseries.c so all
>> pr_*() calls carry the "EEH: " prefix.
> 
> I don't think there's a need to mention pr_fmt here, as it's not a key
> objective of the patch. This could simply be a note at the end.
> 
Agreed. I'll drop this from the commit message.
>> Define RTAS firmware error-type encodings as file-local constants.
>> Only the two IOA bus-error types are supported; other PAPR encodings
>> are not reachable through the generic EEH_ERR_TYPE_* UAPI:
>>
>>    RTAS_ERR_TYPE_IOA_BUS_ERROR     0x07
>>    RTAS_ERR_TYPE_IOA_BUS_ERROR_64  0x0f
>>
>> Add RTAS_ERRINJCT_BUF_SIZE for the ibm,errinjct work buffer size.
> 
> I'm not sure RTAS_ERRINJCT_BUF_SIZE needs to be included in this patch,
> as it seems unrelated and isn't used by any of the APIs introduced here.
> Would it make more sense to move this to the patch where it is actually 
> used?
> 
Yes, this will be addressed by merging the two patches.
>> Add pseries_eeh_type_to_rtas() to translate the two generic EEH error
>> types (EEH_ERR_TYPE_32, EEH_ERR_TYPE_64) into the corresponding RTAS
>> ibm,errinjct encodings.
>>
>> Add validate_addr_mask_in_pe() to verify that a caller-provided address
>> falls within a BAR of some device in the PE.  RTAS IOA bus-error
>> injection requires a PCI/IOA bus address; validate_addr_mask_in_pe()
>> accepts only PCI bus addresses.  VFIO userspace resource addresses are
>> normalized to PCI bus addresses in vfio_iommu_spapr_tce.c before
>> reaching this backend; no resource-address fallback is added here.
>>
>> Use pcibios_resource_to_bus() to convert each BAR resource to PCI bus
>> address space before validating the address.  Only standard BARs
>> (BAR0..BAR5) are searched; ROM and bridge resources are not IOA
>> bus-error targets.  Hold pci_rescan_remove_lock while traversing PE
>> devices and their BAR resources so PCI device removal cannot race the
>> address validation.
>>
>> Skip unassigned or disabled BARs explicitly: on pseries,
>> pcibios_fixup_resources() zero-bases unassigned BARs (start=0,
>> end=size-1) and sets IORESOURCE_UNSET, so resource_size() is non-zero
>> for them and pcibios_resource_to_bus() treats them as bus address zero.
>> Use pci_resource_len() (which returns 0 when end==0) instead of
>> resource_size(), and reject BARs with IORESOURCE_UNSET or
>> IORESOURCE_DISABLED set.
>>
>> Returns -EINVAL (Linux errno) rather than a raw RTAS status.
> 
> This is another example where I'm having difficulty understanding
> how the above statement relates to the new APIs introduced by this patch.
>
Agreed. This detail is unnecessary here. >> validate_errinjct_args() and 
prepare_errinjct_buffer() are introduced
>> in the next patch alongside their callers so each intermediate commit
>> builds cleanly with CONFIG_WERROR.
>>
>> pseries_eeh_err_inject() retains the existing MMIO injection body
>> unchanged in this patch.
> 
> 
> Okay, but could you clarify how these are related to the APIs introduced 
> in this patch?
> 
>> It is replaced by the full RTAS session
>> implementation in the next patch.  This keeps the patch bisectable:
>> each commit builds and functions correctly independently.
> 
> Could you help me understand the need to mention git bisect-ability here?
> 
> I'm also not sure why the above two paragraphs are needed. Why do we need
> to document the nuances of other APIs in this patch when they are introduce
> or modified in subsequent patches?
> 
The intention was to introduce the helpers without breaking
intermediate builds. However, the current split still leaves unused
static functions. I'll merge the patches and drop these explanations.
>>
>> Reported-by: kernel test robot <lkp@intel.com>
>> Closes: https://lore.kernel.org/oe-kbuild-all/202512101130.EYUo0oZx- 
>> lkp@intel.com/
> 
> 
> Aren't these tags intended for cases where the issue is fixed in a 
> separate patch/commit,
> rather than in a revised version of the same patch? Do we really these 
> tags?
> 
Agreed. I'll drop these tags and retain the details in the changelog.
> 
>> Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
>> ---
>>   arch/powerpc/platforms/pseries/eeh_pseries.c | 134 +++++++++++++++++++
>>   1 file changed, 134 insertions(+)
>>
>> diff --git a/arch/powerpc/platforms/pseries/eeh_pseries.c b/arch/ 
>> powerpc/platforms/pseries/eeh_pseries.c
>> index b12ef382fec7..28b1fd19e8bc 100644
>> --- a/arch/powerpc/platforms/pseries/eeh_pseries.c
>> +++ b/arch/powerpc/platforms/pseries/eeh_pseries.c
>> @@ -12,6 +12,8 @@
>>    * Copyright Linas Vepstas 2005, 2006
>>    */
>> +#define pr_fmt(fmt) "EEH: " fmt
>> +
>>   #include <linux/atomic.h>
>>   #include <linux/delay.h>
>>   #include <linux/export.h>
>> @@ -23,6 +25,7 @@
>>   #include <linux/rbtree.h>
>>   #include <linux/sched.h>
>>   #include <linux/seq_file.h>
>> +#include <linux/sizes.h>
>>   #include <linux/spinlock.h>
>>   #include <linux/crash_dump.h>
>> @@ -786,6 +789,137 @@ static int pseries_notify_resume(struct eeh_dev 
>> *edev)
>>   }
>>   #endif
>> +/*
>> + * RTAS firmware error-type encodings (PAPR).  These are pseries- 
>> private;
>> + * user-space sees only the generic EEH_ERR_TYPE_* values from eeh.h.
>> + * Only IOA bus-error types are supported; other PAPR encodings are not
>> + * reachable through the generic EEH_ERR_TYPE_* UAPI.
>> + */
>> +#define RTAS_ERR_TYPE_IOA_BUS_ERROR        0x07
>> +#define RTAS_ERR_TYPE_IOA_BUS_ERROR_64        0x0f
>> +
>> +/* Size of the ibm,errinjct work buffer as defined by PAPR */
>> +#define RTAS_ERRINJCT_BUF_SIZE            SZ_1K
> 
> Wouldn't it be better to move this to the first patch where it is used?
> 
Yes. Addressed by merging 2/5 and 3/5.
>> +
>> +/**
>> + * pseries_eeh_type_to_rtas - Map generic EEH error type to RTAS 
>> encoding
>> + * @type: generic EEH error type (EEH_ERR_TYPE_32, EEH_ERR_TYPE_64)
>> + *
>> + * Translates the generic VFIO/EEH error type passed from userspace into
>> + * the RTAS-specific ibm,errinjct error type encoding defined by PAPR.
>> + *
>> + * Return: RTAS error type on success, -EINVAL for unknown types.
>> + */
>> +static int pseries_eeh_type_to_rtas(int type)
>> +{
>> +    switch (type) {
>> +    case EEH_ERR_TYPE_32:
>> +        return RTAS_ERR_TYPE_IOA_BUS_ERROR;
>> +    case EEH_ERR_TYPE_64:
>> +        return RTAS_ERR_TYPE_IOA_BUS_ERROR_64;
>> +    default:
>> +        return -EINVAL;
>> +    }
>> +}
>> +
>> +/**
>> + * validate_addr_mask_in_pe - Validate addr against PCI bus BAR 
>> addresses in PE
>> + * @pe:   EEH PE containing one or more PCI devices
>> + * @addr: PCI bus address to validate
>> + * @mask: address mask (passed to firmware unchanged)
> 
> Is the mask really necessary?
> 
No. It is only used to identify the no-address injection case
where both addr and mask are zero. I'll move that check to
the caller and remove the mask argument from this helper.
> 
>> + *
>> + * RTAS IOA bus-error injection uses PCI bus addresses.  Linux PCI 
>> resources
>> + * are CPU/resource addresses and may differ on pseries due to PHB 
>> window
>> + * translation.  Convert each BAR resource to PCI bus address space 
>> before
>> + * validating @addr.
> 
> The same comment is also present inside the function. Could we drop one to
> avoid duplication? I think keeping it inside the function would be better.
> 
> 
Sure.
>> + *
>> + * Zero addr and mask are accepted without BAR lookup (no-address 
>> injection).
>> + *
>> + * Return: 0 if valid, -EINVAL on invalid input.
> 
> I think, -EINVAL otherwise. would be more accurate.
> 
Agreed.
>> + */
>> +static int validate_addr_mask_in_pe(struct eeh_pe *pe, unsigned long 
>> addr,
>> +                    unsigned long mask)
>> +{
>> +    struct pci_bus_region region;
>> +    struct eeh_dev *edev, *tmp;
>> +    struct pci_dev *pdev;
>> +    struct resource *res;
>> +    resource_size_t bus_start;
>> +    resource_size_t bus_len;
>> +    bool found = false;
>> +    int bar;
>> +
>> +    if (!addr && !mask)
>> +        return 0;
>> +
>> +    if (!pe)
>> +        return -EINVAL;
>> +
>> +    /*
>> +     * RTAS IOA bus-error injection uses PCI bus addresses. Linux PCI
>> +     * resources are CPU/resource addresses and may differ on pseries 
>> due
>> +     * to PHB window translation. Convert each BAR resource to PCI bus
>> +     * address space before validating @addr.
>> +     *
>> +     * Hold pci_rescan_remove_lock across the traversal to protect pdev
>> +     * lifetime: pci_stop_and_remove_bus_device() requires this lock.
> 
> Wouldn't it be more meaningful to explain why this lock is needed here
> rather than listing other APIs that use it?
> 
Agreed. The lock is intended to protect the traversal against
concurrent PCI device removal. I'll simplify the comment.
>> +     */
>> +    pci_lock_rescan_remove();
>> +    eeh_pe_for_each_dev(pe, edev, tmp) {
>> +        pdev = eeh_dev_to_pci_dev(edev);
>> +        if (!pdev)
>> +            continue;
>> +
>> +        /*
>> +         * Validate against standard BARs (BAR0..BAR5) only.
>> +         * ROM and bridge resources are not IOA bus-error targets.
>> +         */
>> +        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.
>> +             * resource_size() is non-zero for such BARs, and
>> +             * pcibios_resource_to_bus() treats them as bus address
>> +             * zero, so they must be excluded explicitly.
>> +             * 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;
> 
> Nit: Would it be better to check the above conditions before calling 
> pci_resource_len()?
> 
Sure. I'll check the resource flags first.
>> +
>> +            pcibios_resource_to_bus(pdev->bus, &region, res);
>> +
>> +            bus_start = region.start;
>> +            bus_len = pci_resource_len(pdev, bar);
> 
> How the bus_len returned by pci_resource_len(...) is different from?
> bus_len = region.end - region.start + 1;
> 
There is no difference for a valid BAR, as the translation
preserves the resource size. I'll avoid the redundant calculation.
>> +
>> +            if ((resource_size_t)addr >= bus_start &&
>> +                ((resource_size_t)addr - bus_start) < bus_len) {
>> +                pr_debug("addr=0x%lx mask=0x%lx validated in PCI bus 
>> BAR[%d] of %s: bus range 0x%llx-0x%llx\n",
>> +                     addr, mask, bar, pci_name(pdev),
>> +                     (unsigned long long)region.start,
>> +                     (unsigned long long)region.end);
>> +                found = true;
>> +                goto done;
>> +            }
>> +        }
>> +    }
>> +done:
>> +    pci_unlock_rescan_remove();
>> +
>> +    if (!found)
>> +        pr_err("addr=0x%lx mask=0x%lx not within any PCI bus BAR of 
>> any device in PE\n",
>> +               addr, mask);
>> +    return found ? 0 : -EINVAL;
> 
> This check is repeated twice here. I think we can improve this. How about
> restructuring the function as follows:
> 
> 
> static bool addr_in_pdev_bars(pdev, addr)
> {
>      for (bar = 0; bar < 6; bar++) {
>          len = pci_resource_len(pdev, bar);
>          if (!len || !is_mem_or_io(res) || is_unset_or_disabled(res))
>              continue;
> 
>          pcibios_resource_to_bus(pdev->bus, &region, res);
>          if (addr >= region.start && addr - region.start < len)
>              return true;
>      }
>      return false;
> }
> 
> static int validate_addr_mask_in_pe(pe, addr, mask)
> {
>      if (!addr && !mask)
>          return 0;
>      if (!pe)
>          return -EINVAL;
> 
>      pci_lock_rescan_remove();
>      for_each_dev(pe, pdev) {
>          if (pdev && addr_in_pdev_bars(pdev, addr)) {
>              pci_unlock_rescan_remove();
>              return 0;
>          }
>      }
>      pci_unlock_rescan_remove();
> 
>      pr_err("addr not in any BAR of PE\n");
>      return -EINVAL;
> }
> 
> 
> Splitting out the BAR check gets rid of the goto and the found flag.
> The lock and unlock now sit around one simple loop.
> 
Agreed. I'll split the per-device BAR lookup from the PE
traversal as suggested, with the no-address check moved to
the caller.
> - Sourabh Jain
> 
>> +}
>> +
>>   /**
>>    * pseries_eeh_err_inject - Inject specified error to the indicated PE
>>    * @pe: the indicated PE
Thnks,
Narayana Murty.
> 


  reply	other threads:[~2026-11-20  7:20 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 [this message]
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
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=a149f6b8-2aba-4e99-a64a-ef9ec7f0d449@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=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