2024-06-02 14:19:19

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH 0/2 net-next] devlink: Constify struct devlink_dpipe_table_ops

Patch 1 updates devl_dpipe_table_register() and struct
devlink_dpipe_table to accept "const struct devlink_dpipe_table_ops".

Then patch 2 updates the only user of this function.

This is compile tested only.

Christophe JAILLET (2):
devlink: Constify the 'table_ops' parameter of
devl_dpipe_table_register()
mlxsw: spectrum_router: Constify struct devlink_dpipe_table_ops

drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c | 8 ++++----
include/net/devlink.h | 4 ++--
net/devlink/dpipe.c | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)

--
2.45.1



2024-06-02 14:19:37

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH 2/2 net-next] mlxsw: spectrum_router: Constify struct devlink_dpipe_table_ops

'struct devlink_dpipe_table_ops' are not modified in this driver.

Constifying these structures moves some data to a read-only section, so
increase overall security.

On a x86_64, with allmodconfig:
Before:
======
text data bss dec hex filename
15557 712 0 16269 3f8d drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.o

After:
=====
text data bss dec hex filename
15789 488 0 16277 3f95 drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.o

Signed-off-by: Christophe JAILLET <[email protected]>
---
drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
index ca80af06465f..fa6eddd27ecf 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
@@ -283,7 +283,7 @@ static u64 mlxsw_sp_dpipe_table_erif_size_get(void *priv)
return MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
}

