From patchwork Fri Jan 27 19:40:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13119300 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 E92C8C38142 for ; Fri, 27 Jan 2023 19:50:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 829C86B0072; Fri, 27 Jan 2023 14:50:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D9FE6B0095; Fri, 27 Jan 2023 14:50:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67BA66B00A3; Fri, 27 Jan 2023 14:50:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 57CCB6B0072 for ; Fri, 27 Jan 2023 14:50:02 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2F7DB80754 for ; Fri, 27 Jan 2023 19:50:02 +0000 (UTC) X-FDA: 80401619844.20.64C5553 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf14.hostedemail.com (Postfix) with ESMTP id 68BF2100027 for ; Fri, 27 Jan 2023 19:49:52 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nhjpt9Vb; spf=pass (imf14.hostedemail.com: domain of 3-SjUYwYKCMAy0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3-SjUYwYKCMAy0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674848992; 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=icGEQDhVNg8AQkGt0Dau1cb43VWZWeb/kUxMjHSAwGA=; b=qOjhPsVfxzKtIPm/YUBVoeLvOXSU04bEWofQSdt47CcT/ZSM97+rHBSqNJOZM215iDkmCs 6KCJa6qvbtL69ICXYUmTW6vzlA1xbTw12r5BkvnOEvSCb7+9LIJ6xdF/D8EtczLI/2Ffjn IIJxv04LiGMMgzG5g15nmOfhm/MlLdM= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nhjpt9Vb; spf=pass (imf14.hostedemail.com: domain of 3-SjUYwYKCMAy0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3-SjUYwYKCMAy0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674848992; a=rsa-sha256; cv=none; b=SW3iBIy8feHYDH3nhXN9cNlxrNzx54dehbVgdw/Mom/b/u4msTfqU/Ly7tnYjh46f8TFEK sEIjaqi9KvMumTF6iIyF1dk61D2wQ6/cWnI4cCvwmC+nDzVlMJOh0OlX79fva0ap1SIuQY F0HQdpEmg9UIIWSlTrscMGYWOFr6jJk= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-482d3bf0266so65539887b3.3 for ; Fri, 27 Jan 2023 11:49:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=icGEQDhVNg8AQkGt0Dau1cb43VWZWeb/kUxMjHSAwGA=; b=nhjpt9VbHDPsHYg33OlJfuq5Iz35VmBZ3kiMxPcXRXZZYdOboFlR0spKtxfGWFFcLn eBkIzKgB8QHaANcEzDHfkdLN1fRlxg2tqUBsMTv/7fNevBLbu/43ueowkRgVsLx1vLRo uHdRFKLtGeWmcojM55WkW4Vbk+IWqqj37nvYWjKvQOLDRhcdlXynMiveqJDQteuGpWZz ETc6Sup2efRPDAlMWE74qe3dlQIJeV8JWIsag7a7AlDm28r/breAdd9LIL/XkRDxD2X3 yud8bBPMeadGbrZ7ftbCoegvJj4wUFszXo3BfVZSLdIr/XgKY9tYqvkkj2bzILo8Fvtn ItZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=icGEQDhVNg8AQkGt0Dau1cb43VWZWeb/kUxMjHSAwGA=; b=bt+913KojV/87BniCo5+RJbyIGZXh8gUrWB5vCzzhF3ZrQB2MxCH9kSfE6O7Ij1a9p Ouep7jpzGTPYPsIN/2yW1+33ejS/2w0wrGYrokEHD9eXn464aCFKvHqdg+19zzT+YfwU aDuVtg6a5GotWLjQ54mdskPqQtEWTrrMUKgf1zVCT2aMUfxG1c4qSAJtH3ZPex8eD/Ua wiWjO7cwfU65T6PyXe9GLJp78avnt+fQ+fiN3mbBz+uRxrqz18qLvn6SYJWRu3QMgFkH 9WJPwpU6EMmKhgd7GysF3+z2jpy+VYyp6AEF/Huf8p9weAFY8nnVu6/iDsYhAjRm9Xhm xfqA== X-Gm-Message-State: AO0yUKVALNKxs9nJrB63oR+6SL7N7+y3mQNRbQKNSDix/Liz1XxcbQAx BAC9rqDG2AAGdZbaqWbK6h9GepxsDH0= X-Google-Smtp-Source: AK7set+R/81FxpFmvdAm43AdDVGV+lMO8EmoQcyFeqmQ4bL2GAdYwzTWfE7122Mwrx91JEcHzv5APn9iCmY= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:4e19:be9:c5d0:8483]) (user=surenb job=sendgmr) by 2002:a81:48cb:0:b0:506:4c8b:231e with SMTP id v194-20020a8148cb000000b005064c8b231emr1848392ywa.80.1674848505193; Fri, 27 Jan 2023 11:41:45 -0800 (PST) Date: Fri, 27 Jan 2023 11:40:50 -0800 In-Reply-To: <20230127194110.533103-1-surenb@google.com> Mime-Version: 1.0 References: <20230127194110.533103-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230127194110.533103-14-surenb@google.com> Subject: [PATCH v2 13/33] mm/mmap: move VMA locking before vma_adjust_trans_huge call From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 68BF2100027 X-Stat-Signature: q7rqfh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ZA7HwgZ55jtKPrJGkIZ9hW2cPxTD7LawyjNnsdUqQ8IcuPohShZecco0MPPD6KoNLB66Zdc+E1uSBBkr2oKmDtLl47t34zgw0CKcQAVEDtIgqQMh3uWsPZrHLJB9WN4KSnNz0Mm8RTGIm9ks66K0AXwItvmIwuBqL3G93xCxtRdq73qxR2Y8m8eAWkG7dCwT8RxBPVfNYGIWi8km55qzpxt+TCtsNHoB0B9Of2ZHfdGSnt26eHm+nH9phTuP14fR/kTn+bm1MzchQSjZkYS5AocUPxtWSqNWWGNztc9UrjjtZscUDzt2Gdpta4+FHV4j78acZKW4kW7lnlloowY8bzvICIvUxKq9g29lZXOtsbD8+39KeFpM84pwwO9frkvE40BoK1UEhikLgvYQUudbxXFa4IzaFP+wJKtip8sT1UP6Xwe0DB5aNLzNA0vt4GfCm6zJ2G7rWixX8cC70DsLyRJvoil9iZQ3rcUs9Q5Z1nKniFwzxgsj8HzsbomOibXnaGfQqjeBgxXgE3Ur5ePSJ0UEGXe+Gt08HiVn0RD9JuPyVXM/HOw5rqhAbhcrVQNO/QPh9qY+NPA5W/T1SN0QME4UQAm5xjhjjTym1sNv8ZGrW6merti7dwz3WTGshpHdZIssBeh/5+lIhN0gnSF4ZLIZtRHINg07OHg35TbdJiD4R8kw/EU3GI7Oa8cjnaEq1WCEdEF/Kw3JCL+2U7+uxtPPYA== 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: vma_adjust_trans_huge() modifies the VMA and such modifications should be done after VMA is marked as being written. Therefore move VMA flag modifications before vma_adjust_trans_huge() so that VMA is marked before all these modifications. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index 9efe13d36df7..7467d691e357 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2910,11 +2910,12 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, if (vma_iter_prealloc(vmi)) goto unacct_fail; + /* Set flags first to implicitly lock the VMA before updates */ + vm_flags_set(vma, VM_SOFTDIRTY); vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0); init_vma_prep(&vp, vma); vma_prepare(&vp); vma->vm_end = addr + len; - vm_flags_set(vma, VM_SOFTDIRTY); vma_iter_store(vmi, vma); vma_complete(&vp, vmi, mm);