From nobody Sat Oct 11 04:17:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 660F52E610C; Wed, 11 Jun 2025 11:28:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749641321; cv=none; b=K1aDIWlsRc4t9V4GmFO1wrd18NgSCBHRVe8ieBQ24csnAopVpMwUROJuD0HVWCn/A5XYYdG6e2CFTkfwJGZEmvlBV+sfdd4/xord1JBsiGcU0Ir53PZg5vddh9zrhIb7VekZzsIpql8ceVGR/aw9Mm/LbH9aq9r3wLHlMWL+Qv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749641321; c=relaxed/simple; bh=T6q2yFdgakZEOZU9u/ytjbTNL39PdbxoVInLilVt3Ic=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O540z5O6Dt6+kydF8CaoNWEVsYJfjWO3tskybkY3mLDn5szW33YI8wdmuzgLRqiCT2PIRJ0ELVxqh10QDXWiL3nChCWMJk49At4D1CyGAQKNgHDRJ7LevPFIBV7iFf6Q7CrZkXziSRm/uXD6ycZo9WRo2D1JicsYH6q2ha2t8RI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MAuQdRZ4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZGEvyC0y; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MAuQdRZ4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZGEvyC0y" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749641313; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zDlH5v3YZBlYQycy/xaWrBQqMKOpqx8ipedaJ9Lxiv0=; b=MAuQdRZ4ySpgmDxn4Nbu4Bo0PmR+n5zbw7gzAz3EikdcOMy0sR+YHgTbKIVRpO+e15N0PP 7edbzU29I46glFDKx0OYXVtwPzskcCLTHlgEokGN+Sk36Pbnzu2di2Evjzyn2rj/CLdzQ3 R3oST2pLL4bo7mOODqf8Hvt0zHxEQw8ocsa5TuXIFKDQMIs5AmC3MxYcBtjqwIXd39c0i3 FRqzJBUHqSUfPf19V+/oOf9FuaboHz92TJSM/Sg86Q4lWH+eJa9Fwghe5nE+LnKFs41v7B HVcmSlRtp7rDOq1MtkLah5lHsXApzHOkdWtRITaWOXhdk9cnR64PeSCwQI7qng== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749641313; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zDlH5v3YZBlYQycy/xaWrBQqMKOpqx8ipedaJ9Lxiv0=; b=ZGEvyC0yhbww7Vhljaf2eg4e3eDPYnNXVNZcP0d0nDSYJwx5H6PSyWELizEJmeYtn5hmXy L1clTV7xnmQUdaBA== Date: Wed, 11 Jun 2025 13:28:26 +0200 Subject: [PATCH v4 1/2] MIPS: Don't crash in stack_top() for tasks without ABI or vDSO 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-kunit-mips-v4-1-1d8997fb2ae4@linutronix.de> References: <20250611-kunit-mips-v4-0-1d8997fb2ae4@linutronix.de> In-Reply-To: <20250611-kunit-mips-v4-0-1d8997fb2ae4@linutronix.de> To: Thomas Bogendoerfer , Brendan Higgins , David Gow , Rae Moar , Huacai Chen Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749641311; l=2007; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=T6q2yFdgakZEOZU9u/ytjbTNL39PdbxoVInLilVt3Ic=; b=8tsInK9oDBoh5sQZKdthSd6ffDG12OWMcob31jETTgzZUtW6tOAyKacr9caidH41w02DFwLXi Tlv8gDhZZMnCgeSE1JUKcghO3heyvj1W0cEXn2yBfxKk4gYOY3vjg1U X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Not all tasks have an ABI associated or vDSO mapped, for example kthreads never do. If such a task ever ends up calling stack_top(), it will derefence the NULL ABI pointer and crash. This can for example happen when using kunit: mips_stack_top+0x28/0xc0 arch_pick_mmap_layout+0x190/0x220 kunit_vm_mmap_init+0xf8/0x138 __kunit_add_resource+0x40/0xa8 kunit_vm_mmap+0x88/0xd8 usercopy_test_init+0xb8/0x240 kunit_try_run_case+0x5c/0x1a8 kunit_generic_run_threadfn_adapter+0x28/0x50 kthread+0x118/0x240 ret_from_kernel_thread+0x14/0x1c Only dereference the ABI point if it is set. The GIC page is also included as it is specific to the vDSO. Also move the randomization adjustment into the same conditional. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow Reviewed-by: Huacai Chen --- arch/mips/kernel/process.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index b630604c577f9ff3f2493b0f254363e499c8318c..02aa6a04a21da437909eeac4f14= 9155cc298f5b5 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -690,18 +690,20 @@ unsigned long mips_stack_top(void) } =20 /* Space for the VDSO, data page & GIC user page */ - top -=3D PAGE_ALIGN(current->thread.abi->vdso->size); - top -=3D PAGE_SIZE; - top -=3D mips_gic_present() ? PAGE_SIZE : 0; + if (current->thread.abi) { + top -=3D PAGE_ALIGN(current->thread.abi->vdso->size); + top -=3D PAGE_SIZE; + top -=3D mips_gic_present() ? PAGE_SIZE : 0; + + /* Space to randomize the VDSO base */ + if (current->flags & PF_RANDOMIZE) + top -=3D VDSO_RANDOMIZE_SIZE; + } =20 /* Space for cache colour alignment */ if (cpu_has_dc_aliases) top -=3D shm_align_mask + 1; =20 - /* Space to randomize the VDSO base */ - if (current->flags & PF_RANDOMIZE) - top -=3D VDSO_RANDOMIZE_SIZE; - return top; } =20 --=20 2.49.0 From nobody Sat Oct 11 04:17:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 A35CC2609C7; Wed, 11 Jun 2025 11:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749641324; cv=none; b=d8QCyt9Q1jVjd/xqwba/mnmOOpqVzByDagQzyP6YBVPQAwLhSyzthxNUebzuhh/IBuBw9WpN9N0F4R8EViyXkmaKPEeW8997L+mpI1ZX1v4msoyXqqjAm/801SUQ+Qz0NNgp5JHFxy8erktuXDLbE0o247t1hDbs9Fm/BE6Gk6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749641324; c=relaxed/simple; bh=viIorSaJJPgs+NDzJ8EdjNfVLhfYMDHCVwxLX34JTvA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mEJbWyzgebLd2VnPSLdiONJUbx6uQ1gzxkEYo6OlwDgpi/cYjsCgpixx+lVm/8/Ysyvq4WtfrkLg6GoGycaYXqcVavNqMt+UXHk5iW75w6P2icIbZ5bStgDPAocGT4Exm4F1Y9fTl5Odut3HC6hfeYx5LiCyN8+Zy7ZReh7W7xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=U1iGUX13; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=drWr+xb4; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="U1iGUX13"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="drWr+xb4" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749641314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G2ROgs5PeJeUCZVBna+9TCUSWt8qvswhzd0dmf697KM=; b=U1iGUX13cpj5rb4tZHtxwQIdKrPToCglmHji/2BCvOU9820+/uXZD4RZJ7cOUtqKNxeCr2 U3I6K31iK8cAj87thYRkhgHefg6hDDyTk47xDkOLFKe/E7LXpjNepjssgP7Y1ufOQpFZw+ d1FUFOMAikdZu9A7Ee9nEUKFybM5knN+NtkzNVlhQgw2ChwgFuAvDJJT7TmjP4hsCgWuwL iC2UwwCR9aUgVF5lR077sIOXvZYHlgBTkJFEKzMEmAzKDdzCEMk2ialIosDKks+agYGzyv a63oqfwO/NrFYN3WUr4bxlZoYLC3b+wyPKAZ8gTABQ7lIcTr1OJzdd+N0EG/dA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749641314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G2ROgs5PeJeUCZVBna+9TCUSWt8qvswhzd0dmf697KM=; b=drWr+xb44jo1z7KwPDF+VUamXpkpOr6tOb4+QqsDyn+YuT3w1vA+UHSO1DcKo2yrYtcG87 A4OVXPB1wT3DjLAw== Date: Wed, 11 Jun 2025 13:28:27 +0200 Subject: [PATCH v4 2/2] kunit: qemu_configs: Add MIPS configurations 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-kunit-mips-v4-2-1d8997fb2ae4@linutronix.de> References: <20250611-kunit-mips-v4-0-1d8997fb2ae4@linutronix.de> In-Reply-To: <20250611-kunit-mips-v4-0-1d8997fb2ae4@linutronix.de> To: Thomas Bogendoerfer , Brendan Higgins , David Gow , Rae Moar , Huacai Chen Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749641311; l=4178; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=viIorSaJJPgs+NDzJ8EdjNfVLhfYMDHCVwxLX34JTvA=; b=CyWZQdegRaeKI/KmyBSeKdZ6JBHl/BV57XwyX3h4qiz8VOrqVu1kWG6eKMlwqCWTA6fX4XTZW z/gydFTkODcCToYiF8lxfkGjJG/DKYQckJA0ndGE5PKKT9yuLcMKQ1f X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Add basic support to run various MIPS variants via kunit_tool using the virtualized malta platform. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- tools/testing/kunit/qemu_configs/mips.py | 18 ++++++++++++++++++ tools/testing/kunit/qemu_configs/mips64.py | 19 +++++++++++++++++++ tools/testing/kunit/qemu_configs/mips64el.py | 19 +++++++++++++++++++ tools/testing/kunit/qemu_configs/mipsel.py | 18 ++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/tools/testing/kunit/qemu_configs/mips.py b/tools/testing/kunit= /qemu_configs/mips.py new file mode 100644 index 0000000000000000000000000000000000000000..8899ac157b30bd2ee847eacd5b9= 0fe6ad4e5fb04 --- /dev/null +++ b/tools/testing/kunit/qemu_configs/mips.py @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 + +from ..qemu_config import QemuArchParams + +QEMU_ARCH =3D QemuArchParams(linux_arch=3D'mips', + kconfig=3D''' +CONFIG_32BIT=3Dy +CONFIG_CPU_BIG_ENDIAN=3Dy +CONFIG_MIPS_MALTA=3Dy +CONFIG_SERIAL_8250=3Dy +CONFIG_SERIAL_8250_CONSOLE=3Dy +CONFIG_POWER_RESET=3Dy +CONFIG_POWER_RESET_SYSCON=3Dy +''', + qemu_arch=3D'mips', + kernel_path=3D'vmlinuz', + kernel_command_line=3D'console=3DttyS0', + extra_qemu_params=3D['-M', 'malta']) diff --git a/tools/testing/kunit/qemu_configs/mips64.py b/tools/testing/kun= it/qemu_configs/mips64.py new file mode 100644 index 0000000000000000000000000000000000000000..1478aed05b94da4914f34c6a8af= fdcfe34eb88ea --- /dev/null +++ b/tools/testing/kunit/qemu_configs/mips64.py @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 + +from ..qemu_config import QemuArchParams + +QEMU_ARCH =3D QemuArchParams(linux_arch=3D'mips', + kconfig=3D''' +CONFIG_CPU_MIPS64_R2=3Dy +CONFIG_64BIT=3Dy +CONFIG_CPU_BIG_ENDIAN=3Dy +CONFIG_MIPS_MALTA=3Dy +CONFIG_SERIAL_8250=3Dy +CONFIG_SERIAL_8250_CONSOLE=3Dy +CONFIG_POWER_RESET=3Dy +CONFIG_POWER_RESET_SYSCON=3Dy +''', + qemu_arch=3D'mips64', + kernel_path=3D'vmlinuz', + kernel_command_line=3D'console=3DttyS0', + extra_qemu_params=3D['-M', 'malta', '-cpu', '5K= Ec']) diff --git a/tools/testing/kunit/qemu_configs/mips64el.py b/tools/testing/k= unit/qemu_configs/mips64el.py new file mode 100644 index 0000000000000000000000000000000000000000..300c711d7a82500b2ebcb4cf146= 7b6f72b5c17aa --- /dev/null +++ b/tools/testing/kunit/qemu_configs/mips64el.py @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 + +from ..qemu_config import QemuArchParams + +QEMU_ARCH =3D QemuArchParams(linux_arch=3D'mips', + kconfig=3D''' +CONFIG_CPU_MIPS64_R2=3Dy +CONFIG_64BIT=3Dy +CONFIG_CPU_LITTLE_ENDIAN=3Dy +CONFIG_MIPS_MALTA=3Dy +CONFIG_SERIAL_8250=3Dy +CONFIG_SERIAL_8250_CONSOLE=3Dy +CONFIG_POWER_RESET=3Dy +CONFIG_POWER_RESET_SYSCON=3Dy +''', + qemu_arch=3D'mips64el', + kernel_path=3D'vmlinuz', + kernel_command_line=3D'console=3DttyS0', + extra_qemu_params=3D['-M', 'malta', '-cpu', '5K= Ec']) diff --git a/tools/testing/kunit/qemu_configs/mipsel.py b/tools/testing/kun= it/qemu_configs/mipsel.py new file mode 100644 index 0000000000000000000000000000000000000000..3d3543315b45776d0e77fb5c00c= 8c0a89eafdffd --- /dev/null +++ b/tools/testing/kunit/qemu_configs/mipsel.py @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 + +from ..qemu_config import QemuArchParams + +QEMU_ARCH =3D QemuArchParams(linux_arch=3D'mips', + kconfig=3D''' +CONFIG_32BIT=3Dy +CONFIG_CPU_LITTLE_ENDIAN=3Dy +CONFIG_MIPS_MALTA=3Dy +CONFIG_SERIAL_8250=3Dy +CONFIG_SERIAL_8250_CONSOLE=3Dy +CONFIG_POWER_RESET=3Dy +CONFIG_POWER_RESET_SYSCON=3Dy +''', + qemu_arch=3D'mipsel', + kernel_path=3D'vmlinuz', + kernel_command_line=3D'console=3DttyS0', + extra_qemu_params=3D['-M', 'malta']) --=20 2.49.0