From patchwork Fri Sep 7 22:34:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 10592647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8CB231515 for ; Fri, 7 Sep 2018 22:33:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C7F12B030 for ; Fri, 7 Sep 2018 22:33:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FCD62B12D; Fri, 7 Sep 2018 22:33:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19C4D2B030 for ; Fri, 7 Sep 2018 22:33:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 339298E0004; Fri, 7 Sep 2018 18:33:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2C0458E0001; Fri, 7 Sep 2018 18:33:49 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 161F08E0004; Fri, 7 Sep 2018 18:33:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id C3D168E0001 for ; Fri, 7 Sep 2018 18:33:48 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id e124-v6so7746737pgc.11 for ; Fri, 07 Sep 2018 15:33:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent; bh=ExhzVHsdv6lfoeuwhbFclEbkpbsJl6iiiRC3ImFe1Ec=; b=pHEJ4P+FkzmsF0bS2WWNYiD9A8LLRX+s31RSl01uvkQO72guczJo03DBs7VNVXnPqj 3dtKjTFav1eV/ubwybOXEV5/dA3Y6eHwTFMcRWt5E3nRQQtSp/1w5ypQUckQC68MdOLK 4fxrtFvy4v2dWFXSZFbHVwq/v7VSghiPKkElXeFV+dvTcZ0D3T/UCVKOk8nKsMPUHg4H A8osa9fDf0/T+jAyAaJ+PhSJoey7DYliFVYFQDB2OSAeMWgWW1gGDiPfAYcJgr8Y+94d t6+Qzafm8nH22WQl1B9fcSyimSfiKanO72oMyQ9/2a9KybEF/LSrXyqQPQMqF+rRIkeD w7dg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APzg51CKfI1TYPIX+kx8dllh4czHPA3VGzZwpOpf56ddwmu2E6oHRtEB V0cxgR+lyPwZtY8Ys2h5fCRbUUOo4L5LrD0obhA/RN5Cikosz1edZBXAcljx0lGCBfdWp85ctIk Bummd9erVUmvbVMyr81hYL/stPUIRpwg4GjcgxR/hQCA0/VP8GyQL9vv4Eu+l0rv0yQ== X-Received: by 2002:a63:cf09:: with SMTP id j9-v6mr10312857pgg.195.1536359628472; Fri, 07 Sep 2018 15:33:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZbJPea9x+ZfW6QF+wee7ig2E8F2J8XTNueuOHgfkBRcuX9m6+BAZhZ044/AX7ONkV7JsZm X-Received: by 2002:a63:cf09:: with SMTP id j9-v6mr10312820pgg.195.1536359627630; Fri, 07 Sep 2018 15:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536359627; cv=none; d=google.com; s=arc-20160816; b=M+bjLSS1lnpoCYetvqUDvDie6+4w2wOjMOrfE966lIpHLudx5I93lBm7Sx7JGFkKW+ Yw211porr7bR5rCH8CiP720HIVkabppSCVt2Gapc6lEDyQi/Dad6PDpkYPkywCLiOhPK 0LQLHsU2hOquvQs5uSLJ+o8fcXKs08BMyCuNf2PxRv9dWPeUBSGC3EI2rQj2ePxatHIw LvsapAmhPDHPnKsNq/Yko0QUN2H4qOTnDnJYMY4MWV1jDhYc014P5/shmcMPjdRCn46X XTWknVj0cxlTci1Dyj07zcrU1rUuV1t9M69jWGyEd75XWEW1tJrANNwd1OTvbPgo8hTo w7Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date; bh=ExhzVHsdv6lfoeuwhbFclEbkpbsJl6iiiRC3ImFe1Ec=; b=TmfmVQxD6xTvrTJlrAcM69b8qwrEx2Iky6eGMpyNngbtASpCO4sKUMvdTTnf5Q8VDX cfjcAf+sDR31IIQ+qN1edvTwNRxT+fk3uBssXA8OJVEDAtmYsJ7edb7ka2XGX2AIN96r sPuxOOa2Aa3jOVa5QziP4WXzVNMKxycY7SDtCNvMkC0XD3fnhXz7LzZSfXxnQdqIZ4kv DIahJQVdoLuFOALH+veF58LR5RCgEDh3GtdOsoc1ur5p2Tq2xZNXZ4W9iqt3HTf0HPaA werHr37ZeO6FwVdwhV34E5rR5zn20/bQyUZy5gwebCOz4tQfZ4IYEOqKYlefd/ZKodPF 4UYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga04.intel.com (mga04.intel.com. [192.55.52.120]) by mx.google.com with ESMTPS id m28-v6si9146359pgd.358.2018.09.07.15.33.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 15:33:47 -0700 (PDT) Received-SPF: pass (google.com: domain of alison.schofield@intel.com designates 192.55.52.120 as permitted sender) client-ip=192.55.52.120; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Sep 2018 15:33:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,344,1531810800"; d="scan'208";a="261683969" Received: from alison-desk.jf.intel.com ([10.54.74.53]) by fmsmga006.fm.intel.com with ESMTP; 07 Sep 2018 15:33:44 -0700 Date: Fri, 7 Sep 2018 15:34:26 -0700 From: Alison Schofield To: dhowells@redhat.com, tglx@linutronix.de Cc: Kai Huang , Jun Nakajima , Kirill Shutemov , Dave Hansen , Jarkko Sakkinen , jmorris@namei.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, linux-mm@kvack.org Subject: [RFC 02/12] mm: Generalize the mprotect implementation to support extensions Message-ID: <2dcbb08ed8804e02538a73ee05a4283c54180e36.1536356108.git.alison.schofield@intel.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Today mprotect is implemented to support legacy mprotect behavior plus an extension for memory protection keys. Make it more generic so that it can support additional extensions in the future. This is done is preparation for adding a new system call for memory encyption keys. The intent is that the new encrypted mprotect will be another extension to legacy mprotect. Signed-off-by: Alison Schofield --- mm/mprotect.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index 68dc476310c0..56e64ef7931e 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -35,6 +35,8 @@ #include "internal.h" +#define NO_PKEY -1 + static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, unsigned long end, pgprot_t newprot, int dirty_accountable, int prot_numa) @@ -402,9 +404,9 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, } /* - * pkey==-1 when doing a legacy mprotect() + * When pkey==NO_PKEY we get legacy mprotect behavior here. */ -static int do_mprotect_pkey(unsigned long start, size_t len, +static int do_mprotect_ext(unsigned long start, size_t len, unsigned long prot, int pkey) { unsigned long nstart, end, tmp, reqprot; @@ -528,7 +530,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, unsigned long, prot) { - return do_mprotect_pkey(start, len, prot, -1); + return do_mprotect_ext(start, len, prot, NO_PKEY); } #ifdef CONFIG_ARCH_HAS_PKEYS @@ -536,7 +538,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, SYSCALL_DEFINE4(pkey_mprotect, unsigned long, start, size_t, len, unsigned long, prot, int, pkey) { - return do_mprotect_pkey(start, len, prot, pkey); + return do_mprotect_ext(start, len, prot, pkey); } SYSCALL_DEFINE2(pkey_alloc, unsigned long, flags, unsigned long, init_val)