From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753445AbbJTUhh (ORCPT ); Tue, 20 Oct 2015 16:37:37 -0400 Received: from mail-am1on0095.outbound.protection.outlook.com ([157.56.112.95]:51648 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753276AbbJTUhU (ORCPT ); Tue, 20 Oct 2015 16:37:20 -0400 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; ezchip.com; dkim=none (message not signed) header.d=none;ezchip.com; dmarc=none action=none header.from=ezchip.com; From: Chris Metcalf To: Gilad Ben Yossef , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Andrew Morton , "Rik van Riel" , Tejun Heo , Frederic Weisbecker , Thomas Gleixner , "Paul E. McKenney" , Christoph Lameter , Viresh Kumar , Catalin Marinas , Will Deacon , Andy Lutomirski , CC: Chris Metcalf Subject: [PATCH v8 12/14] arch/tile: adopt prepare_exit_to_usermode() model from x86 Date: Tue, 20 Oct 2015 16:36:10 -0400 Message-ID: <1445373372-6567-13-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1445373372-6567-1-git-send-email-cmetcalf@ezchip.com> References: <1445373372-6567-1-git-send-email-cmetcalf@ezchip.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;AM1FFO11FD034;1:zcicJwiWwL+S+R7OSMWxffITPlcc//i8EK8fee+iVeFOvZl+4pYZH1awwKxbX7oloHuAOiGm8wuc8x1n1kBnOyyqI53//5nj5N92GMfFDPvPs2o9GOPo9T0iO/kH4VMAeKKORrzP53mFJFxWtjdDVMwkPgz+eXKRBj/a5yjjLqS6w4mbYdzppRNgcXRoowfqx6hwGkZQ2gBDDM4xXc9n0og4IxICQZT2X3zJzLVvwE9nGSRgXHpNCAmySvr1E7ydjUCxWdsgtKCzBqyQm4yzofyb3MHPVpyJxCk+OIlYqAyd6oJJ5iTX6jvDHtAKt+TsQp/yvDxHxWTRbQIgX/vz84EEf0O6mVCR6A+suT/M89k= X-Forefront-Antispam-Report: CIP:12.216.194.146;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(5003940100001)(85426001)(5001960100002)(47776003)(106356001)(19580405001)(50466002)(50226001)(229853001)(87936001)(106466001)(105606002)(2950100001)(97736004)(42186005)(64706001)(81156007)(5007970100001)(106476002)(5001770100001)(50986999)(86362001)(189998001)(19580395003)(76176999)(5008740100001)(46102003)(92566002)(6806005)(36756003)(33646002)(11100500001)(48376002)(107886002)(104016004)(9376005)(921003)(4001430100001)(2101003)(1121003)(83996005);DIR:OUT;SFP:1101;SCL:1;SRVR:DB4PR02MB0431;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;PTR:InfoNoRecords;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;DB4PR02MB0431;2:7YdSpoZCrEjZ8EbZqRaUqWmr4/CrklE9Y7hjatmW0EJ5qQzZ8FFK5rCGUwpYGppzhHAeVUpr1rnpEfynnFSRctRCkZQWGv+THY+vuMIjgP557PcDB4kvpyi4266W49DVdNx9wERuWDn3oow/ZGDnGXXON1tbVr2cBsA7/wzXsXE=;3:VJs6Ri74RhBo2+WWfcoHEg+fuuis/vmW/tL3MsG3iiMONhkSZEzR8s3B3/XIgDO2b6kn+c/qIMR0GR2E6WwlG7xJ4CSXJesMmkirZki/Qh7e9/Si7x1J17g1CSjsEesKfNJHjwMm+WtPnEWr5jlscRb2EfCx6TwpzN8L3vE3aQGWwYnhFxF7b+DuAv16Jpu/DCQYqLnw3NYhbQ0jNvUPe2VUU8Nfuqg5Qdz88QCo4gLPp2n/ngTOh4a+eAWi4U/b;25:oD5/EZF9YkRddVgXtj7P4B7BHZNm29vWYY5Ul9RlqznW7mxmpV72TuUArcBmMD6IgnGzWY7PmvTrosUN6swf3EI1WojvwhngkwaUdMbdpRI4QpdOStPCdiDXektZWJ0daAM6cqOXaleFELGewPHCLjGQK7qVbx+iKT5TjOGIS/b4ZqYKl8chORzVkg5/6XOtkBH/Kttt2XmloSCcK6G1tNtBOYogtalgxVqivs6sxXxXel/XnYS+SyhPT34FAEXx;20:GLHDYebSoLSTWiQIbL5uFlgmPOLB10zgQXK+U3XaBcWauly1LEtDKBeFns0Ppo/ZCqOeBWMAak9ykfKYtFi4QryN0Ih1mGv/XALfRfVRBAsJzJwhSBg8nQaBW6eFXqfS/HypzwkmAhluTsEPNRGovseZcveXkxB7HYr2DlsiMx0= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB4PR02MB0431; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(121898900299872); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(3002001);SRVR:DB4PR02MB0431;BCL:0;PCL:0;RULEID:;SRVR:DB4PR02MB0431; X-Microsoft-Exchange-Diagnostics: 1;DB4PR02MB0431;4:/lXfe66H4oCunH5ry6XjfNhmdIlyKB/TzZ1vEdxB6IFmtC7Chx9W78TQnbxKk4+A1AOYnM+5+k9KmACmtSyqyZxoART6M9B7WzWibpUa03AJ6VHACntTj38k0vgj5SPN5bcvCu03XXwUTCJShAUd2P6FMVR/Fb3EfydNfg/0DacWw8LBRO53atWAPmCTuQYr3W4SzeI89wQsZdjvv66bjIWUr4zAedFjGeeeh8jrGgE2NXJMLdxjT6imS5jfaxcvtAsv4klSe5tMwN7yL9WkMuM70pjk/vbdUx9kcjHaoggupeZJywJg162MrCHGmCN3644NvVsxqTeJRZ7YCxa68xAhz0JBOn3jrswBBZBJjXs= X-Forefront-PRVS: 073515755F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB4PR02MB0431;23:GcV7IAJA/fWu4kbRsiVONgTVbjCH1fCPjcCtizIjo?= =?us-ascii?Q?mYDguXM2hd6nXwFv7vKGZHmSf5cddi7YNTILNlQIJK29vX1wCg8XOuX6+evr?= =?us-ascii?Q?pl2C4LpvlihXAG88CeR4Rz66hbZkVyGJ6riOVMhVJeF/AmKbljypWXufqChX?= =?us-ascii?Q?0Mf8BdrKhbO6DJ8RtkpoCROgR6szJp3gM1L7c2qOQHdX0yMdNpw5UgQZ/ywU?= =?us-ascii?Q?PZO0UoUKGlIAYvGEnBP8olPitiAbPingjJe9YJZleiRqm/zoJlVyoTkzLNfW?= =?us-ascii?Q?Tx371hq+sC/W4VRowsXfcx1tUay2hz5RUbh6QENaQJYjCN3steOHj9CpvovI?= =?us-ascii?Q?sTOx0FsCwmCj+XaNkIIB58GlsFJe2H7kW69spXZtUSqrA00hnQWprKGyvEhP?= =?us-ascii?Q?Dd/XAnvtkAvQa4iDL2VdpMaytI0DfYhyw5kmUdEFLLi5yKqjB67QRLbPlYkk?= =?us-ascii?Q?h0cdW7C3/JcB5Esvy2vloU6wb7sVA3amFQaTV2J2JhJJXBbNz0jHBBw9OlHj?= =?us-ascii?Q?nGZ6IU+Yjisbc8M6IR7w4aRy17zkIkgjLxig663p/MJ15JznMwnbxAJa1iWR?= =?us-ascii?Q?hA7iFn5FkoarYTgh4MV+XF/pltOguekdek5JGKYqQ/IE/f/2f+YgYCMZK/4n?= =?us-ascii?Q?YJz7raA8M2CXhrGc5VQwDqE2D648U7er2tcahXNMsUDvKi+aEmk/qxRN1hSX?= =?us-ascii?Q?iog20z83DidXBZOlrrlzecrv/5eKXxHEdFiWuVInIcg67OmpCHngllz3aQ3W?= =?us-ascii?Q?kcVK0h/FU7kEDQpoEqT1dogBSWY2Wzh2TDRXe7sIKaDMagrpXx/FjVXvOaFj?= =?us-ascii?Q?GppBQOI8v7biG3ywyBwSaXOe0SaL9v6ss2mMDp8PEzvN30Lz3MqlA/YSTk40?= =?us-ascii?Q?kupyEtkrdWDeN1dGddiDz86SXV2DBm8A3b/8NY7o8rzl5HJ0wycCmL3d8PBo?= =?us-ascii?Q?THkdcRvRdCowVuW6XQPldp70pAATlDRJb7VxW5y8LKYtan720k/pIRJ85bGJ?= =?us-ascii?Q?zZ0PAU7BGuH+/x5rrh0rW6LuCs02Z9RB3QGNMirx1XVG8gXngIneO30Bl8O8?= =?us-ascii?Q?O2QUDP67KoWb07Sh7YNpGiiony7eWtv+Hl+J2lFRqZO8a7tth1mkmczENxty?= =?us-ascii?Q?sG126fCUIonSZ7ln2FyYSvC6NBkzu0Z20de2tR6yvffLgaq6UpDq/mAM/0aP?= =?us-ascii?Q?LpRNPzL8Hue5l17PaYgZThh6ogvWX5raYfDeKaagXm6FzKFUD6X52qkrKhIS?= =?us-ascii?Q?2Nr1L0kd6mb8t3fd82QfsZ1R3wS8wW8ulyT7WY0?= X-Microsoft-Exchange-Diagnostics: 1;DB4PR02MB0431;5:VxK3nf/ZPILuqdeFZ/nO+8HBtd8xHw7Or8N/wX0bSkb/+ILSuxixPnr4m6yJm74dIHlsPfp8jlK8eZVcHq86nJepKU6cz7p/bABE1EqZGla33qLynagxCh9QvN8NqZWk6Ar4/13S63e38C0qF8Nt0Q==;24:6sB1YQzyzoSAbitdXFPQvdnSs9BPI7ud2gNRGOcnVIoBCVZelxiBbeAzaFRctVtO6QVpbe0P6ne9is4f9Whk/VIRSWs/R3Wt7BhqPD30iBc=;20:K19dKWdQYMYWZmDxXUo4WJT0gsJZM9zmz5tJsXmVUY/fbniXW5GkhWK4LaK4E1MdyDvIknGyQQI+1EUCKMGFRA== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2015 20:37:16.2506 (UTC) X-MS-Exchange-CrossTenant-Id: 0fc16e0a-3cd3-4092-8b2f-0a42cff122c3 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0fc16e0a-3cd3-4092-8b2f-0a42cff122c3;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR02MB0431 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change is a prerequisite change for TASK_ISOLATION but also stands on its own for readability and maintainability. The existing tile do_work_pending() was called in a loop from assembly on the slow path; this change moves the loop into C code as well. For the x86 version see commit c5c46f59e4e7 ("x86/entry: Add new, comprehensible entry and exit handlers written in C"). This change exposes a pre-existing bug on the older tilepro platform; the singlestep processing is done last, but on tilepro (unlike tilegx) we enable interrupts while doing that processing, so we could in theory miss a signal or other asynchronous event. A future change could fix this by breaking the singlestep work into a "prepare" step done in the main loop, and a "trigger" step done after exiting the loop. Since this change is intended as purely a restructuring change, we call out the bug explicitly now, but don't yet fix it. Signed-off-by: Chris Metcalf --- arch/tile/include/asm/processor.h | 2 +- arch/tile/include/asm/thread_info.h | 8 +++- arch/tile/kernel/intvec_32.S | 46 +++++++-------------- arch/tile/kernel/intvec_64.S | 49 +++++++---------------- arch/tile/kernel/process.c | 79 +++++++++++++++++++------------------ 5 files changed, 77 insertions(+), 107 deletions(-) diff --git a/arch/tile/include/asm/processor.h b/arch/tile/include/asm/processor.h index 139dfdee0134..0684e88aacd8 100644 --- a/arch/tile/include/asm/processor.h +++ b/arch/tile/include/asm/processor.h @@ -212,7 +212,7 @@ static inline void release_thread(struct task_struct *dead_task) /* Nothing for now */ } -extern int do_work_pending(struct pt_regs *regs, u32 flags); +extern void prepare_exit_to_usermode(struct pt_regs *regs, u32 flags); /* diff --git a/arch/tile/include/asm/thread_info.h b/arch/tile/include/asm/thread_info.h index dc1fb28d9636..4b7cef9e94e0 100644 --- a/arch/tile/include/asm/thread_info.h +++ b/arch/tile/include/asm/thread_info.h @@ -140,10 +140,14 @@ extern void _cpu_idle(void); #define _TIF_POLLING_NRFLAG (1<flags. It is - * entered with interrupts disabled so we don't miss an event - * that modified the thread_info flags. If any flag is set, we - * handle it and return, and the calling assembly code will - * re-disable interrupts, reload the thread flags, and call back - * if more flags need to be handled. - * - * We return whether we need to check the thread_info flags again - * or not. Note that we don't clear TIF_SINGLESTEP here, so it's - * important that it be tested last, and then claim that we don't - * need to recheck the flags. + * TIF_ALLWORK_MASK flags are set in thread_info->flags. It is + * entered with interrupts disabled so we don't miss an event that + * modified the thread_info flags. We loop until all the tested flags + * are clear. Note that the function is called on certain conditions + * that are not listed in the loop condition here (e.g. SINGLESTEP) + * which guarantees we will do those things once, and redo them if any + * of the other work items is re-done, but won't continue looping if + * all the other work is done. */ -int do_work_pending(struct pt_regs *regs, u32 thread_info_flags) +void prepare_exit_to_usermode(struct pt_regs *regs, u32 thread_info_flags) { - /* If we enter in kernel mode, do nothing and exit the caller loop. */ - if (!user_mode(regs)) - return 0; + if (WARN_ON(!user_mode(regs))) + return; - user_exit(); + do { + local_irq_enable(); - /* Enable interrupts; they are disabled again on return to caller. */ - local_irq_enable(); + if (thread_info_flags & _TIF_NEED_RESCHED) + schedule(); - if (thread_info_flags & _TIF_NEED_RESCHED) { - schedule(); - return 1; - } #if CHIP_HAS_TILE_DMA() - if (thread_info_flags & _TIF_ASYNC_TLB) { - do_async_page_fault(regs); - return 1; - } + if (thread_info_flags & _TIF_ASYNC_TLB) + do_async_page_fault(regs); #endif - if (thread_info_flags & _TIF_SIGPENDING) { - do_signal(regs); - return 1; - } - if (thread_info_flags & _TIF_NOTIFY_RESUME) { - clear_thread_flag(TIF_NOTIFY_RESUME); - tracehook_notify_resume(regs); - return 1; - } - if (thread_info_flags & _TIF_SINGLESTEP) + + if (thread_info_flags & _TIF_SIGPENDING) + do_signal(regs); + + if (thread_info_flags & _TIF_NOTIFY_RESUME) { + clear_thread_flag(TIF_NOTIFY_RESUME); + tracehook_notify_resume(regs); + } + + local_irq_disable(); + thread_info_flags = READ_ONCE(current_thread_info()->flags); + + } while (thread_info_flags & _TIF_WORK_MASK); + + if (thread_info_flags & _TIF_SINGLESTEP) { single_step_once(regs); +#ifndef __tilegx__ + /* + * FIXME: on tilepro, since we enable interrupts in + * this routine, it's possible that we miss a signal + * or other asynchronous event. + */ + local_irq_disable(); +#endif + } user_enter(); - - return 0; } unsigned long get_wchan(struct task_struct *p) -- 2.1.2