mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Zhang <18255117159@163.com>
To: Arnd Bergmann <arnd@kernel.org>,
	Gerd Bayer <gbayer@linux.ibm.com>,
	Manivannan Sadhasivam <mani@kernel.org>,
	Hans Zhang <hans.zhang@cixtech.com>
Cc: "Bjorn Helgaas" <helgaas@kernel.org>,
	bhelgaas@google.com, "Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	jingoohan1@gmail.com,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-next <linux-next@vger.kernel.org>,
	linux-pci@vger.kernel.org,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Niklas Schnelle" <schnelle@linux.ibm.com>,
	"Geert Uytterhoeven" <geert@linux-m68k.org>
Subject: Re: [PATCH] PCI: Fix endianness issues in pci_bus_read_config()
Date: Mon, 4 Aug 2025 16:25:35 +0800	[thread overview]
Message-ID: <f4dfc405-1841-4254-95e9-2079c183277d@163.com> (raw)
In-Reply-To: <74c17623-f1b5-4b28-a118-4e828e1e711a@app.fastmail.com>



On 2025/8/4 16:03, Arnd Bergmann wrote:
> On Mon, Aug 4, 2025, at 05:06, Hans Zhang wrote:
>> On 2025/8/1 19:30, Gerd Bayer wrote:
>>> On Fri, 2025-08-01 at 16:24 +0530, Manivannan Sadhasivam wrote:
>>    }
>>
>> +#define CDNS_PCI_OP_READ(size, type, len)		\
>> +static inline int cdns_pcie_read_cfg_##size		\
>> +	(struct cdns_pcie *pcie, int where, type *val)	\
>> +{							\
>> +	if (len == 4)					\
>> +		*val = cdns_pcie_readl(pcie, where);	\
>> +	else if (len == 2)				\
>> +		*val = cdns_pcie_readw(pcie, where);	\
>> +	else if (len == 1)				\
>> +		*val = cdns_pcie_readb(pcie, where);	\
>> +	else						\
>> +		return PCIBIOS_BAD_REGISTER_NUMBER;	\
>> +							\
>> +	return PCIBIOS_SUCCESSFUL;			\
>> +}
>> +
>> +CDNS_PCI_OP_READ(byte, u8, 1)
>> +CDNS_PCI_OP_READ(word, u16, 2)
>> +CDNS_PCI_OP_READ(dword, u32, 4)
>> +
> 
> This is fine for the calling conventions, but the use of a macro
> doesn't really help readability, so I'd suggest just having
> separate inline functions if they are even needed.
> 

Dear Arnd,

Thank you very much for your reply.

Will change.

