2019-05-23 21:51:41

by Alan Mikhak

[permalink] [raw]
Subject: [PATCH v2] PCI: endpoint: Allocate enough space for fixed size BAR

PCI endpoint test function code should honor the .bar_fixed_size parameter
from underlying endpoint controller drivers or results may be unexpected.

In pci_epf_test_alloc_space(), check if BAR being used for test register
space is a fixed size BAR. If so, allocate the required fixed size.

Signed-off-by: Alan Mikhak <[email protected]>
---
drivers/pci/endpoint/functions/pci-epf-test.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 27806987e93b..7d41e6684b87 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -434,10 +434,16 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
int bar;
enum pci_barno test_reg_bar = epf_test->test_reg_bar;
const struct pci_epc_features *epc_features;
+ size_t test_reg_size;

epc_features = epf_test->epc_features;

- base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),
+ if (epc_features->bar_fixed_size[test_reg_bar])
+ test_reg_size = bar_size[test_reg_bar];
+ else
+ test_reg_size = sizeof(struct pci_epf_test_reg);
+
+ base = pci_epf_alloc_space(epf, test_reg_size,
test_reg_bar, epc_features->align);
if (!base) {
dev_err(dev, "Failed to allocated register space\n");
--
2.7.4


2019-05-23 23:58:49

by Alan Mikhak

[permalink] [raw]
Subject: Re: [PATCH v2] PCI: endpoint: Allocate enough space for fixed size BAR

+Bjorn Helgaas, +Gustavo Pimentel, +Wen Yang, +Kangjie Lu

On Thu, May 23, 2019 at 2:48 PM Alan Mikhak <[email protected]> wrote:
>
> PCI endpoint test function code should honor the .bar_fixed_size parameter
> from underlying endpoint controller drivers or results may be unexpected.
>
> In pci_epf_test_alloc_space(), check if BAR being used for test register
> space is a fixed size BAR. If so, allocate the required fixed size.
>
> Signed-off-by: Alan Mikhak <[email protected]>
> ---
> drivers/pci/endpoint/functions/pci-epf-test.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
> index 27806987e93b..7d41e6684b87 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
> @@ -434,10 +434,16 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
> int bar;
> enum pci_barno test_reg_bar = epf_test->test_reg_bar;
> const struct pci_epc_features *epc_features;
> + size_t test_reg_size;
>
> epc_features = epf_test->epc_features;
>
> - base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),
> + if (epc_features->bar_fixed_size[test_reg_bar])
> + test_reg_size = bar_size[test_reg_bar];
> + else
> + test_reg_size = sizeof(struct pci_epf_test_reg);
> +
> + base = pci_epf_alloc_space(epf, test_reg_size,
> test_reg_bar, epc_features->align);
> if (!base) {
> dev_err(dev, "Failed to allocated register space\n");
> --
> 2.7.4
>

2019-05-24 08:49:20

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: Re: [PATCH v2] PCI: endpoint: Allocate enough space for fixed size BAR



On 24/05/19 5:26 AM, Alan Mikhak wrote:
> +Bjorn Helgaas, +Gustavo Pimentel, +Wen Yang, +Kangjie Lu
>
> On Thu, May 23, 2019 at 2:48 PM Alan Mikhak <[email protected]> wrote:
>>
>> PCI endpoint test function code should honor the .bar_fixed_size parameter
>> from underlying endpoint controller drivers or results may be unexpected.
>>
>> In pci_epf_test_alloc_space(), check if BAR being used for test register
>> space is a fixed size BAR. If so, allocate the required fixed size.
>>
>> Signed-off-by: Alan Mikhak <[email protected]>

Acked-by: Kishon Vijay Abraham I <[email protected]>
>> ---
>> drivers/pci/endpoint/functions/pci-epf-test.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
>> index 27806987e93b..7d41e6684b87 100644
>> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
>> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
>> @@ -434,10 +434,16 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
>> int bar;
>> enum pci_barno test_reg_bar = epf_test->test_reg_bar;
>> const struct pci_epc_features *epc_features;
>> + size_t test_reg_size;
>>
>> epc_features = epf_test->epc_features;
>>
>> - base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),
>> + if (epc_features->bar_fixed_size[test_reg_bar])
>> + test_reg_size = bar_size[test_reg_bar];
>> + else
>> + test_reg_size = sizeof(struct pci_epf_test_reg);
>> +
>> + base = pci_epf_alloc_space(epf, test_reg_size,
>> test_reg_bar, epc_features->align);
>> if (!base) {
>> dev_err(dev, "Failed to allocated register space\n");
>> --
>> 2.7.4
>>

2019-06-11 10:09:11

by Lorenzo Pieralisi

[permalink] [raw]
Subject: Re: [PATCH v2] PCI: endpoint: Allocate enough space for fixed size BAR

On Thu, May 23, 2019 at 02:47:59PM -0700, Alan Mikhak wrote:
> PCI endpoint test function code should honor the .bar_fixed_size parameter
> from underlying endpoint controller drivers or results may be unexpected.
>
> In pci_epf_test_alloc_space(), check if BAR being used for test register
> space is a fixed size BAR. If so, allocate the required fixed size.
>
> Signed-off-by: Alan Mikhak <[email protected]>
> ---
> drivers/pci/endpoint/functions/pci-epf-test.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)

Applied to pci/endpoint for v5.3, thanks.

Lorenzo

> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
> index 27806987e93b..7d41e6684b87 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
> @@ -434,10 +434,16 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
> int bar;
> enum pci_barno test_reg_bar = epf_test->test_reg_bar;
> const struct pci_epc_features *epc_features;
> + size_t test_reg_size;
>
> epc_features = epf_test->epc_features;
>
> - base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),
> + if (epc_features->bar_fixed_size[test_reg_bar])
> + test_reg_size = bar_size[test_reg_bar];
> + else
> + test_reg_size = sizeof(struct pci_epf_test_reg);
> +
> + base = pci_epf_alloc_space(epf, test_reg_size,
> test_reg_bar, epc_features->align);
> if (!base) {
> dev_err(dev, "Failed to allocated register space\n");
> --
> 2.7.4
>