-static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {
+static const struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {
.matches_dump = mlxsw_sp_dpipe_table_erif_matches_dump,
.actions_dump = mlxsw_sp_dpipe_table_erif_actions_dump,
.entries_dump = mlxsw_sp_dpipe_table_erif_entries_dump,
@@ -734,7 +734,7 @@ static u64 mlxsw_sp_dpipe_table_host4_size_get(void *priv)
return mlxsw_sp_dpipe_table_host_size_get(mlxsw_sp, AF_INET);
}

-static struct devlink_dpipe_table_ops mlxsw_sp_host4_ops = {
+static const struct devlink_dpipe_table_ops mlxsw_sp_host4_ops = {
.matches_dump = mlxsw_sp_dpipe_table_host4_matches_dump,
.actions_dump = mlxsw_sp_dpipe_table_host_actions_dump,
.entries_dump = mlxsw_sp_dpipe_table_host4_entries_dump,
@@ -811,7 +811,7 @@ static u64 mlxsw_sp_dpipe_table_host6_size_get(void *priv)
return mlxsw_sp_dpipe_table_host_size_get(mlxsw_sp, AF_INET6);
}

-static struct devlink_dpipe_table_ops mlxsw_sp_host6_ops = {
+static const struct devlink_dpipe_table_ops mlxsw_sp_host6_ops = {
.matches_dump = mlxsw_sp_dpipe_table_host6_matches_dump,
.actions_dump = mlxsw_sp_dpipe_table_host_actions_dump,
.entries_dump = mlxsw_sp_dpipe_table_host6_entries_dump,
@@ -1230,7 +1230,7 @@ mlxsw_sp_dpipe_table_adj_size_get(void *priv)
return size;
}

-static struct devlink_dpipe_table_ops mlxsw_sp_dpipe_table_adj_ops = {
+static const struct devlink_dpipe_table_ops mlxsw_sp_dpipe_table_adj_ops = {
.matches_dump = mlxsw_sp_dpipe_table_adj_matches_dump,
.actions_dump = mlxsw_sp_dpipe_table_adj_actions_dump,
.entries_dump = mlxsw_sp_dpipe_table_adj_entries_dump,
--
2.45.1


2024-06-02 14:53:05

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH 1/2 net-next] devlink: Constify the 'table_ops' parameter of devl_dpipe_table_register()

"struct devlink_dpipe_table_ops" only contains some function pointers.

Update "struct devlink_dpipe_table" and the 'table_ops' parameter of
devl_dpipe_table_register() so that structures in drivers can be
constified.

Constifying these structures will move some data to a read-only section, so
increase overall security.

Signed-off-by: Christophe JAILLET <[email protected]>
---
include/net/devlink.h | 4 ++--
net/devlink/dpipe.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 35eb0f884386..db5eff6cb60f 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -352,7 +352,7 @@ struct devlink_dpipe_table {
bool resource_valid;
u64 resource_id;
u64 resource_units;
- struct devlink_dpipe_table_ops *table_ops;
+ const struct devlink_dpipe_table_ops *table_ops;
struct rcu_head rcu;
};

@@ -1751,7 +1751,7 @@ void devl_sb_unregister(struct devlink *devlink, unsigned int sb_index);
void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
int devl_dpipe_table_register(struct devlink *devlink,
const char *table_name,
- struct devlink_dpipe_table_ops *table_ops,
+ const struct devlink_dpipe_table_ops *table_ops,
void *priv, bool counter_control_extern);
void devl_dpipe_table_unregister(struct devlink *devlink,
const char *table_name);
diff --git a/net/devlink/dpipe.c b/net/devlink/dpipe.c
index a72a9292efc5..55009b377447 100644
--- a/net/devlink/dpipe.c
+++ b/net/devlink/dpipe.c
@@ -839,7 +839,7 @@ EXPORT_SYMBOL_GPL(devlink_dpipe_table_counter_enabled);
*/
int devl_dpipe_table_register(struct devlink *devlink,
const char *table_name,
- struct devlink_dpipe_table_ops *table_ops,
+ const struct devlink_dpipe_table_ops *table_ops,
void *priv, bool counter_control_extern)
{
struct devlink_dpipe_table *table;
--
2.45.1


2024-06-03 08:53:59

by Wojciech Drewek

[permalink] [raw]
Subject: Re: [PATCH 1/2 net-next] devlink: Constify the 'table_ops' parameter of devl_dpipe_table_register()



On 02.06.2024 16:18, Christophe JAILLET wrote:
> "struct devlink_dpipe_table_ops" only contains some function pointers.
>
> Update "struct devlink_dpipe_table" and the 'table_ops' parameter of
> devl_dpipe_table_register() so that structures in drivers can be
> constified.
>
> Constifying these structures will move some data to a read-only section, so
> increase overall security.
>
> Signed-off-by: Christophe JAILLET <[email protected]>
> ---

Reviewed-by: Wojciech Drewek <[email protected]>

> include/net/devlink.h | 4 ++--
> net/devlink/dpipe.c | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/net/devlink.h b/include/net/devlink.h
> index 35eb0f884386..db5eff6cb60f 100644
> --- a/include/net/devlink.h
> +++ b/include/net/devlink.h
> @@ -352,7 +352,7 @@ struct devlink_dpipe_table {
> bool resource_valid;
> u64 resource_id;
> u64 resource_units;
> - struct devlink_dpipe_table_ops *table_ops;
> + const struct devlink_dpipe_table_ops *table_ops;
> struct rcu_head rcu;
> };
>
> @@ -1751,7 +1751,7 @@ void devl_sb_unregister(struct devlink *devlink, unsigned int sb_index);
> void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
> int devl_dpipe_table_register(struct devlink *devlink,
> const char *table_name,
> - struct devlink_dpipe_table_ops *table_ops,
> + const struct devlink_dpipe_table_ops *table_ops,
> void *priv, bool counter_control_extern);
> void devl_dpipe_table_unregister(struct devlink *devlink,
> const char *table_name);
> diff --git a/net/devlink/dpipe.c b/net/devlink/dpipe.c
> index a72a9292efc5..55009b377447 100644
> --- a/net/devlink/dpipe.c
> +++ b/net/devlink/dpipe.c
> @@ -839,7 +839,7 @@ EXPORT_SYMBOL_GPL(devlink_dpipe_table_counter_enabled);
> */
> int devl_dpipe_table_register(struct devlink *devlink,
> const char *table_name,
> - struct devlink_dpipe_table_ops *table_ops,
> + const struct devlink_dpipe_table_ops *table_ops,
> void *priv, bool counter_control_extern)
> {
> struct devlink_dpipe_table *table;

2024-06-03 08:58:10

by Wojciech Drewek

[permalink] [raw]
Subject: Re: [PATCH 2/2 net-next] mlxsw: spectrum_router: Constify struct devlink_dpipe_table_ops



On 02.06.2024 16:18, Christophe JAILLET wrote:
> 'struct devlink_dpipe_table_ops' are not modified in this driver.
>
> Constifying these structures moves some data to a read-only section, so
> increase overall security.
>
> On a x86_64, with allmodconfig:
> Before:
> ======
> text data bss dec hex filename
> 15557 712 0 16269 3f8d drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.o
>
> After:
> =====
> text data bss dec hex filename
> 15789 488 0 16277 3f95 drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.o
>
> Signed-off-by: Christophe JAILLET <[email protected]>
> ---

Reviewed-by: Wojciech Drewek <[email protected]>

> drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
> index ca80af06465f..fa6eddd27ecf 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
> @@ -283,7 +283,7 @@ static u64 mlxsw_sp_dpipe_table_erif_size_get(void *priv)
> return MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
> }
>
> -static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {
> +static const struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {
> .matches_dump = mlxsw_sp_dpipe_table_erif_matches_dump,
> .actions_dump = mlxsw_sp_dpipe_table_erif_actions_dump,
> .entries_dump = mlxsw_sp_dpipe_table_erif_entries_dump,
> @@ -734,7 +734,7 @@ static u64 mlxsw_sp_dpipe_table_host4_size_get(void *priv)
> return mlxsw_sp_dpipe_table_host_size_get(mlxsw_sp, AF_INET);
> }
>
> -static struct devlink_dpipe_table_ops mlxsw_sp_host4_ops = {
> +static const struct devlink_dpipe_table_ops mlxsw_sp_host4_ops = {
> .matches_dump = mlxsw_sp_dpipe_table_host4_matches_dump,
> .actions_dump = mlxsw_sp_dpipe_table_host_actions_dump,
> .entries_dump = mlxsw_sp_dpipe_table_host4_entries_dump,
> @@ -811,7 +811,7 @@ static u64 mlxsw_sp_dpipe_table_host6_size_get(void *priv)
> return mlxsw_sp_dpipe_table_host_size_get(mlxsw_sp, AF_INET6);
> }
>
> -static struct devlink_dpipe_table_ops mlxsw_sp_host6_ops = {
> +static const struct devlink_dpipe_table_ops mlxsw_sp_host6_ops = {
> .matches_dump = mlxsw_sp_dpipe_table_host6_matches_dump,
> .actions_dump = mlxsw_sp_dpipe_table_host_actions_dump,
> .entries_dump = mlxsw_sp_dpipe_table_host6_entries_dump,
> @@ -1230,7 +1230,7 @@ mlxsw_sp_dpipe_table_adj_size_get(void *priv)
> return size;
> }
>
> -static struct devlink_dpipe_table_ops mlxsw_sp_dpipe_table_adj_ops = {
> +static const struct devlink_dpipe_table_ops mlxsw_sp_dpipe_table_adj_ops = {
> .matches_dump = mlxsw_sp_dpipe_table_adj_matches_dump,
> .actions_dump = mlxsw_sp_dpipe_table_adj_actions_dump,
> .entries_dump = mlxsw_sp_dpipe_table_adj_entries_dump,

2024-06-03 10:55:01

by Ido Schimmel

[permalink] [raw]
Subject: Re: [PATCH 1/2 net-next] devlink: Constify the 'table_ops' parameter of devl_dpipe_table_register()

On Sun, Jun 02, 2024 at 04:18:52PM +0200, Christophe JAILLET wrote:
> "struct devlink_dpipe_table_ops" only contains some function pointers.
>
> Update "struct devlink_dpipe_table" and the 'table_ops' parameter of
> devl_dpipe_table_register() so that structures in drivers can be
> constified.
>
> Constifying these structures will move some data to a read-only section, so
> increase overall security.
>
> Signed-off-by: Christophe JAILLET <[email protected]>

Reviewed-by: Ido Schimmel <[email protected]>

2024-06-03 10:55:31

by Ido Schimmel

[permalink] [raw]
Subject: Re: [PATCH 2/2 net-next] mlxsw: spectrum_router: Constify struct devlink_dpipe_table_ops

On Sun, Jun 02, 2024 at 04:18:53PM +0200, Christophe JAILLET wrote:
> 'struct devlink_dpipe_table_ops' are not modified in this driver.
>
> Constifying these structures moves some data to a read-only section, so
> increase overall security.
>
> On a x86_64, with allmodconfig:
> Before:
> ======
> text data bss dec hex filename
> 15557 712 0 16269 3f8d drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.o
>
> After:
> =====
> text data bss dec hex filename
> 15789 488 0 16277 3f95 drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.o
>
> Signed-off-by: Christophe JAILLET <[email protected]>

Reviewed-by: Ido Schimmel <[email protected]>

2024-06-03 12:47:22

by Jiri Pirko

[permalink] [raw]
Subject: Re: [PATCH 0/2 net-next] devlink: Constify struct devlink_dpipe_table_ops

Sun, Jun 02, 2024 at 04:18:51PM CEST, [email protected] wrote:
>Patch 1 updates devl_dpipe_table_register() and struct
>devlink_dpipe_table to accept "const struct devlink_dpipe_table_ops".
>
>Then patch 2 updates the only user of this function.
>
>This is compile tested only.
>
>Christophe JAILLET (2):
> devlink: Constify the 'table_ops' parameter of
> devl_dpipe_table_register()
> mlxsw: spectrum_router: Constify struct devlink_dpipe_table_ops

set-
Reviewed-by: Jiri Pirko <[email protected]>

2024-06-05 09:31:48

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH 0/2 net-next] devlink: Constify struct devlink_dpipe_table_ops

Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <[email protected]>:

On Sun, 2 Jun 2024 16:18:51 +0200 you wrote:
> Patch 1 updates devl_dpipe_table_register() and struct
> devlink_dpipe_table to accept "const struct devlink_dpipe_table_ops".
>
> Then patch 2 updates the only user of this function.
>
> This is compile tested only.
>
> [...]

Here is the summary with links:
- [1/2,net-next] devlink: Constify the 'table_ops' parameter of devl_dpipe_table_register()
https://git.kernel.org/netdev/net-next/c/82dc29b9737e
- [2/2,net-next] mlxsw: spectrum_router: Constify struct devlink_dpipe_table_ops
https://git.kernel.org/netdev/net-next/c/b072aa789918

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html