From patchwork Thu Jun 29 19:14:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 114411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9877298vqr; Thu, 29 Jun 2023 12:58:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5unDqMnlU46z+j6aUB62O/lCK5vleXg6vdK8WW7PbbAw+B3O6SEcyEAdLRC8PuvYdcs72R X-Received: by 2002:a05:6808:128f:b0:39c:59e2:dd79 with SMTP id a15-20020a056808128f00b0039c59e2dd79mr539248oiw.36.1688068730320; Thu, 29 Jun 2023 12:58:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688068730; cv=none; d=google.com; s=arc-20160816; b=kZoxwWFDpemCAOYmxXLsFZVmACFA8/lECWBpO9FgpFz9XtqlGlQmFDRDKsyWq344e8 iTQTMqfyPh/sw0DM3cG26OTed9uIpMoOBLTny6mn9z0DaaSVfmEE1PqJaPKrGkH17WVM VU9JgxHaacOxg7dM88O109gpZJ4S/DosAr/ONvdvggawKMe0PIaUR6EmIQtIOEjYn39y mDVX0nj/cnHq7Ws1VIyzNK4iVXvqo+w3YrY15kR7Ow43cM2exOJlIfQLTBHxxJSGSqb9 eVkPr5JladxxAtKoWo85qIenwYJ31izGKqtVfxIHYp26uk6fy5sI0zvxOkxK5KOCE/Pf Ro5g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=g+NcRVz6DlwyP650U53R0sBow95cLltWneKiM8xVWy4=; fh=oj8imIAYOWu9c3WNhWLFIY3i3/lNM5V4UNeSc75Rv0c=; b=y1pAKLUVr6aNizrXEL9XCr/2AHhn0wbXu0bre9UZESSXz0Z09BQP6PpHF3YObnXxF5 qu+4JORpCWSQB3e50K7Ck9uutwFH7rE4Tf2DAAZcewylDo7PAWO7oGRh9L5LGz5sgr+0 03FYtdlSUt2TlsIZXFW4o28Q13q9QZI/oSdkKXQkNMZPOLRf7iQpg2opee75VeCUBeIr MBStPmA4LEVx9LswhY3bQZfOAoTcVSBDAPMNazDU+9Ezoppx9nYw3rCSBM2N21khLS3n LSepXphCND7kTOjmd87CX3rhIcX7ZA7rPzG2pTA3FMCfIMsj3S9T6zymzgiBGF3jL69P naSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KZMHkzW6; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r28-20020a63fc5c000000b00557622c1ca0si10777782pgk.554.2023.06.29.12.58.36; Thu, 29 Jun 2023 12:58:50 -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=@infradead.org header.s=casper.20170209 header.b=KZMHkzW6; 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 S231557AbjF2TTH (ORCPT + 99 others); Thu, 29 Jun 2023 15:19:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230447AbjF2TS1 (ORCPT ); Thu, 29 Jun 2023 15:18:27 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E15B23C24 for ; Thu, 29 Jun 2023 12:14:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=g+NcRVz6DlwyP650U53R0sBow95cLltWneKiM8xVWy4=; b=KZMHkzW6OX3pVpvLi1BlRRDsQ9 14tq/tMjc+Hrm6ASrjWDb8Vx66bhGDFFieE1p3YtcoHv4V0OLqwRJ/hEo0fxBLfXXQI3Wl+Ffn1sm HZ/JjL1mAW5NricHoqNFaS5yfx/Vff56JUhVb7FffLODFkfIe65zA+z4agN2OB8Jcj/AajTwaEYkL xm8he5HSR2Gd3ro4cM3DmkKmIG4bsgStIYe4/xpmb4G5bwchkoSmaOm8osKvWiLYy4Zf3QdHSiulj cxTnvfBFgbb1aVu8D0v0ehfNBNhlpKbDs/MEEBm9NIbcK0cdaUpBTyGD61G/372McjE2grGJfBBRs WBG8gd/Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qEx5t-0056Kz-E4; Thu, 29 Jun 2023 19:14:17 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Linus Torvalds , "Liam R . Howlett" Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH] mm: Always downgrade mmap_lock if requested Date: Thu, 29 Jun 2023 20:14:14 +0100 Message-Id: <20230629191414.1215929-1-willy@infradead.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770068356919492197?= X-GMAIL-MSGID: =?utf-8?q?1770068356919492197?= Now that stack growth must always hold the mmap_lock for write, we can always downgrade the mmap_lock to read and safely unmap pages from the page table, even if we're next to a stack. Signed-off-by: Matthew Wilcox (Oracle) --- mm/mmap.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 9b5188b65800..82efaca58ca2 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2550,19 +2550,8 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, mm->locked_vm -= locked_vm; mm->map_count -= count; - /* - * Do not downgrade mmap_lock if we are next to VM_GROWSDOWN or - * VM_GROWSUP VMA. Such VMAs can change their size under - * down_read(mmap_lock) and collide with the VMA we are about to unmap. - */ - if (downgrade) { - if (next && (next->vm_flags & VM_GROWSDOWN)) - downgrade = false; - else if (prev && (prev->vm_flags & VM_GROWSUP)) - downgrade = false; - else - mmap_write_downgrade(mm); - } + if (downgrade) + mmap_write_downgrade(mm); /* * We can free page tables without write-locking mmap_lock because VMAs