From patchwork Thu Oct 18 20:31:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FOLnxzJz"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhCV26Ltz9s8F for ; Fri, 19 Oct 2018 07:55:50 +1100 (AEDT) Received: from localhost ([::1]:44628 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFKd-0001pp-RZ for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:55:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyF-0007H2-8W for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEy8-0006DI-LC for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:35 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:37726) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy5-00063j-Fo for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:31 -0400 Received: by mail-wr1-x432.google.com with SMTP id q1-v6so2207060wrs.4 for ; Thu, 18 Oct 2018 13:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=X95M23LMKjuiZf2LDeAyYVWbs8JDwp9NRuZihCiZHTU=; b=FOLnxzJzPwZFKDNUC2lBAkt2Xj1P9lvTpzEZGgoHq0p0RUvqwkeT/dwsPjKQ9UO/Q6 svG8oQRXlkEL4JZ8rhGQgjI4ex2/DFfUkuj2AUb11N/dGCWz4O3BNn4PNoEYhoNzAluT YEQaISTc7scIP9dtGfciGrylRvAEVbsnOKkpnUivTyozwFzLwnzMDjRNS6zvmNy3JD2K VPeeU8zVBUnt/E4cXI3cwPJ+WovSRkjLrZf41/lAn8e8iYBZVimQvFF1j1SPWmKho5Uf MHjiaQxjx5eiBxbuQPdGKwIqusUY2hH5TwyPJVUGN93gaBSc/8trp+vQFwVbicIrXW4t PJ7w== 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:subject:date:message-id :in-reply-to:references; bh=X95M23LMKjuiZf2LDeAyYVWbs8JDwp9NRuZihCiZHTU=; b=p+sIcriH57qYE4d+RGL9FtiqbFg9WH0cEtGp/8HLY9Mr6PpGM0w0MnJ7RKlDPoQhE4 2/ExhXXUZpFaUzTHh8PdAd0Wj+vSbwIgEKOqvh5wu69wDmMmOpT9/4+acIEBIv3RYIln oMLgbwNcT0cDks7rps4fOhr9ZxuXX0zR6GQhf/EgOY3W89cCL03TcrO0z+kaq5SNm9Mo 7lIl23EuHfoT4cw6CW7St7Ryl4xexKTYNOG1Z9H0IiKJCNeM5W9mzMxY/AfZrOJA6Fva cx4/J2BbaXHIUonLwGmb7ValC3zLMD/Qwm+6vxBJYtTgbIrKy1U1E2iaId5FgHByr9Vt NGfQ== X-Gm-Message-State: ABuFfogDl7NvTgvY2VHxgW7l0H1dGoIGYrlagesi9DtDx91VSC0gOG7E xJhDiqSWi3z+mTCQEA7gVP26QUOs X-Google-Smtp-Source: ACcGV61yyMofIWqBp+8wUhZ63qYszKaV3C+TuPdgkh8r0yzN6bWFz52FpVFhUEaytz/TI+KuGlDxKQ== X-Received: by 2002:adf:e387:: with SMTP id e7-v6mr30633483wrm.94.1539894738343; Thu, 18 Oct 2018 13:32:18 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:28 +0200 Message-Id: <1539894735-14232-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::432 Subject: [Qemu-devel] [PULL 01/48] es1370: more fixes for ADC_FRAMEADR and ADC_FRAMECNT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" They are not consecutive with DAC1_FRAME* and DAC2_FRAME*; Coverity still complains about es1370_read, while es1370_write was fixed in commit cf9270e5220671f49cc238deaf6136669cc07ae1. Fixes: 154c1d1f960c5147a3f8ef00907504112f271cd8 Signed-off-by: Paolo Bonzini --- hw/audio/es1370.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c index 4f980a5..aa5a8d7 100644 --- a/hw/audio/es1370.c +++ b/hw/audio/es1370.c @@ -585,9 +585,12 @@ static uint64_t es1370_read(void *opaque, hwaddr addr, unsigned size) #endif break; + case ES1370_REG_ADC_FRAMECNT: + d += 2; + goto framecnt; case ES1370_REG_DAC1_FRAMECNT: case ES1370_REG_DAC2_FRAMECNT: - case ES1370_REG_ADC_FRAMECNT: + framecnt: d += (addr - ES1370_REG_DAC1_FRAMECNT) >> 3; val = d->frame_cnt; #ifdef DEBUG_ES1370 @@ -602,9 +605,12 @@ static uint64_t es1370_read(void *opaque, hwaddr addr, unsigned size) #endif break; + case ES1370_REG_ADC_FRAMEADR: + d += 2; + goto frameadr; case ES1370_REG_DAC1_FRAMEADR: case ES1370_REG_DAC2_FRAMEADR: - case ES1370_REG_ADC_FRAMEADR: + frameadr: d += (addr - ES1370_REG_DAC1_FRAMEADR) >> 3; val = d->frame_addr; break; From patchwork Thu Oct 18 20:31:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986261 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SVJhAUzt"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bgzk2YTdz9s8F for ; Fri, 19 Oct 2018 07:45:38 +1100 (AEDT) Received: from localhost ([::1]:44560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFAl-0001Gp-KF for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:45:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEy8-00075y-OQ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEy5-0006Ak-HM for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:31 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:54210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy3-00065J-1d for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:27 -0400 Received: by mail-wm1-x343.google.com with SMTP id y11-v6so1570674wma.3 for ; Thu, 18 Oct 2018 13:32:20 -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=qyIgB9GFPh/wAo0RDRseKkM8RiZ6Xv+sAfwMWFoKjlA=; b=SVJhAUztlp9MHGgu79ESxVN336ZIwuytBP9IenA4BjkNoI+IlDVC3JlAlsPGG411zn oHVj3RTqFNMB5O5B7TcnSi59x5hxzjFVe6ipLqni7lDeydenK8GjHYfYX5/t/8dJREQe CZ9xxb8H+1BT8D2iQg2xuYafcxysmaJoO4qxF1rc3RMp53+0XnGlh/OEvpTb1ZIivgqj SUQ9yL2vzhTP8DfXo0AsxO9qHKCxZ0xwPfGxuSTUBalS20kL8Tu2E+lYoCP8czbuA+rj yejCCf0yu8l/OywqkhTRPjN84eD2M8yL2v3WwBIj6myJ5rjXcuOOSdFPsLTuWVthyA3l G93g== 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=qyIgB9GFPh/wAo0RDRseKkM8RiZ6Xv+sAfwMWFoKjlA=; b=Q/Iy6N4KTx1tobxSYjeesU+hOaAXtZQqJtNffakBI2Y8fWrC54qGhTXha3olD7N6qj JRpNsdcO7iqsM+hY9KYu0/WUvq0ed3vl3ykVjXMTky84zqbGD/IFVbgbPVJgOGx8UQQ/ jjKWYG0UDGzYpiJcNr8NyYHuFV8h8f1kUffKGzsWhp+kPlfrnUFVVCRDkKlnKdQT+LLj 2BYET8RBNOKzUz7OvuB5DvrOjUV8RfuvFucx4UUrYHo9K8NBj5tbxBRl5iyG1ySXuYXS HQ/470RM94/7v40YiIxUhgb2onV/S4dKTIo10cchGQcdJ9lIzmr4Q9z35FD0udx1A28o P/Fg== X-Gm-Message-State: ABuFfojkW5w3vG/JkujyXbMC3fd6jr30OYpjaljlZv5SlRxYSFF4nB+U SsZHoSJNjv79wRNcaUOsWvDtppd+ X-Google-Smtp-Source: ACcGV62sjyLeOyirKqGmIM5fQ0gM0v2Wn+wqGNV16vOE7i75al427DXT3Jn2nNeKqy6Cl+PaF2/AiA== X-Received: by 2002:a1c:710:: with SMTP id 16-v6mr1933643wmh.22.1539894739301; Thu, 18 Oct 2018 13:32:19 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:29 +0200 Message-Id: <1539894735-14232-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::343 Subject: [Qemu-devel] [PULL 02/48] Revert some patches from recent [PATCH v6] "Fixing record/replay and adding reverse debugging" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Artem Pisarenko That patch series introduced new virtual clock type for use in external subsystems. It breaks desired behavior in non-record/replay usage scenarios due to a small change to existing behavior. Processing of virtual timers belonging to new clock type is kicked off to the main loop, which makes these timers asynchronous with vCPU thread and, in icount mode, with whole guest execution. This breaks expected determinism in non-record/replay icount mode of emulation where these "external subsystems" are isolated from the host (i.e. they are external only to guest core, not to the entire emulation environment). Example for slirp ("user" backend for network device): User runs qemu in icount mode with rtc clock=vm without any external communication interfaces but with "-netdev user,restrict=on". It expects deterministic execution, because network services are emulated inside qemu and isolated from host. There are no reasons to get reply from DHCP server with different delay or something like that. The next patches revert reimplements the same changes in a better way. This reverts commit 87f4fe7653baf55b5c2f2753fe6003f473c07342. This reverts commit 775a412bf83f6bc0c5c02091ee06cf649b34c593. This reverts commit 9888091404a702d7ec79d51b088d994b9fc121bd. Signed-off-by: Artem Pisarenko Message-Id: <18b1e7c8f155fe26976f91be06bde98eef6f8751.1539764043.git.artem.k.pisarenko@gmail.com> Signed-off-by: Paolo Bonzini --- include/qemu/timer.h | 9 --------- slirp/ip6_icmp.c | 7 +++---- ui/input.c | 8 ++++---- util/qemu-timer.c | 2 -- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index a005ed2..39ea907 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -42,14 +42,6 @@ * In icount mode, this clock counts nanoseconds while the virtual * machine is running. It is used to increase @QEMU_CLOCK_VIRTUAL * while the CPUs are sleeping and thus not executing instructions. - * - * @QEMU_CLOCK_VIRTUAL_EXT: virtual clock for external subsystems - * - * The virtual clock only runs during the emulation. It stops - * when the virtual machine is stopped. The timers for this clock - * do not recorded in rr mode, therefore this clock could be used - * for the subsystems that operate outside the guest core. - * */ typedef enum { @@ -57,7 +49,6 @@ typedef enum { QEMU_CLOCK_VIRTUAL = 1, QEMU_CLOCK_HOST = 2, QEMU_CLOCK_VIRTUAL_RT = 3, - QEMU_CLOCK_VIRTUAL_EXT = 4, QEMU_CLOCK_MAX } QEMUClockType; diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 3f41187..ee333d0 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -17,7 +17,7 @@ static void ra_timer_handler(void *opaque) { Slirp *slirp = opaque; timer_mod(slirp->ra_timer, - qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + NDP_Interval); + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval); ndp_send_ra(slirp); } @@ -27,10 +27,9 @@ void icmp6_init(Slirp *slirp) return; } - slirp->ra_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL_EXT, - ra_timer_handler, slirp); + slirp->ra_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, ra_timer_handler, slirp); timer_mod(slirp->ra_timer, - qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + NDP_Interval); + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval); } void icmp6_cleanup(Slirp *slirp) diff --git a/ui/input.c b/ui/input.c index dd7f6d7..51b1019 100644 --- a/ui/input.c +++ b/ui/input.c @@ -271,7 +271,7 @@ static void qemu_input_queue_process(void *opaque) item = QTAILQ_FIRST(queue); switch (item->type) { case QEMU_INPUT_QUEUE_DELAY: - timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + item->delay_ms); return; case QEMU_INPUT_QUEUE_EVENT: @@ -301,7 +301,7 @@ static void qemu_input_queue_delay(struct QemuInputEventQueueHead *queue, queue_count++; if (start_timer) { - timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + item->delay_ms); } } @@ -448,8 +448,8 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms) } if (!kbd_timer) { - kbd_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL_EXT, - qemu_input_queue_process, &kbd_queue); + kbd_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, qemu_input_queue_process, + &kbd_queue); } if (queue_count < queue_limit) { qemu_input_queue_delay(&kbd_queue, kbd_timer, diff --git a/util/qemu-timer.c b/util/qemu-timer.c index eb60d8f..86bfe84 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -496,7 +496,6 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) switch (timer_list->clock->type) { case QEMU_CLOCK_REALTIME: - case QEMU_CLOCK_VIRTUAL_EXT: break; default: case QEMU_CLOCK_VIRTUAL: @@ -598,7 +597,6 @@ int64_t qemu_clock_get_ns(QEMUClockType type) return get_clock(); default: case QEMU_CLOCK_VIRTUAL: - case QEMU_CLOCK_VIRTUAL_EXT: if (use_icount) { return cpu_get_icount(); } else { From patchwork Thu Oct 18 20:31:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986303 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WAi8yvaT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhXt03yfz9s5c for ; Fri, 19 Oct 2018 08:10:54 +1100 (AEDT) Received: from localhost ([::1]:44718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFZD-0006GU-FH for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:10:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyF-0007H3-DA for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEy7-0006C1-WB for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:37 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:39908) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy3-000660-H8 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:29 -0400 Received: by mail-wr1-x42a.google.com with SMTP id 61-v6so35109149wrb.6 for ; Thu, 18 Oct 2018 13:32:21 -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=F+gd4r1k2Nw0Yr+GOSsn9Ee8n3KcP2p27rYr9qRIXYA=; b=WAi8yvaT+l4apWJ7ZXZfCh6UgmL4munER2RpvvqfODUURua34kk046MyCkceH1+QPD Z1AC1SrwuR2PXDgTCxz++H+/lmyPwfwfYNAYNK6p2xJR8IyfdKIrDq3p2cRLJ4tgSSm6 8n+oDspiyXP+WZRJfwqmqQWUOIv0ioH3qMEiswSncKJRA1w3nUmtrW416JS4Y0BKFM1O 1tyR8rp5/1dHDGhfsyDmCgwTnN+C9MIQra8dwhdb3kGMNc72rypEbJyMlrWUmeaZKuSh 96+A2py/OqefYJ7lHf4H/GT6WsKfvvW7spBRIpYTx36wcudVfH2mgfEhVckBBRnrMOg6 mprQ== 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=F+gd4r1k2Nw0Yr+GOSsn9Ee8n3KcP2p27rYr9qRIXYA=; b=Bgx5j3UI+LDPFCb2CuRBg/ddwJ+CbYoYIE1EaCZ2PhmL2w8ZmpvKndZ/qEMJVtgG3L UHgGPD8eSgOlqoSHe6+s77yX3NCtWTig3/RBrYX+s+vzhQm6Huq33a6CLh8HHy8i4Tbs xG84f2ZD3AdFGUsgDRwIpgGxXD+rDF3EISc9tN1OmTEYWqBrHlNcJ+21a2vb6m5M1dbY csT3ONt/eLOygkP3ncedRQMLxvXlq026fsVu0tjikizzzW0EpQNDG4FGvddk4r293Tew SHXZQvrTvjHpxh9Ygs0Un7sS723rJq77HooCJtYUOQdCxzU/CHBNN+OqORhK1Fom1AWT s34w== X-Gm-Message-State: ABuFfogNfuIyOYEGyY0z1mne3Vs170+AwqcNQhqbMA3fqjIY3q4YLNrW gBwjpekfqrxI57YS5uyLSC6LjzfH X-Google-Smtp-Source: ACcGV62f6TrBH+c/1i8rZ2w+I4br2W+h3GwMHs2ur25a3PbvXtewYYXTW4oRYxIQZdMIVyRFON84Yw== X-Received: by 2002:adf:92e6:: with SMTP id 93-v6mr32153259wrn.124.1539894740446; Thu, 18 Oct 2018 13:32:20 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:30 +0200 Message-Id: <1539894735-14232-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::42a Subject: [Qemu-devel] [PULL 03/48] qemu-timer: introduce timer attributes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Artem Pisarenko Attributes are simple flags, associated with individual timers for their whole lifetime. They intended to be used to mark individual timers for special handling when they fire. New/init functions family in timer interface updated and refactored (new 'attribute' argument added, timer_list replaced with timer_list_group+type combinations, comments improved to avoid info duplication). Also existing aio interface extended with attribute-enabled variants of functions, which create/initialize timers. Signed-off-by: Artem Pisarenko Message-Id: Signed-off-by: Paolo Bonzini --- include/block/aio.h | 59 ++++++++++++++++++++++--- include/qemu/timer.h | 109 +++++++++++++++++++++++----------------------- tests/ptimer-test-stubs.c | 13 ++++-- util/qemu-timer.c | 13 ++++-- 4 files changed, 124 insertions(+), 70 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index f08630c..0ca25df 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -388,18 +388,41 @@ struct LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp); struct LinuxAioState *aio_get_linux_aio(AioContext *ctx); /** - * aio_timer_new: + * aio_timer_new_with_attrs: * @ctx: the aio context * @type: the clock type * @scale: the scale + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR_ values + * to assign * @cb: the callback to call on timer expiry * @opaque: the opaque pointer to pass to the callback * - * Allocate a new timer attached to the context @ctx. + * Allocate a new timer (with attributes) attached to the context @ctx. * The function is responsible for memory allocation. * - * The preferred interface is aio_timer_init. Use that - * unless you really need dynamic memory allocation. + * The preferred interface is aio_timer_init or aio_timer_init_with_attrs. + * Use that unless you really need dynamic memory allocation. + * + * Returns: a pointer to the new timer + */ +static inline QEMUTimer *aio_timer_new_with_attrs(AioContext *ctx, + QEMUClockType type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) +{ + return timer_new_full(&ctx->tlg, type, scale, attributes, cb, opaque); +} + +/** + * aio_timer_new: + * @ctx: the aio context + * @type: the clock type + * @scale: the scale + * @cb: the callback to call on timer expiry + * @opaque: the opaque pointer to pass to the callback + * + * Allocate a new timer attached to the context @ctx. + * See aio_timer_new_with_attrs for details. * * Returns: a pointer to the new timer */ @@ -407,7 +430,29 @@ static inline QEMUTimer *aio_timer_new(AioContext *ctx, QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - return timer_new_tl(ctx->tlg.tl[type], scale, cb, opaque); + return timer_new_full(&ctx->tlg, type, scale, 0, cb, opaque); +} + +/** + * aio_timer_init_with_attrs: + * @ctx: the aio context + * @ts: the timer + * @type: the clock type + * @scale: the scale + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR_ values + * to assign + * @cb: the callback to call on timer expiry + * @opaque: the opaque pointer to pass to the callback + * + * Initialise a new timer (with attributes) attached to the context @ctx. + * The caller is responsible for memory allocation. + */ +static inline void aio_timer_init_with_attrs(AioContext *ctx, + QEMUTimer *ts, QEMUClockType type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) +{ + timer_init_full(ts, &ctx->tlg, type, scale, attributes, cb, opaque); } /** @@ -420,14 +465,14 @@ static inline QEMUTimer *aio_timer_new(AioContext *ctx, QEMUClockType type, * @opaque: the opaque pointer to pass to the callback * * Initialise a new timer attached to the context @ctx. - * The caller is responsible for memory allocation. + * See aio_timer_init_with_attrs for details. */ static inline void aio_timer_init(AioContext *ctx, QEMUTimer *ts, QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - timer_init_tl(ts, ctx->tlg.tl[type], scale, cb, opaque); + timer_init_full(ts, &ctx->tlg, type, scale, 0, cb, opaque); } /** diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 39ea907..8ff1092 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -2,6 +2,7 @@ #define QEMU_TIMER_H #include "qemu-common.h" +#include "qemu/bitops.h" #include "qemu/notify.h" #include "qemu/host-utils.h" @@ -52,6 +53,16 @@ typedef enum { QEMU_CLOCK_MAX } QEMUClockType; +/** + * QEMU Timer attributes: + * + * An individual timer may be given one or multiple attributes when initialized. + * Each attribute corresponds to one bit. Attributes modify the processing + * of timers when they fire. + * + * No attributes defined currently. + */ + typedef struct QEMUTimerList QEMUTimerList; struct QEMUTimerListGroup { @@ -67,6 +78,7 @@ struct QEMUTimer { QEMUTimerCB *cb; void *opaque; QEMUTimer *next; + int attributes; int scale; }; @@ -418,22 +430,27 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg); */ /** - * timer_init_tl: + * timer_init_full: * @ts: the timer to be initialised - * @timer_list: the timer list to attach the timer to + * @timer_list_group: (optional) the timer list group to attach the timer to + * @type: the clock type to use * @scale: the scale value for the timer + * @attributes: 0, or one or more OR'ed QEMU_TIMER_ATTR_ values * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Initialise a new timer and associate it with @timer_list. + * Initialise a timer with the given scale and attributes, + * and associate it with timer list for given clock @type in @timer_list_group + * (or default timer list group, if NULL). * The caller is responsible for allocating the memory. * * You need not call an explicit deinit call. Simply make * sure it is not on a list with timer_del. */ -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque); +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque); /** * timer_init: @@ -445,14 +462,12 @@ void timer_init_tl(QEMUTimer *ts, * * Initialize a timer with the given scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init(QEMUTimer *ts, QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - timer_init_tl(ts, main_loop_tlg.tl[type], scale, cb, opaque); + timer_init_full(ts, NULL, type, scale, 0, cb, opaque); } /** @@ -464,9 +479,7 @@ static inline void timer_init(QEMUTimer *ts, QEMUClockType type, int scale, * * Initialize a timer with nanosecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_ns(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -483,9 +496,7 @@ static inline void timer_init_ns(QEMUTimer *ts, QEMUClockType type, * * Initialize a timer with microsecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_us(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -502,9 +513,7 @@ static inline void timer_init_us(QEMUTimer *ts, QEMUClockType type, * * Initialize a timer with millisecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_ms(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -513,27 +522,37 @@ static inline void timer_init_ms(QEMUTimer *ts, QEMUClockType type, } /** - * timer_new_tl: - * @timer_list: the timer list to attach the timer to + * timer_new_full: + * @timer_list_group: (optional) the timer list group to attach the timer to + * @type: the clock type to use * @scale: the scale value for the timer + * @attributes: 0, or one or more OR'ed QEMU_TIMER_ATTR_ values * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Create a new timer and associate it with @timer_list. + * Create a new timer with the given scale and attributes, + * and associate it with timer list for given clock @type in @timer_list_group + * (or default timer list group, if NULL). * The memory is allocated by the function. * * This is not the preferred interface unless you know you - * are going to call timer_free. Use timer_init instead. + * are going to call timer_free. Use timer_init or timer_init_full instead. + * + * The default timer list has one special feature: in icount mode, + * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is + * not true of other timer lists, which are typically associated + * with an AioContext---each of them runs its timer callbacks in its own + * AioContext thread. * * Returns: a pointer to the timer */ -static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list, - int scale, - QEMUTimerCB *cb, - void *opaque) +static inline QEMUTimer *timer_new_full(QEMUTimerListGroup *timer_list_group, + QEMUClockType type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { QEMUTimer *ts = g_malloc0(sizeof(QEMUTimer)); - timer_init_tl(ts, timer_list, scale, cb, opaque); + timer_init_full(ts, timer_list_group, type, scale, attributes, cb, opaque); return ts; } @@ -544,21 +563,16 @@ static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list, * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Create a new timer and associate it with the default - * timer list for the clock type @type. - * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. + * Create a new timer with the given scale, + * and associate it with the default timer list for the clock type @type. + * See timer_new_full for details. * * Returns: a pointer to the timer */ static inline QEMUTimer *timer_new(QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - return timer_new_tl(main_loop_tlg.tl[type], scale, cb, opaque); + return timer_new_full(NULL, type, scale, 0, cb, opaque); } /** @@ -569,12 +583,7 @@ static inline QEMUTimer *timer_new(QEMUClockType type, int scale, * * Create a new timer with nanosecond scale on the default timer list * associated with the clock. - * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ @@ -590,14 +599,9 @@ static inline QEMUTimer *timer_new_ns(QEMUClockType type, QEMUTimerCB *cb, * @cb: the callback to call when the timer expires * @opaque: the opaque pointer to pass to the callback * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. - * * Create a new timer with microsecond scale on the default timer list * associated with the clock. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ @@ -613,14 +617,9 @@ static inline QEMUTimer *timer_new_us(QEMUClockType type, QEMUTimerCB *cb, * @cb: the callback to call when the timer expires * @opaque: the opaque pointer to pass to the callback * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. - * * Create a new timer with millisecond scale on the default timer list * associated with the clock. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ diff --git a/tests/ptimer-test-stubs.c b/tests/ptimer-test-stubs.c index ca5cc3b..54b3fd2 100644 --- a/tests/ptimer-test-stubs.c +++ b/tests/ptimer-test-stubs.c @@ -34,14 +34,19 @@ int64_t ptimer_test_time_ns; int use_icount = 1; bool qtest_allowed; -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque) +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { - ts->timer_list = timer_list; + if (!timer_list_group) { + timer_list_group = &main_loop_tlg; + } + ts->timer_list = timer_list_group->tl[type]; ts->cb = cb; ts->opaque = opaque; ts->scale = scale; + ts->attributes = attributes; ts->expire_time = -1; } diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 86bfe84..04527a3 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -339,14 +339,19 @@ int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout) } -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque) +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { - ts->timer_list = timer_list; + if (!timer_list_group) { + timer_list_group = &main_loop_tlg; + } + ts->timer_list = timer_list_group->tl[type]; ts->cb = cb; ts->opaque = opaque; ts->scale = scale; + ts->attributes = attributes; ts->expire_time = -1; } From patchwork Thu Oct 18 20:31:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TmiC6/BC"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bh8412CSz9s1c for ; Fri, 19 Oct 2018 07:52:52 +1100 (AEDT) Received: from localhost ([::1]:44609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFHl-0007JC-MW for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:52:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEy8-000765-P6 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEy5-0006Ab-EF for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:31 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:35971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy1-00066Y-Qs for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:27 -0400 Received: by mail-wm1-x344.google.com with SMTP id a8-v6so1626269wmf.1 for ; Thu, 18 Oct 2018 13:32:22 -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=RjqBrvJxw4+BzQE5/W7t9Zaud/Hwg2+ea952w8wVXT0=; b=TmiC6/BCVe+aLE9jNu2O/HbB8T2RleKizASr092dw1XG5qoauAfFzg6eI3c++D5vKA dx6TuBis+4DiBz1Kdp63gPSeug+gXcDWd7Hf3kVYGlaNFZwgIG9ka6VFx4m02IhTkREQ 6A7UGNUfcdBEEpwy19aSrsZGsG9P86dRFpeLrkyXURtwx2I+gr47CPyrIXYFl0TQtezq xsaVh4BbajvnkvV3zsxyPKqxDDP8M829xPoVzxkriS9CGbYiNmGT52/dXkt7vWDNlmWv SEyJJgBFEJOjwiKpGa45KO3ORBdSnjMMCy3q23RZ8godpl5i4ZPr4ragOdC9RXd8VzH1 ROAg== 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=RjqBrvJxw4+BzQE5/W7t9Zaud/Hwg2+ea952w8wVXT0=; b=KoaC+G9agL94dEDCwXfFMgI/djBq8ovBr+D8u8CCuadBfAorCcPnRNO+ESPwU8EBDn BBOALfLR/rSjSlv6dFhh2HZR9T/YeIfCYrmIF0qcY/Hw0LIqJZGf1cqQ7uDagHAh6d4x 5V1jcU9BLguvl7QZzMSfAq5EauWe+p/IjKgvFJ+nU5nvgCX5LyhgybzJglvgH2zX+OfX 6D1ST97i8twzaE+HV3jzT7PK0ptNh6OONQfn7cjjmDjtOHG2PwDi22go3exZJYlrMjj3 z58yNWldpp2C9Y2oAgnZqe8KDXjryPXMtldBvWrH5A1hC+dzqopUdv4WRMPcpTW19RsZ k6sg== X-Gm-Message-State: ABuFfohp7y6gkz+jS96LZ4EEUFthUgYI0O5irkZ+dnpPZA364Yq/wuAr p/kkWEuk2y9LamHpqYcPiCjIQIrO X-Google-Smtp-Source: ACcGV615vWHCZajFUU1V0Ls1Ur/VliY0kervUXM9twXCtYJrt0/MNybCGgQMvmUxRGF1HSgExyxRhw== X-Received: by 2002:a1c:a683:: with SMTP id p125-v6mr1961332wme.24.1539894741472; Thu, 18 Oct 2018 13:32:21 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:31 +0200 Message-Id: <1539894735-14232-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::344 Subject: [Qemu-devel] [PULL 04/48] qemu-timer: avoid checkpoints for virtual clock timers in external subsystems X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Artem Pisarenko Adds EXTERNAL attribute definition to qemu timers subsystem and assigns it to virtual clock timers, used in slirp (ICMP IPv6) and ui (key queue). Virtual clock processing in rr mode can use this attribute instead of a separate clock type. Fixes: 87f4fe7653baf55b5c2f2753fe6003f473c07342 Fixes: 775a412bf83f6bc0c5c02091ee06cf649b34c593 Fixes: 9888091404a702d7ec79d51b088d994b9fc121bd Signed-off-by: Artem Pisarenko Message-Id: Signed-off-by: Paolo Bonzini --- include/qemu/timer.h | 10 +++++++++- slirp/ip6_icmp.c | 4 +++- ui/input.c | 5 +++-- util/qemu-timer.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 8ff1092..9f37c92 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -60,9 +60,17 @@ typedef enum { * Each attribute corresponds to one bit. Attributes modify the processing * of timers when they fire. * - * No attributes defined currently. + * The following attributes are available: + * + * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem + * + * Timers with this attribute do not recorded in rr mode, therefore it could be + * used for the subsystems that operate outside the guest core. Applicable only + * with virtual clock type. */ +#define QEMU_TIMER_ATTR_EXTERNAL BIT(0) + typedef struct QEMUTimerList QEMUTimerList; struct QEMUTimerListGroup { diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index ee333d0..cd1e0b9 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -27,7 +27,9 @@ void icmp6_init(Slirp *slirp) return; } - slirp->ra_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, ra_timer_handler, slirp); + slirp->ra_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, + SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, + ra_timer_handler, slirp); timer_mod(slirp->ra_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval); } diff --git a/ui/input.c b/ui/input.c index 51b1019..7c9a410 100644 --- a/ui/input.c +++ b/ui/input.c @@ -448,8 +448,9 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms) } if (!kbd_timer) { - kbd_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, qemu_input_queue_process, - &kbd_queue); + kbd_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, + SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, + qemu_input_queue_process, &kbd_queue); } if (queue_count < queue_limit) { qemu_input_queue_delay(&kbd_queue, kbd_timer, diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 04527a3..1cc1b2f 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -489,6 +489,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) bool progress = false; QEMUTimerCB *cb; void *opaque; + bool need_replay_checkpoint = false; if (!atomic_read(&timer_list->active_timers)) { return false; @@ -504,8 +505,15 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) break; default: case QEMU_CLOCK_VIRTUAL: - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { - goto out; + if (replay_mode != REPLAY_MODE_NONE) { + /* Checkpoint for virtual clock is redundant in cases where + * it's being triggered with only non-EXTERNAL timers, because + * these timers don't change guest state directly. + * Since it has conditional dependence on specific timers, it is + * subject to race conditions and requires special handling. + * See below. + */ + need_replay_checkpoint = true; } break; case QEMU_CLOCK_HOST: @@ -520,14 +528,39 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) break; } + /* + * Extract expired timers from active timers list and and process them. + * + * In rr mode we need "filtered" checkpointing for virtual clock. The + * checkpoint must be recorded/replayed before processing any non-EXTERNAL timer, + * and that must only be done once since the clock value stays the same. Because + * non-EXTERNAL timers may appear in the timers list while it being processed, + * the checkpoint can be issued at a time until no timers are left and we are + * done". + */ current_time = qemu_clock_get_ns(timer_list->clock->type); - for(;;) { - qemu_mutex_lock(&timer_list->active_timers_lock); - ts = timer_list->active_timers; + qemu_mutex_lock(&timer_list->active_timers_lock); + while ((ts = timer_list->active_timers)) { if (!timer_expired_ns(ts, current_time)) { - qemu_mutex_unlock(&timer_list->active_timers_lock); + /* No expired timers left. The checkpoint can be skipped + * if no timers fired or they were all external. + */ break; } + if (need_replay_checkpoint + && !(ts->attributes & QEMU_TIMER_ATTR_EXTERNAL)) { + /* once we got here, checkpoint clock only once */ + need_replay_checkpoint = false; + qemu_mutex_unlock(&timer_list->active_timers_lock); + if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { + goto out; + } + qemu_mutex_lock(&timer_list->active_timers_lock); + /* The lock was released; start over again in case the list was + * modified. + */ + continue; + } /* remove timer from the list before calling the callback */ timer_list->active_timers = ts->next; @@ -535,12 +568,15 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) ts->expire_time = -1; cb = ts->cb; opaque = ts->opaque; - qemu_mutex_unlock(&timer_list->active_timers_lock); /* run the callback (the timer list can be modified) */ + qemu_mutex_unlock(&timer_list->active_timers_lock); cb(opaque); + qemu_mutex_lock(&timer_list->active_timers_lock); + progress = true; } + qemu_mutex_unlock(&timer_list->active_timers_lock); out: qemu_event_set(&timer_list->timers_done_ev); From patchwork Thu Oct 18 20:31:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ql3RYpkh"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bh3Q5vtxz9s1c for ; Fri, 19 Oct 2018 07:48:50 +1100 (AEDT) Received: from localhost ([::1]:44578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFDs-00046F-7a for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:48:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEy8-00075x-OK for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEy3-00069O-G2 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:31 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:46267) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy1-00067D-H3 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:25 -0400 Received: by mail-wr1-x444.google.com with SMTP id n11-v6so35030281wru.13 for ; Thu, 18 Oct 2018 13:32:24 -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=ePtbzgc70k9gGLpBJMUy8rTVhabLbrTY1Yy2JOKpK+Y=; b=Ql3RYpkhNk++KGgQFnhWgA9gCk/As2O0rQ9UNO1+dX9gwMP0OEMU4R6bIwlUuUiBpY y3aqdzh3nIKPw8FI5y5wN7Kc6h9fV7IsX+PPZ/1OwF8+6R8ovdx3goNlM9GYDfVQcMYJ CSxakcVzZX4lZua5OWmjYul8pdLYXdQVqEYeJuhKaZsoXB0RMYe+Vb1l9oiVPu6H+bCy vhKoLHHsdjPBzJW/HH+b4xi8DoIf2/34xlBQWcp55JkXIRRoODO0kuuM2ZV9HfW8El7X KD+DFR72q36MKHmoKjHwZ1Hk5Z4NvCZPeKv57x6XssUMiAJPlUAgzIK70ATkOmHKSrlb IkZw== 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=ePtbzgc70k9gGLpBJMUy8rTVhabLbrTY1Yy2JOKpK+Y=; b=endB1uUTjB6+mOSwYcqfIPwXSOZB8aLP7qybLYRuJA9m2G2J0ipx5dW49NJ24km9ii vNOfW5SbkSkicozX/7FG1cQLG1uWFkV8z1ShB04w8VRo81RdLXbJJB7WqkEvjI7hd1IE PTpn9QiiqTsQkb5PJXwRuespbm4rGPqLd8pfsbvJaIiXCuvbTsVxa7/UH/3Yumczp10I G4q7L5mXUSEx82tGwxfKr4QAeEtXNYLpgkKnpuSnPza5EU8CwrYGnDkKy9QqBp1ksCYT 0nVB4UUiQFzl1GYlUOd3KsW5nMJFZJX8EcBEb5wimugqpq+n77Hb2RuO6oqSIUpAwjMH 7FFg== X-Gm-Message-State: ABuFfohNgOHY1dKZzowQjfb01NEgBCXSBYZOGq5H+AAVvGZTexDEJ5Z7 iPSPWh5SZaRNFr0ARtSF8wD9hadN X-Google-Smtp-Source: ACcGV60667TNLJ9adr6jY7nY5PQClLZvesFxq7ah2xxua4OwNKr+3Kme0mHVD0wDMTTUxjvch90Y3Q== X-Received: by 2002:adf:aa90:: with SMTP id h16-v6mr29120135wrc.216.1539894742800; Thu, 18 Oct 2018 13:32:22 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:32 +0200 Message-Id: <1539894735-14232-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::444 Subject: [Qemu-devel] [PULL 05/48] qemu-timer: optimize record/replay checkpointing for all clocks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Artem Pisarenko Removes redundant checkpoints in replay log when there are no expired timers in timers list, associated with corresponding clock (i.e. no rr events associated with current clock value). This also improves performance in rr mode. Signed-off-by: Artem Pisarenko Message-Id: <549dbf4ebfa4c82051d01a264c27f88929fc277b.1539764043.git.artem.k.pisarenko@gmail.com> Signed-off-by: Paolo Bonzini --- include/qemu/timer.h | 2 +- util/qemu-timer.c | 67 +++++++++++++++++++++++----------------------------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 9f37c92..9c668c8 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -65,7 +65,7 @@ typedef enum { * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem * * Timers with this attribute do not recorded in rr mode, therefore it could be - * used for the subsystems that operate outside the guest core. Applicable only + * used for the subsystems that operate outside the guest core. Relevant only * with virtual clock type. */ diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 1cc1b2f..8d3a806 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -482,6 +482,25 @@ bool timer_expired(QEMUTimer *timer_head, int64_t current_time) return timer_expired_ns(timer_head, current_time * timer_head->scale); } +static bool timer_checkpoint(QEMUClockType clock) +{ + assert(replay_mode != REPLAY_MODE_NONE); + switch (clock) { + case QEMU_CLOCK_VIRTUAL: + return replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL); + case QEMU_CLOCK_HOST: + return replay_checkpoint(CHECKPOINT_CLOCK_HOST); + case QEMU_CLOCK_VIRTUAL_RT: + return replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL_RT); + default: + /* QEMU_CLOCK_REALTIME is external to the emulation and does + * not need checkpointing. + */ + break; + } + return true; +} + bool timerlist_run_timers(QEMUTimerList *timer_list) { QEMUTimer *ts; @@ -489,7 +508,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) bool progress = false; QEMUTimerCB *cb; void *opaque; - bool need_replay_checkpoint = false; + bool need_replay_checkpoint = (replay_mode != REPLAY_MODE_NONE); if (!atomic_read(&timer_list->active_timers)) { return false; @@ -500,43 +519,17 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) goto out; } - switch (timer_list->clock->type) { - case QEMU_CLOCK_REALTIME: - break; - default: - case QEMU_CLOCK_VIRTUAL: - if (replay_mode != REPLAY_MODE_NONE) { - /* Checkpoint for virtual clock is redundant in cases where - * it's being triggered with only non-EXTERNAL timers, because - * these timers don't change guest state directly. - * Since it has conditional dependence on specific timers, it is - * subject to race conditions and requires special handling. - * See below. - */ - need_replay_checkpoint = true; - } - break; - case QEMU_CLOCK_HOST: - if (!replay_checkpoint(CHECKPOINT_CLOCK_HOST)) { - goto out; - } - break; - case QEMU_CLOCK_VIRTUAL_RT: - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL_RT)) { - goto out; - } - break; - } - /* - * Extract expired timers from active timers list and and process them. + * Extract expired timers from active timers list and and process them, + * taking into account checkpointing required in rr mode. * - * In rr mode we need "filtered" checkpointing for virtual clock. The - * checkpoint must be recorded/replayed before processing any non-EXTERNAL timer, - * and that must only be done once since the clock value stays the same. Because - * non-EXTERNAL timers may appear in the timers list while it being processed, - * the checkpoint can be issued at a time until no timers are left and we are - * done". + * The checkpoint must be recorded/replayed before processing any non-EXTERNAL + * timer (external timers are those that don't affect guest state directly; + * usually they are QEMU_CLOCK_REALTIME, which doesn't checkpoint at all, + * but there are exceptions). Checkpointing, furthermore, must only be done once + * since the clock value stays the same. Because non-EXTERNAL timers may appear + * in the timers list while it being processed, the checkpoint can be issued at + * a time until no timers are left and we are done". */ current_time = qemu_clock_get_ns(timer_list->clock->type); qemu_mutex_lock(&timer_list->active_timers_lock); @@ -552,7 +545,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) /* once we got here, checkpoint clock only once */ need_replay_checkpoint = false; qemu_mutex_unlock(&timer_list->active_timers_lock); - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { + if (!timer_checkpoint(timer_list->clock->type)) { goto out; } qemu_mutex_lock(&timer_list->active_timers_lock); From patchwork Thu Oct 18 20:31:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986310 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KPzH1Qdm"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhcT5M6Rz9s8J for ; Fri, 19 Oct 2018 08:14:01 +1100 (AEDT) Received: from localhost ([::1]:44731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFcE-0000Mc-PM for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:13:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyF-0007H5-EI for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEy8-0006Dg-SS for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:37 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:56234) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy7-00067j-VJ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:32 -0400 Received: by mail-wm1-x330.google.com with SMTP id 206-v6so1556464wmb.5 for ; Thu, 18 Oct 2018 13:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=YQLXCJHKOBqAsRVJMHEXvjZQz5qctJ72q0tzUh4XlZY=; b=KPzH1QdmkioJQng+p37/DUt4V1hMbO54nqU/Yy9GAwiqvdDJK6V5h9cqibxzhFJR2t wODJrPdxLLOgi4WEbaMr/049sCmKYpC+NgNaHzRE5kqaoZ8+4b3qLkwzmmkmM+pPy3TQ hHl3u0uo9hgub/Thk2liiGKQ17EOrXMbClkSz7ZVtpPDotfeU7KEjV30Odlbb3AtNDSX Xo99GOrZt3iKC6NeeH3Zhfx8CUdHUiMEYn+/wFePXeCdei8AS5QWM2oboVZxrolstzkp 5SJzNLP4A32BPPsz4G9PTngo6CJ52EtX+xLj2eUmhiEQ5LWdtC6YVfOPL6sVopLeTkXQ F34A== 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:subject:date:message-id :in-reply-to:references; bh=YQLXCJHKOBqAsRVJMHEXvjZQz5qctJ72q0tzUh4XlZY=; b=GSBjnP/1FCtQu687Z1a1FuQNhaL9h5C6Cnvf8skxUfAJ6mnobWQ2j2pPEMDA62zSDS 7nwsFe7cE1e2GFi0KR5OxI6+gfxzZ90lwgbxjFjaE9MQCSNCShoDlSG5KY1a+0bMg5At PBUWBIDOE1Kh8TAOBSXwWtzeW3+pMXxusoPpydawScnzlNeA3j4aAhr+SiW+r2FTAXyZ +S4qJA+Z3QiQg8Tb8vuCp3A8f+Vb6KakHMMI2LIHYM7Rz0sXkgiUf9V3wqW8otvmqjzo 450MXch1zdGjUrh104bA78aVY8UB80SwNh92JD3eXg1YRneAiIRGRFu58XVauDXKZNfN qugQ== X-Gm-Message-State: AGRZ1gL7+1h3X9+E1+qGytQiLdz9elzrbtmEit3tudJ/nwsai1RFNmJ3 uwVYCEECTgP3Ez5arlwNHZ+3zVvB X-Google-Smtp-Source: ACcGV63UY+mVnjDxFSoPT0GWT4gNZlBHdOLK/mHxPACoZR5ZTEPQoZY1nWaNHR+7vw16b0EsOgtvuw== X-Received: by 2002:a1c:b20d:: with SMTP id b13-v6mr1815818wmf.141.1539894743904; Thu, 18 Oct 2018 13:32:23 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:33 +0200 Message-Id: <1539894735-14232-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::330 Subject: [Qemu-devel] [PULL 06/48] target-i386: kvm: do not initialize padding fields X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The exception.pad field is going to be renamed to pending in an upcoming header file update. Remove the unnecessary initialization; it was introduced to please valgrind (commit 7e680753cfa2) but they were later rendered unnecessary by commit 076796f8fd27f4d, which added the "= {}" initializer to the declaration of "events". Therefore the patch does not change behavior in any way. Signed-off-by: Paolo Bonzini Reviewed-by: Peter Maydell --- target/i386/kvm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index dc4047b..302f420 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -2686,7 +2686,6 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) events.exception.nr = env->exception_injected; events.exception.has_error_code = env->has_error_code; events.exception.error_code = env->error_code; - events.exception.pad = 0; events.interrupt.injected = (env->interrupt_injected >= 0); events.interrupt.nr = env->interrupt_injected; @@ -2695,7 +2694,6 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) events.nmi.injected = env->nmi_injected; events.nmi.pending = env->nmi_pending; events.nmi.masked = !!(env->hflags2 & HF2_NMI_MASK); - events.nmi.pad = 0; events.sipi_vector = env->sipi_vector; events.flags = 0; From patchwork Thu Oct 18 20:31:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rr/2DRkT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhln2VGrz9s8J for ; Fri, 19 Oct 2018 08:20:21 +1100 (AEDT) Received: from localhost ([::1]:44765 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFiM-0006yc-TA for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:20:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JK-Ch for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyE-0006IY-87 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:51545) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy9-00068P-1D for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:33 -0400 Received: by mail-wm1-x342.google.com with SMTP id 143-v6so1566591wmf.1 for ; Thu, 18 Oct 2018 13:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=vYjKdiE2GLGblxtAlP1NLTHpKgRffcwOXUKRX+FNq5w=; b=rr/2DRkTn70OZ2ao+XAYdF0ipB2cCTtivgvuLPDj6tDxGVzlZHi0VURtlxHmYFdxLK 53K8DaKSCl2TzjOPhdLH1Ho/2zMqGwwEHWmhav/iRTR0dzHRP3D25q+nYKSMiPHkVnN7 NK2Hzw5pion9FbPgnsA2weeANJQGxvQRCCfho4qsaUkRkGaV4ymmjlErjWMGUYJrAM9l wMZ72Z558lc3Uof4mU5H/6gUZCgUZmy6tGnAlywHMXj2/rWE18WvOrv+Yp7JjbelSzpD UuORaqmweKozv/5Sph19LOXVdvjrK1du3+aybkAMkHyvYMLm9CiIpGtuBvdYLbC49fnU gj2A== 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:subject:date:message-id :in-reply-to:references; bh=vYjKdiE2GLGblxtAlP1NLTHpKgRffcwOXUKRX+FNq5w=; b=Rja8dvySAa2krpurwgNXJfJai2G3ZKn9PRdXUQJV6AZWc3UWZ1A7GQsvO+NMZDMVzI T4qp3s/hJzzhB0EFWAo7LNFjLyuk/+9kPKgXayOx1KmbsqlAcL8Zll1RTm+SbRJbQqsr hjXg06QYHGqNUKiZcIChrR+OOMLg5aeF5BMwuVlNTeJtaMdsJ/LH0v3G9CnzD1O/i9I2 /xVMz8yonJZqrikOLu5D1KLgzkkrYCDz/wVdcitiNeIk/PmvJtI4637ubR3BbX0N8Ki2 /OJSW7PleBKYAsv5fb9XvYkF7jOh5Vj/g9hQu/uHpAqFpwXEBy9H41nAWCTtPpKZOmkB xLPA== X-Gm-Message-State: AGRZ1gJjuboIr+z9DNoIWlwXYaRlke6qpQ676cZdYZy2pBB6SrmCN6F5 8V6PKkFS0votp/ZQ54wSBy/Z2738 X-Google-Smtp-Source: ACcGV61Yu9dne1Te+jSjP8x71Ak6PD+5t+QNB/H7ji6P4wwcL5oQG+PpOTBK2gZZcB3EstuPq94zSQ== X-Received: by 2002:a1c:b58e:: with SMTP id e136-v6mr1817229wmf.114.1539894744994; Thu, 18 Oct 2018 13:32:24 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:34 +0200 Message-Id: <1539894735-14232-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::342 Subject: [Qemu-devel] [PULL 07/48] linux-headers: update to 4.20-rc1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This brings in eVMCS and coalesced PIO support, as well as other features we do not support yet. Signed-off-by: Paolo Bonzini --- linux-headers/asm-powerpc/kvm.h | 1 + linux-headers/asm-x86/kvm.h | 8 ++++++-- linux-headers/linux/kvm.h | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/linux-headers/asm-powerpc/kvm.h b/linux-headers/asm-powerpc/kvm.h index 1b32b56..8c876c1 100644 --- a/linux-headers/asm-powerpc/kvm.h +++ b/linux-headers/asm-powerpc/kvm.h @@ -634,6 +634,7 @@ struct kvm_ppc_cpu_char { #define KVM_REG_PPC_DEC_EXPIRY (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbe) #define KVM_REG_PPC_ONLINE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbf) +#define KVM_REG_PPC_PTCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc0) /* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index fd23d57..dabfcf7 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -288,6 +288,7 @@ struct kvm_reinject_control { #define KVM_VCPUEVENT_VALID_SIPI_VECTOR 0x00000002 #define KVM_VCPUEVENT_VALID_SHADOW 0x00000004 #define KVM_VCPUEVENT_VALID_SMM 0x00000008 +#define KVM_VCPUEVENT_VALID_PAYLOAD 0x00000010 /* Interrupt shadow states */ #define KVM_X86_SHADOW_INT_MOV_SS 0x01 @@ -299,7 +300,7 @@ struct kvm_vcpu_events { __u8 injected; __u8 nr; __u8 has_error_code; - __u8 pad; + __u8 pending; __u32 error_code; } exception; struct { @@ -322,7 +323,9 @@ struct kvm_vcpu_events { __u8 smm_inside_nmi; __u8 latched_init; } smi; - __u32 reserved[9]; + __u8 reserved[27]; + __u8 exception_has_payload; + __u64 exception_payload; }; /* for KVM_GET/SET_DEBUGREGS */ @@ -381,6 +384,7 @@ struct kvm_sync_regs { #define KVM_STATE_NESTED_GUEST_MODE 0x00000001 #define KVM_STATE_NESTED_RUN_PENDING 0x00000002 +#define KVM_STATE_NESTED_EVMCS 0x00000004 #define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001 #define KVM_STATE_NESTED_SMM_VMXON 0x00000002 diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 83ba4eb..f11a7eb 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -420,13 +420,19 @@ struct kvm_run { struct kvm_coalesced_mmio_zone { __u64 addr; __u32 size; - __u32 pad; + union { + __u32 pad; + __u32 pio; + }; }; struct kvm_coalesced_mmio { __u64 phys_addr; __u32 len; - __u32 pad; + union { + __u32 pad; + __u32 pio; + }; __u8 data[8]; }; @@ -719,6 +725,7 @@ struct kvm_ppc_one_seg_page_size { #define KVM_PPC_PAGE_SIZES_REAL 0x00000001 #define KVM_PPC_1T_SEGMENTS 0x00000002 +#define KVM_PPC_NO_HASH 0x00000004 struct kvm_ppc_smmu_info { __u64 flags; @@ -953,6 +960,11 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_NESTED_STATE 157 #define KVM_CAP_ARM_INJECT_SERROR_ESR 158 #define KVM_CAP_MSR_PLATFORM_INFO 159 +#define KVM_CAP_PPC_NESTED_HV 160 +#define KVM_CAP_HYPERV_SEND_IPI 161 +#define KVM_CAP_COALESCED_PIO 162 +#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163 +#define KVM_CAP_EXCEPTION_PAYLOAD 164 #ifdef KVM_CAP_IRQ_ROUTING From patchwork Thu Oct 18 20:31:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="l3+2aGVU"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhP06vL2z9s5c for ; Fri, 19 Oct 2018 08:04:04 +1100 (AEDT) Received: from localhost ([::1]:44676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFSc-0000Xl-F3 for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:04:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JP-DU for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyF-0006J5-8o for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:33364) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy9-00068t-4E for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:33 -0400 Received: by mail-wr1-x42b.google.com with SMTP id e4-v6so35109830wrs.0 for ; Thu, 18 Oct 2018 13:32:27 -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=YVxtFGxDJw1vToy/wlvj40Ia2zdT2TZELui9N0jMEmI=; b=l3+2aGVU6dBNaILR4wFB4ICwwdpdLOd+uX7Kwie3OZQ7Yjz2dVme+JSJiuzNXd5NXk nVgUdhPndTWOY+/sYRmc/X67NxCNzhToA4ZkvtxyK/p1ZrQuG8L71Z9ebaChlHvbqWS0 QkE1kyMFSSMdIOZskmIwJ5F4Qlrc46MRGs2a1ecmB+S1o7HlxjLMofAqT+OB1iqpF7Z5 QLFTo3WS+Jfk3ESOYlTGUBHcDTp2CcUwn2bLAPI6sur/6uzXzS6ISzlm8e/iFAe4qMyI DEJjF0zqQiGrzekWY8CSTmoKhvzQUj61nXqb8as8Dvff3Kptf+rINyLSpl5i7yWSuuTT 8Tgw== 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=YVxtFGxDJw1vToy/wlvj40Ia2zdT2TZELui9N0jMEmI=; b=GZSpXBg3p+xExmck0J2fa6ptl1Rs1NXCDBVN7QDPh+KzWtWNz/rztVmyaagpbusLKc UIHK1m790kQPsNFkPT5fftWzchVCLZ9m4VVBmcJysIwHCYBxmdALa/ZGBPaXzwhRAtt0 QDiWMB1c3t1TPood15o0HWb4IkfGkk0hG8bxXWjVYlyUW3M37avEt/Bt6fO4D+Z7XshV 4GrL3ZeYu/X7/BD2/X7O5czU0qJNaiQ/QS7Ft0qg9K37rxwtRkRXEYa2e9tK9yqq8/tG ibjwUBPVv0IQ1oCW0CWRUTmVhfvlDXm0azbKsWhs9yhGoxmac7V18aeREi7/6yUz0aHI gJmw== X-Gm-Message-State: ABuFfog34bseraSjbwe1GMcigSvqeL60MobdlIM8t9505N9u9cAAbFyG Eh5fPHBKeIbZotD5JXVjyJ8EnX2G X-Google-Smtp-Source: ACcGV63X9d7yhEUlxAv78KXK8TgcFVhKwqM6V/3XIU4bfuEsNsubzMF2axH/+dc32uA6ttRDPbprpg== X-Received: by 2002:a5d:60c3:: with SMTP id x3-v6mr31674553wrt.193.1539894746141; Thu, 18 Oct 2018 13:32:26 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:35 +0200 Message-Id: <1539894735-14232-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::42b Subject: [Qemu-devel] [PULL 08/48] target-i386 : add coalesced_pio API X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peng Hao Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peng Hao the primary API realization. Signed-off-by: Peng Hao Reviewed-by: Eduardo Habkost Message-Id: <1539795177-21038-3-git-send-email-peng.hao2@zte.com.cn> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++--- include/exec/memory.h | 4 ++-- memory.c | 4 ++-- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index de12f78..4880a05 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -79,6 +79,7 @@ struct KVMState int fd; int vmfd; int coalesced_mmio; + int coalesced_pio; struct kvm_coalesced_mmio_ring *coalesced_mmio_ring; bool coalesced_flush_in_progress; int vcpu_events; @@ -560,6 +561,45 @@ static void kvm_uncoalesce_mmio_region(MemoryListener *listener, } } +static void kvm_coalesce_pio_add(MemoryListener *listener, + MemoryRegionSection *section, + hwaddr start, hwaddr size) +{ + KVMState *s = kvm_state; + + if (s->coalesced_pio) { + struct kvm_coalesced_mmio_zone zone; + + zone.addr = start; + zone.size = size; + zone.pio = 1; + + (void)kvm_vm_ioctl(s, KVM_REGISTER_COALESCED_MMIO, &zone); + } +} + +static void kvm_coalesce_pio_del(MemoryListener *listener, + MemoryRegionSection *section, + hwaddr start, hwaddr size) +{ + KVMState *s = kvm_state; + + if (s->coalesced_pio) { + struct kvm_coalesced_mmio_zone zone; + + zone.addr = start; + zone.size = size; + zone.pio = 1; + + (void)kvm_vm_ioctl(s, KVM_UNREGISTER_COALESCED_MMIO, &zone); + } +} + +static MemoryListener kvm_coalesced_pio_listener = { + .coalesced_io_add = kvm_coalesce_pio_add, + .coalesced_io_del = kvm_coalesce_pio_del, +}; + int kvm_check_extension(KVMState *s, unsigned int extension) { int ret; @@ -1616,6 +1656,8 @@ static int kvm_init(MachineState *ms) } s->coalesced_mmio = kvm_check_extension(s, KVM_CAP_COALESCED_MMIO); + s->coalesced_pio = s->coalesced_mmio && + kvm_check_extension(s, KVM_CAP_COALESCED_PIO); #ifdef KVM_CAP_VCPU_EVENTS s->vcpu_events = kvm_check_extension(s, KVM_CAP_VCPU_EVENTS); @@ -1686,13 +1728,15 @@ static int kvm_init(MachineState *ms) s->memory_listener.listener.eventfd_add = kvm_mem_ioeventfd_add; s->memory_listener.listener.eventfd_del = kvm_mem_ioeventfd_del; } - s->memory_listener.listener.coalesced_mmio_add = kvm_coalesce_mmio_region; - s->memory_listener.listener.coalesced_mmio_del = kvm_uncoalesce_mmio_region; + s->memory_listener.listener.coalesced_io_add = kvm_coalesce_mmio_region; + s->memory_listener.listener.coalesced_io_del = kvm_uncoalesce_mmio_region; kvm_memory_listener_register(s, &s->memory_listener, &address_space_memory, 0); memory_listener_register(&kvm_io_listener, &address_space_io); + memory_listener_register(&kvm_coalesced_pio_listener, + &address_space_io); s->many_ioeventfds = kvm_check_many_ioeventfds(); @@ -1778,7 +1822,13 @@ void kvm_flush_coalesced_mmio_buffer(void) ent = &ring->coalesced_mmio[ring->first]; - cpu_physical_memory_write(ent->phys_addr, ent->data, ent->len); + if (ent->pio == 1) { + address_space_rw(&address_space_io, ent->phys_addr, + MEMTXATTRS_UNSPECIFIED, ent->data, + ent->len, true); + } else { + cpu_physical_memory_write(ent->phys_addr, ent->data, ent->len); + } smp_wmb(); ring->first = (ring->first + 1) % KVM_COALESCED_MMIO_MAX; } diff --git a/include/exec/memory.h b/include/exec/memory.h index 3a427aa..667466b 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -419,9 +419,9 @@ struct MemoryListener { bool match_data, uint64_t data, EventNotifier *e); void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section, bool match_data, uint64_t data, EventNotifier *e); - void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section, + void (*coalesced_io_add)(MemoryListener *listener, MemoryRegionSection *section, hwaddr addr, hwaddr len); - void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section, + void (*coalesced_io_del)(MemoryListener *listener, MemoryRegionSection *section, hwaddr addr, hwaddr len); /* Lower = earlier (during add), later (during del) */ unsigned priority; diff --git a/memory.c b/memory.c index d852f11..51204aa 100644 --- a/memory.c +++ b/memory.c @@ -2129,7 +2129,7 @@ static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpa .size = fr->addr.size, }; - MEMORY_LISTENER_CALL(as, coalesced_mmio_del, Reverse, §ion, + MEMORY_LISTENER_CALL(as, coalesced_io_del, Reverse, §ion, int128_get64(fr->addr.start), int128_get64(fr->addr.size)); QTAILQ_FOREACH(cmr, &mr->coalesced, link) { @@ -2140,7 +2140,7 @@ static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpa continue; } tmp = addrrange_intersection(tmp, fr->addr); - MEMORY_LISTENER_CALL(as, coalesced_mmio_add, Forward, §ion, + MEMORY_LISTENER_CALL(as, coalesced_io_add, Forward, §ion, int128_get64(tmp.start), int128_get64(tmp.size)); } From patchwork Thu Oct 18 20:31:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986313 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="X+rZceLD"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhh867yPz9s5c for ; Fri, 19 Oct 2018 08:17:12 +1100 (AEDT) Received: from localhost ([::1]:44750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFfK-0003D4-DU for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:17:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyF-0007H4-D8 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEy9-0006E7-Gp for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:37 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:33367) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy8-00069r-OY for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:33 -0400 Received: by mail-wr1-x42e.google.com with SMTP id e4-v6so35109887wrs.0 for ; Thu, 18 Oct 2018 13:32:28 -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=seeNlGHlQ89oIKFlSzm1J8VJgVA7puMCRqVvyGllTcg=; b=X+rZceLDkuJNBK2BLOliOCu6H1jv4N+nykM6OL+T90SpB3Y9X5GWAELw83hF4tLqJq wF/vqUENXhVjIoWm73AaOzSXsSXujvBPgFHq0OwZLmgs1D1FjrdH/ZHOfsvMp0PpTjw+ lUM0nmlKJPm3iioGZxmVurUCe42aDgiDpqWz7LdfgkerPMXLJbLdI+Uwynl/CRQcdNmm f2p13Pz3X+klA892MubDz+q1lYeBan+7I0YxvL/5fwXAH8YXxmow2c+xpd9iQlNdejC8 97lk0zIZGbC25ELf0qUUsga3BkSwpWskpcj8Lj55OL5tU6g1U+D+pIhQbKUAH2LmZ7V8 /9Dg== 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=seeNlGHlQ89oIKFlSzm1J8VJgVA7puMCRqVvyGllTcg=; b=sATRvZEKh2wlMfKpN8lhbfj1AHbu5XKwEMLYKpifvMx7ZjKPUZ3iA3dAVDA41k9DQj 0/D+3GGWzehUQmP1XFIuvIC43dw0SKPn24mG0eJTFjYkF24b3o/kI1gJ+4HLf0ASjGTs ozrHCFahiv+WSnDfIB0b7Za8NKo8oKXc2NdKomJA+hNLfBLqs4Awo74t8E8pJVhOqBoJ GypxuxHPwf7aftp7HUlVRUNk8v0LizBUGdxb9JjqH2urAMrTk99ostOoxUiPuRfdUsQ7 kdRrEUehA2gagpHlLFkr/ZyZLNdZkG9mONyB8LdjL6/paLDtoMZX7TtyQjYlvKZ0oVEc /Hmw== X-Gm-Message-State: ABuFfohj8+M0C11wa4/26ub1/GEM1pjC3qVWpv3APn7VyFu+V8OI6iVy 83jOv023jMX2yM88KFERiDyxZ78Z X-Google-Smtp-Source: ACcGV62oYlvebKEpwY7WBX+MUKFCXolzwx6YKjeEUvthDqI26pyKbxtbsK5PDdpxxx745K60LHVxWA== X-Received: by 2002:adf:cd0c:: with SMTP id w12-v6mr31736657wrm.67.1539894747561; Thu, 18 Oct 2018 13:32:27 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:36 +0200 Message-Id: <1539894735-14232-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::42e Subject: [Qemu-devel] [PULL 09/48] target-i386: add rtc 0x70 port as coalesced_pio X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peng Hao Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peng Hao Signed-off-by: Peng Hao Message-Id: <1539890353-30273-1-git-send-email-peng.hao2@zte.com.cn> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index acee47d..e4e4de8 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -34,6 +34,7 @@ #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-events-misc.h" #include "qapi/visitor.h" +#include "exec/address-spaces.h" #ifdef TARGET_I386 #include "hw/i386/apic.h" @@ -70,6 +71,7 @@ typedef struct RTCState { ISADevice parent_obj; MemoryRegion io; + MemoryRegion coalesced_io; uint8_t cmos_data[128]; uint8_t cmos_index; int32_t base_year; @@ -990,6 +992,13 @@ static void rtc_realizefn(DeviceState *dev, Error **errp) memory_region_init_io(&s->io, OBJECT(s), &cmos_ops, s, "rtc", 2); isa_register_ioport(isadev, &s->io, base); + /* register rtc 0x70 port for coalesced_pio */ + memory_region_set_flush_coalesced(&s->io); + memory_region_init_io(&s->coalesced_io, OBJECT(s), &cmos_ops, + s, "rtc-index", 1); + memory_region_add_subregion(&s->io, 0, &s->coalesced_io); + memory_region_add_coalescing(&s->coalesced_io, 0, 1); + qdev_set_legacy_instance_id(dev, base, 3); qemu_register_reset(rtc_reset, s); From patchwork Thu Oct 18 20:31:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="auq272Qd"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhBd5yqkz9s8F for ; Fri, 19 Oct 2018 07:55:05 +1100 (AEDT) Received: from localhost ([::1]:44620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFJv-0001BI-EM for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:55:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JL-Ck for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyF-0006Ji-GW for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:43225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy9-0006AR-Gz for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:37 -0400 Received: by mail-wr1-x434.google.com with SMTP id n1-v6so35101387wrt.10 for ; Thu, 18 Oct 2018 13:32:29 -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=R1wPodUAtuSo7rRynHn1i1L3sydhJMz9w9Y7a4yez5w=; b=auq272Qd/5i6MHuaxDriD6Y4hu+N/5XAutOU0NCQ3ZKjW14p1ME71cUGNRaIcZYliA Rhud13TbUENQKGEYp/ycPZWx2kWzLJAt6lN9GaUu7bF1GRv46vKQHHaJyd7s/96hlAP1 69A6/UANf8ITmQDT/vYpK3TuJFThBxr+rsQecA8mX36bi5t/2Aob9JRI42zzIhgiGVdL 0yXxBIPip8ikXPsOdiXgwzT0agTxCv11aD+VwwVyb9PVuUUxkRHWzInX2n/Oyvn4AOKn hj1jbJCdXOKbh8RNmzlJGvsVhEMznyx8JeAQDYrblsZAK9/6X3j8hN0GaX0liuiQ3yhW b+dg== 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=R1wPodUAtuSo7rRynHn1i1L3sydhJMz9w9Y7a4yez5w=; b=h7oIdF8kTBnUPIAvIXYwWpssOKBblzDY4P7vEEj7H6ppu/JP9ELg3I7lrAIPsXbJpJ lxQjGf8ppmDNobLuNPkxqtJii/ISPWwXvT1Sx/P0NaCGEK8n+fJ9SnpKX8b4+EO2ANvS 4RRSQlS3ayAfUyS99rJAapld2s23FyDo6Qq4zVtrXEkf05Z+XSHjdwzwc/pvyR9jRaqc Yjt1fM9SyhRu4o0jGLlJZEKSKbGRVwMXqKJAacqryBUBdB3Feok4B+FHiJ6WS5iwG1Cj tDqA8GOyHU6QAI6QhH986YjjBLIO/TRu+14xpW4+SngojCSQUrcvIGKru3lzTUNbQcYe vj8A== X-Gm-Message-State: ABuFfogQgg9+Gxqq/jkn2Cw/7aC0oEyT0bNHTJi2gY2Zynct9XK/fEzD U0lqfijIMH+uplngbzQrw612IEKI X-Google-Smtp-Source: ACcGV61OfpNO0PJSarGuuBBcK/phLw2zjg/On/Ob2hm3qZSgdq3BP6/n6aGNVLbQv8nXXCqX7wUPgw== X-Received: by 2002:adf:8547:: with SMTP id 65-v6mr30680386wrh.69.1539894748588; Thu, 18 Oct 2018 13:32:28 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:37 +0200 Message-Id: <1539894735-14232-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::434 Subject: [Qemu-devel] [PULL 10/48] target-i386: add i440fx 0xcf8 port as coalesced_pio X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peng Hao Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peng Hao Signed-off-by: Peng Hao Message-Id: <1539795177-21038-5-git-send-email-peng.hao2@zte.com.cn> Signed-off-by: Paolo Bonzini --- hw/pci-host/piix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 0e60834..da73743 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -327,6 +327,10 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp) sysbus_add_io(sbd, 0xcfc, &s->data_mem); sysbus_init_ioports(sbd, 0xcfc, 4); + + /* register i440fx 0xcf8 port as coalesced pio */ + memory_region_set_flush_coalesced(&s->data_mem); + memory_region_add_coalescing(&s->conf_mem, 0, 4); } static void i440fx_realize(PCIDevice *dev, Error **errp) From patchwork Thu Oct 18 20:31:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VbpsqphD"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhBP43xbz9s8F for ; Fri, 19 Oct 2018 07:54:53 +1100 (AEDT) Received: from localhost ([::1]:44619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFJj-00013w-2G for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:54:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JO-D1 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyF-0006JY-Fc for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:37729) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEy9-0006B3-Da for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:37 -0400 Received: by mail-wr1-x434.google.com with SMTP id q1-v6so2207592wrs.4 for ; Thu, 18 Oct 2018 13:32:30 -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=pINoOpLkaRdSD1UDufQR17x7BHKdiP7FLTmKArz1MeY=; b=VbpsqphDDEHg9lqnbBz3oplA4h+Fyqgb7Cib1Lml0vnU55/2kaXKz+WHDV0DEdYY3t p20/DGUOwnf+D51q8D9JYTyeZbQxMcnQcFzGJn0fNGftAruQsx1KHrxsdvwpI7QSDasb +S3YIvdfPuZVkSEIoRGcNzz7kTb5A2221ZdZCcLBGLwD/W28lZMsGuPwmBSpHLBeHh7r 3Ys/mn5KmDKr9JU2j6VEA8S1eqIwTDJKNaPR9gXue7NI+5oBPPcqEEaRIiP1JoMy184d Dx0J+rsGGe1kCYpbRqaeUqv+GiI12qeJKsO5aWW/qZbwdS9jhWiFPQKUTk7du7A0ojRE RdrQ== 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=pINoOpLkaRdSD1UDufQR17x7BHKdiP7FLTmKArz1MeY=; b=VhRD/fqcEveZkVrafQYwwqjCJE2yqwHmH+jSv8aQFWNiec57vJelFTucLozCmJ9NP0 1jEXwaAV57LBEZEVRCnRMGkP0tMdvrKTjZh0AvFYvdNEpIKvYV7qpPWsnqJYlUbnLh20 eRCNDq7Lre+zJuk/kt0Rav4myiWpc6l5uRgihIIkVuFwCxS9I/rHn4XvJ9rbiqAzVbxt imnrAFgY0oOzcSQhbHSPmccleYK772BFsXWfhVa24NW+hFVZbV0GhqwAVArS5sBfXfJW 9WEy7WmeCJjSJB8bRdckbFa8+CPUVZN72zz2EH92EViNBm/F5cJ0FaQ1ad3pRqq7mdNP aIYA== X-Gm-Message-State: ABuFfogyKE58HliUrrG1VMKsv+DjlFFn8QnboJRAioulkV6/Abn68L/2 nT8orMZdsgW9FK9gvHC1TbkO92mM X-Google-Smtp-Source: ACcGV63RUy6aL9pTugAPqF3GtUa5q96Ub0/50HOpMzFkN5Klyz8hRiYEbtr6d/s8VFLD1hvImpSrcg== X-Received: by 2002:adf:e904:: with SMTP id f4-v6mr9334954wrm.258.1539894749463; Thu, 18 Oct 2018 13:32:29 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:38 +0200 Message-Id: <1539894735-14232-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::434 Subject: [Qemu-devel] [PULL 11/48] target-i386: add q35 0xcf8 port as coalesced_pio X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peng Hao Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peng Hao Signed-off-by: Peng Hao Message-Id: <1539795177-21038-6-git-send-email-peng.hao2@zte.com.cn> Signed-off-by: Paolo Bonzini --- hw/pci-host/q35.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 02f9576..8ce1e09 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -51,6 +51,10 @@ static void q35_host_realize(DeviceState *dev, Error **errp) sysbus_add_io(sbd, MCH_HOST_BRIDGE_CONFIG_DATA, &pci->data_mem); sysbus_init_ioports(sbd, MCH_HOST_BRIDGE_CONFIG_DATA, 4); + /* register q35 0xcf8 port as coalesced pio */ + memory_region_set_flush_coalesced(&pci->data_mem); + memory_region_add_coalescing(&pci->conf_mem, 0, 4); + pci->bus = pci_root_bus_new(DEVICE(s), "pcie.0", s->mch.pci_address_space, s->mch.address_space_io, From patchwork Thu Oct 18 20:31:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986278 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="smQrjbbT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhFh2J68z9s8F for ; Fri, 19 Oct 2018 07:57:44 +1100 (AEDT) Received: from localhost ([::1]:44637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFMT-0003QC-Ta for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:57:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JN-D1 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyF-0006Jv-J4 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36774) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyD-0006Bd-Pr for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:39 -0400 Received: by mail-wr1-x443.google.com with SMTP id y16so35119741wrw.3 for ; Thu, 18 Oct 2018 13:32:31 -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=Vt+OJPwFqvspIxKuU10Cf3S4FyhCyr4x2tTw6frY3to=; b=smQrjbbTDp2azVfoSheJxPrN/YaZFEuq968y97tHygndvrdO/NOaQEchRhcoAe48xi L0TlMFt3gWcC9svb91Y9TEDp3WLNwmOIeTnD/A5SlbfjmBTA7ynKOd2u483sDb4kVQZc 7QRgVmPUQPMkrbXnNGoszPlL3163VRBJasyCc0vYNcPyNgR9xp8qC59bbLoKbVYBjIhi /dr1q9EMCGef2u5j6T272KEzPSBZwAJo/HHSvCNhffTBolpfsYjaP1j0G3DlzB5c+j1b qUUPuYr0OU6b6GbcF+us3YGNftqfKItoL63jCVY2bA2Pu4Klj1x+sswsxuAQNc7Tr1J5 /7Dw== 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=Vt+OJPwFqvspIxKuU10Cf3S4FyhCyr4x2tTw6frY3to=; b=aUMCb+BljdLirvm7oqZzm6CbGRSw5i/BhQZzqPlCZoBdx6Y4u2jye93oKavyJ9VxO0 a5LnjU5WJhLJ8yB1Pxj08IBcuh2L4Ciwj3k6z+SqgcuQxyhUXf2z1vugJcm1tCAmh5dC 2gb+K1koDpCfzywgVpZFEbfCJW2dYqwhnFkSSE6P/6BbrbXuYAGPwv/598aEnvWLqGgk A3pafDeNWcY9OGEStxQNnURZEbP934BmhxCNTlz7CAchYt0bSShBGLLsH+3SDrwQhv3t cRgWUv3JiazHN4jgmsE0E3nV06JQK5ObDN3tdKV49qVHLg8Y86LcADTCUTJv9J6uKHVj dPQw== X-Gm-Message-State: ABuFfoi+wJneP4Mq8lR9Oy2zjYzU5IBDFt2LHjcTl/PZWX+GK24ropTE Vbgup8rdHb1cYHlXbR/ordrCRviY X-Google-Smtp-Source: ACcGV63XE44hELnwZdrFKOXFaWuR9RLnQy7eU1rMXSyuxKGokWWBKKcT+9M5UIgPpA+2V21sgapBMA== X-Received: by 2002:adf:f00d:: with SMTP id j13-v6mr28174911wro.88.1539894750585; Thu, 18 Oct 2018 13:32:30 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:39 +0200 Message-Id: <1539894735-14232-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::443 Subject: [Qemu-devel] [PULL 12/48] replay: don't process events at virtual clock checkpoint X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Dovgalyuk Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Pavel Dovgalyuk As QEMU becomes more multi-threaded and non-synchronized, checkpoints move from thread to thread. And the event queue that processed at checkpoints should belong to the same thread in both record and replay executions. This patch disables asynchronous event processing at virtual clock checkpoint, because it may be invoked in different threads at record and replay. This patch is temporary fix until the checkpoints are completely refactored. Signed-off-by: Pavel Dovgalyuk Message-Id: <20181018063345.7433.11678.stgit@pasha-VirtualBox> Signed-off-by: Paolo Bonzini --- replay/replay-events.c | 1 + replay/replay.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/replay/replay-events.c b/replay/replay-events.c index 0964a82..d9a2d49 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -190,6 +190,7 @@ void replay_save_events(int checkpoint) { g_assert(replay_mutex_locked()); g_assert(checkpoint != CHECKPOINT_CLOCK_WARP_START); + g_assert(checkpoint != CHECKPOINT_CLOCK_VIRTUAL); while (!QTAILQ_EMPTY(&events_list)) { Event *event = QTAILQ_FIRST(&events_list); replay_save_event(event, checkpoint); diff --git a/replay/replay.c b/replay/replay.c index 379b51a..8b172b2 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -214,7 +214,14 @@ bool replay_checkpoint(ReplayCheckpoint checkpoint) /* This checkpoint belongs to several threads. Processing events from different threads is non-deterministic */ - if (checkpoint != CHECKPOINT_CLOCK_WARP_START) { + if (checkpoint != CHECKPOINT_CLOCK_WARP_START + /* FIXME: this is temporary fix, other checkpoints + may also be invoked from the different threads someday. + Asynchronous event processing should be refactored + to create additional replay event kind which is + nailed to the one of the threads and which processes + the event queue. */ + && checkpoint != CHECKPOINT_CLOCK_VIRTUAL) { replay_save_events(checkpoint); } res = true; From patchwork Thu Oct 18 20:31:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986289 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EmxbUOy6"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhK00zYzz9s8F for ; Fri, 19 Oct 2018 08:00:36 +1100 (AEDT) Received: from localhost ([::1]:44653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFPF-0006I2-MO for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:00:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JU-FT for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyH-0006LL-BB for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:37267) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyG-0006CF-9J for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:40 -0400 Received: by mail-wm1-x342.google.com with SMTP id 185-v6so1627868wmt.2 for ; Thu, 18 Oct 2018 13:32:32 -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=7eKnW8x7B3Pty89fU4WQVfl0w5gMORVZdNDBX6mZF8c=; b=EmxbUOy6Ae4dNFdRUhOSQMirztc5MtPYxYU7D1lNmBzO9adKVBf66VGynk4v90YpRS h/kr4+1H0Wae5M6cO7mlxLn4CMqTboN73QHRYOBzWdOQdedvJnwekKxYAb3lLELSoxr/ hDMk+oghGiWM/ZStofjbJHJD10XCw0LDqwqBL4oThDgFn7+Pi/xunXdbJz8nlCgTPbIL ip93U/7IKU1rxp7Ey5JdS70cxF/ABCexE6H/8mZVVvn6uo0VYEKYfeVl0/TTgAis5q+f zF0XZy+554NI5RInt8FI4HHOdnf89pns+QzGJ1j3uLecrtdOE0wpX/tTpOyxjENRJkNB v9PA== 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=7eKnW8x7B3Pty89fU4WQVfl0w5gMORVZdNDBX6mZF8c=; b=HVOddho/ciq7uE+3qYzfsWPS5QciJjTffo9ztWcmBpaStBzp+OCfbX7q/rtz1W6cEb UhwITwpsejMJb7xifCcQY9qXfX3ZlAfrtmjytrhxarVGEleac70/4+c40oFy9oAnIj0f mWnpZN/iEciAtMORHNRU4Cp0Rg0rUdevPuVfZ7Y9Y7q2XxN16Q8ypmbMJhpObLYpihSO PdfCxA5EJJgRmL3JXGfUmwiQemuJ6PUaN9g9PzQ4RsHTMNlRCXtkgppcGGuZUc/CmGSx 48RKF+JKhKkJNh6AokVJ0OJ7TgLIL7Q6lo2ulqnTUiVhi7BszAJvOhSsqhF5fAS0PTRi cmkQ== X-Gm-Message-State: ABuFfoilK7XctDxMMoaXAtTUrXJMtO5NQwYFMw5ulZjGobvA0KNwIsTa k8hsB4Dlex92WDqDAITBhBQ6BCBG X-Google-Smtp-Source: ACcGV61WsopMl3bA2++nLqBzELQQblVpoYDdM9sKuDGIjewiEJCIs4WXkM64CYUzcRmDALOH+bkzwg== X-Received: by 2002:a1c:c90f:: with SMTP id f15-v6mr1887104wmb.48.1539894751496; Thu, 18 Oct 2018 13:32:31 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:40 +0200 Message-Id: <1539894735-14232-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::342 Subject: [Qemu-devel] [PULL 13/48] i386/kvm: add support for Hyper-V IPI send X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov Hyper-V PV IPI support is merged to KVM, enable the feature in Qemu. When enabled, this allows Windows guests to send IPIs to other vCPUs with a single hypercall even when there are >64 vCPUs in the request. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Roman Kagan Message-Id: <20181009130853.6412-3-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/hyperv-proto.h | 1 + target/i386/kvm.c | 14 +++++++++++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c88876d..32ea041 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5564,6 +5564,7 @@ static Property x86_cpu_properties[] = { DEFINE_PROP_BOOL("hv-frequencies", X86CPU, hyperv_frequencies, false), DEFINE_PROP_BOOL("hv-reenlightenment", X86CPU, hyperv_reenlightenment, false), DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false), + DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false), DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 730c06f..caa1544 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1382,6 +1382,7 @@ struct X86CPU { bool hyperv_frequencies; bool hyperv_reenlightenment; bool hyperv_tlbflush; + bool hyperv_ipi; bool check_cpuid; bool enforce_cpuid; bool expose_kvm; diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h index d6d5a79..87f36d1 100644 --- a/target/i386/hyperv-proto.h +++ b/target/i386/hyperv-proto.h @@ -58,6 +58,7 @@ #define HV_APIC_ACCESS_RECOMMENDED (1u << 3) #define HV_SYSTEM_RESET_RECOMMENDED (1u << 4) #define HV_RELAXED_TIMING_RECOMMENDED (1u << 5) +#define HV_CLUSTER_IPI_RECOMMENDED (1u << 10) #define HV_EX_PROCESSOR_MASKS_RECOMMENDED (1u << 11) /* diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 302f420..4e62b5c 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -608,7 +608,8 @@ static bool hyperv_enabled(X86CPU *cpu) cpu->hyperv_synic || cpu->hyperv_stimer || cpu->hyperv_reenlightenment || - cpu->hyperv_tlbflush); + cpu->hyperv_tlbflush || + cpu->hyperv_ipi); } static int kvm_arch_set_tsc_khz(CPUState *cs) @@ -888,6 +889,17 @@ int kvm_arch_init_vcpu(CPUState *cs) c->eax |= HV_REMOTE_TLB_FLUSH_RECOMMENDED; c->eax |= HV_EX_PROCESSOR_MASKS_RECOMMENDED; } + if (cpu->hyperv_ipi) { + if (kvm_check_extension(cs->kvm_state, + KVM_CAP_HYPERV_SEND_IPI) <= 0) { + fprintf(stderr, "Hyper-V IPI send support " + "(requested by 'hv-ipi' cpu flag) " + " is not supported by kernel\n"); + return -ENOSYS; + } + c->eax |= HV_CLUSTER_IPI_RECOMMENDED; + c->eax |= HV_EX_PROCESSOR_MASKS_RECOMMENDED; + } c->ebx = cpu->hyperv_spinlock_attempts; From patchwork Thu Oct 18 20:31:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="avg+w/Z7"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhFr58dVz9s3l for ; Fri, 19 Oct 2018 07:57:52 +1100 (AEDT) Received: from localhost ([::1]:44639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFMc-0003Xq-8A for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:57:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyL-0007Lg-9J for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyH-0006LS-Dt for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:36776) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyG-0006EJ-Cp for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:40 -0400 Received: by mail-wr1-x444.google.com with SMTP id y16so35119845wrw.3 for ; Thu, 18 Oct 2018 13:32:34 -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=0kwDTShtZFVXIAGuDL2ET8GZS1Px0xDhc0A4IOiI/fw=; b=avg+w/Z7kkbsR4DUOhaYn7rVxqSpQgD5yAYjnTmCHOpsTv08SE1v2do6hrPE1Hn29d PDub81OsqA+yEuVAJXP/JoLFGDFqqI/ftdfIdaG+f1xmd6ZZ3i9UN8+FIQddhX4qXLMp PvEKvgeLtJqqoBKmHKMR+fB5ADVN4p3e34Ug3Mvh+3wb/RBhQ3gFBpEF/9VhHdCJ4fNR xuJISHdum4LocwQmwEWPkTwfsbt2sOAEpXRD0OpLLMLJDPs8MSim75PmvRm5FgvgrvX3 JPo+b10BXwuWdtP6khfUwegh6eYpXo1Aq+OK699cnIrTQztzj6/S3E3fbGIf9Y2YqsCe p2zw== 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=0kwDTShtZFVXIAGuDL2ET8GZS1Px0xDhc0A4IOiI/fw=; b=Xa7uS10UwU3HLUEANnLSX3zy0d7bzvOIakt8yQvmNmax1hIj6ObdosWssROlFrE5+L 4Am48RWvL/3oo5+aIF5YUK8WItvlJHNRqsp7seMja8ajFT8+BcYbe6CpE4mdCZh33Jwx YTW0o8Hy537mObmOxycVNoolJyWh6hMOARAj60Q9WjwLGlDUDdF9X/n0FQt1iulmEuGp pObJJJCxiheV1p5JZ20YLt/clZujROfgGpQcemvvZesmUH2z1rONzDzUmULcEPI5clP7 Ez0QAcMn/2zZEE30OFUrwQEkKL5eEsUn1CryiAKXBQvSHqkmFLYwpEC6XGkLDefdufLR yJNw== X-Gm-Message-State: ABuFfohDwZsXjPY4pQ20GQqJZtOToMbKOm0qtpnRFy7t7q+qaBgkP/Yq it0fpQwMmgo1DgSiYs7OhGVktnwZ X-Google-Smtp-Source: ACcGV61kUZjDLL3IAFPYOuMT6A2LD1LPClstaJQT4wQpMtjyrRYqEs1Bspy6AtnkbSr1afnp3gSsyw== X-Received: by 2002:adf:f548:: with SMTP id j8-v6mr32826550wrp.241.1539894752818; Thu, 18 Oct 2018 13:32:32 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:41 +0200 Message-Id: <1539894735-14232-15-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::444 Subject: [Qemu-devel] [PULL 14/48] i386: hvf: Fix register refs if REX is present X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Bolshakov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Bolshakov According to Intel(R)64 and IA-32 Architectures Software Developer's Manual, the following one-byte registers should be fetched when REX prefix is present (sorted by reg encoding index): AL, CL, DL, BL, SPL, BPL, SIL, DIL, R8L - R15L The first 8 are fetched if REX.R is zero, the last 8 if non-zero. The following registers should be fetched for instructions without REX prefix (also sorted by reg encoding index): AL, CL, DL, BL, AH, CH, DH, BH Current emulation code doesn't handle accesses to SPL, BPL, SIL, DIL when REX is present, thefore an instruction 40883e "mov %dil,(%rsi)" is decoded as "mov %bh,(%rsi)". That caused an infinite loop in vp_reset: https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg03293.html Signed-off-by: Roman Bolshakov Message-Id: <20181018134401.44471-1-r.bolshakov@yadro.com> Signed-off-by: Paolo Bonzini --- target/i386/hvf/x86_decode.c | 67 +++++++++++++++++++++++++------------------- target/i386/hvf/x86_decode.h | 6 ++-- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/target/i386/hvf/x86_decode.c b/target/i386/hvf/x86_decode.c index 2d7540f..2e33b69 100644 --- a/target/i386/hvf/x86_decode.c +++ b/target/i386/hvf/x86_decode.c @@ -113,7 +113,8 @@ static void decode_modrm_reg(CPUX86State *env, struct x86_decode *decode, { op->type = X86_VAR_REG; op->reg = decode->modrm.reg; - op->ptr = get_reg_ref(env, op->reg, decode->rex.r, decode->operand_size); + op->ptr = get_reg_ref(env, op->reg, decode->rex.rex, decode->rex.r, + decode->operand_size); } static void decode_rax(CPUX86State *env, struct x86_decode *decode, @@ -121,7 +122,8 @@ static void decode_rax(CPUX86State *env, struct x86_decode *decode, { op->type = X86_VAR_REG; op->reg = R_EAX; - op->ptr = get_reg_ref(env, op->reg, 0, decode->operand_size); + op->ptr = get_reg_ref(env, op->reg, decode->rex.rex, 0, + decode->operand_size); } static inline void decode_immediate(CPUX86State *env, struct x86_decode *decode, @@ -263,16 +265,16 @@ static void decode_incgroup(CPUX86State *env, struct x86_decode *decode) { decode->op[0].type = X86_VAR_REG; decode->op[0].reg = decode->opcode[0] - 0x40; - decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.b, - decode->operand_size); + decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.rex, + decode->rex.b, decode->operand_size); } static void decode_decgroup(CPUX86State *env, struct x86_decode *decode) { decode->op[0].type = X86_VAR_REG; decode->op[0].reg = decode->opcode[0] - 0x48; - decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.b, - decode->operand_size); + decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.rex, + decode->rex.b, decode->operand_size); } static void decode_incgroup2(CPUX86State *env, struct x86_decode *decode) @@ -288,16 +290,16 @@ static void decode_pushgroup(CPUX86State *env, struct x86_decode *decode) { decode->op[0].type = X86_VAR_REG; decode->op[0].reg = decode->opcode[0] - 0x50; - decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.b, - decode->operand_size); + decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.rex, + decode->rex.b, decode->operand_size); } static void decode_popgroup(CPUX86State *env, struct x86_decode *decode) { decode->op[0].type = X86_VAR_REG; decode->op[0].reg = decode->opcode[0] - 0x58; - decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.b, - decode->operand_size); + decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.rex, + decode->rex.b, decode->operand_size); } static void decode_jxx(CPUX86State *env, struct x86_decode *decode) @@ -378,16 +380,16 @@ static void decode_xchgroup(CPUX86State *env, struct x86_decode *decode) { decode->op[0].type = X86_VAR_REG; decode->op[0].reg = decode->opcode[0] - 0x90; - decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.b, - decode->operand_size); + decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.rex, + decode->rex.b, decode->operand_size); } static void decode_movgroup(CPUX86State *env, struct x86_decode *decode) { decode->op[0].type = X86_VAR_REG; decode->op[0].reg = decode->opcode[0] - 0xb8; - decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.b, - decode->operand_size); + decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.rex, + decode->rex.b, decode->operand_size); decode_immediate(env, decode, &decode->op[1], decode->operand_size); } @@ -402,8 +404,8 @@ static void decode_movgroup8(CPUX86State *env, struct x86_decode *decode) { decode->op[0].type = X86_VAR_REG; decode->op[0].reg = decode->opcode[0] - 0xb0; - decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.b, - decode->operand_size); + decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.rex, + decode->rex.b, decode->operand_size); decode_immediate(env, decode, &decode->op[1], decode->operand_size); } @@ -412,7 +414,8 @@ static void decode_rcx(CPUX86State *env, struct x86_decode *decode, { op->type = X86_VAR_REG; op->reg = R_ECX; - op->ptr = get_reg_ref(env, op->reg, decode->rex.b, decode->operand_size); + op->ptr = get_reg_ref(env, op->reg, decode->rex.rex, decode->rex.b, + decode->operand_size); } struct decode_tbl { @@ -639,8 +642,8 @@ static void decode_bswap(CPUX86State *env, struct x86_decode *decode) { decode->op[0].type = X86_VAR_REG; decode->op[0].reg = decode->opcode[1] - 0xc8; - decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.b, - decode->operand_size); + decode->op[0].ptr = get_reg_ref(env, decode->op[0].reg, decode->rex.rex, + decode->rex.b, decode->operand_size); } static void decode_d9_4(CPUX86State *env, struct x86_decode *decode) @@ -1686,7 +1689,8 @@ calc_addr: } } -target_ulong get_reg_ref(CPUX86State *env, int reg, int is_extended, int size) +target_ulong get_reg_ref(CPUX86State *env, int reg, int rex, int is_extended, + int size) { target_ulong ptr = 0; int which = 0; @@ -1698,7 +1702,7 @@ target_ulong get_reg_ref(CPUX86State *env, int reg, int is_extended, int size) switch (size) { case 1: - if (is_extended || reg < 4) { + if (is_extended || reg < 4 || rex) { which = 1; ptr = (target_ulong)&RL(env, reg); } else { @@ -1714,10 +1718,11 @@ target_ulong get_reg_ref(CPUX86State *env, int reg, int is_extended, int size) return ptr; } -target_ulong get_reg_val(CPUX86State *env, int reg, int is_extended, int size) +target_ulong get_reg_val(CPUX86State *env, int reg, int rex, int is_extended, + int size) { target_ulong val = 0; - memcpy(&val, (void *)get_reg_ref(env, reg, is_extended, size), size); + memcpy(&val, (void *)get_reg_ref(env, reg, rex, is_extended, size), size); return val; } @@ -1739,7 +1744,8 @@ static target_ulong get_sib_val(CPUX86State *env, struct x86_decode *decode, if (base_reg == R_ESP || base_reg == R_EBP) { *sel = R_SS; } - base = get_reg_val(env, decode->sib.base, decode->rex.b, addr_size); + base = get_reg_val(env, decode->sib.base, decode->rex.rex, + decode->rex.b, addr_size); } if (decode->rex.x) { @@ -1747,7 +1753,8 @@ static target_ulong get_sib_val(CPUX86State *env, struct x86_decode *decode, } if (index_reg != R_ESP) { - scaled_index = get_reg_val(env, index_reg, decode->rex.x, addr_size) << + scaled_index = get_reg_val(env, index_reg, decode->rex.rex, + decode->rex.x, addr_size) << decode->sib.scale; } return base + scaled_index; @@ -1776,7 +1783,8 @@ void calc_modrm_operand32(CPUX86State *env, struct x86_decode *decode, if (decode->modrm.rm == R_EBP || decode->modrm.rm == R_ESP) { seg = R_SS; } - ptr += get_reg_val(env, decode->modrm.rm, decode->rex.b, addr_size); + ptr += get_reg_val(env, decode->modrm.rm, decode->rex.rex, + decode->rex.b, addr_size); } if (X86_DECODE_CMD_LEA == decode->cmd) { @@ -1805,7 +1813,8 @@ void calc_modrm_operand64(CPUX86State *env, struct x86_decode *decode, } else if (0 == mod && 5 == rm) { ptr = RIP(env) + decode->len + (int32_t) offset; } else { - ptr = get_reg_val(env, src, decode->rex.b, 8) + (int64_t) offset; + ptr = get_reg_val(env, src, decode->rex.rex, decode->rex.b, 8) + + (int64_t) offset; } if (X86_DECODE_CMD_LEA == decode->cmd) { @@ -1822,8 +1831,8 @@ void calc_modrm_operand(CPUX86State *env, struct x86_decode *decode, if (3 == decode->modrm.mod) { op->reg = decode->modrm.reg; op->type = X86_VAR_REG; - op->ptr = get_reg_ref(env, decode->modrm.rm, decode->rex.b, - decode->operand_size); + op->ptr = get_reg_ref(env, decode->modrm.rm, decode->rex.rex, + decode->rex.b, decode->operand_size); return; } diff --git a/target/i386/hvf/x86_decode.h b/target/i386/hvf/x86_decode.h index 5ab6f31..ef4bcab 100644 --- a/target/i386/hvf/x86_decode.h +++ b/target/i386/hvf/x86_decode.h @@ -303,8 +303,10 @@ uint64_t sign(uint64_t val, int size); uint32_t decode_instruction(CPUX86State *env, struct x86_decode *decode); -target_ulong get_reg_ref(CPUX86State *env, int reg, int is_extended, int size); -target_ulong get_reg_val(CPUX86State *env, int reg, int is_extended, int size); +target_ulong get_reg_ref(CPUX86State *env, int reg, int rex, int is_extended, + int size); +target_ulong get_reg_val(CPUX86State *env, int reg, int rex, int is_extended, + int size); void calc_modrm_operand(CPUX86State *env, struct x86_decode *decode, struct x86_decode_op *op); target_ulong decode_linear_addr(CPUX86State *env, struct x86_decode *decode, From patchwork Thu Oct 18 20:31:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GDBzeEkc"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhQH1Hxjz9s5c for ; Fri, 19 Oct 2018 08:05:11 +1100 (AEDT) Received: from localhost ([::1]:44682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFTg-0001ds-QD for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:05:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007Jj-M5 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyI-0006M7-O9 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:53353) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyG-0006FW-QF for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:41 -0400 Received: by mail-wm1-x330.google.com with SMTP id y11-v6so1571355wma.3 for ; Thu, 18 Oct 2018 13:32:35 -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=7HUFIcgz90QHXPT1gTvJKrel7pgUOr2cR4wg3G1xNNs=; b=GDBzeEkctsSMq82uJQ81fa7qV4ZRSta7vQjwv5DYS0YdOO/OeQRV9UDQcPkz0R0J7L nSOwUBBOR4m1HYwvjL/N79sRuUXVD7TjcFBFGWaaOTDBezpdvZSpav5aQEfn56EZtcj+ K4HPNkB71CN49MVwVxTinUpijt1zGpz+mXUlLengWxAo3rozwuMOd/zmKeMTNLi/ulBA eCJ1EiPTQjbiUBq1y5ZP1cZqWyP6BBJ5AqHk7/KYkYnchwX8jGHYFge+7yp4lMgWhiNY GA6JI3Y/RvS3ELqWSDD0YUEV8/H6JJzI5YGlZCxzWYMbAR8WsUhtYr3vSpHGUf24MzU0 4M1g== 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=7HUFIcgz90QHXPT1gTvJKrel7pgUOr2cR4wg3G1xNNs=; b=oGY1+wYKAKha+RYekum4i4dnshoPfcdytGO8RqGWQtODuF/k5pLhgCLckkV8zOOaeF BWAEtciiWAIvDADRpG2P1oNIvbjLWHxDSdgos9+xMT8ajQyP5H5ZDDujFwPiGcC0/DbN /mFzVzYgGySuSkbYvUrALPYwFc/YVxyR1TjiSWdnG2X3q1pLwAqhiDHEzEZfjzoyvdQa HUU7xUc01cIjgFRlqROJCQup8YVsq4eJB/ajD6jeHpm+JJ6bKoN+fZaVj2EoDXpapKAI YyKCzhmZy8krnu8nglPPz3FKa2c88iisyErsix6zK7IelYi/HBIiuRlvSehz2ra9Tp4U yDGA== X-Gm-Message-State: ABuFfogzKHD7y8CYRULWHpEFqh4rwZV3ZII3lOZUin02MewAad6Nihn8 zdhlLalguLOePXnhhD+8WitWh8YZ X-Google-Smtp-Source: ACcGV62n40fkKAYN8v+56up/0AsqcaatnbVpzLFi2IjaioaI0o+9y/wXlEidm+EY/KJ7U2g5dlo4VA== X-Received: by 2002:a1c:8154:: with SMTP id c81-v6mr1825666wmd.140.1539894754375; Thu, 18 Oct 2018 13:32:34 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:42 +0200 Message-Id: <1539894735-14232-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::330 Subject: [Qemu-devel] [PULL 15/48] i386: hvf: Remove hvf_disabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Bolshakov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Bolshakov accel_init_machine sets *(acc->allowed) to true if acc->init_machine(ms) succeeds. There's no need to have both hvf_allowed and hvf_disabled. Signed-off-by: Roman Bolshakov Message-Id: <20181018143051.48508-1-r.bolshakov@yadro.com> Signed-off-by: Paolo Bonzini --- include/sysemu/hvf.h | 4 ++-- target/i386/hvf/hvf.c | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/include/sysemu/hvf.h b/include/sysemu/hvf.h index 2411188..aaa51d2 100644 --- a/include/sysemu/hvf.h +++ b/include/sysemu/hvf.h @@ -17,7 +17,7 @@ #include "exec/memory.h" #include "sysemu/accel.h" -extern int hvf_disabled; +extern bool hvf_allowed; #ifdef CONFIG_HVF #include #include @@ -26,7 +26,7 @@ extern int hvf_disabled; #include "hw/hw.h" uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx, int reg); -#define hvf_enabled() !hvf_disabled +#define hvf_enabled() (hvf_allowed) #else #define hvf_enabled() 0 #define hvf_get_supported_cpuid(func, idx, reg) 0 diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 9f52bc4..e193022 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -73,7 +73,6 @@ #include "target/i386/cpu.h" HVFState *hvf_state; -int hvf_disabled = 1; static void assert_hvf_ok(hv_return_t ret) { @@ -604,11 +603,6 @@ int hvf_init_vcpu(CPUState *cpu) return 0; } -void hvf_disable(int shouldDisable) -{ - hvf_disabled = shouldDisable; -} - static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idtvec_info) { X86CPU *x86_cpu = X86_CPU(cpu); @@ -934,7 +928,7 @@ int hvf_vcpu_exec(CPUState *cpu) return ret; } -static bool hvf_allowed; +bool hvf_allowed; static int hvf_accel_init(MachineState *ms) { @@ -942,7 +936,6 @@ static int hvf_accel_init(MachineState *ms) hv_return_t ret; HVFState *s; - hvf_disable(0); ret = hv_vm_create(HV_VM_DEFAULT); assert_hvf_ok(ret); From patchwork Thu Oct 18 20:31:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986296 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uZkq3S9t"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhSj1l7Nz9s5c for ; Fri, 19 Oct 2018 08:07:15 +1100 (AEDT) Received: from localhost ([::1]:44694 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFVg-0003Jl-7H for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:07:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JZ-Fy for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyG-0006Kc-GH for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:38557) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyG-0006G0-6f for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:40 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 193-v6so1614390wme.3 for ; Thu, 18 Oct 2018 13:32:36 -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=ijPp4zzTtPgGNBWA+gMwRzk0RCVhx46orRCV9A5iyEw=; b=uZkq3S9tA2X4HlClAPpkqkXKUXiMl0QuQycjmhcu164T5j8rUI746AnOlBKlZwFXAF XL46q2kxr/mKqyE6m+PpN9mjt5IHgTDy/BSDV9oEeEVc/8wKPY5TD/WtJnQ5ySFZ9Abv 3oi5ZFBLT2yMQbOiJE+el6yEN0y/xAjgfM8EruFQAGvbee9LvsXtDnzJP/opLHrCpym2 o5gviRrZIjKy0iHOM8qSxKh9pEcs+0q4aU5gEa72P34vQi3k85iG/UTf3RCfjWmVGG5U eXPhPhLn4mGJenn4KhMkOkSCrQW29giqtTzMiUm3HLbbUhfwy16nbbytg9q4R20TG5dt JZQA== 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=ijPp4zzTtPgGNBWA+gMwRzk0RCVhx46orRCV9A5iyEw=; b=P1zQc9b0BV2RP7djNqOU+HR4FBDtKlA3zQOTTosC8zX5wRaGk4k694NvraxYSY68w3 A90rt0UVORqfhsUxfVmOQbGFCjf4ZSyjOVVZF4HGXbREBB1FSddFaNhXiTxy78iRaPSJ AYMkylgTct4Vs7J1OXHduT37mICya+xX/p/RXR9VxKzmaygzdahbdpG/hcQAzaH2x9uD pAluex+iMW9C5DocLhf9izSuJ8WdowLBTnEHwKAKHJ7MLyh2ubbLvY//P3Bafts+zIMd 82WEfxcomHrCgQWDUHNiYnst8q+UZfBmqqPL5PVL4Oq3td6mhI/rRK6R47apzKtw3u/q 0dqQ== X-Gm-Message-State: ABuFfojhlEem4sHOaFzOOArkkziYqqEkHlOJNQeBF+Uoih6oc5Gto0cM XHIR37oQRTWVlz3pOC1Lt+mOXyLs X-Google-Smtp-Source: ACcGV60XQJgnolVg3O4ivZAo4RjfCo8PLbnvkMcYrms2oSf/TZdaakMaAEM4THrI+5BcyR9+q/E0/w== X-Received: by 2002:a1c:8085:: with SMTP id b127-v6mr1878312wmd.146.1539894755384; Thu, 18 Oct 2018 13:32:35 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:43 +0200 Message-Id: <1539894735-14232-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::32c Subject: [Qemu-devel] [PULL 16/48] vl: improve/fix documentation related to RTC function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Artem Pisarenko Documentation describing -rtc option updated to better match current implementation and highlight some important specifics. Signed-off-by: Artem Pisarenko Message-Id: <1b245c6c0803d4bf11dcbf9eb32f34af8c2bd0b4.1539846575.git.artem.k.pisarenko@gmail.com> Signed-off-by: Paolo Bonzini --- qemu-options.hx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index f139459..829ed81 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3458,25 +3458,29 @@ HXCOMM Silently ignored for compatibility DEF("clock", HAS_ARG, QEMU_OPTION_clock, "", QEMU_ARCH_ALL) DEF("rtc", HAS_ARG, QEMU_OPTION_rtc, \ - "-rtc [base=utc|localtime|date][,clock=host|rt|vm][,driftfix=none|slew]\n" \ + "-rtc [base=utc|localtime|][,clock=host|rt|vm][,driftfix=none|slew]\n" \ " set the RTC base and clock, enable drift fix for clock ticks (x86 only)\n", QEMU_ARCH_ALL) STEXI -@item -rtc [base=utc|localtime|@var{date}][,clock=host|vm][,driftfix=none|slew] +@item -rtc [base=utc|localtime|@var{datetime}][,clock=host|rt|vm][,driftfix=none|slew] @findex -rtc Specify @option{base} as @code{utc} or @code{localtime} to let the RTC start at the current UTC or local time, respectively. @code{localtime} is required for correct date in -MS-DOS or Windows. To start at a specific point in time, provide @var{date} in the +MS-DOS or Windows. To start at a specific point in time, provide @var{datetime} in the format @code{2006-06-17T16:01:21} or @code{2006-06-17}. The default base is UTC. By default the RTC is driven by the host system time. This allows using of the RTC as accurate reference clock inside the guest, specifically if the host time is smoothly following an accurate external reference clock, e.g. via NTP. If you want to isolate the guest time from the host, you can set @option{clock} -to @code{rt} instead. To even prevent it from progressing during suspension, -you can set it to @code{vm}. +to @code{rt} instead, which provides a host monotonic clock if host support it. +To even prevent the RTC from progressing during suspension, you can set @option{clock} +to @code{vm} (virtual clock). @samp{clock=vm} is recommended especially in +icount mode in order to preserve determinism; however, note that in icount mode +the speed of the virtual clock is variable and can in general differ from the +host clock. Enable @option{driftfix} (i386 targets only) if you experience time drift problems, specifically with Windows' ACPI HAL. This option will try to figure out how From patchwork Thu Oct 18 20:31:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="V74y5okf"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhLP4SfKz9s8F for ; Fri, 19 Oct 2018 08:01:47 +1100 (AEDT) Received: from localhost ([::1]:44664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFQP-0007A3-8n for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:01:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JX-FE for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyG-0006Kp-RC for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:33430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyG-0006GZ-7Q for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:40 -0400 Received: by mail-wm1-x335.google.com with SMTP id y140-v6so2640969wmd.0 for ; Thu, 18 Oct 2018 13:32:37 -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=PL14QHgu4wUm3jVRt3OniFqE50Ah2xyJTud4OSLrkBE=; b=V74y5okfQw/feRs25ZFB8a+ybemGHr7W+POQGvSUhczQllr14HVevCIIgZ/t5Nn5sN PIXPp+f0nZXCsJq0XKd6qm0sE/e2g8Czy7NNi7BXXM+yuJmXlXlc+lWVcwiV/KwfbVT8 fg4GHh96dsYet6O7gcT8E654L0+BOuhubRzSUogPOFwKsx724aPv7wniidPOVnPVi/b+ NWTS8wO53NPuPYTp/XSPHR7sPBv5pZx+mQ9us+rAoqNMEExxSTnys+2+P130wjgXviIP YmIl2TZtCutaiAQw/YXFT5bj/+/ZmLsqmnOZxSMrM55Im9+iVBBTukZigD624TMyujye EWkg== 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=PL14QHgu4wUm3jVRt3OniFqE50Ah2xyJTud4OSLrkBE=; b=ciB4pASSusTh5xaSbWpQDH7jr6MYuig5EpiJ0PGc2QWTeOHadsUPpPHbkrCzv75rN8 m/KHIM6EVry/g9jY2q1x2ogVKGDCH+a23DtlkIodF0ZL5hoFCwm8JYIS2J/Imwd95yW/ 0SWv9TGmbW41m4FG0pMYRCUk4prMaSiU5/wlCFVdymmtFAJo5v0AoSEfLR7nRM5ZrSdo BBOvQ6RyhhBUB79KeBkmo/6A6YFaGQG8iIiFbauEoTadU0JRxUrmXIOxtwhrJfbHwe3E ZB77WWDoUUjQ8+djAgjCN22fV9iecpKIMAYfwWSXv8i0mffNkIIWGYcvcXwkCZfiw0p8 JfFA== X-Gm-Message-State: ABuFfoiKeqZ0DjZRO4CtK4anALCjyr1670sjUaoMDVSh3lh/8PzchwjB ZfhzKLeg+l8wF/tF3jNgMiGFdnUd X-Google-Smtp-Source: ACcGV60Nhios1cdctUaT6wCfER0cz0wSwtdkq2sBKrZ1uB8ZIawQ48ldIcp4+E98hVIVNcfh9jnslQ== X-Received: by 2002:a1c:700b:: with SMTP id l11-v6mr1773820wmc.81.1539894756343; Thu, 18 Oct 2018 13:32:36 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:44 +0200 Message-Id: <1539894735-14232-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::335 Subject: [Qemu-devel] [PULL 17/48] vl: refactor -rtc option references X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Artem Pisarenko Improve code readability and prepare for fixing bug #1797033 Signed-off-by: Artem Pisarenko Message-Id: <9330a48899f997431a34460014886d118a7c0960.1539846575.git.artem.k.pisarenko@gmail.com> Signed-off-by: Paolo Bonzini --- vl.c | 84 +++++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/vl.c b/vl.c index 4e25c78..d15e086 100644 --- a/vl.c +++ b/vl.c @@ -147,8 +147,13 @@ bool enable_cpu_pm = false; int nb_nics; NICInfo nd_table[MAX_NICS]; int autostart; -static int rtc_utc = 1; -static int rtc_date_offset = -1; /* -1 means no change */ +static enum { + RTC_BASE_UTC, + RTC_BASE_LOCALTIME, + RTC_BASE_DATETIME, +} rtc_base_type = RTC_BASE_UTC; +static int rtc_host_datetime_offset = -1; /* valid only for host rtc_clock and + rtc_base_type=RTC_BASE_DATETIME */ QEMUClockType rtc_clock; int vga_interface_type = VGA_NONE; static DisplayOptions dpy; @@ -782,26 +787,30 @@ void qemu_system_vmstop_request(RunState state) /***********************************************************/ /* real time host monotonic timer */ -static time_t qemu_time(void) +static time_t qemu_timedate(void) { return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; } /***********************************************************/ -/* host time/date access */ +/* RTC reference time/date access */ void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti = qemu_time(); + time_t ti = qemu_timedate(); ti += offset; - if (rtc_date_offset == -1) { - if (rtc_utc) - gmtime_r(&ti, tm); - else - localtime_r(&ti, tm); - } else { - ti -= rtc_date_offset; + + switch (rtc_base_type) { + case RTC_BASE_UTC: gmtime_r(&ti, tm); + break; + case RTC_BASE_LOCALTIME: + localtime_r(&ti, tm); + break; + case RTC_BASE_DATETIME: + ti -= rtc_host_datetime_offset; + gmtime_r(&ti, tm); + break; } } @@ -809,23 +818,30 @@ int qemu_timedate_diff(struct tm *tm) { time_t seconds; - if (rtc_date_offset == -1) - if (rtc_utc) - seconds = mktimegm(tm); - else { - struct tm tmp = *tm; - tmp.tm_isdst = -1; /* use timezone to figure it out */ - seconds = mktime(&tmp); - } - else - seconds = mktimegm(tm) + rtc_date_offset; - - return seconds - qemu_time(); + switch (rtc_base_type) { + case RTC_BASE_UTC: + seconds = mktimegm(tm); + break; + case RTC_BASE_LOCALTIME: + { + struct tm tmp = *tm; + tmp.tm_isdst = -1; /* use timezone to figure it out */ + seconds = mktime(&tmp); + break; + } + case RTC_BASE_DATETIME: + seconds = mktimegm(tm) + rtc_host_datetime_offset; + break; + default: + abort(); + } + + return seconds - qemu_timedate(); } -static void configure_rtc_date_offset(const char *startdate) +static void configure_rtc_host_datetime_offset(const char *startdate) { - time_t rtc_start_date; + time_t rtc_start_datetime; struct tm tm; if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", &tm.tm_year, &tm.tm_mon, @@ -841,15 +857,16 @@ static void configure_rtc_date_offset(const char *startdate) } tm.tm_year -= 1900; tm.tm_mon--; - rtc_start_date = mktimegm(&tm); - if (rtc_start_date == -1) { + rtc_start_datetime = mktimegm(&tm); + if (rtc_start_datetime == -1) { date_fail: - error_report("invalid date format"); + error_report("invalid datetime format"); error_printf("valid formats: " "'2006-06-17T16:01:21' or '2006-06-17'\n"); exit(1); } - rtc_date_offset = qemu_time() - rtc_start_date; + rtc_host_datetime_offset = (qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000) + - rtc_start_datetime; } static void configure_rtc(QemuOpts *opts) @@ -859,15 +876,16 @@ static void configure_rtc(QemuOpts *opts) value = qemu_opt_get(opts, "base"); if (value) { if (!strcmp(value, "utc")) { - rtc_utc = 1; + rtc_base_type = RTC_BASE_UTC; } else if (!strcmp(value, "localtime")) { Error *blocker = NULL; - rtc_utc = 0; + rtc_base_type = RTC_BASE_LOCALTIME; error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "-rtc base=localtime"); replay_add_blocker(blocker); } else { - configure_rtc_date_offset(value); + rtc_base_type = RTC_BASE_DATETIME; + configure_rtc_host_datetime_offset(value); } } value = qemu_opt_get(opts, "clock"); From patchwork Thu Oct 18 20:31:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GqPZgm56"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhXC4zBrz9sD9 for ; Fri, 19 Oct 2018 08:10:19 +1100 (AEDT) Received: from localhost ([::1]:44707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFYf-0005jP-4E for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:10:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyK-0007Kw-S0 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyG-0006KO-9K for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:35103) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyF-0006Ig-IY for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:40 -0400 Received: by mail-wm1-x32f.google.com with SMTP id o17-v6so900454wmh.0 for ; Thu, 18 Oct 2018 13:32:38 -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=ESgvzg55dFYv+zGUpIEzurc39yMpRcSnvF7c78daiok=; b=GqPZgm56w2Cd6yzd0s5vOhd3KCAerPgyFwGYcR5jXw/JKGEp7b7j1gOHUDIAa9PNn0 1JpzpFcxEtcVOcafya8o+2eBvnz2ufzBOFQcxUcpnNVn6S86rP/hnR2SDrmkdBHCtGIU Jlj6wCWGI2OOOtT7OHZXxQkzs2KPp5toG0ZWD3kHhXy5XNcve/9SXmYKAJ81o0mBA4ak cBKYY1QPIg+W2frasV6O+t8PcRRsGblWvT41BykhlPfFIEvj48TbL+oZj/0sXCWi7qrf md4esp7jJUzmcVrjkchZIeFy7W72/lryhXxnUHUpltsjEz5JQL8BzSApCPSNdx3QtNVu oyZQ== 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=ESgvzg55dFYv+zGUpIEzurc39yMpRcSnvF7c78daiok=; b=GprtdrkM6d8sGRhiFxnnQgCHUeHtCve8Y3gNqpmGYgG/IDONYfNuGDRF4LmmFDk37g CnrUCJ6y4hzvlVyT17yYkSQgA+at5yYZx8YjVh0HFZN1Kb45a9kUbmAwCBzhYWJ5BhRX Phuf060McvPyiCWCcYA60pzc3bYSIGAmdkY0WQmhVzLYQVlhwA45PGrbFWqHdHJxQPGU wNE6mgp2Z3sWr5riTHabfInROj/PRyxHjyDWQhBBJ0UsVBnCWPIHHjPKAapoa2Ea1BOo VgXufn123JPgAm+PnzLd/TNSFx0hNnR7i/zJ0pn+da+MV9WP31obWBetR+kweQapca7R /upA== X-Gm-Message-State: ABuFfoiucuJuJZYZBTHyHqMQ9LE6lhuz+mQK8eScbK98SSRBTmMMfbr8 IaG321fKs/D2q3/yYfZHjYmiOoXZ X-Google-Smtp-Source: ACcGV635/bqiNl1jrDYpaF6tgY2cLaY8AXTkoD73RftqUXX2gorHTyclMJA0kov3DdMVPe4I0MoC6A== X-Received: by 2002:a1c:1e8e:: with SMTP id e136-v6mr1902054wme.100.1539894757681; Thu, 18 Oct 2018 13:32:37 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:45 +0200 Message-Id: <1539894735-14232-19-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::32f Subject: [Qemu-devel] [PULL 18/48] Fixes RTC bug with base datetime shifts in clock=vm X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Artem Pisarenko This makes all current "-rtc" option parameters combinations produce fixed/unambiguous RTC timedate reference for hardware emulation frontends. It restores determinism of guest execution when used with clock=vm and specified base value. Buglink: https://bugs.launchpad.net/qemu/+bug/1797033 Signed-off-by: Artem Pisarenko Message-Id: <1d963c3e013dfedafa1f6edb9fb219b7e49e39da.1539846575.git.artem.k.pisarenko@gmail.com> Signed-off-by: Paolo Bonzini --- vl.c | 62 +++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/vl.c b/vl.c index d15e086..5bb53f7 100644 --- a/vl.c +++ b/vl.c @@ -152,8 +152,10 @@ static enum { RTC_BASE_LOCALTIME, RTC_BASE_DATETIME, } rtc_base_type = RTC_BASE_UTC; -static int rtc_host_datetime_offset = -1; /* valid only for host rtc_clock and - rtc_base_type=RTC_BASE_DATETIME */ +static time_t rtc_ref_start_datetime; +static int rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */ +static int rtc_host_datetime_offset = -1; /* valid & used only with + RTC_BASE_DATETIME */ QEMUClockType rtc_clock; int vga_interface_type = VGA_NONE; static DisplayOptions dpy; @@ -247,6 +249,7 @@ static struct { static QemuOptsList qemu_rtc_opts = { .name = "rtc", .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), + .merge_lists = true, .desc = { { .name = "base", @@ -785,32 +788,42 @@ void qemu_system_vmstop_request(RunState state) } /***********************************************************/ -/* real time host monotonic timer */ - -static time_t qemu_timedate(void) +/* RTC reference time/date access */ +static time_t qemu_ref_timedate(void) { - return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; + time_t value = qemu_clock_get_ms(rtc_clock) / 1000; + switch (rtc_clock) { + case QEMU_CLOCK_REALTIME: + value -= rtc_realtime_clock_offset; + /* no break */ + case QEMU_CLOCK_VIRTUAL: + value += rtc_ref_start_datetime; + break; + case QEMU_CLOCK_HOST: + if (rtc_base_type == RTC_BASE_DATETIME) { + value -= rtc_host_datetime_offset; + } + break; + default: + assert(0); + } + return value; } -/***********************************************************/ -/* RTC reference time/date access */ void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti = qemu_timedate(); + time_t ti = qemu_ref_timedate(); ti += offset; switch (rtc_base_type) { + case RTC_BASE_DATETIME: case RTC_BASE_UTC: gmtime_r(&ti, tm); break; case RTC_BASE_LOCALTIME: localtime_r(&ti, tm); break; - case RTC_BASE_DATETIME: - ti -= rtc_host_datetime_offset; - gmtime_r(&ti, tm); - break; } } @@ -819,6 +832,7 @@ int qemu_timedate_diff(struct tm *tm) time_t seconds; switch (rtc_base_type) { + case RTC_BASE_DATETIME: case RTC_BASE_UTC: seconds = mktimegm(tm); break; @@ -829,17 +843,14 @@ int qemu_timedate_diff(struct tm *tm) seconds = mktime(&tmp); break; } - case RTC_BASE_DATETIME: - seconds = mktimegm(tm) + rtc_host_datetime_offset; - break; default: abort(); } - return seconds - qemu_timedate(); + return seconds - qemu_ref_timedate(); } -static void configure_rtc_host_datetime_offset(const char *startdate) +static void configure_rtc_base_datetime(const char *startdate) { time_t rtc_start_datetime; struct tm tm; @@ -865,14 +876,19 @@ static void configure_rtc_host_datetime_offset(const char *startdate) "'2006-06-17T16:01:21' or '2006-06-17'\n"); exit(1); } - rtc_host_datetime_offset = (qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000) - - rtc_start_datetime; + rtc_host_datetime_offset = rtc_ref_start_datetime - rtc_start_datetime; + rtc_ref_start_datetime = rtc_start_datetime; } static void configure_rtc(QemuOpts *opts) { const char *value; + /* Set defaults */ + rtc_clock = QEMU_CLOCK_HOST; + rtc_ref_start_datetime = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; + rtc_realtime_clock_offset = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000; + value = qemu_opt_get(opts, "base"); if (value) { if (!strcmp(value, "utc")) { @@ -885,7 +901,7 @@ static void configure_rtc(QemuOpts *opts) replay_add_blocker(blocker); } else { rtc_base_type = RTC_BASE_DATETIME; - configure_rtc_host_datetime_offset(value); + configure_rtc_base_datetime(value); } } value = qemu_opt_get(opts, "clock"); @@ -3035,7 +3051,6 @@ int main(int argc, char **argv, char **envp) error_reportf_err(err, "cannot initialize crypto: "); exit(1); } - rtc_clock = QEMU_CLOCK_HOST; QLIST_INIT (&vm_change_state_head); os_setup_early_signal_handling(); @@ -3755,7 +3770,6 @@ int main(int argc, char **argv, char **envp) if (!opts) { exit(1); } - configure_rtc(opts); break; case QEMU_OPTION_tb_size: #ifndef CONFIG_TCG @@ -3973,6 +3987,8 @@ int main(int argc, char **argv, char **envp) exit(EXIT_FAILURE); } + configure_rtc(qemu_find_opts_singleton("rtc")); + machine_class = select_machine(); set_memory_options(&ram_slots, &maxram_size, machine_class); From patchwork Thu Oct 18 20:31:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nuOL9H5s"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhGh2khZz9s8J for ; Fri, 19 Oct 2018 07:58:36 +1100 (AEDT) Received: from localhost ([::1]:44642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFNK-0004Xs-0Q for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 16:58:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JR-EJ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyG-0006L0-Sl for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:41075) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyG-0006JG-A0 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:40 -0400 Received: by mail-wr1-x431.google.com with SMTP id q7-v6so7265910wrr.8 for ; Thu, 18 Oct 2018 13:32:39 -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=UKqJuZ5p75aKRipV/+rhwBzpllNB/JgRSRkB3jCMH60=; b=nuOL9H5sap7Aci49M7TtBeKgBGadEBulZevvinf7DDFS97bFeC86unCaI007mLRxdL oPALE7aMkNcNMAAz3sv+2RfIZl3ltVIKIr/poVAgsbYP19AnBE3smJUi+mF9oRm4+Gol L9nlfAVoxtNBycACE9VllrdBj44Av1CvIn57jD0sfyRZmaNGANvtx+LOUbcCd6ATPRJl f4KOFktsj1Q3ol1+hUuQi7E2JGkEKBXNxf7vC72YEN6yQQ82jCaE5KmCowxqkbS884hg tnuj9dSsjqzX9ViRdPRPia1HGwh91/ulno1pcIh+5Hld0FJ4Xh6l/LAUV4lKy95Bdohj ULLA== 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=UKqJuZ5p75aKRipV/+rhwBzpllNB/JgRSRkB3jCMH60=; b=aJHRWPZUc+utS/24f3+/WlZfaEPQhFnWQcGawnXf5cOKAtX1SiGO9BuCAUPLW93z6p ERbKPFs2QOXHprSOVql9V6QLSIoxhrqv1vKsYfWduFfXgVUZr1f8ynn0ZZwRL0o+ywNv VtYk9tEjJtbQVBxFMxEYdd9LpdINEQOWO4/UgBcL+nsmE4IPtfGykayhFI/sX6kD6qG9 uFPyeI9QfvQVldiHn0YqLozZ1d+FppEqR/ApNrAG++JoUYBo8qit5AlSZzM17pwgj6nD iT4BjS5tohJPbZSelriMwVGU1lqe8I8mVd+VvuhvNo/2LBNAHFa8ufJDrhCyPvdOjano b4ug== X-Gm-Message-State: ABuFfohtYwkuRvf+le1E78w/F7jH+EvQpVVnWnRiigoPOlEFJ2gn/aHn EBI7FV+FXOX+mhaWSQk/xvgs5rms X-Google-Smtp-Source: ACcGV6006nILNVZj36lKKrjGNKs0/3tV7E19LZLBwQnPMS9UZ9UtFFXFGZF0lZYTdat/jReN0E4CSA== X-Received: by 2002:a5d:6a11:: with SMTP id m17-v6mr31434560wru.192.1539894758641; Thu, 18 Oct 2018 13:32:38 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:46 +0200 Message-Id: <1539894735-14232-20-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::431 Subject: [Qemu-devel] [PULL 19/48] vl, qapi: offset calculation in RTC_CHANGE event reverted X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Artem Pisarenko Return value of qemu_timedate_diff(), used for calculation offset in QAPI 'RTC_CHANGE' event, restored to keep compatibility. Since it wasn't documented that difference is relative to host clock advancement, this change also adds important note to 'RTC_CHANGE' event description to highlight established implementation specifics. Signed-off-by: Artem Pisarenko Message-Id: <1fc12c77e8b7115d3842919a8b586d9cbe4efca6.1539846575.git.artem.k.pisarenko@gmail.com> Signed-off-by: Paolo Bonzini --- qapi/misc.json | 3 ++- vl.c | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index 3a68af9..c85c6c8 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3070,7 +3070,8 @@ # Emitted when the guest changes the RTC time. # # @offset: offset between base RTC clock (as specified by -rtc base), and -# new RTC clock value +# new RTC clock value. Note that value will be different depending +# on clock chosen to drive RTC (specified by -rtc clock). # # Note: This event is rate-limited. # diff --git a/vl.c b/vl.c index 5bb53f7..c5fffa3 100644 --- a/vl.c +++ b/vl.c @@ -789,10 +789,10 @@ void qemu_system_vmstop_request(RunState state) /***********************************************************/ /* RTC reference time/date access */ -static time_t qemu_ref_timedate(void) +static time_t qemu_ref_timedate(QEMUClockType clock) { - time_t value = qemu_clock_get_ms(rtc_clock) / 1000; - switch (rtc_clock) { + time_t value = qemu_clock_get_ms(clock) / 1000; + switch (clock) { case QEMU_CLOCK_REALTIME: value -= rtc_realtime_clock_offset; /* no break */ @@ -812,7 +812,7 @@ static time_t qemu_ref_timedate(void) void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti = qemu_ref_timedate(); + time_t ti = qemu_ref_timedate(rtc_clock); ti += offset; @@ -847,7 +847,7 @@ int qemu_timedate_diff(struct tm *tm) abort(); } - return seconds - qemu_ref_timedate(); + return seconds - qemu_ref_timedate(QEMU_CLOCK_HOST); } static void configure_rtc_base_datetime(const char *startdate) From patchwork Thu Oct 18 20:31:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uUY0P5zJ"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhbn5yljz9s5c for ; Fri, 19 Oct 2018 08:13:25 +1100 (AEDT) Received: from localhost ([::1]:44727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFbf-0008KG-B2 for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:13:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyL-0007Lk-Aa for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyJ-0006Ml-EK for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:55448) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyH-0006KT-Vq for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: by mail-wm1-x341.google.com with SMTP id 206-v6so1557163wmb.5 for ; Thu, 18 Oct 2018 13:32:40 -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=lnWEJ0N4a/WoZ9aaazHe3KgZeg1wSJg067PW2c6O/sM=; b=uUY0P5zJ/2Jl8O24L1P0l473rwhiJgbi4c7XRkkmtWOqSjILGyJ0ukzsbU9jr+3veQ ZgPjebEEYndXJorXbEBJzHr9AJEIuJAJykmZ2ZLd3f27OvI7427qnr7A9mp3VXi3a72M oNXl5/B1/uvoLOjv39I+Wr3+RmnOn627ymidIp3Wl73d6+OR8wb6CmoNQMHHsbwEF6mk YZ8C4m8JF2qilkf8fcnW2UrSwjYkcLrooWDLkcgM+pMITFmCOXFdNsU/wO0TtS/bwTPn Wd632eV4zcTslC9GYUJ/va140w5AV8T2EtdCJ4OT/IxoWrg6SCjkB4k9HwANPiTh7ZVB IJVQ== 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=lnWEJ0N4a/WoZ9aaazHe3KgZeg1wSJg067PW2c6O/sM=; b=MRmfMpIoUn2lYT2ieSKerZf60YZr0BKPRu0TKlp3i2TanX5wZ20n0/TYHdL9bHW75e oSTARSybeBMDe9Bu6RDuw8SsOZz2geJzFdL78RuXeo8VKk4BfE+8p7pKguSon330xPZF m5KWtMQhUUE7WBuMG8km0xiA2/4OEMfBGCp/oRfpizQu5GOhQXb6muO+pHftn0dnmAYR can3Xbpa5tAsTHqZyymhZD1KKTTQlAgbeWBjrmkUXQ0Nq2nkVw+HL/Mh5eszUOpmDbxd ltLHsgy7yYkeuGMObzVWgRl+BveXzZomaEQwCIOZHH2sJrr1yfMKB7nuiy2e0OVprSbH SsUw== X-Gm-Message-State: ABuFfogi8oPJ+zl1SLHyBqA5blKT5NArztZZGy/+l63Ppj9S/Y9XSANQ sG0qj85DZu0cyJgqSOHYJtaCzBEn X-Google-Smtp-Source: ACcGV62GwMR17OmDfczdwqhGzZBoIdWZA9X594dD40qHAAjdSCQ+0Cn90ayU368xOYx5R1ZGtQa+fQ== X-Received: by 2002:a1c:5fc2:: with SMTP id t185-v6mr1900874wmb.12.1539894759639; Thu, 18 Oct 2018 13:32:39 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:47 +0200 Message-Id: <1539894735-14232-21-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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 20/48] call HotplugHandler->plug() as the last step in device realization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov When [2] was fixed it was agreed that adding and calling post_plug() callback after device_reset() was low risk approach to hotfix issue right before release. So it was merged instead of moving already existing plug() callback after device_reset() is called which would be more risky and require all plug() callbacks audit. Looking at the current plug() callbacks, it doesn't seem that moving plug() callback after device_reset() is breaking anything, so here goes agreed upon [3] proper fix which essentially reverts [1][2] and moves plug() callback after device_reset(). This way devices always comes to plug() stage, after it's been fully initialized (including being reset), which fixes race condition [2] without need for an extra post_plug() callback. 1. (25e897881 "qdev: add HotplugHandler->post_plug() callback") 2. (8449bcf94 "virtio-scsi: fix hotplug ->reset() vs event race") 3. https://www.mail-archive.com/qemu-devel@nongnu.org/msg549915.html Signed-off-by: Igor Mammedov Message-Id: <1539696820-273275-1-git-send-email-imammedo@redhat.com> Reviewed-by: Stefan Hajnoczi Tested-by: Pierre Morel Acked-by: Pierre Morel Signed-off-by: Paolo Bonzini --- hw/core/hotplug.c | 10 ---------- hw/core/qdev.c | 16 ++++++---------- hw/scsi/virtio-scsi.c | 11 +---------- include/hw/hotplug.h | 11 ----------- 4 files changed, 7 insertions(+), 41 deletions(-) diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c index 2253072..17ac986 100644 --- a/hw/core/hotplug.c +++ b/hw/core/hotplug.c @@ -35,16 +35,6 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, } } -void hotplug_handler_post_plug(HotplugHandler *plug_handler, - DeviceState *plugged_dev) -{ - HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler); - - if (hdc->post_plug) { - hdc->post_plug(plug_handler, plugged_dev); - } -} - void hotplug_handler_unplug_request(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **errp) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 046d8f1..6b3cc55 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -832,14 +832,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp) DEVICE_LISTENER_CALL(realize, Forward, dev); - if (hotplug_ctrl) { - hotplug_handler_plug(hotplug_ctrl, dev, &local_err); - } - - if (local_err != NULL) { - goto post_realize_fail; - } - /* * always free/re-initialize here since the value cannot be cleaned up * in device_unrealize due to its usage later on in the unplug path @@ -869,8 +861,12 @@ static void device_set_realized(Object *obj, bool value, Error **errp) dev->pending_deleted_event = false; if (hotplug_ctrl) { - hotplug_handler_post_plug(hotplug_ctrl, dev); - } + hotplug_handler_plug(hotplug_ctrl, dev, &local_err); + if (local_err != NULL) { + goto child_realize_fail; + } + } + } else if (!value && dev->realized) { Error **local_errp = NULL; QLIST_FOREACH(bus, &dev->child_bus, sibling) { diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 5a3057d..3aa9971 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -797,16 +797,8 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev, virtio_scsi_acquire(s); blk_set_aio_context(sd->conf.blk, s->ctx); virtio_scsi_release(s); - } -} -/* Announce the new device after it has been plugged */ -static void virtio_scsi_post_hotplug(HotplugHandler *hotplug_dev, - DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(hotplug_dev); - VirtIOSCSI *s = VIRTIO_SCSI(vdev); - SCSIDevice *sd = SCSI_DEVICE(dev); + } if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { virtio_scsi_acquire(s); @@ -976,7 +968,6 @@ static void virtio_scsi_class_init(ObjectClass *klass, void *data) vdc->start_ioeventfd = virtio_scsi_dataplane_start; vdc->stop_ioeventfd = virtio_scsi_dataplane_stop; hc->plug = virtio_scsi_hotplug; - hc->post_plug = virtio_scsi_post_hotplug; hc->unplug = virtio_scsi_hotunplug; } diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h index 51541d6..1a0516a 100644 --- a/include/hw/hotplug.h +++ b/include/hw/hotplug.h @@ -47,8 +47,6 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler, * @parent: Opaque parent interface. * @pre_plug: pre plug callback called at start of device.realize(true) * @plug: plug callback called at end of device.realize(true). - * @post_plug: post plug callback called after device.realize(true) and device - * reset * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling. @@ -63,7 +61,6 @@ typedef struct HotplugHandlerClass { /* */ hotplug_fn pre_plug; hotplug_fn plug; - void (*post_plug)(HotplugHandler *plug_handler, DeviceState *plugged_dev); hotplug_fn unplug_request; hotplug_fn unplug; } HotplugHandlerClass; @@ -87,14 +84,6 @@ void hotplug_handler_pre_plug(HotplugHandler *plug_handler, Error **errp); /** - * hotplug_handler_post_plug: - * - * Call #HotplugHandlerClass.post_plug callback of @plug_handler. - */ -void hotplug_handler_post_plug(HotplugHandler *plug_handler, - DeviceState *plugged_dev); - -/** * hotplug_handler_unplug_request: * * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler. From patchwork Thu Oct 18 20:31:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986321 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gcg6pa4W"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhtg32kBz9sBj for ; Fri, 19 Oct 2018 08:26:19 +1100 (AEDT) Received: from localhost ([::1]:44813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFo8-0004OH-TL for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:26:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyO-0007Pt-6m for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyL-0006P2-IG for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:46 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40228) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyL-0006LH-3O for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: by mail-wm1-x341.google.com with SMTP id z204-v6so1611065wmc.5 for ; Thu, 18 Oct 2018 13:32:41 -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=NeasY3TmLiehi4PHiu3mbs8HYZcW9pK1YSZlWNT4+Ac=; b=Gcg6pa4WZj8FaD2qwV1HR0YU/C6aIZ+LEsTXQJSNvRYAD2huixFq790aZl8y4y8IPE +xuXy9kjDUbHoxThmdeZvvOm/MnZAUwFnPE8BzWVHNZCvbsNFRa4NO9tzvT/pia8q6GG E7KQ1Zib8cKBVwotQXzfrNYAYplHZ48Oa/aanBavj30nVMOfGrOMQa0uoxCnZCKhTLV1 AlRx0Ck5y3LpH6pTZz29qdncdML5CmvDBQGVwWlXjjZ4VShrxxEka/PUi45WIEmuvdkl EeMQJl913nwzhwhWnzl7KuYvCN8fbZVYhH1hhY7LQyQLlC77ME6/OxNO4PEJ+kkfQC5L vgZA== 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=NeasY3TmLiehi4PHiu3mbs8HYZcW9pK1YSZlWNT4+Ac=; b=Vs7oSX7UYIt34tQzEg40TNWvcZebAyW40HGhAAXhQ/DPeGvNLw1/rDywnU9dj5VuhL DXDYBTPOHmH8jAO6KWwDEI6KXOIGz/pcXM/w1tfJiJK3/TLxRkTOufgQzLm00fd2n578 dLPsTuVxL55YtYre9xVbAgC0O5hTKUKr1rLBfLSSmlFBLywqDVWmlpH5xg3mSi0gHRbJ R6TyDC2PNB3EOEYQ8TsbReHQq7PDyDOgGAxuypt4dbSHcgZxDRmh71d1ZW7h/6jFA3y/ FVcH1mImKx8P57jrzBvxmWgfDcqguD3UUto29nRPXV6J8IwBZpi8KNlkpHveP4+kRfI5 07OA== X-Gm-Message-State: ABuFfoiMD+NWWvw0mLSDxCNJthoZCjU/A6SBF02LFQKh2wA1GWNZtSB+ k6hGYXJ5rewLSLtcfbx/5vpUw23J X-Google-Smtp-Source: ACcGV62Ghfkd3mTuoil4SKD0N+M0x7cE34bDYQdAMXnTO1Jn9KDFu6zkLVztbH43NrcUd/1afsq+SA== X-Received: by 2002:a1c:3288:: with SMTP id y130-v6mr1855965wmy.11.1539894760652; Thu, 18 Oct 2018 13:32:40 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:48 +0200 Message-Id: <1539894735-14232-22-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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 21/48] hw: edu: drop DO_UPCAST X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Li Qiang Signed-off-by: Li Qiang Signed-off-by: Paolo Bonzini --- hw/misc/edu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/misc/edu.c b/hw/misc/edu.c index 0687ffd..cdcf550 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -342,7 +342,7 @@ static void *edu_fact_thread(void *opaque) static void pci_edu_realize(PCIDevice *pdev, Error **errp) { - EduState *edu = DO_UPCAST(EduState, pdev, pdev); + EduState *edu = EDU(pdev); uint8_t *pci_conf = pdev->config; pci_config_set_interrupt_pin(pci_conf, 1); @@ -365,7 +365,7 @@ static void pci_edu_realize(PCIDevice *pdev, Error **errp) static void pci_edu_uninit(PCIDevice *pdev) { - EduState *edu = DO_UPCAST(EduState, pdev, pdev); + EduState *edu = EDU(pdev); qemu_mutex_lock(&edu->thr_mutex); edu->stopping = true; From patchwork Thu Oct 18 20:31:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Dfkr5M9q"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhYP1Q7Gz9s5c for ; Fri, 19 Oct 2018 08:11:21 +1100 (AEDT) Received: from localhost ([::1]:44721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFZe-0006ek-OY for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:11:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyO-0007Pq-6b for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyL-0006Oe-B2 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:46 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:36668) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyJ-0006Lt-OC for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: by mail-wm1-x331.google.com with SMTP id a8-v6so1627157wmf.1 for ; Thu, 18 Oct 2018 13:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=XSiDpnE8bYM/w7cuyzvbLsyMuqjABwgLix3HENtrn2Y=; b=Dfkr5M9qSaG0fCkBkKjr78KHHeFd6DJy9g5MT3jTmfYrWc6gnsDpUM5GIvbhPeiUm6 83sS2/6OMS5S5b6w521bauBPeHlax20XiBG6iHL8/y/LhUfV0pR2OzssKV04bRVxXLed f5HJ/sO15b2IC8pa990/92hSYPhUYbGfp4Ep5kgj5RFODdx9Zv5fxI3KMw7Ss8TuLHqZ PNm7fK8qQ9lv1XoUN9RyBokG+lxqAYnUrDsrYb+crOb428FveyXKqKW66nLx8ZEevTKZ VnVqbqy7ejqWZycVajQtrk95n/KInXOm0K3xPsFTzewrEM0LLKxooQv9zG1+63fhyriX gqQA== 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:subject:date:message-id :in-reply-to:references; bh=XSiDpnE8bYM/w7cuyzvbLsyMuqjABwgLix3HENtrn2Y=; b=sdv2bxfuzTQmXg42HcAAxzp8o6xI8PUS+SA8p2Ld6V7Fbe71Rs+B+oeHXQm6QBIv3C fOqJrSY05LOI1/ZTmz4bn65fq2O5DqSnnkZY4hT/1HDmA+hJpLpY7tZnt9xs9G/gFQxN KyXiFdZTRja0EWwAjKEmBuA9YorwhQByREZhDoV51PumEBOXoOY5RYBnlsIjiDav4XZB hwFcNB8ZGqyrU+zY27ELUNdRZjy9oWjU/EyxNhAwWkXiAc+a9rjVgns1f/d1V+pndl9g f1pv4uM78YEiCobSoKoDhaiM39CGa7XZtsHDEVmPKSNpUJ1B1a2seMFAEnA6Jmj7ydDn ysDA== X-Gm-Message-State: ABuFfoh2XQdVy5C0om0UTMzG0GpB5vjYdHo6pj6t1Vv9Ydy8r0Ei/gc1 R4pBB7ET5/nEocTuFXEUHUXaYiwD X-Google-Smtp-Source: ACcGV60t2O4Trk+iFFgCOXkzBGNAfJRAV3ndFZE6TvAtQOtxRCes2ykbtKbvtArUAvNAECVJqJU1bw== X-Received: by 2002:a1c:af07:: with SMTP id y7-v6mr1939118wme.33.1539894761625; Thu, 18 Oct 2018 13:32:41 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:49 +0200 Message-Id: <1539894735-14232-23-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::331 Subject: [Qemu-devel] [PULL 22/48] scsi-disk: fix double completion of failing passthrough requests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If a command fails with a sense that scsi_sense_buf_to_errno converts to ECANCELED/EAGAIN/ENOTCONN or with a unit attention, scsi_req_complete is called twice. This caused a crash. Reported-by: Wangguang Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index c43163c..4074d7c 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -441,9 +441,18 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed) } switch (error) { case 0: - /* The command has run, no need to fake sense. */ + /* A passthrough command has run and has produced sense data; check + * whether the error has to be handled by the guest or should rather + * pause the host. + */ assert(r->status && *r->status); - scsi_req_complete(&r->req, *r->status); + error = scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.sense)); + if (error == ECANCELED || error == EAGAIN || error == ENOTCONN || + error == 0) { + /* These errors are handled by guest. */ + scsi_req_complete(&r->req, *r->status); + return true; + } break; case ENOMEDIUM: scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); @@ -462,17 +471,6 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed) break; } } - if (!error) { - assert(r->status && *r->status); - error = scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.sense)); - - if (error == ECANCELED || error == EAGAIN || error == ENOTCONN || - error == 0) { - /* These errors are handled by guest. */ - scsi_req_complete(&r->req, *r->status); - return true; - } - } blk_error_action(s->qdev.conf.blk, action, is_read, error); if (action == BLOCK_ERROR_ACTION_STOP) { From patchwork Thu Oct 18 20:31:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986319 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OpnnNKHW"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhqG4Mt8z9sBj for ; Fri, 19 Oct 2018 08:23:22 +1100 (AEDT) Received: from localhost ([::1]:44791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFlI-0001CO-5W for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:23:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyO-0007Pr-6c for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyL-0006PF-LS for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:46 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:56242) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyL-0006MV-7a for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: by mail-wm1-x336.google.com with SMTP id 206-v6so1557281wmb.5 for ; Thu, 18 Oct 2018 13:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=8vioGhxmKBtQ1EeLzXWybw94Dw3VJdA1EuxaCfx2geM=; b=OpnnNKHWEdn77/WLRKbZJDUb65Y3idgEWgdB7ShZnFnIDZHZ6d9wxRJMiH5Jt8GXOn 2E1KLv3fXgrWxzBQt97536kdSAl+LUJToaVlelE5gDxfoE4id45IwERB8jsRA6016dGs v831TWVa/sZjcxc9RqNLQuOFcLXSSMIbuE3w56oYH93xSx+9bFphfQsARX5020rEUpS3 J9RG0fJN7Tw4Zm/MECAh8BpEwwxpEfFsxh1z+JeJfLf5qyHyWPPohblfnGtakP1VFu7Q 7B6BhPbRYMwMsTjywmb5kOPpPQhiItFfjw7iwgi3+hhqpJLSL4iEVDadVjTMr2Jum4Ul lL+w== 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:subject:date:message-id :in-reply-to:references; bh=8vioGhxmKBtQ1EeLzXWybw94Dw3VJdA1EuxaCfx2geM=; b=iOOy1352DZYUkoS+KoVonfwrMutJC5yF6QbbtEotoCvZT8GPCnXM+lujo3gcfEtO9R 8FR7TNdjoTN6kIsXf4alq6M7AFdGoyJSzDVKVD/2fXEBwtETC0fiDWwXNx+TpTYwzr6H CJkpFPmHKQTpJpi9/vYIKJrmKH0Y4nNCHDvqNXlnQi0GYaGhHjhiRSTQl9XixVxmO5Uu Y0W7nbh+QRzMAKzdfxlSajx9zGbwxZ0p7/h0AIxMtuEdH1hhmr1eBNEuOOWOKv150pW5 6TQyApXE4EJIqh3rkLcrN1H94/u3jWV9PskqLVvUhg6eRwu55Ou2ly2V8A0vaRMmRByO MV8A== X-Gm-Message-State: ABuFfoglOk41djEJOhmfrPCR3zSfy19HQqKBJwPet6o1HcFfQyWDMepY 7tkb03HGZ0n4X3Tq9HurCs7EevyK X-Google-Smtp-Source: ACcGV604J9wkWW3K51Rc3k/naN/nHCrM38g5px32OXh3F1TLpYdYlqlTpg+t/cSZ5/IinXR3F07Vzg== X-Received: by 2002:a1c:6308:: with SMTP id x8-v6mr1714187wmb.99.1539894762677; Thu, 18 Oct 2018 13:32:42 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:50 +0200 Message-Id: <1539894735-14232-24-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::336 Subject: [Qemu-devel] [PULL 23/48] scsi-disk: fix rerror/werror=ignore X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" rerror=ignore was returning true from scsi_handle_rw_error but the callers were not calling scsi_req_complete when rerror=ignore returns true (this is the correct thing to do when true is returned after executing a passthrough command). Fix this by calling it in scsi_handle_rw_error. Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 4074d7c..e2c5408 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -473,10 +473,15 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed) } blk_error_action(s->qdev.conf.blk, action, is_read, error); + if (action == BLOCK_ERROR_ACTION_IGNORE) { + scsi_req_complete(&r->req, 0); + return true; + } + if (action == BLOCK_ERROR_ACTION_STOP) { scsi_req_retry(&r->req); } - return action != BLOCK_ERROR_ACTION_IGNORE; + return false; } static void scsi_write_complete_noio(SCSIDiskReq *r, int ret) From patchwork Thu Oct 18 20:31:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WD9ZQIda"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhTv3Xn4z9s8J for ; Fri, 19 Oct 2018 08:08:19 +1100 (AEDT) Received: from localhost ([::1]:44701 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFWj-00046p-3Y for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:08:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyO-0007QR-S0 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyN-0006QF-0p for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:48 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:40851) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyL-0006OC-HT for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: by mail-wm1-x332.google.com with SMTP id z204-v6so1611202wmc.5 for ; Thu, 18 Oct 2018 13:32:45 -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=UdK6UDPvmtaTOv2jydA8I09aT3/1CVGdzfVcL+R6bxU=; b=WD9ZQIdagkiK+XXJOKVVPXMbcdKrbjnb9SYX4zHi7KK0NQDX6YePVl9MeYJ5TJTGdY FuMPqY30LH610nlxWCmXjsOM6GKAjsLLBF1498uLTp+aOYa/SwMG1bP9iuaedgbcyL+W eCMv/t92HbS/SYy55uW9a5N1gpqGLjIiC4o0upMibUhNtfGo+9gY39i1LzgQ7k1tKLE/ mHfn3EjlfSLL7KzmVxWcoTor44SzGSgSTapJ7XPElKPDsDV6g15XUfmUUOIU/EjnUWiF 8l5BNHrRdyw3+nICYq/8jxb7w5B0qeGRwr8s+xcJs4NM463dbBuMuDUVKf09v67Vqn3L Uhqg== 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=UdK6UDPvmtaTOv2jydA8I09aT3/1CVGdzfVcL+R6bxU=; b=B84p+quN4v3NDRjYVcC+xQrMYmx5oPXm5WOLYS4rwM+y9yV44e5X5TJlakzrUkT1y6 yu9/PqzfLUwz3QjqFgc4pGV+Sl3xKlN87/sZbh8vTeIyvI9HZBqvpng1trwk62u0AUxB 3t74WbK16qdShHZ5+yzThIVnC3Ea7fxRqh0GijUKyI8Rz/gF+9RpBrrYjglsx7AlBbtH f1eaNOcVD4CNwqy1uRlUFqVhHNEVrodHyrdNQbXndJzJTvpEcuXn+lUOF67R24dp2Mt8 K3iZIGCUgCDT/SlsvO1T62+oObmh85HrrN5e6KNkztD0U5W+qqfxEJ3T34G72NufZlzs 5bVQ== X-Gm-Message-State: ABuFfogApLQlRono20KYWuiKcPBYdqgM6q8azaC1ZXVSSrJALeVr+UKt MGdPQbuXFvGDj4jm5AoielYj6Q3j X-Google-Smtp-Source: ACcGV63DAlE/GJl7XL9V8L5cZoElV7XlMp7qeRtwQISzK7iWdlqU38ggiB8lG9zqGBAaP3ZIGMQ/PA== X-Received: by 2002:a1c:a8c2:: with SMTP id r185-v6mr1866733wme.8.1539894763990; Thu, 18 Oct 2018 13:32:43 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:51 +0200 Message-Id: <1539894735-14232-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::332 Subject: [Qemu-devel] [PULL 24/48] hyperv_testdev: refactor for better maintainability X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Make hyperv_testdev slightly easier to follow and enhance in future. For that, put the hyperv sint routes (wrapped in a helper structure) on a linked list rather than a fixed-size array. Besides, this way HvSintRoute can be treated as an opaque structure, allowing for easier refactoring of the core Hyper-V SynIC code in followup pathches. Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-2-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/misc/hyperv_testdev.c | 116 ++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 61 deletions(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 7549f47..915d74e 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qemu/queue.h" #include #include "hw/hw.h" #include "hw/qdev.h" @@ -20,12 +21,17 @@ #include "target/i386/hyperv.h" #include "kvm_i386.h" -#define HV_TEST_DEV_MAX_SINT_ROUTES 64 +typedef struct TestSintRoute { + QLIST_ENTRY(TestSintRoute) le; + uint8_t vp_index; + uint8_t sint; + HvSintRoute *sint_route; +} TestSintRoute; struct HypervTestDev { ISADevice parent_obj; MemoryRegion sint_control; - HvSintRoute *sint_route[HV_TEST_DEV_MAX_SINT_ROUTES]; + QLIST_HEAD(, TestSintRoute) sint_routes; }; typedef struct HypervTestDev HypervTestDev; @@ -39,70 +45,56 @@ enum { HV_TEST_DEV_SINT_ROUTE_SET_SINT }; -static int alloc_sint_route_index(HypervTestDev *dev) +static void sint_route_create(HypervTestDev *dev, + uint8_t vp_index, uint8_t sint) { - int i; + TestSintRoute *sint_route; - for (i = 0; i < ARRAY_SIZE(dev->sint_route); i++) { - if (dev->sint_route[i] == NULL) { - return i; - } - } - return -1; -} + sint_route = g_new0(TestSintRoute, 1); + assert(sint_route); -static void free_sint_route_index(HypervTestDev *dev, int i) -{ - assert(i >= 0 && i < ARRAY_SIZE(dev->sint_route)); - dev->sint_route[i] = NULL; + sint_route->vp_index = vp_index; + sint_route->sint = sint; + + sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL); + assert(sint_route->sint_route); + + QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le); } -static int find_sint_route_index(HypervTestDev *dev, uint32_t vp_index, - uint32_t sint) +static TestSintRoute *sint_route_find(HypervTestDev *dev, + uint8_t vp_index, uint8_t sint) { - HvSintRoute *sint_route; - int i; + TestSintRoute *sint_route; - for (i = 0; i < ARRAY_SIZE(dev->sint_route); i++) { - sint_route = dev->sint_route[i]; - if (sint_route && sint_route->vp_index == vp_index && - sint_route->sint == sint) { - return i; + QLIST_FOREACH(sint_route, &dev->sint_routes, le) { + if (sint_route->vp_index == vp_index && sint_route->sint == sint) { + return sint_route; } } - return -1; + assert(false); + return NULL; } -static void hv_synic_test_dev_control(HypervTestDev *dev, uint32_t ctl, - uint32_t vp_index, uint32_t sint) +static void sint_route_destroy(HypervTestDev *dev, + uint8_t vp_index, uint8_t sint) { - int i; - HvSintRoute *sint_route; + TestSintRoute *sint_route; - switch (ctl) { - case HV_TEST_DEV_SINT_ROUTE_CREATE: - i = alloc_sint_route_index(dev); - assert(i >= 0); - sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL); - assert(sint_route); - dev->sint_route[i] = sint_route; - break; - case HV_TEST_DEV_SINT_ROUTE_DESTROY: - i = find_sint_route_index(dev, vp_index, sint); - assert(i >= 0); - sint_route = dev->sint_route[i]; - kvm_hv_sint_route_destroy(sint_route); - free_sint_route_index(dev, i); - break; - case HV_TEST_DEV_SINT_ROUTE_SET_SINT: - i = find_sint_route_index(dev, vp_index, sint); - assert(i >= 0); - sint_route = dev->sint_route[i]; - kvm_hv_sint_route_set_sint(sint_route); - break; - default: - break; - } + sint_route = sint_route_find(dev, vp_index, sint); + QLIST_REMOVE(sint_route, le); + kvm_hv_sint_route_destroy(sint_route->sint_route); + g_free(sint_route); +} + +static void sint_route_set_sint(HypervTestDev *dev, + uint8_t vp_index, uint8_t sint) +{ + TestSintRoute *sint_route; + + sint_route = sint_route_find(dev, vp_index, sint); + + kvm_hv_sint_route_set_sint(sint_route->sint_route); } static uint64_t hv_test_dev_read(void *opaque, hwaddr addr, unsigned size) @@ -114,18 +106,20 @@ static void hv_test_dev_write(void *opaque, hwaddr addr, uint64_t data, uint32_t len) { HypervTestDev *dev = HYPERV_TEST_DEV(opaque); - uint8_t ctl; + uint8_t sint = data & 0xFF; + uint8_t vp_index = (data >> 8ULL) & 0xFF; + uint8_t ctl = (data >> 16ULL) & 0xFF; - ctl = (data >> 16ULL) & 0xFF; switch (ctl) { case HV_TEST_DEV_SINT_ROUTE_CREATE: + sint_route_create(dev, vp_index, sint); + break; case HV_TEST_DEV_SINT_ROUTE_DESTROY: - case HV_TEST_DEV_SINT_ROUTE_SET_SINT: { - uint8_t sint = data & 0xFF; - uint8_t vp_index = (data >> 8ULL) & 0xFF; - hv_synic_test_dev_control(dev, ctl, vp_index, sint); + sint_route_destroy(dev, vp_index, sint); + break; + case HV_TEST_DEV_SINT_ROUTE_SET_SINT: + sint_route_set_sint(dev, vp_index, sint); break; - } default: break; } @@ -145,7 +139,7 @@ static void hv_test_dev_realizefn(DeviceState *d, Error **errp) HypervTestDev *dev = HYPERV_TEST_DEV(d); MemoryRegion *io = isa_address_space_io(isa); - memset(dev->sint_route, 0, sizeof(dev->sint_route)); + QLIST_INIT(&dev->sint_routes); memory_region_init_io(&dev->sint_control, OBJECT(dev), &synic_test_sint_ops, dev, "hyperv-testdev-ctl", 4); From patchwork Thu Oct 18 20:31:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986290 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cIvBkzQx"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhKL4bGXz9s8F for ; Fri, 19 Oct 2018 08:00:54 +1100 (AEDT) Received: from localhost ([::1]:44656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFPY-0006Uy-7V for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:00:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyU-0007Y2-Lz for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyO-0006So-Vf for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:54 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:36841) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyN-0006Ou-MQ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:48 -0400 Received: by mail-wr1-x429.google.com with SMTP id y16so35120422wrw.3 for ; Thu, 18 Oct 2018 13:32:45 -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=vV9u57OCAsBK8j6Yl7n98aVXCgkI1fAm6bfBQiDd6pc=; b=cIvBkzQxZx1LaA0rl7CDqufeujovVn/kazoFXj4LCS4d7zsbKpbsqSEGaWfrjUZ3mO wM1kTgtVo3b1DRYOmAdjNDLeBcc0zDun1FFH74VibsH1DmuNhq0lyNMoCcXhMD27xKwL 8vkcsQjCIKj5w+6e5AUf5mMTvb8wcJUYUgZsC6rGSOC1U7JXf+F6VTEtvGi1HjOy+u6M 3XS9+3wzXPanGYd7W4pRTJwbKF5plBfFN5vHFL/Fs4aBWqC/4+oBKoIQWp2nCy6B+oxm qfCylNo7EM/0l+tCaI4Rg9jiN6EH1CD0zct95i1aIUNGe+0o2x6VI8WW2Dg9XOPbrTU2 fbNw== 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=vV9u57OCAsBK8j6Yl7n98aVXCgkI1fAm6bfBQiDd6pc=; b=i30LHxNeqPOtg2tEyU3NMqD4V/Bf3Kvg5lM1oGdvVHaU5CDTXPJkykdKYf8M1lONeD 8vtG1vvJ+muQQOBTUZ0Lt4ot5XoeLlfu2EK8pBv4tPLYlz+YBk3CcbKn0bNSV3VAhab+ /L5Xectit6E/KiOvK6sVu4qp6aZwzaMl2pvFBkMPWGXzo/NDvosIai6PYJZkIk7vagYg XjxcsdRbajvEe7EIBQDzHE9yg8xqs/2O3CsFwMp/KRAov06ZfkEe/oT2BxT4c7sr4POH k/KVa1W9hgdoXqhIgjqczWX6p7S2Ix/M6rEAxMZBBNZs7FVSQTDjkq3LWuthAUuj+k1t HTZw== X-Gm-Message-State: ABuFfoheen9fFSS6//tdbLCBoRrmaXbqeVbjKpbE+43U85PoHpLJfU90 jfwdJtFlNK3R3CJUM/Ns8Ol3Yk07 X-Google-Smtp-Source: ACcGV63Igen0EyrEcIZ93mM94hrMgd0klbHe4l+avm5u2zuyBq7z5d2byvkBt8OSP1+ubVHetbE/gQ== X-Received: by 2002:adf:ae09:: with SMTP id x9-v6mr29358456wrc.102.1539894764835; Thu, 18 Oct 2018 13:32:44 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:52 +0200 Message-Id: <1539894735-14232-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::429 Subject: [Qemu-devel] [PULL 25/48] hyperv_testdev: drop unnecessary includes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-3-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/misc/hyperv_testdev.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 915d74e..7291fb1 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -13,13 +13,9 @@ #include "qemu/osdep.h" #include "qemu/queue.h" -#include -#include "hw/hw.h" #include "hw/qdev.h" #include "hw/isa/isa.h" -#include "sysemu/kvm.h" #include "target/i386/hyperv.h" -#include "kvm_i386.h" typedef struct TestSintRoute { QLIST_ENTRY(TestSintRoute) le; From patchwork Thu Oct 18 20:31:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986293 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kD758bvE"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhPM634vz9s5c for ; Fri, 19 Oct 2018 08:04:23 +1100 (AEDT) Received: from localhost ([::1]:44679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFSt-0000uY-3i for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:04:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyU-0007Y7-Nh for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyP-0006T6-3X for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:54 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:55099) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyO-0006Ph-8J for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:48 -0400 Received: by mail-wm1-x32a.google.com with SMTP id r63-v6so1568231wma.4 for ; Thu, 18 Oct 2018 13:32:46 -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=U2/dpiMHuT1mwacg+6lvEehBe1wOP81596Z9aljx7EQ=; b=kD758bvEYF93N3laKEnI8PlwXqg5VkV8qUOLPOZmMoG7lkJx2ak3ftVu3JAx+Lu2gv wcUSPqS+SDF9yvQlW2xFZKZVOoHXYz3WAefjzMBs0wENQEgYHBMkHN372ZTrfubnFQA/ K69y+YCBR0Qi+mT0MVJWn2G5+ANJTIhkW6lTEd39dQzuNsXVczSJf/Qk+gKhf3EXULW6 gs0R5PlTWWM1OJMPFnE/3lC5Fi91HM2KmcDCEVQMKxdX2HLcycHCemrmUTVORvx1eeUf FJpVDva1kAb6S6NNNpuLtJ9cPNGXCyo2sN6tZdcoweEztNhDB+XRwZvA3hSbONMD1NM5 /nyQ== 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=U2/dpiMHuT1mwacg+6lvEehBe1wOP81596Z9aljx7EQ=; b=nd94ViBPqtyR/6h/YJvZOtj4xzSRZKDf8CCXUqoxj8MHBIaESA8YPU5O+9On5GPTe/ bT0EU1qhK5mHljreB9yGXVOZzJOTp8yKNvj0nrwjhj+iHdWTxP8PgE7fmzr3d4G+P5c5 PA3EWQrH3tcDm0qtgTIK9bgnChjKCAcruSQ3UDbXLJp7R0hpE8ffN9229zwAwNO2JJ8H jHqHWEwm9XtrHzCO57AGhezTD6jurXWN/TmyiAF7MWYVcXX6DvghMRRlCA62QBgWD/7t aMn2g5qlBzkPV7fS3EWkNkg5Y0t+N1biptU/7ORMrDYAqe3oFyzNo3zPzpwAw4Akqp5A lyxw== X-Gm-Message-State: ABuFfoiCnQ3SLr85/u9lKlX33N4SION2vnI4yv3a43TEVGiROkIQTO++ ii+dUNxabRSDQxVyTKdn+0RdNora X-Google-Smtp-Source: ACcGV61znv/1X6Y/7CwZpy/gtdtYpOoYRRA9Da5kyC75h1z/ELX8te4oTi6nmTMW4u4Irx5HOkO+rw== X-Received: by 2002:a1c:aa05:: with SMTP id t5-v6mr1931388wme.71.1539894765718; Thu, 18 Oct 2018 13:32:45 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:53 +0200 Message-Id: <1539894735-14232-27-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::32a Subject: [Qemu-devel] [PULL 26/48] hyperv: cosmetic: g_malloc -> g_new X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-4-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- target/i386/hyperv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 3065d76..47368b7 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -88,7 +88,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, HvSintRoute *sint_route; int r, gsi; - sint_route = g_malloc0(sizeof(*sint_route)); + sint_route = g_new0(HvSintRoute, 1); r = event_notifier_init(&sint_route->sint_set_notifier, false); if (r) { goto err; From patchwork Thu Oct 18 20:31:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="r0xTxfSn"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhhr3ZXFz9s5c for ; Fri, 19 Oct 2018 08:17:48 +1100 (AEDT) Received: from localhost ([::1]:44753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFft-0003gS-Ur for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:17:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyU-0007Y6-NN for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyP-0006TF-7Q for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:54 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:38253) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyO-0006Qn-VM for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:49 -0400 Received: by mail-wr1-x431.google.com with SMTP id a13-v6so35115883wrt.5 for ; Thu, 18 Oct 2018 13:32: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=BkystSI0CRGrpUqLwc5QS/9WLvo+X84cbqkvItspGKM=; b=r0xTxfSnUgHqGH1F+O8ARZXkf5ZxMPAHI3GfTZMXMUG2A17V4S1tfMRnw+LzE3MA7R tE6ijXBqL7Ho5pYEBIdpadvJHgAWjDSGU57Ls1Mu/0F9y0GjGBlpIvhj85fGkiV1i5Ci lhC80aAzXgxt95xTf4In1YG3xZ8EAQRrvnN+850/1Z3nnTaGh5OJC9pqjuNReBKM3iON RDh7nwps8Wri6IRGP13bTtTTKsFvWP/mZI4UvfiMGa83qD0vZ3wM4L8lp06azr51yRx2 5OcBFECN5UZvI857M6FjkONbuLn0SCU1qSFkUypMI9A5GEoZhVPqp3sVtb5rp+P9BFwQ plWQ== 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=BkystSI0CRGrpUqLwc5QS/9WLvo+X84cbqkvItspGKM=; b=tPmEkF6KGMnFmr8TcJvEvQ5H6lDrZUl4/mcDGRPPpIFHZkreH0OqtKtgAlelOURCvC 61Ar6FcSnBepTYpaXRbHpCf125hfR1GpxN/wzCXhBU0P6A9Eu1Z4TGGmgc0xSwTecR54 uvdSJIaVZjOpxvcgdOFDCgph19xw8BuF/IJXFlXDI/Io4DsCQYGJ6LIv6w8akDs1PlqN 7/KWtKLOlQ7cw9ThRvwyXdF6kYEMYDf+SdQQ5aPkgk9d28/Vx6FitqGh1m+immHWCUnG MxGDs4VzFKm+zmKP4fytUPlLDR9Laj2N443jA0lPZxDLKw1AJHPx+TBx2S1eHIlh6V7c sCHA== X-Gm-Message-State: ABuFfog1pOJq8sB0YSIED1+TmbWSFk0anV3I8s9ce24JI+EaIvyrJX68 4bh6MFogmg6ZNE6HUW9M1qsC+Uun X-Google-Smtp-Source: ACcGV63gKiOtzbEdiShZVgFc8F8HecVn6FSSX6Z8ZyWlj5E44q8/woI+iJd3Q0aYLWGgtmthPaRHoQ== X-Received: by 2002:adf:c793:: with SMTP id l19-v6mr30179506wrg.230.1539894767243; Thu, 18 Oct 2018 13:32:47 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:54 +0200 Message-Id: <1539894735-14232-28-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::431 Subject: [Qemu-devel] [PULL 27/48] hyperv: synic: only setup ack notifier if there's a callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan There's no point setting up an sint ack notifier if no callback is specified. Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-5-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- target/i386/hyperv.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 47368b7..acdb0ca 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -77,15 +77,14 @@ static void kvm_hv_sint_ack_handler(EventNotifier *notifier) HvSintRoute *sint_route = container_of(notifier, HvSintRoute, sint_ack_notifier); event_notifier_test_and_clear(notifier); - if (sint_route->sint_ack_clb) { - sint_route->sint_ack_clb(sint_route); - } + sint_route->sint_ack_clb(sint_route); } HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, HvSintAckClb sint_ack_clb) { HvSintRoute *sint_route; + EventNotifier *ack_notifier; int r, gsi; sint_route = g_new0(HvSintRoute, 1); @@ -94,13 +93,15 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, goto err; } - r = event_notifier_init(&sint_route->sint_ack_notifier, false); - if (r) { - goto err_sint_set_notifier; - } + ack_notifier = sint_ack_clb ? &sint_route->sint_ack_notifier : NULL; + if (ack_notifier) { + r = event_notifier_init(ack_notifier, false); + if (r) { + goto err_sint_set_notifier; + } - event_notifier_set_handler(&sint_route->sint_ack_notifier, - kvm_hv_sint_ack_handler); + event_notifier_set_handler(ack_notifier, kvm_hv_sint_ack_handler); + } gsi = kvm_irqchip_add_hv_sint_route(kvm_state, vp_index, sint); if (gsi < 0) { @@ -109,7 +110,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, r = kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, &sint_route->sint_set_notifier, - &sint_route->sint_ack_notifier, gsi); + ack_notifier, gsi); if (r) { goto err_irqfd; } @@ -123,8 +124,10 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, err_irqfd: kvm_irqchip_release_virq(kvm_state, gsi); err_gsi: - event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); - event_notifier_cleanup(&sint_route->sint_ack_notifier); + if (ack_notifier) { + event_notifier_set_handler(ack_notifier, NULL); + event_notifier_cleanup(ack_notifier); + } err_sint_set_notifier: event_notifier_cleanup(&sint_route->sint_set_notifier); err: @@ -139,8 +142,10 @@ void kvm_hv_sint_route_destroy(HvSintRoute *sint_route) &sint_route->sint_set_notifier, sint_route->gsi); kvm_irqchip_release_virq(kvm_state, sint_route->gsi); - event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); - event_notifier_cleanup(&sint_route->sint_ack_notifier); + if (sint_route->sint_ack_clb) { + event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); + event_notifier_cleanup(&sint_route->sint_ack_notifier); + } event_notifier_cleanup(&sint_route->sint_set_notifier); g_free(sint_route); } From patchwork Thu Oct 18 20:31:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oscpMT66"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhxj0vsmz9sBj for ; Fri, 19 Oct 2018 08:28:57 +1100 (AEDT) Received: from localhost ([::1]:44829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFqg-0006eG-L2 for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:28:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyU-0007Y3-Lx for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyP-0006TZ-KJ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:54 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:39182) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyP-0006Sa-DN for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:49 -0400 Received: by mail-wm1-x344.google.com with SMTP id y144-v6so1607814wmd.4 for ; Thu, 18 Oct 2018 13:32:49 -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=txS41myOIyl811WC3S+skfHClt0Kr8UZe0jNMisAZYk=; b=oscpMT666VYkU/08KCwNp4FH+k4bAk/709THIr0fSbgmP0507auI4IYjMbbc6YLka5 Zn88DB2fdMUPK+HviUy819ImMcLmugimqjfWCDpG0RceHPi1KESYE2O84yr5jZaSDZ1X NHwWRHzrPbwH++Ev7Q0dJEXKEZjcLvPF5vVckbN5RE1RoZo5earvqnMTGvvcl+GW5Do6 rD5P6mCdzsLsplztSk0/3pXBxUcxGLA4LUjtPVAuV0/TynbLB3zkqBHIUvIBeTzai1/6 wqriJj7PcdqquLfc7Xf7lnub7UIBrQtYZSsPkeSI6ZbFwnN+bMf8zq7aEyUrqogoj7qK 8jSA== 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=txS41myOIyl811WC3S+skfHClt0Kr8UZe0jNMisAZYk=; b=sQpoRYvGAAVolMXBoscly4vw1h7q0G0AvqLuiB39/xZgBDZt6mO9P4dAcU1vtynhvY DRSclzUUOpv1YJaZ12PANxsk87crzdglsiRpRMDuthvJ+Jst22TaH3q6J4ekmImilvcb 1HslUWbkZxIME5Fm9cxwWCy2zh+ipA6hI/TMvvYpfNAXOIkaOHuuOI9YGFxYeePckxrP +wXlzsibpVGoGn7+WWBLsrMZvOUvSXphHVYqKHweymBEg9PwjQsTqRPoT3SqsDN0R8nv I+jjS00wmhE0F5N+rCtFjMUaFSKx5xs+X9LOP36kta9H/o+z/os95bLGy2OBIt01KE09 uEDg== X-Gm-Message-State: ABuFfoicWVu51O9kgVOt14NMaoohdjMv8mEdMyo8p0yFu7K0R+foI+Xz oJd2n6kEg3KvDdY7XduiQb1efICG X-Google-Smtp-Source: ACcGV61+UGkZwMBLCJdt3XWdeLWIn9BvzqQWWg2k/9IeMF2Pw7NZ1B8TU5ymzVWTWASVv2BF47whHg== X-Received: by 2002:a1c:a683:: with SMTP id p125-v6mr1962617wme.24.1539894768085; Thu, 18 Oct 2018 13:32:48 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:55 +0200 Message-Id: <1539894735-14232-29-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::344 Subject: [Qemu-devel] [PULL 28/48] hyperv: allow passing arbitrary data to sint ack callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Make sint ack callback accept an opaque pointer, that is stored on sint_route at creation time. This allows for more convenient interaction with the callback. Besides, nothing outside hyperv.c should need to know the layout of HvSintRoute fields any more so its declaration can be removed from the header. Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-6-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/misc/hyperv_testdev.c | 2 +- target/i386/hyperv.c | 16 ++++++++++++++-- target/i386/hyperv.h | 15 +++------------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 7291fb1..1f32d3c 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -52,7 +52,7 @@ static void sint_route_create(HypervTestDev *dev, sint_route->vp_index = vp_index; sint_route->sint = sint; - sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL); + sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL, NULL); assert(sint_route->sint_route); QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le); diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index acdb0ca..11fd1ad 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -16,6 +16,16 @@ #include "hyperv.h" #include "hyperv-proto.h" +struct HvSintRoute { + uint32_t sint; + uint32_t vp_index; + int gsi; + EventNotifier sint_set_notifier; + EventNotifier sint_ack_notifier; + HvSintAckClb sint_ack_clb; + void *sint_ack_clb_data; +}; + uint32_t hyperv_vp_index(X86CPU *cpu) { return CPU(cpu)->cpu_index; @@ -77,11 +87,12 @@ static void kvm_hv_sint_ack_handler(EventNotifier *notifier) HvSintRoute *sint_route = container_of(notifier, HvSintRoute, sint_ack_notifier); event_notifier_test_and_clear(notifier); - sint_route->sint_ack_clb(sint_route); + sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); } HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb) + HvSintAckClb sint_ack_clb, + void *sint_ack_clb_data) { HvSintRoute *sint_route; EventNotifier *ack_notifier; @@ -116,6 +127,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, } sint_route->gsi = gsi; sint_route->sint_ack_clb = sint_ack_clb; + sint_route->sint_ack_clb_data = sint_ack_clb_data; sint_route->vp_index = vp_index; sint_route->sint = sint; diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 00c9b45..ab99047 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -16,24 +16,15 @@ #include "cpu.h" #include "sysemu/kvm.h" -#include "qemu/event_notifier.h" typedef struct HvSintRoute HvSintRoute; -typedef void (*HvSintAckClb)(HvSintRoute *sint_route); - -struct HvSintRoute { - uint32_t sint; - uint32_t vp_index; - int gsi; - EventNotifier sint_set_notifier; - EventNotifier sint_ack_notifier; - HvSintAckClb sint_ack_clb; -}; +typedef void (*HvSintAckClb)(void *data); int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb); + HvSintAckClb sint_ack_clb, + void *sint_ack_clb_data); void kvm_hv_sint_route_destroy(HvSintRoute *sint_route); From patchwork Thu Oct 18 20:31:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eYzpghD5"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhmQ0c0Tz9sBj for ; Fri, 19 Oct 2018 08:20:54 +1100 (AEDT) Received: from localhost ([::1]:44772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFit-0007TD-56 for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:20:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyU-0007Y4-M3 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyQ-0006U8-HY for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:54 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:41685) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyQ-0006Tg-AM for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:50 -0400 Received: by mail-wr1-x443.google.com with SMTP id q7-v6so7266343wrr.8 for ; Thu, 18 Oct 2018 13:32:50 -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=Crc8hXh6fuKllNJ5wmjW4kipXdhzcje7NjwDCMhKnrI=; b=eYzpghD5+WI2Y7RXSCgh6PMk9HaZqHygdS8IvG9aEXIU+yQ0sha7xclDeNLV6Y5Em8 TfTnEDqzdO3UeQ3hRF2EeRcAMDLbAcdMDz30jXCx23dUTUtw1OjMcaMOFkyQZ5kR/lKX CFYI3J8X1a4Iu9IJPIe4ccLOkxnC+lhML+QRRmc4XNMZ7LEj9YPORSvSiaRvLd/LjPgr c8uKNRE8shjZoUHJF6Sh0ZtYwTxKesRwYDDR2fdk2DozehIHoqJMRhc7yjOtdPkylY+X TY/lVtkqdBBpPqg2jTikhPBchehGiHs/RoBljp/flqGnDPdC12t+ghyftTqiPQBghazW Ns1g== 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=Crc8hXh6fuKllNJ5wmjW4kipXdhzcje7NjwDCMhKnrI=; b=kCCQTfQWJcnSHFIe7B7pDfFQHG74AowqWpp6PfKV6yIYeqN3XT0GNU20Nqkf+2pkh1 I2GKxoVKw7vnojcbZuzdkFDEOCBSLnT30mNnd5wnr+jQVM3jLMIy+DmVbN6rlqvkvusc 35haYte++yhGV+6RfFceB/zRp1cYk0fASfcsJJMkY66Yr9rF048b9mU20HSyk2WdHctb NdmLEcEVT21n2Iu7pUJSFKgj3YZM/Pt8NuU8SyGNwEFZedD5CbVZJ6MbiggpGFMGzdPq evjwbLll6gWKbHwzHF8+jhfTDe4c67erWNI9Bumxj2c+lwkOgWj5xsfPXrCax/LSOQ6g KR3w== X-Gm-Message-State: ABuFfog6r720ROX8JdqOn3jj59aqq0NBmYRcBMwf6V1CMyDtES1yBpA/ ELicB8tJViTPQbObcXDcs7i0V40x X-Google-Smtp-Source: ACcGV60VWFyBckaedG3mpGesH6ICmOrBeZBX10f+s/5PiG3SminGscNhnf+at82BPwjHZROaD0XOlg== X-Received: by 2002:adf:fec9:: with SMTP id q9-v6mr27754908wrs.164.1539894769168; Thu, 18 Oct 2018 13:32:49 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:56 +0200 Message-Id: <1539894735-14232-30-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::443 Subject: [Qemu-devel] [PULL 29/48] hyperv: address HvSintRoute by X86CPU pointer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Use X86CPU pointer to refer to the respective HvSintRoute instead of vp_index. This is more convenient and also paves the way for future enhancements. Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-7-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- target/i386/hyperv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 11fd1ad..0ce8a7a 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -18,7 +18,7 @@ struct HvSintRoute { uint32_t sint; - uint32_t vp_index; + X86CPU *cpu; int gsi; EventNotifier sint_set_notifier; EventNotifier sint_ack_notifier; @@ -97,6 +97,12 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, HvSintRoute *sint_route; EventNotifier *ack_notifier; int r, gsi; + X86CPU *cpu; + + cpu = hyperv_find_vcpu(vp_index); + if (!cpu) { + return NULL; + } sint_route = g_new0(HvSintRoute, 1); r = event_notifier_init(&sint_route->sint_set_notifier, false); @@ -128,7 +134,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, sint_route->gsi = gsi; sint_route->sint_ack_clb = sint_ack_clb; sint_route->sint_ack_clb_data = sint_ack_clb_data; - sint_route->vp_index = vp_index; + sint_route->cpu = cpu; sint_route->sint = sint; return sint_route; From patchwork Thu Oct 18 20:31:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="usXoxc9T"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhzk3kjQz9sBj for ; Fri, 19 Oct 2018 08:30:42 +1100 (AEDT) Received: from localhost ([::1]:44839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFsN-0007yZ-V8 for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:30:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyU-0007Y5-NM for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyR-0006VC-PO for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:54 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:34195) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyR-0006UL-Hr for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:51 -0400 Received: by mail-wr1-x431.google.com with SMTP id l6-v6so34705513wrt.1 for ; Thu, 18 Oct 2018 13:32:51 -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=Gl5IfXSxMqWRiof4r+tdOTzPmAW5QBMoGSHXsK25mxI=; b=usXoxc9T3QKHtpW/MolNlG7g1bxeXHzA3dQCW2yw+Pj/FyynHhAnuS0RQortymhnWm DhB+vnylHiwM9kaMCxLL/MFHjjFF/Gzt7lpuOztoxIgea5XBR+8ISaP7p9+mbXwU5v2Y 8byD5oXNz7PT1fo4hxyI6y6vBKvFBKnZTvm9Rdg2B6Se5LcUVoRtDCVBLHjm4Gujxl6/ yBBVFqbUlTzB2hdZ6/mQ0Ps6svkfFYwvHGs/MxkIwN7HsBehqypN81NxU2n5qGmCH9yn Mu44HqNIX1nnJuUWj76e1KR1y2t18BbpDG1fR2ZjT3d/A/LjBBBGQGSw8cBsG2CEHfSV rV2Q== 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=Gl5IfXSxMqWRiof4r+tdOTzPmAW5QBMoGSHXsK25mxI=; b=E3fc0P4ma+S4mVN2TO97uAhKIjRuzhWB+aiyjhoMwtXSlpdeA50Gk3gnoegBRSly00 zjEDmI2wMErTOB6lOss9QcFTWZlRQKAsnzrIRVIVz04SH3VDkrqMz2WQPBYKusgYL5Gp tvvIIDCrWPuf5Cnicd53N2UgeMfZXrrUWWuzlDjnM2E7Yi6ZbY1Z0Z09VVwss3oxotYe Bizi+a9OWKinilZRIDjhTZ4BXfeLRaBJKdmzM30fvbUJcixph3RIhik6PXu5CeyAQfrU 2PMkLyM8/DXgJVf3GDzh6IN4EjP5UdxkzsnzXPjdGwYih7A2oJl4/WJZeJ4dwL1W/uxM rfAQ== X-Gm-Message-State: ABuFfojgOsP5aPC/x8kCklQefSqlInCzxYiFAiAo9OPigtxCQoVih4FH XIwczcs5FbKpht2w86/Sd0JQsAla X-Google-Smtp-Source: ACcGV61a4yKrENnGLDJ/bS+Jga5JxTq+9CoERpc+pE534lvW33KucSUw07nJk20BsRWFlSd37FfsgA== X-Received: by 2002:a5d:480b:: with SMTP id l11-v6mr31957979wrq.28.1539894770018; Thu, 18 Oct 2018 13:32:50 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:57 +0200 Message-Id: <1539894735-14232-31-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::431 Subject: [Qemu-devel] [PULL 30/48] hyperv: make HvSintRoute reference-counted X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Multiple entities (e.g. VMBus devices) can use the same SINT route. To make their lives easier in maintaining SINT route ownership, make it reference-counted. Adjust the respective API names accordingly. Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-8-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/misc/hyperv_testdev.c | 4 ++-- target/i386/hyperv.c | 25 +++++++++++++++++++++---- target/i386/hyperv.h | 10 +++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 1f32d3c..dbf4e7e 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -52,7 +52,7 @@ static void sint_route_create(HypervTestDev *dev, sint_route->vp_index = vp_index; sint_route->sint = sint; - sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL, NULL); + sint_route->sint_route = hyperv_sint_route_new(vp_index, sint, NULL, NULL); assert(sint_route->sint_route); QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le); @@ -79,7 +79,7 @@ static void sint_route_destroy(HypervTestDev *dev, sint_route = sint_route_find(dev, vp_index, sint); QLIST_REMOVE(sint_route, le); - kvm_hv_sint_route_destroy(sint_route->sint_route); + hyperv_sint_route_unref(sint_route->sint_route); g_free(sint_route); } diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 0ce8a7a..4d8ef6f 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -24,6 +24,7 @@ struct HvSintRoute { EventNotifier sint_ack_notifier; HvSintAckClb sint_ack_clb; void *sint_ack_clb_data; + unsigned refcount; }; uint32_t hyperv_vp_index(X86CPU *cpu) @@ -90,9 +91,9 @@ static void kvm_hv_sint_ack_handler(EventNotifier *notifier) sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); } -HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data) +HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, + HvSintAckClb sint_ack_clb, + void *sint_ack_clb_data) { HvSintRoute *sint_route; EventNotifier *ack_notifier; @@ -136,6 +137,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, sint_route->sint_ack_clb_data = sint_ack_clb_data; sint_route->cpu = cpu; sint_route->sint = sint; + sint_route->refcount = 1; return sint_route; @@ -154,8 +156,23 @@ err: return NULL; } -void kvm_hv_sint_route_destroy(HvSintRoute *sint_route) +void hyperv_sint_route_ref(HvSintRoute *sint_route) { + sint_route->refcount++; +} + +void hyperv_sint_route_unref(HvSintRoute *sint_route) +{ + if (!sint_route) { + return; + } + + assert(sint_route->refcount > 0); + + if (--sint_route->refcount) { + return; + } + kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &sint_route->sint_set_notifier, sint_route->gsi); diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index ab99047..cdf44a7 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -22,11 +22,11 @@ typedef void (*HvSintAckClb)(void *data); int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); -HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data); - -void kvm_hv_sint_route_destroy(HvSintRoute *sint_route); +HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, + HvSintAckClb sint_ack_clb, + void *sint_ack_clb_data); +void hyperv_sint_route_ref(HvSintRoute *sint_route); +void hyperv_sint_route_unref(HvSintRoute *sint_route); int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route); From patchwork Thu Oct 18 20:31:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986297 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SvPxK/n0"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhSw4KLpz9s8J for ; Fri, 19 Oct 2018 08:07:28 +1100 (AEDT) Received: from localhost ([::1]:44697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFVu-0003WK-36 for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:07:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyY-0007bk-7h for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyV-0006XX-1Q for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:58 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42663) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyU-0006V9-Kr for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:54 -0400 Received: by mail-wr1-x441.google.com with SMTP id r17-v6so2746073wrt.9 for ; Thu, 18 Oct 2018 13:32:52 -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=bgWfMnIsTzSOJi3/V6bjpFv5Z2shBVMJCGBBxv4OtZM=; b=SvPxK/n0CgJBA0NuT7ybBzHIXKnNz1RQ4MwB7/AGrjVvLmvKHgL0X3HyelAAsdjRvX HCLzYAueOnlVCuVKZytHuWKrzdxSXPuYy2p/INzh6aruvCqRYrkCcOIuytwEZipISp4e 2J2JpX2si6G+C/k5YF1IpkcVm+SN0w3NG6S/o+Sf+gtR3V0NsQmexf3HVCRfizgh2w49 lufb0Q5B+ccTU2iwwXPG3+TXcTEyArPa0Q/1SMiDsrDRNOYdW9GIt5h3sprqmOa2BJcr cLbG17beh8zOItvltYn8Iox4qrXKJbSDTqD5jHlvoICNct+FDLlPkOqZGb1zshHYvCrv qExQ== 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=bgWfMnIsTzSOJi3/V6bjpFv5Z2shBVMJCGBBxv4OtZM=; b=kIIMU8tgoIoDx2ksq8s+Kjt43Ej5wiW5N5rUCfUNgh4a4IfCGDM7HDfPy2UqTBIa4L Q+kJvQ5Szggn540jDAyyEByQBcYYxUDi2WpUkPLeflmLbGUFDmNdTyGGeeuHmfpGS9Vd vp8kuQ3gqkdA/x8rwURaVejYvv1Oev7Do57bxFrnba6OQlzOjcSJ/3n2lzmZ68YmC5mQ SjLYiVUx/QCqOAUfbvn6g6nbCvdEDRo+KUsvEdq5JmYUq078VfT6EUYFNwtdCBgMCqRS RreIi9FWh6IfPUVpObonOqXRGEDp3pMlRQWItD6zna0ByalkMwbM5rAWyKUSfWUGn0aW qQ4g== X-Gm-Message-State: ABuFfohWnPAZWVy41LD0R2LbUcDIxu1Fopm4XdQO4DDwPcbNfFyHNIaA 66Z5Ids4xQpZRz2FZcIcxdG8Ps4s X-Google-Smtp-Source: ACcGV60dvj3Osn2yYgcYXSWaqptQTdz2bNoQl0Vhp0vT5gwaf/5DUc+VyPLbkEeEbaK6m+XjrBn/gA== X-Received: by 2002:adf:f90b:: with SMTP id b11-v6mr30991380wrr.307.1539894771019; Thu, 18 Oct 2018 13:32:51 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:58 +0200 Message-Id: <1539894735-14232-32-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::441 Subject: [Qemu-devel] [PULL 31/48] hyperv: rename kvm_hv_sint_route_set_sint X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan There's nothing kvm-specific in it so follow the suite and replace "kvm_hv" prefix with "hyperv". Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-9-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/misc/hyperv_testdev.c | 2 +- target/i386/hyperv.c | 2 +- target/i386/hyperv.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index dbf4e7e..33bbd28 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -90,7 +90,7 @@ static void sint_route_set_sint(HypervTestDev *dev, sint_route = sint_route_find(dev, vp_index, sint); - kvm_hv_sint_route_set_sint(sint_route->sint_route); + hyperv_sint_route_set_sint(sint_route->sint_route); } static uint64_t hv_test_dev_read(void *opaque, hwaddr addr, unsigned size) diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 4d8ef6f..fc537e7 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -185,7 +185,7 @@ void hyperv_sint_route_unref(HvSintRoute *sint_route) g_free(sint_route); } -int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route) +int hyperv_sint_route_set_sint(HvSintRoute *sint_route) { return event_notifier_set(&sint_route->sint_set_notifier); } diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index cdf44a7..59e9f9a 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -28,7 +28,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, void hyperv_sint_route_ref(HvSintRoute *sint_route); void hyperv_sint_route_unref(HvSintRoute *sint_route); -int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route); +int hyperv_sint_route_set_sint(HvSintRoute *sint_route); uint32_t hyperv_vp_index(X86CPU *cpu); X86CPU *hyperv_find_vcpu(uint32_t vp_index); From patchwork Thu Oct 18 20:31:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GoXMYMVb"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhct2B0kz9s5c for ; Fri, 19 Oct 2018 08:14:22 +1100 (AEDT) Received: from localhost ([::1]:44734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFcZ-0000gn-QJ for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:14:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyY-0007bm-9J for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyV-0006Y6-FZ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:58 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:44274) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyU-0006Vx-TT for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:55 -0400 Received: by mail-wr1-x42a.google.com with SMTP id 63-v6so35061259wra.11 for ; Thu, 18 Oct 2018 13:32:53 -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=TXi4CpjJbWC+LGJfu1XtcYa1aDs1KqTq7NFG2bhRFKA=; b=GoXMYMVbmDoS9TIlBLmubdo0zTEtxzHS0aJRYBMjyPjv2JLROiuZjnE+KGN2NNNl7J sH90WXl7j7Xx9pv4do8w9lnTXjVB8Zt4ADqX45CcJVXoevL69zHVKzQZ7C0k88y3/sJd t9I+JbqUdofCs9ddtJHPavZPLqJHvGbriioTdqahpltHNAHTWGjGJIBgTq99rPmd8vlp Iyah4qFH5mL8WvZYQq6k2//tQJZlsI3oQ4Rh5fvK/m0Xu/I/sdc+g+ri3d6EdBegaCCK dFPc07ePatSTd6XChcTj/yiHe7Jx22d9jJARwt5K+Pj2nFPMqcvBkk5aISoMF2gUQVYl ZlEw== 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=TXi4CpjJbWC+LGJfu1XtcYa1aDs1KqTq7NFG2bhRFKA=; b=CjoZGYXffAAI73qm7J/9fZ6/iVAqNGls6/G8gm73tbHd7aZAJSOZPDjRMNKHFE/+p/ P2xzK70YJmj9lGZDu/MhbdG8wpYJvIwbVXYUtOJTAOGszu82igApRIczBef/4++SxTK3 QnHYjviwcFV7+FytaL/zycW8gR9zMs+L3Frhhwr6RnDDzdsR3uvbLc+sPE8iXEYGZulo FfduWQWfcdyGBMT8Cldk8R5oEE/hlicdFZ8xBfj8F76zup+amdRff+1d8NvnPN52HT78 L9CJkyl7+NC8pDTHSueu5afMtd3S7V71Dk060ci6pqvuDeLCAIHyE4Sm3rooOvczOp/c pSMw== X-Gm-Message-State: ABuFfogNM+EZfCoP7FKUZmWvyaLjFDRqfQTNWl9n4Nn7EZP3wtKVd8/4 kQ279wIE/yx5tVEgidlkSHup4RMW X-Google-Smtp-Source: ACcGV621nn/uHnTO4vLmmIuTutWBpuINpNUnbWWM67BorvJl8r23FW8h6mnElqL0G7xYpjq4+ioaOA== X-Received: by 2002:adf:e0c9:: with SMTP id e9-v6mr31188753wri.199.1539894772078; Thu, 18 Oct 2018 13:32:52 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:59 +0200 Message-Id: <1539894735-14232-33-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::42a Subject: [Qemu-devel] [PULL 32/48] hyperv: split hyperv-proto.h into x86 and arch-independent parts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Some parts of the Hyper-V hypervisor-guest interface appear to be target-independent, so move them into a proper header. Not that Hyper-V ARM64 emulation is around the corner but it seems more conveninent to have most of Hyper-V and VMBus target-independent, and allows to avoid conflicts with inclusion of arch-specific headers down the road in VMBus implementation. Signed-off-by: Roman Kagan Message-Id: <20180921082041.29380-2-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- include/hw/hyperv/hyperv-proto.h | 129 +++++++++++++++++++++++++++++++++++++++ target/i386/hyperv-proto.h | 115 +--------------------------------- 2 files changed, 132 insertions(+), 112 deletions(-) create mode 100644 include/hw/hyperv/hyperv-proto.h diff --git a/include/hw/hyperv/hyperv-proto.h b/include/hw/hyperv/hyperv-proto.h new file mode 100644 index 0000000..2dc78ee --- /dev/null +++ b/include/hw/hyperv/hyperv-proto.h @@ -0,0 +1,129 @@ +/* + * Definitions for Hyper-V guest/hypervisor interaction + * + * Copyright (c) 2017-2018 Virtuozzo International GmbH. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_HYPERV_HYPERV_PROTO_H +#define HW_HYPERV_HYPERV_PROTO_H + +#include "qemu/bitmap.h" + +/* + * Hypercall status code + */ +#define HV_STATUS_SUCCESS 0 +#define HV_STATUS_INVALID_HYPERCALL_CODE 2 +#define HV_STATUS_INVALID_HYPERCALL_INPUT 3 +#define HV_STATUS_INVALID_ALIGNMENT 4 +#define HV_STATUS_INVALID_PARAMETER 5 +#define HV_STATUS_INSUFFICIENT_MEMORY 11 +#define HV_STATUS_INVALID_CONNECTION_ID 18 +#define HV_STATUS_INSUFFICIENT_BUFFERS 19 + +/* + * Hypercall numbers + */ +#define HV_POST_MESSAGE 0x005c +#define HV_SIGNAL_EVENT 0x005d +#define HV_HYPERCALL_FAST (1u << 16) + +/* + * Message size + */ +#define HV_MESSAGE_PAYLOAD_SIZE 240 + +/* + * Message types + */ +#define HV_MESSAGE_NONE 0x00000000 +#define HV_MESSAGE_VMBUS 0x00000001 +#define HV_MESSAGE_UNMAPPED_GPA 0x80000000 +#define HV_MESSAGE_GPA_INTERCEPT 0x80000001 +#define HV_MESSAGE_TIMER_EXPIRED 0x80000010 +#define HV_MESSAGE_INVALID_VP_REGISTER_VALUE 0x80000020 +#define HV_MESSAGE_UNRECOVERABLE_EXCEPTION 0x80000021 +#define HV_MESSAGE_UNSUPPORTED_FEATURE 0x80000022 +#define HV_MESSAGE_EVENTLOG_BUFFERCOMPLETE 0x80000040 +#define HV_MESSAGE_X64_IOPORT_INTERCEPT 0x80010000 +#define HV_MESSAGE_X64_MSR_INTERCEPT 0x80010001 +#define HV_MESSAGE_X64_CPUID_INTERCEPT 0x80010002 +#define HV_MESSAGE_X64_EXCEPTION_INTERCEPT 0x80010003 +#define HV_MESSAGE_X64_APIC_EOI 0x80010004 +#define HV_MESSAGE_X64_LEGACY_FP_ERROR 0x80010005 + +/* + * Message flags + */ +#define HV_MESSAGE_FLAG_PENDING 0x1 + +/* + * Number of synthetic interrupts + */ +#define HV_SINT_COUNT 16 + +/* + * Event flags number per SINT + */ +#define HV_EVENT_FLAGS_COUNT (256 * 8) + +/* + * Connection id valid bits + */ +#define HV_CONNECTION_ID_MASK 0x00ffffff + +/* + * Input structure for POST_MESSAGE hypercall + */ +struct hyperv_post_message_input { + uint32_t connection_id; + uint32_t _reserved; + uint32_t message_type; + uint32_t payload_size; + uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE]; +}; + +/* + * Input structure for SIGNAL_EVENT hypercall + */ +struct hyperv_signal_event_input { + uint32_t connection_id; + uint16_t flag_number; + uint16_t _reserved_zero; +}; + +/* + * SynIC message structures + */ +struct hyperv_message_header { + uint32_t message_type; + uint8_t payload_size; + uint8_t message_flags; /* HV_MESSAGE_FLAG_XX */ + uint8_t _reserved[2]; + uint64_t sender; +}; + +struct hyperv_message { + struct hyperv_message_header header; + uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE]; +}; + +struct hyperv_message_page { + struct hyperv_message slot[HV_SINT_COUNT]; +}; + +/* + * SynIC event flags structures + */ +struct hyperv_event_flags { + DECLARE_BITMAP(flags, HV_EVENT_FLAGS_COUNT); +}; + +struct hyperv_event_flags_page { + struct hyperv_event_flags slot[HV_SINT_COUNT]; +}; + +#endif diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h index 87f36d1..8c572cd 100644 --- a/target/i386/hyperv-proto.h +++ b/target/i386/hyperv-proto.h @@ -1,7 +1,7 @@ /* - * Definitions for Hyper-V guest/hypervisor interaction + * Definitions for Hyper-V guest/hypervisor interaction - x86-specific part * - * Copyright (C) 2017 Parallels International GmbH + * Copyright (c) 2017-2018 Virtuozzo International GmbH. * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -10,7 +10,7 @@ #ifndef TARGET_I386_HYPERV_PROTO_H #define TARGET_I386_HYPERV_PROTO_H -#include "qemu/bitmap.h" +#include "hw/hyperv/hyperv-proto.h" #define HV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000 #define HV_CPUID_INTERFACE 0x40000001 @@ -139,25 +139,6 @@ #define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108 /* - * Hypercall status code - */ -#define HV_STATUS_SUCCESS 0 -#define HV_STATUS_INVALID_HYPERCALL_CODE 2 -#define HV_STATUS_INVALID_HYPERCALL_INPUT 3 -#define HV_STATUS_INVALID_ALIGNMENT 4 -#define HV_STATUS_INVALID_PARAMETER 5 -#define HV_STATUS_INSUFFICIENT_MEMORY 11 -#define HV_STATUS_INVALID_CONNECTION_ID 18 -#define HV_STATUS_INSUFFICIENT_BUFFERS 19 - -/* - * Hypercall numbers - */ -#define HV_POST_MESSAGE 0x005c -#define HV_SIGNAL_EVENT 0x005d -#define HV_HYPERCALL_FAST (1u << 16) - -/* * Hypercall MSR bits */ #define HV_HYPERCALL_ENABLE (1u << 0) @@ -166,7 +147,6 @@ * Synthetic interrupt controller definitions */ #define HV_SYNIC_VERSION 1 -#define HV_SINT_COUNT 16 #define HV_SYNIC_ENABLE (1u << 0) #define HV_SIMP_ENABLE (1u << 0) #define HV_SIEFP_ENABLE (1u << 0) @@ -176,94 +156,5 @@ #define HV_STIMER_COUNT 4 -/* - * Message size - */ -#define HV_MESSAGE_PAYLOAD_SIZE 240 - -/* - * Message types - */ -#define HV_MESSAGE_NONE 0x00000000 -#define HV_MESSAGE_VMBUS 0x00000001 -#define HV_MESSAGE_UNMAPPED_GPA 0x80000000 -#define HV_MESSAGE_GPA_INTERCEPT 0x80000001 -#define HV_MESSAGE_TIMER_EXPIRED 0x80000010 -#define HV_MESSAGE_INVALID_VP_REGISTER_VALUE 0x80000020 -#define HV_MESSAGE_UNRECOVERABLE_EXCEPTION 0x80000021 -#define HV_MESSAGE_UNSUPPORTED_FEATURE 0x80000022 -#define HV_MESSAGE_EVENTLOG_BUFFERCOMPLETE 0x80000040 -#define HV_MESSAGE_X64_IOPORT_INTERCEPT 0x80010000 -#define HV_MESSAGE_X64_MSR_INTERCEPT 0x80010001 -#define HV_MESSAGE_X64_CPUID_INTERCEPT 0x80010002 -#define HV_MESSAGE_X64_EXCEPTION_INTERCEPT 0x80010003 -#define HV_MESSAGE_X64_APIC_EOI 0x80010004 -#define HV_MESSAGE_X64_LEGACY_FP_ERROR 0x80010005 - -/* - * Message flags - */ -#define HV_MESSAGE_FLAG_PENDING 0x1 - -/* - * Event flags number per SINT - */ -#define HV_EVENT_FLAGS_COUNT (256 * 8) - -/* - * Connection id valid bits - */ -#define HV_CONNECTION_ID_MASK 0x00ffffff - -/* - * Input structure for POST_MESSAGE hypercall - */ -struct hyperv_post_message_input { - uint32_t connection_id; - uint32_t _reserved; - uint32_t message_type; - uint32_t payload_size; - uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE]; -}; - -/* - * Input structure for SIGNAL_EVENT hypercall - */ -struct hyperv_signal_event_input { - uint32_t connection_id; - uint16_t flag_number; - uint16_t _reserved_zero; -}; - -/* - * SynIC message structures - */ -struct hyperv_message_header { - uint32_t message_type; - uint8_t payload_size; - uint8_t message_flags; /* HV_MESSAGE_FLAG_XX */ - uint8_t _reserved[2]; - uint64_t sender; -}; - -struct hyperv_message { - struct hyperv_message_header header; - uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE]; -}; - -struct hyperv_message_page { - struct hyperv_message slot[HV_SINT_COUNT]; -}; - -/* - * SynIC event flags structures - */ -struct hyperv_event_flags { - DECLARE_BITMAP(flags, HV_EVENT_FLAGS_COUNT); -}; - -struct hyperv_event_flags_page { - struct hyperv_event_flags slot[HV_SINT_COUNT]; -}; #endif From patchwork Thu Oct 18 20:32:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fV00wJTS"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhqt1Qb5z9sC2 for ; Fri, 19 Oct 2018 08:23:54 +1100 (AEDT) Received: from localhost ([::1]:44796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFln-0002LC-NP for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:23:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyY-0007bl-9H for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyV-0006Xu-Cc for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:58 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:39911) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyV-0006Wr-1r for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:55 -0400 Received: by mail-wr1-x429.google.com with SMTP id 61-v6so35110496wrb.6 for ; Thu, 18 Oct 2018 13:32:54 -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=3jMpBjW2RjjaneKFCh4VOi3MYzbeg1SPv8QfUhGFqak=; b=fV00wJTSkJPcPOG6U6XxEMctUqPkOUrOtOSuBeIPX0kgpi6jTlJSpahVmJy5Z34prd FbqY87bI4ng3NgssKuBp8fn1ZknXQA2+Z/8F/TM8XJNZ/k6LcSKqRBSXOi20YE5T2TuT h9r1MrxI6GXPBY/FBbHVc67ZxLiR1TI/30JvSGXQd3tq6Hw/LgcYVADs6KSvGyyoD9XS MuVT3+wDv2jQQCZjakK8XXZpQfNb6bx7Do2lq5eGysMEKEzL2BfnNvgl/4Jbm9mJyfIa 7OOKcNaZe2heI4QzWF0ZSF2C7UTkh6FuZtsaN46MtjE/UOtoCJiqOPuDGv0FxzxZcLMX 64QQ== 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=3jMpBjW2RjjaneKFCh4VOi3MYzbeg1SPv8QfUhGFqak=; b=FI0xo1tZHrJ5ZHq68sJtyiQOPWVSah8+w/Xaw+JsHF30TNuJXNLgt9+weS8kLMRm00 X1jSjGdAJ4Cre3S14XzGe9a8qG/kQqHjAZyNuWsr+vou1yHgA55pAfV0xChvf/4clnno 2BZYh9rrE3HuvOs8GvOrJK0LVZqaYsSyYFTdxhzI/p30Z9944zBCkbANZpoAbDwnwEI+ 54C2WC+MvDA6Nr0b+VubsFoa0xZoONP3mkbmmp0N+PctI0ORMBSdJMrqaB+Ttn4aeCRs toV/VycqgZ5K9p+vP6EJ0Mv03fe0u5HiaQfxF/Et8bnUumc8eHaLVcisxPjlwklvfMaA uyKg== X-Gm-Message-State: ABuFfoi5DNsFgHQck24XLaZjrxvZAkJNjg61HDlo//KTX+jO65DJe2DX DVQgV7ft7MEUX8wvC05kg5tEcjf2 X-Google-Smtp-Source: ACcGV61OoLEa9ZoXkHuTLN4iZZNH+ZPhZo897JoRHj+ntScIR8VdjRuIs0kyqCC3hohQhxNi7oQ/+Q== X-Received: by 2002:adf:92e6:: with SMTP id 93-v6mr32154899wrn.124.1539894773715; Thu, 18 Oct 2018 13:32:53 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:52 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:00 +0200 Message-Id: <1539894735-14232-34-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::429 Subject: [Qemu-devel] [PULL 33/48] hyperv: make hyperv_vp_index inline X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Also make the inverse function, hyperv_find_vcpu, static as it's not used outside hyperv.c This paves the way to making hyperv.c built optionally. Signed-off-by: Roman Kagan Message-Id: <20180921082041.29380-3-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- target/i386/hyperv.c | 11 ++++------- target/i386/hyperv.h | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index fc537e7..6881664 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -27,14 +27,11 @@ struct HvSintRoute { unsigned refcount; }; -uint32_t hyperv_vp_index(X86CPU *cpu) +static X86CPU *hyperv_find_vcpu(uint32_t vp_index) { - return CPU(cpu)->cpu_index; -} - -X86CPU *hyperv_find_vcpu(uint32_t vp_index) -{ - return X86_CPU(qemu_get_cpu(vp_index)); + X86CPU *cpu = X86_CPU(qemu_get_cpu(vp_index)); + assert(hyperv_vp_index(cpu) == vp_index); + return cpu; } int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 59e9f9a..8d4619c 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -30,7 +30,9 @@ void hyperv_sint_route_unref(HvSintRoute *sint_route); int hyperv_sint_route_set_sint(HvSintRoute *sint_route); -uint32_t hyperv_vp_index(X86CPU *cpu); -X86CPU *hyperv_find_vcpu(uint32_t vp_index); +static inline uint32_t hyperv_vp_index(X86CPU *cpu) +{ + return CPU(cpu)->cpu_index; +} #endif From patchwork Thu Oct 18 20:32:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FDlOV9lP"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bj6x1zcjz9sC2 for ; Fri, 19 Oct 2018 08:36:57 +1100 (AEDT) Received: from localhost ([::1]:44878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFyQ-0003eE-So for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:36:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyc-0007i8-Ef for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyY-0006aW-RK for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:33369) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyY-0006Yc-DE for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:58 -0400 Received: by mail-wr1-x42d.google.com with SMTP id e4-v6so35111093wrs.0 for ; Thu, 18 Oct 2018 13:32:56 -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=G6IqdhkrdvpyaHD/SXoNFXNQmc5Z5cgNTKqDy96ex1M=; b=FDlOV9lPIf4gGIuvd+SKMrSk29jD5scZQb3uZzPu+mbkR5xf5Iu1B2g9ID1pU2IHgt c6GvptZRsFhuX1O6wbOmL5+9irJ88xqPD9vMFOLc+63dSzL3yShbeA7JHWptEiUK6E1O UfcbGgUQG3JSPRd2ju7Ph+BTa58Huzs1tOvnQ9JGvopKwh+tgpsMNtPtPIwF6rsFUmS0 5koocrNEAYWq3BWq7uARDepL+UxxbF7xagYb4CNlDaylqMJSh6MwlCF4UHIqdrqKlc4J rW2bkZ0qhR5PO/JPPCHYaI2qbkZIZXll2bJ6LX364IM1E9fKy51ff6Pzw2lNxoixAGBC cDNw== 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=G6IqdhkrdvpyaHD/SXoNFXNQmc5Z5cgNTKqDy96ex1M=; b=VNe3q1lAK+BgKHk44pOR9dDPkVQWcqG6d1eZePvHDnkUcM9AoXL7UCaD4hh9yJGPuI tU/vJ/S//Ypcn6+BCYF+k6AeB61Mscbnxvt2Z96GyMb9fI8GIZ2/s8xtT0vunehpMJRG 0czemfan5FgYaTgVAQGpJMaBzpSSFrae/zkzBrquMsewilWFOh5KGpPOGErTayxZ/qRN 73b0Xt49s9sdMT0/mE00AgXmQulGNW+/HpnGnvFx2feELDicJAYQZcCt0KUKIzm3boDE LGgnKHyVDdAQEQT05X571LOBL7qkTVJXfCQKnALHj5Kb0qj26w90cAJ72Jr/mIdVEK2A h33w== X-Gm-Message-State: ABuFfogobhG90e2B2mazKAHxRQi083EuYsxN8M7F664j239Fp1y7ow6d 4dJc+/knc67nET8jJ4eoxqZGG5yE X-Google-Smtp-Source: ACcGV62KjFIE0p46URym09vEZORNqQ1kHyqeHxyWekqmQRFgHDsH4Ox+LDYiLpS8fFa/jXWHZvgfdA== X-Received: by 2002:a5d:698b:: with SMTP id g11-v6mr32341424wru.159.1539894775057; Thu, 18 Oct 2018 13:32:55 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:01 +0200 Message-Id: <1539894735-14232-35-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::42d Subject: [Qemu-devel] [PULL 34/48] hyperv: factor out arch-independent API into hw/hyperv X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan A significant part of hyperv.c is not actually tied to x86, and can be moved to hw/. This will allow to maintain most of Hyper-V and VMBus target-independent, and to avoid conflicts with inclusion of arch-specific headers down the road in VMBus implementation. Also this stuff can now be opt-out with CONFIG_HYPERV. Signed-off-by: Roman Kagan Message-Id: <20180921082041.29380-4-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/Makefile.objs | 1 + hw/hyperv/Makefile.objs | 2 + hw/hyperv/hyperv.c | 138 +++++++++++++++++++++++++++++++++++ hw/{misc => hyperv}/hyperv_testdev.c | 2 +- hw/misc/Makefile.objs | 1 - include/hw/hyperv/hyperv.h | 31 ++++++++ target/i386/hyperv.c | 127 +------------------------------- target/i386/hyperv.h | 17 +---- target/i386/kvm.c | 5 +- 9 files changed, 178 insertions(+), 146 deletions(-) create mode 100644 hw/hyperv/Makefile.objs create mode 100644 hw/hyperv/hyperv.c rename hw/{misc => hyperv}/hyperv_testdev.c (99%) create mode 100644 include/hw/hyperv/hyperv.h diff --git a/hw/Makefile.objs b/hw/Makefile.objs index a19c141..30722cc 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -9,6 +9,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += cpu/ devices-dirs-$(CONFIG_SOFTMMU) += display/ devices-dirs-$(CONFIG_SOFTMMU) += dma/ devices-dirs-$(CONFIG_SOFTMMU) += gpio/ +devices-dirs-$(CONFIG_HYPERV) += hyperv/ devices-dirs-$(CONFIG_SOFTMMU) += i2c/ devices-dirs-$(CONFIG_SOFTMMU) += ide/ devices-dirs-$(CONFIG_SOFTMMU) += input/ diff --git a/hw/hyperv/Makefile.objs b/hw/hyperv/Makefile.objs new file mode 100644 index 0000000..edaca2f --- /dev/null +++ b/hw/hyperv/Makefile.objs @@ -0,0 +1,2 @@ +obj-y += hyperv.o +obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c new file mode 100644 index 0000000..97db875 --- /dev/null +++ b/hw/hyperv/hyperv.c @@ -0,0 +1,138 @@ +/* + * Hyper-V guest/hypervisor interaction + * + * Copyright (c) 2015-2018 Virtuozzo International GmbH. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "sysemu/kvm.h" +#include "hw/hyperv/hyperv.h" + +struct HvSintRoute { + uint32_t sint; + CPUState *cs; + int gsi; + EventNotifier sint_set_notifier; + EventNotifier sint_ack_notifier; + HvSintAckClb sint_ack_clb; + void *sint_ack_clb_data; + unsigned refcount; +}; + +static CPUState *hyperv_find_vcpu(uint32_t vp_index) +{ + CPUState *cs = qemu_get_cpu(vp_index); + assert(hyperv_vp_index(cs) == vp_index); + return cs; +} + +static void kvm_hv_sint_ack_handler(EventNotifier *notifier) +{ + HvSintRoute *sint_route = container_of(notifier, HvSintRoute, + sint_ack_notifier); + event_notifier_test_and_clear(notifier); + sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); +} + +HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, + HvSintAckClb sint_ack_clb, + void *sint_ack_clb_data) +{ + HvSintRoute *sint_route; + EventNotifier *ack_notifier; + int r, gsi; + CPUState *cs; + + cs = hyperv_find_vcpu(vp_index); + if (!cs) { + return NULL; + } + + sint_route = g_new0(HvSintRoute, 1); + r = event_notifier_init(&sint_route->sint_set_notifier, false); + if (r) { + goto err; + } + + ack_notifier = sint_ack_clb ? &sint_route->sint_ack_notifier : NULL; + if (ack_notifier) { + r = event_notifier_init(ack_notifier, false); + if (r) { + goto err_sint_set_notifier; + } + + event_notifier_set_handler(ack_notifier, kvm_hv_sint_ack_handler); + } + + gsi = kvm_irqchip_add_hv_sint_route(kvm_state, vp_index, sint); + if (gsi < 0) { + goto err_gsi; + } + + r = kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, + &sint_route->sint_set_notifier, + ack_notifier, gsi); + if (r) { + goto err_irqfd; + } + sint_route->gsi = gsi; + sint_route->sint_ack_clb = sint_ack_clb; + sint_route->sint_ack_clb_data = sint_ack_clb_data; + sint_route->cs = cs; + sint_route->sint = sint; + sint_route->refcount = 1; + + return sint_route; + +err_irqfd: + kvm_irqchip_release_virq(kvm_state, gsi); +err_gsi: + if (ack_notifier) { + event_notifier_set_handler(ack_notifier, NULL); + event_notifier_cleanup(ack_notifier); + } +err_sint_set_notifier: + event_notifier_cleanup(&sint_route->sint_set_notifier); +err: + g_free(sint_route); + + return NULL; +} + +void hyperv_sint_route_ref(HvSintRoute *sint_route) +{ + sint_route->refcount++; +} + +void hyperv_sint_route_unref(HvSintRoute *sint_route) +{ + if (!sint_route) { + return; + } + + assert(sint_route->refcount > 0); + + if (--sint_route->refcount) { + return; + } + + kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, + &sint_route->sint_set_notifier, + sint_route->gsi); + kvm_irqchip_release_virq(kvm_state, sint_route->gsi); + if (sint_route->sint_ack_clb) { + event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); + event_notifier_cleanup(&sint_route->sint_ack_notifier); + } + event_notifier_cleanup(&sint_route->sint_set_notifier); + g_free(sint_route); +} + +int hyperv_sint_route_set_sint(HvSintRoute *sint_route) +{ + return event_notifier_set(&sint_route->sint_set_notifier); +} diff --git a/hw/misc/hyperv_testdev.c b/hw/hyperv/hyperv_testdev.c similarity index 99% rename from hw/misc/hyperv_testdev.c rename to hw/hyperv/hyperv_testdev.c index 33bbd28..fc3f6c5 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/hyperv/hyperv_testdev.c @@ -15,7 +15,7 @@ #include "qemu/queue.h" #include "hw/qdev.h" #include "hw/isa/isa.h" -#include "target/i386/hyperv.h" +#include "hw/hyperv/hyperv.h" typedef struct TestSintRoute { QLIST_ENTRY(TestSintRoute) le; diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 6d50b03..680350b 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -71,7 +71,6 @@ obj-$(CONFIG_IOTKIT_SYSCTL) += iotkit-sysctl.o obj-$(CONFIG_IOTKIT_SYSINFO) += iotkit-sysinfo.o obj-$(CONFIG_PVPANIC) += pvpanic.o -obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o obj-$(CONFIG_AUX) += auxbus.o obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o obj-$(CONFIG_MSF2) += msf2-sysreg.o diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h new file mode 100644 index 0000000..d6c8d78 --- /dev/null +++ b/include/hw/hyperv/hyperv.h @@ -0,0 +1,31 @@ +/* + * Hyper-V guest/hypervisor interaction + * + * Copyright (c) 2015-2018 Virtuozzo International GmbH. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_HYPERV_HYPERV_H +#define HW_HYPERV_HYPERV_H + +#include "cpu-qom.h" + +typedef struct HvSintRoute HvSintRoute; +typedef void (*HvSintAckClb)(void *data); + +HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, + HvSintAckClb sint_ack_clb, + void *sint_ack_clb_data); +void hyperv_sint_route_ref(HvSintRoute *sint_route); +void hyperv_sint_route_unref(HvSintRoute *sint_route); + +int hyperv_sint_route_set_sint(HvSintRoute *sint_route); + +static inline uint32_t hyperv_vp_index(CPUState *cs) +{ + return cs->cpu_index; +} + +#endif diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 6881664..1eac727 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -12,28 +12,10 @@ */ #include "qemu/osdep.h" -#include "qemu/main-loop.h" #include "hyperv.h" +#include "hw/hyperv/hyperv.h" #include "hyperv-proto.h" -struct HvSintRoute { - uint32_t sint; - X86CPU *cpu; - int gsi; - EventNotifier sint_set_notifier; - EventNotifier sint_ack_notifier; - HvSintAckClb sint_ack_clb; - void *sint_ack_clb_data; - unsigned refcount; -}; - -static X86CPU *hyperv_find_vcpu(uint32_t vp_index) -{ - X86CPU *cpu = X86_CPU(qemu_get_cpu(vp_index)); - assert(hyperv_vp_index(cpu) == vp_index); - return cpu; -} - int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) { CPUX86State *env = &cpu->env; @@ -79,110 +61,3 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) return -1; } } - -static void kvm_hv_sint_ack_handler(EventNotifier *notifier) -{ - HvSintRoute *sint_route = container_of(notifier, HvSintRoute, - sint_ack_notifier); - event_notifier_test_and_clear(notifier); - sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); -} - -HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data) -{ - HvSintRoute *sint_route; - EventNotifier *ack_notifier; - int r, gsi; - X86CPU *cpu; - - cpu = hyperv_find_vcpu(vp_index); - if (!cpu) { - return NULL; - } - - sint_route = g_new0(HvSintRoute, 1); - r = event_notifier_init(&sint_route->sint_set_notifier, false); - if (r) { - goto err; - } - - ack_notifier = sint_ack_clb ? &sint_route->sint_ack_notifier : NULL; - if (ack_notifier) { - r = event_notifier_init(ack_notifier, false); - if (r) { - goto err_sint_set_notifier; - } - - event_notifier_set_handler(ack_notifier, kvm_hv_sint_ack_handler); - } - - gsi = kvm_irqchip_add_hv_sint_route(kvm_state, vp_index, sint); - if (gsi < 0) { - goto err_gsi; - } - - r = kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, - &sint_route->sint_set_notifier, - ack_notifier, gsi); - if (r) { - goto err_irqfd; - } - sint_route->gsi = gsi; - sint_route->sint_ack_clb = sint_ack_clb; - sint_route->sint_ack_clb_data = sint_ack_clb_data; - sint_route->cpu = cpu; - sint_route->sint = sint; - sint_route->refcount = 1; - - return sint_route; - -err_irqfd: - kvm_irqchip_release_virq(kvm_state, gsi); -err_gsi: - if (ack_notifier) { - event_notifier_set_handler(ack_notifier, NULL); - event_notifier_cleanup(ack_notifier); - } -err_sint_set_notifier: - event_notifier_cleanup(&sint_route->sint_set_notifier); -err: - g_free(sint_route); - - return NULL; -} - -void hyperv_sint_route_ref(HvSintRoute *sint_route) -{ - sint_route->refcount++; -} - -void hyperv_sint_route_unref(HvSintRoute *sint_route) -{ - if (!sint_route) { - return; - } - - assert(sint_route->refcount > 0); - - if (--sint_route->refcount) { - return; - } - - kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, - &sint_route->sint_set_notifier, - sint_route->gsi); - kvm_irqchip_release_virq(kvm_state, sint_route->gsi); - if (sint_route->sint_ack_clb) { - event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); - event_notifier_cleanup(&sint_route->sint_ack_notifier); - } - event_notifier_cleanup(&sint_route->sint_set_notifier); - g_free(sint_route); -} - -int hyperv_sint_route_set_sint(HvSintRoute *sint_route) -{ - return event_notifier_set(&sint_route->sint_set_notifier); -} diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 8d4619c..5c49251 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -16,23 +16,8 @@ #include "cpu.h" #include "sysemu/kvm.h" - -typedef struct HvSintRoute HvSintRoute; -typedef void (*HvSintAckClb)(void *data); +#include "hw/hyperv/hyperv.h" int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); -HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data); -void hyperv_sint_route_ref(HvSintRoute *sint_route); -void hyperv_sint_route_unref(HvSintRoute *sint_route); - -int hyperv_sint_route_set_sint(HvSintRoute *sint_route); - -static inline uint32_t hyperv_vp_index(X86CPU *cpu) -{ - return CPU(cpu)->cpu_index; -} - #endif diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 4e62b5c..b0b42d2 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -774,7 +774,7 @@ static int hyperv_init_vcpu(X86CPU *cpu) } assert(ret == 1); - if (msr_data.entries[0].data != hyperv_vp_index(cpu)) { + if (msr_data.entries[0].data != hyperv_vp_index(CPU(cpu))) { error_report("kernel's vp_index != QEMU's vp_index"); return -ENXIO; } @@ -1949,7 +1949,8 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, HV_X64_MSR_VP_RUNTIME, env->msr_hv_runtime); } if (cpu->hyperv_vpindex && hv_vpindex_settable) { - kvm_msr_entry_add(cpu, HV_X64_MSR_VP_INDEX, hyperv_vp_index(cpu)); + kvm_msr_entry_add(cpu, HV_X64_MSR_VP_INDEX, + hyperv_vp_index(CPU(cpu))); } if (cpu->hyperv_synic) { int j; From patchwork Thu Oct 18 20:32:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986322 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gmvUbx33"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhvC1LCPz9sBj for ; Fri, 19 Oct 2018 08:26:47 +1100 (AEDT) Received: from localhost ([::1]:44816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFoa-0004ka-MA for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:26:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyc-0007i5-ES for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyY-0006aK-Mh for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:35102) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyY-0006Yp-Bn for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:58 -0400 Received: by mail-wm1-x32c.google.com with SMTP id o17-v6so901132wmh.0 for ; Thu, 18 Oct 2018 13:32:56 -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=4cGyecEVSIs+AYdv0CPy8F2Y5rjwgvzgwyZ243RCB+E=; b=gmvUbx33vxUmCHvBjqEBYrPIlZCCfLJyBMexFEJrYXEo3TlGF1s4tpjH7eE+x7LEie rQ6EcNHHWmmWeZvjmDbPLIkIH8I8i22NTtkAEFSREusz4A6KKuLRqPJ1V//kTkovyTeM wqLOWGGj9kjsYrmNYRGwobyMSNngnndXHUZ+Ol9hdTo4UqC80DoHUr6G8XqC9QvdNrkM ewLtUIxTzZ3YFelh7At/bc7uISS70z0m+vU+49p15CwqXR4X9wBywd/ePTN43U9Jdu53 hP5Mf5+4Flm+yaTdZaN+voeYTHdZ4PvEeqhcx2aSdY3Pqy093nkLvaZohvKxN8WSmCqT EEGg== 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=4cGyecEVSIs+AYdv0CPy8F2Y5rjwgvzgwyZ243RCB+E=; b=BbUTODK7qU40mplkWJLc8Wla9U1WgOPlTzgxUTRWAhW7optBae6m2A2akhWhoxM4qn bSYrJvhQuy3VvkelLk5J/RRHYCPaRpgQGGnyxYh2v4Ou0Yx71KWFK5TVxy9yCT0WhwqC 00qpT4t+rgOCkoF1Pz47xcunA7lBRUTK+7+hC0NCOoQURdNilBo06GNYvHBUqSZR4Otd bd8hivwpY4GS2QnzcA0GBsAAYNZKknyqI+7f+DDcZX0xiiogWoMKTlSswOg5MQd2l9UV JYb0hvR1pk0DOAkFeop4FGK24canI4oAna35GgsbKgrjctBsr2PmHJludgEhnJBGKYKj cRXQ== X-Gm-Message-State: ABuFfojb0cIGJaTcI194s8r7esvRwWA8sJVDmVGs8KCubA++XG1kgBkY kqx3wY0V4X8ppQSCZAoPliGYNwGt X-Google-Smtp-Source: ACcGV62xbj2OVExJhhxn8IAIpIrBnx7wjzldOWHdCBhHd3Aik8djxxwESPS+cp+KRXQw2L3OzawAsg== X-Received: by 2002:a1c:5c2:: with SMTP id 185-v6mr1802948wmf.140.1539894775806; Thu, 18 Oct 2018 13:32:55 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:02 +0200 Message-Id: <1539894735-14232-36-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::32c Subject: [Qemu-devel] [PULL 35/48] default-configs: collect CONFIG_HYPERV* in hyperv.mak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Accumulate HYPERV config options in a dedicated file. There are only two so far; more will be added later. Signed-off-by: Roman Kagan Message-Id: <20180921082041.29380-5-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- default-configs/hyperv.mak | 2 ++ default-configs/i386-softmmu.mak | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 default-configs/hyperv.mak diff --git a/default-configs/hyperv.mak b/default-configs/hyperv.mak new file mode 100644 index 0000000..5d0d9fd --- /dev/null +++ b/default-configs/hyperv.mak @@ -0,0 +1,2 @@ +CONFIG_HYPERV=$(CONFIG_KVM) +CONFIG_HYPERV_TESTDEV=y diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 8c7d4a0..210cff2 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -3,6 +3,7 @@ include pci.mak include sound.mak include usb.mak +include hyperv.mak CONFIG_QXL=$(CONFIG_SPICE) CONFIG_VGA_ISA=y CONFIG_VGA_CIRRUS=y @@ -58,7 +59,6 @@ CONFIG_XIO3130=y CONFIG_IOH3420=y CONFIG_I82801B11=y CONFIG_SMBIOS=y -CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) CONFIG_PXB=y CONFIG_ACPI_VMGENID=y CONFIG_FW_CFG_DMA=y From patchwork Thu Oct 18 20:32:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986328 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nwXtLhJJ"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bj4j3xJLz9sC2 for ; Fri, 19 Oct 2018 08:35:01 +1100 (AEDT) Received: from localhost ([::1]:44864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFwZ-0002EL-5z for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:34:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyc-0007hv-Do for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyY-0006aA-IG for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:40854) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyY-0006ZI-8w for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:58 -0400 Received: by mail-wm1-x334.google.com with SMTP id z204-v6so1611720wmc.5 for ; Thu, 18 Oct 2018 13:32: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; bh=H1IMf5fO/8cIX7nkYTPxw2s4NDP5Jr7X5vdHobX0a04=; b=nwXtLhJJHXvjGBcrnfBv91HThd2gu9944dk6zSyKJPTnUqvTdHrhcHp15JzzX0uRqC r9ASbIx0Cic1pcAfD0k+bKsePI4gzDH2R1AJbLpPv7+IHm7c+KsLNuOWD+mhp97dOXI/ qYj1SEneMUDsVklNC3XrK2jtRLFmOhQ53jCc7CGnFZL34hbZxBVtWCoOxAs9Ck5ubsAM rppwzhm5o8jkdXH5WUmM3XvHonkcFDbjWWuqHOXQl4eAlFWDGKUvFe7Zy1rZ+VPKT411 ktYi8oVMg06ur/ehNLqgbEUveFORpcbu7+98a11W73RjU1DRUZGAeK0gFiR2tYD+Pikf IE5w== 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=H1IMf5fO/8cIX7nkYTPxw2s4NDP5Jr7X5vdHobX0a04=; b=RofpJee25mGCn0kn26H7WBL7Ld4jQ3aZzsuNKRFOi+OYnMdusVEEPCKnsaqy2hMwfo cz9etcZk1qVIPmMzf0p0nI031F4dBApZMAUdWvMnVQAiBiInQXiWT7KdJKSilugmr9/h dZ2ZJKiDJVnO2FUyrdsM1J/W5w5O+bX08YAOITUmYHuEqK1q8XJPSUR6ssZYDwB0ye/X ZKyvQFJUVqMMW+LMY/qMDufZ+ey8tR1KFTPCNDoUkSHhS3qIWpjo0eJ0wMMqkhzPceyB WI61GWC+5y5m1jSVsqQD89j4LIpB9aC8urUKag0jY15et2lhfonmnXW2yur3muNaNsW2 +hnw== X-Gm-Message-State: AGRZ1gLpmkekoQudWH0n7wVaLJF8KKn32I+74cdFjKw2a/RQ1A3TqL4o Y5ysKxTGZ9ngkHLiYVev+V7RFPVh X-Google-Smtp-Source: ACcGV6154Jxjm8IVOR1UfNh8012HzCzPoEvXvzaFrz2OHMo7IFXHKSYKPTQfLZAnCRj3F6Qi+GI+mA== X-Received: by 2002:a1c:b20d:: with SMTP id b13-v6mr1817250wmf.141.1539894776732; Thu, 18 Oct 2018 13:32:56 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:03 +0200 Message-Id: <1539894735-14232-37-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::334 Subject: [Qemu-devel] [PULL 36/48] i386: add hyperv-stub for CONFIG_HYPERV=n X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan This will allow to build slightly leaner QEMU that supports some HyperV features of KVM (e.g. SynIC timers, PV spinlocks, APIC assists, etc.) but nothing else on the QEMU side. Signed-off-by: Roman Kagan Message-Id: <20180921082041.29380-6-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- target/i386/Makefile.objs | 17 ++++++++++------- target/i386/hyperv-stub.c | 35 +++++++++++++++++++++++++++++++++++ target/i386/hyperv.h | 2 ++ 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 target/i386/hyperv-stub.c diff --git a/target/i386/Makefile.objs b/target/i386/Makefile.objs index 04678f5..32bf966 100644 --- a/target/i386/Makefile.objs +++ b/target/i386/Makefile.objs @@ -3,17 +3,20 @@ obj-$(CONFIG_TCG) += translate.o obj-$(CONFIG_TCG) += bpt_helper.o cc_helper.o excp_helper.o fpu_helper.o obj-$(CONFIG_TCG) += int_helper.o mem_helper.o misc_helper.o mpx_helper.o obj-$(CONFIG_TCG) += seg_helper.o smm_helper.o svm_helper.o -obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o monitor.o -obj-$(CONFIG_KVM) += kvm.o hyperv.o -obj-$(CONFIG_SEV) += sev.o +ifeq ($(CONFIG_SOFTMMU),y) +obj-y += machine.o arch_memory_mapping.o arch_dump.o monitor.o +obj-$(CONFIG_KVM) += kvm.o obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o -obj-$(call lnot,$(CONFIG_SEV)) += sev-stub.o -# HAX support -ifdef CONFIG_WIN32 +obj-$(CONFIG_HYPERV) += hyperv.o +obj-$(call lnot,$(CONFIG_HYPERV)) += hyperv-stub.o +ifeq ($(CONFIG_WIN32),y) obj-$(CONFIG_HAX) += hax-all.o hax-mem.o hax-windows.o endif -ifdef CONFIG_DARWIN +ifeq ($(CONFIG_DARWIN),y) obj-$(CONFIG_HAX) += hax-all.o hax-mem.o hax-darwin.o obj-$(CONFIG_HVF) += hvf/ endif obj-$(CONFIG_WHPX) += whpx-all.o +endif +obj-$(CONFIG_SEV) += sev.o +obj-$(call lnot,$(CONFIG_SEV)) += sev-stub.o diff --git a/target/i386/hyperv-stub.c b/target/i386/hyperv-stub.c new file mode 100644 index 0000000..5919ba8 --- /dev/null +++ b/target/i386/hyperv-stub.c @@ -0,0 +1,35 @@ +/* + * Stubs for CONFIG_HYPERV=n + * + * Copyright (c) 2015-2018 Virtuozzo International GmbH. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hyperv.h" + +#ifdef CONFIG_KVM +int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) +{ + switch (exit->type) { + case KVM_EXIT_HYPERV_SYNIC: + if (!cpu->hyperv_synic) { + return -1; + } + + /* + * Tracking the changes in the MSRs is unnecessary as there are no + * users for them beside save/load, which is handled nicely by the + * generic MSR save/load code + */ + return 0; + case KVM_EXIT_HYPERV_HCALL: + exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE; + return 0; + default: + return -1; + } +} +#endif diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 5c49251..f0a27c3 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -18,6 +18,8 @@ #include "sysemu/kvm.h" #include "hw/hyperv/hyperv.h" +#ifdef CONFIG_KVM int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); +#endif #endif From patchwork Thu Oct 18 20:32:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986327 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="M5gvlmn6"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bj2G5MS4z9sBj for ; Fri, 19 Oct 2018 08:32:54 +1100 (AEDT) Received: from localhost ([::1]:44850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFuW-0000rd-Ak for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:32:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyc-0007i7-ES for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyZ-0006ax-7R for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:35669) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyY-0006a4-VZ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:59 -0400 Received: by mail-wm1-x343.google.com with SMTP id o17-v6so901194wmh.0 for ; Thu, 18 Oct 2018 13:32:58 -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=RTaoNuPKdzLJ7KrlehIQDYmZBJKalYiNnbQZ/vXcdzU=; b=M5gvlmn6e+Tomdu9pNVg+j4+suYmRhnNcSdS3JYaji4WvapNNHWXzAl+aoGkm6zMZv dDquEsqCKvZAlZR3I6pa8C8PR0Nx2ml8CNffKYxMwvSoOtjKAqfMJh39FXeboDcjFVgb YJyJL/ZBLxp+Q2g0vMOQmwzQTKT5IU2FcOwsf6Gozn2uvd4VbI4zeokGv6nkLkvsRebk d9d1yar9UPHjmIcOuBPTP49u8HE+oQ/QBPPdhd7QVFNTFFG3husVkKiMPBk4JwrhieVB J4WGdhbr1pMZMRa3X6oSHiTDlQPyZo6LfGxYfXIQTiJGYG/zTi4oVVafnh1YhIMlOtAF 1NVQ== 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=RTaoNuPKdzLJ7KrlehIQDYmZBJKalYiNnbQZ/vXcdzU=; b=QMMBSPwNN54Xw3l0cOKv8wnQKKFpqbv493GsgD1L3acAXTs4kG2GQLZC5e0OdGKtGb 3uMiT4cOPv1aBPe0Usxec89X46upSdNkScy7j4OeKivTntz9WIJeWUf0TUVX7jr0Ms51 TGXrTRGpCIYgHDxvn3pYDhW2nJe6jqE3lbd7GDa+cotwO/besnU5nUwAgvxOmssff4+r R9oV3Bqf3LSN8eRj1TrVVb42+ljqycEDxgPgKi2mXoQUyCPxkufWoIQ+hJefVzWxyHIS T6iGr6yaqP5TIFpM+r3hsDoGoE5OBD2PxjT0M9fv501Li5KQrJPvfzkhrPQGObkg9sDP V9ag== X-Gm-Message-State: ABuFfoh/4NwURv4SGM58Y+DVRwAGASjddVmcZo5WAWFKH517r0pfXvj5 4o/vP/f5O3DGaoP37O3aTdvrG2vg X-Google-Smtp-Source: ACcGV63X+xFRPI2H6IFKcwfu+LdLxVXDYW9PaNMsLrDRYZTue+NtUK+drWRIncBpeFblMuDmEMuuKQ== X-Received: by 2002:a1c:544d:: with SMTP id p13-v6mr1814124wmi.144.1539894777700; Thu, 18 Oct 2018 13:32:57 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:04 +0200 Message-Id: <1539894735-14232-38-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::343 Subject: [Qemu-devel] [PULL 37/48] hyperv:synic: split capability testing and setting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Put a bit more consistency into handling KVM_CAP_HYPERV_SYNIC capability, by checking its availability and determining the feasibility of hv-synic property first, and enabling it later. Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-2-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index b0b42d2..2e5b9f6 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -735,8 +735,9 @@ static int hyperv_handle_properties(CPUState *cs) } if (cpu->hyperv_synic) { if (!has_msr_hv_synic || - kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0)) { - fprintf(stderr, "Hyper-V SynIC is not supported by kernel\n"); + !kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_SYNIC)) { + fprintf(stderr, "Hyper-V SynIC (requested by 'hv-synic' cpu flag) " + "is not supported by kernel\n"); return -ENOSYS; } @@ -754,12 +755,14 @@ static int hyperv_handle_properties(CPUState *cs) static int hyperv_init_vcpu(X86CPU *cpu) { + CPUState *cs = CPU(cpu); + int ret; + if (cpu->hyperv_vpindex && !hv_vpindex_settable) { /* * the kernel doesn't support setting vp_index; assert that its value * is in sync */ - int ret; struct { struct kvm_msrs info; struct kvm_msr_entry entries[1]; @@ -768,7 +771,7 @@ static int hyperv_init_vcpu(X86CPU *cpu) .entries[0].index = HV_X64_MSR_VP_INDEX, }; - ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data); + ret = kvm_vcpu_ioctl(cs, KVM_GET_MSRS, &msr_data); if (ret < 0) { return ret; } @@ -780,6 +783,15 @@ static int hyperv_init_vcpu(X86CPU *cpu) } } + if (cpu->hyperv_synic) { + ret = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0); + if (ret < 0) { + error_report("failed to turn on HyperV SynIC in KVM: %s", + strerror(-ret)); + return ret; + } + } + return 0; } From patchwork Thu Oct 18 20:32:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986314 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MNOCzofC"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhhm0VVHz9s5c for ; Fri, 19 Oct 2018 08:17:44 +1100 (AEDT) Received: from localhost ([::1]:44752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFfp-0003ca-GB for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:17:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyc-0007iA-GE for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyb-0006cJ-9G for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:53225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyb-0006bp-2e for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:01 -0400 Received: by mail-wm1-x344.google.com with SMTP id 189-v6so1576941wmw.2 for ; Thu, 18 Oct 2018 13:33:00 -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=WlIQ1584eVXvegaMhvuv7YkG2Rnljttoj5yYyT1rVDM=; b=MNOCzofC9OluSvBl3Lrtfx6xBUgSfN2RQuibMVVADl0wEjmvbHduEJ6mYImsB1dqoX M+YaP4fwu996+k+T69PTTWj5HNKlTU/rT8rNRqpS9Xff/VQhuj2hn2gcoU1i6qblsvRo wSeu51iSP9knJ5pBs8ohM2qBq+EocOju1XWA6aTW+li+7hCuHNOQojT+c6AmvPb0zg4X sOdxldkuTy6zyNi7E+NH+s+ddG9VafV1STMcEFrNsPhh3QbLQG39+UREVWfTwdK67xyg vT2gVnodK8ykb4Th6NtPsJxzUh9IPASEdtLnb/RNsyIq48D5E3aWfBnjsJ0J4zSsDELq zcFg== 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=WlIQ1584eVXvegaMhvuv7YkG2Rnljttoj5yYyT1rVDM=; b=gP72g9xyTbVDYloYAeJ3T5U27+3fG8qH3fU4Bmg4Zz8EoxXxBkaHOlWS+T1hlaaGsl HqSTzTSyqxnhnf5vptes8CkK9rOI/M7KyPVtpGNqn0pAeO6MzkpUHZJmMOt00zNzmoYn snZxXaUMNIhzcTcQvMKOj/yKjkzO5BAhdAheIgTvqrW1WwWb4ycp6uIy+1fTJk/3UPeL OH0k695Ea+06/Hdrguq5s9j6GNoi+2gP3tl0fqGPrTzbuKvBtHMHLhzdNTdqnuEE8r7K jvA9GgqxyLKhaIcbpIULsQEKbvSMpmQoVWvHGpTxpo/rI2zmrlpbnohwmTpiNA5zBR6F 4n9Q== X-Gm-Message-State: ABuFfoi5nM6WtE0qUyk1XWBU0jYTCHDlLQIgjex2CBANb8qYzEKKspYX qvVSLhvFsjL+ZmObmm44HZtrIxhH X-Google-Smtp-Source: ACcGV60dclKOQ6XVmNKbIm9RoNMDQK1UPMqGIcLLKOQSr7hmTLEoHJYc/8okuEY3r2kd/Sr6kNI6Og== X-Received: by 2002:a1c:9d43:: with SMTP id g64-v6mr1850482wme.26.1539894779793; Thu, 18 Oct 2018 13:32:59 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:06 +0200 Message-Id: <1539894735-14232-40-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::344 Subject: [Qemu-devel] [PULL 39/48] hyperv: only add SynIC in compatible configurations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Certain configurations do not allow SynIC to be used in QEMU. In particular, - when hyperv_vpindex is off, SINT routes can't be used as they refer to the destination vCPU by vp_index - older KVM (which doesn't expose KVM_CAP_HYPERV_SYNIC2) zeroes out SynIC message and event pages on every msr load, breaking migration OTOH in-KVM users of SynIC -- SynIC timers -- do work in those configurations, and we shouldn't stop the guest from using them. To cover both scenarios, introduce an X86CPU property that makes CPU init code to skip creation of the SynIC object (and thus disables any SynIC use in QEMU) but keeps the KVM part of the SynIC working. The property is clear by default but is set via compat logic for older machine types. As a result, when hv_synic and a modern machine type are specified, QEMU will refuse to run unless vp_index is on and the kernel is recent enough. OTOH with an older machine type QEMU will run fine with hv_synic=on against an older kernel and/or without vp_index enabled but will disallow the in-QEMU uses of SynIC (in e.g. VMBus). Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-4-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- include/hw/i386/pc.h | 8 ++++++++ target/i386/cpu.c | 2 ++ target/i386/cpu.h | 1 + target/i386/kvm.c | 30 ++++++++++++++++++++++-------- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 6894f37..dfe6746 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -294,6 +294,14 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); int e820_get_num_entries(void); bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); +#define PC_COMPAT_3_0 \ + HW_COMPAT_3_0 \ + {\ + .driver = TYPE_X86_CPU,\ + .property = "x-hv-synic-kvm-only",\ + .value = "on",\ + } + #define PC_COMPAT_2_12 \ HW_COMPAT_2_12 \ {\ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 32ea041..f0d9f7c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5607,6 +5607,8 @@ static Property x86_cpu_properties[] = { * to the specific Windows version being used." */ DEFINE_PROP_INT32("x-hv-max-vps", X86CPU, hv_max_vps, -1), + DEFINE_PROP_BOOL("x-hv-synic-kvm-only", X86CPU, hyperv_synic_kvm_only, + false), DEFINE_PROP_END_OF_LIST() }; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index caa1544..663f3a5 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1378,6 +1378,7 @@ struct X86CPU { bool hyperv_vpindex; bool hyperv_runtime; bool hyperv_synic; + bool hyperv_synic_kvm_only; bool hyperv_stimer; bool hyperv_frequencies; bool hyperv_reenlightenment; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index cf6270a..7b7a565 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -734,8 +734,18 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HYPERV_EAX] |= HV_VP_RUNTIME_AVAILABLE; } if (cpu->hyperv_synic) { - if (!has_msr_hv_synic || - !kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_SYNIC)) { + unsigned int cap = KVM_CAP_HYPERV_SYNIC; + if (!cpu->hyperv_synic_kvm_only) { + if (!cpu->hyperv_vpindex) { + fprintf(stderr, "Hyper-V SynIC " + "(requested by 'hv-synic' cpu flag) " + "requires Hyper-V VP_INDEX ('hv-vpindex')\n"); + return -ENOSYS; + } + cap = KVM_CAP_HYPERV_SYNIC2; + } + + if (!has_msr_hv_synic || !kvm_check_extension(cs->kvm_state, cap)) { fprintf(stderr, "Hyper-V SynIC (requested by 'hv-synic' cpu flag) " "is not supported by kernel\n"); return -ENOSYS; @@ -784,18 +794,22 @@ static int hyperv_init_vcpu(X86CPU *cpu) } if (cpu->hyperv_synic) { - ret = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0); + uint32_t synic_cap = cpu->hyperv_synic_kvm_only ? + KVM_CAP_HYPERV_SYNIC : KVM_CAP_HYPERV_SYNIC2; + ret = kvm_vcpu_enable_cap(cs, synic_cap, 0); if (ret < 0) { error_report("failed to turn on HyperV SynIC in KVM: %s", strerror(-ret)); return ret; } - ret = hyperv_x86_synic_add(cpu); - if (ret < 0) { - error_report("failed to create HyperV SynIC: %s", - strerror(-ret)); - return ret; + if (!cpu->hyperv_synic_kvm_only) { + ret = hyperv_x86_synic_add(cpu); + if (ret < 0) { + error_report("failed to create HyperV SynIC: %s", + strerror(-ret)); + return ret; + } } } From patchwork Thu Oct 18 20:32:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qblYmEuH"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhy24hlQz9sBj for ; Fri, 19 Oct 2018 08:29:14 +1100 (AEDT) Received: from localhost ([::1]:44833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFqy-0006xM-AD for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:29:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyd-0007my-Om for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyc-0006dQ-KE for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:03 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:35670) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyc-0006cc-8D for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:02 -0400 Received: by mail-wm1-x344.google.com with SMTP id o17-v6so901319wmh.0 for ; Thu, 18 Oct 2018 13:33:02 -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=VSYKgQjUXPOFv20jKawdn6ZEM8fCA9RWi5sOJTkWX8Y=; b=qblYmEuHeuIf8KOI9aHDDbujlPFg9Uz+MR0/thaAsQKIty3UlwGXAC+BgY8n17X9HK M99BrYnIOeqK/a0MXBJ9IJXzeYI5vKO/bYfdJOsiNHzg/yuwf8eVnHnWrNAKbRR6nsBV p0NcnSo9L05IlRtkjH4QDvYu54QG6v6cAa8azGdsu1Z6VA8Q+Pps1eSfJo5q1XFhi/AA 3w4sIeWo+35lTerPeZWc6JlWnNrQqk1TvDXD3Ct8OZczUkFAm5TVfQz3XEOd7qry9sEg PiGgFj9OJoSeTC0BqVrQOMAWG7YqcTXinqITDY8MSK+Fbh31nd8u5U9pW1Ffv1ittrzM VqtQ== 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=VSYKgQjUXPOFv20jKawdn6ZEM8fCA9RWi5sOJTkWX8Y=; b=szc3EzGjYxK/fWrVmxboW2qjGhsR0aEkeOOvBSiW91DyOM9/8Zoho3x7/yj8Jacp7/ GdheLAC63WVvAwzCGWJk4EP8DBDFuxux/hOXxRT7+sUHRrRGBtHt7YAhbE0o2u71GsO6 g2LJ31VKKFAsJuCZLiQ2P3tUusPE3AZMWBZ2HQ3b8Uv9yoWPotgalyfVBbOT7TYfD1/U TjPGNdExF8nMul63MAr7ZOR60nKFfshmvWKqD4UuyitkRQ7FDUHLLb4damb83neJfl/l 3D9NQrECJYVqEb6N2YiydN8BSbS3j9TkSjC53NYN38p9Y+s2M9EJ9U4QiVuayjWchvEG rBXQ== X-Gm-Message-State: ABuFfogJOjm5gaOt0OAg096hEaAIxIh4a/4t+OQ1Ed86rpPjr1yrBjgh 8a+Tr89APvesfr9BLE44QFSeitkZ X-Google-Smtp-Source: ACcGV626Pdhns8GEJzPHBwlB0mMQgr5mGMwoT5IwSGtBS15ApvHB6N84A6QBLGz6UeaPzspoDpo2rA== X-Received: by 2002:a1c:34d2:: with SMTP id b201-v6mr1817346wma.115.1539894780980; Thu, 18 Oct 2018 13:33:00 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:07 +0200 Message-Id: <1539894735-14232-41-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::344 Subject: [Qemu-devel] [PULL 40/48] hyperv: make overlay pages for SynIC X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Per Hyper-V spec, SynIC message and event flag pages are to be implemented as so called overlay pages. That is, they are owned by the hypervisor and, when mapped into the guest physical address space, overlay the guest physical pages such that 1) the overlaid guest page becomes invisible to the guest CPUs until the overlay page is turned off 2) the contents of the overlay page is preserved when it's turned off and back on, even at a different address; it's only zeroed at vcpu reset This particular nature of SynIC message and event flag pages is ignored in the current code, and guest physical pages are used directly instead. This happens to (mostly) work because the actual guests seem not to depend on the features listed above. This patch implements those pages as the spec mandates. Since the extra RAM regions, which introduce migration incompatibility, are only added at SynIC object creation which only happens when hyperv_synic_kvm_only == false, no extra compat logic is necessary. Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-5-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/hyperv/hyperv.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- target/i386/hyperv.c | 20 ++++++++++++++------ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 3d6f044..70cf129 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qapi/error.h" +#include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "hw/hyperv/hyperv.h" @@ -21,6 +22,10 @@ typedef struct SynICState { bool enabled; hwaddr msg_page_addr; hwaddr event_page_addr; + MemoryRegion msg_page_mr; + MemoryRegion event_page_mr; + struct hyperv_message_page *msg_page; + struct hyperv_event_flags_page *event_page; } SynICState; #define TYPE_SYNIC "hyperv-synic" @@ -36,8 +41,28 @@ static void synic_update(SynICState *synic, bool enable, { synic->enabled = enable; - synic->msg_page_addr = msg_page_addr; - synic->event_page_addr = event_page_addr; + if (synic->msg_page_addr != msg_page_addr) { + if (synic->msg_page_addr) { + memory_region_del_subregion(get_system_memory(), + &synic->msg_page_mr); + } + if (msg_page_addr) { + memory_region_add_subregion(get_system_memory(), msg_page_addr, + &synic->msg_page_mr); + } + synic->msg_page_addr = msg_page_addr; + } + if (synic->event_page_addr != event_page_addr) { + if (synic->event_page_addr) { + memory_region_del_subregion(get_system_memory(), + &synic->event_page_mr); + } + if (event_page_addr) { + memory_region_add_subregion(get_system_memory(), event_page_addr, + &synic->event_page_mr); + } + synic->event_page_addr = event_page_addr; + } } void hyperv_synic_update(CPUState *cs, bool enable, @@ -54,11 +79,31 @@ void hyperv_synic_update(CPUState *cs, bool enable, static void synic_realize(DeviceState *dev, Error **errp) { + Object *obj = OBJECT(dev); + SynICState *synic = SYNIC(dev); + char *msgp_name, *eventp_name; + uint32_t vp_index; + + /* memory region names have to be globally unique */ + vp_index = hyperv_vp_index(synic->cs); + msgp_name = g_strdup_printf("synic-%u-msg-page", vp_index); + eventp_name = g_strdup_printf("synic-%u-event-page", vp_index); + + memory_region_init_ram(&synic->msg_page_mr, obj, msgp_name, + sizeof(*synic->msg_page), &error_abort); + memory_region_init_ram(&synic->event_page_mr, obj, eventp_name, + sizeof(*synic->event_page), &error_abort); + synic->msg_page = memory_region_get_ram_ptr(&synic->msg_page_mr); + synic->event_page = memory_region_get_ram_ptr(&synic->event_page_mr); + + g_free(msgp_name); + g_free(eventp_name); } - static void synic_reset(DeviceState *dev) { SynICState *synic = SYNIC(dev); + memset(synic->msg_page, 0, sizeof(*synic->msg_page)); + memset(synic->event_page, 0, sizeof(*synic->event_page)); synic_update(synic, false, 0, 0); } diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 0216735..3f76c3e 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "hyperv.h" #include "hw/hyperv/hyperv.h" #include "hyperv-proto.h" @@ -38,6 +39,13 @@ void hyperv_x86_synic_update(X86CPU *cpu) hyperv_synic_update(CPU(cpu), enable, msg_page_addr, event_page_addr); } +static void async_synic_update(CPUState *cs, run_on_cpu_data data) +{ + qemu_mutex_lock_iothread(); + hyperv_x86_synic_update(X86_CPU(cs)); + qemu_mutex_unlock_iothread(); +} + int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) { CPUX86State *env = &cpu->env; @@ -48,11 +56,6 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) return -1; } - /* - * For now just track changes in SynIC control and msg/evt pages msr's. - * When SynIC messaging/events processing will be added in future - * here we will do messages queues flushing and pages remapping. - */ switch (exit->u.synic.msr) { case HV_X64_MSR_SCONTROL: env->msr_hv_synic_control = exit->u.synic.control; @@ -67,7 +70,12 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) return -1; } - hyperv_x86_synic_update(cpu); + /* + * this will run in this cpu thread before it returns to KVM, but in a + * safe environment (i.e. when all cpus are quiescent) -- this is + * necessary because memory hierarchy is being changed + */ + async_safe_run_on_cpu(CPU(cpu), async_synic_update, RUN_ON_CPU_NULL); return 0; case KVM_EXIT_HYPERV_HCALL: { From patchwork Thu Oct 18 20:32:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986309 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cpJZCy/5"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhby3GdKz9s5c for ; Fri, 19 Oct 2018 08:13:34 +1100 (AEDT) Received: from localhost ([::1]:44729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFbn-0008Rh-WF for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:13:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyf-0007qG-EN for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEye-0006eV-4P for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:05 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:45776) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyd-0006dl-PQ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:04 -0400 Received: by mail-wr1-x433.google.com with SMTP id f17-v6so3347571wrs.12 for ; Thu, 18 Oct 2018 13:33:03 -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=lzXXYwwHzNuFyUADlyNEiyzRo1dw6NsmKZBHNj9hPoQ=; b=cpJZCy/5vKpkCZdlnq45QmJqa0m2M7XD5f+Fn1OC/BiWVmUjFM9J4UqCndF6jDlKbN MpgIZ6IBszMQ3sTV/hEbnRmuHAwoq0/oI+Le54zC6txQB3JS98joNYr4CYxYbE9wRyXR BZwhAO3kVUC7fp8aIg0ytwRbdfFf4CdBh1xmDq9ecE9LtqS0fIsCpYsmCZiReKJT3sbp icR9aSuXb+iEPX+IOUuCjpSlXV9ZXZHWZrKZSPx1DeRAa5TJZHvvvhVmM45/36Gco9H6 w9wSLDFeD3qxMdy9G4tcb6Oc1RJVpaqjX5zM6XBCqKHKgTpMqFmgY9OFokinhqRVa9Pu KJZw== 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=lzXXYwwHzNuFyUADlyNEiyzRo1dw6NsmKZBHNj9hPoQ=; b=ECUMbhMO6LesSMvxtWo6+Ds2oRHxTQKFOr6f3Gdp5rcEJkELzplWTR8YVxTuv0b6re miSCo0/4kwHl2GtTYzy0IscTEZibH8fMPJA2hlOAumJ16X8RaymjB7mtNmFrOEA0gawY QmeCfaSimtyJKXCgTwzK/gKDSkXWqvAc36VJEbtNupbZ38ijC5JoQk8jdbH0WNkp8+H5 4Kxp/TWpP73lHZ2s6qlIPOF9LnXd8b1I9ZlD+aLfOKhYK6EhEd/xcn1+uv5CDUqs+lFj /9vxC8LrbiWNwyi1HwxPTaQWsMJyBAJjfpLv1KjXC/lgOS4qwjziut4Ak/+4G1dTbcZG kV+Q== X-Gm-Message-State: ABuFfohpluUTCS7P06lch48ssnEBIfQiyFbs+ok0tSif/zxwm6lIagof Z+OtsVqctz4YK9APV7r6nqQ+czY4 X-Google-Smtp-Source: ACcGV63wMPzkqUwx1jO8kC5Uj5F5lcjqHT2gnOCYQF2EbdkeTNBciKNRiG7IhPjx7D11Y9DvEXAg1g== X-Received: by 2002:adf:e904:: with SMTP id f4-v6mr9336558wrm.258.1539894782127; Thu, 18 Oct 2018 13:33:02 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:08 +0200 Message-Id: <1539894735-14232-42-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::433 Subject: [Qemu-devel] [PULL 41/48] hyperv: add synic message delivery X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Add infrastructure to deliver SynIC messages to the SynIC message page. Note that KVM may also want to deliver (SynIC timer) messages to the same message slot. The problem is that the access to a SynIC message slot is controlled by the value of its .msg_type field which indicates if the slot is being owned by the hypervisor (zero) or by the guest (non-zero). This leaves no room for synchronizing multiple concurrent producers. The simplest way to deal with this for both KVM and QEMU is to only deliver messages in the vcpu thread. KVM already does this; this patch makes it for QEMU, too. Specifically, - add a function for posting messages, which only copies the message into the staging buffer if its free, and schedules a work on the corresponding vcpu to actually deliver it to the guest slot; - instead of a sint ack callback, set up the sint route with a message status callback. This function is called in a bh whenever there are updates to the message slot status: either the vcpu made definitive progress delivering the message from the staging buffer (succeeded or failed) or the guest issued EOM; the status is passed as an argument to the callback. Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-6-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/hyperv/hyperv.c | 162 ++++++++++++++++++++++++++++++++++++++++++--- include/hw/hyperv/hyperv.h | 18 ++++- 2 files changed, 166 insertions(+), 14 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 70cf129..654ca4f 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -148,14 +148,51 @@ static void synic_register_types(void) type_init(synic_register_types) +/* + * KVM has its own message producers (SynIC timers). To guarantee + * serialization with both KVM vcpu and the guest cpu, the messages are first + * staged in an intermediate area and then posted to the SynIC message page in + * the vcpu thread. + */ +typedef struct HvSintStagedMessage { + /* message content staged by hyperv_post_msg */ + struct hyperv_message msg; + /* callback + data (r/o) to complete the processing in a BH */ + HvSintMsgCb cb; + void *cb_data; + /* message posting status filled by cpu_post_msg */ + int status; + /* passing the buck: */ + enum { + /* initial state */ + HV_STAGED_MSG_FREE, + /* + * hyperv_post_msg (e.g. in main loop) grabs the staged area (FREE -> + * BUSY), copies msg, and schedules cpu_post_msg on the assigned cpu + */ + HV_STAGED_MSG_BUSY, + /* + * cpu_post_msg (vcpu thread) tries to copy staged msg to msg slot, + * notify the guest, records the status, marks the posting done (BUSY + * -> POSTED), and schedules sint_msg_bh BH + */ + HV_STAGED_MSG_POSTED, + /* + * sint_msg_bh (BH) verifies that the posting is done, runs the + * callback, and starts over (POSTED -> FREE) + */ + } state; +} HvSintStagedMessage; + struct HvSintRoute { uint32_t sint; SynICState *synic; int gsi; EventNotifier sint_set_notifier; EventNotifier sint_ack_notifier; - HvSintAckClb sint_ack_clb; - void *sint_ack_clb_data; + + HvSintStagedMessage *staged_msg; + unsigned refcount; }; @@ -166,17 +203,115 @@ static CPUState *hyperv_find_vcpu(uint32_t vp_index) return cs; } -static void kvm_hv_sint_ack_handler(EventNotifier *notifier) +/* + * BH to complete the processing of a staged message. + */ +static void sint_msg_bh(void *opaque) +{ + HvSintRoute *sint_route = opaque; + HvSintStagedMessage *staged_msg = sint_route->staged_msg; + + if (atomic_read(&staged_msg->state) != HV_STAGED_MSG_POSTED) { + /* status nor ready yet (spurious ack from guest?), ignore */ + return; + } + + staged_msg->cb(staged_msg->cb_data, staged_msg->status); + staged_msg->status = 0; + + /* staged message processing finished, ready to start over */ + atomic_set(&staged_msg->state, HV_STAGED_MSG_FREE); + /* drop the reference taken in hyperv_post_msg */ + hyperv_sint_route_unref(sint_route); +} + +/* + * Worker to transfer the message from the staging area into the SynIC message + * page in vcpu context. + */ +static void cpu_post_msg(CPUState *cs, run_on_cpu_data data) +{ + HvSintRoute *sint_route = data.host_ptr; + HvSintStagedMessage *staged_msg = sint_route->staged_msg; + SynICState *synic = sint_route->synic; + struct hyperv_message *dst_msg; + bool wait_for_sint_ack = false; + + assert(staged_msg->state == HV_STAGED_MSG_BUSY); + + if (!synic->enabled || !synic->msg_page_addr) { + staged_msg->status = -ENXIO; + goto posted; + } + + dst_msg = &synic->msg_page->slot[sint_route->sint]; + + if (dst_msg->header.message_type != HV_MESSAGE_NONE) { + dst_msg->header.message_flags |= HV_MESSAGE_FLAG_PENDING; + staged_msg->status = -EAGAIN; + wait_for_sint_ack = true; + } else { + memcpy(dst_msg, &staged_msg->msg, sizeof(*dst_msg)); + staged_msg->status = hyperv_sint_route_set_sint(sint_route); + } + + memory_region_set_dirty(&synic->msg_page_mr, 0, sizeof(*synic->msg_page)); + +posted: + atomic_set(&staged_msg->state, HV_STAGED_MSG_POSTED); + /* + * Notify the msg originator of the progress made; if the slot was busy we + * set msg_pending flag in it so it will be the guest who will do EOM and + * trigger the notification from KVM via sint_ack_notifier + */ + if (!wait_for_sint_ack) { + aio_bh_schedule_oneshot(qemu_get_aio_context(), sint_msg_bh, + sint_route); + } +} + +/* + * Post a Hyper-V message to the staging area, for delivery to guest in the + * vcpu thread. + */ +int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *src_msg) +{ + HvSintStagedMessage *staged_msg = sint_route->staged_msg; + + assert(staged_msg); + + /* grab the staging area */ + if (atomic_cmpxchg(&staged_msg->state, HV_STAGED_MSG_FREE, + HV_STAGED_MSG_BUSY) != HV_STAGED_MSG_FREE) { + return -EAGAIN; + } + + memcpy(&staged_msg->msg, src_msg, sizeof(*src_msg)); + + /* hold a reference on sint_route until the callback is finished */ + hyperv_sint_route_ref(sint_route); + + /* schedule message posting attempt in vcpu thread */ + async_run_on_cpu(sint_route->synic->cs, cpu_post_msg, + RUN_ON_CPU_HOST_PTR(sint_route)); + return 0; +} + +static void sint_ack_handler(EventNotifier *notifier) { HvSintRoute *sint_route = container_of(notifier, HvSintRoute, sint_ack_notifier); event_notifier_test_and_clear(notifier); - sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); + + /* + * the guest consumed the previous message so complete the current one with + * -EAGAIN and let the msg originator retry + */ + aio_bh_schedule_oneshot(qemu_get_aio_context(), sint_msg_bh, sint_route); } HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data) + HvSintMsgCb cb, void *cb_data) { HvSintRoute *sint_route; EventNotifier *ack_notifier; @@ -200,14 +335,19 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, goto err; } - ack_notifier = sint_ack_clb ? &sint_route->sint_ack_notifier : NULL; + + ack_notifier = cb ? &sint_route->sint_ack_notifier : NULL; if (ack_notifier) { + sint_route->staged_msg = g_new0(HvSintStagedMessage, 1); + sint_route->staged_msg->cb = cb; + sint_route->staged_msg->cb_data = cb_data; + r = event_notifier_init(ack_notifier, false); if (r) { goto err_sint_set_notifier; } - event_notifier_set_handler(ack_notifier, kvm_hv_sint_ack_handler); + event_notifier_set_handler(ack_notifier, sint_ack_handler); } gsi = kvm_irqchip_add_hv_sint_route(kvm_state, vp_index, sint); @@ -222,8 +362,6 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, goto err_irqfd; } sint_route->gsi = gsi; - sint_route->sint_ack_clb = sint_ack_clb; - sint_route->sint_ack_clb_data = sint_ack_clb_data; sint_route->synic = synic; sint_route->sint = sint; sint_route->refcount = 1; @@ -236,6 +374,7 @@ err_gsi: if (ack_notifier) { event_notifier_set_handler(ack_notifier, NULL); event_notifier_cleanup(ack_notifier); + g_free(sint_route->staged_msg); } err_sint_set_notifier: event_notifier_cleanup(&sint_route->sint_set_notifier); @@ -266,9 +405,10 @@ void hyperv_sint_route_unref(HvSintRoute *sint_route) &sint_route->sint_set_notifier, sint_route->gsi); kvm_irqchip_release_virq(kvm_state, sint_route->gsi); - if (sint_route->sint_ack_clb) { + if (sint_route->staged_msg) { event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); event_notifier_cleanup(&sint_route->sint_ack_notifier); + g_free(sint_route->staged_msg); } event_notifier_cleanup(&sint_route->sint_set_notifier); g_free(sint_route); diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index 6fba476..82d561f 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -11,18 +11,30 @@ #define HW_HYPERV_HYPERV_H #include "cpu-qom.h" +#include "hw/hyperv/hyperv-proto.h" typedef struct HvSintRoute HvSintRoute; -typedef void (*HvSintAckClb)(void *data); + +/* + * Callback executed in a bottom-half when the status of posting the message + * becomes known, before unblocking the connection for further messages + */ +typedef void (*HvSintMsgCb)(void *data, int status); HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data); + HvSintMsgCb cb, void *cb_data); void hyperv_sint_route_ref(HvSintRoute *sint_route); void hyperv_sint_route_unref(HvSintRoute *sint_route); int hyperv_sint_route_set_sint(HvSintRoute *sint_route); +/* + * Submit a message to be posted in vcpu context. If the submission succeeds, + * the status of posting the message is reported via the callback associated + * with the @sint_route; until then no more messages are accepted. + */ +int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); + static inline uint32_t hyperv_vp_index(CPUState *cs) { return cs->cpu_index; From patchwork Thu Oct 18 20:32:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986302 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LVxmRTwA"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhXT1FPjz9s5c for ; Fri, 19 Oct 2018 08:10:33 +1100 (AEDT) Received: from localhost ([::1]:44709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFYs-0005uK-Lm for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:10:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyf-0007qF-6l for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEye-0006el-Fz for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:05 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:40231) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEye-0006eD-9K for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:04 -0400 Received: by mail-wm1-x342.google.com with SMTP id z204-v6so1612001wmc.5 for ; Thu, 18 Oct 2018 13:33:04 -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=vFp6Z/8DOHxngKdWxYeLlhUPmR2EJl6drygvUZcPrY4=; b=LVxmRTwAcjZAELVElVQVDqB0tx5oJE6T4I8703UZQL7q8lJvMX34G0XuLl0CZ46s7y 2DFxu0u5qr5y2mIrcwDbE0ioXDp+ZlCNJYNreTI34In1pPYsoJGs+HpdGAKjilG9TXpo vnFQeeDqsrNzidntywZSk3rLyXAwb61k7Cai5DmwL8wDQVGAhr7K/bEHp7zysLvRMVWh 37ieBpjU3jgz4axJ81blJLA/LPlvKsBRQywdxWFD0swFagv396ysma24KaojMrac5jt5 Xur+2k1//bttN+Ppi3jSSpofFR84PDls5gbaML+BGmfLhonhhQNSgbzL41voSdBOju5J eMBw== 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=vFp6Z/8DOHxngKdWxYeLlhUPmR2EJl6drygvUZcPrY4=; b=c2xM0TxPSn7gzWybFeORubbvEYTR7V56v0+homrS/yJ8+jOsjBnAmdPJxriJcqB8Ai 7JehmCMeI7e108aCzzFltDqK6dl2M9osRLHpeOdXfpiwx/g2JFAG4N2OZK2G5nS/azBQ KVxrPQHhArX2r1eirSKfMqy7N9ngfuFKKJ54M1TiD4oRYFQXrnnevzxN9gGFCOSFlj1S QXX7VnL5I9ppxwu1y7gOFJNLxks+UwTCP+f3F8XFb0qFLsmsHHE5Wd9PLGyuH/2Htp4O 4Uo95jHju6+IgzjEYr85TEmrrA7yWrsUClbcFO4u5/OCBLZ70d1nVIkjhPSSLJOBlFSa ImoQ== X-Gm-Message-State: ABuFfojAsRzJjbhgif78uQfpqAsfYrcEKg2+sUTtXWQqkf0sgwWD0OsK 4smsaW+59umIzsH24SWbyY9unC8E X-Google-Smtp-Source: ACcGV60p4jrQTCS7Ktf+M84aGhqzjXeUxguj5yMOqIqfzbJqqP5g3D/2yyfPwXr7RcdfhqvliVuncw== X-Received: by 2002:a1c:b402:: with SMTP id d2-v6mr1899916wmf.37.1539894782963; Thu, 18 Oct 2018 13:33:02 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:09 +0200 Message-Id: <1539894735-14232-43-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::342 Subject: [Qemu-devel] [PULL 42/48] hyperv: add synic event flag signaling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Add infrastructure to signal SynIC event flags by atomically setting the corresponding bit in the event flags page and firing a SINT if necessary. Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-7-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/hyperv/hyperv.c | 32 ++++++++++++++++++++++++++++++++ include/hw/hyperv/hyperv.h | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 654ca4f..2b0e593 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -12,6 +12,7 @@ #include "qapi/error.h" #include "exec/address-spaces.h" #include "sysemu/kvm.h" +#include "qemu/bitops.h" #include "hw/hyperv/hyperv.h" typedef struct SynICState { @@ -310,6 +311,37 @@ static void sint_ack_handler(EventNotifier *notifier) aio_bh_schedule_oneshot(qemu_get_aio_context(), sint_msg_bh, sint_route); } +/* + * Set given event flag for a given sint on a given vcpu, and signal the sint. + */ +int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno) +{ + int ret; + SynICState *synic = sint_route->synic; + unsigned long *flags, set_mask; + unsigned set_idx; + + if (eventno > HV_EVENT_FLAGS_COUNT) { + return -EINVAL; + } + if (!synic->enabled || !synic->event_page_addr) { + return -ENXIO; + } + + set_idx = BIT_WORD(eventno); + set_mask = BIT_MASK(eventno); + flags = synic->event_page->slot[sint_route->sint].flags; + + if ((atomic_fetch_or(&flags[set_idx], set_mask) & set_mask) != set_mask) { + memory_region_set_dirty(&synic->event_page_mr, 0, + sizeof(*synic->event_page)); + ret = hyperv_sint_route_set_sint(sint_route); + } else { + ret = 0; + } + return ret; +} + HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, HvSintMsgCb cb, void *cb_data) { diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index 82d561f..757c85e 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -34,6 +34,10 @@ int hyperv_sint_route_set_sint(HvSintRoute *sint_route); * with the @sint_route; until then no more messages are accepted. */ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); +/* + * Set event flag @eventno, and signal the SINT if the flag has changed. + */ +int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno); static inline uint32_t hyperv_vp_index(CPUState *cs) { From patchwork Thu Oct 18 20:32:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RqTvJK/q"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bj8w2zswz9sC2 for ; Fri, 19 Oct 2018 08:38:38 +1100 (AEDT) Received: from localhost ([::1]:44894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDG03-00053n-JP for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:38:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyg-0007qI-SF for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyf-0006fn-PJ for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:06 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:42135) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyf-0006f1-Fh for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:05 -0400 Received: by mail-wr1-x429.google.com with SMTP id r17-v6so2746659wrt.9 for ; Thu, 18 Oct 2018 13:33:05 -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=6ScY0Q36fUet9sxMnL5ZRjANdjBRnH/LoTUV7S6kEAg=; b=RqTvJK/q4r5THk4bu99YTMIzwRHFkECPXWKH+K0sWT1OlgCpK4PiSvRbCK9CxJSFtM OF+bVkxf/GYhP6AyiQmnQLOcFsaF3UVJaxSMnsdxC/kNcmxWCXuD4lkIx8NTyXlX/zFS +gHerLY4tBzkxJjzRddxx40PVxNnG3NgtIUaLJJX+T10YQxTg+x2uF9HvjhDbap2+ItN pEnI3ipQScjB1qep2ukLyitHDbPLD2psxZWQeMfTRiwBo/5aW29LU2MbFnd244jxXKZ6 1loFYi2I4FIO7kb59OKh+OFc/Uw+/7FnFRoY9x391HbbMkfFiM+z8eA5oEMKNvMITSEX kKPA== 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=6ScY0Q36fUet9sxMnL5ZRjANdjBRnH/LoTUV7S6kEAg=; b=tEzEam+swgf/3RqLolt4TnYWSYnaFEMSnRuY6EMdNFbKcqceAeBxeQAhsPVV+rO3LM Av2kyjYPcF3+qE2w8vNnrAKGvzzUHGcyyTevQZPYwg976yCUKsGASQei+wL/ucZcRGmU GwpTddphMH59mt5QS1PyOJHxxh5uRnSrk1wotUlgrZpF4ENu68vwXgO/ngKQMcWguJLi I44HN4Mn4jpWs3lPlZXmfQgTulspn+BCIbyh9KUwCdUe0pxFduzgn3OfP/lVAIrI8HR/ n4wjZH1Vqt4gRLOvJhTzpFFKtyvFt3d9aJBWz+/efzyUXZ9d2WFOmyiJlWRorsCIOidu giBg== X-Gm-Message-State: ABuFfojgI3QrOvMv1oUfSggIA080or14jhvEWQma6G/7nf9IHyoWryHk S68OUx5pJ5FYDmp9oKdz/v/PqzvC X-Google-Smtp-Source: ACcGV60fyTnTM89X9T7Im8V+vn12d8cI8bnC3zZm1iCfw1aob5R73If6pdBvLWoS7Y/EuAWeLp5eKw== X-Received: by 2002:adf:bb02:: with SMTP id r2-v6mr30483028wrg.24.1539894784040; Thu, 18 Oct 2018 13:33:04 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:10 +0200 Message-Id: <1539894735-14232-44-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::429 Subject: [Qemu-devel] [PULL 43/48] hyperv: process SIGNAL_EVENT hypercall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Add handling of SIGNAL_EVENT hypercall. For that, provide an interface to associate an EventNotifier with an event connection number, so that it's signaled when the SIGNAL_EVENT hypercall with the matching connection ID is called by the guest. Support for using KVM functionality for this will be added in a followup patch. Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-8-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/hyperv/hyperv.c | 93 ++++++++++++++++++++++++++++++++++++++++ include/hw/hyperv/hyperv-proto.h | 1 + include/hw/hyperv/hyperv.h | 13 ++++++ target/i386/hyperv.c | 10 +++-- 4 files changed, 113 insertions(+), 4 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 2b0e593..d745016 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -13,6 +13,9 @@ #include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "qemu/bitops.h" +#include "qemu/queue.h" +#include "qemu/rcu.h" +#include "qemu/rcu_queue.h" #include "hw/hyperv/hyperv.h" typedef struct SynICState { @@ -450,3 +453,93 @@ int hyperv_sint_route_set_sint(HvSintRoute *sint_route) { return event_notifier_set(&sint_route->sint_set_notifier); } + +typedef struct EventFlagHandler { + struct rcu_head rcu; + QLIST_ENTRY(EventFlagHandler) link; + uint32_t conn_id; + EventNotifier *notifier; +} EventFlagHandler; + +static QLIST_HEAD(, EventFlagHandler) event_flag_handlers; +static QemuMutex handlers_mutex; + +static void __attribute__((constructor)) hv_init(void) +{ + QLIST_INIT(&event_flag_handlers); + qemu_mutex_init(&handlers_mutex); +} + +int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) +{ + int ret; + EventFlagHandler *handler; + + qemu_mutex_lock(&handlers_mutex); + QLIST_FOREACH(handler, &event_flag_handlers, link) { + if (handler->conn_id == conn_id) { + if (notifier) { + ret = -EEXIST; + } else { + QLIST_REMOVE_RCU(handler, link); + g_free_rcu(handler, rcu); + ret = 0; + } + goto unlock; + } + } + + if (notifier) { + handler = g_new(EventFlagHandler, 1); + handler->conn_id = conn_id; + handler->notifier = notifier; + QLIST_INSERT_HEAD_RCU(&event_flag_handlers, handler, link); + ret = 0; + } else { + ret = -ENOENT; + } +unlock: + qemu_mutex_unlock(&handlers_mutex); + return ret; +} + +uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) +{ + uint16_t ret; + EventFlagHandler *handler; + + if (unlikely(!fast)) { + hwaddr addr = param; + + if (addr & (__alignof__(addr) - 1)) { + return HV_STATUS_INVALID_ALIGNMENT; + } + + param = ldq_phys(&address_space_memory, addr); + } + + /* + * Per spec, bits 32-47 contain the extra "flag number". However, we + * have no use for it, and in all known usecases it is zero, so just + * report lookup failure if it isn't. + */ + if (param & 0xffff00000000ULL) { + return HV_STATUS_INVALID_PORT_ID; + } + /* remaining bits are reserved-zero */ + if (param & ~HV_CONNECTION_ID_MASK) { + return HV_STATUS_INVALID_HYPERCALL_INPUT; + } + + ret = HV_STATUS_INVALID_CONNECTION_ID; + rcu_read_lock(); + QLIST_FOREACH_RCU(handler, &event_flag_handlers, link) { + if (handler->conn_id == param) { + event_notifier_set(handler->notifier); + ret = 0; + break; + } + } + rcu_read_unlock(); + return ret; +} diff --git a/include/hw/hyperv/hyperv-proto.h b/include/hw/hyperv/hyperv-proto.h index 2dc78ee..21dc28a 100644 --- a/include/hw/hyperv/hyperv-proto.h +++ b/include/hw/hyperv/hyperv-proto.h @@ -21,6 +21,7 @@ #define HV_STATUS_INVALID_ALIGNMENT 4 #define HV_STATUS_INVALID_PARAMETER 5 #define HV_STATUS_INSUFFICIENT_MEMORY 11 +#define HV_STATUS_INVALID_PORT_ID 17 #define HV_STATUS_INVALID_CONNECTION_ID 18 #define HV_STATUS_INSUFFICIENT_BUFFERS 19 diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index 757c85e..df92ed7 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -39,6 +39,19 @@ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); */ int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno); +/* + * Associate @notifier with the event connection @conn_id, such that @notifier + * is signaled when the guest executes HV_SIGNAL_EVENT hypercall on @conn_id. + * If @notifier is NULL clear the association. + */ +int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier); + +/* + * Process HV_SIGNAL_EVENT hypercall: signal the EventNotifier associated with + * the connection as specified in @param. + */ +uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast); + static inline uint32_t hyperv_vp_index(CPUState *cs) { return cs->cpu_index; diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 3f76c3e..96b3b5a 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -79,16 +79,18 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) return 0; case KVM_EXIT_HYPERV_HCALL: { - uint16_t code; + uint16_t code = exit->u.hcall.input & 0xffff; + bool fast = exit->u.hcall.input & HV_HYPERCALL_FAST; + uint64_t param = exit->u.hcall.params[0]; - code = exit->u.hcall.input & 0xffff; switch (code) { - case HV_POST_MESSAGE: case HV_SIGNAL_EVENT: + exit->u.hcall.result = hyperv_hcall_signal_event(param, fast); + break; default: exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE; - return 0; } + return 0; } default: return -1; From patchwork Thu Oct 18 20:32:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986332 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JF0wwh14"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bjBF5cxcz9sC2 for ; Fri, 19 Oct 2018 08:39:49 +1100 (AEDT) Received: from localhost ([::1]:44899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDG1D-00061K-F3 for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:39:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyh-0007t2-Gr for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyg-0006gZ-PR for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:07 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:41688) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyg-0006fw-Gz for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:06 -0400 Received: by mail-wr1-x442.google.com with SMTP id q7-v6so7267051wrr.8 for ; Thu, 18 Oct 2018 13:33:06 -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=oyn64lGyGVgvvvzaMFhf2Q5Z5Ewc9fa5jWvtrY5hbpA=; b=JF0wwh14tI0b9G3QDb9znHHsCfany9GCECYQMu3IPHU+yG4W1fh0i7F3Hgh4VtXE86 X+zwu0bsLTHfO6keH1B6sVsUOgnMHoj6w6UA2tW+QqTagYK9D+W1gh+vUmc3ZcCMy0Pq 82Bq8vw6BqlWDEFJZMYH1Vogb5k3KIuJY5K1GNZANM6CtiIEBnygKlgmsWAivgthniv9 Ko9Yr9SZZOONvWcuviqQ/MAyTbYolDbjVAimMXppIiCmDbKeVX4UeAF0ScWA4yu1a8bc 066uut7K9L8EIZTIySqz1z3qfM7NSXtZFPxXApqTT2AXnPE+Y+77Bofz/m+bEUwlzT4F UVqg== 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=oyn64lGyGVgvvvzaMFhf2Q5Z5Ewc9fa5jWvtrY5hbpA=; b=FBSSKiYMXYxjia39J1W5GLcXb4+Ft78SC2BaWpNFkENN0F9vy9KVqT8dp5Gyrp/gLy dyPa+D/Lz2LUQuXVpjgRB+ci8JbcTtoqEcOVQ/5F6mTNiupFSSHdoPFf2e2etbXAqqxn fxbJMAwUsdvSPOCShL1RPybJMvDFdmPZqOHfIhUYzQGY2DZoMWRFFXeYzcY2Z4cnCZVS lMLe98JCWZ9eIwgiqTnc/Dg65fghXyFOizA+ok3u2fueE0KLWBCaXI6mOgzq1KtRIrRI 2WjPZMffe6eaIkLVH5olryWqEIFsCypdPDs/eOMOio5q/hFr7w2gq072YLoQ1WoZDZw+ kTQw== X-Gm-Message-State: ABuFfohQg1LEMTWfhL1G5pGI3pFx8vsoWeWNzyIoeJKrYPgvsAB3ibEB uZ0KJqdTfkn088DybYKEptxZVfnQ X-Google-Smtp-Source: ACcGV60LPTdPeDevPWaQgTPI4Tpf2EF65/aQYnHWf4pRJdbN/itO8MwO2GrNd4fPj85rB8AuaojUug== X-Received: by 2002:a5d:6a11:: with SMTP id m17-v6mr31435732wru.192.1539894785228; Thu, 18 Oct 2018 13:33:05 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:11 +0200 Message-Id: <1539894735-14232-45-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::442 Subject: [Qemu-devel] [PULL 44/48] hyperv: add support for KVM_HYPERV_EVENTFD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan When setting up a notifier for Hyper-V event connection, try to use the KVM-assisted one first, and fall back to userspace handling of the hypercall if the kernel doesn't provide the requested feature. Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-9-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/hyperv/hyperv.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index d745016..7a1c1bb 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -13,6 +13,7 @@ #include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "qemu/bitops.h" +#include "qemu/error-report.h" #include "qemu/queue.h" #include "qemu/rcu.h" #include "qemu/rcu_queue.h" @@ -470,7 +471,7 @@ static void __attribute__((constructor)) hv_init(void) qemu_mutex_init(&handlers_mutex); } -int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) +static int set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) { int ret; EventFlagHandler *handler; @@ -503,6 +504,30 @@ unlock: return ret; } +static bool process_event_flags_userspace; + +int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) +{ + if (!process_event_flags_userspace && + !kvm_check_extension(kvm_state, KVM_CAP_HYPERV_EVENTFD)) { + process_event_flags_userspace = true; + + warn_report("Hyper-V event signaling is not supported by this kernel; " + "using slower userspace hypercall processing"); + } + + if (!process_event_flags_userspace) { + struct kvm_hyperv_eventfd hvevfd = { + .conn_id = conn_id, + .fd = notifier ? event_notifier_get_fd(notifier) : -1, + .flags = notifier ? 0 : KVM_HYPERV_EVENTFD_DEASSIGN, + }; + + return kvm_vm_ioctl(kvm_state, KVM_HYPERV_EVENTFD, &hvevfd); + } + return set_event_flag_handler(conn_id, notifier); +} + uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) { uint16_t ret; From patchwork Thu Oct 18 20:32:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986318 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="haqHEPNb"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhnb6D3Zz9s8J for ; Fri, 19 Oct 2018 08:21:55 +1100 (AEDT) Received: from localhost ([::1]:44779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFjt-0008Lh-EG for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:21:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyr-0008DM-RD for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyi-0006hQ-2a for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:12 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:56236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyh-0006gt-RG for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:07 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 206-v6so1558217wmb.5 for ; Thu, 18 Oct 2018 13:33:07 -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=0WIMwHeQ5gna96hERs9chUktGlcbVkLP7prI/gfi0f8=; b=haqHEPNb69xRMJbgQ6WIT7olQRaf0n1HhiWFYHAN2SWB5mmfYKMRypDNVqjwAErnLf JUwocD+ptvdvGyzewgpVYAN52Yn1wCW2x8ftIO4dkq1nbATM4E38JD3Qt9U61gx6bxSj SZYroHNIcxLisfs9WNudqLyiaqpJC0iirMsEodDU8eojkwYO4B5u3ztVw1zO5yuWXvWl wjNJZvSoXbix6aBMBQg9uBEr4+7mWe8DnlPFxf6Tc52dxnytfCXRTx9HYfEMhs4kUcOS SmlovcZUYym+/TgokOJofGm8tIv0pm/5ijK5YYBZZn0B9+2ziZYuRbKKUeoDQyGB7K9v fE/Q== 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=0WIMwHeQ5gna96hERs9chUktGlcbVkLP7prI/gfi0f8=; b=ljR/t3TACJgbzsAtlc6hQ//lJjUeWORfNZvG/1Sb+0Zhq6WBE0DhFzDRiPoIb5ckjw ih68NP4mObbWuG7MbvH8NLw9NOqO02QMLsNQSixM78ZmsikDadh4iCGFNaF1zLBGFRMz VB19Mey/K8n9hPUijMn7O7miw3w8meXWyJzns77gYbVzwkBMdNmDqfq1Do5heHaEClX6 ZXiFftrkOzXKV3C6FuTEUBsE7HXgfJrGNndOMR6CWIBISBhOwK21dHmt1iS1oyaf6bE6 JmnP2E0fLdHWASiaTgadmrc5Fl+/vPMEpLHY0BIr9m3BFGiFXjzwkapmWat/fzodLYvZ kQnw== X-Gm-Message-State: ABuFfog2uCTGWSr+0mtSSxrSOTd4MnM14ZStlGNrLHOtn/DXqJaAF9ek GI5bXNkLyHOve5Kk+OjtP7Aty2aP X-Google-Smtp-Source: ACcGV63DrKkXcwqtoHuKTf8HiocZpevQZ8Knr2P4QZ8rM2S0MHKc4qnp1C44FlUvHCrkwK/coO5inQ== X-Received: by 2002:a1c:700b:: with SMTP id l11-v6mr1775018wmc.81.1539894786496; Thu, 18 Oct 2018 13:33:06 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:12 +0200 Message-Id: <1539894735-14232-46-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::32d Subject: [Qemu-devel] [PULL 45/48] hyperv: process POST_MESSAGE hypercall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Add handling of POST_MESSAGE hypercall. For that, add an interface to regsiter a handler for the messages arrived from the guest on a particular connection id (IOW set up a message connection in Hyper-V speak). Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-10-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/hyperv/hyperv.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ include/hw/hyperv/hyperv.h | 18 ++++++++++ target/i386/hyperv.c | 3 ++ 3 files changed, 105 insertions(+) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 7a1c1bb..a28e724 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -455,6 +455,14 @@ int hyperv_sint_route_set_sint(HvSintRoute *sint_route) return event_notifier_set(&sint_route->sint_set_notifier); } +typedef struct MsgHandler { + struct rcu_head rcu; + QLIST_ENTRY(MsgHandler) link; + uint32_t conn_id; + HvMsgHandler handler; + void *data; +} MsgHandler; + typedef struct EventFlagHandler { struct rcu_head rcu; QLIST_ENTRY(EventFlagHandler) link; @@ -462,15 +470,91 @@ typedef struct EventFlagHandler { EventNotifier *notifier; } EventFlagHandler; +static QLIST_HEAD(, MsgHandler) msg_handlers; static QLIST_HEAD(, EventFlagHandler) event_flag_handlers; static QemuMutex handlers_mutex; static void __attribute__((constructor)) hv_init(void) { + QLIST_INIT(&msg_handlers); QLIST_INIT(&event_flag_handlers); qemu_mutex_init(&handlers_mutex); } +int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data) +{ + int ret; + MsgHandler *mh; + + qemu_mutex_lock(&handlers_mutex); + QLIST_FOREACH(mh, &msg_handlers, link) { + if (mh->conn_id == conn_id) { + if (handler) { + ret = -EEXIST; + } else { + QLIST_REMOVE_RCU(mh, link); + g_free_rcu(mh, rcu); + ret = 0; + } + goto unlock; + } + } + + if (handler) { + mh = g_new(MsgHandler, 1); + mh->conn_id = conn_id; + mh->handler = handler; + mh->data = data; + QLIST_INSERT_HEAD_RCU(&msg_handlers, mh, link); + ret = 0; + } else { + ret = -ENOENT; + } +unlock: + qemu_mutex_unlock(&handlers_mutex); + return ret; +} + +uint16_t hyperv_hcall_post_message(uint64_t param, bool fast) +{ + uint16_t ret; + hwaddr len; + struct hyperv_post_message_input *msg; + MsgHandler *mh; + + if (fast) { + return HV_STATUS_INVALID_HYPERCALL_CODE; + } + if (param & (__alignof__(*msg) - 1)) { + return HV_STATUS_INVALID_ALIGNMENT; + } + + len = sizeof(*msg); + msg = cpu_physical_memory_map(param, &len, 0); + if (len < sizeof(*msg)) { + ret = HV_STATUS_INSUFFICIENT_MEMORY; + goto unmap; + } + if (msg->payload_size > sizeof(msg->payload)) { + ret = HV_STATUS_INVALID_HYPERCALL_INPUT; + goto unmap; + } + + ret = HV_STATUS_INVALID_CONNECTION_ID; + rcu_read_lock(); + QLIST_FOREACH_RCU(mh, &msg_handlers, link) { + if (mh->conn_id == (msg->connection_id & HV_CONNECTION_ID_MASK)) { + ret = mh->handler(msg, mh->data); + break; + } + } + rcu_read_unlock(); + +unmap: + cpu_physical_memory_unmap(msg, len, 0, 0); + return ret; +} + static int set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) { int ret; diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index df92ed7..597381c 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -40,6 +40,18 @@ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno); /* + * Handler for messages arriving from the guest via HV_POST_MESSAGE hypercall. + * Executed in vcpu context. + */ +typedef uint16_t (*HvMsgHandler)(const struct hyperv_post_message_input *msg, + void *data); +/* + * Associate @handler with the message connection @conn_id, such that @handler + * is called with @data when the guest executes HV_POST_MESSAGE hypercall on + * @conn_id. If @handler is NULL clear the association. + */ +int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data); +/* * Associate @notifier with the event connection @conn_id, such that @notifier * is signaled when the guest executes HV_SIGNAL_EVENT hypercall on @conn_id. * If @notifier is NULL clear the association. @@ -47,6 +59,12 @@ int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno); int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier); /* + * Process HV_POST_MESSAGE hypercall: parse the data in the guest memory as + * specified in @param, and call the HvMsgHandler associated with the + * connection on the message contained therein. + */ +uint16_t hyperv_hcall_post_message(uint64_t param, bool fast); +/* * Process HV_SIGNAL_EVENT hypercall: signal the EventNotifier associated with * the connection as specified in @param. */ diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 96b3b5a..b264a28 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -84,6 +84,9 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) uint64_t param = exit->u.hcall.params[0]; switch (code) { + case HV_POST_MESSAGE: + exit->u.hcall.result = hyperv_hcall_post_message(param, fast); + break; case HV_SIGNAL_EVENT: exit->u.hcall.result = hyperv_hcall_signal_event(param, fast); break; From patchwork Thu Oct 18 20:32:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986333 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Czwm+ict"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bjCh1Z46z9sC2 for ; Fri, 19 Oct 2018 08:41:04 +1100 (AEDT) Received: from localhost ([::1]:44908 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDG2P-0007CJ-Rb for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:41:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyr-0008DL-R4 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyk-0006jH-Et for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:12 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:43362) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyi-0006ha-Tj for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:10 -0400 Received: by mail-wr1-x441.google.com with SMTP id n1-v6so35103031wrt.10 for ; Thu, 18 Oct 2018 13:33:08 -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=lXeiB6ekUojRAKLq4p+caxXDfC0SpFZfyJvsQ6gzZwU=; b=Czwm+ict6lMk3Es4dE9yye85plimZzflBpwL4y2Mlcv/iIGNNVGgqg3oOF9hIXbczB i0LuR5U2oFtbcZTPnMudccvSBLCDv6FC8Qf6x0Y8S6IFjls6uaVC1WMLK2NrXJegiTtq LeQTREYPW8EmH+YJSHu6/1Gbem2UPJs/ENLVW5nONvOHiwjAgYmL6RUmBJa1FMhtiSFN Btmy+QoTExx04P9Qt6FxqGkjOPvPyU5Q/ptKV94r82MKkcvGejKELJ+QcnsyX+gPHEaB xF6Ao4uFSd6WCn5WZqFtCXsq/TWRbh6W27pnR4QT76/kxxnhmnw37FdVhOqK9U9mHexl uVWQ== 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=lXeiB6ekUojRAKLq4p+caxXDfC0SpFZfyJvsQ6gzZwU=; b=KAV4XMZcxIVTdUsGKZtM7t9dXHz5WObwn8mHl2lW7J4TrR+W85wdn7OSIEcerxb5x8 FFp5F+ANZbANGTowihsdfx3Rx8/i7wO74x/pUPF8P3Au1oi8jFC+NUtVXz99hignoZsJ lDQRyCu2OD8gkENtplztdFaBTRyMnYLZ0l3DhV4Hiezt2Kv+5jMt5cx4HHgsnSMPO9u8 QT40vFS0k9YDoHSZwbBZMS0hCEacAxjHtRfsWIayyH6cnSwAOnIM7wf0hXIdlqnqkOiU bhHuwjvOJlwnkJ95U92vFz7VFW2/nZsJnk1VDjgawUrndqtPGbV2A0yv6miMKyLqmaEv 0xZQ== X-Gm-Message-State: ABuFfogkmol7vVJgVuEBfQAxuaLpNXmfNVIKEZHLo1voG4TopiES909e pLpIMfRyV18k/3dCCMmxOXrO7D/n X-Google-Smtp-Source: ACcGV61xuXPLYC+WMOVAtsaC7u+35fefXqxxZ9ZQA82vqOChiKGS33H/OMyhyKVuNHmA+0FBal7I3Q== X-Received: by 2002:adf:91a4:: with SMTP id 33-v6mr30398269wri.37.1539894787541; Thu, 18 Oct 2018 13:33:07 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:13 +0200 Message-Id: <1539894735-14232-47-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::441 Subject: [Qemu-devel] [PULL 46/48] hyperv_testdev: add SynIC message and event testmodes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kagan Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Roman Kagan Add testmodes for SynIC messages and events. The message or event connection setup / teardown is initiated by the guest via new control codes written to the test device port. Then the test connections bounce the respective operations back to the guest, i.e. the incoming messages are posted or the incoming events are signaled on the configured vCPUs. Signed-off-by: Roman Kagan Signed-off-by: Paolo Bonzini --- hw/hyperv/hyperv_testdev.c | 165 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-) diff --git a/hw/hyperv/hyperv_testdev.c b/hw/hyperv/hyperv_testdev.c index fc3f6c5..4880333 100644 --- a/hw/hyperv/hyperv_testdev.c +++ b/hw/hyperv/hyperv_testdev.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/queue.h" #include "hw/qdev.h" #include "hw/isa/isa.h" @@ -24,10 +25,26 @@ typedef struct TestSintRoute { HvSintRoute *sint_route; } TestSintRoute; +typedef struct TestMsgConn { + QLIST_ENTRY(TestMsgConn) le; + uint8_t conn_id; + HvSintRoute *sint_route; + struct hyperv_message msg; +} TestMsgConn; + +typedef struct TestEvtConn { + QLIST_ENTRY(TestEvtConn) le; + uint8_t conn_id; + HvSintRoute *sint_route; + EventNotifier notifier; +} TestEvtConn; + struct HypervTestDev { ISADevice parent_obj; MemoryRegion sint_control; QLIST_HEAD(, TestSintRoute) sint_routes; + QLIST_HEAD(, TestMsgConn) msg_conns; + QLIST_HEAD(, TestEvtConn) evt_conns; }; typedef struct HypervTestDev HypervTestDev; @@ -38,7 +55,11 @@ typedef struct HypervTestDev HypervTestDev; enum { HV_TEST_DEV_SINT_ROUTE_CREATE = 1, HV_TEST_DEV_SINT_ROUTE_DESTROY, - HV_TEST_DEV_SINT_ROUTE_SET_SINT + HV_TEST_DEV_SINT_ROUTE_SET_SINT, + HV_TEST_DEV_MSG_CONN_CREATE, + HV_TEST_DEV_MSG_CONN_DESTROY, + HV_TEST_DEV_EVT_CONN_CREATE, + HV_TEST_DEV_EVT_CONN_DESTROY, }; static void sint_route_create(HypervTestDev *dev, @@ -93,6 +114,133 @@ static void sint_route_set_sint(HypervTestDev *dev, hyperv_sint_route_set_sint(sint_route->sint_route); } +static void msg_retry(void *opaque) +{ + TestMsgConn *conn = opaque; + assert(!hyperv_post_msg(conn->sint_route, &conn->msg)); +} + +static void msg_cb(void *data, int status) +{ + TestMsgConn *conn = data; + + if (!status) { + return; + } + + assert(status == -EAGAIN); + + aio_bh_schedule_oneshot(qemu_get_aio_context(), msg_retry, conn); +} + +static uint16_t msg_handler(const struct hyperv_post_message_input *msg, + void *data) +{ + int ret; + TestMsgConn *conn = data; + + /* post the same message we've got */ + conn->msg.header.message_type = msg->message_type; + assert(msg->payload_size < sizeof(conn->msg.payload)); + conn->msg.header.payload_size = msg->payload_size; + memcpy(&conn->msg.payload, msg->payload, msg->payload_size); + + ret = hyperv_post_msg(conn->sint_route, &conn->msg); + + switch (ret) { + case 0: + return HV_STATUS_SUCCESS; + case -EAGAIN: + return HV_STATUS_INSUFFICIENT_BUFFERS; + default: + return HV_STATUS_INVALID_HYPERCALL_INPUT; + } +} + +static void msg_conn_create(HypervTestDev *dev, uint8_t vp_index, + uint8_t sint, uint8_t conn_id) +{ + TestMsgConn *conn; + + conn = g_new0(TestMsgConn, 1); + assert(conn); + + conn->conn_id = conn_id; + + conn->sint_route = hyperv_sint_route_new(vp_index, sint, msg_cb, conn); + assert(conn->sint_route); + + assert(!hyperv_set_msg_handler(conn->conn_id, msg_handler, conn)); + + QLIST_INSERT_HEAD(&dev->msg_conns, conn, le); +} + +static void msg_conn_destroy(HypervTestDev *dev, uint8_t conn_id) +{ + TestMsgConn *conn; + + QLIST_FOREACH(conn, &dev->msg_conns, le) { + if (conn->conn_id == conn_id) { + QLIST_REMOVE(conn, le); + hyperv_set_msg_handler(conn->conn_id, NULL, NULL); + hyperv_sint_route_unref(conn->sint_route); + g_free(conn); + return; + } + } + assert(false); +} + +static void evt_conn_handler(EventNotifier *notifier) +{ + TestEvtConn *conn = container_of(notifier, TestEvtConn, notifier); + + event_notifier_test_and_clear(notifier); + + /* signal the same event flag we've got */ + assert(!hyperv_set_event_flag(conn->sint_route, conn->conn_id)); +} + +static void evt_conn_create(HypervTestDev *dev, uint8_t vp_index, + uint8_t sint, uint8_t conn_id) +{ + TestEvtConn *conn; + + conn = g_new0(TestEvtConn, 1); + assert(conn); + + conn->conn_id = conn_id; + + conn->sint_route = hyperv_sint_route_new(vp_index, sint, NULL, NULL); + assert(conn->sint_route); + + assert(!event_notifier_init(&conn->notifier, false)); + + event_notifier_set_handler(&conn->notifier, evt_conn_handler); + + assert(!hyperv_set_event_flag_handler(conn_id, &conn->notifier)); + + QLIST_INSERT_HEAD(&dev->evt_conns, conn, le); +} + +static void evt_conn_destroy(HypervTestDev *dev, uint8_t conn_id) +{ + TestEvtConn *conn; + + QLIST_FOREACH(conn, &dev->evt_conns, le) { + if (conn->conn_id == conn_id) { + QLIST_REMOVE(conn, le); + hyperv_set_event_flag_handler(conn->conn_id, NULL); + event_notifier_set_handler(&conn->notifier, NULL); + event_notifier_cleanup(&conn->notifier); + hyperv_sint_route_unref(conn->sint_route); + g_free(conn); + return; + } + } + assert(false); +} + static uint64_t hv_test_dev_read(void *opaque, hwaddr addr, unsigned size) { return 0; @@ -105,6 +253,7 @@ static void hv_test_dev_write(void *opaque, hwaddr addr, uint64_t data, uint8_t sint = data & 0xFF; uint8_t vp_index = (data >> 8ULL) & 0xFF; uint8_t ctl = (data >> 16ULL) & 0xFF; + uint8_t conn_id = (data >> 24ULL) & 0xFF; switch (ctl) { case HV_TEST_DEV_SINT_ROUTE_CREATE: @@ -116,6 +265,18 @@ static void hv_test_dev_write(void *opaque, hwaddr addr, uint64_t data, case HV_TEST_DEV_SINT_ROUTE_SET_SINT: sint_route_set_sint(dev, vp_index, sint); break; + case HV_TEST_DEV_MSG_CONN_CREATE: + msg_conn_create(dev, vp_index, sint, conn_id); + break; + case HV_TEST_DEV_MSG_CONN_DESTROY: + msg_conn_destroy(dev, conn_id); + break; + case HV_TEST_DEV_EVT_CONN_CREATE: + evt_conn_create(dev, vp_index, sint, conn_id); + break; + case HV_TEST_DEV_EVT_CONN_DESTROY: + evt_conn_destroy(dev, conn_id); + break; default: break; } @@ -136,6 +297,8 @@ static void hv_test_dev_realizefn(DeviceState *d, Error **errp) MemoryRegion *io = isa_address_space_io(isa); QLIST_INIT(&dev->sint_routes); + QLIST_INIT(&dev->msg_conns); + QLIST_INIT(&dev->evt_conns); memory_region_init_io(&dev->sint_control, OBJECT(dev), &synic_test_sint_ops, dev, "hyperv-testdev-ctl", 4); From patchwork Thu Oct 18 20:32:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gymUeMGG"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhgY2rmkz9s5c for ; Fri, 19 Oct 2018 08:16:41 +1100 (AEDT) Received: from localhost ([::1]:44748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFeo-0002pP-OD for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:16:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyx-0008LJ-WA for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyo-0006oR-Cw for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:17 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:37972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyk-0006iJ-GW for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:11 -0400 Received: by mail-wm1-x341.google.com with SMTP id 193-v6so1615628wme.3 for ; Thu, 18 Oct 2018 13:33:10 -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=De8NwmFa5akDYuqBdOrmCmF0zFNnVmk+QyPYEwc7WmE=; b=gymUeMGGYBO2ddZjSzKFAeqds8lLq+ET2u+wRfyDqOcvJaHwpMu53533PrUVibKIb7 opUEqzpOOdtBpY4hxoWokPjk8QR/b3vEEHLdSs7KyQts/F4fKSkxn3KzgL24PGPjm1+/ Bworrbsa6THUt+wzcX73c4wPNmFvUlFRvC5vx2kf0z0CGRjMtc/phMsVUAAllbyZ557K u3/F1D55O43Gamu2+kbXBnD02663InKe6o3TRjvOk25Jr4OAe1p61ysF9H0YwvDgRMSR Hgq7UOq9KpMyhk7iklQXVLOYsJklxMccxypzBXE6FDoxemk2RYn+rtVgTCOBqPjEMD3W xymg== 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=De8NwmFa5akDYuqBdOrmCmF0zFNnVmk+QyPYEwc7WmE=; b=UpHMyEXiytxnUngjr7gZcHEAhNM3ocncihBYpPdtMWociGue0remKR8q+GCfuv8po4 7DvHQhBi/uhL4Ec6bBEJp1a9d4eVP9XeH45DRGD/bFFXbkMqy14MvLX/2H50woUEvBGs cxyG7+OS8IOygbArZADfwsU73bdesUeuA6mchCx5bdql6dp8ShYeRIbTh/SSuEuTO98B sYnVAgs36t3XY6UussDlB3QpSf9kEsVE3e+zwXei9/SIZxNIfv2JFzTuHiOwJZ9WTBIJ +U1PCFmm0/17AU13WKxCGoXmQzpWyM/vrDNwvcY6qMhs9PHwY/PK0auU/6szIhmSt+hr GZpw== X-Gm-Message-State: ABuFfoiJuI+jC9MN5vylNv2IgcWtRTJw+U836EXpHUk3GVE9mG6oLsXA A1xrt8C/KxztRyyvsHopE0LAIHdm X-Google-Smtp-Source: ACcGV63SW5qDn9AyGIC530grxrYPYIshqCMueoGg7vq6fGX2l+MfINTVo2lUd02EfWWl7VF+yEhPtw== X-Received: by 2002:a1c:1e8e:: with SMTP id e136-v6mr1903369wme.100.1539894789266; Thu, 18 Oct 2018 13:33:09 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:14 +0200 Message-Id: <1539894735-14232-48-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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 47/48] target/i386: kvm: just return after migrate_add_blocker failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Li Qiang When migrate_add_blocker failed, the invtsc_mig_blocker is not appended so no need to remove. This can save several instructions. Signed-off-by: Li Qiang Message-Id: <20181006091816.7659-1-liq3ea@163.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 7b7a565..115d8b4 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1198,7 +1198,7 @@ int kvm_arch_init_vcpu(CPUState *cs) if (local_err) { error_report_err(local_err); error_free(invtsc_mig_blocker); - goto fail; + return r; } /* for savevm */ vmstate_x86_cpu.unmigratable = 1; From patchwork Thu Oct 18 20:32:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dcOSso+U"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bj06702Mz9sBj for ; Fri, 19 Oct 2018 08:31:02 +1100 (AEDT) Received: from localhost ([::1]:44845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFsi-0008E3-Ij for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:31:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEz0-0008Mu-W8 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyy-0006sf-1j for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:25 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:39657) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyq-0006kc-97 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:17 -0400 Received: by mail-wm1-x330.google.com with SMTP id y144-v6so1608645wmd.4 for ; Thu, 18 Oct 2018 13:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=8r3sTWBWhTiD/8sRkve63BtWuTsIlPBKBUDE414YNPE=; b=dcOSso+U1rMAGfx+EhlSafovuQmVbYVvevktFeBC4W/9VZjTZKYAleuz4oOAydY35q TGc2ejuZrpJMJ6gTEHPLNaHMlS2feZNTPx0yKHnYMQZcPDsE56tuMYRAzrxVCXqHEs9O Ea0TpAwmn0avzytlJxspE2V+kCyq/GJFhv5FFtiwEXT6jFfKLegAjh2dpofzCftM2f/J zX4ydRCYT5vBMWLTHgUSMBEhvJUHE/CyyfwXhiwHT9aXnrFCdBpce4/gPSaLRVHrbrmx UBAe2EvHXXUsxMZn6oY5IluOfhRdbBFleVMf35K/z06h+bzCFlw8ZCgGMHjrXAmHzcM+ MRFg== 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:subject:date:message-id :in-reply-to:references; bh=8r3sTWBWhTiD/8sRkve63BtWuTsIlPBKBUDE414YNPE=; b=pJ67D/2cDd2RWnUu0RBA7BqqFbiW3KEpSmbSX16m9SnftNK50kiS531Ui/cjNUQj6o D0To4sQnMOhHK1wdiuLJUcp+SIzF2tct9ferwdbSobLp+SlsTXotjPQo75Qba7CUYDx8 ZBqyGizmVhQ5lQ1Og+EnJK55Yo4P5t82JPCIh767LR3tFAlFGrwrgnAtpCsGY+Nqki/H zsO+Ee8Ilq+W3K0zKYttJPiRm0nfED9w2mebHLC1U70zSNPo66gWO+3bYex4pZOHHXcC Nonc4lRRhI/oOwYRFwJWZIPVt7kxrz0MHYCjj+8WbE34WVdZPKg8eW6xXOZSvY+EYuO+ 4QgA== X-Gm-Message-State: ABuFfohV4vu6lzBUbITt4xH55+iFuORfJiabfYoQLks0Vu0vorilRNnN puLULphLSMjc/pwsmmN1EpBb4L3E X-Google-Smtp-Source: ACcGV60luzgsjbWlpn8i/5iNydiGVzAw30ZF9GnEY//P0ipDVc0SBq+dCdAvQTHrXyQz7znEP8Qn/g== X-Received: by 2002:a1c:af07:: with SMTP id y7-v6mr1940398wme.33.1539894790727; Thu, 18 Oct 2018 13:33:10 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:15 +0200 Message-Id: <1539894735-14232-49-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-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::330 Subject: [Qemu-devel] [PULL 48/48] replay: pass raw icount value to replay_save_clock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This avoids lock recursion when REPLAY_CLOCK is called inside the timers spinlock. Signed-off-by: Paolo Bonzini --- cpus.c | 4 ++-- include/sysemu/replay.h | 10 ++++++++-- replay/replay-internal.c | 25 +++++++++++++++---------- replay/replay-internal.h | 2 ++ replay/replay-time.c | 8 +++++--- stubs/cpu-get-icount.c | 5 +++++ stubs/replay.c | 2 +- 7 files changed, 38 insertions(+), 18 deletions(-) diff --git a/cpus.c b/cpus.c index 361678e..1c741bc 100644 --- a/cpus.c +++ b/cpus.c @@ -509,8 +509,8 @@ static void icount_warp_rt(void) seqlock_write_lock(&timers_state.vm_clock_seqlock, &timers_state.vm_clock_lock); if (runstate_is_running()) { - int64_t clock = REPLAY_CLOCK(REPLAY_CLOCK_VIRTUAL_RT, - cpu_get_clock_locked()); + int64_t clock = REPLAY_CLOCK_LOCKED(REPLAY_CLOCK_VIRTUAL_RT, + cpu_get_clock_locked()); int64_t warp_delta; warp_delta = clock - timers_state.vm_clock_warp_start; diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 7f7a594..3a7c58e 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -100,14 +100,20 @@ bool replay_has_interrupt(void); /* Processing clocks and other time sources */ /*! Save the specified clock */ -int64_t replay_save_clock(ReplayClockKind kind, int64_t clock); +int64_t replay_save_clock(ReplayClockKind kind, int64_t clock, + int64_t raw_icount); /*! Read the specified clock from the log or return cached data */ int64_t replay_read_clock(ReplayClockKind kind); /*! Saves or reads the clock depending on the current replay mode. */ #define REPLAY_CLOCK(clock, value) \ (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \ : replay_mode == REPLAY_MODE_RECORD \ - ? replay_save_clock((clock), (value)) \ + ? replay_save_clock((clock), (value), cpu_get_icount_raw()) \ + : (value)) +#define REPLAY_CLOCK_LOCKED(clock, value) \ + (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \ + : replay_mode == REPLAY_MODE_RECORD \ + ? replay_save_clock((clock), (value), cpu_get_icount_raw_locked()) \ : (value)) /* Events */ diff --git a/replay/replay-internal.c b/replay/replay-internal.c index b077cb5..1cea1d4 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -217,20 +217,25 @@ void replay_mutex_unlock(void) } } +void replay_advance_current_step(uint64_t current_step) +{ + int diff = (int)(replay_get_current_step() - replay_state.current_step); + + /* Time can only go forward */ + assert(diff >= 0); + + if (diff > 0) { + replay_put_event(EVENT_INSTRUCTION); + replay_put_dword(diff); + replay_state.current_step += diff; + } +} + /*! Saves cached instructions. */ void replay_save_instructions(void) { if (replay_file && replay_mode == REPLAY_MODE_RECORD) { g_assert(replay_mutex_locked()); - int diff = (int)(replay_get_current_step() - replay_state.current_step); - - /* Time can only go forward */ - assert(diff >= 0); - - if (diff > 0) { - replay_put_event(EVENT_INSTRUCTION); - replay_put_dword(diff); - replay_state.current_step += diff; - } + replay_advance_current_step(replay_get_current_step()); } } diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 9b0fd91..af6f4d5 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -122,6 +122,8 @@ void replay_finish_event(void); data_kind variable. */ void replay_fetch_data_kind(void); +/*! Advance replay_state.current_step to the specified value. */ +void replay_advance_current_step(uint64_t current_step); /*! Saves queued events (like instructions and sound). */ void replay_save_instructions(void); diff --git a/replay/replay-time.c b/replay/replay-time.c index 6a7565e..0df1693 100644 --- a/replay/replay-time.c +++ b/replay/replay-time.c @@ -15,13 +15,15 @@ #include "replay-internal.h" #include "qemu/error-report.h" -int64_t replay_save_clock(ReplayClockKind kind, int64_t clock) +int64_t replay_save_clock(ReplayClockKind kind, int64_t clock, int64_t raw_icount) { - if (replay_file) { g_assert(replay_mutex_locked()); - replay_save_instructions(); + /* Due to the caller's locking requirements we get the icount from it + * instead of using replay_save_instructions(). + */ + replay_advance_current_step(raw_icount); replay_put_event(EVENT_CLOCK + kind); replay_put_qword(clock); } diff --git a/stubs/cpu-get-icount.c b/stubs/cpu-get-icount.c index 0b7239d..35f0c1e 100644 --- a/stubs/cpu-get-icount.c +++ b/stubs/cpu-get-icount.c @@ -11,6 +11,11 @@ int64_t cpu_get_icount(void) abort(); } +int64_t cpu_get_icount_raw(void) +{ + abort(); +} + void qemu_timer_notify_cb(void *opaque, QEMUClockType type) { qemu_notify_event(); diff --git a/stubs/replay.c b/stubs/replay.c index 04279ab..4ac6078 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -4,7 +4,7 @@ ReplayMode replay_mode; -int64_t replay_save_clock(unsigned int kind, int64_t clock) +int64_t replay_save_clock(unsigned int kind, int64_t clock, int64_t raw_icount) { abort(); return 0;