Skip to contentSkip to conversation

PCI: endpoint: Make pci_epf_ops in pci_epf_driver const

PATCH Applied Lars-Peter Clausen 3 participants 11 messages Jul 22, 2023 – Dec 18, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 PCI: endpoint: Make pci_epf_ops in pci_epf_driver const

The pci_epf_ops struct contains a set of callbacks that are used by the pci_epf_driver. The ops struct is never modified by the epf core itself.

Marking the ops pointer const allows epf drivers to declare their pci_epf_ops struct to be const. This allows the struct to be placed in the read-only section. Which for example brings some security benefits as the callbacks can not be overwritten.

---
 include/linux/pci-epf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pci-epf.h +1 -1
index 3f44b6aec477..34be3f1da46c 100644
@@ -98,7 +98,7 @@ struct pci_epf_driver {
 	void	(*remove)(struct pci_epf *epf);
 
 	struct device_driver	driver;
-	struct pci_epf_ops	*ops;
+	const struct pci_epf_ops *ops;
 	struct module		*owner;
 	struct list_head	epf_group;
 	const struct pci_epf_device_id	*id_table;
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/5 PCI: endpoint: pci-epf-mhi: Constify pci_epf_ops and pci_epf_event_ops

Both the pci_epf_ops and pci_epf_evnt_ops structs for the PCI endpoint mhi driver are never modified. Mark them as const so they can be placed in the read-only section.

---
 drivers/pci/endpoint/functions/pci-epf-mhi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/endpoint/functions/pci-epf-mhi.c +2 -2
index 9c1f5a154fbd..bb1c8e502a09 100644
@@ -389,7 +389,7 @@ static void pci_epf_mhi_unbind(struct pci_epf *epf)
 	pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, epf_bar);
 }
 
