2014-07-22 16:19:56

by Ethan Zhao

[permalink] [raw]
Subject: [PATCH 0/4] Introduce device assignment flag operation helper function

This patch set introduces three PCI device flag operation helper functions
when set pci device PF/VF to assigned or deassigned status also check it.
and patch 2,3,4 apply these helper functions to KVM,XEN and PCI.

Much thanks to suggestion from
[email protected],
[email protected],
[email protected]


BR,
Ethan


2014-07-22 16:19:59

by Ethan Zhao

[permalink] [raw]
Subject: [PATCH 1/4] PCI: introduce helper functions for device flag operation

This patch introduced three helper functions to hide direct
device flag operation.

void pci_set_dev_assigned(struct pci_dev *pdev);
void pci_set_dev_deassigned(struct pci_dev *pdev);
bool pci_is_dev_assigned(struct pci_dev *pdev);

Signed-off-by: Ethan Zhao <[email protected]>
---
include/linux/pci.h | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index aab57b4..5f6f8fa 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1129,6 +1129,19 @@ resource_size_t pcibios_window_alignment(struct pci_bus *bus,

int pci_set_vga_state(struct pci_dev *pdev, bool decode,
unsigned int command_bits, u32 flags);
+/* helper functions for operation of device flag */
+static inline void pci_set_dev_assigned(struct pci_dev *pdev)
+{
+ pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+static inline void pci_set_dev_deassigned(struct pci_dev *pdev)
+{
+ pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
+{
+ return pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED ? true : false;
+}
/* kmem_cache style wrapper around pci_alloc_consistent() */

#include <linux/pci-dma.h>
--
1.7.1

2014-07-22 16:20:09

by Ethan Zhao

[permalink] [raw]
Subject: [PATCH 3/4] xen-pciback: use pci device flag operation helper function

Use pci device flag operation helper functions when set device
to assigned or deassigned state.

Signed-off-by: Ethan Zhao <[email protected]>
---
drivers/xen/xen-pciback/pci_stub.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
index 62fcd48..71f69f1 100644
--- a/drivers/xen/xen-pciback/pci_stub.c
+++ b/drivers/xen/xen-pciback/pci_stub.c
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
xen_pcibk_config_free_dyn_fields(dev);
xen_pcibk_config_free_dev(dev);

- dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+ pci_set_dev_deassigned(dev);
pci_dev_put(dev);

kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
dev_dbg(&dev->dev, "reset device\n");
xen_pcibk_reset_device(dev);

- dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+ pci_set_dev_assigned(dev);
return 0;

config_release:
--
1.7.1

2014-07-22 16:20:13

by Ethan Zhao

[permalink] [raw]
Subject: [PATCH 4/4] PCI: use device flag operation helper function in iov.c

Use device flag operation helper functions when check device
assignment status.

Signed-off-by: Ethan Zhao <[email protected]>
---
drivers/pci/iov.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index de7a747..61fad36 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -633,7 +633,7 @@ int pci_vfs_assigned(struct pci_dev *dev)
* our dev as the physical function and the assigned bit is set
*/
if (vfdev->is_virtfn && (vfdev->physfn == dev) &&
- (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED))
+ pci_is_dev_assigned(vfdev))
vfs_assigned++;

vfdev = pci_get_device(dev->vendor, dev_id, vfdev);
--
1.7.1

2014-07-22 16:20:48

by Ethan Zhao

[permalink] [raw]
Subject: [PATCH 2/4] KVM: use pci device flag operation helper functions

Use helper function instead of direct operation to pci device
flag when set device to assigned or deassigned.

Signed-off-by: Ethan Zhao <[email protected]>
---
virt/kvm/assigned-dev.c | 2 +-
virt/kvm/iommu.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index bf06577..d122bda 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
else
pci_restore_state(assigned_dev->dev);

- assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+ pci_set_dev_deassigned(assigned_dev->dev);

pci_release_regions(assigned_dev->dev);
pci_disable_device(assigned_dev->dev);
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
index 0df7d4b..8cfe021 100644
--- a/virt/kvm/iommu.c
+++ b/virt/kvm/iommu.c
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
goto out_unmap;
}

- pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+ pci_set_dev_assigned(pdev);

dev_info(&pdev->dev, "kvm assign device\n");

@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,

iommu_detach_device(domain, &pdev->dev);

- pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+ pci_set_dev_deassigned(pdev);

dev_info(&pdev->dev, "kvm deassign device\n");

--
1.7.1

2014-07-22 17:35:05

by Konrad Rzeszutek Wilk

[permalink] [raw]
Subject: Re: [PATCH 3/4] xen-pciback: use pci device flag operation helper function

On Wed, Jul 23, 2014 at 12:19:03AM +0800, Ethan Zhao wrote:
> Use pci device flag operation helper functions when set device
> to assigned or deassigned state.
>
> Signed-off-by: Ethan Zhao <[email protected]>

Reviewed-by: Konrad Rzeszutek Wilk <[email protected]>
> ---
> drivers/xen/xen-pciback/pci_stub.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
> index 62fcd48..71f69f1 100644
> --- a/drivers/xen/xen-pciback/pci_stub.c
> +++ b/drivers/xen/xen-pciback/pci_stub.c
> @@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
> xen_pcibk_config_free_dyn_fields(dev);
> xen_pcibk_config_free_dev(dev);
>
> - dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
> + pci_set_dev_deassigned(dev);
> pci_dev_put(dev);
>
> kfree(psdev);
> @@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
> dev_dbg(&dev->dev, "reset device\n");
> xen_pcibk_reset_device(dev);
>
> - dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
> + pci_set_dev_assigned(dev);
> return 0;
>
> config_release:
> --
> 1.7.1
>

2014-07-24 11:10:17

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH 2/4] KVM: use pci device flag operation helper functions

