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 0EBDEC54E94 for ; Thu, 26 Jan 2023 11:52:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FD216B0071; Thu, 26 Jan 2023 06:52:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AD2F8E0001; Thu, 26 Jan 2023 06:52:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 474D46B0073; Thu, 26 Jan 2023 06:52:34 -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 379606B0071 for ; Thu, 26 Jan 2023 06:52:34 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E9DDCA0A8A for ; Thu, 26 Jan 2023 11:52:33 +0000 (UTC) X-FDA: 80396787786.24.FF4EE94 Received: from outbound-smtp37.blacknight.com (outbound-smtp37.blacknight.com [46.22.139.220]) by imf24.hostedemail.com (Postfix) with ESMTP id 23DD3180014 for ; Thu, 26 Jan 2023 11:52:30 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.220 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674733951; 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; bh=C8/5f8s4MR/LTyms1yjMfWxzAxB797vDW1oPpgDKbbc=; b=g8Zd36C/Hb+i9JSk5yvTKuLaGyHsE7XqYi5NLE8ge01jwEJ9Lb6ab+TuO0TUCNHOfHH8lT CA0cc23J+4chcdbD1N2g5awfAzXaxxd+YdUfMy+hgs+OMwnBOHSMmpjlErpfJSwDJD3gAw Jn9e09ruYtMB4HqqHqZPGYAXtCVzyFo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.220 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674733951; a=rsa-sha256; cv=none; b=AWppHNXTPVlc0TUZGiX1E/wCaCpKcqiAMz0T4wrroCMxxNii/3EITJrTHHSKs0aJ8UUQit GCfjVO5N0Gdhfwahh1gl9YMj/N8hUAtxs9zkY9sTsyAL+9tG1llEBA/9EdKLhAmMulbH41 GWDN6kAF/ahkxLMDw2FMhTahghpAwfM= Received: from mail.blacknight.com (pemlinmail05.blacknight.ie [81.17.254.26]) by outbound-smtp37.blacknight.com (Postfix) with ESMTPS id 63FFF1F18 for ; Thu, 26 Jan 2023 11:52:29 +0000 (GMT) Received: (qmail 32236 invoked from network); 26 Jan 2023 11:52:28 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 26 Jan 2023 11:52:28 -0000 Date: Thu, 26 Jan 2023 11:52:24 +0000 From: Mel Gorman To: Andrew Morton Cc: Suren Baghdasaryan , michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, 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, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@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 Subject: Re: [PATCH v3 1/7] kernel/fork: convert vma assignment to a memcpy Message-ID: <20230126115224.3urhskf35eomk7xl@techsingularity.net> References: <20230125233554.153109-1-surenb@google.com> <20230125233554.153109-2-surenb@google.com> <20230125162159.a66e5ef05fecb405e85ffec9@linux-foundation.org> <20230125173449.5472cffc989dfab4b83c491d@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20230125173449.5472cffc989dfab4b83c491d@linux-foundation.org> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 23DD3180014 X-Rspam-User: X-Stat-Signature: rc9jeguoykc31tt8ohxp8mtut381br1f X-HE-Tag: 1674733950-958080 X-HE-Meta: U2FsdGVkX1/QpeAxmZuCwCuuRII7Jr/rdOs2xpSmfjeRF/vsRUYonA4QwrgMnUZhHWePgc5bS/TCDPPDW+VIiVLG2L2x2rLLFdnOmxasLwuLxDfU/Kfm5TDauaO3HUBxGDmAnGXl++kVq4T2QfE/gTN6xMN77zyQ4crVjC0lFFzV2RO3O5RdmwgBlpPruP7wfEXLfbJP0gBehkgwaLykWArFYGFS3lhrI6VkjOXva37yD5b3y5eqaMt1iQdhokxVwRdJNTvz/2DVyeYfB8Fg7UZ0U6+2ziTeM56E00pvvn6QzxgQvi0DsAizxP4RLKvh38y/srsCwXYPyf+XE/qEWTk0GPQs2PpULe9gqNjKbuLmbXs0yEURNNgnY1HpCYF25QXZu4rswzUSIoYEQWiyV9ZvkWz4BrUj0BMuesR1YoJx434k15p1bKga0O9gSA1zQOZtKuNtPO+fDSgOnEmo8NVa26LWCtX816EHNvfVFGHgiiroCzD94qQRL4WdzB86v4R8//8Z8cJKcynNFOVFkH0iitrffmlzzQMzH4d8Jr8FuaKZ32E6k0MJr8dtdMQm6AKb7pZ6alFxyu8QGXitVpM351BaD9yExoxe4QBqUSQf+o2JzzbFyN7OopPIp5KXbY/e5ucSolVMOuL8EXN+jb9ed2rZro9Jgl2EQ8/Moy+PBmx9m1FseZVpNb42BJz9ngzjadfmkNY6jQMyZkHNiYdiktHV4H0UFg7cK20Bs6X8X+37vP/YglNg2LtW+MQAPknDGzQUSgAhmWQJCvqLCLBCghJ5w000xr0CdGwybqbMat4itnR9+t/8DPLudILaguwVVgOdK5zMXspHg1dZL+E8wo1ahUgVaQSzlj0fMtMLVEMD660Lo5xEyzuWXxAXuq5SFgr4fk0dTCxrZxEglFIn+khcUHqMZfBgcgaqYRzbMukCWEoLZBjSC7C/sNVCU30Dg+iWtgNpDi8Tjmy SJOROMVZ MC5XDWnItUAZv39LS6c76jf55UfSTfRORkEPQhkEgfeCXu1J9MaCzBGauBDJQhxuXtz067VPcIIr3LB9BXAvWHfPdlx0ETrWLGb7hT7zCsrXAnlm86+Y8GmD55zrOAWAgybwtNUG0yuWhU1tSx/11k3Q/W/Rg++5riUfUWD4FnI7qRThIUFcJwzQW9NNfQ9jyJRJeq92W/dnPxuPS8r/1rIcuXboRRjOcXHNVgZrGjbM8W+AQW7IMfcnKXIWtvfrQks1HDMuSg49me9tqUoiU9iFL/uxlFs3jDOwfy2iTAh2SztlGPICNabj+u88xmuCIiObaU547kx7Ci9w= 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: On Wed, Jan 25, 2023 at 05:34:49PM -0800, Andrew Morton wrote: > On Wed, 25 Jan 2023 16:50:01 -0800 Suren Baghdasaryan wrote: > > > On Wed, Jan 25, 2023 at 4:22 PM Andrew Morton wrote: > > > > > > On Wed, 25 Jan 2023 15:35:48 -0800 Suren Baghdasaryan wrote: > > > > > > > Convert vma assignment in vm_area_dup() to a memcpy() to prevent compiler > > > > errors when we add a const modifier to vma->vm_flags. > > > > > > > > ... > > > > > > > > --- a/kernel/fork.c > > > > +++ b/kernel/fork.c > > > > @@ -482,7 +482,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) > > > > * orig->shared.rb may be modified concurrently, but the clone > > > > * will be reinitialized. > > > > */ > > > > - *new = data_race(*orig); > > > > + memcpy(new, orig, sizeof(*new)); > > > > > > The data_race() removal is unchangelogged? > > > > True. I'll add a note in the changelog about that. Ideally I would > > like to preserve it but I could not find a way to do that. > > > > Perhaps Paul can comment? > > I wonder if KCSAN knows how to detect this race, given that it's now in > a memcpy. I assume so. data_race() is just wrapping an expression around __kcsan_[en|dis]able_current and ensuring the expression is evaluated once and returning the correct type. I believe the following should be sufficient. diff --git a/kernel/fork.c b/kernel/fork.c index 9f7fe3541897..1b30ee568e02 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -472,7 +472,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) * orig->shared.rb may be modified concurrently, but the clone * will be reinitialized. */ - *new = data_race(*orig); + data_race(memcpy(new, orig, sizeof(*new))); INIT_LIST_HEAD(&new->anon_vma_chain); dup_anon_vma_name(orig, new); } I don't see how memcpy could automagically figure out whether the memcpy is prone to races or not in an arbitrary context. Assuming using data_race this way is ok then Acked-by: Mel Gorman -- Mel Gorman SUSE Labs