From patchwork Wed Mar 14 07:46:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 885632 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 401P5q1BGdz9sV5 for ; Wed, 14 Mar 2018 18:50:23 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fpxzn5nF"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 401P5p6p53zF0gL for ; Wed, 14 Mar 2018 18:50:22 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fpxzn5nF"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c0d::244; helo=mail-qt0-x244.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fpxzn5nF"; dkim-atps=neutral Received: from mail-qt0-x244.google.com (mail-qt0-x244.google.com [IPv6:2607:f8b0:400d:c0d::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 401P2K1W74zF0p6 for ; Wed, 14 Mar 2018 18:47:20 +1100 (AEDT) Received: by mail-qt0-x244.google.com with SMTP id v90so2428549qte.12 for ; Wed, 14 Mar 2018 00:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=ngFyGJnwOFPZCWa0js0poPFjJELbkUl51nN6Yfm2ioc=; b=fpxzn5nFgcfkx4tI+3iDF5izlQuBBZhbZJtjrXWoT5Y5jv3RPvnTM0HlXiy877v+x5 H4ailFMGWmcEybOvS7ntzFPvNIo4VbVK6afAactm/MQ+ry9v4RTpTVKBHoP9lOhkQUwU sImwZOv/IBV5SPFZ7gT9nn7NXgFI+fEnooXgATzSByMzwGVwZJoDx533sh0uDAt3k73H Q3woqjuQ96UKrld5KPSiRhh+8U4RwukZ/RBXgL5hFH2wpyfkCMd9jmSk2vTz7EFH61QH /nxy17Dn1XLEylhgYTgXXYd+slvgIaRF1/toUN6RilPi6Tav6+u6FhreJkGfIoLHXo0z 8N8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=ngFyGJnwOFPZCWa0js0poPFjJELbkUl51nN6Yfm2ioc=; b=SUYn1/ImVUX6e8ldCtx4d7gi5sAjC4Kf+ZH08syyvOqVUjiwogYsKMrvfE2+rSquVE h/mOE8Ni4gVtuWZRFu098F3NvLd0p7zNL2zWIjMblQQgsnrYtQtXHNHprVqzVnXqY0Md oDqjTKq1/Hv4X0yUTRSly+yl4UzmJHg0P8/PLVcI9sg54KAiuKt9FEGGq+uwd7J9PwRJ zl/f0puze5oGnWGcPBHtuBFvDKLCnABsXtM30RG5WPPTnXcyai6A4I0Nt8xUnpr1HLwV LCmuwz2CzrXtNvxRHtQ8+rQUeAzB2KsUKM2Ez7lXVg2abwhCWREsBVKx0xUpWEKkU16y HGYA== X-Gm-Message-State: AElRT7En6keiMLjcQdJ+A8vNzK9x7DLR/V87ROb6q/D+WnwO6LeCmA3O iMX/6RtMuEZxxl984MfMy8s= X-Google-Smtp-Source: AG47ELsoBzFcDXZJnG5BGc/ARpXdzjpMkZeV4MCa1AZ95kANP82Wj+Ccj4cGsGRvrbhsDI/fVu6mIA== X-Received: by 10.237.62.130 with SMTP id n2mr5729424qtf.81.1521013639082; Wed, 14 Mar 2018 00:47:19 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id s186sm1119918qkf.70.2018.03.14.00.47.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 00:47:18 -0700 (PDT) From: Ram Pai To: mingo@redhat.com Subject: [PATCH 1/1 v2] x86: pkey-mprotect must allow pkey-0 Date: Wed, 14 Mar 2018 00:46:14 -0700 Message-Id: <1521013574-27041-1-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: msuchanek@suse.com, linuxram@us.ibm.com, mhocko@kernel.org, dave.hansen@intel.com, paulus@samba.org, khandual@linux.vnet.ibm.com, linux-arch@vger.kernel.org, corbet@lwn.net, x86@kernel.org, bauerman@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, arnd@arndb.de, fweimer@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, ebiederm@xmission.com, akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Once an address range is associated with an allocated pkey, it cannot be reverted back to key-0. There is no valid reason for the above behavior. On the contrary applications need the ability to do so. The patch relaxes the restriction. Tested on x86_64. cc: Dave Hansen cc: Michael Ellermen cc: Ingo Molnar Signed-off-by: Ram Pai --- arch/x86/include/asm/pkeys.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index a0ba1ff..6ea7486 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -52,7 +52,7 @@ bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) * from pkey_alloc(). pkey 0 is special, and never * returned from pkey_alloc(). */ - if (pkey <= 0) + if (pkey < 0) return false; if (pkey >= arch_max_pkey()) return false; @@ -92,7 +92,8 @@ int mm_pkey_alloc(struct mm_struct *mm) static inline int mm_pkey_free(struct mm_struct *mm, int pkey) { - if (!mm_pkey_is_allocated(mm, pkey)) + /* pkey 0 is special and can never be freed */ + if (!pkey || !mm_pkey_is_allocated(mm, pkey)) return -EINVAL; mm_set_pkey_free(mm, pkey);