From patchwork Thu Sep 17 14:04:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1366147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bsdyd2xnWz9sTS; Fri, 18 Sep 2020 00:05:13 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kIuX8-0007XD-6t; Thu, 17 Sep 2020 14:05:10 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kIuX4-0007WO-RJ for kernel-team@lists.ubuntu.com; Thu, 17 Sep 2020 14:05:06 +0000 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kIuX4-0000a8-HV for kernel-team@lists.ubuntu.com; Thu, 17 Sep 2020 14:05:06 +0000 Received: by mail-qk1-f198.google.com with SMTP id m23so1561033qkh.10 for ; Thu, 17 Sep 2020 07:05:06 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z/hK1y4KWho584RR9hDyUNTtwdphpapzd6YW9sLQnEM=; b=tvRxXV+jqG3jVzFhCMGa9pwh78FDhsyAHAgH7UPgiULTzLfw7RXdiFqIbiRLP9+Fzz yB2DPpVVAOPgfFm+UIMRBwx6wphu1Afm6jV4YbXi6YYQM8h7sBLdtha2+g7gxPk9Qcyg YjpXNeFqvVBJLZBHuzJzD2bvD4pCkOGWornU9vSNoL9e2MQs3ocW0uq459HtAx1RJ6Pm jMX3GqfxVsq8sdOHKqnS117mOSAajY6dh3UJpwnXN1e41Pn1vJiZQTiYXQRqmf3DQY8y mrwBAUXapv7DoDydi+5SI3p4XGxSmOaICYjKItb5P7WH6VNrwxFmnWXrDQII18VGbxdF 8sOw== X-Gm-Message-State: AOAM53306+U/maHQdHXBYGe3Flf2XGgspV91qVlxqEH5bVtw+knSl40j fNmUH6UR7vz9FBxctDDAXmbOvwPyWvB+tsbCnMf+DrvrbZzHDPsbk38e8ThapA+XhppPhyr1vUj VTkXzCtJgEbu1aoydt8pAHZitoaL+z9swQgS5bOEK X-Received: by 2002:a05:620a:a10:: with SMTP id i16mr28005652qka.31.1600351504205; Thu, 17 Sep 2020 07:05:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/0RmXV49nRBh8kwxEeB3ffAF8gdNFEDhGT/ESpsmvufCVII+L93gcZhaNXBv/R8iE8TIwug== X-Received: by 2002:a05:620a:a10:: with SMTP id i16mr28005621qka.31.1600351503880; Thu, 17 Sep 2020 07:05:03 -0700 (PDT) Received: from valinor.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id f8sm22200604qkb.123.2020.09.17.07.05.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 07:05:03 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 1/1] x86/hyperv: Properly suspend/resume reenlightenment notifications Date: Thu, 17 Sep 2020 11:04:57 -0300 Message-Id: <20200917140457.1950760-2-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200917140457.1950760-1-marcelo.cerri@canonical.com> References: <20200917140457.1950760-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Vitaly Kuznetsov BugLink: https://bugs.launchpad.net/bugs/1895980 Errors during hibernation with reenlightenment notifications enabled were reported: [ 51.730435] PM: hibernation entry [ 51.737435] PM: Syncing filesystems ... ... [ 54.102216] Disabling non-boot CPUs ... [ 54.106633] smpboot: CPU 1 is now offline [ 54.110006] unchecked MSR access error: WRMSR to 0x40000106 (tried to write 0x47c72780000100ee) at rIP: 0xffffffff90062f24 native_write_msr+0x4/0x20) [ 54.110006] Call Trace: [ 54.110006] hv_cpu_die+0xd9/0xf0 ... Normally, hv_cpu_die() just reassigns reenlightenment notifications to some other CPU when the CPU receiving them goes offline. Upon hibernation, there is no other CPU which is still online so cpumask_any_but(cpu_online_mask) returns >= nr_cpu_ids and using it as hv_vp_index index is incorrect. Disable the feature when cpumask_any_but() fails. Also, as we now disable reenlightenment notifications upon hibernation we need to restore them on resume. Check if hv_reenlightenment_cb was previously set and restore from hv_resume(). Signed-off-by: Vitaly Kuznetsov Reviewed-by: Dexuan Cui Reviewed-by: Tianyu Lan Link: https://lore.kernel.org/r/20200512160153.134467-1-vkuznets@redhat.com Signed-off-by: Wei Liu (cherry picked from commit 38dce4195f0daefb566279fd9fd51e1fbd62ae1b) Signed-off-by: Marcelo Henrique Cerri Acked-by: Thadeu Lima de Souza Cascardo Acked-by: Ian May --- arch/x86/hyperv/hv_init.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index c14469fe93d2..1412e59eda01 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -226,10 +226,18 @@ static int hv_cpu_die(unsigned int cpu) rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl)); if (re_ctrl.target_vp == hv_vp_index[cpu]) { - /* Reassign to some other online CPU */ + /* + * Reassign reenlightenment notifications to some other online + * CPU or just disable the feature if there are no online CPUs + * left (happens on hibernation). + */ new_cpu = cpumask_any_but(cpu_online_mask, cpu); - re_ctrl.target_vp = hv_vp_index[new_cpu]; + if (new_cpu < nr_cpu_ids) + re_ctrl.target_vp = hv_vp_index[new_cpu]; + else + re_ctrl.enabled = 0; + wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl)); } @@ -293,6 +301,13 @@ static void hv_resume(void) hv_hypercall_pg = hv_hypercall_pg_saved; hv_hypercall_pg_saved = NULL; + + /* + * Reenlightenment notifications are disabled by hv_cpu_die(0), + * reenable them here if hv_reenlightenment_cb was previously set. + */ + if (hv_reenlightenment_cb) + set_hv_tscchange_cb(hv_reenlightenment_cb); } /* Note: when the ops are called, only CPU0 is online and IRQs are disabled. */