From patchwork Thu Jan 6 02:25:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 12705033 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31C39C433EF for ; Thu, 6 Jan 2022 02:29:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344833AbiAFC3Z convert rfc822-to-8bit (ORCPT ); Wed, 5 Jan 2022 21:29:25 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:35168 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344850AbiAFC2x (ORCPT ); Wed, 5 Jan 2022 21:28:53 -0500 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 205N7PXc005928 for ; Wed, 5 Jan 2022 18:28:53 -0800 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3ddmqsgtmh-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 05 Jan 2022 18:28:52 -0800 Received: from twshared7572.23.frc3.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 5 Jan 2022 18:28:51 -0800 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id EA94B273E541A; Wed, 5 Jan 2022 18:25:50 -0800 (PST) From: Song Liu To: , , CC: , , , , , , Song Liu , Song Liu Subject: [PATCH v3 bpf-next 4/7] bpf: add a pointer of bpf_binary_header to bpf_prog Date: Wed, 5 Jan 2022 18:25:30 -0800 Message-ID: <20220106022533.2950016-5-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220106022533.2950016-1-song@kernel.org> References: <20220106022533.2950016-1-song@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: SsESG9ip5BGyIhB65xDlP2VMDcLf4Oly X-Proofpoint-GUID: SsESG9ip5BGyIhB65xDlP2VMDcLf4Oly X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-05_08,2022-01-04_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 adultscore=0 malwarescore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 clxscore=1015 mlxlogscore=429 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2112160000 definitions=main-2201060011 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net With sub page allocation, we cannot simply use bpf_func & PAGE_MASK to find the bpf_binary_header. Add a pointer to struct bpf_prog to avoid this logic. Use this point for x86_64. If the pointer is not set by the jit engine, fall back to original logic. Signed-off-by: Song Liu --- arch/x86/net/bpf_jit_comp.c | 2 ++ include/linux/filter.h | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index ce1f86f245c9..fe4f08e25a1d 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -2339,6 +2339,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) if (header) bpf_jit_binary_free(header); prog = orig_prog; + header = NULL; goto out_addrs; } if (image) { @@ -2406,6 +2407,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) if (tmp_blinded) bpf_jit_prog_release_other(prog, prog == orig_prog ? tmp : orig_prog); + prog->hdr = header; return prog; } diff --git a/include/linux/filter.h b/include/linux/filter.h index 6d73d89c99a4..b5c7e12f7675 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -584,6 +584,7 @@ struct bpf_prog { const struct bpf_insn *insn); struct bpf_prog_aux *aux; /* Auxiliary fields */ struct sock_fprog_kern *orig_prog; /* Original BPF program */ + struct bpf_binary_header *hdr; /* Instructions for interpreter */ union { DECLARE_FLEX_ARRAY(struct sock_filter, insns); @@ -893,9 +894,14 @@ static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr) static inline struct bpf_binary_header * bpf_jit_binary_hdr(const struct bpf_prog *fp) { - unsigned long real_start = (unsigned long)fp->bpf_func; - unsigned long addr = real_start & PAGE_MASK; + unsigned long real_start; + unsigned long addr; + if (fp->hdr) + return fp->hdr; + + real_start = (unsigned long)fp->bpf_func; + addr = real_start & PAGE_MASK; return (void *)addr; }