From patchwork Wed Feb 1 00:01:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13123571 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 38C32C636CC for ; Wed, 1 Feb 2023 00:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Tn8lJ+OhoBp24E/NpLV6VCIzFZ6BbBAzfAkazdEK6ko=; b=h0v ivLtXuGwjU42ksnBYmbHLrkxvK4b8yXlPUVJGSoS8QLh1QwS4axjiv1lYtcYfPlU/PGJM0MS+bSZ3 Zyd1F5I5c+Muv3bHyYklH2Es2caEWvbqqZgPPPyLFqx2wpDnuMNsZTRy3AKJrIB/G0xPsnxReBD3P 7iduntiCHqT3/GsRCSJ0P6gggByAfNQZ2a5nOszWzYTJYS3QFTsHdahaN/+EsS8zynkrBcdw4d1DA HmVXduFOdIaN6DAWdY8ynQYh5lD9KRmVw5yFTd+XH/9WNJ6ms94uTsq+x4tnSbMHzlgXlBVjIQmCz Qn/Pe0efDU+JL9w6pDq0JzQjaE8b+zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pN0ZB-009jHr-KT; Wed, 01 Feb 2023 00:01:33 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pN0Z9-009jGe-73 for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 00:01:32 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-50660dd3263so183890107b3.19 for ; Tue, 31 Jan 2023 16:01:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=bxtFPzszSwirgU1/0J+PiMZRXMSQgSBrsapRb9QUY2A=; b=Rk9+8STvrqcbQlKiAZtMBFXlHokjI0hFJPEVyGKrBrbMfUwZG8qeTJEuvgsTMPrddh QBvNTohEnVdpbnlrXIgz3Ikz6D2cz4x6un8ohdjcDpAfu7gZ17WU+drJlhJu9Qtc4X1w EN1waKUDwB0WD09JdlRGgqA2ctv2OIzWCDINQo+peotxUMRoWPkFgEen/RotX4SxEykY LuacT9neZvFmURFR16w8DaONfwFwVOcr03mG+PjT2JsZXXZmxD4X3lmTqKTBd5FY/kIG JWR8f0Sx+Z/NFa0Ne873ZtAwDgad97njkhjjwAf7i14upKxsl5EruUIt4SUZYeig/N3q ro2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bxtFPzszSwirgU1/0J+PiMZRXMSQgSBrsapRb9QUY2A=; b=2QgXMh6Noe4ewwG11+hQuEIvBNRS0btWs3L9u/4hNbSedC0LRDwOpSyeWt4Vtaj5HR 8O0ysInT5YoIThBWQ3uJDAi680fJcYcEcsU5fLxDYr0yopHx90i9ENSnWINC3RtinC1M pv8aKfPoydpUMtfbbttNXuW/GzxfSL4wE2us8Eux/axOP5KUURzJS+wy5kD273aDsXvK z/Hd+Eu8LJWHTn27nZsyW1nj70oWSE5a5aFCFOgPAjuNREjIo7Xx+y8FbpsdmvxFFal+ HkGZBs41gMtIOu2AwPBde+mtTaulxdw28W6oYRSuWCFOyVL8DeVZKTl1CLIXGHtFK7an YFEA== X-Gm-Message-State: AO0yUKUz6k8FoHO21Z1DG2RxvWyc6Ax1Meq8BOsGOhLbSt+NvtrG5qFS 8bcRpaeqcK4BIXO6MPsO+O2chZNNueo= X-Google-Smtp-Source: AK7set8qCAXBbF1QMD7keC0/SZMMktYNysM7vnt2K6tJydZhJP2e/r9qdYRWK1+YTYhm0sm9RG76XRb3Zl4= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:3d02:e79b:d9e3:ddd3]) (user=surenb job=sendgmr) by 2002:a81:204:0:b0:4db:df79:a7c7 with SMTP id 4-20020a810204000000b004dbdf79a7c7mr21711ywc.515.1675209688185; Tue, 31 Jan 2023 16:01:28 -0800 (PST) Date: Tue, 31 Jan 2023 16:01:16 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230201000116.1333160-1-surenb@google.com> Subject: [PATCH 1/1] mm: introduce vm_flags_reset_once to replace WRITE_ONCE vm_flags updates 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, 42.hyeyoo@gmail.com, 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230131_160131_270516_BDCD66E4 X-CRM114-Status: GOOD ( 10.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Provide vm_flags_reset_once() and replace the vm_flags updates which used WRITE_ONCE() to prevent compiler optimizations. Fixes: 0cce31a0aa0e ("mm: replace vma->vm_flags direct modifications with modifier calls") Reported-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Signed-off-by: Suren Baghdasaryan Acked-by: Michal Hocko --- Notes: - The patch applies cleanly over mm-unstable - The SHA in Fixes: line is from mm-unstable, so is... unstable include/linux/mm.h | 7 +++++++ mm/mlock.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 5bf0ad48faaa..23ce04f6e91e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -648,6 +648,13 @@ static inline void vm_flags_reset(struct vm_area_struct *vma, vm_flags_init(vma, flags); } +static inline void vm_flags_reset_once(struct vm_area_struct *vma, + vm_flags_t flags) +{ + mmap_assert_write_locked(vma->vm_mm); + WRITE_ONCE(ACCESS_PRIVATE(vma, __vm_flags), flags); +} + static inline void vm_flags_set(struct vm_area_struct *vma, vm_flags_t flags) { diff --git a/mm/mlock.c b/mm/mlock.c index ed49459e343e..617469fce96d 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -380,7 +380,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma, */ if (newflags & VM_LOCKED) newflags |= VM_IO; - vm_flags_reset(vma, newflags); + vm_flags_reset_once(vma, newflags); lru_add_drain(); walk_page_range(vma->vm_mm, start, end, &mlock_walk_ops, NULL); @@ -388,7 +388,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma, if (newflags & VM_IO) { newflags &= ~VM_IO; - vm_flags_reset(vma, newflags); + vm_flags_reset_once(vma, newflags); } }