From nobody Fri Sep 25 00:03:39 2026 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (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 A3F9327AC57 for ; Fri, 18 Sep 2026 13:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789737545; cv=none; b=GJ5+aNS92WA7JLt80JIeXUv7m3KaRODWJrsPDiNc5A7vDG+f0XkHt+no9oNn52DGTIIzJO7hmZJgvVBgAJm7O1xWNl/dW6fWMTizfD0LT+FC8N3GD+7lsfj69ONmHngbJL2ZhJVcy2WEjlKlNzlyTDhnJtxR1rx/mHfao7ZHt98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789737545; c=relaxed/simple; bh=LNeh7zm2p73PrVkoXPGxxYDKl/Dawye1sRPQQGYDQUI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=We0+GZzdSE+KO9bPrQwpTHru5iCBOhla8zcnrtZp+DZLAIy2p6hnr9Iiy0spSzn2RV0xOZH1NoqTorJz1x+GARAl9kRXYpDLYSq7YXiLynWYynLKRMogO06JV1zTLO/PCFF7deIABp5tyoRHedPYYqszMVrgZ/wNdGwK+KL1hek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jkH2B9ew; arc=none smtp.client-ip=209.85.128.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jkH2B9ew" Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-490a767c7dcso6194185e9.2 for ; Fri, 18 Sep 2026 06:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789737542; x=1790342342; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Lo1KsoI1XuIoEcDs+Ce0ZXJLIqJlsl+upMRklAIDXKY=; b=jkH2B9ewBvDogcSCWHJKJIoq/E0sO5yeZz+l0xIIx27/rE6uQaOyZKWghRpsbjhf77 HuVrom5088a0ylxgjCNFdNv+7zTtwtB1/5YvmU+BnEDSk6bGjzhHZURoeoH8kJ3Q5u/P 82L0GBuvY/u50AYirQCMPU27pncx4BTecQDQPmPSSTV/OLp2zroVivBjNBIhTvDKD8Px cm/xiBn9qU84PP7hK7cOF0rmQicexuN+FCUllPCSc3CQwO5bcr56CbRkM0XK3lWy27V8 PCXPTz/l7w+cOuPZDvDZSDPsF+q1wedTevEUUzxtIT+5ctD1nZJpqkrqO/slalxC5EWg CXnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789737542; x=1790342342; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Lo1KsoI1XuIoEcDs+Ce0ZXJLIqJlsl+upMRklAIDXKY=; b=EtIjHf23dA86z5N9RQ85xo7kLsAq4NnnIh46d6tvG0dSq+DUp1TKT2xIQGpSwnymJ1 PnFmltpaWrLS9Xr1EaIN//VxPn7PEyuQcROjf+Tj41p2awOYXpveBzL6IqLAGvUu4OX9 W1P0qZx2RpFOLM+MiPVtISfkEw4OqW4fWMLr6yqnDZSuZriIoVi1goVY2wFrHYzqgnql 26PLjV3LP0di47S9N+Lgpm02gyDJ4x/hpOlRjS7mViSWHzYPR79s6446u2eVlA2LC78/ oUCdCaENmE9uVcJ0wqDsJSVi2nuQhcX9RQ5MJ5SpXbbEUjPXa1uO/+UmEEntptFHypX3 UlhA== X-Forwarded-Encrypted: i=1; AKwUvBzVJ0KTRShEgvnIwX1MOlLTug8XPN/60BbZp/38jd3diG8WVdofC4DXpEf6t07rECXyKSaWVh/75GfNnio=@vger.kernel.org X-Gm-Message-State: AFuF++m3GQvHsCZLLA1i2yhlpL7ffD3psfolw3EmsQG7Ebt4muGOWVfL 6I1XtQP/qWfcqjMjDofAp0zqsnSQc8UOP8OSn/bM4mP8Bxk/hZ9ukuRrku/+5L1MUXXQlIH6wBM c1aGk8/dllhJblMHPosiumw== X-Received: from wmbje21.prod.google.com ([2002:a05:600c:1f95:b0:49e:6e7c:4200]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3550:b0:49e:7d74:7b7a with SMTP id 5b1f17b1804b1-49fc56db8f3mr33347175e9.6.1789737541522; Fri, 18 Sep 2026 06:19:01 -0700 (PDT) Date: Fri, 18 Sep 2026 14:16:53 +0100 In-Reply-To: <20260918131656.3710047-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260918131656.3710047-1-vdonnefort@google.com> X-Mailer: git-send-email 2.55.0.1082.g2b9226bbc0-goog Message-ID: <20260918131656.3710047-2-vdonnefort@google.com> Subject: [PATCH v1 1/4] PM: hibernate: Add arch specific hooks for hibernate_map/unmap_page From: Vincent Donnefort To: catalin.marinas@arm.com, will@kernel.org, rafael@kernel.org Cc: mark.rutland@arm.com, lenb@kernel.org, pavel@kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, thierry.reding@kernel.org, rppt@kernel.org, Vincent Donnefort Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hibernate_map_page() is called from an atomic context. This is problematic for Arm BBML3 systems where the linear map may contain blocks and is allowed to split as splitting is a sleepable operation. Add arch hook so arm64 can define its own implementation without relying on the direct map. Signed-off-by: Vincent Donnefort --- include/linux/suspend.h | 2 ++ kernel/power/snapshot.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index b02876f1ae38..10fe2298d94e 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -401,6 +401,8 @@ int hibernate_quiet_exec(int (*func)(void *data), void = *data); int hibernate_resume_nonboot_cpu_disable(void); int arch_hibernation_header_save(void *addr, unsigned int max_size); int arch_hibernation_header_restore(void *addr); +void *hibernate_map_page(struct page *page); +void hibernate_unmap_page(struct page *page); =20 #else /* CONFIG_HIBERNATION */ static inline void register_nosave_region(unsigned long b, unsigned long e= ) {} diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index b209712cb2c3..b41952f1de2a 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -85,7 +85,7 @@ static inline int hibernate_restore_unprotect_page(void *= page_address) {return 0 * It is still worth to have a warning here if something changes and this * will no longer be the case. */ -static inline void hibernate_map_page(struct page *page) +void * __weak hibernate_map_page(struct page *page) { if (IS_ENABLED(CONFIG_ARCH_HAS_SET_DIRECT_MAP)) { int ret =3D set_direct_map_default_noflush(page); @@ -95,9 +95,10 @@ static inline void hibernate_map_page(struct page *page) } else { debug_pagealloc_map_pages(page, 1); } + return page_address(page); } =20 -static inline void hibernate_unmap_page(struct page *page) +void __weak hibernate_unmap_page(struct page *page) { if (IS_ENABLED(CONFIG_ARCH_HAS_SET_DIRECT_MAP)) { unsigned long addr =3D (unsigned long)page_address(page); @@ -1456,8 +1457,9 @@ static bool safe_copy_page(void *dst, struct page *s_= page) if (kernel_page_present(s_page)) { zeros_only =3D do_copy_page(dst, page_address(s_page)); } else { - hibernate_map_page(s_page); - zeros_only =3D do_copy_page(dst, page_address(s_page)); + void *src =3D hibernate_map_page(s_page); + + zeros_only =3D do_copy_page(dst, src); hibernate_unmap_page(s_page); } return zeros_only; --=20 2.55.0.1082.g2b9226bbc0-goog From nobody Fri Sep 25 00:03:39 2026 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (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 DF15937AA9E for ; Fri, 18 Sep 2026 13:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789737546; cv=none; b=d59oRuwcO2TWUqStF7Yh4WYAcOGUWhUpgN6IPLVYxz5YS3HNAA7kD/CgFpHn8hoN9bj5zk2j5Jx985appo815cXDCTpmPgc6sBOqypxPJE0HfHIuA3bEDG6pl+LWlZI0LPsVfRKx7oHgf7ExJppTSAX/baLHKtmnZqgTCh6u/8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789737546; c=relaxed/simple; bh=ncZg2VuW+AySF8gMan+UeGIC3Uxuyips31vZXC/8WFE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hcKcspDl9/HOw//AVjwKZ5+VpwhU0aX8Ssmu9lfKNuS535oAy6Z7ir7TFUI1Ryd2v2yZnovkhcgJn2aSiWQqFAHCbJQ5pEzw2+8y6YV75gAmlGeVk/fCeGk5ak42PTGjpU98C2go4bEuOg9QdwzTIJ2S8xeowBirBiG1WfpInbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B/gWKm33; arc=none smtp.client-ip=209.85.221.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B/gWKm33" Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-472c330e555so349300f8f.1 for ; Fri, 18 Sep 2026 06:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789737543; x=1790342343; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=R10EWAoqeqiwKYs38V4/eu87hmfK6YBmKaV1HjMgWDg=; b=B/gWKm33uRLY8ViiqpqQuf3gOS2bqWPrpt4nqhleSfJMIhc9LdiVIL2w0IDp/6k/Lc JNCb0mU7s4bdXBF1ZsECVKDFwtPUmHcrdNkcToZDR0XqPKwB+WdwdCVva541OcOlFKgp wgciMsVAidAgQb4nJEtz17JpYV3RjCE/5jR0IZNDM8kb1NoXGX8YK6LxuRaQy/yrJOBl khrcf4Q4rG1cdTMS5RugwSu1SKR3SnvhcFky8wxPleTqaKn1QoZc5tTbeVkNfrGxV6Li Z6KQU3HjbL5ipHnlNUz3wHEwh1YeMSvBKM+O/k+v1c0Y6kX5vtTsPOnztwf6+Xxb9sxx Wavg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789737543; x=1790342343; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=R10EWAoqeqiwKYs38V4/eu87hmfK6YBmKaV1HjMgWDg=; b=XqhHd6EivgdwGehqgmw789M33C/Qen9Uq5iMOvwDKUXk75mVxVEnM+8EPHc2kacuNp Go5aYJ0lpFNoCxlRkzBr08UV/1jcWDs6+y91+9N3p6BinEh6rz+mULTnpXROyRspRfJL SdmanPo0uhxgZ/Z3NrUESqv9A5hLDzBa5EaYa9y6N6yW7reXLObIfMbf2iYCUmPN6NMg h7cblQnvm0JyDR8KTAmHvJNfRcrHwf5Zl/yOuzWPaUH8rTXuLhZTe0XAK0xBYElDUzOF /oflt35LIfawpJZXqWtsX02m86IZe4jamE20GtN5pYe3GYVT716BNTUSURTAM8JFYxxI jbVg== X-Forwarded-Encrypted: i=1; AKwUvByTqEdRlV340ydEJsVCbMQ24cjaxNkIxV8CpHmdKMWTeeFrjq816u6PWq7obHYs8Dvar1StH9ODMmbHkrg=@vger.kernel.org X-Gm-Message-State: AFuF++nWEAfRIPnETyN2tK40IUuVMMFdIzrlkQzDtcb/y+1H88rcORtC gbENpmY1pTZ86j0C4J1eQyX/be6sfAE+/rEzPYt6zUWGjxRgy0A+xWAFM2A6AHZtGmmzrtc56qH mc3DmCNIRbmjDF5AkVp3tzA== X-Received: from wmsl26.prod.google.com ([2002:a05:600c:1d1a:b0:49e:6680:860c]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1993:b0:49c:ffe3:2b3f with SMTP id 5b1f17b1804b1-49fc56dbc54mr34667275e9.3.1789737542981; Fri, 18 Sep 2026 06:19:02 -0700 (PDT) Date: Fri, 18 Sep 2026 14:16:54 +0100 In-Reply-To: <20260918131656.3710047-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260918131656.3710047-1-vdonnefort@google.com> X-Mailer: git-send-email 2.55.0.1082.g2b9226bbc0-goog Message-ID: <20260918131656.3710047-3-vdonnefort@google.com> Subject: [PATCH v1 2/4] arm64: hibernate: Use fixmap for hibernate_map/unmap_page From: Vincent Donnefort To: catalin.marinas@arm.com, will@kernel.org, rafael@kernel.org Cc: mark.rutland@arm.com, lenb@kernel.org, pavel@kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, thierry.reding@kernel.org, rppt@kernel.org, Vincent Donnefort Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The default implementation for hibernate_map_page uses the direct map. This creates an unnecessary limitation for BBML3 enabled systems which can split linear map blocks and can enable memfd_secret users regardless of the linear map mapping level. Block splitting acquires a mutex (pgtable_split_lock) and as a consequence is incompatible with hibernation. We know hibernation would only call set_direct_map*() on a PTE-level region since it was previously split by memfd_secret. But let's avoid special casing hibernation in split_kernel_leaf_mapping(). On hibernation, do not modify the direct map and instead use a fixmap, better suited for a transient mapping hibernation needs to copy the page content. It removes the need for handling atomic context in split_kernel_leaf_mapping() altogether. Signed-off-by: Vincent Donnefort --- arch/arm64/include/asm/fixmap.h | 3 +++ arch/arm64/kernel/hibernate.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixma= p.h index 170c3502d723..c8a65fd8584d 100644 --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -73,6 +73,9 @@ enum fixed_addresses { FIX_ENTRY_TRAMP_TEXT1, #define TRAMP_VALIAS (__fix_to_virt(FIX_ENTRY_TRAMP_TEXT1)) #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ +#ifdef CONFIG_HIBERNATION + FIX_HIBERNATE, +#endif __end_of_permanent_fixed_addresses, =20 /* diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 7bf117427777..bbd0779081fa 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -213,6 +214,17 @@ static int create_safe_exec_page(void *src_start, size= _t length, return 0; } =20 +void *hibernate_map_page(struct page *page) +{ + set_fixmap(FIX_HIBERNATE, page_to_phys(page)); + return (void *)__fix_to_virt(FIX_HIBERNATE); +} + +void hibernate_unmap_page(struct page *page) +{ + clear_fixmap(FIX_HIBERNATE); +} + #ifdef CONFIG_ARM64_MTE =20 static DEFINE_XARRAY(mte_pages); --=20 2.55.0.1082.g2b9226bbc0-goog From nobody Fri Sep 25 00:03:39 2026 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (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 362C34F391F for ; Fri, 18 Sep 2026 13:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789737547; cv=none; b=pMaKqOt7YORiEB0OgoLwTvTHeEq+cL5vvsj1hRMGrkJqkKlo380LDPCSMzB+21HMKg9tpJAZ7uHrbuM9UQB/9WXsYH0o3k7wNh8r/UmLPPgmigrX986p11Q6VAhfT9tN+H0BD+QtkJlTDlEYRL+OfpkAMWoIXnQwzheMSGZjepk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789737547; c=relaxed/simple; bh=GrzDV6cczkYxjO5tC/93Uw9vwmtlbRDBmm6zE9MIKJ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gylF9n624GNcDJgypQFXjDGcPYht7YAvBI5YnO2mGS8+QrC/VSjCwFtF2SxvcpUZXkrvdK69ICSDTY4UvC7ICDBKATMuAgW3FQ19YVASiQF/R6C1mt3BKfCk1i487xk7hcoPAgCq4LrlbU79uTK3mG4vcz9pTOj4o0ZDOlldKhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=R/JFIC4z; arc=none smtp.client-ip=209.85.221.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="R/JFIC4z" Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4870663a5c4so313981f8f.1 for ; Fri, 18 Sep 2026 06:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789737544; x=1790342344; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9aOX9z3d/XK6ZHrErASZL6mYBZmtA4GVOMC24/C+YOg=; b=R/JFIC4zEEQpEff/oP2df94bgAiDtd+SE/pejnaF/QeIS71LUweyItTE7HpAxCZ2fP xl2bZHyQhulpFc5LSOlYLF5L5Q9fwgKT69h0TUjNwap7yIi2RK0Zr2T5X0BFMdK+zucw 8Y06uQ9jD4KqyUvXg6UWPeLOUcoN8jdtsRZYZo+16sK3sYyDoAPW1k1q/IOfuQpAxVKj 8RMfBoAM5/p1Gf5FP93KmZOUtrfqy90KrHdQ8ld8JGMrVJfvdN7LuYepmpeBnV5CyY5e UQk2vMQxiMHymM0k/0Co7Dy/adOvSO7gwweFfJPbjNe8d3t7NQmMMgixVv6+xNZIDGtp kjpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789737544; x=1790342344; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9aOX9z3d/XK6ZHrErASZL6mYBZmtA4GVOMC24/C+YOg=; b=lmFpgfnLUwnR9UKHuSAEMvNGGypqBrCZo9Z3QH3X3iItH/UvR5hi4rWgKfIC4JGiEH gMIz5kqjYhxdQHQpcMb0l3+hIi/dJA+NCZGvAftUPAAWko6CveYBM3RNPn0DLxESecDr Ujlg+uZEWqjdQia/c2/XZe2rNQ3E5x1hmxtmApqY3ffsGqtroSa437bF6aFr+zBcdVj+ 5thA6ZWUbBUgw871ky3tjhaAKc0omBf8pSORdo+3VoXTOwBDwokINWuk+1d483iBitxU mk3sQuB10qgLMu3FbZvzqqjfFIlbXfZkZaLHBOcO9V1ywjO+COOUfj4ScxM2bJ9j7AeL Oziw== X-Forwarded-Encrypted: i=1; AKwUvBwglfWEXJZksB7whJdrheOkkMW6cXr2AbklIp6Q2fY+y2s7X6U8IgUYukADMTPsNpixcNlWzwhyRcg0czA=@vger.kernel.org X-Gm-Message-State: AFuF++m0l/R/XmdwsTuYVNsRpCrhBpx5f7HfzLu5ejAVXI8Zg0ltzrb1 Q9LdhXAE1DkXgcGMhqYCHrglHpo3UbjGP7exeNCPZFuAf/+VnxeoFfamftDxyznImJYQVrNDj45 28veL3H3oqwFMbIfS8cEfbQ== X-Received: from wrdf12.prod.google.com ([2002:a5d:58ec:0:b0:487:11c9:7de9]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2884:b0:487:360:5be1 with SMTP id ffacd0b85a97d-4871e2112femr3684285f8f.8.1789737544221; Fri, 18 Sep 2026 06:19:04 -0700 (PDT) Date: Fri, 18 Sep 2026 14:16:55 +0100 In-Reply-To: <20260918131656.3710047-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260918131656.3710047-1-vdonnefort@google.com> X-Mailer: git-send-email 2.55.0.1082.g2b9226bbc0-goog Message-ID: <20260918131656.3710047-4-vdonnefort@google.com> Subject: [PATCH v1 3/4] arm64: mm: Introduce linear_map_needs_set() helper From: Vincent Donnefort To: catalin.marinas@arm.com, will@kernel.org, rafael@kernel.org Cc: mark.rutland@arm.com, lenb@kernel.org, pavel@kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, thierry.reding@kernel.org, rppt@kernel.org, Vincent Donnefort Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" can_set_direct_map() is intended as an external query function, but is also being called internally by map_mem() to initialise linear_map_requires_bbml3, duplicating the feature checks already present in force_pte_mapping(). Factor the list of features that require modifying linear map attributes into a shared helper linear_map_needs_set(). Signed-off-by: Vincent Donnefort --- arch/arm64/include/asm/mmu.h | 1 + arch/arm64/mm/mmu.c | 22 ++++++++++++++++++++-- arch/arm64/mm/pageattr.c | 12 +----------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h index 5e1211c540ab..12ed21e2d0d7 100644 --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -70,6 +70,7 @@ extern void create_pgd_mapping(struct mm_struct *mm, phys= _addr_t phys, pgprot_t prot, bool page_mappings_only); extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t pro= t); extern void mark_linear_text_alias_ro(void); +extern bool linear_map_needs_set(void); extern int split_kernel_leaf_mapping(unsigned long start, unsigned long en= d); extern void linear_map_maybe_split_to_ptes(void); =20 diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 79d90226fd5d..c18ed601f0a8 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -776,6 +776,24 @@ static int split_kernel_leaf_mapping_locked(unsigned l= ong addr) return ret; } =20 +/* + * True if the linear map needs to be modified for one of the following + * features: + * + * rodata_full and DEBUG_PAGEALLOC need to protect/unprotect pages in + * the linear map. + * + * KFENCE pool needs to protect/unprotect pages in the linear map if + * initialized late. + * + * Realms need to mark pages shared/protected in the linear map. + */ +bool linear_map_needs_set(void) +{ + return rodata_full || debug_pagealloc_enabled() || + arm64_kfence_can_set_direct_map() || is_realm_world(); +} + static inline bool force_pte_mapping(void) { const bool bbml3 =3D system_capabilities_finalized() ? @@ -785,7 +803,7 @@ static inline bool force_pte_mapping(void) return true; if (bbml3) return false; - return rodata_full || arm64_kfence_can_set_direct_map() || is_realm_world= (); + return linear_map_needs_set(); } =20 static DEFINE_MUTEX(pgtable_split_lock); @@ -1203,7 +1221,7 @@ static void __init map_mem(void) =20 arm64_kfence_map_pool(); =20 - linear_map_requires_bbml3 =3D !force_pte_mapping() && can_set_direct_map(= ); + linear_map_requires_bbml3 =3D !force_pte_mapping() && linear_map_needs_se= t(); =20 if (force_pte_mapping()) flags |=3D NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c index bbe98ac9ad8c..c1ba74eb602f 100644 --- a/arch/arm64/mm/pageattr.c +++ b/arch/arm64/mm/pageattr.c @@ -89,17 +89,7 @@ bool rodata_full __ro_after_init =3D true; =20 bool can_set_direct_map(void) { - /* - * rodata_full, DEBUG_PAGEALLOC and a Realm guest all require linear - * map to be mapped at page granularity, so that it is possible to - * protect/unprotect single pages. - * - * KFENCE pool requires page-granular mapping if initialized late. - * - * Realms need to make pages shared/protected at page granularity. - */ - return rodata_full || debug_pagealloc_enabled() || - arm64_kfence_can_set_direct_map() || is_realm_world(); + return linear_map_needs_set(); } =20 static int update_range_prot(unsigned long start, unsigned long size, --=20 2.55.0.1082.g2b9226bbc0-goog From nobody Fri Sep 25 00:03:39 2026 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (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 8FD17299922 for ; Fri, 18 Sep 2026 13:19:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789737549; cv=none; b=R1iFQYPSsYCBdaT4IzG1VhqI43ZeJk5y0kvQ8m5zdIxvqHSFcB19QnJrYF6BQ/pH70pD/2uZSZdErUEZhMkI+zJ0s0HMkNa1+TQQrpUZiF3UZrIdJorpvO9Gl8UlXH8vGr5AckEOsxtX0/j4tItUmfIGbRP2R4Rs/Mi3dQb+CTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789737549; c=relaxed/simple; bh=Ixxw6mUKGozOVNHy36L9BvzO5kqYLozMBT/gU9qeUOE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ab5giJjhM3o62kvlxku9j7q8Nt9Hm9evKjWG6zyMP5Iv34WVZ5uhseOcB8NCxKdB1fepdkgVxKPZKILYkzISULnw8YkeWwKb3BrsBl133cAoKy3EvXUeKgy/ziEy6sQM7sBEfh4NuJyAHWZgfgXYVoTAWQjEiSzDYF3A1LM9Ztk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=O9osNgLc; arc=none smtp.client-ip=209.85.128.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="O9osNgLc" Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-49e823c4868so6258045e9.0 for ; Fri, 18 Sep 2026 06:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789737545; x=1790342345; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=otp0k2i4YCw4bQ4ES7pDpC2btKFgr9S5MNUmkPBiGJY=; b=O9osNgLcrZyNEBaBbNDdTnP1aNwi2TUECCahZuj6vIvG/y8Adh+8gr8Owk3tf9NOvY JxzHit8WjeS3ZtdHI4G9kspD1L0f3ytS8SVmB/wSdM2dKHj1+FOZsI0/TUntnJzXgcVL VJ15kJG6IqpbMX25Y41tEdqu2UwwbiMigWgOoDDRLvXh+HSyd7n8eW7oylWMQzCcguoN L19RNojLMTSpi8UDdtdWKTUC+P/1e/zxd6Ig5Dsb7s6UIV/dKEWEppVdNKwQiNrFy/+B I9mNeDWww4SomkyIpNDrTNxr9C/sbu9fMQReyerLc6ItQ3J9vAngqkRfbp38opgmSTdD Awwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789737545; x=1790342345; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=otp0k2i4YCw4bQ4ES7pDpC2btKFgr9S5MNUmkPBiGJY=; b=glTbBrYSYAXZSOHjF8EXow6Ca9WRNWxupGqBDtqZGBPBpTMXW2KDiaypPSD6sN0poV Qi4nKdiYgQxRt0LN5Bm2hKnTeV4RBThjrUkxWYTMMSc60ycybxs4p77RiGJ0MUn6vDB+ S0VBck8Wh9tDIwnx1yYPZE85Cc6IJIs+3+5dwpVkFzFzaZnO3JDBg67UuXrRg3EIdPm0 0oV7pEABsqYKR2x84q9rLGR8E2MaDuI0xj6nd4BkhCIvxWyO6TzKFCi40lvIpH5z6whp pmuTZOSSWuc9AJ/7DS7xaAPe/b7YKt1TjlgGwOp1vWgnLJIMH3QoYgXW6O32KV2Xcw0n 2Few== X-Forwarded-Encrypted: i=1; AKwUvByuPTg3DqFbcYPSeyupZxj650slagsWpkFdW/An5q7zkmfSc57jBCGUibRx9kmozrNpffCeLEstoFpA2dY=@vger.kernel.org X-Gm-Message-State: AFuF++lYk6F36SExZPuzz30hLJ4a8F+IWzTTGl948l5x/isi6DLkUVb8 or81bbc5Xh7z9kLf+wzX3Cs1UkW+7hw1c44NMsfgCn7d/ZMCNJQivEHXCfHCEPh8HfxuhqD+UvD eKtccu5bnS/GcqgpPBLXdJw== X-Received: from wmps28.prod.google.com ([2002:a05:600c:319c:b0:49c:caed:426c]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:64c5:b0:49e:6c11:c4fc with SMTP id 5b1f17b1804b1-49fc56aa4e7mr86535595e9.7.1789737545460; Fri, 18 Sep 2026 06:19:05 -0700 (PDT) Date: Fri, 18 Sep 2026 14:16:56 +0100 In-Reply-To: <20260918131656.3710047-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260918131656.3710047-1-vdonnefort@google.com> X-Mailer: git-send-email 2.55.0.1082.g2b9226bbc0-goog Message-ID: <20260918131656.3710047-5-vdonnefort@google.com> Subject: [PATCH v1 4/4] arm64: mm: Allow can_set_direct_map() on BBML3 systems From: Vincent Donnefort To: catalin.marinas@arm.com, will@kernel.org, rafael@kernel.org Cc: mark.rutland@arm.com, lenb@kernel.org, pavel@kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, thierry.reding@kernel.org, rppt@kernel.org, Vincent Donnefort Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On BBML3 systems, block mappings in the linear map can be split dynamically at runtime without break-before-make faults. In such systems, allow can_set_direct_map() to enable set_direct_map_* users. split_kernel_leaf_mapping() must now allow splitting for BBML3 systems where no feature requires a split (i.e. !linear_map_needs_set()). As a consequence, it can't solely rely on linear_map_requires_bbml3 anymore. Instead, deduce force_pte_mapping() value and filter out non-lm addresses. Signed-off-by: Vincent Donnefort --- arch/arm64/mm/mmu.c | 24 +++++++++++++++--------- arch/arm64/mm/pageattr.c | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index c18ed601f0a8..4c345065d33f 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -811,24 +811,30 @@ static bool linear_map_requires_bbml3; =20 int split_kernel_leaf_mapping(unsigned long start, unsigned long end) { + bool force_pte; int ret; =20 /* * If the region is within a pte-mapped area, there is no need to try to - * split. Additionally, CONFIG_DEBUG_PAGEALLOC and CONFIG_KFENCE may - * change permissions from atomic context so for those cases (which are - * always pte-mapped), we must not go any further because taking the - * mutex below may sleep. Do not call force_pte_mapping() here because - * it could return a confusing result if called from a secondary cpu - * prior to finalizing caps. Instead, linear_map_requires_bbml3 gives us - * what we need. + * split: + * + * Do not call force_pte_mapping() here because it could return a + * confusing result if called from a secondary cpu prior to finalizing + * caps. Instead, retrieve that value with linear_map_requires_bbml3. + * + * Additionally, CONFIG_KFENCE may change permissions from atomic + * context so for this case (which is always pte-mapped), we must not go + * any further because taking the mutex below may sleep. + * + * Finally, set_memory_* can be called on PTE-mapped vmalloc mappings. */ - if (!linear_map_requires_bbml3 || is_kfence_address((void *)start)) + force_pte =3D !linear_map_requires_bbml3 && linear_map_needs_set(); + if (force_pte || is_kfence_address((void *)start) || !__is_lm_address(__t= ag_reset(start))) return 0; =20 if (!system_supports_bbml3()) { /* - * BBML3 systems should not be trying to change + * Non-BBML3 systems should not be trying to change * permissions on anything that is not pte-mapped in the first * place. Just return early and let the permission change code * raise a warning if not already pte-mapped. diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c index c1ba74eb602f..f952cc125705 100644 --- a/arch/arm64/mm/pageattr.c +++ b/arch/arm64/mm/pageattr.c @@ -89,7 +89,7 @@ bool rodata_full __ro_after_init =3D true; =20 bool can_set_direct_map(void) { - return linear_map_needs_set(); + return linear_map_needs_set() || system_supports_bbml3(); } =20 static int update_range_prot(unsigned long start, unsigned long size, --=20 2.55.0.1082.g2b9226bbc0-goog