From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934297AbbI1PS1 (ORCPT ); Mon, 28 Sep 2015 11:18:27 -0400 Received: from mail-db3on0076.outbound.protection.outlook.com ([157.55.234.76]:23648 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934269AbbI1PSV (ORCPT ); Mon, 28 Sep 2015 11:18:21 -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 v7 10/11] arch/tile: adopt prepare_exit_to_usermode() model from x86 Date: Mon, 28 Sep 2015 11:17:25 -0400 Message-ID: <1443453446-7827-11-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1443453446-7827-1-git-send-email-cmetcalf@ezchip.com> References: <1443453446-7827-1-git-send-email-cmetcalf@ezchip.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD041;1:L0hYxMhC2qdsS9Q6v8sWD0GOGeZBSqoOzkBuViXAYTCLMSq57l9FBmSuq5Le+OmZEowEtTyj++mJpIV4m8Iq1ieiA3DXfbRqQICvZdTa+XImQORCEnREC53P3FznfFkFr3197jUd0QEb9h44HEJQP2gy5XyNZOsGFC+gxwCF7cKUFblCGaUkgArUSZycy+4JS4y8dnasYgGyeuNsakBTYI9hxj21YLkwIcMw//OityQj1Eb+/0vgtNO72Gxl+v1qTW2qghSJiet/2wS39FPt3gsq3mFht6JBspLdUIxtkxEgmmCQVVk/b8ueBbNsqlMCBWdkSZSZFgoD6Ou3/xv1KV8XLc4mtDpkM5zES8XgORY= X-Forefront-Antispam-Report: CIP:12.216.194.146;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(64706001)(33646002)(19580405001)(5001770100001)(5001860100001)(97736004)(50226001)(47776003)(92566002)(19580395003)(11100500001)(86362001)(5007970100001)(5001830100001)(48376002)(104016004)(50466002)(5003940100001)(77156002)(46102003)(4001540100001)(87936001)(105606002)(81156007)(50986999)(6806005)(76176999)(2950100001)(107886002)(5001960100002)(106476002)(106466001)(62966003)(189998001)(68736005)(106356001)(229853001)(36756003)(85426001)(42186005)(9376005)(921003)(2101003)(4001430100001)(83996005)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR02MB0783;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;PTR:InfoNoRecords;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;VI1PR02MB0783;2:uqAWQDgDqfxHe34SQuZcDQOYq1t4As7S9MQDV8KwuAY7fWVu8qchflyW0lMXhoFmF+8uSIp58IC+EoXDWXDlVd5D+L4dZtfppijQNpEPee3gyHHsRt087+iyKrYw6d7Z1LKiF9G/G9RD8rhvh4ELZDegNNtFEqVDFYYPxjMATYM=;3:o/1n0H2LDLSO11wjdba9bzck7W1yOKBOtiKA+isxSm7/90/adowuDtBTXvPE4luZ4hMGaB2ZR6ZjnYfQtG8mTo0/Z8Sn4Lya4TAgyR5Fq7/ta3r3OTHua+yOKhemhCv8/1eJyMeqQIC7AbAhMYbzEKAmP89B+CcZ3FQhBR0IbXL4MAf55RxepxOKICdfec8kL2g9YH1g0wQ6MGo7QQaCJlYoEcBgKlnxvuAMzJlNpQHojNQtOD41pRtOMnWkaE8M;25:SIO1YPqCPae5pVXcfgYFG0w+GUQhAT1AUZkIFX0kv6A58V2mGb0dKt8Jt7Eh6paNvPfCMDtHPmXsfr8Y53sNHJsdAG7LYLFfsNnRP8BQdvzZjekA4lwuCfL7SYC4wqStBlWe1j/WY3PNOpY6FQupfurW0yhy78CX98oL47AgpFHTK1c97rgDqruxxvxgFN2DW+wJz0OfTBXfSmExKlb4iw7G9I2hFhIDB469GPwwjbl3MnayuzhOMWgsZHLvcVws;20:W/0UMj4V62Bg2cmIBqr6u4r4asV1MQiM+hRNI1QnbzoTe7Ed8AoSPAgRUJVqbeyxxPp4bb9QNMvmX/H5oSwtnPfc0y4ySIBofAcZM9q7auGtF0ALnVHhQXQiUe8Kx4nWxbwUFGCve4irpUu8j9schaZJ+LgQbnNlPZ4T1IzBQ7I= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB0783; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001);SRVR:VI1PR02MB0783;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB0783; X-Microsoft-Exchange-Diagnostics: 1;VI1PR02MB0783;4:rkvQQZp1lAJJiKoifdeJob8LdX5pDmbDHifpQX6eTr2rkklVQEQhV00PVS67FH0CPoVyb2gqRMwAkMd/hw82nUY+SqpnaEUKTAwueaP1/ZOwiDCT4opFxJ1RRcYAdiS3tbM0/wJE5sWuwPOb3Vai/gtdrvxvdFIpCv9P0J4XaglSK1QZObMPMrT2m7hlVRluFxOpj0pVOMV/TY/v0I7FSgFk0j50STJArdKIQ7Ev7fBrUP2mvVjY23fiMZxWyeymGZS2k5Sy0YWuVUd/9KDvrXJOhXil+TDR1u8qcUel4FevzW0qzXlbFb5G7fGsqHHIV07rOTScnbbqoYbwPOFS/0mofq2kzbY72HpRAAHCU4c= X-Forefront-PRVS: 0713BC207F X-Microsoft-Exchange-Diagnostics: =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ticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2015 15:18:17.0625 (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: VI1PR02MB0783 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