From patchwork Thu Apr 11 16:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13626348 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 E07A8C4345F for ; Thu, 11 Apr 2024 16:06:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 748BA6B00C0; Thu, 11 Apr 2024 12:06:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D0876B00C2; Thu, 11 Apr 2024 12:06:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 549806B00C3; Thu, 11 Apr 2024 12:06:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2BBC36B00C0 for ; Thu, 11 Apr 2024 12:06:45 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E69FB40C1E for ; Thu, 11 Apr 2024 16:06:44 +0000 (UTC) X-FDA: 81997729128.23.10ABBC1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 38A5DA0027 for ; Thu, 11 Apr 2024 16:06:43 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="eRW/q4WS"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712851603; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D1BTf2N+zCWAOqcFc0gPFGJn38p/N6Sbkw/J2Gz0+tA=; b=Q+bclvkkSvAMCMUZWltzJdalIA3ezhjvzl/XpIi56gYj/SKB2EUOampoHIzyv01duXmYgj nsivPWM+sSPvgRnopLC31RxVm8Pac+veH5xgKwUYfnu48Hl125UxdxXlix62ckf7Uz9BXA 6rmXnbSDg3NY40u4Wh7iZZ80Z0dlVF0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="eRW/q4WS"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712851603; a=rsa-sha256; cv=none; b=q6QTQNUEmqM1xwNh0zEJQdygqwlZuiOjROskCeJMFA5jVSfzZ4C9RA261zgXGTFIa5lnwW MsDuyCWUXjCRxl+x1PRf70Gjaa4j5gqUuTho6K1OKajUYllm/A38lwH04POciAaIQWVA92 +PE9U1C6aAJVOD3qljTNeTspDsGQfTE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7DC02620F0; Thu, 11 Apr 2024 16:06:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A810C4AF09; Thu, 11 Apr 2024 16:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712851602; bh=GpS8ytfjSzE76nC42qU8VRxGL9fjdKFDqm8vIE1x4YY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eRW/q4WS++c0r4pBuIO3O4Xg4RhucjdHqnNZoi79AHoLhQPJWC7o5buwGGFBPvniC VKRspPAvG+oxGO/Mu52T5QZWLHipAdpse5TDkTXl4UCRQQbTzoV2tVhPjQUCAlmNo0 NG232/NssiPa7JNKn0tv4mghHev6HdVbKr+LbbRCokaCTTwVdChPLdcxxCtgfIMnpO Z1hyZ7UoVGi2N4el/7GuNUEzPhXZ5vzgMOKVlVVadMtRh3z+39u712GiPM9IWHw2qe adjgDWeIItjJVb1bdKVNluXidKTvt1LLI9M1CnLR4urws3bFChygnRYjAkvNDCL/IG 2uw/kGGX3wdrg== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Andy Lutomirski , Arnd Bergmann , Catalin Marinas , Christoph Hellwig , Helge Deller , Lorenzo Stoakes , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Mathieu Desnoyers , Michael Ellerman , Mike Rapoport , Palmer Dabbelt , Peter Zijlstra , Russell King , Song Liu , Steven Rostedt , Thomas Gleixner , Uladzislau Rezki , Will Deacon , bpf@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [RFC PATCH 7/7] x86/module: enable ROX caches for module text Date: Thu, 11 Apr 2024 19:05:26 +0300 Message-ID: <20240411160526.2093408-8-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411160526.2093408-1-rppt@kernel.org> References: <20240411160526.2093408-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 38A5DA0027 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 5bszo8ohbd91jyzoydrq1yecujf137w5 X-HE-Tag: 1712851603-860306 X-HE-Meta: U2FsdGVkX18y80/86dexM/AFhQaPXDKW24nBJ5NkNvqr6KJhRyuYsB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lbowKaN8e75G/IvioMNIihLXi8Hw459nS66vl/ZtVqjhrtQtBpamMy1nnrlIr4IyPBb69Dz5dmYyamabJYy6KJgEZ+akwgjrvYYSBNAfChjIJ87quGGEPc477Vz5+OA== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" Enable execmem's cache of PMD_SIZE'ed pages mapped as ROX for module text allocations. Signed-off-by: Mike Rapoport (IBM) --- arch/x86/mm/init.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 8e8cd0de3af6..049a8b4c64e2 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -1102,9 +1102,23 @@ unsigned long arch_max_swapfile_size(void) #endif #ifdef CONFIG_EXECMEM +static void execmem_invalidate(void *ptr, size_t size, bool writeable) +{ + /* fill memory with INT3 instructions */ + if (writeable) + memset(ptr, 0xcc, size); + else + text_poke_set(ptr, 0xcc, size); +} + static struct execmem_info execmem_info __ro_after_init = { + .invalidate = execmem_invalidate, .ranges = { - [EXECMEM_DEFAULT] = { + [EXECMEM_MODULE_TEXT] = { + .flags = EXECMEM_KASAN_SHADOW | EXECMEM_ROX_CACHE, + .alignment = MODULE_ALIGN, + }, + [EXECMEM_KPROBES...EXECMEM_MODULE_DATA] = { .flags = EXECMEM_KASAN_SHADOW, .alignment = MODULE_ALIGN, }, @@ -1119,9 +1133,16 @@ struct execmem_info __init *execmem_arch_setup(void) offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; start = MODULES_VADDR + offset; - execmem_info.ranges[EXECMEM_DEFAULT].start = start; - execmem_info.ranges[EXECMEM_DEFAULT].end = MODULES_END; - execmem_info.ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL; + + for (int i = EXECMEM_MODULE_TEXT; i < EXECMEM_TYPE_MAX; i++) { + struct execmem_range *r = &execmem_info.ranges[i]; + + r->start = start; + r->end = MODULES_END; + r->pgprot = PAGE_KERNEL; + } + + execmem_info.ranges[EXECMEM_MODULE_TEXT].pgprot = PAGE_KERNEL_ROX; return &execmem_info; }