Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp580649pxu; Tue, 6 Oct 2020 13:41:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhJv0T7bEmErb2W/TsTk//G+G76UJLoh4d6YXEa12zX0XhN59saEBKX1JItA9kzJbacaqN X-Received: by 2002:a50:9ec6:: with SMTP id a64mr7464588edf.382.1602016890738; Tue, 06 Oct 2020 13:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602016890; cv=none; d=google.com; s=arc-20160816; b=l+mDWFnITsiy5StXbCnWXN9UyKTXNCidB3e+ivEotjb+h9Mcz6cV5kZlMrqPPkAWUL Y85RZ86L9aADruo+pIdmTh3aT8a61PgVvbixf86maa/CqV2HSfMTpXgkgZbrk/kZ7xi+ QS9HZgAYY3k5P+wnG6m8c04IP0hE7ZvFaUlVtlUvAuIC6T8Scf3c03LJFUr6Nk41QKom nat2+NuTpvWhSd6ObMP2bfbucYk9BRMWkAuX82zqyZPtHJUiThOr7CAMfhqEtR8VtKw3 cL/dNvHJjFNHFQPNHVfwdEUFAMRVVAQebickNDbYCJGv8bTERfuPMlbyMf9Hjan6JmMk ETFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aP26k3iPNr1VpqvkggYcdxciq5A3h6k+A8ZkkiVk+vE=; b=qp/nQQ6kzGU9y3lBaaDG7ejSIsa+/yGqkuCQkdZ6DPnJQQtHkprjEvbiAjVSxJ7ct3 XuvkEV7HMU5w/37vgR8y/VSEY4VxTkqImcIQXFIVwJQ+PkK129Mv4JaJoU0Gpxfoqaj7 XlS60SbG1k4PMAu5UNqZnIqJbTIHHLgbI3zQiWPoF8eeroH1rLqzunVGrSH1l6sJ3/35 hHCR2kyiR235PuQuxI+Tfbj91qFwhiTtkWmDfg+c1G9sas7Wbt7kMNsrSFfvYIiTn+Nn Dflsq0kQm+r8bq+wFot9ek4w6UaFCZHizof8RxfK0QLrNQD3jphRKQLFXsBt9MkfrvjJ LgOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=ZS2TGe3M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a8si2978149ejr.157.2020.10.06.13.41.07; Tue, 06 Oct 2020 13:41:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=ZS2TGe3M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727342AbgJFUjE (ORCPT + 99 others); Tue, 6 Oct 2020 16:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727166AbgJFUjE (ORCPT ); Tue, 6 Oct 2020 16:39:04 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05BDDC0613D2 for ; Tue, 6 Oct 2020 13:39:04 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id y20so14473399iod.5 for ; Tue, 06 Oct 2020 13:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aP26k3iPNr1VpqvkggYcdxciq5A3h6k+A8ZkkiVk+vE=; b=ZS2TGe3M6BM2pCGvzZsvuQhQScVUluOJsnRH1r5i7A7P6n2UP7siMbluTKbkh4+efU UbqSZZ+fZQFwAS4BzVTQ+ar++o7dmdlQJ22yy7Dy/lTn9yWkfYz7e1qZyE9eKgBE3HSs q2vSZxGTu1hN+p8wF+jDAJ+KtO9L8yLq2iLt8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aP26k3iPNr1VpqvkggYcdxciq5A3h6k+A8ZkkiVk+vE=; b=K/9eWk79bSgY9MFlOC6tStORuYau50huW7+8hDajXgoV8jUPjNbK7waxXHPIylC4i1 Gs/ZFRzSziVpiEuJguwabEtitMkFhVIu4mHdb08OheDWkRuxAK6vNaRhyIpxT750cFzJ ENzNCgPrETfCJkkTwlKiK8vaDmf60LCJxSo+URCfRZ4Ag3pysozmneueSi+30Q8nShAi nnvn5+2CWSvDv8wi0owixrvYP6r+1zg6bmr3XtxK1TiwWZ2rAAxdJbJnTlaQ/YiLuW/S IrMkmtqh0O4Maztsi+yZ1ZHVE4EwmPmkjZpXix+FbkpNOxvfRd1zLC4X6Y/6RBQt2J2D p4zw== X-Gm-Message-State: AOAM5308IjC4ZYCXfNn6p6jTgxwNy5gpO0sVr2K+usUxwl+ARx+O6GUo 27gOuwzYwMKyM6yXHGCXbdNmPgE0veaZMJtqdXqB X-Received: by 2002:a5d:9842:: with SMTP id p2mr2700429ios.113.1602016743286; Tue, 06 Oct 2020 13:39:03 -0700 (PDT) MIME-Version: 1.0 References: <1593266228-61125-1-git-send-email-guoren@kernel.org> <1593266228-61125-2-git-send-email-guoren@kernel.org> <20200911204512.GA2705@aurel32.net> <20200914103836.GB2705@aurel32.net> <87lfgzeidk.fsf@igel.home> In-Reply-To: From: Atish Patra Date: Tue, 6 Oct 2020 13:38:52 -0700 Message-ID: Subject: Re: [PATCH V2 1/3] riscv: Fixup static_obj() fail To: Guo Ren Cc: Andreas Schwab , Tycho Andersen , Albert Ou , Nick Hu , Anup Patel , Palmer Dabbelt , Linux Kernel Mailing List , linux-csky@vger.kernel.org, Guo Ren , Zong Li , Paul Walmsley , Greentime Hu , Thomas Gleixner , linux-riscv Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 6, 2020 at 9:46 AM Guo Ren wrote: > > On Tue, Oct 6, 2020 at 3:14 AM Atish Patra wrote: > > > > On Thu, Sep 24, 2020 at 9:19 AM Guo Ren wrote: > > > > > > How about this, revert the commit and don't free INIT_DATA_SECTION. I > > > think the solution is safe enough, but wast a little memory. > > > > > > diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S > > > index f3586e3..34d00d9 100644 > > > --- a/arch/riscv/kernel/vmlinux.lds.S > > > +++ b/arch/riscv/kernel/vmlinux.lds.S > > > @@ -22,13 +22,11 @@ SECTIONS > > > /* Beginning of code and text segment */ > > > . = LOAD_OFFSET; > > > _start = .; > > > - _stext = .; > > > HEAD_TEXT_SECTION > > > . = ALIGN(PAGE_SIZE); > > > > > > __init_begin = .; > > > INIT_TEXT_SECTION(PAGE_SIZE) > > > - INIT_DATA_SECTION(16) > > > . = ALIGN(8); > > > __soc_early_init_table : { > > > __soc_early_init_table_start = .; > > > @@ -55,6 +53,7 @@ SECTIONS > > > . = ALIGN(SECTION_ALIGN); > > > .text : { > > > _text = .; > > > + _stext = .; > > > TEXT_TEXT > > > SCHED_TEXT > > > CPUIDLE_TEXT > > > @@ -67,6 +66,8 @@ SECTIONS > > > _etext = .; > > > } > > > > > > + INIT_DATA_SECTION(16) > > > + > > > > I think you need to move EXIT_DATA as well. Currently, we have init > > data & text in one section. > It's not related to this issue. There is two check code problem: Yes. But we shouldn't move only INIT_DATA_SECTION out of __init section while leaving percpu & exit data in the __init section. Here is what I have in mind. diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index 9795359cb9da..4432cef8184e 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -26,13 +26,11 @@ SECTIONS /* Beginning of code and text segment */ . = LOAD_OFFSET; _start = .; _start = .; - _stext = .; HEAD_TEXT_SECTION . = ALIGN(PAGE_SIZE); __init_begin = .; INIT_TEXT_SECTION(PAGE_SIZE) - INIT_DATA_SECTION(16) . = ALIGN(8); __soc_early_init_table : { __soc_early_init_table_start = .; @@ -49,16 +47,13 @@ SECTIONS { EXIT_TEXT } - .exit.data : - { - EXIT_DATA - } - PERCPU_SECTION(L1_CACHE_BYTES) + __init_end = .; . = ALIGN(SECTION_ALIGN); .text : { _text = .; + _stext = .; TEXT_TEXT SCHED_TEXT CPUIDLE_TEXT @@ -77,6 +72,17 @@ SECTIONS #endif /* Start of data section */ + __init_data_begin = .; + INIT_DATA_SECTION(16) + .exit.data : + { + EXIT_DATA + } + + PERCPU_SECTION(L1_CACHE_BYTES) + + __init_data_end = .; + As you correctly pointed out, this wastes around ~200K init memory that is wasted. That is not an ideal solution. The other alternative is to move __init_text section after _text as well similar to other architectures. But that won't work for RISC-V as we jump from _start to __start_kernel(in __init section) in head.S. A JAL instruction can't be fit because __start_kernel is now too far. We can't replace JAL with a JALR because that would require an additional instruction and violates image header format. Any other ideas to solve this problem without wasting memory ? > 1. static int static_obj(const void *obj) > { > unsigned long start = (unsigned long) &_stext, > end = (unsigned long) &_end, > addr = (unsigned long) obj; > > /* > * static variable? > */ > if ((addr >= start) && (addr < end)) > return 1; > > 2. /* Is this address range in the kernel text area? */ > static inline void check_kernel_text_object(const unsigned long ptr, > unsigned long n, bool to_user) > { > unsigned long textlow = (unsigned long)_stext; > unsigned long texthigh = (unsigned long)_etext; > unsigned long textlow_linear, texthigh_linear; > > if (overlaps(ptr, n, textlow, texthigh)) > usercopy_abort("kernel text", NULL, to_user, ptr - > textlow, n); > > The patch of commit: a0fa4027dc911 (riscv: Fixup static_obj() fail) broke 2th. > > > In general it is better idea to separate those similar to ARM64. > > Additionally, ARM64 applies different mapping for init data & text > > as the init data section is marked as non-executable[1] > Yes, it's safer to protect init text & init data, but it's should be > another patch. > Yes. I will send the patch based on this fix. > > > > However, we don't modify any permission for any init sections. Should > > we do that as well ? > Agree, we should do that. > > > > > [1] https://patchwork.kernel.org/patch/9572869/ > > > > > /* Start of data section */ > > > _sdata = .; > > > RO_DATA(SECTION_ALIGN) > > > > > > On Thu, Sep 24, 2020 at 3:36 PM Andreas Schwab wrote: > > > > > > > > On Sep 14 2020, Aurelien Jarno wrote: > > > > > > > > > How should we proceed to get that fixed in time for 5.9? For the older > > > > > branches where it has been backported (so far 5.7 and 5.8), should we > > > > > just get that commit reverted instead? > > > > > > > > Can this please be resolved ASAP? > > > > > > > > Andreas. > > > > > > > > -- > > > > Andreas Schwab, schwab@linux-m68k.org > > > > GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 > > > > "And now for something completely different." > > > > > > > > > > > > -- > > > Best Regards > > > Guo Ren > > > > > > ML: https://lore.kernel.org/linux-csky/ > > > > > > _______________________________________________ > > > linux-riscv mailing list > > > linux-riscv@lists.infradead.org > > > http://lists.infradead.org/mailman/listinfo/linux-riscv > > > > > > > > -- > > Regards, > > Atish > > > > -- > Best Regards > Guo Ren > > ML: https://lore.kernel.org/linux-csky/ -- Regards, Atish