From patchwork Fri Sep 8 13:39:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 13377481 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D238663AD for ; Fri, 8 Sep 2023 13:39:39 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9674A1BC1 for ; Fri, 8 Sep 2023 06:39:37 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Rhxzm5PQjz4f3kk8 for ; Fri, 8 Sep 2023 21:39:32 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgDHVqkPJPtkRmSwCg--.44307S4; Fri, 08 Sep 2023 21:39:29 +0800 (CST) From: Hou Tao To: bpf@vger.kernel.org Cc: Martin KaFai Lau , Alexei Starovoitov , Andrii Nakryiko , Song Liu , Hao Luo , Yonghong Song , Daniel Borkmann , KP Singh , Stanislav Fomichev , Jiri Olsa , John Fastabend , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , houtao1@huawei.com Subject: [PATCH bpf 0/4] Fix the unmatched unit_size of bpf_mem_cache Date: Fri, 8 Sep 2023 21:39:19 +0800 Message-Id: <20230908133923.2675053-1-houtao@huaweicloud.com> X-Mailer: git-send-email 2.29.2 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDHVqkPJPtkRmSwCg--.44307S4 X-Coremail-Antispam: 1UD129KBjvJXoW7AF48Kry5XFyrXr13Zr4xJFb_yoW8Xw1kpa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P_HELO_FCRDNS, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net From: Hou Tao Hi, The patchset aims to fix the reported warning [0] when the unit_size of bpf_mem_cache is mismatched with the object size of underly slab-cache. Patch #1 fixes the warning by adjusting size_index according to the value of KMALLOC_MIN_SIZE, so bpf_mem_cache with unit_size which is smaller than KMALLOC_MIN_SIZE or is not aligned with KMALLOC_MIN_SIZE will be redirected to bpf_mem_cache with bigger unit_size. Patch #2 doesn't do prefill for these redirected bpf_mem_cache to save memory. Patch #3 adds further error check in bpf_mem_alloc_init() to ensure the unit_size and object_size are always matched and to prevent potential issues due to the mismatch. Please see individual patches for more details. And comments are always welcome. [0]: https://lore.kernel.org/bpf/87jztjmmy4.fsf@all.your.base.are.belong.to.us Hou Tao (4): bpf: Adjust size_index according to the value of KMALLOC_MIN_SIZE bpf: Don't prefill for unused bpf_mem_cache bpf: Ensure unit_size is matched with slab cache object size selftests/bpf: Test all valid alloc sizes for bpf mem allocator kernel/bpf/memalloc.c | 87 ++++++++++++- .../selftests/bpf/prog_tests/test_bpf_ma.c | 50 +++++++ .../testing/selftests/bpf/progs/test_bpf_ma.c | 123 ++++++++++++++++++ 3 files changed, 256 insertions(+), 4 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_ma.c create mode 100644 tools/testing/selftests/bpf/progs/test_bpf_ma.c