Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp5128683imd; Tue, 30 Oct 2018 12:24:27 -0700 (PDT) X-Google-Smtp-Source: AJdET5f9hYN4Jxp/KmjH4Tc7DFGslqHBDJvpPPX2huPDxNobF7ptpanr8iYJu5yrWLiGC4qW7kpb X-Received: by 2002:a63:6b08:: with SMTP id g8mr150427pgc.119.1540927467218; Tue, 30 Oct 2018 12:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540927467; cv=none; d=google.com; s=arc-20160816; b=cirPl1N1X8bSSW7OXrCsOnlYE69lDunhO5LENR43cEfFgmRYWxFklp9fI4hOIeGT1+ WqYbgX1W0a3dfI+X9mCV2lMxVS2bW/vIehIIkABU3TFX6LZdW27rIJzGUGRrm9PIDsNM VYGh6UzVmonS5nY1Iep2M7fI2FFdKcyKBjRtROQj79q0BhBJP8YLblvYZ40VxXqwbgme kuM6rP7lCaktH8p+6WO5u5ljbBkgRNSu5S+5+BWHz76i1Vivz5jbpDmSx/3w7h/ApSkh mAnxV3ppoZbVoiBS7MJgdR2NPOVOBpa1aYoPLg+tGmgCKfWJDJ3v/D9odLXARadH98l1 UKGA== 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=37nJP9R2qcO8HBp/dMyepi58FVf9IEQD7mWnc5gvOVU=; b=vkbevruKRX4HhsZC4v9E2guflPrOmpEFddtgi9JTfj25dX+SpEMiJHSobEZ9/reso8 3Ig92zC/umU8U19wrPcjObER10jJbqDO3PmxNWNBp+0hRRAvnhn7YsVjvU16AqsK6d62 1kFJdkE63Jdtd3SakKQD2AGP7BOCYtH3XskJfg5ICaQgc7rUwVTCTkwITI3EBFBvs8Q9 NjXphYh2Cvj20tyEqHKVE/IReyB62VwJ1mGDH6hb1kAASvCDyDTOsE+A69Av4m5si9CH Zm4c3aG7gVqXa6psib2Qt2/AdCnYhqBncu1EZKaPmyzs8QSeI95qBg071LnwMo/6a9yQ /7Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=KRJQaIsC; 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 e184-v6si25972126pfa.206.2018.10.30.12.24.11; Tue, 30 Oct 2018 12:24:27 -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=KRJQaIsC; 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 S1727732AbeJaEPM (ORCPT + 99 others); Wed, 31 Oct 2018 00:15:12 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:45990 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725743AbeJaEPM (ORCPT ); Wed, 31 Oct 2018 00:15:12 -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=37nJP9R2qcO8HBp/dMyepi58FVf9IEQD7mWnc5gvOVU=; b=KRJQaIsC774yFQU2a5LgnLkLS SSGXeYxMt6FaQKWmDTNz6ne2oE0AZXsXUx4Q0g+y3nyb1M6pLClzCvMywUxGuJXr/xjqubuyTnZv2 Go2w8uj9DvgZcq74mG3w4ej1/TWmISnqEs7SNchJML7UQ4DvCtIsDlh4F7VO5KTqGSoHg3Q08g8sd KaWv/YZMWvFsFR7+vPRVEmamyeE+y4hxCpQRbZGLGVCpwDAB9x2qnfYQXPrh4CjxytK50eeB1JUsY uarR2NbtMIwmc1HWVfWxIRWE3wQWYCUBr65PxjBkuyYVpOxIkKU0kqMWCC6mV6jbf3nx8kik7wyB5 4un6CBuYw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gHZYr-0000hc-Sk; Tue, 30 Oct 2018 19:20:21 +0000 Date: Tue, 30 Oct 2018 12:20:21 -0700 From: Matthew Wilcox To: Tycho Andersen Cc: Andy Lutomirski , Kees Cook , Peter Zijlstra , Igor Stoppa , Mimi Zohar , Dave Chinner , James Morris , Michal Hocko , Kernel Hardening , linux-integrity , linux-security-module , Igor Stoppa , Dave Hansen , Jonathan Corbet , Laura Abbott , Randy Dunlap , Mike Rapoport , "open list:DOCUMENTATION" , LKML , Thomas Gleixner Subject: Re: [PATCH 10/17] prmem: documentation Message-ID: <20181030192021.GC10491@bombadil.infradead.org> References: <20181023213504.28905-11-igor.stoppa@huawei.com> <20181026092609.GB3159@worktop.c.hoisthospitality.com> <20181028183126.GB744@hirez.programming.kicks-ass.net> <40cd77ce-f234-3213-f3cb-0c3137c5e201@gmail.com> <20181030152641.GE8177@hirez.programming.kicks-ass.net> <0A7AFB50-9ADE-4E12-B541-EC7839223B65@amacapital.net> <20181030175814.GB10491@bombadil.infradead.org> <20181030182841.GE7343@cisco> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181030182841.GE7343@cisco> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 30, 2018 at 12:28:41PM -0600, Tycho Andersen wrote: > On Tue, Oct 30, 2018 at 10:58:14AM -0700, Matthew Wilcox wrote: > > On Tue, Oct 30, 2018 at 10:06:51AM -0700, Andy Lutomirski wrote: > > > > On Oct 30, 2018, at 9:37 AM, Kees Cook wrote: > > > I support the addition of a rare-write mechanism to the upstream kernel. > > > And I think that there is only one sane way to implement it: using an > > > mm_struct. That mm_struct, just like any sane mm_struct, should only > > > differ from init_mm in that it has extra mappings in the *user* region. > > > > I'd like to understand this approach a little better. In a syscall path, > > we run with the user task's mm. What you're proposing is that when we > > want to modify rare data, we switch to rare_mm which contains a > > writable mapping to all the kernel data which is rare-write. > > > > So the API might look something like this: > > > > void *p = rare_alloc(...); /* writable pointer */ > > p->a = x; > > q = rare_protect(p); /* read-only pointer */ > > > > To subsequently modify q, > > > > p = rare_modify(q); > > q->a = y; > > Do you mean > > p->a = y; > > here? I assume the intent is that q isn't writable ever, but that's > the one we have in the structure at rest. Yes, that was my intent, thanks. To handle the list case that Igor has pointed out, you might want to do something like this: list_for_each_entry(x, &xs, entry) { struct foo *writable = rare_modify(entry); kref_get(&writable->ref); rare_protect(writable); } but we'd probably wrap it in list_for_each_rare_entry(), just to be nicer.