Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5289377yba; Wed, 8 May 2019 10:44:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6ASpO3vSZiYDsgFczZamrDPhn+nk/Wd3ErcsyA4wHAavhta7/Z+QY+if4hDRG+xFEWgVk X-Received: by 2002:a62:4607:: with SMTP id t7mr51398888pfa.138.1557337482578; Wed, 08 May 2019 10:44:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557337482; cv=none; d=google.com; s=arc-20160816; b=S7gYsYPKT0ZeSsvt3aR60TRdUtmRM3C4l8RXtWPnchuUHo6g9vwMPWB7qwB/syEIzf 3ztwjAVc3sRuDyZtQml+L65u+O4fQ/xYd/Hr4KR97IjlDtix35MgH2EyOQ4tdJtkqA3F bWSSzk6eumhHpLczKvi9w3x2q4HGw10sjwAo+YwQi4IORiZJx8YKw1Sb84V1nq9aLFWY oBx8WJoah1h0V4aIA4SC+QgW+yETwj/7GrkhvqGQW/YNoddZtFv3fMcCs79jwDcOUFkp eB3NboKu15aUunfjIwBGicGtaWWuhVrsjLllOSnHOwKvERmNRYQcsCOFYRrLsmXljW0T g+Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=63N4Scvmymr/HxGljrqFhwEljj66qpjYxN4DGuSs010=; b=qhOwb/wR5hh5wFSz7YRvRo8EbSvYlg1q8O4HSflDSVp90Wtu2xTUmDEaeXRnJ2qgeo niu2BS5Lqe2TOqmw2MIqbTyi/frX+Jlz0HJZhygQWceALTZO8U5ntcp1glZ531dkk0ZT hh/YM3MJITKICaFpdOXu2dhVuYekHGIvKiyfosuHumy3YTkYKGya+cViHuvxFnYeyayM tz93bp4mXAQXhDcjSCLmEPopMrH7e32wPus87QTwNUYaDjjPIf2szi1FzQFMyJ2DkBLs 14WCYr2VqhO/IlQY6tHmohS0J9Dgjf/vZ/gWPp7Slkzg4SQzjzAxIyY0EaC/N5Cw2zk3 kWyQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si23251479pgu.572.2019.05.08.10.44.26; Wed, 08 May 2019 10:44:42 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727859AbfEHOsm (ORCPT + 99 others); Wed, 8 May 2019 10:48:42 -0400 Received: from mga09.intel.com ([134.134.136.24]:1393 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728413AbfEHOot (ORCPT ); Wed, 8 May 2019 10:44:49 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 May 2019 07:44:49 -0700 X-ExtLoop1: 1 Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 08 May 2019 07:44:44 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id CCCC7D8A; Wed, 8 May 2019 17:44:30 +0300 (EEST) From: "Kirill A. Shutemov" To: Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , David Howells Cc: Kees Cook , Dave Hansen , Kai Huang , Jacob Pan , Alison Schofield , linux-mm@kvack.org, kvm@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" Subject: [PATCH, RFC 42/62] mm: Generalize the mprotect implementation to support extensions Date: Wed, 8 May 2019 17:44:02 +0300 Message-Id: <20190508144422.13171-43-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> References: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alison Schofield 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 Signed-off-by: Kirill A. Shutemov --- mm/mprotect.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index e768cd656a48..23e680f4b1d5 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -35,6 +35,8 @@ #include "internal.h" +#define NO_KEY -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) @@ -452,9 +454,9 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, } /* - * pkey==-1 when doing a legacy mprotect() + * When pkey==NO_KEY 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; @@ -578,7 +580,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_KEY); } #ifdef CONFIG_ARCH_HAS_PKEYS @@ -586,7 +588,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) -- 2.20.1