Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1450236iol; Fri, 10 Jun 2022 07:47:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQ7dhl4neDBmnNz6Ceg0ljPG+K/ZVsYBuXO9NwlZZet7N1IqMIrEyCgNhbp+J7EnQuRV8I X-Received: by 2002:a17:90b:1bc7:b0:1e8:317d:6b3b with SMTP id oa7-20020a17090b1bc700b001e8317d6b3bmr133533pjb.136.1654872443099; Fri, 10 Jun 2022 07:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654872443; cv=none; d=google.com; s=arc-20160816; b=DC1YPUBXSbvFj3rYvZmTKFCV4Vb8zobGqOTXRKnQnkW07V9D8WsC02MIKgGVngBg6e lA8LA+AiIitLJiTWZKdFWXyLghvXPP1KwO5b1Jk4bSpq9IXhSEN1GFwFeYzrZT6St4LX 6kPF6yKQ7ipx5xHJWgKCN1tDI14/rfrLyWjAZDEt5JKTOEwfVZzmoMTqsFI1LO4AOcB6 kNCC8/QFXDVZBf77eoFZMCqTTA3FJYgZE9b0HJmYgP4y2vIsqzfqj4+8hHNJmk1YF38g XqoXkfoeiABPscXdkl1v0qGGu0YG7g0Cn5YWp3J9Hb+pJZmLiBjqCFMFASS4uj5iPzJx 88GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=iZkxFrCdz5HGHbN5AvcrMQrT1OxBg7CaPmIJCaX17lQ=; b=fdrvCANU+E9C80pFPRq8rnzEMPcgbY92NDpy+8MWEUbkGWG3bxRSFqcMAeWI5YC8OU vjrbt5nILHKB9PasFK+gJBIdTCYCJj8HO5nWrcTfWrCJ9p2uNjkrIgRjmi1YTD7XP4nQ 1GuMDHdvpClb0NU5pct5/tT1Ev6TpPIT080hkMhKEU25NAy/x8pqo7cGCHmlHIYud1rl tf/FSHiZVVYtmLVzSZ39iZiNJ5vkHlG9bYkIuWPxVtSpr3eGxBcjIl0GpBwhddGUx5X9 cKQT9AuFE88d9hiO4L+39H7Caz934GI+N3xawmK9Cx0gGN1mbhVg400JCekOLVTmQDQ3 XtSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KP4HYvtz; 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 c10-20020a170902c1ca00b00165638d6e2esi27149326plc.445.2022.06.10.07.47.07; Fri, 10 Jun 2022 07:47:23 -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=KP4HYvtz; 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 S232819AbiFJOaK (ORCPT + 99 others); Fri, 10 Jun 2022 10:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232554AbiFJOaH (ORCPT ); Fri, 10 Jun 2022 10:30:07 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B408A19C38 for ; Fri, 10 Jun 2022 07:30:02 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id s135so9295568pgs.10 for ; Fri, 10 Jun 2022 07:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=iZkxFrCdz5HGHbN5AvcrMQrT1OxBg7CaPmIJCaX17lQ=; b=KP4HYvtz1/r9i95F1wjVEcLG8E0YRVrsbrMUEtJAGlXCThtn4I+AwBI020BZ8QkENk VkYJUza7vjx9KRxYxYn1blwfJ4DmHGeHYEfXLV2JLucPyU1CcT6RyAiFEGz5xNB1qNs3 /H8oz5Osobi0eyKYL6Jxc/SkFRW8e6Rmy5hPD/ePq+GzeBSEpX/JtBIT336CQfQT3h78 bJKW+VdriFLI+sUb13QBvbPpKxYpaG4Rm0NEHazp3sA5OclNymsh1q+DI3F/mUVofBjx 5cE40h+i7ZQvqjZzKy99OzoR963rVw88+d7oUzCl+YjMBsKs03AJB7Mm5xf283OcfSp5 whAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=iZkxFrCdz5HGHbN5AvcrMQrT1OxBg7CaPmIJCaX17lQ=; b=0vXXW4PDr6YLceYNMoR8swLAICZcH5IT3AONwEhiEGemMVt7UMqnfIKzBO5wqjpuOe wkfSng+twOyA8ZI598g+zRP9dmZhHegFdRpCF+LGrXOkvmqE5rq4zNc8MFuIMF3+3I78 l5wwq3QJA9pBGm4fBk5ruQSBzMz2KgZFHpGwHaCYD4vlojUzhz9x9T2Jzo9egmXCAhwF Y6Pvj6z27K63JzYwvDftuH1M9fhv5CaAQCKWTLWsEV4Za7cS0SMCXD9uAUyuZjnJv7SQ VD82HXho0Sao9DWsQ2o0HwnOtciGVnNfU3LOYyfsgvW4j1mRS+OSus8/BPDz7sEWwMuV rH4A== X-Gm-Message-State: AOAM530GZggj8AihPQkEhnPSwMw0A8wm2OZHV5hABqM86QqqfJUN0ukS qGlHQM34s4KUeZjbw3ugNWLPrA== X-Received: by 2002:a63:8241:0:b0:3fe:2e64:95f0 with SMTP id w62-20020a638241000000b003fe2e6495f0mr13325930pgd.190.1654871401611; Fri, 10 Jun 2022 07:30:01 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id h11-20020a62830b000000b0050dc7628150sm19477473pfe.42.2022.06.10.07.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 07:29:59 -0700 (PDT) Date: Fri, 10 Jun 2022 14:29:55 +0000 From: Sean Christopherson To: Grzegorz Jaszczyk 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)" , dbehr@google.com, dtor@google.com Subject: Re: [PATCH 1/2] x86: notify hypervisor about guest entering s2idle state Message-ID: References: <20220609110337.1238762-1-jaz@semihalf.com> <20220609110337.1238762-2-jaz@semihalf.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Fri, Jun 10, 2022, Grzegorz Jaszczyk wrote: > czw., 9 cze 2022 o 16:55 Sean Christopherson napisaƂ(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 time 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. > > > +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 hypervisor may not > > be KVM, and if it is KVM, it may be an older version of KVM that doesn't support > > the hypercall. The latter scenario won't be fatal unless KVM has been modified, > > but blindly doing a hypercall for a different hypervisor could have disastrous > > results, e.g. the registers ABIs are different, so the above will make 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 something like this, e.g. see KVM_FEATURE_CLOCKSOURCE2. But honestly I wouldn't spend 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 enumerates s2idle support to the guest. > > The bigger question is, why is KVM involved at all? KVM is just a dumb pipe out > > to userspace, and not a very good one at that. There are multiple well 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 ACPI_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); }