From patchwork Mon Jan 9 06:24:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JeeHeng Sia X-Patchwork-Id: 3721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2002418wrt; Sun, 8 Jan 2023 22:26:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXv8dHTvmIW2RhuMs9hoWYOruMTP8mdhsVKU9BQj1Lk/w2oSkQtH87h+us1ENgXvIxMpCtp2 X-Received: by 2002:a17:906:9f07:b0:7ec:27d7:1838 with SMTP id fy7-20020a1709069f0700b007ec27d71838mr68621955ejc.22.1673245608838; Sun, 08 Jan 2023 22:26:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673245608; cv=none; d=google.com; s=arc-20160816; b=ONUZJJ4PhHp4fMKV+ZF6HCsJHE4k5kHlzw9QsZBm5jLQ6os4VFqmxvUn+plDT2DDS+ U1M6tltoYTheC9XaBdbE4j9WlX1KPM8Tf6MPwahFGLh5CgT+Ow1u55LIHdSliVZwo/VA DgIG4klhpGVah/mDt4kedhBEXHRNwjp/yheCuI1lT2cYshWL+UPiAPJqdchp6jcTIAFQ Xyl4HTBmEhuyGjhaBAO8VRaSzpwKxrdSImSLaitr2wAogGCnuxRTPFeFDjXOa1dKBN8Y d1WE6ZTVU9lcGeVNn3AxAU4Qw2I/2cZd4VFP3f4lmycNM8+5JtThTGMKXs+kW3ghjPHc XC5w== 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=BbvO4Ry9L9lwVn68HL8svQfXJ9KYNNpcD3V2HlVZE1c=; b=smWKjMvHEO0PSQLybdu/Ik/FVKQfNCVfssb3MhlaVh+2MOcxS27CMBZJZLe6Hsq9oG gwidp9Q07hD8juZ1K0amYnztCk7Plb4rQq8qFxGpCMXmdCGAspcqYZOvF29n9uTE2l+X U3HdpNc6GR9NMHQs31cgSun49g4jI0ro/y09SuxQB9v4KxFkAfU01Pt2BOpN9wFbNFnJ CUE0EC3gSLDhawePSeFDU4o8JRF6ChtHsQFVi5vXMWro6y+4v9tMhO7/heqFd6/y/BDG fUQxZjphV4G3NJ7Sh1+C5TLv+kPVA1c6pYcZfCy8+q0/RlAsH98VPDul8uT1XBDwK0O2 ok2Q== 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 wu1-20020a170906eec100b0078d2a99972fsi8913278ejb.316.2023.01.08.22.26.25; Sun, 08 Jan 2023 22:26:48 -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 S233682AbjAIGYt convert rfc822-to-8bit (ORCPT + 99 others); Mon, 9 Jan 2023 01:24:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbjAIGYW (ORCPT ); Mon, 9 Jan 2023 01:24:22 -0500 Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A047BE14 for ; Sun, 8 Jan 2023 22:24:17 -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 DF58924E035; Mon, 9 Jan 2023 14:24:15 +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; Mon, 9 Jan 2023 14:24:15 +0800 Received: from jsia-virtual-machine.localdomain (60.49.128.133) by EXMBX066.cuchost.com (172.16.6.66) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 9 Jan 2023 14:24:12 +0800 From: Sia Jee Heng To: , , CC: , , , , Subject: [PATCH v2 0/3] RISC-V Hibernation Support Date: Mon, 9 Jan 2023 14:24:04 +0800 Message-ID: <20230109062407.3235-1-jeeheng.sia@starfivetech.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [60.49.128.133] X-ClientProxiedBy: EXCAS066.cuchost.com (172.16.6.26) To EXMBX066.cuchost.com (172.16.6.66) X-YovoleRuleAgent: yovoleflag 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754525187411286265?= X-GMAIL-MSGID: =?utf-8?q?1754525187411286265?= 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 - CONFIG_ARCH_RV64I - CONFIG_64BIT 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-rc3 and are tested on StarFive VF2 SBC board. Hibernation for RV32 and ACPI platform mode are not supported in this series at the moment. Changes since v1: - Rebased to kernel v6.2-rc3 - Fixed bot's compilation error 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 | 8 + 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, 521 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/kernel/hibernate-asm.S create mode 100644 arch/riscv/kernel/hibernate.c base-commit: 1fe4fd6f5cad346e598593af36caeadc4f5d4fa9