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 From patchwork Fri Jul 7 04:32:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13304385 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 F0A8AC0015E for ; Fri, 7 Jul 2023 04:32:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A7D88D0003; Fri, 7 Jul 2023 00:32:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32F318D0001; Fri, 7 Jul 2023 00:32:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 180038D0003; Fri, 7 Jul 2023 00:32:20 -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 06CF58D0001 for ; Fri, 7 Jul 2023 00:32:20 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C69D8A02B6 for ; Fri, 7 Jul 2023 04:32:19 +0000 (UTC) X-FDA: 80983543998.28.5A7AA03 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf15.hostedemail.com (Postfix) with ESMTP id E4A52A0007 for ; Fri, 7 Jul 2023 04:32:17 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=eODw2VAG; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3UZWnZAYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3UZWnZAYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688704337; 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=sOqq0WN+jYVzOAHPCJmC3T8ZmV+ri02/8UcPUSwENZU=; b=cIY83qP1u2WC0URkCKmoWXndWOvEd5UIFQKVAXZZYX0jVjWxfRTvrALhzyNjLiX/4a+Fw0 8DDZNBXgfo9+vU5vzkmzmPpuMTrkhlV7BkyMMThUM0O7pItS5iwqQySspk92hIIf7Kkm0x Uk9mPXTagL+jiUYdIzQB21gTSm0XzU4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=eODw2VAG; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3UZWnZAYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3UZWnZAYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688704337; a=rsa-sha256; cv=none; b=bKr+6jcZyVH1xguJDrvFOInAIj3lhVIdfpuQ4T0XdAgSVxAHVM6/f5EYvQGoJcYAfgjW8g XvuBBFj9UAfKTr4bxNfZNfgBSkK7V8YHGqsb0FNq1nADM0jYl2Gr5/3HjSbw/TT+D233eY kRaBPyXG37zXnWpzscOV9V8X6iif7ig= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-56ff7b4feefso17595187b3.0 for ; Thu, 06 Jul 2023 21:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688704337; x=1691296337; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sOqq0WN+jYVzOAHPCJmC3T8ZmV+ri02/8UcPUSwENZU=; b=eODw2VAG4LYwUudSofmYsJnD5sDvgnvXm7FQ6WhI9uyNSxsp0njiK6thMN6LRU5jTF gYmW5dl0SjECbLtK8iZkOH2xEUNg27Y4ApUuh7waJQakQ9qHP1nx+nYn3YKoVQ98VxWz OY4YiR+GiMKjF2MsRbpXNOQvq0vJJsB3vwvYf8qNkr7WvRvnC7O9FwEtRfKLje9Z1BZP 9cOyuGcTKL1Y+u5/k71eAVQKBKvf+ar9q4SEqw+qNvkFIduc73n4qBi271JwmDnSiSe9 HnhcI0RwPWBtG3pS/6ZbVosWthJ25wdjphq0ZVDNfyhX/7kCWTDbFnICRKBZ285B6A6q 2nhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688704337; x=1691296337; 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=sOqq0WN+jYVzOAHPCJmC3T8ZmV+ri02/8UcPUSwENZU=; b=bjGqW9BIQyEG6iP62yK1eSg6jFADbVN1s0fMAFxgVTaXq5X57XTULRmc569PYyWfoX wU0N8woqkeGOkbrMnucM3jEdBaZE1MEVEGnFHVl+JuTc9+/stiugC6xUMygAnv/VS7kE RF1Doq7M4BT1aVcUZl5k2audJfh6Ky7jauh7hkEZSuPdVNts1qwtzpO6GDGnsju87i+a C/eVDVCxjG9JCSZ/rw7JwtDfRh1NCQQdWNU7NPRICu62XWX8NC4f/dfigudaMwjMz2sZ 2NerAkmbm1mFh1rbelWvhigrTrssVoQyU2gEhBMrFwww/2fFYHyjreVlxepKkOcS9V34 l02w== X-Gm-Message-State: ABy/qLYsSHqTn1562s9QHfyWyKEiprsJ51VHxQR6/aQhzfK+GXRfaaLs ftCST18twF7Z8XP/fTYBAVufd6uvWgw= X-Google-Smtp-Source: APBJJlHJJzo6xKqRfCwu3K4BMa/DSUqUwTqtDXrv/pQ5MfhlCzg1HW7hTPTkOQo0rodXtQODdOcQ37BKfgc= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:fd8f:e174:8bb4:814]) (user=surenb job=sendgmr) by 2002:a81:af1b:0:b0:573:6b9c:6fa1 with SMTP id n27-20020a81af1b000000b005736b9c6fa1mr27409ywh.1.1688704337053; Thu, 06 Jul 2023 21:32:17 -0700 (PDT) Date: Thu, 6 Jul 2023 21:32:11 -0700 In-Reply-To: <20230707043211.3682710-1-surenb@google.com> Mime-Version: 1.0 References: <20230707043211.3682710-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.390.g38632f3daf-goog Message-ID: <20230707043211.3682710-2-surenb@google.com> Subject: [PATCH 2/2] mm: lock newly mapped VMA which can be modified after it becomes visible 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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E4A52A0007 X-Stat-Signature: o7bkqft4d6hunnpay3dgs8tq7za57j5p X-HE-Tag: 1688704337-297630 X-HE-Meta: U2FsdGVkX1/9RZM1YUU8NbidxM4rPXmhd40j7eICnxD6c3Rwj6WaI346lq/+Kq0QohTfgQsmQE679dvBjXGPpyzgeLVKx0gGL8m34Fj67bySv+Bps6mwPHXqIU5EhtxlkQsPRXLGc2ZCj3O6Pm0KCVGzFJonfJbhDRuUac1IyZ2CK7GKlN6/UlbEkg+GqT6lDoDp+6JYQi6dMcX0WRsfmTRhbgwQWMx2FgIFFxYGi+dK5KKZ3OgngrJB0oO+7t+XFkKgYcMKN4q0a82N9MrY/ztkY/3yE8xyg3VXgGx/RTVNXWOTpAxJVakAXDPCaNxAVBUBklaiC7PxfEaaBNO624BGU6EVxNV7OunvJuAt5Zfx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+5fwtHuPsJeOVS4TxKbW3RjhZ+/tOXAmVeLCQKJzkKafGwyoAa0e9YWNtfo1Uvz2Y5QjCzJv2Swf0R65Kip2mJ7iDbI08AeA8Jya8wXfmwdOV99L4hJx+dh8WUe13fxQ/0hD7RKTqL+CuGl2VbzV/GOiA9pg7JRV0w0U1tLnImG5DyBUTouY= 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: mmap_region adds a newly created VMA into VMA tree and might modify it afterwards before dropping the mmap_lock. This poses a problem for page faults handled under per-VMA locks because they don't take the mmap_lock and can stumble on this VMA while it's still being modified. Currently this does not pose a problem since post-addition modifications are done only for file-backed VMAs, which are not handled under per-VMA lock. However, once support for handling file-backed page faults with per-VMA locks is added, this will become a race. Fix this by write-locking the VMA before inserting it into the VMA tree. Other places where a new VMA is added into VMA tree do not modify it after the insertion, so do not need the same locking. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index c66e4622a557..84c71431a527 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2812,6 +2812,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (vma->vm_file) i_mmap_lock_write(vma->vm_file->f_mapping); + /* Lock the VMA since it is modified after insertion into VMA tree */ + vma_start_write(vma); vma_iter_store(&vmi, vma); mm->map_count++; if (vma->vm_file) {