Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp780843iog; Wed, 15 Jun 2022 12:09:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vI9uGsxHbjkujL8H7q+680idOLPcpfGQTczJCuRaKi4/yOp/iFkyIOj0gcL+LQnUwuE/yZ X-Received: by 2002:a17:90a:5104:b0:1ea:e86b:6aed with SMTP id t4-20020a17090a510400b001eae86b6aedmr238201pjh.69.1655320178267; Wed, 15 Jun 2022 12:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655320178; cv=none; d=google.com; s=arc-20160816; b=NaJ0uS6pMvpbaykWt8rnaosIZ4TnC8MhgvNFepAIxKkx1ThN8Dk/cank32m2WweuM1 eGMypJtbB+0I9cvMwY6hDkaDWdlHv1Q03gFILKUv0B5bG/VhyUGnK3DJtVTUqVnO/sEE Dnpg9gmi+0HQFwL+325m9GEHm9F7B9UKlII5ovcK43zcKwjZJDQJRsv4M60BqlVvttIV TCyvEFkCVsUPnPHDbZ8WlinCRrBqu/AamsMpjOCHyW5DB+FJWcpwhuFrfsM8vE0OI9RM Fj4sBdtsafNvh0XLJv2BIz285oK6Z0gtwMZt+XWnfg7BZdFDmS3ZPX02TkvMGLLcY9Es OQ5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=R/+J1Y9yB1sPzolzla9qc2fDqAKL6OPTM1OdQs0CRno=; b=DF/11tPRgw1sllWZrKuIlmzlFPAfYtxw1Im1pBbrnHyEMQtASCon8p/BVJKdpYQNs4 CKAHGrhQXBpAH1FZ+aDTTs/q28CMGbhc15AjUDjuCjNlqRx3IhsQ7s3SdmdLX+7J3PSx qvRmmJb5/LQP+ghnK7X6X28EeM88yjriBSquvPs3T/XqqvRCpOKp/o5lBti9z5hqb14s gGGoSsN18eHcx8WUNYrMr+gPGn/7hoc7BYJtcqVQKfIbEnkmaR6DXzc3BU8IMab5p1pJ PB2PKUnGfPWNCfpKbPbBGtqpRFnzBd8Yy1rmE32phZaFs8rv6IBFC3X9gGpGJ7ujM31O 2MwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=abcd5znL; 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 s196-20020a632ccd000000b003aa7a26283fsi17427160pgs.7.2022.06.15.12.09.25; Wed, 15 Jun 2022 12:09:38 -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=@semihalf.com header.s=google header.b=abcd5znL; 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 S245041AbiFOSyR (ORCPT + 99 others); Wed, 15 Jun 2022 14:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358485AbiFOSyK (ORCPT ); Wed, 15 Jun 2022 14:54:10 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D82DA381A2 for ; Wed, 15 Jun 2022 11:54:08 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id a2so20311701lfg.5 for ; Wed, 15 Jun 2022 11:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=R/+J1Y9yB1sPzolzla9qc2fDqAKL6OPTM1OdQs0CRno=; b=abcd5znL1a7ok4I0g4GWuTjmiANg0iKDQGwuE8doxfsT9kdULYDdRiGccgJroEls8X 5xxZ8c5rwhA/zDqfvtRxTYIP5tKxBkenLEJWpclHtYqcMmHK2uWBV5hfIs0kRo7LEfbt tMGhhPywkfqrfCOHEVHsbf6UtAOSJVXPOkoy4/k2815rrk9vAmRWXWK2HhxteiU/wkww 44eCjmP4UoMmiJFizXetKCX9q31AmKP1NgwtXf+uNkb1VeyaQ1V0Hct4EyPLVHQNq+wd 0QF+UxZGiWL2qZCF4My/2/U9LTnK3jD4sVBeSS9XopFiK2K4V6xWIYuWYAcSfFSMU5l2 BWBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=R/+J1Y9yB1sPzolzla9qc2fDqAKL6OPTM1OdQs0CRno=; b=K15crrWAL5dMQXrRCVgltbVwaNCFlcVyyZhGfxrmQOR8tMyTOlYgUzNb1ymE8YpM8u Qg+8LVyV2ry59Qy+PbGu/gBFujRKAEl12lyWbwmWhBvNk+iJz/2IDvceQYpgFwJxf01S lemZotjePEi4S1tKcjFZFAXWag/bCx8TpPd2I365NSV/7kMvCrtQdwraa8WYVRnQlLIZ WoJp14liP5w0dDrIn1gNaU1iosqGCKH5Dwkdx4dW4BaIVNYixy/gGr0nGX/MzgJA8wa+ SAgYDOehwJ6LQohQ2+pZRp9hLR7LuiiFksJqJ9LLp29qbPAm7brquslQ+4J3N4gF16tQ RXNA== X-Gm-Message-State: AJIora9oQeuXQNzbQFPd/TU+e5SHiZ5OS7WfAHXrS+hBWEHK7WkrbhVe WzDRh4rDwwRkqu9QNFr7Sy4pH5HIbOfSbaXkSyfPIw== X-Received: by 2002:a05:6512:2087:b0:479:1615:3afe with SMTP id t7-20020a056512208700b0047916153afemr509273lfr.114.1655319247144; Wed, 15 Jun 2022 11:54:07 -0700 (PDT) MIME-Version: 1.0 References: <20220609110337.1238762-1-jaz@semihalf.com> <20220609110337.1238762-2-jaz@semihalf.com> In-Reply-To: From: Grzegorz Jaszczyk Date: Wed, 15 Jun 2022 20:53:56 +0200 Message-ID: Subject: Re: [PATCH 1/2] x86: notify hypervisor about guest entering s2idle state To: Sean Christopherson Cc: linux-kernel@vger.kernel.org, Dmytro Maluka , Zide Chen , Peter Fang , Tomasz Nowicki , Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "Rafael J. Wysocki" , Len Brown , Pavel Machek , Ashish Kalra , Mario Limonciello , Hans de Goede , Sachi King , Arnaldo Carvalho de Melo , David Dunn , Wei Wang , Nicholas Piggin , "open list:KERNEL VIRTUAL MACHINE (KVM)" , "open list:DOCUMENTATION" , "open list:ACPI" , "open list:HIBERNATION (aka Software Suspend, aka swsusp)" , Dominik Behr , Dmitry Torokhov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 pt., 10 cze 2022 o 16:30 Sean Christopherson napisa=C5= =82(a): > > On Fri, Jun 10, 2022, Grzegorz Jaszczyk wrote: > > czw., 9 cze 2022 o 16:55 Sean Christopherson napisa= =C5=82(a): > > Above could be actually prevented if the VMM had control over the > > guest resumption. E.g. after VMM receives notification about guest > > entering s2idle state, it would park the vCPU actually preventing it > > from exiting s2idle without VMM intervention. > > Ah, so you avoid races by assuming the VM wakes itself from s2idle any ti= me a vCPU > is run, even if the vCPU doesn't actually have a wake event. That would = be very > useful info to put in the changelog. Just to clarify: I assumed that the VM may wake from s2idle any time a vCPU is running and got a wake event. So going back to the previous example: 1. VM0 enters s2idle 2. VMM gets notification about VM0 is in s2idle and during this notification handling, the vCPU notifying about s2idle is not running (we are in the middle of handling vCPU exit in VMM). So even if some wakeup event will arrive it couldn't allow that vCPU to exit the s2idle. This pending wakeup event wouldn't wakeup the VM0 until VMM unpark the vCPU and VMM has control over it. > > > > > +static void s2idle_hypervisor_notify(void) > > > > +{ > > > > + if (static_cpu_has(X86_FEATURE_HYPERVISOR)) > > > > + kvm_hypercall0(KVM_HC_SYSTEM_S2IDLE); > > > > > > Checking the HYPERVISOR flag is not remotely sufficient. The hypervi= sor may not > > > be KVM, and if it is KVM, it may be an older version of KVM that does= n't support > > > the hypercall. The latter scenario won't be fatal unless KVM has bee= n modified, > > > but blindly doing a hypercall for a different hypervisor could have d= isastrous > > > results, e.g. the registers ABIs are different, so the above will mak= e a random > > > request depending on what is in other GPRs. > > > > Good point: we've actually thought about not confusing/breaking VMMs > > so I've introduced KVM_CAP_X86_SYSTEM_S2IDLE VM capability in the > > second patch, but not breaking different hypervisors is another story. > > Would hiding it under new 's2idle_notify_kvm' module parameter work > > for upstream?: > > No, enumerating support via KVM_CPUID_FEATURES is the correct way to do s= omething > like this, e.g. see KVM_FEATURE_CLOCKSOURCE2. But honestly I wouldn't sp= end too > much time understanding how all of that works, because I still feel quite= strongly > that getting KVM involved is completely unnecessary. A solution that isn= 't KVM > specific is preferable as it can then be implemented by any VMM that enum= erates > s2idle support to the guest. Sure, thank you for the explanation and an example. > > > > The bigger question is, why is KVM involved at all? KVM is just a du= mb pipe out > > > to userspace, and not a very good one at that. There are multiple we= ll established > > > ways to communicate with the VMM without custom hypercalls. > > > > Could you please kindly advise about the recommended way of > > communication with VMM, taking into account that we want to send this > > notification just before entering s2idle state (please see also answer > > to next comment), which is at a very late stage of the suspend process > > with a lot of functionality already suspended? > > MMIO or PIO for the actual exit, there's nothing special about hypercalls= . As for > enumerating to the guest that it should do something, why not add a new A= CPI_LPS0_* > function? E.g. something like > > static void s2idle_hypervisor_notify(void) > { > if (lps0_dsm_func_mask > 0) > acpi_sleep_run_lps0_dsm(ACPI_LPS0_EXIT_HYPERVISOR_NOTIFY > lps0_dsm_func_mask, lps0_dsm_guid= ); > } Great, thank you for your suggestion! I will try this approach and come back. Since this will be the main change in the next version, will it be ok for you to add Suggested-by: Sean Christopherson tag? Best regards, Grzegorz