Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp613089iob; Wed, 4 May 2022 04:30:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwHPbRZCQ+ntNNs6RBwh/0WIqBaf/w/t8P7YDX6/U7i2Q898Dezyn14punhizsybxOHIp7 X-Received: by 2002:a17:907:60d3:b0:6db:8b59:1564 with SMTP id hv19-20020a17090760d300b006db8b591564mr19712080ejc.228.1651663818799; Wed, 04 May 2022 04:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651663818; cv=none; d=google.com; s=arc-20160816; b=i5yCyo1Xg3RnoG2NcXKrCLXSGpeJSto2BuwKTOmdXXO3wLqtmdzq/dPMWIOP4XOr+L NR5uq1zpYVcs7Jv6UsCznwQuZVaBtiJGybFa9CGagD3d0qql5GahJIrZYpFN71F+Mvjl OwRQU/8wl7APL7H6+fz5m05g2ep5U9qyjMEwleLMwo0arpJkbRlGCppJXnTABn+C0zkv FJE3jgfCgKwdMlToqDv7K+ILhKKv83rq0AiOW0rCYzTFl6q99DmZfcP5NQbZ9sULC7Ho lNI/A+j9R3Clpu12mh+29zqrSDyq6VL3F7a+JhDzlam20sI63MGg0boDrRxWW34RDWzM fPFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=KgPp4H0NuOXhN/wKLMYd5omlFxsjaCCDTXWIWXRSBbg=; b=XCwYToBLgSx57EYzaX5MQ5vkWCJ1f+E12C6HdP7iCFXVoLMZpq813h8QrIKbfr3Rpo viemUABLqXXoyugcNRSJgFYjMOliaegaUA49tPP5Wdd+cl3wrKvLQJe9F6UHU6VFkkWx l+KcT/FkeH8NWQk9/5jX8kgPIkc3aryMZdjWG2+vzIj1nrx7hLQy49+Kivf2wCDzRUdN sbvA3jLYWmUsnwkg1/2TTBvgptMJ5GpiOKZWTP+K+fWRBpP5dWP8OIDgMVxI4Ei792Mw w+Vs8i4suqPpZgL3iVYdb/wurs9l1LAB4M9CcvnoXe37aRNJ7wnZHCROCdzRRCTRI/Pz 8NIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DmyQSOYJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rk27-20020a170907215b00b006f3a15fb802si15998098ejb.486.2022.05.04.04.29.54; Wed, 04 May 2022 04:30:18 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20210112 header.b=DmyQSOYJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344211AbiEDD2b (ORCPT + 99 others); Tue, 3 May 2022 23:28:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235640AbiEDD23 (ORCPT ); Tue, 3 May 2022 23:28:29 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79ECA275CD for ; Tue, 3 May 2022 20:24:54 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id p18-20020aa78612000000b0050d1c170018so17078pfn.15 for ; Tue, 03 May 2022 20:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=KgPp4H0NuOXhN/wKLMYd5omlFxsjaCCDTXWIWXRSBbg=; b=DmyQSOYJGcco5+Z4OTfOviHTkWkf+fn4I7+QmVo96W+55a7ZQD7pIzftEAC3pnN8ZA l9JcBz03PNT7zTv1nUYlVUfKoC4VpY85yltqlsI6Xvd0Lmqep6+thdtV2s31+MT0FwpO QGEQ4A0BkecMPTbEqMvp6Bg+K7qJLJjV/zOSNJf03h0nwFjjTIyWhhDSnW3slTH3bsJH Y4c3nZYGMB+yKeWutRtXiYPLrYyUfec5ztQc2jKgLOypWbICymKSrVim4l4DL1zPUIiP CHdmOTTLgA3y6KADxJGz9tVkJJ5ra4vTG89lT4lG9Vo9O6O5GYBs/0RUyCzDTxEKH6w1 PRtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=KgPp4H0NuOXhN/wKLMYd5omlFxsjaCCDTXWIWXRSBbg=; b=Fhlr14BxhFMxGsFDwI/+Y9RvtskzT5+ibx+H6Nm3s75byaa0XHsd3TyQ22bYME/yfO fytRIPEgww2k1HgsPLDglwgGP1wxxHIHBRFwsps8ATeeR0QZ+lJJlCFcvDNlCNvZ5Pbe 1ziddAdSbFeTPBmiVo7Pym8O2jKkkcs1E2iCP1nEE6nsueEfuMLEEzJwZhRsnT2uMg5s 1EX/wg9DYemanoLw6RmeTblnexu0/c1i/S5ao0QamN4STOgNg9sulL5VA+qfPKEWNHuH +Ed9dHQbCnodShYHiA+eW8D83d0q5UavunRnUnmKfjoUnen2W6CGCwjTg6mcgjLUv4q8 cxqQ== X-Gm-Message-State: AOAM533iHL8+MGSyAuzD8R9yKEA7fOMiKisYeuMhHUg7Z7+x0+jQfcnO 1w+cPa6oLKhmDwg7GYdeNva/ELgh6p4= X-Received: from oupton3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:21eb]) (user=oupton job=sendgmr) by 2002:a17:90a:c986:b0:1d9:56e7:4e83 with SMTP id w6-20020a17090ac98600b001d956e74e83mr221104pjt.1.1651634693511; Tue, 03 May 2022 20:24:53 -0700 (PDT) Date: Wed, 4 May 2022 03:24:34 +0000 Message-Id: <20220504032446.4133305-1-oupton@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v6 00/12] KVM: arm64: PSCI SYSTEM_SUSPEND support From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, reijiw@google.com, ricarkol@google.com, Oliver Upton Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 The PSCI v1.0 specification describes a call, SYSTEM_SUSPEND, which allows software to request that the system be placed into the lowest possible power state and await a wakeup event. This call is optional in v1.0 and v1.1. KVM does not currently support this optional call. This series adds support for the PSCI SYSTEM_SUSPEND call to KVM/arm64. For reasons best described in patch 8, it is infeasible to correctly implement PSCI SYSTEM_SUSPEND (or any system-wide event for that matter) in a split design between kernel/userspace. As such, this series cheaply exits to userspace so it can decide what to do with the call. This series also gives userspace some help to emulate suspension with a new MP state that awaits an unmasked pending interrupt. Patches 1-5 are small reworks to more easily shoehorn the new features into the kernel. Patch 6 stands up the new suspend MP state, allowing userspace to emulate the PSCI call. Patch 7 actually allows userspace to enable the PSCI call, which requires explicit opt-in for the new KVM_EXIT_SYSTEM_EVENT type. Patches 8-11 clean up the way PSCI is tested in selftests to more easily add new test cases. Finally, the last patch actually tests that PSCI SYSTEM_SUSPEND calls within the guest result in userspace exits. Applies cleanly to 5.18-rc5. I'm sure you're already aware of it Marc, but for the sake of everyone else there's some light conflict with Raghu's patches that you've got queued up [1]. Tested with the included selftest and a hacked up kvmtool [2] with support for the new UAPI. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/hcall-selection [2]: https://lore.kernel.org/all/20220311175717.616958-1-oupton@google.com/ v5: http://lore.kernel.org/r/20220311174001.605719-1-oupton@google.com v5 -> v6: - Rebase to 5.18-rc5 - Collect Reiji's R-b's - Drop the system_event helper. Since we now have variadic data returning to userspace it doesn't make much sense to roll it up into a helper. Meh. - Put back the pointless kvm_vcpu_request() in kvm_arm_vcpu_suspend(). We'll rip out the reliance on vCPU requests for power state later on. It is entirely benign, even when a vCPU targets itself. Oliver Upton (12): KVM: arm64: Don't depend on fallthrough to hide SYSTEM_RESET2 KVM: arm64: Dedupe vCPU power off helpers KVM: arm64: Track vCPU power state using MP state values KVM: arm64: Rename the KVM_REQ_SLEEP handler KVM: arm64: Return a value from check_vcpu_requests() KVM: arm64: Add support for userspace to suspend a vCPU KVM: arm64: Implement PSCI SYSTEM_SUSPEND selftests: KVM: Rename psci_cpu_on_test to psci_test selftests: KVM: Create helper for making SMCCC calls selftests: KVM: Use KVM_SET_MP_STATE to power off vCPU in psci_test selftests: KVM: Refactor psci_test to make it amenable to new tests selftests: KVM: Test SYSTEM_SUSPEND PSCI call Documentation/virt/kvm/api.rst | 76 ++++++- arch/arm64/include/asm/kvm_host.h | 10 +- arch/arm64/kvm/arm.c | 104 +++++++-- arch/arm64/kvm/psci.c | 65 ++++-- include/uapi/linux/kvm.h | 4 + tools/testing/selftests/kvm/.gitignore | 2 +- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/aarch64/psci_cpu_on_test.c | 121 ---------- .../testing/selftests/kvm/aarch64/psci_test.c | 213 ++++++++++++++++++ .../selftests/kvm/include/aarch64/processor.h | 22 ++ .../selftests/kvm/lib/aarch64/processor.c | 25 ++ tools/testing/selftests/kvm/steal_time.c | 13 +- 12 files changed, 480 insertions(+), 177 deletions(-) delete mode 100644 tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c create mode 100644 tools/testing/selftests/kvm/aarch64/psci_test.c -- 2.36.0.464.gb9c8b46e94-goog