Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4162725pxv; Mon, 19 Jul 2021 18:56:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwUPDtVPTVn34y2sAapsmE8SAMrGOVmSpf1BtdvHiO2LsDsyN07EiBGzmwpGCtSz37kU69 X-Received: by 2002:aa7:dbc8:: with SMTP id v8mr36989362edt.242.1626746207100; Mon, 19 Jul 2021 18:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626746207; cv=none; d=google.com; s=arc-20160816; b=kykMq9LpNYmdrCg2zNqY1Ar6yc8TYSHh19G2RsSwY2R2M9Q/VEC9qKmFyeD/9zWrjI uEqk+WC5WrsoJLAtVprRJSN4HSseEU5aLIa0CVbmwxJx9+mAyHrt0mc+uPaHBcve3vel Mv3kqgH2zAahGhN200ia+1dITYMH78JWfKGDdEn3tfMoNVGjGTmYWDV02U6k82v1HMN9 BSOPCdUZo/zqaOFqrupr910dhdNRnnDHb+SkYpqDwbIH2xqaKfTVp3vcZDoCCzfUG38Y VwhmICcxSHjIABNL5NJXWiBUyM3Wuao8wpA0SG9yFdkLIkxz94syejs5x0+CLlC3UxrX ZRrw== 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=Zfw4NkNarA7+t2+ZoX6J2kfRllBmbbpZBhXMAQikZKg=; b=NzmRenK3kYbCF8AesTCxJuleJZywTj9bNH3gJMnMEeCfGjLRQGtkutoL0UsP+eruBV hysuo4hdv4oHg3NXiCRKosyg9GwSZqHiqTRTPRBhx/OtqACHdqaB/6MBiVyOFMUnZrIf AYd3kXmvBK05nreeFwqlfscKIEjyU0qb0R9Vu1s4RG0n5UWjbQWhByrrts3Rzxmg8wDM Q908ebHY03I6WWvEv2Nvg6TG1Vg9BLGDB+3B5XjimPvy5FHa7pC0/VYw0XwOxmdWBhot vwkDhARHeHLcyEM47eGPVzrS7tff43z3I6V5cpLk86gSUg+ODc2Qf++SVZM1IAmr84a3 ovmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h89eH3dK; 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 ch10si21882289edb.145.2021.07.19.18.56.24; Mon, 19 Jul 2021 18:56:47 -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=h89eH3dK; 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 S1347397AbhGSPQJ (ORCPT + 99 others); Mon, 19 Jul 2021 11:16:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:40456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245177AbhGSOr1 (ORCPT ); Mon, 19 Jul 2021 10:47:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B513E6136D; Mon, 19 Jul 2021 15:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626708227; bh=EVtl3DQpMr+8kzgOJSeZTYtS123L4SiJJlDRRAR5rQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h89eH3dK/OKcR+4lFSj5tw9fsCtoHxKEU2xrdRkM07CMErigqFYUml2NRytLqjVdp g9QQ4A2PAGIDYRuLO8v6YBYtxKXfgQeEzyPbompHLYH3xHPV3ZaYaTTm/Uuq9mk8AF khz16/OfWEbUgmvrmWRyAKEhy5w5o/D3YJfT9fD4= 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.14 231/315] KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run() Date: Mon, 19 Jul 2021 16:52:00 +0200 Message-Id: <20210719144951.016562972@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.861561397@linuxfoundation.org> References: <20210719144942.861561397@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 @@ -7237,6 +7237,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);