Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3777985pxv; Mon, 19 Jul 2021 08:31:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPionFuwtOtfSpHa3PgFDHrNM/hiwj43k11JAp6RSWtJbFUluh5foA26KgOQC1lwZnNcCc X-Received: by 2002:aa7:d1c4:: with SMTP id g4mr35007684edp.382.1626708686820; Mon, 19 Jul 2021 08:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708686; cv=none; d=google.com; s=arc-20160816; b=ZtJ0s3yiPBpmMC2Na915cfnNPYK60nAVZtX52b/7VGf0m62fWeHtVjWXNZ69REHya2 N7j4d0A39K2sZXvR0TF6VW7ddcmrpuKWE7zAgaoA5DB8U9UjOD424pj1qIcITr7+ilX+ g4ynsTfCD0yVkFiNvDQqJa9Drzk0XPc2bR/53yMzEYTWsHxQsh/kDH3c45DLNKuafYTr uQJa8WobdcH/HHiaykhB1A8aVJw54qb22jEZd43ae/rcEpXDDsqbTLBk12n5JtJx24Xw xxd6TSVtc7CijlSzhVsAei/M88SXpDMpCbs2lhYBGKhQ8lKZvv6ONH6G4KIum/V6mk8o 0hLg== 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=mTnceEpMMl2WB6Lm/HGAdOSmEuDZ3GX15spZM2iI4CE=; b=QrWJGlRzIBPNkFopz5G9esp3FOMMvprrqQHpwYMAmnZFy0aTVaOKHdrvn4tmfENyQn fknnnJF8ctROz7wUzp2ZAVh4gZOeyuiSTAmgFPizA5Bhja7rFygllWr7YC2lz/2hSp8p 0eJpCyhvAJee39/uA9Gl+DaCRGiR9IlK0PsiSN5Vhm0d152GITIA8Pf/FekywnsyEY83 WYX6Rk8PFMsJRTczJmdTV2AQKwsPeM1+eFaW5egfCdOUlgp3Pahjb4wiFoFFslDhaN5n n6Bxr8o+8eVKhBsaQa9Gnkyd2TZPqUb5jppEmMwjjBr1DsJspC/PAGtivAMl2PeYQcSv CRag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w8F2tTEw; 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 gx12si21360088ejc.158.2021.07.19.08.31.04; Mon, 19 Jul 2021 08:31:26 -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=w8F2tTEw; 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 S1343851AbhGSOse (ORCPT + 99 others); Mon, 19 Jul 2021 10:48:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:46154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243999AbhGSOcg (ORCPT ); Mon, 19 Jul 2021 10:32:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 964E560551; Mon, 19 Jul 2021 15:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707566; bh=uGK7TRqmLeMBZNebujvsvaybiaQqa+sTGjV2A2pnPYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w8F2tTEwVzVjlXOLpA65ntghJbpCVfUmZPR+ELG5ixw1/YLh7snPI/vDxLuWsEJnQ Tfl+xpmmRr5b+frm8oMod9CV4RD9K4XChKASpo1BEqRsaq+Ulx/nYBVj8GowHF7PG7 N5D0r39YUiZ558I7aSm0mG5A5Ks1ikfGpUgJOFsk= 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.9 181/245] KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run() Date: Mon, 19 Jul 2021 16:52:03 +0200 Message-Id: <20210719144946.250539225@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@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 @@ -7044,6 +7044,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);