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: 13123570 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 C59D6C38142 for ; Wed, 1 Feb 2023 00:01:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5344C6B0074; Tue, 31 Jan 2023 19:01:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E3086B0075; Tue, 31 Jan 2023 19:01:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AB586B0078; Tue, 31 Jan 2023 19:01:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 28E9A6B0074 for ; Tue, 31 Jan 2023 19:01:32 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F0D86160784 for ; Wed, 1 Feb 2023 00:01:31 +0000 (UTC) X-FDA: 80416768782.25.5EB7332 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf13.hostedemail.com (Postfix) with ESMTP id 31AC82001B for ; Wed, 1 Feb 2023 00:01:28 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Rk9+8STv; spf=pass (imf13.hostedemail.com: domain of 32KvZYwYKCLstvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=32KvZYwYKCLstvsfochpphmf.dpnmjovy-nnlwbdl.psh@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=1675209689; 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: references:dkim-signature; bh=bxtFPzszSwirgU1/0J+PiMZRXMSQgSBrsapRb9QUY2A=; b=5UEMGENuDlWHWhnfKbCPvGMywqgJkFJnueSgwmTsG9U1VDjsvSOeJY5HEoCW26eB7qaWMg oxnVdgpmybVrEmMJg4OOrnrd/ESR4fwLrIV4pMpZsd4PYC98jx8qjUFCWtgZbR3MSI21P4 6Yf823F7OTMlqoq3emttXFW9yJeiisk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Rk9+8STv; spf=pass (imf13.hostedemail.com: domain of 32KvZYwYKCLstvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=32KvZYwYKCLstvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675209689; a=rsa-sha256; cv=none; b=6byd9r0b3pkW7ZZm5g9RiBO1VccUZLuoS+sstO6k69ufn/hSdZ8eiT+MgKlfoN2ayChrvw 8BcI+OvcNV/uMbR1Y6wJ5CjY5UpogV1MSnhk2igORGbaBY8DGu8uKHmsZ/Zv+9r9AnuHcY mX+NrKkAKq6m43Imb4fmajIoXOTu5bs= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5028c723d28so183027737b3.15 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=a0qLXNGg6NggE1cDvxzrLl4l0xhjmY5klFaWZzAaOlFEOqDlb/r7PnvwhJD3eIaEDz 4R7svQw1grmRWLxlJsdM40GcNdRqcaWxFRwxWct/5vmmoGRqoQb9P8q/tQGQ2eIfBhjs B91L8qzta9fHNHNmiYT9L/fVGJuR9xWEVozCTNkdvQkOdm19ZCpHRjwFLIiLQjwimyPt t9RlVBCRjJ8F1bZdgps73QUnnCHgxVqPmaZFIJbP57BIAWvHOOXAms+SYFc5LOKSIXvL buV+5v6eDZ9rGzn6Ye7KfxsyjOHsxd/7hjV2OiSwsoc1r8oXJECmbxDrtxS8qArsESCG MCBg== X-Gm-Message-State: AO0yUKXbs4EFNbkeu4r1wwOys5osXu3x24unS74mvKecYYJK7jESbvs0 qgomE9mPm8IsTWUkbLqqqfsv0cjj6WE= 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 31AC82001B X-Rspam-User: X-Stat-Signature: 4ocwdrs6x3ni33454zm1mz4it8xnyezn X-HE-Tag: 1675209688-965006 X-HE-Meta: U2FsdGVkX181GpPffA5KVkp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u0YatJj9KXxTsMAmg+4uw1DAT7QKe32gHL1UMoOk3QdAaibBXYM9fFfshJs2MhJNOvRlSUj5Tyq30DIfr3ddR46JkGYEXhWXajl7A4ns6BKqQEoScOXhgkyrMdJcIVaKB0O4gvlYPINEqjXva/SXyKuivZoORd+ZkFov/4/qAmtnb0HyjdRbmAlOa3DWqVqZkWRqFDPmeyV1cFMjX6SSJVx3hwSyDxr0CSlRO4KrjkBAdJQ0NROstseu4BOz6iS3xNf08MxSFQfYas7Vkt+qahSPbasH26DjU9vGy8XSOopNS4z2LwEhJnvmeqsJs+dAt0yETOrMMFK9uQN/d9ZUKrR8rqltQkwClaU8DpVQU+WSmh8CvoRYqNkjLjAdgx/NTG8AWNM6yfVvClhErpd9knV4VRC6c2b39gOhDgzxF5xIniUlYX5hg6RVh6u8VuZ+w1zfpn3ZnFL41KqMje1nz5T23RTdWPD4S22qMzugdlswiI98ALV5soVL46CTHNzpJu3n2CFsm5yt69YdOLDRBnNSq+zDXQo5vJhRRD5SA+H4Zhb80xcUhAqMtpEaeJ+AqNNccVtoBbKqpTys0tH6ZGG4EDlVzFtVLMbmyXhuUGaeKJXJTQqB2U7puilcohm+BPhX1nMBkElOeGO1NBi83ykcSsKhozpbNhvvTxW1ZmWwN1EZc= 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: 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 Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- 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); } }