Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3138440pxb; Mon, 16 Nov 2020 06:49:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzE41fkYAgpKR/ISR9t6ZES/d9kOd2Zih4BaGXvelik8CegJkl0kPbunIwSQt2IeZegRpyv X-Received: by 2002:a17:906:17d1:: with SMTP id u17mr14333443eje.229.1605538156418; Mon, 16 Nov 2020 06:49:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605538156; cv=none; d=google.com; s=arc-20160816; b=NhIDizG1xjZ5AV1u4e5+tXMbU9ivsT+JluhqSUCbAnBI0zOv71QvaZOxzQbSnAt8Se 1ZpquKniFSYdn2ePUnhAnnrmTzpSBC4ruCi711SeLAfV8kQWokA+7SAC8ym+Zvb8y56j fVjQZESuyziiYv12gD7pyYkp2bYuE0MBwQYnDpDLP5M1id47N2gIF8wMThVxcRuH3JGb 5q/Mk8hclPFXVt+jyg8MU63YYr+XBDyt8vE4t60thnWTuM8I9ko1CLTK8Yb90jmSLx59 foWQGJOoLbn4BqSBd/5lcLj1806j7GqHvl/SZeKSBLvi0d7BaAUSn39zF/7n1011Bt/7 HHBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=4S8SgdDR3pFNDkoUDRIY1QDyIkmivlrOJFce4B1D2Gw=; b=blFX6W2mD6vf1TVz1R6s748SsMlRj6utfJjysEfaecgne0LzHOMzeV+iNGf8XGntd9 GiY3J71uoCJGAybaTitHM1vypdagXtJMCaJhJE7IPPlb4Owg/jQ9L0DkHaYvHinoRPDi 5WJ3OBQFQW8j569jMbjh6yJBKa302Z+/+LJVOys507xdrM3GdNCbeDoTZ4CDaCXGaQUT uaJ4p6GoMBp9nQGhs8MxfRtv1/yjczr/oK17tMdldMhgXsGfDvySNANRWc7htCAQJeqH 1bkT3c2H/GxOJ+ShKULemDM6cP3Uqnl+u2GS0EfQmbqzr/bfUtg/aSrLEft4v9huFFWM sfOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b="LAfy/WbN"; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq11si12008905edb.332.2020.11.16.06.48.51; Mon, 16 Nov 2020 06:49:16 -0800 (PST) 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=@oracle.com header.s=corp-2020-01-29 header.b="LAfy/WbN"; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730402AbgKPOqo (ORCPT + 99 others); Mon, 16 Nov 2020 09:46:44 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:32958 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730382AbgKPOqf (ORCPT ); Mon, 16 Nov 2020 09:46:35 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0AGEiVYR143629; Mon, 16 Nov 2020 14:46:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=4S8SgdDR3pFNDkoUDRIY1QDyIkmivlrOJFce4B1D2Gw=; b=LAfy/WbNOpRDv5odOVIf+5d2obPGwIh261YLcSxwydg1gawcIXdbyzucATwjCTc9smCc 2JktZeLFMMcXW9mDIMMhIrnC+CtXt7VP9eY2LoY0Dx9o8xlVXVR4QfJkm6yYxyf3tTW5 Pqmwdak7sLOrLWlIvaz1poy7jt8acovX7Is1VW7CT6mBWboBGoWYJ4+G62sw4z5Xsa5e kZ3kWPLw2uzoi4cDVoWuucgUH+uPTejqXbYDvUCLy9OIdET7OQXtANy5B9YLuIA/fYei ZpDiYIzijc71MdhJ6p0IYsKtDG4hjWNfUyplDxSbcgb+B9/vc+zVjyfqD7kHXQd4jbzt jQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 34t4ranhct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 16 Nov 2020 14:46:14 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0AGEjDbT164502; Mon, 16 Nov 2020 14:46:14 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 34umcww30s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Nov 2020 14:46:14 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0AGEkCVW014559; Mon, 16 Nov 2020 14:46:12 GMT Received: from localhost.localdomain (/92.157.91.83) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 16 Nov 2020 06:46:12 -0800 From: Alexandre Chartre To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org, thomas.lendacky@amd.com, jroedel@suse.de Cc: konrad.wilk@oracle.com, jan.setjeeilers@oracle.com, junaids@google.com, oweisse@google.com, rppt@linux.vnet.ibm.com, graf@amazon.de, mgross@linux.intel.com, kuzuno@gmail.com, alexandre.chartre@oracle.com Subject: [RFC][PATCH v2 05/21] x86/entry: Implement ret_from_fork body with C code Date: Mon, 16 Nov 2020 15:47:41 +0100 Message-Id: <20201116144757.1920077-6-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201116144757.1920077-1-alexandre.chartre@oracle.com> References: <20201116144757.1920077-1-alexandre.chartre@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9806 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011160090 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9806 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011160090 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ret_from_fork is a mix of assembly code and calls to C functions. Re-implement ret_from_fork so that it calls a single C function. Signed-off-by: Alexandre Chartre --- arch/x86/entry/common.c | 18 ++++++++++++++++++ arch/x86/entry/entry_64.S | 28 +++++----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index d222212908ad..7ee15a12c115 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -35,6 +35,24 @@ #include #include +__visible noinstr void return_from_fork(struct pt_regs *regs, + struct task_struct *prev, + void (*kfunc)(void *), void *kargs) +{ + schedule_tail(prev); + if (kfunc) { + /* kernel thread */ + kfunc(kargs); + /* + * A kernel thread is allowed to return here after + * successfully calling kernel_execve(). Exit to + * userspace to complete the execve() syscall. + */ + regs->ax = 0; + } + syscall_exit_to_user_mode(regs); +} + static __always_inline void run_syscall(sys_call_ptr_t sysfunc, struct pt_regs *regs) { diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 274384644b5e..73e9cd47dc83 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -276,31 +276,13 @@ SYM_FUNC_END(__switch_to_asm) */ .pushsection .text, "ax" SYM_CODE_START(ret_from_fork) - UNWIND_HINT_EMPTY - movq %rax, %rdi - call schedule_tail /* rdi: 'prev' task parameter */ - - testq %rbx, %rbx /* from kernel_thread? */ - jnz 1f /* kernel threads are uncommon */ - -2: UNWIND_HINT_REGS - movq %rsp, %rdi - call syscall_exit_to_user_mode /* returns with IRQs disabled */ + movq %rsp, %rdi /* pt_regs */ + movq %rax, %rsi /* 'prev' task parameter */ + movq %rbx, %rdx /* kernel thread func */ + movq %r12, %rcx /* kernel thread arg */ + call return_from_fork /* returns with IRQs disabled */ jmp swapgs_restore_regs_and_return_to_usermode - -1: - /* kernel thread */ - UNWIND_HINT_EMPTY - movq %r12, %rdi - CALL_NOSPEC rbx - /* - * A kernel thread is allowed to return here after successfully - * calling kernel_execve(). Exit to userspace to complete the execve() - * syscall. - */ - movq $0, RAX(%rsp) - jmp 2b SYM_CODE_END(ret_from_fork) .popsection -- 2.18.4