Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4201707pxf; Tue, 30 Mar 2021 01:41:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXhKPBdcGlOQ9g9KAwgJUoZcYuJT/o1lgayQWF8YNyBz37Lu3tcz86f5vtCqzXQ5bldA9z X-Received: by 2002:a17:906:6a06:: with SMTP id o6mr31655358ejr.306.1617093676841; Tue, 30 Mar 2021 01:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617093676; cv=none; d=google.com; s=arc-20160816; b=wPdSDuHwFK54z5a+BVo63NSMSayGYabPuai2QBPUDq904NDH7S5v7YmL5qNI8AD4jX TBGAJA3oOY5HbLv8D1ubt3b+3O9hV7yWM23qDhcFMrDoeec9un+TnENM9btLTWMJxKff +0TpF6H9TKNHAwD+/JYmqAfw1c/XPXNQX946//fKEllcCmoFFG26fIL27SqHqH3QBjNg 5kvemD9AxDpnY5rupDReK8S89d4Nn1HXB7/oYd6AZTNOI+2lE4KmOYIu1OT0+XQnNwnu S/SrMF/wWXEmRIAq5lDb1lAAcsDwuh2AJo6TOTkD4xcE9pc/+n4lA2WXt+VGKBn/yYHJ n+8w== 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=eCcrISktlAw+3fQ6MCDB0YjZKBw+luCOtXLpGcTzW6E=; b=ZZT1kXPaa02TLcMm0TVUVZMzugTB3R+0dK+wPevdIm7nOMvMijkqYwrgukiFcIQq/w frnAFnEqCykOTx/p0qgmPU7t+f21tcdDH/L4AiXQoyM0aoCQcoEwVdC2g5/j1mqlWKjm gyOCi9LsHJJAHny7ktuofgG13sN9eXHwDkRBoK0Xb90bNWp6A3SJrlZ/NAV/LYhTNoyt kNCQYWp+4Fha0vKWhwsNgaArBtgZv1W/VL1si7/0HNW+o79W0MKPWxjoF6ZprvcnydmJ VEvxtHQPWYTSSlOkqCD8uH2kK8IYcNxW8fwnshn74R2ldDEE/rgntFnAbFaq/E53bsBv 1ZAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Mx6QIAbg; 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 c17si13545210ede.535.2021.03.30.01.40.53; Tue, 30 Mar 2021 01:41:16 -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=Mx6QIAbg; 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 S230248AbhC3Ih6 (ORCPT + 99 others); Tue, 30 Mar 2021 04:37:58 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54728 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbhC3Ihh (ORCPT ); Tue, 30 Mar 2021 04:37:37 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 12U8ZEfw168269; Tue, 30 Mar 2021 04:37:33 -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=eCcrISktlAw+3fQ6MCDB0YjZKBw+luCOtXLpGcTzW6E=; b=Mx6QIAbgPVZJuqe4x26I4xhtz4IJFm3Mftfv6w65siWW0SR/iJE44kEonVGlKKP2SbTZ +SuYDkW4rpOAy5M7NyPbHRQA5SjpzyFyPvyxqVrAZJWq/BvAZgJExzO+y0VSwvqGipKx +rTwqOKCUXk+EyG/rU0jPyvIrhWFelshAfDjviO1lgMBqyg0vrdX3bkdVI+VnU2NWgJ4 ApYXl35P6OsuvOVylpY8pAPV87lyBD389dniMuRleFsELeuY6e9AO3X8u3s90i73wtrR 0uT0VcS3SwUC7aAGhKt6MWMjhBPyOM2nMN85xcqtOAV8RhdHiblbKtkPPXwSHKQJhzu/ zw== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 37jhrv1dp8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Mar 2021 04:37:32 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 12U8WO28009711; Tue, 30 Mar 2021 08:37:30 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06ams.nl.ibm.com with ESMTP id 37huyhahkg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Mar 2021 08:37:30 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 12U8b8VZ31261098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Mar 2021 08:37:08 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9887DAE055; Tue, 30 Mar 2021 08:37:27 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5205DAE04D; Tue, 30 Mar 2021 08:37:27 +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:37:27 +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:37:27 +0200 In-Reply-To: (Sven Schnelle's message of "Tue, 30 Mar 2021 10:13:49 +0200") 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: dcgSjmEF5TgIC6wyg5NYKFCZf0398Gsq X-Proofpoint-ORIG-GUID: dcgSjmEF5TgIC6wyg5NYKFCZf0398Gsq 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 mlxlogscore=999 mlxscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 spamscore=0 suspectscore=0 malwarescore=0 clxscore=1015 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103300060 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sven Schnelle writes: > 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. Thinking about this again i guess this idea won't work because the exit loop might have scheduled the old process away already...