From patchwork Tue Apr 5 17:38:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Metcalf X-Patchwork-Id: 8753941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 747B89F7C9 for ; Tue, 5 Apr 2016 17:41:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83FB82038E for ; Tue, 5 Apr 2016 17:41:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9127320390 for ; Tue, 5 Apr 2016 17:41:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1anUxT-0001sq-KC; Tue, 05 Apr 2016 17:40:07 +0000 Received: from mail-ve1eur01on0083.outbound.protection.outlook.com ([104.47.1.83] helo=EUR01-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1anUxP-0001Cj-AV for linux-arm-kernel@lists.infradead.org; Tue, 05 Apr 2016 17:40:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=d3p1q35HdsabfSPSAlQU6erG+cp6uNC4FA0oYgjZCu0=; b=Z0nGxc9T2sAH1kqfv7TsU4n5gXbwh57+BsWSYQAh3npaViqlheF8QJnAsh2V0hXLfgV42t2Q82H+uLvCiG2RbCawKZAv0J4qB7yj6m/UQ9W8YhoQKHU3Oy2q0/urfjkqKdMy0kyBcXOKgnp9ic12GYk4drLMzKUhzC4WvGpjVTo= Received: from AM3PR05CA036.eurprd05.prod.outlook.com (10.141.192.46) by DB5PR05MB1528.eurprd05.prod.outlook.com (10.164.39.154) with Microsoft SMTP Server (TLS) id 15.1.447.15; Tue, 5 Apr 2016 17:39:39 +0000 Received: from AM1FFO11OLC005.protection.gbl (2a01:111:f400:7e00::101) by AM3PR05CA036.outlook.office365.com (2a01:111:e400:882a::46) with Microsoft SMTP Server (TLS) id 15.1.447.15 via Frontend Transport; Tue, 5 Apr 2016 17:39:39 +0000 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; mellanox.com; dkim=none (message not signed) header.d=none; mellanox.com; dmarc=fail action=none header.from=mellanox.com; Received-SPF: Fail (protection.outlook.com: domain of ezchip.com does not designate 12.216.194.146 as permitted sender) receiver=protection.outlook.com; client-ip=12.216.194.146; helo=ld-1.internal.tilera.com; Received: from ld-1.internal.tilera.com (12.216.194.146) by AM1FFO11OLC005.mail.protection.outlook.com (10.174.64.132) with Microsoft SMTP Server (TLS) id 15.1.453.6 via Frontend Transport; Tue, 5 Apr 2016 17:39:38 +0000 Received: (from cmetcalf@localhost) by ld-1.internal.tilera.com (8.14.4/8.14.4/Submit) id u35Hdbsd015589; Tue, 5 Apr 2016 13:39:37 -0400 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 , Mark Rutland , , Subject: [PATCH v12 12/13] arm64: factor work_pending state machine to C Date: Tue, 5 Apr 2016 13:38:41 -0400 Message-ID: <1459877922-15512-13-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1459877922-15512-1-git-send-email-cmetcalf@mellanox.com> References: <1459877922-15512-1-git-send-email-cmetcalf@mellanox.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:12.216.194.146; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(45074003)(189002)(92566002)(36756003)(11100500001)(104016004)(5001770100001)(19580405001)(1220700001)(86362001)(1096002)(6806005)(85426001)(586003)(4001430100002)(50466002)(48376002)(19580395003)(50226001)(42186005)(189998001)(47776003)(76176999)(5008740100001)(50986999)(87936001)(2906002)(105606002)(4326007)(107886002)(106466001)(2950100001)(33646002)(5001970100001)(5003940100001)(229853001)(2201001)(921003)(1121003)(83996005)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR05MB1528; H:ld-1.internal.tilera.com; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11OLC005; 1:cBplmX9431istigaFIMQP0HWbRhlXT3Ks6FR3o3aqqexKxKBub1m6TLzxQooEEF2JiPF5fJ7kYb5lBO94cXI19ZEcqlpungo70S0swSZIrvpR2IZJkusTsqZAy68YGzHbAKDHiqWxTPRJLzrCGYsYsXW9ay2W/0goNsCN1yk7uZfCwEmbcKMwuITFM515Nd19UM1DHbcUVJhTQHBo5biSvYZVwAQv5u39uuPju0+TBr+L6MxrWAEw7+UYjc3mhmEWZZEuxEFyBXrq22u0Rj3FlnKZhmC0plgihfzV+cxv4pAu7V5zI72q5UAxwhQ1WpyxSySUJsqzhI8F1M1YHZy/sPyZVJy3N4NJylvO5NXZHIen5bUJJMELNzhVHlDrtNZpuMkX7afizGfCZifiD3Jg/TJVhUKRSm7CmLl0aBmGWaiR4JFcpEbBrcfRA6PyHKJRWYx3e3MNkxu5yJjmX8MvZTCkp0XtMH5jfS/r73+cvJFTbNr028ce+ZagW52mtQdZoZ/yV5cBX6+kIByQkz0qthrfdw1HPa93blqxIEvTAG2Rz4kfi2W+913DgBKc8yXOVYhB5Fs8a0BMRlnzyPgHUdFkIx42TxROWL+pSf4MvCifupIYFCMOVFW7pD5z44M MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: a5df92e9-c1bb-43f7-8654-08d35d79434e X-Microsoft-Exchange-Diagnostics: 1; DB5PR05MB1528; 2:bof/Zbq3z3R5GL2qM0B5mVZZM7dJAonsRqNX4MnJSCIqtUzwiaYzZtT19G4xvrZjg4x8DO2/QUDNQdAWHQ8KH3VRSezCwkTqrZ+5Lp26myycxrRsL6251axq78SgiD7N8rghvBN63DwpruaHn3c7NHXrgIdfJK5M/Ma50txcIe4BZnOvWsXOANWArol0/j24; 3:Xb16E8HK/1AmFr2XvHS+K0ZMBxq20uWo5NuYm01OJsCQvuiQNyXcjjGiRKJ9FeIPRGSlHlPyUlzk1KhSpGwk6cKdXtYjErSR4dyyjIpJs4/TH73ZtVIGapplzyR2T0GFtBTZvwghIDilQwNrWNS0NzMXRYHwfAiGxFCP75AMuGSk+YQkOZcx53mKogmaaoM2S9WPEZCTM1PWgWw+z3oOwBw2QYdW4RHNgz2AjJ5tmqs= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR05MB1528; X-Microsoft-Exchange-Diagnostics: 1; DB5PR05MB1528; 25:pU03QcFf2d2zU+hdJ4DbSDqz5GZCyogaGrtbEGJOwCOoUg+IpKJTboyiZqQKrX2lsS9YBFH3Nzc3R1XN6gTwsY6QiheJKnSAqAHZ9ghw/tnM9lyoEzpteApSwq7dNBTRIOpodenmquvefky0ROmw8w1XPdfN5r0uU+4Fj1h+v43UFWbGfYxhBEa6O4ebbAv9QJuyrMxZ4tKiS95kXrZw/V5fnv5GIgVlvwajr16tJIz6meVY3M8Q9+e6ATaamn7SXT2veNzK/0gIQXakzEmZDHAMKgbikP0rRPW2i2wtFHtVFKyNreV/Fpy0Xe61H6E0b6CjkwjVAtImKk9ldfgBIcJMvemWKxfvHIa6tgaaDIj7MkdotCrC5ZNaZb+kxm1UP9VfzeOeTMyRLjZhq1iltQVDnjiEXY8+n2u8R71IHpy5buRBpJdcsKMFLHvNpCWPYvxCfe75qUzDdMI6DLgVvo76mt+mh+/xPLvSFCuZW2gYfncuyUbiHJo6zTuTyi1A7dp/S8xi8BYLcfl18ohTl4fOC2NfKTx1HGiCHuPZLjuJ6KI+MLiwetEW5+UFOsKPJ5MXf7X1hLv3I2s+pCMiWDMzCJiRlzV/5wQ6TDmiBGzpOQAg+jcpG96mQF1ovrBqv6TmmpHW9KdPdEeKNMAhLFNYmnMbGsH1pA+NraGv/Oi9FTOx72aGsTrtUOyEMuXc X-Microsoft-Exchange-Diagnostics: 1; DB5PR05MB1528; 20:g3mhmUJ5wXi4jmRP2WNnyBCLptFxp8sTimX8ueeT4BFSeSpR5iONchsAFZgUwFfj9MtfWzOjvMhxs+XcXWlvqS3OgMqtJ5GvNnrKzQoQ2i4kwkSBZDENTZO8o7CRL8U2g0VbRPaB/UDW5TCFGaRBLlu8881LswRGE9FqD3hGslERqkvNMCsem7rMop1W0GuaVkCwEtEjzEvCqcWdZK8Qq3SF3OdLMafw+plHFzWzJOBtMc3CyAt8GtotxYnSSCgckchjGBRgjkVDk4rF/t24sP/zXwKQprl2Oq0Sf3T9PL5n7LQNpoSfZ+i3JJ+SaoWZz+K4FNRx9qKTW35DtvdpzawKviVtsRm0q27RZgH+Qrh1mtBJVFBUMN+BawsPqtNaAWOiwNeINWJH+63U/oW9/Pt5RLv0Lgkm1NT9aGj6o6R/yfHPODvJVblBw/SVmQc90gPFlhlJJDONO+oEWIMu2Fp4kRVzn+5p3/lHeDTJt3EdHA128TsVrumTw4mLlI4U X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(13024025)(8121501046)(13018025)(13017025)(13015025)(5005006)(3002001)(10201501046); SRVR:DB5PR05MB1528; BCL:0; PCL:0; RULEID:; SRVR:DB5PR05MB1528; X-Microsoft-Exchange-Diagnostics: 1; DB5PR05MB1528; 4:9zXl+H/XWTsNe3VuMaNsKICM00liYz5Tz7Hz8/VkPQb32EaG8pVclE+t8HKXP+aKruTBMkZczSpJwWhBYoJ5ziGP4zmyx3g4sTBY4wD1aN1TLDVxsBeV8AY2G5mA5S40toN4PNyB8iZLtmfdcZZEtehsnjv66/C+T33QortcTsbkKLnN+oIzT7cdiZ+HEel1HG7XajlmuDTLB2F7BYHQFVAy44stKNEORcPD3sG8yeajeHw7TXwEPjQAd/DxV9PrlZk6bo7cnh0lQke8WzrbVu5+J4QlgX8gTnrpxq7ZVC6Qz+MgXuY++XqAtfksv4YFk6aFAZHZhwtjMhL3xJLsKDl86gwzCbyOWofHJXRpVVTK1MYciZcHhfbAb3QKhlPdE8DLg3DLDi5zN1RlCWZnma+w8R4jS3yZGfklcS6tv6DVclx2WS3U11r2kjFD5NDQCLPSzBQ9yqu/ZtMHFzicsg== X-Forefront-PRVS: 0903DD1D85 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB5PR05MB1528; 23:UyqL3c5JitOdvbsEL/LQ6z3gGJNeuH/nm0kXzqYFR?= =?us-ascii?Q?Q0zINporxAZUplYJht1E2/iwj0DBpxOx9YXxUK+iuuR385+m7h0cwqH7JZ+p?= =?us-ascii?Q?bpdvDdUQHgDtBptaz1uEm/SkHJoLo0jTFTn5I8wln0U7d66MELwk48jkLjD4?= =?us-ascii?Q?6YG4+g0B3wcehOgqLkGCOo3v2afdZTS8D9UHd+31D3KxssKxWXTZfE+q8sTx?= =?us-ascii?Q?4VCiHDHLtApWuKj33pl+BeUC3IB5QwxOHwgG3q4Ysa6Dv8u/iq0k8N64BzbA?= =?us-ascii?Q?eDQIRZpMKgpx0juhw8uANL17O+w/09VNwBs+kuAgCXJmYorsv8Zm9JlotOAz?= =?us-ascii?Q?qwGK4d8Eh8atyKlys0Cp6tDhkaeIuvg8LJDHSEzD/srnOSUMOAUpAbGzoE34?= =?us-ascii?Q?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1528; 5:C0fF0fVpIPABxWNzLbSPOJf8Gqi2YdAeBki8ImC8Qt4Ke81h5RPvSFQJJkFoPw7ZbHrTgs07dL80i/o81qMZGPsIpbJ7kQPbTSra6n023FNM4GMvTizd0LiG6Yi2s7qix+hJCKOzRWuWiillcslG8w==; 24:oXbFLoXptFeu0t/9eQS3wevKSWVxbFjfHizX82Evnu9eB1KBVi0TJRhDPgEpCAmssrfwrsOHLh68WtI+LOknCpogFtPBWJBRA/FobF2s0VM= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2016 17:39:38.6649 (UTC) X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a652971c-7d2e-4d9b-a6a4-d149256f461b; Ip=[12.216.194.146]; Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR05MB1528 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160405_104003_781883_146C1BC5 X-CRM114-Status: GOOD ( 15.29 ) X-Spam-Score: -2.0 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chris Metcalf Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently ret_fast_syscall, work_pending, and ret_to_user form an ad-hoc state machine that can be difficult to reason about due to duplicated code and a large number of branch targets. This patch factors the common logic out into the existing do_notify_resume function, converting the code to C in the process, making the code more legible. This patch tries to closely mirror the existing behaviour while using the usual C control flow primitives. As local_irq_{disable,enable} may be instrumented, we balance exception entry (where we will almost most likely enable IRQs) with a call to trace_hardirqs_on just before the return to userspace. Signed-off-by: Chris Metcalf --- arch/arm64/kernel/entry.S | 12 ++++-------- arch/arm64/kernel/signal.c | 36 ++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 12e8d2bcb3f9..d70a9e44b7d6 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -674,18 +674,13 @@ ret_fast_syscall_trace: * Ok, we need to do extra processing, enter the slow path. */ work_pending: - tbnz x1, #TIF_NEED_RESCHED, work_resched - /* TIF_SIGPENDING, TIF_NOTIFY_RESUME or TIF_FOREIGN_FPSTATE case */ mov x0, sp // 'regs' - enable_irq // enable interrupts for do_notify_resume() bl do_notify_resume - b ret_to_user -work_resched: #ifdef CONFIG_TRACE_IRQFLAGS - bl trace_hardirqs_off // the IRQs are off here, inform the tracing code + bl trace_hardirqs_on // enabled while in userspace #endif - bl schedule - + ldr x1, [tsk, #TI_FLAGS] // re-check for single-step + b finish_ret_to_user /* * "slow" syscall return path. */ @@ -694,6 +689,7 @@ ret_to_user: ldr x1, [tsk, #TI_FLAGS] and x2, x1, #_TIF_WORK_MASK cbnz x2, work_pending +finish_ret_to_user: enable_step_tsk x1, x2 kernel_exit 0 ENDPROC(ret_to_user) diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index a8eafdbc7cb8..404dd67080b9 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -402,15 +402,31 @@ static void do_signal(struct pt_regs *regs) asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int thread_flags) { - if (thread_flags & _TIF_SIGPENDING) - do_signal(regs); - - if (thread_flags & _TIF_NOTIFY_RESUME) { - clear_thread_flag(TIF_NOTIFY_RESUME); - tracehook_notify_resume(regs); - } - - if (thread_flags & _TIF_FOREIGN_FPSTATE) - fpsimd_restore_current_state(); + /* + * The assembly code enters us with IRQs off, but it hasn't + * informed the tracing code of that for efficiency reasons. + * Update the trace code with the current status. + */ + trace_hardirqs_off(); + do { + if (thread_flags & _TIF_NEED_RESCHED) { + schedule(); + } else { + local_irq_enable(); + + if (thread_flags & _TIF_SIGPENDING) + do_signal(regs); + + if (thread_flags & _TIF_NOTIFY_RESUME) { + clear_thread_flag(TIF_NOTIFY_RESUME); + tracehook_notify_resume(regs); + } + + if (thread_flags & _TIF_FOREIGN_FPSTATE) + fpsimd_restore_current_state(); + } + local_irq_disable(); + thread_flags = READ_ONCE(current_thread_info()->flags); + } while (thread_flags & _TIF_WORK_MASK); }