Il 22/07/2014 18:19, Ethan Zhao ha scritto:
> Use helper function instead of direct operation to pci device
> flag when set device to assigned or deassigned.
>
> Signed-off-by: Ethan Zhao <[email protected]>
> ---
> virt/kvm/assigned-dev.c | 2 +-
> virt/kvm/iommu.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
> index bf06577..d122bda 100644
> --- a/virt/kvm/assigned-dev.c
> +++ b/virt/kvm/assigned-dev.c
> @@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
> else
> pci_restore_state(assigned_dev->dev);
>
> - assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
> + pci_set_dev_deassigned(assigned_dev->dev);
>
> pci_release_regions(assigned_dev->dev);
> pci_disable_device(assigned_dev->dev);
> diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
> index 0df7d4b..8cfe021 100644
> --- a/virt/kvm/iommu.c
> +++ b/virt/kvm/iommu.c
> @@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
> goto out_unmap;
> }
>
> - pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
> + pci_set_dev_assigned(pdev);
>
> dev_info(&pdev->dev, "kvm assign device\n");
>
> @@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
>
> iommu_detach_device(domain, &pdev->dev);
>
> - pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
> + pci_set_dev_deassigned(pdev);
>
> dev_info(&pdev->dev, "kvm deassign device\n");
>
>

Acked-by: Paolo Bonzini <[email protected]>

2014-07-28 21:00:25

by Alex Williamson

[permalink] [raw]
Subject: Re: [PATCH 1/4] PCI: introduce helper functions for device flag operation

