All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr <olekstysh@gmail.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Oleksandr Andrushchenko" <oleksandr_andrushchenko@epam.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Julien Grall" <julien@xen.org>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Wei Liu" <wl@xen.org>, "Paul Durrant" <paul@xen.org>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH V7 02/11] vpci: add hooks for PCI device assign/de-assign
Date: Wed, 27 Jul 2022 17:01:58 +0300	[thread overview]
Message-ID: <2e0efae5-27f7-831d-6f9e-06d03374b716@gmail.com> (raw)
In-Reply-To: <51afa25b-93ea-2685-b238-2edd9292bece@suse.com>


On 27.07.22 13:03, Jan Beulich wrote:


Hello Jan


> On 19.07.2022 19:42, Oleksandr Tyshchenko wrote:
>> @@ -1558,6 +1560,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag)
>>   {
>>       const struct domain_iommu *hd = dom_iommu(d);
>>       struct pci_dev *pdev;
>> +    uint8_t old_devfn;
> Why "old"? There's nothing "new" here. Perhaps "orig", considering ...


ok


>
>> @@ -1594,6 +1599,8 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag)
>>                             pci_to_dev(pdev), flag)) )
>>           goto done;
>>   
>> +    old_devfn = devfn;
>> +
>>       for ( ; pdev->phantom_stride; rc = 0 )
>>       {
>>           devfn += pdev->phantom_stride;
> ... this updating of devfn is what you mean to deal with?

As I understand that was the intention of the author. At least I don't 
see other reasons.



> Then again
> I see no need for a separate variable in the first place. The input
> (seg,bus,devfn) tuple is translated to a pdev, so you can simply ...
>
>> @@ -1603,6 +1610,10 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag)
>>                           pci_to_dev(pdev), flag);
>>       }
>>   
>> +    rc = vpci_assign_device(pdev);
>> +    if ( rc && deassign_device(d, seg, bus, old_devfn) )
> ... use pdev->devfn here.


Thanks, good point, will drop old_devfn and use pdev->devfn. I am 
wondering whether the printk after "done:" label (and other possible 
printk-s down the code) should really use pdev->devfn instead of devfn 
in PCI_SBDF construct?



