Re: [PATCH v2] PCI: endpoint: pci-epf-test: Allow overriding default BAR sizes

Niklas Cassel
2026-01-28T19:21:23Z

On Wed, Jan 28, 2026 at 06:11:57PM +0100, Niklas Cassel wrote:
> @@ -1312,6 +1315,87 @@ static void pci_epf_test_unbind(struct pci_epf *epf)
> pci_epf_test_free_space(epf);
> }
>
> +#define PCI_EPF_TEST_BAR_SIZE_R(_name, _id) \
> + static ssize_t pci_epf_test_##_name##_show(struct config_item *item, \
> + char *page) \
> + { \
> + struct config_group *group = to_config_group(item); \
> + struct pci_epf_test *epf_test = container_of(group, \
> + struct pci_epf_test, group); \
> + \
> + return sprintf(page, "%zu\n", epf_test->bar_size[_id]); \
> + }
> +
> +#define PCI_EPF_TEST_BAR_SIZE_W(_name, _id) \
> + static ssize_t pci_epf_test_##_name##_store(struct config_item *item, \
> + const char *page, size_t len) \
> + { \
> + struct config_group *group = to_config_group(item); \
> + struct pci_epf_test *epf_test = container_of(group, \
> + struct pci_epf_test, group); \
> + int val; \
> + int ret; \
> + \
> + ret = kstrtouint(page, 0, &val); \
> + if (ret) \
> + return ret; \
> + \
> + if (!is_power_of_2(val)) \
> + return -EINVAL; \
> + \
> + epf_test->bar_size[_id] = val; \
> + \
> + return len; \
> + }
> +

This code does not handle:

# echo 1024 > functions/pci_epf_test/func1/pci_epf_test.0/bar1_size
# echo 0 > controllers/a40000000.pcie-ep/start
# echo 2048 > functions/pci_epf_test/func1/pci_epf_test.0/bar1_size
# echo 1 > controllers/a40000000.pcie-ep/start

Since backing memory for a BAR is allocated in .bind()

And set_bar() is called in .epc_init()

Setting/overriding the BAR size must be done before .bind(), i.e.
at probe() time.
(probe() is called when doing: mkdir functions/pci_epf_test/func1 in configfs)

Therefore, we must make sure that modifying bar*_size after the EPF has
been bound to a EPC will result in an error.

Will send a V3.

Kind regards,
Niklas