Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1292274pxb; Fri, 21 Jan 2022 14:33:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLqqgLTKiPa5Sm/V1cTNh8oVRfr8SXmqYMlE7t+iWHvF1lU4t/MSbgGZT6ae4yB/LOJBeL X-Received: by 2002:a17:902:dac9:b0:14a:52d1:a266 with SMTP id q9-20020a170902dac900b0014a52d1a266mr5343583plx.161.1642804402862; Fri, 21 Jan 2022 14:33:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642804402; cv=none; d=google.com; s=arc-20160816; b=Tiu4eZi7YvGhaqY8k8oAf9+4o6cOM6w1wzSUtMO2V4oc67M73BPy8WXEmSTovoXDVH nRVQN5iBlUALo5aC/BvVF8duKLQ5MD4gVk9SW7G1bNEfvdWe40PgZuDF+0XLelD7eV4m 29j0bnvWKsNJiqWC55mgEiNm8rtKHpw8PHfEu8YhjPYgxA2eR4mL5whe6iue/PFm9GLb 6weB+QlBESUQ4GWkYqppSt7+AX4jvnw5wiX7GIozgymqlh2X+cfaTb++bZwvEp8UMO+w nPyTWgnXbt6ML/dHVIAM/JJs1viVylwp1c53F4Ro9E67i6qYHyd3f9bZti89ayOeecOC saLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eJuqwd/hBrvG4bO8PH6bAPcGLwvyj+x0/SP4MY9PP6s=; b=hMQk8+UtuVAQ3h4wzTF9pw2o1XGW6Lxm69JesLCrG0mDPqxnsf0Ts05SjyGpE9NkoT VlG4LwLcXPTgtEIzNCjvw4K30p6qggS+sOsu1iQmslr8s+2G4ovknT9moP6t5rLIZDW/ 2WAn8gNeIiNnbXWbG6KlQ2esmCW9yAZ3yyqHn6YoJdOLZdZTB9B87tlzAs6TiuSBITm5 QzHxTBy+AsAAqacsW7uWugUuoy9vHdez/5i2dQ4eCCAL3Ttn6k6i4CwbctLyMTgj/0Rq nS3KZsdxTIxt75t3f9cqVK8YV6xIWDnFSCf962WeTAywmjRgRWHL2QnoTyzkuDacEOCR RzTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p10si6826386pls.262.2022.01.21.14.33.08; Fri, 21 Jan 2022 14:33:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377491AbiATTOT convert rfc822-to-8bit (ORCPT + 99 others); Thu, 20 Jan 2022 14:14:19 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:39490 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377492AbiATTNf (ORCPT ); Thu, 20 Jan 2022 14:13:35 -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 20KHwWFG013570 for ; Thu, 20 Jan 2022 11:13:35 -0800 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3dpyswcse1-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Jan 2022 11:13:35 -0800 Received: from twshared0654.04.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 20 Jan 2022 11:13:30 -0800 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 35D1D283245F4; Thu, 20 Jan 2022 11:13:23 -0800 (PST) From: Song Liu To: , , CC: , , , , , , Song Liu Subject: [PATCH v5 bpf-next 4/7] bpf: add a pointer of bpf_binary_header to bpf_prog Date: Thu, 20 Jan 2022 11:13:02 -0800 Message-ID: <20220120191306.1801459-5-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220120191306.1801459-1-song@kernel.org> References: <20220120191306.1801459-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: aFT82_p_nu_M3AzZCfknw3gLDmZwbequ X-Proofpoint-ORIG-GUID: aFT82_p_nu_M3AzZCfknw3gLDmZwbequ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-20_07,2022-01-20_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 bulkscore=0 mlxlogscore=903 priorityscore=1501 impostorscore=0 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 suspectscore=0 spamscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201200097 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 5855eb474c62..27ea68604c22 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; } -- 2.30.2