Re: [PATCH bpf-next] bpf: Reduce smap->elem_size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 12/16/22 3:29 PM, Martin KaFai Lau wrote:
From: Martin KaFai Lau <martin.lau@xxxxxxxxxx>

'struct bpf_local_storage_elem' has a 56 bytes padding at the end
which can be used for attr->value_size.  The current smap->elem_size

'can be' => 'will be'?

calculation is unnecessarily inflated by 56 bytes.

The patch is to fix it by calculating the smap->elem_size
with offsetof().

Signed-off-by: Martin KaFai Lau <martin.lau@xxxxxxxxxx>

Acked-by: Yonghong Song <yhs@xxxxxx>

---
  kernel/bpf/bpf_local_storage.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index b39a46e8fb08..cb43e70613b1 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -580,8 +580,8 @@ static struct bpf_local_storage_map *__bpf_local_storage_map_alloc(union bpf_att
  		raw_spin_lock_init(&smap->buckets[i].lock);
  	}
- smap->elem_size =
-		sizeof(struct bpf_local_storage_elem) + attr->value_size;
+	smap->elem_size = offsetof(struct bpf_local_storage_elem, sdata) +
+		offsetof(struct bpf_local_storage_data, data[attr->value_size]);
return smap;
  }



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux