From patchwork Sun Jun 3 20:18:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10445581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 060EF60375 for ; Sun, 3 Jun 2018 20:18:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E429228992 for ; Sun, 3 Jun 2018 20:18:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3C9C28A00; Sun, 3 Jun 2018 20:18:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D12928992 for ; Sun, 3 Jun 2018 20:18:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 771A26B0003; Sun, 3 Jun 2018 16:18:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7212B6B0006; Sun, 3 Jun 2018 16:18:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 612396B0007; Sun, 3 Jun 2018 16:18:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f197.google.com (mail-wr0-f197.google.com [209.85.128.197]) by kanga.kvack.org (Postfix) with ESMTP id 013496B0003 for ; Sun, 3 Jun 2018 16:18:44 -0400 (EDT) Received: by mail-wr0-f197.google.com with SMTP id 33-v6so22398216wrb.12 for ; Sun, 03 Jun 2018 13:18:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:reply-to:references:mime-version:in-reply-to:user-agent :message-id:content-transfer-encoding:content-disposition; bh=zkPqCGIBcnT1N/2pFlRWli4Kdv0jWrYXQmrQu+nhmHE=; b=seT36ff6EA2jRN4VAzgER50cas9Wo2jr3hUA8XYgmou1ostrZvdmjY2defq9caqi8l tkU0dPepfzRD+xBvp2bhERyzPkqQqFQmMgXK80mbsZy8dNFwz6UVWsRtnWANRWl+YEly e7JEDDJ890VQaUHxN+IBGlsDUgG+M6Iz8MBb9Mbi7ZEFmLP1qzTmkLrxwhI0DtNL5eMo 1GzHmxJ4/hdCW+gS2d+ViXlXkua/OZUY9ndtXr4RI/3g4FPWrnOLXIluAEmz6wTrtmmd esj9jKUdqBgoqi+9rJHRmL9vUeK9jYz2S3ipE8qVQCe99hC6UaK9SNSJpBU8gWOZFydh hJUw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of linuxram@us.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=linuxram@us.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: APt69E3Yy3R+1PMQ7N2QjFiig6yh3WdJRSvrTakmidUEomNmIwCxvB0Q Kp6OjstzDQM3SvuxTylwL+QMpwRK/Sh545AdtmqI6RnS27DaSxSIbhaeS+5KOH33R/V/PsUrx0u ltsyG99OPcNugr5duS00eBQbnUFfMUr4vB4z3vm/sie8sE2ErC+X4AwoyUNMVWsvcgg== X-Received: by 2002:a1c:b954:: with SMTP id j81-v6mr7153477wmf.89.1528057123353; Sun, 03 Jun 2018 13:18:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJlUydylX05WNzh7bm6AJHFApw8IxOnVVtTlnw2ggiIwGitC5i6haxxYj4pskU5AKjgdtma X-Received: by 2002:a1c:b954:: with SMTP id j81-v6mr7153464wmf.89.1528057122366; Sun, 03 Jun 2018 13:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528057122; cv=none; d=google.com; s=arc-20160816; b=Vh5lJXhxd8F0k4dSGJP8AKPWnlGfHTIM1CZhs9blXDlw8Z2X/5jxlZCYd9/rhQtMBo ca1lrb75LRuv6f895fCUlpPHjP0fWZZ55RO9SLeVudLElkJNZD5lExRLECBSAiceqtFC L9nt3T8U6pWPthMsfFDCI1tJe3TvKs6Z89bk6ZM/U/BsbLa0BKmEUyp5jXoT4iCbmoj/ /r7Rmr38iybc+4qoGiGSQ2L8xjx64Wp03MKbblQMNDW83SoeyQjOydQtkPKm+LKlKDOi 1gfk5mwJNjde5CECzrywCP6csY9j0ZlESEqY7cPfVZhCgXhapvfJ1M3zpxY5NmUqEQ3V FusQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:content-transfer-encoding:message-id:user-agent :in-reply-to:mime-version:references:reply-to:subject:cc:to:from :date:arc-authentication-results; bh=zkPqCGIBcnT1N/2pFlRWli4Kdv0jWrYXQmrQu+nhmHE=; b=IyyqAguneXrQn24/7gpZc7Iedj0vbdDTAk9iYkUpwGbJ9HcNpxLXHfh62DtKMdgk9t 5hroDqYcS00uyJSwbjEupAZoHxWxJeNQxkXLQ5KrKvwI7tSdy25jxtGm121O1FHcp1lj U+eiFT70T4nb4JoUQknXnc2RWfY6WXIEVL3r/z7Zm+p3Ie8j+FtwP7ebHM0J1uS/7SaR /JOpUThhHdAbqQodrbS4wJlO8tseNh/hlqKXYSs4Y4Ldg/O0u7LV0FgNa7mAJhq6Z1pc a+Ivaz09s87NS15gZt3m5vvQFL5IYegLVbL+AXMHoCWwY3IfA87LQ+VY2yCmg3UOefWs er9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linuxram@us.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=linuxram@us.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id h6-v6si21258449wrb.44.2018.06.03.13.18.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jun 2018 13:18:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linuxram@us.ibm.com designates 148.163.158.5 as permitted sender) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linuxram@us.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=linuxram@us.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w53KESIY034731 for ; Sun, 3 Jun 2018 16:18:40 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jc8e24x8u-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 03 Jun 2018 16:18:40 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 3 Jun 2018 21:18:39 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Sun, 3 Jun 2018 21:18:37 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w53KIaPx28311664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 3 Jun 2018 20:18:36 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE9BC42041; Sun, 3 Jun 2018 21:09:01 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A24F84203F; Sun, 3 Jun 2018 21:09:00 +0100 (BST) Received: from ram.oc3035372033.ibm.com (unknown [9.85.153.100]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Sun, 3 Jun 2018 21:09:00 +0100 (BST) Date: Sun, 3 Jun 2018 13:18:32 -0700 From: Ram Pai To: Florian Weimer Cc: Andy Lutomirski , Linux-MM , linuxppc-dev , Dave Hansen Subject: Re: pkeys on POWER: Access rights not reset on execve Reply-To: Ram Pai References: <53828769-23c4-b2e3-cf59-239936819c3e@redhat.com> <20180519011947.GJ5479@ram.oc3035372033.ibm.com> <20180519202747.GK5479@ram.oc3035372033.ibm.com> <20180520060425.GL5479@ram.oc3035372033.ibm.com> <20180520191115.GM5479@ram.oc3035372033.ibm.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.20 (2009-12-10) X-TM-AS-GCONF: 00 x-cbid: 18060320-0028-0000-0000-000002CC41E1 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060320-0029-0000-0000-00002382C352 Message-Id: <20180603201832.GA10109@ram.oc3035372033.ibm.com> Content-Disposition: inline X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-03_12:, , 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=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806030252 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP On Mon, May 21, 2018 at 01:29:11PM +0200, Florian Weimer wrote: > On 05/20/2018 09:11 PM, Ram Pai wrote: > >Florian, > > > > Does the following patch fix the problem for you? Just like x86 > > I am enabling all keys in the UAMOR register during > > initialization itself. Hence any key created by any thread at > > any time, will get activated on all threads. So any thread > > can change the permission on that key. Smoke tested it > > with your test program. > > I think this goes in the right direction, but the AMR value after > fork is still strange: > > AMR (PID 34912): 0x0000000000000000 > AMR after fork (PID 34913): 0x0000000000000000 > AMR (PID 34913): 0x0000000000000000 > Allocated key in subprocess (PID 34913): 2 > Allocated key (PID 34912): 2 > Setting AMR: 0xffffffffffffffff > New AMR value (PID 34912): 0x0fffffffffffffff > About to call execl (PID 34912) ... > AMR (PID 34912): 0x0fffffffffffffff > AMR after fork (PID 34914): 0x0000000000000003 > AMR (PID 34914): 0x0000000000000003 > Allocated key in subprocess (PID 34914): 2 > Allocated key (PID 34912): 2 > Setting AMR: 0xffffffffffffffff > New AMR value (PID 34912): 0x0fffffffffffffff > > I mean this line: > > AMR after fork (PID 34914): 0x0000000000000003 > > Shouldn't it be the same as in the parent process? Fixed it. Please try this patch. If it all works to your satisfaction, I will clean it up further and send to Michael Ellermen(ppc maintainer). commit 51f4208ed5baeab1edb9b0f8b68d7144449b3527 Author: Ram Pai Date: Sun Jun 3 14:44:32 2018 -0500 Fix for the fork bug. Signed-off-by: Ram Pai > > Thanks, > Florian diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 1237f13..999dd08 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -582,6 +582,7 @@ static void save_all(struct task_struct *tsk) __giveup_spe(tsk); msr_check_and_clear(msr_all_available); + thread_pkey_regs_save(&tsk->thread); } void flush_all_to_thread(struct task_struct *tsk) diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c index ab4519a..af6aa4a 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -294,6 +294,7 @@ void thread_pkey_regs_save(struct thread_struct *thread) */ thread->amr = read_amr(); thread->iamr = read_iamr(); + thread->uamor = read_uamor(); } void thread_pkey_regs_restore(struct thread_struct *new_thread, @@ -315,9 +316,13 @@ void thread_pkey_regs_init(struct thread_struct *thread) if (static_branch_likely(&pkey_disabled)) return; - thread->amr = read_amr() & pkey_amr_mask; - thread->iamr = read_iamr() & pkey_iamr_mask; + thread->amr = pkey_amr_mask; + thread->iamr = pkey_iamr_mask; thread->uamor = pkey_uamor_mask; + + write_uamor(pkey_uamor_mask); + write_amr(pkey_amr_mask); + write_iamr(pkey_iamr_mask); } static inline bool pkey_allows_readwrite(int pkey)