From patchwork Wed Mar 2 20:09:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Metcalf X-Patchwork-Id: 8485201 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 C61909F96D for ; Wed, 2 Mar 2016 20:13:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5400920382 for ; Wed, 2 Mar 2016 20:13:16 +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 5F0D42034E for ; Wed, 2 Mar 2016 20:13:15 +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 1abD78-0008GG-8s; Wed, 02 Mar 2016 20:11:18 +0000 Received: from mail-db3on0091.outbound.protection.outlook.com ([157.55.234.91] helo=emea01-db3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1abD74-0008An-A8 for linux-arm-kernel@lists.infradead.org; Wed, 02 Mar 2016 20:11:16 +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=15DW9yU4eW8t8qP6I0adkCYWsJ795aG06vjzE+wU7jc=; b=rKcucktHCEHK2qu182ZO/IdYP/R4QT5Zq56mVbtn/a6aRWr53Vo4wtnGHzYNG/9VJG87bURIxU2Qf4qSrJT/2UxQSKCahAV6xDpXjsDykiMbpzmCYcSZX5I3yBC+PipwgffRJqBh4QcD6n8hw2ZMRi8svb3jR0F9Z87nTcnhYPU= Received: from AM3PR05CA0057.eurprd05.prod.outlook.com (10.162.114.25) by AM4PR05MB1523.eurprd05.prod.outlook.com (10.164.79.153) with Microsoft SMTP Server (TLS) id 15.1.415.20; Wed, 2 Mar 2016 20:10:37 +0000 Received: from AM1FFO11FD017.protection.gbl (2a01:111:f400:7e00::197) by AM3PR05CA0057.outlook.office365.com (2a01:111:e400:52b7::25) with Microsoft SMTP Server (TLS) id 15.1.415.20 via Frontend Transport; Wed, 2 Mar 2016 20:10:38 +0000 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; 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 AM1FFO11FD017.mail.protection.outlook.com (10.174.64.206) with Microsoft SMTP Server (TLS) id 15.1.427.7 via Frontend Transport; Wed, 2 Mar 2016 20:10:36 +0000 Received: (from cmetcalf@localhost) by ld-1.internal.tilera.com (8.14.4/8.14.4/Submit) id u22KAa9G004983; Wed, 2 Mar 2016 15:10:36 -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 v10 11/12] arm64: factor work_pending state machine to C Date: Wed, 2 Mar 2016 15:09:35 -0500 Message-ID: <1456949376-4910-12-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1456949376-4910-1-git-send-email-cmetcalf@ezchip.com> References: <1456949376-4910-1-git-send-email-cmetcalf@ezchip.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CPI:12.216.194.146; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(339900001)(189002)(199003)(5001770100001)(107886002)(87936001)(575784001)(19580395003)(5001970100001)(19580405001)(189998001)(50226001)(36756003)(42186005)(2201001)(50466002)(50986999)(76176999)(81156011)(85426001)(92566002)(47776003)(5008740100001)(104016004)(229853001)(6806005)(33646002)(2950100001)(5003940100001)(2906002)(1220700001)(1096002)(586003)(4326007)(48376002)(106466001)(105606002)(4001430100002)(921003)(42882005)(1121003)(2101003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB1523; H:ld-1.internal.tilera.com; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD017; 1:tKsb6Dk/1Ge1JaDPAosyOhe7jPUmdXnGH5lu0ghBUMzpHJuUIGQ4M638gz+/bgK+Sgjg+iJc0hOyyibTpVGBMEI5o9fpv4LleuczrSO50BoG/o27U3mKN/YiuPvtv2x4tG1slJjaK8OW+hnstZTgrA79BUZ0GwKKuyB8C7DcJ8Y07Qo/G6rz3qLBg4Qe3OtUi1Hfyg5I4BIUvFHl+5EdggZ0256V+b+dFuOCQatwKf4nKxwEPD2HTfmCRFbf7Qvk3S/PRXEvPYQL2HxGheDc9F2OLq2olqDGeTmtf7/8Z8+iHfmD42vZ1Ky8/OtvAwlWlo5SffjMFJbCiqLTaywSBngRzdIGTwGvR22zV+KfZLHu67/sxjGxjLwOFTFu+0v/XSS0hz5/1WljYf4V/Ib4Me7ERz+v1lsPpGxbz9lxskzp31iNRBmDw64LKj9kftBjDn0+ZdtKUjLQCApiFfAJ+H1OdmRgFVp8tiyGZgqidXnPqSdfVcMERTbT+y+SZEFo MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; AM4PR05MB1523; 2:yTPdHczfUI37A2acEdFGlpyROCdxxthJbqprY+81Cj9TggkvBRMmVd7I/oycmta1YvPUrkE9AFwIOdJsT4iuTiaEbH8d3V/T8BT4FSI9Salshftb3rd0JdduJa53A9s0mcCZmZP6NDQVs1nepAlIOw==; 3:d5xXg1/Vaf8ZqUNgnJ+DIZQDFv7H2yhJpTuiiAqIeS4dSMLwq/5XKxFmb+6kbHEFuDMGcsXfdu+sP/aoADKw7SZPdrNTmJmpl6btshXxmJvOK0hzEvnd0uDvZkUxXm8rDXFZBsNwKX7uOU1KAmyZmQ81gpCuenhDWGGHK8uwDyw=; 25:9eZO75ux/dzJ/DGMAV3F5y0b8pikB8fmKsG4wULDxEoIvsCjVftc88fyD1+O2yPez+tmPiQ70+hybgtsIxcS32v92uTfoPOpRlyXdr2H9g+h8Cn0O3wit/yA4WTIQLpqn5jI53Y7DlBhxvf1qG7D2SPkIMjFPJaDThMKsePCTiAI7GRb7ofJdPT2MOuJqZNGUr+pPmkhhNS7XqCrVen9YyhIiwJHd2Zxep1rTEqxvZ60DX35gW7hg9Kbl54t6Z2gjWxmLtiMP1cXcQXS6Cy8cakHUna2Pry+M3m44e3a3qZsMfEYZT/wFaCT4SHKPh7ulg8O0Nd0NsVvSRM4FBz93w== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM4PR05MB1523; X-MS-Office365-Filtering-Correlation-Id: c6250f5a-b0de-43e2-c14e-08d342d6b872 X-MLNXRule-EZCH-Linux: Rule triggered X-MLNXRule-Acc-Dom-4: Rule triggered X-Microsoft-Exchange-Diagnostics: 1; AM4PR05MB1523; 20:geeqc5l5ImRX4o19rcCjJ9ISPwy4SXG0jbni/a5Yur33ixkJnBaGd7chO6lyDtJSXVewwCK1jk7iWrI7BtnXDcZXa0aaalHy0C9+5mNy5ospDwQGoB0ZYxTxtofvsHLEeA/fePqGGfGTfHwdH18aObFWdlfT4sqXfUix/CCUKnyGhat2eLjKRXOmHH872FIXlW1bFEZ9Y6j1MsAIo5Tt5c6gopKusejvZ8+4FFFyHulWjfQ29+Uany8ysDFM1Fs+gxUQNPO/ckn5xzZnOCFW11Imjih110N7fRM8l8Qe1yAblY0YAtaV7fUFj6CY7o5RJesPMXs5X9KmLBXZ3gGYbKzi+hqy4cYe8/krPWN9wYD4EKPaZXIqKymts7+8fYPI6Z+MuvKLXNGAYOLyFbQgaOsD1DxnO6MjaINlCoNY8jJvyenOrbnjnVthTENZ+CrcoNyqLsZqUCRuQwUi3E35NSQdqV1u9xFJkOeITAg75fqRpwLPBKz++9sQv44XJYibbnD4JE0xWcEsROaHAz9CshPggjra/qGOYIQVknEEbHYprL0FOjRAJ98dymUKaWj3Vps4HQwfCP8efyTOKwZuXevMuzo06B7TN4EIrwnkmrY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13023025)(13017025)(13024025)(13018025)(13015025)(8121501046)(10201501046)(3002001); SRVR:AM4PR05MB1523; BCL:0; PCL:0; RULEID:; SRVR:AM4PR05MB1523; X-Microsoft-Exchange-Diagnostics: 1; AM4PR05MB1523; 4:1xpzYMiC8FGO2HswQalJFlBYbk07WhPMvRaQa7ivfwIyH5w5ph/I7jcvfPdHL1OcoPxfguVLiByeKhqNjdw/PA6aF8bTiSpEte+5iey1+yUsnxGshGhh+BMQrXtW95h5NvWsLrqHlx0N52oBc5NhlaDPfG7CxSZ2Ayu1Xx2/V/h3q76YxS9BFwzf+TkKNmr3g4HsnlR6Vtytxwdr/Z4mFUHqaT3yoPHbiIxk0uY7lOPRhm1/U5w64xdc1OnTg3v4c5UuJJD//pkyj+qUJerR00skOL7suuu66wQ3usXFDN5feG/uRV0/jDnTsOBqvK/3rmOhQp3esUG0ucIxeUbTqtu0pRc+sm9PzC2D1KOwMqLNTGF5ES+HRQ4IDCGHwjMNHG7ZV7mOEYSEgX3fsCbLE/U79+3DzQrl+B0OboMym7L2sT4B1lPch/tc7XwM3UCpm9ewP4KXKMl+pI+mGJIjzw== X-Forefront-PRVS: 086943A159 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR05MB1523; 23:N4GZCfbZYzwPWy+arPJ4nce2YxnM3EDGLJCRYG/S3?= =?us-ascii?Q?zfuqvQZZLyTu3ysomX0ACHrDPLoI/pYrSYWyNN0PCPSU2+CzTLWm5EYtvBcE?= =?us-ascii?Q?3KcTm5oPG+SMB1IckyupwQAMh2RyjWMB10+FMxrcI6WbCWYxTsnjzmwtGwa0?= =?us-ascii?Q?03XZwewx1CW4S2HOtwGVhc/ROj5ES81kMADPZF1B59z568jtbgPES7vZdm8T?= =?us-ascii?Q?jcOIgRmbAAtPrPBL8oZaymI3/aEkQfrOfYIunjvspDyKN24wNC/GjDqWV1AZ?= =?us-ascii?Q?nT47OuTgxbS9roZYmYVR3LzcVyUoR8euo3s0S4UGo3ifL8qvBdD9UhYtEXAB?= =?us-ascii?Q?p8UZC4GO0bxf3qq+tp6EAEcnDPSENFegeSux7auGzcWwmiagErUCzaL/bOj8?= =?us-ascii?Q?1hj+cG04TDrFTlixC8P5nBiAZ9U5A0o+4qXBDe+yvhq+qsbsscwk1zikJ7RX?= =?us-ascii?Q?FSb6HuCPNlvvM0DxGEaXixFKD8huwp/GsZaTk5hACpXbXA9ndVJBHwzKMdpq?= =?us-ascii?Q?QlAjIPINe/Tp3Y/6i5RAvr9anJQDSDK63LF9E7u8j9kJn30k2yby5ZK7V0oy?= =?us-ascii?Q?TUbSbxvjhgXPSS6EELsUHE0iwjTSB9Fqezn9IgApjbcsfwKf2xdxI9dXTHWD?= =?us-ascii?Q?f/BroTk39TEbV/M1CGxPJ8FeX5/QDxFq4WWqcaSGq7pm1xxz8qtAsuXzC2ws?= =?us-ascii?Q?sTGNwxowZSUHkpW0fGUYWfvwRx5y9CaLYn2LtirT3o1ZIeBzVIcmhi27shxa?= =?us-ascii?Q?vM5F9Q1xGUbWTClnTavo0q4SYTcR4q7uEZErk5LJyPuPT0E6wT/5fscg7H/h?= =?us-ascii?Q?vplR1pE1zv9ilFbP30+Gjba2jx5INthaWsSMdlg+aikNJOI89/FG0SoFZ1gE?= =?us-ascii?Q?U8HiRpxiGkOfJBvKEun8YnCeBLjvFBNpiNu/P/4jRIF8NOUZWuNVGkDV87qR?= =?us-ascii?Q?wSC/tfyzy5k/N0Lor1oplZ0wC86yj6VEevT4/Vw+zQ85qDUcWJdn6WJC3qid?= =?us-ascii?Q?QYDAfKgXmAVEO+ZvBGI4qckP35Sh0McvUkpVkW653l87y+g3GmHNy94oqIQg?= =?us-ascii?Q?B24ViJHp6QBcFXp/4KcRYti5QIWGk3P2IMTS/dqzDXDsTdZpxL4xpnvvGHKq?= =?us-ascii?Q?NkOakYGVB1/gGVzw/3hf+Mo7uGBIUduYTtf56IbighmOM1raXSXxT+FVsOUF?= =?us-ascii?Q?qdfGUvlgg/V3BmVBBSgCUziOoME6rgdLrM9?= X-Microsoft-Exchange-Diagnostics: 1; AM4PR05MB1523; 5:EXaPqNliptZcefxDx01poWD8+xcCvdj1FgMC1L/CEcgZDArk8xpZC2nKv70KU2cRYIuJtSACAViWwR34g1X0dHpeYtlCELyWmp3+nvy9lb9xxpvmYqbWWjjZKiTozH/ZpZh3FBLRo2AFuPgpgGWJbw==; 24:fXqHK5znpUfwUxfPg36GXh8+4W1ITvXowk+XizFyouGZSXgX4W2bLKb75YbVm7z1BJR8Wr2rHXfNuEkkrGPyVY9+KxdW7zDuPKXUcDXALso= X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2016 20:10:36.9966 (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: AM4PR05MB1523 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160302_121114_853826_55101C12 X-CRM114-Status: GOOD ( 13.77 ) X-Spam-Score: -1.9 (-) 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 | 30 ++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 16 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..3432e14b7d6e 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -402,15 +402,29 @@ 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); + while (true) { - if (thread_flags & _TIF_NOTIFY_RESUME) { - clear_thread_flag(TIF_NOTIFY_RESUME); - tracehook_notify_resume(regs); - } + if (thread_flags & _TIF_NEED_RESCHED) { + schedule(); + } else { + local_irq_enable(); + + if (thread_flags & _TIF_SIGPENDING) + do_signal(regs); - if (thread_flags & _TIF_FOREIGN_FPSTATE) - fpsimd_restore_current_state(); + 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); + if (!(thread_flags & _TIF_WORK_MASK)) + break; + } }