Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10484187imu; Thu, 6 Dec 2018 01:46:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/V+IZnH5900T1hTMcQGsR/2RyKtTzuotFgaA3hsR+K50cTmw1ikfRo8hIuA+E19jxz8+mZp X-Received: by 2002:a17:902:ab84:: with SMTP id f4mr26890433plr.207.1544089583444; Thu, 06 Dec 2018 01:46:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544089583; cv=none; d=google.com; s=arc-20160816; b=iEDkQ96Svykh4FpRYY8MUIu9z5TBtbRkQYp8rpWck0gT8+lmX5q6eI4Ix9evZ6vXMA ZKSX4TpBNe49pSQmMSqdpLtnOQ3Ldj03vq9Rgx0A7/C4qU681SxpRZlh6147L51OiIpc 1sylMqaeYW0Xj6a6XMjySzk53ZJ3AMfW1N6fjdDHldJjrJZ+Hs+MX6XqkBoSTkGRxHlO hzHX9k9oPOIuTJVdWJttWJymWdEwasLOEDSOtDRf7/rVlVIy287bw0OMZjRHfqnxoAWH /qPKai38P27CyR58HBu3FP8M2ZK36GcHUy9P+R+xputRrZBEozw2M3xYO6zW3dARw577 2IZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+Oc9aPprVL/I8aoLjV3ntWcij0NK7R/RtAEC+ha4tto=; b=0PjydfWp2JgU3+guAFq03KdPsvlLcbLGd5Tf90nYPEUJYN0uo9fX1AEwOpVfp2DQiR o2HbaWoMOZUNs4oNpUEIdMWRAfB4yGTSPLjBvyO2lwY9dhVL8nD+DtyTQkHCdiq9P+oJ YSKSIydJXHAkZGi9A2wjE6MkXBu6UBKfm86INuLiwaHIRYL4tprQDJZlFx+AAATzI/Bm jbMWjGb+xaUIr0lXr6rYpeVOibTIemQ+br4WrSsWVnxkpjyqsQyhCVNgjY0eb9/W5Xct koKjBzWO5FZdzCEO5VJx8eZ5wlkoh7crkzw9HVB9VKYS8Jdb3qEsLvBFa+DlZOXNhdjw rZ4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=mKV5ebHo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j132si23050536pfc.84.2018.12.06.01.46.06; Thu, 06 Dec 2018 01:46:23 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=mKV5ebHo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729127AbeLFJpY (ORCPT + 99 others); Thu, 6 Dec 2018 04:45:24 -0500 Received: from merlin.infradead.org ([205.233.59.134]:46828 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727763AbeLFJpY (ORCPT ); Thu, 6 Dec 2018 04:45:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+Oc9aPprVL/I8aoLjV3ntWcij0NK7R/RtAEC+ha4tto=; b=mKV5ebHo5lV4y9zyrU2euNCRc wuSf9414bTPHTvA0KSNa5woZt/SBWRuEZyfuEzhbp9A1B1mWu2RWw4tSN9VU73LBfne/gpJ3TpiyY SArF2D2WKFTw130pW9wTagCc4W4cr/qWcJPOFaBKmTD7VAQpVTbTfSnZz6tQnGTZjwqv4sYLyruZx 5GAxh2v7hI1SY7jTcslSXpM5uH/a7Yz+J1qqLJ2scxlQyzjWgsfSSbr1wePV2XmsNrIE0RDxOHk/L 8PRep4ct6P3rgzIaMLvn8ev+0AG0u7JzJ/MdZAgB1MLEM4DJukpyhRvgOHcioleL/dHuJFvVkDtUi UGEa04UWQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUqDG-0005JO-A1; Thu, 06 Dec 2018 09:44:54 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9054E2029F4C1; Thu, 6 Dec 2018 10:44:51 +0100 (CET) Date: Thu, 6 Dec 2018 10:44:51 +0100 From: Peter Zijlstra To: Andy Lutomirski Cc: Igor Stoppa , 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 Subject: Re: [PATCH 2/6] __wr_after_init: write rare for static allocation Message-ID: <20181206094451.GC13538@hirez.programming.kicks-ass.net> References: <20181204121805.4621-1-igor.stoppa@huawei.com> <20181204121805.4621-3-igor.stoppa@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Because performance is down the drain already, an additional full memory barrier is peanuts here (and in fact already implied by the x86 CR3 munging).