From patchwork Fri Oct 9 21:13:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11829685 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4087816C1 for ; Fri, 9 Oct 2020 21:14:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFF612240B for ; Fri, 9 Oct 2020 21:14:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="wPbRCSdF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="XUHSmS4B" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CFF612240B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uveNxkAGHn86qitI/mCVEnGEsYrmU7oI9Ofi2ZLKLBk=; b=wPbRCSdFygZnhkBAJ5FL84Ieo rPL6M3/nBT9fqVNNSyb28fpdZx8b9/FnxQ+6jEALW2j7oKTLh4ywBIWxne9FhPEtOrPB9I4qFtlR7 r0y/kGrbksM2XF4y6oPiQW1EKnZRfosW7S6Fy1I7iG2C0zXf0Zuna8bAYmyhSHDwdlXL6g48l3URf AvC6NxpEWDcfGLeVF2PLjgneYRN/yfQGYYapS/T0fQ1La90rRvEOvik7cliuGH4d6exYGcnp/5sHG 4JsrVwgRjS5BJL9H7AQx5oVcIzeCdiKJyUOUhzDFsQ4iIbDOeodBxgwdkxcucoAMIgG2fEADGln1p juGhg8z2w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQziB-0004mj-AP; Fri, 09 Oct 2020 21:13:59 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQzi8-0004kN-C2 for linux-riscv@lists.infradead.org; Fri, 09 Oct 2020 21:13:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1602278036; x=1633814036; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/QbUqQmeMLjTwBzMbaBF9lCBuT7lct8fLe+m4vUDssY=; b=XUHSmS4BmrjOYDcZRZiytRQ8eDZPaU3+K1MCnWI0DK4c4Dau2yrJ6sCS FiXrGggvYrTn4jhaDV/MVIJtBzUmadrKjbVHE0PY6ZZ0A3wxKje77MbC0 4WvKn5SiIyDp1tFmWI1uNzVwzuUhHJ2JR27rW5hLSijIItEEbmBp0ThmQ aoO73iT+szNEPk2PU1ErDWI7tF6zdBU6mlyDBkoa4y+HQQcn1ztGPb4rh RXzqDEPJvqEiaXmIQ0Qcgi/2tXMQBn79a2p090JjfWFrETyyB41YXWDwB SyguGUMnyNsDmGJvu1vcfRwzmNdn5i/NMZSgiQqMB4a9m9aUbznAsaSVX A==; IronPort-SDR: iaJ3cgYsMRYvhb8kOmrEs//5vzb0YDslKp/cJqtendqpwTtq5lrjLVz0jfP1UnxxB/xz13QOQk QermcOtio050D7glUi5HO/R9XRk+9mCgs+1Gb6p5blRb8J/1Yzt+2HV+ry5kWOYJXhdvQyoAH3 ZlFQxyLCNSs21XPeQq19ucyMls+x1X65SlLrmtcBiDGTbppk6zrtWyyxO5Z4/GTgGZSC5z6ID5 GfUDbXSRLvhgRO2dJp3H/gZOczdImDFKFelOFTMO+iURo1vIZeOrfSx1RHiDXKrfVPDa3HMXyr xdY= X-IronPort-AV: E=Sophos;i="5.77,356,1596470400"; d="scan'208";a="149406012" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2020 05:13:53 +0800 IronPort-SDR: gF0bHf8z3Z4uroL+T04r4xJtOP/DkKeAib9jbD5NlmJvhf9fmTINhzNw9NUsqv2lONuMFlAnCe tZL1lp6jgU0/MaTFIpxwLoH8xzBVFN8MPbmh+zd6kSudUOVwlsUUus8x+lFKunQSQSjy7Ee+ub KPsBtbgdFWdyOCZtxFwmqL4FxrrIu7ehprhs+NdDUZ9LLU/dih1eWoZNb9I8AX7a6YIbBlbiY3 cYuywf2QrZ//Y4zNMIZbBlTKGalB2pm7bbwReb2zYGbelBT/mjkm4GkWNDWzcW/D3+XLwILpI7 Q82cr2ugE9VtLTzvBwjwzUaN Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 13:59:41 -0700 IronPort-SDR: DpNNZ5QX9GY5e4Dv4bfNJw2Zednqrf5wkbR/vJKlJyg8CCbe3aBt1YYFjjIY93YGNCX/Bv0hD6 OMi72XUnj78eYponFLeyS5CjqiV5CyauHbxPhIoGTODjsCGH4pu2DKx6MI6AWzyP17Q283EfiZ s/xPfPLrNk3M5jA5RtoLPgHW6XEOFTW774UAKVo3TBIUzQ4wbOHWeLuH0ryZ43idOgBb7cI4AF VBZoRioUS0iai5b8kyxfB3VVu4T8YtAeJFUAtqwAVlzkc/fl29HQl6TdpF6qqAkS717tWe5kkZ s4c= WDCIronportException: Internal Received: from usa003000.ad.shared (HELO jedi-01.hgst.com) ([10.86.60.38]) by uls-op-cesaip01.wdc.com with ESMTP; 09 Oct 2020 14:13:53 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH 1/5] RISC-V: Move __start_kernel to .head.text Date: Fri, 9 Oct 2020 14:13:40 -0700 Message-Id: <20201009211344.2358688-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201009211344.2358688-1-atish.patra@wdc.com> References: <20201009211344.2358688-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201009_171356_537299_9B2AF72A X-CRM114-Status: GOOD ( 11.63 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.42 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Kees Cook , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Guo Ren , Palmer Dabbelt , Zong Li , Paul Walmsley , Greentime Hu , Andrew Morton , Borislav Petkov , Michel Lespinasse , Ard Biesheuvel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Currently, __start_kernel is kept in _init while _start is in head section. This may result in "relocation truncated to fit error" if _init section is moved far from head. It also makes sense to keep entire head.S in one section. Keep __start_kernel in head section rather than _init. Signed-off-by: Atish Patra --- arch/riscv/kernel/head.S | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 3631147732ee..e820b0c09528 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -178,7 +178,6 @@ setup_trap_vector: END(_start) - __INIT ENTRY(_start_kernel) /* Mask all interrupts */ csrw CSR_IE, zero From patchwork Fri Oct 9 21:13:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11829683 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01C691592 for ; Fri, 9 Oct 2020 21:14:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C7D412240A for ; Fri, 9 Oct 2020 21:14:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FWLkckaP"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="cTc2IsOv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7D412240A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aszBDOHt3D19ol1x6/GJJRoivJ1athLSJP6Kx88FPPI=; b=FWLkckaP0/6S6rHVGB3/0zCSX w/odE7F9NshzxklXSWQC6w7sUzRab/hf2pIXh8lZ9w7W2RcIw10DozM9hc+DBFyF5zAGEIsUlWPRG JDikOVTeUt/eDVYojgKZKuJtbbarhdc64F2h+qW6l9dzmml0lL0JgSNtu2GF4qn5h4mN6y5STj35m sxVdX89NQQsogXVmUHJqnhLaqjZeQR6po8lMS+RKsKJdf73fXK2VsArAhL3m+FLwcx/UM5w2BvAsq ZFCp8BgtwBOckCpTkUedyAfJZHp67Rx54pBuupodgVK4jdLKp4aNFi4dZEDuy5cmAUcYU0CVplXGy EbopxA+Xw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQziC-0004ql-Ry; Fri, 09 Oct 2020 21:14:00 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQzi8-0004kW-Os for linux-riscv@lists.infradead.org; Fri, 09 Oct 2020 21:13:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1602278036; x=1633814036; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uLCpsvC/inR65HE35KjykwBVwDdqIbHHxLVflczTr2Y=; b=cTc2IsOvEMs47FzizyWp6PWEw16Y/VJWzJPC2AFAV1AT4KZzj0KURmsF PL1b6lyJW94UYV+dtEabKhbM8aORf5xGwt0NKUftt2tp4yMw0KQl2qqHk ZkMXKhGHOj9fuck0UFg3iryLcg1ajaeISMuhn5/xxkk8beYMM4oUis1cp wLknCTdjrEkVo7KA3oRv3lK5WrdJLsaDTvbkvaxPi39UGH7MJxift8Pl0 7WBNt1qDJTEeUcAAHLyFMR63pHBKyQr2KU60Dp2LgVfzeEYbW4MoiI+nQ Xbu8NRrPACNTOpve75WQO/31Z0SeZK2xhNKiAJlJVQ5Z9cN/h5ClruGWV Q==; IronPort-SDR: ruOhXMRLALHCuuXKgOtyXiac30ll57kB6oKDfRUJXsPxXGz0tLhRW2UmUDK8f/dJeMjQdMZIIH ej4poOC136nG+ZDpGnXAK3ah9vUVWmQc+ebiZzVE9B8Fb20bVvOoQkBQxQ3ETnxX4VeCuebfft ANHd14Hdqu2SEnKgLp61PNzKTeFsWfLkNLBHUqXFotbkNnFUrvcoqV10EiBHqYY4sziAKL9rM4 jUokSb2uKGd8m6OfVVzbcro7ChM6kkseZ/NOjpZgjoINyzTRmmSWT0LVesSvu0ZTEdyiz4J8AU u0U= X-IronPort-AV: E=Sophos;i="5.77,356,1596470400"; d="scan'208";a="149406014" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2020 05:13:54 +0800 IronPort-SDR: VlM1crg8hWLlQo57j5WsLW1y72REU2Rkh+oXjYHp0nIUB/9U64VfR8r4sp+tHxCZb5Ep6Bjqiu ZTsJDWCoOxLFAvFBSxEolEmqCLagpPAwWU8PTf4I1yf/T5D+UTTCx1IQP53fRsDxTog5uKcPHv me7O7cR6g+BJJjC+k1Q9dMwEAQnsZ1vAYsrrfnrEMvBJ0IoKamp9whXqoOBjHandiSIcr2IxT2 cX7xdgdKanEWBqRZixdsSyup7nfEMPXyiZ0ElIMSvEQDElOUJVmTeo/MGWmgJMLQd3hL/XfGaG Qf0STdm0mx1ScUeacF6j5mYn Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 13:59:41 -0700 IronPort-SDR: k7VpveUvGC2efjb8TPkb5b963i4tk0vSeShUCYhda4iG2UWjLq+U326k8Xt4PhRxdYNxbiKZlQ /mBkP0UVKgvqGOVYokqviIhHplcWANZ7EsinNEySw51Yn+4Ac5jV/YeNq+Zufdes7yw8VE/Zx+ vE/MtSu5voyQ5Ycv8mdj3yTD9Q/Sd517jWj4nIxipZ5wPzDivks1gcSZ2ikOthVbWJtplBy+nP WQGaAG1aXjZw+VDCaMbqVrqB4Ix9O92YzSxBPXVdJsavTS4J0IZBC6pd/olzUvJb5ymWMbgd6V Rrg= WDCIronportException: Internal Received: from usa003000.ad.shared (HELO jedi-01.hgst.com) ([10.86.60.38]) by uls-op-cesaip01.wdc.com with ESMTP; 09 Oct 2020 14:13:53 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH 2/5] RISC-V: Initialize SBI early Date: Fri, 9 Oct 2020 14:13:41 -0700 Message-Id: <20201009211344.2358688-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201009211344.2358688-1-atish.patra@wdc.com> References: <20201009211344.2358688-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201009_171356_950958_6EF2601D X-CRM114-Status: GOOD ( 10.69 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.42 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Kees Cook , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Guo Ren , Palmer Dabbelt , Zong Li , Paul Walmsley , Greentime Hu , Andrew Morton , Borislav Petkov , Michel Lespinasse , Ard Biesheuvel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Currently, SBI is initialized towards the end of arch setup. This prevents the set memory operations to be invoked earlier as it requires a full tlb flush. Initialize SBI as early as possible. Signed-off-by: Atish Patra --- arch/riscv/kernel/setup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 1db17f37736e..a5cac440aadf 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -90,6 +90,9 @@ void __init setup_arch(char **cmdline_p) pr_err("No DTB found in kernel mappings\n"); #endif +#if IS_ENABLED(CONFIG_RISCV_SBI) + sbi_init(); +#endif #ifdef CONFIG_SWIOTLB swiotlb_init(1); #endif @@ -98,10 +101,6 @@ void __init setup_arch(char **cmdline_p) kasan_init(); #endif -#if IS_ENABLED(CONFIG_RISCV_SBI) - sbi_init(); -#endif - #ifdef CONFIG_SMP setup_smp(); #endif From patchwork Fri Oct 9 21:13:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11829687 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6743139F for ; Fri, 9 Oct 2020 21:14:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 553B22240A for ; Fri, 9 Oct 2020 21:14:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eAnR15E2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="HqQEFrwO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 553B22240A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lcH56+sV20xtqifd8jKwO3GVa+COyrP6AVQtNvFRElk=; b=eAnR15E2ZX3LFx1K6GgefIPAC PvUy4bUe/re6KZrEaHMeSc1o67yePS7n8kgGhWDvJgTT+YMe6ho1ALpEcgo54U/+jmlS1wHEW/ScN HlUHzQ2e7eTYCzZvtFYl3U0pGema837hJVcPCZFzUFybnddBXf6lfNDTi+B+XEW63+LFbveUM22pb LTtR0PB2yTnlfPy/LSZ7DuvElEnoOWxx7fIaYWWd6Ab2LvBgx2dzMZczAW/D089XC1Zerxfo2vO6V HHMd/Pc2SPijKmymQBU7C8iYLES3XR71lOIJf1sl/HN1meUfBBrmVRWdMPlqKDm/vPfHAMgy/9JU3 h7+LvTEBg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQziD-0004rB-TA; Fri, 09 Oct 2020 21:14:01 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQzi9-0004kN-Hy for linux-riscv@lists.infradead.org; Fri, 09 Oct 2020 21:13:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1602278037; x=1633814037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fglb0o2Ozn6JOzVy78SpXXGYj0jpbArC9/S0MZnBZpA=; b=HqQEFrwODA4fmIltDwMOW2juYxJL4+ictpx7Cckx9g50E8iYX68Hjwlx BXYsFxu5Pqjs3t434+drxSIolUq60r/dW45DApdeiY4vnGo8oAd+r5m7o NYovv96gHYK1sItQjWsBtuRirG6pUTEK37o6RszGFsEge2zJACXfdtO9R jdDZFYBJ5uhKRDao/DFJckfPl25vvzGw+ojxfHDB7dFsnR9jCVoP1FPLT DTNHSCkJm8+RWsXNHEq2fvfr1ejmNAIeidP5OvplsujRCODLBT99KdylH gdnAoR75YosFMS7s3py78yqUJyrWA1sK7KzrWAFeIFITwGwRzrLTLk1FZ w==; IronPort-SDR: hNH+4TlG6Pgep2JCYBUV91vV3Ni+pjoHpOPGxa1OWQfr+xOPT3kguOsLy1MRIQv/Fk3fkwpo76 /q7X+RClTgsrGWQhpRpac5bwrU+hFTi8H6ffvjSZoOFQpk9YpcBLVU8IdfEXFCEaVb7JJVsq9q hS9CF+7RvkUsF5DZF2SaOvex7y9Qk94oS6QBBnUT3QjLfbQZykfKLu1ly8JAeoea+40sxKdCRc n1gaxCqKwnaA2GZW4x/YrbKbN6Sc+SgbfYUfv/p+iv8Ddfu6rSaqAja4UAzDqQn+I6klupq/CX B28= X-IronPort-AV: E=Sophos;i="5.77,356,1596470400"; d="scan'208";a="149406016" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2020 05:13:54 +0800 IronPort-SDR: dbPRlWzNr4rOGZ0pnHrNpg1UUCPYR12Eq/b62JlJzl14iRgSjHZ3N8IHbKZ8wWwo8Wp+/tgp+q cnKp2a9uj7uzGhBVl0h07uFfb3ezGqWIJazCfzVvXwQl+pWLqQJLgDFX77/vm7naYt3qRaesqP UQnmHMELv1ZSJyTdUD4QH9c481QbvrSlB1KLlASdkQeW7iy7/Axvxmxgw3G+5OcShcd8XAIwiq ZxUIyVj4fAEKwUwy74BGzGtpL+DkXZyhXhW6WBns6XyGJXHDlu2wW96A0+TzHvPadAN+RBfHyU 8KTFk5QIdMXIkHlxjdQw/X+6 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 13:59:42 -0700 IronPort-SDR: eXGMo36/52VIraPdKKeyD28xmyCV+mQZPzhV/YTH64o581o6ScGk7bLiN93yXBMQTCkjGuOkms 0N3E+GW1tdh1bVCCL+QBeaHOw6asvHx1UicY9iUd+c7IwJC+woP9ogmP4SjWFEqSXWoZ68n8AD O7Altp7APqErBc3jAA0g2uQ7iaM6hBC35fHXn6hUhEGKsJKLgTASVOqhsG+/UTKMHTj6+gSF8l 4Q/1ezkRYQmZ27+AEIEptvxYcveQOB3bPouGAM9EXcXwnvA526DJKdotAeu/3T6TgoxTKknKj1 H+E= WDCIronportException: Internal Received: from usa003000.ad.shared (HELO jedi-01.hgst.com) ([10.86.60.38]) by uls-op-cesaip01.wdc.com with ESMTP; 09 Oct 2020 14:13:54 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH 3/5] RISC-V: Enforce protections for kernel sections early Date: Fri, 9 Oct 2020 14:13:42 -0700 Message-Id: <20201009211344.2358688-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201009211344.2358688-1-atish.patra@wdc.com> References: <20201009211344.2358688-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201009_171357_740371_A381DDC5 X-CRM114-Status: GOOD ( 15.16 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.42 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Kees Cook , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Guo Ren , Palmer Dabbelt , Zong Li , Paul Walmsley , Greentime Hu , Andrew Morton , Borislav Petkov , Michel Lespinasse , Ard Biesheuvel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Currently, all memblocks are mapped with PAGE_KERNEL_EXEC and the strict permissions are only enforced after /init starts. This leaves the kernel vulnerable from possible buggy built-in modules. Apply permissions to individual sections as early as possible. Signed-off-by: Atish Patra --- arch/riscv/include/asm/set_memory.h | 2 ++ arch/riscv/kernel/setup.c | 2 ++ arch/riscv/mm/init.c | 11 +++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index 4c5bae7ca01c..4cc3a4e2afd3 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -15,11 +15,13 @@ int set_memory_ro(unsigned long addr, int numpages); int set_memory_rw(unsigned long addr, int numpages); int set_memory_x(unsigned long addr, int numpages); int set_memory_nx(unsigned long addr, int numpages); +void protect_kernel_text_data(void); #else static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; } static inline int set_memory_x(unsigned long addr, int numpages) { return 0; } static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } +static inline void protect_kernel_text_data(void) {}; #endif int set_direct_map_invalid_noflush(struct page *page); diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index a5cac440aadf..4176a2affd1d 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -93,6 +94,7 @@ void __init setup_arch(char **cmdline_p) #if IS_ENABLED(CONFIG_RISCV_SBI) sbi_init(); #endif + protect_kernel_text_data(); #ifdef CONFIG_SWIOTLB swiotlb_init(1); #endif diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index c888c4470b34..7859a1d1b34d 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -623,7 +623,7 @@ static inline void setup_vm_final(void) #endif /* CONFIG_MMU */ #ifdef CONFIG_STRICT_KERNEL_RWX -void mark_rodata_ro(void) +void protect_kernel_text_data(void) { unsigned long text_start = (unsigned long)_text; unsigned long text_end = (unsigned long)_etext; @@ -632,9 +632,16 @@ void mark_rodata_ro(void) unsigned long max_low = (unsigned long)(__va(PFN_PHYS(max_low_pfn))); set_memory_ro(text_start, (text_end - text_start) >> PAGE_SHIFT); - set_memory_ro(rodata_start, (data_start - rodata_start) >> PAGE_SHIFT); set_memory_nx(rodata_start, (data_start - rodata_start) >> PAGE_SHIFT); set_memory_nx(data_start, (max_low - data_start) >> PAGE_SHIFT); +} + +void mark_rodata_ro(void) +{ + unsigned long rodata_start = (unsigned long)__start_rodata; + unsigned long data_start = (unsigned long)_data; + + set_memory_ro(rodata_start, (data_start - rodata_start) >> PAGE_SHIFT); debug_checkwx(); } From patchwork Fri Oct 9 21:13:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11829693 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0C6B16C1 for ; Fri, 9 Oct 2020 21:14:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 818BF2240A for ; Fri, 9 Oct 2020 21:14:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LlYVT2Xt"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="jxqX9Ib3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 818BF2240A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EFyU15w+pQR3MQk94TN3Rol9+FXkj3AeeWwxNBLHNQ0=; b=LlYVT2Xt0vR3Ba3THucXtSTYa jsPaNFfYclxS9q1eD/xspzX1OTQhq7/25qReiOxOaSOYSe+dvv3/QYc3UqdEVWdJLnNpX0ASMhIlo 17SQ4tc9qIsa33Xhmt+qbHKAifq1slFdm9arX5Wf5Lg/RjLhjJcDvVyG+0LZY9yazsShDUbSWrmrr O6NipcvKJxJyazznWh6hY6v4676VCVm++sMLag7FJu5YZBwPsxv44p0rVwkQfiKTraek19sn7XYBg ynSqrzc07pIESPYnBMLKcHsj04eTuj5TMd1/KRtIkM4lJj3B2ZOESa7hc0X3XL39/O5H7IikbgOrA MwrK9b5cw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQziE-0004sV-DG; Fri, 09 Oct 2020 21:14:02 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQzi9-0004kL-J2 for linux-riscv@lists.infradead.org; Fri, 09 Oct 2020 21:13:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1602278037; x=1633814037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/rFWaVS2Mp29X2G5njahMGadr4BBV3Wqr3D/UpzWpM8=; b=jxqX9Ib3lPpMXjvo6JJBYJzvRmtq51oafpoukB1eeWh9aaCWBYSbiyjH C5UmjSBDxpkEsfjGqmTieG7WH/Slslj/eJpyLnnPjgGPyFAZ21d6ZENZE n+yWTLOXeeu4TV7ZubQ/AwlHywEgSSh0KiXNE2mk1s7DjboWQWBlL+fM+ dCdqseB9PflFU1YmS9AUosHjZSbecF5MR6FhHeRXdy6++ifJLhLWg8r6i mQ92Xl51bfhWbwmsDSBnYG7CcNOTpkABDBW5kLqgrg7WefFvvx4+SGiJY z6T8c1C3qQgX/f3M37kEa8dTJm2z+Ziuv2Z2kIKk3PsxYgn2DySzi5jR0 w==; IronPort-SDR: yKqN7uN1anlpKxsDgMeWi8EX8cGeagh66ll3hpqoE9wpPpWQt5TE9aj5FGF+5x/NhsqkAk5TlF mqDEmIOXv/XXDMlzaRh9GnE2CSCwkdiHdpY9chy3mIXNnGsrGW2NWUXe9EFvxJm5c/pMRao+Q/ CL2jMp44yj6TdKCiD9k9ocfMgDklNoHYH89xPCCsjNAqzB156qignvdACPNHI4kFiWEwS03ybf ubtE1Gbdp0YOG9QsAcO3HHG32/BO3jIxYRNC6pBqjXS14GudF2OHdw6Mu/DLJLIpgXS4AmDGKT xKc= X-IronPort-AV: E=Sophos;i="5.77,356,1596470400"; d="scan'208";a="149406018" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2020 05:13:55 +0800 IronPort-SDR: X+mRQPuXPVbJNkbfSz9S7dnmTN4K0vGAUTkX+naiMxSVs/EHz5Tj7qIzWgq2zYda7cExGDJFYU IYfeBT3dQfVb+shGJXB422KD4mavW4/8P0gGNB94QU6Sn67ITf0S02Tq2XeBasUOwZFaSM1qjH aZ9Twx1d4id9prdAXQLfSF1igPcNLLELgakKGauqJFMm/fBzQYZ4ISchv2geve4bdh315a554F BkBSfoAfx0pm4G5fhSZXQBJCsuwq22soxe3YuCdruhKqe0KPpc8tgv2prXBv1swMIowPsBPLbm PCHw80YPfOfl1PJmLwlO6F8H Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 13:59:42 -0700 IronPort-SDR: vm6/p5xIqey4ku5y72/6cCg/OOc897k5XjcVj4FdaEbbZDVCqcq4mtvLumHn2E24vNG6BFLfrL 912oWzPCuZmN2zDXb3PgxZBnOqpcCPq9fMDZBxTuUudr23AxRDHvlHa/zPDeiMfZxxDFhvTuky 7czWnLbJZ6V5eBNSjxQCyeAoKDbjENsMPgEGOrZXdrH8gm1AKioXf1z5JKxljqEWNrxJhp/uho Giuf2oHZim1ErI19qM5Uuo/QkTDEP+CwFfP7hmgoD3GA3kPXZTihlsKZfLn55pv/KHYwvJ9z++ 1UA= WDCIronportException: Internal Received: from usa003000.ad.shared (HELO jedi-01.hgst.com) ([10.86.60.38]) by uls-op-cesaip01.wdc.com with ESMTP; 09 Oct 2020 14:13:55 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH 4/5] RISC-V: Protect .init.text & .init.data Date: Fri, 9 Oct 2020 14:13:43 -0700 Message-Id: <20201009211344.2358688-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201009211344.2358688-1-atish.patra@wdc.com> References: <20201009211344.2358688-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201009_171357_812589_89B53303 X-CRM114-Status: GOOD ( 16.98 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.42 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Kees Cook , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Guo Ren , Palmer Dabbelt , Zong Li , Paul Walmsley , Greentime Hu , Andrew Morton , Borislav Petkov , Michel Lespinasse , Ard Biesheuvel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Currently, .init.text & .init.data are intermixed which makes it impossible apply different permissions to them. .init.data shouldn't need exec permissions while .init.text shouldn't have write permission. Keep them in separate sections so that different permissions are applied to each section. This improves the kernel protection under CONFIG_STRICT_KERNEL_RWX. We also need to restore the permissions for the entire _init section after it is freed so that those pages can be used for other purpose. Signed-off-by: Atish Patra --- arch/riscv/include/asm/sections.h | 2 ++ arch/riscv/include/asm/set_memory.h | 2 ++ arch/riscv/kernel/setup.c | 4 ++++ arch/riscv/kernel/vmlinux.lds.S | 10 +++++++++- arch/riscv/mm/init.c | 6 ++++++ arch/riscv/mm/pageattr.c | 6 ++++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/sections.h b/arch/riscv/include/asm/sections.h index d60802bfafbc..730d2c4a844d 100644 --- a/arch/riscv/include/asm/sections.h +++ b/arch/riscv/include/asm/sections.h @@ -10,6 +10,8 @@ #include extern char _start[]; extern char _start_kernel[]; +extern char __init_data_begin[], __init_data_end[]; +extern char __init_text_begin[], __init_text_end[]; extern bool init_mem_is_free; diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index 4cc3a4e2afd3..913429c9c1ae 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -15,6 +15,7 @@ int set_memory_ro(unsigned long addr, int numpages); int set_memory_rw(unsigned long addr, int numpages); int set_memory_x(unsigned long addr, int numpages); int set_memory_nx(unsigned long addr, int numpages); +int set_memory_default(unsigned long addr, int numpages); void protect_kernel_text_data(void); #else static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } @@ -22,6 +23,7 @@ static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; } static inline int set_memory_x(unsigned long addr, int numpages) { return 0; } static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } static inline void protect_kernel_text_data(void) {}; +static inline int set_memory_default(unsigned long addr, int numpages) { return 0; } #endif int set_direct_map_invalid_noflush(struct page *page); diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 4176a2affd1d..b8a35ef0eab0 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -129,6 +129,10 @@ bool init_mem_is_free = false; void free_initmem(void) { + unsigned long init_begin = (unsigned long)__init_begin; + unsigned long init_end = (unsigned long)__init_end; + + set_memory_default(init_begin, (init_end - init_begin) >> PAGE_SHIFT); free_initmem_default(POISON_FREE_INITMEM); init_mem_is_free = true; } diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index 0807633f0dc8..15b9882588ae 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -30,8 +30,8 @@ SECTIONS . = ALIGN(PAGE_SIZE); __init_begin = .; + __init_text_begin = .; INIT_TEXT_SECTION(PAGE_SIZE) - INIT_DATA_SECTION(16) . = ALIGN(8); __soc_early_init_table : { __soc_early_init_table_start = .; @@ -48,11 +48,19 @@ SECTIONS { EXIT_TEXT } + + __init_text_end = .; + . = ALIGN(SECTION_ALIGN); + /* Start of init data section */ + __init_data_begin = .; + INIT_DATA_SECTION(16) .exit.data : { EXIT_DATA } PERCPU_SECTION(L1_CACHE_BYTES) + + __init_data_end = .; __init_end = .; . = ALIGN(SECTION_ALIGN); diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 7859a1d1b34d..3ef0eafcc7c7 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -627,11 +627,17 @@ void protect_kernel_text_data(void) { unsigned long text_start = (unsigned long)_text; unsigned long text_end = (unsigned long)_etext; + unsigned long init_text_start = (unsigned long)__init_text_begin; + unsigned long init_text_end = (unsigned long)__init_text_end; + unsigned long init_data_start = (unsigned long)__init_data_begin; + unsigned long init_data_end = (unsigned long)__init_data_end; unsigned long rodata_start = (unsigned long)__start_rodata; unsigned long data_start = (unsigned long)_data; unsigned long max_low = (unsigned long)(__va(PFN_PHYS(max_low_pfn))); + set_memory_ro(init_text_start, (init_text_end - init_text_start) >> PAGE_SHIFT); set_memory_ro(text_start, (text_end - text_start) >> PAGE_SHIFT); + set_memory_nx(init_data_start, (init_data_end - init_data_start) >> PAGE_SHIFT); set_memory_nx(rodata_start, (data_start - rodata_start) >> PAGE_SHIFT); set_memory_nx(data_start, (max_low - data_start) >> PAGE_SHIFT); } diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c index 19fecb362d81..aecedaf086ab 100644 --- a/arch/riscv/mm/pageattr.c +++ b/arch/riscv/mm/pageattr.c @@ -128,6 +128,12 @@ static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask, return ret; } +int set_memory_default(unsigned long addr, int numpages) +{ + return __set_memory(addr, numpages, __pgprot(_PAGE_KERNEL | _PAGE_EXEC), + __pgprot(0)); +} + int set_memory_ro(unsigned long addr, int numpages) { return __set_memory(addr, numpages, __pgprot(_PAGE_READ), From patchwork Fri Oct 9 21:13:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11829689 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C98F1592 for ; Fri, 9 Oct 2020 21:14:06 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 132B42240A for ; Fri, 9 Oct 2020 21:14:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ykQ8cSML"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="W+1iEf1Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 132B42240A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bUQqLiTe6ENmwM4RRqizrnBDLcFTB0lgEXDOzwGIubY=; b=ykQ8cSMLgJaRcZL8c2gPiz9BL Pj9VP6Z5TxYiIjzohsnAToP8CEFqbL4mmOOc0+P5fKGJQxPCiDzAn+FANAm6BvcO3fWf/9tADU9ZZ X9J5VavQjKcGwEOCNcKI1irXOX+G32USVuMmeNo+YX+VbtdeS9stULFvhkxk0naYcPHYueJDqMXfn TaUGXiQPgtaETg1T3Y/GbYUUx3j+Eti+BL5omaga1Hc5NrnM3cYT4xvil9Wvh0Ff8xE9AxKV25xoB 0LVoC2huk8CZ4RD8sE0Loguj7iHLGXDr4yJ2QHjTG2bf01m5nXabQUP50kC5MxKeNQUYbopDZxjmQ FEP+lWuOA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQziF-0004sz-2Q; Fri, 09 Oct 2020 21:14:03 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQziA-0004kW-Fk for linux-riscv@lists.infradead.org; Fri, 09 Oct 2020 21:13:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1602278038; x=1633814038; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CEOo6JngBKtDuR3zNiPVEE237ISONrVcfU90kTdl4dc=; b=W+1iEf1ZTinqJmyI4y91+U0AkcOLMBCKxWVmMjMdaD6Mhf6zn5riUSA4 Fv1jIW2lg5d62x4mU496TbDpZjISu7Fv+2OEHqnFcqmCRRERi66EcbB2B tcgE4GMpxjdgcjLFeBfvIU2bZIlSMXm/YhLYavVqwRD/hAmYLcxHVyaAD 7obteQ6Kb7BEtQZN4vy5jGe/MslbvAj72pXhv+rn/fHy+gzL6eR4Bgyrv VlxnXvDYn9zpn234sdmAKkFLqbmomLcgaMGhbnF68rRa/rFrQFzDBe3/B lHas6PFVYK9uKorFuNZWixXdPVh2N/kBhPmDTyMiIFpC4Aa0lipJWqchl w==; IronPort-SDR: dgsg4SF3LsGIKlWIYEAbCNDCNRRzsh17JfSTlbYFd38MxytTq1nSc1bf9tq7a39tktp62zE9Su vfNpFSqqjGazGNqFkJd2dNikk9NCYWyTCjOqD0OrQD+H3UIgrn/G/uLyQqKyaFUJlAMOxNN67A y/hgJcO5bEfOhOluJ5pCzlzOL0sybzmxYnmmTg3xB4u663Yalq2ZgLoiTzwyeeEmBbhtjggnT0 GAoy++nKj8W+Y9j4EiR+pU88GNzWeLRECrfrEVwNxhcj/goEeqsoFMz6fGDzWMZPhwUknba206 a+s= X-IronPort-AV: E=Sophos;i="5.77,356,1596470400"; d="scan'208";a="149406020" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2020 05:13:55 +0800 IronPort-SDR: s8mODAAUNTK6Q/h8fFRFUMmAFE/nOAEAB+USdVPISUrYv3o8BB2tzATMEru8pykRqON2btyaCL m2ojxzgc+3N7NZ0HJWLasRWFhtsHCH6xsiYc6ln+k0SAbI3zha9RIjF24aI9PpW+YZnLXQJUo6 sypNUEbf4abmeJ+fEf6HY8SRmYVseuadcM6944qAT0+Ex3RiQbervDtyDHhEf6vdZtGVZplkHK 2RLy/pK6asJj/4YNLQUPcK2Ig1e3oCp7Eo4ZQtHT9ufevLWakZTs+o++b63Bfet2Ci2G08a58G +VKBl9Xl45cYD5AWmgxE7tIo Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 13:59:43 -0700 IronPort-SDR: xXNYNpuECda/K0oZVXImx5r+Kibd3x1J+MzfXjxi413udaVCYh0GU2b9kRFOJQn6wk7UK+WREx 6re5MRNGaGLYrVcdHJ4myYpM6ZmmwsiDeRlg1H1HDTmFSL3f4U/rI3hhlrx4QDGErN2QmVAO8g W30shVY2Tf7Pa4N3JshPtZyShOaRH4PWQRuUxGcwO/q8e0ZkuccrWJFe3QSBV55xw/1B6xWNps X2UT0lQgjuSXucitoPhpWdZf5ZcYabUQQrMLWzxL3t448DGDaNz9ugmCJChIyzUCsf1OD8dx9v Odg= WDCIronportException: Internal Received: from usa003000.ad.shared (HELO jedi-01.hgst.com) ([10.86.60.38]) by uls-op-cesaip01.wdc.com with ESMTP; 09 Oct 2020 14:13:55 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH 5/5] RISC-V: Move dynamic relocation section under __init Date: Fri, 9 Oct 2020 14:13:44 -0700 Message-Id: <20201009211344.2358688-6-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201009211344.2358688-1-atish.patra@wdc.com> References: <20201009211344.2358688-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201009_171358_760359_3B68F6A1 X-CRM114-Status: GOOD ( 10.82 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.42 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Kees Cook , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Guo Ren , Palmer Dabbelt , Zong Li , Paul Walmsley , Greentime Hu , Andrew Morton , Borislav Petkov , Michel Lespinasse , Ard Biesheuvel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Dynamic relocation section are only required during boot. Those sections can be freed after init. Thus, it can be moved to __init section. Signed-off-by: Atish Patra --- arch/riscv/kernel/vmlinux.lds.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index 15b9882588ae..4aedb4fd79e5 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -60,6 +60,10 @@ SECTIONS } PERCPU_SECTION(L1_CACHE_BYTES) + .rel.dyn : { + *(.rel.dyn*) + } + __init_data_end = .; __init_end = .; @@ -112,10 +116,6 @@ SECTIONS BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) - .rel.dyn : { - *(.rel.dyn*) - } - #ifdef CONFIG_EFI . = ALIGN(PECOFF_SECTION_ALIGNMENT); __pecoff_data_virt_size = ABSOLUTE(. - __pecoff_text_end);