From patchwork Thu Mar 21 09:47:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10863203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D3EB6C2 for ; Thu, 21 Mar 2019 09:47:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF8F92A001 for ; Thu, 21 Mar 2019 09:47:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E28332A097; Thu, 21 Mar 2019 09:47:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UPPERCASE_50_75 autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7BE5F2A001 for ; Thu, 21 Mar 2019 09:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YMAEAxrN2f2RU886TggwJ0bjD6YNe6oKWQZOuBgv288=; b=eOG4xDyDlRrpay dFkv+NWV5g4HuxK34h1uK5qJ/WU2gChLlghs2PzXG5w3oGRc8eOaaNObYfg9k/HAUzWUcHPb4nd2r vyGh+ydWdq8AcyFV9p+F3E9tPMW6E0+nyLMM+hEw1suEbM68X7cvFQ4fYFosSSvsvM2mdCND2M+I3 Ixt4LJJvpszHOCukjPIFpNw9vVEKjycUmVdk/16Fln58r8mXf9IZ/Gf6dj7R/RPwCerQ3BhR+BzI7 eXmSPPN4L5WEhaqB/LFVqiSn9VNW0D2rqKWYM9uyl/KTIKoV0MaiE85D7NbjKh7CfT9+BUR++AFqo Vw2edIF8wzfDVEUsm+rw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIg-0007f1-Bi; Thu, 21 Mar 2019 09:47:50 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIc-0007bS-5R for linux-riscv@lists.infradead.org; Thu, 21 Mar 2019 09:47:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1553161666; x=1584697666; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=w4dVKfN5ZmXiG15CA3JMTgfloONM1rxnpuZsSQQesj8=; b=kCJe2lQJ/RLl7qf+kwWFGLw/7aj++3pDeA5oH0EtCB+dKaeJjzUr57bd sgzLds4Ek0s18o2MTeeRYyj8lFZSOmyGD+vnn/8QFkRkTBPpyFxolGB6o eGeuTkF8Ao6Y4/EJo0S/4s97uIn1XPceBzGh3Z+zeeAULAAnr2v/xsLfD 0X04ulh2cx5FqetUitUFgmKpEak0EIpAJl1b4cnNG9+xQLeS0q5RkQ5Bi FfFtKLASxbSN6YmGzeOrG3vsC0qin0NVkRF5qwv0gvmA7uKpU2w6rwKKM 0iuDvXNczX/tab2y6ddfsMwH5b420Zy66NHgKfWt3Uc0+cbKn1HWooEzD Q==; X-IronPort-AV: E=Sophos;i="5.60,252,1549900800"; d="scan'208";a="105647550" Received: from mail-by2nam05lp2050.outbound.protection.outlook.com (HELO NAM05-BY2-obe.outbound.protection.outlook.com) ([104.47.50.50]) by ob1.hgst.iphmx.com with ESMTP; 21 Mar 2019 17:47:46 +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=w5TIGr+xISzJZCK8B6VvVozLxUD4U89lHpLv+XA3rBM=; b=GrKb2FLfO2z/qnl3SiaNik/Vdi+taUNTwrp1gd4PDJtqWA0LkSRsXn9u0kDtf6ggr1A9HsS5AbTPdjaK8+xcnRWOhJFWLpay5Ynj+Q1QrWMiZNX4lgxvDVYSGGqGl163l2TGNL2woVbhoOQ4qdEhhnmOEq1CI7jDqPC4H9YbIDo= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.246.15) by MN2PR04MB5757.namprd04.prod.outlook.com (20.179.21.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.14; Thu, 21 Mar 2019 09:47:43 +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.013; Thu, 21 Mar 2019 09:47:43 +0000 From: Anup Patel To: Palmer Dabbelt , Albert Ou Subject: [PATCH v2 1/5] RISC-V: Add separate defconfig for 32bit systems Thread-Topic: [PATCH v2 1/5] RISC-V: Add separate defconfig for 32bit systems Thread-Index: AQHU38shr0lS/xpi+k6cJOWF2UHeng== Date: Thu, 21 Mar 2019 09:47:43 +0000 Message-ID: <20190321094710.16552-2-anup.patel@wdc.com> References: <20190321094710.16552-1-anup.patel@wdc.com> In-Reply-To: <20190321094710.16552-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: PN1PR0101CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::23) 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: [106.51.18.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a0b75087-114d-4b85-8c30-08d6ade243b2 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:MN2PR04MB5757; x-ms-traffictypediagnostic: MN2PR04MB5757: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0983EAD6B2 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(376002)(346002)(136003)(366004)(396003)(189003)(199004)(54906003)(1076003)(68736007)(110136005)(316002)(6436002)(81166006)(2906002)(78486014)(8936002)(66574012)(5660300002)(25786009)(50226002)(6486002)(52116002)(102836004)(6506007)(36756003)(386003)(26005)(9456002)(186003)(76176011)(97736004)(99286004)(11346002)(446003)(476003)(486006)(2616005)(44832011)(81156014)(105586002)(14454004)(4326008)(72206003)(14444005)(106356001)(256004)(86362001)(55236004)(6512007)(71190400001)(7736002)(71200400001)(66066001)(3846002)(478600001)(305945005)(6116002)(53936002)(2171002)(8676002); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2PR04MB5757; H:MN2PR04MB6061.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: sxwMIfO2PXIXFu6EtTE7ykI1eJjQ7nvhWI8oxWMXqp+8A5BWa4IjpbK/f7K/ZFPetbOboS04BFRC/YWIIhAZplAypWhr02j+nEWsuz4vKbeZuHSLnWIHawegHsuGQKv23cMrFRD1h7lBSmZzF6hmxSYdLTcnbLiqeGlw6q86kzJs5gxghsmi4s6+mxW36chHWA6ZUDYsNE3oCOOtPUElKJO9k1quo34L+veY8xV2B5+6RPHyZQTzJQ5Pihbnp0Qce7arCYJFMN7SDqCs/FTzPoHbznJCRuvorHJ/nDw7EaHVIhzVHGJzj6n5d0j4p84YOtoxW0Bx1EJo++G0dg6gr6nvOGgMlBxueVpfpWk+0pirsxFeGMqZZQ76qVvsP3jVTfp08ZKqQPBMwMOGs7oi5wyQTVoukXA86sANCgEQofA= MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0b75087-114d-4b85-8c30-08d6ade243b2 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2019 09:47:43.2514 (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: MN2PR04MB5757 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190321_024746_274585_5397E511 X-CRM114-Status: GOOD ( 14.58 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , "linux-kernel@vger.kernel.org" , Mike Rapoport , Christoph Hellwig , Atish Patra , Paul Walmsley , "linux-riscv@lists.infradead.org" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds rv32_defconfig for 32bit systems. The only difference between rv32_defconfig and defconfig is that rv32_defconfig has CONFIG_ARCH_RV32I=y. Signed-off-by: Anup Patel --- arch/riscv/configs/rv32_defconfig | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 arch/riscv/configs/rv32_defconfig diff --git a/arch/riscv/configs/rv32_defconfig b/arch/riscv/configs/rv32_defconfig new file mode 100644 index 000000000000..1a911ed8e772 --- /dev/null +++ b/arch/riscv/configs/rv32_defconfig @@ -0,0 +1,84 @@ +CONFIG_SYSVIPC=y +CONFIG_POSIX_MQUEUE=y +CONFIG_IKCONFIG=y +CONFIG_IKCONFIG_PROC=y +CONFIG_CGROUPS=y +CONFIG_CGROUP_SCHED=y +CONFIG_CFS_BANDWIDTH=y +CONFIG_CGROUP_BPF=y +CONFIG_NAMESPACES=y +CONFIG_USER_NS=y +CONFIG_CHECKPOINT_RESTORE=y +CONFIG_BLK_DEV_INITRD=y +CONFIG_EXPERT=y +CONFIG_BPF_SYSCALL=y +CONFIG_ARCH_RV32I=y +CONFIG_SMP=y +CONFIG_MODULES=y +CONFIG_MODULE_UNLOAD=y +CONFIG_NET=y +CONFIG_PACKET=y +CONFIG_UNIX=y +CONFIG_INET=y +CONFIG_IP_MULTICAST=y +CONFIG_IP_ADVANCED_ROUTER=y +CONFIG_IP_PNP=y +CONFIG_IP_PNP_DHCP=y +CONFIG_IP_PNP_BOOTP=y +CONFIG_IP_PNP_RARP=y +CONFIG_NETLINK_DIAG=y +CONFIG_PCI=y +CONFIG_PCIEPORTBUS=y +CONFIG_PCI_HOST_GENERIC=y +CONFIG_PCIE_XILINX=y +CONFIG_DEVTMPFS=y +CONFIG_BLK_DEV_LOOP=y +CONFIG_VIRTIO_BLK=y +CONFIG_BLK_DEV_SD=y +CONFIG_BLK_DEV_SR=y +CONFIG_ATA=y +CONFIG_SATA_AHCI=y +CONFIG_SATA_AHCI_PLATFORM=y +CONFIG_NETDEVICES=y +CONFIG_VIRTIO_NET=y +CONFIG_MACB=y +CONFIG_E1000E=y +CONFIG_R8169=y +CONFIG_MICROSEMI_PHY=y +CONFIG_INPUT_MOUSEDEV=y +CONFIG_SERIAL_8250=y +CONFIG_SERIAL_8250_CONSOLE=y +CONFIG_SERIAL_OF_PLATFORM=y +CONFIG_SERIAL_EARLYCON_RISCV_SBI=y +CONFIG_HVC_RISCV_SBI=y +# CONFIG_PTP_1588_CLOCK is not set +CONFIG_DRM=y +CONFIG_DRM_RADEON=y +CONFIG_FRAMEBUFFER_CONSOLE=y +CONFIG_USB=y +CONFIG_USB_XHCI_HCD=y +CONFIG_USB_XHCI_PLATFORM=y +CONFIG_USB_EHCI_HCD=y +CONFIG_USB_EHCI_HCD_PLATFORM=y +CONFIG_USB_OHCI_HCD=y +CONFIG_USB_OHCI_HCD_PLATFORM=y +CONFIG_USB_STORAGE=y +CONFIG_USB_UAS=y +CONFIG_VIRTIO_MMIO=y +CONFIG_SIFIVE_PLIC=y +CONFIG_EXT4_FS=y +CONFIG_EXT4_FS_POSIX_ACL=y +CONFIG_AUTOFS4_FS=y +CONFIG_MSDOS_FS=y +CONFIG_VFAT_FS=y +CONFIG_TMPFS=y +CONFIG_TMPFS_POSIX_ACL=y +CONFIG_NFS_FS=y +CONFIG_NFS_V4=y +CONFIG_NFS_V4_1=y +CONFIG_NFS_V4_2=y +CONFIG_ROOT_NFS=y +CONFIG_CRYPTO_USER_API_HASH=y +CONFIG_CRYPTO_DEV_VIRTIO=y +CONFIG_PRINTK_TIME=y +# CONFIG_RCU_TRACE is not set From patchwork Thu Mar 21 09:47:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10863205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3C7F6C2 for ; Thu, 21 Mar 2019 09:47:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABE8B29FA2 for ; Thu, 21 Mar 2019 09:47:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F9402A09A; Thu, 21 Mar 2019 09:47:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1849B29FA2 for ; Thu, 21 Mar 2019 09:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JhWgO9aX6KmhW3fb30R8dC8m+VqeHnrqjuMsrRAEt0Y=; b=JjZVh5Ap4YjspL EVGLKMIlEYflsVl9crKK7ipz/p8tbJrivFGeDiAwT9PAMrXQgzINh2rflsFNABZJPpLvEM7280+uW wysbsch1s0aSMESAe5LG40/6glbFLKH06KTatvL/xItdnUixIy/hUy/g/6sdmSNUHKP6Usciw8BUe uFqKElrCbfiRpLtZFmdzYHZottGpgdpBtkqy4UZpxBs+5XAoezM2cVIfrZ5RGr7//5Q8yXwtGWXpu gM5edKgQ+rHW1B9Wct6aSqxXPCCyYcpWEokym08T9MnyeeG7AOdmX8zqaqsNE0N+Q05MrDrzhS4fI H8AG/SCnop6xczBkcucA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIk-0007ht-04; Thu, 21 Mar 2019 09:47:54 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIg-0007bS-EQ for linux-riscv@lists.infradead.org; Thu, 21 Mar 2019 09:47:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1553161671; x=1584697671; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=xLA0YyUU6QsAu+Pu3XDuXdtDHuF56eOkepq1O65EIrs=; b=XlEqXksA+d14hC7+PGCDsgbxb1CAzFan77vBQaUI9LYZaQ9ciExUTXbm NokpkUIm5EsXu3nrMPdWod3meoRaD7FM+nVTy+ZbvVz2B2YhNimvFlkEW mSHyCVwSOA0MHjwBM7NhQUAe3zfGv82W7Ek3BAP+idiLtjQyTlVjjO5C2 vRjtTZ/T38wqsbz5LZdOKnLSK7scQVQXlkTCtBNV0SnF7K7c5FEjp0Pr6 PsFoYN3m6DbLxvJoZzFSUOnUtTzCMIKrIk12Lw2IA3+0UGWB+IFZp0WQ8 DjhrPy1mCcnvt2ucSBv8KPbSBurkoNj7M4ZM4l9Rdn5tb0j6yVlIYSt0s g==; X-IronPort-AV: E=Sophos;i="5.60,252,1549900800"; d="scan'208";a="105647555" Received: from mail-bl2nam02lp2054.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([104.47.38.54]) by ob1.hgst.iphmx.com with ESMTP; 21 Mar 2019 17:47:50 +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=f8xdW15+pgOsMivtJQMJyzQSkirF9S4gqcJJxzV4yhc=; b=i6xP8D2Gok9upIpzMRI2Mbhkzaco4HhEmClHI7qe/vlP/IkPmn9penVVSAwUrxWwaT2u1g1O6fIFP9DhmR9Tal+VXn0OKp48hAiKmJWeSWtQQKDDJHpP3IoN6uZmMKkQkEpiiEemTDWybG/YUF9mvUvMlKIi70KO3jJjevY/Noo= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.246.15) by MN2PR04MB6239.namprd04.prod.outlook.com (20.178.249.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Thu, 21 Mar 2019 09:47:47 +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.013; Thu, 21 Mar 2019 09:47:47 +0000 From: Anup Patel To: Palmer Dabbelt , Albert Ou Subject: [PATCH v2 2/5] RISC-V: Make setup_vm() independent of GCC code model Thread-Topic: [PATCH v2 2/5] RISC-V: Make setup_vm() independent of GCC code model Thread-Index: AQHU38sjvEGuhXlLm0iFrXSosiNqNA== Date: Thu, 21 Mar 2019 09:47:47 +0000 Message-ID: <20190321094710.16552-3-anup.patel@wdc.com> References: <20190321094710.16552-1-anup.patel@wdc.com> In-Reply-To: <20190321094710.16552-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: PN1PR0101CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::23) 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: [106.51.18.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1c206b52-68a9-4b03-e510-08d6ade24627 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:MN2PR04MB6239; x-ms-traffictypediagnostic: MN2PR04MB6239: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0983EAD6B2 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(376002)(366004)(136003)(396003)(346002)(189003)(199004)(256004)(6506007)(4326008)(6512007)(486006)(36756003)(2171002)(446003)(102836004)(478600001)(386003)(72206003)(53936002)(2906002)(305945005)(76176011)(11346002)(26005)(44832011)(14444005)(55236004)(7736002)(25786009)(14454004)(476003)(78486014)(1076003)(2616005)(52116002)(6486002)(6436002)(9456002)(81156014)(186003)(316002)(8676002)(5660300002)(68736007)(106356001)(105586002)(71200400001)(86362001)(81166006)(54906003)(8936002)(66066001)(97736004)(6116002)(71190400001)(3846002)(99286004)(110136005)(50226002); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2PR04MB6239; H:MN2PR04MB6061.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: aqvmhVu3czW5H2lyMpgn1rjFukr5Qro32hKOhfa31n+1ZBlhybAzX5DVjEWb+inm04JZQyc+RSNnP2odT7GTEdCoj+bTwDDx7QfCyGw8c7IhtJ5RAXRPIm3vRVSl0jNOJ+MCslIS0WEuq4F0tT6OJ5yFISVL/cz/R+EnS2vGx7hNYUVQP0vbZLdXnuiBcpJCi5VzuCKmlAbg3PiaBfw96kEevdzWvO5igcDpdj4ymPt+RlOhAM2Zwl9GvHavjZWc9tLYGm7r9uc9gSYdybda2RZZGoNg7At3L7uv/4V0okZexRwy7UqE6h6rV2LAA+8Gpw1q/seR5Ccq4QbLp/vKEMcMr2wBMZTSFSD6Zx5K4xqcY+wznt+wbxVQJxFGB8xqKk1SKpvNsMicRkZhG9SR0rjM7JmhL/isgUpotpVdiAQ= MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c206b52-68a9-4b03-e510-08d6ade24627 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2019 09:47:47.3609 (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: MN2PR04MB6239 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190321_024750_671380_ABD7180D X-CRM114-Status: GOOD ( 18.80 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , "linux-kernel@vger.kernel.org" , Mike Rapoport , Christoph Hellwig , Atish Patra , Paul Walmsley , "linux-riscv@lists.infradead.org" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The setup_vm() must access kernel symbols in a position independent way because it will be called from head.S with MMU off. If we compile kernel with cmodel=medany then PC-relative addressing will be used in setup_vm() to access kernel symbols so it works perfectly fine. Although, if we compile kernel with cmodel=medlow then either absolute addressing or PC-relative addressing (based on whichever requires fewer instructions) is used to access kernel symbols in setup_vm(). This can break setup_vm() whenever any absolute addressing is used to access kernel symbols. With the movement of setup_vm() from kernel/setup.c to mm/init.c, the setup_vm() is now broken for cmodel=medlow but it works perfectly fine for cmodel=medany. This patch fixes setup_vm() and makes it independent of GCC code model by accessing kernel symbols relative to kernel load address instead of assuming PC-relative addressing. Fixes: 6f1e9e946f0b ("RISC-V: Move setup_vm() to mm/init.c") Signed-off-by: Anup Patel --- arch/riscv/kernel/head.S | 1 + arch/riscv/mm/init.c | 73 ++++++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index fe884cd69abd..7966262b4f9d 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -62,6 +62,7 @@ clear_bss_done: /* Initialize page tables and relocate to virtual addresses */ la sp, init_thread_union + THREAD_SIZE + la a0, _start call setup_vm call relocate diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index b379a75ac6a6..e38f8195e45b 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -172,55 +172,78 @@ void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot) } } -asmlinkage void __init setup_vm(void) +static inline void *__load_addr(void *ptr, uintptr_t load_pa) { extern char _start; + uintptr_t va = (uintptr_t)ptr; + uintptr_t sz = (uintptr_t)(&_end) - (uintptr_t)(&_start); + + if (va >= PAGE_OFFSET && va <= (PAGE_OFFSET + sz)) + return (void *)(load_pa + (va - PAGE_OFFSET)); + return (void *)va; +} + +#define __load_va(ptr, load_pa) __load_addr(ptr, load_pa) +#define __load_pa(ptr, load_pa) ((uintptr_t)__load_addr(ptr, load_pa)) + +asmlinkage void __init setup_vm(uintptr_t load_pa) +{ uintptr_t i; - uintptr_t pa = (uintptr_t) &_start; +#ifndef __PAGETABLE_PMD_FOLDED + pmd_t *pmdp; +#endif + pgd_t *pgdp; + phys_addr_t map_pa; + pgprot_t tableprot = __pgprot(_PAGE_TABLE); pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC); - va_pa_offset = PAGE_OFFSET - pa; - pfn_base = PFN_DOWN(pa); + va_pa_offset = PAGE_OFFSET - load_pa; + pfn_base = PFN_DOWN(load_pa); /* Sanity check alignment and size */ BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0); - BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0); + BUG_ON((load_pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0); #ifndef __PAGETABLE_PMD_FOLDED - trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] = - pfn_pgd(PFN_DOWN((uintptr_t)trampoline_pmd), - __pgprot(_PAGE_TABLE)); - trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot); + pgdp = __load_va(trampoline_pg_dir, load_pa); + map_pa = __load_pa(trampoline_pmd, load_pa); + pgdp[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] = + pfn_pgd(PFN_DOWN(map_pa), tableprot); + trampoline_pmd[0] = pfn_pmd(PFN_DOWN(load_pa), prot); + + pgdp = __load_va(swapper_pg_dir, load_pa); for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) { size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i; - swapper_pg_dir[o] = - pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i, - __pgprot(_PAGE_TABLE)); + map_pa = __load_pa(swapper_pmd, load_pa); + pgdp[o] = pfn_pgd(PFN_DOWN(map_pa) + i, tableprot); } + pmdp = __load_va(swapper_pmd, load_pa); for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++) - swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot); + pmdp[i] = pfn_pmd(PFN_DOWN(load_pa + i * PMD_SIZE), prot); - swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] = - pfn_pgd(PFN_DOWN((uintptr_t)fixmap_pmd), - __pgprot(_PAGE_TABLE)); + map_pa = __load_pa(fixmap_pmd, load_pa); + pgdp[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] = + pfn_pgd(PFN_DOWN(map_pa), tableprot); + pmdp = __load_va(fixmap_pmd, load_pa); + map_pa = __load_pa(fixmap_pte, load_pa); fixmap_pmd[(FIXADDR_START >> PMD_SHIFT) % PTRS_PER_PMD] = - pfn_pmd(PFN_DOWN((uintptr_t)fixmap_pte), - __pgprot(_PAGE_TABLE)); + pfn_pmd(PFN_DOWN(map_pa), tableprot); #else - trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] = - pfn_pgd(PFN_DOWN(pa), prot); + pgdp = __load_va(trampoline_pg_dir, load_pa); + pgdp[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] = + pfn_pgd(PFN_DOWN(load_pa), prot); + pgdp = __load_va(swapper_pg_dir, load_pa); for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) { size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i; - swapper_pg_dir[o] = - pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot); + pgdp[o] = pfn_pgd(PFN_DOWN(load_pa + i * PGDIR_SIZE), prot); } - swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] = - pfn_pgd(PFN_DOWN((uintptr_t)fixmap_pte), - __pgprot(_PAGE_TABLE)); + map_pa = __load_pa(fixmap_pte, load_pa); + pgdp[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] = + pfn_pgd(PFN_DOWN(map_pa), tableprot); #endif } From patchwork Thu Mar 21 09:47:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10863207 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 092B16C2 for ; Thu, 21 Mar 2019 09:48:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2AE7286BC for ; Thu, 21 Mar 2019 09:48:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C59D32A001; Thu, 21 Mar 2019 09:48:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8DFF52A001 for ; Thu, 21 Mar 2019 09:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9IzzziXFbXv4fzTSKTXaLUqSKkYnE+A02+GAM/kP41A=; b=Ad1IjPHbjmbT4t X1kD7XxkRzpzCJk+reLJ+2WXgnp/sVK9cpwfsyM1AVCMu43rBEgWvMd7VQbZ3xc3PIdEZ/fITdaDp io35AVY6gddelQt/m9Sdx28CqbpFxy9LoctrqQZiUHJImAUJh3J3BQxtNavxyiuuvSsVGHBWy5JYL UWOQh8XczOrLLJm9jbnErI0XYCN/xGJB1ASjCbkSBiGh52Xx7JU5ohFYpoeNrGP4WI7x21jUiBmxz wfncdyZw+BCs8e87genLwfK1QJgSwtXkni3gyhP5ImELE5h99SgioA5GRR0Spj8nAw5NR84+NYES0 0B1zgJE7pQRiouINaffA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIn-0007kv-PV; Thu, 21 Mar 2019 09:47:57 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIj-0007bS-S9 for linux-riscv@lists.infradead.org; Thu, 21 Mar 2019 09:47:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1553161674; x=1584697674; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=DReYSIu4lu3Znm6sxWmsqhc/bnFDCL7zBw5k+5T5irc=; b=jHOI6kq5t/QLAsefFMPyO6BkKj/DVHaj3rs/859lzIaVwz7UFReeOM1/ ASEcNBvFJSDv6vecLHbbJIYmx7Wgl1wFYJfh9It3C2yYXPZM6Zwsbgi0v FW2xE71RegDH3yQQonHtjR3NG2VoU5Ixq/GrEqrHY9swQabo68VhqjBnM b4s0OQqNlidnbKafQwzSZXp9YbIZJbPDKFoWMscScTFM/vevx43einFOK 9rCQzKKhBelUwlXMNeqk2swHm0qpzGaC5/v1tNJfO3pL60dW3dGjKa2e0 8WZsfTVl/sMWYlRV3mi36EXXLAOHtEZvcsyAGS7Q1vEk5gWeBOac80/CU g==; X-IronPort-AV: E=Sophos;i="5.60,252,1549900800"; d="scan'208";a="105647559" Received: from mail-bl2nam02lp2051.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([104.47.38.51]) by ob1.hgst.iphmx.com with ESMTP; 21 Mar 2019 17:47:53 +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=RsItQezegWagmh5VljIaT25x1DWlaRs2xIA5T4KFAt0=; b=fDvboi2soonVXHISN0QSfZQobWi9Qkse4hFV4pvk120JQlJSYck8AHVfz9N29sRN6kHmnbIrL/3jjyD27Ukfjk2ln5p+tHzOclViCp4h/u6wy8B4Fw/N6tdQ14wz12eOdJrPEyrePaOvyRUeOmkWsZK8WRQtTeFumnjL3F3WTP8= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.246.15) by MN2PR04MB6239.namprd04.prod.outlook.com (20.178.249.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Thu, 21 Mar 2019 09:47:51 +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.013; Thu, 21 Mar 2019 09:47:51 +0000 From: Anup Patel To: Palmer Dabbelt , Albert Ou Subject: [PATCH v2 3/5] RISC-V: Allow booting kernel from any 4KB aligned address Thread-Topic: [PATCH v2 3/5] RISC-V: Allow booting kernel from any 4KB aligned address Thread-Index: AQHU38smxmc1jYxaFE+Ebv0FuT3Fyg== Date: Thu, 21 Mar 2019 09:47:51 +0000 Message-ID: <20190321094710.16552-4-anup.patel@wdc.com> References: <20190321094710.16552-1-anup.patel@wdc.com> In-Reply-To: <20190321094710.16552-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: PN1PR0101CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::23) 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: [106.51.18.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d6596b96-a6d6-4bb0-0db3-08d6ade24884 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:MN2PR04MB6239; x-ms-traffictypediagnostic: MN2PR04MB6239: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0983EAD6B2 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(376002)(366004)(136003)(396003)(346002)(189003)(199004)(256004)(6506007)(4326008)(6512007)(486006)(36756003)(2171002)(446003)(102836004)(478600001)(386003)(72206003)(53946003)(53936002)(2906002)(305945005)(76176011)(11346002)(26005)(44832011)(14444005)(55236004)(7736002)(25786009)(14454004)(476003)(78486014)(1076003)(2616005)(52116002)(6486002)(6436002)(9456002)(30864003)(81156014)(186003)(316002)(8676002)(5660300002)(68736007)(106356001)(105586002)(71200400001)(86362001)(81166006)(54906003)(8936002)(66066001)(97736004)(6116002)(71190400001)(3846002)(99286004)(110136005)(50226002)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2PR04MB6239; H:MN2PR04MB6061.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 4t7faPdXyY7JUp/nxWHs/GJ1pY72k1NmC5zD6HLcH2GYyBTNRyM6l1WyTDjB64ivdqHQsqH6FCebc2ovEPGtTHvhC4urc5VsZZGSpcd4iXE7HE2N5dr0zMgh3se7QgER23wxS7WQddhXkkRE1JLzaFsQb5eZ948PJBaO2JON4kb6zBwoMEmBLN5vHXWPPN+aQ5cQotiuOeINn2OecYmbMZ/gEx5bUybAWdgrf07tv+2us9CHCxhn8v0QDr2AH+aGbe2EcHW3N9miLf3LCqEjQTpQCCvg/nfB4cBzG/m+CW8fAPTjAYMotYkpDeTyVaNu4muYiUU8D0S1VZVXG3W9szH7o3Qr3JkQbfm6VCyVEueGrPHbmjm5Of7EO78iN5oWu05SkZ7AFh1wE0CjODU0o/xHF4nzeLlVF7gtnM16Y6w= MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6596b96-a6d6-4bb0-0db3-08d6ade24884 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2019 09:47:51.3313 (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: MN2PR04MB6239 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190321_024754_047950_2CF8D8B9 X-CRM114-Status: GOOD ( 25.31 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , "linux-kernel@vger.kernel.org" , Mike Rapoport , Christoph Hellwig , Atish Patra , Paul Walmsley , "linux-riscv@lists.infradead.org" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, we have to boot RISCV64 kernel from a 2MB aligned physical address and RISCV32 kernel from a 4MB aligned physical address. This constraint is because initial pagetable setup (i.e. setup_vm()) maps entire RAM using hugepages (i.e. 2MB for 3-level pagetable and 4MB for 2-level pagetable). Further, the above booting contraint also results in memory wastage because if we boot kernel from some address (which is not same as RAM start address) then RISCV kernel will map PAGE_OFFSET virtual address lineraly to physical address and memory between RAM start and will be reserved/unusable. For example, RISCV64 kernel booted from 0x80200000 will waste 2MB of RAM and RISCV32 kernel booted from 0x80400000 will waste 4MB of RAM. This patch re-writes the initial pagetable setup code to allow booting RISV32 and RISCV64 kernel from any 4KB (i.e. PAGE_SIZE) aligned address. To achieve this: 1. We add kconfig option BOOT_PAGE_ALIGNED. When it is enabled we use 4KB mappings in initial page table setup otherwise we use 2MB/4MB mappings. 2. We map kernel and dtb (few MBs) in setup_vm() (called from head.S) 3. Once we reach paging_init() (called from setup_arch()) after memblock setup, we map all available memory banks. With this patch in-place, the booting constraint for RISCV32 and RISCV64 kernel is much more relaxed when CONFIG_BOOT_PAGE_ALIGNED=y and we can now boot kernel very close to RAM start thereby minimizng memory wastage. Signed-off-by: Anup Patel --- arch/riscv/Kconfig | 11 + arch/riscv/include/asm/fixmap.h | 5 + arch/riscv/include/asm/pgtable-64.h | 5 + arch/riscv/include/asm/pgtable.h | 6 +- arch/riscv/kernel/head.S | 1 + arch/riscv/kernel/setup.c | 4 +- arch/riscv/mm/init.c | 402 ++++++++++++++++++++++++---- 7 files changed, 378 insertions(+), 56 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index eb56c82d8aa1..1b0c66f7aba3 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -172,6 +172,17 @@ config SMP If you don't know what to do here, say N. +config BOOT_PAGE_ALIGNED + bool "Allow booting from page aligned address" + help + This enables support for booting kernel from any page aligned + address (i.e. 4KB aligned). This option is particularly useful + on systems with very less RAM (few MBs) because using it we + can boot kernel closer RAM start thereby reducing unusable RAM + below kernel. + + If you don't know what to do here, say N. + config NR_CPUS int "Maximum number of CPUs (2-32)" range 2 32 diff --git a/arch/riscv/include/asm/fixmap.h b/arch/riscv/include/asm/fixmap.h index 57afe604b495..5cf53dd882e5 100644 --- a/arch/riscv/include/asm/fixmap.h +++ b/arch/riscv/include/asm/fixmap.h @@ -21,6 +21,11 @@ */ enum fixed_addresses { FIX_HOLE, +#define FIX_FDT_SIZE SZ_1M + FIX_FDT_END, + FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1, + FIX_PTE, + FIX_PMD, FIX_EARLYCON_MEM_BASE, __end_of_fixed_addresses }; diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h index 7aa0ea9bd8bb..56ecc3dc939d 100644 --- a/arch/riscv/include/asm/pgtable-64.h +++ b/arch/riscv/include/asm/pgtable-64.h @@ -78,6 +78,11 @@ static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot) return __pmd((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot)); } +static inline unsigned long _pmd_pfn(pmd_t pmd) +{ + return pmd_val(pmd) >> _PAGE_PFN_SHIFT; +} + #define pmd_ERROR(e) \ pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e)) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 1141364d990e..05fa2115e736 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -121,12 +121,16 @@ static inline void pmd_clear(pmd_t *pmdp) set_pmd(pmdp, __pmd(0)); } - static inline pgd_t pfn_pgd(unsigned long pfn, pgprot_t prot) { return __pgd((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot)); } +static inline unsigned long _pgd_pfn(pgd_t pgd) +{ + return pgd_val(pgd) >> _PAGE_PFN_SHIFT; +} + #define pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1)) /* Locate an entry in the page global directory */ diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 7966262b4f9d..12a3ec5eb8ab 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -63,6 +63,7 @@ clear_bss_done: /* Initialize page tables and relocate to virtual addresses */ la sp, init_thread_union + THREAD_SIZE la a0, _start + mv a1, s1 call setup_vm call relocate diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index ecb654f6a79e..acdd0f74982b 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -62,7 +63,8 @@ unsigned long boot_cpu_hartid; void __init parse_dtb(unsigned int hartid, void *dtb) { - if (early_init_dt_scan(__va(dtb))) + dtb = (void *)fix_to_virt(FIX_FDT) + ((uintptr_t)dtb & ~PAGE_MASK); + if (early_init_dt_scan(dtb)) return; pr_err("No DTB passed to the kernel\n"); diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index e38f8195e45b..c389fbfeccd8 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1,14 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* + * Copyright (C) 2019 Western Digital Corporation or its affiliates. * Copyright (C) 2012 Regents of the University of California - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ #include @@ -43,13 +36,6 @@ void setup_zero_page(void) memset((void *)empty_zero_page, 0, PAGE_SIZE); } -void __init paging_init(void) -{ - setup_zero_page(); - local_flush_tlb_all(); - zone_sizes_init(); -} - void __init mem_init(void) { #ifdef CONFIG_FLATMEM @@ -143,18 +129,36 @@ void __init setup_bootmem(void) } } +#define MAX_EARLY_MAPPING_SIZE SZ_128M + pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE); #ifndef __PAGETABLE_PMD_FOLDED -#define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT) -pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss; -pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE); +#if MAX_EARLY_MAPPING_SIZE < PGDIR_SIZE +#define NUM_SWAPPER_PMDS 1UL +#else +#define NUM_SWAPPER_PMDS (MAX_EARLY_MAPPING_SIZE/PGDIR_SIZE) +#endif +#define NUM_TRAMPOLINE_PMDS 1UL +pmd_t swapper_pmd[PTRS_PER_PMD*NUM_SWAPPER_PMDS] __page_aligned_bss; +pmd_t trampoline_pmd[PTRS_PER_PMD*NUM_TRAMPOLINE_PMDS] + __initdata __aligned(PAGE_SIZE); pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss; +#define NUM_SWAPPER_PTES (MAX_EARLY_MAPPING_SIZE/PMD_SIZE) +#else +#define NUM_SWAPPER_PTES (MAX_EARLY_MAPPING_SIZE/PGDIR_SIZE) #endif +#define NUM_TRAMPOLINE_PTES 1UL + +pte_t swapper_pte[PTRS_PER_PTE*NUM_SWAPPER_PTES] __page_aligned_bss; +pte_t trampoline_pte[PTRS_PER_PTE*NUM_TRAMPOLINE_PTES] + __initdata __aligned(PAGE_SIZE); pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss; +uintptr_t map_size; + void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot) { unsigned long addr = __fix_to_virt(idx); @@ -172,6 +176,13 @@ void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot) } } +struct mapping_ops { + pte_t *(*get_pte_virt)(phys_addr_t pa); + phys_addr_t (*alloc_pte)(uintptr_t va, uintptr_t load_pa); + pmd_t *(*get_pmd_virt)(phys_addr_t pa); + phys_addr_t (*alloc_pmd)(uintptr_t va, uintptr_t load_pa); +}; + static inline void *__load_addr(void *ptr, uintptr_t load_pa) { extern char _start; @@ -186,64 +197,347 @@ static inline void *__load_addr(void *ptr, uintptr_t load_pa) #define __load_va(ptr, load_pa) __load_addr(ptr, load_pa) #define __load_pa(ptr, load_pa) ((uintptr_t)__load_addr(ptr, load_pa)) -asmlinkage void __init setup_vm(uintptr_t load_pa) +static phys_addr_t __init final_alloc_pgtable(void) +{ + return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE); +} + +static pte_t *__init early_get_pte_virt(phys_addr_t pa) +{ + return (pte_t *)((uintptr_t)pa); +} + +static pte_t *__init final_get_pte_virt(phys_addr_t pa) +{ + clear_fixmap(FIX_PTE); + + return (pte_t *)set_fixmap_offset(FIX_PTE, pa); +} + +static phys_addr_t __init early_alloc_trampoline_pte(uintptr_t va, + uintptr_t load_pa) +{ + pte_t *base = __load_va(trampoline_pte, load_pa); + uintptr_t pte_num = ((va - PAGE_OFFSET) >> PMD_SHIFT); + + BUG_ON(pte_num >= NUM_TRAMPOLINE_PTES); + + return (uintptr_t)&base[pte_num * PTRS_PER_PTE]; +} + +static phys_addr_t __init early_alloc_swapper_pte(uintptr_t va, + uintptr_t load_pa) +{ + pte_t *base = __load_va(swapper_pte, load_pa); + uintptr_t pte_num = ((va - PAGE_OFFSET) >> PMD_SHIFT); + + BUG_ON(pte_num >= NUM_SWAPPER_PTES); + + return (uintptr_t)&base[pte_num * PTRS_PER_PTE]; +} + +static phys_addr_t __init final_alloc_pte(uintptr_t va, uintptr_t load_pa) +{ + return final_alloc_pgtable(); +} + +static void __init create_pte_mapping(pte_t *ptep, + uintptr_t va, phys_addr_t pa, + phys_addr_t sz, pgprot_t prot) { - uintptr_t i; + uintptr_t pte_index = pte_index(va); + + BUG_ON(sz != PAGE_SIZE); + + if (pte_none(ptep[pte_index])) + ptep[pte_index] = pfn_pte(PFN_DOWN(pa), prot); +} + #ifndef __PAGETABLE_PMD_FOLDED +static pmd_t *__init early_get_pmd_virt(phys_addr_t pa) +{ + return (pmd_t *)((uintptr_t)pa); +} + +static pmd_t *__init final_get_pmd_virt(phys_addr_t pa) +{ + clear_fixmap(FIX_PMD); + + return (pmd_t *)set_fixmap_offset(FIX_PMD, pa); +} + +static phys_addr_t __init early_alloc_trampoline_pmd(uintptr_t va, + uintptr_t load_pa) +{ + pmd_t *base = __load_va(trampoline_pmd, load_pa); + uintptr_t pmd_num = (va - PAGE_OFFSET) >> PGDIR_SHIFT; + + BUG_ON(pmd_num >= NUM_TRAMPOLINE_PMDS); + + return (uintptr_t)&base[pmd_num * PTRS_PER_PMD]; +} + +static phys_addr_t __init early_alloc_swapper_pmd(uintptr_t va, + uintptr_t load_pa) +{ + pmd_t *base = __load_va(swapper_pmd, load_pa); + uintptr_t pmd_num = (va - PAGE_OFFSET) >> PGDIR_SHIFT; + + BUG_ON(pmd_num >= NUM_SWAPPER_PMDS); + + return (uintptr_t)&base[pmd_num * PTRS_PER_PMD]; +} + +static phys_addr_t __init final_alloc_pmd(uintptr_t va, uintptr_t load_pa) +{ + return final_alloc_pgtable(); +} + +static void __init create_pmd_mapping(pmd_t *pmdp, + uintptr_t va, phys_addr_t pa, + phys_addr_t sz, pgprot_t prot, + uintptr_t ops_load_pa, + struct mapping_ops *ops) +{ + pte_t *ptep; + phys_addr_t pte_phys; + uintptr_t pmd_index = pmd_index(va); + + if (sz == PMD_SIZE) { + if (pmd_none(pmdp[pmd_index])) + pmdp[pmd_index] = pfn_pmd(PFN_DOWN(pa), prot); + return; + } + + if (pmd_none(pmdp[pmd_index])) { + pte_phys = ops->alloc_pte(va, ops_load_pa); + pmdp[pmd_index] = pfn_pmd(PFN_DOWN(pte_phys), + __pgprot(_PAGE_TABLE)); + ptep = ops->get_pte_virt(pte_phys); + memset(ptep, 0, PAGE_SIZE); + } else { + pte_phys = PFN_PHYS(_pmd_pfn(pmdp[pmd_index])); + ptep = ops->get_pte_virt(pte_phys); + } + + create_pte_mapping(ptep, va, pa, sz, prot); +} + +static void __init create_pgd_mapping(pgd_t *pgdp, + uintptr_t va, phys_addr_t pa, + phys_addr_t sz, pgprot_t prot, + uintptr_t ops_load_pa, + struct mapping_ops *ops) +{ pmd_t *pmdp; + phys_addr_t pmd_phys; + uintptr_t pgd_index = pgd_index(va); + + if (sz == PGDIR_SIZE) { + if (pgd_val(pgdp[pgd_index]) == 0) + pgdp[pgd_index] = pfn_pgd(PFN_DOWN(pa), prot); + return; + } + + if (pgd_val(pgdp[pgd_index]) == 0) { + pmd_phys = ops->alloc_pmd(va, ops_load_pa); + pgdp[pgd_index] = pfn_pgd(PFN_DOWN(pmd_phys), + __pgprot(_PAGE_TABLE)); + pmdp = ops->get_pmd_virt(pmd_phys); + memset(pmdp, 0, PAGE_SIZE); + } else { + pmd_phys = PFN_PHYS(_pgd_pfn(pgdp[pgd_index])); + pmdp = ops->get_pmd_virt(pmd_phys); + } + + create_pmd_mapping(pmdp, va, pa, sz, prot, ops_load_pa, ops); +} +#else +static void __init create_pgd_mapping(pgd_t *pgdp, + uintptr_t va, phys_addr_t pa, + phys_addr_t sz, pgprot_t prot, + uintptr_t ops_load_pa, + struct mapping_ops *ops) +{ + pte_t *ptep; + phys_addr_t pte_phys; + uintptr_t pgd_index = pgd_index(va); + + if (sz == PGDIR_SIZE) { + if (pgd_val(pgdp[pgd_index]) == 0) + pgdp[pgd_index] = pfn_pgd(PFN_DOWN(pa), prot); + return; + } + + if (pgd_val(pgdp[pgd_index]) == 0) { + pte_phys = ops->alloc_pte(va, ops_load_pa); + pgdp[pgd_index] = pfn_pgd(PFN_DOWN(pte_phys), + __pgprot(_PAGE_TABLE)); + ptep = ops->get_pte_virt(pte_phys); + memset(ptep, 0, PAGE_SIZE); + } else { + pte_phys = PFN_PHYS(_pgd_pfn(pgdp[pgd_index])); + ptep = ops->get_pte_virt(pte_phys); + } + + create_pte_mapping(ptep, va, pa, sz, prot); +} +#endif + +static uintptr_t __init best_map_size(uintptr_t load_pa, phys_addr_t size) +{ +#ifdef CONFIG_BOOT_PAGE_ALIGNED + uintptr_t map_sz = PAGE_SIZE; +#else +#ifndef __PAGETABLE_PMD_FOLDED + uintptr_t map_sz = PMD_SIZE; +#else + uintptr_t map_sz = PGDIR_SIZE; +#endif #endif - pgd_t *pgdp; + +#ifndef __PAGETABLE_PMD_FOLDED + if (!(load_pa & (PMD_SIZE - 1)) && + (size >= PMD_SIZE) && + (map_sz < PMD_SIZE)) + map_sz = PMD_SIZE; +#endif + + if (!(load_pa & (PGDIR_SIZE - 1)) && + (size >= PGDIR_SIZE) && + (map_sz < PGDIR_SIZE)) + map_sz = PGDIR_SIZE; + + return map_sz; +} + +asmlinkage void __init setup_vm(uintptr_t load_pa, uintptr_t dtb_pa) +{ phys_addr_t map_pa; + uintptr_t va, end_va; + uintptr_t load_sz = __load_pa(&_end, load_pa) - load_pa; pgprot_t tableprot = __pgprot(_PAGE_TABLE); pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC); + struct mapping_ops tramp_ops, swap_ops; va_pa_offset = PAGE_OFFSET - load_pa; pfn_base = PFN_DOWN(load_pa); + map_size = best_map_size(load_pa, PGDIR_SIZE); /* Sanity check alignment and size */ BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0); - BUG_ON((load_pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0); + BUG_ON((load_pa % map_size) != 0); + BUG_ON(load_sz > MAX_EARLY_MAPPING_SIZE); -#ifndef __PAGETABLE_PMD_FOLDED - pgdp = __load_va(trampoline_pg_dir, load_pa); - map_pa = __load_pa(trampoline_pmd, load_pa); - pgdp[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] = - pfn_pgd(PFN_DOWN(map_pa), tableprot); - trampoline_pmd[0] = pfn_pmd(PFN_DOWN(load_pa), prot); + /* Setup trampoline mapping ops */ + tramp_ops.get_pte_virt = __load_va(early_get_pte_virt, load_pa); + tramp_ops.alloc_pte = __load_va(early_alloc_trampoline_pte, load_pa); + tramp_ops.get_pmd_virt = NULL; + tramp_ops.alloc_pmd = NULL; - pgdp = __load_va(swapper_pg_dir, load_pa); + /* Setup swapper mapping ops */ + swap_ops.get_pte_virt = __load_va(early_get_pte_virt, load_pa); + swap_ops.alloc_pte = __load_va(early_alloc_swapper_pte, load_pa); + swap_ops.get_pmd_virt = NULL; + swap_ops.alloc_pmd = NULL; - for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) { - size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i; +#ifndef __PAGETABLE_PMD_FOLDED + /* Update trampoline mapping ops for PMD */ + tramp_ops.get_pmd_virt = __load_va(early_get_pmd_virt, load_pa); + tramp_ops.alloc_pmd = __load_va(early_alloc_trampoline_pmd, load_pa); - map_pa = __load_pa(swapper_pmd, load_pa); - pgdp[o] = pfn_pgd(PFN_DOWN(map_pa) + i, tableprot); - } - pmdp = __load_va(swapper_pmd, load_pa); - for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++) - pmdp[i] = pfn_pmd(PFN_DOWN(load_pa + i * PMD_SIZE), prot); + /* Update swapper mapping ops for PMD */ + swap_ops.get_pmd_virt = __load_va(early_get_pmd_virt, load_pa); + swap_ops.alloc_pmd = __load_va(early_alloc_swapper_pmd, load_pa); + /* Setup swapper PGD and PMD for fixmap */ map_pa = __load_pa(fixmap_pmd, load_pa); - pgdp[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] = - pfn_pgd(PFN_DOWN(map_pa), tableprot); - pmdp = __load_va(fixmap_pmd, load_pa); + create_pgd_mapping(__load_va(swapper_pg_dir, load_pa), + FIXADDR_START, map_pa, PGDIR_SIZE, tableprot, + load_pa, &swap_ops); map_pa = __load_pa(fixmap_pte, load_pa); - fixmap_pmd[(FIXADDR_START >> PMD_SHIFT) % PTRS_PER_PMD] = - pfn_pmd(PFN_DOWN(map_pa), tableprot); + create_pmd_mapping(__load_va(fixmap_pmd, load_pa), + FIXADDR_START, map_pa, PMD_SIZE, tableprot, + load_pa, &swap_ops); #else - pgdp = __load_va(trampoline_pg_dir, load_pa); - pgdp[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] = - pfn_pgd(PFN_DOWN(load_pa), prot); + /* Setup swapper PGD for fixmap */ + map_pa = __load_pa(fixmap_pte, load_pa); + create_pgd_mapping(__load_va(swapper_pg_dir, load_pa), + FIXADDR_START, map_pa, PGDIR_SIZE, tableprot, + load_pa, &swap_ops); +#endif - pgdp = __load_va(swapper_pg_dir, load_pa); - for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) { - size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i; + /* Setup trampoling PGD covering first few MBs of kernel */ + end_va = PAGE_OFFSET + PAGE_SIZE*PTRS_PER_PTE; + for (va = PAGE_OFFSET; va < end_va; va += map_size) + create_pgd_mapping(__load_va(trampoline_pg_dir, load_pa), + va, load_pa + (va - PAGE_OFFSET), + map_size, prot, load_pa, &tramp_ops); + + /* + * Setup swapper PGD covering entire kernel which will allows + * us to reach paging_init(). We map all memory banks later in + * setup_vm_final() below. + */ + end_va = PAGE_OFFSET + load_sz; + for (va = PAGE_OFFSET; va < end_va; va += map_size) + create_pgd_mapping(__load_va(swapper_pg_dir, load_pa), + va, load_pa + (va - PAGE_OFFSET), + map_size, prot, load_pa, &swap_ops); + + /* Create fixed mapping for early parsing of FDT */ + end_va = __fix_to_virt(FIX_FDT) + FIX_FDT_SIZE; + for (va = __fix_to_virt(FIX_FDT); va < end_va; va += PAGE_SIZE) + create_pte_mapping(__load_va(fixmap_pte, load_pa), + va, dtb_pa + (va - __fix_to_virt(FIX_FDT)), + PAGE_SIZE, prot); +} - pgdp[o] = pfn_pgd(PFN_DOWN(load_pa + i * PGDIR_SIZE), prot); - } +static void __init setup_vm_final(void) +{ + phys_addr_t pa, start, end; + struct memblock_region *reg; + struct mapping_ops ops; + pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC); - map_pa = __load_pa(fixmap_pte, load_pa); - pgdp[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] = - pfn_pgd(PFN_DOWN(map_pa), tableprot); + /* Setup mapping ops */ + ops.get_pte_virt = final_get_pte_virt; + ops.alloc_pte = final_alloc_pte; +#ifndef __PAGETABLE_PMD_FOLDED + ops.get_pmd_virt = final_get_pmd_virt; + ops.alloc_pmd = final_alloc_pmd; +#else + ops.get_pmd_virt = NULL; + ops.alloc_pmd = NULL; #endif + + /* Map all memory banks */ + for_each_memblock(memory, reg) { + start = reg->base; + end = start + reg->size; + + if (start >= end) + break; + if (memblock_is_nomap(reg)) + continue; + if (start <= __pa(PAGE_OFFSET) && + __pa(PAGE_OFFSET) < end) + start = __pa(PAGE_OFFSET); + + for (pa = start; pa < end; pa += map_size) + create_pgd_mapping(swapper_pg_dir, + (uintptr_t)__va(pa), pa, + map_size, prot, 0, &ops); + } + + clear_fixmap(FIX_PTE); + clear_fixmap(FIX_PMD); +} + +void __init paging_init(void) +{ + setup_vm_final(); + setup_zero_page(); + local_flush_tlb_all(); + zone_sizes_init(); } From patchwork Thu Mar 21 09:47:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10863209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CD8A1515 for ; Thu, 21 Mar 2019 09:48:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36BAC2A001 for ; Thu, 21 Mar 2019 09:48:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29CA02A067; Thu, 21 Mar 2019 09:48:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B4CC2A06A for ; Thu, 21 Mar 2019 09:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=urGucWPiUiGLPn20EEwAdfLW9RLw8VCxJU8y3Ya1VTY=; b=lcsmm5WYWpCEvQ Qk7wdHIjB/bopbmNcZiQOoo+VbXJej3wVlTjFo3uL4cdQ6Jieu40iFRgDQd/atYIYm0vGZenbldd4 znYMYEeraK6FNiWfeopeah1poHYBnlkd5hgvkE7SRSUL60sMzjzLnbGNULm4N2SF1EjevbvnsP+JP 98DswR4bh386MXoxxAKiN8V+xfj6oOMLbQ2FCn8Q0IGzFJ9Za7xB6+KamVnFHWw6VK+BT5nBTeY34 doutbDfkHysuIpFkv+hOQr/dw3g+mO5Teop7uD3g00zcHQHQ43+iAdLK6XKVJCPt8qfaIdAxCUQ+/ f0u0Ta5SuxfphQ3WBkNQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIs-0007oX-Jf; Thu, 21 Mar 2019 09:48:02 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIp-0007ks-73 for linux-riscv@lists.infradead.org; Thu, 21 Mar 2019 09:48:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1553161700; x=1584697700; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=TFYL4eqVb0jXiSXMlqxFlpDrPIsv9WoAzlfJnt9SHxs=; b=IEmn/zIkVZ0I1rBpL+bh7SW2o55HjbRFG4dHjUaHwe8lBzMcZQ1pAi+O CAbAWnIuZH8UYEbAMAU85JykB0UICPHxOpLM5KQu7FG0jvHz8Jhvpwfxo lXI7O8NjZFG6mmaC713YV93nWBkGkeN8TnR1veUCPJPWYYmebbDEyXkqF f7cZvLMEax0qmQR8eZ2ytbzb4Dqh35dYmybxTLV/WabtohBUeATSFXHY5 5+UvZPJocgqc/GgcqfTlo/DGUeB3wWkjYM1ta/yFdycqegs5rXXjtMmmO 8cfeDyD+zNlB9VWvmfciyDKErkwXL8YPEGD96MMSjUJc1VX7dowOA/V9b A==; X-IronPort-AV: E=Sophos;i="5.60,252,1549900800"; d="scan'208";a="202598360" Received: from mail-bl2nam02lp2056.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([104.47.38.56]) by ob1.hgst.iphmx.com with ESMTP; 21 Mar 2019 17:48:16 +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=Z3h8iZ+jadvxf04CQHJpGglOn7DTTWn4Y4fhaXeRsuM=; b=KpwkNqvmXlEM60lQaEQGBt7d6AoKQu7aAgJ2sBrqeCXna4HdzqfODi8v4FPdBbbiRRQJ/LZBhk7B9VDRMNeUMqAXWn101ryD2+MgXV8kup6Sx7ePA/oKaqLLYO5uf5+BqzTGgeU/dnhFc2b4BDzejj7AR/+KF432ObvtYe+HzdU= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.246.15) by MN2PR04MB6239.namprd04.prod.outlook.com (20.178.249.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Thu, 21 Mar 2019 09:47:55 +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.013; Thu, 21 Mar 2019 09:47:55 +0000 From: Anup Patel To: Palmer Dabbelt , Albert Ou Subject: [PATCH v2 4/5] RISC-V: Remove redundant trampoline page table Thread-Topic: [PATCH v2 4/5] RISC-V: Remove redundant trampoline page table Thread-Index: AQHU38sosu9cOHGmQkG5TxxiSwF1Nw== Date: Thu, 21 Mar 2019 09:47:55 +0000 Message-ID: <20190321094710.16552-5-anup.patel@wdc.com> References: <20190321094710.16552-1-anup.patel@wdc.com> In-Reply-To: <20190321094710.16552-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: PN1PR0101CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::23) 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: [106.51.18.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a2782063-6942-4428-1d90-08d6ade24acf x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:MN2PR04MB6239; x-ms-traffictypediagnostic: MN2PR04MB6239: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0983EAD6B2 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(376002)(366004)(136003)(396003)(346002)(189003)(199004)(256004)(6506007)(4326008)(6512007)(486006)(36756003)(2171002)(446003)(102836004)(478600001)(386003)(72206003)(53936002)(2906002)(305945005)(76176011)(11346002)(26005)(44832011)(14444005)(55236004)(7736002)(25786009)(14454004)(476003)(78486014)(1076003)(2616005)(52116002)(6486002)(6436002)(9456002)(81156014)(186003)(316002)(8676002)(5660300002)(68736007)(106356001)(105586002)(71200400001)(86362001)(81166006)(54906003)(8936002)(66066001)(97736004)(6116002)(71190400001)(3846002)(99286004)(110136005)(50226002); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2PR04MB6239; H:MN2PR04MB6061.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: pAy4iDkcWAVf9G5ckvoCEUILNEaGaEhV+FIRJvxxhjKP8S9qoz4SSekhjrvm6JKsML3/7KwA4py5Lq2KH+IqOZaVYbNYsvLV/9KLWFG43Yn5PpSoNpj307h4WMf9W32MaTSFzGVVM1boxE3oAz2bCMCzIth8768ZKqyzLH9FncZcmcl7ylx64ACuewXont0wOiAG5qsC7vMW9P+5WA4ufnhr6IDPVqNF41HsROE3RWSVofD0b4YoQhMMvQd0bSyyKpT2ss/3YB/D8VVUxl1ammhSPX++bdqC3/zDW5AqM+9TDK+TkIrQYKOi3qi5ze3aj3KDoeFO4PCdnqAywqn61aZtHTvCI4SgBVG24LNKZTAAen5jNIfxFhzRfM/xxHzoYNuW0nAh5AHpuiYLQTtXey99h1eFSGZhYgRY64Ex/Rg= MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2782063-6942-4428-1d90-08d6ade24acf X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2019 09:47:55.0976 (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: MN2PR04MB6239 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190321_024759_293519_19747C67 X-CRM114-Status: GOOD ( 15.80 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , "linux-kernel@vger.kernel.org" , Mike Rapoport , Christoph Hellwig , Atish Patra , Paul Walmsley , "linux-riscv@lists.infradead.org" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The trampoline page table is redundant because: 1. There is no mapping in trampoling page table which is not covered by swapper page table. 2. The relocate() in head.S will first load trampoline page table and after that it will load swapper page table. Same thing can be achieved by straight away loading swapper page table. 3. The trampoline page table is in init section. The relocate() will break after trampoline page table has been free'ed by kernel. This also means runtime HART hotplug will not work correctly due to broken relocate() after kernel is booted. Due to above, this patch removes trampoline page table and related code from kernel/head.S and mm/init.c. Signed-off-by: Anup Patel --- arch/riscv/kernel/head.S | 13 ++----- arch/riscv/mm/init.c | 79 ++++++++-------------------------------- 2 files changed, 19 insertions(+), 73 deletions(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 12a3ec5eb8ab..94f424e2038d 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -93,21 +93,19 @@ relocate: add a0, a0, a1 csrw stvec, a0 - /* Compute satp for kernel page tables, but don't load it yet */ + /* Compute satp for kernel page directory, but don't load it yet */ la a2, swapper_pg_dir srl a2, a2, PAGE_SHIFT li a1, SATP_MODE or a2, a2, a1 /* - * Load trampoline page directory, which will cause us to trap to + * Load kernel page directory, which will cause us to trap to * stvec if VA != PA, or simply fall through if VA == PA */ - la a0, trampoline_pg_dir - srl a0, a0, PAGE_SHIFT - or a0, a0, a1 sfence.vma - csrw sptbr, a0 + csrw sptbr, a2 + .align 2 1: /* Set trap vector to spin forever to help debug */ @@ -120,9 +118,6 @@ relocate: la gp, __global_pointer$ .option pop - /* Switch to kernel page tables */ - csrw sptbr, a2 - ret .Lsecondary_start: diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index c389fbfeccd8..2e2f2567964c 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -132,7 +132,6 @@ void __init setup_bootmem(void) #define MAX_EARLY_MAPPING_SIZE SZ_128M pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; -pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE); #ifndef __PAGETABLE_PMD_FOLDED #if MAX_EARLY_MAPPING_SIZE < PGDIR_SIZE @@ -140,21 +139,14 @@ pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE); #else #define NUM_SWAPPER_PMDS (MAX_EARLY_MAPPING_SIZE/PGDIR_SIZE) #endif -#define NUM_TRAMPOLINE_PMDS 1UL pmd_t swapper_pmd[PTRS_PER_PMD*NUM_SWAPPER_PMDS] __page_aligned_bss; -pmd_t trampoline_pmd[PTRS_PER_PMD*NUM_TRAMPOLINE_PMDS] - __initdata __aligned(PAGE_SIZE); pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss; #define NUM_SWAPPER_PTES (MAX_EARLY_MAPPING_SIZE/PMD_SIZE) #else #define NUM_SWAPPER_PTES (MAX_EARLY_MAPPING_SIZE/PGDIR_SIZE) #endif -#define NUM_TRAMPOLINE_PTES 1UL - pte_t swapper_pte[PTRS_PER_PTE*NUM_SWAPPER_PTES] __page_aligned_bss; -pte_t trampoline_pte[PTRS_PER_PTE*NUM_TRAMPOLINE_PTES] - __initdata __aligned(PAGE_SIZE); pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss; uintptr_t map_size; @@ -214,19 +206,7 @@ static pte_t *__init final_get_pte_virt(phys_addr_t pa) return (pte_t *)set_fixmap_offset(FIX_PTE, pa); } -static phys_addr_t __init early_alloc_trampoline_pte(uintptr_t va, - uintptr_t load_pa) -{ - pte_t *base = __load_va(trampoline_pte, load_pa); - uintptr_t pte_num = ((va - PAGE_OFFSET) >> PMD_SHIFT); - - BUG_ON(pte_num >= NUM_TRAMPOLINE_PTES); - - return (uintptr_t)&base[pte_num * PTRS_PER_PTE]; -} - -static phys_addr_t __init early_alloc_swapper_pte(uintptr_t va, - uintptr_t load_pa) +static phys_addr_t __init early_alloc_pte(uintptr_t va, uintptr_t load_pa) { pte_t *base = __load_va(swapper_pte, load_pa); uintptr_t pte_num = ((va - PAGE_OFFSET) >> PMD_SHIFT); @@ -266,19 +246,7 @@ static pmd_t *__init final_get_pmd_virt(phys_addr_t pa) return (pmd_t *)set_fixmap_offset(FIX_PMD, pa); } -static phys_addr_t __init early_alloc_trampoline_pmd(uintptr_t va, - uintptr_t load_pa) -{ - pmd_t *base = __load_va(trampoline_pmd, load_pa); - uintptr_t pmd_num = (va - PAGE_OFFSET) >> PGDIR_SHIFT; - - BUG_ON(pmd_num >= NUM_TRAMPOLINE_PMDS); - - return (uintptr_t)&base[pmd_num * PTRS_PER_PMD]; -} - -static phys_addr_t __init early_alloc_swapper_pmd(uintptr_t va, - uintptr_t load_pa) +static phys_addr_t __init early_alloc_pmd(uintptr_t va, uintptr_t load_pa) { pmd_t *base = __load_va(swapper_pmd, load_pa); uintptr_t pmd_num = (va - PAGE_OFFSET) >> PGDIR_SHIFT; @@ -418,7 +386,7 @@ asmlinkage void __init setup_vm(uintptr_t load_pa, uintptr_t dtb_pa) uintptr_t load_sz = __load_pa(&_end, load_pa) - load_pa; pgprot_t tableprot = __pgprot(_PAGE_TABLE); pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC); - struct mapping_ops tramp_ops, swap_ops; + struct mapping_ops ops; va_pa_offset = PAGE_OFFSET - load_pa; pfn_base = PFN_DOWN(load_pa); @@ -429,51 +397,34 @@ asmlinkage void __init setup_vm(uintptr_t load_pa, uintptr_t dtb_pa) BUG_ON((load_pa % map_size) != 0); BUG_ON(load_sz > MAX_EARLY_MAPPING_SIZE); - /* Setup trampoline mapping ops */ - tramp_ops.get_pte_virt = __load_va(early_get_pte_virt, load_pa); - tramp_ops.alloc_pte = __load_va(early_alloc_trampoline_pte, load_pa); - tramp_ops.get_pmd_virt = NULL; - tramp_ops.alloc_pmd = NULL; - - /* Setup swapper mapping ops */ - swap_ops.get_pte_virt = __load_va(early_get_pte_virt, load_pa); - swap_ops.alloc_pte = __load_va(early_alloc_swapper_pte, load_pa); - swap_ops.get_pmd_virt = NULL; - swap_ops.alloc_pmd = NULL; + /* Setup mapping ops */ + ops.get_pte_virt = __load_va(early_get_pte_virt, load_pa); + ops.alloc_pte = __load_va(early_alloc_pte, load_pa); + ops.get_pmd_virt = NULL; + ops.alloc_pmd = NULL; #ifndef __PAGETABLE_PMD_FOLDED - /* Update trampoline mapping ops for PMD */ - tramp_ops.get_pmd_virt = __load_va(early_get_pmd_virt, load_pa); - tramp_ops.alloc_pmd = __load_va(early_alloc_trampoline_pmd, load_pa); - - /* Update swapper mapping ops for PMD */ - swap_ops.get_pmd_virt = __load_va(early_get_pmd_virt, load_pa); - swap_ops.alloc_pmd = __load_va(early_alloc_swapper_pmd, load_pa); + /* Update mapping ops for PMD */ + ops.get_pmd_virt = __load_va(early_get_pmd_virt, load_pa); + ops.alloc_pmd = __load_va(early_alloc_pmd, load_pa); /* Setup swapper PGD and PMD for fixmap */ map_pa = __load_pa(fixmap_pmd, load_pa); create_pgd_mapping(__load_va(swapper_pg_dir, load_pa), FIXADDR_START, map_pa, PGDIR_SIZE, tableprot, - load_pa, &swap_ops); + load_pa, &ops); map_pa = __load_pa(fixmap_pte, load_pa); create_pmd_mapping(__load_va(fixmap_pmd, load_pa), FIXADDR_START, map_pa, PMD_SIZE, tableprot, - load_pa, &swap_ops); + load_pa, &ops); #else /* Setup swapper PGD for fixmap */ map_pa = __load_pa(fixmap_pte, load_pa); create_pgd_mapping(__load_va(swapper_pg_dir, load_pa), FIXADDR_START, map_pa, PGDIR_SIZE, tableprot, - load_pa, &swap_ops); + load_pa, &ops); #endif - /* Setup trampoling PGD covering first few MBs of kernel */ - end_va = PAGE_OFFSET + PAGE_SIZE*PTRS_PER_PTE; - for (va = PAGE_OFFSET; va < end_va; va += map_size) - create_pgd_mapping(__load_va(trampoline_pg_dir, load_pa), - va, load_pa + (va - PAGE_OFFSET), - map_size, prot, load_pa, &tramp_ops); - /* * Setup swapper PGD covering entire kernel which will allows * us to reach paging_init(). We map all memory banks later in @@ -483,7 +434,7 @@ asmlinkage void __init setup_vm(uintptr_t load_pa, uintptr_t dtb_pa) for (va = PAGE_OFFSET; va < end_va; va += map_size) create_pgd_mapping(__load_va(swapper_pg_dir, load_pa), va, load_pa + (va - PAGE_OFFSET), - map_size, prot, load_pa, &swap_ops); + map_size, prot, load_pa, &ops); /* Create fixed mapping for early parsing of FDT */ end_va = __fix_to_virt(FIX_FDT) + FIX_FDT_SIZE; From patchwork Thu Mar 21 09:47:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10863211 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14B571515 for ; Thu, 21 Mar 2019 09:48:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E19332A06A for ; Thu, 21 Mar 2019 09:48:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5C972A096; Thu, 21 Mar 2019 09:48:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 758582A06A for ; Thu, 21 Mar 2019 09:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WKmfxJ70AUemCjMquCC51Qr12hOyyNqYDKlSuuimf2k=; b=k46hk0Cdo0HLBN iuheUhS3spcI6aPObTTMFIrBPBJDxTz7CR5Kj4KFhv5RMBbNnYKrf2h+fzYZxtCz6h4CmO5UcoSf2 RL7ot2ACFIe4x8Ncsxx6AafLMDKZElHQZmUxH1yjazt6u37GJzUAnFGGjaqQIfzo9NA63XVIzjYN8 tDFAMOT1jrqKBPadX0y0BB3+AmMMEV2gZkdsUwIhTk2R1wMmpx1ArtvTtupK6TAswlauZ4bDvpvWA 9W+EgOElTovlltVYjt5T7PclRK51IbofR/Ci72nF6EMr4pdcXCpDtWOvPqkU2JkEJXLmSk9xJA2dI psLEFrjNwignxDQgCsNw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIv-0007rD-95; Thu, 21 Mar 2019 09:48:05 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6uIs-0007bS-2B for linux-riscv@lists.infradead.org; Thu, 21 Mar 2019 09:48:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1553161682; x=1584697682; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Q6hXRzC0vGA645ktNicxb3BEemwCUqYLlnUqgkKeibE=; b=qrIjZ77mNl0IvV0w9BjFCptV3Sry+iaZKuudtfrbe+Lr/oH32DM/L+ML MT5obrWDP3nI1NShouQyrbPowLLO2oqtyrcs7WT5qR62AjbnxNIiVi9Pu nFvoVC5LY6SLINrqEbd94b73KtPGM/LM7vn9WmRCrd62YkSCk14CUkSeQ DfIpgKLZD36ewBhWJfOLNtAXI8JBQBvRb82v3ow4slAwBUDVIQKP5OzcC wT3QUcbdluHZ7FIr08A4Sg1jENdBWLQGCDQnRzoOTm4HdHwy34iFLeiae l8V4Gtrzx7t5r8if2sIWXssa3z0WRkmyqHU0Z5YyYMXUWBYk9Pck/+utA A==; X-IronPort-AV: E=Sophos;i="5.60,252,1549900800"; d="scan'208";a="105647572" Received: from mail-by2nam05lp2053.outbound.protection.outlook.com (HELO NAM05-BY2-obe.outbound.protection.outlook.com) ([104.47.50.53]) by ob1.hgst.iphmx.com with ESMTP; 21 Mar 2019 17:48:01 +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=4LbwOC8XHClkPLqdxM/n9B1nf499u0WZ63uDkO9yh54=; b=YV4A9AA0s8p93yLutItilWhmdWe2FfRLk+lLWcH46KyrJH/w49GsXSA+pzspkGgfKrafBOLpzsD6YIh2jacQwhdPYmyCYwUh70BOj2cD2xwpDREq2l182dR76mnqR5PTGpRIUV/8AcN+L92z4oOyesR2YR2Mf8lPsmHPsMB8qa0= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.246.15) by MN2PR04MB5757.namprd04.prod.outlook.com (20.179.21.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.14; Thu, 21 Mar 2019 09:47:59 +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.013; Thu, 21 Mar 2019 09:47:59 +0000 From: Anup Patel To: Palmer Dabbelt , Albert Ou Subject: [PATCH v2 5/5] RISC-V: Fix memory reservation in setup_bootmem() Thread-Topic: [PATCH v2 5/5] RISC-V: Fix memory reservation in setup_bootmem() Thread-Index: AQHU38sqoeGxllaIbUykcsHRC35P2A== Date: Thu, 21 Mar 2019 09:47:58 +0000 Message-ID: <20190321094710.16552-6-anup.patel@wdc.com> References: <20190321094710.16552-1-anup.patel@wdc.com> In-Reply-To: <20190321094710.16552-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: PN1PR0101CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::23) 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: [106.51.18.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 177279ee-b41f-4faa-49d8-08d6ade24d20 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:MN2PR04MB5757; x-ms-traffictypediagnostic: MN2PR04MB5757: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0983EAD6B2 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(376002)(346002)(136003)(366004)(396003)(189003)(199004)(54906003)(1076003)(68736007)(110136005)(316002)(6436002)(81166006)(2906002)(78486014)(8936002)(5660300002)(25786009)(50226002)(6486002)(52116002)(102836004)(6506007)(36756003)(386003)(26005)(9456002)(186003)(76176011)(97736004)(99286004)(11346002)(446003)(476003)(486006)(2616005)(44832011)(81156014)(105586002)(14454004)(4326008)(72206003)(106356001)(256004)(86362001)(55236004)(6512007)(71190400001)(7736002)(71200400001)(66066001)(3846002)(478600001)(305945005)(6116002)(53936002)(2171002)(8676002); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2PR04MB5757; H:MN2PR04MB6061.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Eb3W4JB1Mdxp/nq209Dc01qXKnHHc2l03eOvJOgRGR0M7lys0Ltd1157F1RvBDAC9AYzrGCVEQmypGkFjjOmyvWOVfiNaJGPeSADMNorTlqyu/Y2iztwhIqx+L9C6VnRPaIBCYwY1fckkXIuPhNfVCWGABIPo0v3jsCclR6tgMnJWGW7O8ldX6tXVGaOSqUKIwAHB8+8quGrO/wpputA00DFGT89qpS+ehFzAMXZv7I8n8E4Kq28rAcMOujzQJP/K8QWYcrC8Idhb7KazgAhEHYbc27zMtvbEx5M3CCSc7hGrysrMozt+upOBsEitLaZ1yTwwNg9+bQcalhAsP/YsDOVz9alf9Bbae7LkLloHk9HJNiu+Tj6xaVgRTbLOfIsgppatsWZrz3PqSqR5M3QMYL4sQ4djhJEU9f5sHodBK4= MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 177279ee-b41f-4faa-49d8-08d6ade24d20 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2019 09:47:58.9921 (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: MN2PR04MB5757 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190321_024802_176845_3A287D04 X-CRM114-Status: GOOD ( 18.65 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , "linux-kernel@vger.kernel.org" , Mike Rapoport , Christoph Hellwig , Atish Patra , Paul Walmsley , "linux-riscv@lists.infradead.org" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, the setup_bootmem() reserves memory from RAM start to the kernel end. This prevents us from exploring ways to use the RAM below (or before) the kernel start hence this patch updates setup_bootmem() to only reserve memory from the kernel start to the kernel end. Signed-off-by: Mike Rapoport Signed-off-by: Anup Patel Reviewed-by: Christoph Hellwig --- arch/riscv/mm/init.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 2e2f2567964c..99b42380d17d 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -18,6 +18,8 @@ #include #include +extern char _start[]; + static void __init zone_sizes_init(void) { unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, }; @@ -93,15 +95,17 @@ void __init setup_bootmem(void) /* Find the memory region containing the kernel */ for_each_memblock(memory, reg) { - phys_addr_t vmlinux_end = __pa(_end); + phys_addr_t vmlinux_end = __pa(&_end); + phys_addr_t vmlinux_start = __pa(&_start); phys_addr_t end = reg->base + reg->size; if (reg->base <= vmlinux_end && vmlinux_end <= end) { /* - * Reserve from the start of the region to the end of + * Reserve from the start of the kernel to the end of * the kernel */ - memblock_reserve(reg->base, vmlinux_end - reg->base); + memblock_reserve(vmlinux_start, + vmlinux_end - vmlinux_start); mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET); } } @@ -177,7 +181,6 @@ struct mapping_ops { static inline void *__load_addr(void *ptr, uintptr_t load_pa) { - extern char _start; uintptr_t va = (uintptr_t)ptr; uintptr_t sz = (uintptr_t)(&_end) - (uintptr_t)(&_start);