Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4341067pxj; Tue, 8 Jun 2021 11:57:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQss5QqJ3A7GYVnM3/GtAiCi2GA8lPw9M4avwVia+ShFaeAYnDNJSE16G/0DgU7Q8vOxZd X-Received: by 2002:aa7:d388:: with SMTP id x8mr26491618edq.338.1623178624005; Tue, 08 Jun 2021 11:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623178623; cv=none; d=google.com; s=arc-20160816; b=oaSx/dlgAa9ktlZMnKQEqjn4UUQyTIqy/S+2JRQJyXLCPT+r7Cqa52LwT7XGoK+eMl twGtkaVJWRRglz8HXYfJNL6+LtUq+MCfQIvlCARiXDHwF6hekepIvqqo0h58pm0O6I2a Ps/4/DoudPhoTzzBqw3yCCWxehCVzcHbq/XdCPoQyEVm0CGbUs9SHwxwaSXZs9f5jt3C lDbg3/0gnZvLdeGGLfvmHQHV3VVWIztTyvMMC8cDqH/d3G8jLrlf2yhy4tK8M8oSF8vw 3ycem0aCxpeiUhFbf1s6hVXMGxoNgT5vPbNjdt51DOlM9/bDDB5Cfy9UqkWvYBMMhfW+ svhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SN8w3P+l4U3m/ybJOFr9sgtUYvT41ZfjAKEySlpqxI4=; b=x2k7gf7yowyz6AHIXK84lqpKJ8Ve8RtUhctKRZR7ihllnGWGxFb7/4JpQE3yMOgYj6 uHdxrW3EFFxkixnoXoXPK7l7afUgKo06THTsyMKPzcRNMA2G5rBFBdIR7q2e4N3GmOOk BJoUKmnMmr01lebuciKr8PNGN/rXnrfmQLY2lGB9s25wH4+Elo8LFP9PpLjeqrihT+9S v2Zz0P3w/NhfZx3Ll0FWTcYhbeJCf69VKEaSuXeD0JJPfo5gseBIpPnzgAokAMBDd7BX 3p1VmMeGPf42AULZGQTgG0xwE6nS5UGxi+Q7cZnZ3RSYkxeOJGMOjTMJdD/uAiRle27F kQHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iYyZmoLd; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo20si397092edb.481.2021.06.08.11.56.40; Tue, 08 Jun 2021 11:57:03 -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=@linuxfoundation.org header.s=korg header.b=iYyZmoLd; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236700AbhFHSzD (ORCPT + 99 others); Tue, 8 Jun 2021 14:55:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:48486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234623AbhFHStC (ORCPT ); Tue, 8 Jun 2021 14:49:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9B8466145B; Tue, 8 Jun 2021 18:38:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177515; bh=SgEDQZahBXLmRlM+Ro6zNahyJ908klVeumAifoNCmiA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iYyZmoLdgWrcmcY80IqCAoXCcdffVmcV3wMovtjp5M/znisvPR0He+54PwuD36U9P 9wTme/L12mjH6UqKhppKZ25nCuDa/iBFeyYZi58Hmc+WhjbBL1WN8KlZybPR95NTJP E49el9gnJx2vPf5UvNbnqtABo0BqRQcQtynYbT8A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Vitaly Kuznetsov , Paolo Bonzini , Andrea Righi , Krzysztof Kozlowski Subject: [PATCH 5.4 72/78] x86/kvm: Teardown PV features on boot CPU as well Date: Tue, 8 Jun 2021 20:27:41 +0200 Message-Id: <20210608175937.696836901@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Kuznetsov commit 8b79feffeca28c5459458fe78676b081e87c93a4 upstream. Various PV features (Async PF, PV EOI, steal time) work through memory shared with hypervisor and when we restore from hibernation we must properly teardown all these features to make sure hypervisor doesn't write to stale locations after we jump to the previously hibernated kernel (which can try to place anything there). For secondary CPUs the job is already done by kvm_cpu_down_prepare(), register syscore ops to do the same for boot CPU. Krzysztof: This fixes memory corruption visible after second resume from hibernation: BUG: Bad page state in process dbus-daemon pfn:18b01 page:ffffea000062c040 refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 compound_mapcount: -30591 flags: 0xfffffc0078141(locked|error|workingset|writeback|head|mappedtodisk|reclaim) raw: 000fffffc0078141 dead0000000002d0 dead000000000100 0000000000000000 raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: PAGE_FLAGS_CHECK_AT_PREP flag set bad because of flags: 0x78141(locked|error|workingset|writeback|head|mappedtodisk|reclaim) Signed-off-by: Vitaly Kuznetsov Message-Id: <20210414123544.1060604-3-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini Signed-off-by: Andrea Righi [krzysztof: Extend the commit message] Signed-off-by: Krzysztof Kozlowski Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/kvm.c | 57 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 16 deletions(-) --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -428,6 +429,25 @@ static void __init sev_map_percpu_data(v } } +static void kvm_guest_cpu_offline(void) +{ + kvm_disable_steal_time(); + if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) + wrmsrl(MSR_KVM_PV_EOI_EN, 0); + kvm_pv_disable_apf(); + apf_task_wake_all(); +} + +static int kvm_cpu_online(unsigned int cpu) +{ + unsigned long flags; + + local_irq_save(flags); + kvm_guest_cpu_init(); + local_irq_restore(flags); + return 0; +} + #ifdef CONFIG_SMP #define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG) @@ -547,31 +567,34 @@ static void __init kvm_smp_prepare_boot_ kvm_spinlock_init(); } -static void kvm_guest_cpu_offline(void) +static int kvm_cpu_down_prepare(unsigned int cpu) { - kvm_disable_steal_time(); - if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) - wrmsrl(MSR_KVM_PV_EOI_EN, 0); - kvm_pv_disable_apf(); - apf_task_wake_all(); -} + unsigned long flags; -static int kvm_cpu_online(unsigned int cpu) -{ - local_irq_disable(); - kvm_guest_cpu_init(); - local_irq_enable(); + local_irq_save(flags); + kvm_guest_cpu_offline(); + local_irq_restore(flags); return 0; } -static int kvm_cpu_down_prepare(unsigned int cpu) +#endif + +static int kvm_suspend(void) { - local_irq_disable(); kvm_guest_cpu_offline(); - local_irq_enable(); + return 0; } -#endif + +static void kvm_resume(void) +{ + kvm_cpu_online(raw_smp_processor_id()); +} + +static struct syscore_ops kvm_syscore_ops = { + .suspend = kvm_suspend, + .resume = kvm_resume, +}; static void __init kvm_apf_trap_init(void) { @@ -649,6 +672,8 @@ static void __init kvm_guest_init(void) kvm_guest_cpu_init(); #endif + register_syscore_ops(&kvm_syscore_ops); + /* * Hard lockup detection is enabled by default. Disable it, as guests * can get false positives too easily, for example if the host is