From nobody Sun Sep 28 00:37:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1561082761; cv=none; d=zoho.com; s=zohoarc; b=iB0CUYW7eMzLolbJYLOwMpSWTDO35eJBCSl+PpG8wDG89wATRPK1LE9FJuS7plm3an0h/dwPegKaevubykXYzXH6eSrFkKbgi+G6U1nuscz5TEmiXZBgEgAYQj/gpywQ3m09hYJLRBJYkUzeNpOBw7k+X2Y2iYkV83117KdXl8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561082761; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=r43n33nGY2axkM37zxfub6AARNJoo1eQ/uWxCMQ4hvk=; b=e5o7k46NoIScgGX1EqT24BSoXEXzZDjtqp7hfLqMhPA4D/5e6xFSog4AwPL/wvZ3hQQkXGsR1e87JICtomckGJuJk5kPNSq0QTEvyVky2iKWFw8RReJ6QzHOOK/yTtOlhZr/q7zJm+YoXo/FDwNAyAquyBXIK7kJq1GLRRvWxxQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561082761283637.2217087455333; Thu, 20 Jun 2019 19:06:01 -0700 (PDT) Received: from localhost ([::1]:54126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8w2-00045Y-7i for importer@patchew.org; Thu, 20 Jun 2019 22:05:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40998) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8a2-0006Xp-71 for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1he8Zx-0006Tm-9f for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:05 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:54635) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1he8Zt-0006LR-NI for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:42:58 -0400 Received: by mail-wm1-x341.google.com with SMTP id g135so4780620wme.4 for ; Thu, 20 Jun 2019 18:42:50 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d1sm1123125wru.41.2019.06.20.18.42.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 18:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=r43n33nGY2axkM37zxfub6AARNJoo1eQ/uWxCMQ4hvk=; b=Qmr7Vmie6oOO75Cuc0lPVhTuaLBYQWhMyUCO/IMJLJ5kXF4Aa4KwVwAIZ3bar2g2zS Ddu/hmJtkJw39/XLTtfa5kd3XEcEM5+pQveXkimnp5kqKlT3S//bs8ZELkZwQ7+OgXEI 8U431em1lMa1xs37jA/fRhHjOIx+LEH3nBRXfZ0bBdp70YZJYuOAd93vkvodmO3hGl3v aPp5dFA5a8BvbRRa6S2Xo3XQON0QMIEzjW/AXcVVOzHBv3A6xydkAXLMihhSRvbx32kO YxjL8EKBgM8UpDv+mkEKxirqmPl22ZcRd7lT0jM3tb57CwREQZy07QnIj9BBGS1cRuhu E17w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=r43n33nGY2axkM37zxfub6AARNJoo1eQ/uWxCMQ4hvk=; b=UZAf9erzx3jysQeUfembmMLjkmCVgN+0qpcRSBKHEv2cC7eifGVz+uGxpZANgzGZMb syuSb7pLiOgKFrYyL5HxFoQqQwG48PL+7bhc+t1U/arXfSQlKtwkDKBocablVlf5R8VY Lah/hVVTBrTvvS6rBQ7dqzOrRkiwktsihWDjNgZcwioXPvZZYSDBefbii9lltygX7Kl8 N+eWPjYYEO+X2PCzaqo/gO+9o8W50btdnLYBxb/zY47BeL2Ot/pOCs+2HsVNSpJqW4A8 aQ3mN2cLjUO38wt7jB03fP0J1cNugARvYjWOj3QpZD5eHqlVArogciPhWoaZDj+7NVco aoGQ== X-Gm-Message-State: APjAAAUb5WBBdyeTOzj5grs8r7+Ei56At59XWDT1JZWI5aee/uWYDseO opFGEoyqROAenGb83P0fYvP13GGH X-Google-Smtp-Source: APXvYqxnM1zPDrLYlvDV8usVLTBU4jDVOi6kJd8T5LYmcsoGidthmv/+ahvmYtNvl3I+MRhoGRMu/g== X-Received: by 2002:a1c:208c:: with SMTP id g134mr1553520wmg.112.1561081369020; Thu, 20 Jun 2019 18:42:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 03:42:21 +0200 Message-Id: <1561081350-3723-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> References: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PULL 16/25] target/i386: kvm: Re-inject #DB to guest with updated DR6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Liran Alon If userspace (QEMU) debug guest, when #DB is raised in guest and intercepted by KVM, KVM forwards information on #DB to userspace instead of injecting #DB to guest. While doing so, KVM don't update vCPU DR6 but instead report the #DB DR6 value to userspace for further handling. See KVM's handle_exception() DB_VECTOR handler. QEMU handler for this case is kvm_handle_debug(). This handler basically checks if #DB is related to one of user set hardware breakpoints and if not, it re-inject #DB into guest. The re-injection is done by setting env->exception_injected to #DB which will later be passed as events.exception.nr to KVM_SET_VCPU_EVENTS ioctl by kvm_put_vcpu_events(). However, in case userspace re-injects #DB, KVM expects userspace to set vCPU DR6 as reported to userspace when #DB was intercepted! Otherwise, KVM_REQ_EVENT handler will inject #DB with wrong DR6 to guest. Fix this issue by updating vCPU DR6 appropriately when re-inject #DB to guest. Reviewed-by: Nikita Leshenko Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-5-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index c763643..9864aa0 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -3897,6 +3897,9 @@ static int kvm_handle_debug(X86CPU *cpu, /* pass to guest */ env->exception_injected =3D arch_info->exception; env->has_error_code =3D 0; + if (arch_info->exception =3D=3D EXCP01_DB) { + env->dr[6] =3D arch_info->dr6; + } } =20 return ret; --=20 1.8.3.1