Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4064pxb; Mon, 31 Jan 2022 03:51:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/IIWrgLfqEnJE9wOy3Zf37lztmZ1bRVjxnvXXyKm3IHdmlpZyQJ6nW1OgcGeVPVk1k5JL X-Received: by 2002:a63:84c6:: with SMTP id k189mr16570855pgd.79.1643629885824; Mon, 31 Jan 2022 03:51:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643629885; cv=none; d=google.com; s=arc-20160816; b=FdSw1Un9AcX4+YOa5Jkuzsoy5QMTc/PWinxrHOY/BnWOzrZh4xGLZm+GKv+51pffrh 9OInfzzAtEogHx5Yuv/E0KC66XmXlcCX37p5AAp3xWuTSjKEuzX0pXO04iIBx4tuRyfV bmrODl6X9mS6Zp25kmgmSjGK6334KHmff+FZKtkg8RPUgY2PUVqIQGm1AG2wiIhTj6c1 6WfawK6MQpXnuuMKqrHg6CG6qDXwCuob/nq4CdMmuxpE617zX8xElD51SSiXSzy8fvv2 hKnG+4Iuoc9XnR1Oz8GAFlm8UoGvOkhhKhDGSYIbIts22p/bajRAsoIHTuIcMUUAwh2H BifA== 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=r/gkve840EaH2zR2XPzzzShQsb4yhn40WYvWu/myb6w=; b=Fuq0J9TGF7e/G9L0d/hzDOoQvs5jDhP3TzCn3Jv6kcjNpr/PqFMQl5radyRehRx/nE UC+2+MMjNE4IJvBWmB20AQjnkPw0ALGqqJMCjVSJQlKbc8KgVClPZ8Wu5FfcvLIIpnIO 6mds3PGj0him2kAWsarNuXUP5JWpUzijV+DyzNiT3ZH+Jm0GmG6i4LVvcOdMIOCYd6Q+ JgS0lVqX6JEXOqjI/eT5cGcBjHEvUo3ZKIjLRBs9ZA+8uQYnUxVbccJbeeIr3Z385Z9s d9WAlgwdWA6+mFeVxas1q8PmyndDF8TJkGJQH28q7motyIy8wsIIEv6/ipawW1fMs3wS laiA== 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 ke17si684992pjb.75.2022.01.31.03.51.14; Mon, 31 Jan 2022 03:51:25 -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 S1351239AbiA1X5T convert rfc822-to-8bit (ORCPT + 99 others); Fri, 28 Jan 2022 18:57:19 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:10008 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344727AbiA1X5R (ORCPT ); Fri, 28 Jan 2022 18:57:17 -0500 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20SKe9fD026412 for ; Fri, 28 Jan 2022 15:57:16 -0800 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3dv8um6b98-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 28 Jan 2022 15:57:16 -0800 Received: from twshared0654.04.ash8.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 28 Jan 2022 15:57:14 -0800 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id F3B2528E02F93; Fri, 28 Jan 2022 15:45:35 -0800 (PST) From: Song Liu To: , , CC: , , , , , , , Song Liu Subject: [PATCH v7 bpf-next 6/9] bpf: introduce bpf_arch_text_copy Date: Fri, 28 Jan 2022 15:45:14 -0800 Message-ID: <20220128234517.3503701-7-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220128234517.3503701-1-song@kernel.org> References: <20220128234517.3503701-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: bMCnYoILlEqUjdhJic2dWCNsqpqDaA5A X-Proofpoint-GUID: bMCnYoILlEqUjdhJic2dWCNsqpqDaA5A 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-28_08,2022-01-28_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 malwarescore=0 suspectscore=0 clxscore=1015 mlxscore=0 phishscore=0 adultscore=0 mlxlogscore=998 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201280130 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This will be used to copy JITed text to RO protected module memory. On x86, bpf_arch_text_copy is implemented with text_poke_copy. bpf_arch_text_copy returns pointer to dst on success, and ERR_PTR(errno) on errors. Signed-off-by: Song Liu --- arch/x86/net/bpf_jit_comp.c | 7 +++++++ include/linux/bpf.h | 2 ++ kernel/bpf/core.c | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index ce1f86f245c9..9792bf10d881 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -2413,3 +2413,10 @@ bool bpf_jit_supports_kfunc_call(void) { return true; } + +void *bpf_arch_text_copy(void *dst, void *src, size_t len) +{ + if (text_poke_copy(dst, src, len) == NULL) + return ERR_PTR(-EINVAL); + return dst; +} diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 28ac752f21ba..7f58fe256671 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2350,6 +2350,8 @@ enum bpf_text_poke_type { int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, void *addr1, void *addr2); +void *bpf_arch_text_copy(void *dst, void *src, size_t len); + struct btf_id_set; bool btf_id_set_contains(const struct btf_id_set *set, u32 id); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 7cbcf6bfbb52..dc0142e20c72 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2448,6 +2448,11 @@ int __weak bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, return -ENOTSUPP; } +void * __weak bpf_arch_text_copy(void *dst, void *src, size_t len) +{ + return ERR_PTR(-ENOTSUPP); +} + DEFINE_STATIC_KEY_FALSE(bpf_stats_enabled_key); EXPORT_SYMBOL(bpf_stats_enabled_key); -- 2.30.2