From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5CA733F5BF for ; Fri, 14 Aug 2026 12:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786709098; cv=none; b=to19AGZL1A/ssBiDjtKiioswkBeM2BLW65OJz7qjxR5VO75XQUtmJxlERS08Ftvdqb/SNsm+m52MY7ll3/PpRRrgjcwXPaICaYKbDiYgUesI6abKwBRpj4a6jUOEztLYp0P+jVlon3HQvj/EcFIOFzvaaoluLaaOnrDza13f3rM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786709098; c=relaxed/simple; bh=UYzYQgt/6OLeIfaMZGCWLM7T/aWZcK/FVyWxu7+UJDo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SdRyKCfZnNKPIga4EodgnWNX231aPY6QbjqKdA9fkEUXYJK2qm/Eh1bFvoT4CPOpSOL8W+vGGcDjvQ/1SdvK7gLtj5SF2Rfg8LTS6S7RRGvGJlYKmsEaaEPjzN7t8vsG77mjm+MTrqZ+wRhhDFemIrhDqpGU6MHKFdWrqI9Vr+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CBF0ezR5; arc=none smtp.client-ip=209.85.208.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CBF0ezR5" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-39db07589caso7059241fa.2 for ; Fri, 14 Aug 2026 05:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786709095; x=1787313895; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=K95ykzEShOLEivVx29SWjU23KHeS4yVUrSdELipcQNA=; b=CBF0ezR5Ngtf0tY1FOUHmJ4JRMcxUIfIMLWF85JC41Jx5jW77c9C8blK2sxDPqKsxt VN5L4iWbdttdpJwbE75AEQ2m/62w4abRTPPJ05SUFqFB9daGw7KFbuEKRwZmYzzC05fP CzwV9UK1IHb1CE4Id84DYiBf5f1LD6dE3/u8IS5D0AFDqhyai3xuEXdtYm1lQlUJLMxK RxaB0VIqdRax10LKs6KrJm6L2UT3qI8J0Vne7L/+p06B1KZgqrgWbJ76Tc04S9lE6Rwp dMBv8fHkYb8Z5ZDrSRgEx5+cQMrzJNsn6ynEd3H/+M+w+9nfXeVa1yHaJo0KJX8Zz2X7 y8aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786709095; x=1787313895; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=K95ykzEShOLEivVx29SWjU23KHeS4yVUrSdELipcQNA=; b=iR4fCJaGvHluwAcKhzF8rESKlEbCnb3hFuyTnjaSWGvfQGEdxoKuz3gIHIsUKFSP4z dH982DWNWLxLqEvFR3Yrkk/+3nSPpuYFAp5+sEtV3u/SEzU4JR4IDs9SdT7tlKPrm8ux EVlCa6EGc4rsprTQiU4lwxsO8kcj5gqHrs11ffMwFuJ/qXNi5GekgyS49g1zCAZKSY9z 2RmLtiyATFSl5YJFJVK9fEGQSr5DmbaVuypgzB6+HRFDgNdxPYBqDefqs1wsjBketAKD /RGmk5y90KjfKPWYrtELR6pMErkLq1HKdk1ACBgdOUfGIXUM2n+ofK1bfb31+iG/gVN5 rPmg== X-Forwarded-Encrypted: i=1; AHgh+RoxICH1Y3udLFeR1YtF68J+rZ+VHut56V57hgP7LxR5l2/j1ywrcisQE1rMuPIv/fhj+uYK+2n0AAnC0kc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6ngBjnlFpkn7n7LHU+foALTMkJIiDSOlYKM72K5FKQLyk3Hsr lX+jeLfPUbpsDre7r4Pzdq3x0VmKaGFeYOkNi3eTyKXU1qul9ROaL5yj X-Gm-Gg: AR+sD128JW7/Wk/RB2qhPl1+/R/Fm3MXrFzuiPCgpkb+FagUEJNIAmY72NryAHPRNX+ syymig1Fx35qmupnx0ia0F+n5L8fFC6vRcNxLMNcz2aOV0Dm4PZ7z8zduqbzAykotTTIEW62/6Y QeZMfetrvMVP7unoQ2+4dTYacvSINtnYR5E4Lhnfpwr54kgzptO/9z4rEgaWgzOTbbj2V7lhVUY u23uGI4B4EY0KlTjb2ifxhPHxmZsfkoAhNvAo4FKYlleFl8Zk60HCdHkgT0mlos+SlGWwk9osBa mwBq23qJLzrphOZvmmBIKIAUubLpES5+JhnE5j58pvJZF9PFmKYGYpPO1NObsvgnkDCpxmzirNR HuS4hLX25RaS2vayZB2Gul9LMXi37gjTn0bum4i/Qt5XL5I/2+qdfm7X/PU3CqWF5N4sr4S8KyP 4T9Il+GcODF6AN2+9SLUeeAnGiSSInztYXUBDNT83RDJktrAyKY7GEiT07frXu5w9oWt8eEua7Z 0eu X-Received: by 2002:a05:651c:a346:b0:39d:b5b9:f0f4 with SMTP id 38308e7fff4ca-3a1324053d9mr5759571fa.10.1786709094349; Fri, 14 Aug 2026 05:04:54 -0700 (PDT) Received: from localhost (soda.int.kasm.eu. [2001:678:a5c:1202:7b92:9ac1:b9ef:5287]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3a130872f9csm5614151fa.7.2026.08.14.05.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 05:04:53 -0700 (PDT) Date: Fri, 14 Aug 2026 14:04:53 +0200 From: Klara Modin To: Xiaofeng Yuan Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nam Cao , Klara Modin , prabhakar.csengg@gmail.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable Message-ID: References: <20260814082742.148403-1-xiaofengmian@163.com> <20260814082742.148403-3-xiaofengmian@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260814082742.148403-3-xiaofengmian@163.com> On 2026-08-14 08:27:42 +0000, Xiaofeng Yuan wrote: > patch_map() always creates a temporary writable mapping via fixmap for > kernel text addresses, even when CONFIG_STRICT_KERNEL_RWX is disabled > and the kernel text is already mapped with _PAGE_WRITE. > > This is unnecessary overhead at best, and on minimal configurations > it can cause page faults. > > Skip the fixmap path for kernel text when CONFIG_STRICT_KERNEL_RWX > is not enabled, since the text pages are already writable in that case. > The module text path is already gated on CONFIG_STRICT_MODULE_RWX and > is kept unchanged. > > Reported-by: Klara Modin > Closes: https://lore.kernel.org/all/ant_8TaBbov_GS4i@soda.int.kasm.eu/ > Reported-by: Lad Prabhakar > Closes: https://lore.kernel.org/all/CA+V-a8tQK8rih9SGGTyqrEBGpNkx4H0eX2YccCRrgkVAPr+EBg@mail.gmail.com/ > --- > v5: fix the fixmap gating for kernel text. The v4 early return on > CONFIG_STRICT_MODULE_RWX wrongly skipped the fixmap for kernel text > too, which panics on configs with CONFIG_MODULES=n where > CONFIG_STRICT_MODULE_RWX is unavailable but CONFIG_STRICT_KERNEL_RWX > is still enabled and kernel text is read-only. > v3: early return when !CONFIG_STRICT_MODULE_RWX (per Nam Cao's suggestion) > v2: add commit description > > Signed-off-by: Xiaofeng Yuan This version works fine for me. Thanks, Tested-by: Klara Modin > --- > arch/riscv/kernel/patch.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c > index 16b243376f..2239c28981 100644 > --- a/arch/riscv/kernel/patch.c > +++ b/arch/riscv/kernel/patch.c > @@ -45,6 +45,8 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap) > phys_addr_t phys; > > if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) { > + if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) > + return addr; > phys = __pa_symbol(addr); > } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) { > struct page *page = vmalloc_to_page(addr); > -- > 2.43.0 >