Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32366902rwd; Fri, 7 Jul 2023 12:42:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlHR1ZeVIB8xyEItmSq3b4G/VgrVmgVqYLMN0A0fpFwyveWTS+55XkHbTA9TQ20Mjy7tD9PN X-Received: by 2002:a17:903:22cf:b0:1b8:870c:4ce8 with SMTP id y15-20020a17090322cf00b001b8870c4ce8mr10549842plg.18.1688758947359; Fri, 07 Jul 2023 12:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688758947; cv=none; d=google.com; s=arc-20160816; b=ju0gE0DRmrPzdLyx61tjtdrXCXSbRlI1MdNry0h8sZdHopD1V9BNSLyb0eF2Xg9K7F R8yPR6GdNGLBOOsSbn1PnhZCoxxqfcjckEdVNJTLyBv5pQDHqN7dl9jbFKQpUyFFxEjF 7Lm59RDHInB1ahYXIuQ0C2QqPZjwvXU/sQeD41PBJbvmSKiNxtmrfyN8ts0qb6pg9fzK aTPpZ1wtOiPZpxpYBG8ZOzCWCTniSsCPBm4Hm8CE/Uk2a8IjJXpdXT1sJl+Dlgzi2xn+ CAmy/WEE4TTIZBNSA4ED6oy/BVSdeeoCk+1LATC64DVi7eYH9RQNwqh+rQTug1v3Xee6 e/gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=XyPPUi+MRQXmfk9eJbb0Q/RJjC1R1VDWxOmvCavvj7w=; fh=in8q4HCBysMEY0oj9EPy8AT53097KpEr43R3vtpFCzY=; b=SM1MlznAzIWEQ3EddUVm3wvdaKPZ4/UaZYoeTA55c73zgO6xUse8cfETBfzPrf0nG7 V5aBWiaqvhgPDrpd+xVB7k0JyTrI+uYgz/7Z8+btLiGNo8s1OL4WUdTwAfpLeb9iOLXu cNU5Lh7I1ITpd9AFCJ2hXhvjvzZ+KqxoEmBbWYJzjJiD8xHyJWUwi09waizMkfovisgc AM8idWcAUYQUF6l6WPhMcFjmo9mrlP5goBLpLCZq+zaOc6R4NQYByLgbUhXuoQrGcADB OGnoB/KzP5jcF3gwOARWbf1J1tqWcPIswhmmw0vIxjosV7+X8aPU2zJVnXGWfBLeg3bD 39hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=wCvnlZrB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx2-20020a170903138200b001b85a47d2b7si3940035plb.422.2023.07.07.12.42.15; Fri, 07 Jul 2023 12:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=wCvnlZrB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233046AbjGGT3z (ORCPT + 99 others); Fri, 7 Jul 2023 15:29:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbjGGT1x (ORCPT ); Fri, 7 Jul 2023 15:27:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E85E02108; Fri, 7 Jul 2023 12:27:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7879461A53; Fri, 7 Jul 2023 19:27:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE4E3C433C7; Fri, 7 Jul 2023 19:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1688758071; bh=b/nwBttY6PR9kozBothsfSykputrrbxrsvZzb9AG8AU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=wCvnlZrBJGLSDJgRrLUP8aaVEj7mKzHi5Xl7RY9sPfO9gEXCFboDs+BkPgdm2xi0U qL//eHQGQ5spOtGzccOdBx8sBHY0HKSffBwQhpYq8PjujN2Vd0UGqPG6Lc8/DJ+Zij +4ML/Rvc8EsrL1/Or79/KAuP6drfMI7GStW6KqrU= Date: Fri, 7 Jul 2023 12:27:50 -0700 From: Andrew Morton To: Suren Baghdasaryan 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 Subject: Re: [PATCH 1/2] mm: lock a vma before stack expansion Message-Id: <20230707122750.f7cd77fe19b625cff37423ed@linux-foundation.org> In-Reply-To: <20230707043211.3682710-1-surenb@google.com> References: <20230707043211.3682710-1-surenb@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 6 Jul 2023 21:32:10 -0700 Suren Baghdasaryan wrote: > 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. What are the possible runtime effects of this change? > --- 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 > -- > 2.41.0.255.g8b1d071c50-goog