-static struct pci_epc_event_ops pci_epf_mhi_event_ops = {
+static const struct pci_epc_event_ops pci_epf_mhi_event_ops = {
 	.core_init = pci_epf_mhi_core_init,
 	.link_up = pci_epf_mhi_link_up,
 	.link_down = pci_epf_mhi_link_down,
@@ -428,7 +428,7 @@ static const struct pci_epf_device_id pci_epf_mhi_ids[] = {
 	{},
 };
 
-static struct pci_epf_ops pci_epf_mhi_ops = {
+static const struct pci_epf_ops pci_epf_mhi_ops = {
 	.unbind	= pci_epf_mhi_unbind,
 	.bind	= pci_epf_mhi_bind,
 };
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 2/5
#2 lore raw

Re: [PATCH 2/5] PCI: endpoint: pci-epf-mhi: Constify pci_epf_ops and pci_epf_event_ops

Quoted 5 lines · Lars-Peter Clausen

Both the pci_epf_ops and pci_epf_evnt_ops structs for the PCI endpoint mhi driver are never modified. Mark them as const so they can be placed in the read-only section.

- Mani

Quoted 29 lines
---
 drivers/pci/endpoint/functions/pci-epf-mhi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/endpoint/functions/pci-epf-mhi.c +2 -2
index 9c1f5a154fbd..bb1c8e502a09 100644
@@ -389,7 +389,7 @@ static void pci_epf_mhi_unbind(struct pci_epf *epf)
 	pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, epf_bar);
 }
 
-static struct pci_epc_event_ops pci_epf_mhi_event_ops = {
+static const struct pci_epc_event_ops pci_epf_mhi_event_ops = {
 	.core_init = pci_epf_mhi_core_init,
 	.link_up = pci_epf_mhi_link_up,
 	.link_down = pci_epf_mhi_link_down,
@@ -428,7 +428,7 @@ static const struct pci_epf_device_id pci_epf_mhi_ids[] = {
 	{},
 };
 
-static struct pci_epf_ops pci_epf_mhi_ops = {
+static const struct pci_epf_ops pci_epf_mhi_ops = {
 	.unbind	= pci_epf_mhi_unbind,
 	.bind	= pci_epf_mhi_bind,
 };
Signature · 1 line
2.39.2
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#3 lore raw

PATCH 3/5 PCI: endpoint: pci-epf-ntb: Constify pci_epf_ops

In reply to Lars-Peter Clausen

The pci_epf_ops struct for the PCI endpoint ntb driver is never modified. Mark it as const so it can be placed in the read-only section.

---
 drivers/pci/endpoint/functions/pci-epf-ntb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-ntb.c +1 -1
index 9aac2c6f3bb9..630181469720 100644
@@ -2099,7 +2099,7 @@ static int epf_ntb_probe(struct pci_epf *epf,
 	return 0;
 }
 
-static struct pci_epf_ops epf_ntb_ops = {
+static const struct pci_epf_ops epf_ntb_ops = {
 	.bind	= epf_ntb_bind,
 	.unbind	= epf_ntb_unbind,
 	.add_cfs = epf_ntb_add_cfs,
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 3/5
#4 lore raw

Re: [PATCH 3/5] PCI: endpoint: pci-epf-ntb: Constify pci_epf_ops

Quoted 4 lines · Lars-Peter Clausen

The pci_epf_ops struct for the PCI endpoint ntb driver is never modified. Mark it as const so it can be placed in the read-only section.

- Mani

Quoted 20 lines
---
 drivers/pci/endpoint/functions/pci-epf-ntb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-ntb.c +1 -1
index 9aac2c6f3bb9..630181469720 100644
@@ -2099,7 +2099,7 @@ static int epf_ntb_probe(struct pci_epf *epf,
 	return 0;
 }
 
-static struct pci_epf_ops epf_ntb_ops = {
+static const struct pci_epf_ops epf_ntb_ops = {
 	.bind	= epf_ntb_bind,
 	.unbind	= epf_ntb_unbind,
 	.add_cfs = epf_ntb_add_cfs,
Signature · 1 line
2.39.2
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#5 lore raw

PATCH 4/5 PCI: endpoint: pci-epf-vntb: Constify pci_epf_ops

In reply to Lars-Peter Clausen

The pci_epf_ops struct for the PCI endpoint vntb driver is never modified. Mark it as const so it can be placed in the read-only section.

---
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +1 -1
index c8b423c3c26e..ff4b43af4487 100644
@@ -1387,7 +1387,7 @@ static void epf_ntb_unbind(struct pci_epf *epf)
 }
 
 // EPF driver probe
-static struct pci_epf_ops epf_ntb_ops = {
+static const struct pci_epf_ops epf_ntb_ops = {
 	.bind   = epf_ntb_bind,
 	.unbind = epf_ntb_unbind,
 	.add_cfs = epf_ntb_add_cfs,
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 4/5
#6 lore raw

Re: [PATCH 4/5] PCI: endpoint: pci-epf-vntb: Constify pci_epf_ops

Quoted 4 lines · Lars-Peter Clausen

The pci_epf_ops struct for the PCI endpoint vntb driver is never modified. Mark it as const so it can be placed in the read-only section.

- Mani

Quoted 20 lines
---
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +1 -1
index c8b423c3c26e..ff4b43af4487 100644
@@ -1387,7 +1387,7 @@ static void epf_ntb_unbind(struct pci_epf *epf)
 }
 
 // EPF driver probe
-static struct pci_epf_ops epf_ntb_ops = {
+static const struct pci_epf_ops epf_ntb_ops = {
 	.bind   = epf_ntb_bind,
 	.unbind = epf_ntb_unbind,
 	.add_cfs = epf_ntb_add_cfs,
Signature · 1 line
2.39.2
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#7 lore raw

PATCH 5/5 PCI: endpoint: pci-epf-test: Constify pci_epf_ops

In reply to Lars-Peter Clausen

The pci_epf_ops struct for the PCI endpoint test driver is never modified. Mark it as const so it can be placed in the read-only section.

---
 drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-test.c +1 -1
index 1f0d2b84296a..7cc1c5c70afc 100644
@@ -973,7 +973,7 @@ static int pci_epf_test_probe(struct pci_epf *epf,
 	return 0;
 }
 
-static struct pci_epf_ops ops = {
+static const struct pci_epf_ops ops = {
 	.unbind	= pci_epf_test_unbind,
 	.bind	= pci_epf_test_bind,
 };
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 5/5
#8 lore raw

Re: [PATCH 5/5] PCI: endpoint: pci-epf-test: Constify pci_epf_ops

Quoted 4 lines · Lars-Peter Clausen

The pci_epf_ops struct for the PCI endpoint test driver is never modified. Mark it as const so it can be placed in the read-only section.

- Mani

Quoted 20 lines
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-test.c +1 -1
index 1f0d2b84296a..7cc1c5c70afc 100644
@@ -973,7 +973,7 @@ static int pci_epf_test_probe(struct pci_epf *epf,
 	return 0;
 }
 
-static struct pci_epf_ops ops = {
+static const struct pci_epf_ops ops = {
 	.unbind	= pci_epf_test_unbind,
 	.bind	= pci_epf_test_bind,
 };
Signature · 1 line
2.39.2
Signature · 1 line
மணிவண்ணன் சதாசிவம்
maintainer Reviewed-by on v1 1/5
#9 lore raw
In reply to Lars-Peter Clausen
Quoted 9 lines · Lars-Peter Clausen

The pci_epf_ops struct contains a set of callbacks that are used by the pci_epf_driver. The ops struct is never modified by the epf core itself.

Marking the ops pointer const allows epf drivers to declare their pci_epf_ops struct to be const. This allows the struct to be placed in the read-only section. Which for example brings some security benefits as the callbacks can not be overwritten.

- Mani

Quoted 20 lines
---
 include/linux/pci-epf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pci-epf.h +1 -1
index 3f44b6aec477..34be3f1da46c 100644
@@ -98,7 +98,7 @@ struct pci_epf_driver {
 	void	(*remove)(struct pci_epf *epf);
 
 	struct device_driver	driver;
-	struct pci_epf_ops	*ops;
+	const struct pci_epf_ops *ops;
 	struct module		*owner;
 	struct list_head	epf_group;
 	const struct pci_epf_device_id	*id_table;
Signature · 1 line
2.39.2
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#10 lore raw
In reply to Lars-Peter Clausen

Hello,

Quoted 7 lines

The pci_epf_ops struct contains a set of callbacks that are used by the pci_epf_driver. The ops struct is never modified by the epf core itself.

Marking the ops pointer const allows epf drivers to declare their pci_epf_ops struct to be const. This allows the struct to be placed in the read-only section. Which for example brings some security benefits as the callbacks can not be overwritten.

Applied to endpoint, thank you!

[01/05] PCI: endpoint: Make struct pci_epf_ops in pci_epf_driver const

        https://git.kernel.org/pci/pci/c/86362293044b
[02/05] PCI: endpoint: pci-epf-mhi: Make structs pci_epf_ops and pci_epf_event_ops const
        https://git.kernel.org/pci/pci/c/150d04ddf386
[03/05] PCI: endpoint: pci-epf-ntb: Make struct pci_epf_ops const
        https://git.kernel.org/pci/pci/c/54f22c9758dc
[04/05] PCI: endpoint: pci-epf-vntb: Make struct pci_epf_ops const
        https://git.kernel.org/pci/pci/c/c21b53deda09
[05/05] PCI: endpoint: pci-epf-test: Make struct pci_epf_ops const
        https://git.kernel.org/pci/pci/c/6f517e044096

	Krzysztof