Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3037948imu; Sun, 9 Dec 2018 15:45:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/WuLnrpb3UpGShO4/BUXiR2nI64zfJ+TSaicP3ZRtW8Bu/tDTfuR78r3iyWd2oa3IAI9asF X-Received: by 2002:a17:902:28aa:: with SMTP id f39mr10176983plb.297.1544399137294; Sun, 09 Dec 2018 15:45:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544399137; cv=none; d=google.com; s=arc-20160816; b=wLMjPsM8l5n/XepBzNYoCly4AhA1uLQG71q31kRh2xpKfXro2EKqUrs/6W7dzUFBMa kqG63kCf71Kf6Hl7z5/aB8+hV86+uHu4xP99JlQbofS10TEtmqEUR7fLlGdhHV3Tmm/s Ih7aH3Rq8iYxTQFWDC7uc1tdiTv/YwGFI2nClweoiESnxaTFqFhFUuzqky75DMTPipxv FFoXIZ7wN9Ff6cZOHTtKNXQbAW9iUicv1s+Dtd72PnwHySzHu+AA4FwlU/Rnb/WWDpnR J1Rdu3yRXRmNST2UlrTfGkORlhrZ/E11n18IIcWSeK7eJxhc6KHu7uHQnmg3YsuPTC8o gN8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=aSbfvJCmqfAHFgKylE3VLr16VVPfdibM9zf2CTitOJM=; b=Yg6jC9i4LG7Y74KPZEjHpwZkaAzpqtBDSiW9lpA9QzKrAukJo7lqj5xwtgHiW1kZLY zwIfNLsFOi4+wx+vT/v0aGM54ImPHBX3Ffi5cBOzKOwNW1OTTmfUzPylEu9eKOvME4SS hgcDVpsQFWNd02GgLVdh0aY6h5zA//KEv+WJdYfOGAyvmP6qHoPLXnT4eh6jq8KM2hs0 OsX5m8Ps9/C3loe+y0l13wz6qYB/fA7qD4+ntUIfD/WeVUDaYYGqMkBl81RL6VqrBFld Hy5JWU2GLRk4qz/POP7FImppclgMm+k0HR8h9vrtrgM9JamMg0nxqDlQsQpep1rjYDik NeTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=E+nCmQhI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w24si8033626pgj.582.2018.12.09.15.45.22; Sun, 09 Dec 2018 15:45:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=E+nCmQhI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbeLIWc0 (ORCPT + 99 others); Sun, 9 Dec 2018 17:32:26 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:37621 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbeLIWc0 (ORCPT ); Sun, 9 Dec 2018 17:32:26 -0500 Received: by mail-lf1-f65.google.com with SMTP id p17so6630098lfh.4; Sun, 09 Dec 2018 14:32:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=aSbfvJCmqfAHFgKylE3VLr16VVPfdibM9zf2CTitOJM=; b=E+nCmQhIR90wXfefO8VAiow2e+ZE4h5e7a9+Ojvj5ehWOC+O3j5fyoGILntutdpY9j WxsyufQda/KjhthwOR3eQTjRqrPpTCCdC5508U64mVuUFVHAvjt1joLZDIvEft++jcxj PKc3Oqcf4yczvNyDdyCwAxBXSVZVxTS9oSoqkC4+DFOQTyPXEsJWtqzX/l9e309Iv42l 4fu/wFvFQPZ66GK+glSu33qYxnUEA5lkkuBLBKxFWqU+7hF/fzGzsPgLxOTn6vIipj0x 52MayLG6Jtl09NsZ4IC20ClEmirN1Ovf0/+qW93H/kPWIeJvJI4wifLbGmXn7ee2QbMZ SmfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=aSbfvJCmqfAHFgKylE3VLr16VVPfdibM9zf2CTitOJM=; b=pQgWg+w3Svc60KlvRxdNtBIXER8fIMopUWUTOD6BMWGJYH9vtmmuqqt392RjUxznaq c3NDBr4U8po0EraSMTwVbIyQvPTP9n4PGfQgeIpoGPcQwbGES2Kfn323bLGnoi3fZmeY crqqRFut+9c4o4+9treeaXNvToS2p835MeUb7+XNNXkYhbUEGDcI9GBWS0x8KmsZ3Fi/ a1yjrmNkafhv8cXMOoJBWlj0eWxuLSGk2SSmkGk/OGlbHdrXmb9FjZMabZxlZ1gnYMcJ poeCh6POQEUTh3rJGW4vpWW/0NUs8TlsL73jC4naA7BBrO5xBbStKOxoIJFrz8FP/nD0 O5bA== X-Gm-Message-State: AA+aEWY3ansIu6Zf4kT4LDpoRMvLXmhCY77ojF13kCyfsNvkpFHuKAUR 3dCSjNis2Bs2l8SuEtDDbPb49YADaHs= X-Received: by 2002:a19:c4cc:: with SMTP id u195mr5342648lff.141.1544394743398; Sun, 09 Dec 2018 14:32:23 -0800 (PST) Received: from [192.168.10.160] (91-159-62-226.elisa-laajakaista.fi. [91.159.62.226]) by smtp.gmail.com with ESMTPSA id x29-v6sm1820387ljb.97.2018.12.09.14.32.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Dec 2018 14:32:22 -0800 (PST) Subject: Re: [PATCH 2/6] __wr_after_init: write rare for static allocation To: Peter Zijlstra , Andy Lutomirski Cc: linux-arch , linux-s390 , Martin Schwidefsky , Heiko Carstens , Benjamin Herrenschmidt , Kees Cook , Matthew Wilcox , Igor Stoppa , Nadav Amit , Dave Hansen , linux-integrity , Kernel Hardening , Linux-MM , LKML References: <20181204121805.4621-1-igor.stoppa@huawei.com> <20181204121805.4621-3-igor.stoppa@huawei.com> <20181206094451.GC13538@hirez.programming.kicks-ass.net> From: Igor Stoppa Message-ID: Date: Mon, 10 Dec 2018 00:32:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181206094451.GC13538@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/12/2018 11:44, Peter Zijlstra wrote: > On Wed, Dec 05, 2018 at 03:13:56PM -0800, Andy Lutomirski wrote: > >>> + if (op == WR_MEMCPY) >>> + memcpy((void *)wr_poking_addr, (void *)src, len); >>> + else if (op == WR_MEMSET) >>> + memset((u8 *)wr_poking_addr, (u8)src, len); >>> + else if (op == WR_RCU_ASSIGN_PTR) >>> + /* generic version of rcu_assign_pointer */ >>> + smp_store_release((void **)wr_poking_addr, >>> + RCU_INITIALIZER((void **)src)); >>> + kasan_enable_current(); >> >> Hmm. I suspect this will explode quite badly on sane architectures >> like s390. (In my book, despite how weird s390 is, it has a vastly >> nicer model of "user" memory than any other architecture I know >> of...). I think you should use copy_to_user(), etc, instead. I'm not >> entirely sure what the best smp_store_release() replacement is. >> Making this change may also mean you can get rid of the >> kasan_disable_current(). > > If you make the MEMCPY one guarantee single-copy atomicity for native > words then you're basically done. > > smp_store_release() can be implemented with: > > smp_mb(); > WRITE_ONCE(); > > So if we make MEMCPY provide the WRITE_ONCE(), all we need is that > barrier, which we can easily place at the call site and not overly > complicate our interface with this. Ok, so the 3rd case (WR_RCU_ASSIGN_PTR) could be handled outside of this function. But, since now memcpy() will be replaced by copy_to_user(), can I assume that also copy_to_user() will be atomic, if the destination is properly aligned? On x86_64 it seems yes, however it's not clear to me if this is the outcome of an optimization or if I can expect it to be always true. -- igor