From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38F1518A922; Mon, 28 Oct 2024 06:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730098189; cv=none; b=bnKY8YF1UFpdXbivYpsbCPpQNr5/9ndi2/5uQsDXCz+f6wcI6SApLxIAbk6au8yIyzrV3b7brmxdOK3XcgEPFfuvHz3Tmd5WHhmsQhU2Ft0PKY/X5M9OwIvMxXp4P0G2JTP7yg25Ij7ahgH2P0bJuGx2q8rfQj4zPBzyB+36wvU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730098189; c=relaxed/simple; bh=c0M3kYmdEWIoQkp9dfFFtvZ7HDXzdEGJmQR3HlTN3Rw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lMA5wyF0FTroiv8OZ5JGhBrhedAI7yRitJBmG9M2RjIsbJ5gAo5PpIu1IpDDPEl3Q2PiM9pg4gwX25Coo09eh72Q3u2VG3Bvx9tkQKxKbGUWnY8w4u57niMemJr2DrswSczrkP/RqxhASY9LlV5FCxMd3Wpduh1anExLg8ozFVM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pA0ZEMlH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="pA0ZEMlH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC168C4CEC3; Mon, 28 Oct 2024 06:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730098189; bh=c0M3kYmdEWIoQkp9dfFFtvZ7HDXzdEGJmQR3HlTN3Rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pA0ZEMlHn6O43eYR15OiOQ1jnCOoNafWaalf1add23kkcMnub/zYO9AVe8yOdFa1d 4d/CVIMVeUZFW5ukGP4SSj9bA5rMA5sazeALhzqF9dMHyveWuYtreZAqntUM/omqru 9iy+RsnYuaBf4/4wYIZXF54m4TfjmzEXW7z/D6zI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Hildenbrand , Leo Fu , Thomas Huth , "Matthew Wilcox (Oracle)" , Ryan Roberts , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Hugh Dickins , Kefeng Wang , Andrew Morton , Sasha Levin Subject: [PATCH 6.11 116/261] mm: dont install PMD mappings when THPs are disabled by the hw/process/vma Date: Mon, 28 Oct 2024 07:24:18 +0100 Message-ID: <20241028062314.936693269@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028062312.001273460@linuxfoundation.org> References: <20241028062312.001273460@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.11-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Hildenbrand [ Upstream commit 2b0f922323ccfa76219bcaacd35cd50aeaa13592 ] We (or rather, readahead logic :) ) might be allocating a THP in the pagecache and then try mapping it into a process that explicitly disabled THP: we might end up installing PMD mappings. This is a problem for s390x KVM, which explicitly remaps all PMD-mapped THPs to be PTE-mapped in s390_enable_sie()->thp_split_mm(), before starting the VM. For example, starting a VM backed on a file system with large folios supported makes the VM crash when the VM tries accessing such a mapping using KVM. Is it also a problem when the HW disabled THP using TRANSPARENT_HUGEPAGE_UNSUPPORTED? At least on x86 this would be the case without X86_FEATURE_PSE. In the future, we might be able to do better on s390x and only disallow PMD mappings -- what s390x and likely TRANSPARENT_HUGEPAGE_UNSUPPORTED really wants. For now, fix it by essentially performing the same check as would be done in __thp_vma_allowable_orders() or in shmem code, where this works as expected, and disallow PMD mappings, making us fallback to PTE mappings. Link: https://lkml.kernel.org/r/20241011102445.934409-3-david@redhat.com Fixes: 793917d997df ("mm/readahead: Add large folio readahead") Signed-off-by: David Hildenbrand Reported-by: Leo Fu Tested-by: Thomas Huth Cc: Thomas Huth Cc: Matthew Wilcox (Oracle) Cc: Ryan Roberts Cc: Christian Borntraeger Cc: Janosch Frank Cc: Claudio Imbrenda Cc: Hugh Dickins Cc: Kefeng Wang Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/memory.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index cda2c12c500b8..cb66345e398d2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4719,6 +4719,15 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) pmd_t entry; vm_fault_t ret = VM_FAULT_FALLBACK; + /* + * It is too late to allocate a small folio, we already have a large + * folio in the pagecache: especially s390 KVM cannot tolerate any + * PMD mappings, but PTE-mapped THP are fine. So let's simply refuse any + * PMD mappings if THPs are disabled. + */ + if (thp_disabled_by_hw() || vma_thp_disabled(vma, vma->vm_flags)) + return ret; + if (!thp_vma_suitable_order(vma, haddr, PMD_ORDER)) return ret; -- 2.43.0