From patchwork Sun Apr 30 20:19:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13227289 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 81ED3C77B60 for ; Sun, 30 Apr 2023 20:19:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BFEC6B0072; Sun, 30 Apr 2023 16:19:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 749376B0074; Sun, 30 Apr 2023 16:19:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E9806B0075; Sun, 30 Apr 2023 16:19:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4AFBE6B0072 for ; Sun, 30 Apr 2023 16:19:42 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7F0AAAD662 for ; Sun, 30 Apr 2023 20:19:41 +0000 (UTC) X-FDA: 80739172962.10.0C00D05 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf30.hostedemail.com (Postfix) with ESMTP id B3D7980009 for ; Sun, 30 Apr 2023 20:19:39 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=RgSAcUcA; spf=pass (imf30.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682885979; 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:references:dkim-signature; bh=b23kKCtHH6bptYMnbkiFzswByhO4ugXGC7lReBIJxcE=; b=NILT5Z5Gdp33DAsvB0ipGyulLq4O/SFJriZJMbZusF9Xc7Nxw6vVIXpuha0omT6C3B1qsR zkAOmInr/dSukPHIU51jP1cCzcSp4wiE1zjZgNL/ONatATiR67EyGpwIwzvJOwdbjQX+TH pqqLKFQXFShulwshHDxuuYvBK6KXga4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682885979; a=rsa-sha256; cv=none; b=eDDm6mZTur9MfBY/aHVo1/wiyBZrQ9+ev+EgEJPG+oKjtuO7MM2rCHNiSxbgzLVrmf8I1/ EcjeiYycbtNhGGi0yk3Rrv2XSeiOdJiHeifN/wvgmyzXbN2gK+pGRhPYMBoqwuazqAX1Lo D+Gef8SxsV1NfveviirHrnZiZMxr3TE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=RgSAcUcA; spf=pass (imf30.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-3f1950f5628so17354185e9.3 for ; Sun, 30 Apr 2023 13:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682885978; x=1685477978; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b23kKCtHH6bptYMnbkiFzswByhO4ugXGC7lReBIJxcE=; b=RgSAcUcAQnMir0yk7+P9NWQKpZGc724wNfiCtLYUJMRweuO2G+rKaOundt+kRebwgE 2sA6flt2erNsCueOprvBW5SVElIoXeSqxHKlTYRo8Cw0fuD0ciyAHEh4AqzOJ79knliE tI+mXlKr22bkfbqqxwogYvuX9gJzfcwlkj31+Hx0lnvhaZQ45bKVZ8ygnOqmAN2t/m0F AFck/JQXi3Wnk9y6Qs5sEAcTgxRgzt4BNEXcCuW8IMPnZTSe9D4D29ih0EszWGpOvkqT 0C6kd4cypf2y4ntF4CURxvHijaSw2BKIRmpcHs6CbSoOcbZ0sgOtmzAuvGyCNFQOUABm 6p/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682885978; x=1685477978; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b23kKCtHH6bptYMnbkiFzswByhO4ugXGC7lReBIJxcE=; b=WaO7jXDEah6wdkO/qklOIDeDTrjwxRy0NYLd/d4VgNF5pxiOb+++CT5VKg+Q8+e2MY aQIYqKAE5yHs1lYgCwmZ2hkDVu1p0xqdA/Xj+V0R8/GACnNJzL7wHIoKGzhzyhw418os ojqWtJsCzpvLulhWWCZIGt9N0dXIyWbKqiKGcgBn3DvAGR/OA4MwR39OQzGmsO7p52pA hoGY4tp959aqEAH0l+1FlYkZ0ZsjmNBzmykg5TOt1g3ZmQE9TLQOq0daWjdQrIdtcbml UV81oQJkOc4kVq9qgSZmTr/Dkbh//wC1CVZoOIqZgMAC+Wya6sAZPfQQmqiH0YLTonpB SyDA== X-Gm-Message-State: AC+VfDz1tNu760t970hV3LhFUV8yRummhAxHdy6JOShRfZXHChIN/IXR aP2rk641/Q8aCaqAn+UlzQt11jLjfdOQVw== X-Google-Smtp-Source: ACHHUZ6jJ+pDxPFfbgjuEUDVYH+RAM1MTqF8dig4HP3VWbf9qEzmQ6g1LWOyO8x9g4vaC13vY+25Mw== X-Received: by 2002:a7b:c84b:0:b0:3f1:75a9:5c0d with SMTP id c11-20020a7bc84b000000b003f175a95c0dmr9248332wml.26.1682885977604; Sun, 30 Apr 2023 13:19:37 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id j32-20020a05600c1c2000b003f173987ec2sm34328903wms.22.2023.04.30.13.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Apr 2023 13:19:36 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Lorenzo Stoakes Subject: [PATCH] mm/mmap/vma_merge: always check invariants Date: Sun, 30 Apr 2023 21:19:17 +0100 Message-Id: X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: B3D7980009 X-Rspamd-Server: rspam09 X-Stat-Signature: bai7wn7yrm4x8h4c3jo4obcduh7t54bd X-HE-Tag: 1682885979-613138 X-HE-Meta: U2FsdGVkX18wxnJwCBzXu1WvQgAKEy0Ft1sE3CCkVuR1xEmZOww7B/AQlrIcQNLmvSfbv8qE3MgK82ju8ldjP6cKVGEimZM5iK1SIwkjdilIctMFT0Fw0XcFze3lhx1uZaoNtv3vDhvpvEFYMBo8cQtAM2NngyGyGYTod+nOxfCFnoz2PFYtmOvZaPnCStxbWElopNyPYeC1Wey6qmOHMz9xdPi6YPHiD1OH9617QKkkS6cuM2KUeXKxMJSyEMYftMU3fqFDAH5RhCjv1VS7hygEbNEsZjQ8Lvte66X/QKm1/HTkHXhbE4zNQcqh5EsXo8LayrlmEW0fCSqCNpGjDNod1dyqaP1JK4hamfHa/F8wzfnhY2uy4cx3fqnHOz2jPisYi8cCIF9yIuPLos1DWLW3m/5dh4VpaqT+WCrqAZLlSZr2fjFXgC2so9huWB0StwGw4tIM4ABGX7jpKAeKU0ATGNSlKnavJsgGRyoNwKhVZbwG9k7j2NiG815FR/LZQJLXVvtdOnjD9Cpv6HRM37dd1xUlXX6nTqvRNKgMzHuSiGHScMENQiVwIUQpe0QBisidyxl1jVJSnfTV9cCR/XXulPwrIlJozdeo4A2bWfZXkxLwErTlB2Y925fc7czWkmavAMsWDmC7FZu/O4yUoL1+sJFpGmmuZHz8Nninuo82n46NEXE4ZCchePWhsMbNQIkJJ0FHDKfUVUKfmAJ/Yxqj93h3FfZ1KM82QcHV6YVJo0P/sbQD53/zZEEVW0QYBAWncYGG6XQiSysZyCYYtjVpEUAcl9fqPUgpXyJH+MFPwVDGe0mIcp0SFa5/j6xosDV/UyU4l//Wl/tRrZtypfkTDZ8D5kt+pJ1FJZfN8jLJzEG1uAkGvHTiv/NQaiii2Sdl75BtaIxCpgtUTPBc6AEAmWqYIG1+XT7fMjMDG2mP39jB6V+EbF9iRaqOYwQGPCNaamM/kgL+o1ErC3T b/H6mebP +0fPV8ApTzmmxpKLnx42H9D/s0QnRQ8odh22mmOl9f7vtgnZ5F+R3AucEahVlu84OOMe7I+J+rMXNIrnn9fObj+UZq2AXnXLWnu73zZ2MYEE9MU99EjaKW+ui38hbBca4nYA4NYMY7E4wFR3I/Ixzf7cLCMxZDfSJgMPjJSt56YWNeoKiqdBDuC6V6EwAJyzKmm1M1db2Q0cuqNp05eJI4XLV9Hdz2fa1ukypbAB5/wAKU01V2zT9CkBUpdvjwnon+ZBfcXyQ5ee/FbXk/QpSWdPYJPq+rRdOhNpum01Jj9MOeS+RJLmCBgaNqU3Qo6bEiYLwVCOgBu1BvDqaINwoixJqlLvrZ5NqpRQ0TDp0sPPZccYZccqShSkR0ROnu00H84JI8+IyrQtxOUe1pBM6F7EZr2eDtAsJy4zrhU76aH3wyhNuXLG/2w4m7Ne5+eQfJY+jrQVnDS7nJznIM/b9wWg81g== 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: We may still have inconsistent input parameters even if we choose not to merge and the vma_merge() invariant checks are useful for checking this with no production runtime cost (these are only relevant when CONFIG_DEBUG_VM is specified). Therefore, perform these checks regardless of whether we merge. This is relevant, as a recent issue (addressed in commit "mm/mempolicy: Correctly update prev when policy is equal on mbind") in the mbind logic was only picked up in the 6.2.y stable branch where these assertions are performed prior to determining mergeability. Had this remained the same in mainline this issue may have been picked up faster, so moving forward let's always check them. Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka Reviewed-by: David Hildenbrand Reviewed-by: Liam R. Howlett --- mm/mmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 5522130ae606..13678edaa22c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -960,17 +960,17 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, merge_next = true; } + /* Verify some invariant that must be enforced by the caller. */ + VM_WARN_ON(prev && addr <= prev->vm_start); + VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end)); + VM_WARN_ON(addr >= end); + if (!merge_prev && !merge_next) return NULL; /* Not mergeable. */ res = vma = prev; remove = remove2 = adjust = NULL; - /* Verify some invariant that must be enforced by the caller. */ - VM_WARN_ON(prev && addr <= prev->vm_start); - VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end)); - VM_WARN_ON(addr >= end); - /* Can we merge both the predecessor and the successor? */ if (merge_prev && merge_next && is_mergeable_anon_vma(prev->anon_vma, next->anon_vma, NULL)) {