Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1808798ybb; Thu, 26 Mar 2020 07:43:27 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtOULlNkdmp448jrW5cMsEY3yHw51iS4xWG3/h8bu9u0m94HUGQczb2k0bag7d23JGH5EVh X-Received: by 2002:a05:6830:18eb:: with SMTP id d11mr6529179otf.243.1585233807678; Thu, 26 Mar 2020 07:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585233807; cv=none; d=google.com; s=arc-20160816; b=Z1hboTTMD5dJ77Adp7+g+2Gf2gvNiaWnSJQfZJKMeeTWxpwwSA38yoowyxqyN9+aVI 0K/EzpihUytVB9UjupkxO1PrpcbNWMXlzheVepsfTia6c265BDk8FbgTqvp5TzdPrLNP uLDtmkh7WkXTD289hesi/tqek8P+7UyUO66Vp6bG28XIsk7eesjnJoi3w4ARz4DB7IT8 xQkDmtrRjT/9/3pDRzwr6Jq5OCu1KLdaZGSvlWYZhh7pE6HefxNy07yGf0BHzhsXPzeV daDn2slnXfRoTqflmDnuUpwKuUUefWOxgO7jT6YSOWOdRTrIklUYoO6RgyCsh31KiweU a7Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id :dkim-signature; bh=pxlhHd5KJjHJbZKhUrrTB5maIqr0JBMbVZgBuq9rqY8=; b=PCIvD8ebzBYox1oAuyu6io+A8WetgcHqsrKTw6Bk3utKNHIwQujgEMuwP4oMupwkL/ HV11dq55ue/r9UrTUbh+PFAyW3LIbiuJEX9t9JWXtrQ+p2FsVih9tU+Z/zk4oUJ4jRuI PxlWQDecEQgn9Ml0rC473CAKvpxjgba8vmeWs6SSjt8//aKnO+IpuPA7jSA2Qi2aiqml NZAXojylZW1svdV3+2frIot1QP7Bwp8uAJ79/tzOVFuY1dZn40ZqP4+d34kaXe5jSF2C Rcx/uTXQUYBE1W1GvktBAOAZixhrpgoxaDubXM3a3w4MhBBjNuOQ1VQqyBIKXl5CJwIj B17A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=mJgIki0K; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c133si1195987oif.272.2020.03.26.07.43.13; Thu, 26 Mar 2020 07:43:27 -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; dkim=pass header.i=@c-s.fr header.s=mail header.b=mJgIki0K; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727832AbgCZOmS (ORCPT + 99 others); Thu, 26 Mar 2020 10:42:18 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:60999 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbgCZOmS (ORCPT ); Thu, 26 Mar 2020 10:42:18 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48p7466SP9z9vBmt; Thu, 26 Mar 2020 15:42:14 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=mJgIki0K; 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 cr9aaoSfj6m6; Thu, 26 Mar 2020 15:42:14 +0100 (CET) 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 48p746529Yz9vBmr; Thu, 26 Mar 2020 15:42:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1585233734; bh=pxlhHd5KJjHJbZKhUrrTB5maIqr0JBMbVZgBuq9rqY8=; h=From:Subject:To:Cc:Date:From; b=mJgIki0KIobQpvxL4shrRvaUsX2PrpAHFRxhXSImCNW6EPhlmMgYw1kvv98dBNn/m mrTOYJdkt/CnIa9OY1UVWKIU6x6ziFptgzZP5knwnD+oNQ5VJMcecfCHfAMF504wul /YdBUHanRuX6qYBkn+TcQRd764WnxcRcIQ/We3HA= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2E4318B7AD; Thu, 26 Mar 2020 15:42:16 +0100 (CET) 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 zamguf2qSdgK; Thu, 26 Mar 2020 15:42:16 +0100 (CET) Received: from pc16570vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id ED95F8B756; Thu, 26 Mar 2020 15:42:15 +0100 (CET) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id B152C655EB; Thu, 26 Mar 2020 14:42:15 +0000 (UTC) Message-Id: From: Christophe Leroy Subject: [RFC PATCH] powerpc/lib: Fixing use a temporary mm for code patching To: cmr@informatik.wtf Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Thu, 26 Mar 2020 14:42:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)); err = unmap_patch(&patch_mapping); if (err) @@ -179,7 +182,7 @@ static int do_patch_instruction(unsigned int *addr, unsigned int instr) * think we just wrote. * XXX: BUG_ON() instead? */ - WARN_ON(memcmp(addr, &instr, sizeof(instr))); + WARN_ON(*addr != instr); out: local_irq_restore(flags); -- 2.25.0