[PATCH] iommufd: Constify struct dma_buf_attach_ops

Christophe JAILLET posted 1 patch 1 month, 1 week ago
drivers/iommu/iommufd/pages.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] iommufd: Constify struct dma_buf_attach_ops
Posted by Christophe JAILLET 1 month, 1 week ago
'struct dma_buf_attach_ops' is not modified in this driver.

Constifying this structure moves some data to a read-only section, so
increases overall security, especially when the structure holds some
function pointers.

On a x86_64, with allmodconfig:
Before:
======
   text	   data	    bss	    dec	    hex	filename
  81096	  13899	    192	  95187	  173d3	drivers/iommu/iommufd/pages.o

After:
=====
   text	   data	    bss	    dec	    hex	filename
  81160	  13835	    192	  95187	  173d3	drivers/iommu/iommufd/pages.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only.
---
 drivers/iommu/iommufd/pages.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
index 8124c554f2cc..9bdb2945afe1 100644
--- a/drivers/iommu/iommufd/pages.c
+++ b/drivers/iommu/iommufd/pages.c
@@ -1450,7 +1450,7 @@ static void iopt_revoke_notify(struct dma_buf_attachment *attach)
 	pages->dmabuf.phys.len = 0;
 }
 
-static struct dma_buf_attach_ops iopt_dmabuf_attach_revoke_ops = {
+static const struct dma_buf_attach_ops iopt_dmabuf_attach_revoke_ops = {
 	.allow_peer2peer = true,
 	.invalidate_mappings = iopt_revoke_notify,
 };
-- 
2.53.0
Re: [PATCH] iommufd: Constify struct dma_buf_attach_ops
Posted by Jason Gunthorpe 1 month ago
On Thu, Feb 26, 2026 at 10:05:21PM +0100, Christophe JAILLET wrote:
> 'struct dma_buf_attach_ops' is not modified in this driver.
> 
> Constifying this structure moves some data to a read-only section, so
> increases overall security, especially when the structure holds some
> function pointers.
> 
> On a x86_64, with allmodconfig:
> Before:
> ======
>    text	   data	    bss	    dec	    hex	filename
>   81096	  13899	    192	  95187	  173d3	drivers/iommu/iommufd/pages.o
> 
> After:
> =====
>    text	   data	    bss	    dec	    hex	filename
>   81160	  13835	    192	  95187	  173d3	drivers/iommu/iommufd/pages.o
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only.
> ---
>  drivers/iommu/iommufd/pages.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied thanks

Jason