Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2828303ybk; Tue, 12 May 2020 09:05:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAccVXRRizu2NjR9+OGxytTTUyg/v0+kkLCOr3dn1edYl+iKBK0K2SunCGRBEf6u1dWPJn X-Received: by 2002:a17:906:ae88:: with SMTP id md8mr1510916ejb.119.1589299500515; Tue, 12 May 2020 09:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589299500; cv=none; d=google.com; s=arc-20160816; b=qmiHN542O8UHK/K6R9fr2upEzHXai8fryg1KuDUCsBMnOvDa5CfovEI8Pyuxfi8Igu fYLTvSfyFq7qMbzA9mt48F6QH0BMwZzoq316VnZa30oTYDOw9r4ABlGxr7MreEwQlFDH SVaziA6vje2CSkb9qaQ7diuMve47uinH3K8+x0kYBRpW2Wdr8KG0LH2SLgA7ZOpqHfIY On29qDSXcEzqRV3ohjIprxgfRfN9jgjMg3CQEXfCn29oEkFIjrzVChj15IAapaBscJhh 29ATaErTB3n0fFgOsG9UqBG2foDXJDSTnbrXdFB/qyUtlQd64Imk1nL1o1PKEeY7kTp3 QafA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=nL6n0gs44aSe+c4xP2RS6AmyhHuCE1lHHuLbFzSoNGo=; b=cqgoCmMsq8kaar8p/K4xP+SjT69Ncg8yz+/MdTc1P6MhbJ6vhTGUZbi/jx3SwAWkx5 P8hBQj4GMC0V/ybHrbGBOiwYQ0+sgZdD3aIgpYrbVUGBnP4BvJRL0QNxwitqGsLM+RvC 2fK+fWez4ybnG13WUheRRYUrY8WRpDdb9hYSVeCiQnOQZwYTzDB79ktWaqI4C9VcdxyX ZRjR26cWD2UTmyYrXpdt9OeoY0Ret8AY02cZN7XT42PV12GpgOLX2LiJh2wL3x1y3vgO qjMlTsXPCp67KQPOZE9DFKbm0PGhRnzFrWX6KNAadmrsnv1PUMeuLxpJWNoIZERGVoiW ItQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FacGXlpV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch10si8338177edb.346.2020.05.12.09.04.29; Tue, 12 May 2020 09:05:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FacGXlpV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728493AbgELQCB (ORCPT + 99 others); Tue, 12 May 2020 12:02:01 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:52329 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725987AbgELQCB (ORCPT ); Tue, 12 May 2020 12:02:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589299320; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=nL6n0gs44aSe+c4xP2RS6AmyhHuCE1lHHuLbFzSoNGo=; b=FacGXlpVTipMCzw5E65rtqe8Cs412aCVT9+1x6ZyhwGaeF4J+CDpxmQpYFhDUGd5KTAnmd M7lADnX1RG9DtF0el8rPIdqJ6xIDmLaye3K9L7AaQuFTHtEoR9Y3EeNM+RwP2D7za5xayx lvG2pcaNoGBCzswl7E6E9o+xGs4h2rk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-428-yGbGbgOGNEWr2HXPNBc0CA-1; Tue, 12 May 2020 12:01:58 -0400 X-MC-Unique: yGbGbgOGNEWr2HXPNBc0CA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09855800687; Tue, 12 May 2020 16:01:57 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id A42EE60C05; Tue, 12 May 2020 16:01:54 +0000 (UTC) From: Vitaly Kuznetsov To: linux-hyperv@vger.kernel.org Cc: Wei Liu , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Michael Kelley , Dexuan Cui , Tianyu Lan Subject: [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications Date: Tue, 12 May 2020 18:01:53 +0200 Message-Id: <20200512160153.134467-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 fd51bac11b46..acf76b466db6 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. */ -- 2.25.4