Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4844245ybg; Tue, 29 Oct 2019 13:16:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAuDsk9OTD61b4sbqrMpa+2cn4/WuJyiWl58G0FY0LzpkPaeDzHq8p889dCoTiKmRyp9w0 X-Received: by 2002:a17:906:c08:: with SMTP id s8mr5329074ejf.73.1572380194629; Tue, 29 Oct 2019 13:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572380194; cv=none; d=google.com; s=arc-20160816; b=Iikq+MIT7XQdvMp2Q5E6P8b+RBN5RHD7OX2wxhNRz0Vyq1V3vSnDe3Sv3dfCMTzZzV TQyI1U4Wb0cY4sD7KjMFiCjUYdS3OmmGoC5I1/EL70EpYH+zZ/KUanECLycXXgf4M0ZC MQ31AEorWZhbkbplw+cnlsn9rddeXid/n/oGvrIy/kV3fcNZd86Y41UzEzYhQXaaojSs 5R8YMJLgnwvSAqbRjM0qpbLbZ4/kjdRkeHLAwhV5YAhSPNTDfD3Pd/Sc35pttakh1Kvv WQ/sjsgPueyjDJRGC+Wn4aZXWT46M0TzWl6MjqHTzgM74gwQVzjcqIxb+IVaIHaUSI27 lrLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date; bh=rDKpfKRUBjWgWkhR+mDxe8hcRpk/u3q6h+2VX+qtLYI=; b=bWo+1bFt5t8l9Yq5yrkRuLEx1EQHIVxwG9kNP4pC3A+8wMcD+/gXYxr2USPyzKDBtl 48i2g5PpQkuICm1OZVKqXm8LO/opEZlOF2IZWQqQRy1o/J8rbKc8UFCGHVKO6afNSO67 dv1jI3727IxFNWE/CuzGIVvstLtJlpnR+hemzoylDxCuLihPTYqoV1R+nGwob8kEbGpY Oj5FUoUPgNOvHSIJ6rGp7T72c5jG/hBZ3hZqSOvnaiTjAPy2w04FhqZhw2H9W4G+aaPJ g9k91E1U9oQ66tSFWCoPQhiD7oic9LN42slteRNvKDLfTExGP3eyfr6Tw5pQI4LeQD3o 8EbA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c36si11822565edf.165.2019.10.29.13.16.11; Tue, 29 Oct 2019 13:16:34 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726636AbfJ2UP1 (ORCPT + 99 others); Tue, 29 Oct 2019 16:15:27 -0400 Received: from mga18.intel.com ([134.134.136.126]:4073 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725840AbfJ2UP1 (ORCPT ); Tue, 29 Oct 2019 16:15:27 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Oct 2019 13:15:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,245,1569308400"; d="scan'208";a="283348320" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by orsmga001.jf.intel.com with SMTP; 29 Oct 2019 13:15:14 -0700 Received: by stinkbox (sSMTP sendmail emulation); Tue, 29 Oct 2019 22:15:13 +0200 Date: Tue, 29 Oct 2019 22:15:13 +0200 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: linux-kernel@vger.kernel.org Cc: Andrew Morton , "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , linux-mm@kvack.org Subject: khugepaged might_sleep() warn due to CONFIG_HIGHPTE=y Message-ID: <20191029201513.GG1208@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I got some khugepaged spew on a 32bit x86: [ 217.490026] BUG: sleeping function called from invalid context at include/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 2203 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 Looks like it's due to CONFIG_HIGHPTE=y pte_offset_map()->kmap_atomic() vs. mmu_notifier_invalidate_range_start(). 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 :) 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, anon_vma_lock_write(vma->anon_vma); - pte = pte_offset_map(pmd, address); - pte_ptl = 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 = pte_offset_map(pmd, address); + pte_ptl = pte_lockptr(mm, pmd); + pmd_ptl = pmd_lock(mm, pmd); /* probably unnecessary */ /* * After this gup_fast can't run anymore. This also removes -- Ville Syrj?l? Intel