From patchwork Fri Mar 11 22:10:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Metcalf X-Patchwork-Id: 8569691 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7E1D0C0553 for ; Fri, 11 Mar 2016 22:14:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 704ED20272 for ; Fri, 11 Mar 2016 22:14: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 763D220219 for ; Fri, 11 Mar 2016 22:14: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 1aeVIM-0006Rn-6n; Fri, 11 Mar 2016 22:12:30 +0000 Received: from mail-am1on0077.outbound.protection.outlook.com ([157.56.112.77] helo=emea01-am1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aeVII-0006PN-1x for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2016 22:12:27 +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=OVCInsqp3bqiGDK3gctzSrj9rJMIyuEj7mo5ofAuLg0=; b=ODpu7+fTIC7zQ1sKZ+yudmYzZX/vV40+pgaiwmzwNHYLmDHUbPSLlCjokDXIMvTAJSqmgCEiPS0YgU+MngBvbHiUgFH6ohiAzmiAcnedjevAQKOE2vHtA70lzterZPYVBYmaBLmIqeqgOHf4Awh+k5G7dAp3lBN1stxzFocL5cA= Received: from DB4PR05CA0026.eurprd05.prod.outlook.com (10.160.40.36) by DB5PR05MB1525.eurprd05.prod.outlook.com (10.164.39.151) with Microsoft SMTP Server (TLS) id 15.1.427.16; Fri, 11 Mar 2016 22:12:01 +0000 Received: from AM1FFO11FD001.protection.gbl (2a01:111:f400:7e00::185) by DB4PR05CA0026.outlook.office365.com (2a01:111:e400:9850::36) with Microsoft SMTP Server (TLS) id 15.1.434.16 via Frontend Transport; Fri, 11 Mar 2016 22:12:01 +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 AM1FFO11FD001.mail.protection.outlook.com (10.174.64.83) with Microsoft SMTP Server (TLS) id 15.1.434.11 via Frontend Transport; Fri, 11 Mar 2016 22:12:00 +0000 Received: (from cmetcalf@localhost) by ld-1.internal.tilera.com (8.14.4/8.14.4/Submit) id u2BMBxOC026294; Fri, 11 Mar 2016 17:11:59 -0500 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 v11 12/13] arm64: factor work_pending state machine to C Date: Fri, 11 Mar 2016 17:10:22 -0500 Message-ID: <1457734223-26209-13-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1457734223-26209-1-git-send-email-cmetcalf@mellanox.com> References: <1457734223-26209-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)(45074003)(6806005)(87936001)(1096002)(86362001)(1220700001)(85426001)(575784001)(50986999)(76176999)(92566002)(960300001)(36756003)(4001430100002)(42186005)(50466002)(106466001)(50226001)(11100500001)(105606002)(2201001)(586003)(2906002)(33646002)(189998001)(5001970100001)(104016004)(5008740100001)(5003940100001)(47776003)(5001770100001)(229853001)(19580405001)(107886002)(4326007)(19580395003)(2950100001)(48376002)(921003)(1121003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR05MB1525; H:ld-1.internal.tilera.com; FPR:; SPF:Fail; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD001; 1:uHu+hFsPCG0KnTQvpDkvzUpdWaRGKGm/BSsLFo8Z4GsC3vv244Z4JoQXfBepMMdPSuGfOMB2/uYl4N5dEhimxC0181/0yhDWRBgvU1XadL8PWmSqtfKkNWKuGweHjbCf8BvBUAD/F+oeKqANVYpR/oQq3UlZQ6IKRqb4zcFqRoY3eSoT56UsQPtL2Wvck4eLTmmlkazrFbQWC5il8j26V1JCf7wgUvX8AfB4AAYdYIe5a71fLDMjG4yoUMLJpEkX5OD+/Us9kexiE7DeOh+nkKcsERjKB4BNTsB6hvmdV7luKn1Vkz6cVpnfOVny9ESr6RpSM6CTXGApK4cHbMZafNvqjXdTG4yflCp+/j8oFZmGYzxLgQUw8olVr1zv/F0H3v/334MQTIeiU9EUwG/KNp0K8mYqX2QA+2T6RgVnhtnOqWvsEaJJ7cfpNSVrUasYqcanVathkvfVlCOsscavqhF2mtWT8Zy/I30AY11yIYs++z96Zap7oFmFvRam0c1m6F3Tj5HM5d9CdSVd4UkmCjWIlzpzl7lLlSoBTXuzSaTSfWnlI947X1/dFtf/IWWj MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 1fd4a656-de3f-4e56-6113-08d349fa2b58 X-Microsoft-Exchange-Diagnostics: 1; DB5PR05MB1525; 2:tB5Dy5j2P2pOA8yGw1kDkS1l9zw1p3/WuonJWzCc8K9CxEVt817hCYSdDDB13+kKWqar+Qd4/6Sn0qJxe29rBYligT5zKkOQkpHrz8nWKikSu3SGi6VHFZzIqrq3ZE5E8hJTOdKKg4HXsfHISY1w/QnoVKytRLFW/rOlekAZSL8tTC071IRuRVaZyFzWawtK; 3:LJHn3jd1I0YzOgRztYKpUFPcZmPV6nmpElGmRv5a0euH7S7vVMvTjOQtJSCk4/tWxnNeM4/DgYXNfVYT6BD4volgIrqBTLNs6breG641jiFMkhvsxPydHGBDBXHi6jzYVc1dnoo3darM6Yk7AwQqDgSmRQo7CdWgbLQMxIkb4JEhM6UUP18GuXt3B/tYSmN2k8D7aFQ7r4u1QW1ngkQFsrJMnn1jtNQrXiuz/1OpG3I=; 25:X5MteleVyqUv9nI+tGU3piaoHCrxszgo1+TSf7pI/lhmeGXDVHj3Ml7mgpMrDZSFIt+v4g9jg2yQ+mqWxgUJt0A+ka1ZlvQcEeT7IMqY76sMt3LQ/xa0RnyQmGSjaSaJt4i6XcxirLDx1pN4TU69darCCfEpsQ0Wmx+lo+zYXBgcGtRKXL6s79zLkzApV8mZWVogGhRpXkcPwOA5JR8VOKMvprsAe+H0jsNx0QICOQuuTPQI/zhw4hLrK+Em9rl3We6cGe+iPpv1tTm89pq5fKjJbhp9zehWwrQdMep/4AF5Da3qvkP17m5rTCM+NCRNR1Ly9t6MSKMYM8EuWpwkoQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR05MB1525; X-MLNXRule-EZCH-Linux: Rule triggered X-Microsoft-Exchange-Diagnostics: 1; DB5PR05MB1525; 20:Rhv7JmaRPyk/FU4RJdI22saUNI8cGY7uU6U6As8JsEjjGgQ3b/o5KkFMs2K+I4yBwjOPy6bqRxll81pjLsJNww9tvqu9dR3cAnieyuWL14V7meJFHYWLabaUFk14K0YlnBXuDfnp0IFBx7wASadP0PwBKUEx3yDGTxNqL6l0Q9i8fbKr63DunX8wRVryY/NdScX2YnGBjt5U+4Cd8a4sr0x5xjHBDIbMSwZyeSii0GnRSA1Z5dgtlqqzRMHdvhcaMLilTK19WjdAV0D4khu8JZQY0fYlInI31B3gtGLemomcakKjmsND8IUukCKrPeY3JHEX3bvQuM1W/iFlK5dTFh1Q4MjCH8l8pK7b7+pK76DcpENj6d1GxtKIt2Ks2yDaK4DFi1CGv+soFQZHlhdlwzPFk/qohmlBbwUuU1TAXxvU6n++NjSzN2APCzJBSzEP82LJM1yWveA59aPUVf6SQNbwGh/PTvj8d41qvXe12s89GV1l7Bnl9yzCSH+Ic5HW X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(13018025)(13015025)(13017025)(13024025)(13023025)(3002001)(10201501046); SRVR:DB5PR05MB1525; BCL:0; PCL:0; RULEID:; SRVR:DB5PR05MB1525; X-Microsoft-Exchange-Diagnostics: 1; DB5PR05MB1525; 4:Pcwq0OsWPsR2V0BzDXyPLJlVxuBWeiBDKZjP4ccntonf3lJm6jsoUXmF6UTkTLgzb0Gp772wtJrH55mxU6jb7+BdLXbhy3ibiJe2MZexOQXk+oC1MIDZCndHBniRbTtBpR7uDy8MmL81UjgtJGpwwy7Ea1b4xBOIm3KW/Zhnva4P7Z1lV+98UVBx2Ms5WCT5YQG83yXzgp4r/jWMQb8Ycxje806Gq66crVJ0CK6hfLT12TfeADmSwfk6cEiJH3Li+u994Ca82b/2JwEkAkhL6lmZEdgxE4xEwG4EIgaaETJS4AtaBjEmOFJlvDzoC+Y9rt2SFLsq0eunfkzAWgpWOtqj+pDoqjuvIgyiEtEYhhGpaE4KPVynbzQ9vBFnbha6lNl3zWgQlMJMTpgDAWr7J2XGBL1pKarbcHOm8L9aNf57lXW6GzcK6Wk6xRNMKgT8s+3SDGmLVE4DuaXbW2MXKg== X-Forefront-PRVS: 087894CD3C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB5PR05MB1525; 23:P7bYjooLPvkdG1ojJMkKFRJWGV20Aw5QQ7mp06hJ3?= =?us-ascii?Q?qMcDZ0Q2tTlQqZB7hmx/kdWCF2qzrHdjzqVJ/x7R6MAjdSwuUGMUMHBSxyRR?= =?us-ascii?Q?cIbhi3MOraRKR6E66T/BSYFayenZsnNxuiGA4hPVjz1bSL16h88PXlAgq3mq?= =?us-ascii?Q?Eh776Tzd7R0SYO5xFIDu7ggb+vQv9nHCICITHCaYk7a9ke6wsVK/AarI2DSw?= =?us-ascii?Q?ZR7IDGYmFlEyk8zv33WyB0eucaWO3emkOBOB62zI6aNRPNitJtwtepAGf1U/?= =?us-ascii?Q?Lg9T2wQbiC+atR748JDbysNWdySnZacTBN6OlPJGgNv/llc8oXLWCyt9QI9L?= =?us-ascii?Q?F3WSBYiHu0NFwu1Q33CLRfWp1RnTXYmFpL6RisX/qg3QMlfpX3Cryj5Ru/rJ?= =?us-ascii?Q?cRy4P6Lz2rMpaDqgY8vibiu2GPmZqK00PlKgc67Mmg20cQfXVb8PUlEnffyV?= =?us-ascii?Q?M3O+96jOaS51DGxrlK9gc6DkHFxioY4Q/tnIDjreIyl/IXlJUPFmzoHinZSN?= =?us-ascii?Q?3LlGFWX/35KDtZcbNp35SdeuDfgwfN3dQDb/jYcf/F0lSVTDKiewzNvudyrQ?= =?us-ascii?Q?AFaH4JSi60HqqHsOVJgoVWSuGduPSt1fXc6grymw3Q2EcU97HcKABKni1UhX?= =?us-ascii?Q?U2VJaC6XGu3S051YwZsLdz9bFnFyZj4iRtmuxmEIq88MR6sV6DCrvktfVRRW?= =?us-ascii?Q?OBFsYlJlxuzbDd9jBBMF7mn5eiM4v5D0HZWsaBG1mkC55iAoELfQkv4c9TYN?= =?us-ascii?Q?zyq6S2AwibytitOScqbUyTKL1nU5xP9SUHwskCXftLaDWlSkDbg/q77zWW1s?= =?us-ascii?Q?9T9K5bi7asRHihBxYsTx4ivNmUR46gTAIqO9o8p5v6Y6j4+eA0kdhcCJWiDZ?= =?us-ascii?Q?7owQsupv27cWspQAMDoN0ICRI+qv8ivViVcGi2gvtcumhdnzH5PWGJYEO5lC?= =?us-ascii?Q?abJ7CH879oMTgc0tiXH99BcZ1lWGnl/OGcD1EIMLRXobItYuD0HKdTvcKFSz?= =?us-ascii?Q?xFuV/LFE+j7VbXZc4Io7YiD/CITZkmXu5hbytfszLz3oRrXjMQgrSbCREbF7?= =?us-ascii?Q?vbwy9E8vzN5IH8WbMSnw3UgbWHhYxjy6qhgINzfZOzOqXlha4zqT+wUBZWg2?= =?us-ascii?Q?Tp2l27bpl51W9riL1WCorqmWwz0Rd6HM5rwxmMS/0fPczLT/RT2ROkJUcxcd?= =?us-ascii?Q?ZWma7stUcjd80cb7d051M8KGPx3g9xpRlux?= X-Microsoft-Exchange-Diagnostics: 1; DB5PR05MB1525; 5:1QpNm34i2A52th353d51qkHHOA2ddHStUtXlV+opwnQvPmRxyEN4tPkorgKRCftGhyzLXuzJfi73YPtR1M5naFg54hSwRpu0qyzzRPOo0b9bZipMBjC8D2MyVpxWLWa0Lh7Mmnfpverpe0wFzJqAfg==; 24:KLbR9c5nvtFwb/kq3xyKnfU4phEiJqSXqKnLq+TRbWnORvdzk84cbEROmwHfkGUmLZrr6LZqwW5YmPG58TIrj9BFImSOpy0LpP0T3wE9oHI= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2016 22:12:00.3023 (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: DB5PR05MB1525 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160311_141226_584550_2D3F0C0F X-CRM114-Status: GOOD ( 15.60 ) 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=-4.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 1f7f5a2b61bf..966d0d4308f2 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 e18c48cb6db1..1f172f8afe47 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); }