From patchwork Thu Feb 1 17:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 85161 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7BA73857C55 for ; Thu, 1 Feb 2024 17:41:40 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id 7643838582A7 for ; Thu, 1 Feb 2024 17:41:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7643838582A7 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7643838582A7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::533 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706809273; cv=none; b=tV1vR4nt6o1Kwao+V4DJZ+HsH279iAaMcHnwWhxF7Gh3j0DrUnmTXZy1lUsY8ngC3GaPRbDOUhz2Qj6vobr/1pthDjFL81QswYY0dBpG+YEQ/ZeQea3fzO4zoGb+uOE6RuBrsWWd4CbisVGplKK2ZzLrLqSVIDub+miU2mFLb2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706809273; c=relaxed/simple; bh=y+tuMEFvcCglfZuBbVeWvKp2vhmHGikIywMTafmotLE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=EF98XuPcTtqe9lNP7fdqy3HE2CjS0qgCPqgZ/ot79eex3uBjha1jfX5TTqEwua/XpvpkXN+80+pCjlDtfCeflqRRo+5KTh6eSWBhhSzH//vVJ1doSu10l4AuJtMK41pv7eYcDA/p9ulby0pLw8snZQluh2a5SyOAD6GpoPYFVK0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5cfd95130c6so828905a12.1 for ; Thu, 01 Feb 2024 09:41:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706809270; x=1707414070; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dZY5v8A65dzA/NYxcV1XdMFNnRkoG+K0SnU+ncUMQCI=; b=vgMNQTjVJdoPK0YTy1IDr0cWWV6UQ8Nu5EYi01GZteFc7z0UhXy9LuYcWQstBLhY4L PMkw6PFJyAFKeRL3rfFtUzrlCOIvic/A4yJOy5ox2pUrRmfr4XDr5hXKfEbafdtf40Be yPHsn5MczzqapRusRXdobnYf6723qmoqUXOzipqB8nS8N+84QppY2j63ww9W2XHoly74 D8gzuGTYX8CADtvft61k9UVoZJE84AqsqR4zNiOHiYriTaIjuBk1woL5zdzBIYXcl/Vg AZZTDO70D2f99H74eeXfjIK3APZiL/0rJq5K7YEvaLjCmfyUVXPan4cXx9z3+r+/7JfW 1R7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706809270; x=1707414070; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dZY5v8A65dzA/NYxcV1XdMFNnRkoG+K0SnU+ncUMQCI=; b=A2+yWM8F76ne8ER937ky2M/0+4TfgCUiltGeYC90rSIAYZ+wpCj6zZM+ts/3ytypHl ouBcl9eKpVUQstBW+teGcmt0kmmB3slD6tbi6u7AHRMbcHC7pjH9R/1nVO0CWJJF8/GV Tnzndp30ARnbneaXVwGl8F01xcpg9lo10c8rrepDhRhAc3aec/QVvwZVnU71gJDOcNLV GfqDq8Of5CNCrv+8ftFByVb76MclKc7keh0bUPYRSDFSVyvj3M7dI9OEGP7MXCiH7ePY ippO8nNTS4qMPaW6N9lmE/drzFu9ez/ISM0aVSLTkgeC2PoiqAVhsyOGCgWuONi2bmIK dE6w== X-Gm-Message-State: AOJu0YyU+M0t4hpYUea1meNO/UuVgMoacPX+pTsd9FIWSYBRJYet9z4b 2137h1aVh6lKiZOedKxG6iTbio4Zm8vC1U7T2VsoOHpDIG5X3aoEoU62Z9criGcbdQoZLLLemBs i X-Google-Smtp-Source: AGHT+IFJW803uY65Hk3aS2MGxI2txU2n11LSu0Yur8uXkiI/jYTrFW/Ar+SqjU5PJOuHeTmrSYzbwA== X-Received: by 2002:aa7:91ca:0:b0:6de:1b57:ca8c with SMTP id z10-20020aa791ca000000b006de1b57ca8cmr5539028pfa.23.1706809269816; Thu, 01 Feb 2024 09:41:09 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:574b:9f0f:d31f:94d6:a7fb]) by smtp.gmail.com with ESMTPSA id w20-20020a056a0014d400b006dde0969ce3sm11516pfu.66.2024.02.01.09.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:41:09 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Khem Raj Subject: [PATCH] mips: FIx clone3 implementation (BZ 31325) Date: Thu, 1 Feb 2024 14:41:03 -0300 Message-Id: <20240201174103.798138-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org For o32 we need to setup a minimal stack frame to allow cprestore on __thread_start_clone3 (which instruct the linker to save the gp for PIC). Also, there is no guarantee by kABI that $8 will be preserved after syscall execution, so we need to save it on the provided stack. Checked on mipsel-linux-gnu. Reported-by: Khem Raj Tested-by: Khem Raj --- sysdeps/unix/sysv/linux/mips/clone3.S | 32 ++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/sysdeps/unix/sysv/linux/mips/clone3.S b/sysdeps/unix/sysv/linux/mips/clone3.S index e9fec2fa47..481b8ae963 100644 --- a/sysdeps/unix/sysv/linux/mips/clone3.S +++ b/sysdeps/unix/sysv/linux/mips/clone3.S @@ -37,11 +37,6 @@ .text .set nomips16 -#if _MIPS_SIM == _ABIO32 -# define EXTRA_LOCALS 1 -#else -# define EXTRA_LOCALS 0 -#endif #define FRAMESZ ((NARGSAVE*SZREG)+ALSZ)&ALMASK GPOFF= FRAMESZ-(1*SZREG) NESTED(__clone3, SZREG, sp) @@ -68,8 +63,31 @@ NESTED(__clone3, SZREG, sp) beqz a0, L(error) /* No NULL cl_args pointer. */ beqz a2, L(error) /* No NULL function pointer. */ +#if _MIPS_SIM == _ABIO32 + /* Both stack and stack_size on clone_args are defined as uint64_t, and + there is no need to handle values larger than to 32 bits for o32. */ +# if __BYTE_ORDER == __BIG_ENDIAN +# define CL_STACKPOINTER_OFFSET 44 +# define CL_STACKSIZE_OFFSET 52 +# else +# define CL_STACKPOINTER_OFFSET 40 +# define CL_STACKSIZE_OFFSET 48 +# endif + + /* For o32 we need to setup a minimal stack frame to allow cprestore + on __thread_start_clone3. Also there is no guarantee by kABI that + $8 will be preserved after syscall execution (so we need to save it + on the provided stack). */ + lw t0, CL_STACKPOINTER_OFFSET(a0) /* Load the stack pointer. */ + lw t1, CL_STACKSIZE_OFFSET(a0) /* Load the stack_size. */ + addiu t1, -32 /* Update the stack size. */ + addu t2, t1, t0 /* Calculate the thread stack. */ + sw a3, 0(t2) /* Save argument pointer. */ + sw t1, CL_STACKSIZE_OFFSET(a0) /* Save the new stack size. */ +#else move $8, a3 /* a3 is set to 0/1 for syscall success/error while a4/$8 is returned unmodified. */ +#endif /* Do the system call, the kernel expects: v0: system call number @@ -125,7 +143,11 @@ L(thread_start_clone3): /* Restore the arg for user's function. */ move t9, a2 /* Function pointer. */ +#if _MIPS_SIM == _ABIO32 + PTR_L a0, 0(sp) +#else move a0, $8 /* Argument pointer. */ +#endif /* Call the user's function. */ jal t9