Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5318981pxb; Mon, 28 Mar 2022 10:51:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfmW2ADw0kjU/H5Nl9QMEIjGeE6W4DOBszno0klZk7FZjfu7JDfOR1w9t2QZNWq8Ofxoqh X-Received: by 2002:a63:481d:0:b0:380:ea8d:4301 with SMTP id v29-20020a63481d000000b00380ea8d4301mr10862348pga.285.1648489911527; Mon, 28 Mar 2022 10:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648489911; cv=none; d=google.com; s=arc-20160816; b=Y6kQQEDF3S9e4gbMTSvvRxOQdsc1S5Q5GXmJhNZtavGG1iPOFpR63OxQ25hXIFgfnJ CztstptTYYqNkBAdcWPcXRyc+4eDzTRQdDPeBL64Ghs3DVdRGk4Hx2eegsO0BV1DxMlp d+UZCovLjKQFiG2dbHRZmVm9/CeabaICpKfxc4smfTiY30EloxKkLreKdurfML1uKGTb HnfMIaX3YgBMo1u9LQohbnQKu//LyYS0FlInfFJodZhwcJC2hCHhh3E31SNRIAmFqT/s bDYG2nHaKf0LfE3VzrYdn699erJI3s6bMZSpD06ma0elE5DSYRthW5sKgjUXYqQq12gi ZMAQ== 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:to:from; bh=+oEE13bVcH0omX3cno4c9hMdb3mwy2/157580J1c7vM=; b=AKBSwEENEpOLhSxtVG2L8FRYYrMvg0E19Eq81RP1q0NDsqLD+171+jbhg0CwYU/V0O T1rHXb5pltjQ74HAxr7Z/NHtZX7u8550LeOs5/42ow476I6VEnHYgQbC1OKxm/vox2LH YB2N5sUiThXhXGuhh88PLT7BdXi4ekyg/OC74URJyo643Fi5+XyJ5QVLrsJYognD1dQD Ennu+90s+5NuDzKxh9Gj2j4/p/O8zry+Y709jJHxn1/xOUKaCp6Y/wRIjut6mB/PdTXF SclMbTpbTjqjqBpqTwfbs3Lo+RknFjsLM0qMnB+TivQUi69VNXtT4QUgiv8/Tl5uUUzi aMFg== ARC-Authentication-Results: i=1; mx.google.com; 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 u33-20020a631421000000b003816043eebbsi13157884pgl.176.2022.03.28.10.51.34; Mon, 28 Mar 2022 10:51:51 -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; 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 S239310AbiC1I0g convert rfc822-to-8bit (ORCPT + 99 others); Mon, 28 Mar 2022 04:26:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231297AbiC1I0f (ORCPT ); Mon, 28 Mar 2022 04:26:35 -0400 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A75DDEA8 for ; Mon, 28 Mar 2022 01:24:54 -0700 (PDT) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id B58C35F8EA; Mon, 28 Mar 2022 10:24:52 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: mm: use mmap_assert_write_locked() instead of open coding it Date: Mon, 28 Mar 2022 10:24:51 +0200 Message-ID: <5827758.TJ1SttVevJ@mobilepool36.emlix.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,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 In case the lock is actually not held at this point this also avoids a stale lock reference if built with NDEBUG. Signed-off-by: Rolf Eike Beer --- mm/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 3aa839f81e63..d62598dc2fdd 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3561,7 +3561,7 @@ int mm_take_all_locks(struct mm_struct *mm) struct vm_area_struct *vma; struct anon_vma_chain *avc; - BUG_ON(mmap_read_trylock(mm)); + mmap_assert_write_locked(mm); mutex_lock(&mm_all_locks_mutex); @@ -3641,7 +3641,7 @@ void mm_drop_all_locks(struct mm_struct *mm) struct vm_area_struct *vma; struct anon_vma_chain *avc; - BUG_ON(mmap_read_trylock(mm)); + mmap_assert_write_locked(mm); BUG_ON(!mutex_is_locked(&mm_all_locks_mutex)); for (vma = mm->mmap; vma; vma = vma->vm_next) { -- 2.35.1 -- Rolf Eike Beer, emlix GmbH, https://www.emlix.com Fon +49 551 30664-0, Fax +49 551 30664-11 Gothaer Platz 3, 37083 Göttingen, Germany Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160 Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055 emlix - smart embedded open source