Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2832122pxv; Mon, 12 Jul 2021 03:03:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzasTM7da9ZnvSvUWIv/O76E84JragGIGgAdVAuXTI9FiMvQG+fGuWqQwUgP3ruXvxk+z1e X-Received: by 2002:a92:c747:: with SMTP id y7mr34180697ilp.199.1626084201250; Mon, 12 Jul 2021 03:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084201; cv=none; d=google.com; s=arc-20160816; b=aJ5rz6ChfEBoABlz6YfMgCZeIYXPlQt0v+grvhQwveUIuP0/o98MMgI6e5XT2HwPRF llfN/FpHfs2Zwr6tX0PTCPZFsaY094GfvGv4yis4b6lJa7nCNEpkTlvoCyw5fwSOGDrx 6x3S4OEUHV/GzDbFMA88bTl88J8DjxeNDY+NtebDpOOTdZ355jfKFjAcZjXXTwSsbaip 7PMOuioqek6VK0UKy8LLBdpL+RNi5z0+010Q5jjq0K0fnUpeu4Pj1cFhoMIZHUAPXDNm IHpLviIwjzBET2bECIYMX9HKjW5OB7RuBA7BOEnq8eI1dWaJ1UdPvOpJJqEgcB4JPP+Y B+vw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WQbWc5D5BnqdU2uMuFgFZRjN95c4U+d5bMy0pSA2Yak=; b=c5EwlJAi7m4JstJ83YSs3IlW8cUVGwRprQ4G51DWHh8kI8KCT/RTBStgYUMI4F37Mg 7LiLAcVfAK6IctWEPpxRDjNa17jug8DoJxzw6CxuYmpkywZM2zoSOUxRGaSETVqTRTll 5Bdx5h7c/vbHTeNDl+JLfjaSDco84+l6PeT4e2GuzcTEPr4hQyx0gUprSvKKF1cfMlKK ohr4i796lvyJyU+06DkNgTloO39nCbv2NEhqdNwkIVbxD3rKw0sykxJTD78+E3lqKINv IfRValy6iqGKzltXJIeBSwX6IWsn3MUs/az8UzueC6z8MHA/+iMCXTNq34SfJM0fXj0r GPtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=briAex5u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b4si4141348jat.6.2021.07.12.03.03.08; Mon, 12 Jul 2021 03:03:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=briAex5u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244415AbhGLHSW (ORCPT + 99 others); Mon, 12 Jul 2021 03:18:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:53864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236674AbhGLGx1 (ORCPT ); Mon, 12 Jul 2021 02:53:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 83835610D0; Mon, 12 Jul 2021 06:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072638; bh=fsXzZU99CNoQrO+dXEfkeHAuHSfCDX2X0HKResemX5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=briAex5uVBS7PPMUWfoIwBqYTKnW0Rh7GCIfTsUYBIleMQ4DxrtxQuLVPj9BFfhjf i94iG3uCBFp8IB5KHeQIduRYLVHTOI+a5ZhfpM3z10UHuGZTIaxLYB/7fahsvXTVj5 VDtr8YgR9OezGSr/1AgvAGaA1oGI2F6te0zssGKI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Aneesh Kumar K.V" , Dan Williams , "Kirill A . Shutemov" , Jan Kara , David Hildenbrand , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 562/593] mm/pmem: avoid inserting hugepage PTE entry with fsdax if hugepage support is disabled Date: Mon, 12 Jul 2021 08:12:02 +0200 Message-Id: <20210712060956.508914388@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aneesh Kumar K.V [ Upstream commit bae84953815793f68ddd8edeadd3f4e32676a2c8 ] Differentiate between hardware not supporting hugepages and user disabling THP via 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' For the devdax namespace, the kernel handles the above via the supported_alignment attribute and failing to initialize the namespace if the namespace align value is not supported on the platform. For the fsdax namespace, the kernel will continue to initialize the namespace. This can result in the kernel creating a huge pte entry even though the hardware don't support the same. We do want hugepage support with pmem even if the end-user disabled THP via sysfs file (/sys/kernel/mm/transparent_hugepage/enabled). Hence differentiate between hardware/firmware lacking support vs user-controlled disable of THP and prevent a huge fault if the hardware lacks hugepage support. Link: https://lkml.kernel.org/r/20210205023956.417587-1-aneesh.kumar@linux.ibm.com Signed-off-by: Aneesh Kumar K.V Reviewed-by: Dan Williams Cc: "Kirill A . Shutemov" Cc: Jan Kara Cc: David Hildenbrand Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/huge_mm.h | 15 +++++++++------ mm/huge_memory.c | 6 +++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index ff55be011739..10c7a80a0394 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -84,6 +84,7 @@ static inline vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, } enum transparent_hugepage_flag { + TRANSPARENT_HUGEPAGE_NEVER_DAX, TRANSPARENT_HUGEPAGE_FLAG, TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, @@ -129,6 +130,13 @@ extern unsigned long transparent_hugepage_flags; */ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) { + + /* + * If the hardware/firmware marked hugepage support disabled. + */ + if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_NEVER_DAX)) + return false; + if (vma->vm_flags & VM_NOHUGEPAGE) return false; @@ -140,12 +148,7 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_FLAG)) return true; - /* - * For dax vmas, try to always use hugepage mappings. If the kernel does - * not support hugepages, fsdax mappings will fallback to PAGE_SIZE - * mappings, and device-dax namespaces, that try to guarantee a given - * mapping size, will fail to enable - */ + if (vma_is_dax(vma)) return true; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 6301ecc1f679..f1432d4d81c7 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -375,7 +375,11 @@ static int __init hugepage_init(void) struct kobject *hugepage_kobj; if (!has_transparent_hugepage()) { - transparent_hugepage_flags = 0; + /* + * Hardware doesn't support hugepages, hence disable + * DAX PMD support. + */ + transparent_hugepage_flags = 1 << TRANSPARENT_HUGEPAGE_NEVER_DAX; return -EINVAL; } -- 2.30.2