From patchwork Mon Oct 31 22:25:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 13026422 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2F2AECAAA1 for ; Mon, 31 Oct 2022 22:26:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51E7C6B0074; Mon, 31 Oct 2022 18:26:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4818C6B0075; Mon, 31 Oct 2022 18:26:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AEAB6B0078; Mon, 31 Oct 2022 18:26:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1B4A36B0074 for ; Mon, 31 Oct 2022 18:26:04 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DC8E980629 for ; Mon, 31 Oct 2022 22:26:03 +0000 (UTC) X-FDA: 80082678606.16.F8802EE Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf13.hostedemail.com (Postfix) with ESMTP id 7495420009 for ; Mon, 31 Oct 2022 22:26:03 +0000 (UTC) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VMPADh021770 for ; Mon, 31 Oct 2022 15:26:02 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3kjk60t971-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 31 Oct 2022 15:26:02 -0700 Received: from twshared24004.14.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 31 Oct 2022 15:26:01 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id 14D99F0CC5BD; Mon, 31 Oct 2022 15:25:52 -0700 (PDT) From: Song Liu To: , CC: , , , , , , , Song Liu Subject: [PATCH bpf-next v1 RESEND 2/5] x86/alternative: support vmalloc_exec() and vfree_exec() Date: Mon, 31 Oct 2022 15:25:38 -0700 Message-ID: <20221031222541.1773452-3-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221031222541.1773452-1-song@kernel.org> References: <20221031222541.1773452-1-song@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: 5wxCRpD5bDIukhVDczoE-w1t_gHXr_e- X-Proofpoint-ORIG-GUID: 5wxCRpD5bDIukhVDczoE-w1t_gHXr_e- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_21,2022-10-31_01,2022-06-22_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667255163; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qJBuqZwUYjAdic8Fx/39Kej9QvrkoIoDUXShDgKr244=; b=i9Tg2HFTQhIHpSoUSQLbWnEoMJT9EWAr306yVIXkhDUBqVUqy+WPOeus3zVJ/Ad+nRRGkH eN0apmS7+9I+ol1HvmDLF0HZbm3Lt4XWWjSvLL614rVFrrwBS0IVZX9t4+M0WNwxcnZrDt BZGHNuU5CcfS+IdU/ER2QM/bbT9A3kM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of "prvs=2303bf8861=songliubraving@meta.com" designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=2303bf8861=songliubraving@meta.com"; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667255163; a=rsa-sha256; cv=none; b=byJIXoHjN9+djGouPQABDJEf2KA3bISiYQjAGw2GrCIoZWWqOjOE4M7tZPim5jPk4ZklST 7mPiTZZLR3nNeO9tkTkVm2Wq5/lZ/XsVwYK6Zn3SXVa43HZ6tXh94aSpSxuFx1pYuEjHbX 3vabaJmop7tJ+kdWF8vk4OD16ZBalI0= X-Stat-Signature: 9cjf7pt1ny9dqud5nkqq8qw638neaje5 X-Rspamd-Queue-Id: 7495420009 Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of "prvs=2303bf8861=songliubraving@meta.com" designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=2303bf8861=songliubraving@meta.com"; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1667255163-294710 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Implement arch_vcopy_exec() and arch_invalidate_exec() to support vmalloc_exec. arch_vcopy_exec() copies dynamic kernel text (such as BPF programs) to RO+X memory region allocated by vmalloc_exec(). arch_invalidate_exec() fills memory with 0xcc after it is released by vfree_exec(). Signed-off-by: Song Liu --- arch/x86/kernel/alternative.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 5cadcea035e0..73d89774ace3 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -1270,6 +1270,18 @@ void *text_poke_copy(void *addr, const void *opcode, size_t len) return addr; } +void *arch_vcopy_exec(void *dst, void *src, size_t len) +{ + if (text_poke_copy(dst, src, len) == NULL) + return ERR_PTR(-EINVAL); + return dst; +} + +int arch_invalidate_exec(void *ptr, size_t len) +{ + return IS_ERR_OR_NULL(text_poke_set(ptr, 0xcc, len)); +} + /** * text_poke_set - memset into (an unused part of) RX memory * @addr: address to modify