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: 768866 Delivered-To: patch@linaro.org Received: by 2002:adf:9bca:0:b0:33a:e5bd:fedd with SMTP id e10csp516419wrc; Thu, 1 Feb 2024 09:41:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhbvgSyxk6pzr2WnVxY2i55bDtAuozZEDQQ6JEmzEU4+1eDPXF45h7LRZLml0i4XmBAc0J X-Received: by 2002:a05:6214:2aa4:b0:68c:46ab:c8d6 with SMTP id js4-20020a0562142aa400b0068c46abc8d6mr5796114qvb.38.1706809290672; Thu, 01 Feb 2024 09:41:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706809290; cv=pass; d=google.com; s=arc-20160816; b=OvCtzkVOAPFNVWQmaAUzKX0m/z+0hl/QI3HbwzN+8IdVQi8L2PElA61Q12gSQM6hos TdwFd9SCCNsp+6ePAxbdoaSTAiR8SYceODAHRD4je6ExrN9aHuDQ7g+ro+ZNprBG5VWZ ao/K/gzxOiC1HLFXlBb8UIlXbxMl129pV4U4mdf1UBGHGgauPjR9bfvn88MSprrCEJI2 7QTisk08LPRLXmGXyHJJv/5BYIiRJ2k5XL7r+yxeRjlFxULv7QgAmAU5nEFa7rv2ZgmE baTpwAluGlPu+PefSampgMWnH6jTMlYNsf3Ovr+q35nRiwRnoSnM4xd5WAyQVUJ74yt0 Eh7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=dZY5v8A65dzA/NYxcV1XdMFNnRkoG+K0SnU+ncUMQCI=; fh=PPnOu0GRaFb98i29CHNjlQJdNxgpkPYxRtjP3kAs7R4=; b=TExfeJI0jh73nVyR0fa3QEVFhCOA8ctFSrzfN/qEUgHU4lIsPcJgLdwYp1FA2I5ItW BMehWN0lOOcwKWCoe74eNEgWWuMHq4SiVv5Fi0S0J0oCoOt6fSfPprXc60rCvE08zK14 YhBOhVhn2NaNvLdJfiySbUUaPtPPLYUiYyqGchOk/k4xMpADTQRJFwbn4+1fBstD7g3+ 0eil581XzSTm+egb6QKPS+FjWd4X5nIfxBDCd26rkX1uIA+dsfchCWg805puZubvi5PF V0Q0rYO8DAX497nQ3herUCA0+Km2t0tQLUE5J39uybEMXrJeSkmRoAGiVxe/lvQHhvoo aO9A==; darn=linaro.org ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vgMNQTjV; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=1; AJvYcCUgSOFbZ0Q1VZZ7FxYfaEErPXC2cWx5rlMS6xmdrfgGYhgGBu3GxGSANz75z4E3DYDp1lejjMa5bs3Uq4cSQy0E Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f5-20020a0562141d2500b0068c433cd6b7si11638522qvd.584.2024.02.01.09.41.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vgMNQTjV; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 508143858030 for ; Thu, 1 Feb 2024 17:41:30 +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-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+patch=linaro.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