From patchwork Thu Jun 23 05:24:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Gowans, James" X-Patchwork-Id: 12891806 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 B6AC1C433EF for ; Thu, 23 Jun 2022 05:24:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00FCA8E0126; Thu, 23 Jun 2022 01:24:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F01868E0115; Thu, 23 Jun 2022 01:24:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC91C8E0126; Thu, 23 Jun 2022 01:24:23 -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 CB8BB8E0115 for ; Thu, 23 Jun 2022 01:24:23 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 9AE9E6130B for ; Thu, 23 Jun 2022 05:24:23 +0000 (UTC) X-FDA: 79608360006.10.0178235 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by imf08.hostedemail.com (Postfix) with ESMTP id E3EDA16001F for ; Thu, 23 Jun 2022 05:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1655961863; x=1687497863; h=from:to:subject:date:message-id:content-id: content-transfer-encoding:mime-version; bh=hMoso+/V2818SwupS9cNiewpYWBrlCw0KZ1RZ+8A8H0=; b=psmz01ga/hrJxURA4jek/nhBnGqF/aaSc2mVcF6q2TGt4dyhCccCqV6u BVmN27kI/Vjl1XLOZVgU+D7JsSvfE9evna8y4pl8TxFo1TNZz5qjHL5FN X3A1GPanURKy3ksq/y39diGDyiv5nLeMiGAfpBpI31qW6Lar0nkpRpoXr I=; X-IronPort-AV: E=Sophos;i="5.92,215,1650931200"; d="scan'208";a="231261649" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-c92fe759.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP; 23 Jun 2022 05:24:07 +0000 Received: from EX13D12EUC004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-c92fe759.us-east-1.amazon.com (Postfix) with ESMTPS id 0A77BC08FA; Thu, 23 Jun 2022 05:24:04 +0000 (UTC) Received: from EX13D14EUC001.ant.amazon.com (10.43.164.165) by EX13D12EUC004.ant.amazon.com (10.43.164.129) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Thu, 23 Jun 2022 05:24:03 +0000 Received: from EX13D14EUC001.ant.amazon.com ([10.43.164.165]) by EX13D14EUC001.ant.amazon.com ([10.43.164.165]) with mapi id 15.00.1497.036; Thu, 23 Jun 2022 05:24:03 +0000 From: "Gowans, James" To: "linux-mm@kvack.org" , "christian.koenig@amd.com" , "linux-kernel@vger.kernel.org" , =?utf-8?b?U2Now7ZuaGVyciwgSmFuIEgu?= , "thomas.hellstrom@linux.intel.com" , "akpm@linux-foundation.org" Subject: [PATCH] mm: Split huge PUD on wp_huge_pud fallback Thread-Topic: [PATCH] mm: Split huge PUD on wp_huge_pud fallback Thread-Index: AQHYhsFzt/PTU5inYUGKFJ1qIAcfKw== Date: Thu, 23 Jun 2022 05:24:03 +0000 Message-ID: <6f48d622eb8bce1ae5dd75327b0b73894a2ec407.camel@amazon.com> Accept-Language: en-ZA, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.43.165.192] Content-ID: <837474CBF305B649A87CA60126C3ED28@amazon.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=psmz01ga; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf08.hostedemail.com: domain of "prvs=16614e81a=jgowans@amazon.com" designates 207.171.184.29 as permitted sender) smtp.mailfrom="prvs=16614e81a=jgowans@amazon.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655961863; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=hMoso+/V2818SwupS9cNiewpYWBrlCw0KZ1RZ+8A8H0=; b=1DQ2pCFTpj4y1EdlZUlCTyfgQRGGqH/uf28GODtUuatrGGN6Mjskbg5WOHqfi9IYKQWh2f bH9KmTT0DCvxCJutI8RGzUEVe8TKO46bWdIHB+D5vtS+e9Tn3X0nQOpzAIoOGiBnulQz8T JSC9J/3i7nC8nV17CAgoP29NbyykJ6Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655961863; a=rsa-sha256; cv=none; b=l6j3ANewgXOP3qWDca2Ma0Fvsohp6jHrBVqBoElF3I0tLq0cH3CZ8nDZco9/q9k7DvlO1j JZ0TYBNTF9msk1p+G0Du2Cjc9hqPk5R/2F5m6LLyBSajC0bpJbW+fv2U5wFED2C8139Mo7 xnnISG+oHxIikAvcqb+zXP58HPJrA6M= X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: E3EDA16001F X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=psmz01ga; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf08.hostedemail.com: domain of "prvs=16614e81a=jgowans@amazon.com" designates 207.171.184.29 as permitted sender) smtp.mailfrom="prvs=16614e81a=jgowans@amazon.com" X-Stat-Signature: 1joxqc8izjxo3tcbq1yqpgea75pjp9at X-HE-Tag: 1655961862-293235 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: Currently the implementation will split the PUD when a fallback is taken inside the create_huge_pud function. This isn't where it should be done: the splitting should be done in wp_huge_pud, just like it's done for PMDs. Reason being that if a callback is taken during create, there is no PUD yet so nothing to split, whereas if a fallback is taken when encountering a write protection fault there is something to split. It looks like this was the original intention with the commit where the splitting was introduced, but somehow it got moved to the wrong place between v1 and v2 of the patch series. Rebase mistake perhaps. Fixes: 327e9fd48972 ("mm: Split huge pages on write-notify or COW") Cc: Thomas Hellström Cc: Andrew Morton Cc: Christian König Cc: Jan H. Schönherr Signed-off-by: James Gowans Reviewed-by: Thomas Hellström Acked-by: David Hildenbrand --- mm/memory.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7a089145cad4..4cf7d4b6c950 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4802,29 +4802,30 @@ static vm_fault_t create_huge_pud(struct vm_fault *vmf) defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vmf->vma)) - goto split; - if (vmf->vma->vm_ops->huge_fault) { - vm_fault_t ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); - - if (!(ret & VM_FAULT_FALLBACK)) - return ret; - } -split: - /* COW or write-notify not handled on PUD level: split pud.*/ - __split_huge_pud(vmf->vma, vmf->pud, vmf->address); + return VM_FAULT_FALLBACK; + if (vmf->vma->vm_ops->huge_fault) + return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ return VM_FAULT_FALLBACK; } static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) { -#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ + defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vmf->vma)) - return VM_FAULT_FALLBACK; - if (vmf->vma->vm_ops->huge_fault) - return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + goto split; + if (vmf->vma->vm_ops->huge_fault) { + vm_fault_t ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); + + if (!(ret & VM_FAULT_FALLBACK)) + return ret; + } +split: + /* COW or write-notify not handled on PUD level: split pud.*/ + __split_huge_pud(vmf->vma, vmf->pud, vmf->address); +#endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ return VM_FAULT_FALLBACK; }