Received: by 10.213.65.68 with SMTP id h4csp1599630imn; Mon, 26 Mar 2018 10:36:56 -0700 (PDT) X-Google-Smtp-Source: AG47ELt4rJmS+lD4KUg4x0wj+DcV3f3ShlmbDvQDdNhEuLHp5wMcRLxyrFh8E9fxoKGOp5Lt5Gfl X-Received: by 10.98.62.71 with SMTP id l68mr29436934pfa.98.1522085816760; Mon, 26 Mar 2018 10:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522085816; cv=none; d=google.com; s=arc-20160816; b=Ea4Bqi+9sek6C01nw/UUgg+girUW2Cectcp+vWAYLapZieW9ocJBfHOhkEzaOwT+/2 Bsl3Q+8FIvXUe1+2lJNVZEPUgURrIUudRNBzwB72TgCoxukies+CCsTn8xkDvl0YPbng LMYCCljNOFV5200e7b60tuZNG7awd4qc5md0raFp0Uxz5eYlDZsPg2gfQ+bKNvr1TuQR fz8w5aCotLyceQmIUkXNn2d2wd7pggUxy+cwqqyA8wvc8bac9FRgRe0Hot64wP7k1mNB VhTVZKgF7GjKvC1WqQ5FAKCvu1qsJrUTwXwfAGvKoox5jFyr4U/zv8xNcXdLAOfTq9f9 B/Ow== 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=Atf3PNKRFJsqLQvPfYikCvxq94Vrh1U33lWjnp9WxTA=; b=fr3eW2GXvpb2LWgCBCx5cFK0AiPr0GG8pELPpaID4SuZEncLsv2CSjIJLbMgF2IG4Q aAnV7JaXjJG3vrA/oA8PcVcSG9275ZrnwZO/MWIV+D5uXM1TJL7FS9XSqZgSH+po3irJ FzN8hg0Eg2A/ZmplCASTGW9N33vtz6s0+clNllwANhBxHOPQzpTy0bRxAdzr6TmULLNU Te/30mblbfD8CsaV8Z3x4H98MOFSnQfin1Dqb+P2/5VSmfrrzSsQV8D3cNFeE63qmOKD V53fl1k7pKRHjgTwDMc87Ir4EKu8WnSBpU/cnRK0LHR8hZA255a2cVKOxuwevYPrLUQn zdfw== 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 b80si9135522pfj.134.2018.03.26.10.36.41; Mon, 26 Mar 2018 10:36:56 -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 S1752644AbeCZRfi (ORCPT + 99 others); Mon, 26 Mar 2018 13:35:38 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35632 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751684AbeCZRfh (ORCPT ); Mon, 26 Mar 2018 13:35:37 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2QHUn6t123574 for ; Mon, 26 Mar 2018 13:35:37 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gy1thaynq-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 26 Mar 2018 13:35:36 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Mar 2018 18:35:32 +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; Mon, 26 Mar 2018 18:35:28 +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 w2QHZRG944695632; Mon, 26 Mar 2018 17:35:27 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E551F11C04A; Mon, 26 Mar 2018 18:27:52 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E04911C054; Mon, 26 Mar 2018 18:27:51 +0100 (BST) Received: from ram.oc3035372033.ibm.com (unknown [9.85.192.202]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 26 Mar 2018 18:27:50 +0100 (BST) Date: Mon, 26 Mar 2018 10:35:23 -0700 From: Ram Pai To: Dave Hansen Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, tglx@linutronix.de, dave.hansen@intel.com, mpe@ellerman.id.au, mingo@kernel.org, akpm@linux-foundation.org, shuah@kernel.org Subject: Re: [PATCH 1/9] x86, pkeys: do not special case protection key 0 Reply-To: Ram Pai References: <20180323180903.33B17168@viggo.jf.intel.com> <20180323180905.B40984E6@viggo.jf.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180323180905.B40984E6@viggo.jf.intel.com> User-Agent: Mutt/1.5.20 (2009-12-10) X-TM-AS-GCONF: 00 x-cbid: 18032617-0040-0000-0000-000004271CAD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032617-0041-0000-0000-0000262A31C9 Message-Id: <20180326173522.GB5743@ram.oc3035372033.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-26_08:,, 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=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803260180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 23, 2018 at 11:09:05AM -0700, Dave Hansen wrote: > > From: Dave Hansen > > mm_pkey_is_allocated() treats pkey 0 as unallocated. That is > inconsistent with the manpages, and also inconsistent with > mm->context.pkey_allocation_map. Stop special casing it and only > disallow values that are actually bad (< 0). > > The end-user visible effect of this is that you can now use > mprotect_pkey() to set pkey=0. > > This is a bit nicer than what Ram proposed because it is simpler > and removes special-casing for pkey 0. On the other hand, it does > allow applciations to pkey_free() pkey-0, but that's just a silly > thing to do, so we are not going to protect against it. > > Signed-off-by: Dave Hansen > Cc: Ram Pai > Cc: Thomas Gleixner > Cc: Dave Hansen > Cc: Michael Ellermen > Cc: Ingo Molnar > Cc: Andrew Morton p > Cc: Shuah Khan > --- > > b/arch/x86/include/asm/mmu_context.h | 2 +- > b/arch/x86/include/asm/pkeys.h | 6 +++--- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff -puN arch/x86/include/asm/mmu_context.h~x86-pkey-0-default-allocated arch/x86/include/asm/mmu_context.h > --- a/arch/x86/include/asm/mmu_context.h~x86-pkey-0-default-allocated 2018-03-21 15:47:48.182198927 -0700 > +++ b/arch/x86/include/asm/mmu_context.h 2018-03-21 15:47:48.187198927 -0700 > @@ -192,7 +192,7 @@ static inline int init_new_context(struc > > #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS > if (cpu_feature_enabled(X86_FEATURE_OSPKE)) { > - /* pkey 0 is the default and always allocated */ > + /* pkey 0 is the default and allocated implicitly */ > mm->context.pkey_allocation_map = 0x1; In the second patch, you introduce DEFAULT_KEY. Maybe you should introduce here and express the above code as mm->context.pkey_allocation_map = (0x1 << DEFAULT_KEY); Incase your default key changes to something else, you are still good. > /* -1 means unallocated or invalid */ > mm->context.execute_only_pkey = -1; > diff -puN arch/x86/include/asm/pkeys.h~x86-pkey-0-default-allocated arch/x86/include/asm/pkeys.h > --- a/arch/x86/include/asm/pkeys.h~x86-pkey-0-default-allocated 2018-03-21 15:47:48.184198927 -0700 > +++ b/arch/x86/include/asm/pkeys.h 2018-03-21 15:47:48.188198927 -0700 > @@ -49,10 +49,10 @@ bool mm_pkey_is_allocated(struct mm_stru > { > /* > * "Allocated" pkeys are those that have been returned > - * from pkey_alloc(). pkey 0 is special, and never > - * returned from pkey_alloc(). > + * from pkey_alloc() or pkey 0 which is allocated > + * implicitly when the mm is created. > */ > - if (pkey <= 0) > + if (pkey < 0) > return false; > if (pkey >= arch_max_pkey()) > return false; > _ -- Ram Pai