From patchwork Fri Oct 11 10:24:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13832342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 894ECCFD316 for ; Fri, 11 Oct 2024 10:25:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2124C6B00AD; Fri, 11 Oct 2024 06:25:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C4646B00B1; Fri, 11 Oct 2024 06:25:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08A2B6B00B2; Fri, 11 Oct 2024 06:25:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DA3BE6B00AD for ; Fri, 11 Oct 2024 06:25:08 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DEA1FABEB2 for ; Fri, 11 Oct 2024 10:24:59 +0000 (UTC) X-FDA: 82660938654.03.34219CF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 44A3920008 for ; Fri, 11 Oct 2024 10:25:04 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YRvUPBv9; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728642262; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VMssNf1Ju+sw1bhZpq8lk0Jjp7pzX4VBi27YvpYNCzI=; b=il6uSUCm2yEbEIg5rT8TkvdN+lBF8pQTDBK/nBRDFpEYRfE6nweWmeDR8fZUYgR5gbbRsc MwUDOBkOy/Z/DWCCgRngh5zXohT1FcFg69d6Mc2/6kvHayfMrpf8Tgv496WAso0Y392OLu SKHF43xwNReSEi6AnAmax0C0LQorfLI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YRvUPBv9; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728642262; a=rsa-sha256; cv=none; b=EyEkGvduErOm69SxSByvrNCr+JNH0w9dr1cbab9FrnSn39oqGQjWoHiRUcZvij7FnAqdmw OBq1c0f1zwQ3q6s1K3Wh4TygYOGLABLdxTaBc4a7hBhYG6WgXAWKjSiKbceNMBcKG9EM29 BDAJB+en1ERxTZFZ/KewvW0Gi0HQy+M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728642306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VMssNf1Ju+sw1bhZpq8lk0Jjp7pzX4VBi27YvpYNCzI=; b=YRvUPBv9zP5NMDpejjomNmR8r4LWaBnl4hx2xdYhybq1yXwbBzJAAvDVDDvZWain3vUsMm UPNLH0Z70dRXJ812Ol179ZWeXUh9jGgAnyJFIJyl/6aDxQxCKF6tMFKV2c1KY+4nhE5285 LKVIvTg0BRgGetUilkIeSRDcILzjRaM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-pXT2G1CgOGWkQX4PSZq0Wg-1; Fri, 11 Oct 2024 06:25:00 -0400 X-MC-Unique: pXT2G1CgOGWkQX4PSZq0Wg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4D2C11955F07; Fri, 11 Oct 2024 10:24:58 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.80.4]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1B6E91955F42; Fri, 11 Oct 2024 10:24:52 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, kvm@vger.kernel.org, David Hildenbrand , Andrew Morton , Hugh Dickins , Thomas Huth , "Matthew Wilcox (Oracle)" , Ryan Roberts , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Kefeng Wang Subject: [PATCH v1 1/2] mm: huge_memory: add vma_thp_disabled() and thp_disabled_by_hw() Date: Fri, 11 Oct 2024 12:24:44 +0200 Message-ID: <20241011102445.934409-2-david@redhat.com> In-Reply-To: <20241011102445.934409-1-david@redhat.com> References: <20241011102445.934409-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspam-User: X-Stat-Signature: 8s5n6h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QX63b06zioOmRRX0LWHRIXoit+xEasWBZf22vmpWxAwnIAIBEWW30LFE9mC6wIBizyiuANbOAFS/QUQaH859N8DXpaAnxuBLEO2SizWsRTSQjaUHO21IbQSVDtI5WsFfllv+vYD3FLsFlAPq+iwujRZ/KqgJsVQJtO8K9sndBTV0/CdBnWndZd4MZQ1n2EkPwnAGOKuZNm+S5m1NzMNIuaAbszoY8N3Wxdo+NDO/6MRc/wdjbEn2PfJtAi/mgAc+pKk8PGaDLsKPyYivEwSGo6LXBJT8BNaXsGLfMzK866hte1q16PzbpJrq3mxglHmBzr/ZYriP05Kwp18zW1rXU63DouCNgb+qydysIRqj77lVnOL2guLG/3CiRb9ppYb8LNRZC1qUXks= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kefeng Wang Add vma_thp_disabled() and thp_disabled_by_hw() helpers to be shared by shmem_allowable_huge_orders() and __thp_vma_allowable_orders(). Signed-off-by: Kefeng Wang [ rename to vma_thp_disabled(), split out thp_disabled_by_hw() ] Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts --- include/linux/huge_mm.h | 18 ++++++++++++++++++ mm/huge_memory.c | 13 +------------ mm/shmem.c | 7 +------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 67d0ab3c3bba..ef5b80e48599 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -322,6 +322,24 @@ struct thpsize { (transparent_hugepage_flags & \ (1<vm_mm->flags); +} + +static inline bool thp_disabled_by_hw(void) +{ + /* If the hardware/firmware marked hugepage support disabled. */ + return transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED); +} + unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned long addr, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 87b49ecc7b1e..2fb328880b50 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -109,18 +109,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, if (!vma->vm_mm) /* vdso */ return 0; - /* - * Explicitly disabled through madvise or prctl, or some - * architectures may disable THP for some mappings, for - * example, s390 kvm. - * */ - if ((vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) - return 0; - /* - * If the hardware/firmware marked hugepage support disabled. - */ - if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) + if (thp_disabled_by_hw() || vma_thp_disabled(vma, vm_flags)) return 0; /* khugepaged doesn't collapse DAX vma, but page fault is fine. */ diff --git a/mm/shmem.c b/mm/shmem.c index 4f11b5506363..c5adb987b23c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1664,12 +1664,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, loff_t i_size; int order; - if (vma && ((vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) - return 0; - - /* If the hardware/firmware marked hugepage support disabled. */ - if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) + if (thp_disabled_by_hw() || (vma && vma_thp_disabled(vma, vm_flags))) return 0; global_huge = shmem_huge_global_enabled(inode, index, write_end, From patchwork Fri Oct 11 10:24:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13832343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47A0BCFD31D for ; Fri, 11 Oct 2024 10:25:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEA6D6B00A2; Fri, 11 Oct 2024 06:25:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C722F6B00B1; Fri, 11 Oct 2024 06:25:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3A9F6B00B2; Fri, 11 Oct 2024 06:25:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 90A6A6B00A2 for ; Fri, 11 Oct 2024 06:25:11 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 58116120FEF for ; Fri, 11 Oct 2024 10:25:07 +0000 (UTC) X-FDA: 82660938738.09.65EA9CA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id B47D61A0006 for ; Fri, 11 Oct 2024 10:25:06 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Eg0IZHMX; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728642126; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UZ3IdlQSiC9SBRAFeIkUjQ3G20iTXPL8FgSwyp2DDL0=; b=64JdGJuhJq8w3NLgVClv3e7ol+yrAoSkWRbg6bmpJuS5lxZYFeKMl6s1wTBZOL2RLLoVx7 /fn/8vm0E5zqnBmcvW09K3TRM7XxIS6g4gH7b1fvqr4pOIRORTHrR9QRJdwU45O8iuoxSM o+xtzAdlcW4pow82YlIR7KcaNdxZ8MU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Eg0IZHMX; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728642126; a=rsa-sha256; cv=none; b=uIuxJln2zsDdRqtpso9qJpuerZ5sMl5njMxNmd1cWliAjZTx3he/kiNhaM/ExlqHUE80Ls G2sRI0aagBueg3hr3BaBJAeHWRdADPKD/yxFI0vC/fC5A2n/ksIJxld1dKGhXguyCQdi1c kPtpcsBY8yCyTL2rmYaULugBB7E1g14= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728642308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UZ3IdlQSiC9SBRAFeIkUjQ3G20iTXPL8FgSwyp2DDL0=; b=Eg0IZHMXIT2pR11GyVUKzabwVHslxYHCT9x7YwXqKVku4WrzDVACHKWinBkKlyMrq66OJR h1TOgeQOWdsc0QLTUlc/VkJdn2SQCEOkHXI2TQsCeUscc/wzbhgZlU5KWsRmin1NqCunYu /Vu1hg5nRxeet4FwJob+8SSSQvZA3ts= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-AWsUiTUhPfSrctqTbSxh0w-1; Fri, 11 Oct 2024 06:25:05 -0400 X-MC-Unique: AWsUiTUhPfSrctqTbSxh0w-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9D7D91955F3D; Fri, 11 Oct 2024 10:25:03 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.80.4]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E484D1956089; Fri, 11 Oct 2024 10:24:58 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, kvm@vger.kernel.org, David Hildenbrand , Andrew Morton , Hugh Dickins , Thomas Huth , "Matthew Wilcox (Oracle)" , Ryan Roberts , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Kefeng Wang , Leo Fu Subject: [PATCH v1 2/2] mm: don't install PMD mappings when THPs are disabled by the hw/process/vma Date: Fri, 11 Oct 2024 12:24:45 +0200 Message-ID: <20241011102445.934409-3-david@redhat.com> In-Reply-To: <20241011102445.934409-1-david@redhat.com> References: <20241011102445.934409-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B47D61A0006 X-Stat-Signature: zd3573b13aiccdfie7fuf57x6cmfntri X-Rspam-User: X-HE-Tag: 1728642306-731843 X-HE-Meta: U2FsdGVkX18TsmBfgtopBQrp26jFe99ruYi/9xUgvughJ/F/B9bTIa+cBKNkgTyuFnsnySBPSR9zf0jvqcUmTmYVHK/sUZKhmHnUIlkjuvprssPfrUzA+o5WSV3oMor0fMFzgryLqhXrMM05+ctTuHI2epLxzz7ZgynRSODFkez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kT6icHKaWsE+JSl+Vm1A4vdiRQjz4sIjAAOVscKTEbsQVu9cIVloF96W2IFzRMyYxMbeD7CPZajTflfn6aqMjY/btDsP9VJ+9LDfBnrgt/WeYJP10e4bCHrNVel04d8HkVui9VFbAVGdkIWg5pSCTEjW0nfGISWLo9N4vycxrOy7nPMJSiR/XNDt+U9LCnQ0X9sm+qfvQxzqjkpHP2fiIiEqWCmb7UCiQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. Reported-by: Leo Fu Fixes: 793917d997df ("mm/readahead: Add large folio readahead") Cc: Thomas Huth Cc: Matthew Wilcox (Oracle) Cc: Ryan Roberts Cc: Christian Borntraeger Cc: Janosch Frank Cc: Claudio Imbrenda Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts --- mm/memory.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 2366578015ad..a2e501489517 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4925,6 +4925,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;