Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3757432pxv; Mon, 19 Jul 2021 08:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyFpREtOZ9vNCT9MOjMVFrpCxEpO4gn+QXzqFH0gKj3n+WTZzgfERt0gri/GnE5Rg14UEe X-Received: by 2002:a02:8206:: with SMTP id o6mr21752721jag.92.1626707097622; Mon, 19 Jul 2021 08:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626707097; cv=none; d=google.com; s=arc-20160816; b=XrN9Uy7VkRG9HdivdeS3qRGloaPW0fD/tsWr4fAu8XCNznJOKN91OhcFHmEnp5IXN7 yTDwOeIicjgxqdW2m/0Mw6TjTdV4vuikeoULfoce5WSS2Wd8dwCkpVse/bSea7/VFpjo wkVMMBUL+moyNXvoM+nh1hbmVRD8TvitmdhdhaVuyeK3zRyV7iBB8HaWBYrc3gTocPra ca0nzdoNRB2tMi0bPVOQ6NcRnizG6zUPQMb89pQM0aM2MWVhKzDeTqYWC6+4RfGNpBL5 Hzs2ZRanPz/HXVC/KolLULz1FYX+HbNhAEa6g0mjDmCfIqvUKFL1qrvN5Y5MU9FOd89y XidQ== 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=nM///KVoiFf+RIvbCFujpRWGc6c8VkVXFm/ZxlhwXXQ=; b=AtZH3woTRPwwy4lIei95imQR3wRbt/ZgjFsXj+mljF/XSqW2M5xMOWpbyc8L7o7zKr s4gUvk0ySOSfud5EKsklU8yfQsWey9886dCWE5MtJMmWVyUGImzH6tTXwtQGjrnCAyeP 7RcGcwaNmwEq2i82B35kWXUAGSTl5kFcISTBWX/7POIFlb8hCd4wnoFoOqVFS2+JYfqF Ipmm1eY8keAVtd7SAn7UI7CZySBAeH5/4acXYFjXeiTv/jkC/PV+vx5F888jKThWgo+r qu8GGJCoZyeXxiMxn/zFmz0Ftc54DwmsrLwTLAbL/BOvOSI96gh7cgmLWA5/Kq6ZWdNo dMpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oZxi1UKb; 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 w25si9690239iot.26.2021.07.19.08.04.24; Mon, 19 Jul 2021 08:04:57 -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=oZxi1UKb; 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 S242317AbhGSOXS (ORCPT + 99 others); Mon, 19 Jul 2021 10:23:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:57198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242537AbhGSOVH (ORCPT ); Mon, 19 Jul 2021 10:21:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9FE3C611ED; Mon, 19 Jul 2021 15:01:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626706898; bh=8uWssO0YkT0C4lwDe44dqW2kBgyS9swD+yCS3njJEdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oZxi1UKb1qD+smGBA2i7FVS/yg4fmHvx6ZglVbmRWKtWAQ4Lj5F1H6WowO5EiGbLH xzlUnnr/wzCVsB3qS1pNrLWsvdUBfyRv1macn9GNwhK9+rlukGACU/gfLuuD6NrEhI 65Nwfp31SxVGsq1Ueok//XTKgRTeWCLhikIPZPZw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lai Jiangshan , Paolo Bonzini Subject: [PATCH 4.4 142/188] KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run() Date: Mon, 19 Jul 2021 16:52:06 +0200 Message-Id: <20210719144941.139240845@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144913.076563739@linuxfoundation.org> References: <20210719144913.076563739@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: Lai Jiangshan commit f85d40160691881a17a397c448d799dfc90987ba upstream. When the host is using debug registers but the guest is not using them nor is the guest in guest-debug state, the kvm code does not reset the host debug registers before kvm_x86->run(). Rather, it relies on the hardware vmentry instruction to automatically reset the dr7 registers which ensures that the host breakpoints do not affect the guest. This however violates the non-instrumentable nature around VM entry and exit; for example, when a host breakpoint is set on vcpu->arch.cr2, Another issue is consistency. When the guest debug registers are active, the host breakpoints are reset before kvm_x86->run(). But when the guest debug registers are inactive, the host breakpoints are delayed to be disabled. The host tracing tools may see different results depending on what the guest is doing. To fix the problems, we clear %db7 unconditionally before kvm_x86->run() if the host has set any breakpoints, no matter if the guest is using them or not. Signed-off-by: Lai Jiangshan Message-Id: <20210628172632.81029-1-jiangshanlai@gmail.com> Cc: stable@vger.kernel.org [Only clear %db7 instead of reloading all debug registers. - Paolo] Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 2 ++ 1 file changed, 2 insertions(+) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6724,6 +6724,8 @@ static int vcpu_enter_guest(struct kvm_v set_debugreg(vcpu->arch.eff_db[3], 3); set_debugreg(vcpu->arch.dr6, 6); vcpu->arch.switch_db_regs &= ~KVM_DEBUGREG_RELOAD; + } else if (unlikely(hw_breakpoint_active())) { + set_debugreg(0, 7); } kvm_x86_ops->run(vcpu);