Received: by 10.213.65.68 with SMTP id h4csp1241872imn; Wed, 14 Mar 2018 14:02:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELv0tvOMHh6nqclgeIBIydiX1msvVbnjnr8GmTJugiTcQjjR/bU0G71aHNgTolLba3b8WnLm X-Received: by 2002:a17:902:b185:: with SMTP id s5-v6mr5260956plr.109.1521061375787; Wed, 14 Mar 2018 14:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521061375; cv=none; d=google.com; s=arc-20160816; b=CN7bDCdWKflBIlu4MKyLDF2Kx0wPHihY1RlWKYY5KeYOmakQuc3/HRg8GTUUrYYOqS P/aV3ej7nq/gCCV8y0PZLwvEFIOiSYP6+184raBvCNx+/GobkZyjYPvMvNMu0PQdWe0D FM0UzpByeHhbGhSTeaE41CV28C3GeEKrC03gpUooUhs2Pxfw5qjm7PXdak3tZLEWCHxU 2hhJaTbqXq3LKuEaFm1WrsCbseq5r3LOjC8rQhgE7pVgcyYBtf3YypU84YMB9H+zmPiD bdO3LsGUx0EI7psfbfIbCWIt3lxX0i61w8qSx+Q4S/30wIpjF/b1G6MQgjBDLVSJc5Rs 7g+Q== 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=f0dHZRoaagEUh0CZPWTpbjHpvyUCHhnIcOhdExaJp7g=; b=OVO6lKk8IccHz4+CuhZLc24iGkWd9ot1QuqcfwXTLfDsOhDgozhk9ouKhdvX3dKqlM UzDgK27xaCXR00bp76csXCZwJWwjQmmfsPXEmvcZNWNFR+Sxt8wSHt/fgoHVM3bf1UdL duXN0w7tg2/pdu1mwD2qjkmYz/uKqJxzMD53zdgnpiFLldgbGcOVN1I4BJycycAqQiWQ Bb+GmJevX/TXC5rpjYY6xRRXOOP9tmGdU/HyQ19/AFk1QNV/CVtr6oiK/fN0hFdO2zil SdLK/U2J7qQS4gwBpwBUer+XHO3njp+re4Q7SCofzNzj3v2VznIZnf67/fTJaETbEGpV eVeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SIXTDmVz; 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 n11si2378119pgq.439.2018.03.14.14.02.41; Wed, 14 Mar 2018 14:02:55 -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=SIXTDmVz; 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 S1752355AbeCNVBB (ORCPT + 99 others); Wed, 14 Mar 2018 17:01:01 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:45931 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003AbeCNVA4 (ORCPT ); Wed, 14 Mar 2018 17:00:56 -0400 Received: by mail-qt0-f196.google.com with SMTP id v90so4989955qte.12; Wed, 14 Mar 2018 14:00:56 -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=f0dHZRoaagEUh0CZPWTpbjHpvyUCHhnIcOhdExaJp7g=; b=SIXTDmVzya4RWp3JJ8lTIKDLwMNyfQSHDntutkWBlgAswHUpElNN5ZCqXil6A8+hCa KVwxu9hn9FhhgeMgBYCPeZjcDiteSovtf08LfPz2OvDTnyDL201xYNz0PxKjHCqbhYq2 ikM0LAEhUYlEA+4WT7BxmE8AqWuhaS10VszhAQZgnwzetaB7/dFWsHz4I7UYNdmOFbII kSZ/oQH9jml5GtjtRqgYSRHrcFEsxQsJ9hg3iXE86SYAZWfLBjjRd50+cH/2uf1XVqgt pHZ7pDfo0TCOdP9iP7M3mojeJyQhmf5VF2QAQ594UuMrKgAjf/9QE3MFtRLxxZjMi7y1 2SEA== 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=f0dHZRoaagEUh0CZPWTpbjHpvyUCHhnIcOhdExaJp7g=; b=Xe5DAoTn7u7GVtwJlIHOuvJX7onMCd9jQykhLRUvumattxj2Kk7QioTNxa4hBFQ0aN nvHuZ1y4sfeCE8VlB2T3MYz/Y/Py3Ttcx3uNsyk4MFQxiYN8Kl0+YyV5+M7Q87cO82Gk zEBB3RsDOLfJGSTtjq9tHX187pFA8ax5PGCUjMt0L2l6N7TmNE+jDwCb9RpCXdm2VBgO 5IVC+nAt7v3axV4TYQOTknOMRodb1OWKEj09Lh2Xdxa+rGRGDrf39gcsLfDQ6R85LgEj iSOzXLRXRphvmuT6SALUtT5bmUzItUCJgdqJPD92Zd9BsrqyPExXy10zRYE5QOgLnCBo +noQ== X-Gm-Message-State: AElRT7F3mEeNva1F/qB7qyfDp/q/mWzDrYrB6YDmQ339uQCxsn82+Njt iFy9Sejo9/wd+mv6PgWhpkQ= X-Received: by 10.200.4.9 with SMTP id v9mr9013683qtg.69.1521061256095; Wed, 14 Mar 2018 14:00:56 -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 21sm2225509qkk.10.2018.03.14.14.00.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 14:00:55 -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, Ulrich.Weigand@de.ibm.com Subject: [PATCH v3] x86: treat pkey-0 special Date: Wed, 14 Mar 2018 14:00:14 -0700 Message-Id: <1521061214-22385-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 Applications need the ability to associate an address-range with some key and latter revert to its initial default key. Pkey-0 comes close to providing this function but falls short, because the current implementation disallows applications to explicitly associate pkey-0 to the address range. This patch clarifies the semantics of pkey-0 and provides the corresponding implementation on powerpc. Pkey-0 is special with the following semantics. (a) it is implicitly allocated and can never be freed. It always exists. (b) it is the default key assigned to any address-range. (c) it can be explicitly associated with any address-range. Tested on x86_64. History: v3 : added clarification of the semantics of pkey0. -- suggested by Dave Hansen v2 : split the patch into two, one for x86 and one for powerpc -- suggested by Michael Ellermen 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