[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d2240ab0-5d91-4b41-945f-e29b40f7b7f4@163.com>
Date: Sat, 2 Aug 2025 23:23:34 +0800
From: Hans Zhang <18255117159@....com>
To: Keith Busch <kbusch@...nel.org>
Cc: Gerd Bayer <gbayer@...ux.ibm.com>, Manivannan Sadhasivam
<mani@...nel.org>, Hans Zhang <hans.zhang@...tech.com>,
Arnd Bergmann <arnd@...nel.org>, Bjorn Helgaas <helgaas@...nel.org>,
bhelgaas@...gle.com, Alexander Gordeev <agordeev@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
jingoohan1@...il.com, Krzysztof Wilczy´nski
<kwilczynski@...nel.org>, linux-kernel@...r.kernel.org,
linux-s390@...r.kernel.org, linux-next <linux-next@...r.kernel.org>,
linux-pci@...r.kernel.org, Lorenzo Pieralisi <lpieralisi@...nel.org>,
Rob Herring <robh@...nel.org>, Niklas Schnelle <schnelle@...ux.ibm.com>,
geert@...ux-m68k.org
Subject: Re: [PATCH] PCI: Fix endianness issues in pci_bus_read_config()
On 2025/8/2 02:08, Keith Busch wrote:
> On Sat, Aug 02, 2025 at 12:54:27AM +0800, Hans Zhang wrote:
>> As I mentioned in my reply to Mani's email, the data ultimately read here is
>> also a forced type conversion.
>>
>> #define PCI_OP_READ(size, type, len) \
>> int noinline pci_bus_read_config_##size \
>> (struct pci_bus *bus, unsigned int devfn, int pos, type *value) \
>> { \
>> unsigned long flags; \
>> u32 data = 0; \
>> int res; \
>> \
>> if (PCI_##size##_BAD) \
>> return PCIBIOS_BAD_REGISTER_NUMBER; \
>> \
>> pci_lock_config(flags); \
>> res = bus->ops->read(bus, devfn, pos, len, &data); \
>> if (res) \
>> PCI_SET_ERROR_RESPONSE(value); \
>> else \
>> *value = (type)data; \
>> pci_unlock_config(flags); \
>> \
>> return res; \
>> }
>>
>> And this function. Could it be that I misunderstood something?
>
> The above macro retains the caller's type for "value". If the caller
> passes a "u8 *", the value is deferenced as a u8.
Dear Keith,
In this macro definition, bus->ops->read needs to ensure the byte order
of the read, as Lukas mentioned; otherwise, there is also a big-endian
issue at this location.
>
> The function below promotes everything to a u32 pointer and deferences
> it as such regardless of what type the user passed in.
I searched and learned that readb/readw/readl automatically handle byte
order, so there is no big-endian order issue.
>
>> int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
>> int where, int size, u32 *val)
>> {
>> void __iomem *addr;
>>
>> addr = bus->ops->map_bus(bus, devfn, where);
>> if (!addr)
>> return PCIBIOS_DEVICE_NOT_FOUND;
>>
>> if (size == 1)
>> *val = readb(addr);
>> else if (size == 2)
>> *val = readw(addr);
>> else
>> *val = readl(addr);
>>
>> return PCIBIOS_SUCCESSFUL;
>> }
Best regards,
Hans
Powered by blists - more mailing lists