From patchwork Fri Mar 11 17:57:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12778490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 320D6C4332F for ; Fri, 11 Mar 2022 17:58:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ytDz2G0yazNdrPmckpOaE0rlZPAPLSh6QxdYNldAhjk=; b=GYXeafy7B7EdH1O++acbAhb9g4 wSIexz3gc2PvNhz2BcHPnnhiJJ7Q+9riTbZpvBlzXb7FP5Y4oYnr/LaVbk1UxCWsetsNoPoeGXzzV qIE1N4A4dMDSTrEwO2K9XOmARe41fGIMHPVaYCYR5gRrS343Y+RJE1E5oxCUCz6LHE5xktSsytm1Y 9u+EwiBq1p/0uggMyzpWSkiftt9SKIPcD+shywJ+0bZ32TJ9nQsiVG2g4aPZaiR0H2eDwZbXewBZa EvXxdoZmHE/GCQIcusqSeYlUnVRz1LPumeH4mfIPf8lsBwHzCCFVAz9Pt0UveFT4USsvD2vwi3Wsi Wmholi9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjW7-00HYDi-B6; Fri, 11 Mar 2022 17:57:31 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjW4-00HYCK-1z for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 17:57:29 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d07ae11462so75101667b3.8 for ; Fri, 11 Mar 2022 09:57:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XCuvtprnSb0PQ/tTeAtCenAIJT2ThbfBVkwuYC3SZPg=; b=kt7/mh7D7/XK6jC/qxq5AKckTCsDG9s1vf0i5tSAGW3qW+PMa+EbHCv7HEUNbZqBhn yWZM0d5kwmCn3UPnOiteAwCNH/RHYa1o5c1R5jo8a2mbiVT1BlQdcX08fWiKdTf3inGd /wA2Nspc1mpYoqG3077m2DcigYRNrisUBQxjc+WR8l6t9YyToIDr1FoyvzRozet51MAp WDbs7eygrxtaCKkB07ogoj7KfiS02MArxQf8AGUZemcSUnL+eKAi/V2jj/IgENgEnisM 1AWYtPsvAfBxtwunoa98mEFgtQK3j9S0fT466vXE3yggcKERk61aovGUFw/uZZyAQ3CX 5DFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XCuvtprnSb0PQ/tTeAtCenAIJT2ThbfBVkwuYC3SZPg=; b=JdHSwU6FL++5rkYi1DgOErRif6EhTWLU9JDU1AJGexgQV/sHBH6uSuvjSCJeIlYauG qa+DHgtVaPWeYo4FpwFAn13MCJKFXd+WS8VTtVDTFl8e3/4/l4wL409SDcz3QlYE3NA8 aaSyfrEWu/0cQGF1R2WZQa7fmhaInsekRsqh1Zoe1AQ4tI6XC1fG9M/9s+/t8bfPGc0b 2WkJwRsSibuLgHeexkJgwOq9rqY9frw6yJ2MRp98aGB/DeZgHu0dx4O/arFBtDvNoIj2 +Fozjbi0lW6fuNVC6LSEqEMIdEKYzrQ2K+QXuSr2LPcJ72cKuSX2GlLL8vhEQRisjY1r QLqA== X-Gm-Message-State: AOAM533fgu57xBZdPc4o3AzX5tjwOM5AJy0UWKpS2HzduE95BqhL18cF JeUA2aGmS54NnCvpZ4qR2doN5h/HYxM= X-Google-Smtp-Source: ABdhPJzyWAv8S/KHu/ZXZs/nZFoiMKCNOwLwIUWaIPx4cyu6tv+ii6X96+maMdMohSISaf+E5F1ZO7oskvs= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a25:fb05:0:b0:628:8c88:acf5 with SMTP id j5-20020a25fb05000000b006288c88acf5mr8952224ybe.187.1647021445912; Fri, 11 Mar 2022 09:57:25 -0800 (PST) Date: Fri, 11 Mar 2022 17:57:12 +0000 In-Reply-To: <20220311174001.605719-1-oupton@google.com> Message-Id: <20220311175717.616958-1-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [RFC PATCH kvmtool 0/5] ARM: Implement PSCI SYSTEM_SUSPEND From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Peter Shier , Ricardo Koller , Reiji Watanabe , Will Deacon , Julien Thierry , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_095728_128071_6843B4DE X-CRM114-Status: GOOD ( 13.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a prototype for supporting KVM_CAP_ARM_SYSTEM_SUSPEND on kvmtool. The capability allows userspace to expose the SYSTEM_SUSPEND PSCI call to its guests. Implement SYSTEM_SUSPEND using KVM_MP_STATE_SUSPENDED, which emulates the execution of a WFI instruction in the kernel. Resume the guest when a wakeup event is recognized and reset it to the requested entry address and context ID. Patches 2-4 are small reworks to more easily shoehorn PSCI support into kvmtool. Patch 5 adds some SMCCC handlers and makes use of them to implement PSCI SYSTEM_SUSPEND. For now, just check the bare-minimum, that all vCPUs besides the caller have stopped. There are also checks that can be made against the requested entry address, but they are at the discretion of the implementation. Tested with 'echo mem > /sys/power/state' to see that the vCPU is in fact placed in a suspended state for the PSCI call. Hacked the switch statement to fall through to WAKEUP immediately after to verify the vCPU is set up correctly for resume. It would be nice if kvmtool actually provided a device good for wakeups, since the RTC implementation has omitted any interrupt support. kernel changes: http://lore.kernel.org/r/20220311174001.605719-1-oupton@google.com Oliver Upton (5): TESTONLY: Sync KVM headers with pending changes Allow architectures to hook KVM_EXIT_SYSTEM_EVENT ARM: Stash vcpu_init in the vCPU structure ARM: Add a helper to re-init a vCPU ARM: Implement PSCI SYSTEM_SUSPEND arm/aarch32/kvm-cpu.c | 72 ++++++++++++++++++++ arm/aarch64/kvm-cpu.c | 66 +++++++++++++++++++ arm/include/arm-common/kvm-cpu-arch.h | 23 ++++--- arm/kvm-cpu.c | 95 ++++++++++++++++++++++++++- arm/kvm.c | 9 +++ include/kvm/kvm-cpu.h | 1 + include/linux/kvm.h | 21 ++++++ kvm-cpu.c | 8 +++ 8 files changed, 283 insertions(+), 12 deletions(-)