From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 BAD2E3B8945 for ; Mon, 27 Apr 2026 12:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777292930; cv=none; b=rRJytFY5JWKOF3cFfapH4uOF8sQpWdscuEOhSeWO4fA4zsfWvXY7ASCGvtBOwnZwT1Aoj8z10BCVALpyTf7n1jYHYxz4XfuOZryamrskd9bhML1f0aDYPgEGia5eM6MdQf98oBBfJlLCPX7Bi2hTgVvqfO5qEr+7kGh8JIA+c0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777292930; c=relaxed/simple; bh=f538yH5w5Pax3lmCsHValW0vRI1ifnSNY2hRp8CvHAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y4KaG5GS6X6tS6chX7ya5Kyu6URrReo/Pu1KVdgbpfZf43JT2jyWuAbUYbHFiqOHBk0PADJ8hfZ9Q1wf9nAhL07EHsmXMyruD47w1QvP1PFmcgXEXmfhORbV3tvBBXHQK8T41ZAqHIqXRNzynzrYvxA9U5bwQ7LNyh66MFGTJMk= 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=TJKybmOv; arc=none smtp.client-ip=209.85.210.174 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="TJKybmOv" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-827270d50d4so9088446b3a.3 for ; Mon, 27 Apr 2026 05:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777292928; x=1777897728; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Prf45VRePEkbJ9bJmHgdAkS/+1uEQpgga1mrG9S2bCY=; b=TJKybmOvou3ut7X64LsTcK4JJyGPLnSwmJt4roI6C6JP4qfNIBEZLcH7iMfRlhAU3M MVAi6cVrBX6y7i54b5a9Rm1jNHMIvlH2Ci6VjTlx3hBJbjINx1uu/45X73XdGmYtBovW zW+As1A25HFzn4cKZG0Wnuwt4hmm6qmiP0Dr0hpcn3Cf+iA4OIFO0RsEg7f3JGCiFXFF 1KWx3U1XhDyTGZ4pY5Qwywwlo3Ujl2Vz/crfQVlkZ+7/jCUD8bHUgNEhOJHFxVtOcRJA Hx70agMX9ZVNFGYrCRv8s1+zxiJVtTvpkULpksdojPAZ5rwtguzdh9GX802oNSmY2xw8 s/ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777292928; x=1777897728; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Prf45VRePEkbJ9bJmHgdAkS/+1uEQpgga1mrG9S2bCY=; b=E7ZvCrrCJzGhB0P3D05Ro0ygFpTCHlahPx3QQcIYRalRvlDirwX+0wy5k0c3svXkCP YZacq8EGZXApkt4QnkpnQy2+NQFUpV/Qq1vHKA30xWwzfFsaU0gXjIPKPpTnLZonApTy +wCkgJ5pe8S77ivn0vzc90m6imCnxr5/71Lh5lvXLx85q/Bz6cPuCdaqsZjnvLSDaEl5 gzBiNt3CR1oqVqcELpWIwZrMZTp5JtaIlPZVQ2ZJyYW56xqE7Ieoakcp45H67LbbDyPc 5dQwmwtyNSnzMLg12eW9izVTriYJCdE3tf1THGePr3JLMOfzSriqTiOAVA2SG+F/NAqg gLqw== X-Forwarded-Encrypted: i=1; AFNElJ8JouVX7syUK9knDLhHvdJBNEn05nfgAQx5obSy4/yTQh1lk3vabmVsO9dYqb4CuP0704sikMinX1W2+Po=@vger.kernel.org X-Gm-Message-State: AOJu0YxVRykvvoPuA5J3QxVXch4FmSXKWTxC51EujhyO+iVqa4FxnCH4 UoSfOPgqtppmfZhBN56GD084vuo9v97DjzporNXLNzpGNL2SJ88IcmjX X-Gm-Gg: AeBDietosqTZRv8go/10gyG0NfHD/+1U+rb2ifkzFKJPbiA8LEnVsQCVgoMlXx87Aws wAmkMWDInXSE+Y34ZhnWYksMYwakGcde/8I+QL/oGgRCNOZXeRTJQn15yqc40yhLn46tJ2+sXGr v/Eq9adrUhsnqnl0RmxtWW1XNrvdB1UFmCl68HNoNq4nUpZQk5L8havPTC2iQUzFH3t5qXZd13+ BtsH7wPfYNYshR/WoSKK1mlsV1NqTqHCi0RUQmlK5epOOZ8Ddf3AxYEfz4eSzbUV/wd5xAm7rGs NNXmavkZOORbKRCctoeK7uk5DeVyQ4wNb+TWxB5wzV2RahOrXDRQTGBXNxXRFbGBX0XN6PcIyS0 YFtXTCELGZDRlLjHZdlAKyDPciQVSGjCEh5lFj9OvnkmFz4GOizaBu0UPAKyZE3TRcEuRe9ONRS YI1JFvx0r88ozWoXACfKyvMrbgM3IYcIESPiMBv5oFkXZFSlCbxW9z9czxSwa9KelZdb0iXxl7I toyoOkeNJy/H7O2 X-Received: by 2002:a05:6a00:8b0f:b0:82f:c1b4:8ba2 with SMTP id d2e1a72fcca58-82fc1b4931emr20643060b3a.47.1777292928001; Mon, 27 Apr 2026 05:28:48 -0700 (PDT) Received: from li-1a3e774c-28e4-11b2-a85c-acc9f2883e29.ibm.com ([129.41.58.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8e9f7735sm32733466b3a.21.2026.04.27.05.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 05:28:47 -0700 (PDT) From: "Mukesh Kumar Chaurasiya (IBM)" To: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com, dvyukov@google.com, vincenzo.frascino@arm.com, oleg@redhat.com, kees@kernel.org, luto@amacapital.net, wad@chromium.org, mchauras@linux.ibm.com, sshegde@linux.ibm.com, thuth@redhat.com, ruanjinjie@huawei.com, akpm@linux-foundation.org, macro@orcam.me.uk, ldv@strace.io, charlie@rivosinc.com, deller@gmx.de, kevin.brodsky@arm.com, ritesh.list@gmail.com, yeoreum.yun@arm.com, agordeev@linux.ibm.com, segher@kernel.crashing.org, mark.rutland@arm.com, ryan.roberts@arm.com, pmladek@suse.com, feng.tang@linux.alibaba.com, peterz@infradead.org, kan.liang@linux.intel.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Cc: Samir M , David Gow , Venkat Rao Bagalkote Subject: [PATCH v5 4/8] powerpc: Introduce syscall exit arch functions Date: Mon, 27 Apr 2026 17:57:38 +0530 Message-ID: <20260427122742.210074-5-mkchauras@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427122742.210074-1-mkchauras@gmail.com> References: <20260427122742.210074-1-mkchauras@gmail.com> 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: Mukesh Kumar Chaurasiya Add PowerPC-specific implementations of the generic syscall exit hooks used by the generic entry/exit framework: - arch_exit_to_user_mode_work_prepare() - arch_exit_to_user_mode_work() These helpers handle user state restoration when returning from the kernel to userspace, including FPU/VMX/VSX state, transactional memory, KUAP restore, and per-CPU accounting. Additionally, move check_return_regs_valid() from interrupt.c to interrupt.h so it can be shared by the new entry/exit logic. No functional change is intended with this patch. Signed-off-by: Mukesh Kumar Chaurasiya Tested-by: Samir M Tested-by: David Gow Tested-by: Venkat Rao Bagalkote Reviewed-by: Shrikanth Hegde --- arch/powerpc/include/asm/entry-common.h | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/arch/powerpc/include/asm/entry-common.h b/arch/powerpc/include/asm/entry-common.h index 837a7e020e82..ff0625e04778 100644 --- a/arch/powerpc/include/asm/entry-common.h +++ b/arch/powerpc/include/asm/entry-common.h @@ -6,6 +6,7 @@ #include #include #include +#include #include static __always_inline void booke_load_dbcr0(void) @@ -123,4 +124,52 @@ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) #define arch_enter_from_user_mode arch_enter_from_user_mode +static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs, + unsigned long ti_work) +{ + unsigned long mathflags; + + if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) { + if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) && + unlikely((ti_work & _TIF_RESTORE_TM))) { + restore_tm_state(regs); + } else { + mathflags = MSR_FP; + + if (cpu_has_feature(CPU_FTR_VSX)) + mathflags |= MSR_VEC | MSR_VSX; + else if (cpu_has_feature(CPU_FTR_ALTIVEC)) + mathflags |= MSR_VEC; + + /* + * If userspace MSR has all available FP bits set, + * then they are live and no need to restore. If not, + * it means the regs were given up and restore_math + * may decide to restore them (to avoid taking an FP + * fault). + */ + if ((regs->msr & mathflags) != mathflags) + restore_math(regs); + } + } + + check_return_regs_valid(regs); +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + local_paca->tm_scratch = regs->msr; +#endif + /* Restore user access locks last */ + kuap_user_restore(regs); +} + +#define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare + +static __always_inline void arch_exit_to_user_mode(void) +{ + booke_load_dbcr0(); + + account_cpu_user_exit(); +} + +#define arch_exit_to_user_mode arch_exit_to_user_mode + #endif /* _ASM_PPC_ENTRY_COMMON_H */ -- 2.53.0