Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759714AbcCDUDM (ORCPT ); Fri, 4 Mar 2016 15:03:12 -0500 Received: from mail-db3on0054.outbound.protection.outlook.com ([157.55.234.54]:17927 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758743AbcCDUDJ (ORCPT ); Fri, 4 Mar 2016 15:03:09 -0500 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=mellanox.com; Subject: Re: [PATCH v10 11/12] arm64: factor work_pending state machine to C To: Will Deacon References: <1456949376-4910-1-git-send-email-cmetcalf@ezchip.com> <1456949376-4910-12-git-send-email-cmetcalf@ezchip.com> <20160304163814.GD7886@arm.com> CC: 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 , Andy Lutomirski , "Mark Rutland" , , From: Chris Metcalf Message-ID: <56D9E9E7.9000503@mellanox.com> Date: Fri, 4 Mar 2016 15:02:47 -0500 User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20160304163814.GD7886@arm.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [12.216.194.146] X-ClientProxiedBy: SN1PR0701CA0067.namprd07.prod.outlook.com (25.163.126.35) To VI1PR05MB1696.eurprd05.prod.outlook.com (25.165.235.158) X-MS-Office365-Filtering-Correlation-Id: 1ac733ba-5c1a-4b43-f659-08d34467ff17 X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1696;2:g+UT5Kn0dwe2x6pxtDZfu/FzRO7HR+fw/p38a92pK+lU0M1XYd8wDMfmpGAqAFFnhFYqe9fkL0LUXmGsMY6Bf7PH7aZFhAp/rmhLEiCeF1HIIqJC8IDLtVQTPUtwTOUkU3vQjSA6mIZvyltgRSrnk9MElL3RSEV03KdTZcFx3kwbk3fG0I1Ytg3CIh65/foc;3:HsOQDkK9Hfb6XbBPUirYUJpkDBofRF+iKnziQZmP6DCmvnlNw+cTStkV2tfQldILnpmCUvhEFNGLJU/oksm83Jq3lixM3DldTg/DB2dL8LSLD19oyAoBpHQrhj4LMucQ;25:t6HXSgwRZenpnCEdNTF59dt4KugyDWrCVDqaPrbppSgdZjjoJbr2SbREGrWgZ2JRBHKTyIh/1uc9lJ15URhHuQOwq+Z+0+ltJPLyLab+xi8pDxz8gaBVplf8fcDCKQWK8389uAGFM12A8+FrRT9JYFxvfz42Ja0TMNU3382OHlA4HwzlvPNXEK7t5LBWaWp05ByD11KLvisqb+/BqK39/MRo6fEmZ8EeIWWTV8l47ppoKeZdfA0REaivPlwUZrXYXWn8HMVEM9ntNVwhtNzEaxod4wNCmbFlyL4eGjbXA50cvgu/gVIk1s8U6fgcVkNyYwl6fu8pedWDeDfkNcNKGg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1696; X-MLNXRule-EZCH-Linux: Rule triggered X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1696;20:hCm6aJGbqCX/c10trBNpe72EZD0m3xrCPfTRU4h03JH9mMFVx6wf3qjspq0MVcV7Wx4bcIa8ubwgBycKW+p7cT1oMP9s06rgLmCnYoRiA3noWdttlxftEbEbbaglKNe20OEjK31JmIwyq908lGhIlPR5U73HjP9RQWshZZYXAHG0c/NAUpcE/RbY7wHmTjqMAL0lHu0CRNgd52DewfCqGe5i2jjbm4DLZdc3mhPuY2bhEMdgtohvg0rmBALOmEzsX5ysp+olhUUcFFtp7xOaExqTbYs3Fd372VKW9s8w0DJOfONG0UuAJp1heFr+vH0JQRR/wcJf/YNNZLrUokV5WpwOrk5SFftmRSoTyg+g3vKwamOzhy15fopt+grI1AQIpxDl666PoRr/DesyrBSoCADu1DaGX/z6CgP3i1i9jzbjN4d2OI3nI+mUVnUScVz4F1NsuCw08+VJjfJqKeXukSICko9UHefQyHD7hJI4i6N7I+tukFAbcN+WnGnaILyN;4:3eAkp02/tXxn+Ix95LKhdIyt3nRUdEJ9tnHkKod4FfaqwhKjnS0sPiwrUK7r93FqRsf/2BucssdKoN3mzYcEtzcti3DIBYP9hRWtXcZgnipHGavwEF3ZNW4xSkccqVrTzK7r++zUDmFNhAmkd3FJ9qxUm6sfq7SNUW0gbUhIXaj3kaJPPlecq+p62xkS02sksQIt9QGztJJDnsXQNgkNMMhGLFOVeKanf8R+l8LwkYK5DdLVNPA4Ey1PiP9863tPstHyD5B1ChO3+MKqe4tXN3FRaurD+bUYkuXqlO4sd+WyF32bx+CCo/aL7/hQq8iW2ZloKMeUWksppcjp3EG+to0s0ZZFLwNKuy1JI6eeA6jjrItVfwYXQIEylpfJDLa5 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)(10201501046)(3002001);SRVR:VI1PR05MB1696;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1696; X-Forefront-PRVS: 0871917CDA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6049001)(6009001)(24454002)(479174004)(377454003)(575784001)(86362001)(189998001)(80316001)(19580395003)(15975445007)(42186005)(77096005)(50466002)(110136002)(5008740100001)(5004730100002)(81166005)(59896002)(83506001)(64126003)(2950100001)(33656002)(4001350100001)(65816999)(54356999)(122386002)(1096002)(2906002)(23746002)(87976001)(50986999)(66066001)(4326007)(87266999)(76176999)(586003)(3846002)(6116002)(230700001)(47776003)(36756003)(40100003)(92566002)(18886065003);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB1696;H:[10.15.7.41];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;VI1PR05MB1696;23:OfSBHToAycaGKs9qqk2A3Dk/FrAmsW+ZH08ch?= =?Windows-1252?Q?NUMHVWcrQgDJDGzNUKNqWoC1D6dGZfNpDN711kNYOne/+DujfAVX9KTa?= =?Windows-1252?Q?xeQcY78yUlcR6M0hO1BFrsbDJSE5NiQOEdhNnbo7yu4j17r2TEoWpGPe?= =?Windows-1252?Q?w+HtGJE/Q/1ezXooi25LTYUM41m5qVxo7QutkJwV4YPeVvdDx00VkcLo?= =?Windows-1252?Q?LiRfZV/r764xIXy1NDHNVI/hICTm9cpcXLgULZQtjI1cPNmX+yf+3y80?= =?Windows-1252?Q?j4xkq+8PT7JEzrmGt4JQkvNPdCzfYGsB3DXsGd4WPI2ZPfxjFmot+WwG?= =?Windows-1252?Q?ptakzTlAxI+xci7N720lMa5MV5RZfi4QXBfYJt2NuwkHUzNm+V5Cxu9v?= =?Windows-1252?Q?GOXaQN9DIQ9mB5DOYFoAr9GR4krVSPZPOsnkxy2y72z+EYMY9vhJ4qLj?= =?Windows-1252?Q?yHo0mPKJmHqgcGdMb22lPLku4pUOSR3XJ0vZJOLmX7ygsuDLynpF76/p?= =?Windows-1252?Q?NMDyeiJrUS6my4+PHe2Pmf0wYJZQhXbLGCQAbJcqHDSJ8gh8M5zXCner?= =?Windows-1252?Q?dL9DrTKlME6ByIzT9HNdcHo4VpOTnSFdq3hkNLEEzcRe5Ws5O/hP6KSo?= =?Windows-1252?Q?+AW1naauplGbmgA/do4ZeJiVv4zAoqc01X4/nmVvu/N4eaQx8Wvay4NG?= =?Windows-1252?Q?oLmM/Y6yPUkWc/AFdHqZ1KfdTpBBHevLT4yPLt0sDw5pnM/p//+e3nJc?= =?Windows-1252?Q?nsGT/Z/gDap6BIe/hs10tSRf3AiNjNhvAyylxTBx129HlytKVPu4DO9+?= =?Windows-1252?Q?2qUYkP4i9tD+E2dZvpdsQRTaKb5eeeaI6TGx1wAVXKV7HvQPuLgZd266?= =?Windows-1252?Q?EHgyVGFz8BzLbqEAMSelsZ31Ia7Hg4uCgFLHy4RYxjAH8s29ghI29JD6?= =?Windows-1252?Q?cshYXgo1r9l00FUniOGwBrLebBq1rH4s5c0NfWEZYiEAgGXLKQDpuLhX?= =?Windows-1252?Q?61g7vKV1GykqOhIZFIbi0pGhs5g4US/H1Iv8PtgM5Q45dDvkOe0FjUJW?= =?Windows-1252?Q?lCuo0kw923eJ2r30y86OQMN57Bb0hP3UNM9VwMb4Reb7gfrBJbza651m?= =?Windows-1252?Q?yC3l+u65qwtqeBt8C0q/lqwX2ArYMMcOM47fGjYlC+7FYAiUhv/vmpsZ?= =?Windows-1252?Q?pzvta63+2a1MX0rbq1WKTgmE23a3IVZqh4vNjwjHXTEwkwdJag5xws7s?= =?Windows-1252?Q?1oa/L9S3d0DsH2N0R0ei+1kN36oXKQfoKsJwdwImmuO+iVec2KXO2mth?= =?Windows-1252?Q?1G6?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1696;5:f1TJueq4enYgLmihoPvLgrxm41Y1vittkTBbRqewoqem9HSYYngw+g3cQ6LjPN1MDLAfstmz2XtgEHSXgv2xT/ff2a4NaJld7ECy55opnoq1Mf/9VT6/QgHwdOCKLG9dpynwhSPxCqEl+zFVFiPLdQ==;24:MaV1WcfznlZPXxDVwDk4WL0lafvAtHiK1Ia63NPDUZoca85Rp+tqDNKAdrTucltqK80Zga/8BTdW/CoriG3yFOzIv643IrtiNOROHKqsUtE= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2016 20:03:00.4420 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB1696 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3353 Lines: 82 On 03/04/2016 11:38 AM, Will Deacon wrote: > Hi Chris, > > On Wed, Mar 02, 2016 at 03:09:35PM -0500, Chris Metcalf wrote: >> 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. > [...] > >> 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 > This doesn't look right to me. We only get here after running > do_notify_resume, which returns with interrupts disabled. > > Do we not instead need to inform the tracing code that interrupts are > disabled prior to calling do_notify_resume? I think you are right about the trace_hardirqs_off prior to calling into do_notify_resume, given Catalin's recent commit to add it. I dropped it since I was moving schedule() into C code, but I suspect we'll see the same problem that Catalin saw with CONFIG_TRACE_IRQFLAGS without it. I'll copy the arch/arm approach and add a trace_hardirqs_off() at the top of do_notify_resume(). The trace_hardirqs_on I was copying from Mark Rutland's earlier patch: http://permalink.gmane.org/gmane.linux.ports.arm.kernel/467781 I don't know if it's necessary to flag that interrupts are enabled prior to returning to userspace; it may well not be. Mark, can you comment on what led you to add that trace_hardirqs_on? For now I've left both of them in there. >> 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) { >> [...] >> + } > This might be easier to read as a do { ... } while. Yes, and in fact that's how I did it for arch/tile, as the maintainer. I picked up the arch/x86 version as more canonical to copy. But I'm more than happy to do it the other way :-). Fixed. -- Chris Metcalf, EZChip Semiconductor http://www.ezchip.com