Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp108413ybx; Tue, 29 Oct 2019 15:10:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxryAinjibJ8dsBfiphGErdb1BPFYNgIft8Tlplc5dl+bVFmjxSRFF+6HeA9TVrKjEGr3/s X-Received: by 2002:a50:b723:: with SMTP id g32mr28107790ede.13.1572387043288; Tue, 29 Oct 2019 15:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572387043; cv=none; d=google.com; s=arc-20160816; b=c478YDaLjGt9wHm7E7ZAAe/I9XhAQqCWZR5i8SuFb5FEWX+ud1f1bLaHyo8H7LX0oX +FFCKzxfclm6tE8kKAVm4ivt0959MObC832aj8AzrKGqeygGA3S4v34MyO0dAo38uLiX qdDqiojy0F8ylup4iaWdFivB3RJvGOJ3PvndiBjw5WmOMf4NWD0hloR036sx1Q44KtkE Oq2BxKhCQk8sChKRlTJ/7qCMCYVLJwBxvzJEdzNxMzyEyCkA39rJA47+a7YFadL6/U0T Sp+pnr1q0K+Yj21meJrNQGZuv7gijbwvgu74rpAqtUrxc0/QWk0lOWPK+G8uR+2CMP42 8jRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=pxbT7FZm8HKhnwyzQkqTp7LLTp7zhPHuq0YTwDj2TCQ=; b=wjJuJ7YpEhHM6pCQ74Ay00E9j3eKoIeixzpzuFB1M7xOoJImcMURtye6QnWEX70QzM /w4zQ76p+gfGZKnl+qMzf9A0YMjjCXjW9JTpY3T+OQgYNDvBcOJHEbkmpbkukO3ROudf aBprO3HuWgWu05AoQEltcSIfjtkYIjg/CMfns5Odjfscn03gx82aO7al4nnP3ndAGS+d 4lZGgKaKZ/TFSytPeScUpDN0x+c+9KtJ+V4U4R62TcuCAbzhJCt2njI4klJiC/X2kjrv tg2+0/bvcZRYd3fKxK1iatuD9Oir3JetLubZxqVZIsYpxRdKEdle00fgZMgTlvGyyQhz CPWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NwwDI9pw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y31si59646edb.47.2019.10.29.15.10.19; Tue, 29 Oct 2019 15:10:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NwwDI9pw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728341AbfJ2VCL (ORCPT + 99 others); Tue, 29 Oct 2019 17:02:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:38242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726711AbfJ2VCL (ORCPT ); Tue, 29 Oct 2019 17:02:11 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 199182087E; Tue, 29 Oct 2019 21:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572382930; bh=DU276rBOmXNq/UGPWSsHr+vCt4tZPq33yvckroogy+s=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NwwDI9pwnDo75NGmhbNfHM/Z52BOv/JUemoHekwTJypzHNtZFbJvRDk+E1Wc7jgUC On20wb4dVGoVudHP0YtkioHoHAmgGvETr9xPwj0hBuoBho6V+6x/fFUAFlnWfQN9Vw pFqgMOSZ0/b9dD4OKeTBUpNaSAK7B84JMq1Kn71U= Date: Tue, 29 Oct 2019 14:02:09 -0700 From: Andrew Morton To: Ville =?ISO-8859-1?Q?Syrj=E4l=E4?= Cc: linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , linux-mm@kvack.org, =?ISO-8859-1?Q?J=E9?= =?ISO-8859-1?Q?r=F4me?= Glisse , Ralph Campbell , Ira Weiny , Jason Gunthorpe , Daniel Vetter , Andrea Arcangeli Subject: Re: khugepaged might_sleep() warn due to CONFIG_HIGHPTE=y Message-Id: <20191029140209.e70385637d3617ad43869f31@linux-foundation.org> In-Reply-To: <20191029201513.GG1208@intel.com> References: <20191029201513.GG1208@intel.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 29 Oct 2019 22:15:13 +0200 Ville Syrj=E4l=E4 wrote: > Hi, >=20 > I got some khugepaged spew on a 32bit x86: >=20 > [ 217.490026] BUG: sleeping function called from invalid context at incl= ude/linux/mmu_notifier.h:346 > [ 217.492826] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 25,= name: khugepaged > [ 217.495589] INFO: lockdep is turned off. > [ 217.498371] CPU: 1 PID: 25 Comm: khugepaged Not tainted 5.4.0-rc5-elk+= #206 > [ 217.501233] Hardware name: System manufacturer P5Q-EM/P5Q-EM, BIOS 220= 3 07/08/2009 > [ 217.501697] Call Trace: > [ 217.501697] dump_stack+0x66/0x8e > [ 217.501697] ___might_sleep.cold.96+0x95/0xa6 > [ 217.501697] __might_sleep+0x2e/0x80 > [ 217.501697] collapse_huge_page.isra.51+0x5ac/0x1360 > [ 217.501697] ? __alloc_pages_nodemask+0xec/0xf80 > [ 217.501697] ? __alloc_pages_nodemask+0x191/0xf80 > [ 217.501697] ? trace_hardirqs_on+0x4a/0xf0 > [ 217.501697] khugepaged+0x9a9/0x20f0 > [ 217.501697] ? _raw_spin_unlock+0x21/0x30 > [ 217.501697] ? trace_hardirqs_on+0x4a/0xf0 > [ 217.501697] ? wait_woken+0xa0/0xa0 > [ 217.501697] kthread+0xf5/0x110 > [ 217.501697] ? collapse_pte_mapped_thp+0x3b0/0x3b0 > [ 217.501697] ? kthread_create_worker_on_cpu+0x20/0x20 > [ 217.501697] ret_from_fork+0x2e/0x38 >=20 > Looks like it's due to CONFIG_HIGHPTE=3Dy pte_offset_map()->kmap_atomic()= vs. > mmu_notifier_invalidate_range_start(). >=20 > My naive idea would be to just reorder those things, but not sure > if there's some magic ordering constraint here. At least the machine > still boots when I do it :) >=20 > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 0a1b4b484ac5..f05d27b7183d 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -1028,12 +1028,13 @@ static void collapse_huge_page(struct mm_struct *= mm, > =20 > anon_vma_lock_write(vma->anon_vma); > =20 > - pte =3D pte_offset_map(pmd, address); > - pte_ptl =3D pte_lockptr(mm, pmd); > - > mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, NULL, mm, > address, address + HPAGE_PMD_SIZE); > mmu_notifier_invalidate_range_start(&range); > + > + pte =3D pte_offset_map(pmd, address); > + pte_ptl =3D pte_lockptr(mm, pmd); > + > pmd_ptl =3D pmd_lock(mm, pmd); /* probably unnecessary */ > /* > * After this gup_fast can't run anymore. This also removes >=20 Looks good to me. Can you resend it with a signoff please?