From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vitaly Kuznetsov Subject: Re: [PATCH v5 1/3] x86/hyper-v: Suspend/resume the hypercall page for hibernation Date: Thu, 26 Sep 2019 12:44:16 +0200 Message-ID: <87ef0372wv.fsf@vitty.brq.redhat.com> References: <1567723581-29088-1-git-send-email-decui@microsoft.com> <1567723581-29088-2-git-send-email-decui@microsoft.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1567723581-29088-2-git-send-email-decui@microsoft.com> Sender: linux-kernel-owner@vger.kernel.org To: Dexuan Cui Cc: "linux-arch@vger.kernel.org" , "arnd@arndb.de" , "bp@alien8.de" , "daniel.lezcano@linaro.org" , Haiyang Zhang , "hpa@zytor.com" , KY Srinivasan , "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "mingo@redhat.com" , "sashal@kernel.org" , Stephen Hemminger , "tglx@linutronix.de" , "x86@kernel.org" , Michael Kelley , Sasha Levin List-Id: linux-arch.vger.kernel.org Dexuan Cui writes: > This is needed for hibernation, e.g. when we resume the old kernel, we need > to disable the "current" kernel's hypercall page and then resume the old > kernel's. > > Signed-off-by: Dexuan Cui > Reviewed-by: Michael Kelley > --- > arch/x86/hyperv/hv_init.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > index 866dfb3..037b0f3 100644 > --- a/arch/x86/hyperv/hv_init.c > +++ b/arch/x86/hyperv/hv_init.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > > void *hv_hypercall_pg; > @@ -223,6 +224,34 @@ static int __init hv_pci_init(void) > return 1; > } > > +static int hv_suspend(void) > +{ > + union hv_x64_msr_hypercall_contents hypercall_msr; > + > + /* Reset the hypercall page */ > + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > + hypercall_msr.enable = 0; > + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > + (trying to think out loud, not sure there's a real issue): When PV IPIs (or PV TLB flush) are enabled we do the following checks: if (!hv_hypercall_pg) return false; or if (!hv_hypercall_pg) goto do_native; which will pass as we're not invalidating the pointer. Can we actually be sure that the kernel will never try to send an IPI/do TLB flush before we resume? -- Vitaly 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 X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D372EC432C2 for ; Thu, 26 Sep 2019 10:44:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD319222C2 for ; Thu, 26 Sep 2019 10:44:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725815AbfIZKoU (ORCPT ); Thu, 26 Sep 2019 06:44:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17465 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725208AbfIZKoU (ORCPT ); Thu, 26 Sep 2019 06:44:20 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E369A7FDCA for ; Thu, 26 Sep 2019 10:44:19 +0000 (UTC) Received: by mail-wr1-f69.google.com with SMTP id v13so751952wrq.23 for ; Thu, 26 Sep 2019 03:44:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Riw/2Ux9OsHBDm8paJcZzsJiBRoPakD2IyewC8/qlH0=; b=hxH4ac6FQzcPzhOqW58K4/GN6LFLsJNsNXIcPkyysvTZ0d0HtJRlEZ9TKedPLbkrt6 cCN4TM9QmaQlR+tl8wFxVVPRCt3g6EdRHgHb9ssryGnFtoq/pjnE47vyvCIhb+BUKkTB uiAY/vC/TJUAPa5e8uAlpDgszExfJqr9Oya3xjpbQVLlTbbIlJfQ40vm+SUUwZWdL7Ba yam4JxDFrsofeoVwOUhf2JnJQizA5A3BQ+DjAtLvAveQD/MXw6RxVUjEtmfh9q42lcP3 IRulGBuqaY7YuhhjWiIl+2KSNyIUeWpTxbC4kt8/FZvYnPhAFsIwfXuFQKcHxZtkc2V9 1KEQ== X-Gm-Message-State: APjAAAUKO07X3hokYdCf9QM0HAbs08VeiTtaVA5NMryuC2ubc31xPg6q xCGiPy5v9J2aak9Q+7DYD9WcjTYOgTV2LY8OJovVGM+vy5Lp6Siifa3vMDJq/sS2+aSXaLon4BG J8AaypJUj4AGzkrfGEwit8y7f X-Received: by 2002:adf:f8cf:: with SMTP id f15mr2319300wrq.292.1569494658663; Thu, 26 Sep 2019 03:44:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxr5GEjW6ka0m4Lpc1OF+XdjpU3XZQ6+sKdP/4G5PYjuXWwBJlGoNZuBr1r4uMLP1CN0JDCCQ== X-Received: by 2002:adf:f8cf:: with SMTP id f15mr2319287wrq.292.1569494658461; Thu, 26 Sep 2019 03:44:18 -0700 (PDT) Received: from vitty.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id q19sm3835597wra.89.2019.09.26.03.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 03:44:17 -0700 (PDT) From: Vitaly Kuznetsov To: Dexuan Cui Cc: "linux-arch\@vger.kernel.org" , "arnd\@arndb.de" , "bp\@alien8.de" , "daniel.lezcano\@linaro.org" , Haiyang Zhang , "hpa\@zytor.com" , KY Srinivasan , "linux-hyperv\@vger.kernel.org" , "linux-kernel\@vger.kernel.org" , "mingo\@redhat.com" , "sashal\@kernel.org" , Stephen Hemminger , "tglx\@linutronix.de" , "x86\@kernel.org" , Michael Kelley , Sasha Levin Subject: Re: [PATCH v5 1/3] x86/hyper-v: Suspend/resume the hypercall page for hibernation In-Reply-To: <1567723581-29088-2-git-send-email-decui@microsoft.com> References: <1567723581-29088-1-git-send-email-decui@microsoft.com> <1567723581-29088-2-git-send-email-decui@microsoft.com> Date: Thu, 26 Sep 2019 12:44:16 +0200 Message-ID: <87ef0372wv.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-hyperv-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hyperv@vger.kernel.org Dexuan Cui writes: > This is needed for hibernation, e.g. when we resume the old kernel, we need > to disable the "current" kernel's hypercall page and then resume the old > kernel's. > > Signed-off-by: Dexuan Cui > Reviewed-by: Michael Kelley > --- > arch/x86/hyperv/hv_init.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > index 866dfb3..037b0f3 100644 > --- a/arch/x86/hyperv/hv_init.c > +++ b/arch/x86/hyperv/hv_init.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > > void *hv_hypercall_pg; > @@ -223,6 +224,34 @@ static int __init hv_pci_init(void) > return 1; > } > > +static int hv_suspend(void) > +{ > + union hv_x64_msr_hypercall_contents hypercall_msr; > + > + /* Reset the hypercall page */ > + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > + hypercall_msr.enable = 0; > + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > + (trying to think out loud, not sure there's a real issue): When PV IPIs (or PV TLB flush) are enabled we do the following checks: if (!hv_hypercall_pg) return false; or if (!hv_hypercall_pg) goto do_native; which will pass as we're not invalidating the pointer. Can we actually be sure that the kernel will never try to send an IPI/do TLB flush before we resume? -- Vitaly