Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp525369iol; Thu, 9 Jun 2022 08:24:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLamQsyy6x2HZzaCymUMqXaAdkIs1jAXaaFmD1Ws+erY1yuPOlR6R0y3qlszeoMKBtzJnt X-Received: by 2002:a17:90b:1c02:b0:1e3:4b6d:4269 with SMTP id oc2-20020a17090b1c0200b001e34b6d4269mr3861851pjb.57.1654788253061; Thu, 09 Jun 2022 08:24:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654788253; cv=none; d=google.com; s=arc-20160816; b=S/ywyYTZParJ4rxgRweC2enCt4IGB0gmxv3gcQeHfBYJOftGXY9hygcRm8CacTsAlC CdNXpabESGWSzllpiCvipRs0s6xgqgKXwh6nHZQOHYnKUuGOwa0n1aAiO5CaTt7WzN4V a9d8jVa0SAnWZJgIdf/dE0xNPEDvbVgqHYiwqLvPlKwrXFDfz0f3fymQ7DkHALblbDh5 jb2Da15L8VRxzwqjGEG9H/l3qVwUEKKSyaDuIS5EzyuKDrn+RD7cm8zYjGfaPHALhae0 4F4UB8eX2M4iNjFCSjBQFvMjvmvT9cO84xctaDqf6UFu0i/6eJHA8Ajy/UkradOIBaaz UQRw== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ERqpHHB15unBSTeHEqEMR3UFvMYfb3/GCbSADTuIbHA=; b=a06BUhdd7HhgWaMZCqL6qU8RDsiRMUeJc2+cdngS6bVmRRviZUBS892hqczxN/Ebbx VDyRw3CsHV0mVZBFbbwRdjb/bP9Aa6BCtrAIJ9o3EgUEGW2QnP++4ric8Bum/yRyzZyH CJ+6HigRqk2XvzxfngKtfYeVkcJL2TH6ww7a4nIQCmlspBhgV0tfi4rnR9+X+wQlbaXY V8ppk5XMPX8o11jo83tEkCmmoUBMpO6n9/FC3vRH/g26D/CRfFpi2AD++kGPMonJ9bxt arhDV3BKA6/c0X2jCaaU/Vecc3R8szmDscsq1M0Axno7Oo32fD4g/9CteC3mHX5Py7dO ApeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AkkQ1lNN; 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 oa18-20020a17090b1bd200b001c6a62efe0dsi28401185pjb.89.2022.06.09.08.23.58; Thu, 09 Jun 2022 08:24:13 -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=AkkQ1lNN; 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 S241636AbiFIOzy (ORCPT + 99 others); Thu, 9 Jun 2022 10:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241642AbiFIOzv (ORCPT ); Thu, 9 Jun 2022 10:55:51 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8850137F051 for ; Thu, 9 Jun 2022 07:55:49 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id x4so12725630pfj.10 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=Ztutv1Zyy10G/ABaXSy+pgJ5tjiXOCfjAbYoMwqKfuqa/AQ2LfB5oG/eg4QPl/0xqS YX25KOGZrpy7nDyDyJZ+zXOnQjWfZftZiWs6K80O+9GzaqxkHuxX85fCo7Ff3WMRnTYe i6dGizLYcxuQ8UDutgbBGE5soVHEOXcgehgKyTn0y+4cZCuWI4lydbawETHggmbchtUs babmXSxiOeV6wdqfwsSNgZXjmgCfIqNzdn6ZqNvBvwYIyEodbHREfMoTC7XX6/fxie+A yBZ2KAm5A3V2OeKUjfvEwEmG+7mEuec5/uDV9pyJaNvj9WX/89c39L0VPRWd2DelIGUD JwPQ== X-Gm-Message-State: AOAM531dROHHysxcnJNaRduV2OLx1OT7xDFXZAXM+5QGHGxKTIBmTjLd sBhresMasRa4Fh3PVWy07opKQQ== 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> 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=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 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.