From patchwork Tue Jun 20 23:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13286505 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 6DA43EB64DC for ; Tue, 20 Jun 2023 23:57:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D89898D0003; Tue, 20 Jun 2023 19:57:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D11618D0001; Tue, 20 Jun 2023 19:57:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B165C8D0003; Tue, 20 Jun 2023 19:57:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A011C8D0001 for ; Tue, 20 Jun 2023 19:57:34 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 74102C065C for ; Tue, 20 Jun 2023 23:57:34 +0000 (UTC) X-FDA: 80924790828.29.EDFC664 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf15.hostedemail.com (Postfix) with ESMTP id AD5E4A0004 for ; Tue, 20 Jun 2023 23:57:32 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=djOCkf7s; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 36zySZAYKCNgMOL8H5AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36zySZAYKCNgMOL8H5AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687305452; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=a/KyKqe8FdTi+g9/IKt8G5I/SC33PtSDDTh0FPFRaVQ=; b=VhttDQ7UAWVhFjBr/cGRUa9haLSqYb8FPjRWmMhvrbicks9GxQu2ZT1aTTuBzslB3tnrOn apLp2bxdDzDze+QX85GmD8aJRS9iX6gBIoRt+gyzXQkXBD8Y+7DZi/wdl2dsdo3MF7ah2u SnsUehwaojZtrRkD5p/Ot7HZtxnrh4g= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=djOCkf7s; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 36zySZAYKCNgMOL8H5AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36zySZAYKCNgMOL8H5AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687305452; a=rsa-sha256; cv=none; b=QrguU+hZrEnUZ8eXvEvEzP0cMuNIXpa0Cd9QVf2gvosFkqfy9/BH265bQxq0rdfprFXtOL v5RqVSqyZOLnxZ137xwRzjmKFHc8iNViYhhpybNHsLs+ypu5prqSQI8l6fGgDkSd8Ixtn8 WTjjT/3zbBg3keEyJidky/GsYMpnN/Q= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-bc68c4e046aso5161121276.0 for ; Tue, 20 Jun 2023 16:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687305452; x=1689897452; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=a/KyKqe8FdTi+g9/IKt8G5I/SC33PtSDDTh0FPFRaVQ=; b=djOCkf7sRmJEOqkBFJ1FAWr8LXWtr4BdpV1egpT43a8UfDOVBoBIuOCLxFedXjFa5b 1QOybvoapiGbw4NqKAvUWz+Fu19NBYstRwQlaC9K679sBdbRylerMVN2GPJl6f40HGRd jkUzOBouUCpguF36dwOGv4Mqx54tXxWhHGK35MaM5gY/XnL1tOp4MMdkKJjbjpszTSXG +MmeKpVWaqVgIGvTyv3WvYXc4kg3IolRfClLe0BDvx9p80AJntMQZuo8Dm0Z5JpwnDBm eulTjrH/K/rDevjtJ8yQo2HNk4iADzua7QHUx9I7o9do4iwPamwNMonQ11jiZ1XTlxGC ivrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687305452; x=1689897452; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a/KyKqe8FdTi+g9/IKt8G5I/SC33PtSDDTh0FPFRaVQ=; b=PgXyrCbQG9mboFc109LcbMdn/OkTJ+g/iYJuTpVThnojYg2V2KRrYlPxu3023ADLoU +cV2Ar8YJS1uCWytdjc6xvxH8wvu2jfNfMhgtSZXMGjiuu4Bux2FeOgEaJN9qXYYM7II TOgfrZAuyxfhkHn18a4IqlI+TYv1elSOpcDBVuL+jCljKzwdk+Vfx5Zbx13A0y7jPxiI 7X3hERqH14K4kE8bXklXp2cDPXha5/mk8HVqHPPlfZmVXO06hOe/B/Q3SpmgUcexCxoe 5hH1SNGdiGz/n6tkhi+iGqk3AV4EjNTQT+HYA6eot0XMcpwTtmfdro6P/e9v4QddcKsa jspA== X-Gm-Message-State: AC+VfDynZuBkm2CCCm82kd6Yl6k6WTel9QDNxNT+k+zYlVH0xG4TKn+e kWI9ah81CMBdnjyBHctkQZjnlvwdqeY= X-Google-Smtp-Source: ACHHUZ6RGKpgQ9EJdSN1FRj/ySFNHpQNXjGlsvUEbgvZMHU1XkTWuCp5dJ4lnRJ4a/8Ly/xUzjteixKvrs4= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:3f57:9854:e19:8906]) (user=surenb job=sendgmr) by 2002:a25:fc28:0:b0:ba8:5bc9:80fe with SMTP id v40-20020a25fc28000000b00ba85bc980femr5330222ybd.1.1687305451896; Tue, 20 Jun 2023 16:57:31 -0700 (PDT) Date: Tue, 20 Jun 2023 16:57:25 -0700 In-Reply-To: <20230620235726.3873043-1-surenb@google.com> Mime-Version: 1.0 References: <20230620235726.3873043-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230620235726.3873043-2-surenb@google.com> Subject: [PATCH 2/3] mm: change vma_start_read to fail to lock a detached VMA From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, torvalds@linuxfoundation.org, vegard.nossum@oracle.com, mpe@ellerman.id.au, Liam.Howlett@oracle.com, lrh2000@pku.edu.cn, mgorman@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Queue-Id: AD5E4A0004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bk6pmcz3wykyi85q7y6msq7u1o58xqno X-HE-Tag: 1687305452-732115 X-HE-Meta: U2FsdGVkX18B5LyXXMDtJMws3CGg69olRSByk+fq/7pPdIJLx2dBU6TwowRb2v/aicfzRt/8Qj4y+T4CRJoIw1FSgpIF+qKQO/6KmVmvJU90VJotj5uwQrS/uowgcvJ2zdGbRBhH7u0wXd7XojzjPNRnqzBy4w2A+/+MJfmYxCd0ZMLzL+Adde49mtBmSBkEwIiY3XSHOJyUseL8B3JFdgmd4loy2two3JK49g2sa1n3RKyH+B2p0ia4nS2VJ/O3vyBRLaZeGayx/XzFn/l8R1vSZDFBIPPqvvhE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0/bKsg9tNEfDGzNTpObjF1w4elHnMRdS6pQs0NPVw0/atr5X6E/01xO1A8NWFl43F94fNdvtvTeZIJnNx1i11ZMC0CevsZinuicMXPN6SCBDm6FjCcaj/eLRk98R9J/z75rS6xUqHZqCtKk8AlCN99otRwmfNV/yQWl8RFMyXpBVmtCtqGNY9p+BnGfVZM0/39jmkMxSjSphhJP18za+fdEBh2g1yjTMm7jqrNqF9SlSTmbzl+bZDWTRmWldYYMaKz7IsqkcGVh/v1IsdiCaO9O3KqEUM5JJG7bcA12qWUE7yjnCWrIcVDUxAtRANaajDx9fZgg+QQ== 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: vma_start_read can successfully lock a detached VMA relying on its caller to check for vma->detached. Change vma_start_read to include that check and fail if the VMA got detached. Suggested-by: Linus Torvalds Signed-off-by: Suren Baghdasaryan --- include/linux/mm.h | 4 ++-- include/linux/vm_event_item.h | 1 - mm/memory.c | 10 +--------- mm/vmstat.c | 1 - 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 8410da79c570..74e3033c9fc2 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -651,8 +651,8 @@ static inline bool vma_start_read(struct vm_area_struct *vma) if (unlikely(down_read_trylock(&vma->vm_lock->lock) == 0)) return false; - /* Fail if VMA was write-locked after we checked it earlier */ - if (unlikely(vm_lock_seq != READ_ONCE(vma->vm_lock_seq))) { + /* Fail if VMA is detached or was write-locked after we checked it earlier */ + if (unlikely(vma->detached || vm_lock_seq != READ_ONCE(vma->vm_lock_seq))) { up_read(&vma->vm_lock->lock); return false; } diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 8abfa1240040..e741098954ff 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -154,7 +154,6 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, VMA_LOCK_SUCCESS, VMA_LOCK_ABORT, VMA_LOCK_RETRY, - VMA_LOCK_MISS, #endif NR_VM_EVENT_ITEMS }; diff --git a/mm/memory.c b/mm/memory.c index f69fbc251198..bd666fa20748 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5275,7 +5275,7 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, struct vm_area_struct *vma; rcu_read_lock(); -retry: + vma = mas_walk(&mas); if (!vma) goto inval; @@ -5306,14 +5306,6 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, goto inval; } - /* Check if the VMA got isolated after we found it */ - if (vma->detached) { - vma_end_read(vma); - count_vm_vma_lock_event(VMA_LOCK_MISS); - /* The area was replaced with another one */ - goto retry; - } - rcu_read_unlock(); return vma; inval: diff --git a/mm/vmstat.c b/mm/vmstat.c index c28046371b45..5d6acdb1b611 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1403,7 +1403,6 @@ const char * const vmstat_text[] = { "vma_lock_success", "vma_lock_abort", "vma_lock_retry", - "vma_lock_miss", #endif #endif /* CONFIG_VM_EVENT_COUNTERS || CONFIG_MEMCG */ };