From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E727AC43334 for ; Thu, 9 Jun 2022 14:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243194AbiFIOzw (ORCPT ); Thu, 9 Jun 2022 10:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241140AbiFIOzv (ORCPT ); Thu, 9 Jun 2022 10:55:51 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82F6E37F045 for ; Thu, 9 Jun 2022 07:55:49 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id w21so21338209pfc.0 for ; Thu, 09 Jun 2022 07:55:49 -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:in-reply-to; bh=ERqpHHB15unBSTeHEqEMR3UFvMYfb3/GCbSADTuIbHA=; b=AkkQ1lNNSImZ+9IyPfR9U+c4QA+kolWUMUz3suIATQi0Q2AT516ThrNMDTDlnvc7YE /ZhYeyTdnRriWNOxky9myWCfBKm4Sn1EWd1VrHKfPD1yEyHRqP4S1+QQbz/iIxwNIBjn JQ7GFOFH08vZ6a6OHq94eZcvHzamYR/fbyvHYugF2OElBhX86mXkX1rNNeZpILEQFfBF dE7hNmYosDvhTkksbpmcq2gzj7a/JVXxBPr73g/1Daer4sv0xHXFMfv/WYodigfXFFLF X02RmIDCx9AtutgUj4ELTanbechY5vI8hnlVa9VUMddqUEjvdpZtsBkslYmL32KxgL8H lhiQ== 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:in-reply-to; bh=ERqpHHB15unBSTeHEqEMR3UFvMYfb3/GCbSADTuIbHA=; b=2zkTCh4how49OdgCnLlLtTQP1g+VjqvBLn/hwJHMvup6D5DxzswLhD5XrSVMO3+qVv l4r0YezfqzcbJOX3W10fGx0CQ7nAHOBhlYd3AiJiNoghTEIXQZQ1p/GpBS+L9gNVLb0Z 2bmqigwNfD5sfuQw5ScdVV3a5GIKctvfBI7x1ySD14rkoruqt4WprQznpOYzWZEuyw4s ZCgs5iAO2YQgEhjKEpW3u0QpswRPxISgdh/YMDpEWy5cTAPjxgZzYf+qe8Vqn1mllBO/ WF0nyYHg/w47nRDEMy0Q00IsnIRGp6SaDjZz7fQva0LDU5TvpRrLs5YqCh35s65C0Cl0 r7HA== X-Gm-Message-State: AOAM5309D3UD1haNKEJjDneQM9PqzStVxLgFprofU7BvBwT10DkObint X1IFkl8IIvIy+PfY5GQRA/iVXA== X-Google-Smtp-Source: ABdhPJy8b0sXVZ9mcdG0q6aDwplLKBr+elC41y+xW9yxBNhIl6TnCHVg9fqa2vtTLTESAaaUZeU85A== X-Received: by 2002:aa7:8d0f:0:b0:518:d867:bae8 with SMTP id j15-20020aa78d0f000000b00518d867bae8mr39566603pfe.13.1654786548865; Thu, 09 Jun 2022 07:55:48 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id j188-20020a62c5c5000000b0051c77027d7fsm2702846pfg.218.2022.06.09.07.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jun 2022 07:55:48 -0700 (PDT) Date: Thu, 9 Jun 2022 14:55:44 +0000 From: Sean Christopherson To: Grzegorz Jaszczyk Cc: linux-kernel@vger.kernel.org, dmy@semihalf.com, 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 , Brijesh Singh , Ashish Kalra , Mario Limonciello , Pratik Vishwakarma , 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)" 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=us-ascii Content-Disposition: inline In-Reply-To: <20220609110337.1238762-2-jaz@semihalf.com> Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Thu, Jun 09, 2022, Grzegorz Jaszczyk wrote: > +9. KVM_HC_SYSTEM_S2IDLE > +------------------------ > + > +:Architecture: x86 > +:Status: active > +:Purpose: Notify the hypervisor that the guest is entering s2idle state. What about exiting s2idle? E.g. 1. VM0 enters s2idle 2. host notes that VM0 is in s2idle 3. VM0 exits s2idle 4. host still thinks VM0 is in s2idle 5. VM1 enters s2idle 6. host thinks all VMs are in s2idle, suspends the system > +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. 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. I bet if you're clever this can even be done without any guest changes, e.g. I gotta imagine acpi_sleep_run_lps0_dsm() triggers MMIO/PIO with the right ACPI configuration.