Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5081035ybf; Wed, 4 Mar 2020 16:59:15 -0800 (PST) X-Google-Smtp-Source: ADFU+vthUS2Zbf4mp28yAwKzpPhuWL6yG5DPWVcMQQIrw4Wg1yVQHVDApIBY6gep35paOq+Hzjnw X-Received: by 2002:a54:4396:: with SMTP id u22mr3781832oiv.128.1583369955189; Wed, 04 Mar 2020 16:59:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583369955; cv=none; d=google.com; s=arc-20160816; b=o1VRyLrNKc8neq60HeMpi6oGU8bSEQsxJ5IkjeFiAUf2PPE69cp8TQc1VL7qZzA9hp SZFOvW9/nMd+Th3BYqI4zx41d1pD4Pd/5GnFF471qrbgDSYHdUAoBZ1eiKYgt60JIJJQ Z8XAIHCAM4CVlsIPrqBu149i23jZ7vBZBZxWAQbPqinmFdkaf56ly/s/vTSZKe0ugHRp 3003utFDVeg3jA7X5TG8pav3z1iks4kyec+frrlgIKVbghtcfXONbwJf710sHlWwPAJq ORl2ww88aRl8QXCQfvbYYhzs9Ix60qAzGj5hMqrNhn1eCKOoMgBbwrrWLff+pGUGfpPk cszg== 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 :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=HhIcP1OmX7KCJe/LzPGyLrrs+To5FwKg4wadhbBvhh0=; b=uIrHtYwN6LR4MLyaTHyAEoX3zPaYS8oAvOiz9e1NjAO9qsacdZKQ5FlcLuc+ZWxD9H H9dA8KGLweqG23c4ba+qusgKMxjWve5jhR1tcC8sQSpaUZr28m59Pr4cUhk2XlR5ACSM NUXzVCoTsX1wo0MyQqxwvv5U46g02dXn+zXf28+jIvIYGFgVSFmsZu2Gu7Y6e0ytL2zE ET7KyEtP4at0ebk4tOFsTuKdGXkrdmZH3rSy/juD6OEiUpk8iXUkfrEZNuADJbH3enn/ 5bAUE++9A+MjkDWnLqSV+R4fQt2E511eXNRZz0wMvD363Yzt9uJ7MxC51AjrNCalamB7 IvEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=Aq2qqLvb; 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 x14si2196670oto.221.2020.03.04.16.59.03; Wed, 04 Mar 2020 16:59:15 -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=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=Aq2qqLvb; 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 S1725912AbgCEA6r (ORCPT + 99 others); Wed, 4 Mar 2020 19:58:47 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35627 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbgCEA6r (ORCPT ); Wed, 4 Mar 2020 19:58:47 -0500 Received: by mail-pg1-f196.google.com with SMTP id 7so1881078pgr.2 for ; Wed, 04 Mar 2020 16:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=HhIcP1OmX7KCJe/LzPGyLrrs+To5FwKg4wadhbBvhh0=; b=Aq2qqLvbqlU5Kjj4F0+/BOA9infgEg+KgkHaarF5Qd364tds3v0rBe1kM6S1n+VRFQ KMbfEg959bSsq+g+BpJ+T5+0ObvEBeIPAd68I1k5uwjBYzsS1RX/pM6xaA4Wlf0etwy9 z0ZF3cd9owkVC8se+XXBMIhOnUaUIEbNAptYSZMYxA+LoO4r04W9v8y8hw5xP2vV2fSd QB2nUS0hM9b3vsJeSeCh6VUmJcY2DSKkaubpIE1gdKZOmxvydMTwAUx5NWgbQSgfUfBs B39SyxjVf2MrSiaU02IvghnrbuCMuy2SW3FUPjkTeMYflYtZC8xIAFCvW3aTW2GnVUjm JFJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=HhIcP1OmX7KCJe/LzPGyLrrs+To5FwKg4wadhbBvhh0=; b=EQ7A2CkcqvQ8sYUsAczIXp7BvIu7qcfId5/26uh4ppKsZGaq202OXppg8Yi3Ue2CdM FkxAo0ToHUcNI6qdSwJKtxuBVDBtbI1m5Nvuk0y5ZDYyI8ftlDIFrJmftQv1lnuW3Zqr SqQQQmDOPX8kV7fKXjJErm8FFgMSXDXAurhLRknbyqCMZtLTO4PuJLmpzxprMd/Pjyvz KX/PG4UXLBl2Ac6/oWwjDz5O811OftWtQUYfFqw7ouE887QyZHZm8fi/HD8CLNb1Yfi1 tfhrALnVUKXuQQ9LUOpCz3cRYnsHqG3X0nGpEpV9UZR9qJk9OWO9hPEnI0e4P7xmGO/M FXRA== X-Gm-Message-State: ANhLgQ0zFaasH7Xxz50xTbT2ZZeI9VUPywvUgM0SIj+CYPVeUImjmZB2 HwvwiGoOvwFJdMsW8Iyzr8KZVg== X-Received: by 2002:aa7:8687:: with SMTP id d7mr5703217pfo.164.1583369925861; Wed, 04 Mar 2020 16:58:45 -0800 (PST) Received: from localhost ([2620:0:1000:2514:23a5:d584:6a92:3e3c]) by smtp.gmail.com with ESMTPSA id e9sm3910889pjt.16.2020.03.04.16.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 16:58:45 -0800 (PST) Date: Wed, 04 Mar 2020 16:58:45 -0800 (PST) X-Google-Original-Date: Wed, 04 Mar 2020 16:58:05 PST (-0800) Subject: Re: [PATCH 5/8] riscv: add alignment for text, rodata and data sections In-Reply-To: <20200217083223.2011-6-zong.li@sifive.com> CC: Paul Walmsley , aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, zong.li@sifive.com From: Palmer Dabbelt To: zong.li@sifive.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 Feb 2020 00:32:20 PST (-0800), zong.li@sifive.com wrote: > 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) Reviewed-by: Palmer Dabbelt