Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1578964ima; Thu, 25 Oct 2018 01:14:25 -0700 (PDT) X-Google-Smtp-Source: AJdET5ckJ6MmEFTOseoZmjFPMZ9Koei23yFaTFBTTd0/1f9ITyZk5tn8n0YYjDnIHUDWF3gsTeiR X-Received: by 2002:a63:1e15:: with SMTP id e21-v6mr548893pge.430.1540455265262; Thu, 25 Oct 2018 01:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540455265; cv=none; d=google.com; s=arc-20160816; b=sxx+YQRAgwp2jlxWDwPS0ntRjzPSQVC88Bsx25Xex87uZZeGvTTXme/6hAkLPRd8/F zFhbperiGFnAq0DRIaNvRv4d8sR4ghnbXfrBz/pa2kGUf2mBZS1UcZ2MEIPmLMj2NSGT qcCechsg8AwS+Eu0JsNySb0mDGndiFDNtsCEtefUSGkHd88l8rORi+GCAqqyITjFlU2W vjCjDoXoiIiCjRbO3bnvSTHn+TA9/1vycEFfyouhwiZ0BEM0NqN0c1B90hfmf53Uqo1G yE682Y7i82USZzLPf7j5B32mVtaOzE3Qsy09x6VQdpRPKHc0Z++GOZV+KXhI4MiCzOrG yQYA== 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=4GvxGFKzNAUdnVvq5ALjFaJxTeQT6fedOqXQs6Nl+Cs=; b=yNqpwAMTQZi4buVwwDjFjCFCjg3eZom2H5frG68cdhqMdleUQA2aiNANrnUMDPchuE CWJu9OsN3fMXYxQ+ksttwwOSzvQf86eWG/fA19qsugoTLTxxHlFlLvtwSBfvHbuXEDTx c5lhFznuxeLUJ6Bj8yabrmTjoc9sjrU//KWOiyXtInfqBrHS8y047WS5yMQPcPIBFxUN MPxNo43NqZMcSmmCW8lG0pF0B+kre3hOQLVzgtyifnpd3TkX9R12LW7pn+ck/tgi1USx k7SA1RKXkdF6YKTQbpjHnqqPy7mvOzVX/eZpdOUJtIIIJxL/PDX0agd1KIrVgluLT0s4 syRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b="0Eu/5A5z"; 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 j10-v6si7186756pgk.22.2018.10.25.01.14.08; Thu, 25 Oct 2018 01:14:25 -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=pass header.i=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b="0Eu/5A5z"; 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 S1727361AbeJYQnW (ORCPT + 99 others); Thu, 25 Oct 2018 12:43:22 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51542 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727201AbeJYQnV (ORCPT ); Thu, 25 Oct 2018 12:43:21 -0400 Received: by mail-wm1-f68.google.com with SMTP id 143-v6so538883wmf.1 for ; Thu, 25 Oct 2018 01:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=4GvxGFKzNAUdnVvq5ALjFaJxTeQT6fedOqXQs6Nl+Cs=; b=0Eu/5A5zGVIqdsitCio+oF2mJA+TBdgWEeL0O6Tb32pQvr8keCU0kESbHDtBJFEMa6 8/Mf736AJdLDtBGSSNJstj6VmcYxUnc/VxVrTx4yEomBqlxV2DJeWrgf4nD2csvKYY5V vXplcRsNkc6XAvIL+EknLrLNuCO22RmruDzOt3apa3R8/qSvZq/dBn53kMKYPx3Qv0dw ImvWH+CyWFE68PaL442YwHk5cW9KtCSYb7Zx5HembqySvGqenFooU4MAH+wfraTfrfNl bksX22FEYpjB0+xxFpHzjHZirQCJHrORqLoWJYvISvvVwIZTnCuVeRDPVXj4M8XXEP5V VzCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=4GvxGFKzNAUdnVvq5ALjFaJxTeQT6fedOqXQs6Nl+Cs=; b=njvzX7cJm7R6WrYHFOdydqNeurdES0HEDwE0L1Qj2YLhXyYHupy/JLQsB79csS2Q/n uPGdg0ENNVptrPoMK+bkc7/RB0lwKGfzCAoQ6f2xONt7YTFC2i5zpWQ16kLjDCv7rokg 7ZSx+6qTDhxjV+n445puaorFQjl2lcwsZrtEDdOP5a0LLrDY21m9Fdol24oTLgBbbnc+ 32D61qyYm2hwmNLDP2QU8zIH3nvKAxvGoKbwAfCyXLSlVk+e6C3rIah6HxlfHSaHItIX WEfrj4Mr8xJ5uPGhjyWW1fY8qU1VeYInxtbV+bfyYFKlAkO+/FWQotYnqNggNqXg7HgI PvAg== X-Gm-Message-State: AGRZ1gJGLbHy3RU4YEjhEkSQEtWOCDhlG9D4mXh+pekeCyCOp6cEdxfX OyatApuMUFtEjR7cEhKm0vgyrw== X-Received: by 2002:a1c:9901:: with SMTP id b1-v6mr723909wme.15.1540455100460; Thu, 25 Oct 2018 01:11:40 -0700 (PDT) Received: from cisco ([173.38.220.34]) by smtp.gmail.com with ESMTPSA id q77-v6sm420220wmd.33.2018.10.25.01.11.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Oct 2018 01:11:39 -0700 (PDT) Date: Thu, 25 Oct 2018 09:11:30 +0100 From: Tycho Andersen To: Igor Stoppa Cc: Mathieu Desnoyers , 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 , Dave Hansen , Jonathan Corbet , Laura Abbott , Thomas Gleixner , Kate Stewart , "David S. Miller" , Greg Kroah-Hartman , Philippe Ombredanne , "Paul E. McKenney" , Josh Triplett , rostedt , Lai Jiangshan , linux-kernel Subject: Re: [PATCH 14/17] prmem: llist, hlist, both plain and rcu Message-ID: <20181025081130.GA31945@cisco> References: <20181023213504.28905-1-igor.stoppa@huawei.com> <20181023213504.28905-15-igor.stoppa@huawei.com> <1634210774.446.1540381072927.JavaMail.zimbra@efficios.com> <243a8ff2-889c-089f-a1ff-c882933ca5c3@gmail.com> <20181024145606.GA9019@cisco> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 25, 2018 at 01:52:11AM +0300, Igor Stoppa wrote: > On 24/10/2018 17:56, Tycho Andersen wrote: > > On Wed, Oct 24, 2018 at 05:03:01PM +0300, Igor Stoppa wrote: > > > On 24/10/18 14:37, Mathieu Desnoyers wrote: > > > > Also, is it the right approach to duplicate existing APIs, or should we > > > > rather hook into page fault handlers and let the kernel do those "shadow" > > > > mappings under the hood ? > > > > > > This question is probably a good candidate for the small Q&A section I have > > > in the 00/17. > > > > > > > > > > Adding a new GFP flags for dynamic allocation, and a macro mapping to > > > > a section attribute might suffice for allocation or definition of such > > > > mostly-read-only/seldom-updated data. > > > > > > I think what you are proposing makes sense from a pure hardening standpoint. > > > From a more defensive one, I'd rather minimise the chances of giving a free > > > pass to an attacker. > > > > > > Maybe there is a better implementation of this, than what I have in mind. > > > But, based on my current understanding of what you are describing, there > > > would be few issues: > > > > > > 1) where would the pool go? The pool is a way to manage multiple vmas and > > > express common property they share. Even before a vma is associated to the > > > pool. > > > > > > 2) there would be more code that can seamlessly deal with both protected and > > > regular data. Based on what? Some parameter, I suppose. > > > That parameter would be the new target. > > > If the code is "duplicated", as you say, the actual differences are baked in > > > at compile time. The "duplication" would also allow to have always inlined > > > functions for write-rare and leave more freedom to the compiler for their > > > non-protected version. > > > > > > Besides, I think the separate wr version also makes it very clear, to the > > > user of the API, that there will be a price to pay, in terms of performance. > > > The more seamlessly alternative might make this price less obvious. > > > > What about something in the middle, where we move list to list_impl.h, > > and add a few macros where you have list_set_prev() in prlist now, so > > we could do, > > > > // prlist.h > > > > #define list_set_next(head, next) wr_ptr(&head->next, next) > > #define list_set_prev(head, prev) wr_ptr(&head->prev, prev) > > > > #include > > > > // list.h > > > > #define list_set_next(next) (head->next = next) > > #define list_set_next(prev) (head->prev = prev) > > > > #include > > > > I wonder then if you can get rid of some of the type punning too? It's > > not clear exactly why that's necessary from the series, but perhaps > > I'm missing something obvious :) > > nothing obvious, probably there is only half a reference in the slides I > linked-to in the cover letter :-) > > So far I have minimized the number of "intrinsic" write rare functions, > mostly because I would want first to reach an agreement on the > implementation of the core write-rare. > > However, once that is done, it might be good to convert also the prlists to > be "intrinsics". A list node is 2 pointers. > If that was the alignment, i.e. __align(sizeof(list_head)), it might be > possible to speed up a lot the list handling even as write rare. > > Taking as example the insertion operation, it would be probably sufficient, > in most cases, to have only two remappings: > - one covering the page with the latest two nodes > - one covering the page with the list head > > That is 2 vs 8 remappings, and a good deal of memory barriers less. > > This would be incompatible with what you are proposing, yet it would be > justifiable, I think, because it would provide better performance to prlist, > potentially widening its adoption, where performance is a concern. I guess the writes to these are rare, right? So perhaps it's not such a big deal :) > > I also wonder how much the actual differences being baked in at > > compile time makes. Most (all?) of this code is inlined. > > If the inlined function expects to receive a prlist_head *, instead of a > list_head *, doesn't it help turning runtime bugs into buildtime bugs? In principle it's not a bug to use the prmem helpers where the regular ones would do, it's just slower (assuming the types are the same). But mostly, it's a way to avoid actually copying and pasting most of the implementations of most of the data structures. I see some other replies in the thread already, but this seems not so good to me. Tycho