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 1FDDCC636CC for ; Tue, 7 Feb 2023 17:16:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F568900005; Tue, 7 Feb 2023 12:16:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A513900002; Tue, 7 Feb 2023 12:16:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F774900005; Tue, 7 Feb 2023 12:16:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 69D56900002 for ; Tue, 7 Feb 2023 12:16:21 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 29B80A0391 for ; Tue, 7 Feb 2023 17:16:21 +0000 (UTC) X-FDA: 80441149362.29.D245970 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf23.hostedemail.com (Postfix) with ESMTP id 0CC33140026 for ; Tue, 7 Feb 2023 17:16:18 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Y9FmfEJa; spf=pass (imf23.hostedemail.com: domain of elver@google.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=elver@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=1675790179; 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=Z7B14u7hbB/VXiWZvddsL6aIZYt39FVX4bLARrPtAv0=; b=jlA98tFQJkXdPTC4BTSg+XkBdAIwqqKaWeEzoSnmcbSt5qRmtmFgqKbz59gmI/zy2m7UVF g50drGOYowblbkoPvFIVVVyW/gF5C4wB/G1Jx5GOSR3fXxeUgecCfNcMvGKjKO5vhx4ghZ XcEeAlXdUKv0MaoqbqxtxUHbvWwyR5o= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Y9FmfEJa; spf=pass (imf23.hostedemail.com: domain of elver@google.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675790179; a=rsa-sha256; cv=none; b=sLDiaPU53rywYkLFc2Rlm7IphN8wdeOzU3nDQN6U3TADePiugA71u6CbEA/cxXhwzCoc5S C+iKMnP+FFsYuGz7YPu3gA/J7M7G8k4EnzlHlvyH5l1FZyPXlqHvP2Hx5EiKVSe1S5czjj cfQEJOc6ZZOz1zDbEGeAgSdiuWVa/WU= Received: by mail-wr1-f52.google.com with SMTP id m14so14233042wrg.13 for ; Tue, 07 Feb 2023 09:16:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=Z7B14u7hbB/VXiWZvddsL6aIZYt39FVX4bLARrPtAv0=; b=Y9FmfEJaPUKP01BpBrAbyUYKx/RChLT6yUXZss4TzkZZpnxSibWVx6Ft9DTOKNZSlf bbzELRho2ZJluKmjB595UuxnvHVIBSwm694bjmmrYm+OuT1ALInGSP3Qp1NZvBrRXrgB lGn6Ds34sf3a038gEV1tz052BldGx7hPZAYSAvCkpHt5Yfw/AadKxqOqu19QdZ1sWaO6 amTDGpYaHu9W423M6iD5H1vqa+EweqMvK7pUi5qqpAUQmnIUjj/fg3Qh4aoNZaEzpeRO JP0tMINwibFX5Il2vdPlZN2ptjO9vYxmwRp7I5p6XZn9gmRoXWpuWbMK/zHk6Xy5MtX/ nh4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z7B14u7hbB/VXiWZvddsL6aIZYt39FVX4bLARrPtAv0=; b=eEFBVYmyJtgbWgK68RujDNyVynaveCrigCJ6czRsF4pmuUM9Cy0KyXmwcviI/3y2sF hmQA6sqOFmTA9Y6FGNFLyOC/GUJYt+ATrh+CO9NjXE04bFF3yo8hNNgmdzfguGoa/VN6 SuFMqJ68y/H6qEnJyq5fpGkwTxe020smqAGzDR2aE7Nl6bnhdsdarx4PG9wEk5MdFv+c qmYlYaiqcJD18dCSef+8aw2nksYcKm05PzpqX1g6J3u1PrwF+/xV5yfHE3ZgHaIV7fd6 Feeq6my7LOdqdBitjg1XsJKZLSzELEIjOI46MGeCVWXBckXJVsFe7C3m192XhoZbcc/M Vn4g== X-Gm-Message-State: AO0yUKWDXIgnlfqtJwxf1Y57GRMcWRRSVqcuSrwjmkvps3tEWu3V7iPY QDqezH5qHCZeQo5aC3Ae7C3JOg== X-Google-Smtp-Source: AK7set/eY6l3j0tIm+E4Ulj8uu+N4HWCIJbO8QgFYfPq9KRYPC10pX+4fMH8NtYMAoGaEz1vRgHJQw== X-Received: by 2002:adf:f44b:0:b0:2bf:e4b2:64a8 with SMTP id f11-20020adff44b000000b002bfe4b264a8mr3630125wrp.42.1675790177410; Tue, 07 Feb 2023 09:16:17 -0800 (PST) Received: from elver.google.com ([2a00:79e0:9c:201:57f3:e3b1:e247:9c58]) by smtp.gmail.com with ESMTPSA id s16-20020adff810000000b002c3dc4131f5sm9414897wrp.18.2023.02.07.09.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 09:16:16 -0800 (PST) Date: Tue, 7 Feb 2023 18:16:09 +0100 From: Marco Elver To: "Paul E. McKenney" Cc: Andrew Morton , Suren Baghdasaryan , 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, 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: References: <20230125233554.153109-1-surenb@google.com> <20230125233554.153109-2-surenb@google.com> <20230125162159.a66e5ef05fecb405e85ffec9@linux-foundation.org> <20230125173449.5472cffc989dfab4b83c491d@linux-foundation.org> <20230126172726.GA682281@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230126172726.GA682281@paulmck-ThinkPad-P17-Gen-1> User-Agent: Mutt/2.2.9 (2022-11-12) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0CC33140026 X-Stat-Signature: n8jm8ja5izjpofoudjr315pt1eybf1jm X-HE-Tag: 1675790178-667841 X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IF1x6cn1oSL5w0neFGgRj1FHxgQAG7PElPMPvhG/auVIbD0iL6Edvl+U/4YcOVVwwpS3Vcb2E+Nd1d/oDeVQQ4HBRw3wSjT8a2YIEUTqZ9mHolyapM295HnK1zj7qcPrq5ZL0GxTq4X8p4jEWCF32Yumi3UfduwvYfCFbydXBUl15ByTdBDX4AowailRTA4U/f7ZqMvmeCBVlOY+Mlx32jmTHszg8QfC2Kynu+Z2ww7FvFneMVNWyUxTQrCl+iSNK09qzYymp3sqKgnOqASjiGK18xtF46f1dgdMLfIkn17mlmp/8CJFctRas6lZJITxWNDSLkoV8xF5xiotssoMBLTLJsXFKkhLeV+3M9nMlsTYKV5X9DIDPsZ+l+h9cOIhNvuXj135GGooCKB9Dz7klNV+7742DolIL25gS97OASifXXVKD1 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 Thu, Jan 26, 2023 at 09:27AM -0800, Paul E. McKenney wrote: > 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. > > I ran an experiment memcpy()ing between a static array and an onstack > array, and KCSAN did not complain. But maybe I was setting it up wrong. > > This is what I did: > > long myid = (long)arg; /* different value for each task */ > static unsigned long z1[10] = { 0 }; > unsigned long z2[10]; > > ... > > memcpy(z1, z2, ARRAY_SIZE(z1) * sizeof(z1[0])); > for (zi = 0; zi < ARRAY_SIZE(z1); zi++) > z2[zi] += myid; > memcpy(z2, z1, ARRAY_SIZE(z1) * sizeof(z1[0])); > > Adding Marco on CC for his thoughts. ( Sorry for not seeing it earlier - just saw this by chance. ) memcpy() data races will be detected as of (given a relatively recent Clang compiler): https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7c201739beef Also beware that the compiler is free to "optimize" things by either inlining memcpy() (turning an explicit memcpy() into just a bunch of loads/stores), or outline plain assignments into memcpy() calls. So the only way to be sure what ends up there is to look at the disassembled code. The data_race() was introduced by: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cda099b37d716 It says: "vm_area_dup() blindly copies all fields of original VMA to the new one. This includes coping vm_area_struct::shared.rb which is normally protected by i_mmap_lock. But this is fine because the read value will be overwritten on the following __vma_link_file() under proper protection. Thus, mark it as an intentional data race and insert a few assertions for the fields that should not be modified concurrently." And as far as I can tell this hasn't changed. Thanks, -- Marco