>
>> +        domain_crash(d);
>> +
>>    done:
>>       if ( rc )
>>           printk(XENLOG_G_WARNING "%pd: assign (%pp) failed (%d)\n",
> This log message will want to appear _before_ the domain_crash()
> related output, or you will want to add another log message there.

I will probably add another log message before domain_crash() leaving 
this one as is.

printk(XENLOG_ERR "%pd: %pp was left partially assigned\n", d, 
&PCI_SBDF(seg, bus, devfn));


>
>> --- a/xen/drivers/vpci/vpci.c
>> +++ b/xen/drivers/vpci/vpci.c
>> @@ -92,6 +92,37 @@ int vpci_add_handlers(struct pci_dev *pdev)
>>   
>>       return rc;
>>   }
>> +
>> +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT
>> +/* Notify vPCI that device is assigned to guest. */
>> +int vpci_assign_device(struct pci_dev *pdev)
>> +{
>> +    int rc;
>> +
>> +    ASSERT(pcidevs_write_locked());
>> +
>> +    if ( !has_vpci(pdev->domain) )
>> +        return 0;
>> +
>> +    rc = vpci_add_handlers(pdev);
>> +    if ( rc )
>> +        vpci_deassign_device(pdev);
>> +
>> +    return rc;
>> +}
>> +
>> +/* Notify vPCI that device is de-assigned from guest. */
>> +void vpci_deassign_device(struct pci_dev *pdev)
>> +{
>> +    ASSERT(pcidevs_write_locked());
>> +
>> +    if ( !has_vpci(pdev->domain) )
>> +        return;
> There's no need for this check since ...
>
>> +    vpci_remove_device(pdev);
> ... this function already has it. At which point the question is why
> a separate function needs to exist in the first place. To match with
> vpci_assign_device(), a simple #define to alias is would be enough.
> (This is one of the cases where personally I think a #define is
> superior to an inline wrapper.)


Agree, but ...


>
> Unless, of course, later patches extend this function. If so, the
> commit message giving this as justification for the introduction of
> (apparent) redundancy would be helpful.

... exactly, the later patches extend this function. I will update 
commit description.



>
> Jan

-- 
Regards,

Oleksandr Tyshchenko



  reply	other threads:[~2022-07-27 14:02 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 17:42 [PATCH V7 00/11] PCI devices passthrough on Arm, part 3 Oleksandr Tyshchenko
2022-07-19 17:42 ` [PATCH V7 01/11] xen/pci: arm: add stub for is_memory_hole Oleksandr Tyshchenko
2022-07-29 16:28   ` Oleksandr
2022-08-03  9:29     ` Rahul Singh
2022-08-03 14:18       ` Oleksandr
2022-07-19 17:42 ` [PATCH V7 02/11] vpci: add hooks for PCI device assign/de-assign Oleksandr Tyshchenko
2022-07-27 10:03   ` Jan Beulich
2022-07-27 14:01     ` Oleksandr [this message]
2022-07-27 14:35       ` Jan Beulich
2022-07-27 16:49         ` Oleksandr
2022-07-19 17:42 ` [PATCH V7 03/11] vpci/header: implement guest BAR register handlers Oleksandr Tyshchenko
2022-07-27 10:15   ` Jan Beulich
2022-07-27 16:17     ` Oleksandr
2022-07-28  7:01       ` Jan Beulich
2022-07-28 14:56         ` Oleksandr
2022-07-19 17:42 ` [PATCH V7 04/11] rangeset: add RANGESETF_no_print flag Oleksandr Tyshchenko
2022-07-26 14:48   ` Rahul Singh
2022-07-19 17:42 ` [PATCH V7 05/11] vpci/header: handle p2m range sets per BAR Oleksandr Tyshchenko
2022-07-19 17:42 ` [PATCH V7 06/11] vpci/header: program p2m with guest BAR view Oleksandr Tyshchenko
2022-07-27 10:19   ` Jan Beulich
2022-07-27 17:06     ` Oleksandr
2022-07-28  7:04       ` Jan Beulich
2022-07-19 17:42 ` [PATCH V7 07/11] vpci/header: emulate PCI_COMMAND register for guests Oleksandr Tyshchenko
2022-07-26 15:30   ` Jan Beulich
2022-07-27 17:30     ` Oleksandr
2022-07-19 17:42 ` [PATCH V7 08/11] vpci/header: reset the command register when adding devices Oleksandr Tyshchenko
2022-07-26 15:09   ` Rahul Singh
2022-07-26 15:23   ` Jan Beulich
2022-07-27  8:58     ` Oleksandr
2022-07-27  9:46       ` Jan Beulich
2022-07-27 16:53         ` Oleksandr
2022-07-19 17:42 ` [PATCH V7 09/11] vpci: add initial support for virtual PCI bus topology Oleksandr Tyshchenko
2022-07-27 10:32   ` Jan Beulich
2022-07-28 14:16     ` Oleksandr
2022-07-28 14:26       ` Jan Beulich
2022-07-28 14:41         ` Oleksandr
2022-07-19 17:42 ` [PATCH V7 10/11] xen/arm: translate virtual PCI bus topology for guests Oleksandr Tyshchenko
2022-07-26 15:16   ` Jan Beulich
2022-07-27 17:54     ` Oleksandr
2022-07-27 19:39       ` Oleksandr
2022-07-28  7:15         ` Jan Beulich
2022-07-28 16:35           ` Oleksandr
2022-07-29  6:06             ` Jan Beulich
2022-07-29 16:26               ` Oleksandr
2022-07-19 17:42 ` [PATCH V7 11/11] xen/arm: account IO handlers for emulated PCI MSI-X Oleksandr Tyshchenko
2022-07-26 14:50   ` Rahul Singh
2022-07-26 13:47 ` [PATCH V7 00/11] PCI devices passthrough on Arm, part 3 Rahul Singh
2022-07-26 15:18   ` Oleksandr Tyshchenko

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=2e0efae5-27f7-831d-6f9e-06d03374b716@gmail.com \
    --to=olekstysh@gmail.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=oleksandr_andrushchenko@epam.com \
    --cc=paul@xen.org \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.