Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2569204ybb; Sun, 5 Apr 2020 10:47:24 -0700 (PDT) X-Google-Smtp-Source: APiQypKPTGc+AIv76utAgNCk3ugpK4JhuIIrySDdMN2QrM+Oo1G4rufY6HotOB51dDTFvYQvro5F X-Received: by 2002:a9d:22e9:: with SMTP id y96mr14639268ota.217.1586108843936; Sun, 05 Apr 2020 10:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586108843; cv=none; d=google.com; s=arc-20160816; b=mbjvq2w2qTF0+g1cXEgp5ydYUa3q3quVjNROXRMq/ktBs0hbe8yJBiB4vL37muEFTm QBqO5lo2qi0elr3JEsRek6tOW2lNAHioUBOAdEElvVqG28FDSNWVMoVV1NXtqgLQ9okk FHcb3vKPS8GJN9xXLzebpvC0VrLiCyyLP38QxR+RJM3LU24h3FQY8ZVw8JGxTriNafSS 8OPsN1DALW3P/3CiwETXPAGl6fH//Jq5m/f4k8mDPzbynNjsNjqOzCVT/GPpb4G4A6lC U0b6UPvErXiVieNaPGDBzMUE3+KSkor7K2Tv9W9wekGYmr5p7hfpYWfZaecHzIORagUM 5FKw== 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:references :in-reply-to:message-id:dkim-signature; bh=+Vq2DhCbptHoTJrgP33JgNBllJVdhbPixQ4rKRn8KTc=; b=n9CoNWjjpJ38Z00yBuD6DeeTBiCEgCds8WpUL8LNwkmPiTrIv6T4HGaS2rHTceVve2 yeED2GNsAQ4Vn5DxSztfOW0YC9pyNZINOA2Zk7qKmrfTW/8QUgcWr3XBHAWRGBftSsyT hlbTcGee2ml64BbsuZv4iX9Yl9j0NnrAoJbiGLjeH71bCXDZ4+BraLlXjx+IJQ4IflGM Qco+yUYGYJwJCnz1ANgo60cRQMzx8z5ooRVV5CvNNwMBc9L80v47a3nIcNSJwo7DSMB0 rxkg29YQIIXtLGUD3Xej9PSd6OBh43SzJbwU64qS8XdIWrgb8NIu0faoh1IkW7bVpMI6 SpGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=QLJ3b7CJ; 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 a6si6789252oto.34.2020.04.05.10.47.12; Sun, 05 Apr 2020 10:47:23 -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=QLJ3b7CJ; 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 S1727614AbgDERoj (ORCPT + 99 others); Sun, 5 Apr 2020 13:44:39 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:27481 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727526AbgDERoi (ORCPT ); Sun, 5 Apr 2020 13:44:38 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48wLdt1zXhz9ty3K; Sun, 5 Apr 2020 19:44:34 +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=QLJ3b7CJ; 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 R4RvUfwHAYZs; Sun, 5 Apr 2020 19:44:34 +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 48wLdt0tkLz9ty2y; Sun, 5 Apr 2020 19:44:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1586108674; bh=+Vq2DhCbptHoTJrgP33JgNBllJVdhbPixQ4rKRn8KTc=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=QLJ3b7CJ8Gq87V16BA8wfYh4F4xMypFjjrSVEBa0uF4KuV4nFXoW9J2UCbOXC0o0H AG9edKIqLvjHjmcQ45BHg94qU07TJWIR1/GM5KDGX7vPXfHWHVqVOgBvmmUJ8BFBKj roh4Q99JevJ1MTcJ/Gf1PKHKy1TqBrus6a5RUJyc= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9C9148B783; Sun, 5 Apr 2020 19:44:37 +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 b8YXuLWyKOtd; Sun, 5 Apr 2020 19:44:37 +0200 (CEST) Received: from pc16570vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 659138B774; Sun, 5 Apr 2020 19:44:37 +0200 (CEST) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 3A98E6571C; Sun, 5 Apr 2020 17:44:37 +0000 (UTC) Message-Id: <6e7e16e234125dfa11a8004e1e1d0fe47fd1adf5.1586108649.git.christophe.leroy@c-s.fr> In-Reply-To: <029e1064b1ad738785718221ea468c9cfc282457.1586108649.git.christophe.leroy@c-s.fr> References: <029e1064b1ad738785718221ea468c9cfc282457.1586108649.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [RFC PATCH v2 02/13] powerpc/32s: Create C version of kuap_restore() and kuap_check() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , npiggin@gmail.com, msuchanek@suse.de Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Sun, 5 Apr 2020 17:44:37 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation of porting PPC32 to C syscall entry/exit, create C version of kuap_restore() and kuap_check() on book3s/32. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/kup.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h index 3c0ba22dc360..c85bc5b56366 100644 --- a/arch/powerpc/include/asm/book3s/32/kup.h +++ b/arch/powerpc/include/asm/book3s/32/kup.h @@ -102,6 +102,27 @@ static inline void kuap_update_sr(u32 sr, u32 addr, u32 end) isync(); /* Context sync required after mtsrin() */ } +static inline void kuap_restore(struct pt_regs *regs) +{ + u32 kuap = current->thread.kuap; + u32 addr = kuap & 0xf0000000; + u32 end = kuap << 28; + + if (unlikely(!kuap)) + return; + + current->thread.kuap = 0; + kuap_update_sr(mfsrin(addr) & ~SR_KS, addr, end); /* Clear Ks */ +} + +static inline void kuap_check(void) +{ + if (!IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) + return; + + WARN_ON_ONCE(current->thread.kuap != 0); +} + static __always_inline void allow_user_access(void __user *to, const void __user *from, u32 size, unsigned long dir) { -- 2.25.0