Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 195313596E for ; Tue, 14 Jan 2025 17:04:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.107.17.57 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736874243; cv=none; b=mJPxyPvpRRgaqxY3H1aW0n/23KAdhJqGeyyOWfgLmpIO37SGyP4Zsk8dlDTqzkNu02R/1Jxa1A0k15/F2bw3FjxShA4kmcqPT1ste2ruIsVKEi3fheKCUJ2pUdm2nedtXOXfnEnQyLEM0D5Z8j/MHFt1lZotSEfgJ9ayw6JxAbY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736874243; c=relaxed/simple; bh=Rfgiq6/UryIhZSCWUbu/PoI5BvYzr2e2ETtvwXy7rlk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZKU8mLwId0senzGUrv9cP5srShiejn+5Y+RHLbRJmdMZv7RXE1kusyLMMmLGtCoPolZ+XEN9Hg3c0aqOof3DI05/7utL6A+H9Jhr0nT/SisYkPSleNmDZ+OEra4pKHhWLypmlBbR/B3vLa6L0SJnv3Tg1Qd5oGaNyltlWfPwF+Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strace.io; spf=pass smtp.mailfrom=altlinux.org; arc=none smtp.client-ip=194.107.17.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strace.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altlinux.org Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id A741F72C8CC; Tue, 14 Jan 2025 20:04:00 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 95EF47CCB3A; Tue, 14 Jan 2025 19:04:00 +0200 (IST) Date: Tue, 14 Jan 2025 19:04:00 +0200 From: "Dmitry V. Levin" To: Christophe Leroy Cc: Alexey Gladkov , Oleg Nesterov , Michael Ellerman , Eugene Syromyatnikov , Mike Frysinger , Renzo Davoli , Davide Berardi , strace-devel@lists.strace.io, Madhavan Srinivasan , Nicholas Piggin , Naveen N Rao , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/7] powerpc: properly negate error in syscall_set_return_value() Message-ID: <20250114170400.GB11820@strace.io> References: <20250113171054.GA589@strace.io> <6558110c-c2cb-4aa3-9472-b3496f71ebb8@csgroup.eu> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6558110c-c2cb-4aa3-9472-b3496f71ebb8@csgroup.eu> On Mon, Jan 13, 2025 at 06:34:44PM +0100, Christophe Leroy wrote: > Le 13/01/2025 à 18:10, Dmitry V. Levin a écrit : > > Bring syscall_set_return_value() in sync with syscall_get_error(), > > and let upcoming ptrace/set_syscall_info selftest pass on powerpc. > > > > This reverts commit 1b1a3702a65c ("powerpc: Don't negate error in > > syscall_set_return_value()"). > > There is a clear detailed explanation in that commit of why it needs to > be done. > > If you think that commit is wrong you have to explain why with at least > the same level of details. OK, please have a look whether this explanation is clear and detailed enough: ======= powerpc: properly negate error in syscall_set_return_value() When syscall_set_return_value() is used to set an error code, the caller specifies it as a negative value in -ERRORCODE form. In !trap_is_scv case the error code is traditionally stored as follows: gpr[3] contains a positive ERRORCODE, and ccr has 0x10000000 flag set. Here are a few examples to illustrate this convention. The first one is from syscall_get_error(): /* * If the system call failed, * regs->gpr[3] contains a positive ERRORCODE. */ return (regs->ccr & 0x10000000UL) ? -regs->gpr[3] : 0; The second example is from regs_return_value(): if (is_syscall_success(regs)) return regs->gpr[3]; else return -regs->gpr[3]; The third example is from check_syscall_restart(): regs->result = -EINTR; regs->gpr[3] = EINTR; regs->ccr |= 0x10000000; Compared with these examples, the failure of syscall_set_return_value() to assign a positive ERRORCODE into regs->gpr[3] is clearly visible: /* * In the general case it's not obvious that we must deal with * CCR here, as the syscall exit path will also do that for us. * However there are some places, eg. the signal code, which * check ccr to decide if the value in r3 is actually an error. */ if (error) { regs->ccr |= 0x10000000L; regs->gpr[3] = error; } else { regs->ccr &= ~0x10000000L; regs->gpr[3] = val; } This fix brings syscall_set_return_value() in sync with syscall_get_error() and lets upcoming ptrace/set_syscall_info selftest pass on powerpc. Fixes: 1b1a3702a65c ("powerpc: Don't negate error in syscall_set_return_value()"). ======= -- ldv