From patchwork Mon Nov 7 02:10:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 16218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1782889wru; Sun, 6 Nov 2022 18:11:42 -0800 (PST) X-Google-Smtp-Source: AMsMyM7E2ufmZWV6eEfggWL3VPz2qXZlChKSrxSeqXbB8LdlPpszIirJE1i/9auJlSQYGLH2H6zX X-Received: by 2002:a17:906:b08d:b0:782:d526:3e36 with SMTP id x13-20020a170906b08d00b00782d5263e36mr45010784ejy.358.1667787102436; Sun, 06 Nov 2022 18:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667787102; cv=none; d=google.com; s=arc-20160816; b=bcw26zjXWxYY71LcyRfQ4LLi6O/P/U1pFgySRfolmyNCUJ57gEgdq2mDwvq5ZGcllS yepappbbmmLLeVbDPlTPqCOpl+tmjv9uHSa9N//c7rQMROSjer0JyLQNybdvpNGVA5/O RpJIR5JnyIL8BMYShgeN1H3f5kbSoqim2rr6Zk/wGRiWNre/1Ld9DWMZGAo00gUnbRit DiJ5sABPLlkQ0402RoZWLVzbUXjXShv6qj3WVElyLV8tz+bOMLpirm5IEvuxfPx0ufER PEHvTYjv01eoN5Ke5DbC8775mzsp4P3O+DVgksFDG1Bf2tEYuUaKUjzXGaNdTXsFg0Wj zDrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=JWCRU0wMC+dzOW6EcNPcg7iP/EOKI6q2MiVyrooXUYw=; b=E/Y9EAcdCesUi8co8Vx2PnL6WBAqRyPEObnxPL0Is9wvYBnHPUkP/Bv9iB+MT0gqIf fo8D9VF6qO+Wl5Jhz7RdO4tsABkK/oE5bAPWIJSgMyxcGpOZZZ4SSg7DFkKJARwMpVF2 il97kY0W+YQS6iswRYvWu9dX1jH04fuz1trEETfQ2lWcr+PvuEq2SJGomSQd6+tRJ2zm gJJi8znf5Ex0iasnK0uVIB/xRJaQW20yObwEneEe7cbVJjsNNAMBAJstKKsh1WshLttC qv6XB+qpRpod9M6r4TkisTg1W52r27CrAXD1OHKcdGCchqAeCTqkEId+BH+TS+7MpI0Y 9GtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Xn3zOl5l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a508e46000000b00462dca18096si7465263edx.520.2022.11.06.18.11.18; Sun, 06 Nov 2022 18:11:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Xn3zOl5l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230160AbiKGCKi (ORCPT + 99 others); Sun, 6 Nov 2022 21:10:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiKGCKh (ORCPT ); Sun, 6 Nov 2022 21:10:37 -0500 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B9C7B4B1 for ; Sun, 6 Nov 2022 18:10:35 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1667787033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JWCRU0wMC+dzOW6EcNPcg7iP/EOKI6q2MiVyrooXUYw=; b=Xn3zOl5lAYUw6ONBHZHt4eG74DxIo5Goll6gq/JeI01k/JAlWo37TqbzlkK9kRzm3LQr3c +RLDBdglbR5O/ptroHh9JAqRc4BUEhyDs1t2Es2CjWPwNjjmL5+KZCVQEFsW99ZfR/j2nU QU1wKCWbDRlbgnaEDRBPlYDO1+m7S4o= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v1] arch/x86/mm/hugetlbpage.c: pud_huge() returns 0 when using 2-level paging Date: Mon, 7 Nov 2022 11:10:10 +0900 Message-Id: <20221107021010.2449306-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748801528705706814?= X-GMAIL-MSGID: =?utf-8?q?1748801528705706814?= From: Naoya Horiguchi The following bug is reported to be triggered when starting X on x86-32 system with i915: [ 225.777375] kernel BUG at mm/memory.c:2664! [ 225.777391] invalid opcode: 0000 [#1] PREEMPT SMP [ 225.777405] CPU: 0 PID: 2402 Comm: Xorg Not tainted 6.1.0-rc3-bdg+ #86 [ 225.777415] Hardware name: /8I865G775-G, BIOS F1 08/29/2006 [ 225.777421] EIP: __apply_to_page_range+0x24d/0x31c [ 225.777437] Code: ff ff 8b 55 e8 8b 45 cc e8 0a 11 ec ff 89 d8 83 c4 28 5b 5e 5f 5d c3 81 7d e0 a0 ef 96 c1 74 ad 8b 45 d0 e8 2d 83 49 00 eb a3 <0f> 0b 25 00 f0 ff ff 81 eb 00 00 00 40 01 c3 8b 45 ec 8b 00 e8 76 [ 225.777446] EAX: 00000001 EBX: c53a3b58 ECX: b5c00000 EDX: c258aa00 [ 225.777454] ESI: b5c00000 EDI: b5900000 EBP: c4b0fdb4 ESP: c4b0fd80 [ 225.777462] DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068 EFLAGS: 00010202 [ 225.777470] CR0: 80050033 CR2: b5900000 CR3: 053a3000 CR4: 000006d0 [ 225.777479] Call Trace: [ 225.777486] ? i915_memcpy_init_early+0x63/0x63 [i915] [ 225.777684] apply_to_page_range+0x21/0x27 [ 225.777694] ? i915_memcpy_init_early+0x63/0x63 [i915] [ 225.777870] remap_io_mapping+0x49/0x75 [i915] [ 225.778046] ? i915_memcpy_init_early+0x63/0x63 [i915] [ 225.778220] ? mutex_unlock+0xb/0xd [ 225.778231] ? i915_vma_pin_fence+0x6d/0xf7 [i915] [ 225.778420] vm_fault_gtt+0x2a9/0x8f1 [i915] [ 225.778644] ? lock_is_held_type+0x56/0xe7 [ 225.778655] ? lock_is_held_type+0x7a/0xe7 [ 225.778663] ? 0xc1000000 [ 225.778670] __do_fault+0x21/0x6a [ 225.778679] handle_mm_fault+0x708/0xb21 [ 225.778686] ? mt_find+0x21e/0x5ae [ 225.778696] exc_page_fault+0x185/0x705 [ 225.778704] ? doublefault_shim+0x127/0x127 [ 225.778715] handle_exception+0x130/0x130 [ 225.778723] EIP: 0xb700468a Recently pud_huge() got aware of non-present entry by commit 3a194f3f8ad0 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry") to handle some special states of gigantic page. However, it's overlooked that pud_none() always returns false when running with 2-level paging, and as a result pmd_huge() can return true pointlessly. Introduce "#if CONFIG_PGTABLE_LEVELS > 2" to pud_huge() to deal with this. Fixes: 3a194f3f8ad0 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry") Reported-by: Ville Syrjälä Signed-off-by: Naoya Horiguchi Cc: Tested-by: Ville Syrjälä Reviewed-by: Muchun Song --- arch/x86/mm/hugetlbpage.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c index 6b3033845c6d..5804bbae4f01 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -37,8 +37,12 @@ int pmd_huge(pmd_t pmd) */ int pud_huge(pud_t pud) { +#if CONFIG_PGTABLE_LEVELS > 2 return !pud_none(pud) && (pud_val(pud) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT; +#else + return 0; +#endif } #ifdef CONFIG_HUGETLB_PAGE