Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp642540ybz; Wed, 15 Apr 2020 15:47:29 -0700 (PDT) X-Google-Smtp-Source: APiQypLCtQ3AQUlWAvoPsbdtJIYVBjYsTpdaC5Dat+sS247SXH8QeeENEez6oFFGynhnTe+deKPx X-Received: by 2002:a17:906:c7da:: with SMTP id dc26mr4697268ejb.46.1586990849023; Wed, 15 Apr 2020 15:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586990849; cv=none; d=google.com; s=arc-20160816; b=o6p2VfdjpPY/6GHrWFaz1TLqJ7BNpRTM0yUAnsh+tWIN/TPmYvwMdh3X9avElC5UJd YsQfpV2fbNrKoEwSDvir4iWkEqu2dV63opKKg5LTf5bjwBh5FzA2874g2FkJKNLvouGH F11x9NMeI/Xwz9KTC67+VL+2n46xoqUqi03Z09a+T8oQ0ODXWRCswNUTiGQUxeP57121 i59LUZi/3SOKw3u+7yH/7bM9IKfriEwNWzxOfxD+LieDLR9oJpcYH6LFmILowIJOBCst nBsbGZ58tICqeuHsCuU4SeDSvQWOazjv0XzCwjJXEji9mD7iSLZa53eEmyec0GdZp81S 3cAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=dV6YOiJ4H7/Y4XRgt4cAkIwhpU0OWRnUnXsQ0TRfdTQ=; b=Prz9WqUkC49p3m9EfMXL0W+TpvLpIJUZR65ka/6eLCs9ka3nVvS9IvsJ8pwy72qnM7 VWxo4bb2jhYnl6i3re1+wmXVmceJU0PPas87qtf1pobssla9Lu6wJbqa5IBQfnLcZNQW H3Tl4WGz2Hw4aVTUyjE9/3L1Jkil4ZysXA/YhsfZZ1et8h8vUhxOOQ1J2rngk+BjQ4oq gxKEIfKYMo2a/4h9Ay+Lde/Vkhe43Efk/RGQrTZYpF7zgYh73Lhd+Yxpl/mQf87NxKlE RG3y5CqldoItBssK3UzoYP1EEllYCQJYqzgq1zdY43O3qNHS6+wzX8E7Km0sbEA8jOi8 t4Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=l3bXNSrG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x68si9153445ede.282.2020.04.15.15.47.05; Wed, 15 Apr 2020 15:47:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=l3bXNSrG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408381AbgDOJMy (ORCPT + 99 others); Wed, 15 Apr 2020 05:12:54 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:13063 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408349AbgDOJMu (ORCPT ); Wed, 15 Apr 2020 05:12:50 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 492Gpk5yV6z9tyhC; Wed, 15 Apr 2020 11:12:46 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=l3bXNSrG; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id TaUh6lmL-P5o; Wed, 15 Apr 2020 11:12:46 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 492Gpk4cxWz9tyh9; Wed, 15 Apr 2020 11:12:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1586941966; bh=dV6YOiJ4H7/Y4XRgt4cAkIwhpU0OWRnUnXsQ0TRfdTQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=l3bXNSrGdxlnjlWOnENO9yr6woUzN6ZgWaFq0AeIbus2cgvd5vr++ZYzkKQD5rUfk wgf04+Ea7y8Pc4hBCTZm3k4kIvjtxa3VIUV/aMcjX+kcT+EV9MdeSHnycTXiaqXSVT pQhi3bHOfa4chGHCdXqoHHn+pvVwwc1LteiUO7wg= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C180E8B922; Wed, 15 Apr 2020 11:12:47 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id CWq1knqHjwR5; Wed, 15 Apr 2020 11:12:47 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4B6258B91F; Wed, 15 Apr 2020 11:12:47 +0200 (CEST) Subject: Re: [RFC PATCH] powerpc/lib: Fixing use a temporary mm for code patching To: Christopher M Riedl Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <581069710.188209.1586927814880@privateemail.com> From: Christophe Leroy Message-ID: Date: Wed, 15 Apr 2020 11:12:35 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <581069710.188209.1586927814880@privateemail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 15/04/2020 à 07:16, Christopher M Riedl a écrit : >> On March 26, 2020 9:42 AM Christophe Leroy wrote: >> >> >> This patch fixes the RFC series identified below. >> It fixes three points: >> - Failure with CONFIG_PPC_KUAP >> - Failure to write do to lack of DIRTY bit set on the 8xx >> - Inadequaly complex WARN post verification >> >> However, it has an impact on the CPU load. Here is the time >> needed on an 8xx to run the ftrace selftests without and >> with this series: >> - Without CONFIG_STRICT_KERNEL_RWX ==> 38 seconds >> - With CONFIG_STRICT_KERNEL_RWX ==> 40 seconds >> - With CONFIG_STRICT_KERNEL_RWX + this series ==> 43 seconds >> >> Link: https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=166003 >> Signed-off-by: Christophe Leroy >> --- >> arch/powerpc/lib/code-patching.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c >> index f156132e8975..4ccff427592e 100644 >> --- a/arch/powerpc/lib/code-patching.c >> +++ b/arch/powerpc/lib/code-patching.c >> @@ -97,6 +97,7 @@ static int map_patch(const void *addr, struct patch_mapping *patch_mapping) >> } >> >> pte = mk_pte(page, pgprot); >> + pte = pte_mkdirty(pte); >> set_pte_at(patching_mm, patching_addr, ptep, pte); >> >> init_temp_mm(&patch_mapping->temp_mm, patching_mm); >> @@ -168,7 +169,9 @@ static int do_patch_instruction(unsigned int *addr, unsigned int instr) >> (offset_in_page((unsigned long)addr) / >> sizeof(unsigned int)); >> >> + allow_write_to_user(patch_addr, sizeof(instr)); >> __patch_instruction(addr, instr, patch_addr); >> + prevent_write_to_user(patch_addr, sizeof(instr)); >> > > On radix we can map the page with PAGE_KERNEL protection which ends up > setting EAA[0] in the radix PTE. This means the KUAP (AMR) protection is > ignored (ISA v3.0b Fig. 35) since we are accessing the page from MSR[PR]=0. > > Can we employ a similar approach on the 8xx? I would prefer *not* to wrap > the __patch_instruction() with the allow_/prevent_write_to_user() KUAP things > because this is a temporary kernel mapping which really isn't userspace in > the usual sense. On the 8xx, that's pretty different. The PTE doesn't control whether a page is user page or a kernel page. The only thing that is set in the PTE is whether a page is linked to a given PID or not. PAGE_KERNEL tells that the page can be addressed with any PID. The user access right is given by a kind of zone, which is in the PGD entry. Every pages above PAGE_OFFSET are defined as belonging to zone 0. Every pages below PAGE_OFFSET are defined as belonging to zone 1. By default, zone 0 can only be accessed by kernel, and zone 1 can only be accessed by user. When kernel wants to access zone 1, it temporarily changes properties of zone 1 to allow both kernel and user accesses. So, if your mapping is below PAGE_OFFSET, it is in zone 1 and kernel must unlock it to access it. And this is more or less the same on hash/32. This is managed by segment registers. One segment register corresponds to a 256Mbytes area. Every pages below PAGE_OFFSET can only be read by default by kernel. Only user can write if the PTE allows it. When the kernel needs to write at an address below PAGE_OFFSET, it must change the segment properties in the corresponding segment register. So, for both cases, if we want to have it local to a task while still allowing kernel access, it means we have to define a new special area between TASK_SIZE and PAGE_OFFSET which belongs to kernel zone. That looks complex to me for a small benefit, especially as 8xx is not SMP and neither are most of the hash/32 targets. Christophe