Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1556714pxb; Tue, 8 Feb 2022 22:10:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfCRXiiaweNs4u/RAdrlRPZJ/krLAuYZO2UCJ8i1DP/upErjzXi83DmC2HJEQugI80nbUL X-Received: by 2002:a17:90a:fc6:: with SMTP id 64mr902261pjz.36.1644387050945; Tue, 08 Feb 2022 22:10:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644387050; cv=none; d=google.com; s=arc-20160816; b=Hp/Ke+gHEotustMtmTkxBF3/z3APIY7QrORuCtd/O3ySktrEVckEB7eYTTt7DM6VmN TK02+aMhK/0DTj3JZ0wPjw4e8yV4ZGov8MW4sNtCLiWEKGXbw3MBJBzoNTV/sCQFRJMu UtCM0P5yit0DvbUiuZFh/Z6qsCrgcAg6wPPoehwdQgQ6/M3BkfRRMM3Rb0KIovLRDtt5 cK+JVd6K+evnQHvnFGh4E5VPfgvqF1aYoTu9N/SgUf+BptRFfYs89HjmKL+0FHCapm+p 4OoNbPNQALVBf9vreuV50n6n1CorTWaTonrVmpTUaqn+V/OTZ6NHB8s3Nthk8oawTQpY 6sFQ== 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=+Kd56tLjboeXiGPz5xd3Qz1PgQbLxHyqfAErrxpN/UQ=; b=ZhFPxY0odUp504AxlhnNKKnDJVTiXQfDikFDcBzAadEDY6aDTd5joGFN+sI1KWKIFe D3HWNw4layduDJ7Sfa9m6jBAVpQOGUMB/CcS5srSuobJKuRS/c5NImlhbp0tFcruZJtP /muW7YHVJWjHz3xwHAaAadh0jk8lQUcZHqRmdU1eRtDe9+y81xvLvOYH0i4nllEFguHV nmOcDoudiAzqv+kqPNbyJLc34S2Jbj0fn6zAEyKACOczjyk4xrsA6Pyh5NRJbikjBjK+ vFDuFm4or/LMtU4arj4M/FPGB/iRZiEacAbzPXlen+PPdlCpVoe2wUs4JRRtM4q6jbu1 +0Lg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s8si11902447plk.601.2022.02.08.22.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 22:10:50 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E41C1DF28A37; Tue, 8 Feb 2022 21:55:44 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231553AbiBDTB3 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 4 Feb 2022 14:01:29 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:37796 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231249AbiBDTBQ (ORCPT ); Fri, 4 Feb 2022 14:01:16 -0500 Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 214IiuMR021816 for ; Fri, 4 Feb 2022 11:01:16 -0800 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3e19gar6bn-11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 04 Feb 2022 11:01:16 -0800 Received: from twshared6457.05.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Feb 2022 11:01:10 -0800 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 3B6F3296C578C; Fri, 4 Feb 2022 10:58:07 -0800 (PST) From: Song Liu To: , , CC: , , , , , , , Song Liu Subject: [PATCH v9 bpf-next 6/9] bpf: introduce bpf_arch_text_copy Date: Fri, 4 Feb 2022 10:57:39 -0800 Message-ID: <20220204185742.271030-7-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220204185742.271030-1-song@kernel.org> References: <20220204185742.271030-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: WYj8XUZumePmpoWpt9gUcmemZrTE8WHQ X-Proofpoint-GUID: WYj8XUZumePmpoWpt9gUcmemZrTE8WHQ 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-02-04_07,2022-02-03_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 clxscore=1015 malwarescore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=992 impostorscore=0 phishscore=0 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202040104 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 36f6fc3e6e69..c13d148f7396 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -2412,3 +2412,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 366f88afd56b..ea0d7fd4a410 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2362,6 +2362,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 e3fe53df0a71..a5ec480f9862 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2440,6 +2440,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