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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDD74C54E94 for ; Wed, 25 Jan 2023 22:02:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 698E86B0071; Wed, 25 Jan 2023 17:02:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 649266B0073; Wed, 25 Jan 2023 17:02:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 511E26B0074; Wed, 25 Jan 2023 17:02:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4208F6B0071 for ; Wed, 25 Jan 2023 17:02:56 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0DCEDA0665 for ; Wed, 25 Jan 2023 22:02:56 +0000 (UTC) X-FDA: 80394697152.12.DA043B6 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id 3E41F14001A for ; Wed, 25 Jan 2023 22:02:52 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="t/IOpihd"; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674684173; 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=5k+aKOTBAzFA63mlQuhZsbPEWLj3sVMT5IsyRndOvJ4=; b=CuHYsEP0KahGYaNwMYKpkioYH4zfwQvFs90AJXAtFwwr5cFeONGNRqoYTPOocYhUeilsgf L9NSJVqm1m2wwZqyKYj5TFJ56QUy9birluPC6DlGwjoU7uSO+/WmpbZwQWuxO3AgDuGc4g oYRvkBDhQ0bXXLMXbZJ6jyG77lLbfPs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="t/IOpihd"; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674684173; a=rsa-sha256; cv=none; b=dF8bOaTPq56T8x0+OYNf5OxWU/N3thbcGa9kjH9JRzn/8Ajw9CsBU02y7/DrRnNBFiSDgH dx7mTAiwtL9e7jBNgN/oiVy4yco7PSASVP/3p+OE6nkaAlmwpb5Ks3+Rcm5M/I35rIqftw IzM0AEqqHJ4DczkcQMUfu0Rdnw1MfqI= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5k+aKOTBAzFA63mlQuhZsbPEWLj3sVMT5IsyRndOvJ4=; b=t/IOpihdlpo7K6OBvWliDrbqr4 BYWFzeg41vBFlfpT21qRWibW/3nGbyi+rWOI6yHdL5aRjtipCgM+I0ejXHcnRtXm9W/WGHY6YHcQS QAwAEl5HzTv2b3R+YoFMU6CpBD/aKv9k8VNP7uFiVJpUONW0pc2EFbHXSKxJNVAE5WVQyoWt/a9TY 0pAvpEX6ykQgrINQV33c4NduWdqHENYUTGa4/UaGVM6uhhY4wZm6IFL19SkMIt5wZaSdDCFBnEdcZ e+eK6BdK+oR1kPE+pJHzmsVRZFI0LqI4kc9d1FNvgWvgR83eEWuTxTCDZgJnw1LJMxXUzrNgrP3Jl sVK2lL9A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKnqz-006ECJ-Ho; Wed, 25 Jan 2023 22:02:49 +0000 Date: Wed, 25 Jan 2023 22:02:49 +0000 From: Matthew Wilcox To: Suren Baghdasaryan Cc: linux-mm@kvack.org Subject: Re: [PATCH v2 1/6] mm: introduce vma->vm_flags modifier functions Message-ID: References: <20230125083851.27759-1-surenb@google.com> <20230125083851.27759-2-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3E41F14001A X-Rspam-User: X-Stat-Signature: 8ubu44gqsde5zin68z7zmgp5x46go4xo X-HE-Tag: 1674684172-929305 X-HE-Meta: U2FsdGVkX18jsrUjJqeaKxrWSPcrgsEt4uJxT2q7i3xdroqzcdNWfV+Rgr8GlWMzj7DTXJk1AfUJigGIfCWzDW8mLJbiJi6W5Ifz4ZgfEKHizbFUG3Ze1rfUzh31wKd8vcA0dgqdY6crjwuWxRWm2lj3FeifAKoRiSHcO7Y19iry9Fn05/wCGB1A1euhkY+Njr0HUKpmrVCvIxKvUCEkNn/dnv+RP9d3Swq8NHjbf3xImdWL2+jz4RsdFQ2x3TEnKgmJyb7arr9mtCGChC0JvmjWpZOAKwgdhcxzOKrh8yg57vHAhqLjqRVlCB/YC3AQPdBJ3UDRsOAlTaVaL4o/iFI/+1K9lrm5GywMhn9f/0TvHJtUZhq8FXSj2KfeVhDWsho6ANZUFyvmC7gOxpf5qWxDxXGoUesZ+ekMXtWgdeZZYIH+ErUL+bQrjp2s5N62JdwBIRmKe2s2SUU38CnBirWQrE+I5lnbvAHltLUA1wAKnAYjmHJK1aklsLM76iWsui3pgjo+6CGxmXxbbHZrrDeJYaS4drK4mDsoq5L3ZsJ3FLq7PxGcQ5Jq2An8NZ15hN24CRIvN4eP88r0nw5E7+AnH3TTfnswFi3jLoSTsqqgvfrXKH2gdi1ns2xATb6u5BjvzAWO+BZ9C9OlZRX6OveHGIkvXfTq3K4ckqpqCdn9Bi0zrXnl1odGhnXdigfgXBHnma2rKpNrMFto3re+ev7cp4KxMi278DVoyvElEVQ8ruBwG40xArTeschfkmHgxaBHLHquHBRT48apm7J4nSzp7AzAEEnnFGbUMGFPiQc9+REkTMjO/9An8oxfE/QfYPE+F1lNMqWql5gNLfHo3cTAfX4HjBVRnijng+coZvs5EuOWXx6SJouGWDhwszUTK5WdSW3zEelbf90oOQg92hCVSDopQ+fWZpZG3+b1sBY7tVtNi0DzKQngTc2iq/UCu/twUmPkxDk/pnWAN4U tMNEx6S7 iWU2mH4f/9xRuo9fCCYBstKJpBdGMq+XbHsju2d10qvyeyh/UBAel8Y53gbHUjOI3kEqoLl5Z5duBtynwRdt86Lm20QPzY9QSS3UOX0NGUFA4z0GX7d71e7VWlyYWmGB5KvTQxgIGyG8VpNhSFgMa61eH8jk0uzsmFxgThh5AXsHYu8yavr6dqP1d1hF6Dqe6MhC4r+JHba+n2UjJmzh/04DkuG4a61Zkaq98ZkYGaH4rePuTsyF1jAzgmF9gNKk2TZkesLPCKvybiwKK7FTlhAbDKA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jan 25, 2023 at 01:08:13PM -0800, Suren Baghdasaryan wrote: > On Wed, Jan 25, 2023 at 1:07 PM Suren Baghdasaryan wrote: > > > > On Wed, Jan 25, 2023 at 1:04 PM Suren Baghdasaryan wrote: > > > > > > On Wed, Jan 25, 2023 at 12:35 PM Matthew Wilcox wrote: > > > > > > > > [I'm just going to trim the incredibly long list of recipients. Too > > > > many bounces, and I doubt any of them really care] > > > > > > > > On Wed, Jan 25, 2023 at 11:21:56AM -0800, Suren Baghdasaryan wrote: > > > > > On Wed, Jan 25, 2023 at 10:37 AM Matthew Wilcox wrote: > > > > > > Here's a trick I saw somewhere in the VFS: > > > > > > > > > > > > union { > > > > > > const vm_flags_t vm_flags; > > > > > > vm_flags_t __private __vm_flags; > > > > > > }; > > > > > > > > > > > > Now it can be read by anybody but written only by those using > > > > > > ACCESS_PRIVATE. > > > > > > > > > > Huh, this is quite nice! I think it does not save us from the cases > > > > > when vma->vm_flags is passed by a reference and modified indirectly, > > > > > like in ksm_madvise()? Though maybe such usecases are so rare (I found > > > > > only 2 cases) that we can ignore this? > > > > > > > > Taking the address of vma->vm_flags will give you a const-qualified > > > > pointer, which gcc will then warn about passing to a non-const-qualified > > > > function argument, so I think we're good? > > > > > > Yes, actually I just realized that too when trying to use > > > &ACCESS_PRIVATE() to get the address of vm->vm_flags in dump_vma(). > > > So, I think your trick gives us an easy way to have a read-only > > > vm_flags. Thanks! > > > > Another nasty problem I hit is that READ_ONCE() requires an l-value, > > so READ_ONCE(vma->vm_flags) would not be directly convertible into > > READ_ONCE(get_vm_flags(vma->vm_flags)). I'm not sure if > > s/READ_ONCE(get_vm_flags(vma->vm_flags))/READ_ONCE(get_vm_flags(vma)) > > > ACCESS_PRIVATE() implicitly constitutes READ_ONCE(). With your > > approach that would not be needed but I'm still curious how this issue > > could be solved. I think you'd have to bury the READ_ONCE() inside get_vm_flags() or have a get_vm_flags_once() variant.