From patchwork Fri Oct 7 23:43:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 13001544 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 E4D8FC433FE for ; Fri, 7 Oct 2022 23:46:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38AB36B0074; Fri, 7 Oct 2022 19:46:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 313CB6B0075; Fri, 7 Oct 2022 19:46:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 141666B0078; Fri, 7 Oct 2022 19:46:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DCA7D6B0074 for ; Fri, 7 Oct 2022 19:46:13 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 904C71A00EC for ; Fri, 7 Oct 2022 23:46:13 +0000 (UTC) X-FDA: 79995789426.09.E1E30E8 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf10.hostedemail.com (Postfix) with ESMTP id 1EC77C0013 for ; Fri, 7 Oct 2022 23:46:12 +0000 (UTC) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 297NZmq8009416 for ; Fri, 7 Oct 2022 16:46:12 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3k26gy8vyx-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 07 Oct 2022 16:46:11 -0700 Received: from twshared6211.23.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 7 Oct 2022 16:46:09 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id E1612DE442D8; Fri, 7 Oct 2022 16:43:20 -0700 (PDT) From: Song Liu To: , CC: , , , , , , , , Song Liu Subject: [RFC v2 0/4] vmalloc_exec for modules and BPF programs Date: Fri, 7 Oct 2022 16:43:11 -0700 Message-ID: <20221007234315.2877365-1-song@kernel.org> X-Mailer: git-send-email 2.30.2 X-FB-Internal: Safe X-Proofpoint-GUID: a0X1RdUoPlQf23zJzYrNVtCX3BWJ1z6o X-Proofpoint-ORIG-GUID: a0X1RdUoPlQf23zJzYrNVtCX3BWJ1z6o X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-10-07_04,2022-10-07_01,2022-06-22_01 ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of "prvs=1279faf8c2=songliubraving@fb.com" designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1279faf8c2=songliubraving@fb.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=1665186373; a=rsa-sha256; cv=none; b=TM7SMIKA33ajuJb/g1zybqoBgduGROASvvjc5SP4G3+sfilKf60uHjAOGx3h09VOFy4kV5 udO05h2SCxzgtdLKbIhVAI+E/UwT/aLD7uHI1QYTv51xv/GIcrYo6X/LfS/2Ctf22HmGQt BIKlBWlrihD9lu5Ht4jBJLZ6tlRJkVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665186373; 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: references; bh=lp3uwbLGhwGPzmPX+vVv5sHZLmClQcfioNWQsDjLhOc=; b=KA9yHSeO2Sxb7z9MJOear+tTKvetpTSpKxFrwA4SqvvN6CBRqAJ4A4VnCxfILcolwEgkZr 9o+4qqIHON8x9s0FV1RbYxboRMOF8EnILsnRh7GcHEGfb7zXKU2Tp/vK8aCj/0YV5WAxlH kgsqDktpuxXvgAuITw9mZD63ZRnQZ/g= X-Rspamd-Queue-Id: 1EC77C0013 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of "prvs=1279faf8c2=songliubraving@fb.com" designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1279faf8c2=songliubraving@fb.com"; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) X-Rspamd-Server: rspam10 X-Stat-Signature: y4zyq5tzkd9fp3gzoex1s5b5ty6udj3e X-HE-Tag: 1665186372-101397 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: Changes RFC v1 => RFC v2: 1. Major rewrite of the logic of vmalloc_exec and vfree_exec. They now work fine with BPF programs (patch 1, 2, 4). But module side (patch 3) still need some work. This set is a prototype that allows dynamic kernel text (modules, bpf programs, various trampolines, etc.) to share huge pages. The idea is similar to Peter's suggestion in [1]. Please refer to each patch for more detais. The ultimate goal is to only host kernel text in 2MB pages (for x86_64). Please share your comments on this. Thanks! [1] https://lore.kernel.org/bpf/Ys6cWUMHO8XwyYgr@hirez.programming.kicks-ass.net/ [2] RFC v1: https://lore.kernel.org/linux-mm/20220818224218.2399791-3-song@kernel.org/T/ Song Liu (4): vmalloc: introduce vmalloc_exec and vfree_exec bpf: use vmalloc_exec modules, x86: use vmalloc_exec for module core vmalloc_exec: share a huge page with kernel text arch/x86/Kconfig | 1 + arch/x86/kernel/alternative.c | 30 +++- arch/x86/kernel/module.c | 1 + arch/x86/mm/init_64.c | 3 +- include/linux/vmalloc.h | 2 + kernel/bpf/core.c | 155 ++---------------- kernel/module/main.c | 23 +-- kernel/module/strict_rwx.c | 3 - kernel/trace/ftrace.c | 3 +- mm/nommu.c | 7 + mm/vmalloc.c | 296 ++++++++++++++++++++++++++++++++++ 11 files changed, 358 insertions(+), 166 deletions(-) --- 2.30.2