From nobody Mon Feb 9 16:44:59 2026 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=1560559642; cv=none; d=zoho.com; s=zohoarc; b=i3ryEPl+I8X4/pzKAUGsp0s6+W+mBvLbI0V6OVmxIwRdYppzh94jGXIj7v4YZ5+YlpNFFOYGhfZ5i42jTlozA89b3VlUPM1uxzH3uWqZdHaF1lZZNYgR1rgTSMMSY+HQ7FFwy184DD0IjGUSvLHOVQNsnU+h0Oiwhfs0UVCHLpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560559642; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Tuj2jcO/BLerGp9WHchtQ73E8BBK3njFpTpGB+i8VjI=; b=djg7gPTeY/J03xzChYh/D0ytwkFzcepIK+ptMroe3PKV/DmYutzR8HRkLdT8EQ+I5fGAQxvvcl2aVGm6EYdpFYZY5PPPGgjNVuxxCFHOTCgTsJvJek4iUPEygKjw8WdnS4JB7HqHS4PsPd83iCQSEbsfarrQFwju3GXC8mUewuw= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560559642942806.9425963571929; Fri, 14 Jun 2019 17:47:22 -0700 (PDT) Received: from localhost ([::1]:57814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbwqi-0002Lj-11 for importer@patchew.org; Fri, 14 Jun 2019 20:47:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60420) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbwmc-0000Vr-Dp for qemu-devel@nongnu.org; Fri, 14 Jun 2019 20:43:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbwma-0004Aj-OJ for qemu-devel@nongnu.org; Fri, 14 Jun 2019 20:43:01 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:35064) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbwmZ-00049W-UZ for qemu-devel@nongnu.org; Fri, 14 Jun 2019 20:43:00 -0400 Received: by mail-wm1-x343.google.com with SMTP id c6so3877964wml.0 for ; Fri, 14 Jun 2019 17:42:58 -0700 (PDT) Received: from donizetti.lan ([2001:b07:6468:f312:1da0:213e:1763:a1a8]) by smtp.gmail.com with ESMTPSA id m21sm3774234wmc.1.2019.06.14.17.42.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 14 Jun 2019 17:42:57 -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 :mime-version:content-transfer-encoding; bh=Tuj2jcO/BLerGp9WHchtQ73E8BBK3njFpTpGB+i8VjI=; b=FfUlWh4NN90smDWXqsZIEUrL80d5krp6TQUPG85yIn2No5UHhYhb4tdc2EEvA64WMw jyAFA0mTXSugllkdFdWVJJM/1rTeWOpG9DxYwvAqYJ9IA6ziX03qT+N4Na+TsaeAPJjh hIHRhncetbUj260Jbe8I/Yf9A1vGWrBvRspy3Xbi8ou/6sNv0VFe8M/keovvFPmKYY/o BeezW0iorndlXyuD51dyhuivGh0eQnVSG7dwtRQcPbjIFhYBQwgPnOheF7ibIY1EkL7w gcTg0nPfxOgDkNE1DziYY9Jnp56oz9xscP5uwpvS3HnJxUQC+BXFBiWu6dLyaj/sYpnM glMg== 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:mime-version:content-transfer-encoding; bh=Tuj2jcO/BLerGp9WHchtQ73E8BBK3njFpTpGB+i8VjI=; b=MogGfL/bUp2OQgZaO0kfsc+rq2Tpw7L8LPa5bJg3BjDr60Lu2jSvEPfSr9vKdB6XKJ KYdQvMmzPalGYqfRqByMG/paNRqoscpbswwt38jLf7bkqmOhUNVUDXtF5mpGOsGsploP 88QipTZehqJUZiXh+bxymsXNqiQpk+kNyqJjRQXKtbp0kQak1bMRwtnij5768MQ/uBeq /3nBY9JJ7wtyLEZ+Hb87MYnGKUDKc4OYjUnUzm53NzIoXuqhDW7Axf7HV3aMo2Y0vcOk us+U6W0mj5GuN4QdzNFcpP2L059iprmRIIHOsQk2LlxkTYR/8WNouzuza+IR6PfewQtP jVpg== X-Gm-Message-State: APjAAAUR2LKYJvOi0r+ha0hhwdTZaTcUJJU4bBGK0iq+6KNtWrBELqqW +I6zApgd22rgaEImxtlUcoo6Wawz X-Google-Smtp-Source: APXvYqxnDfbSIMjtDK6qE3IP4/WjGAGMF/TrvxTtI9EYB8Nr4KbaoV53xwSxcyApa+FcNQgPMu2X0g== X-Received: by 2002:a1c:3c8a:: with SMTP id j132mr9528804wma.172.1560559377625; Fri, 14 Jun 2019 17:42:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sat, 15 Jun 2019 02:42:51 +0200 Message-Id: <20190615004256.16367-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190615004256.16367-1-pbonzini@redhat.com> References: <20190615004256.16367-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PATCH 2/7] KVM: i386: 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@oracle.com, nikita.leshchenko@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Signed-off-by: Liran Alon 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 c8d8196e71..53f95b02a0 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -3546,6 +3546,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 2.21.0