From patchwork Sat Jul 8 19:12: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: 13305702 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 7F890EB64DA for ; Sat, 8 Jul 2023 19:12:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1FDC8D0001; Sat, 8 Jul 2023 15:12:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD0B06B0072; Sat, 8 Jul 2023 15:12:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C97868D0001; Sat, 8 Jul 2023 15:12:18 -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 B9D866B0071 for ; Sat, 8 Jul 2023 15:12:18 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 83DB8C01F0 for ; Sat, 8 Jul 2023 19:12:18 +0000 (UTC) X-FDA: 80989390356.27.23B646D Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf04.hostedemail.com (Postfix) with ESMTP id CEDA940019 for ; Sat, 8 Jul 2023 19:12:16 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=e+tppejd; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3D7WpZAYKCEw685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3D7WpZAYKCEw685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688843536; 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=JxWcwQCt64OXVUnpGWZTSfPA4gPHWHeYyOn+4bzO86s=; b=SsN1TOpBl8oqC81vuE2arvyzMZM8c8wHRpoRmP14KUb+R0VhYd/nefDxdeCYuJ6Gazy9B0 SEd8d9389CFl8iLiHRE77lzONtioXEu01VUPBppUQ9U51EI9Rg0tNKfoqum52HMxHr/eGv jrY8ZhKMpWlUOHVlV9IBkX9NHSxIBB4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=e+tppejd; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3D7WpZAYKCEw685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3D7WpZAYKCEw685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688843536; a=rsa-sha256; cv=none; b=NR3W6ieJBZX7w/DYt+NGUepUHlkECpw8KQzxA/4WmxfnrjJZLTT1818nZS0gqjX/32UiIb 5Huj0yCcNtl5eT2HiqBTxaAMcL5o0fEmwusRcxu45Ng5B6Gvb1MOgwhRGzgyv+TVI09LAJ IETawT/rYzanppen8fFH3JPVpkYl2hY= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-c64ef5bde93so3496346276.0 for ; Sat, 08 Jul 2023 12:12:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688843536; x=1691435536; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=JxWcwQCt64OXVUnpGWZTSfPA4gPHWHeYyOn+4bzO86s=; b=e+tppejdoz5kN8B3C5WlD+0nrZGu/5EqfAONbG0hP/lWZ7G+LSD9YpK/YdiONHY+ET COyN68AHpyc5cvZcCJI9Kdj/VXVTOhzXyqaYxVOU/XE8oiqZCtvDT9Ohjc4lwpKs8uIs Q4SGdk/Hg/xVzMRwTNMA5Eb7fUdiGxUNFD+tTkYwspdAJA3H1WkY5sp8/o9lg62jTXI9 vPMevfc26zzweXBMLZnrlY/VDaPVf886Cj6pjLGQXsKtCnCzJ7R7L8Gjg1qP169pUZdf 1fQiHyVHhW2J/bG8DUWZndT612qIhsJaOJnKsT3WA5FG5hybdpqBg5J7YK8LJ6GcI8+m tGNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688843536; x=1691435536; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JxWcwQCt64OXVUnpGWZTSfPA4gPHWHeYyOn+4bzO86s=; b=FzNFQU6q5mTvLeu3NBUPRqTQApqesWPdpW+Kk9rgrJa8mM21uhnWws/IsD+uZzs6++ 4PpvyYN2pMJ3AoypVIWHq8ErIUosxD8KHzbk9B2PG5tbmpIDzOaSqIee7FsxQW5tpFAW F1n7C67eQcngrV4L/vW3Atoj4RXCjz/NHj+A3+I+JSg1r9srzS3BAUchbPzPeJB1WaBp c1HIvcNg7RpIFHxUo/H+1Mohz4IqUCW31kPCl6XJK4Ej5AMYAjnvMANiNTvCs36OH3EQ 0UZhZpsADY0c2cRoKXQNuNCKf7Ekj0X8fu2AciNbX/bfPkX9qbmyndWS/GEh0Rja/O1p 8cBw== X-Gm-Message-State: ABy/qLbRx89tkPqhF8kHhpgJ9W4CD2/OOp0JAWzOMqWaBCPuTZ/F82on Zu6Y/textV5058Oa2vO5Qy+bXk0wG1s= X-Google-Smtp-Source: APBJJlHhdNayqx2O2N+8ynu4MlCffNN+ZnIRARK/gUWveaZn8/1xJL36UJUekD5xd/lYzHt6QBE2wx7GXfo= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6f0:5193:79db:25b3]) (user=surenb job=sendgmr) by 2002:a5b:10e:0:b0:c39:d6f6:481f with SMTP id 14-20020a5b010e000000b00c39d6f6481fmr73329ybx.10.1688843535891; Sat, 08 Jul 2023 12:12:15 -0700 (PDT) Date: Sat, 8 Jul 2023 12:12:10 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.390.g38632f3daf-goog Message-ID: <20230708191212.4147700-1-surenb@google.com> Subject: [PATCH v2 1/3] mm: lock a vma before stack expansion From: Suren Baghdasaryan To: torvalds@linux-foundation.org Cc: akpm@linux-foundation.org, regressions@leemhuis.info, bagasdotme@gmail.com, jacobly.alt@gmail.com, willy@infradead.org, liam.howlett@oracle.com, david@redhat.com, peterx@redhat.com, ldufour@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, regressions@lists.linux.dev, Suren Baghdasaryan , stable@vger.kernel.org X-Rspamd-Queue-Id: CEDA940019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jczh3b7eh6qg5caw1pdmw93m96mb3hx9 X-HE-Tag: 1688843536-393972 X-HE-Meta: U2FsdGVkX18RF5xDt0hSpNsG2gfRAEDo27MTFtvx0Pou8OWESuFgcwPFC28z4ur46TxwDF1Md3RxM051wD6qG434+svPiPin2LGwurMzrCMQNC9qMyrjTHbEdMrKyqjZ9LRG8u7j4Mn4u0ssuJlU/1H08g/YZrri2f7eySQAMS0FLVKgWzavfUZ/HIN4YrbdWcN20ZnbiKZoSeS/3Pd17MXJTldAbfusjcrIazLAPo9N+tsZPZVIs7lxxdvFkbK4N+DtKTu+th7/QMOnE1pUq3lXwvuN99oImnegIdNubLoBrw3RZ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kD+pyxTzKGKr6cs+V2vrphqIFguaxiwv02Kxpl2NCWFA21GJ2KPd9clxs51s0Ikt5xBijLbEd3zQDnAztW9dHNR1MQTe3lNfQI9A9kGaqv3Mu1YMWHV0XXth4Ei1r28zL9rZDq2S6DT0kbmXr+52c0Q+n3utPL16kScahCifk6R6Vy4PQRWiRcUK7rfZf6QSGNmW43ABthfDF35tZhTqOuSgH4wH8/yoWqazpV3XFlp5j3QixioeRgttnsIU3gzMH/Uq/kR9edSCuymBswyeBstmbX7mkwF44Xv7VOFbrJpx0UzkjOCToRnIqcjxXeax9tDcRlY52pmzFO/3TbInj+DYwWREDyHxspBX7jNbkPXYZa9J36dYyhY= 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: 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. Cc: stable@vger.kernel.org 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