Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1919069rwl; Thu, 5 Jan 2023 22:31:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXv6Fa/InglbTvFlot2WvP8eUjCglO9C5gW3XTwDOOPEbB1R+/hEGW0ZMBsQU8jr7BezDYf1 X-Received: by 2002:a17:907:d093:b0:7c0:cd95:bbb7 with SMTP id vc19-20020a170907d09300b007c0cd95bbb7mr42258982ejc.77.1672986719758; Thu, 05 Jan 2023 22:31:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672986719; cv=none; d=google.com; s=arc-20160816; b=F+M8wzzsv7YTuI308K0UC7vJ22I3pNJ1qeVj1L1Uv8VZUay7eNLzJ9RqvJOgt3PQb+ XRlTGuTzMl6Ddzmpo2PzsV56IYdT5SmPJdZgLrZ4zZqBSzcP6P9C35E8HTpjESelfmwM pEzd2qSZBLOQbTelvHfFF06PPPyU246Mi5yo637byQ0tcpmDkTck8tbbe4w9LPqpamxc jfyhw52u6PPp0UVdSIzjsoc+D3WG8ADkDqdC5YkQdlMS22ABIfvVSIbQJT0ifGV+5+y7 1TtEA3ApPNx5DPt89ItlOmcjmAwVL/m9NAa0PTHDeVOgg+3iGF7ja2L0n1RGPrkvsxr3 Kivg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Br38cAJ0e7fiqlbsjr3y63h4haiYw1/tf6jkDriWzbY=; b=VXTBJL9mCdCafgnt5+UxjrkZElWs0glJh8NhVje9ELnxMCWCZB72DM9qDpaahJorXx u7cgfowKvQp4jjUxOQSAf00tZ/h+gfic71c7lqaI0jn1Hdzdq9UYn41g8d7udYjSWl2K ACrj04hMrnCI7aKDvCP/FB5GE5ykJmAihi4c4wefAUqBmopFDcKmdiPraKqM8b8CwxgO sp2JEeaQCA1IgYxveAQoVFEE9Z2TS1jl96/i0eptwGQaJUDlu/jII6KsdiLunozWOgO1 TnO+7ySzDpqfv/7fh6x9ARZnHAIHY7+Q3teWcnZQWhq0qEyL7GzQUbyzYPU9p9ZQN8X6 zQtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wv4-20020a170907080400b007c10bb5b4b3si356371ejb.681.2023.01.05.22.31.47; Thu, 05 Jan 2023 22:31:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230184AbjAFGF6 convert rfc822-to-8bit (ORCPT + 56 others); Fri, 6 Jan 2023 01:05:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbjAFGF4 (ORCPT ); Fri, 6 Jan 2023 01:05:56 -0500 Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7721C41E for ; Thu, 5 Jan 2023 22:05:48 -0800 (PST) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id 7583424E035; Fri, 6 Jan 2023 14:05:45 +0800 (CST) Received: from EXMBX066.cuchost.com (172.16.7.66) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 6 Jan 2023 14:05:45 +0800 Received: from jsia-virtual-machine.localdomain (202.188.176.82) by EXMBX066.cuchost.com (172.16.6.66) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 6 Jan 2023 14:05:41 +0800 From: Sia Jee Heng To: , , CC: , , , , Subject: [PATCH 0/3] RISC-V Hibernation Support Date: Fri, 6 Jan 2023 14:05:32 +0800 Message-ID: <20230106060535.104321-1-jeeheng.sia@starfivetech.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [202.188.176.82] X-ClientProxiedBy: EXCAS061.cuchost.com (172.16.6.21) To EXMBX066.cuchost.com (172.16.6.66) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series adds RISC-V Hibernation/suspend to disk support. Low level Arch functions were created to support hibernation. swsusp_arch_suspend() relies code from __cpu_suspend_enter() to write cpu state onto the stack, then calling swsusp_save() to save the memory image. arch_hibernation_header_restore() and arch_hibernation_header_save() functions are implemented to prevent kernel crash when resume, the kernel built version is saved into the hibernation image header to making sure only the same kernel is restore when resume. swsusp_arch_resume() creates a temporary page table that covering only the linear map, copies the restore code to a 'safe' page, then start to restore the memory image. Once completed, it restores the original kernel's page table. It then calls into __hibernate_cpu_resume() to restore the CPU context. Finally, it follows the normal hibernation path back to the hibernation core. To enable hibernation/suspend to disk into RISCV, the below config need to be enabled: - CONFIG_ARCH_HIBERNATION_HEADER - CONFIG_ARCH_HIBERNATION_POSSIBLE At high-level, this series includes the following changes: 1) Change suspend_save_csrs() and suspend_restore_csrs() to public function as these functions are common to suspend/hibernation. (patch 1) 2) Enhance kernel_page_present() function to support huge page. (patch 2) 3) Add arch/riscv low level functions to support hibernation/suspend to disk. (patch 3) The above patches are based on kernel v6.2-rc2 and are tested on Starfive VF2 SBC board. Sia Jee Heng (3): RISC-V: Change suspend_save_csrs and suspend_restore_csrs to public function RISC-V: mm: Enable huge page support to kernel_page_present() function RISC-V: Add arch functions to support hibernation/suspend-to-disk arch/riscv/Kconfig | 7 + arch/riscv/include/asm/suspend.h | 23 ++ arch/riscv/kernel/Makefile | 2 +- arch/riscv/kernel/asm-offsets.c | 5 + arch/riscv/kernel/hibernate-asm.S | 123 +++++++++++ arch/riscv/kernel/hibernate.c | 353 ++++++++++++++++++++++++++++++ arch/riscv/kernel/suspend.c | 4 +- arch/riscv/mm/pageattr.c | 6 + 8 files changed, 520 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/kernel/hibernate-asm.S create mode 100644 arch/riscv/kernel/hibernate.c base-commit: 1f5abbd77e2c1787e74b7c2caffac97def78ba52 -- 2.34.1