From patchwork Wed May 31 22:08:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 13262763 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A5A3C77B73 for ; Wed, 31 May 2023 22:08:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230388AbjEaWIh (ORCPT ); Wed, 31 May 2023 18:08:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjEaWIg (ORCPT ); Wed, 31 May 2023 18:08:36 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49A631B8 for ; Wed, 31 May 2023 15:08:19 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-626157a186bso8552996d6.1 for ; Wed, 31 May 2023 15:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1685570898; x=1688162898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xcpMDk08TnAKM11DZYaTQHoJHdMHYlx0PmCfJSmuqxQ=; b=wEwknpWuACfVk2BLZAAwhK1P+A8Agyg2LkaiMrZv/vk+Jqv3PjEA3zHf+KOHmK4Pxx sYYbfV/UmdJ7qbsavZh91UeTFvV/aLbtLtNOxKYXZP0bQ+FrDbx/ezrzjN+6DuOM96+6 CyyRczA9px0WqR6nr3eZ09ZYqir15Ii3x7h8o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685570898; x=1688162898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xcpMDk08TnAKM11DZYaTQHoJHdMHYlx0PmCfJSmuqxQ=; b=boA3mVFl/R3wnKPeUchKbH35hGCFCZUSuGlI3+0Va60V+tmRlDhBOnFPpQSiiQdCQX bseJgsEKpsExDohe3kV23QHJpW0r3ht5NZ1VvuIhV2TenQEKsgZ4OkTwBJH32iPCai0g zurzAOeR/eAbQluYIBvgi8dPcSBGXqJvNa8Tov03VgFb5nHCf8lFmoakuhb0o7F+yh1o Dkdxq9Mbx5iieHDNCtkXy8rZP9fmNFIed1hAATFWBkRWWLtt4OlgM4+XWwEwdiUaCunD ArVMDn4RL6TyAeMdMNnA+ABuM+39k6JFj77sNBSMNvmCuac75HrjrQnxG1L6FOHPVrrR qADQ== X-Gm-Message-State: AC+VfDyvciti8hp4XnAqM3cGwDzANJMrZvDAN17nOoVIazernME2nqe8 FhF0Uzop/zEK34v1MpLEQqh8Kg== X-Google-Smtp-Source: ACHHUZ6VD/g4jSj2d9B84SOdyc6mJVRalNKUWWpk2+9CxmTsHgUmiKwb5GcyFfj7v6tYE/kvvmPfuQ== X-Received: by 2002:a05:6214:509d:b0:570:5389:2216 with SMTP id kk29-20020a056214509d00b0057053892216mr16116075qvb.22.1685570898020; Wed, 31 May 2023 15:08:18 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id f2-20020ac87f02000000b003f6b0f4126fsm6666172qtk.8.2023.05.31.15.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 15:08:17 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Linus Torvalds , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra , Vineeth Pillai Subject: [PATCH v4 1/7] mm/mremap: Optimize the start addresses in move_page_tables() Date: Wed, 31 May 2023 22:08:01 +0000 Message-ID: <20230531220807.2048037-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog In-Reply-To: <20230531220807.2048037-1-joel@joelfernandes.org> References: <20230531220807.2048037-1-joel@joelfernandes.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Recently, we see reports [1] of a warning that triggers due to move_page_tables() doing a downward and overlapping move on a mutually-aligned offset within a PMD. By mutual alignment, I mean the source and destination addresses of the mremap are at the same offset within a PMD. This mutual alignment along with the fact that the move is downward is sufficient to cause a warning related to having an allocated PMD that does not have PTEs in it. This warning will only trigger when there is mutual alignment in the move operation. A solution, as suggested by Linus Torvalds [2], is to initiate the copy process at the PMD level whenever such alignment is present. Implementing this approach will not only prevent the warning from being triggered, but it will also optimize the operation as this method should enhance the speed of the copy process whenever there's a possibility to start copying at the PMD level. Some more points: a. The optimization can be done only when both the source and destination of the mremap do not have anything mapped below it up to a PMD boundary. I add support to detect that. b. #a is not a problem for the call to move_page_tables() from exec.c as nothing is expected to be mapped below the source. However, for non-overlapping mutually aligned moves as triggered by mremap(2), I added support for checking such cases. c. I currently only optimize for PMD moves, in the future I/we can build on this work and do PUD moves as well if there is a need for this. But I want to take it one step at a time. d. We need to be careful about mremap of ranges within the VMA itself. For this purpose, I added checks to determine if the address to align is not the beginning of the VMA which that address corresponds to. [1] https://lore.kernel.org/all/ZB2GTBD%2FLWTrkOiO@dhcp22.suse.cz/ [2] https://lore.kernel.org/all/CAHk-=whd7msp8reJPfeGNyt0LiySMT0egExx3TVZSX3Ok6X=9g@mail.gmail.com/ Suggested-by: Linus Torvalds Signed-off-by: Joel Fernandes (Google) --- mm/mremap.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/mm/mremap.c b/mm/mremap.c index 411a85682b58..bf355e4d6bd4 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -478,6 +478,51 @@ static bool move_pgt_entry(enum pgt_entry entry, struct vm_area_struct *vma, return moved; } +/* + * A helper to check if a previous mapping exists. Required for + * move_page_tables() and realign_addr() to determine if a previous mapping + * exists before we can do realignment optimizations. + */ +static bool can_align_down(struct vm_area_struct *vma, unsigned long addr_to_align, + unsigned long mask) +{ + unsigned long addr_masked = addr_to_align & mask; + struct vm_area_struct *prev = NULL, *cur = NULL; + + /* + * If @addr_to_align of either source or destination is not the beginning + * of the corresponding VMA, we can't align down or we will destroy part + * of the current mapping. + */ + if (vma->vm_start != addr_to_align) + return false; + + /* + * Find the VMA before @vma to see if it subsumes the masked address. + * The mmap write lock is held here so the lookup is safe. + */ + cur = find_vma_prev(vma->vm_mm, vma->vm_start, &prev); + if (WARN_ON_ONCE(cur != vma)) + return false; + + return !prev || prev->vm_end <= addr_masked; +} + +/* Opportunistically realign to specified boundary for faster copy. */ +static void realign_addr(unsigned long *old_addr, struct vm_area_struct *old_vma, + unsigned long *new_addr, struct vm_area_struct *new_vma, + unsigned long mask) +{ + bool mutually_aligned = (*old_addr & ~mask) == (*new_addr & ~mask); + + if ((*old_addr & ~mask) && mutually_aligned + && can_align_down(old_vma, *old_addr, mask) + && can_align_down(new_vma, *new_addr, mask)) { + *old_addr = *old_addr & mask; + *new_addr = *new_addr & mask; + } +} + unsigned long move_page_tables(struct vm_area_struct *vma, unsigned long old_addr, struct vm_area_struct *new_vma, unsigned long new_addr, unsigned long len, @@ -493,6 +538,15 @@ unsigned long move_page_tables(struct vm_area_struct *vma, old_end = old_addr + len; + /* + * If possible, realign addresses to PMD boundary for faster copy. + * Don't align for intra-VMA moves as we may destroy existing mappings. + */ + if ((vma != new_vma) + && (len >= PMD_SIZE - (old_addr & ~PMD_MASK))) { + realign_addr(&old_addr, vma, &new_addr, new_vma, PMD_MASK); + } + if (is_vm_hugetlb_page(vma)) return move_hugetlb_page_tables(vma, new_vma, old_addr, new_addr, len); @@ -565,6 +619,13 @@ unsigned long move_page_tables(struct vm_area_struct *vma, mmu_notifier_invalidate_range_end(&range); + /* + * Prevent negative return values when {old,new}_addr was realigned + * but we broke out of the above loop for the first PMD itself. + */ + if (len + old_addr < old_end) + return 0; + return len + old_addr - old_end; /* how much done */ } From patchwork Wed May 31 22:08:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 13262764 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 413E8C77B73 for ; Wed, 31 May 2023 22:08:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230419AbjEaWIl (ORCPT ); Wed, 31 May 2023 18:08:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbjEaWIj (ORCPT ); Wed, 31 May 2023 18:08:39 -0400 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27D2A1BD for ; Wed, 31 May 2023 15:08:20 -0700 (PDT) Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-75b08639930so81569785a.0 for ; Wed, 31 May 2023 15:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1685570899; x=1688162899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IKyKgK7RUrVgt5O/vBjlSKA4QqkZUlv4FmPm/U0omy4=; b=obKUiscoppUsJUJ3/7hX1SsM+6rEew9ZQfKAMh3vWfYW1rmT9yIKGAZubZxIr4LEiG +Al4BVanJStN5/cLaoxvQfUA8HotrTrtltYR3OAN7CO/qw/V5C9yoijvOQuFNRqFFvUd FvFegsoDVgzfl78OoRhTbHXYk02PvrhI2s2+A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685570899; x=1688162899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IKyKgK7RUrVgt5O/vBjlSKA4QqkZUlv4FmPm/U0omy4=; b=IHliGCJ/QUAEt+Eq8gWRFAFVI4XYJFNWY30e27pbbxDwNpbVDSVwooKuTTbm6AoW43 jmt9+SWtYVKhL5cvLjLeEaw9wRsdEYeWzdHz+6y2zwqvvQTKQ8bg2Jj4Qj6QDKiT14LE tdui41uRE341P4ikDfARv9DzPdqqquq+xrZUJ3bdxvWIxJ/Ob2HVmpsM7v4zIZ1c8xL6 wDD5xAI55NE6p46VCmzpF/r+oNVeorx2S6Utcn0gtYcSZemgGmYH3q6Y7Jz1bsvrTfUy TrBD+u/o7CaRmYcpQxtstHXF/SHVKo0Y6JzjGiheQ+k0fXCZotNtKQYq6KIpFtdg43KT 0RKg== X-Gm-Message-State: AC+VfDyknaxle64pW86gqEu3Nqz+gPmjcLjxPYMCHLJf2PWs2gtJW2lt 6k8tfdiTA/RA01sOXQ+CxRDULw== X-Google-Smtp-Source: ACHHUZ7AkCLZ1IadOtiNpTKRumVwd03RrWCxqJfgVOKG6KWsEhn44uxV0VQrpA8Ip4FERNK4pI0qpA== X-Received: by 2002:ac8:5a83:0:b0:3f5:1d97:1922 with SMTP id c3-20020ac85a83000000b003f51d971922mr15388023qtc.2.1685570899022; Wed, 31 May 2023 15:08:19 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id f2-20020ac87f02000000b003f6b0f4126fsm6666172qtk.8.2023.05.31.15.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 15:08:18 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Linus Torvalds , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra , Vineeth Pillai Subject: [PATCH v4 2/7] mm/mremap: Allow moves within the same VMA for stack Date: Wed, 31 May 2023 22:08:02 +0000 Message-ID: <20230531220807.2048037-3-joel@joelfernandes.org> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog In-Reply-To: <20230531220807.2048037-1-joel@joelfernandes.org> References: <20230531220807.2048037-1-joel@joelfernandes.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org For the stack move happening in shift_arg_pages(), the move is happening within the same VMA which spans the old and new ranges. In case the aligned address happens to fall within that VMA, allow such moves and don't abort the optimization. In the mremap case, we cannot allow any such moves as will end up destroying some part of the mapping (either the source of the move, or part of the existing mapping). So just avoid it for mremap. Signed-off-by: Joel Fernandes (Google) --- fs/exec.c | 2 +- include/linux/mm.h | 2 +- mm/mremap.c | 40 ++++++++++++++++++---------------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 7c44d0c65b1b..7a7217353115 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -707,7 +707,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift) * process cleanup to remove whatever mess we made. */ if (length != move_page_tables(vma, old_start, - vma, new_start, length, false)) + vma, new_start, length, false, true)) return -ENOMEM; lru_add_drain(); diff --git a/include/linux/mm.h b/include/linux/mm.h index 1f79667824eb..dd415cd2493d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2265,7 +2265,7 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen); extern unsigned long move_page_tables(struct vm_area_struct *vma, unsigned long old_addr, struct vm_area_struct *new_vma, unsigned long new_addr, unsigned long len, - bool need_rmap_locks); + bool need_rmap_locks, bool for_stack); /* * Flags used by change_protection(). For now we make it a bitmap so diff --git a/mm/mremap.c b/mm/mremap.c index bf355e4d6bd4..0283f9f43d92 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -479,22 +479,23 @@ static bool move_pgt_entry(enum pgt_entry entry, struct vm_area_struct *vma, } /* - * A helper to check if a previous mapping exists. Required for - * move_page_tables() and realign_addr() to determine if a previous mapping - * exists before we can do realignment optimizations. + * A helper to check if aligning down is OK. The newly aligned address should + * not fall on any existing mapping otherwise we don't align. For the stack + * moving down, that's a special move within the VMA that is created to span + * the source and destination of the move, so we make an exception for it. */ static bool can_align_down(struct vm_area_struct *vma, unsigned long addr_to_align, - unsigned long mask) + unsigned long mask, bool for_stack) { unsigned long addr_masked = addr_to_align & mask; struct vm_area_struct *prev = NULL, *cur = NULL; /* - * If @addr_to_align of either source or destination is not the beginning - * of the corresponding VMA, we can't align down or we will destroy part - * of the current mapping. + * Other than for stack moves, if @addr_to_align of either source or + * destination is not the beginning of the corresponding VMA, we can't + * align down or we will destroy part of the current mapping. */ - if (vma->vm_start != addr_to_align) + if (!for_stack && vma->vm_start != addr_to_align) return false; /* @@ -511,13 +512,13 @@ static bool can_align_down(struct vm_area_struct *vma, unsigned long addr_to_ali /* Opportunistically realign to specified boundary for faster copy. */ static void realign_addr(unsigned long *old_addr, struct vm_area_struct *old_vma, unsigned long *new_addr, struct vm_area_struct *new_vma, - unsigned long mask) + unsigned long mask, bool for_stack) { bool mutually_aligned = (*old_addr & ~mask) == (*new_addr & ~mask); if ((*old_addr & ~mask) && mutually_aligned - && can_align_down(old_vma, *old_addr, mask) - && can_align_down(new_vma, *new_addr, mask)) { + && can_align_down(old_vma, *old_addr, mask, for_stack) + && can_align_down(new_vma, *new_addr, mask, for_stack)) { *old_addr = *old_addr & mask; *new_addr = *new_addr & mask; } @@ -526,7 +527,7 @@ static void realign_addr(unsigned long *old_addr, struct vm_area_struct *old_vma unsigned long move_page_tables(struct vm_area_struct *vma, unsigned long old_addr, struct vm_area_struct *new_vma, unsigned long new_addr, unsigned long len, - bool need_rmap_locks) + bool need_rmap_locks, bool for_stack) { unsigned long extent, old_end; struct mmu_notifier_range range; @@ -538,14 +539,9 @@ unsigned long move_page_tables(struct vm_area_struct *vma, old_end = old_addr + len; - /* - * If possible, realign addresses to PMD boundary for faster copy. - * Don't align for intra-VMA moves as we may destroy existing mappings. - */ - if ((vma != new_vma) - && (len >= PMD_SIZE - (old_addr & ~PMD_MASK))) { - realign_addr(&old_addr, vma, &new_addr, new_vma, PMD_MASK); - } + /* If possible, realign addresses to PMD boundary for faster copy. */ + if (len >= PMD_SIZE - (old_addr & ~PMD_MASK)) + realign_addr(&old_addr, vma, &new_addr, new_vma, PMD_MASK, for_stack); if (is_vm_hugetlb_page(vma)) return move_hugetlb_page_tables(vma, new_vma, old_addr, @@ -694,7 +690,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, } moved_len = move_page_tables(vma, old_addr, new_vma, new_addr, old_len, - need_rmap_locks); + need_rmap_locks, false); if (moved_len < old_len) { err = -ENOMEM; } else if (vma->vm_ops && vma->vm_ops->mremap) { @@ -708,7 +704,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, * and then proceed to unmap new area instead of old. */ move_page_tables(new_vma, new_addr, vma, old_addr, moved_len, - true); + true, false); vma = new_vma; old_len = new_len; old_addr = new_addr; From patchwork Wed May 31 22:08:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 13262765 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5AF8C7EE2A for ; Wed, 31 May 2023 22:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230428AbjEaWIo (ORCPT ); Wed, 31 May 2023 18:08:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230393AbjEaWIk (ORCPT ); Wed, 31 May 2023 18:08:40 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B321BF for ; Wed, 31 May 2023 15:08:20 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-6260a2522d9so2167806d6.3 for ; Wed, 31 May 2023 15:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1685570900; x=1688162900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hVpzQtIDQfKWEqbseo+tZ+eEsBzkT6BTR9cKFnwSYiE=; b=UVc+juOdhvc+cdjx5ehHJJwwP68jGUuabxnGl2sSfw5+c3rM6PEEz7zmzj6t/Ykjlz IEsXCnKiFlo+h2JixjtD4OcEGGHRU/PJBz4uJQNMcO2ZId0sz4Pi773QRZBHIET4s7rS u0CUYL69ZSD7t8s8GCIDl4lvJdB5gvJ7I/eFc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685570900; x=1688162900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hVpzQtIDQfKWEqbseo+tZ+eEsBzkT6BTR9cKFnwSYiE=; b=VfSmQvSd84GZO0JzHEOnpIsyiz7/h8iqwMROChI51PWjP7srJe5DAfhepZk6ljcymq 7Pgic+jem950scO9FoB/mvpKzddSrQeGIJYxCn62bKbPGLa6OldUb5pjLG5j5JYBmLxu eKwiDa6uBybF6HiVYdqJNqvZCEiV5gYaCNT/UT7X3Of7IeodEsdLGSc+B+IjrlFIaUjS k6zWQJ8aM7/GRkhSc7hHZGAz+kP+j+Vai8KUoKvtiCfKuYVcYe6pZKTDoiT0U7fIlhgI 3QVeDQXlaYvRVPlOfiO/ZgoyKESWGMr+B5dadpIbB0AR/C/8HUqpZ2xQsE188KVtKVUL lFWw== X-Gm-Message-State: AC+VfDzlWy2xIi6zUQS6K+OTu5QQx5bLkPheYP7fIQrbpiZO8Oe9wT2S 3r8mAesD6Fw6UAkocDTeAVzjzg== X-Google-Smtp-Source: ACHHUZ6MK0NGbKvNzGTkIT5KQRbjPCfTItoxAs0WkJkwEfUWMktvJqSRp0xRq7Tiv2SENcLbvIsx6Q== X-Received: by 2002:a05:6214:1ccc:b0:625:1c04:6761 with SMTP id g12-20020a0562141ccc00b006251c046761mr8116673qvd.27.1685570899912; Wed, 31 May 2023 15:08:19 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id f2-20020ac87f02000000b003f6b0f4126fsm6666172qtk.8.2023.05.31.15.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 15:08:19 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Linus Torvalds , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra , Vineeth Pillai Subject: [PATCH v4 3/7] selftests: mm: Fix failure case when new remap region was not found Date: Wed, 31 May 2023 22:08:03 +0000 Message-ID: <20230531220807.2048037-4-joel@joelfernandes.org> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog In-Reply-To: <20230531220807.2048037-1-joel@joelfernandes.org> References: <20230531220807.2048037-1-joel@joelfernandes.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When a valid remap region could not be found, the source mapping is not cleaned up. Fix the goto statement such that the clean up happens. Signed-off-by: Joel Fernandes (Google) --- tools/testing/selftests/mm/mremap_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c index 5c3773de9f0f..6822d657f589 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -316,7 +316,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb, if (addr + c.dest_alignment < addr) { ksft_print_msg("Couldn't find a valid region to remap to\n"); ret = -1; - goto out; + goto clean_up_src; } addr += c.dest_alignment; } From patchwork Wed May 31 22:08:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 13262766 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3E6FC77B73 for ; Wed, 31 May 2023 22:08:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230473AbjEaWIv (ORCPT ); Wed, 31 May 2023 18:08:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230323AbjEaWIn (ORCPT ); Wed, 31 May 2023 18:08:43 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15E53196 for ; Wed, 31 May 2023 15:08:21 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-3f6b2f1a04bso68295951cf.3 for ; Wed, 31 May 2023 15:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1685570901; x=1688162901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dpicKoUd2HYKUWTIhMS6ThagQPd/JY7bC7rJfvoQE2Y=; b=C2nanwM4s2qBeaw7g/O1s/IU/DVR7Y2rNl+A3MbDPeVyLvdaIPdY6T2eaGhET6A0sF up/AOMYaez92DN3FPLb14JMGsjTAdM2hcriEezhuAu++ExO/CNN3lO1c6isZ2nAox6kS 6vZCyox2c8xGrqTdhmbAICcrkrOV8Zq0SaMjs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685570901; x=1688162901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dpicKoUd2HYKUWTIhMS6ThagQPd/JY7bC7rJfvoQE2Y=; b=fwovIn+/q1AnRPA7gOq3lkQhXawrsAHzpABBey6g5cp29Vov+wJ5++eb9S7rjrZ3tq 1WWbwtNm5z5ReuogkOXSpBPj+/Fur7/NtGkojzYfjAVBu3+D0uv3UW6tnVgQYeACchZZ 1NCB/Mp7izMOdkjXhtnvB7D5Zewu+ivb9IGJflEuE/pwo5bIY3ukHzm1spCs8OG90bZx 1VnJTr5bg8xMPxg+o2J6bmjj5c50YknWf8DRIFeSbECuLKOab0POJ5McofM/YX4+eaYt ZB6I/7I7iq95TkAjQ43zdFNYKcAklyGL2SjZlbu5vJ+QldPViXF+YSahO1hXeuFywdHf zpPw== X-Gm-Message-State: AC+VfDzuwcqLa3g50i9YKaklefPC58ZcPpIvByFb0lF541I++TtWmeE+ CsczeSYhiuFhyWaSukKdlYfXXA== X-Google-Smtp-Source: ACHHUZ4fuBeiJwYmTyjlbh3vNdxD6U2rVYsiG5NEaciB66hwrL3r2K1rWBnhNt+DCnNTWPl/qP0dEg== X-Received: by 2002:a05:622a:189d:b0:3f4:cfed:96bd with SMTP id v29-20020a05622a189d00b003f4cfed96bdmr9701607qtc.21.1685570900832; Wed, 31 May 2023 15:08:20 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id f2-20020ac87f02000000b003f6b0f4126fsm6666172qtk.8.2023.05.31.15.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 15:08:20 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Linus Torvalds , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra , Vineeth Pillai Subject: [PATCH v4 4/7] selftests: mm: Add a test for mutually aligned moves > PMD size Date: Wed, 31 May 2023 22:08:04 +0000 Message-ID: <20230531220807.2048037-5-joel@joelfernandes.org> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog In-Reply-To: <20230531220807.2048037-1-joel@joelfernandes.org> References: <20230531220807.2048037-1-joel@joelfernandes.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This patch adds a test case to check if a PMD-alignment optimization successfully happens. I add support to make sure there is some room before the source mapping, otherwise the optimization to trigger PMD-aligned move will be disabled as the kernel will detect that a mapping before the source exists and such optimization becomes impossible. Signed-off-by: Joel Fernandes (Google) --- tools/testing/selftests/mm/mremap_test.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c index 6822d657f589..6304eb0947a3 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -44,6 +44,7 @@ enum { _1MB = 1ULL << 20, _2MB = 2ULL << 20, _4MB = 4ULL << 20, + _5MB = 5ULL << 20, _1GB = 1ULL << 30, _2GB = 2ULL << 30, PMD = _2MB, @@ -235,6 +236,11 @@ static void *get_source_mapping(struct config c) unsigned long long mmap_min_addr; mmap_min_addr = get_mmap_min_addr(); + /* + * For some tests, we need to not have any mappings below the + * source mapping. Add some headroom to mmap_min_addr for this. + */ + mmap_min_addr += 10 * _4MB; retry: addr += c.src_alignment; @@ -434,7 +440,7 @@ static int parse_args(int argc, char **argv, unsigned int *threshold_mb, return 0; } -#define MAX_TEST 13 +#define MAX_TEST 14 #define MAX_PERF_TEST 3 int main(int argc, char **argv) { @@ -500,6 +506,10 @@ int main(int argc, char **argv) test_cases[12] = MAKE_TEST(PUD, PUD, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, "2GB mremap - Source PUD-aligned, Destination PUD-aligned"); + /* Src and Dest addr 1MB aligned. 5MB mremap. */ + test_cases[13] = MAKE_TEST(_1MB, _1MB, _5MB, NON_OVERLAPPING, EXPECT_SUCCESS, + "5MB mremap - Source 1MB-aligned, Destination 1MB-aligned"); + perf_test_cases[0] = MAKE_TEST(page_size, page_size, _1GB, NON_OVERLAPPING, EXPECT_SUCCESS, "1GB mremap - Source PTE-aligned, Destination PTE-aligned"); /* From patchwork Wed May 31 22:08:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 13262768 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92B7DC7EE23 for ; Wed, 31 May 2023 22:08:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230434AbjEaWIw (ORCPT ); Wed, 31 May 2023 18:08:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230427AbjEaWIo (ORCPT ); Wed, 31 May 2023 18:08:44 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D52ECE43 for ; Wed, 31 May 2023 15:08:22 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6259c242c96so2198966d6.3 for ; Wed, 31 May 2023 15:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1685570901; x=1688162901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5uxB3oRU/w04R3PYxIzVnLNEBr3g7H+Udo5r270v9fQ=; b=KZ9VWWx/xG7DewQ/8d+zcl3ld9GrYdlEo/fNzEJu2I3fo1LrpAp8r9/ibWQsUMx58r CoxF/f179s/puFhFnoF5Ey6W27dHDYy61tHYsBYjFECoFjwNB6KbmP6kwo8P20umokpb BwdyqxWQhW1JptP5/nrvDL8ITCLwrxHrx+5vE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685570901; x=1688162901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5uxB3oRU/w04R3PYxIzVnLNEBr3g7H+Udo5r270v9fQ=; b=X9Uc+rq7gk7faZ/Y6Xeuc4si/WFecLNyO0KK8gr8SgxeQ4IxeahLcyF/3gR1vjHlAm YgfmXDX09i0ptnP96Iu1HTZP9r2IJ4q3UBlsdAoZt2X88gt3A36pv0EwSwDGS2yDwHFx GB0nAg63WosvANaKq9WXrB6qO5GaEhpPFYOCfGF3EVk5m+QftFQPseGgT4A9KcJcRFtM gjBGhOh95RQ7t/FvShgJQ+H66+B5nbYDr1g1UjbQavnDozE0C/Wg+5bksseG7MYx3ZAB ODAneNiAm3L1/k92FYz4vPtcKwTC8h9+iRZoX5IEicNiV23UWZhjzP69Rm9+/aDqvypL z3NA== X-Gm-Message-State: AC+VfDzYlzBlWgWksjRweWIjcVAhK4znxy9oADTXJhf3VsZE9kjbR0Rs ViORzEtCM4GfZF9kNiQngGsxCA== X-Google-Smtp-Source: ACHHUZ4C+oQ1AVbo4zSzekEvTy6KfJRvqrvWFBxnB8psxVFZyu0vYdrpSSs8wuMpjckZfKwWwYViLQ== X-Received: by 2002:a05:6214:2a46:b0:623:9a41:e9f9 with SMTP id jf6-20020a0562142a4600b006239a41e9f9mr9457344qvb.35.1685570901614; Wed, 31 May 2023 15:08:21 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id f2-20020ac87f02000000b003f6b0f4126fsm6666172qtk.8.2023.05.31.15.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 15:08:21 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Linus Torvalds , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra , Vineeth Pillai Subject: [PATCH v4 5/7] selftests: mm: Add a test for remapping to area immediately after existing mapping Date: Wed, 31 May 2023 22:08:05 +0000 Message-ID: <20230531220807.2048037-6-joel@joelfernandes.org> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog In-Reply-To: <20230531220807.2048037-1-joel@joelfernandes.org> References: <20230531220807.2048037-1-joel@joelfernandes.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This patch adds support for verifying that we correctly handle the situation where something is already mapped before the destination of the remap. Any realignment of destination address and PMD-copy will destroy that existing mapping. In such cases, we need to avoid doing the optimization. To test this, we map an area called the preamble before the remap region. Then we verify after the mremap operation that this region did not get corrupted. Putting some prints in the kernel, I verified that we optimize correctly in different situations: Optimize when there is alignment and no previous mapping (this is tested by previous patch). can_align_down(old_vma->vm_start=2900000, old_addr=2900000, mask=-2097152): 0 can_align_down(new_vma->vm_start=2f00000, new_addr=2f00000, mask=-2097152): 0 === Starting move_page_tables === Doing PUD move for 2800000 -> 2e00000 of extent=200000 <-- Optimization Doing PUD move for 2a00000 -> 3000000 of extent=200000 Doing PUD move for 2c00000 -> 3200000 of extent=200000 Don't optimize when there is alignment but there is previous mapping (this is tested by this patch). Notice that can_align_down() returns 1 for the destination mapping as we detected there is something there. can_align_down(old_vma->vm_start=2900000, old_addr=2900000, mask=-2097152): 0 can_align_down(new_vma->vm_start=5700000, new_addr=5700000, mask=-2097152): 1 === Starting move_page_tables === Doing move_ptes for 2900000 -> 5700000 of extent=100000 <-- Unoptimized Doing PUD move for 2a00000 -> 5800000 of extent=200000 Doing PUD move for 2c00000 -> 5a00000 of extent=200000 Signed-off-by: Joel Fernandes (Google) --- tools/testing/selftests/mm/mremap_test.c | 57 +++++++++++++++++++++--- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c index 6304eb0947a3..d7366074e2a8 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -29,6 +29,7 @@ struct config { unsigned long long dest_alignment; unsigned long long region_size; int overlapping; + int dest_preamble_size; }; struct test { @@ -283,7 +284,7 @@ static void *get_source_mapping(struct config c) static long long remap_region(struct config c, unsigned int threshold_mb, char pattern_seed) { - void *addr, *src_addr, *dest_addr; + void *addr, *src_addr, *dest_addr, *dest_preamble_addr; unsigned long long i; struct timespec t_start = {0, 0}, t_end = {0, 0}; long long start_ns, end_ns, align_mask, ret, offset; @@ -300,7 +301,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb, goto out; } - /* Set byte pattern */ + /* Set byte pattern for source block. */ srand(pattern_seed); for (i = 0; i < threshold; i++) memset((char *) src_addr + i, (char) rand(), 1); @@ -312,6 +313,9 @@ static long long remap_region(struct config c, unsigned int threshold_mb, addr = (void *) (((unsigned long long) src_addr + c.region_size + offset) & align_mask); + /* Remap after the destination block preamble. */ + addr += c.dest_preamble_size; + /* See comment in get_source_mapping() */ if (!((unsigned long long) addr & c.dest_alignment)) addr = (void *) ((unsigned long long) addr | c.dest_alignment); @@ -327,6 +331,24 @@ static long long remap_region(struct config c, unsigned int threshold_mb, addr += c.dest_alignment; } + if (c.dest_preamble_size) { + dest_preamble_addr = mmap((void *) addr - c.dest_preamble_size, c.dest_preamble_size, + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANONYMOUS | MAP_SHARED, + -1, 0); + if (dest_preamble_addr == MAP_FAILED) { + ksft_print_msg("Failed to map dest preamble region: %s\n", + strerror(errno)); + ret = -1; + goto clean_up_src; + } + + /* Set byte pattern for the dest preamble block. */ + srand(pattern_seed); + for (i = 0; i < c.dest_preamble_size; i++) + memset((char *) dest_preamble_addr + i, (char) rand(), 1); + } + clock_gettime(CLOCK_MONOTONIC, &t_start); dest_addr = mremap(src_addr, c.region_size, c.region_size, MREMAP_MAYMOVE|MREMAP_FIXED, (char *) addr); @@ -335,7 +357,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb, if (dest_addr == MAP_FAILED) { ksft_print_msg("mremap failed: %s\n", strerror(errno)); ret = -1; - goto clean_up_src; + goto clean_up_dest_preamble; } /* Verify byte pattern after remapping */ @@ -353,6 +375,23 @@ static long long remap_region(struct config c, unsigned int threshold_mb, } } + /* Verify the dest preamble byte pattern after remapping */ + if (c.dest_preamble_size) { + srand(pattern_seed); + for (i = 0; i < c.dest_preamble_size; i++) { + char c = (char) rand(); + + if (((char *) dest_preamble_addr)[i] != c) { + ksft_print_msg("Preamble data after remap doesn't match at offset %d\n", + i); + ksft_print_msg("Expected: %#x\t Got: %#x\n", c & 0xff, + ((char *) dest_preamble_addr)[i] & 0xff); + ret = -1; + goto clean_up_dest; + } + } + } + start_ns = t_start.tv_sec * NS_PER_SEC + t_start.tv_nsec; end_ns = t_end.tv_sec * NS_PER_SEC + t_end.tv_nsec; ret = end_ns - start_ns; @@ -365,6 +404,9 @@ static long long remap_region(struct config c, unsigned int threshold_mb, */ clean_up_dest: munmap(dest_addr, c.region_size); +clean_up_dest_preamble: + if (c.dest_preamble_size && dest_preamble_addr) + munmap(dest_preamble_addr, c.dest_preamble_size); clean_up_src: munmap(src_addr, c.region_size); out: @@ -440,7 +482,7 @@ static int parse_args(int argc, char **argv, unsigned int *threshold_mb, return 0; } -#define MAX_TEST 14 +#define MAX_TEST 15 #define MAX_PERF_TEST 3 int main(int argc, char **argv) { @@ -449,7 +491,7 @@ int main(int argc, char **argv) unsigned int threshold_mb = VALIDATION_DEFAULT_THRESHOLD; unsigned int pattern_seed; int num_expand_tests = 2; - struct test test_cases[MAX_TEST]; + struct test test_cases[MAX_TEST] = {}; struct test perf_test_cases[MAX_PERF_TEST]; int page_size; time_t t; @@ -510,6 +552,11 @@ int main(int argc, char **argv) test_cases[13] = MAKE_TEST(_1MB, _1MB, _5MB, NON_OVERLAPPING, EXPECT_SUCCESS, "5MB mremap - Source 1MB-aligned, Destination 1MB-aligned"); + /* Src and Dest addr 1MB aligned. 5MB mremap. */ + test_cases[14] = MAKE_TEST(_1MB, _1MB, _5MB, NON_OVERLAPPING, EXPECT_SUCCESS, + "5MB mremap - Source 1MB-aligned, Dest 1MB-aligned with 40MB Preamble"); + test_cases[14].config.dest_preamble_size = 10 * _4MB; + perf_test_cases[0] = MAKE_TEST(page_size, page_size, _1GB, NON_OVERLAPPING, EXPECT_SUCCESS, "1GB mremap - Source PTE-aligned, Destination PTE-aligned"); /* From patchwork Wed May 31 22:08:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 13262767 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F702C7EE2A for ; Wed, 31 May 2023 22:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230445AbjEaWIx (ORCPT ); Wed, 31 May 2023 18:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230431AbjEaWIp (ORCPT ); Wed, 31 May 2023 18:08:45 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B73E19D for ; Wed, 31 May 2023 15:08:23 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-6261a61b38cso2268056d6.1 for ; Wed, 31 May 2023 15:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1685570902; x=1688162902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pDm/ZCxPHx9AYeeJr9uyqvYyWstDuMZWrpU9WcV6+zY=; b=qw8bed+Y5biDzHP7EfFtKZs57yNm2Xtw56wpbBOlZcJdMjQ/zNwrMclm47nOYNozFu tlAKh71SIC64nmj5L4aBGSYN+57DOusiaJrtitM4FMj4SCLpKTOJ+7N14sse+z9nRXxf Dfx6iFxi0M2RgWN7VIDJsMRJrYyRrNwtzkiXM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685570902; x=1688162902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pDm/ZCxPHx9AYeeJr9uyqvYyWstDuMZWrpU9WcV6+zY=; b=FbZgeBLXSPNRklbduVrcUR5K+pKirXAPja5u+mJTbEKJa16mn7Y1ULs3mg3MaYPIxT yM1sDZFsYkWmJKgBz5mXuVzb+/eRz9tGC7155EOTcLBDNfydIUKXTcnA/vGCEX4kBkqy lbh7kqxczk3xKiFrLBX35o9huohYOOdkltGtacEeHsYwLcVQsc73mej5yaC8Gm0woVn9 GHUgUDMw0tXtRG/pBMa9C7nInAhJxk6p1/HcqNHj7nzkjLmSj9gc16dkr+FFofxsUlTc srDBTgT/C0oSk/fyuBDZbXucbx5lsrlHeewXxW+o6W8fVFfQqM3QBWm2V2g2OtG5zcTe hOig== X-Gm-Message-State: AC+VfDweVtYQYeIwk4in+fJHZYWOfYldV6CoGjaG3SGEb2uUQYQFrPPr rrU88XJ6IDy2YO7qClJ17vRdbQ== X-Google-Smtp-Source: ACHHUZ6l7pCJSIoI7lqzFcZ3gOJOyLfjdalrVqKZSDT9zEE7joJ3wMQU5TCIp3pppCRoQCP1coMxiQ== X-Received: by 2002:a05:6214:20a9:b0:626:1052:20f3 with SMTP id 9-20020a05621420a900b00626105220f3mr8694018qvd.18.1685570902568; Wed, 31 May 2023 15:08:22 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id f2-20020ac87f02000000b003f6b0f4126fsm6666172qtk.8.2023.05.31.15.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 15:08:21 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Linus Torvalds , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra , Vineeth Pillai Subject: [PATCH v4 6/7] selftests: mm: Add a test for remapping within a range Date: Wed, 31 May 2023 22:08:06 +0000 Message-ID: <20230531220807.2048037-7-joel@joelfernandes.org> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog In-Reply-To: <20230531220807.2048037-1-joel@joelfernandes.org> References: <20230531220807.2048037-1-joel@joelfernandes.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Move a block of memory within a memory range. Any alignment optimization on the source address may cause corruption. Verify using kselftest that it works. I have also verified with tracing that such optimization does not happen due to this check in can_align_down(): if (!for_stack && vma->vm_start != addr_to_align) return false; Signed-off-by: Joel Fernandes (Google) --- tools/testing/selftests/mm/mremap_test.c | 79 +++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c index d7366074e2a8..f45d1abedc9c 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -23,6 +23,7 @@ #define VALIDATION_NO_THRESHOLD 0 /* Verify the entire region */ #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) +#define SIZE_MB(m) ((size_t)m * (1024 * 1024)) struct config { unsigned long long src_alignment; @@ -226,6 +227,79 @@ static void mremap_expand_merge_offset(FILE *maps_fp, unsigned long page_size) ksft_test_result_fail("%s\n", test_name); } +/* + * Verify that an mremap within a range does not cause corruption + * of unrelated part of range. + * + * Consider the following range which is 2MB aligned and is + * a part of a larger 10MB range which is not shown. Each + * character is 256KB below making the source and destination + * 2MB each. The lower case letters are moved (s to d) and the + * upper case letters are not moved. The below test verifies + * that the upper case S letters are not corrupted by the + * adjacent mremap. + * + * |DDDDddddSSSSssss| + */ +static void mremap_move_within_range(char pattern_seed) +{ + char *test_name = "mremap mremap move within range"; + void *src, *dest; + int i, success = 1; + + size_t size = SIZE_MB(20); + void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (ptr == MAP_FAILED) { + perror("mmap"); + success = 0; + goto out; + } + memset(ptr, 0, size); + + src = ptr + SIZE_MB(6); + src = (void *)((unsigned long)src & ~(SIZE_MB(2) - 1)); + + /* Set byte pattern for source block. */ + srand(pattern_seed); + for (i = 0; i < SIZE_MB(2); i++) { + ((char *)src)[i] = (char) rand(); + } + + dest = src - SIZE_MB(2); + + void *new_ptr = mremap(src + SIZE_MB(1), SIZE_MB(1), SIZE_MB(1), + MREMAP_MAYMOVE | MREMAP_FIXED, dest + SIZE_MB(1)); + if (new_ptr == MAP_FAILED) { + perror("mremap"); + success = 0; + goto out; + } + + /* Verify byte pattern after remapping */ + srand(pattern_seed); + for (i = 0; i < SIZE_MB(1); i++) { + char c = (char) rand(); + + if (((char *)src)[i] != c) { + ksft_print_msg("Data at src at %d got corrupted due to unrelated mremap\n", + i); + ksft_print_msg("Expected: %#x\t Got: %#x\n", c & 0xff, + ((char *) src)[i] & 0xff); + success = 0; + } + } + +out: + if (munmap(ptr, size) == -1) + perror("munmap"); + + if (success) + ksft_test_result_pass("%s\n", test_name); + else + ksft_test_result_fail("%s\n", test_name); +} + /* * Returns the start address of the mapping on success, else returns * NULL on failure. @@ -491,6 +565,7 @@ int main(int argc, char **argv) unsigned int threshold_mb = VALIDATION_DEFAULT_THRESHOLD; unsigned int pattern_seed; int num_expand_tests = 2; + int num_misc_tests = 1; struct test test_cases[MAX_TEST] = {}; struct test perf_test_cases[MAX_PERF_TEST]; int page_size; @@ -572,7 +647,7 @@ int main(int argc, char **argv) (threshold_mb * _1MB >= _1GB); ksft_set_plan(ARRAY_SIZE(test_cases) + (run_perf_tests ? - ARRAY_SIZE(perf_test_cases) : 0) + num_expand_tests); + ARRAY_SIZE(perf_test_cases) : 0) + num_expand_tests + num_misc_tests); for (i = 0; i < ARRAY_SIZE(test_cases); i++) run_mremap_test_case(test_cases[i], &failures, threshold_mb, @@ -590,6 +665,8 @@ int main(int argc, char **argv) fclose(maps_fp); + mremap_move_within_range(pattern_seed); + if (run_perf_tests) { ksft_print_msg("\n%s\n", "mremap HAVE_MOVE_PMD/PUD optimization time comparison for 1GB region:"); From patchwork Wed May 31 22:08:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 13262769 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C2A0C77B73 for ; Wed, 31 May 2023 22:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230505AbjEaWI5 (ORCPT ); Wed, 31 May 2023 18:08:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjEaWIr (ORCPT ); Wed, 31 May 2023 18:08:47 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B32F6124 for ; Wed, 31 May 2023 15:08:24 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-3f83114e0c6so26721cf.0 for ; Wed, 31 May 2023 15:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1685570903; x=1688162903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SGzgxSyjCn8pa3p9gX1cUENGQh2HTVaDIrajDjGHrWE=; b=qJbeR3XeX0dyQ9w7zcHDC41lKw4DZl+B5m5ma1wY70zRgQql4bUjPrC4gMymasqXTK BM3QFGwkJEfYqGrUUz8QS6vJaOIG8X1W6MInIXdLQA50Nx8lnRPaUJqzQu+w7PsHFbIi L4d4GNIFwmhD3BECzPNdaa0JfvVlVcgox0QHY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685570903; x=1688162903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SGzgxSyjCn8pa3p9gX1cUENGQh2HTVaDIrajDjGHrWE=; b=Q2Ss7mPvy/gKNHaraUHe7n9XXG0eb+jRxs4Ow6I5kHzhZ+wamb4smLhlTrcs4h/qPz x4C488fsPpgnJh0Bpcf4I1p1a/GBpeMSqpPMcArT2j7HJgBTOi05tQA3RzCzOfQQIapi AeX7yAIsqC0x7abuwBEsfcCvOwQxBlPMfCUjatnsmKomWlmgNUcjzY0En6o27cHAJY/O G2/dNTzK1F9hcI9nzQIo9Y1Qk44wgGWmTwgDJK60lvkEwhyCDRRCWy2Szkr1xa+efhhb QH38g9noHZLHHyGNGMEwt70k9HruaJ0z22u3UEajCQWRXF5Sb2BMGTvExJhyGJIzTPtS cB9w== X-Gm-Message-State: AC+VfDx+HSKKd9P6nCgfutN11YHMmBYRtbWoxEY7xuBBJFdGCCswVumD oPF9624ME2QADlr7vYDYDiG1FQ== X-Google-Smtp-Source: ACHHUZ6+jFrqsN+RgvwHjevLZQaiKw86Y9ByO7H4nf0Ur0uc0THRQNYH80hkrr7ME5DDE/rEaaF0gw== X-Received: by 2002:ac8:7fc6:0:b0:3ef:25ad:27fb with SMTP id b6-20020ac87fc6000000b003ef25ad27fbmr6757537qtk.30.1685570903640; Wed, 31 May 2023 15:08:23 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id f2-20020ac87f02000000b003f6b0f4126fsm6666172qtk.8.2023.05.31.15.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 15:08:22 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Linus Torvalds , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra , Vineeth Pillai Subject: [PATCH v4 7/7] selftests: mm: Add a test for moving from an offset from start of mapping Date: Wed, 31 May 2023 22:08:07 +0000 Message-ID: <20230531220807.2048037-8-joel@joelfernandes.org> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog In-Reply-To: <20230531220807.2048037-1-joel@joelfernandes.org> References: <20230531220807.2048037-1-joel@joelfernandes.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org It is possible that the aligned address falls on no existing mapping, however that does not mean that we can just align it down to that. This test verifies that the "vma->vm_start != addr_to_align" check in can_align_down() prevents disastrous results if aligning down when source and dest are mutually aligned within a PMD but the source/dest addresses requested are not at the beginning of the respective mapping containing these addresses. Signed-off-by: Joel Fernandes (Google) --- tools/testing/selftests/mm/mremap_test.c | 189 ++++++++++++++++------- 1 file changed, 134 insertions(+), 55 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c index f45d1abedc9c..c71ac8306c89 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -24,6 +24,7 @@ #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) #define SIZE_MB(m) ((size_t)m * (1024 * 1024)) +#define SIZE_KB(k) ((size_t)k * 1024) struct config { unsigned long long src_alignment; @@ -148,6 +149,60 @@ static bool is_range_mapped(FILE *maps_fp, void *start, void *end) return success; } +/* + * Returns the start address of the mapping on success, else returns + * NULL on failure. + */ +static void *get_source_mapping(struct config c) +{ + unsigned long long addr = 0ULL; + void *src_addr = NULL; + unsigned long long mmap_min_addr; + + mmap_min_addr = get_mmap_min_addr(); + /* + * For some tests, we need to not have any mappings below the + * source mapping. Add some headroom to mmap_min_addr for this. + */ + mmap_min_addr += 10 * _4MB; + +retry: + addr += c.src_alignment; + if (addr < mmap_min_addr) + goto retry; + + src_addr = mmap((void *) addr, c.region_size, PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANONYMOUS | MAP_SHARED, + -1, 0); + if (src_addr == MAP_FAILED) { + if (errno == EPERM || errno == EEXIST) + goto retry; + goto error; + } + /* + * Check that the address is aligned to the specified alignment. + * Addresses which have alignments that are multiples of that + * specified are not considered valid. For instance, 1GB address is + * 2MB-aligned, however it will not be considered valid for a + * requested alignment of 2MB. This is done to reduce coincidental + * alignment in the tests. + */ + if (((unsigned long long) src_addr & (c.src_alignment - 1)) || + !((unsigned long long) src_addr & c.src_alignment)) { + munmap(src_addr, c.region_size); + goto retry; + } + + if (!src_addr) + goto error; + + return src_addr; +error: + ksft_print_msg("Failed to map source region: %s\n", + strerror(errno)); + return NULL; +} + /* * This test validates that merge is called when expanding a mapping. * Mapping containing three pages is created, middle page is unmapped @@ -300,60 +355,6 @@ static void mremap_move_within_range(char pattern_seed) ksft_test_result_fail("%s\n", test_name); } -/* - * Returns the start address of the mapping on success, else returns - * NULL on failure. - */ -static void *get_source_mapping(struct config c) -{ - unsigned long long addr = 0ULL; - void *src_addr = NULL; - unsigned long long mmap_min_addr; - - mmap_min_addr = get_mmap_min_addr(); - /* - * For some tests, we need to not have any mappings below the - * source mapping. Add some headroom to mmap_min_addr for this. - */ - mmap_min_addr += 10 * _4MB; - -retry: - addr += c.src_alignment; - if (addr < mmap_min_addr) - goto retry; - - src_addr = mmap((void *) addr, c.region_size, PROT_READ | PROT_WRITE, - MAP_FIXED_NOREPLACE | MAP_ANONYMOUS | MAP_SHARED, - -1, 0); - if (src_addr == MAP_FAILED) { - if (errno == EPERM || errno == EEXIST) - goto retry; - goto error; - } - /* - * Check that the address is aligned to the specified alignment. - * Addresses which have alignments that are multiples of that - * specified are not considered valid. For instance, 1GB address is - * 2MB-aligned, however it will not be considered valid for a - * requested alignment of 2MB. This is done to reduce coincidental - * alignment in the tests. - */ - if (((unsigned long long) src_addr & (c.src_alignment - 1)) || - !((unsigned long long) src_addr & c.src_alignment)) { - munmap(src_addr, c.region_size); - goto retry; - } - - if (!src_addr) - goto error; - - return src_addr; -error: - ksft_print_msg("Failed to map source region: %s\n", - strerror(errno)); - return NULL; -} - /* Returns the time taken for the remap on success else returns -1. */ static long long remap_region(struct config c, unsigned int threshold_mb, char pattern_seed) @@ -487,6 +488,83 @@ static long long remap_region(struct config c, unsigned int threshold_mb, return ret; } +/* + * Verify that an mremap aligning down does not destroy + * the beginning of the mapping just because the aligned + * down address landed on a mapping that maybe does not exist. + */ +static void mremap_move_1mb_from_start(char pattern_seed) +{ + char *test_name = "mremap move 1mb from start at 2MB+256KB aligned src"; + void *src = NULL, *dest = NULL; + int i, success = 1; + + /* Config to reuse get_source_mapping() to do an aligned mmap. */ + struct config c = { + .src_alignment = SIZE_MB(1) + SIZE_KB(256), + .region_size = SIZE_MB(6) + }; + + src = get_source_mapping(c); + if (!src) { + success = 0; + goto out; + } + + c.src_alignment = SIZE_MB(1) + SIZE_KB(256); + dest = get_source_mapping(c); + if (!dest) { + success = 0; + goto out; + } + + /* Set byte pattern for source block. */ + srand(pattern_seed); + for (i = 0; i < SIZE_MB(2); i++) { + ((char *)src)[i] = (char) rand(); + } + + /* + * Unmap the beginning of dest so that the aligned address + * falls on no mapping. + */ + munmap(dest, SIZE_MB(1)); + + void *new_ptr = mremap(src + SIZE_MB(1), SIZE_MB(1), SIZE_MB(1), + MREMAP_MAYMOVE | MREMAP_FIXED, dest + SIZE_MB(1)); + if (new_ptr == MAP_FAILED) { + perror("mremap"); + success = 0; + goto out; + } + + /* Verify byte pattern after remapping */ + srand(pattern_seed); + for (i = 0; i < SIZE_MB(1); i++) { + char c = (char) rand(); + + if (((char *)src)[i] != c) { + ksft_print_msg("Data at src at %d got corrupted due to unrelated mremap\n", + i); + ksft_print_msg("Expected: %#x\t Got: %#x\n", c & 0xff, + ((char *) src)[i] & 0xff); + success = 0; + } + } + +out: + if (src && munmap(src, c.region_size) == -1) + perror("munmap src"); + + if (dest && munmap(dest, c.region_size) == -1) + perror("munmap dest"); + + if (success) + ksft_test_result_pass("%s\n", test_name); + else + ksft_test_result_fail("%s\n", test_name); +} + static void run_mremap_test_case(struct test test_case, int *failures, unsigned int threshold_mb, unsigned int pattern_seed) @@ -565,7 +643,7 @@ int main(int argc, char **argv) unsigned int threshold_mb = VALIDATION_DEFAULT_THRESHOLD; unsigned int pattern_seed; int num_expand_tests = 2; - int num_misc_tests = 1; + int num_misc_tests = 2; struct test test_cases[MAX_TEST] = {}; struct test perf_test_cases[MAX_PERF_TEST]; int page_size; @@ -666,6 +744,7 @@ int main(int argc, char **argv) fclose(maps_fp); mremap_move_within_range(pattern_seed); + mremap_move_1mb_from_start(pattern_seed); if (run_perf_tests) { ksft_print_msg("\n%s\n",