From patchwork Fri Jul 7 04:32:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13304384 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 1E4D1EB64D9 for ; Fri, 7 Jul 2023 04:32:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B13A8D0002; Fri, 7 Jul 2023 00:32:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63A318D0001; Fri, 7 Jul 2023 00:32:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DA5C8D0002; Fri, 7 Jul 2023 00:32:18 -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 360E48D0001 for ; Fri, 7 Jul 2023 00:32:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EEBF0160585 for ; Fri, 7 Jul 2023 04:32:17 +0000 (UTC) X-FDA: 80983543914.06.330AF1B Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf18.hostedemail.com (Postfix) with ESMTP id 1B82E1C0008 for ; Fri, 7 Jul 2023 04:32:15 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="Gwtq/b9i"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3TpWnZAYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3TpWnZAYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688704336; 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: references:dkim-signature; bh=sZ6z8dQsy+feCMa6mHLv7bXXJoh0AFryfACo+v22y/I=; b=jFF9GaZPVrsfNlKo3qp/UbVLBfGV8ThbBgxw2eQC6wmOTCfr80HiotXIwAMYQOvp0aumBu UppH8+ynovkqlOi4LDpwmJZyIXUtw3GeIAGMw2auUccTmmiYIlVfB+TlUcKzTvdNp8Q+28 7Qeh2oYv04cw4V+c+zLJn2HE5VLlF5w= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="Gwtq/b9i"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3TpWnZAYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3TpWnZAYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688704336; a=rsa-sha256; cv=none; b=EFkXHwTSXqVTgQ83h4Uc0QdOgds/CUE/O2bhWaS2G+i9EVQNj/ISckUGs4q/4b0ifGOH3k eShniQ1gnqYwOsYw6XKPZxUEByZxwh8yaV23LB4FV/XYpT14A+PV6wXHVa/vOfy/sfj4NE VpPUJMWGc6l9hWw2PABBS4+yu6pMkcw= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5707177ff8aso16299867b3.2 for ; Thu, 06 Jul 2023 21:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688704335; x=1691296335; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=sZ6z8dQsy+feCMa6mHLv7bXXJoh0AFryfACo+v22y/I=; b=Gwtq/b9i6ROYeVk/l2zLnMZzShNECphjVgRqvWJv5OGn+qPgDf0aYOccyWRYQYFvoe a7kkq7Xd+cJ5Yl1sqH5mEwr1FQQ5mDvqjjOvtUPlT/znd2rFs7Pck6McGti6M/rVA24s llLvscQ9xrZVeoRLucl11LU6f6n6b0Xa29TjReH/+Gm/F3SrGIpra5wV33NUcvECjY3b edvx0fZJHvb/lQFLmDlwXRw3XoweSUsN7MydjcGTLSgxwpx2SVLkOc4pe3ecCewVkym6 3owTws6qa98ajMMWF0iXsyo8KL9j5OzHAPnkMl9JjHL2TyBxof/pLt96lGmatkHdhHzc zIJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688704335; x=1691296335; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sZ6z8dQsy+feCMa6mHLv7bXXJoh0AFryfACo+v22y/I=; b=JTwEt+p3XU1+xkPjLFcC3EiWJIFfx7P4gSZx186NpC1vK8W+b+RLhufjskmpx//fDw gC7rDYtCUy2uV4v+nHMJtUyYTzZ+tlz3IT4WV9chYTBFmkig0lNQ1zSAxy9c+6YTNUwV J+pwehJnytGsWT5Zy7hXR0d05ZKUl8o/0euW5xKhzLOZjnQwsadAOSfX9/+PKgP96yy1 bpLM0hxfqn5D45tGwkYIeHxGdOIuV6jOY+OZ/ZjhSekyhvWqCP+7pONbaDyX+Oqutb6o 0zw94PHEGGKibjKH+Jhbfqy9NqNjDlV2wKzDwUxeznq3nAhGYIGFG/99ZPhwCZPp/3eW xJLw== X-Gm-Message-State: ABy/qLZYdfu3IHCWATXLmKENUlZCKjr0/zbqabgnmtX1LED80QkpO65u IvDgcvXw3sWE9ryKrcv15rY2DLrfp9c= X-Google-Smtp-Source: APBJJlFkYEJCxhTy7hdsK2AY5aTIGyzLomxQxPwMN23ZBPHY8N4SuK35j+IjBDaJ4zJACbfSU1q2dNs4+C8= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:fd8f:e174:8bb4:814]) (user=surenb job=sendgmr) by 2002:a05:6902:508:b0:c4b:6ed6:6147 with SMTP id x8-20020a056902050800b00c4b6ed66147mr43761ybs.9.1688704334865; Thu, 06 Jul 2023 21:32:14 -0700 (PDT) Date: Thu, 6 Jul 2023 21:32:10 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.390.g38632f3daf-goog Message-ID: <20230707043211.3682710-1-surenb@google.com> Subject: [PATCH 1/2] mm: lock a vma before stack expansion From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, liam.howlett@oracle.com, david@redhat.com, peterx@redhat.com, vbabka@suse.cz, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, hannes@cmpxchg.org, dave@stgolabs.net, ldufour@linux.ibm.com, hughd@google.com, punit.agrawal@bytedance.com, lstoakes@gmail.com, rientjes@google.com, axelrasmussen@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, gthelen@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspam-User: X-Stat-Signature: xe57eq5nj64uxw8n68iawwpptekfopnw X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1B82E1C0008 X-HE-Tag: 1688704335-734843 X-HE-Meta: U2FsdGVkX1+KHf/tufpJ3hyKBEMuUAtsu/2gEuSKSQ4l9ZvWm4B2An4/i0lA4bxrUaIuleP8fP4XmRxZ8yGQv7kGVOaCW5HV2y867LnAnRTrae59v7zPgl+U6mQSJlVS5sXHbIwA9ZtWNW3Gy0RvzBETRCz/m2PHq3qoyaLEhNg/5KdKHdi/fGgMQsRQaCLF6FH+Nd9fYyRyNRIjLRknmknq2vDz7wrNo4ZCuN0qqi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0umMEEzGPZq8Qaz0krkKCR2mlXAFxAXxiyP8NJG421qtIUaU3AzTJUBBArUm+kWpFkJtmcWr3REGmN4pmwjBZi3nfLfE58Iz0rJ4b9LVLFrG3jQNdU85MnfCHjp07IgvqSAgTyed70mj77xukBZ1EWtbKwuC5GlUURFYhwsZlCtk9qQJQWNpMxz5s+acBL9/uBZybCdnUX5VdaYMDPGyEiqNh4AHmg/hIT/wWKN2134l13F8fmzs+5VDxx/9ln2EWyNWab6tEuT9JkpZi7ztwudY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000453, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: With recent changes necessitating mmap_lock to be held for write while expanding a stack, per-VMA locks should follow the same rules and be write-locked to prevent page faults into the VMA being expanded. Add the necessary locking. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 204ddcd52625..c66e4622a557 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1977,6 +1977,8 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address) return -ENOMEM; } + /* Lock the VMA before expanding to prevent concurrent page faults */ + vma_start_write(vma); /* * vma->vm_start/vm_end cannot change under us because the caller * is required to hold the mmap_lock in read mode. We need the @@ -2064,6 +2066,8 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address) return -ENOMEM; } + /* Lock the VMA before expanding to prevent concurrent page faults */ + vma_start_write(vma); /* * vma->vm_start/vm_end cannot change under us because the caller * is required to hold the mmap_lock in read mode. We need the