From patchwork Fri Aug 25 15:18:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hari Bathini X-Patchwork-Id: 13366068 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 C783810797 for ; Fri, 25 Aug 2023 15:18:50 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8CD5212C for ; Fri, 25 Aug 2023 08:18:49 -0700 (PDT) Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37PF93Kb019409; Fri, 25 Aug 2023 15:18:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=R65EbJlLwHJb5seiON9QSx7U8ud+0yOykXg2FvFaQE4=; b=nRoBFW5utg9kInrL4IoC+co5rrE0EZnul92ALXeHcBtRvDn5//LrXqkAQiUhbFWppfp6 KXhlqPERoG2YMXMJqmebZ9IG76OimUxStwbZNsb83kghTcFE2NtNyXnLcKIcMNSEZTST Fcw5pEgOPtsyEiFdCbdTpRScozzyTsulk7cwZaE9YOeusVbZ92kJSzbgkWer1GcMOYS/ ImPrtAEgpPsKIRAag9DcBxryXvV/UqbQayMwXQ7m/IgK0rnO+iOGl08hpY/mcdxdsClz ZNjVDmktn4Hei12GmKCL2GKtqX7wTaySW01ycruUovKYrCiaWse6lxnLJJwkIJa6dVH8 kA== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3spwk6st3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Aug 2023 15:18:18 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37PF7B7H004093; Fri, 25 Aug 2023 15:18:16 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sn21s0g0r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Aug 2023 15:18:16 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37PFIE9B20447868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Aug 2023 15:18:14 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC0E22004B; Fri, 25 Aug 2023 15:18:14 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C34A820043; Fri, 25 Aug 2023 15:18:12 +0000 (GMT) Received: from li-bd3f974c-2712-11b2-a85c-df1cec4d728e.ibm.com.com (unknown [9.43.75.97]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 25 Aug 2023 15:18:12 +0000 (GMT) From: Hari Bathini To: linuxppc-dev , bpf@vger.kernel.org Cc: Michael Ellerman , "Naveen N. Rao" , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Christophe Leroy Subject: [PATCH 0/5] powerpc/bpf: use BPF prog pack allocator Date: Fri, 25 Aug 2023 20:48:05 +0530 Message-ID: <20230825151810.164418-1-hbathini@linux.ibm.com> X-Mailer: git-send-email 2.41.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: PSQhWMh6X9OFORCi59SorDgmNy_oYGGH X-Proofpoint-ORIG-GUID: PSQhWMh6X9OFORCi59SorDgmNy_oYGGH X-Proofpoint-UnRewURL: 0 URL was un-rewritten Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-25_13,2023-08-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 mlxlogscore=591 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308250134 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Most BPF programs are small, but they consume a page each. For systems with busy traffic and many BPF programs, this may also add significant pressure on instruction TLB. High iTLB pressure usually slows down the whole system causing visible performance degradation for production workloads. bpf_prog_pack, a customized allocator that packs multiple bpf programs into preallocated memory chunks, was proposed [1] to address it. This series extends this support on powerpc. Patches 1 & 2 add the arch specific functions needed to support this feature. Patch 3 enables the support for powerpc and ensures cleanup is handled gracefully. Patch 4 introduces patch_instructions() that optimizes some calls while patching more than one instruction. Patch 5 leverages this new function to improve time taken for JIT'ing BPF programs. Note that the first 3 patches are sufficient to enable the support for bpf_prog_pack on powerpc. Patches 4 & 5 are to improve the JIT compilation time of BPF programs on powerpc. Thanks to Christophe and Song for reviewing v2 [2]. Changes in v3: * Fixed segfault issue observed on ppc32 due to inaccurate offset calculation for branching. * Tried to minimize the performance impact for patch_instruction() with the introduction of patch_instructions(). * Corrected uses of u32* vs ppc_instr_t. * Moved the change that introduces patch_instructions() to after enabling bpf_prog_pack support. * Added few comments to improve code readability. [1] https://lore.kernel.org/bpf/20220204185742.271030-1-song@kernel.org/ [2] https://lore.kernel.org/all/20230309180028.180200-1-hbathini@linux.ibm.com/ Hari Bathini (5): powerpc/bpf: implement bpf_arch_text_copy powerpc/bpf: implement bpf_arch_text_invalidate for bpf_prog_pack powerpc/bpf: use bpf_jit_binary_pack_[alloc|finalize|free] powerpc/code-patching: introduce patch_instructions() powerpc/bpf: use patch_instructions() arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/lib/code-patching.c | 94 ++++++++++++--- arch/powerpc/net/bpf_jit.h | 12 +- arch/powerpc/net/bpf_jit_comp.c | 138 ++++++++++++++++++----- arch/powerpc/net/bpf_jit_comp32.c | 13 ++- arch/powerpc/net/bpf_jit_comp64.c | 10 +- 6 files changed, 205 insertions(+), 63 deletions(-)