From patchwork Sun Oct 27 02:56:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13852423 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 CD278D0C604 for ; Sun, 27 Oct 2024 02:57:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E1096B008A; Sat, 26 Oct 2024 22:57:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58F8B6B008C; Sat, 26 Oct 2024 22:57:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4577C6B0092; Sat, 26 Oct 2024 22:57:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1826E6B008A for ; Sat, 26 Oct 2024 22:57:05 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CE2A7A19BF for ; Sun, 27 Oct 2024 02:56:25 +0000 (UTC) X-FDA: 82717868898.17.FB19372 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by imf18.hostedemail.com (Postfix) with ESMTP id 4A8D61C000A for ; Sun, 27 Oct 2024 02:56:53 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="PjKKA+/U"; spf=pass (imf18.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=richard.weiyang@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=1729997666; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=g6txh1nnVyYQgpchnAIscrpBhXyntsjoQHVvAAOld4s=; b=QnUzotew0DTkyO3qXgVx9T49kVCh8XugvkrGxgqo8ZQ8KPBG1A7d23dgh+9Dm4SiCOTQBq hVlgo6rdPi501KGWvTMIRE/GpjUEDYilJHCeNKJ1avjFxjYIJf1cvK05092OpWD7YNgcok BubRqeo/EtnXIKWLLo3WPfefG2WgQ0g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729997666; a=rsa-sha256; cv=none; b=de24luOwXnoMxNBMxGzsp6AnDiRVq2bE5P3bTgxwBVhGxrujTzjHV0hBco3IP1H3xKt5oA Gz4m6NqzCeR0L74H1hz0d1QpWG1//GlCfp8Tg9Fqj2XmOfBL6tfdTXew0GXsAGrE6tEnkV 8HFHE3Uiw2QVzeA+UcOdogtWibLiHjI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="PjKKA+/U"; spf=pass (imf18.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a9a2cdc6f0cso435340766b.2 for ; Sat, 26 Oct 2024 19:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729997821; x=1730602621; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g6txh1nnVyYQgpchnAIscrpBhXyntsjoQHVvAAOld4s=; b=PjKKA+/UbibbtTj9g7tIecl2WL52aT5Y0VANF4kzKaxhLuOBdlLOV3Z5ro6SvGvCNM k4PXmnC9YDFdoJH9N4j8/8hlvAdKW7+gsAtd2+kuabkP1WvuuuEjnerwtlSta2I1nqCD NxznDPpCGAHHlCBBar1riDy5NGWXBslRPGlH1euLC4KyGNXAkED4ioLfcWkPZhL4Apei TgWGYqULH3X6NqcZSHSMBKQYF9VERCJsKOcw0DCvB/3J+PQ6C08c6pk+zniHRCQmIiSf o4XUkvIIky/YUSDQZDfRm1v9bnr3vQkTK6nz526Qbto5EPrhlgn4h+A39VXm1ZJFeapM 8y3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729997821; x=1730602621; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g6txh1nnVyYQgpchnAIscrpBhXyntsjoQHVvAAOld4s=; b=Kn5Q9Fhy5Mj0GToSVv6CE/l/7lj1Bigym8oEPeqSqj+K7h6FnogcASrvBRmWEczXc7 pUZxHGpYIKAKo4rc+Z9VeYhVZOPOWJpprs7+rI9CgBw+rS7+2WSNTJ7eylo2eMMHKhxP +pMVBc5z2aVZ/jU1CFmzFEDsKqFEHxH3Z6UdsgzKjtlWmvd32Yr+gbKd6+u+YFMJV+Hf 5iefNp0pRfCBjmO3G8OoeYQoC/hE1f8kXiFfT6ZIONyGn66f9WpuS8g6tEzGukR2u7Lp aCzufWeSEhXKONBKYhdYHdnDYNyGhF0AKKEnpwL/Ykicf2yjp28G4lej4GMx53PrgRpY Xc/w== X-Gm-Message-State: AOJu0YzavBAbnTlfTy/CaOhhybmxd46Dil05u9ct/5SmmQGsoc0miOTK mx8udGkhI1yhuGKlVlFfGSZDlg4/kCDMX67wZVOihuTeoXqTdhmV/Y+b6A== X-Google-Smtp-Source: AGHT+IFixoIciqihO2BvX6GVCVmg7X++omus3dIiv3+3y+rNRdRHYhiNmY/3QieuwSGDfuYvatOQTQ== X-Received: by 2002:a17:907:7d87:b0:a9a:f0e:cd4 with SMTP id a640c23a62f3a-a9de619a63bmr380558266b.55.1729997820916; Sat, 26 Oct 2024 19:57:00 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b30d6fefesm231619766b.165.2024.10.26.19.56.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Oct 2024 19:56:59 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , Lorenzo Stoakes Subject: [PATCH] mm/mlock: set the correct prev on failure Date: Sun, 27 Oct 2024 02:56:29 +0000 Message-Id: <20241027025629.14715-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4A8D61C000A X-Stat-Signature: 9ty4wmtbqt9daz33idonbwau8rcpdozp X-HE-Tag: 1729997813-186659 X-HE-Meta: U2FsdGVkX18tNxQ8je9UR5sfKtX+5dnJaoSqhkdQZ26jAW8U9h0+KmwRCbJ4j1Kem4M8wL2g6W2vrC5NHZ8V1u1FoMYt9z94vcztIrJOa9jXjwNXlF76xR2gsOjcbaKm6yNeN8siMTRqu1njpe8BTS+SUIf0g0MSEYYcM/A8dWtSvCn8CZ51n/HcR7Ue1qtas3mg2jxcFSfHQQ5t6SgGJ3TnorROxqQY3LdC0kRKWzwz5ARB5i3exWEssx7A3W3NBRpP/vX6M4zrBjRWRgvyZGBylRjXmDL6cuxgRgpXkVewiOYyUVUU/h/L+drMri8u1EDlvQVwaqIBin3W8dLI7EHgfUlc5hJ4a8jzey4Ap832l1DcijrNzbCFmI1TCJmZdDflQlFnUyiZ9JNCa3lm9OM3ErfdEYskBE1RCghsMbclFFI+2rh90latWblRhOlwlBkkBmRPVRpXxLFMUJ0MRgQs8gHGVlaemT7+925CyqSToI8C3PFhyKrab4V6JIXYRFuyaukklRfbydBY7xHhz43bEo3vqzPmO1kMvbzzf6ZbJgKJkjxkdBrpGh/TuaM+RXtfTjGAElEvOZGcpV9yiPf5C4plHpFTh62350UaYFgGFRxJylYmSv5u2X5/WIUv47nb/G8FJS2SUyKEoLRhrelNaLvn6eIa4FtYHFbF8zMUbz6f8eA4vq/k8Y3Y6EtIKAFqTt2UkQXREN14OMf/R/KVHXHHFCg9rhrT2AhtMJqTzwQqTf/uVJDl4qu/Ael/VRwdUFQJDn3HFUEpbnDsTxdcJS2fKNaxMUPKoWhXDruv9CxSOBR0V4Ruxz/VmdVjmi52a8mBadPy+T8Wb2r6oHi3xqdrxvT+djFlSd8MN12Uqhk5PkpC8qfUBqv3mhHy99CVEGQpXm4GbF6sWnJ40TlWG6iKyz+pIExhHSxJytG75jYsV0TErgnjxX/InpPmd59dfxeo50fvuOqZvXK IGt7DRsY NCyf68ogcgNKgM4fIcxkyoFaYxl0yQ8RwAD35bZuGTQKu4M1YySKz5FS9PWBR3A+c5jNiJfZlqj50CEuhPDilqhjxft5jsoG6zFq7+Nd5wjoL4UWR5Az7vnPDSm1D/Kf8MGYd2pZwIzPgqKXj7wZRN6naJu9BdnFqhnC0PUSaIAKBOFnBwq/SPVEUK4/lx0Y2LIzShWL9twWdh/nN4E0adiNWQFikzqmUcJQ9hihMXexnUDouAQVeRr+sF4DRBc/sIgmVXJjtlEC56OyCWB5j5p8oGn8s5Ey/M1kBAtZy8YOrT7paNi/NYEPMtQuUZeaIop9Tuq0UjUzG48OoLgoSHc3TGyB3j9gjhfKkv0p+NpeiQLeUBgiACimelD6DoRHeCN4lyV/Mha6OY4mOnaiodHfkWY7f6MbBqfe8HZr1V5yJutMeYaxVR4JeaN0ygiw2wAt2J4Om6OVAKvY4f6aDixVTJt7k2W3B0/Ei7LE2zY2IaC8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000419, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: After commit 94d7d9233951 ("mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al."), if vma_modify_flags() return error, the vma is set to an error code. This will lead to an invalid prev be returned. Signed-off-by: Wei Yang CC: Lorenzo Stoakes --- mm/mlock.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index e3e3dc2b2956..8c3f9cf8f960 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -478,11 +478,12 @@ static int mlock_fixup(struct vma_iterator *vmi, struct vm_area_struct *vma, /* don't set VM_LOCKED or VM_LOCKONFAULT and don't count */ goto out; - vma = vma_modify_flags(vmi, *prev, vma, start, end, newflags); - if (IS_ERR(vma)) { - ret = PTR_ERR(vma); + *prev = vma_modify_flags(vmi, *prev, vma, start, end, newflags); + if (IS_ERR(*prev)) { + ret = PTR_ERR(*prev); goto out; } + vma = *prev; /* * Keep track of amount of locked VM.