linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesse Brandeburg <jesse.brandeburg@intel.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: <mj@ucw.cz>, <linux-pci@vger.kernel.org>
Subject: Re: [PATCH pciutils v1] pciutils: add new readpci utility
Date: Tue, 11 Oct 2022 10:47:26 -0700	[thread overview]
Message-ID: <e17390fb-0aee-4111-36fc-61bdf6799180@intel.com> (raw)
In-Reply-To: <20221011164904.GA2995976@bhelgaas>

On 10/11/2022 9:49 AM, Bjorn Helgaas wrote:
> I like this idea.  I often use rdwrmem, which is more general-purpose,
> but it's a bit of a hassle that it's not commonly installed like
> pciutils is, and you have to manually come up with the physical
> address of a BAR.

I think that's a lot of the advantage of this tool. And yes, there are a 
lot of other versions of this program around that just read/write 
/dev/mem. Having it come with the pciutils makes the most sense to me, 
which is why I'm here.

> The names:
>    "setpci" -- read and write PCI config space
>    "readpci" -- read and write PCI MMIO BARs
> are slightly confusing since both support reads *and* writes, and
> there's no clear config space vs BAR connection in the names.

Yeah, naming is super hard. I chose the *pci name to just keep it 
consistent with the tools in this package, but if Martin or you has some 
other suggestions, we can rabbit down that hole. I'm not super opposed 
to something like:
"mmio_write_pci"
or even
"mmio_pci"

> Would it make any sense to integrate this into setpci, e.g., by
> adding an address format for BAR MMIO offsets?

I hadn't thought of that, but it's not a horrible idea. My feeling in 
general is that I like to differentiate the tools to having "one job" 
sort of unix/posix style, and since this one reads/writes mmio, offset 
from the BAR, I prefer that setpci keep the job of reading/writing PCI 
registers, and this new thing does mmio.

>> basic usage to read a register:
>>
>> $ sudo ./readpci -s 17:0.0 -a 0xb8000
>> 17:00.0 (8086:1592) - Device 8086:1592
>> 0xb8000 == 0x1
> 
> Possibly annotate with the BAR # and the complete physical address (to
> correlate with lspci or dmesg output, especially when debugging via
> email)?  Maybe also useful with reading MSI-X BAR.  Looks like maybe
> it already does some of this with "v".

I think your point is reasonable, here is the -v output currently:
$ sudo ./readpci -s 17:0.0 -a 0xb8000 -v
17:00.0 (8086:1592) - Device 8086:1592
BAR0: len 0x02000000
0xb8000 == 0x1

Maybe I should print the BAR0 address as well, basically yielding the 
bits of math that were used to find the final offset and printing that 
too in verbose mode?

Maybe something like (proposal)
$ sudo ./readpci -s 17:0.0 -a 0xb8000 -v
17:00.0 (8086:1592) - Device 8086:1592
BAR0: Memory at 387ffa000000 (64-bit, prefetchable) [size=32M]
Final address:  387ffa0b8000
0xb8000 == 0x00000001

<the BAR0 string is like the one from lspci -vvv>

> 
> Possibly fill out the value to indicate the access width, e.g.,
> 0x00000001 in this case?

yes, good point.

> 
>> Currently the utility only allows reading or writing one 32 bit address at
>> a time. The utility must be run as root.
> 
> Does this mean the *address* is limited to 32 bits, or the access size
> is 32 bits?

Yeah, I should clarify that, it's the size of the target register, not 
the address, however, I don't have any devices with > 4GB of registers 
to try it out on to see if larger addresses will work.

> 
>> +++ b/readpci.man
> 
>> +Access to read and write registers in PCI configuration space is restricted to root,
> 
> IIUC, readpci is for MMIO, not config space.  But I guess readpci
> still needs data from config space to figure out *where* to read?  But
> I assume that would normally come from sysfs, not config space
> directly, so we can account for _TRA offsets.  I assume that info is
> sysfs is also root-only, so it amounts to the same thing.  And
> /dev/mem itself is also root-only.

I think this is a copy/paste error, so will fix. It was meant to be 
saying Access to read and write registers via /dev/mem is restricted to 
root.

> I guess I would say either just "readpci can only be used by root" or
> list the items actually required (sysfs config info and /dev/mem) in
> case access to them requires different CAP_SYS_* things.

In this case the app actually checks it's being run by UID 0, since 
we'll get all sorts of chained failures if you run it as a regular user. 
But simplifying the text as you suggested is best.

> 
>> +So,
>> +.I readpci
>> +isn't available to normal users.
> 
>> +.B -b [<value>]
>> +Optional parameter, defaults to 0 if not specified. BAR number to access if
>> +other than BAR0.
> 
> Maybe move the main point ("BAR number") first, mention the "optional"
> part later?

OK, will fix

>> +on any bus, "0.3" selects third function of device 0 on all buses and ".4" shows only
>> +the fourth function of each device.
> 
> Isn't "0.3" the *fourth* function?  0.0, 0.1, 0.2, 0.3?  Maybe reword
> to avoid the question of whether we start with "zeroth" or "first",
> e.g., "0.3 selects function 3 of device 0 on all buses"?

Good point, will fix.

> 
>> +There might be some, but none known at this time. If you find one please
>> +let the list know.
> 
> Does this man page say what "the list" refers to?

I'll expand it!
Thanks for the review!

      reply	other threads:[~2022-10-11 17:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-11  1:27 [PATCH pciutils v1] pciutils: add new readpci utility Jesse Brandeburg
2022-10-11 16:49 ` Bjorn Helgaas
2022-10-11 17:47   ` Jesse Brandeburg [this message]

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=e17390fb-0aee-4111-36fc-61bdf6799180@intel.com \
    --to=jesse.brandeburg@intel.com \
    --cc=helgaas@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mj@ucw.cz \
    /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;
as well as URLs for NNTP newsgroup(s).