Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3003515img; Mon, 25 Mar 2019 01:32:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyz0jcZILGsoF6kK/t45wlcVLeLiafxTpu/bBotrgF/86Gf/DaR4AGH+uyPF9nkYQymIesC X-Received: by 2002:a17:902:203:: with SMTP id 3mr24252687plc.336.1553502733037; Mon, 25 Mar 2019 01:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553502733; cv=none; d=google.com; s=arc-20160816; b=OH8InX7XnxnfSAtq5XJ+2BD3AjzyNggxZ6gP8ITozkm/G5uok+E0bI3x3K5D1i+bUp e4WNC73JoxjWdZweJXWzuqoU57Vs3WVioRdGGAe6rPikN9vqkBuiIQrie+/gt/mKu52u KS+IHq5rmjQB+u3WaHCWXQxSUNM6WDO0rgHd1c27E0KiLhCz1/6sgFhGp1u5KU+wZx7k AMs2zodO1DNIxkueWsSRKWHYZvEGlayM8hW/7r6gOyZ3FEcW1JbDBJwLXRsEASItH5Ow 22bmfMlPjojTPpbG4p4K4oGRkx2ObB8BqwJBnx8nUugUjTTyHvhzfrynM7AF5Dj9w3Lv IgQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :wdcipoutbound:content-language:accept-language:message-id:date :thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-signature; bh=LmAnGsdt7VyN6Ue2euAp9ivZV3nKKYSniXsXBU4avgY=; b=n9jrRN7RwrzLXhEfs1XdC4P2FMr3rFgQm12EdEArFaLR5XpVrEgnYM181S0FpzjaPZ BaYyYT4RmEERuu2ImxWAGPnLD7ccJaeCC8cnWnw9K6BODS1nW6gSzkQGWSuG4BarUCDU 4sfThqhj2zgpfm5oVk1NUZwVocEb861Vwdz4PuxBqC3jrFK5CemslTBVUchfBEZzRxby LkYolk5SZmsv7qKU12HHmTpW84pPOC+CzfUp3aS0JZXTPe7igXRWDQETmQD2gZ3/FzgJ qw0Hcipi3YCCViyTa46mroNap1t0hAEfUuOaDddXEj1ujoPMr294aykNHcJU1t7qjYG0 XSWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=iCBCIG5N; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector1-wdc-com header.b=dhkj1p4g; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q18si12802546pgh.498.2019.03.25.01.31.58; Mon, 25 Mar 2019 01:32:13 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=iCBCIG5N; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector1-wdc-com header.b=dhkj1p4g; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730030AbfCYIbH (ORCPT + 99 others); Mon, 25 Mar 2019 04:31:07 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:48530 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729823AbfCYIbG (ORCPT ); Mon, 25 Mar 2019 04:31:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1553502666; x=1585038666; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=J9LvRr+UrUvy7PKQS/6b8Vr10RQixb2JocXKeByuXBw=; b=iCBCIG5NLCElp0m6Ruy4VKbG3cJOzVMFG6BRbho3yiEjHYJ14rYUbaR3 aYaZHW8/tLx/v5AyhUhr+WHFsscffkkE8/bt4p/Gyx59/a8NlR2EeQzze r9Au27k+5szHbL0NXzVfPR5lUCzSM8scdo7w7x4d+wcdM6WoO/ZM50WTj ICQoYjjRoF+wVR9W8VOX07ZvOP147bsQpeXMiLyoPf+zwL7IuxPevzXu3 Lff1iQhCWVH53QCoFxxNQRLSag3lgv+M42ThGlWlpMb2IDE4uI1NkZ/Z/ UlU3vLLx+JCy+nvvxLwicOJD7TXZes4+RefaNPm1EfCk8Sv6Q6nblgwKR g==; X-IronPort-AV: E=Sophos;i="5.60,256,1549900800"; d="scan'208";a="209756303" Received: from mail-bl2nam02lp2052.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([104.47.38.52]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2019 16:31:05 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LmAnGsdt7VyN6Ue2euAp9ivZV3nKKYSniXsXBU4avgY=; b=dhkj1p4gMOU0YqduevVIc5MxniXoh6nxC+lepwxN73WCd0GcOSCdSHGpSOipAg6J1FI6jOlDQKEzJAYIqeSb3RZdmCMimVHXDXcpV5wF4aRH7gA5rpmNjDoF17rQXG63XsaRjBbbztlawhShFNx6lMiql04LRH6M2EvDsGZDKgI= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.246.15) by MN2PR04MB6125.namprd04.prod.outlook.com (20.178.248.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.18; Mon, 25 Mar 2019 08:31:03 +0000 Received: from MN2PR04MB6061.namprd04.prod.outlook.com ([fe80::d197:7b59:7e0d:e819]) by MN2PR04MB6061.namprd04.prod.outlook.com ([fe80::d197:7b59:7e0d:e819%4]) with mapi id 15.20.1730.019; Mon, 25 Mar 2019 08:31:03 +0000 From: Anup Patel To: Palmer Dabbelt , Albert Ou CC: Atish Patra , Christoph Hellwig , Paul Walmsley , Mike Rapoport , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Anup Patel Subject: [PATCH v3] RISC-V: Always compile mm/init.c with cmodel=medany and notrace Thread-Topic: [PATCH v3] RISC-V: Always compile mm/init.c with cmodel=medany and notrace Thread-Index: AQHU4uUVvhvO5bM920yk8A0vzDmtRA== Date: Mon, 25 Mar 2019 08:31:03 +0000 Message-ID: <20190325083027.6393-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR01CA0127.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:35::21) To MN2PR04MB6061.namprd04.prod.outlook.com (2603:10b6:208:d8::15) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Anup.Patel@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [129.253.179.161] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bca2f778-2038-43c5-a786-08d6b0fc37bf x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);SRVR:MN2PR04MB6125; x-ms-traffictypediagnostic: MN2PR04MB6125: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0987ACA2E2 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(376002)(136003)(346002)(396003)(199004)(189003)(486006)(68736007)(52116002)(2906002)(99286004)(71190400001)(71200400001)(97736004)(105586002)(54906003)(110136005)(4326008)(106356001)(2616005)(476003)(316002)(44832011)(8936002)(26005)(53936002)(186003)(25786009)(36756003)(3846002)(6116002)(6436002)(50226002)(7736002)(6506007)(386003)(256004)(14444005)(6486002)(6512007)(102836004)(2171002)(86362001)(66066001)(14454004)(305945005)(478600001)(72206003)(81166006)(1076003)(5660300002)(81156014)(8676002);DIR:OUT;SFP:1102;SCL:1;SRVR:MN2PR04MB6125;H:MN2PR04MB6061.namprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: LXhHfB9ZyIG2/r7VPX6GvHiWD/bPlD2XsXpQ0Mc/S2rIaRhQa/FyELFwazHyx13WS8tiRTOKELg0gzK+xfjwBFCQKjgNW7mydg80f/1r6/KhU9BNacKMQqLTnqUsgkhWRu+jcl5BAQ1PJizyGQBIZ1tYmSLk7KEsyPCoZw1i71WwtzPhMotpckTfmjGPLM1nD+39z6ohR76xXRmG3pDx4gFlLZOYtWTHDRyEhOAvfCiqZ6HMbKS5oFFx1C6M+1I87uwXC+wJ9o1omT8YR0lDB+u+oPOOWpDvR5sp8kUpYa2XnIdylSwjDR+ljEdgVmOzIKlOl1MSs9VzgJdVGCnVxE1TWEvkZ1eY6RjXtOMGNHdM2fSV8uKpmHNn13weZ9du3k6Bp3a0vsm5ERqWPcfIjI/msqvBqmLhsKN5vOvPwQw= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: bca2f778-2038-43c5-a786-08d6b0fc37bf X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Mar 2019 08:31:03.8081 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6125 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Linux RISC-V 32bit kernel is broken after we moved setup_vm() from kernel/setup.c to mm/init.c because Linux RISC-V 32bit kernel by default uses cmodel=3Dmedlow which results in a non-position-independent setup_vm()= . This patch fixes Linux RISC-V 32bit kernel booting by: 1. Forcing cmodel=3Dmedany for mm/init.c 2. Moving remaing MM-related stuff va_pa_offset, pfn_base and empty_zero_page from kernel/setup.c to mm/init.c Further, the setup_vm() cannot handle GCC epilog/prolog for ftrace so we disable function tracing for mm/init.c by not using "-pg" compiler flag. Fixes: 6f1e9e946f0b ("RISC-V: Move setup_vm() to mm/init.c") Suggested-by: Christoph Hellwig Suggested-by: Mike Rapoport Signed-off-by: Anup Patel Reviewed-by: Mike Rapoport --- v3: Don't use CFLAG "-pg" for mm/init.o v2: Removed CFLAGS_setup.o from kernel/Makefile and replaced SoBs --- arch/riscv/kernel/Makefile | 3 --- arch/riscv/kernel/setup.c | 8 -------- arch/riscv/mm/Makefile | 7 +++++++ arch/riscv/mm/init.c | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index f13f7f276639..598568168d35 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -4,7 +4,6 @@ ifdef CONFIG_FTRACE CFLAGS_REMOVE_ftrace.o =3D -pg -CFLAGS_REMOVE_setup.o =3D -pg endif extra-y +=3D head.o @@ -29,8 +28,6 @@ obj-y +=3D vdso.o obj-y +=3D cacheinfo.o obj-y +=3D vdso/ -CFLAGS_setup.o :=3D -mcmodel=3Dmedany - obj-$(CONFIG_FPU) +=3D fpu.o obj-$(CONFIG_SMP) +=3D smpboot.o obj-$(CONFIG_SMP) +=3D smp.o diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index ecb654f6a79e..540a331d1376 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -48,14 +48,6 @@ struct screen_info screen_info =3D { }; #endif -unsigned long va_pa_offset; -EXPORT_SYMBOL(va_pa_offset); -unsigned long pfn_base; -EXPORT_SYMBOL(pfn_base); - -unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_al= igned_bss; -EXPORT_SYMBOL(empty_zero_page); - /* The lucky hart to first increment this variable will boot the other cor= es */ atomic_t hart_lottery; unsigned long boot_cpu_hartid; diff --git a/arch/riscv/mm/Makefile b/arch/riscv/mm/Makefile index eb22ab49b3e0..c1d79e3d005d 100644 --- a/arch/riscv/mm/Makefile +++ b/arch/riscv/mm/Makefile @@ -1,5 +1,12 @@ + +ifdef CONFIG_FTRACE +CFLAGS_REMOVE_init.o =3D -pg +endif + obj-y +=3D init.o obj-y +=3D fault.o obj-y +=3D extable.o obj-y +=3D ioremap.o obj-y +=3D cacheflush.o + +CFLAGS_init.o :=3D -mcmodel=3Dmedany diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index b379a75ac6a6..8cf9ff1f9058 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -25,6 +25,10 @@ #include #include +unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] + __page_aligned_bss; +EXPORT_SYMBOL(empty_zero_page); + static void __init zone_sizes_init(void) { unsigned long max_zone_pfns[MAX_NR_ZONES] =3D { 0, }; @@ -143,6 +147,11 @@ void __init setup_bootmem(void) } } +unsigned long va_pa_offset; +EXPORT_SYMBOL(va_pa_offset); +unsigned long pfn_base; +EXPORT_SYMBOL(pfn_base); + pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE); @@ -172,6 +181,19 @@ void __set_fixmap(enum fixed_addresses idx, phys_addr_= t phys, pgprot_t prot) } } +/* + * The setup_vm() is called from head.S with MMU-off. + * + * Following requirements should be honoured for setup_vm() to work + * correctly: + * 1) It should use PC-relative addressing for accessing kernel symbols. + * To achieve this we always use GCC cmodel=3Dmedany. + * 2) The compiler instrumentation for FTRACE will not work for setup_vm() + * so disable compiler instrumentation when FTRACE is enabled. + * + * Currently, the above requirements are honoured by using custom CFLAGS + * for init.o in mm/Makefile. + */ asmlinkage void __init setup_vm(void) { extern char _start; -- 2.17.1