Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4522955ybv; Mon, 17 Feb 2020 00:33:27 -0800 (PST) X-Google-Smtp-Source: APXvYqzorSHxfN7DVCRnxqYLvS2M+XQ63YYPmO1QeV1H2CuvKl2YuyKBd7E777Izw9InRe/iqDtT X-Received: by 2002:a9d:6301:: with SMTP id q1mr10949322otk.299.1581928406670; Mon, 17 Feb 2020 00:33:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581928406; cv=none; d=google.com; s=arc-20160816; b=hHjf9f1Edym81N7gBabpT/iZ+VGdI1wGU7Pkhu6g4vAks9nlyxcyZgPdwGkx64CayS dQpYFt1Bzq4RRbStq8yYNSlHeVnHOsxpaP2Rp+8GNcz8YPsBGL4li5Q0Z1RW2A8hfrjd xUWI6yCES/kzu+fLFekatI8zPHYnD0t9at33GjMnMsojEcyJFNKzTcglmIiD+gRyvV7Z Td3Ym3mJSUpHEoJkPmYHSGBsf/lwJEPd3TYb1sv900cBTx8zvSt7os2rThupGbkUUEDB TfOX6srsykQJuBxu9J4pYl2+BtCxUrb9f7Stjk+aqxoEcyy1fqfmJbIgxSc2wXACkoRf NN+g== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gPsxu3vF78VOjjNcgLn5UDiKYUv2stj5MGhKdcRPAdc=; b=VbcPJWerp7FlZT0NrswRTpAGbaOjHuZl3GnI7JLd62MToZDTIVHbd4yXJtKuQ/XQ8q EwMiiosMSFaIwTgcOOULcYVXYmNPHi5Um5uphStCaWHO6WA3icrxveVdjlXVPNwtrkoj KqW2lY3cLWG6RKlFCrdnnPwZBeAfz7A1lU4ZYcELqINr6GTvLJhMX2NuWdSQFuWZdfWW fA4GA1wgNC6oHb+rWEx/irYahV9dqI755ykd1RfLSmk/5TQ6j7WCbWV/cpZvs/BtYRaq qWAF9zeOb1ODrzecDD98p16sPn8E0FKzYTjYNLzU4CLK9wCLi/8DtaaY3r03iZdpsQm2 Sjzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=QqfINpR4; 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 d15si6641313otl.82.2020.02.17.00.33.14; Mon, 17 Feb 2020 00:33:26 -0800 (PST) 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=@sifive.com header.s=google header.b=QqfINpR4; 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 S1728378AbgBQIck (ORCPT + 99 others); Mon, 17 Feb 2020 03:32:40 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37088 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728363AbgBQIci (ORCPT ); Mon, 17 Feb 2020 03:32:38 -0500 Received: by mail-pg1-f194.google.com with SMTP id z12so8683645pgl.4 for ; Mon, 17 Feb 2020 00:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gPsxu3vF78VOjjNcgLn5UDiKYUv2stj5MGhKdcRPAdc=; b=QqfINpR4S7uL5kzHi8zrFcEKpS0Hg6u0xhWvKZCxhOoVT8L95+H0av5sZv8SMIac4L m9Y32Pb60l6i1c8EfoTohasGi8mVKDbPiE0EDl1u6VhnGCKibAoT6zpoy+iy39KUZ04/ FUQBEUjTIyi+2LGaFqST+8rSr2NfpNuJzZUgUftU5yT2l2zNwxGg2krVwXx0x92LIn37 b8pR/IMMdGiJbQhsUJKH8Tl+ksvjKtjFBw4uZH39UnW+/bsuwYxlExwcEn7Ipy/wKW2Q AgoGrRI8Xr92quYiRyKvvcFt82qn06dATL7pOG399TqQvwYf4d3HOxfXR/ALUQqKVLEb BzuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gPsxu3vF78VOjjNcgLn5UDiKYUv2stj5MGhKdcRPAdc=; b=jqPmgRtCBB6PabUWwWiIjvGWuxmgh8CtOd7p+AYq95EsraqayfmWVvlgXOFS2GgvYV jQ6b175/dr01uBp86Wo7sgdsEJt1GW7P3E34uPGVDGh2G+Ltdqkti0OqjUOLv88cr7tY oLVRQTnxdqzTvkt9oLeRNrysF/xWRK22Uw1bJ+EYTnxPnjHtDraq//PQUZsJffCxdzRq CQjLlUi5VrwbQyxmJKqSYlAD0R2+Vg4ZQhlQzJ/rH4+x1MAsZkh6WraauaJZMnJKQTUj MrUCpGOQRAlVg9UMWGqjIJMATzC2gCzqgnuDGOjCmiBoitRgl9WlupfgsCaXpVXSo9ki Vfzg== X-Gm-Message-State: APjAAAUj0QlrCTYF2AoVfpq4OxEwwtjh5FhySP9eCEgHhSWw0OerHvRh 9AwxBpj0U7WZD7TcqJutVYP9jR8Zets= X-Received: by 2002:a63:6441:: with SMTP id y62mr15877518pgb.86.1581928357485; Mon, 17 Feb 2020 00:32:37 -0800 (PST) Received: from hsinchu02.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id z10sm16989319pgz.88.2020.02.17.00.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 00:32:37 -0800 (PST) From: Zong Li To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH 5/8] riscv: add alignment for text, rodata and data sections Date: Mon, 17 Feb 2020 16:32:20 +0800 Message-Id: <20200217083223.2011-6-zong.li@sifive.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217083223.2011-1-zong.li@sifive.com> References: <20200217083223.2011-1-zong.li@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kernel mapping will tried to optimize its mapping by using bigger size. In rv64, it tries to use PMD_SIZE, and tryies to use PGDIR_SIZE in rv32. To ensure that the start address of these sections could fit the mapping entry size, make them align to the biggest alignment. Define a macro SECTION_ALIGN because the HPAGE_SIZE or PMD_SIZE, etc., are invisible in linker script. This patch is prepared for STRICT_KERNEL_RWX support. Signed-off-by: Zong Li --- arch/riscv/include/asm/set_memory.h | 13 +++++++++++++ arch/riscv/kernel/vmlinux.lds.S | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index a9783a878dca..a91f192063c2 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -6,6 +6,7 @@ #ifndef _ASM_RISCV_SET_MEMORY_H #define _ASM_RISCV_SET_MEMORY_H +#ifndef __ASSEMBLY__ /* * Functions to change memory attributes. */ @@ -17,4 +18,16 @@ int set_memory_nx(unsigned long addr, int numpages); int set_direct_map_invalid_noflush(struct page *page); int set_direct_map_default_noflush(struct page *page); +#endif /* __ASSEMBLY__ */ + +#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX +#ifdef CONFIG_64BIT +#define SECTION_ALIGN (1 << 21) +#else +#define SECTION_ALIGN (1 << 22) +#endif +#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */ +#define SECTION_ALIGN L1_CACHE_BYTES +#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */ + #endif /* _ASM_RISCV_SET_MEMORY_H */ diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index 4ba8a5397e8b..0b145b9c1778 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -37,6 +37,7 @@ SECTIONS PERCPU_SECTION(L1_CACHE_BYTES) __init_end = .; + . = ALIGN(SECTION_ALIGN); .text : { _text = .; _stext = .; @@ -53,13 +54,14 @@ SECTIONS } /* Start of data section */ - RO_DATA(L1_CACHE_BYTES) + RO_DATA(SECTION_ALIGN) .srodata : { *(.srodata*) } EXCEPTION_TABLE(0x10) + . = ALIGN(SECTION_ALIGN); _sdata = .; RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) -- 2.25.0