Received: by 10.213.65.68 with SMTP id h4csp162468imn; Mon, 26 Mar 2018 18:05:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+6KaBxKgeapHMYUnR2hHQF6n7zapWZFh8QXQAb17a0MPngW3I6sfNeXsATuRMZ3JOSvO4e X-Received: by 2002:a17:902:778b:: with SMTP id o11-v6mr202481pll.106.1522112722173; Mon, 26 Mar 2018 18:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522112722; cv=none; d=google.com; s=arc-20160816; b=qZu1FYggPSGHOuPkHBz9mWroIVZIjRe0ZknJWORFSVHxM5rB5VJRbo5XG7tnRD/j+R gu8jiQmwxqJS2/R1urjv+Fez2/lhBFAHh++9umBQzVP2t7rJsaugN7dCcoEzandEjOlD iqHeF6cCO0ro3rYYktkEAZjo1lX/dJEgcqhPyIbfecTVyu8YJURJeniy9mD5DaKBcBSy xlDXqMOCzx7AiQquw5XjRwIS22KUrxVIoM4mwz9ybKpEbm8hB6Mz6k/geKSJNhyJyZ+F w+R8fxDOfsoz6wWlSjuFRwpchPt58XkzkJV2DyTd4szNYWdOUtG7vTsPTISzlbsdCXK4 GbNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date:arc-authentication-results; bh=MOo738I6c1mMhFoMWsEcZpofj5c8K80dpPH1t07rUXY=; b=IqYSs7fmKZ9Qy7ZxC9YN4IJNjd64aZO0iCQJ+QhKgvVuyhEPjmUmbWWNU2cHgJ4v5E bKa3hgo1xZ7642VNcsQMVFpt87rkLHV63g8ISx5irpsL7fFkB/vnom1j/+t6Wqsxsat7 x6FHrfiUpz/w2XXLZbpmCl0gSjT/ThAOTaxcXFmXTP/jYvB0nww5jc7s/PlpcWaaIBw8 87CHfbXwt+FT3BXIY7yB7sMM0SPXm7FPR0a9xTlMliPKQR/YBcG3AUaXYwwdIwBH2kUd 6YEHWWk298Fz40l4cA7aIXgN+LIYFivQgwk0w+02Gs6mkXiKE5/KCncHk9M/IP3I19in FYkg== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si55067pfa.103.2018.03.26.18.05.08; Mon, 26 Mar 2018 18:05:22 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752180AbeC0BEK (ORCPT + 99 others); Mon, 26 Mar 2018 21:04:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:45268 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751866AbeC0BEI (ORCPT ); Mon, 26 Mar 2018 21:04:08 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2R14231106304 for ; Mon, 26 Mar 2018 21:04:08 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gy868far8-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 26 Mar 2018 21:04:07 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 27 Mar 2018 02:04:05 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 27 Mar 2018 02:04:00 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2R140JA8520116; Tue, 27 Mar 2018 01:04:00 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 12F5111C04A; Tue, 27 Mar 2018 01:56:25 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A03C611C058; Tue, 27 Mar 2018 01:56:21 +0100 (BST) Received: from ram.oc3035372033.ibm.com (unknown [9.85.192.202]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 27 Mar 2018 01:56:21 +0100 (BST) Date: Mon, 26 Mar 2018 18:03:53 -0700 From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, fweimer@redhat.com, msuchanek@suse.com, tglx@linutronix.de, shuah@kernel.org Subject: Re: [PATCH] powerpc, pkey: make protection key 0 less special Reply-To: Ram Pai References: <1522107101-16083-1-git-send-email-linuxram@us.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1522107101-16083-1-git-send-email-linuxram@us.ibm.com> User-Agent: Mutt/1.5.20 (2009-12-10) X-TM-AS-GCONF: 00 x-cbid: 18032701-0040-0000-0000-0000042735FC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032701-0041-0000-0000-0000262A4BD4 Message-Id: <20180327010353.GC5743@ram.oc3035372033.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-26_11:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803270010 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 26, 2018 at 04:31:41PM -0700, Ram Pai wrote: > 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. > > Lets make pkey-0 less special and treat it almost like any other key. > Thus it can be explicitly associated with any address range, and can be > freed. This gives the application more flexibility and power. The > ability to free pkey-0 must be used responsibily, since pkey-0 is > associated with almost all address-range by default. > > Even with this change pkey-0 continues to be slightly more special > from the following point of view. > (a) it is implicitly allocated. > (b) it is the default key assigned to any address-range. > > Tested on powerpc. This patch is not entirely correct. > > cc: Thomas Gleixner > cc: Dave Hansen > cc: Michael Ellermen > cc: Ingo Molnar > cc: Andrew Morton > Signed-off-by: Ram Pai > --- > arch/powerpc/include/asm/pkeys.h | 24 ++++++++++++++++++++---- > 1 file changed, 20 insertions(+), 4 deletions(-) > > diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h > index 0409c80..9c7d3bd 100644 > --- a/arch/powerpc/include/asm/pkeys.h > +++ b/arch/powerpc/include/asm/pkeys.h > @@ -101,10 +101,18 @@ static inline u16 pte_to_pkey_bits(u64 pteflags) > > static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) > { > - /* A reserved key is never considered as 'explicitly allocated' */ > - return ((pkey < arch_max_pkey()) && > - !__mm_pkey_is_reserved(pkey) && > - __mm_pkey_is_allocated(mm, pkey)); > + /* pkey 0 is allocated by default. */ > + if (!pkey) > + return true; This is wrong. pkey-0 should not be treated any special here. Will fix this and send a new patch. Sorry for the noise. RP