Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933284AbdC3MBJ (ORCPT ); Thu, 30 Mar 2017 08:01:09 -0400 Received: from mail-sn1nam02on0044.outbound.protection.outlook.com ([104.47.36.44]:10496 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751217AbdC3MBH (ORCPT ); Thu, 30 Mar 2017 08:01:07 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=vmware.com; Subject: Re: [PATCH 1/4] mm/vmalloc: allow to call vfree() in atomic context To: Andrey Ryabinin , References: <20170330102719.13119-1-aryabinin@virtuozzo.com> CC: , , , , , , , , , , , , , From: Thomas Hellstrom Message-ID: <2cfc601e-3093-143e-b93d-402f330a748a@vmware.com> Date: Thu, 30 Mar 2017 14:00:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <20170330102719.13119-1-aryabinin@virtuozzo.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [155.4.205.56] X-ClientProxiedBy: AM3PR07CA0125.eurprd07.prod.outlook.com (10.165.223.11) To DM2PR05MB765.namprd05.prod.outlook.com (10.141.179.14) X-MS-Office365-Filtering-Correlation-Id: 8d2f6ca0-40c0-4a9d-3feb-08d47764710d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:DM2PR05MB765; X-Microsoft-Exchange-Diagnostics: 1;DM2PR05MB765;3:kRwM6TdzHkdjOzLOEd+GmpxHeKb5FtxiUBKhajcLvsRH5BhvVPICK8LDSjj8Sk8xWQ8kgn4m+qQgKkRw2zdc0PiAxxI9PXmwZ2h45U8QqThBgLhtNStIOPa/J1bTIN3w9Q2aRX9E2BtLQeROpoVC3//MZQlRaEekglsv+3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W8BPzWMAghfFQoJRxS/eYpS1mfVTwQXzD9ip4Ot0lepJ0fMcA4fDUmtD5aSIvSi3SiYuGw5PrXpr09kkSIQPoqdEKf4IDnD3D40lGYpGN5RZ5pUMaBQqow35KzGVq+/GkrbfhruOBsIwV0YaOckmH8cqv1jh+GplUteCuLVcViTayuIqgZ5nBuRzd464VuBogX1cCK3YThzLz0EmR7JGwz240rRVp3A31SbEgojp4WlAtWyoki41gyoPrQTqtEgPS6Jr1C+hbJEc6ThJnw1Q6qsenP8YlORAOHCc//mX2wdqHNhxcJznR2V5dcgQqwnPHnqRMWy5WG/fbzuLMcmNsq92q8/vVk2U84nvy7koTHLdbZd4wjvV1yzUM5fT/9JjWfrKOwpaZwlu3fw58LyaIl3H373ycjjnhBVmS12/W2cTnH+bOjmXLUN X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123564025)(20161123562025)(6072148);SRVR:DM2PR05MB765;BCL:0;PCL:0;RULEID:;SRVR:DM2PR05MB765; X-Microsoft-Exchange-Diagnostics: 1;DM2PR05MB765;4:nevr/3VQGnGVFSCoHsijQkDkpV4OaxhVcNTOULhs+CAX/LCNbWZLeHe6xFHiwu20Z7ThIN20Vf/s8UwCFeMYVPwz271jsRLl8cnrAMfYqo/NMoqrT3SBUP3OEXzaDttPgt+XMQmoCBzVJ2uttDckmwibL+VTJ1fJRW+D9qa3nnFOheMe8vMUvgEVUQXhrgLsmbSJjAOM8mz/BZnH54aLIsWUZJPKzwxFr94WgCxcU+vFBrkiI9kCk/1dn9wwIZjGubDhxucMhHhObsd9gV6tfZn++8VYlMaWXGtT92LP5Ix81OeyuOCoNeGTPlI6x+f14I44BxfLO5mwYBULNJf2hF1iSpZerQJHIMH4vs04//kXR2B9D04DEj2Yvx5smkdOZo/dfNpxExukJKWZn341U6jE+tQWigVz0H0sfgLJIW1xuaoHizWGlMdvEjSQHOkRZIODK8o9/hzZTBtMJ6spNu2r4n04/3zopbhV/tRegxp+ZnWMclCSArsBdBlmQRBUwvCuYAwn9Uy27I+xGKo2MOY/LUuRjgJUhf4TUiAFIxWnoFLbprATo22WipKvbOor2OLM2ivhmCffELlLyz4wHHXCZvtn3paH+/+D5DENW18hcrYP6vYumb09mlYzA+PGZz1J4C1gMaZ8mdd4rxIPtQrI/x53SbtOcAQU0HVzpvRkPtrz8iHByXmtizTsspyBsSwB9TPDabmpY3Lw1yWKl5fw1HWG3E8fE3h1XtPnia4= X-Forefront-PRVS: 02622CEF0A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39450400003)(39410400002)(39840400002)(39400400002)(377454003)(24454002)(66066001)(230700001)(64126003)(65956001)(65826007)(5660300001)(6666003)(2950100002)(33646002)(6246003)(25786009)(6506006)(53936002)(53546009)(229853002)(189998001)(76176999)(54356999)(50986999)(36756003)(50466002)(31696002)(81166006)(47776003)(23746002)(6512007)(6486002)(31686004)(54906002)(4326008)(8676002)(7736002)(305945005)(2906002)(38730400002)(6116002)(7416002)(3846002)(4001350100001)(83506001)(42186005)(86362001)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR05MB765;H:linlap1.localdomain;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;DM2PR05MB765;23:K6KEGgpYN6GTjzRogvPXnOjtECB836/7vKAfJp?= =?Windows-1252?Q?q5zyaRii3UGtwOPBQCY7lnNZx6wLWYx62Vihy5S/CB0uLf4VIkLIAAIN?= =?Windows-1252?Q?g+i+eyrobatoSM//JM1hcPCSt5h2kzBqQ4QY15MkK1sglw7WfdYfYn+/?= =?Windows-1252?Q?Nui+9ny+QJbpr+DdJp4mEFkd4FJHa23p1fpB7ABozDBAYd/BxRA33eum?= =?Windows-1252?Q?vv5M7yC06qT4wSknHc36HZuM0NvbhajlpIzhG78F2EJXor0y49oNSKA3?= =?Windows-1252?Q?IhFV4kAWwhohIoYqR/oswxiictMRAo/RHRokMM8w1KaL5HhMzLD8/ehg?= =?Windows-1252?Q?JuJ+Dwh1BeVR83KV8dfEiFNksbLpJHYiM8fC0xf0hqoFre86XofZLw7O?= =?Windows-1252?Q?9H2AxCdhBUt4uP29qKEKbpqSSUFI1MYUi792zB6uoLzFlMH2U5LG+Nbl?= =?Windows-1252?Q?WFSm/iVBsGIJJocvY4My4IJ9JvIcZackuH6ec+joVE71rHsNY00jvOVA?= =?Windows-1252?Q?2EzEQYOvqaTYSvJGRvmnv/x8Mbtl2BfiWgig5XmbuQnnnFJF29e7iR0P?= =?Windows-1252?Q?A2jXyeXfTdI+hgCtCblXt1dm6V26MGK7pvBP3Pfd/KpEzFzHa753pwJr?= =?Windows-1252?Q?vIlGN1KbWeHtpvNUdd8gR8fl6qNj30b5UbZa8i70R+bqADJ5pUA0juYO?= =?Windows-1252?Q?/4J/HpAQyW7LM6NgoEJj44fQ/UEWBu4bUvRA3sPcSJHGsIltu/Hkxkd7?= =?Windows-1252?Q?yt14qGRkuDji3+ty0nefpOP3+RWPj3/r/xM/Zl8fkDlFdNd4XOXYsIQ6?= =?Windows-1252?Q?PDI6hKFhSp8cMYnh7AKbN3GiT3MCiDNTK4gVbmcafLOS9x+0Jz9mrQ13?= =?Windows-1252?Q?UFHqoNfISEu+0+nJ/ODi0qIHE5c7fV+JrpoEzRF1KhZboHw7Kl5FvrB4?= =?Windows-1252?Q?XqHTkVswf7K3J8sqato8YfA1olwXzAauSloPFNN6bDePT+R1yv2Q+vvj?= =?Windows-1252?Q?JLxdbzV+849kMcEvJcNEL56o0777E7NXxBx5Eb+mJmI8PtF1n0zENxNO?= =?Windows-1252?Q?7RksiS9RVgS/dj7TrZdx7W7M568rFFZ7BNR9hksXBHR5cVQOcm5CmAFc?= =?Windows-1252?Q?KJ9LYahngeVSk4lXhOMAj819/AakcvftiCDIxvE5O0q3muS6+2CXYSdz?= =?Windows-1252?Q?LSDxjrCxXxtxOydlHQFDuz0tFYLFhSMcoknBeEqEABXsNEv7at8BybGO?= =?Windows-1252?Q?6UxZ/zT0djjeERb2hH/X0Pinp84xZLzpnBPcyeQanhpbd2L4+Nk3wvji?= =?Windows-1252?Q?s2U2UbeRUgNCp28xZzyD2thMszfUuEmCY+i2C7ExLf7f0=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR05MB765;6:sVeMMuRqOj+KZE8MdGeDg9PE3vepqVD/3xwWQSHVGGMD+6qVU8uCc/gLfqxeHXGvV/1A+Jxi1FXErfZGKyaINkISD89rhv9ODSK5uUNx/sRxa6dUzcZYjgfWIVT1rNi/X9CxSzuaPh6SLIBJAkALf2VWvJLTFlxvI1KsbSCgy2TYfCY1onVTw8r3vblmr/Bs8cYsuEmvlxXsrM1VXnHN5zqag4reQHjmz9FPqbegFfrNe/KtxWuBvOs57DGsomvZPnrPAHM6Vjs8LopGuWMRXgphksN1h12zDmVNMJcmqvAwbTRYLOzUyEUQ8ynJo5PvNIPsLMh2as2Dr9hq8zC3xsA9bA5dnLe+968TtbPmlRtW4nwmCubTddfHFAraPcktcm5dqgCpv2/J5AtvtxZWkQ==;5:Y4M5VUxpXeQFEKw6XoSwomXYP12kk2u14es5sbzAUfqAxq/G/hAkVbGaQObQRSm/JyPH66tAd9iTf4XZ8IBuvcOMo8iBvBltOW1KgPpm0623NtANH7pY4vEzUqIZOyMT2oIyLI2nyeSThoE6f2RfOd1p2sAE1dMs2oPZpS9K1mE=;24:tMVaXrDlRSu+F1U2+tgcfvwuEgWzbpC5PuhQWrmBMe7QHPv/TqJQ+4KlJ+5q7svbj9xtriZKFxl9egUGSBntMBwpUFoHvO7f0S22HGR4udc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM2PR05MB765;7:auT0kVU0NBQG79veQwxz4PpAhu4H5BoIxzHi5wvAZCvETLlmkWNSuUezs+OH+xhkNIzdLdDhoMjmoBdB/97mKWYYYOiazJjFHFOAGLmneUwrD2yfFR5TX/JtI2V/LTWe8xfgqjnoO2bIaSYs7NV2ej3+mcHmeV4RWDU2NO2/DsUYSYtSmLRB/N0c8a3h+ELUL8nUNwRaUBrYa5+fOeZO6b0ZQw/QOTq2jBZQz3qnhtc0B1ShCAnOBrIE4Xm21gYzy9/Fkv2nUlNu8PArlOhm5HwKqOw6+OYfqGq6ixzpqBMjWXf1TdlnLNOjAgQT5GNT5xCdFFSh9IJ6VvBLUTYayA==;20:BNvLQJW9HaJFwQhSB/mTzG3BFU57sJWcl8bYnt/iD/eHnyXPuxz0LnAQlNPUnN4ksVMqMhXKLLZpkY/YvscX0eIYPG8DbdfA1i1qusRxmCaE/UN2BQGw0J+ZFIFA1YzVsNB3pXpMLrgxSdEMRiPtWUOXPEgJAaevj6lXFfPVNAg= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2017 12:01:01.8341 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR05MB765 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4000 Lines: 109 On 03/30/2017 12:27 PM, Andrey Ryabinin wrote: > Commit 5803ed292e63 ("mm: mark all calls into the vmalloc subsystem > as potentially sleeping") added might_sleep() to remove_vm_area() from > vfree(), and commit 763b218ddfaf ("mm: add preempt points into > __purge_vmap_area_lazy()") actually made vfree() potentially sleeping. > > This broke vmwgfx driver which calls vfree() under spin_lock(). > > BUG: sleeping function called from invalid context at mm/vmalloc.c:1480 > in_atomic(): 1, irqs_disabled(): 0, pid: 341, name: plymouthd > 2 locks held by plymouthd/341: > #0: (drm_global_mutex){+.+.+.}, at: [] drm_release+0x3b/0x3b0 [drm] > #1: (&(&tfile->lock)->rlock){+.+...}, at: [] ttm_object_file_release+0x28/0x90 [ttm] > > Call Trace: > dump_stack+0x86/0xc3 > ___might_sleep+0x17d/0x250 > __might_sleep+0x4a/0x80 > remove_vm_area+0x22/0x90 > __vunmap+0x2e/0x110 > vfree+0x42/0x90 > kvfree+0x2c/0x40 > drm_ht_remove+0x1a/0x30 [drm] > ttm_object_file_release+0x50/0x90 [ttm] > vmw_postclose+0x47/0x60 [vmwgfx] > drm_release+0x290/0x3b0 [drm] > __fput+0xf8/0x210 > ____fput+0xe/0x10 > task_work_run+0x85/0xc0 > exit_to_usermode_loop+0xb4/0xc0 > do_syscall_64+0x185/0x1f0 > entry_SYSCALL64_slow_path+0x25/0x25 > > This can be fixed in vmgfx, but it would be better to make vfree() > non-sleeping again because we may have other bugs like this one. > > __purge_vmap_area_lazy() is the only function in the vfree() path that > wants to be able to sleep. So it make sense to schedule > __purge_vmap_area_lazy() via schedule_work() so it runs only in sleepable > context. This will have a minimal effect on the regular vfree() path. > since __purge_vmap_area_lazy() is rarely called. > > Fixes: 5803ed292e63 ("mm: mark all calls into the vmalloc subsystem as > potentially sleeping") > Reported-by: Tetsuo Handa > Signed-off-by: Andrey Ryabinin > Cc: > > Signed-off-by: Andrey Ryabinin > --- > mm/vmalloc.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 68eb002..ea1b4ab 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -701,7 +701,7 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end) > * Kick off a purge of the outstanding lazy areas. Don't bother if somebody > * is already purging. > */ > -static void try_purge_vmap_area_lazy(void) > +static void try_purge_vmap_area_lazy(struct work_struct *work) > { > if (mutex_trylock(&vmap_purge_lock)) { > __purge_vmap_area_lazy(ULONG_MAX, 0); > @@ -720,6 +720,8 @@ static void purge_vmap_area_lazy(void) > mutex_unlock(&vmap_purge_lock); > } > > +static DECLARE_WORK(purge_vmap_work, try_purge_vmap_area_lazy); > + > /* > * Free a vmap area, caller ensuring that the area has been unmapped > * and flush_cache_vunmap had been called for the correct range > @@ -736,7 +738,7 @@ static void free_vmap_area_noflush(struct vmap_area *va) > llist_add(&va->purge_list, &vmap_purge_list); > > if (unlikely(nr_lazy > lazy_max_pages())) > - try_purge_vmap_area_lazy(); Perhaps a slight optimization would be to schedule work iff !mutex_locked(&vmap_purge_lock) below? /Thomas > + schedule_work(&purge_vmap_work); > } > > /* > @@ -1125,7 +1127,6 @@ void vm_unmap_ram(const void *mem, unsigned int count) > unsigned long addr = (unsigned long)mem; > struct vmap_area *va; > > - might_sleep(); > BUG_ON(!addr); > BUG_ON(addr < VMALLOC_START); > BUG_ON(addr > VMALLOC_END); > @@ -1477,8 +1478,6 @@ struct vm_struct *remove_vm_area(const void *addr) > { > struct vmap_area *va; > > - might_sleep(); > - > va = find_vmap_area((unsigned long)addr); > if (va && va->flags & VM_VM_AREA) { > struct vm_struct *vm = va->vm;