Received: by 10.213.65.68 with SMTP id h4csp825308imn; Wed, 14 Mar 2018 00:48:27 -0700 (PDT) X-Google-Smtp-Source: AG47ELs0gRgmcTw3eUDYRRGI4eVytaK6ELv5qgVMsnm0Fa3++buMj3hu+y8X8jf8AXP1eqJayhVm X-Received: by 10.99.7.76 with SMTP id 73mr2943593pgh.349.1521013707533; Wed, 14 Mar 2018 00:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521013707; cv=none; d=google.com; s=arc-20160816; b=XwiXE3f5tqmKI1TBjIXSvubNwv/cWT1CMTbRwpTsf1PhC+GwtuhygkDTBEDWDo8Mpt 2R/6gynZiJMWnbRvyPbsMtkILDKIULTXojU02AuEclyf4xzj0eQNLf92W/llp7x9U3l0 8EU5UocRV3yQ4RgF59iSdtxtQl72ewF2rNHnshPJVYd5LTJvLhjcgB337a/+BA1f0AyA Uth7ND5fZrJ/tdSeHLkmI6WCPhjYUj25SAnJawJ4LW+BTdT3H1kNnP6YsYMe54ukvcOX ncsuMdqG3ZKAYVylcoK1jV0Oc1WgBQ6Vp8EuhWJNGcH1SGfYAjnkJK1Yw2998jaUozFV VZDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ngFyGJnwOFPZCWa0js0poPFjJELbkUl51nN6Yfm2ioc=; b=Quzmrqy9VJTCzIEZ0UVFPO31VF2ugJIlJVXm5Qq0K+oG/GFDzwg299an7FjC4SIs1D +HSDumFLDVbVGjhy2JtNtOFucADYTnpgjLX0q/IK1AfVMahafgbThLa+A6B0sGbnfaEb d2/fwl8Z7dTBxYGMe7xxSFaSGcrkIBj+qBM4dOPtIApXUKkKofD+ELVlmQisfEb/p36Y +/bLTAzwKjFR9EFpS5rCVun1Ax8QHNir5OpzAcj+xxeV2lKPxSMO6CeSgF3vHEW3TFwh HCHbwQpOH75GULxvnnfnETeSn0NN+5bW3oiq16cDoyBw2studGW/zJyK3I9CBzaJBQc9 1VeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fpxzn5nF; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b35-v6si1583974plh.84.2018.03.14.00.48.13; Wed, 14 Mar 2018 00:48: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=@gmail.com header.s=20161025 header.b=fpxzn5nF; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753391AbeCNHrV (ORCPT + 99 others); Wed, 14 Mar 2018 03:47:21 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:40342 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753219AbeCNHrT (ORCPT ); Wed, 14 Mar 2018 03:47:19 -0400 Received: by mail-qt0-f194.google.com with SMTP id y6so2459743qtm.7; Wed, 14 Mar 2018 00:47:19 -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=DxNQ2T8bgadCOHeUl65XYUm78bauwbM0HIXSv1k+sNlmAxYPAAbLZ3ybUXlz7MEC32 i1q0UrqCuZUMi09dNu5k7vpvZ9xCtkYadTkdp1FdwW9DdN4fuBfJ/60xlf/VAfjqZvSc rzEG9BeAg47cZILlnYqyfbh2VEZ+1rJnByVv56ScyKvKiGOiYEoAlK8t87219g3GDC/V pWfAdGiOeSJDoJhnefXL4G0iHveARIwi2XvL99KNzun4/qEgdw1ELopfd2e+OVkhtLrq vNI6BC1dd74eSJslE2kapGOLBjUSxNIGQk81/AD2zRz9f4pP1PK+/pB+LtZ27JLIAFrY UjLw== X-Gm-Message-State: AElRT7EEoi7dtxyjbgWiifDK8Hkagpus6gkVGjOw2pts3fv9Uq1PNxZB lPwslLYD0pgGUszyRxvspvs= 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 Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com, corbet@lwn.net, arnd@arndb.de, fweimer@redhat.com, msuchanek@suse.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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 1.8.3.1