>> @@ -112,17 +110,17 @@ int pci_bus_read_config(void *priv, unsigned int
>> devfn, int where, u32 size,
>>    ({									\
>>    	int __ttl = PCI_FIND_CAP_TTL;					\
>>    	u8 __id, __found_pos = 0;					\
>> -	u32 __pos = (start);						\
>> -	u32 __ent;							\
>> +	u8 __pos = (start);						\
>> +	u16 __ent;							\
>>    									\
>> -	read_cfg(args, __pos, 1, &__pos);				\
>> +	read_cfg##_byte(args, __pos, &__pos);				\
>>    									\
>>    	while (__ttl--) {						\
>>    		if (__pos < PCI_STD_HEADER_SIZEOF)			\
>>    			break;						\
>>    									\
>>    		__pos = ALIGN_DOWN(__pos, 4);				\
>> -		read_cfg(args, __pos, 2, &__ent);			\
>> +		read_cfg##_word(args, __pos, &__ent);			\
>>    									\
>>    		__id = FIELD_GET(PCI_CAP_ID_MASK, __ent);		\
>>    		if (__id == 0xff)					\
> 
> I still don't feel great about this macro either, and suspect
> we should have a better abstraction with fixed types and a
> global function to do it, but I don't see anything obviously
> wrong here either.


Here is the history of communication with Bjorn and Ilpo. Because 
variable parameters need to be used, otherwise it will be very difficult 
to unify. I'll also think about your proposal again.


Bjorn:
https://lore.kernel.org/linux-pci/20250715224705.GA2504490@bhelgaas/
 > > I would like this a lot better if it could be implemented as a
 > > function, but I assume it has to be a macro for some varargs reason.
 > >
 >
Hans:
https://lore.kernel.org/linux-pci/903ea9c4-87d6-45a8-9825-4a0d45ec608f@163.com/
 > Yes. The macro definitions used in combination with the previous review
 > opinions of Ilpo.

Ilpo:
https://lore.kernel.org/linux-pci/d59fde6e-3e4a-248a-ae56-c35b4c6ec44c@linux.intel.com/
The other option would be to standardize the accessor interface signature
and pass the function as a pointer. One might immediately think of generic
PCI core accessors making it sound simpler than it is but here the
complication is the controller drivers want to pass some internal
structure due to lack of pci_dev so it would need to be void
*read_cfg_data. Then we'd need to deal with those voids also in some
generic PCI accessors which is a bit ugly.


Best regards,
Hans


  reply	other threads:[~2025-08-04  8:26 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-16 16:11 [PATCH v14 0/7] Refactor capability search into common macros Hans Zhang
2025-07-16 16:11 ` [PATCH v14 1/7] PCI: Introduce generic bus config read helper function Hans Zhang
2025-07-16 16:11 ` [PATCH v14 2/7] PCI: Clean up __pci_find_next_cap_ttl() readability Hans Zhang
2025-07-16 16:11 ` [PATCH v14 3/7] PCI: Refactor standard capability search into common macro Hans Zhang
2025-07-16 16:12 ` [PATCH v14 4/7] PCI: Refactor extended " Hans Zhang
2025-07-16 16:12 ` [PATCH v14 5/7] PCI: dwc: Use common PCI host bridge APIs for finding the capabilities Hans Zhang
2025-07-16 16:12 ` [PATCH v14 6/7] PCI: cadence: " Hans Zhang
2025-07-16 16:12 ` [PATCH v14 7/7] PCI: cadence: Use cdns_pcie_find_*capability to avoid hardcode Hans Zhang
2025-07-16 23:11 ` [PATCH v14 0/7] Refactor capability search into common macros Bjorn Helgaas
2025-07-31  7:32   ` [REGRESSION] next/master: suspect endianness issue in common PCI capability search macro Gerd Bayer
2025-07-31 17:38     ` [PATCH] PCI: Fix endianness issues in pci_bus_read_config() Gerd Bayer
2025-07-31 18:39       ` Bjorn Helgaas
2025-07-31 19:01         ` Arnd Bergmann
2025-08-01  8:18           ` Manivannan Sadhasivam
2025-08-01  9:25             ` Hans Zhang
2025-08-01  9:47               ` Manivannan Sadhasivam
2025-08-01 10:06                 ` Hans Zhang
2025-08-01 10:54                   ` Manivannan Sadhasivam
2025-08-01 11:30                     ` Gerd Bayer
2025-08-01 16:54                       ` Hans Zhang
2025-08-01 18:08                         ` Keith Busch
2025-08-02 15:23                           ` Hans Zhang
2025-08-02 15:40                             ` Arnd Bergmann
2025-08-04  3:06                       ` Hans Zhang
2025-08-04  8:03                         ` Arnd Bergmann
2025-08-04  8:25                           ` Hans Zhang [this message]
2025-08-04 10:09                         ` Gerd Bayer
2025-08-12 14:44                           ` Hans Zhang
2025-08-13  7:47                             ` Niklas Schnelle
2025-08-13  7:50                               ` Hans Zhang
2025-08-04 14:33                         ` Bjorn Helgaas
2025-08-04 15:04                           ` Hans Zhang
2025-08-01 16:47                     ` Hans Zhang
2025-07-31 18:53       ` Lukas Wunner
2025-08-01  7:52       ` Geert Uytterhoeven
2025-08-01 13:00   ` [PATCH v14 0/7] Refactor capability search into common macros Bjorn Helgaas

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=f4dfc405-1841-4254-95e9-2079c183277d@163.com \
    --to=18255117159@163.com \
    --cc=agordeev@linux.ibm.com \
    --cc=arnd@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gbayer@linux.ibm.com \
    --cc=geert@linux-m68k.org \
    --cc=hans.zhang@cixtech.com \
    --cc=helgaas@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jingoohan1@gmail.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=robh@kernel.org \
    --cc=schnelle@linux.ibm.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®