From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 BFFB3C38142 for ; Wed, 18 Jan 2023 02:09:00 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NxThW1P0Dz3cfK for ; Wed, 18 Jan 2023 13:08:59 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=E/NELfxM; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=google.com (client-ip=2607:f8b0:4864:20::112c; helo=mail-yw1-x112c.google.com; envelope-from=surenb@google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=E/NELfxM; dkim-atps=neutral Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NxTgS64JNz30NN for ; Wed, 18 Jan 2023 13:08:03 +1100 (AEDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-4e4a6af2d99so129898537b3.4 for ; Tue, 17 Jan 2023 18:08:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IPntz93C+TLeiYuya3M1C/wd28MHaFTPeMLFazEhwmE=; b=E/NELfxMjFTBI1CmtbcqjwsiauENdaTqInach8c86SJR2c1/56WBUHAal3gIhTRUSb jv5FEJFY1G+j14AmMioNZe/bJvrtUa4pwIjIu906R7jCEXint9daeTioB7w/OdN0H1eo eJQ22mc9V/eYL4wCsWdZ1vcc44AiUDEtW1uHBGuQyk23DmBqSMDkwC2DgQVpl8YosT9e mRedZ/Kmq4J+N524TLxW75CBx6pTTLnnuzhjvwPqs4zhrByXdnUiCcoHjxOALgS+Toir JxLqPBv9lh1Hz0PKEROEOPoPjIho1oPrj/ub9qhqrValKsHTGtbIGxv2iJwSdawi2I4l OJBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IPntz93C+TLeiYuya3M1C/wd28MHaFTPeMLFazEhwmE=; b=o/MZTnUU3rNAiBozQAdhBi7B07cDO+o4ZUd7mIMB7L4S5QEYoUJ3LlC9POj7qkqZZU BQ5dgXMT/urQpu956FA29q0v7CI5vsFgi83WlcV/eO8P0ujQ9xondip9pjvmCAZ8pmkL C4vEROXOK0/g8XZK5ADVaN8KyrB81nZ3w7QLD00T7IVS+iSfKlBJlV/ouJPwLyd4hJuF NX0kzRr5T2fK8QDL9yj3S2Z5JnPKHJUPHT/wj0rh6qHHWPcXh5mVPvW9/TUgSS0SrZg2 FkJcRTVcqonfWV7ovd4SQRnarQxbgB3fyWowBKk5yTR6/90YT/k+sEHXEalFHAs1sdZG RQhg== X-Gm-Message-State: AFqh2kqng5ypCj8GJaCqbUYC4VqtcQbYD+x/qPa3T/n7LmFq5Jr+rt0/ J5gI0T/Kzdg/eFmNU/iyOPQQE4+fOB4ClQK4ycI2Kw== X-Google-Smtp-Source: AMrXdXt6HN6HjCJ0KoPrl+Bw/cVoPlnqd1wGxDKFOs1p/ddQiqBkhapFdQZ4VL85ZMUAD+PRUyF839a3jZDZ94RZE64= X-Received: by 2002:a81:784c:0:b0:4e1:5013:6da1 with SMTP id t73-20020a81784c000000b004e150136da1mr767604ywc.218.1674007680736; Tue, 17 Jan 2023 18:08:00 -0800 (PST) MIME-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-14-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 17 Jan 2023 18:07:49 -0800 Message-ID: Subject: Re: [PATCH 13/41] mm: introduce vma->vm_flags modifier functions To: Michal Hocko Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: michel@lespinasse.org, joelaf@google.com, songliubraving@fb.com, leewalsh@google.com, david@redhat.com, peterz@infradead.org, bigeasy@linutronix.de, peterx@redhat.com, dhowells@redhat.com, linux-mm@kvack.org, edumazet@google.com, jglisse@google.com, punit.agrawal@bytedance.com, arjunroy@google.com, dave@stgolabs.net, minchan@google.com, x86@kernel.org, hughd@google.com, willy@infradead.org, gurua@google.com, laurent.dufour@fr.ibm.com, linux-arm-kernel@lists.infradead.org, rientjes@google.com, axelrasmussen@google.com, kernel-team@android.com, soheil@google.com, paulmck@kernel.org, jannh@google.com, liam.howlett@oracle.com, shakeelb@google.com, luto@kernel.org, gthelen@google.com, ldufour@linux.ibm.com, vbabka@suse.cz, posk@google.com, lstoakes@gmail.com, peterjung1337@gmail.com, linuxppc-dev@lists.ozlabs.org, kent.overstreet@linux.dev, hughlynch@google.com, linux-kernel@vger.kernel.org, hannes@cmpxchg.org, akpm@linux-foundation.org, tatashin@google.com, mgorman@techsingularity.ne t Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, Jan 17, 2023 at 7:15 AM 'Michal Hocko' via kernel-team wrote: > > On Tue 17-01-23 16:09:03, Michal Hocko wrote: > > On Mon 09-01-23 12:53:08, Suren Baghdasaryan wrote: > > > To keep vma locking correctness when vm_flags are modified, add modifier > > > functions to be used whenever flags are updated. > > > > > > Signed-off-by: Suren Baghdasaryan > > > --- > > > include/linux/mm.h | 38 ++++++++++++++++++++++++++++++++++++++ > > > include/linux/mm_types.h | 8 +++++++- > > > 2 files changed, 45 insertions(+), 1 deletion(-) > > > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > > index ec2c4c227d51..35cf0a6cbcc2 100644 > > > --- a/include/linux/mm.h > > > +++ b/include/linux/mm.h > > > @@ -702,6 +702,44 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) > > > vma_init_lock(vma); > > > } > > > > > > +/* Use when VMA is not part of the VMA tree and needs no locking */ > > > +static inline > > > +void init_vm_flags(struct vm_area_struct *vma, unsigned long flags) > > > +{ > > > + WRITE_ONCE(vma->vm_flags, flags); > > > +} > > > > Why do we need WRITE_ONCE here? Isn't vma invisible during its > > initialization? Ack. Will change to a simple assignment. > > > > > + > > > +/* Use when VMA is part of the VMA tree and needs appropriate locking */ > > > +static inline > > > +void reset_vm_flags(struct vm_area_struct *vma, unsigned long flags) > > > +{ > > > + vma_write_lock(vma); > > > + init_vm_flags(vma, flags); > > > +} > > > + > > > +static inline > > > +void set_vm_flags(struct vm_area_struct *vma, unsigned long flags) > > > +{ > > > + vma_write_lock(vma); > > > + vma->vm_flags |= flags; > > > +} > > > + > > > +static inline > > > +void clear_vm_flags(struct vm_area_struct *vma, unsigned long flags) > > > +{ > > > + vma_write_lock(vma); > > > + vma->vm_flags &= ~flags; > > > +} > > > + > > > +static inline > > > +void mod_vm_flags(struct vm_area_struct *vma, > > > + unsigned long set, unsigned long clear) > > > +{ > > > + vma_write_lock(vma); > > > + vma->vm_flags |= set; > > > + vma->vm_flags &= ~clear; > > > +} > > > + > > > > This is rather unusual pattern. There is no note about locking involved > > in the naming and also why is the locking part of this interface in the > > first place? I can see reason for access functions to actually check for > > lock asserts. > > OK, it took me a while but it is clear to me now. The confusion comes > from the naming vma_write_lock is no a lock in its usual terms. It is > more of a vma_mark_modified with side effects to read locking which is a > real lock. With that it makes more sense to have this done in these > helpers rather than requiring all users to keep this subtletly in mind. If renaming vma-locking primitives the way Matthew suggested in https://lore.kernel.org/all/Y8cZMt01Z1FvVFXh@casper.infradead.org/ makes it easier to read/understand, I'm all for it. Let's discuss the naming in that email thread because that's where these functions are introduced. > > -- > Michal Hocko > SUSE Labs > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >