Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4448059imw; Tue, 19 Jul 2022 06:50:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uQ39Um1jcGXwOTliTlCR9dWNsx1z42c3yyuCM0/Vgpr9w9dTT6Yd0dnnGr7nFFbP5us+WK X-Received: by 2002:a17:906:7007:b0:6ff:8028:42e with SMTP id n7-20020a170906700700b006ff8028042emr30709155ejj.278.1658238652393; Tue, 19 Jul 2022 06:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238652; cv=none; d=google.com; s=arc-20160816; b=j0H+rRPlt0/fJdKwd40VAmpOSehyL+d7YZUBTACYBxora0/oEh2dkNAAGr1CoO9FrO tKSmeEv2LIIaUzjnxMDQ4unwD8tdq0Er4Hfqcko83EbzHExoRZu07w2nIPmfnXdojyzl 7YYgMDMGwsbmxm8a4S69ySAWFC7Nj1j+4lm8GX2l2SuIlUhYHvglW3ZgplG7XsZkkt7c mB6CUtePlPTkM7JpfqPRlbZu6KhWZKhRzMhUdiG9sBQqiZ9xy0XGpv3ZXvv/ToIGj4CF VCYElfn5afsBzJW8I4SqdPSxaeSfgyr49aj0zHbmbMUOK36QFYwS3ttqayo6mMzMWjZo wE5A== 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=zWQKKUT+wJWBmqcRw8wnF0UZknMxFzuskUrdfcq1Az4=; b=a6rl3RKM1+v3XNC/rRUSnpmUQCq+sB49TlzQute5HHcW7QAjzV2MwU8RF7hqhVBdWN PRL2uShCXWjubBetpBKc/SBNT8tbWRBZGfGEcMm1VVdgqfSKUBBuQnhN2ysAH6+fwF4U 4kdFmL5uI4eYALwDPn9w9oCcqr/DfsjwPewC/9VeFwmOsHX3+LtRadjnOENlEypZ9mXc uvCqqSCYgNw6ORvJwV5q40BIMXeRNymr1nlR7FrscPly3O7iq9nIV52TRHvWsPhivHw+ hrA7eW+v/YlVU/Bal/Zl5ZDBwcNlEXyrrqcxcZjK2Gn3LNa0xqfB7WNrWSmd1jvcmrZs hcew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V5mxilaX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb40-20020a1709076da800b006f445fe1697si4052714ejc.35.2022.07.19.06.50.28; Tue, 19 Jul 2022 06:50:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V5mxilaX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239174AbiGSMQY (ORCPT + 99 others); Tue, 19 Jul 2022 08:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239505AbiGSMOp (ORCPT ); Tue, 19 Jul 2022 08:14:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C9152E77; Tue, 19 Jul 2022 05:05:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 21367B81A8F; Tue, 19 Jul 2022 12:05:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71BFFC341C6; Tue, 19 Jul 2022 12:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232336; bh=YMDBGYootgjGAwFHAuKAVkJi74f5AYifSu57aZ2Fmkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V5mxilaX/5A1KtNbGomZZOA63Timi1VLxuVxSp6f94GYpqD+kIy+MyBo856DDIcvP YXxYHAR/9jKUk575F16wqSZ7w8Gbl0ZFqGLkBdmEtc/beMI6jKO9yAGoOBwDy4i8lv OklqVw/vGN325Q3fwx4rOcPuNCH1zVcmqd3TXXBM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Gowans , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , "=?UTF-8?q?Jan=20H . =20Sch=C3=B6nherr?=" , Andrew Morton Subject: [PATCH 5.10 009/112] mm: split huge PUD on wp_huge_pud fallback Date: Tue, 19 Jul 2022 13:53:02 +0200 Message-Id: <20220719114626.879484109@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gowans, James commit 14c99d65941538aa33edd8dc7b1bbbb593c324a2 upstream. 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. Link: https://lkml.kernel.org/r/6f48d622eb8bce1ae5dd75327b0b73894a2ec407.camel@amazon.com Fixes: 327e9fd48972 ("mm: Split huge pages on write-notify or COW") Signed-off-by: James Gowans Reviewed-by: Thomas Hellström Cc: Christian König Cc: Jan H. Schönherr Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/memory.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) --- a/mm/memory.c +++ b/mm/memory.c @@ -4369,6 +4369,19 @@ static vm_fault_t create_huge_pud(struct 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 */ + return VM_FAULT_FALLBACK; +} + +static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) +{ +#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)) goto split; if (vmf->vma->vm_ops->huge_fault) { vm_fault_t ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); @@ -4379,19 +4392,7 @@ static vm_fault_t create_huge_pud(struct 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 */ - return VM_FAULT_FALLBACK; -} - -static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) -{ -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - /* 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 */ +#endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ return VM_FAULT_FALLBACK; }