Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp91093lqj; Thu, 11 Apr 2024 10:38:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUuMBAIToLISg7nHCWLB69OR+cXzDWW5mrDdPtnWp0/ZaGb3dtkns92IAcRP+El6/yxvwYMZ9tXTNDk316rQ+cuuOpAQkr4OL3f7OYI2Q== X-Google-Smtp-Source: AGHT+IEfoLwwlZoj9nIS2Ori6KTJPaD47A1Rzx6+sct01IJ9lP2e0pakeGi67JazIk/ViBmOzhIh X-Received: by 2002:ac8:7dcc:0:b0:434:fb83:8e0d with SMTP id c12-20020ac87dcc000000b00434fb838e0dmr435024qte.24.1712857088570; Thu, 11 Apr 2024 10:38:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712857088; cv=pass; d=google.com; s=arc-20160816; b=UmtazAQg9WmBzMZUfrqos6iXRuiDZnMvd8zgujv15RcT5op0wg4u8ZVUf/MztgHsU1 BoW11/COiQWgER4+nkMN5EgA2M4z0gD7EOFaNEKkNDZV4Uz8Dki5FrrTaPAUJhFD3exF RQ93DgDrES6cYA8m131heGR6TVvX2xziVXzdhcVm2g84vwPBJ33RjF3EHWr8sXnclx3Z sGesYC6WCxcXv2wZx8oQPCOmLDEvCNhbwGAgvFHQzJ6Im5+GyIWR3crFj4RM+m9TQS0O qF7J465+4gd4lhlKMb1X7tGAA0Z+16CODkNsBV0dKnvLEYezkZQRhVr1lQGz0tjTK9HM jDCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=D1BTf2N+zCWAOqcFc0gPFGJn38p/N6Sbkw/J2Gz0+tA=; fh=gMFRjFG9KasUYvwr0WK5/KYxde7tueU8fZSQFYWo6W4=; b=kLYmTGyygVo/bhkvRs7z9Mscq3PgpU1ooztqysX6aXMVgfQaGusfdxO7+wPsnRdfRL Z1wr288md/yHcs6kqFkr+T+n0fZY8kJpXcY1FXtPk/RwczePJ1Cc8BRsKBlB2QG9lCfU L5vebz5dXaumSO7beozwPRj0XCGGbZk43HPAPohgw6CC0+VT2zeRKG5SfUIGCRKz1v1f Ke6uFGPgTjuMqtcG5AYN0l1tALswyuBN3845imOWW/NavWi6B7GXINA7y9JCyTjZ+10j ge7h0ZQY5BTdjDeV9zhdg/gtr5VJ+q1Jh6p1hrIp9cA1E+7vS0zBb+sr0iTptb786sG3 KChg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eRW/q4WS"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141277-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o14-20020ac85a4e000000b004367eb0edd2si428509qta.722.2024.04.11.10.38.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:38:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eRW/q4WS"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141277-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4BC9D1C2141B for ; Thu, 11 Apr 2024 17:38:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E1461509B9; Thu, 11 Apr 2024 16:06:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eRW/q4WS" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95AF97FBA3; Thu, 11 Apr 2024 16:06:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851602; cv=none; b=V/K1vI+am7Y8kCauY9pTpBX+Om3gt9c5tt46y7Ip6Gx8NmtN+faaxarKNqH2513WFGe4w1ouZZC1ORBMt+rk3UsMjuREp9KytQPgKV2v18/X5+bUJ5RntWqyCX17B5Ou3pQWOAUta9E706JGUejVuslra31I3Sczi0DKKjvgi6M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851602; c=relaxed/simple; bh=GpS8ytfjSzE76nC42qU8VRxGL9fjdKFDqm8vIE1x4YY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sDyMGJeu7DcHah/asI4jkO2BprdRBal/6loYPrbVOPgZtXSYSnd7RFTy+MCl8G0R/cgt9qcqkJ5XW4MpPfow+Bl6Bpfu38M1FE70Bs8Mtx0jegngxw83p1tSRtSZOmEwy6HgbS1MiBG/XUOuAj+xcGIp51hPyGs8uU+bkfHUg8o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eRW/q4WS; arc=none smtp.client-ip=10.30.226.201 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; } -- 2.43.0