Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@amd.com>
To: dan.j.williams@intel.com, linux-pci@vger.kernel.org,
	linux-coco@lists.linux.dev
Cc: gregkh@linuxfoundation.org, bhelgaas@google.com, lukas@wunner.de,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>
Subject: Re: [PATCH resend v6 04/10] PCI/TSM: Authenticate devices via platform TSM
Date: Fri, 26 Sep 2025 11:14:37 +1000	[thread overview]
Message-ID: <d7de6b3e-957b-4ea0-bf00-585ec1467174@amd.com> (raw)
In-Reply-To: <68d5c99fbb056_1c7910082@dwillia2-mobl4.notmuch>



On 26/9/25 09:00, dan.j.williams@intel.com wrote:
> Alexey Kardashevskiy wrote:
> [..]
>>>> It is still a rather global thing. May I suggest this?
>>>
>>> I am not too keen on this.
>>>
>>> Yes, it is global, but less often used compared to @ops, and I do not
>>> want both @ops and @tsm_dev in @pci_tsm.
>>
>> Why exactly?
> 
> ...because it complicates the data structure merely for code convenience
> which is often the wrong tradeoff.
> 
> Here are the current options:
> 
> 1/ Current:
> struct pci_tsm {
>          struct pci_dev *pdev;
>          struct pci_dev *dsm_dev;
>          const struct pci_tsm_ops *ops;
> };
> 
> 2/ Alternative:
> struct pci_tsm {
>          struct pci_dev *pdev;
>          struct pci_dev *dsm_dev;
>          struct tsm_dev *tsm_dev;
> };
> 
> 2/ Proposed:
> struct pci_tsm {
>          struct pci_dev *pdev;
>          struct pci_dev *dsm_dev;
>          struct tsm_dev *tsm_dev;
>          const struct pci_tsm_ops *ops;
> };
> 
> I rank 3 last because it implies that @tsm_dev and @ops may have
> different lifetimes or otherwise may not be related to the same object
> until you read the code.
>
> I rank 2 after 1 because most of 'struct pci_tsm_ops' do not need the
> tsm_dev parameter.
> 
> Now, I would maybe go with 2 if 'struct tsm_dev' could be defined as:
> 
> diff --git a/include/linux/tsm.h b/include/linux/tsm.h
> index 376139585797..3619ffa8f8c1 100644
> --- a/include/linux/tsm.h
> +++ b/include/linux/tsm.h
> @@ -112,7 +112,7 @@ struct pci_tsm_ops;
>   struct tsm_dev {
>          struct device dev;
>          int id;
> -       const struct pci_tsm_ops *pci_ops;
> +       const struct pci_tsm_ops pci_ops;

Either variant of 2 (with "*pci_ops" or "pci_ops") is fine by me.


>   };
>   
> ...i.e. a container_of() relationship, but that makes pci_ops mandatory.

Do you need to be able to resolve tsm_dev from pci_ops pointer?


> It is already the case that TDX has as a few host-services in mind that
> may end up sharing common infrastructure at a TSM device level, so 1
> remains the preference.
> 
>>> So the options are lookup @ops
>>> from @tsm_dev or lookup @tsm_dev from @ops. Given @ops is used more
>>> often that is how I came up with the current arrangement.
>>
>> I am looking at:
>> https://github.com/AMDESE/linux-kvm/commit/9e3caf921ad6ddd6bd860ec307b986649322a618
>> and not really sure "more often" applies here.
>>
>> And do we have to check now if tsm_dev passed in probe() is the same
>> as the owner?
> 
> @ops are not passed passed back in probe so ->probe() can not verify.
> Also ->probe() sets the operations to use via pci_tsm_link_constructor()
> so at that point it does not matter how ->probe() got invoked the result
> is still the TSM driver returning the ops associated with @tsm_dev.


Any pci_tsm_ops::probe implementation can be called with any tsm_dev. So every probe() should verify that BUG_ON(tsm_dev::pci_ops::probe != itself). Although it is not possible right now. And I do not see a better way. So I do not insist really. But my head explodes at this point :)


>> I struggle to find any other _ops doing the same owner
>> caching easily.
> 
> struct file_operations::owner looks like one example.

Not exactly the same - struct module does not have back reference to file_operations. And the file_operations::owner is an ELF with some code but tsm_dev is just some memory from kmalloc(). I guess "dev" implies "module" though.

> 
>> Or merge struct pci_tsm_ops into struct tsm_dev to stop pretending
>> that pci_tsm_ops is an interface, and then we won't even need that
>> @owner. Dunno. Aneesh? :)
> 
> Not sure what you mean by "pretending that pci_tsm_ops is an interface"?

Most of these _ops are stateless (so no "owner") set of hooks, often "static" (and should be "const", and live in .ro sections, not sure if they do). And this _ops could follow the pattern. Thanks,


-- 
Alexey


  reply	other threads:[~2025-09-26  1:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 23:56 [PATCH resend v6 00/10] PCI/TSM: Core infrastructure for PCI device security (TDISP) Dan Williams
2025-09-11 23:56 ` [PATCH resend v6 01/10] coco/tsm: Introduce a core device for TEE Security Managers Dan Williams
2025-09-11 23:56 ` [PATCH resend v6 02/10] PCI/IDE: Enumerate Selective Stream IDE capabilities Dan Williams
2025-09-15 16:32   ` Jonathan Cameron
2025-09-11 23:56 ` [PATCH resend v6 03/10] PCI: Introduce pci_walk_bus_reverse(), for_each_pci_dev_reverse() Dan Williams
2025-09-11 23:56 ` [PATCH resend v6 04/10] PCI/TSM: Authenticate devices via platform TSM Dan Williams
2025-09-15 11:27   ` Alexey Kardashevskiy
2025-09-19 20:15     ` dan.j.williams
2025-09-22 12:26       ` Alexey Kardashevskiy
2025-09-25 23:00         ` dan.j.williams
2025-09-26  1:14           ` Alexey Kardashevskiy [this message]
2025-09-15 11:37   ` Alexey Kardashevskiy
2025-09-19 20:29     ` dan.j.williams
2025-09-11 23:56 ` [PATCH resend v6 05/10] samples/devsec: Introduce a PCI device-security bus + endpoint sample Dan Williams
2025-09-11 23:56 ` [PATCH resend v6 06/10] PCI: Add PCIe Device 3 Extended Capability enumeration Dan Williams
2025-09-11 23:56 ` [PATCH resend v6 07/10] PCI/IDE: Add IDE establishment helpers Dan Williams
2025-09-16  0:14   ` Alexey Kardashevskiy
2025-09-25 19:54     ` dan.j.williams
2025-09-11 23:56 ` [PATCH resend v6 08/10] PCI/IDE: Report available IDE streams Dan Williams
2025-09-11 23:56 ` [PATCH resend v6 09/10] PCI/TSM: Report active " Dan Williams
2025-09-11 23:56 ` [PATCH resend v6 10/10] samples/devsec: Add sample IDE establishment Dan Williams
2025-09-16 12:18 ` [PATCH resend v6 00/10] PCI/TSM: Core infrastructure for PCI device security (TDISP) Aneesh Kumar K.V
2025-09-19  4:17   ` Alexey Kardashevskiy
2025-09-19 12:17     ` Jason Gunthorpe

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=d7de6b3e-957b-4ea0-bf00-585ec1467174@amd.com \
    --to=aik@amd.com \
    --cc=bhelgaas@google.com \
    --cc=dan.j.williams@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=sameo@rivosinc.com \
    --cc=yilun.xu@linux.intel.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