Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2641255ybh; Mon, 9 Mar 2020 09:56:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuV8beO1rh228swGQ1GF0uRlCrwS8n6JFnkNpBW2KDvaMEpvp0HjW1HXo5/NLmofFwt2MJ4 X-Received: by 2002:a9d:6949:: with SMTP id p9mr13410450oto.364.1583773007246; Mon, 09 Mar 2020 09:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583773007; cv=none; d=google.com; s=arc-20160816; b=YnG79EEFEoh9EBbOEipzDggz2wQ/5luEcTKWfsIYeYQ8gfVd/SiNhw5JU4diLJwUqy DYOlQuDlplB19FS1kdKR1zFCx3rjsvarP38Ararzv5iVNPjn6Ipd62RkpcOF5sn1sP4V X9OAFigbSXGA9LkRDmcoSAc0PyE8cR5JXLHonx+5DWrIbgziAbHfLgTXuywnjB4799qo 2QHEcwFnz3DmRLn3p0tR6xo2BB3K3KRgFBNso8Xslu+xCNhU8gy+pmYfOP0zlAm5VAkX 53NwzAtJJ2tukAGiOIySPryvp6XXZUkKi08GxfdO2Z8gHh19KrXF9NFoOJ5GQQjlsWsV SSmQ== 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=eOvGoomldlItgrTMe3b4RPvPtMpqmI4vOPIxgU5N5dw=; b=HBL4KrLu3b/x3VE6abkIzCYNhH/wRQylqDDP58AURWK+4JmCLcDr6uq5gCynO3wTBe euC8GLrAxXStZyEjWHeOTKDw7wWMPjpNKt6s5D4eH9kbDHy0SFtT1HCgPQYey8CmjJEQ POVnuERALnAHQzQ+ZZdTkQit9Kg87ZWMEj7rMy1tCCsMdUnwiYCi/hME/mRwFiQP3MQo puNBptKWq4+PIjA6BqtfKqdLiGdGWBm0wbsFyZkFfLdBeuCfsr8Yq0CiBy5tY2AEdySp saJFLU9AYG+ziF7Choe9kO2QVqtvVLp/wg5MQa0Z4NcLo9Xeyn4E5pOBgfkyWEczknXz 7WdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Sx5t7i4q; 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 s27si673177otg.229.2020.03.09.09.56.35; Mon, 09 Mar 2020 09:56:47 -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=Sx5t7i4q; 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 S1727349AbgCIQ4G (ORCPT + 99 others); Mon, 9 Mar 2020 12:56:06 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:51923 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727317AbgCIQ4B (ORCPT ); Mon, 9 Mar 2020 12:56:01 -0400 Received: by mail-pj1-f66.google.com with SMTP id y7so115130pjn.1 for ; Mon, 09 Mar 2020 09:56:01 -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=eOvGoomldlItgrTMe3b4RPvPtMpqmI4vOPIxgU5N5dw=; b=Sx5t7i4qo7aZC3e6rBAaMwJOSvAe94WC6mvx/MQEjX+d/7LAbkmXgEXeV1meT/5Rgx WQYUaQkMp2UN5BeERTN/yq/g384+aAor82Dq3CQsz8s3fhSQIgfhNA4Mog8V77Psp6KN CE8ZLqsaaRqY+gH5n7M+rHmJ6CmUOak7gZ02LWQbYgTGSKbPkQ2hmDWSDeuHYUR+lvm9 Dz5+6J7fnjLxSNK333c7nXq2/D0eJWn6+RIhnWK4bWLBb1ztsE459vR/CerehyiWRdS8 BiNmV3bfU/7SPip+wqhSyQR3OZckv4l7CqoOwRNyqHSIHlRL5P0s8GQtv38mgDU68BAn MFQg== 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=eOvGoomldlItgrTMe3b4RPvPtMpqmI4vOPIxgU5N5dw=; b=DKBrEiVmoYmKpX28kzL9YfN+Q4mayYJQER6pZAqL+nc93wIxhjK5CHZkkkYBPgcroY OES9tyWUp/qKGJT7ks3xw8NqK3v+wmj03aC3U2ZBseJ14srDAPzpw01i3vF5fuR+0ej+ aSHCT0DVoI61N0NdTOMd1cUyn2EwWHIi51OXcLMzjc7TlVUpEO8fz/cTaiUF0V5EOCFV E+7ZZ1+BQi0DiFFJ1Z7adhHKS6a8HJX01GDXMBju5VUDr1XDIjxC/wLqvRI0Gx2y1EzL u4o/gaRbFzuBZ+sthWzBeftajJFIpQJrCYbWOTydGyXhrpn/456s4s5Mz+UFeqC6h7bC DhFA== X-Gm-Message-State: ANhLgQ3goUsu4pNo8hx7rNW/+6/6bf7eHdtMQXZ5lYDqpNQ3BAcM6RnP 496XqWERTp+0oYtMuDFStLMwvg== X-Received: by 2002:a17:902:b485:: with SMTP id y5mr15847694plr.4.1583772960751; Mon, 09 Mar 2020 09:56:00 -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 cm2sm104013pjb.23.2020.03.09.09.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 09:56:00 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH v3 5/9] riscv: add alignment for text, rodata and data sections Date: Tue, 10 Mar 2020 00:55:40 +0800 Message-Id: <0e60e503eefbebeb9c9a24a125feef876a80c148.1583772574.git.zong.li@sifive.com> X-Mailer: git-send-email 2.25.1 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 --- 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.25.1