Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6110848ybi; Wed, 31 Jul 2019 08:30:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfCtG0mGifOaUpuRrqurhADmZunG+miCZhFUblvqSqsvDUklJLmAtYmyDHTtexVhGCp6Ae X-Received: by 2002:a63:db47:: with SMTP id x7mr113822733pgi.375.1564587052446; Wed, 31 Jul 2019 08:30:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564587052; cv=none; d=google.com; s=arc-20160816; b=EE+ka69/lJG1B8lQfI5JOGs8FiLSx3gbq26RpHNph4l1xa8cJwOwA3CRGWGEpWDAqe my6W7Z1MrzRW7XmKZooFaOxi0Y0Tz4KgBQnwN/Q0VBf3k7SKSV4DBqcFOxS0nU6KkoPw GznJoFwO1WlnutHUkOfrCw+bZqh9lzFlh+yCjUJbuEKbLCKWXZyJsTBv/xd30Xi3DiMX D3/5bnYVt1H0PV1Lklw4W58JfGi6gLzJSQOcWd7VdxZD1V9SaJYeThGsQJz7wSGtjRst zK80Qf91ySB03YqnLK83a7PnV+3BI8ioRkW+MFi3qtxAxsutZvLHEX+zb09vFHGvJ/Sb 62mQ== 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 :dkim-signature; bh=Qu4eqa88cl7hA3fQdb28KWqV5w4hCLiKuLbYR7iJuDE=; b=O1eL33U7nj+0zjYkG+gJBjvkcETbX4OS67N3s/1Um5+7YHperqCh36AyVnyJgGxnNj saQdrrepxlmVCe+ucoJY1SZNo5HRHyjISZpazCg/cdP0UK8O8tnnZB/omG6KYcg1KM/o 0LtghospF/0CiLM2D1BqQWbixxFLEV4Ms3Ug/vDdtz+rNj+7aQ4FpmI5F6ThA8n9akNu ruRUUIN8pPOmoD2itgLahgUrHbpPyc3vSbZ40V3noY0UgGPWNdNxt5Q8eAv3O+KrxuZK 3v2InPvmRTardsrnouqyWlwUcWvD5ekfX7m9Xc6qiJSIa4AT042iMxV+QQEvLbVY+rCa yGug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=EapzB6nV; 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 a15si34420576pfi.48.2019.07.31.08.30.37; Wed, 31 Jul 2019 08:30:52 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=EapzB6nV; 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 S1730172AbfGaPWM (ORCPT + 99 others); Wed, 31 Jul 2019 11:22:12 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:43657 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727628AbfGaPWL (ORCPT ); Wed, 31 Jul 2019 11:22:11 -0400 Received: by mail-ed1-f67.google.com with SMTP id e3so66073142edr.10 for ; Wed, 31 Jul 2019 08:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qu4eqa88cl7hA3fQdb28KWqV5w4hCLiKuLbYR7iJuDE=; b=EapzB6nV2zuG3XXqORhtOg865rDFWXiiuUO8FpJLb/h1WDao3VpOzWeFDmaFbxm/XL 47TBQ8nUUTf9qkmZiYlrYuMBsFG5TIn6RKRtGHhdoEi679Dd/WD/MF4HtnmQP59r+ZVS lWZPfIfuMFEgQo4Y3mbUEU6Vw4ZKVnL+c9FxScjZKMpMrPiR+cuZijKKGYKRXfElKJqa Xlf/ibW3jXNNJBvLlFTHpGgT5lOrKP+W2Zir2emFXNHQgTL1ugZEAXaNqYvDXjvvf1sY eVxqaYVdOcCPAQPOF9hrrzA0BOHPgcYf40DmCzESR4BUuRMyXnjNV9lnjdj/b1tOOPp+ BzBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qu4eqa88cl7hA3fQdb28KWqV5w4hCLiKuLbYR7iJuDE=; b=Msp8GkuyxvFwCRz31JCyXf24zrUn4OzcF1Prb3HLShvtSKT1MuRIJ58WfacAN5Qhj3 kaaccAuI1YkzUiOSXxSv5LXEjvI9BmR10yvK3wmOMyECcXxyHLBK6w4nFwhBxq0hTaq4 jBOddu/KuDlTIu/dEvh91pMzAjszzgh8p5H2EVjMCyml84/ZbvcZOg72Cfzb06bxFQJP +Kk3UEEdyOfI/QHloG2J02jBKwQJDkChdGkptSLKUSZPgXgNng74YCAanoHk6dtyKYq1 HTy0iHg5SsQ4VcrR3uCIaa+epkRWAJpWmKIwWeKIcpnno3CH/EMSsXpIQNOxHw7XQMzF aRKQ== X-Gm-Message-State: APjAAAV+RX5fAO2QOt5jv3rcRaltlfn/dVovG6c9nb4zklh9ZEi6gcni h/LNl0c9WiM8mYU5dzgVOGk= X-Received: by 2002:a50:acc6:: with SMTP id x64mr110288029edc.100.1564586034088; Wed, 31 Jul 2019 08:13:54 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id oe21sm11729742ejb.44.2019.07.31.08.13.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 08:13:52 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 172081045FF; Wed, 31 Jul 2019 18:08:17 +0300 (+03) 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: [PATCHv2 41/59] mm: Generalize the mprotect implementation to support extensions Date: Wed, 31 Jul 2019 18:07:55 +0300 Message-Id: <20190731150813.26289-42-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> References: <20190731150813.26289-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 82d7b194a918..4d55725228e3 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) @@ -453,9 +455,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; @@ -579,7 +581,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 @@ -587,7 +589,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.21.0