Message ID | 20230106060535.104321-1-jeeheng.sia@starfivetech.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp665241wrt; Thu, 5 Jan 2023 22:06:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXupQGYnHtrqY6uFO0nluhBStaDYJTMAJvEf/SHJmmpy92+JzdOu7Aa5aAxOZ9ODiwn/r1Rx X-Received: by 2002:a17:902:e944:b0:189:d8fb:1523 with SMTP id b4-20020a170902e94400b00189d8fb1523mr63936081pll.36.1672985176963; Thu, 05 Jan 2023 22:06:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672985176; cv=none; d=google.com; s=arc-20160816; b=z7xPhSa0SeY7UYCC8yu9zRzzxKDVhKKa5PMhITSGwnUPqA4B5eemBT5ebj5tRcY2yY DfSAxrDHOXrD9AIDm0UGx3fh0WEkluzvhURjxYCvnFRjmfalHlg8Ajw95lcstnuZCCvx k9CyepnmQQ1ODkGMNT58bpRYkdkmJSMb3lZN/T6NFTqIFQht3+f5VonCVG8idUu+P+i8 zn3ur5toiSflpMyUvWvP9XQcH0lHbQqt1r+eKVzRmG96HmCzCxeKQ5fVaY16qnpmhqMN sg4nvdeAOy99AJSNzsAA6kFJKCahlkPjBL3kN/YoUnExR1RvKQduQnmpqefAt4nDnF6/ hssw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e17-20020a656891000000b0049cd14d3a7esi555703pgt.75.2023.01.05.22.06.04; Thu, 05 Jan 2023 22:06:16 -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 <rfc822;tmhikaru@gmail.com> + 99 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <jeeheng.sia@starfivetech.com> To: <paul.walmsley@sifive.com>, <palmer@dabbelt.com>, <aou@eecs.berkeley.edu> CC: <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>, <jeeheng.sia@starfivetech.com>, <leyfoon.tan@starfivetech.com>, <mason.huo@starfivetech.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754252104784259231?= X-GMAIL-MSGID: =?utf-8?q?1754252104784259231?= |
Series | RISC-V Hibernation Support | |
Message
JeeHeng Sia
Jan. 6, 2023, 6:05 a.m. UTC
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
Comments
Hey folks, Just passing on some issues that automation picked up. On 6 January 2023 06:05:32 GMT, Sia Jee Heng <jeeheng.sia@starfivetech.com> wrote: >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 Unfortunately this breaks rv32_defconfig https://patchwork.kernel.org/project/linux-riscv/patch/20230106060535.104321-3-jeeheng.sia@starfivetech.com/ > RISC-V: Add arch functions to support hibernation/suspend-to-disk This one then breaks rv64 allmodconfig too :/ https://patchwork.kernel.org/project/linux-riscv/patch/20230106060535.104321-4-jeeheng.sia@starfivetech.com/ Thanks, Conor. > > 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
> -----Original Message----- > From: Conor Dooley <conor@kernel.org> > Sent: Friday, 6 January, 2023 5:38 PM > To: JeeHeng Sia <jeeheng.sia@starfivetech.com>; paul.walmsley@sifive.com; > palmer@dabbelt.com; aou@eecs.berkeley.edu > Cc: linux-riscv@lists.infradead.org; linux-kernel@vger.kernel.org; JeeHeng Sia > <jeeheng.sia@starfivetech.com>; Leyfoon Tan > <leyfoon.tan@starfivetech.com>; Mason Huo > <mason.huo@starfivetech.com> > Subject: Re: [PATCH 0/3] RISC-V Hibernation Support > > Hey folks, > Just passing on some issues that automation picked up. Thanks. Will submit a new patches series to address the issues. > > > On 6 January 2023 06:05:32 GMT, Sia Jee Heng > <jeeheng.sia@starfivetech.com> wrote: > >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 > > Unfortunately this breaks rv32_defconfig > https://patchwork.kernel.org/project/linux- > riscv/patch/20230106060535.104321-3-jeeheng.sia@starfivetech.com/ > > > RISC-V: Add arch functions to support hibernation/suspend-to-disk > > This one then breaks rv64 allmodconfig too :/ > > https://patchwork.kernel.org/project/linux- > riscv/patch/20230106060535.104321-4-jeeheng.sia@starfivetech.com/ > > Thanks, > Conor. > > > > > 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