Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4453028ybb; Tue, 7 Apr 2020 07:48:16 -0700 (PDT) X-Google-Smtp-Source: APiQypIDfOzlsCv0Crh9IRa+0sy7zzEwX2v4+wPWNZTgsrYFu8drgI9M/8sTuAiA4045TF/SVT/N X-Received: by 2002:a9d:4698:: with SMTP id z24mr1831629ote.271.1586270896739; Tue, 07 Apr 2020 07:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586270896; cv=none; d=google.com; s=arc-20160816; b=ZEBzfx87ZhLcvKxqVcFtOAIVP6jIIYMDYYmBrFM8v8T2GThoQRajxl7p8OT41Q/zH8 Z6/zzuWf3BVSP090T4M4t4j7v/CPGqKvyLiBR3Dbv8OkhZtDdPQKoSes7Ffku4FHDO0I bKQO4opL6wcEcCTbL96Vz5UGwWV/0KcncXMXn6wN+gE0Q0DsfZ9LQrMwt4VYx7jG+vh2 9bS+YT1tu8IuhpseIrmew4aTUqmDk0w3OCgMZGjvpeYE5OvME6gWdaFIS4SX92Q06K2M j2kPOq/Nyxcd9mkovzvGKOXlsGtnZb5P+RFPLyy1jwYmac1TTYI7TVfhlesOj/D08yjF dxbA== 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=geDMvpdyp4eREUjGenxPiMAgszPzsf8hdgTrRUcyDVI=; b=Y2Y0JRS2kjy36pRgtqB7M/4cKz0THd8gD6AKym5vOZQ+Ry83E988yCaYRgxYjVvq8a QioVd61fxR9gs7TNol/2VNTK+ChX3w3Tg/j20nJF96JOHFbJQ3hE+zADi+3O6BnKZ+eC VkVhNE0TpL/OrdUYTZcT15MqDW/ovGVVz8AgXtaSL8JiQLCaitQv38VBsWD3s14VKN4p 4BiPrbOUOEWGExMrG3YujTjOZtS6rZDguNkDkf3VBi/kWrGpQSXt1LETsE26+sVzvfjL /3FS7VdfaBGs2nxHi+SYWSaESxG/8khlxHgUxB6+83Kd+2Rno51lCLXZaX0paOd3R9C8 uTgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=JBxizfUV; 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 t2si1218703otb.284.2020.04.07.07.48.03; Tue, 07 Apr 2020 07:48:16 -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=@sifive.com header.s=google header.b=JBxizfUV; 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 S1729367AbgDGOrS (ORCPT + 99 others); Tue, 7 Apr 2020 10:47:18 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:33700 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729344AbgDGOrR (ORCPT ); Tue, 7 Apr 2020 10:47:17 -0400 Received: by mail-pg1-f196.google.com with SMTP id d17so1844570pgo.0 for ; Tue, 07 Apr 2020 07:47:15 -0700 (PDT) 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=geDMvpdyp4eREUjGenxPiMAgszPzsf8hdgTrRUcyDVI=; b=JBxizfUVQ4VwCje90RdukKZBh/ywXEy+VAtWwgau09WHsbrygimeUgLaDGNihbFdPZ eDybrac2/Ma3vtwVtZ+dV10ejldg12V79mPPn+6PEcb+pYiamkJfHvdVCc3pQywEgffS 61nByA/bmGC+KvIQ961VXAVS+jeOKfdvsn2YvlzRhS4+b9g+s7hBJOhV9Zurmg6tfc88 hRFeb/pdtnq4jQdvIW1maqRVT/GoZMh6q3OCXYlUAxtVz2Sa7KW7AhM451d55reG1kbv bdvnAWUvHjr7PiJ0CRL0hEJnBVdf4VVNAcT2NTV9xOdaANofRCoMNuG4j0Ia+W6wAhRU xUww== 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=geDMvpdyp4eREUjGenxPiMAgszPzsf8hdgTrRUcyDVI=; b=PDD+Wp1b4qdo/aC5XpAIHJ8i2ULXGhhUh0nY5LVwinExX6VVkivLQgimS6RXsRkRH9 9m8lg0fZ8b1mreDEua8dy4kKJzxXPQndPgDO2o2tCmqY5nOGavljq+AyRuy8Yn9KHvQQ rtklDlZNMMeDmKCxVNe8Rqu0CiaZ5uEqRRIUMYVwZYfDONLchU1Jv5lC5wlSbjvKxFud nU7dniQTItKIMPyrPVDtzOSFcBNPVpJ1wf/nPK7dE81oXcyvWFOnzI6LenqZdaL06RIy D7w/F3La2MkiVolGCyxF2oqfQbX7EYU2QsXOsjovPJsDKd8P1WhWPQissFncGlPUpwLM mz7g== X-Gm-Message-State: AGi0PuZ6tW8rIyB1tzMIBHteVrVyz1PyIWRAmWc+IfIVEXw8ogkUi41R ie4fTZxWAV4K6DIDib0Levlbwg== X-Received: by 2002:aa7:9a08:: with SMTP id w8mr2724871pfj.317.1586270835251; Tue, 07 Apr 2020 07:47:15 -0700 (PDT) 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 y15sm14190093pfc.206.2020.04.07.07.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:47:14 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, mhiramat@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li , Palmer Dabbelt Subject: [PATCH v4 8/9] riscv: add alignment for text, rodata and data sections Date: Tue, 7 Apr 2020 22:46:53 +0800 Message-Id: <24d705447a3033ee94c3dc9687b97870e2521090.1586265122.git.zong.li@sifive.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: References: 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 Reviewed-by: Palmer Dabbelt --- arch/riscv/include/asm/set_memory.h | 13 +++++++++++++ arch/riscv/kernel/vmlinux.lds.S | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index 620d81c372d9..4c5bae7ca01c 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. */ @@ -24,4 +25,16 @@ static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } 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 02e948b620af..ef87deea0350 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -9,6 +9,7 @@ #include #include #include +#include OUTPUT_ARCH(riscv) ENTRY(_start) @@ -36,6 +37,7 @@ SECTIONS PERCPU_SECTION(L1_CACHE_BYTES) __init_end = .; + . = ALIGN(SECTION_ALIGN); .text : { _text = .; _stext = .; @@ -53,13 +55,14 @@ SECTIONS /* Start of data section */ _sdata = .; - RO_DATA(L1_CACHE_BYTES) + RO_DATA(SECTION_ALIGN) .srodata : { *(.srodata*) } EXCEPTION_TABLE(0x10) + . = ALIGN(SECTION_ALIGN); _data = .; RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) -- 2.26.0