Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4188775pxf; Tue, 30 Mar 2021 01:15:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+yil/uEAO/GwDu6svD4CFt5N8A8wWUAPHCQDZCwKKE/fD1Tap6bbb1fzcUARp2lpG6saR X-Received: by 2002:a05:6402:c8:: with SMTP id i8mr32797848edu.57.1617092122104; Tue, 30 Mar 2021 01:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617092122; cv=none; d=google.com; s=arc-20160816; b=OKIdFV3bnFjd71AFUCTUfIagcU/LSlCvRTqDaPcd+S1Uyc05daAvHLwJS5e08VMSTn J45Y/FXM0KNj0uT81xtbA7OxRghI8iahl5lV1CjnM4d8Jc5kRaM3QEawO2rmRWd74uzk +ITR7vtw+qgrTFD76++LajtFj7wVMnQH/ZF/1969mIZnK+YHBt/TzWwjQqOINM04RTy0 CiTRm/MUhETHgX+BxqqyGskp5RN0KHfADXqW44IztZ4D0Xe7xbb60yrLz7GfsLv8A977 FU9oyY6itLwhmZhlRM5I0H+LvawHd9VLco4pqeirmgXnG6fLVG9GFwq+EK3Sk88eKjPk NzEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=Tx0vTlJrzzEHRPOxY5i6He5735ZUbCWKAXaebQPSpZ8=; b=bkFtX0C1OXfqJR7QdxYffstVwR5xY3qhukTPDp07f4wnWQssoF6pVebSZlZQ7rbsJX tYBbwZa5kszU5xG7499NIqHLLSQd8JCEjGfrXcMCxoxLQq6CkIvhvDPyjAwqe3/1ulas cVVoCjD0GgUkoxG1uZInYwFnQBydfKGm3k5Hs9y+Xer4JRqXp7vUpzT19grT8BPcTPHU 8YnL+GaPKCX83pPG9Vnp6XO9kbuPjoyfR0z9Zf8acjzLahLhXTckC+rzaO0OvzMLormH MRyoN7YfHxo8MpSW52e+dWToU88mP0dxfHRUAG/eUYsJyXLALKWlU8HmVx+bsUO5rLTB MnWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=nd5IwqAx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q17si14775145ejj.672.2021.03.30.01.14.59; Tue, 30 Mar 2021 01:15:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=nd5IwqAx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbhC3IOE (ORCPT + 99 others); Tue, 30 Mar 2021 04:14:04 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50704 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231269AbhC3IN7 (ORCPT ); Tue, 30 Mar 2021 04:13:59 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 12U868DR155168; Tue, 30 Mar 2021 04:13:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : references : date : in-reply-to : message-id : content-type : mime-version; s=pp1; bh=Tx0vTlJrzzEHRPOxY5i6He5735ZUbCWKAXaebQPSpZ8=; b=nd5IwqAx8aOlSSlRdze32E1Kwv4GWqUj8mkPweiNQlcHzQD6YDqJmACtWE46AC16wHll gRJ9y+V0qdZ+9D/iUTPzML908TX8c6r4DHO26XPV9gdIlsaRZ2tY4jxP2A47nWeG+qfS uez6ALcA+O3hntZwGPX0BHBufYSGcVgCz/Ef//7XLSWUPpeYgWRN2yEkJqhKbm+6KYQR O5bT52ZIGUbrcmrwgv9lhQMy8tJjzaIuojTXAtSf7yLAyFSp1R8MwwKMXjrn3cYDZLZ0 7BC53XxCXQKwuqjBE99//KZxGaIhTTtrF38Ou15xpI1EKLPXBtywvtyrQ4MPQzg/5saU Hw== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 37jj60stbn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Mar 2021 04:13:54 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 12U8CYxm007647; Tue, 30 Mar 2021 08:13:52 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 37hvb8jged-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Mar 2021 08:13:52 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 12U8Dnbp27132394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Mar 2021 08:13:49 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 96EA7AE053; Tue, 30 Mar 2021 08:13:49 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4EABAAE04D; Tue, 30 Mar 2021 08:13:49 +0000 (GMT) Received: from tuxmaker.linux.ibm.com (unknown [9.152.85.9]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 30 Mar 2021 08:13:49 +0000 (GMT) From: Sven Schnelle To: Andy Lutomirski Cc: Vasily Gorbik , X86 ML , linux-arch , Mark Rutland , LKML , Heiko Carstens , Christian Borntraeger Subject: Re: Is s390's new generic-using syscall code actually correct? References: Date: Tue, 30 Mar 2021 10:13:49 +0200 In-Reply-To: (Andy Lutomirski's message of "Wed, 24 Mar 2021 11:06:54 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YGR-Fnr690GZm7djAbElDBVuN559izJ8 X-Proofpoint-ORIG-GUID: YGR-Fnr690GZm7djAbElDBVuN559izJ8 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-30_02:2021-03-26,2021-03-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103300055 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, Andy Lutomirski writes: > On Wed, Mar 24, 2021 at 10:39 AM Vasily Gorbik wrote: >> >> Hi Andy, >> >> On Sat, Mar 20, 2021 at 08:48:34PM -0700, Andy Lutomirski wrote: >> > Hi all- >> > >> > I'm working on my kentry patchset, and I encountered: >> > >> > commit 56e62a73702836017564eaacd5212e4d0fa1c01d >> > Author: Sven Schnelle >> > Date: Sat Nov 21 11:14:56 2020 +0100 >> > >> > s390: convert to generic entry >> > >> > As part of this work, I was cleaning up the generic syscall helpers, >> > and I encountered the goodies in do_syscall() and __do_syscall(). >> > >> > I'm trying to wrap my head around the current code, and I'm rather confused. >> > >> > 1. syscall_exit_to_user_mode_work() does *all* the exit work, not just >> > the syscall exit work. So a do_syscall() that gets called twice will >> > do the loopy part of the exit work (e.g. signal handling) twice. Is >> > this intentional? If so, why? >> > >> > 2. I don't understand how this PIF_SYSCALL_RESTART thing is supposed >> > to work. Looking at the code in Linus' tree, if a signal is pending >> > and a syscall returns -ERESTARTSYS, the syscall will return back to >> > do_syscall(). The work (as in (1)) gets run, calling do_signal(), >> > which will notice -ERESTARTSYS and set PIF_SYSCALL_RESTART. >> > Presumably it will also push the signal frame onto the stack and aim >> > the return address at the svc instruction mentioned in the commit >> > message from "s390: convert to generic entry". Then __do_syscall() >> > will turn interrupts back on and loop right back into do_syscall(). >> > That seems incorrect. >> > >> > Can you enlighten me? My WIP tree is here: >> > https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/log/?h=x86/kentry >> > >> >> For all the details to that change we'd have to wait for Sven, who is back >> next week. >> >> > Here are my changes to s390, and I don't think they're really correct: >> > >> > >> > https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/diff/arch/s390/kernel/syscall.c?h=x86/kentry&id=58a459922be0fb8e0f17aeaebcb0ac8d0575a62c >> >> Couple of things: syscall_exit_to_user_mode_prepare is static, >> and there is another code path in arch/s390/kernel/traps.c using >> enter_from_user_mode/exit_to_user_mode. >> >> Anyhow I gave your branch a spin and got few new failures on strace test >> suite, in particular on restart_syscall test. I'll try to find time to >> look into details. > > I refreshed the branch, but I confess I haven't compile tested it. :) > > I would guess that the new test case failures are a result of the > buggy syscall restart logic. I think that all of the "restart" cases > except execve() should just be removed. Without my patch, I suspect > that signal delivery with -ERESTARTSYS would create the signal frame, > do an accidental "restarted" syscall that was a no-op, and then > deliver the signal. With my patch, it may simply repeat the original > interrupted signal forever. PIF_SYSCALL_RESTART is set in arch_do_signal_or_restart(), but only if there's no signal handler registered. In that case we don't need a signal frame, so that should be fine. The problem why your branch is not working is that arch_do_signal_or_restart() gets called from exit_to_user_mode_prepare(), and that is after the check whether PIF_SYSCALL_RESTART is set in __do_syscall(). So i'm wondering how to fix that. x86 simply rewinds the pc, so the system call instruction gets re-executed when returning to user space. For s390 that doesn't work, as the s390 svc instruction might have the syscall number encoded. If we would have to restart a system call with restart_systemcall(), we need to change the syscall number to __NR_restart_syscall. As we cannot change the hardcoded system call number, we somehow need to handle that inside of the kernel. So i wonder whether we should implement the PIF_SYSCALL_RESTART check in entry.S after all the return to user space entry code was run but before doing the real swtch back to user space. If PIF_SYSCALL_RESTART is set we would then just jump back to the entry code and pretend we came from user space. That would have the benefit that the entry C code looks the same like other architectures and that amount of code to add in entry.S shouldn't be much. Any thoughts? Regards Sven