Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp548655ima; Fri, 26 Oct 2018 02:41:56 -0700 (PDT) X-Google-Smtp-Source: AJdET5c8fq8VMWJGjfU8JQbAoPx1xJ0PyxP+H+Y1pQWIYQPPaCrEdOhxpuofG0MJBlu0JDGdUyrM X-Received: by 2002:a17:902:54d:: with SMTP id 71-v6mr2863456plf.80.1540546916081; Fri, 26 Oct 2018 02:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540546916; cv=none; d=google.com; s=arc-20160816; b=kYkB1dmdMvtMeV6bgM+Go+7Ln5Nt7GaV0XuWf6auVJUMxIr7HGZ2r+Qk+wbP1BroKT 7jx77K+kmv7hHOnbGOp/wY93NDQFaukfPl/fnJQuBI/azh2L8z45Ih6VObxKEwvM9hG8 Y7nls0OAzBeF0lifF9QyB2D8RxK6NfOrwFcubC+mZ3fXZhMpARXHIiO2Azgp80ot2oY7 ncHKFu5TcJerm9Z2RkThMd7zru/6DBuQj3xOi5WB0iWpCfrL+fCQ8iQiZq+5uIf0Oi/W 1p5j2/FWkXWcXD5zB17uh1XD2ox3pXC259l09I9Y/VCfnCnFbwKYxulFrUjO+izdKF9Q He+w== 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=12yu2//rJr5DMe6Xs212+GnjuBvECqEIB865SHmpats=; b=XeaBOUDZEt4j3CBosQZaroF7DfLv157vVwTzsiFiHLk8zBJwtbPAHgg879IAMNVCPH BrhGHYEs65rf0XQjBRhBdjIipF7FqwoRFO2XJQmaNQfmxJCHSJbdiIa6VPEUYbbvJoAD 9PFvOauJH0grDoDKBCrJva5wYO/is8O1Anb4RwavKshahM5GZMel1MEETAfLNj74zQLM M/M5K0Um6UGzQPbf6vQdgWUj5ph+Mw/U2waB2SJZAtZ32dRsmLZEBdzNTY+iIUp3M18O uRTlCCi4IOmb2bAtiiBKyT+F2Xb1eYzCyoKLWe37ONiy8gtACZwUjPtx/yPqhTdhdkbE h7Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=b1F6jio+; 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 w64-v6si7229379pfw.101.2018.10.26.02.41.40; Fri, 26 Oct 2018 02:41:56 -0700 (PDT) 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=bombadil.20170209 header.b=b1F6jio+; 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 S1726772AbeJZSRk (ORCPT + 99 others); Fri, 26 Oct 2018 14:17:40 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:32946 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbeJZSRj (ORCPT ); Fri, 26 Oct 2018 14:17:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=12yu2//rJr5DMe6Xs212+GnjuBvECqEIB865SHmpats=; b=b1F6jio+XBPpKYaCFyXWeTKLX 0YXjPfjW4OUpBKs6kq3RneDw5i5Gu4zlc+org+qK7VTwoQRAgE579i7J04e4uFIkMAVtT0/ArZYjY 9zKYrVrVfnbSARe2wBt/mgBY+pGwmt5OyzzaMRNbkT3HY5Ybc+Hz9DGL4UHeV33eGcIS3edWEMHvQ DJvz+Ml7p+T93g6NBAAqAGrIoXeZ4KmshNPYXRSiUM2fvJrbWy4ma+PEgBN2eR4UFZAzihjlc9NCs Bm1zHcP7+YLlOlGguCNKaBNKRWGo1aUbA8/pxQoko0+0ic0SHnzCuiCYzxVdH3QjZMzf+qP2wEiiQ cwpzUinAw==; Received: from [167.98.65.38] (helo=worktop) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gFyc7-0005NO-Lb; Fri, 26 Oct 2018 09:41:08 +0000 Received: by worktop (Postfix, from userid 1000) id B10AA6E07CA; Fri, 26 Oct 2018 11:41:05 +0200 (CEST) Date: Fri, 26 Oct 2018 11:41:05 +0200 From: Peter Zijlstra To: Igor Stoppa Cc: Mimi Zohar , Kees Cook , Matthew Wilcox , Dave Chinner , James Morris , Michal Hocko , kernel-hardening@lists.openwall.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, igor.stoppa@huawei.com, Dave Hansen , Jonathan Corbet , Laura Abbott , Vlastimil Babka , "Kirill A. Shutemov" , Andrew Morton , Pavel Tatashin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 02/17] prmem: write rare for static allocation Message-ID: <20181026094105.GE3159@worktop.c.hoisthospitality.com> References: <20181023213504.28905-1-igor.stoppa@huawei.com> <20181023213504.28905-3-igor.stoppa@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181023213504.28905-3-igor.stoppa@huawei.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 24, 2018 at 12:34:49AM +0300, Igor Stoppa wrote: > +static __always_inline That's far too large for inline. > +bool wr_memset(const void *dst, const int c, size_t n_bytes) > +{ > + size_t size; > + unsigned long flags; > + uintptr_t d = (uintptr_t)dst; > + > + if (WARN(!__is_wr_after_init(dst, n_bytes), WR_ERR_RANGE_MSG)) > + return false; > + while (n_bytes) { > + struct page *page; > + uintptr_t base; > + uintptr_t offset; > + uintptr_t offset_complement; > + > + local_irq_save(flags); > + page = virt_to_page(d); > + offset = d & ~PAGE_MASK; > + offset_complement = PAGE_SIZE - offset; > + size = min(n_bytes, offset_complement); > + base = (uintptr_t)vmap(&page, 1, VM_MAP, PAGE_KERNEL); > + if (WARN(!base, WR_ERR_PAGE_MSG)) { > + local_irq_restore(flags); > + return false; > + } > + memset((void *)(base + offset), c, size); > + vunmap((void *)base); BUG > + d += size; > + n_bytes -= size; > + local_irq_restore(flags); > + } > + return true; > +} > + > +static __always_inline Similarly large > +bool wr_memcpy(const void *dst, const void *src, size_t n_bytes) > +{ > + size_t size; > + unsigned long flags; > + uintptr_t d = (uintptr_t)dst; > + uintptr_t s = (uintptr_t)src; > + > + if (WARN(!__is_wr_after_init(dst, n_bytes), WR_ERR_RANGE_MSG)) > + return false; > + while (n_bytes) { > + struct page *page; > + uintptr_t base; > + uintptr_t offset; > + uintptr_t offset_complement; > + > + local_irq_save(flags); > + page = virt_to_page(d); > + offset = d & ~PAGE_MASK; > + offset_complement = PAGE_SIZE - offset; > + size = (size_t)min(n_bytes, offset_complement); > + base = (uintptr_t)vmap(&page, 1, VM_MAP, PAGE_KERNEL); > + if (WARN(!base, WR_ERR_PAGE_MSG)) { > + local_irq_restore(flags); > + return false; > + } > + __write_once_size((void *)(base + offset), (void *)s, size); > + vunmap((void *)base); Similarly BUG. > + d += size; > + s += size; > + n_bytes -= size; > + local_irq_restore(flags); > + } > + return true; > +} > +static __always_inline Guess what.. > +uintptr_t __wr_rcu_ptr(const void *dst_p_p, const void *src_p) > +{ > + unsigned long flags; > + struct page *page; > + void *base; > + uintptr_t offset; > + const size_t size = sizeof(void *); > + > + if (WARN(!__is_wr_after_init(dst_p_p, size), WR_ERR_RANGE_MSG)) > + return (uintptr_t)NULL; > + local_irq_save(flags); > + page = virt_to_page(dst_p_p); > + offset = (uintptr_t)dst_p_p & ~PAGE_MASK; > + base = vmap(&page, 1, VM_MAP, PAGE_KERNEL); > + if (WARN(!base, WR_ERR_PAGE_MSG)) { > + local_irq_restore(flags); > + return (uintptr_t)NULL; > + } > + rcu_assign_pointer((*(void **)(offset + (uintptr_t)base)), src_p); > + vunmap(base); Also still bug. > + local_irq_restore(flags); > + return (uintptr_t)src_p; > +} Also, I see an amount of duplication here that shows you're not nearly lazy enough.