On Wed, 2014-07-23 at 00:19 +0800, Ethan Zhao wrote:
> This patch introduced three helper functions to hide direct
> device flag operation.
>
> void pci_set_dev_assigned(struct pci_dev *pdev);
> void pci_set_dev_deassigned(struct pci_dev *pdev);
> bool pci_is_dev_assigned(struct pci_dev *pdev);
>
> Signed-off-by: Ethan Zhao <[email protected]>
> ---
> include/linux/pci.h | 13 +++++++++++++
> 1 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index aab57b4..5f6f8fa 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1129,6 +1129,19 @@ resource_size_t pcibios_window_alignment(struct pci_bus *bus,
>
> int pci_set_vga_state(struct pci_dev *pdev, bool decode,
> unsigned int command_bits, u32 flags);
> +/* helper functions for operation of device flag */
> +static inline void pci_set_dev_assigned(struct pci_dev *pdev)
> +{
> + pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
> +}
> +static inline void pci_set_dev_deassigned(struct pci_dev *pdev)
> +{
> + pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
> +}

I think pci_clear_dev_assigned() would make more sense, we're not
setting a flag named DEASSIGNED.

> +static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
> +{
> + return pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED ? true : false;
> +}

The ternary operation isn't necessary. Thanks,

Alex

> /* kmem_cache style wrapper around pci_alloc_consistent() */
>
> #include <linux/pci-dma.h>


2014-07-29 01:53:51

by Ethan Zhao

[permalink] [raw]
Subject: Re: [PATCH 1/4] PCI: introduce helper functions for device flag operation


On 2014/7/29 5:00, Alex Williamson wrote:
> On Wed, 2014-07-23 at 00:19 +0800, Ethan Zhao wrote:
>> This patch introduced three helper functions to hide direct
>> device flag operation.
>>
>> void pci_set_dev_assigned(struct pci_dev *pdev);
>> void pci_set_dev_deassigned(struct pci_dev *pdev);
>> bool pci_is_dev_assigned(struct pci_dev *pdev);
>>
>> Signed-off-by: Ethan Zhao <[email protected]>
>> ---
>> include/linux/pci.h | 13 +++++++++++++
>> 1 files changed, 13 insertions(+), 0 deletions(-)
>>
>> diff --git a/include/linux/pci.h b/include/linux/pci.h
>> index aab57b4..5f6f8fa 100644
>> --- a/include/linux/pci.h
>> +++ b/include/linux/pci.h
>> @@ -1129,6 +1129,19 @@ resource_size_t pcibios_window_alignment(struct pci_bus *bus,
>>
>> int pci_set_vga_state(struct pci_dev *pdev, bool decode,
>> unsigned int command_bits, u32 flags);
>> +/* helper functions for operation of device flag */
>> +static inline void pci_set_dev_assigned(struct pci_dev *pdev)
>> +{
>> + pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
>> +}
>> +static inline void pci_set_dev_deassigned(struct pci_dev *pdev)
>> +{
>> + pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
>> +}
> I think pci_clear_dev_assigned() would make more sense, we're not
> setting a flag named DEASSIGNED.
Though it is a flag operation now, may not later, we define it
because we want to hide the internal operation.
'set' to 'deassigned' status is enough. So I would like keep it.
>
>> +static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
>> +{
>> + return pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED ? true : false;
>> +}
> The ternary operation isn't necessary. Thanks,
Yep,

return pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED

is enough.

Thanks,
Ethan
>
> Alex
>
>> /* kmem_cache style wrapper around pci_alloc_consistent() */
>>
>> #include <linux/pci-dma.h>
>
>

2014-07-29 02:31:29

by Alex Williamson

[permalink] [raw]
Subject: Re: [PATCH 1/4] PCI: introduce helper functions for device flag operation

On Tue, 2014-07-29 at 09:53 +0800, ethan zhao wrote:
> On 2014/7/29 5:00, Alex Williamson wrote:
> > On Wed, 2014-07-23 at 00:19 +0800, Ethan Zhao wrote:
> >> This patch introduced three helper functions to hide direct
> >> device flag operation.
> >>
> >> void pci_set_dev_assigned(struct pci_dev *pdev);
> >> void pci_set_dev_deassigned(struct pci_dev *pdev);
> >> bool pci_is_dev_assigned(struct pci_dev *pdev);
> >>
> >> Signed-off-by: Ethan Zhao <[email protected]>
> >> ---
> >> include/linux/pci.h | 13 +++++++++++++
> >> 1 files changed, 13 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/include/linux/pci.h b/include/linux/pci.h
> >> index aab57b4..5f6f8fa 100644
> >> --- a/include/linux/pci.h
> >> +++ b/include/linux/pci.h
> >> @@ -1129,6 +1129,19 @@ resource_size_t pcibios_window_alignment(struct pci_bus *bus,
> >>
> >> int pci_set_vga_state(struct pci_dev *pdev, bool decode,
> >> unsigned int command_bits, u32 flags);
> >> +/* helper functions for operation of device flag */
> >> +static inline void pci_set_dev_assigned(struct pci_dev *pdev)
> >> +{
> >> + pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
> >> +}
> >> +static inline void pci_set_dev_deassigned(struct pci_dev *pdev)
> >> +{
> >> + pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
> >> +}
> > I think pci_clear_dev_assigned() would make more sense, we're not
> > setting a flag named DEASSIGNED.
> Though it is a flag operation now, may not later, we define it
> because we want to hide the internal operation.
> 'set' to 'deassigned' status is enough. So I would like keep it.

I disagree, the opposite of a 'set' is a 'clear', or at least an
'unset'. Using bit-ops-like terminology doesn't lock us into an
implementation. As written, this could just as easily be setting two
different variables.

> >
> >> +static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
> >> +{
> >> + return pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED ? true : false;
> >> +}
> > The ternary operation isn't necessary. Thanks,
> Yep,
>
> return pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED
>
> is enough.
>
> Thanks,
> Ethan
> >
> > Alex
> >
> >> /* kmem_cache style wrapper around pci_alloc_consistent() */
> >>
> >> #include <linux/pci-dma.h>
> >
> >
>


2014-07-29 02:43:57

by Ethan Zhao

[permalink] [raw]
Subject: Re: [PATCH 1/4] PCI: introduce helper functions for device flag operation


On 2014/7/29 10:31, Alex Williamson wrote:
> On Tue, 2014-07-29 at 09:53 +0800, ethan zhao wrote:
>> On 2014/7/29 5:00, Alex Williamson wrote:
>>> On Wed, 2014-07-23 at 00:19 +0800, Ethan Zhao wrote:
>>>> This patch introduced three helper functions to hide direct
>>>> device flag operation.
>>>>
>>>> void pci_set_dev_assigned(struct pci_dev *pdev);
>>>> void pci_set_dev_deassigned(struct pci_dev *pdev);
>>>> bool pci_is_dev_assigned(struct pci_dev *pdev);
>>>>
>>>> Signed-off-by: Ethan Zhao <[email protected]>
>>>> ---
>>>> include/linux/pci.h | 13 +++++++++++++
>>>> 1 files changed, 13 insertions(+), 0 deletions(-)
>>>>
>>>> diff --git a/include/linux/pci.h b/include/linux/pci.h
>>>> index aab57b4..5f6f8fa 100644
>>>> --- a/include/linux/pci.h
>>>> +++ b/include/linux/pci.h
>>>> @@ -1129,6 +1129,19 @@ resource_size_t pcibios_window_alignment(struct pci_bus *bus,
>>>>
>>>> int pci_set_vga_state(struct pci_dev *pdev, bool decode,
>>>> unsigned int command_bits, u32 flags);
>>>> +/* helper functions for operation of device flag */
>>>> +static inline void pci_set_dev_assigned(struct pci_dev *pdev)
>>>> +{
>>>> + pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
>>>> +}
>>>> +static inline void pci_set_dev_deassigned(struct pci_dev *pdev)
>>>> +{
>>>> + pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
>>>> +}
>>> I think pci_clear_dev_assigned() would make more sense, we're not
>>> setting a flag named DEASSIGNED.
>> Though it is a flag operation now, may not later, we define it
>> because we want to hide the internal operation.
>> 'set' to 'deassigned' status is enough. So I would like keep it.
> I disagree, the opposite of a 'set' is a 'clear', or at least an
> 'unset'. Using bit-ops-like terminology doesn't lock us into an
> implementation. As written, this could just as easily be setting two
> different variables.
So there are two pairs of opposite:

set assigned ---> unset assigned
set assigned ---> set deassigned

Here you prefer the 'verb' set /unset, and I prefer the 'adj.'
assigned / deassigned.

Do they really have different meaning or make confusion ? I don't
think so.

Thanks,
Ethan

>
>>>> +static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
>>>> +{
>>>> + return pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED ? true : false;
>>>> +}
>>> The ternary operation isn't necessary. Thanks,
>> Yep,
>>
>> return pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED
>>
>> is enough.
>>
>> Thanks,
>> Ethan
>>> Alex
>>>
>>>> /* kmem_cache style wrapper around pci_alloc_consistent() */
>>>>
>>>> #include <linux/pci-dma.h>
>>>
>
>

2014-07-29 03:37:46

by Alexander Duyck

[permalink] [raw]
Subject: Re: [PATCH 1/4] PCI: introduce helper functions for device flag operation

On 07/28/2014 07:43 PM, ethan zhao wrote:
>
> On 2014/7/29 10:31, Alex Williamson wrote:
>> On Tue, 2014-07-29 at 09:53 +0800, ethan zhao wrote:
>>> On 2014/7/29 5:00, Alex Williamson wrote:
>>>> On Wed, 2014-07-23 at 00:19 +0800, Ethan Zhao wrote:
>>>>> This patch introduced three helper functions to hide direct
>>>>> device flag operation.
>>>>>
>>>>> void pci_set_dev_assigned(struct pci_dev *pdev);
>>>>> void pci_set_dev_deassigned(struct pci_dev *pdev);
>>>>> bool pci_is_dev_assigned(struct pci_dev *pdev);
>>>>>
>>>>> Signed-off-by: Ethan Zhao <[email protected]>
>>>>> ---
>>>>> include/linux/pci.h | 13 +++++++++++++
>>>>> 1 files changed, 13 insertions(+), 0 deletions(-)
>>>>>
>>>>> diff --git a/include/linux/pci.h b/include/linux/pci.h
>>>>> index aab57b4..5f6f8fa 100644
>>>>> --- a/include/linux/pci.h
>>>>> +++ b/include/linux/pci.h
>>>>> @@ -1129,6 +1129,19 @@ resource_size_t
>>>>> pcibios_window_alignment(struct pci_bus *bus,
>>>>> int pci_set_vga_state(struct pci_dev *pdev, bool decode,
>>>>> unsigned int command_bits, u32 flags);
>>>>> +/* helper functions for operation of device flag */
>>>>> +static inline void pci_set_dev_assigned(struct pci_dev *pdev)
>>>>> +{
>>>>> + pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
>>>>> +}
>>>>> +static inline void pci_set_dev_deassigned(struct pci_dev *pdev)
>>>>> +{
>>>>> + pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
>>>>> +}
>>>> I think pci_clear_dev_assigned() would make more sense, we're not
>>>> setting a flag named DEASSIGNED.
>>> Though it is a flag operation now, may not later, we define it
>>> because we want to hide the internal operation.
>>> 'set' to 'deassigned' status is enough. So I would like keep it.
>> I disagree, the opposite of a 'set' is a 'clear', or at least an
>> 'unset'. Using bit-ops-like terminology doesn't lock us into an
>> implementation. As written, this could just as easily be setting two
>> different variables.
> So there are two pairs of opposite:
>
> set assigned ---> unset assigned
> set assigned ---> set deassigned
>
> Here you prefer the 'verb' set /unset, and I prefer the 'adj.' assigned
> / deassigned.
>
> Do they really have different meaning or make confusion ? I don't think
> so.
>
> Thanks,
> Ethan
>

I agree with Alex W. If you are going to use the "set" name you should
probably use "clear" for the operation that undoes it. Using the term
set implies that it is setting a bit and we currently don't have a
deassigned/unassigned bit.

If that doesn't work perhaps you could use something like
get/put_assigned_device or acquire/release_assigned_device. You just
need to describe what it is you are doing. You could even consider
adding some tests to return an error if you attempt to assign a device
that is already assigned.

Thanks,

Alex D

2014-07-29 03:47:59

by ethan zhao

[permalink] [raw]
Subject: Re: [PATCH 1/4] PCI: introduce helper functions for device flag operation

Both of you and Alex W prefer the 'Verb' , Ok, I accept the suggestion.

Thanks,
Ethan


On Tue, Jul 29, 2014 at 11:37 AM, Alexander Duyck
<[email protected]> wrote:
> On 07/28/2014 07:43 PM, ethan zhao wrote:
>>
>> On 2014/7/29 10:31, Alex Williamson wrote:
>>> On Tue, 2014-07-29 at 09:53 +0800, ethan zhao wrote:
>>>> On 2014/7/29 5:00, Alex Williamson wrote:
>>>>> On Wed, 2014-07-23 at 00:19 +0800, Ethan Zhao wrote:
>>>>>> This patch introduced three helper functions to hide direct
>>>>>> device flag operation.
>>>>>>
>>>>>> void pci_set_dev_assigned(struct pci_dev *pdev);
>>>>>> void pci_set_dev_deassigned(struct pci_dev *pdev);
>>>>>> bool pci_is_dev_assigned(struct pci_dev *pdev);
>>>>>>
>>>>>> Signed-off-by: Ethan Zhao <[email protected]>
>>>>>> ---
>>>>>> include/linux/pci.h | 13 +++++++++++++
>>>>>> 1 files changed, 13 insertions(+), 0 deletions(-)
>>>>>>
>>>>>> diff --git a/include/linux/pci.h b/include/linux/pci.h
>>>>>> index aab57b4..5f6f8fa 100644
>>>>>> --- a/include/linux/pci.h
>>>>>> +++ b/include/linux/pci.h
>>>>>> @@ -1129,6 +1129,19 @@ resource_size_t
>>>>>> pcibios_window_alignment(struct pci_bus *bus,
>>>>>> int pci_set_vga_state(struct pci_dev *pdev, bool decode,
>>>>>> unsigned int command_bits, u32 flags);
>>>>>> +/* helper functions for operation of device flag */
>>>>>> +static inline void pci_set_dev_assigned(struct pci_dev *pdev)
>>>>>> +{
>>>>>> + pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
>>>>>> +}
>>>>>> +static inline void pci_set_dev_deassigned(struct pci_dev *pdev)
>>>>>> +{
>>>>>> + pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
>>>>>> +}
>>>>> I think pci_clear_dev_assigned() would make more sense, we're not
>>>>> setting a flag named DEASSIGNED.
>>>> Though it is a flag operation now, may not later, we define it
>>>> because we want to hide the internal operation.
>>>> 'set' to 'deassigned' status is enough. So I would like keep it.
>>> I disagree, the opposite of a 'set' is a 'clear', or at least an
>>> 'unset'. Using bit-ops-like terminology doesn't lock us into an
>>> implementation. As written, this could just as easily be setting two
>>> different variables.
>> So there are two pairs of opposite:
>>
>> set assigned ---> unset assigned
>> set assigned ---> set deassigned
>>
>> Here you prefer the 'verb' set /unset, and I prefer the 'adj.' assigned
>> / deassigned.
>>
>> Do they really have different meaning or make confusion ? I don't think
>> so.
>>
>> Thanks,
>> Ethan
>>
>
> I agree with Alex W. If you are going to use the "set" name you should
> probably use "clear" for the operation that undoes it. Using the term
> set implies that it is setting a bit and we currently don't have a
> deassigned/unassigned bit.
>
> If that doesn't work perhaps you could use something like
> get/put_assigned_device or acquire/release_assigned_device. You just
> need to describe what it is you are doing. You could even consider
> adding some tests to return an error if you attempt to assign a device
> that is already assigned.
>
> Thanks,
>
> Alex D
>