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-Rspam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NEVBUf CUYSRC44xnR1aLU8pneafmrezdsc+3yvEz6fnbMTshZEkS2l/SagfDDPrRbLh6ONxuoVFh5DTsx4p5sS2TI0hxE/w2olBrDWTSzZjkCZ+oKVI6IbEqQ2MmeBFi60RsGAXqDiSJEx2lyoLJNl0gBhILElFABJaD93+2x4ogWorBAPaWpzGtvJz7xyxR4JNaJlS8VLrqs5U/g1BnWqxRTftGWTSKDBHXQ+o/E6eBUibXaMSM7PAkHIJe9R1tkT6icHKaWsE+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;