Received: by 10.223.185.111 with SMTP id b44csp694520wrg; Fri, 9 Mar 2018 11:56:26 -0800 (PST) X-Google-Smtp-Source: AG47ELv/U+5bPsOZOlwuHXBh22+wQy+xHbCUQ3iyceqfMWzP5tT2pYak00SyMtgsCADDswRR2imV X-Received: by 2002:a17:902:128c:: with SMTP id g12-v6mr28916094pla.85.1520625385956; Fri, 09 Mar 2018 11:56:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520625385; cv=none; d=google.com; s=arc-20160816; b=Z4UYJnhlXeYYXsM3jBm8UR/jKe+lUSA87s00uypd6BQJzPC4vQ9GRG+SFMISX+XHTP 5G1jGCdPJZFq7uwPgKq4EZNtM8xHLjyr8lKgqLiuhNQnrgEKQORl3rFHio2Jp1vspd3K /5E4sdRrHQcWtg5EFIP/xczkLX8mg/Pnf0Q9Ez2VKYye9iWoVUgXwxQeK+GJTosH5VhO mPSnXc9/PJ+A1MlAi1xFm5KwcIgakOMQPQbcVNxA2u1H3NlyfcbVO7d8+RdovjJpcYHy GWhjw0zZpR9Mj02ttzNzMvlyme35l4mcgEBtZdCkUxgfEUYuG5oeHzBnM46ESl6FmkUF HK0A== 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=43k+uamugiLxieQ7DPmtikRrzhS1+D9Xaqdg2I//Juc=; b=N+/d6MvyvZsHA3cT2w9PvWCq8PFKPWTDZqi14KHqqRWWugVxVj2nPRs8Qghc4lOEHl VyiTRosLuYwKLn+ot9bKK1sPsIlHjjnBmINGi3Yl9cPgUer4yfv7smf0ndRsTPjPDYVm ThlFRdzjt5wU5cpk8+ah+80TLOTnJdkj67XRDFnYaUKzFRlHWP722xJMDlcoK/OKtmeS HqKuijqIvyUtLj7roaP8PWI13FM7GyOlCk4vBPzN6LnVV+uuYtMCWBlXX3YgAAisAHzh p2m7b5jt/Bi2unf5DxB+SPn3RSGktxgYuGGnKB3iPd9gh3vCrjBBHHgSSkAMe3THv+di MwPA== 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 f31-v6si1378646plb.636.2018.03.09.11.56.10; Fri, 09 Mar 2018 11:56:25 -0800 (PST) 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 S1751397AbeCITyy (ORCPT + 99 others); Fri, 9 Mar 2018 14:54:54 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46682 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751227AbeCITyv (ORCPT ); Fri, 9 Mar 2018 14:54:51 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w29Jsps2144671 for ; Fri, 9 Mar 2018 14:54:51 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gkwwe6uhp-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Fri, 09 Mar 2018 14:54:50 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Mar 2018 19:54:48 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 9 Mar 2018 19:54:43 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w29JsgtV50528312; Fri, 9 Mar 2018 19:54:42 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD75CAE045; Fri, 9 Mar 2018 19:45:15 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40E0BAE04D; Fri, 9 Mar 2018 19:45:11 +0000 (GMT) Received: from ram.oc3035372033.ibm.com (unknown [9.85.196.180]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 9 Mar 2018 19:45:11 +0000 (GMT) Date: Fri, 9 Mar 2018 11:54:35 -0800 From: Ram Pai To: Balbir Singh Cc: Michael Ellerman , Ingo Molnar , "akpm@linux-foundation.org" , "open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)" , linux-mm , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , linux-arch , "linux-kernel@vger.kernel.org" , Dave Hansen , Benjamin Herrenschmidt , Paul Mackerras , Anshuman Khandual , Aneesh Kumar KV , Haren Myneni/Beaverton/IBM , Michal Hocko , Thiago Jung Bauermann , "Eric W. Biederman" , Jonathan Corbet , Arnd Bergmann , fweimer@redhat.com, msuchanek@suse.com, Ulrich.Weigand@de.ibm.com Subject: Re: [PATCH] x86, powerpc : pkey-mprotect must allow pkey-0 Reply-To: Ram Pai References: <1520583161-11741-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: User-Agent: Mutt/1.5.20 (2009-12-10) X-TM-AS-GCONF: 00 x-cbid: 18030919-0012-0000-0000-000005BAF5E6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18030919-0013-0000-0000-000019371BC0 Message-Id: <20180309195435.GQ1060@ram.oc3035372033.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-09_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1803090239 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 09, 2018 at 07:37:04PM +1100, Balbir Singh wrote: > On Fri, Mar 9, 2018 at 7:12 PM, Ram Pai wrote: > > 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. > > I looked at the code and my observation was going to be that we need > to change mm_pkey_is_allocated. I still fail to understand what > happens if pkey 0 is reserved? What is the default key is it the first > available key? Assuming 0 is the default key may work and seems to > work, but I am sure its mostly by accident. It would be nice, if we > could have a notion of the default key. I don't like the special > meaning given to key 0 here. Remember on powerpc if 0 is reserved and > UAMOR/AMOR does not allow modification because it's reserved, setting > 0 will still fail The linux pkey API, assumes pkey-0 is the default key. If no key is explicitly associated with a page, the default key gets associated. When a default key gets associated with a page, the permissions on the page are not dictated by the permissions of the default key, but by the permission of other bits in the pte; i.e _PAGE_RWX. On powerpc, and AFAICT on x86, neither the hardware nor the hypervisor reserves key-0. Hence the OS is free to use the key value, the way it chooses. On Linux we choose to associate key-0 the special status called default-key. However I see your point. If some cpu architecture takes away key-0 from Linux, than implementing the special status for key-0 on that architecture can become challenging, though not impossible. That architecture implementation can internally map key-0 value to some other available key, and associate that key to the page. And offcourse make sure that the hardware/MMU uses the pte's RWX bits to enforce permissions, for that key. -- Ram Pai