From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753202AbcADTu5 (ORCPT ); Mon, 4 Jan 2016 14:50:57 -0500 Received: from mail-am1on0069.outbound.protection.outlook.com ([157.56.112.69]:53248 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753120AbcADTuu (ORCPT ); Mon, 4 Jan 2016 14:50:50 -0500 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 v9 10/13] arch/tile: adopt prepare_exit_to_usermode() model from x86 Date: Mon, 4 Jan 2016 14:34:48 -0500 Message-ID: <1451936091-29247-11-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1451936091-29247-1-git-send-email-cmetcalf@ezchip.com> References: <1451936091-29247-1-git-send-email-cmetcalf@ezchip.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD012;1:7daBNuIT+syxrNLCqilcqvZ13Yhv+DGbhJUNLDSm0wG0hQh62VrBpRHXQIB/oaGKWtAw5/f06UHO4IDACC+swnVnYAQEWZXRunmtPpx6DGA9HTy5eHbWDdba9avGUL2ChIhddaWIXv1vy+mBy1aT6kp4pRaEV8dra2sOE9URrPMCnz+G4uxIkTYxSlwH9v/VR4Fr+5v7HnlKUkiboKLHUymYJZebwdF2lvxRT9pAQJtKz0IXlsuPF7WEhpTC8p8Ngsytvoi6+9oF71na/tMDJ72cUr2TtG+NBtfJLRM0RsgUU9vTeRiyNsqUCni4+8KPQAOwAAv5RuzBX2ITF5K9f2zBWUjlGDBBiOUYLheFb1trjNsHr8Ra84DIGCOwmreB 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)(106466001)(47776003)(107886002)(2950100001)(85426001)(42186005)(87936001)(48376002)(4326007)(50986999)(92566002)(50226001)(76176999)(19580395003)(229853001)(11100500001)(86362001)(1096002)(5003940100001)(33646002)(4001430100002)(36756003)(105606002)(189998001)(5001970100001)(6806005)(104016004)(1220700001)(5008740100001)(19580405001)(50466002)(586003)(5001770100001)(921003)(83996005)(2101003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:AM2PR02MB0419;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;PTR:wb-fw1.tilera.com;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;AM2PR02MB0419;2:tgqB8AnQChwzePqgc1h3mxyKjZaociuKrekavPhVhi2+q0pl3mOuyq7rob0NTaIjrYmUKJB9UlvG7r6wNTjsBzAmx1uEF/1iJ5Qs2L5GAWkUsWyHvv5GqNUdsI8MPiDEyPyOcZDgMzQK1FzocA2BDA==;3:e4CXw3KV3c7MbxoJu0BaAYmYfGvGCW3ovD18aVv2igWs8AsUuNGB9CdCiFFFcVb+wji16FaJhAdXNOBYpsFmDCoVLuEn4hGjAq7eHcEElCjcpTUFJD5AmnafWkLp4V+KgaCcU8vn+jpcii9OnyU2LuHgc6cZPXM8xubXUsg5s8X8HJeFVSk0o4lfcacvtZyDArRc/5ZaiKy2ehEbE5m5Ri99/8cqQXLsGINlBUBFPSE=;25:5LqUrzheh2q1O6LGwaP8MzhO5G1nokiQWn/3KSqQakgGB9vVkRVsv5tQFDW0FQhnm8KuwmOu9UnEVknZOxBOzUv+Z8F7bh3sQWFSNXK65YDPNT97jHiwUBIx3k7LMUfGT+006SzFarnUtcdrHntcVPpYHU81+orNt4MC/tivnMU51QEbX4ToWPblNMyewP+E5PqjYffsDRJQExXXUAGQCJhW7+hn9dGSilsUDaaNq8E+Mf6cSjHF6BotBiYyacZL;20:gVTHR6BnHvw3KJ6sQ4cPFCvruPyl3HEkMwaqi0D4yECInfTgi6zI0kGfPaqd9znjSdIGSTaxBI59Wq8YGuUSDocUvIC+mswA87Ea8s42jb3jXbF/QFD+OE0r2h5r2296k9BO+ku11LBLX2ZWzw7/BCrqP1UlGLLtIQpukpJNmE4= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM2PR02MB0419; 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)(10201501046)(3002001);SRVR:AM2PR02MB0419;BCL:0;PCL:0;RULEID:;SRVR:AM2PR02MB0419; X-Microsoft-Exchange-Diagnostics: 1;AM2PR02MB0419;4:ZTMv2WESgOfZG7+AfwewdWLILwKB65zyzuBtz9HsY6NjZhCYGZgTYAeCdkY6V3OmHj/jXXyx+VDMzNqogLm3sRPlAFyDRnGzpi0xn9QgMaaVkvd4tmgyAHGRRmUhQnZEgO2wGKDHd47Y1BZ9zTMW4cZVOe9L4gz1AJISwsoSNHeAOeKbRWlfXtotWA4yaAmSCceT9N4CJD7FEDoT8DHc/yzlBEKIeC3+JHusng72QCrPOTI6MyMAhy089hHiNZyppcOjFIrL/dQZmpvWSmdp/8nCSQOaz33tunB/xfg9H87AQYdpOZo2vNGfgvMR2taXdYzBKig69e+Nal4xhWR+Mk0RU1pH45oqLmsQV1PDLXer6lo5rwKu3NfRpPTl3e88A955cZ1+IQy/stmKWmKYf6BRX79q8z3q+rKMZ4Y1FnY= X-Forefront-PRVS: 08118EFC2B X-Microsoft-Exchange-Di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768Wm5EpNOA56T719MPAC8L66b?= =?us-ascii?Q?Hf7Kz70h1hU8d5/pafvwHIy0K83sWMeDATVQ95my0KOwawIMel6ifGUWF9om?= =?us-ascii?Q?h1/vGvbgWgdhGQHzwlKZ0c9FkyUusD7CA+VaFso0vu6KDymnMRsbxpo1WauD?= =?us-ascii?Q?gmXFvTGEbANE16vvc+Rs7GbFSq8VQyH0kBx/MqJhFAV+SLncI1ppkLywIjd6?= =?us-ascii?Q?4tRmAEFGOxftDCPFQurr/OCGGjyXKUAbr6p8I6RTM465MylosQ8oFn0/7FzV?= =?us-ascii?Q?/WOU8d3DMaQEun+GanHfMlMErY8FJ+31aUZYGauVX/rPrFk0co56Q=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;AM2PR02MB0419;5:pcTFodlrTCtN6yEre2lzjmYBAxQfLhptfao5q2+M8PSw/Ikn2+E3lyBHllSfr4luPzw0kUX2s8p185267vWvzzIiDVO5Qg1gV3xCt23YL8NhgcwXUO7K/WjPlAvfyEjA6jD0ZVyhADGf5pSRln8KSA==;24:iHJvGQiX6oPX4UTIQrna/lMdbH9DTvuGmfb9Q1ESHZb3JL2Z3liSFBz9kNcDSI3Ybq/R4Lptc9nuIwbWZxrSnKIbN5VHowWIRvvKjCHSUmg= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2016 19:35:43.4133 (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: AM2PR02MB0419 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