From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321034011476.50869454024564; Thu, 1 Jun 2017 05:43:54 -0700 (PDT) Received: from localhost ([::1]:44158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPSC-0004vP-6V for importer@patchew.org; Thu, 01 Jun 2017 08:43:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQR-0003MZ-Gm for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQN-0005fF-87 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:03 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35356) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQN-0005eY-22 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:41:59 -0400 Received: by mail-wm0-x243.google.com with SMTP id g15so11028088wmc.2 for ; Thu, 01 Jun 2017 05:41:57 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.41.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:41:55 -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=X+QrCGsug6TNVGVsam5dWZ/6rpjMMZmdDcvTPUbNPMw=; b=XHUEpjaueoQBr8IqkgS0iz9SMu3MEMn5ziDSxhDXWVpdDfrfytkHtwb8XeJF8s6xUK oclHLo33zBETJUFmf4OLSdT3rXKuDyXTyYrY0CJxDi19Clgvsv/GVqyoUglPiOHIYkz8 uSnxgeZQg/d1vAtEtSJo/G7WqbQK3t3s3xoDQf06ODZRDz3gcutdyyvo3BNl7PAld+s6 TOGanVyYOYxe6ZfjDIAAvB8W6fA2VFmCn67Uon6tWqwCMheBCTNixJZz3f5XSdKhWnzP RkI3gE+iOUtkmHqcRuVlI1Y05psEOLh+GqT90X0NvKdVKoc1Uv3hA6KbP3A6YQj0GDiV Z6TA== 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=X+QrCGsug6TNVGVsam5dWZ/6rpjMMZmdDcvTPUbNPMw=; b=GNkwHm3XyF7TGllOTZj53ivgn5Ki/qCSNwmr9R8Uok6+ysLVp6T/5PiNRQ2BeJmw4V 2tMRsrMKUFZPDpIvTlOpjvqzDtPQ6Z772rF1tBoLN6Sj3NIaxZQM1gPmQIuyLCqeNxDP ikgZwTLhjrRqXKXYmUBKFCyTf99fD50XsrL4DHjPA+48bk/fEKM4Fo5lodB/6l6L8IHU AzgaZ+Gb1e2uIAg0CfepV1TMXcalV9diBokipzReLpwQxna51qaHaVbeC0xtS4UfnTEp m2Z7RYzHDz7ryPo8YSBoAQwl5SJFjhTz+bJznQ7Zq5ZZ+RG8Qt97+YJ1Kji77f6QOaMA cAQw== X-Gm-Message-State: AODbwcAa2rnnwXlIsImla+KItnZbB+webO5b+mfSdRyFYCSoqhX8w3e8 sq0FgrIQ9I1SJOyaZYU= X-Received: by 10.28.181.139 with SMTP id e133mr8446522wmf.65.1496320916180; Thu, 01 Jun 2017 05:41:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:19 +0200 Message-Id: <1496320911-51305-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::243 Subject: [Qemu-devel] [PULL 01/33] mc146818rtc: update periodic timer only if it is needed 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: Xiao Guangrong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Currently, the timer is updated whenever RegA or RegB is written even if the periodic timer related configuration is not changed This patch optimizes it slightly to make the update happen only if its period or enable-status is changed, also later patches are depend on this optimization Signed-off-by: Xiao Guangrong Message-Id: <20170510083259.3900-2-xiaoguangrong@tencent.com> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 93de3e1..7d78391 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -391,6 +391,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) { RTCState *s =3D opaque; + bool update_periodic_timer; =20 if ((addr & 1) =3D=3D 0) { s->cmos_index =3D data & 0x7f; @@ -423,6 +424,8 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, } break; case RTC_REG_A: + update_periodic_timer =3D (s->cmos_data[RTC_REG_A] ^ data) & 0= x0f; + if ((data & 0x60) =3D=3D 0x60) { if (rtc_running(s)) { rtc_update_time(s); @@ -445,10 +448,17 @@ static void cmos_ioport_write(void *opaque, hwaddr ad= dr, /* UIP bit is read only */ s->cmos_data[RTC_REG_A] =3D (data & ~REG_A_UIP) | (s->cmos_data[RTC_REG_A] & REG_A_UIP); - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + + if (update_periodic_timer) { + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + } + check_update_timer(s); break; case RTC_REG_B: + update_periodic_timer =3D (s->cmos_data[RTC_REG_B] ^ data) + & REG_B_PIE; + if (data & REG_B_SET) { /* update cmos to when the rtc was stopping */ if (rtc_running(s)) { @@ -475,7 +485,11 @@ static void cmos_ioport_write(void *opaque, hwaddr add= r, qemu_irq_lower(s->irq); } s->cmos_data[RTC_REG_B] =3D data; - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + + if (update_periodic_timer) { + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + } + check_update_timer(s); break; case RTC_REG_C: --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321099328281.8759011215111; Thu, 1 Jun 2017 05:44:59 -0700 (PDT) Received: from localhost ([::1]:44161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPTF-0005nG-IV for importer@patchew.org; Thu, 01 Jun 2017 08:44:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQS-0003Mn-0O for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQM-0005f3-VK for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:04 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34091) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQM-0005ef-Lq for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:41:58 -0400 Received: by mail-wm0-x241.google.com with SMTP id d127so11018589wmf.1 for ; Thu, 01 Jun 2017 05:41:58 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.41.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:41: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=KHQFnnfRU4aj5x3+Aex7iEYcfgRRSUJDqZu4ep4ltuM=; b=FSZLrDDTALsZK5IpyeoWiVGStBvXabhiZjSZ1FmQMYgSkqadvsYDquQX7mQTIdt4Zf ag5o/OjuVDYPp1a+ANUVYty0rdY78yRTRxyox+VRlvorlCPVxO7PSZd1DycUSZdhU6aW a1sIa8a7rB9iwUMajbEJbXhnQcmPoZokOqCE5GsY9YKClHdy2yknFP6ObzxIEgibbTPi KJpm7OtakW1NDYFJxcZhy8Q5TyjZhjoBmvx/TseCDb9SMO7XFGO3R5raOtI8gjwqbrP1 HXDgtRhFqYmDosEKhnLjSoQkf8vLp3AujfEIf8RBWd8vR+FNUN/MYpTiNptS3SJ45FmZ ZfAQ== 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=KHQFnnfRU4aj5x3+Aex7iEYcfgRRSUJDqZu4ep4ltuM=; b=q4LPNHPV0IufyPpp7GAtrPhNeqpokpyMxjg+hfZhVJXPVOgBURRAQh7jA1RPCayNo+ MfHUQsLGsIe7Gnc4jztbjRjmkHBxVderQiuZlCmmz6r4L0aF2LQ8WPH8SCqtHkm9qUlf cgnJ0kpIEERnwZ1SbrUfSaLymAVoISGIkh54gTBNNMYIyfKziAlEDZjN9b5LmnBU9Rvm w3HcDWHR0g0B7RGJVTvnB0B99r5okaEOcddMLY4gGJnHcVA+D7kD35VyNUt3et90dbfa SN8l2Xthgvk9myu2/RKfhEu/jUrMggThmiycVJZ80efOpX0KBnA5Ncp6lbMHVUGqLMKw 8Cww== X-Gm-Message-State: AODbwcDeM5/i3p6tYIo0UxnAjBRzcO5iYuk5Lvih1FrELbNlkF22Vov3 Ti7IvqSCK85Bc6tpraA= X-Received: by 10.28.232.156 with SMTP id f28mr258233wmi.112.1496320917387; Thu, 01 Jun 2017 05:41:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:20 +0200 Message-Id: <1496320911-51305-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::241 Subject: [Qemu-devel] [PULL 02/33] mc146818rtc: precisely count the clock for periodic timer 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: Xiao Guangrong , Tai Yunfang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Tai Yunfang There are two issues in current code: 1) If the period is changed by re-configuring RegA, the coalesced irq will be scaled to reflect the new period, however, it calculates the new interrupt number like this: s->irq_coalesced =3D (s->irq_coalesced * s->period) / period; There are some clocks will be lost if they are not enough to be squeezed to a single new period that will cause the VM clock slower In order to fix the issue, we calculate the interrupt window based on the precise clock rather than period, then the clocks lost during period is scaled can be compensated properly 2) If periodic_timer_update() is called due to RegA reconfiguration, i.e, the period is updated, current time is not the start point for the next periodic timer, instead, which should start from the last interrupt, otherwise, the clock in VM will become slow This patch takes the clocks from last interrupt to current clock into account and compensates the clocks for the next interrupt, especially if a complete interrupt was lost in this window, the time can be caught up by LOST_TICK_POLICY_SLEW Signed-off-by: Tai Yunfang Signed-off-by: Xiao Guangrong Message-Id: <20170510083259.3900-3-xiaoguangrong@tencent.com> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 120 +++++++++++++++++++++++++++++++++++++++------= ---- 1 file changed, 97 insertions(+), 23 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 7d78391..aeb60cc 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -146,31 +146,100 @@ static void rtc_coalesced_timer(void *opaque) } #endif =20 -/* handle periodic timer */ -static void periodic_timer_update(RTCState *s, int64_t current_time) +static uint32_t rtc_periodic_clock_ticks(RTCState *s) { - int period_code, period; - int64_t cur_clock, next_irq_clock; + int period_code; + + if (!(s->cmos_data[RTC_REG_B] & REG_B_PIE)) { + return 0; + } =20 period_code =3D s->cmos_data[RTC_REG_A] & 0x0f; - if (period_code !=3D 0 - && (s->cmos_data[RTC_REG_B] & REG_B_PIE)) { - if (period_code <=3D 2) - period_code +=3D 7; - /* period in 32 Khz cycles */ - period =3D 1 << (period_code - 1); -#ifdef TARGET_I386 - if (period !=3D s->period) { - s->irq_coalesced =3D (s->irq_coalesced * s->period) / period; - DPRINTF_C("cmos: coalesced irqs scaled to %d\n", s->irq_coales= ced); - } - s->period =3D period; -#endif + if (!period_code) { + return 0; + } + + if (period_code <=3D 2) { + period_code +=3D 7; + } + + /* period in 32 Khz cycles */ + return 1 << (period_code - 1); +} + +/* + * handle periodic timer. @old_period indicates the periodic timer update + * is just due to period adjustment. + */ +static void +periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_peri= od) +{ + uint32_t period; + int64_t cur_clock, next_irq_clock, lost_clock =3D 0; + + period =3D rtc_periodic_clock_ticks(s); + + if (period) { /* compute 32 khz clock */ cur_clock =3D muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND); =20 - next_irq_clock =3D (cur_clock & ~(period - 1)) + period; + /* + * if the periodic timer's update is due to period re-configuration, + * we should count the clock since last interrupt. + */ + if (old_period) { + int64_t last_periodic_clock, next_periodic_clock; + + next_periodic_clock =3D muldiv64(s->next_periodic_time, + RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND= ); + last_periodic_clock =3D next_periodic_clock - old_period; + lost_clock =3D cur_clock - last_periodic_clock; + assert(lost_clock >=3D 0); + } + +#ifdef TARGET_I386 + /* + * s->irq_coalesced can change for two reasons: + * + * a) if one or more periodic timer interrupts have been lost, + * lost_clock will be more that a period. + * + * b) when the period may be reconfigured, we expect the OS to + * treat delayed tick as the new period. So, when switching + * from a shorter to a longer period, scale down the missing, + * because the OS will treat past delayed ticks as longer + * (leftovers are put back into lost_clock). When switching + * to a shorter period, scale up the missing ticks since the + * OS handler will treat past delayed ticks as shorter. + */ + if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { + uint32_t old_irq_coalesced =3D s->irq_coalesced; + + s->period =3D period; + lost_clock +=3D old_irq_coalesced * old_period; + s->irq_coalesced =3D lost_clock / s->period; + lost_clock %=3D s->period; + if (old_irq_coalesced !=3D s->irq_coalesced || + old_period !=3D s->period) { + DPRINTF_C("cmos: coalesced irqs scaled from %d to %d, " + "period scaled from %d to %d\n", old_irq_coalesc= ed, + s->irq_coalesced, old_period, s->period); + rtc_coalesced_timer_update(s); + } + } else +#endif + { + /* + * no way to compensate the interrupt if LOST_TICK_POLICY_SLEW + * is not used, we should make the time progress anyway. + */ + lost_clock =3D MIN(lost_clock, period); + } + + assert(lost_clock >=3D 0 && lost_clock <=3D period); + + next_irq_clock =3D cur_clock + period - lost_clock; s->next_periodic_time =3D muldiv64(next_irq_clock, NANOSECONDS_PER= _SECOND, RTC_CLOCK_RATE) + 1; timer_mod(s->periodic_timer, s->next_periodic_time); @@ -186,7 +255,7 @@ static void rtc_periodic_timer(void *opaque) { RTCState *s =3D opaque; =20 - periodic_timer_update(s, s->next_periodic_time); + periodic_timer_update(s, s->next_periodic_time, 0); s->cmos_data[RTC_REG_C] |=3D REG_C_PF; if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { s->cmos_data[RTC_REG_C] |=3D REG_C_IRQF; @@ -391,6 +460,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) { RTCState *s =3D opaque; + uint32_t old_period; bool update_periodic_timer; =20 if ((addr & 1) =3D=3D 0) { @@ -425,6 +495,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, break; case RTC_REG_A: update_periodic_timer =3D (s->cmos_data[RTC_REG_A] ^ data) & 0= x0f; + old_period =3D rtc_periodic_clock_ticks(s); =20 if ((data & 0x60) =3D=3D 0x60) { if (rtc_running(s)) { @@ -450,7 +521,8 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, (s->cmos_data[RTC_REG_A] & REG_A_UIP); =20 if (update_periodic_timer) { - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock), + old_period); } =20 check_update_timer(s); @@ -458,6 +530,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, case RTC_REG_B: update_periodic_timer =3D (s->cmos_data[RTC_REG_B] ^ data) & REG_B_PIE; + old_period =3D rtc_periodic_clock_ticks(s); =20 if (data & REG_B_SET) { /* update cmos to when the rtc was stopping */ @@ -487,7 +560,8 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, s->cmos_data[RTC_REG_B] =3D data; =20 if (update_periodic_timer) { - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock), + old_period); } =20 check_update_timer(s); @@ -757,7 +831,7 @@ static int rtc_post_load(void *opaque, int version_id) uint64_t now =3D qemu_clock_get_ns(rtc_clock); if (now < s->next_periodic_time || now > (s->next_periodic_time + get_max_clock_jump())) { - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock), 0); } } =20 @@ -822,7 +896,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, = void *data) int64_t now =3D *(int64_t *)data; =20 rtc_set_date_from_host(ISA_DEVICE(s)); - periodic_timer_update(s, now); + periodic_timer_update(s, now, 0); check_update_timer(s); #ifdef TARGET_I386 if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321183614341.1321823477326; Thu, 1 Jun 2017 05:46:23 -0700 (PDT) Received: from localhost ([::1]:44172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPUc-00075h-2v for importer@patchew.org; Thu, 01 Jun 2017 08:46:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQR-0003MV-GZ for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQN-0005fP-OR for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:03 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34093) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQN-0005f7-I6 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:41:59 -0400 Received: by mail-wm0-x241.google.com with SMTP id d127so11018716wmf.1 for ; Thu, 01 Jun 2017 05:41:59 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.41.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:41: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=Exg2syP81gDmcrVEGxGRINRbbz4o0JJUZuq7hDAN3Rw=; b=ZtkRrjdLIhsw8TaBuMGBdp0H7+aMIpy9G1DPNAM+OkodC+OrQaud2cjhgNbblAEUpJ rs4O1aovQiglE999F/GqvEylO2h0o0wApGMDoDjKOjoNvkIyqPoN+IIug5mYYWaAIDvG pxB6cYBUt77Akc4P9oiy++mEY1PSSZCgjjpimdBSxM24XIqWraZauLh75G6CaPoSFfNJ o5XGrOD5YeAIYTkYn8CGlr39s8RAe4Cfym8rzystP3hUOsUnIVaSPclfd+UO/BrNcdgV spzCGDjVb1USu73AegNq/7tt2jte1xgxYfGMPxVw6l94J8uBzrJXvic6kwhvRATM/RwG bWzA== 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=Exg2syP81gDmcrVEGxGRINRbbz4o0JJUZuq7hDAN3Rw=; b=r6qhMNFXx/Cant095yj1Vmd3azqnjFrNJV8C7QjLNWIGU7DwEWMTi7lvAh2LIPGZla 2PrBnteyiIga+KW4G3SDv6aqTdtwjch7ewR1fAn+Gimw7XYZ44nwbg27K/rEwwVNahYz 3QwwqPbysGD07U/h1GsuaouCiSxlfJiTIxCVoCVjPNSxVYk+Bh3vUmSt2lAHwT0hHfVq k2iHP5RdMYmGtmn9hbMWcfhOzFQm64L9XuIKeVtwTKAA8V4GrlLqmwq+G+CrjMaZP3Jp PLKUISs5ToGIRoIazthm6duTZglB1aCtFTSp6XaFhfi4cfGnWkSx98PNtT3c+uqOQfKH hjcQ== X-Gm-Message-State: AODbwcDjK+BeG28ZLWUsvSTzEN8uwRpfkJDygCDQewbx0oqG4fZWb+UW 31J4STjw5sbiqgUCsUo= X-Received: by 10.28.48.21 with SMTP id w21mr8561580wmw.44.1496320918356; Thu, 01 Jun 2017 05:41:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:21 +0200 Message-Id: <1496320911-51305-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::241 Subject: [Qemu-devel] [PULL 03/33] mc146818rtc: ensure LOST_TICK_POLICY_SLEW is only enabled on TARGET_I386 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: Xiao Guangrong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Any tick policy specified on other platforms rather on TARGET_I386 will fall back to LOST_TICK_POLICY_DISCARD silently, this patch makes sure only TARGET_I386 can enable LOST_TICK_POLICY_SLEW After that, we can enable LOST_TICK_POLICY_SLEW in the common code which need not use '#ifdef TARGET_I386' to make these code be x86 specific anymore Signed-off-by: Xiao Guangrong Message-Id: <20170510083259.3900-4-xiaoguangrong@tencent.com> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index aeb60cc..4870a72 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -974,19 +974,19 @@ static void rtc_realizefn(DeviceState *dev, Error **e= rrp) =20 rtc_set_date_from_host(isadev); =20 -#ifdef TARGET_I386 switch (s->lost_tick_policy) { +#ifdef TARGET_I386 case LOST_TICK_POLICY_SLEW: s->coalesced_timer =3D timer_new_ns(rtc_clock, rtc_coalesced_timer, s); break; +#endif case LOST_TICK_POLICY_DISCARD: break; default: error_setg(errp, "Invalid lost tick policy."); return; } -#endif =20 s->periodic_timer =3D timer_new_ns(rtc_clock, rtc_periodic_timer, s); s->update_timer =3D timer_new_ns(rtc_clock, rtc_update_timer, s); --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321088422409.8982625495205; Thu, 1 Jun 2017 05:44:48 -0700 (PDT) Received: from localhost ([::1]:44160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPT4-0005gd-Sk for importer@patchew.org; Thu, 01 Jun 2017 08:44:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQR-0003MW-GW for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQO-0005fb-Ow for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:03 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36254) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQO-0005fT-In for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:00 -0400 Received: by mail-wm0-x243.google.com with SMTP id k15so11048268wmh.3 for ; Thu, 01 Jun 2017 05:42:00 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.41.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:41: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=5EYOBR43m1sK1N5wwDP+npsjedy09nV2p3ruO/nJHEQ=; b=nh1MOERkQZG2eg4Fvi1DzUsIBEW6WNLUjMkQgV/9ZvC4+A1LVagCIApeX8zzEyUDMY zfRtOyD7SrU2l4HEppqeP0obg83i23SWj1hZoafYibMJdRPq+S5+ArilK+YLiyKzDAHG vwDkNs+gDNPZxtv9Rf85R9FpIRobMAi9SF9FvP1HY1oImY2dGCuu8cpuTrmJIYxwGBln qUNQ9idysPwF7DHY/dLQD5j4HuYiEDMin5TSwgHzKp7XXbY8fBInbrr3CYpxqaNjhn4V jbwXc+Y6QW6G4/OQB5S4psTTDT3v6Trw5MDXtvTqoe3ahcW1hjKFTodfuV1naZQX47cO xHeg== 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=5EYOBR43m1sK1N5wwDP+npsjedy09nV2p3ruO/nJHEQ=; b=hc5K3+Mm9fU90zUJqmY21cHP4r4tLyl+z87b86nM3KRky4R4ZFb1RlFjt8eYFqcKXc NYLt6Wk4cEygqcK6uwzj69KioSLX36T8inrGfKjcFSA0z3/AeWMYP+8DN5P45qmr1kXJ 1SSqaRNwkfBuQUylBR+rRmbpJIVBY0ymgkn3lZL00IA1sk/WkRCzBoMnl8NNKCXqkQ3J oknhOezEokdsxaIrhC5tKa7OZCHMsaxWz8ZTPT561tbKtJjwH3UxO0Z9q9rTewP0qcM0 yZYlKoU5jN7Y1tysfPo6yPKpdd7ewLNUsFZxHqXMUTHbB3AIZDvw04R8ttuKS6U+Zk5u NHxg== X-Gm-Message-State: AODbwcBq7rC3Y0UcYKy4wW4k6SeLGxljyYWropkMqlFTK+zC1GDSIr4e G8BoE+mLKdtw1bSBZDo= X-Received: by 10.28.31.135 with SMTP id f129mr9744480wmf.78.1496320919353; Thu, 01 Jun 2017 05:41:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:22 +0200 Message-Id: <1496320911-51305-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::243 Subject: [Qemu-devel] [PULL 04/33] mc146818rtc: drop unnecessary '#ifdef TARGET_I386' 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: Xiao Guangrong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong If the code purely depends on LOST_TICK_POLICY_SLEW, we can simply drop '#ifdef TARGET_I386' as only x86 can enable this tick policy Signed-off-by: Xiao Guangrong Message-Id: <20170510083259.3900-5-xiaoguangrong@tencent.com> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 4870a72..f9d6181 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -112,7 +112,6 @@ static uint64_t get_guest_rtc_ns(RTCState *s) guest_clock - s->last_update + s->offset; } =20 -#ifdef TARGET_I386 static void rtc_coalesced_timer_update(RTCState *s) { if (s->irq_coalesced =3D=3D 0) { @@ -126,6 +125,7 @@ static void rtc_coalesced_timer_update(RTCState *s) } } =20 +#ifdef TARGET_I386 static void rtc_coalesced_timer(void *opaque) { RTCState *s =3D opaque; @@ -198,7 +198,6 @@ periodic_timer_update(RTCState *s, int64_t current_time= , uint32_t old_period) assert(lost_clock >=3D 0); } =20 -#ifdef TARGET_I386 /* * s->irq_coalesced can change for two reasons: * @@ -227,9 +226,7 @@ periodic_timer_update(RTCState *s, int64_t current_time= , uint32_t old_period) s->irq_coalesced, old_period, s->period); rtc_coalesced_timer_update(s); } - } else -#endif - { + } else { /* * no way to compensate the interrupt if LOST_TICK_POLICY_SLEW * is not used, we should make the time progress anyway. @@ -244,9 +241,7 @@ periodic_timer_update(RTCState *s, int64_t current_time= , uint32_t old_period) RTC_CLOCK_RATE) + 1; timer_mod(s->periodic_timer, s->next_periodic_time); } else { -#ifdef TARGET_I386 s->irq_coalesced =3D 0; -#endif timer_del(s->periodic_timer); } } @@ -835,13 +830,11 @@ static int rtc_post_load(void *opaque, int version_id) } } =20 -#ifdef TARGET_I386 if (version_id >=3D 2) { if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { rtc_coalesced_timer_update(s); } } -#endif return 0; } =20 @@ -898,11 +891,10 @@ static void rtc_notify_clock_reset(Notifier *notifier= , void *data) rtc_set_date_from_host(ISA_DEVICE(s)); periodic_timer_update(s, now, 0); check_update_timer(s); -#ifdef TARGET_I386 + if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { rtc_coalesced_timer_update(s); } -#endif } =20 /* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE) @@ -923,12 +915,10 @@ static void rtc_reset(void *opaque) =20 qemu_irq_lower(s->irq); =20 -#ifdef TARGET_I386 if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { s->irq_coalesced =3D 0; s->irq_reinject_on_ack_count =3D 0; =09 } -#endif } =20 static const MemoryRegionOps cmos_ops =3D { --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321352627371.59821964002913; Thu, 1 Jun 2017 05:49:12 -0700 (PDT) Received: from localhost ([::1]:44181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPXK-00016H-N7 for importer@patchew.org; Thu, 01 Jun 2017 08:49:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQR-0003MX-Gz for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQQ-0005gf-6c for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:03 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35363) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQP-0005fi-T7 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:02 -0400 Received: by mail-wm0-x244.google.com with SMTP id g15so11028585wmc.2 for ; Thu, 01 Jun 2017 05:42:01 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.41.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:41:59 -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=bB57iMqXIRrgbYpCdy9hkUQfa/px3wD/S4cjQQoGCno=; b=WzoTG2PFBAiXUxMEPV3OXf4UP/yF15sS7CiCyvfouECR+4OpM8NFugVAzymIoIDEhd wjRxtFapzX/3VOrV/mC3l6TeHXf0yUjkLwHq+6Jna2iHeN/OoemB+eRBYOLdaRjR2n3F ojkk4raXJtbPYeSPI+xQ50/oeQtBCLPPj7oFoI/OxsADEAAkSPsY7lzM7p6hDEFV0BnU n/u2lWMgpDBz6MyKzdKwIC2/fMJTibSjC6bZAcgZmjvwsF7MgkwVBSrfu4BkTIb1Cw41 Yy1mH9LMKM9fqYm6psT4OzTjKzXT58b22JmHoZLB/yNURoyUJ21J1lBYllslGxMCXL9V nwQg== 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=bB57iMqXIRrgbYpCdy9hkUQfa/px3wD/S4cjQQoGCno=; b=EeGUsyTEVk24MfpokkOBOROZjJ56vR31QkHugI5AKH7JBiGPhqEq5TxCVfAFyf6m0o 88q5QU4pT0DO5VUQS9E/Oomt2ccSgyuLQAY7RKQWPloeshwUpZKxeFQDPeP6u0RN7LiC P0ERpZUxPAVkY9lR7+iOIPEqeShvRhd4dz8sZeHxn+L+PsKyEx5gbJxBPLwKnONKgPRi SCdrIg6ZKMn8WH5Vb/ppGxZgigic7vLzVmygUtzhWYz029YlPV/FW0T0YFoYlICBrh8+ U+QChj4oUwcy5oTGDyTGXPNrac+H6qyW4VbwyZlbgXnsTtizhZDWJKUt8HUvr0nomDP/ FE+w== X-Gm-Message-State: AODbwcCXBafQCxNqckrdkVeOfZlorfMptMZ8oRnqt6v2LdUqF/viz/0M OfEOPevoyQIceizOc4U= X-Received: by 10.223.143.35 with SMTP id p32mr1136427wrb.120.1496320920482; Thu, 01 Jun 2017 05:42:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:23 +0200 Message-Id: <1496320911-51305-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::244 Subject: [Qemu-devel] [PULL 05/33] mc146818rtc: embrace all x86 specific code 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: Xiao Guangrong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Introduce a function, rtc_policy_slew_deliver_irq(), which delivers irq if LOST_TICK_POLICY_SLEW is used, as which is only supported on x86, other platforms call it will trigger a assert After that, we can move the x86 specific code to the common place Signed-off-by: Xiao Guangrong Message-Id: <20170510083259.3900-6-xiaoguangrong@tencent.com> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 60 ++++++++++++++++++++++++++--------------------= ---- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index f9d6181..542cd09 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -125,17 +125,34 @@ static void rtc_coalesced_timer_update(RTCState *s) } } =20 +static QLIST_HEAD(, RTCState) rtc_devices =3D + QLIST_HEAD_INITIALIZER(rtc_devices); + #ifdef TARGET_I386 +void qmp_rtc_reset_reinjection(Error **errp) +{ + RTCState *s; + + QLIST_FOREACH(s, &rtc_devices, link) { + s->irq_coalesced =3D 0; + } +} + +static bool rtc_policy_slew_deliver_irq(RTCState *s) +{ + apic_reset_irq_delivered(); + qemu_irq_raise(s->irq); + return apic_get_irq_delivered(); +} + static void rtc_coalesced_timer(void *opaque) { RTCState *s =3D opaque; =20 if (s->irq_coalesced !=3D 0) { - apic_reset_irq_delivered(); s->cmos_data[RTC_REG_C] |=3D 0xc0; DPRINTF_C("cmos: injecting from timer\n"); - qemu_irq_raise(s->irq); - if (apic_get_irq_delivered()) { + if (rtc_policy_slew_deliver_irq(s)) { s->irq_coalesced--; DPRINTF_C("cmos: coalesced irqs decreased to %d\n", s->irq_coalesced); @@ -144,6 +161,12 @@ static void rtc_coalesced_timer(void *opaque) =20 rtc_coalesced_timer_update(s); } +#else +static bool rtc_policy_slew_deliver_irq(RTCState *s) +{ + assert(0); + return false; +} #endif =20 static uint32_t rtc_periodic_clock_ticks(RTCState *s) @@ -254,21 +277,17 @@ static void rtc_periodic_timer(void *opaque) s->cmos_data[RTC_REG_C] |=3D REG_C_PF; if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { s->cmos_data[RTC_REG_C] |=3D REG_C_IRQF; -#ifdef TARGET_I386 if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { if (s->irq_reinject_on_ack_count >=3D RTC_REINJECT_ON_ACK_COUN= T) - s->irq_reinject_on_ack_count =3D 0; =09 - apic_reset_irq_delivered(); - qemu_irq_raise(s->irq); - if (!apic_get_irq_delivered()) { + s->irq_reinject_on_ack_count =3D 0; + if (!rtc_policy_slew_deliver_irq(s)) { s->irq_coalesced++; rtc_coalesced_timer_update(s); DPRINTF_C("cmos: coalesced irqs increased to %d\n", s->irq_coalesced); } } else -#endif - qemu_irq_raise(s->irq); + qemu_irq_raise(s->irq); } } =20 @@ -612,20 +631,6 @@ static void rtc_get_time(RTCState *s, struct tm *tm) rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900; } =20 -static QLIST_HEAD(, RTCState) rtc_devices =3D - QLIST_HEAD_INITIALIZER(rtc_devices); - -#ifdef TARGET_I386 -void qmp_rtc_reset_reinjection(Error **errp) -{ - RTCState *s; - - QLIST_FOREACH(s, &rtc_devices, link) { - s->irq_coalesced =3D 0; - } -} -#endif - static void rtc_set_time(RTCState *s) { struct tm tm; @@ -745,22 +750,19 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr= addr, if (ret & (REG_C_UF | REG_C_AF)) { check_update_timer(s); } -#ifdef TARGET_I386 + if(s->irq_coalesced && (s->cmos_data[RTC_REG_B] & REG_B_PIE) && s->irq_reinject_on_ack_count < RTC_REINJECT_ON_ACK_COU= NT) { s->irq_reinject_on_ack_count++; s->cmos_data[RTC_REG_C] |=3D REG_C_IRQF | REG_C_PF; - apic_reset_irq_delivered(); DPRINTF_C("cmos: injecting on ack\n"); - qemu_irq_raise(s->irq); - if (apic_get_irq_delivered()) { + if (rtc_policy_slew_deliver_irq(s)) { s->irq_coalesced--; DPRINTF_C("cmos: coalesced irqs decreased to %d\n", s->irq_coalesced); } } -#endif break; default: ret =3D s->cmos_data[s->cmos_index]; --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321247019199.08047456903716; Thu, 1 Jun 2017 05:47:27 -0700 (PDT) Received: from localhost ([::1]:44174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPVd-0007sb-Kj for importer@patchew.org; Thu, 01 Jun 2017 08:47:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQV-0003Pn-8v for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQQ-0005gq-V9 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:07 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35369) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQQ-0005gZ-N6 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:02 -0400 Received: by mail-wm0-x241.google.com with SMTP id g15so11028764wmc.2 for ; Thu, 01 Jun 2017 05:42:02 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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 :mime-version:content-transfer-encoding; bh=VRLkBkIM3K6/EBaPJYuFtJbkpOauMi+BElKrOXPQuB0=; b=VOuMQOu/GhAWreKozsykb9/J24AXf4p4VMteuuzyLCZW++9wAZsZB152KV2zcKITyz vyXJa9Ov1ZRP7OUjFhN3ifc5JZRnFbFI4R/xhSbpBIRZmiyZ8odFbVBqJ8Me30lZFdmK B/+744YSnX1YJr7PCbKJHNUQUPTJw5VjKhf0voRobQiGL6aySYQB+SVCm0c33HOthbYv 2hyVjUDunHVbwxk77LTavBgRMlcROg7XaqmNKW/vJtBp77z0swldNiMG3NcKAMFpv1M1 Tmu3AYsAmpmN8MRcHCfyxN0qPa3tGYdLu40BHcny5mjaCCn/ea17oK2GARDhZkYKTtAz uqlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=VRLkBkIM3K6/EBaPJYuFtJbkpOauMi+BElKrOXPQuB0=; b=uXA5Ta28mjC/CF4iNqL58oJIPqkHHWJvCpUsp/ZjrS4FJ4iJaJXHNik57zWQwB1lXO Y9XEHMwSP0ZyrK8WgnSt+I6a8WKO91O5HHoXNGd0dXDKxK3FNymSyTZlVvM/cqoFph6C giDihDdtP4xHhwsxA9rKVyqd7V/8GZXKrZaYzva+ZFFsomlFnhNBC2tzVaxuSQAB5h7J M3x9IhrWEVHVw3VRNv9OCdOg+kMazYgz8ux0+Bx3rSNKKiUVYeW/PgWsK4ttYcMSZ6iB FZv0EIjnpCL8v7aoDAW6zaDwLkV56Pmoo7pidEez0ANEe6zMLEhP2wxiwWscDDgXdaXc 2iPw== X-Gm-Message-State: AODbwcAQBfPTqmoLib9PNgYph2dX5SFvrKbMmxxPLJupeCNLh7PWAhlU HKOggvSUH6tuVOJS4+8= X-Received: by 10.28.41.65 with SMTP id p62mr8604715wmp.32.1496320921434; Thu, 01 Jun 2017 05:42:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:24 +0200 Message-Id: <1496320911-51305-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 06/33] kvm: irqchip: trace changes on msi add/remove 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: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Peter Xu It'll be nice to know which virq belongs to which device/vector when adding msi routes, so adding two more parameters for the add trace. Meanwhile, releasing virq has no tracing before. Add one for it. Signed-off-by: Peter Xu Message-Id: <1494309644-18743-2-git-send-email-peterx@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Paolo Bonzini --- kvm-all.c | 4 +++- trace-events | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 90b8573..2598b1f 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1144,6 +1144,7 @@ void kvm_irqchip_release_virq(KVMState *s, int virq) } clear_gsi(s, virq); kvm_arch_release_virq_post(virq); + trace_kvm_irqchip_release_virq(virq); } =20 static unsigned int kvm_hash_msi(uint32_t data) @@ -1287,7 +1288,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, int vector= , PCIDevice *dev) return -EINVAL; } =20 - trace_kvm_irqchip_add_msi_route(virq); + trace_kvm_irqchip_add_msi_route(dev ? dev->name : (char *)"N/A", + vector, virq); =20 kvm_add_routing_entry(s, &kroute); kvm_arch_add_msi_route_post(&kroute, vector, dev); diff --git a/trace-events b/trace-events index e582d63..f01ec05 100644 --- a/trace-events +++ b/trace-events @@ -69,8 +69,9 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d,= type 0x%x, arg %p" kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retri= eve ONEREG %" PRIu64 " from KVM: %s" kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set O= NEREG %" PRIu64 " to KVM: %s" kvm_irqchip_commit_routes(void) "" -kvm_irqchip_add_msi_route(int virq) "Adding MSI route virq=3D%d" +kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector= %d virq %d" kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=3D%d" +kvm_irqchip_release_virq(int virq) "virq %d" =20 # TCG related tracing (mostly disabled by default) # cpu-exec.c --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321515566914.3899198717286; Thu, 1 Jun 2017 05:51:55 -0700 (PDT) Received: from localhost ([::1]:44194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPZx-0003F6-Uh for importer@patchew.org; Thu, 01 Jun 2017 08:51:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQS-0003NK-Qd for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQR-0005ha-Rb for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:04 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36263) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQR-0005gu-Jz for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:03 -0400 Received: by mail-wm0-x243.google.com with SMTP id k15so11048712wmh.3 for ; Thu, 01 Jun 2017 05:42:03 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5HIVcRC7sTaQ4oyVWeVogPL27OYQ23z1XhMRTjFdMXM=; b=N2dq5lm5GxuXTQtXVsGJs81vlaETunRdKg75jeGhwcuTydiIZljM5NX8lnd4QOO2A/ V2nx5eavq+niFNYbRrGsDsBxvmTga14FyfNZZj8p6UWIJURv6GmJZIASzSsYGMdnZFRR 5TwbK7C0Zfq9z17NzWK8DAg8FWT6nxpQF/eF8m+FC0Mcs7ipJ5pS1bUYmfrOvViRzEeT uGAQ+1W3P49ETK0+FG1m2Vr9A6wwa5X1IMea98ZLndlfEun5Yz0zOy1lBxkF1UtXLni5 tJNA2ywuOrJhmn0ph89d1CteFRTcyDoTfdRrPr0X5p4AUIVOUzASoixADeQ47DtRNkUP 0scg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5HIVcRC7sTaQ4oyVWeVogPL27OYQ23z1XhMRTjFdMXM=; b=HAUkMhvb1jJyw8LoXj3iEVtjxjs1AFodjeYkA+kqPHUt+o0escRwpy35TypF1gSF/V s6SOI/dV7mbQ8OnrN7POkLSM53LvuI4T7+WoAvVmrbdlYn+HJ5D5Ox3/t5lM1TV9XJDN DIucvm4ONRE84W/R9plXz+L0T3SpbCx60QEIpC/LKZ8BUyxLy9t0I7ReRsEPqlYLoiOt /+1qX+fhC9sqI42Zt4ZjPdqyEmO7iIa/WC4s7LD83CySVwu5yUgMmUt/B4PTRBkeugdm qt/exx8aNnv0pIShuwz+ppweoyLTJY3lFp7irQME9/t97rKQe/mrYPZd7h6ror3qXBa8 M5rg== X-Gm-Message-State: AODbwcAB+Ixvgbd8Bw2VLnCz88DCkSPaDLQ5o+sgaP+/u4n+ILTagl6B Tz+64OqZEO1z4iIYJHw= X-Received: by 10.223.142.48 with SMTP id n45mr1138843wrb.188.1496320922382; Thu, 01 Jun 2017 05:42:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:25 +0200 Message-Id: <1496320911-51305-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PULL 07/33] msix: trace control bit write op 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: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Peter Xu Meanwhile, abstract a function to detect msix masked bit. Signed-off-by: Peter Xu Message-Id: <1494309644-18743-3-git-send-email-peterx@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Paolo Bonzini --- hw/pci/msix.c | 11 +++++++++-- hw/pci/trace-events | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index bb54e8b..fc5fe51 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -22,6 +22,7 @@ #include "hw/xen/xen.h" #include "qemu/range.h" #include "qapi/error.h" +#include "trace.h" =20 #define MSIX_CAP_LENGTH 12 =20 @@ -130,10 +131,14 @@ static void msix_handle_mask_update(PCIDevice *dev, i= nt vector, bool was_masked) } } =20 +static bool msix_masked(PCIDevice *dev) +{ + return dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL= _MASK; +} + static void msix_update_function_masked(PCIDevice *dev) { - dev->msix_function_masked =3D !msix_enabled(dev) || - (dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_M= ASK); + dev->msix_function_masked =3D !msix_enabled(dev) || msix_masked(dev); } =20 /* Handle MSI-X capability config write. */ @@ -148,6 +153,8 @@ void msix_write_config(PCIDevice *dev, uint32_t addr, return; } =20 + trace_msix_write_config(dev->name, msix_enabled(dev), msix_masked(dev)= ); + was_masked =3D dev->msix_function_masked; msix_update_function_masked(dev); =20 diff --git a/hw/pci/trace-events b/hw/pci/trace-events index 2b9cf24..83c8f5a 100644 --- a/hw/pci/trace-events +++ b/hw/pci/trace-events @@ -7,3 +7,6 @@ pci_update_mappings_add(void *d, uint32_t bus, uint32_t slo= t, uint32_t func, int # hw/pci/pci_host.c pci_cfg_read(const char *dev, unsigned devid, unsigned fnid, unsigned offs= , unsigned val) "%s %02u:%u @0x%x -> 0x%x" pci_cfg_write(const char *dev, unsigned devid, unsigned fnid, unsigned off= s, unsigned val) "%s %02u:%u @0x%x <- 0x%x" + +# hw/pci/msix.c +msix_write_config(char *name, bool enabled, bool masked) "dev %s enabled %= d masked %d" --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321253961166.62252280248697; Thu, 1 Jun 2017 05:47:33 -0700 (PDT) Received: from localhost ([::1]:44175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPVk-0007yI-By for importer@patchew.org; Thu, 01 Jun 2017 08:47:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQU-0003OS-1K for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQT-0005i7-2s for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:06 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:34107) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQS-0005hq-T5 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:05 -0400 Received: by mail-wm0-x244.google.com with SMTP id d127so11019465wmf.1 for ; Thu, 01 Jun 2017 05:42:04 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=T6bvJg/zc/9Mpl3ah40Cn4ahjkiLMrxR5IZSt98CIm8=; b=QqCi8rnGHtbTK9bSnWXqUQ/D7BofePuuR1u9B6VpBsZps7poIKTwU5JvJ1kEt/CKe/ MrNSPBXr+vpl9JvhStjBZ6ZgVIdSx7vBB4YGKw7Avecq2wZknuznydw6mkGDQBdE/c/H MWTuQD0C1eyxj8yJkpi8A2992DbH0BRIxU0AvBRivgrWtmYCo4mbtlYxSvLd9YAe60Ca CnTUzZKOTUiWHkwEGsGPYLRpRwtNKe2SAq9YLV1lIaaqgA3wnuz2JQ0msd3xOWSaDMNL 8anlsjZUwJnJe67zscHWJuA1YXX12X1yPjTm1R4Hn9vp97vHCRFnwXvmLv2o1vU6JOHY Wdow== 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=T6bvJg/zc/9Mpl3ah40Cn4ahjkiLMrxR5IZSt98CIm8=; b=U78qvmBCR6gZ66B6ckdcU4mGsLIuxGK9qVmauDK5ss59NW+CPcXvIeLRovhJHgMNjk yaObOEVZMCa3MndeY1Vt2Q7qlwiQR/N53HFLRfaulhKGg9ToQr72gbiV24Deh9wRtjyq fpChhs1/XIq9zsXUnPo2i+cOC3b+Of0Ho23jG+xgJFNzrrCux4InqSf9M2+hsXH0+ZA7 dlUQSYHhkx7gCwy2xyGbvDsCooMDFNIUKEcxf5D3DzcV0ELrkxSXbHaut6K1zEZp0x4n J3cdMYB2OwVmKmF4w2Q/N7E++zg0QHcq27i8Asfxk62q7756q2mPfDJWhlnzMQcqD4j3 pf6A== X-Gm-Message-State: AODbwcBJA4oXu50r2c3iMVxJFoAilOZDvJ8bgH9yM0uPnoM5sAZmq7P3 rY+eP/BicrY7q29WCsg= X-Received: by 10.28.27.197 with SMTP id b188mr1607086wmb.61.1496320923606; Thu, 01 Jun 2017 05:42:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:26 +0200 Message-Id: <1496320911-51305-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::244 Subject: [Qemu-devel] [PULL 08/33] kvm: irqchip: skip update msi when 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: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu It's possible that one device kept its irqfd/virq there even when MSI/MSIX was disabled globally for that device. One example is virtio-net-pci (see commit f1d0f15a6 and virtio_pci_vq_vector_mask()). It is used as a fast path to avoid allocate/release irqfd/virq frequently when guest enables/disables MSIX. However, this fast path brought a problem to msi_route_list, that the device MSIRouteEntry is still dangling there even if MSIX disabled - then we cannot know which message to fetch, even if we can, the messages are meaningless. In this case, we can just simply ignore this entry. It's safe, since when MSIX is enabled again, we'll rebuild them no matter what. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1448813 Signed-off-by: Peter Xu Message-Id: <1494309644-18743-4-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 011d4a5..82c72d2 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -43,6 +43,7 @@ #include "standard-headers/asm-x86/hyperv.h" #include "hw/pci/pci.h" #include "hw/pci/msi.h" +#include "hw/pci/msix.h" #include "migration/blocker.h" #include "exec/memattrs.h" #include "trace.h" @@ -3510,12 +3511,17 @@ static void kvm_update_msi_routes_all(void *private= , bool global, int cnt =3D 0; MSIRouteEntry *entry; MSIMessage msg; + PCIDevice *dev; + /* TODO: explicit route update */ QLIST_FOREACH(entry, &msi_route_list, list) { cnt++; - msg =3D pci_get_msi_message(entry->dev, entry->vector); - kvm_irqchip_update_msi_route(kvm_state, entry->virq, - msg, entry->dev); + dev =3D entry->dev; + if (!msix_enabled(dev) && !msi_enabled(dev)) { + continue; + } + msg =3D pci_get_msi_message(dev, entry->vector); + kvm_irqchip_update_msi_route(kvm_state, entry->virq, msg, dev); } kvm_irqchip_commit_routes(kvm_state); trace_kvm_x86_update_msi_routes(cnt); --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321037601955.5748090574059; Thu, 1 Jun 2017 05:43:57 -0700 (PDT) Received: from localhost ([::1]:44159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPSE-0004yj-Ss for importer@patchew.org; Thu, 01 Jun 2017 08:43:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQU-0003P7-QK for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQU-0005iK-3y for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:06 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33568) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQT-0005iD-TI for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:06 -0400 Received: by mail-wm0-x243.google.com with SMTP id b84so11063081wmh.0 for ; Thu, 01 Jun 2017 05:42:05 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=TZMqk6n7j+WhSqyyd48UWmTami0aU/3mA9UHgvRN250=; b=QmXhH4DEmlg2SdAWCL4F/uVhNhkWpz2k8tXXUK6xk4+9MT4J2Cj1DdGujYYBiSKlqM OCswgO8nHbXeLzdPQU0r/iTFbtRhkLDy+T+3XtmQpnu266CrMhKj5tdINWfALouPKo1Q VtoQ/OJVtFs01JI0GLYL6D4f8T9MC9RU4R9U5tu9IiqBNrNyuXx6Ah5B5vdE2fZwCvzC 0MtrxkxXnzoOa3RgHZ4f0tfcfWYMFuHHvNh+StEj+VjUv8ke0uaPX25nnDbeMNAKTLJr ebmZHbmKVFDBYru6i4HJwl06tyTtnZ/g5Gy7hKB7aS30rmPjtZr4CJvZWl07ZDaZkeGx 13rQ== 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=TZMqk6n7j+WhSqyyd48UWmTami0aU/3mA9UHgvRN250=; b=W/uPW5CTwZsc5vXh5jLZ0F0U6OkHhmiSopcw2WgiIFqmUejemmdsuvw6VInSpkGkLY JQTbM2oMioJjzSpZM8maS1LgNbwLLuZ7GbA+jYyDG8UQ+N/cwShQZbdcR4tCLIL3D+Zl Q9Czy6K3Zqt1Nu/Szzjd884o54hlkVBq/cSBJkCEEXH4/QvgWyvzVWvpFXoa9ruvrJEh 6MHAvxP18kRgfKUyW9twZv9A0g+xd0zb1hw3AXZ1hgCReF4P5+mSXz3Wu2UwHSeQIkAF 3QubRp4Hu17JH0FqQk7FKGBbEHlr/yMTQBD8XZjsUVXGmQRQzw8PfVYS6vAqKHeTMVjP qtKw== X-Gm-Message-State: AODbwcCnh0nASczypWPLSZynlzsLConX8nq8YrRuWMx/ce9WaSBcvo0C 7PUGInYyCWt/Ho+D3Ug= X-Received: by 10.28.135.82 with SMTP id j79mr9775690wmd.10.1496320924729; Thu, 01 Jun 2017 05:42:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:27 +0200 Message-Id: <1496320911-51305-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::243 Subject: [Qemu-devel] [PULL 09/33] Check the return value of fcntl in qemu_set_cloexec 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: pbonzini@redhat.com, Stefano Stabellini , groug@kaod.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini Assert that the return value is not an error. This issue was found by Coverity. CID: 1374831 Signed-off-by: Stefano Stabellini CC: groug@kaod.org CC: pbonzini@redhat.com CC: Eric Blake Message-Id: <1494356693-13190-2-git-send-email-sstabellini@kernel.org> Signed-off-by: Paolo Bonzini --- util/oslib-posix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 4d9189e..16894ad 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -182,7 +182,9 @@ void qemu_set_cloexec(int fd) { int f; f =3D fcntl(fd, F_GETFD); - fcntl(fd, F_SETFD, f | FD_CLOEXEC); + assert(f !=3D -1); + f =3D fcntl(fd, F_SETFD, f | FD_CLOEXEC); + assert(f !=3D -1); } =20 /* --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321579187246.23104237552866; Thu, 1 Jun 2017 05:52:59 -0700 (PDT) Received: from localhost ([::1]:44197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPay-0004Rs-L2 for importer@patchew.org; Thu, 01 Jun 2017 08:52:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQV-0003QQ-WE for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQV-0005ij-4N for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:08 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35385) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQU-0005iS-VV for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:07 -0400 Received: by mail-wm0-x241.google.com with SMTP id g15so11029266wmc.2 for ; Thu, 01 Jun 2017 05:42:06 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=7FklvMGoS+ej8kkZ7T1Y1DMkbeEOlzaVTdLv/Zbimjs=; b=bYPbKU/I6Wv7wKyad95tcn13DXRXcygWEZr2/rW7RkrtKdtrwelTTG2zPIOexg50KX BcWKQCkkVxmOWgWO9Na3wyCvu1iyKzFkBXZ8LSfdM1FBSRZvPZcvRhnT0eYZNOJde3dH gospIyUNfAEppYumuagLNJpUg/iUYzZQFFjWbbMf6efe29/PKR2Y/p3sIswndWH+xi7h IRaNqXt2lVIGMvymgfVhlmt22urBkM/HnyFj++jPJyO76AwkjhZeAxXaos7E2uAk+b0C g+pfH3W3m2c+9NCQHFMnopcfvYM/1no6+wX2APhYk7v3Zwo+XqsyFuUaLvxXDMg7Kwms TPWg== 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=7FklvMGoS+ej8kkZ7T1Y1DMkbeEOlzaVTdLv/Zbimjs=; b=fXPjPdK6dK+HRf2xR68lgtbtjqznpOCtEe1sHJmU6Z38KgzV4BRr4nBFittKAzT7tw mkODWGsB8GAZ8MDlMd20gkZUZ8GG0TISrFUC51EpY+pJLZClUoT766wsJQZDkHs5wI7v D7ATOLvRayv70x9L1gMoKi4JUfho6nNNxRyGwap5YAWYNCcNW3ClTZavWySMeiERDvlv 1l0lfpVjlftKvXKLyOT4PmLIppF3BrM3/C3uHcxu0rJn4U4oXyxqi5oVBta2mNYXW4z2 mCZWbt+XG7zrcgW4RzLWJnx8rzcc+u76kHWlRW2vbZKm1SqXupKwdce/EJnTFGA60H3w /pTA== X-Gm-Message-State: AODbwcAu6OFuJREwS1k6mpdf7bZDMkdDgyBp3/QiqtkExPLc8QeKH79h 4Dv17VlowgODnoEK9uQ= X-Received: by 10.28.56.198 with SMTP id f189mr1432353wma.111.1496320925769; Thu, 01 Jun 2017 05:42:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:28 +0200 Message-Id: <1496320911-51305-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::241 Subject: [Qemu-devel] [PULL 10/33] nbd: strict nbd_wr_syncv 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: Vladimir Sementsov-Ogievskiy Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy nbd_wr_syncv is called either from coroutine or from client negotiation code, when socket is in blocking mode. So, -EAGAIN is impossible. Furthermore, EAGAIN is confusing, as, what to read/write again? With EAGAIN as a return code we don't know how much data is already read or written by the function, so in case of EAGAIN the whole communication is broken. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170516094533.6160-2-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- nbd/common.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nbd/common.c b/nbd/common.c index dccbb8e..4db45b3 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -20,6 +20,10 @@ #include "qapi/error.h" #include "nbd-internal.h" =20 +/* nbd_wr_syncv + * The function may be called from coroutine or from non-coroutine context. + * When called from non-coroutine context @ioc must be in blocking mode. + */ ssize_t nbd_wr_syncv(QIOChannel *ioc, struct iovec *iov, size_t niov, @@ -42,11 +46,8 @@ ssize_t nbd_wr_syncv(QIOChannel *ioc, len =3D qio_channel_writev(ioc, local_iov, nlocal_iov, &local_= err); } if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { - if (qemu_in_coroutine()) { - qio_channel_yield(ioc, do_read ? G_IO_IN : G_IO_OUT); - } else { - return -EAGAIN; - } + assert(qemu_in_coroutine()); + qio_channel_yield(ioc, do_read ? G_IO_IN : G_IO_OUT); continue; } if (len < 0) { --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321578881187.61930616130417; Thu, 1 Jun 2017 05:52:58 -0700 (PDT) Received: from localhost ([::1]:44196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPay-0004Pu-4a for importer@patchew.org; Thu, 01 Jun 2017 08:52:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQc-0003cX-3I for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQX-0005jA-5u for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:14 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36278) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQW-0005j1-QG for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:09 -0400 Received: by mail-wm0-x244.google.com with SMTP id k15so11049168wmh.3 for ; Thu, 01 Jun 2017 05:42:08 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=QrNzrpSR1bq3AscMlLyH0Q6d5t8UgEcta/OhRYB6NQU=; b=nTMkOs+l9kFwxUHdhP5gl4ezYxzOX6mO4QeFUvsH7nHQmAKVllMy9gOshn0ZCI/a7f 91hWLfvJr+OHNYE6LmzC49JuaPHebhgVlUCK18sc1PPv/iH+fY877JhIW8x8L3gIik17 KwmHPW7xN+EWUNh7PfAhxPFD1pxkwqXVUkefgMb/RYLZXSugzIleIsUfy2DTDQhlujlj QLEPnbD8ztgxk3CEg4sVUIzM5OVMe3eJyzkZYPZ/dYPzn86wT5apUBPa0gJW4R3I1gDK 2w4woaBzpovANjWxkgP6YRkFYrN77pvsU40GhAa6Lyw+e29MeUIY+zZ7t0mCKw8tlTf0 umSA== 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=QrNzrpSR1bq3AscMlLyH0Q6d5t8UgEcta/OhRYB6NQU=; b=mlpcsX/58S4yA/MOgEMcsDGQR/4uuydFnJU3v/Y1lJ2DEZhk9Crq9zhhU9+A5pRKoA pIh1v8EY5k1LuqWgn8ZXt5iqOKSuslRY6V6DadNIuvTlaVu0EW5WYy1d+QijtdwqG7P0 s79iVN6hAHjDo1DloL8WA/xFal5ZezhsCAqfik0VKIAKvb7ln0TZlcJCqeAP6jGX1yfz fhPKgQyVZBzdbP99JIAt2r/QdruO28sCBnpjqFVSBhs6zI3sb8LoPzHO1s1u3MsYDYMx wNEXaJn4sIor+Mdn+8w6fZFGOcs020Dk+NoRnVhS4E2GmpkUXIfoyA2eTWgYL7xnIbjp 1OSQ== X-Gm-Message-State: AODbwcAbln06Zua7ORKWpCcoOWHjFQNpBSU5yiiJsejv0ts5RQ2ur5Ah ladppY4OuG7116abTDQ= X-Received: by 10.28.238.67 with SMTP id m64mr8569630wmh.57.1496320927333; Thu, 01 Jun 2017 05:42:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:29 +0200 Message-Id: <1496320911-51305-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::244 Subject: [Qemu-devel] [PULL 11/33] nbd: read_sync and friends: return 0 on success 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: Vladimir Sementsov-Ogievskiy Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy functions read_sync, drop_sync, write_sync, and also nbd_negotiate_write, nbd_negotiate_read, nbd_negotiate_drop_sync returns number of processed bytes. But what this number can be, except requested number of bytes? Actually, underlying nbd_wr_syncv function returns a value >=3D 0 and !=3D requested_bytes only on eof on read operation. So, firstly, it is impossible on write (let's add an assert) and on read it actually means, that communication is broken (except nbd_receive_reply, see below). Most of callers operate like this: if (func(..., size) !=3D size) { /* error path */ } , i.e.: 1. They are not interested in partial success 2. Extra duplications in code (especially bad are duplications of magic numbers) 3. User doesn't see actual error message, as return code is lost. (this patch doesn't fix this point, but it makes fixing easier) Several callers handles ret >=3D 0 and !=3D requested-size separately, by just returning EINVAL in this case. This patch makes read_sync and friends return EINVAL in this case, so final behavior is the same. And only one caller - nbd_receive_reply() does something not so obvious. It returns EINVAL for ret > 0 and !=3D requested-size, like previous group, but for ret =3D=3D 0 it returns 0. The only caller of nbd_receive_reply() - nbd_read_reply_entry() handles ret =3D=3D 0 in the same way as ret < 0, so for now it doesn't matter. However, in following commits error path handling will be improved and we'll need to distinguish success from fail in this case too. So, this patch adds separate helper for this case - read_sync_eof. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170516094533.6160-3-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- nbd/client.c | 63 ++++++++++++++++------------------------ nbd/nbd-internal.h | 34 +++++++++++++++++++--- nbd/server.c | 84 +++++++++++++++++++++-----------------------------= ---- 3 files changed, 88 insertions(+), 93 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index a58fb02..6b74a62 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -86,9 +86,9 @@ static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD_I= NITIALIZER(exports); =20 */ =20 -/* Discard length bytes from channel. Return -errno on failure, or - * the amount of bytes consumed. */ -static ssize_t drop_sync(QIOChannel *ioc, size_t size) +/* Discard length bytes from channel. Return -errno on failure and 0 on + * success*/ +static int drop_sync(QIOChannel *ioc, size_t size) { ssize_t ret =3D 0; char small[1024]; @@ -96,14 +96,13 @@ static ssize_t drop_sync(QIOChannel *ioc, size_t size) =20 buffer =3D sizeof(small) >=3D size ? small : g_malloc(MIN(65536, size)= ); while (size > 0) { - ssize_t count =3D read_sync(ioc, buffer, MIN(65536, size)); + ssize_t count =3D MIN(65536, size); + ret =3D read_sync(ioc, buffer, MIN(65536, size)); =20 - if (count <=3D 0) { + if (ret < 0) { goto cleanup; } - assert(count <=3D size); size -=3D count; - ret +=3D count; } =20 cleanup: @@ -136,12 +135,12 @@ static int nbd_send_option_request(QIOChannel *ioc, u= int32_t opt, stl_be_p(&req.option, opt); stl_be_p(&req.length, len); =20 - if (write_sync(ioc, &req, sizeof(req)) !=3D sizeof(req)) { + if (write_sync(ioc, &req, sizeof(req)) < 0) { error_setg(errp, "Failed to send option request header"); return -1; } =20 - if (len && write_sync(ioc, (char *) data, len) !=3D len) { + if (len && write_sync(ioc, (char *) data, len) < 0) { error_setg(errp, "Failed to send option request data"); return -1; } @@ -170,7 +169,7 @@ static int nbd_receive_option_reply(QIOChannel *ioc, ui= nt32_t opt, nbd_opt_reply *reply, Error **errp) { QEMU_BUILD_BUG_ON(sizeof(*reply) !=3D 20); - if (read_sync(ioc, reply, sizeof(*reply)) !=3D sizeof(*reply)) { + if (read_sync(ioc, reply, sizeof(*reply)) < 0) { error_setg(errp, "failed to read option reply"); nbd_send_opt_abort(ioc); return -1; @@ -219,7 +218,7 @@ static int nbd_handle_reply_err(QIOChannel *ioc, nbd_op= t_reply *reply, goto cleanup; } msg =3D g_malloc(reply->length + 1); - if (read_sync(ioc, msg, reply->length) !=3D reply->length) { + if (read_sync(ioc, msg, reply->length) < 0) { error_setg(errp, "failed to read option error message"); goto cleanup; } @@ -321,7 +320,7 @@ static int nbd_receive_list(QIOChannel *ioc, const char= *want, bool *match, nbd_send_opt_abort(ioc); return -1; } - if (read_sync(ioc, &namelen, sizeof(namelen)) !=3D sizeof(namelen)) { + if (read_sync(ioc, &namelen, sizeof(namelen)) < 0) { error_setg(errp, "failed to read option name length"); nbd_send_opt_abort(ioc); return -1; @@ -334,7 +333,7 @@ static int nbd_receive_list(QIOChannel *ioc, const char= *want, bool *match, return -1; } if (namelen !=3D strlen(want)) { - if (drop_sync(ioc, len) !=3D len) { + if (drop_sync(ioc, len) < 0) { error_setg(errp, "failed to skip export name with wrong length= "); nbd_send_opt_abort(ioc); return -1; @@ -343,14 +342,14 @@ static int nbd_receive_list(QIOChannel *ioc, const ch= ar *want, bool *match, } =20 assert(namelen < sizeof(name)); - if (read_sync(ioc, name, namelen) !=3D namelen) { + if (read_sync(ioc, name, namelen) < 0) { error_setg(errp, "failed to read export name"); nbd_send_opt_abort(ioc); return -1; } name[namelen] =3D '\0'; len -=3D namelen; - if (drop_sync(ioc, len) !=3D len) { + if (drop_sync(ioc, len) < 0) { error_setg(errp, "failed to read export description"); nbd_send_opt_abort(ioc); return -1; @@ -477,7 +476,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } =20 - if (read_sync(ioc, buf, 8) !=3D 8) { + if (read_sync(ioc, buf, 8) < 0) { error_setg(errp, "Failed to read data"); goto fail; } @@ -503,7 +502,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } =20 - if (read_sync(ioc, &magic, sizeof(magic)) !=3D sizeof(magic)) { + if (read_sync(ioc, &magic, sizeof(magic)) < 0) { error_setg(errp, "Failed to read magic"); goto fail; } @@ -515,8 +514,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, uint16_t globalflags; bool fixedNewStyle =3D false; =20 - if (read_sync(ioc, &globalflags, sizeof(globalflags)) !=3D - sizeof(globalflags)) { + if (read_sync(ioc, &globalflags, sizeof(globalflags)) < 0) { error_setg(errp, "Failed to read server flags"); goto fail; } @@ -534,8 +532,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, } /* client requested flags */ clientflags =3D cpu_to_be32(clientflags); - if (write_sync(ioc, &clientflags, sizeof(clientflags)) !=3D - sizeof(clientflags)) { + if (write_sync(ioc, &clientflags, sizeof(clientflags)) < 0) { error_setg(errp, "Failed to send clientflags field"); goto fail; } @@ -573,13 +570,13 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, } =20 /* Read the response */ - if (read_sync(ioc, &s, sizeof(s)) !=3D sizeof(s)) { + if (read_sync(ioc, &s, sizeof(s)) < 0) { error_setg(errp, "Failed to read export length"); goto fail; } *size =3D be64_to_cpu(s); =20 - if (read_sync(ioc, flags, sizeof(*flags)) !=3D sizeof(*flags)) { + if (read_sync(ioc, flags, sizeof(*flags)) < 0) { error_setg(errp, "Failed to read export flags"); goto fail; } @@ -596,14 +593,14 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, goto fail; } =20 - if (read_sync(ioc, &s, sizeof(s)) !=3D sizeof(s)) { + if (read_sync(ioc, &s, sizeof(s)) < 0) { error_setg(errp, "Failed to read export length"); goto fail; } *size =3D be64_to_cpu(s); TRACE("Size is %" PRIu64, *size); =20 - if (read_sync(ioc, &oldflags, sizeof(oldflags)) !=3D sizeof(oldfla= gs)) { + if (read_sync(ioc, &oldflags, sizeof(oldflags)) < 0) { error_setg(errp, "Failed to read export flags"); goto fail; } @@ -619,7 +616,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, } =20 TRACE("Size is %" PRIu64 ", export flags %" PRIx16, *size, *flags); - if (zeroes && drop_sync(ioc, 124) !=3D 124) { + if (zeroes && drop_sync(ioc, 124) < 0) { error_setg(errp, "Failed to read reserved block"); goto fail; } @@ -744,7 +741,6 @@ int nbd_disconnect(int fd) ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request) { uint8_t buf[NBD_REQUEST_SIZE]; - ssize_t ret; =20 TRACE("Sending request to server: " "{ .from =3D %" PRIu64", .len =3D %" PRIu32 ", .handle =3D %" PR= Iu64 @@ -759,16 +755,7 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *= request) stq_be_p(buf + 16, request->from); stl_be_p(buf + 24, request->len); =20 - ret =3D write_sync(ioc, buf, sizeof(buf)); - if (ret < 0) { - return ret; - } - - if (ret !=3D sizeof(buf)) { - LOG("writing to socket failed"); - return -EINVAL; - } - return 0; + return write_sync(ioc, buf, sizeof(buf)); } =20 ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply) @@ -777,7 +764,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply) uint32_t magic; ssize_t ret; =20 - ret =3D read_sync(ioc, buf, sizeof(buf)); + ret =3D read_sync_eof(ioc, buf, sizeof(buf)); if (ret <=3D 0) { return ret; } diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index f43d990..e6bbc7c 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -94,7 +94,13 @@ #define NBD_ENOSPC 28 #define NBD_ESHUTDOWN 108 =20 -static inline ssize_t read_sync(QIOChannel *ioc, void *buffer, size_t size) +/* read_sync_eof + * Tries to read @size bytes from @ioc. Returns number of bytes actually r= ead. + * May return a value >=3D 0 and < size only on EOF, i.e. when iteratively= called + * qio_channel_readv() returns 0. So, there are no needs to call read_sync= _eof + * iteratively. + */ +static inline ssize_t read_sync_eof(QIOChannel *ioc, void *buffer, size_t = size) { struct iovec iov =3D { .iov_base =3D buffer, .iov_len =3D size }; /* Sockets are kept in blocking mode in the negotiation phase. After @@ -105,12 +111,32 @@ static inline ssize_t read_sync(QIOChannel *ioc, void= *buffer, size_t size) return nbd_wr_syncv(ioc, &iov, 1, size, true); } =20 -static inline ssize_t write_sync(QIOChannel *ioc, const void *buffer, - size_t size) +/* read_sync + * Reads @size bytes from @ioc. Returns 0 on success. + */ +static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size) +{ + ssize_t ret =3D read_sync_eof(ioc, buffer, size); + + if (ret >=3D 0 && ret !=3D size) { + ret =3D -EINVAL; + } + + return ret < 0 ? ret : 0; +} + +/* write_sync + * Writes @size bytes to @ioc. Returns 0 on success. + */ +static inline int write_sync(QIOChannel *ioc, const void *buffer, size_t s= ize) { struct iovec iov =3D { .iov_base =3D (void *) buffer, .iov_len =3D siz= e }; =20 - return nbd_wr_syncv(ioc, &iov, 1, size, false); + ssize_t ret =3D nbd_wr_syncv(ioc, &iov, 1, size, false); + + assert(ret < 0 || ret =3D=3D size); + + return ret < 0 ? ret : 0; } =20 struct NBDTLSHandshakeData { diff --git a/nbd/server.c b/nbd/server.c index 924a1fe..1e1096c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -112,7 +112,7 @@ static gboolean nbd_negotiate_continue(QIOChannel *ioc, return TRUE; } =20 -static ssize_t nbd_negotiate_read(QIOChannel *ioc, void *buffer, size_t si= ze) +static int nbd_negotiate_read(QIOChannel *ioc, void *buffer, size_t size) { ssize_t ret; guint watch; @@ -130,8 +130,7 @@ static ssize_t nbd_negotiate_read(QIOChannel *ioc, void= *buffer, size_t size) =20 } =20 -static ssize_t nbd_negotiate_write(QIOChannel *ioc, const void *buffer, - size_t size) +static int nbd_negotiate_write(QIOChannel *ioc, const void *buffer, size_t= size) { ssize_t ret; guint watch; @@ -148,24 +147,24 @@ static ssize_t nbd_negotiate_write(QIOChannel *ioc, c= onst void *buffer, return ret; } =20 -static ssize_t nbd_negotiate_drop_sync(QIOChannel *ioc, size_t size) +static int nbd_negotiate_drop_sync(QIOChannel *ioc, size_t size) { - ssize_t ret, dropped =3D size; + ssize_t ret; uint8_t *buffer =3D g_malloc(MIN(65536, size)); =20 while (size > 0) { - ret =3D nbd_negotiate_read(ioc, buffer, MIN(65536, size)); + size_t count =3D MIN(65536, size); + ret =3D nbd_negotiate_read(ioc, buffer, count); if (ret < 0) { g_free(buffer); return ret; } =20 - assert(ret <=3D size); - size -=3D ret; + size -=3D count; } =20 g_free(buffer); - return dropped; + return 0; } =20 /* Basic flow for negotiation @@ -206,22 +205,22 @@ static int nbd_negotiate_send_rep_len(QIOChannel *ioc= , uint32_t type, type, opt, len); =20 magic =3D cpu_to_be64(NBD_REP_MAGIC); - if (nbd_negotiate_write(ioc, &magic, sizeof(magic)) !=3D sizeof(magic)= ) { + if (nbd_negotiate_write(ioc, &magic, sizeof(magic)) < 0) { LOG("write failed (rep magic)"); return -EINVAL; } opt =3D cpu_to_be32(opt); - if (nbd_negotiate_write(ioc, &opt, sizeof(opt)) !=3D sizeof(opt)) { + if (nbd_negotiate_write(ioc, &opt, sizeof(opt)) < 0) { LOG("write failed (rep opt)"); return -EINVAL; } type =3D cpu_to_be32(type); - if (nbd_negotiate_write(ioc, &type, sizeof(type)) !=3D sizeof(type)) { + if (nbd_negotiate_write(ioc, &type, sizeof(type)) < 0) { LOG("write failed (rep type)"); return -EINVAL; } len =3D cpu_to_be32(len); - if (nbd_negotiate_write(ioc, &len, sizeof(len)) !=3D sizeof(len)) { + if (nbd_negotiate_write(ioc, &len, sizeof(len)) < 0) { LOG("write failed (rep data length)"); return -EINVAL; } @@ -256,7 +255,7 @@ nbd_negotiate_send_rep_err(QIOChannel *ioc, uint32_t ty= pe, if (ret < 0) { goto out; } - if (nbd_negotiate_write(ioc, msg, len) !=3D len) { + if (nbd_negotiate_write(ioc, msg, len) < 0) { LOG("write failed (error message)"); ret =3D -EIO; } else { @@ -287,15 +286,15 @@ static int nbd_negotiate_send_rep_list(QIOChannel *io= c, NBDExport *exp) } =20 len =3D cpu_to_be32(name_len); - if (nbd_negotiate_write(ioc, &len, sizeof(len)) !=3D sizeof(len)) { + if (nbd_negotiate_write(ioc, &len, sizeof(len)) < 0) { LOG("write failed (name length)"); return -EINVAL; } - if (nbd_negotiate_write(ioc, name, name_len) !=3D name_len) { + if (nbd_negotiate_write(ioc, name, name_len) < 0) { LOG("write failed (name buffer)"); return -EINVAL; } - if (nbd_negotiate_write(ioc, desc, desc_len) !=3D desc_len) { + if (nbd_negotiate_write(ioc, desc, desc_len) < 0) { LOG("write failed (description buffer)"); return -EINVAL; } @@ -309,7 +308,7 @@ static int nbd_negotiate_handle_list(NBDClient *client,= uint32_t length) NBDExport *exp; =20 if (length) { - if (nbd_negotiate_drop_sync(client->ioc, length) !=3D length) { + if (nbd_negotiate_drop_sync(client->ioc, length) < 0) { return -EIO; } return nbd_negotiate_send_rep_err(client->ioc, @@ -340,7 +339,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, uint32_t length) LOG("Bad length received"); goto fail; } - if (nbd_negotiate_read(client->ioc, name, length) !=3D length) { + if (nbd_negotiate_read(client->ioc, name, length) < 0) { LOG("read failed"); goto fail; } @@ -373,7 +372,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, TRACE("Setting up TLS"); ioc =3D client->ioc; if (length) { - if (nbd_negotiate_drop_sync(ioc, length) !=3D length) { + if (nbd_negotiate_drop_sync(ioc, length) < 0) { return NULL; } nbd_negotiate_send_rep_err(ioc, NBD_REP_ERR_INVALID, NBD_OPT_START= TLS, @@ -437,8 +436,7 @@ static int nbd_negotiate_options(NBDClient *client) ... Rest of request */ =20 - if (nbd_negotiate_read(client->ioc, &flags, sizeof(flags)) !=3D - sizeof(flags)) { + if (nbd_negotiate_read(client->ioc, &flags, sizeof(flags)) < 0) { LOG("read failed"); return -EIO; } @@ -464,8 +462,7 @@ static int nbd_negotiate_options(NBDClient *client) uint32_t clientflags, length; uint64_t magic; =20 - if (nbd_negotiate_read(client->ioc, &magic, sizeof(magic)) !=3D - sizeof(magic)) { + if (nbd_negotiate_read(client->ioc, &magic, sizeof(magic)) < 0) { LOG("read failed"); return -EINVAL; } @@ -476,14 +473,14 @@ static int nbd_negotiate_options(NBDClient *client) } =20 if (nbd_negotiate_read(client->ioc, &clientflags, - sizeof(clientflags)) !=3D sizeof(clientflag= s)) { + sizeof(clientflags)) < 0) + { LOG("read failed"); return -EINVAL; } clientflags =3D be32_to_cpu(clientflags); =20 - if (nbd_negotiate_read(client->ioc, &length, sizeof(length)) !=3D - sizeof(length)) { + if (nbd_negotiate_read(client->ioc, &length, sizeof(length)) < 0) { LOG("read failed"); return -EINVAL; } @@ -513,7 +510,7 @@ static int nbd_negotiate_options(NBDClient *client) return -EINVAL; =20 default: - if (nbd_negotiate_drop_sync(client->ioc, length) !=3D leng= th) { + if (nbd_negotiate_drop_sync(client->ioc, length) < 0) { return -EIO; } ret =3D nbd_negotiate_send_rep_err(client->ioc, @@ -551,7 +548,7 @@ static int nbd_negotiate_options(NBDClient *client) return nbd_negotiate_handle_export_name(client, length); =20 case NBD_OPT_STARTTLS: - if (nbd_negotiate_drop_sync(client->ioc, length) !=3D leng= th) { + if (nbd_negotiate_drop_sync(client->ioc, length) < 0) { return -EIO; } if (client->tlscreds) { @@ -570,7 +567,7 @@ static int nbd_negotiate_options(NBDClient *client) } break; default: - if (nbd_negotiate_drop_sync(client->ioc, length) !=3D leng= th) { + if (nbd_negotiate_drop_sync(client->ioc, length) < 0) { return -EIO; } ret =3D nbd_negotiate_send_rep_err(client->ioc, @@ -659,12 +656,12 @@ static coroutine_fn int nbd_negotiate(NBDClientNewDat= a *data) TRACE("TLS cannot be enabled with oldstyle protocol"); goto fail; } - if (nbd_negotiate_write(client->ioc, buf, sizeof(buf)) !=3D sizeof= (buf)) { + if (nbd_negotiate_write(client->ioc, buf, sizeof(buf)) < 0) { LOG("write failed"); goto fail; } } else { - if (nbd_negotiate_write(client->ioc, buf, 18) !=3D 18) { + if (nbd_negotiate_write(client->ioc, buf, 18) < 0) { LOG("write failed"); goto fail; } @@ -679,7 +676,7 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData = *data) stq_be_p(buf + 18, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); len =3D client->no_zeroes ? 10 : sizeof(buf) - 18; - if (nbd_negotiate_write(client->ioc, buf + 18, len) !=3D len) { + if (nbd_negotiate_write(client->ioc, buf + 18, len) < 0) { LOG("write failed"); goto fail; } @@ -702,11 +699,6 @@ static ssize_t nbd_receive_request(QIOChannel *ioc, NB= DRequest *request) return ret; } =20 - if (ret !=3D sizeof(buf)) { - LOG("read failed"); - return -EINVAL; - } - /* Request [ 0 .. 3] magic (NBD_REQUEST_MAGIC) [ 4 .. 5] flags (NBD_CMD_FLAG_FUA, ...) @@ -737,7 +729,6 @@ static ssize_t nbd_receive_request(QIOChannel *ioc, NBD= Request *request) static ssize_t nbd_send_reply(QIOChannel *ioc, NBDReply *reply) { uint8_t buf[NBD_REPLY_SIZE]; - ssize_t ret; =20 reply->error =3D system_errno_to_nbd_errno(reply->error); =20 @@ -754,16 +745,7 @@ static ssize_t nbd_send_reply(QIOChannel *ioc, NBDRepl= y *reply) stl_be_p(buf + 4, reply->error); stq_be_p(buf + 8, reply->handle); =20 - ret =3D write_sync(ioc, buf, sizeof(buf)); - if (ret < 0) { - return ret; - } - - if (ret !=3D sizeof(buf)) { - LOG("writing to socket failed"); - return -EINVAL; - } - return 0; + return write_sync(ioc, buf, sizeof(buf)); } =20 #define MAX_NBD_REQUESTS 16 @@ -1067,7 +1049,7 @@ static ssize_t nbd_co_send_reply(NBDRequestData *req,= NBDReply *reply, rc =3D nbd_send_reply(client->ioc, reply); if (rc >=3D 0) { ret =3D write_sync(client->ioc, req->data, len); - if (ret !=3D len) { + if (ret < 0) { rc =3D -EIO; } } @@ -1141,7 +1123,7 @@ static ssize_t nbd_co_receive_request(NBDRequestData = *req, if (request->type =3D=3D NBD_CMD_WRITE) { TRACE("Reading %" PRIu32 " byte(s)", request->len); =20 - if (read_sync(client->ioc, req->data, request->len) !=3D request->= len) { + if (read_sync(client->ioc, req->data, request->len) < 0) { LOG("reading from socket failed"); rc =3D -EIO; goto out; --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321357135570.8713185813481; Thu, 1 Jun 2017 05:49:17 -0700 (PDT) Received: from localhost ([::1]:44182 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPXP-000199-HK for importer@patchew.org; Thu, 01 Jun 2017 08:49:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQc-0003cY-3M for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQX-0005jI-UR for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:14 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35391) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQX-0005j5-Kw for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:09 -0400 Received: by mail-wm0-x244.google.com with SMTP id g15so11029527wmc.2 for ; Thu, 01 Jun 2017 05:42:09 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=/5AiP0aM3qct8OzdTV7PqSQeeDXpgUAaU1BRwwc8rqs=; b=n2xYS5jejQzWCIJxs5B4e22IDrkgpHm5U4n7xwzPl2O8/73BcVEn6EZ4I/sB6AqS// qdYZW7jI1ESMZ9myEVPMXMxE5gbBm8/SNXcp7tQvFwaqjdvzUVRSkHVq+627JzC49fWe BzwGy8/y5esrUVjn91A04v7oG4fyLLki/AnxV2E3szrF/Sx7VdCY38W7WK5np1T7lXmf mgVd3fwoFKfDwVvTJPRaWc11BVEhX+erJGNkPbFTKvSNb9u+G4JhpzhJCD3L8IT5hQzr 5rsPeaBCFWNiLC04SJOD71HR6GvmHxoofJp0Y3rybddKXfeeI1hT7gOn1S7KVaEyWVJT PS/g== 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=/5AiP0aM3qct8OzdTV7PqSQeeDXpgUAaU1BRwwc8rqs=; b=U4QOFzYlW+zN6YctiZ8lfYqupOP2ubFua+HprZ4JNnK/E0WBGEzQlV1wIp8jcYa/bF 23noMCVKsgpS++c075fa/hpSsmg+z3FIPstqEF6dTEXnVEd7dr39i9rIWIR7JWuZj+vL 7GHiLZmTmG7JhVYA5ct4OhafjJCL7cSgwurO4jJTU1utJb0Jez8d46Mc7MzcOhk3jgO8 ZOVPNQ1AMX6fw8VNJAVnvkEgRXle2bKSKzfWqOP4jgMODZ2N6EqUlgEt7XalMgj6rSBz rZl5DHXParhC+oqECiUbFZpyFQwe41X8V8ahs/7L1tF4VWJHnD+YGOSAygHN4Csn090U 9p3A== X-Gm-Message-State: AODbwcCkyekNozFTUNCSscXdaaLfm3N1k4RghsoBI1oo+g0aticyNF1+ HXPasW4Y/GNa+EmsqDQ= X-Received: by 10.28.17.203 with SMTP id 194mr1679416wmr.100.1496320928393; Thu, 01 Jun 2017 05:42:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:30 +0200 Message-Id: <1496320911-51305-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::244 Subject: [Qemu-devel] [PULL 12/33] nbd: add errp parameter to nbd_wr_syncv() 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: Vladimir Sementsov-Ogievskiy Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Will be used in following patch to provide actual error message in some cases. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170516094533.6160-4-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- block/nbd-client.c | 4 ++-- include/block/nbd.h | 3 ++- nbd/common.c | 12 +++++------- nbd/nbd-internal.h | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 1e2952f..538d95e 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -136,7 +136,7 @@ static int nbd_co_send_request(BlockDriverState *bs, rc =3D nbd_send_request(s->ioc, request); if (rc >=3D 0) { ret =3D nbd_wr_syncv(s->ioc, qiov->iov, qiov->niov, request->l= en, - false); + false, NULL); if (ret !=3D request->len) { rc =3D -EIO; } @@ -165,7 +165,7 @@ static void nbd_co_receive_reply(NBDClientSession *s, } else { if (qiov && reply->error =3D=3D 0) { ret =3D nbd_wr_syncv(s->ioc, qiov->iov, qiov->niov, request->l= en, - true); + true, NULL); if (ret !=3D request->len) { reply->error =3D EIO; } diff --git a/include/block/nbd.h b/include/block/nbd.h index 0ed0775..9d385ea 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -127,7 +127,8 @@ ssize_t nbd_wr_syncv(QIOChannel *ioc, struct iovec *iov, size_t niov, size_t length, - bool do_read); + bool do_read, + Error **errp); int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint16_t *fla= gs, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, diff --git a/nbd/common.c b/nbd/common.c index 4db45b3..bd81637 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -28,10 +28,10 @@ ssize_t nbd_wr_syncv(QIOChannel *ioc, struct iovec *iov, size_t niov, size_t length, - bool do_read) + bool do_read, + Error **errp) { ssize_t done =3D 0; - Error *local_err =3D NULL; struct iovec *local_iov =3D g_new(struct iovec, niov); struct iovec *local_iov_head =3D local_iov; unsigned int nlocal_iov =3D niov; @@ -41,19 +41,17 @@ ssize_t nbd_wr_syncv(QIOChannel *ioc, while (nlocal_iov > 0) { ssize_t len; if (do_read) { - len =3D qio_channel_readv(ioc, local_iov, nlocal_iov, &local_e= rr); + len =3D qio_channel_readv(ioc, local_iov, nlocal_iov, errp); } else { - len =3D qio_channel_writev(ioc, local_iov, nlocal_iov, &local_= err); + len =3D qio_channel_writev(ioc, local_iov, nlocal_iov, errp); } if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { + /* errp should not be set */ assert(qemu_in_coroutine()); qio_channel_yield(ioc, do_read ? G_IO_IN : G_IO_OUT); continue; } if (len < 0) { - TRACE("I/O error: %s", error_get_pretty(local_err)); - error_free(local_err); - /* XXX handle Error objects */ done =3D -EIO; goto cleanup; } diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index e6bbc7c..1d479fe 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -108,7 +108,7 @@ static inline ssize_t read_sync_eof(QIOChannel *ioc, vo= id *buffer, size_t size) * our request/reply. Synchronization is done with recv_coroutine, so * that this is coroutine-safe. */ - return nbd_wr_syncv(ioc, &iov, 1, size, true); + return nbd_wr_syncv(ioc, &iov, 1, size, true, NULL); } =20 /* read_sync @@ -132,7 +132,7 @@ static inline int write_sync(QIOChannel *ioc, const voi= d *buffer, size_t size) { struct iovec iov =3D { .iov_base =3D (void *) buffer, .iov_len =3D siz= e }; =20 - ssize_t ret =3D nbd_wr_syncv(ioc, &iov, 1, size, false); + ssize_t ret =3D nbd_wr_syncv(ioc, &iov, 1, size, false, NULL); =20 assert(ret < 0 || ret =3D=3D size); =20 --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321521195546.086524717502; Thu, 1 Jun 2017 05:52:01 -0700 (PDT) Received: from localhost ([::1]:44195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPa3-0003K6-Nl for importer@patchew.org; Thu, 01 Jun 2017 08:51:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQc-0003ca-3P for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQZ-0005jT-EP for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:14 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:38276) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQZ-0005jN-44 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:11 -0400 Received: by mail-wm0-x22d.google.com with SMTP id n195so30605704wmg.1 for ; Thu, 01 Jun 2017 05:42:10 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:09 -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=LinIVzC/iJYGzbYu2yoDUljFlDDyXfOFA4I+gecpsxE=; b=m8VYX1HdOGSX/ZK+kjh3ZbdIsQNm+jkf2XUk+3GE5l2l4aAl5Gh/Z03t/QUI7IQcVz JVQDqjwCFgBqTuTkuJ/+lyaAcNdG/D8u5PI35rmjnwcA2MbtgvU289apbWHnVfpZu0mO u8Yp3gcmy+H6dYCaQ5Dt80yeCg5S3XoRy7Dw8rJZaJjbedLiRI+iD+/6oKIfY0qDd4cS WJcFvNcWwCw0RTkmuJlaza7UV13H2I85jV/Vu8kIQ4dpa2DrWXMjVXqe9pnVzNlLLC+Q EUoRX1lFnYQ9s17sIMUTW7+kUI46Ycomvzqh5YTz+yLMAguHV+MBoZRyi8oySjV0Toma YGFw== 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=LinIVzC/iJYGzbYu2yoDUljFlDDyXfOFA4I+gecpsxE=; b=LEPyWpbA6dGquXCw9Or7FEM7ROff0G3aAj6x/U2Tom5+iIIy20ZRi85YEulwa2tfrp /zT/OZMjfUDWnwwGRGjokz+ZXUHpC2xDMJX0rUUXIl3YO4gk9GKrW3t0dJ4B+bGpFCf/ VSj+U8/rq45MlNSff3pCZsAYT0hfL0ET1RSIE8tww/252vCZxTeI1eiTF39zA2FhKY2h TGxaqbfej1VIhjToo6r060ONo2a3HQfWnHjfAT25Kr52zOQelryoHxYLKBozXBckBsW9 bVafOyayw9olPgMG3b6/HqDdbBb1IKNBkGXwmrIewJ3OYPAklTwX/K13xi5ozWTTIVTB mtDA== X-Gm-Message-State: AODbwcBdEVb/nw4AAXNDUztmlfHkx2+MMoxCO86JCnRuuenlj0ZyopHb rApluzLyiOJ2oIJNHZc= X-Received: by 10.223.135.227 with SMTP id c32mr1426237wrc.10.1496320929672; Thu, 01 Jun 2017 05:42:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:31 +0200 Message-Id: <1496320911-51305-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::22d Subject: [Qemu-devel] [PULL 13/33] nbd: add errp to read_sync, write_sync and drop_sync 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: Vladimir Sementsov-Ogievskiy Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy There a lot of calls of these functions, which already have errp, which they are filling themselves. On the other hand, nbd_wr_syncv has errp parameter too, so it would be great to connect them. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170516094533.6160-5-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- nbd/client.c | 76 +++++++++++++++++++++++++++-----------------------= ---- nbd/nbd-internal.h | 16 +++++++----- nbd/server.c | 12 ++++----- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 6b74a62..f102375 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -88,7 +88,7 @@ static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD_I= NITIALIZER(exports); =20 /* Discard length bytes from channel. Return -errno on failure and 0 on * success*/ -static int drop_sync(QIOChannel *ioc, size_t size) +static int drop_sync(QIOChannel *ioc, size_t size, Error **errp) { ssize_t ret =3D 0; char small[1024]; @@ -97,7 +97,7 @@ static int drop_sync(QIOChannel *ioc, size_t size) buffer =3D sizeof(small) >=3D size ? small : g_malloc(MIN(65536, size)= ); while (size > 0) { ssize_t count =3D MIN(65536, size); - ret =3D read_sync(ioc, buffer, MIN(65536, size)); + ret =3D read_sync(ioc, buffer, MIN(65536, size), errp); =20 if (ret < 0) { goto cleanup; @@ -135,13 +135,13 @@ static int nbd_send_option_request(QIOChannel *ioc, u= int32_t opt, stl_be_p(&req.option, opt); stl_be_p(&req.length, len); =20 - if (write_sync(ioc, &req, sizeof(req)) < 0) { - error_setg(errp, "Failed to send option request header"); + if (write_sync(ioc, &req, sizeof(req), errp) < 0) { + error_prepend(errp, "Failed to send option request header"); return -1; } =20 - if (len && write_sync(ioc, (char *) data, len) < 0) { - error_setg(errp, "Failed to send option request data"); + if (len && write_sync(ioc, (char *) data, len, errp) < 0) { + error_prepend(errp, "Failed to send option request data"); return -1; } =20 @@ -169,8 +169,8 @@ static int nbd_receive_option_reply(QIOChannel *ioc, ui= nt32_t opt, nbd_opt_reply *reply, Error **errp) { QEMU_BUILD_BUG_ON(sizeof(*reply) !=3D 20); - if (read_sync(ioc, reply, sizeof(*reply)) < 0) { - error_setg(errp, "failed to read option reply"); + if (read_sync(ioc, reply, sizeof(*reply), errp) < 0) { + error_prepend(errp, "failed to read option reply"); nbd_send_opt_abort(ioc); return -1; } @@ -218,8 +218,8 @@ static int nbd_handle_reply_err(QIOChannel *ioc, nbd_op= t_reply *reply, goto cleanup; } msg =3D g_malloc(reply->length + 1); - if (read_sync(ioc, msg, reply->length) < 0) { - error_setg(errp, "failed to read option error message"); + if (read_sync(ioc, msg, reply->length, errp) < 0) { + error_prepend(errp, "failed to read option error message"); goto cleanup; } msg[reply->length] =3D '\0'; @@ -320,8 +320,8 @@ static int nbd_receive_list(QIOChannel *ioc, const char= *want, bool *match, nbd_send_opt_abort(ioc); return -1; } - if (read_sync(ioc, &namelen, sizeof(namelen)) < 0) { - error_setg(errp, "failed to read option name length"); + if (read_sync(ioc, &namelen, sizeof(namelen), errp) < 0) { + error_prepend(errp, "failed to read option name length"); nbd_send_opt_abort(ioc); return -1; } @@ -333,8 +333,8 @@ static int nbd_receive_list(QIOChannel *ioc, const char= *want, bool *match, return -1; } if (namelen !=3D strlen(want)) { - if (drop_sync(ioc, len) < 0) { - error_setg(errp, "failed to skip export name with wrong length= "); + if (drop_sync(ioc, len, errp) < 0) { + error_prepend(errp, "failed to skip export name with wrong len= gth"); nbd_send_opt_abort(ioc); return -1; } @@ -342,15 +342,15 @@ static int nbd_receive_list(QIOChannel *ioc, const ch= ar *want, bool *match, } =20 assert(namelen < sizeof(name)); - if (read_sync(ioc, name, namelen) < 0) { - error_setg(errp, "failed to read export name"); + if (read_sync(ioc, name, namelen, errp) < 0) { + error_prepend(errp, "failed to read export name"); nbd_send_opt_abort(ioc); return -1; } name[namelen] =3D '\0'; len -=3D namelen; - if (drop_sync(ioc, len) < 0) { - error_setg(errp, "failed to read export description"); + if (drop_sync(ioc, len, errp) < 0) { + error_prepend(errp, "failed to read export description"); nbd_send_opt_abort(ioc); return -1; } @@ -476,8 +476,8 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } =20 - if (read_sync(ioc, buf, 8) < 0) { - error_setg(errp, "Failed to read data"); + if (read_sync(ioc, buf, 8, errp) < 0) { + error_prepend(errp, "Failed to read data"); goto fail; } =20 @@ -502,8 +502,8 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } =20 - if (read_sync(ioc, &magic, sizeof(magic)) < 0) { - error_setg(errp, "Failed to read magic"); + if (read_sync(ioc, &magic, sizeof(magic), errp) < 0) { + error_prepend(errp, "Failed to read magic"); goto fail; } magic =3D be64_to_cpu(magic); @@ -514,8 +514,8 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, uint16_t globalflags; bool fixedNewStyle =3D false; =20 - if (read_sync(ioc, &globalflags, sizeof(globalflags)) < 0) { - error_setg(errp, "Failed to read server flags"); + if (read_sync(ioc, &globalflags, sizeof(globalflags), errp) < 0) { + error_prepend(errp, "Failed to read server flags"); goto fail; } globalflags =3D be16_to_cpu(globalflags); @@ -532,8 +532,8 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, } /* client requested flags */ clientflags =3D cpu_to_be32(clientflags); - if (write_sync(ioc, &clientflags, sizeof(clientflags)) < 0) { - error_setg(errp, "Failed to send clientflags field"); + if (write_sync(ioc, &clientflags, sizeof(clientflags), errp) < 0) { + error_prepend(errp, "Failed to send clientflags field"); goto fail; } if (tlscreds) { @@ -570,14 +570,14 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, } =20 /* Read the response */ - if (read_sync(ioc, &s, sizeof(s)) < 0) { - error_setg(errp, "Failed to read export length"); + if (read_sync(ioc, &s, sizeof(s), errp) < 0) { + error_prepend(errp, "Failed to read export length"); goto fail; } *size =3D be64_to_cpu(s); =20 - if (read_sync(ioc, flags, sizeof(*flags)) < 0) { - error_setg(errp, "Failed to read export flags"); + if (read_sync(ioc, flags, sizeof(*flags), errp) < 0) { + error_prepend(errp, "Failed to read export flags"); goto fail; } be16_to_cpus(flags); @@ -593,15 +593,15 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char= *name, uint16_t *flags, goto fail; } =20 - if (read_sync(ioc, &s, sizeof(s)) < 0) { - error_setg(errp, "Failed to read export length"); + if (read_sync(ioc, &s, sizeof(s), errp) < 0) { + error_prepend(errp, "Failed to read export length"); goto fail; } *size =3D be64_to_cpu(s); TRACE("Size is %" PRIu64, *size); =20 - if (read_sync(ioc, &oldflags, sizeof(oldflags)) < 0) { - error_setg(errp, "Failed to read export flags"); + if (read_sync(ioc, &oldflags, sizeof(oldflags), errp) < 0) { + error_prepend(errp, "Failed to read export flags"); goto fail; } be32_to_cpus(&oldflags); @@ -616,8 +616,8 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, } =20 TRACE("Size is %" PRIu64 ", export flags %" PRIx16, *size, *flags); - if (zeroes && drop_sync(ioc, 124) < 0) { - error_setg(errp, "Failed to read reserved block"); + if (zeroes && drop_sync(ioc, 124, errp) < 0) { + error_prepend(errp, "Failed to read reserved block"); goto fail; } rc =3D 0; @@ -755,7 +755,7 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *r= equest) stq_be_p(buf + 16, request->from); stl_be_p(buf + 24, request->len); =20 - return write_sync(ioc, buf, sizeof(buf)); + return write_sync(ioc, buf, sizeof(buf), NULL); } =20 ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply) @@ -764,7 +764,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply) uint32_t magic; ssize_t ret; =20 - ret =3D read_sync_eof(ioc, buf, sizeof(buf)); + ret =3D read_sync_eof(ioc, buf, sizeof(buf), NULL); if (ret <=3D 0) { return ret; } diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 1d479fe..d607164 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -100,7 +100,8 @@ * qio_channel_readv() returns 0. So, there are no needs to call read_sync= _eof * iteratively. */ -static inline ssize_t read_sync_eof(QIOChannel *ioc, void *buffer, size_t = size) +static inline ssize_t read_sync_eof(QIOChannel *ioc, void *buffer, size_t = size, + Error **errp) { struct iovec iov =3D { .iov_base =3D buffer, .iov_len =3D size }; /* Sockets are kept in blocking mode in the negotiation phase. After @@ -108,18 +109,20 @@ static inline ssize_t read_sync_eof(QIOChannel *ioc, = void *buffer, size_t size) * our request/reply. Synchronization is done with recv_coroutine, so * that this is coroutine-safe. */ - return nbd_wr_syncv(ioc, &iov, 1, size, true, NULL); + return nbd_wr_syncv(ioc, &iov, 1, size, true, errp); } =20 /* read_sync * Reads @size bytes from @ioc. Returns 0 on success. */ -static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size) +static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size, + Error **errp) { - ssize_t ret =3D read_sync_eof(ioc, buffer, size); + ssize_t ret =3D read_sync_eof(ioc, buffer, size, errp); =20 if (ret >=3D 0 && ret !=3D size) { ret =3D -EINVAL; + error_setg(errp, "End of file"); } =20 return ret < 0 ? ret : 0; @@ -128,11 +131,12 @@ static inline int read_sync(QIOChannel *ioc, void *bu= ffer, size_t size) /* write_sync * Writes @size bytes to @ioc. Returns 0 on success. */ -static inline int write_sync(QIOChannel *ioc, const void *buffer, size_t s= ize) +static inline int write_sync(QIOChannel *ioc, const void *buffer, size_t s= ize, + Error **errp) { struct iovec iov =3D { .iov_base =3D (void *) buffer, .iov_len =3D siz= e }; =20 - ssize_t ret =3D nbd_wr_syncv(ioc, &iov, 1, size, false, NULL); + ssize_t ret =3D nbd_wr_syncv(ioc, &iov, 1, size, false, errp); =20 assert(ret < 0 || ret =3D=3D size); =20 diff --git a/nbd/server.c b/nbd/server.c index 1e1096c..ee59e5d 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -124,7 +124,7 @@ static int nbd_negotiate_read(QIOChannel *ioc, void *bu= ffer, size_t size) nbd_negotiate_continue, qemu_coroutine_self(), NULL); - ret =3D read_sync(ioc, buffer, size); + ret =3D read_sync(ioc, buffer, size, NULL); g_source_remove(watch); return ret; =20 @@ -142,7 +142,7 @@ static int nbd_negotiate_write(QIOChannel *ioc, const v= oid *buffer, size_t size) nbd_negotiate_continue, qemu_coroutine_self(), NULL); - ret =3D write_sync(ioc, buffer, size); + ret =3D write_sync(ioc, buffer, size, NULL); g_source_remove(watch); return ret; } @@ -694,7 +694,7 @@ static ssize_t nbd_receive_request(QIOChannel *ioc, NBD= Request *request) uint32_t magic; ssize_t ret; =20 - ret =3D read_sync(ioc, buf, sizeof(buf)); + ret =3D read_sync(ioc, buf, sizeof(buf), NULL); if (ret < 0) { return ret; } @@ -745,7 +745,7 @@ static ssize_t nbd_send_reply(QIOChannel *ioc, NBDReply= *reply) stl_be_p(buf + 4, reply->error); stq_be_p(buf + 8, reply->handle); =20 - return write_sync(ioc, buf, sizeof(buf)); + return write_sync(ioc, buf, sizeof(buf), NULL); } =20 #define MAX_NBD_REQUESTS 16 @@ -1048,7 +1048,7 @@ static ssize_t nbd_co_send_reply(NBDRequestData *req,= NBDReply *reply, qio_channel_set_cork(client->ioc, true); rc =3D nbd_send_reply(client->ioc, reply); if (rc >=3D 0) { - ret =3D write_sync(client->ioc, req->data, len); + ret =3D write_sync(client->ioc, req->data, len, NULL); if (ret < 0) { rc =3D -EIO; } @@ -1123,7 +1123,7 @@ static ssize_t nbd_co_receive_request(NBDRequestData = *req, if (request->type =3D=3D NBD_CMD_WRITE) { TRACE("Reading %" PRIu32 " byte(s)", request->len); =20 - if (read_sync(client->ioc, req->data, request->len) < 0) { + if (read_sync(client->ioc, req->data, request->len, NULL) < 0) { LOG("reading from socket failed"); rc =3D -EIO; goto out; --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321413331622.3955710090854; Thu, 1 Jun 2017 05:50:13 -0700 (PDT) Received: from localhost ([::1]:44183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPYJ-0001tU-HK for importer@patchew.org; Thu, 01 Jun 2017 08:50:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQc-0003cc-3Z for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQa-0005jm-LC for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:14 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36285) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQa-0005jY-BB for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:12 -0400 Received: by mail-wm0-x244.google.com with SMTP id k15so11049548wmh.3 for ; Thu, 01 Jun 2017 05:42:12 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=xas5MrMter4Z8C1VPTzpzFJNGYrEqm5+sfYT3JfjM/k=; b=lCw8DBXDIPmuBYwI3F3t7BGZrikGq3/+hCrjgXkuTRUyetI0bGlwbCIHiTWbW2ohyI DPVfEoAh/2CHDyGWmgLH7S1HngMPYSCO7NLwnnKOgBtJ3NxofnlckKIgSLNQ85/A9ND4 F/b9cR6eEaPP4a9nx62FApskQ4E23IL/IKXWuV9OVUyKpI8nYTdJWatpyZvFUcnwcSIR ymAmNTzaCfVd/l6Txg9lBgqabDa5aZevX/H9IwFeCECIEdgnDe/cyzQkVXooP8E3UqkC 9ev9rp9HOCcd7SlO2XS5T6sYjO1DKQm4DL4lilw64LTbLkAkgALSFJ15NKV8+qu0534m k3DQ== 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=xas5MrMter4Z8C1VPTzpzFJNGYrEqm5+sfYT3JfjM/k=; b=aPx3eFZxQe0ktzHIpnL38wme+4xVCPYPiYV6bcsRJlyGut3natbkgk7HPQ40PwMzFh 8ybaVI/q7GSUkLcz0pfUZyVJ/gQ9sPg4BD4CNrysJHCRc22ZPrH5ed+huN5UsDu/gWgX Rh4VJJItfUPGdAKOnyNeUKDhAAAZsI0bY7O1WTtHeOpNEccOFYx1PppyOzEX2fBj0i+L aiKQ4e+ZoQfPzUj71WNuQinIamS2prmBq9onGcoxvN82s/mYGEfI9FZYQxNnxNkLOsat BwgIPeZXM5SJVtD0mzSlvGSsz6rY+aDf++0TevYMRhrY01KQbk99WJ1Y+uRBEPqO9yVk qy/g== X-Gm-Message-State: AODbwcDfMMAaDrEhX+fgRMzTjk06M3uLyM3s6b/wlPFvPtRxNIoDBFUX DRfjCwEYsgw5SMUZKEI= X-Received: by 10.28.5.82 with SMTP id 79mr1588941wmf.103.1496320931034; Thu, 01 Jun 2017 05:42:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:32 +0200 Message-Id: <1496320911-51305-15-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::244 Subject: [Qemu-devel] [PULL 14/33] nbd/client.c: use errp instead of LOG 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: Vladimir Sementsov-Ogievskiy Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Move to modern errp scheme from just LOGging errors. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170526110913.89098-1-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- block/nbd-client.c | 7 ++++++- include/block/nbd.h | 5 +++-- nbd/client.c | 30 +++++++++++++++++------------- qemu-nbd.c | 3 ++- tests/qemu-iotests/083.out | 2 ++ 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 538d95e..09d955b 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -28,6 +28,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "nbd-client.h" =20 #define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs)) @@ -70,10 +71,14 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) NBDClientSession *s =3D opaque; uint64_t i; int ret; + Error *local_err =3D NULL; =20 for (;;) { assert(s->reply.handle =3D=3D 0); - ret =3D nbd_receive_reply(s->ioc, &s->reply); + ret =3D nbd_receive_reply(s->ioc, &s->reply, &local_err); + if (ret < 0) { + error_report_err(local_err); + } if (ret <=3D 0) { break; } diff --git a/include/block/nbd.h b/include/block/nbd.h index 9d385ea..416257a 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -133,9 +133,10 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char = *name, uint16_t *flags, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, off_t *size, Error **errp); -int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size); +int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size, + Error **errp); ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request); -ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply); +ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp); int nbd_client(int fd); int nbd_disconnect(int fd); =20 diff --git a/nbd/client.c b/nbd/client.c index f102375..595d99e 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -627,11 +627,13 @@ fail: } =20 #ifdef __linux__ -int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size) +int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size, + Error **errp) { unsigned long sectors =3D size / BDRV_SECTOR_SIZE; if (size / BDRV_SECTOR_SIZE !=3D sectors) { - LOG("Export size %lld too large for 32-bit kernel", (long long) si= ze); + error_setg(errp, "Export size %lld too large for 32-bit kernel", + (long long) size); return -E2BIG; } =20 @@ -639,7 +641,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size) =20 if (ioctl(fd, NBD_SET_SOCK, (unsigned long) sioc->fd) < 0) { int serrno =3D errno; - LOG("Failed to set NBD socket"); + error_setg(errp, "Failed to set NBD socket"); return -serrno; } =20 @@ -647,7 +649,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size) =20 if (ioctl(fd, NBD_SET_BLKSIZE, (unsigned long)BDRV_SECTOR_SIZE) < 0) { int serrno =3D errno; - LOG("Failed setting NBD block size"); + error_setg(errp, "Failed setting NBD block size"); return -serrno; } =20 @@ -659,7 +661,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size) =20 if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) { int serrno =3D errno; - LOG("Failed setting size (in blocks)"); + error_setg(errp, "Failed setting size (in blocks)"); return -serrno; } =20 @@ -670,12 +672,12 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t= flags, off_t size) =20 if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) { int serrno =3D errno; - LOG("Failed setting read-only attribute"); + error_setg(errp, "Failed setting read-only attribute"); return -serrno; } } else { int serrno =3D errno; - LOG("Failed setting flags"); + error_setg(errp, "Failed setting flags"); return -serrno; } } @@ -723,8 +725,10 @@ int nbd_disconnect(int fd) } =20 #else -int nbd_init(int fd, QIOChannelSocket *ioc, uint16_t flags, off_t size) +int nbd_init(int fd, QIOChannelSocket *ioc, uint16_t flags, off_t size, + Error **errp) { + error_setg(errp, "nbd_init is only supported on Linux"); return -ENOTSUP; } =20 @@ -758,19 +762,19 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest = *request) return write_sync(ioc, buf, sizeof(buf), NULL); } =20 -ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply) +ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) { uint8_t buf[NBD_REPLY_SIZE]; uint32_t magic; ssize_t ret; =20 - ret =3D read_sync_eof(ioc, buf, sizeof(buf), NULL); + ret =3D read_sync_eof(ioc, buf, sizeof(buf), errp); if (ret <=3D 0) { return ret; } =20 if (ret !=3D sizeof(buf)) { - LOG("read failed"); + error_setg(errp, "read failed"); return -EINVAL; } =20 @@ -788,7 +792,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply) =20 if (reply->error =3D=3D ESHUTDOWN) { /* This works even on mingw which lacks a native ESHUTDOWN */ - LOG("server shutting down"); + error_setg(errp, "server shutting down"); return -EINVAL; } TRACE("Got reply: { magic =3D 0x%" PRIx32 ", .error =3D % " PRId32 @@ -796,7 +800,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply) magic, reply->error, reply->handle); =20 if (magic !=3D NBD_REPLY_MAGIC) { - LOG("invalid magic (got 0x%" PRIx32 ")", magic); + error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); return -EINVAL; } return sizeof(buf); diff --git a/qemu-nbd.c b/qemu-nbd.c index b7ab86b..f60842f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -288,8 +288,9 @@ static void *nbd_client_thread(void *arg) goto out_socket; } =20 - ret =3D nbd_init(fd, sioc, nbdflags, size); + ret =3D nbd_init(fd, sioc, nbdflags, size, &local_error); if (ret < 0) { + error_report_err(local_error); goto out_fd; } =20 diff --git a/tests/qemu-iotests/083.out b/tests/qemu-iotests/083.out index 0c13888..a24c6bf 100644 --- a/tests/qemu-iotests/083.out +++ b/tests/qemu-iotests/083.out @@ -69,10 +69,12 @@ read failed: Input/output error =20 =3D=3D=3D Check disconnect 4 reply =3D=3D=3D =20 +read failed read failed: Input/output error =20 =3D=3D=3D Check disconnect 8 reply =3D=3D=3D =20 +read failed read failed: Input/output error =20 =3D=3D=3D Check disconnect before data =3D=3D=3D --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321665597184.6787259963536; Thu, 1 Jun 2017 05:54:25 -0700 (PDT) Received: from localhost ([::1]:44203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPcN-0005dk-NG for importer@patchew.org; Thu, 01 Jun 2017 08:54:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQc-0003dH-BD for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQb-0005jv-C6 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:14 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36286) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQb-0005jj-6Z for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:13 -0400 Received: by mail-wm0-x244.google.com with SMTP id k15so11049631wmh.3 for ; Thu, 01 Jun 2017 05:42:13 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:11 -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=31lvrrUuhrxHk+N3/PDiYZZ7iLkDPuTr10cSDKl06pc=; b=TgSQRkYDVLpnp4noaiJUamie37f037zVSk6eZY6DmW4IZdEIiTh2UFYz7DVmly3XQK MoTTY3gSE+aeoFls1+ydkF52aWyVjBPDAHiWscX6QKabgagsv72mp7yPv7aCMJtk1xgj yAgGo/N27ZnUbGt0dlHaGnQc1I64KgKtOJIbYiPLA61QSg5qBfkaFfbsUDEUQODySaq5 rNDpwCAWljD5H034xRfWKT2lcsMD3l5vK5LHe9Y0dDgNlWYQt8EcPZw0X1H5Nppr/diP tbPCBYogXlnZ+DHzC+v2Vqaw5Hhdaq1vhtWfi5+gP+3WmWKGbOpdRjRq3P2FTfxjGIX3 K6QQ== 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=31lvrrUuhrxHk+N3/PDiYZZ7iLkDPuTr10cSDKl06pc=; b=HbFj1gzxc0773AYRzaY2kp7bt8U1ndnkuucYUh57o9+AI7mk8iKO/2chA2heJJ1Fyq VP4S8bULAyGpPnE7wxrIU+7V+BHNYtqTbpqDRLSrTbw1hUDBqSTcPcj8RwFV6/pPOkHg AghNdgUKy/KD+BkW2El5Iu26/KhoKAP8wSTOG8A8UXQWGI4maPLYrr/WSGUDA+5YNNyM JF15bvtA1nVTac3S1aLxMhvEaKSvw7MSE3G2v/lAu7Xq2mvOFnRe5p13xOueEMS8LUqy ZE28abzUGQdz26PTearrF15Z9kg8qCnC86JMl99rfAauKlr85JeEiw7i22R1rOs8LwzV IXAg== X-Gm-Message-State: AODbwcCbqP75Avj6rPx5voLvwak36ie4pQ6lMoAvrPcxouw+S1n7mjHE jjGU04T6EBJ4HELpCyM= X-Received: by 10.28.175.84 with SMTP id y81mr9729931wme.25.1496320932005; Thu, 01 Jun 2017 05:42:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:33 +0200 Message-Id: <1496320911-51305-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::244 Subject: [Qemu-devel] [PULL 15/33] exec: simplify phys_page_find() params 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: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu It really only plays with the dispatchers, so the parameter list does not need that complexity. This helps for readability at least. Signed-off-by: Peter Xu Message-Id: <1494838260-30439-2-git-send-email-peterx@redhat.com> Reviewed-by: David Gibson Signed-off-by: Paolo Bonzini --- exec.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/exec.c b/exec.c index 96e3ac9..29633cd 100644 --- a/exec.c +++ b/exec.c @@ -373,10 +373,11 @@ static inline bool section_covers_addr(const MemoryRe= gionSection *section, int128_getlo(section->size), addr); } =20 -static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr, - Node *nodes, MemoryRegionSectio= n *sections) +static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr= addr) { - PhysPageEntry *p; + PhysPageEntry lp =3D d->phys_map, *p; + Node *nodes =3D d->map.nodes; + MemoryRegionSection *sections =3D d->map.sections; hwaddr index =3D addr >> TARGET_PAGE_BITS; int i; =20 @@ -414,8 +415,7 @@ static MemoryRegionSection *address_space_lookup_region= (AddressSpaceDispatch *d, section_covers_addr(section, addr)) { update =3D false; } else { - section =3D phys_page_find(d->phys_map, addr, d->map.nodes, - d->map.sections); + section =3D phys_page_find(d, addr); update =3D true; } if (resolve_subpage && section->mr->subpage) { @@ -1283,8 +1283,7 @@ static void register_subpage(AddressSpaceDispatch *d,= MemoryRegionSection *secti subpage_t *subpage; hwaddr base =3D section->offset_within_address_space & TARGET_PAGE_MASK; - MemoryRegionSection *existing =3D phys_page_find(d->phys_map, base, - d->map.nodes, d->map.se= ctions); + MemoryRegionSection *existing =3D phys_page_find(d, base); MemoryRegionSection subsection =3D { .offset_within_address_space =3D base, .size =3D int128_make64(TARGET_PAGE_SIZE), --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321816733578.0968136964659; Thu, 1 Jun 2017 05:56:56 -0700 (PDT) Received: from localhost ([::1]:44216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPep-0007mJ-0J for importer@patchew.org; Thu, 01 Jun 2017 08:56:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQd-0003gK-9s for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQc-0005kS-Hj for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:15 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33589) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQc-0005jz-Bt; Thu, 01 Jun 2017 08:42:14 -0400 Received: by mail-wm0-x244.google.com with SMTP id b84so11063945wmh.0; Thu, 01 Jun 2017 05:42:14 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:12 -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=rZPd2EpwCr0E+hKxm3dgk1klNysbub8Vv+9emWkUwIQ=; b=vGCdZKV5LKlmMYuJPQA5U6p5sj7+DxXdB9C/YYqpSZqqNIeiAoUkRSsSkkecdU9WNk rpTFQCyIFJpNr4+Nn8et6k2bIOUH8sTNGG9ud0y2kK7zUHsFumbyF2FCjeGn+AbnZ4tH JbX1H3NaY+Oc/bUFdeIlOP9khNgvcPmgBFCfTJ2BX6rMdFFbPKNKHnBVElR5SsW7tNqU 1ulbTj4Vga8ZsfdN5xup3kKfu2lNOuTrNuIBXpcYlcss6fiIa+R4/a2ERG4S/f0umlwF oYw3aeQ1ZH+V2aiCz2DZzNzIAtP8YUpqP5BGvQDup38irclSxBQu4DI+rkoryGCQAVaO miRQ== 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=rZPd2EpwCr0E+hKxm3dgk1klNysbub8Vv+9emWkUwIQ=; b=nVNASeT+zDhOfjLZ7r/j+QfYnn0LYjNmaRluH26zGC3W4MobCDkfu9CSGpbIvTSM2A ZXAurFg0YZEKvcQ6o1J1VG0kwuwTCLobJnYh6B3hTlB20F8brD8HbHIHYkzKB8EG0mXm vU8Z4yIpLtnAN1IM8k0+TJX3hM16U/d4zpeB5p9+AjOceIvpjv5ABeFK+HmHK5q9anpo TODqs4368lpwc7Vyhb2DtpQWCSNhuU0bkTwQ9n7YkOGEW7/jGiu6rzQZN4iyUk32CFsK lW/9RxGF1VprwRPWQenagYt3QD9A7X2KoiYcRV+o/+p3tXlKfWRJJN0XHLfSnrfPDt88 AADw== X-Gm-Message-State: AODbwcCYZqA8pp0/w7fKJhF3WrjDeb5S4i4hX5X02JQjRGepzfjl0Mdl nC2mFaRSSCARS84c5hk= X-Received: by 10.28.209.131 with SMTP id i125mr1487048wmg.57.1496320933156; Thu, 01 Jun 2017 05:42:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:34 +0200 Message-Id: <1496320911-51305-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::244 Subject: [Qemu-devel] [PULL 16/33] virtio-scsi: Unset hotplug handler when unrealize 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: Fam Zheng , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng This matches the qbus_set_hotplug_handler in realize, and it releases the final reference to the embedded VirtIODevice so that it is properly finalized. A use-after-free is fixed with this patch, indirectly: virtio_device_instance_finalize wasn't called at hot-unplug, and the vdev->listener would be a dangling pointer in the global and the per address space listener list. See also RHBZ 1449031. Cc: qemu-stable@nongnu.org Signed-off-by: Fam Zheng Message-Id: <20170518102808.30046-1-famz@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/virtio-scsi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 46a3e3f..f46f06d 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -918,6 +918,9 @@ void virtio_scsi_common_unrealize(DeviceState *dev, Err= or **errp) =20 static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp) { + VirtIOSCSI *s =3D VIRTIO_SCSI(dev); + + qbus_set_hotplug_handler(BUS(&s->bus), NULL, &error_abort); virtio_scsi_common_unrealize(dev, errp); } =20 --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321754092872.2339208519636; Thu, 1 Jun 2017 05:55:54 -0700 (PDT) Received: from localhost ([::1]:44214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPdo-0006uC-Bm for importer@patchew.org; Thu, 01 Jun 2017 08:55:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQg-0003nl-Fa for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQe-0005kt-CQ for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:18 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:38327) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQe-0005kg-1X for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:16 -0400 Received: by mail-wm0-x234.google.com with SMTP id n195so30608825wmg.1 for ; Thu, 01 Jun 2017 05:42:15 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:13 -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=I7BGOFHaZ6nzttkc5wae6PUd2AGnXxzHFsF79p7+QVk=; b=DluU+U0nvfVUkrfwmXA9pG8OdzO6aTaqFqzgm/tryvNe+ePS54R4Pc8XIWsmQTpwr1 dgmN6HKa7JpgFUTQtcVebdAJbuhCOYNeVaZBz1ysqOXvgl+BOHQd4rqzkeSVh/hHoCY/ 13TE+rvwoJHPK/LF1pLPl2QbM4wJfCk443Se4Sne/LpDsPLSXiBeeBbxlXDAY5fn41vq OJY//y968BHj+o3MGe/IXQeWWFz8Dfg9vHU/SiZzGXLDToZill117wGXq4k6eYhyQCRN m5siK3rZM3CKecB40gKbn0hZd1B6RAucRt3S4WRmhVMsvGlsms0y/HrUslsrSJHXyen/ uq3Q== 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=I7BGOFHaZ6nzttkc5wae6PUd2AGnXxzHFsF79p7+QVk=; b=hwxZjU58PzGq00004lw8G4YQSL9xruioeZqYJbRQJ1ZWBShtWTVRTQx3bFFNgUO0r+ 3q7K4EYOTL2eE+2Aw3gALGMjAtjrU0LewL1VMvkVcaqokWPvzNn8YpQfFEZQtIXglvEp Dd9/vIdMXGmVP38c7jI4wlrhARSJKtVEnGaxgjE6wPcohxWEMKq9/x323/ztn/RxWcCk b2twtPbZqYNTIFllcQjeQFhqv1L90Yi3D0YgPR787383uJKOSgFkRlV/uOskNPBk07iJ h2gBUyuWLfP9xL8eggdfK2nRrdamZLCRq1Boiwhwp/Dyf1SFKpzsv5vqpSakqGi+v87w 6J4w== X-Gm-Message-State: AODbwcC/4qfb4YprFPfxwQoYhrj1VHU7CMVtP520iBsTKHDsgWsWmIxp 5owsuCZrwLfMXScX0WQ= X-Received: by 10.28.140.74 with SMTP id o71mr9518386wmd.90.1496320934536; Thu, 01 Jun 2017 05:42:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:35 +0200 Message-Id: <1496320911-51305-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::234 Subject: [Qemu-devel] [PULL 17/33] vhost-user-scsi: Introduce vhost-user-scsi host device 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: Felipe Franciosi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Felipe Franciosi This commit introduces a vhost-user device for SCSI. This is based on the existing vhost-scsi implementation, but done over vhost-user instead. It also uses a chardev to connect to the backend. Unlike vhost-scsi (today), VMs using vhost-user-scsi can be live migrated. To use it, start Qemu with a command line equivalent to: qemu-system-x86_64 \ -chardev socket,id=3Dvus0,path=3D/tmp/vus.sock \ -device vhost-user-scsi-pci,chardev=3Dvus0,bus=3Dpci.0,addr=3D... A separate commit presents a sample application linked with libiscsi to provide a backend for vhost-user-scsi. Signed-off-by: Felipe Franciosi Message-Id: <1488479153-21203-4-git-send-email-felipe@nutanix.com> --- .gitignore | 1 + default-configs/pci.mak | 1 + default-configs/s390x-softmmu.mak | 1 + hw/scsi/Makefile.objs | 1 + hw/scsi/vhost-scsi-common.c | 1 - hw/scsi/vhost-user-scsi.c | 211 ++++++++++++++++++++++++++++++++= ++++ hw/virtio/virtio-pci.c | 54 +++++++++ hw/virtio/virtio-pci.h | 11 ++ include/hw/virtio/vhost-user-scsi.h | 35 ++++++ include/hw/virtio/virtio-scsi.h | 2 + 10 files changed, 317 insertions(+), 1 deletion(-) create mode 100644 hw/scsi/vhost-user-scsi.c create mode 100644 include/hw/virtio/vhost-user-scsi.h diff --git a/.gitignore b/.gitignore index 55a001e..fa96bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ /qemu-version.h.tmp /module_block.h /vscclient +/vhost-user-scsi /fsdev/virtfs-proxy-helper *.[1-9] *.a diff --git a/default-configs/pci.mak b/default-configs/pci.mak index 60dc651..1c523b8 100644 --- a/default-configs/pci.mak +++ b/default-configs/pci.mak @@ -42,3 +42,4 @@ CONFIG_VGA=3Dy CONFIG_VGA_PCI=3Dy CONFIG_IVSHMEM=3D$(CONFIG_EVENTFD) CONFIG_ROCKER=3Dy +CONFIG_VHOST_USER_SCSI=3D$(CONFIG_LINUX) diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-soft= mmu.mak index 9615a48..1b8aaa4 100644 --- a/default-configs/s390x-softmmu.mak +++ b/default-configs/s390x-softmmu.mak @@ -1,5 +1,6 @@ CONFIG_PCI=3Dy CONFIG_VIRTIO_PCI=3Dy +CONFIG_VHOST_USER_SCSI=3D$(CONFIG_LINUX) CONFIG_VIRTIO=3Dy CONFIG_SCLPCONSOLE=3Dy CONFIG_TERMINAL3270=3Dy diff --git a/hw/scsi/Makefile.objs b/hw/scsi/Makefile.objs index 54d8754..b188f72 100644 --- a/hw/scsi/Makefile.objs +++ b/hw/scsi/Makefile.objs @@ -11,4 +11,5 @@ obj-$(CONFIG_PSERIES) +=3D spapr_vscsi.o ifeq ($(CONFIG_VIRTIO),y) obj-y +=3D virtio-scsi.o virtio-scsi-dataplane.o obj-$(CONFIG_VHOST_SCSI) +=3D vhost-scsi-common.o vhost-scsi.o +obj-$(CONFIG_VHOST_USER_SCSI) +=3D vhost-scsi-common.o vhost-user-scsi.o endif diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index e41c031..d434b3e 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -16,7 +16,6 @@ */ =20 #include "qemu/osdep.h" -#include #include "qapi/error.h" #include "qemu/error-report.h" #include "migration/migration.h" diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c new file mode 100644 index 0000000..d27b2ad --- /dev/null +++ b/hw/scsi/vhost-user-scsi.c @@ -0,0 +1,211 @@ +/* + * vhost-user-scsi host device + * + * Copyright (c) 2016 Nutanix Inc. All rights reserved. + * + * Author: + * Felipe Franciosi + * + * This work is largely based on the "vhost-scsi" implementation by: + * Stefan Hajnoczi + * Nicholas Bellinger + * + * This work is licensed under the terms of the GNU LGPL, version 2 or lat= er. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/typedefs.h" +#include "qom/object.h" +#include "hw/fw-path-provider.h" +#include "hw/qdev-core.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-backend.h" +#include "hw/virtio/vhost-user-scsi.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-access.h" +#include "sysemu/char.h" + +/* Features supported by the host application */ +static const int user_feature_bits[] =3D { + VIRTIO_F_NOTIFY_ON_EMPTY, + VIRTIO_RING_F_INDIRECT_DESC, + VIRTIO_RING_F_EVENT_IDX, + VIRTIO_SCSI_F_HOTPLUG, + VHOST_INVALID_FEATURE_BIT +}; + +static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserSCSI *s =3D (VHostUserSCSI *)vdev; + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + bool start =3D (status & VIRTIO_CONFIG_S_DRIVER_OK) && vdev->vm_runnin= g; + + if (vsc->dev.started =3D=3D start) { + return; + } + + if (start) { + int ret; + + ret =3D vhost_scsi_common_start(vsc); + if (ret < 0) { + error_report("unable to start vhost-user-scsi: %s", strerror(-= ret)); + exit(1); + } + } else { + vhost_scsi_common_stop(vsc); + } +} + +static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ +} + +static void vhost_user_scsi_save(QEMUFile *f, void *opaque) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(opaque); + virtio_save(vdev, f); +} + +static int vhost_user_scsi_load(QEMUFile *f, void *opaque, int version_id) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(opaque); + return virtio_load(vdev, f, version_id); +} + +static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) +{ + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + VHostUserSCSI *s =3D VHOST_USER_SCSI(dev); + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + static int vhost_user_scsi_id; + Error *err =3D NULL; + int ret; + + if (!vs->conf.chardev.chr) { + error_setg(errp, "vhost-user-scsi: missing chardev"); + return; + } + + virtio_scsi_common_realize(dev, vhost_dummy_handle_output, + vhost_dummy_handle_output, + vhost_dummy_handle_output, &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } + + vsc->dev.nvqs =3D 2 + vs->conf.num_queues; + vsc->dev.vqs =3D g_new(struct vhost_virtqueue, vsc->dev.nvqs); + vsc->dev.vq_index =3D 0; + vsc->dev.backend_features =3D 0; + + ret =3D vhost_dev_init(&vsc->dev, (void *)&vs->conf.chardev, + VHOST_BACKEND_TYPE_USER, 0); + if (ret < 0) { + error_setg(errp, "vhost-user-scsi: vhost initialization failed: %s= ", + strerror(-ret)); + return; + } + + /* Channel and lun both are 0 for bootable vhost-user-scsi disk */ + vsc->channel =3D 0; + vsc->lun =3D 0; + vsc->target =3D vs->conf.boot_tpgt; + + register_savevm(dev, "vhost-user-scsi", vhost_user_scsi_id++, 1, + vhost_user_scsi_save, vhost_user_scsi_load, s); +} + +static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCSI *s =3D VHOST_USER_SCSI(dev); + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); + + /* This will stop the vhost backend. */ + vhost_user_scsi_set_status(vdev, 0); + + vhost_dev_cleanup(&vsc->dev); + g_free(vsc->dev.vqs); + + virtio_scsi_common_unrealize(dev, errp); +} + +static uint64_t vhost_user_scsi_get_features(VirtIODevice *vdev, + uint64_t features, Error **er= rp) +{ + VHostUserSCSI *s =3D VHOST_USER_SCSI(vdev); + + /* Turn on predefined features supported by this device */ + features |=3D s->host_features; + + return vhost_scsi_common_get_features(vdev, features, errp); +} + +static Property vhost_user_scsi_properties[] =3D { + DEFINE_PROP_CHR("chardev", VirtIOSCSICommon, conf.chardev), + DEFINE_PROP_UINT32("boot_tpgt", VirtIOSCSICommon, conf.boot_tpgt, 0), + DEFINE_PROP_UINT32("num_queues", VirtIOSCSICommon, conf.num_queues, 1), + DEFINE_PROP_UINT32("max_sectors", VirtIOSCSICommon, conf.max_sectors, + 0xFFFF), + DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSICommon, conf.cmd_per_lun, = 128), + DEFINE_PROP_BIT64("hotplug", VHostUserSCSI, host_features, + VIRTIO_SCSI_F_HOTPLUG, + true), + DEFINE_PROP_BIT64("param_change", VHostUserSCSI, host_features, + VIRTIO_SCSI_F_CHANGE, + true), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vhost_user_scsi_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + FWPathProviderClass *fwc =3D FW_PATH_PROVIDER_CLASS(klass); + + dc->props =3D vhost_user_scsi_properties; + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + vdc->realize =3D vhost_user_scsi_realize; + vdc->unrealize =3D vhost_user_scsi_unrealize; + vdc->get_features =3D vhost_user_scsi_get_features; + vdc->set_config =3D vhost_scsi_common_set_config; + vdc->set_status =3D vhost_user_scsi_set_status; + fwc->get_dev_path =3D vhost_scsi_common_get_fw_dev_path; +} + +static void vhost_user_scsi_instance_init(Object *obj) +{ + VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(obj); + + vsc->feature_bits =3D user_feature_bits; + + /* Add the bootindex property for this object */ + device_add_bootindex_property(obj, &vsc->bootindex, "bootindex", NULL, + DEVICE(vsc), NULL); +} + +static const TypeInfo vhost_user_scsi_info =3D { + .name =3D TYPE_VHOST_USER_SCSI, + .parent =3D TYPE_VHOST_SCSI_COMMON, + .instance_size =3D sizeof(VHostUserSCSI), + .class_init =3D vhost_user_scsi_class_init, + .instance_init =3D vhost_user_scsi_instance_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_FW_PATH_PROVIDER }, + { } + }, +}; + +static void virtio_register_types(void) +{ + type_register_static(&vhost_user_scsi_info); +} + +type_init(virtio_register_types) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index f9b7244..d52faeb 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2135,6 +2135,59 @@ static const TypeInfo vhost_scsi_pci_info =3D { }; #endif =20 +/* vhost-user-scsi-pci */ +static Property vhost_user_scsi_pci_properties[] =3D { + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **= errp) +{ + VHostUserSCSIPCI *dev =3D VHOST_USER_SCSI_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(vdev); + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D vs->conf.num_queues + 3; + } + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void vhost_user_scsi_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vhost_user_scsi_pci_realize; + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + dc->props =3D vhost_user_scsi_pci_properties; + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D PCI_DEVICE_ID_VIRTIO_SCSI; + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_STORAGE_SCSI; +} + +static void vhost_user_scsi_pci_instance_init(Object *obj) +{ + VHostUserSCSIPCI *dev =3D VHOST_USER_SCSI_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_SCSI); + object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), + "bootindex", &error_abort); +} + +static const TypeInfo vhost_user_scsi_pci_info =3D { + .name =3D TYPE_VHOST_USER_SCSI_PCI, + .parent =3D TYPE_VIRTIO_PCI, + .instance_size =3D sizeof(VHostUserSCSIPCI), + .instance_init =3D vhost_user_scsi_pci_instance_init, + .class_init =3D vhost_user_scsi_pci_class_init, +}; + /* vhost-vsock-pci */ =20 #ifdef CONFIG_VHOST_VSOCK @@ -2612,6 +2665,7 @@ static void virtio_pci_register_types(void) #ifdef CONFIG_VHOST_SCSI type_register_static(&vhost_scsi_pci_info); #endif + type_register_static(&vhost_user_scsi_pci_info); #ifdef CONFIG_VHOST_VSOCK type_register_static(&vhost_vsock_pci_info); #endif diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index b095dfc..69f5959 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -26,6 +26,7 @@ #include "hw/virtio/virtio-input.h" #include "hw/virtio/virtio-gpu.h" #include "hw/virtio/virtio-crypto.h" +#include "hw/virtio/vhost-user-scsi.h" =20 #ifdef CONFIG_VIRTFS #include "hw/9pfs/virtio-9p.h" @@ -44,6 +45,7 @@ typedef struct VirtIOBalloonPCI VirtIOBalloonPCI; typedef struct VirtIOSerialPCI VirtIOSerialPCI; typedef struct VirtIONetPCI VirtIONetPCI; typedef struct VHostSCSIPCI VHostSCSIPCI; +typedef struct VHostUserSCSIPCI VHostUserSCSIPCI; typedef struct VirtIORngPCI VirtIORngPCI; typedef struct VirtIOInputPCI VirtIOInputPCI; typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI; @@ -230,6 +232,15 @@ struct VHostSCSIPCI { }; #endif =20 +#define TYPE_VHOST_USER_SCSI_PCI "vhost-user-scsi-pci" +#define VHOST_USER_SCSI_PCI(obj) \ + OBJECT_CHECK(VHostUserSCSIPCI, (obj), TYPE_VHOST_USER_SCSI_PCI) + +struct VHostUserSCSIPCI { + VirtIOPCIProxy parent_obj; + VHostUserSCSI vdev; +}; + /* * virtio-blk-pci: This extends VirtioPCIProxy. */ diff --git a/include/hw/virtio/vhost-user-scsi.h b/include/hw/virtio/vhost-= user-scsi.h new file mode 100644 index 0000000..01861f7 --- /dev/null +++ b/include/hw/virtio/vhost-user-scsi.h @@ -0,0 +1,35 @@ +/* + * vhost-user-scsi host device + * + * Copyright (c) 2016 Nutanix Inc. All rights reserved. + * + * Author: + * Felipe Franciosi + * + * This file is largely based on "vhost-scsi.h" by: + * Stefan Hajnoczi + * + * This work is licensed under the terms of the GNU LGPL, version 2 or lat= er. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#ifndef VHOST_USER_SCSI_H +#define VHOST_USER_SCSI_H + +#include "qemu-common.h" +#include "hw/qdev.h" +#include "hw/virtio/virtio-scsi.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-scsi-common.h" + +#define TYPE_VHOST_USER_SCSI "vhost-user-scsi" +#define VHOST_USER_SCSI(obj) \ + OBJECT_CHECK(VHostUserSCSI, (obj), TYPE_VHOST_USER_SCSI) + +typedef struct VHostUserSCSI { + VHostSCSICommon parent_obj; + uint64_t host_features; +} VHostUserSCSI; + +#endif /* VHOST_USER_SCSI_H */ diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scs= i.h index eac2013..ca77a42 100644 --- a/include/hw/virtio/virtio-scsi.h +++ b/include/hw/virtio/virtio-scsi.h @@ -21,6 +21,7 @@ #include "hw/virtio/virtio.h" #include "hw/pci/pci.h" #include "hw/scsi/scsi.h" +#include "sysemu/char.h" #include "sysemu/iothread.h" =20 #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common" @@ -53,6 +54,7 @@ struct VirtIOSCSIConf { char *vhostfd; char *wwpn; #endif + CharBackend chardev; uint32_t boot_tpgt; IOThread *iothread; }; --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322055386882.5620094215323; Thu, 1 Jun 2017 06:00:55 -0700 (PDT) Received: from localhost ([::1]:44239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPie-00034N-NF for importer@patchew.org; Thu, 01 Jun 2017 09:00:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQi-0003pz-Fb for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQf-0005lN-TJ for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:20 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35406) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQf-0005lC-F8 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:17 -0400 Received: by mail-wm0-x241.google.com with SMTP id g15so11030349wmc.2 for ; Thu, 01 Jun 2017 05:42:17 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:15 -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=0MpC8YNPa8ZeXDwv3YjLdvdx2lD5c00Vlg+BjyXIvzk=; b=sTaijjqV7Mfukw449+wgVW571hwiFeTGGx0vBI6hmToXOca8KfqclS7LW4JUlROKTv RYfVvTnURafxLuWQBdehYBWOv4aJRHQNRRgUgQmDSL64dHY3tgm4AZHs8kky86eMEvsy vJ1pLA9lanbJ0DUkMTW7n+twJVFHdIH9huTabdaEt9FNPWCT7J27qXHJczVf1Abn99Nc hTjB/DnoGxQ37Ozall2cBtCt7q1lPvAC9Wl4dmAbKsO+sLtDt2gMIbrWIkFKpCT6gH7+ a945plIM5lgoMna6pxIhMFLjX/YBEMYCWj70alrTlDP4XbGsj2W0vhR2Jk0GTTvg4kVe 8B0w== 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=0MpC8YNPa8ZeXDwv3YjLdvdx2lD5c00Vlg+BjyXIvzk=; b=MCJiiWn5YoTAfqRs5c//+saLhC2Xv8z5pRmc5yKkJUDbeG8NAf5kXzQFeqXZz8ZzlQ 71qzK+qvwC6Ss/EPbWy16GUY6BvK0ya+wzWUMQ+XXU//TiUZEJVs5lrKSWANzy+eKShH /OBFKNQFzJBo76jPrE9PdoVnLnFU8xJaI6+ZoMukgRvRhjTWCibFs7zO/N2HsPzACuyN Y/91pzmOfLSr0qM5TeYqB9EA3vrhb4A+fPR4bHMofMMyg51CTJVnOhd8XA8Swaqc4tw7 2Z1dBWvTSmG/ksLvtVV89agviQdAqH8p2SUME8pA7iRKoX05dklC1Ld0gL1NpjuVs6wv YHYQ== X-Gm-Message-State: AODbwcBwzsI8o2Qy8gErZu4KRf0SIFZ/Ahqgoj+vK7giEgVnUlsvu/hg SyB9j7C8kQ2Hwcbr/fQ= X-Received: by 10.223.135.227 with SMTP id c32mr1426647wrc.10.1496320936044; Thu, 01 Jun 2017 05:42:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:36 +0200 Message-Id: <1496320911-51305-19-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::241 Subject: [Qemu-devel] [PULL 18/33] vhost-user-scsi: Introduce a vhost-user-scsi sample application 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: Felipe Franciosi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Felipe Franciosi This commit introduces a vhost-user-scsi backend sample application. It must be linked with libiscsi and libvhost-user. To use it, compile with: $ make vhost-user-scsi And run as follows: $ ./vhost-user-scsi -u vus.sock -i iscsi://uri_to_target/ $ qemu-system-x86_64 --enable-kvm -m 512 \ -object memory-backend-file,id=3Dmem,size=3D512m,share=3Don,mem-path= =3Dguestmem \ -numa node,memdev=3Dmem \ -chardev socket,id=3Dvhost-user-scsi,path=3Dvus.sock \ -device vhost-user-scsi-pci,chardev=3Dvhost-user-scsi \ The application is currently limited at one LUN only and it processes requests synchronously (therefore only achieving QD1). The purpose of the code is to show how a backend can be implemented and to test the vhost-user-scsi Qemu implementation. If a different instance of this vhost-user-scsi application is executed at a remote host, a VM can be live migrated to such a host. Signed-off-by: Felipe Franciosi Message-Id: <1488479153-21203-5-git-send-email-felipe@nutanix.com> --- Makefile | 3 + Makefile.objs | 4 + contrib/libvhost-user/libvhost-user.h | 11 +- contrib/vhost-user-scsi/Makefile.objs | 1 + contrib/vhost-user-scsi/vhost-user-scsi.c | 886 ++++++++++++++++++++++++++= ++++ 5 files changed, 900 insertions(+), 5 deletions(-) create mode 100644 contrib/vhost-user-scsi/Makefile.objs create mode 100644 contrib/vhost-user-scsi/vhost-user-scsi.c diff --git a/Makefile b/Makefile index c830d7a..e14988d 100644 --- a/Makefile +++ b/Makefile @@ -269,6 +269,7 @@ dummy :=3D $(call unnest-vars,, \ ivshmem-client-obj-y \ ivshmem-server-obj-y \ libvhost-user-obj-y \ + vhost-user-scsi-obj-y \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \ @@ -473,6 +474,8 @@ ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) $(COMM= ON_LDADDS) $(call LINK, $^) ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) $(COMMON_LDADDS) $(call LINK, $^) +vhost-user-scsi$(EXESUF): $(vhost-user-scsi-obj-y) + $(call LINK, $^) =20 module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak $(call quiet-command,$(PYTHON) $< $@ \ diff --git a/Makefile.objs b/Makefile.objs index 2100845..1fa9450 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -112,6 +112,10 @@ qga-vss-dll-obj-y =3D qga/ ivshmem-client-obj-y =3D contrib/ivshmem-client/ ivshmem-server-obj-y =3D contrib/ivshmem-server/ libvhost-user-obj-y =3D contrib/libvhost-user/ +vhost-user-scsi.o-cflags :=3D $(LIBISCSI_CFLAGS) +vhost-user-scsi.o-libs :=3D $(LIBISCSI_LIBS) +vhost-user-scsi-obj-y =3D contrib/vhost-user-scsi/ +vhost-user-scsi-obj-y +=3D contrib/libvhost-user/libvhost-user.o =20 ###################################################################### trace-events-subdirs =3D diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/= libvhost-user.h index af02a31..53ef222 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "standard-headers/linux/virtio_ring.h" =20 @@ -192,11 +193,11 @@ typedef struct VuVirtq { } VuVirtq; =20 enum VuWatchCondtion { - VU_WATCH_IN =3D 1 << 0, - VU_WATCH_OUT =3D 1 << 1, - VU_WATCH_PRI =3D 1 << 2, - VU_WATCH_ERR =3D 1 << 3, - VU_WATCH_HUP =3D 1 << 4, + VU_WATCH_IN =3D POLLIN, + VU_WATCH_OUT =3D POLLOUT, + VU_WATCH_PRI =3D POLLPRI, + VU_WATCH_ERR =3D POLLERR, + VU_WATCH_HUP =3D POLLHUP, }; =20 typedef void (*vu_panic_cb) (VuDev *dev, const char *err); diff --git a/contrib/vhost-user-scsi/Makefile.objs b/contrib/vhost-user-scs= i/Makefile.objs new file mode 100644 index 0000000..e83a38a --- /dev/null +++ b/contrib/vhost-user-scsi/Makefile.objs @@ -0,0 +1 @@ +vhost-user-scsi-obj-y =3D vhost-user-scsi.o diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user= -scsi/vhost-user-scsi.c new file mode 100644 index 0000000..b5ae02c --- /dev/null +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -0,0 +1,886 @@ +/* + * vhost-user-scsi sample application + * + * Copyright (c) 2016 Nutanix Inc. All rights reserved. + * + * Author: + * Felipe Franciosi + * + * This work is licensed under the terms of the GNU GPL, version 2 only. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "contrib/libvhost-user/libvhost-user.h" +#include "hw/virtio/virtio-scsi.h" +#include "iscsi/iscsi.h" + +#include + +/* Small compat shim from glib 2.32 */ +#ifndef G_SOURCE_CONTINUE +#define G_SOURCE_CONTINUE TRUE +#endif +#ifndef G_SOURCE_REMOVE +#define G_SOURCE_REMOVE FALSE +#endif + +/* #define VUS_DEBUG 1 */ + +/** Log helpers **/ + +#define PPRE \ + struct timespec ts; \ + char timebuf[64]; \ + struct tm tm; \ + (void)clock_gettime(CLOCK_REALTIME, &ts); \ + (void)strftime(timebuf, 64, "%Y%m%d %T", gmtime_r(&ts.tv_sec, &tm)) + +#define PEXT(lvl, msg, ...) do { \ + PPRE; \ + fprintf(stderr, "%s.%06ld " lvl ": %s:%s():%d: " msg "\n", \ + timebuf, ts.tv_nsec / 1000, \ + __FILE__, __func__, __LINE__, ## __VA_ARGS__); \ +} while (0) + +#define PNOR(lvl, msg, ...) do { \ + PPRE; \ + fprintf(stderr, "%s.%06ld " lvl ": " msg "\n", \ + timebuf, ts.tv_nsec / 1000, ## __VA_ARGS__); \ +} while (0) + +#ifdef VUS_DEBUG +#define PDBG(msg, ...) PEXT("DBG", msg, ## __VA_ARGS__) +#define PERR(msg, ...) PEXT("ERR", msg, ## __VA_ARGS__) +#define PLOG(msg, ...) PEXT("LOG", msg, ## __VA_ARGS__) +#else +#define PDBG(msg, ...) { } +#define PERR(msg, ...) PNOR("ERR", msg, ## __VA_ARGS__) +#define PLOG(msg, ...) PNOR("LOG", msg, ## __VA_ARGS__) +#endif + +/** vhost-user-scsi specific definitions **/ + + /* Only 1 LUN and device supported today */ +#define VUS_MAX_LUNS 1 +#define VUS_MAX_DEVS 1 + +#define VUS_ISCSI_INITIATOR "iqn.2016-11.com.nutanix:vhost-user-scsi" + +typedef struct iscsi_lun { + struct iscsi_context *iscsi_ctx; + int iscsi_lun; +} iscsi_lun_t; + +typedef struct vhost_scsi_dev { + VuDev vu_dev; + int server_sock; + GMainLoop *loop; + GTree *fdmap; /* fd -> gsource context id */ + iscsi_lun_t luns[VUS_MAX_LUNS]; +} vhost_scsi_dev_t; + +static vhost_scsi_dev_t *vhost_scsi_devs[VUS_MAX_DEVS]; + +/** glib event loop integration for libvhost-user and misc callbacks **/ + +QEMU_BUILD_BUG_ON((int)G_IO_IN !=3D (int)VU_WATCH_IN); +QEMU_BUILD_BUG_ON((int)G_IO_OUT !=3D (int)VU_WATCH_OUT); +QEMU_BUILD_BUG_ON((int)G_IO_PRI !=3D (int)VU_WATCH_PRI); +QEMU_BUILD_BUG_ON((int)G_IO_ERR !=3D (int)VU_WATCH_ERR); +QEMU_BUILD_BUG_ON((int)G_IO_HUP !=3D (int)VU_WATCH_HUP); + +typedef struct vus_gsrc { + GSource parent; + vhost_scsi_dev_t *vdev_scsi; + GPollFD gfd; + vu_watch_cb vu_cb; +} vus_gsrc_t; + +static gint vus_fdmap_compare(gconstpointer a, gconstpointer b) +{ + return (b > a) - (b < a); +} + +static gboolean vus_gsrc_prepare(GSource *src, gint *timeout) +{ + assert(timeout); + + *timeout =3D -1; + return FALSE; +} + +static gboolean vus_gsrc_check(GSource *src) +{ + vus_gsrc_t *vus_src =3D (vus_gsrc_t *)src; + + assert(vus_src); + + return vus_src->gfd.revents & vus_src->gfd.events; +} + +static gboolean vus_gsrc_dispatch(GSource *src, GSourceFunc cb, gpointer d= ata) +{ + vhost_scsi_dev_t *vdev_scsi; + vus_gsrc_t *vus_src =3D (vus_gsrc_t *)src; + + assert(vus_src); + assert(!(vus_src->vu_cb && cb)); + + vdev_scsi =3D vus_src->vdev_scsi; + + assert(vdev_scsi); + + if (cb) { + return cb(data); + } + if (vus_src->vu_cb) { + vus_src->vu_cb(&vdev_scsi->vu_dev, vus_src->gfd.revents, data); + } + return G_SOURCE_CONTINUE; +} + +static GSourceFuncs vus_gsrc_funcs =3D { + vus_gsrc_prepare, + vus_gsrc_check, + vus_gsrc_dispatch, + NULL +}; + +static int vus_gsrc_new(vhost_scsi_dev_t *vdev_scsi, int fd, GIOCondition = cond, + vu_watch_cb vu_cb, GSourceFunc gsrc_cb, gpointer d= ata) +{ + GSource *vus_gsrc; + vus_gsrc_t *vus_src; + guint id; + + assert(vdev_scsi); + assert(fd >=3D 0); + assert(vu_cb || gsrc_cb); + assert(!(vu_cb && gsrc_cb)); + + vus_gsrc =3D g_source_new(&vus_gsrc_funcs, sizeof(vus_gsrc_t)); + if (!vus_gsrc) { + PERR("Error creating GSource for new watch"); + return -1; + } + vus_src =3D (vus_gsrc_t *)vus_gsrc; + + vus_src->vdev_scsi =3D vdev_scsi; + vus_src->gfd.fd =3D fd; + vus_src->gfd.events =3D cond; + vus_src->vu_cb =3D vu_cb; + + g_source_add_poll(vus_gsrc, &vus_src->gfd); + g_source_set_callback(vus_gsrc, gsrc_cb, data, NULL); + id =3D g_source_attach(vus_gsrc, NULL); + assert(id); + g_source_unref(vus_gsrc); + + g_tree_insert(vdev_scsi->fdmap, (gpointer)(uintptr_t)fd, + (gpointer)(uintptr_t)id); + + return 0; +} + +/* from libiscsi's scsi-lowlevel.h ** + * + * nb. We can't directly include scsi-lowlevel.h due to a namespace confli= ct: + * QEMU's scsi.h also defines "SCSI_XFER_NONE". + */ + +#define SCSI_CDB_MAX_SIZE 16 + +struct scsi_iovector { + struct scsi_iovec *iov; + int niov; + int nalloc; + size_t offset; + int consumed; +}; + +struct scsi_allocated_memory { + struct scsi_allocated_memory *next; + char buf[0]; +}; + +struct scsi_data { + int size; + unsigned char *data; +}; + +enum scsi_sense_key { + SCSI_SENSE_NO_SENSE =3D 0x00, + SCSI_SENSE_RECOVERED_ERROR =3D 0x01, + SCSI_SENSE_NOT_READY =3D 0x02, + SCSI_SENSE_MEDIUM_ERROR =3D 0x03, + SCSI_SENSE_HARDWARE_ERROR =3D 0x04, + SCSI_SENSE_ILLEGAL_REQUEST =3D 0x05, + SCSI_SENSE_UNIT_ATTENTION =3D 0x06, + SCSI_SENSE_DATA_PROTECTION =3D 0x07, + SCSI_SENSE_BLANK_CHECK =3D 0x08, + SCSI_SENSE_VENDOR_SPECIFIC =3D 0x09, + SCSI_SENSE_COPY_ABORTED =3D 0x0a, + SCSI_SENSE_COMMAND_ABORTED =3D 0x0b, + SCSI_SENSE_OBSOLETE_ERROR_CODE =3D 0x0c, + SCSI_SENSE_OVERFLOW_COMMAND =3D 0x0d, + SCSI_SENSE_MISCOMPARE =3D 0x0e +}; + +struct scsi_sense { + unsigned char error_type; + enum scsi_sense_key key; + int ascq; + unsigned sense_specific:1; + unsigned ill_param_in_cdb:1; + unsigned bit_pointer_valid:1; + unsigned char bit_pointer; + uint16_t field_pointer; +}; + +enum scsi_residual { + SCSI_RESIDUAL_NO_RESIDUAL =3D 0, + SCSI_RESIDUAL_UNDERFLOW, + SCSI_RESIDUAL_OVERFLOW +}; + +struct scsi_task { + int status; + int cdb_size; + int xfer_dir; + int expxferlen; + unsigned char cdb[SCSI_CDB_MAX_SIZE]; + enum scsi_residual residual_status; + size_t residual; + struct scsi_sense sense; + struct scsi_data datain; + struct scsi_allocated_memory *mem; + void *ptr; + + uint32_t itt; + uint32_t cmdsn; + uint32_t lun; + + struct scsi_iovector iovector_in; + struct scsi_iovector iovector_out; +}; + +/** libiscsi integration **/ + +static int iscsi_add_lun(iscsi_lun_t *lun, char *iscsi_uri) +{ + struct iscsi_url *iscsi_url; + struct iscsi_context *iscsi_ctx; + int ret =3D 0; + + assert(lun); + assert(iscsi_uri); + + iscsi_ctx =3D iscsi_create_context(VUS_ISCSI_INITIATOR); + if (!iscsi_ctx) { + PERR("Unable to create iSCSI context"); + return -1; + } + + iscsi_url =3D iscsi_parse_full_url(iscsi_ctx, iscsi_uri); + if (!iscsi_url) { + PERR("Unable to parse iSCSI URL: %s", iscsi_get_error(iscsi_ctx)); + goto fail; + } + + iscsi_set_session_type(iscsi_ctx, ISCSI_SESSION_NORMAL); + iscsi_set_header_digest(iscsi_ctx, ISCSI_HEADER_DIGEST_NONE_CRC32C); + if (iscsi_full_connect_sync(iscsi_ctx, iscsi_url->portal, iscsi_url->l= un)) { + PERR("Unable to login to iSCSI portal: %s", iscsi_get_error(iscsi_= ctx)); + goto fail; + } + + lun->iscsi_ctx =3D iscsi_ctx; + lun->iscsi_lun =3D iscsi_url->lun; + + PDBG("Context %p created for lun 0: %s", iscsi_ctx, iscsi_uri); + +out: + if (iscsi_url) { + iscsi_destroy_url(iscsi_url); + } + return ret; + +fail: + (void)iscsi_destroy_context(iscsi_ctx); + ret =3D -1; + goto out; +} + +static struct scsi_task *scsi_task_new(int cdb_len, uint8_t *cdb, int dir, + int xfer_len) { + struct scsi_task *task; + + assert(cdb_len > 0); + assert(cdb); + + task =3D calloc(1, sizeof(struct scsi_task)); + if (!task) { + PERR("Error allocating task: %s", strerror(errno)); + return NULL; + } + + memcpy(task->cdb, cdb, cdb_len); + task->cdb_size =3D cdb_len; + task->xfer_dir =3D dir; + task->expxferlen =3D xfer_len; + + return task; +} + +static int get_cdb_len(uint8_t *cdb) +{ + assert(cdb); + + switch (cdb[0] >> 5) { + case 0: return 6; + case 1: /* fall through */ + case 2: return 10; + case 4: return 16; + case 5: return 12; + } + PERR("Unable to determine cdb len (0x%02hhX)", cdb[0] >> 5); + return -1; +} + +static int handle_cmd_sync(struct iscsi_context *ctx, + VirtIOSCSICmdReq *req, + struct iovec *out, unsigned int out_len, + VirtIOSCSICmdResp *rsp, + struct iovec *in, unsigned int in_len) { + struct scsi_task *task; + uint32_t dir; + uint32_t len; + int cdb_len; + int i; + + assert(ctx); + assert(req); + assert(rsp); + + if (!(!req->lun[1] && req->lun[2] =3D=3D 0x40 && !req->lun[3])) { + /* Ignore anything different than target=3D0, lun=3D0 */ + PDBG("Ignoring unconnected lun (0x%hhX, 0x%hhX)", + req->lun[1], req->lun[3]); + rsp->status =3D SCSI_STATUS_CHECK_CONDITION; + memset(rsp->sense, 0, sizeof(rsp->sense)); + rsp->sense_len =3D 18; + rsp->sense[0] =3D 0x70; + rsp->sense[2] =3D SCSI_SENSE_ILLEGAL_REQUEST; + rsp->sense[7] =3D 10; + rsp->sense[12] =3D 0x24; + + return 0; + } + + cdb_len =3D get_cdb_len(req->cdb); + if (cdb_len =3D=3D -1) { + return -1; + } + + len =3D 0; + if (!out_len && !in_len) { + dir =3D SCSI_XFER_NONE; + } else if (out_len) { + dir =3D SCSI_XFER_TO_DEV; + for (i =3D 0; i < out_len; i++) { + len +=3D out[i].iov_len; + } + } else { + dir =3D SCSI_XFER_FROM_DEV; + for (i =3D 0; i < in_len; i++) { + len +=3D in[i].iov_len; + } + } + + task =3D scsi_task_new(cdb_len, req->cdb, dir, len); + if (!task) { + PERR("Unable to create iscsi task"); + return -1; + } + + if (dir =3D=3D SCSI_XFER_TO_DEV) { + task->iovector_out.iov =3D (struct scsi_iovec *)out; + task->iovector_out.niov =3D out_len; + } else if (dir =3D=3D SCSI_XFER_FROM_DEV) { + task->iovector_in.iov =3D (struct scsi_iovec *)in; + task->iovector_in.niov =3D in_len; + } + + PDBG("Sending iscsi cmd (cdb_len=3D%d, dir=3D%d, task=3D%p)", + cdb_len, dir, task); + if (!iscsi_scsi_command_sync(ctx, 0, task, NULL)) { + PERR("Error serving SCSI command"); + free(task); + return -1; + } + + memset(rsp, 0, sizeof(*rsp)); + + rsp->status =3D task->status; + rsp->resid =3D task->residual; + + if (task->status =3D=3D SCSI_STATUS_CHECK_CONDITION) { + rsp->response =3D VIRTIO_SCSI_S_FAILURE; + rsp->sense_len =3D task->datain.size - 2; + memcpy(rsp->sense, &task->datain.data[2], rsp->sense_len); + } + + free(task); + + PDBG("Filled in rsp: status=3D%hhX, resid=3D%u, response=3D%hhX, sense= _len=3D%u", + rsp->status, rsp->resid, rsp->response, rsp->sense_len); + + return 0; +} + +/** libvhost-user callbacks **/ + +static vhost_scsi_dev_t *vdev_scsi_find_by_vu(VuDev *vu_dev); + +static void vus_panic_cb(VuDev *vu_dev, const char *buf) +{ + vhost_scsi_dev_t *vdev_scsi; + + assert(vu_dev); + + vdev_scsi =3D vdev_scsi_find_by_vu(vu_dev); + + if (buf) { + PERR("vu_panic: %s", buf); + } + + if (vdev_scsi) { + assert(vdev_scsi->loop); + g_main_loop_quit(vdev_scsi->loop); + } +} + +static void vus_add_watch_cb(VuDev *vu_dev, int fd, int vu_evt, vu_watch_c= b cb, + void *pvt) { + vhost_scsi_dev_t *vdev_scsi; + guint id; + + assert(vu_dev); + assert(fd >=3D 0); + assert(cb); + + vdev_scsi =3D vdev_scsi_find_by_vu(vu_dev); + if (!vdev_scsi) { + vus_panic_cb(vu_dev, NULL); + return; + } + + id =3D (guint)(uintptr_t)g_tree_lookup(vdev_scsi->fdmap, + (gpointer)(uintptr_t)fd); + if (id) { + GSource *vus_src =3D g_main_context_find_source_by_id(NULL, id); + assert(vus_src); + g_source_destroy(vus_src); + (void)g_tree_remove(vdev_scsi->fdmap, (gpointer)(uintptr_t)fd); + } + + if (vus_gsrc_new(vdev_scsi, fd, vu_evt, cb, NULL, pvt)) { + vus_panic_cb(vu_dev, NULL); + } +} + +static void vus_del_watch_cb(VuDev *vu_dev, int fd) +{ + vhost_scsi_dev_t *vdev_scsi; + guint id; + + assert(vu_dev); + assert(fd >=3D 0); + + vdev_scsi =3D vdev_scsi_find_by_vu(vu_dev); + if (!vdev_scsi) { + vus_panic_cb(vu_dev, NULL); + return; + } + + id =3D (guint)(uintptr_t)g_tree_lookup(vdev_scsi->fdmap, + (gpointer)(uintptr_t)fd); + if (id) { + GSource *vus_src =3D g_main_context_find_source_by_id(NULL, id); + assert(vus_src); + g_source_destroy(vus_src); + (void)g_tree_remove(vdev_scsi->fdmap, (gpointer)(uintptr_t)fd); + } +} + +static void vus_proc_ctl(VuDev *vu_dev, int idx) +{ + /* Control VQ not implemented */ +} + +static void vus_proc_evt(VuDev *vu_dev, int idx) +{ + /* Event VQ not implemented */ +} + +static void vus_proc_req(VuDev *vu_dev, int idx) +{ + vhost_scsi_dev_t *vdev_scsi; + VuVirtq *vq; + + assert(vu_dev); + + vdev_scsi =3D vdev_scsi_find_by_vu(vu_dev); + if (!vdev_scsi) { + vus_panic_cb(vu_dev, NULL); + return; + } + + if ((idx < 0) || (idx >=3D VHOST_MAX_NR_VIRTQUEUE)) { + PERR("VQ Index out of range: %d", idx); + vus_panic_cb(vu_dev, NULL); + return; + } + + vq =3D vu_get_queue(vu_dev, idx); + if (!vq) { + PERR("Error fetching VQ (dev=3D%p, idx=3D%d)", vu_dev, idx); + vus_panic_cb(vu_dev, NULL); + return; + } + + PDBG("Got kicked on vq[%d]@%p", idx, vq); + + while (1) { + VuVirtqElement *elem; + VirtIOSCSICmdReq *req; + VirtIOSCSICmdResp *rsp; + + elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement)); + if (!elem) { + PDBG("No more elements pending on vq[%d]@%p", idx, vq); + break; + } + PDBG("Popped elem@%p", elem); + + assert(!((elem->out_num > 1) && (elem->in_num > 1))); + assert((elem->out_num > 0) && (elem->in_num > 0)); + + if (elem->out_sg[0].iov_len < sizeof(VirtIOSCSICmdReq)) { + PERR("Invalid virtio-scsi req header"); + vus_panic_cb(vu_dev, NULL); + break; + } + req =3D (VirtIOSCSICmdReq *)elem->out_sg[0].iov_base; + + if (elem->in_sg[0].iov_len < sizeof(VirtIOSCSICmdResp)) { + PERR("Invalid virtio-scsi rsp header"); + vus_panic_cb(vu_dev, NULL); + break; + } + rsp =3D (VirtIOSCSICmdResp *)elem->in_sg[0].iov_base; + + if (handle_cmd_sync(vdev_scsi->luns[0].iscsi_ctx, + req, &elem->out_sg[1], elem->out_num - 1, + rsp, &elem->in_sg[1], elem->in_num - 1) !=3D 0= ) { + vus_panic_cb(vu_dev, NULL); + break; + } + + vu_queue_push(vu_dev, vq, elem, 0); + vu_queue_notify(vu_dev, vq); + + free(elem); + } +} + +static void vus_queue_set_started(VuDev *vu_dev, int idx, bool started) +{ + VuVirtq *vq; + + assert(vu_dev); + + if ((idx < 0) || (idx >=3D VHOST_MAX_NR_VIRTQUEUE)) { + PERR("VQ Index out of range: %d", idx); + vus_panic_cb(vu_dev, NULL); + return; + } + + vq =3D vu_get_queue(vu_dev, idx); + + switch (idx) { + case 0: + vu_set_queue_handler(vu_dev, vq, started ? vus_proc_ctl : NULL); + break; + case 1: + vu_set_queue_handler(vu_dev, vq, started ? vus_proc_evt : NULL); + break; + default: + vu_set_queue_handler(vu_dev, vq, started ? vus_proc_req : NULL); + } +} + +static const VuDevIface vus_iface =3D { + .queue_set_started =3D vus_queue_set_started, +}; + +static gboolean vus_vhost_cb(gpointer data) +{ + VuDev *vu_dev =3D (VuDev *)data; + + assert(vu_dev); + + if (!vu_dispatch(vu_dev) !=3D 0) { + PERR("Error processing vhost message"); + vus_panic_cb(vu_dev, NULL); + return G_SOURCE_REMOVE; + } + + return G_SOURCE_CONTINUE; +} + +/** misc helpers **/ + +static int unix_sock_new(char *unix_fn) +{ + int sock; + struct sockaddr_un un; + size_t len; + + assert(unix_fn); + + sock =3D socket(AF_UNIX, SOCK_STREAM, 0); + if (sock <=3D 0) { + perror("socket"); + return -1; + } + + un.sun_family =3D AF_UNIX; + (void)snprintf(un.sun_path, sizeof(un.sun_path), "%s", unix_fn); + len =3D sizeof(un.sun_family) + strlen(un.sun_path); + + (void)unlink(unix_fn); + if (bind(sock, (struct sockaddr *)&un, len) < 0) { + perror("bind"); + goto fail; + } + + if (listen(sock, 1) < 0) { + perror("listen"); + goto fail; + } + + return sock; + +fail: + (void)close(sock); + + return -1; +} + +/** vhost-user-scsi **/ + +static vhost_scsi_dev_t *vdev_scsi_find_by_vu(VuDev *vu_dev) +{ + int i; + + assert(vu_dev); + + for (i =3D 0; i < VUS_MAX_DEVS; i++) { + if (&vhost_scsi_devs[i]->vu_dev =3D=3D vu_dev) { + return vhost_scsi_devs[i]; + } + } + + PERR("Unknown VuDev %p", vu_dev); + return NULL; +} + +static void vdev_scsi_deinit(vhost_scsi_dev_t *vdev_scsi) +{ + if (!vdev_scsi) { + return; + } + + if (vdev_scsi->server_sock >=3D 0) { + struct sockaddr_storage ss; + socklen_t sslen =3D sizeof(ss); + + if (getsockname(vdev_scsi->server_sock, (struct sockaddr *)&ss, + &sslen) =3D=3D 0) { + struct sockaddr_un *su =3D (struct sockaddr_un *)&ss; + (void)unlink(su->sun_path); + } + + (void)close(vdev_scsi->server_sock); + vdev_scsi->server_sock =3D -1; + } + + if (vdev_scsi->loop) { + g_main_loop_unref(vdev_scsi->loop); + vdev_scsi->loop =3D NULL; + } +} + +static vhost_scsi_dev_t *vdev_scsi_new(char *unix_fn) +{ + vhost_scsi_dev_t *vdev_scsi =3D NULL; + + assert(unix_fn); + + vdev_scsi =3D calloc(1, sizeof(vhost_scsi_dev_t)); + if (!vdev_scsi) { + PERR("calloc: %s", strerror(errno)); + return NULL; + } + + vdev_scsi->server_sock =3D unix_sock_new(unix_fn); + if (vdev_scsi->server_sock < 0) { + goto err; + } + + vdev_scsi->loop =3D g_main_loop_new(NULL, FALSE); + if (!vdev_scsi->loop) { + PERR("Error creating glib event loop"); + goto err; + } + + vdev_scsi->fdmap =3D g_tree_new(vus_fdmap_compare); + if (!vdev_scsi->fdmap) { + PERR("Error creating glib tree for fdmap"); + goto err; + } + + return vdev_scsi; + +err: + vdev_scsi_deinit(vdev_scsi); + free(vdev_scsi); + + return NULL; +} + +static int vdev_scsi_add_iscsi_lun(vhost_scsi_dev_t *vdev_scsi, + char *iscsi_uri, uint32_t lun) { + assert(vdev_scsi); + assert(iscsi_uri); + assert(lun < VUS_MAX_LUNS); + + if (vdev_scsi->luns[lun].iscsi_ctx) { + PERR("Lun %d already configured", lun); + return -1; + } + + if (iscsi_add_lun(&vdev_scsi->luns[lun], iscsi_uri) !=3D 0) { + return -1; + } + + return 0; +} + +static int vdev_scsi_run(vhost_scsi_dev_t *vdev_scsi) +{ + int cli_sock; + int ret =3D 0; + + assert(vdev_scsi); + assert(vdev_scsi->server_sock >=3D 0); + assert(vdev_scsi->loop); + + cli_sock =3D accept(vdev_scsi->server_sock, (void *)0, (void *)0); + if (cli_sock < 0) { + perror("accept"); + return -1; + } + + vu_init(&vdev_scsi->vu_dev, + cli_sock, + vus_panic_cb, + vus_add_watch_cb, + vus_del_watch_cb, + &vus_iface); + + if (vus_gsrc_new(vdev_scsi, cli_sock, G_IO_IN, NULL, vus_vhost_cb, + &vdev_scsi->vu_dev)) { + goto fail; + } + + g_main_loop_run(vdev_scsi->loop); + +out: + vu_deinit(&vdev_scsi->vu_dev); + + return ret; + +fail: + ret =3D -1; + goto out; +} + +int main(int argc, char **argv) +{ + vhost_scsi_dev_t *vdev_scsi =3D NULL; + char *unix_fn =3D NULL; + char *iscsi_uri =3D NULL; + int opt, err =3D EXIT_SUCCESS; + + while ((opt =3D getopt(argc, argv, "u:i:")) !=3D -1) { + switch (opt) { + case 'h': + goto help; + case 'u': + unix_fn =3D strdup(optarg); + break; + case 'i': + iscsi_uri =3D strdup(optarg); + break; + default: + goto help; + } + } + if (!unix_fn || !iscsi_uri) { + goto help; + } + + vdev_scsi =3D vdev_scsi_new(unix_fn); + if (!vdev_scsi) { + goto err; + } + vhost_scsi_devs[0] =3D vdev_scsi; + + if (vdev_scsi_add_iscsi_lun(vdev_scsi, iscsi_uri, 0) !=3D 0) { + goto err; + } + + if (vdev_scsi_run(vdev_scsi) !=3D 0) { + goto err; + } + +out: + if (vdev_scsi) { + vdev_scsi_deinit(vdev_scsi); + free(vdev_scsi); + } + if (unix_fn) { + free(unix_fn); + } + if (iscsi_uri) { + free(iscsi_uri); + } + + return err; + +err: + err =3D EXIT_FAILURE; + goto out; + +help: + fprintf(stderr, "Usage: %s [ -u unix_sock_path -i iscsi_uri ] | [ -h ]= \n", + argv[0]); + fprintf(stderr, " -u path to unix socket\n"); + fprintf(stderr, " -i iscsi uri for lun 0\n"); + fprintf(stderr, " -h print help and quit\n"); + + goto err; +} --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322022417780.1402377733186; Thu, 1 Jun 2017 06:00:22 -0700 (PDT) Received: from localhost ([::1]:44231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPi8-0002bK-Ov for importer@patchew.org; Thu, 01 Jun 2017 09:00:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQi-0003pf-3C for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQg-0005lg-Q6 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:20 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQg-0005lJ-H7 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:18 -0400 Received: by mail-wm0-x242.google.com with SMTP id b84so11064453wmh.0 for ; Thu, 01 Jun 2017 05:42:18 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:16 -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=iBJmPStcm6lPB4z9dh0qhtbktFEiddPmcsJOolmhT78=; b=Hlzqeh9pnCCJJUV3wWfC0rQCBi6IMucA5fF6hNkaC7EidjlNMk9weZOA0GqnC1UqZG zbqHWRqYO1HO5odqqkswtqmy7aUhHen7vFbcQff8gsY5jYk0qg+Q5P/CGRS5J5vx2UYe N0yf0o7fsaOq9r8AeKixV+iqszTIy/28Nu+dGZ5hvbApG1cIIZ/6fYHdY1ZMUeqaE5R4 3NVC0Q++txCOaoZ2HQ9h4V3Pp56w6xjJHoImlNw9c2rHnd9CkKFni3uDndHu+lrPB8ng zzqvog1ralPV/45wEBbilsSAlnNCOJz/fLWgGqSOKSsUXeaFLMACxwgsbfghqX4QBWmg cgCQ== 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=iBJmPStcm6lPB4z9dh0qhtbktFEiddPmcsJOolmhT78=; b=CYHfC/G9S6UVttq9pIIujxkBwxxGFvxaAkkt6nCG+mc/VaNIeZ2TO6/qPnedzzj7pQ IN1IGuaXekMKQkwElziXKK/nb1xf1kN7IfjPGsI7sRGMAIeFF/eNMwomJeUrEGm7O/K1 NNe1/0ZBgjif7Np8flhxvRDfK6DH7RDc+ePlay28WSiXa3h0t2PzS6LwPznFYGdv/UCR m2pO7EJy94UiZMQfnKZMOnDWqLVJJJFOrFw2iiremb6JnMXbvgjnPMC32nkoTRTIzVCn a9a8i5XumMpMXNfscyrcrr/ryr+sN5qmtyICtTSIsa7ab/hs1UDYSHOOgfEjZiIl6y1A 6bjQ== X-Gm-Message-State: AODbwcAXo+Was4/xsXOO+/4CiO0EjARMLf89eu2gEarwA6ByY9I2sXLT YBt/UEaIpwCnVfuCmQI= X-Received: by 10.223.170.193 with SMTP id i1mr1117073wrc.143.1496320937152; Thu, 01 Jun 2017 05:42:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:37 +0200 Message-Id: <1496320911-51305-20-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::242 Subject: [Qemu-devel] [PULL 19/33] target/i386: enable A20 automatically in system management mode 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Ignore env->a20_mask when running in system management mode. Reported-by: Anthony Xu Signed-off-by: Paolo Bonzini Message-Id: <1494502528-12670-1-git-send-email-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini --- target/i386/arch_memory_mapping.c | 18 +++++++++-------- target/i386/cpu.h | 9 +++++++++ target/i386/helper.c | 42 +++++++++++++++++++++--------------= ---- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/target/i386/arch_memory_mapping.c b/target/i386/arch_memory_ma= pping.c index 826aee5..647cff2 100644 --- a/target/i386/arch_memory_mapping.c +++ b/target/i386/arch_memory_mapping.c @@ -272,25 +272,27 @@ void x86_cpu_get_memory_mapping(CPUState *cs, MemoryM= appingList *list, { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + int32_t a20_mask; =20 if (!cpu_paging_enabled(cs)) { /* paging is disabled */ return; } =20 + a20_mask =3D x86_get_a20_mask(env); if (env->cr[4] & CR4_PAE_MASK) { #ifdef TARGET_X86_64 if (env->hflags & HF_LMA_MASK) { if (env->cr[4] & CR4_LA57_MASK) { hwaddr pml5e_addr; =20 - pml5e_addr =3D (env->cr[3] & PLM4_ADDR_MASK) & env->a20_ma= sk; - walk_pml5e(list, cs->as, pml5e_addr, env->a20_mask); + pml5e_addr =3D (env->cr[3] & PLM4_ADDR_MASK) & a20_mask; + walk_pml5e(list, cs->as, pml5e_addr, a20_mask); } else { hwaddr pml4e_addr; =20 - pml4e_addr =3D (env->cr[3] & PLM4_ADDR_MASK) & env->a20_ma= sk; - walk_pml4e(list, cs->as, pml4e_addr, env->a20_mask, + pml4e_addr =3D (env->cr[3] & PLM4_ADDR_MASK) & a20_mask; + walk_pml4e(list, cs->as, pml4e_addr, a20_mask, 0xffffULL << 48); } } else @@ -298,16 +300,16 @@ void x86_cpu_get_memory_mapping(CPUState *cs, MemoryM= appingList *list, { hwaddr pdpe_addr; =20 - pdpe_addr =3D (env->cr[3] & ~0x1f) & env->a20_mask; - walk_pdpe2(list, cs->as, pdpe_addr, env->a20_mask); + pdpe_addr =3D (env->cr[3] & ~0x1f) & a20_mask; + walk_pdpe2(list, cs->as, pdpe_addr, a20_mask); } } else { hwaddr pde_addr; bool pse; =20 - pde_addr =3D (env->cr[3] & ~0xfff) & env->a20_mask; + pde_addr =3D (env->cr[3] & ~0xfff) & a20_mask; pse =3D !!(env->cr[4] & CR4_PSE_MASK); - walk_pde2(list, cs->as, pde_addr, env->a20_mask, pse); + walk_pde2(list, cs->as, pde_addr, a20_mask, pse); } } =20 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index c4602ca..32a3a0c 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1624,6 +1624,15 @@ static inline MemTxAttrs cpu_get_mem_attrs(CPUX86Sta= te *env) return ((MemTxAttrs) { .secure =3D (env->hflags & HF_SMM_MASK) !=3D 0 = }); } =20 +static inline int32_t x86_get_a20_mask(CPUX86State *env) +{ + if (env->hflags & HF_SMM_MASK) { + return -1; + } else { + return env->a20_mask; + } +} + /* fpu_helper.c */ void cpu_set_mxcsr(CPUX86State *env, uint32_t val); void cpu_set_fpuc(CPUX86State *env, uint16_t val); diff --git a/target/i386/helper.c b/target/i386/helper.c index f11cac6..6c16e7c 100644 --- a/target/i386/helper.c +++ b/target/i386/helper.c @@ -724,6 +724,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; uint64_t ptep, pte; + int32_t a20_mask; target_ulong pde_addr, pte_addr; int error_code =3D 0; int is_dirty, prot, page_size, is_write, is_user; @@ -739,6 +740,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, #endif is_write =3D is_write1 & 1; =20 + a20_mask =3D x86_get_a20_mask(env); if (!(env->cr[0] & CR0_PG_MASK)) { pte =3D addr; #ifdef TARGET_X86_64 @@ -777,7 +779,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, =20 if (la57) { pml5e_addr =3D ((env->cr[3] & ~0xfff) + - (((addr >> 48) & 0x1ff) << 3)) & env->a20_mask; + (((addr >> 48) & 0x1ff) << 3)) & a20_mask; pml5e =3D x86_ldq_phys(cs, pml5e_addr); if (!(pml5e & PG_PRESENT_MASK)) { goto do_fault; @@ -796,7 +798,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, } =20 pml4e_addr =3D ((pml5e & PG_ADDRESS_MASK) + - (((addr >> 39) & 0x1ff) << 3)) & env->a20_mask; + (((addr >> 39) & 0x1ff) << 3)) & a20_mask; pml4e =3D x86_ldq_phys(cs, pml4e_addr); if (!(pml4e & PG_PRESENT_MASK)) { goto do_fault; @@ -810,7 +812,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, } ptep &=3D pml4e ^ PG_NX_MASK; pdpe_addr =3D ((pml4e & PG_ADDRESS_MASK) + (((addr >> 30) & 0x= 1ff) << 3)) & - env->a20_mask; + a20_mask; pdpe =3D x86_ldq_phys(cs, pdpe_addr); if (!(pdpe & PG_PRESENT_MASK)) { goto do_fault; @@ -835,7 +837,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, { /* XXX: load them when cr3 is loaded ? */ pdpe_addr =3D ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) & - env->a20_mask; + a20_mask; pdpe =3D x86_ldq_phys(cs, pdpe_addr); if (!(pdpe & PG_PRESENT_MASK)) { goto do_fault; @@ -848,7 +850,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, } =20 pde_addr =3D ((pdpe & PG_ADDRESS_MASK) + (((addr >> 21) & 0x1ff) <= < 3)) & - env->a20_mask; + a20_mask; pde =3D x86_ldq_phys(cs, pde_addr); if (!(pde & PG_PRESENT_MASK)) { goto do_fault; @@ -870,7 +872,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, x86_stl_phys_notdirty(cs, pde_addr, pde); } pte_addr =3D ((pde & PG_ADDRESS_MASK) + (((addr >> 12) & 0x1ff) <<= 3)) & - env->a20_mask; + a20_mask; pte =3D x86_ldq_phys(cs, pte_addr); if (!(pte & PG_PRESENT_MASK)) { goto do_fault; @@ -886,7 +888,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, =20 /* page directory entry */ pde_addr =3D ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & - env->a20_mask; + a20_mask; pde =3D x86_ldl_phys(cs, pde_addr); if (!(pde & PG_PRESENT_MASK)) { goto do_fault; @@ -913,7 +915,7 @@ int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, =20 /* page directory entry */ pte_addr =3D ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & - env->a20_mask; + a20_mask; pte =3D x86_ldl_phys(cs, pte_addr); if (!(pte & PG_PRESENT_MASK)) { goto do_fault; @@ -992,7 +994,7 @@ do_check_protect_pse36: } =20 do_mapping: - pte =3D pte & env->a20_mask; + pte =3D pte & a20_mask; =20 /* align to page_size */ pte &=3D PG_ADDRESS_MASK & ~(page_size - 1); @@ -1039,11 +1041,13 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, va= ddr addr) CPUX86State *env =3D &cpu->env; target_ulong pde_addr, pte_addr; uint64_t pte; + int32_t a20_mask; uint32_t page_offset; int page_size; =20 + a20_mask =3D x86_get_a20_mask(env); if (!(env->cr[0] & CR0_PG_MASK)) { - pte =3D addr & env->a20_mask; + pte =3D addr & a20_mask; page_size =3D 4096; } else if (env->cr[4] & CR4_PAE_MASK) { target_ulong pdpe_addr; @@ -1064,7 +1068,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vadd= r addr) =20 if (la57) { pml5e_addr =3D ((env->cr[3] & ~0xfff) + - (((addr >> 48) & 0x1ff) << 3)) & env->a20_mask; + (((addr >> 48) & 0x1ff) << 3)) & a20_mask; pml5e =3D x86_ldq_phys(cs, pml5e_addr); if (!(pml5e & PG_PRESENT_MASK)) { return -1; @@ -1074,13 +1078,13 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, va= ddr addr) } =20 pml4e_addr =3D ((pml5e & PG_ADDRESS_MASK) + - (((addr >> 39) & 0x1ff) << 3)) & env->a20_mask; + (((addr >> 39) & 0x1ff) << 3)) & a20_mask; pml4e =3D x86_ldq_phys(cs, pml4e_addr); if (!(pml4e & PG_PRESENT_MASK)) { return -1; } pdpe_addr =3D ((pml4e & PG_ADDRESS_MASK) + - (((addr >> 30) & 0x1ff) << 3)) & env->a20_mask; + (((addr >> 30) & 0x1ff) << 3)) & a20_mask; pdpe =3D x86_ldq_phys(cs, pdpe_addr); if (!(pdpe & PG_PRESENT_MASK)) { return -1; @@ -1095,14 +1099,14 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, va= ddr addr) #endif { pdpe_addr =3D ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) & - env->a20_mask; + a20_mask; pdpe =3D x86_ldq_phys(cs, pdpe_addr); if (!(pdpe & PG_PRESENT_MASK)) return -1; } =20 pde_addr =3D ((pdpe & PG_ADDRESS_MASK) + - (((addr >> 21) & 0x1ff) << 3)) & env->a20_mask; + (((addr >> 21) & 0x1ff) << 3)) & a20_mask; pde =3D x86_ldq_phys(cs, pde_addr); if (!(pde & PG_PRESENT_MASK)) { return -1; @@ -1114,7 +1118,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vadd= r addr) } else { /* 4 KB page */ pte_addr =3D ((pde & PG_ADDRESS_MASK) + - (((addr >> 12) & 0x1ff) << 3)) & env->a20_mask; + (((addr >> 12) & 0x1ff) << 3)) & a20_mask; page_size =3D 4096; pte =3D x86_ldq_phys(cs, pte_addr); } @@ -1125,7 +1129,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vadd= r addr) uint32_t pde; =20 /* page directory entry */ - pde_addr =3D ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & en= v->a20_mask; + pde_addr =3D ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & a2= 0_mask; pde =3D x86_ldl_phys(cs, pde_addr); if (!(pde & PG_PRESENT_MASK)) return -1; @@ -1134,14 +1138,14 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, va= ddr addr) page_size =3D 4096 * 1024; } else { /* page directory entry */ - pte_addr =3D ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->= a20_mask; + pte_addr =3D ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & a20_m= ask; pte =3D x86_ldl_phys(cs, pte_addr); if (!(pte & PG_PRESENT_MASK)) { return -1; } page_size =3D 4096; } - pte =3D pte & env->a20_mask; + pte =3D pte & a20_mask; } =20 #ifdef TARGET_X86_64 --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322195582228.96739023282362; Thu, 1 Jun 2017 06:03:15 -0700 (PDT) Received: from localhost ([::1]:44249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPku-0004ub-1P for importer@patchew.org; Thu, 01 Jun 2017 09:03:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQm-0003w1-VZ for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQi-0005lv-0V for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:25 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:36296) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQh-0005lk-Mj for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:19 -0400 Received: by mail-wm0-x242.google.com with SMTP id k15so11050304wmh.3 for ; Thu, 01 Jun 2017 05:42:19 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:17 -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=Pnv+zsxCNBeXYDXyLwGkmxfbK/Imy/bNzOzuuv57NLQ=; b=UVGgoKNPwQaFdTLp/oNUel5Rp3ndpZ3w0qMXqudbJSYt4V5fWwqKI4DBJAK+cZ6G5Y QBo4MfHcuSM5SQRA+kmZb4IE8tJ7eWcvWrn0p+23La8sC2us3JPzZOeGe7GJDL+HHutw 5RjS4yM4XzLdsZzZWBg2JH7f0qDIrxQv/EpB1Wh6LOYP5DWzatHy7ICtimY5ndbY2UuQ OyuRu/tcjzHtE74yVYNIuRPnHJF9A3nKtex4KvavvxYtk596hGk7SEOf3ybGOydUpYTT g8NHRLPzEzO5z0iGoOzE+KDUWB1sjvgHNxLplhfsjTKzmThC7IwcLpNfW+slGpEv5N3T PDZQ== 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=Pnv+zsxCNBeXYDXyLwGkmxfbK/Imy/bNzOzuuv57NLQ=; b=Qu7pmDD31eZYPzkJH7WY4Pd614pu1kc+aal9LPRBPuzDyV+BTJKdkBtL7MvQPT7Wcp b1aeX3Pcxt87fJyULp9k7SIviTeLMaDKYFzMoN33omKLQ3tkwj7E/ykvt+LWe3aIvyYJ +Gf4k17PgHfg97D18YeUbMO3lnhRvvygiPUxlg05a+v2t9HDj7azAa+z43pwcQk2ZSvR Ilqe4OxgJJ/CaSxL+fH55e9xk+DxqQDDYFV75h0MMlg/6DGoAXl1/cNeBXdX8cZRjqjw 1nu14SOoAJiQ5ORzm1/Pw3kmzbzHrENJL8hM/TfL9bWKMLgxZnBj4jN2NKTAFVPm8uxv HKmQ== X-Gm-Message-State: AODbwcDFZh3ulI13MsqoDDYt6E8Dq77pA3uaAK762tjNsQydZHMoIcHM wsOTVEAgVjWtqcacJjM= X-Received: by 10.28.38.68 with SMTP id m65mr1704308wmm.25.1496320938211; Thu, 01 Jun 2017 05:42:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:38 +0200 Message-Id: <1496320911-51305-21-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::242 Subject: [Qemu-devel] [PULL 20/33] target/i386: use multiple CPU AddressSpaces 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This speeds up SMM switches. Later on it may remove the need to take the BQL, and it may also allow to reuse code between TCG and KVM. Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 15 +++++++++----- target/i386/cpu.h | 11 +++++++++- target/i386/helper.c | 54 ++++++++++++++++++++++++--------------------= ---- target/i386/machine.c | 4 ---- target/i386/smm_helper.c | 18 ---------------- 5 files changed, 47 insertions(+), 55 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a41d595..a638832 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3239,7 +3239,7 @@ static void x86_cpu_machine_done(Notifier *n, void *u= nused) cpu->smram =3D g_new(MemoryRegion, 1); memory_region_init_alias(cpu->smram, OBJECT(cpu), "smram", smram, 0, 1ull << 32); - memory_region_set_enabled(cpu->smram, false); + memory_region_set_enabled(cpu->smram, true); memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->smra= m, 1); } } @@ -3619,7 +3619,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) =20 #ifndef CONFIG_USER_ONLY if (tcg_enabled()) { - AddressSpace *newas =3D g_new(AddressSpace, 1); + AddressSpace *as_normal =3D address_space_init_shareable(cs->memor= y, + "cpu-memory= "); + AddressSpace *as_smm =3D g_new(AddressSpace, 1); =20 cpu->cpu_as_mem =3D g_new(MemoryRegion, 1); cpu->cpu_as_root =3D g_new(MemoryRegion, 1); @@ -3635,9 +3637,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) get_system_memory(), 0, ~0ull); memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->cpu_= as_mem, 0); memory_region_set_enabled(cpu->cpu_as_mem, true); - address_space_init(newas, cpu->cpu_as_root, "CPU"); - cs->num_ases =3D 1; - cpu_address_space_init(cs, newas, 0); + address_space_init(as_smm, cpu->cpu_as_root, "CPU"); + + cs->num_ases =3D 2; + cpu_address_space_init(cs, as_normal, 0); + cpu_address_space_init(cs, as_smm, 1); =20 /* ... SMRAM with higher priority, linked from /machine/smram. */ cpu->machine_done.notify =3D x86_cpu_machine_done; @@ -4053,6 +4057,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc= , void *data) #ifdef CONFIG_USER_ONLY cc->handle_mmu_fault =3D x86_cpu_handle_mmu_fault; #else + cc->asidx_from_attrs =3D x86_asidx_from_attrs; cc->get_memory_mapping =3D x86_cpu_get_memory_mapping; cc->get_phys_page_debug =3D x86_cpu_get_phys_page_debug; cc->write_elf64_note =3D x86_cpu_write_elf64_note; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 32a3a0c..c2e081c 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1450,6 +1450,16 @@ int x86_cpu_handle_mmu_fault(CPUState *cpu, vaddr ad= dr, void x86_cpu_set_a20(X86CPU *cpu, int a20_state); =20 #ifndef CONFIG_USER_ONLY +static inline int x86_asidx_from_attrs(CPUState *cs, MemTxAttrs attrs) +{ + return !!attrs.secure; +} + +static inline AddressSpace *cpu_addressspace(CPUState *cs, MemTxAttrs attr= s) +{ + return cpu_get_address_space(cs, cpu_asidx_from_attrs(cs, attrs)); +} + uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr); uint32_t x86_lduw_phys(CPUState *cs, hwaddr addr); uint32_t x86_ldl_phys(CPUState *cs, hwaddr addr); @@ -1652,7 +1662,6 @@ void do_interrupt_x86_hardirq(CPUX86State *env, int i= ntno, int is_hw); =20 /* smm_helper.c */ void do_smm_enter(X86CPU *cpu); -void cpu_smm_update(X86CPU *cpu); =20 /* apic.c */ void cpu_report_tpr_access(CPUX86State *env, TPRAccess access); diff --git a/target/i386/helper.c b/target/i386/helper.c index 6c16e7c..d0daa1f 100644 --- a/target/i386/helper.c +++ b/target/i386/helper.c @@ -1403,89 +1403,89 @@ uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - return address_space_ldub(cs->as, addr, - cpu_get_mem_attrs(env), - NULL); + return address_space_ldub(as, addr, attrs, NULL); } =20 uint32_t x86_lduw_phys(CPUState *cs, hwaddr addr) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - return address_space_lduw(cs->as, addr, - cpu_get_mem_attrs(env), - NULL); + return address_space_lduw(as, addr, attrs, NULL); } =20 uint32_t x86_ldl_phys(CPUState *cs, hwaddr addr) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - return address_space_ldl(cs->as, addr, - cpu_get_mem_attrs(env), - NULL); + return address_space_ldl(as, addr, attrs, NULL); } =20 uint64_t x86_ldq_phys(CPUState *cs, hwaddr addr) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - return address_space_ldq(cs->as, addr, - cpu_get_mem_attrs(env), - NULL); + return address_space_ldq(as, addr, attrs, NULL); } =20 void x86_stb_phys(CPUState *cs, hwaddr addr, uint8_t val) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - address_space_stb(cs->as, addr, val, - cpu_get_mem_attrs(env), - NULL); + address_space_stb(as, addr, val, attrs, NULL); } =20 void x86_stl_phys_notdirty(CPUState *cs, hwaddr addr, uint32_t val) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - address_space_stl_notdirty(cs->as, addr, val, - cpu_get_mem_attrs(env), - NULL); + address_space_stl_notdirty(as, addr, val, attrs, NULL); } =20 void x86_stw_phys(CPUState *cs, hwaddr addr, uint32_t val) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - address_space_stw(cs->as, addr, val, - cpu_get_mem_attrs(env), - NULL); + address_space_stw(as, addr, val, attrs, NULL); } =20 void x86_stl_phys(CPUState *cs, hwaddr addr, uint32_t val) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - address_space_stl(cs->as, addr, val, - cpu_get_mem_attrs(env), - NULL); + address_space_stl(as, addr, val, attrs, NULL); } =20 void x86_stq_phys(CPUState *cs, hwaddr addr, uint64_t val) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; + MemTxAttrs attrs =3D cpu_get_mem_attrs(env); + AddressSpace *as =3D cpu_addressspace(cs, attrs); =20 - address_space_stq(cs->as, addr, val, - cpu_get_mem_attrs(env), - NULL); + address_space_stq(as, addr, val, attrs, NULL); } #endif diff --git a/target/i386/machine.c b/target/i386/machine.c index 3cb2729..8c7a822 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -274,10 +274,6 @@ static int cpu_post_load(void *opaque, int version_id) cpu_x86_update_dr7(env, dr7); } tlb_flush(cs); - - if (tcg_enabled()) { - cpu_smm_update(cpu); - } return 0; } =20 diff --git a/target/i386/smm_helper.c b/target/i386/smm_helper.c index f051a77..90621e5 100644 --- a/target/i386/smm_helper.c +++ b/target/i386/smm_helper.c @@ -43,19 +43,6 @@ void helper_rsm(CPUX86State *env) #define SMM_REVISION_ID 0x00020000 #endif =20 -/* Called with iothread lock taken */ -void cpu_smm_update(X86CPU *cpu) -{ - CPUX86State *env =3D &cpu->env; - bool smm_enabled =3D (env->hflags & HF_SMM_MASK); - - g_assert(qemu_mutex_iothread_locked()); - - if (cpu->smram) { - memory_region_set_enabled(cpu->smram, smm_enabled); - } -} - void do_smm_enter(X86CPU *cpu) { CPUX86State *env =3D &cpu->env; @@ -73,7 +60,6 @@ void do_smm_enter(X86CPU *cpu) } else { env->hflags2 |=3D HF2_NMI_MASK; } - cpu_smm_update(cpu); =20 sm_state =3D env->smbase + 0x8000; =20 @@ -338,10 +324,6 @@ void helper_rsm(CPUX86State *env) env->hflags2 &=3D ~HF2_SMM_INSIDE_NMI_MASK; env->hflags &=3D ~HF_SMM_MASK; =20 - qemu_mutex_lock_iothread(); - cpu_smm_update(cpu); - qemu_mutex_unlock_iothread(); - qemu_log_mask(CPU_LOG_INT, "SMM: after RSM\n"); log_cpu_state_mask(CPU_LOG_INT, CPU(cpu), CPU_DUMP_CCOP); } --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321729965775.3011115168747; Thu, 1 Jun 2017 05:55:29 -0700 (PDT) Received: from localhost ([::1]:44207 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPdQ-0006WJ-81 for importer@patchew.org; Thu, 01 Jun 2017 08:55:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQm-0003w3-Vn for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQi-0005mD-JA for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:25 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33602) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQi-0005lm-CQ for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:20 -0400 Received: by mail-wm0-x243.google.com with SMTP id b84so11064600wmh.0 for ; Thu, 01 Jun 2017 05:42:20 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:18 -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=ke4JE9QId6dMx4LetYJCN0H44m5/5iGpHOaPnzjuE1M=; b=m3KTEiopWMOo4Au32UonHwUd00f5MEQ9dRSJSIN12i4AVjKZ3Rlv6xAi+Nm+DWOI09 qsXUKvesxxvNqn65cZWQqQsdSzyemmuREb6qdo2baQysdZcP7G2ZOgjGUyf0oqEIqIBu paV03m+sqxELky6WaVcVFHON6O5Io4VVNRsayTqwJMYTq2Ix/HGN13gcjsuTK1zA0nZ0 4+GZ3SGK5xU872IAwdjQtbA4cYeYWlrs3UoAA1crnOPslJNzuyEyZaix1V0AZ3XAzJmm C5Al16+VfIl4BlQR4TxYi54dG1kqb/89xErDGjYmBL7DNsnN/YlH8CYJmxpIMGxcKAGh M+qQ== 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=ke4JE9QId6dMx4LetYJCN0H44m5/5iGpHOaPnzjuE1M=; b=siWSCe2E6N72RzgdddlJR/fZ62Tp5K18+26q8qGqVpjh0y1xVMkbvwvtDZcVIIt69g wcNN/5KcpqknFUnIh6bAsIWllRNrxN/PVo54xNruqs/LGcIwYelcI0ojhqE3NXBT+r3w t1Mw6h4EIw9cKuMgw9v5sn0jSZLoFx9R2ADPg436sW1IlraJgWqy+8vO4rpmtqhtMqoo 1X9Mcl/vuYfxAwIB9WVu5b/s0Y+gAwfxX8SKJd/NSXVdG029yCVfmnPxMDXBXWdKK6Mp yMlELpum36AmUqgqQYrmBKYAqDHQujlvvPuDvkwb2mn0AcA/QUY646r+/rdBpLds/t9A A37Q== X-Gm-Message-State: AODbwcCB9l8l6qBAde67TLx+odlbSCPMoCJJCSECcG2RMX5bM8+A5G9J fQqk3cs1yXZDLI8BZR4= X-Received: by 10.223.134.150 with SMTP id 22mr1106468wrx.121.1496320939191; Thu, 01 Jun 2017 05:42:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:39 +0200 Message-Id: <1496320911-51305-22-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::243 Subject: [Qemu-devel] [PULL 21/33] i386: fix read/write cr with icount option 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: Mihail Abakumov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Mihail Abakumov Running Windows with icount causes a crash in instruction of write cr. This patch fixes it. Reading and writing cr cause an icount read because there are called cpu_get_apic_tpr and cpu_set_apic_tpr functions. So, there is need gen_io_start()/gen_io_end() calls. Signed-off-by: Mihail Abakumov Message-Id: Signed-off-by: Paolo Bonzini --- target/i386/translate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/i386/translate.c b/target/i386/translate.c index 1d1372f..39912f3 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -7914,14 +7914,26 @@ static target_ulong disas_insn(CPUX86State *env, Di= sasContext *s, gen_update_cc_op(s); gen_jmp_im(pc_start - s->cs_base); if (b & 2) { + if (s->tb->cflags & CF_USE_ICOUNT) { + gen_io_start(); + } gen_op_mov_v_reg(ot, cpu_T0, rm); gen_helper_write_crN(cpu_env, tcg_const_i32(reg), cpu_T0); + if (s->tb->cflags & CF_USE_ICOUNT) { + gen_io_end(); + } gen_jmp_im(s->pc - s->cs_base); gen_eob(s); } else { + if (s->tb->cflags & CF_USE_ICOUNT) { + gen_io_start(); + } gen_helper_read_crN(cpu_T0, cpu_env, tcg_const_i32(reg= )); gen_op_mov_reg_v(ot, rm, cpu_T0); + if (s->tb->cflags & CF_USE_ICOUNT) { + gen_io_end(); + } } break; default: --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321823551142.3873959608917; Thu, 1 Jun 2017 05:57:03 -0700 (PDT) Received: from localhost ([::1]:44218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPew-0007ta-4T for importer@patchew.org; Thu, 01 Jun 2017 08:57:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQm-0003w4-Vu for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQj-0005mc-TB for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:25 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34150) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQj-0005mM-JZ for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:21 -0400 Received: by mail-wm0-x242.google.com with SMTP id d127so11021262wmf.1 for ; Thu, 01 Jun 2017 05:42:21 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:19 -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=x3pt/O3UyPGugpdUo3VrpBFpwHrysNPNCrwmQf1nYEU=; b=XROjmyufdlP2bLVw1RHIvjo8nzmLwsIQcO/CUy1VX6aD5I0TEnl1eOluEbRoxtNKn5 g0jy+ljgma51vsCTKVuPPeQXjOwjk83oNffyN0F2v80KwMvHiALchwtRjRkMPgO6Ye66 JT0Fr3dbv0WSUIOa+7yi42FNbjVC5+bps6rYH5s7M79XhWDGO1c059YHCFqdmivA5tfX fNbiYoz2pr/h8GCLa/j0GBgT7gXtbWIqkkOzV2AOzSsfh/Fxu4V12tf1zA3NTy0ZEYNN VYnGjRFnsIh2qJM/QAB2S58NkvwIRxdg1rBuZ6nv8lHbhXiAu/PrE0/zWbSNHHjvcLI6 vCIg== 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=x3pt/O3UyPGugpdUo3VrpBFpwHrysNPNCrwmQf1nYEU=; b=bJ7r3HDu3w7fUC1CeJhNhDjadsqH+PLGJit1W+PzTPVMO4s/mE0T1b/X/zr9rUpOiP 9Ye50ZRmwVGX8D5GqioPWUbX5WMktdWc5KrHbFXmzanWt1IRgnwYc1+wLG844kpQf5j2 1gy9NrHUJHql5NkQvoBYEGj9rBWEGhfWt4lMOAu8Gh4lGWG2EW2ffW3lEfjWk52qjNUF FZiD6KyMWMdMAaXtu4856ScJzI/g5hEe4S/X6kx9ue2LQUblbahVeMWLf4+kITVcGxwi rkX7Tzpv7J9PvpbyS7oza10+Z9gWnFGRRvmnCYEeqcC3u9Ey+KA0/BWd9AK8V0CHBANu CKdw== X-Gm-Message-State: AODbwcDZ7Fb5LAa1tKvIbmGyY9GiosBvH5VIBjV04iDuXGilp0hG72Y8 PUEFVpbxL//Ugsf/j1Q= X-Received: by 10.223.169.171 with SMTP id b40mr1172301wrd.147.1496320940348; Thu, 01 Jun 2017 05:42:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:40 +0200 Message-Id: <1496320911-51305-23-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::242 Subject: [Qemu-devel] [PULL 22/33] sockets: improve error reporting if UNIX socket path is too long 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Daniel P. Berrange" The 'struct sockaddr_un' only allows 108 bytes for the socket path. If the user supplies a path, QEMU uses snprintf() to silently truncate it when too long. This is undesirable because the user will then be unable to connect to the path they asked for. If the user doesn't supply a path, QEMU builds one based on TMPDIR, but if that leads to an overlong path, it mistakenly uses error_setg_errno() with a stale errno value, because snprintf() does not set errno on truncation. In solving this the code needed some refactoring to ensure we don't pass 'un.sun_path' directly to any APIs which expect NUL-terminated strings, because the path is not required to be terminated. Signed-off-by: Daniel P. Berrange Message-Id: <20170525155300.22743-1-berrange@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- util/qemu-sockets.c | 68 ++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index d8183f7..dfaf4e1 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -845,6 +845,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, { struct sockaddr_un un; int sock, fd; + char *pathbuf =3D NULL; + const char *path; =20 sock =3D qemu_socket(PF_UNIX, SOCK_STREAM, 0); if (sock < 0) { @@ -852,20 +854,22 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, return -1; } =20 - memset(&un, 0, sizeof(un)); - un.sun_family =3D AF_UNIX; - if (saddr->path && strlen(saddr->path)) { - snprintf(un.sun_path, sizeof(un.sun_path), "%s", saddr->path); + if (saddr->path && saddr->path[0]) { + path =3D saddr->path; } else { const char *tmpdir =3D getenv("TMPDIR"); tmpdir =3D tmpdir ? tmpdir : "/tmp"; - if (snprintf(un.sun_path, sizeof(un.sun_path), "%s/qemu-socket-XXX= XXX", - tmpdir) >=3D sizeof(un.sun_path)) { - error_setg_errno(errp, errno, - "TMPDIR environment variable (%s) too large",= tmpdir); - goto err; - } + path =3D pathbuf =3D g_strdup_printf("%s/qemu-socket-XXXXXX", tmpd= ir); + } =20 + if (strlen(path) > sizeof(un.sun_path)) { + error_setg(errp, "UNIX socket path '%s' is too long", path); + error_append_hint(errp, "Path must be less than %zu bytes\n", + sizeof(un.sun_path)); + goto err; + } + + if (pathbuf !=3D NULL) { /* * This dummy fd usage silences the mktemp() unsecure warning. * Using mkstemp() doesn't make things more secure here @@ -873,24 +877,25 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, * to unlink first and thus re-open the race window. The * worst case possible is bind() failing, i.e. a DoS attack. */ - fd =3D mkstemp(un.sun_path); + fd =3D mkstemp(pathbuf); if (fd < 0) { error_setg_errno(errp, errno, - "Failed to make a temporary socket name in %s= ", tmpdir); + "Failed to make a temporary socket %s", pathb= uf); goto err; } close(fd); - if (update_addr) { - g_free(saddr->path); - saddr->path =3D g_strdup(un.sun_path); - } } =20 - if (unlink(un.sun_path) < 0 && errno !=3D ENOENT) { + if (unlink(path) < 0 && errno !=3D ENOENT) { error_setg_errno(errp, errno, - "Failed to unlink socket %s", un.sun_path); + "Failed to unlink socket %s", path); goto err; } + + memset(&un, 0, sizeof(un)); + un.sun_family =3D AF_UNIX; + strncpy(un.sun_path, path, sizeof(un.sun_path)); + if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) { error_setg_errno(errp, errno, "Failed to bind socket to %s", un.su= n_path); goto err; @@ -900,9 +905,16 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, goto err; } =20 + if (update_addr && pathbuf) { + g_free(saddr->path); + saddr->path =3D pathbuf; + } else { + g_free(pathbuf); + } return sock; =20 err: + g_free(pathbuf); closesocket(sock); return -1; } @@ -932,9 +944,16 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, qemu_set_nonblock(sock); } =20 + if (strlen(saddr->path) > sizeof(un.sun_path)) { + error_setg(errp, "UNIX socket path '%s' is too long", saddr->path); + error_append_hint(errp, "Path must be less than %zu bytes\n", + sizeof(un.sun_path)); + goto err; + } + memset(&un, 0, sizeof(un)); un.sun_family =3D AF_UNIX; - snprintf(un.sun_path, sizeof(un.sun_path), "%s", saddr->path); + strncpy(un.sun_path, saddr->path, sizeof(un.sun_path)); =20 /* connect to peer */ do { @@ -956,13 +975,18 @@ static int unix_connect_saddr(UnixSocketAddress *sadd= r, } =20 if (rc < 0) { - error_setg_errno(errp, -rc, "Failed to connect socket"); - close(sock); - sock =3D -1; + error_setg_errno(errp, -rc, "Failed to connect socket %s", + saddr->path); + goto err; } =20 g_free(connect_state); return sock; + + err: + close(sock); + g_free(connect_state); + return -1; } =20 #else --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322225390518.9739395143192; Thu, 1 Jun 2017 06:03:45 -0700 (PDT) Received: from localhost ([::1]:44251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPlM-0005bi-Ox for importer@patchew.org; Thu, 01 Jun 2017 09:03:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQm-0003w2-VY for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQk-0005mo-NR for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:25 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:36301) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQk-0005mg-GL for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:22 -0400 Received: by mail-wm0-x242.google.com with SMTP id k15so11050633wmh.3 for ; Thu, 01 Jun 2017 05:42:22 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=xFMxbfoFu4v+bTbRaECYUQ+rvE6hhcC7AbsqIutc7Is=; b=g1KFJnwOPqdLXwSwoYAb2IXjw8MjGzA3n38uC2riAw0QujT2ygCtxNmk5m5nxDnl4R pc/2WEkuyIvEF08j0R6/3+Bzuyzhar12/BkNQTmeBCav6wB40NjLdEGuXhMyAKAYhxBk 5IOJSKaog0TqvWslTKrFtpurkMspBduCTXP2NsEhEfinyLDrOWOcG7Y5BMIqHYrCz732 Bvxch/J47+xVVIta4BMLdNtRC33dwOJKHUFDKDX+BW19/ANZvTCZauYx/GRX77xuDy+F AZN0wf82apkwc03VFZBmyuMjmnDAZ+cEqOIKSLKkdJg4M4+Gwb24y7S4tfwq9EA+OY2J MUzg== 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=xFMxbfoFu4v+bTbRaECYUQ+rvE6hhcC7AbsqIutc7Is=; b=Rr0eluuNR4Evr5W4bjUsjUx5pLVIUNxln2/ODmakNzXm0LlRQJWcuArPIfoLYSDpI1 XBBUnS0KcCzO/9Xxwc/EISTns9EY8LcIQzEL8BLCiB0MNu3CSgKVKS/aXNxOlbiAKjwc /GG7hJlpK6gqRAmVqfSOFLVusETqB+IXhjn+WPBeKjKMAW2fi/5IKHIulIPjsv0Kqe4J ZX6n0yXN5OqxKAvEOtZbY8IiWpfQrloMGlj4tOlduAxoMmEz9fdhz88MZIKv054lX7VM BC8FORb+FjCXU+CiMhWgeMZhSbPOGS3NXUAe726vHj7m8EANaNeFWf5Jhgfsz/rUF7C/ UhVQ== X-Gm-Message-State: AODbwcBOcI2Lo6UHen+UnkywRKnPcFRK2BD5HU6Zu940PUEsm1qra/vs NPisg+LyxFe+KoKqLK0= X-Received: by 10.223.161.194 with SMTP id v2mr1333055wrv.132.1496320941314; Thu, 01 Jun 2017 05:42:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:41 +0200 Message-Id: <1496320911-51305-24-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::242 Subject: [Qemu-devel] [PULL 23/33] exec: fix address_space_get_iotlb_entry page mask 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: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu The IOTLB that it returned didn't guarantee that page_mask is indeed a so-called page mask. That won't affect current usage since now only vhost is using it (vhost API allows arbitary IOTLB range). However we have IOTLB scemantic and we should best follow it. This patch fixes this issue to make sure the page_mask is always a valid page mask. Fixes: a764040 ("exec: abstract address_space_do_translate()") Signed-off-by: Peter Xu Message-Id: <1496212378-22605-1-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- exec.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/exec.c b/exec.c index 29633cd..22b8f0c 100644 --- a/exec.c +++ b/exec.c @@ -528,16 +528,14 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSp= ace *as, hwaddr addr, section.offset_within_region; =20 if (plen =3D=3D (hwaddr)-1) { - /* - * We use default page size here. Logically it only happens - * for identity mappings. - */ - plen =3D TARGET_PAGE_SIZE; + /* If not specified during translation, use default mask */ + plen =3D TARGET_PAGE_MASK; + } else { + /* Make it a valid page mask */ + assert(plen); + plen =3D pow2floor(plen) - 1; } =20 - /* Convert to address mask */ - plen -=3D 1; - return (IOMMUTLBEntry) { .target_as =3D section.address_space, .iova =3D addr & ~plen, --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321672706901.9021422834575; Thu, 1 Jun 2017 05:54:32 -0700 (PDT) Received: from localhost ([::1]:44205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPcV-0005lC-4f for importer@patchew.org; Thu, 01 Jun 2017 08:54:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQn-0003wU-7B for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQl-0005n3-WC for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:25 -0400 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]:38412) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQl-0005mu-PL for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:23 -0400 Received: by mail-wm0-x229.google.com with SMTP id n195so30614258wmg.1 for ; Thu, 01 Jun 2017 05:42:23 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=u8Y1qM4C4qATHmb3Wzn7G09+j/M+ZO+S8HgqzlPe4CE=; b=Nf2czF7b2OXGDDLRl5N0BzWvLabcwnpPDwRnFOPZIh+GJCn+FMRrkYs17+TcBtZ++p Decn8dFapkImiDn1g6dLPFyIzn8l9UkDwkvJOWe6xDNvd7XCnLK6b3Cd/hM0U4T7494G 4ZQlWmP6UeHp0+kSZVQ5S4VqxV8yUrbWMud+j9PNdDOJB5Aw7x6pTpM/cjiCYGrV+I1D oW94RFLL554jhTUUp/Y/cVeKoTaA0eKBGz+i6jNd5CCQU7ONEnsC8AH4f//NtNtpHvLa CZZMBtx7FXjQF657IpOu7lLURE25v+m2IHkP5wmYw35mAJjsw+vQ/vq9++2xlpTjQ7x/ sI2Q== 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=u8Y1qM4C4qATHmb3Wzn7G09+j/M+ZO+S8HgqzlPe4CE=; b=Dmm/xwtUijJf3InmfvZ3UGEbfvxnnL++zVzwzW5dv3ywLbXDEgxPhkVBuYS3jBq1jL v2py0EnjK1B2JkWLaQNd6y0ngIl5NliHJ9wYqDy/hdJQteYeqtt84a03hIwY8O0werb7 IRsO5qhHOBrh8w/mGAxFpPXWa+PvyLJkkLxHQoHcQylilKmCFiq6kGTKqLmOApuOXhIC zhWpZyNe6+Te6Ve04Rq8842GbcOfQxvz2WZW4bkB154LSjAkJ1p0sbO5fX3I5bAPjQfC A6eqEURYAVLvecU/po4L24DBi5aCp9B1MpqBShUZtDdkxFaJECXNXSdWL0DfKD1xx15e AOpA== X-Gm-Message-State: AODbwcCPtLBIdtx0bk2OuRyiwRoh3/b/GUJKPvnITE8RHKOnGx3+ZNLJ 3S+3h29pXE9gsltHAds= X-Received: by 10.223.145.195 with SMTP id 61mr1275771wri.43.1496320942420; Thu, 01 Jun 2017 05:42:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:42 +0200 Message-Id: <1496320911-51305-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::229 Subject: [Qemu-devel] [PULL 24/33] nbd: Fully initialize client in case of failed negotiation 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake If a non-NBD client connects to qemu-nbd, we would end up with a SIGSEGV in nbd_cilent_put() because we were trying to unregister the client's association to the export, even though we skipped inserting the client into that list. Easy trigger in two terminals: $ qemu-nbd -p 30001 --format=3Draw file $ nmap 127.0.0.1 -p 30001 nmap claims that it thinks it connected to a pago-services1 server (which probably means nmap could be updated to learn the NBD protocol and give a more accurate diagnosis of the open port - but that's not our problem), then terminates immediately, so our call to nbd_negotiate() fails. The fix is to reorder nbd_co_client_start() to ensure that all initialization occurs before we ever try talking to a client in nbd_negotiate(), so that the teardown sequence on negotiation failure doesn't fault while dereferencing a half-initialized object. While debugging this, I also noticed that nbd_update_server_watch() called by nbd_client_closed() was still adding a channel to accept the next client, even when the state was no longer RUNNING. That is fixed by making nbd_can_accept() pay attention to the current state. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1451614 Signed-off-by: Eric Blake Message-Id: <20170527030421.28366-1-eblake@redhat.com> Signed-off-by: Paolo Bonzini --- nbd/server.c | 8 +++----- qemu-nbd.c | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index ee59e5d..49b55f6 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1358,16 +1358,14 @@ static coroutine_fn void nbd_co_client_start(void *= opaque) =20 if (exp) { nbd_export_get(exp); + QTAILQ_INSERT_TAIL(&exp->clients, client, next); } + qemu_co_mutex_init(&client->send_lock); + if (nbd_negotiate(data)) { client_close(client); goto out; } - qemu_co_mutex_init(&client->send_lock); - - if (exp) { - QTAILQ_INSERT_TAIL(&exp->clients, client, next); - } =20 nbd_client_receive_next_request(client); =20 diff --git a/qemu-nbd.c b/qemu-nbd.c index f60842f..651f85e 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -325,7 +325,7 @@ out: =20 static int nbd_can_accept(void) { - return nb_fds < shared; + return state =3D=3D RUNNING && nb_fds < shared; } =20 static void nbd_export_closed(NBDExport *exp) --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321968968586.0914684612192; Thu, 1 Jun 2017 05:59:28 -0700 (PDT) Received: from localhost ([::1]:44228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPhH-0001rS-7J for importer@patchew.org; Thu, 01 Jun 2017 08:59:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQo-0003xg-9a for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQm-0005nM-VF for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:26 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34154) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQm-0005n7-LK for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:24 -0400 Received: by mail-wm0-x242.google.com with SMTP id d127so11021552wmf.1 for ; Thu, 01 Jun 2017 05:42:24 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=oR9Ls6km9mJdGwOF7ozF2hyH6IsyL/h/ZfKPoM83AaI=; b=R018E7wq8MGmzvpYzR/qq+unGKilIiCSvJI6iuzfhShqpwJDYLbZ9uNeje7oa1l3+s WKfnGGc+THl9kmRUZuezUu0TW1shxW0S4LypiALjO7mJNONdVaAmlbjLWsyigTAfM9k6 jLAV5O6SA82S+kyRRSaX58ttwWqTS00jZGbG2JQ8VK+EVWEFxc0DEowKzu57K5dH0uNM 5hADrVhOIzXnAo8qr+9bdorAj8U8w1qjeffkd6pdIgU0hSXblLNrWrSGwtmxNDDUj9xa EUS1aWCCONx/7Q5UF2nbIXzeabXCM8K3+aO5HtAKsP0fhxfrvQAVKgqUF4POczoO7keB 2aVw== 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=oR9Ls6km9mJdGwOF7ozF2hyH6IsyL/h/ZfKPoM83AaI=; b=N8S1LnWuDCyiWkHNzb4Hga4QAxFovllwkkP+43TT1KEdO237E/adaN+lis+dKxd6mW k2rBnD2xEwesTwYvv6fpO8/sAM5AwQkiV0fHQSebwC/Tx8af7QLdhkApXQCHHxRhtBxf N7bNw5Q8Rkk/6468nF51FYLSWEWfBw5OXJVFQSsURhjKlwY1tnObZiQv1GMdlHA1NKx3 R8l2CBzgL0Jj3PNtZWlYamw05Gy0+bmM1JywRV4Kj8olMlXVeE9YsWfhCrvHrJ2Rms5n gS7IGdD8p9TGmHzW0bF2wz4NSjgRGQ1ZlnX0o/qECAN5YOdKWgN8Prfkc5ix69npNewf 3Eag== X-Gm-Message-State: AODbwcB/8qVHGVoA113EP1lb6uJ6ooLhuAKiqiEJ3r34156QK/cVrGP3 +IH8nF7s2oE61OkEH9w= X-Received: by 10.28.59.212 with SMTP id i203mr8383416wma.14.1496320943381; Thu, 01 Jun 2017 05:42:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:43 +0200 Message-Id: <1496320911-51305-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::242 Subject: [Qemu-devel] [PULL 25/33] qtest: add rtc periodic timer test 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: Xiao Guangrong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong It tests the accuracy of rtc periodic timer which is recently improved & fixed by commit 7ffcb539a3 ("mc146818rtc: precisely count the clock for periodic timer", 2017-05-19). Signed-off-by: Xiao Guangrong Message-Id: <20170527025301.23499-1-xiaoguangrong@tencent.com> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 15 +++---------- include/hw/timer/mc146818rtc.h | 19 ++++++++++++++++ tests/rtc-test.c | 49 ++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 542cd09..1b8d3d7 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -120,7 +120,7 @@ static void rtc_coalesced_timer_update(RTCState *s) /* divide each RTC interval to 2 - 8 smaller intervals */ int c =3D MIN(s->irq_coalesced, 7) + 1;=20 int64_t next_clock =3D qemu_clock_get_ns(rtc_clock) + - muldiv64(s->period / c, NANOSECONDS_PER_SECOND, RTC_CLOCK_RATE= ); + periodic_clock_to_ns(s->period / c); timer_mod(s->coalesced_timer, next_clock); } } @@ -178,16 +178,8 @@ static uint32_t rtc_periodic_clock_ticks(RTCState *s) } =20 period_code =3D s->cmos_data[RTC_REG_A] & 0x0f; - if (!period_code) { - return 0; - } - - if (period_code <=3D 2) { - period_code +=3D 7; - } =20 - /* period in 32 Khz cycles */ - return 1 << (period_code - 1); + return periodic_period_to_clock(period_code); } =20 /* @@ -260,8 +252,7 @@ periodic_timer_update(RTCState *s, int64_t current_time= , uint32_t old_period) assert(lost_clock >=3D 0 && lost_clock <=3D period); =20 next_irq_clock =3D cur_clock + period - lost_clock; - s->next_periodic_time =3D muldiv64(next_irq_clock, NANOSECONDS_PER= _SECOND, - RTC_CLOCK_RATE) + 1; + s->next_periodic_time =3D periodic_clock_to_ns(next_irq_clock) + 1; timer_mod(s->periodic_timer, s->next_periodic_time); } else { s->irq_coalesced =3D 0; diff --git a/include/hw/timer/mc146818rtc.h b/include/hw/timer/mc146818rtc.h index 7c8e64b..f23e734 100644 --- a/include/hw/timer/mc146818rtc.h +++ b/include/hw/timer/mc146818rtc.h @@ -10,4 +10,23 @@ ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq= intercept_irq); void rtc_set_memory(ISADevice *dev, int addr, int val); int rtc_get_memory(ISADevice *dev, int addr); =20 +static inline uint32_t periodic_period_to_clock(int period_code) +{ + if (!period_code) { + return 0; + } + + if (period_code <=3D 2) { + period_code +=3D 7; + } + /* period in 32 Khz cycles */ + return 1 << (period_code - 1); +} + +#define RTC_CLOCK_RATE 32768 + +static inline int64_t periodic_clock_to_ns(int64_t clocks) +{ + return muldiv64(clocks, NANOSECONDS_PER_SECOND, RTC_CLOCK_RATE); +} #endif /* MC146818RTC_H */ diff --git a/tests/rtc-test.c b/tests/rtc-test.c index a086efd..0500686 100644 --- a/tests/rtc-test.c +++ b/tests/rtc-test.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" =20 #include "libqtest.h" +#include "hw/timer/mc146818rtc.h" #include "hw/timer/mc146818rtc_regs.h" =20 static uint8_t base =3D 0x70; @@ -542,6 +543,52 @@ static void register_b_set_flag(void) g_assert_cmpint(cmos_read(RTC_CENTURY), =3D=3D, 0x20); } =20 +#define RTC_PERIOD_CODE1 13 /* 8 Hz */ +#define RTC_PERIOD_CODE2 15 /* 2 Hz */ + +#define RTC_PERIOD_TEST_NR 50 + +static uint64_t wait_periodic_interrupt(uint64_t real_time) +{ + while (!get_irq(RTC_ISA_IRQ)) { + real_time =3D clock_step_next(); + } + + g_assert((cmos_read(RTC_REG_C) & REG_C_PF) !=3D 0); + return real_time; +} + +static void periodic_timer(void) +{ + int i; + uint64_t period_clocks, period_time, start_time, real_time; + + /* disable all interrupts. */ + cmos_write(RTC_REG_B, cmos_read(RTC_REG_B) & + ~(REG_B_PIE | REG_B_AIE | REG_B_UIE)); + cmos_write(RTC_REG_A, RTC_PERIOD_CODE1); + /* enable periodic interrupt after properly configure the period. */ + cmos_write(RTC_REG_B, cmos_read(RTC_REG_B) | REG_B_PIE); + + start_time =3D real_time =3D clock_step_next(); + + for (i =3D 0; i < RTC_PERIOD_TEST_NR; i++) { + cmos_write(RTC_REG_A, RTC_PERIOD_CODE1); + real_time =3D wait_periodic_interrupt(real_time); + cmos_write(RTC_REG_A, RTC_PERIOD_CODE2); + real_time =3D wait_periodic_interrupt(real_time); + } + + period_clocks =3D periodic_period_to_clock(RTC_PERIOD_CODE1) + + periodic_period_to_clock(RTC_PERIOD_CODE2); + period_clocks *=3D RTC_PERIOD_TEST_NR; + period_time =3D periodic_clock_to_ns(period_clocks); + + real_time -=3D start_time; + g_assert_cmpint(ABS((int64_t)(real_time - period_time)), <=3D, + NANOSECONDS_PER_SECOND * 0.5); +} + int main(int argc, char **argv) { QTestState *s =3D NULL; @@ -564,6 +611,8 @@ int main(int argc, char **argv) qtest_add_func("/rtc/set-year/1980", set_year_1980); qtest_add_func("/rtc/misc/register_b_set_flag", register_b_set_flag); qtest_add_func("/rtc/misc/fuzz-registers", fuzz_registers); + qtest_add_func("/rtc/periodic/interrupt", periodic_timer); + ret =3D g_test_run(); =20 if (s) { --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496321875370333.5693688671612; Thu, 1 Jun 2017 05:57:55 -0700 (PDT) Received: from localhost ([::1]:44220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPfl-0000Rn-WF for importer@patchew.org; Thu, 01 Jun 2017 08:57:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQo-0003yT-Gq for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQn-0005ns-Jz for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:26 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35419) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQn-0005nI-EF for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:25 -0400 Received: by mail-wm0-x243.google.com with SMTP id g15so11031137wmc.2 for ; Thu, 01 Jun 2017 05:42:25 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:23 -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=MCKH31VOEKhO/ZXNUkE7tqkwtV9n1g+ubr7fJoLkoEA=; b=WNWdO3nBRNXd1sxMksaD3D+JmFpRZr3Z/scF5QSneTGhVMLiBcnzS7PNll34ZUOKwL N08IIJg2cDJ6C8Gdc7fpb3waK3Zg4zG3fnO6/Lp2Q4oLeb8yu7PDQ57XXaDmWERkK8dr 523nvKOyQ3yY2KsckOiZM//vPPlnvkwjnvfX9W+tbTWIZhHBgn/5TCj3Tb8UXtKRBNcK idSWtwX9GFLTWnQV8FHBs/vNZNT4MOUc5szurp4mwArkdBtEh+co6g9ZKddRYb+lFtue CDJhFCyMVCDJ5dm+El9UuROMUvmka8x74OmM/yiDa8QQiVhOPQlI9FFCecOPPzbIpyXs Wk1g== 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=MCKH31VOEKhO/ZXNUkE7tqkwtV9n1g+ubr7fJoLkoEA=; b=r2MZOCAvJExYv/1xjUoX0clHFAWFVDhABRGr2tSAsvB4YJ6DvNAbbG3xB3QwKlI5Xx uYCH9SbinxAtUNm/yEz/QNJ4hXAo0ALxEedlwnFOqR9+DyX6v1+J+g64oZh6uTTip0Lv Wfat5a9mCC7Yjepz2tjenQ+BoUCJ3ZtV3vQLcUzDXPp+JFcVEGiQSNZeuWiYKcD3cqke WPUuLGHE/BJlOnboYfC2TGyJOeMURHEU+IRWrGyF+toJLToVKI+kS+puZoCo3mKr7E2U Wkoe8VGan58brNhmR7oZBPZTlIC7aKEO0ciPFbMsBKLs9Ka7I+a8/RClw0D32vxDT2Bx 7q2w== X-Gm-Message-State: AODbwcBptXmqz0et0guw/Q6tADREqmXUn9xs6ocqpzvUjnmje61p24YT E8ngZBh8lamqLoCMtdM= X-Received: by 10.223.169.117 with SMTP id u108mr1359590wrc.59.1496320944265; Thu, 01 Jun 2017 05:42:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:44 +0200 Message-Id: <1496320911-51305-27-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::243 Subject: [Qemu-devel] [PULL 26/33] kvmclock: update system_time_msr address forcibly 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: Denis Plotnikov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Denis Plotnikov Do an update of system_time_msr address every time before reading the value of tsc_timestamp from guest's kvmclock page. There is no other code paths which ensure that qemu has an up-to-date value of system_time_msr. So, force this update on guest's tsc_timestamp reading. This bug causes effect on those nested setups which turn off TPR access interception for L2 guests and that access being intercepted by L0 doesn't show up in L1. Linux bootstrap initiate kvmclock before APIC initializing causing TPR acce= ss. That's why on L1 guests, having TPR interception turned on for L2, the effe= ct of the bug is not revealed. This patch fixes this problem by making sure it knows the correct system_time_msr address every time it is needed. Signed-off-by: Denis Plotnikov Message-Id: <1496054944-25623-1-git-send-email-dplotnikov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/i386/kvm/clock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index 13eca37..363d1b5 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -19,6 +19,7 @@ #include "qemu/host-utils.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/hw_accel.h" #include "kvm_i386.h" #include "hw/sysbus.h" #include "hw/kvm/clock.h" @@ -69,6 +70,8 @@ static uint64_t kvmclock_current_nsec(KVMClockState *s) uint64_t nsec_hi; uint64_t nsec; =20 + cpu_synchronize_state(cpu); + if (!(env->system_time_msr & 1ULL)) { /* KVM clock not active */ return 0; --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322388439606.7281641901859; Thu, 1 Jun 2017 06:06:28 -0700 (PDT) Received: from localhost ([::1]:44265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPo0-0007n2-U3 for importer@patchew.org; Thu, 01 Jun 2017 09:06:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQq-00043J-8n for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQp-0005oP-3Q for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:28 -0400 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:37408) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQo-0005o1-TS; Thu, 01 Jun 2017 08:42:27 -0400 Received: by mail-wm0-x22a.google.com with SMTP id d127so58787859wmf.0; Thu, 01 Jun 2017 05:42:26 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=3QGughV8OY3wxlSZuxfBq2us9g9D19Am/IQZ2VUX6ks=; b=JZ0GBWcP8qaGk6WrO9qgyQFN6387EOZqxjep2HAC4deAZRrx44/gOIAustnZPNUoLP jp+bwx88wXVnI6Si/9dUbf3v3UnrsR7gpQhhycGQ0SrrMFvh3fFysQFfdKksdCYTZjAl rgXt2/ly2TEajg//Dmnp91hmLpIY1jSU8sO5hszFAE/6JNYYF1WWbIc95nkfHfROUC6N 5Thr4PXvnUbJGOMoAHgDbsvyijJ9FE7V0mnRxTNo6euixOYPDvv8WXQqDA9cDU7/pLy2 jR3TVG6nb/yyO7Ycg5RN634oXWNW2kg2kBKLpgMP3IBcaVcpJpZKWvgSErYorhx2UxTZ 8lwA== 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=3QGughV8OY3wxlSZuxfBq2us9g9D19Am/IQZ2VUX6ks=; b=oWyXweYymFvJgBe01170i8aAEb1wYrQWWSHFZi9TfEemXG8z6OxrM1v23NQSZHeCvV eHNJJcoiKZv/n5n/NXL9owc9+H6dVjfWxrckhXY4y/GVbmbHtlV06BOL8iqZgb1Z6XZq pbuvzGJUkeaLLtRIG6OICYnHuQrCQZlbqv7pvFeffXDjkMjprcoqmTcXc+42T7rLn9AO r7vbLmmM6LkIazQBum+wRhKfsqbLMfe39loyBzBZRYqmv0PHkdhptmJVw25Z7uF1bg65 2qCQivENalA05YZgIE1n/TvioTE712pGmVgegGDtZyB82m6nkKwSZoEY1iNKbf49G0rR xetw== X-Gm-Message-State: AODbwcCbdZUYsbqYC3vwzt/pdUEeII+OXy9c6m2Fb9mG959yw1RD6Jkz FnL7HyYr47KZWKcPGu4= X-Received: by 10.28.175.136 with SMTP id y130mr1678518wme.112.1496320945281; Thu, 01 Jun 2017 05:42:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:45 +0200 Message-Id: <1496320911-51305-28-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::22a Subject: [Qemu-devel] [PULL 27/33] linuxboot_dma: compile for i486 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: qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The ROM uses the cmovne instruction, which is new in Pentium Pro and does n= ot work when running QEMU with "-cpu 486". Avoid producing that instruction. Suggested-by: Richard W.M. Jones Suggested-by: Thomas Huth Reported-by: Rob Landley Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- pc-bios/linuxboot_dma.bin | Bin 1536 -> 1536 bytes pc-bios/optionrom/Makefile | 1 + 2 files changed, 1 insertion(+) diff --git a/pc-bios/linuxboot_dma.bin b/pc-bios/linuxboot_dma.bin index 218d3ab4a29bfb5ab7125ec7a4d29dad1860c673..d176f62797813e4b926dca9dfce= 7ce554dc1a4d6 100644 GIT binary patch literal 1536 zcmeHFL2J`s82-{_T52KL%w~}udiW-YBE*9t=3Ds~ClrIm^s9^6H6Pf%onr07*+kWd=3DL zpW)d<4G1ZESU1FyUDSCf^YYaxioy<}t?!rmu^#*f?mHxJo;-Qp_kHp#Je^o$|2##; zYs)n)qh6k7XI07O)9TW>>H@3WSgzkI-MW44`qG_Jxhgq7fAt@+rpuZy7{g_FpG^eo zuoD<7Fjn!zK~Uydy3X@Fj1CnQuA}{tXz$^z=3D7>a?#S!%6CsARNbiO)h=3Dv+Q~y@5O1 ze8y7!akTy&-YXMV@p3Es`0q*km+)Mtxe(3DE2)a5;c%$H0|Yu~mbnR0C7dKHR7Zsr zmrccq5lm%U=3DwXc39gV6@%Jl!9^%vQ9V0A-7aUkNnpxu8npp2ruY0}SsKn=3DBiGN9Y; L*>&K*abWuoMsO(* literal 1536 zcmeHF&ubGw6rN4Dn#RCxYN|nUh%gpJFME=3DL9)#^}1F5!ps0f07iy|#(O1W^nf~VP8b!3b3v@l;?V$SuIwL6uYt5>dGyH&BPBIn1?(K>6@S?eidI1hgSZ^wky zNA%Hz@f^krJcQTH!Ptb+b>Z7QOZy_v)9!Gc_A*CUnxyOgP~7<9qN#In@`mGjfw=3Dz$ z*1p4gW?~r|cz_FdqLT)y8y*s0Z-)z#_;!*cE?PD>cN4CX-n&AUsLGXj9UuS(2NP%(`OENoGw|EGqnf#7ASHq-k?KrExJ~ z^CHnSr*VvZO%mMQmY+taei4m+{T$|c^(w4)XlpT*^|#=3D^eK`aF_0%gE_5j9w)aV=3Dc zk7$UtO_Fkt>S!)b5N*mx5@orPY(na#Hj4MfwIDj65ohT<|dXkK7E?qHJ9XdoKqMjysh NXm9N~@Si)N{RVuA8xQ~h diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile index fa53d9e..a9a9e5e 100644 --- a/pc-bios/optionrom/Makefile +++ b/pc-bios/optionrom/Makefile @@ -13,6 +13,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom) ifeq ($(lastword $(filter -O%, -O0 $(CFLAGS))),-O0) override CFLAGS +=3D -O2 endif +override CFLAGS +=3D -march=3Di486 =20 # Drop -fstack-protector and the like QEMU_CFLAGS :=3D $(filter -W%, $(QEMU_CFLAGS)) $(CFLAGS_NOPIE) -ffreestand= ing --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322126832386.21504163567295; Thu, 1 Jun 2017 06:02:06 -0700 (PDT) Received: from localhost ([::1]:44245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPjo-00040k-3p for importer@patchew.org; Thu, 01 Jun 2017 09:02:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQq-00043K-Ky for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQp-0005oY-Qd for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:28 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:37416) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQp-0005oL-JM for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:27 -0400 Received: by mail-wm0-x234.google.com with SMTP id d127so58788403wmf.0 for ; Thu, 01 Jun 2017 05:42:27 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:25 -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=B2WajsaQjJ0Y2Hq6+34SOKshc86Q3FiInRHuVuWRiLM=; b=J6Gw62F1XO6s4kOHa7D8mwR0WD4sjI5qyOMILzt8/4fntplU1PVC5Hs/HuPV2AEb6f TdyGrjmC9rbRz62jM9HNZTC16kWYpXj0QhVzIG3iAy0BAyXfhhpX4Ht9qB9xEL5UwF+F AmQRzyktaS0Y6bEUW7O/4O4STaIvbqTwSzvoXag8gOS6KlD/yiNSYG38gR/gI6Uwzo4A gfOm96no6DTGvc9uk5Vhv1ORnwu3Hs1W63SFGhXekodHR2ik7QCBymTGS24GY214A26l iRWkdZK03ZBb8lMh9q4tEfQInAaldFxdhMV9ta8kzWFAh7jNInZeLQ/I0hX91kVqfrne IPRg== 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=B2WajsaQjJ0Y2Hq6+34SOKshc86Q3FiInRHuVuWRiLM=; b=ofigFdO/dkM+P0FFCDTdS2OQQW+qSyqynYFuwLBPsvRFUi4zfA1vCietUa2CJT6ajH WZCLUFHX9pi8YLl9Mg9tp6jdgdNzT2QlG6hIrgm3jDIgOFihdbvx//x4W+w9+vZkkV8z R8hEvG3s6id09DfQ7tkdsq12nXcYrCtMJALkvChGuinqUPtndCMmAIk0wj7qqq+N28kN xpXsyGLJgwtJDHwYI6mMkMSrgC78TCZ9Qtys9qvwBDcb5t0odPjgVeF8QbI0Y1JiI2oS 0Z4BegO+a/GO0XVJvHQINsL/cdDC5TCGWL1Pg0klejGNRLQ4jiu7R5+as5XMZPDwhlZw V0oQ== X-Gm-Message-State: AODbwcCM/QupATnySd8+hP5mbZsFMqVpkSk6C3U35kJlRN6QwQajhTrO 511W3uO7DZrKe7vSmCc= X-Received: by 10.28.48.72 with SMTP id w69mr1661098wmw.103.1496320946148; Thu, 01 Jun 2017 05:42:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:46 +0200 Message-Id: <1496320911-51305-29-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::234 Subject: [Qemu-devel] [PULL 28/33] edu: fix memory leak on msi_broken platforms 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: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If msi_init fails, the thread has already been created and the mutex/condvar are not destroyed. Initialize everything only after the point where pci_edu_realize cannot fail. Reported-by: Markus Armbruster Cc: Peter Xu Signed-off-by: Paolo Bonzini --- hw/misc/edu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/misc/edu.c b/hw/misc/edu.c index 401039c..01acacf 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -343,6 +343,12 @@ static void pci_edu_realize(PCIDevice *pdev, Error **e= rrp) EduState *edu =3D DO_UPCAST(EduState, pdev, pdev); uint8_t *pci_conf =3D pdev->config; =20 + pci_config_set_interrupt_pin(pci_conf, 1); + + if (msi_init(pdev, 0, 1, true, false, errp)) { + return; + } + timer_init_ms(&edu->dma_timer, QEMU_CLOCK_VIRTUAL, edu_dma_timer, edu); =20 qemu_mutex_init(&edu->thr_mutex); @@ -350,12 +356,6 @@ static void pci_edu_realize(PCIDevice *pdev, Error **e= rrp) qemu_thread_create(&edu->thread, "edu", edu_fact_thread, edu, QEMU_THREAD_JOINABLE); =20 - pci_config_set_interrupt_pin(pci_conf, 1); - - if (msi_init(pdev, 0, 1, true, false, errp)) { - return; - } - memory_region_init_io(&edu->mmio, OBJECT(edu), &edu_mmio_ops, edu, "edu-mmio", 1 << 20); pci_register_bar(pdev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &edu->mmio); --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322363767416.6941843361009; Thu, 1 Jun 2017 06:06:03 -0700 (PDT) Received: from localhost ([::1]:44263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPnZ-0007OF-BE for importer@patchew.org; Thu, 01 Jun 2017 09:05:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQt-000454-13 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQq-0005oo-Jc for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:31 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35424) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQq-0005oc-Cu for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:28 -0400 Received: by mail-wm0-x243.google.com with SMTP id g15so11031360wmc.2 for ; Thu, 01 Jun 2017 05:42:28 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qWko5us9/lO8KeimwWCxowQBjXnVKnfgR02gn8S4MwE=; b=G1kj6BA8E7e+0Cv+U8qIrhr5JogpGCVWj917jwkJ9rf10T4pHkLb5KNe5kiJUTrpOY rdXnck36RB+QhPn4nApdYGmLeZD61/goAFPBU0viHyOc6iUrSvGMGxachES8/Pc9xbHf W76Ds4eJjkuu6fYAr53bK00jk6LkUiAKmXT5p1pKMS4/QNAIb/NwJZKa2t0mTzJ4F1kl JDyMVgsJ5qWWm4nnW1O4sKw5R0lO+q6DQh6fzH0oWabhokCzulIA+0XH9D0r8nusRdwO 3H0IIMHeJyXVFd/9saC1cPTnF/oxs4tURV42H/WNvtjGnP+Kv/W/2KabxEa9NCwfJ5qe fhsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=qWko5us9/lO8KeimwWCxowQBjXnVKnfgR02gn8S4MwE=; b=Wy5CY2pPMsw7WansiPBKDfgyGbIMuXd6Wkh6lT/dkxXPk8HG5pFM/Pmbl2ye4BkZ5E EkD8pItLAf8ngLTDT81ma06rjA/3248FrQQSu3BpcKa6B4SSE3mS7Awviphwc8DA75wZ 9DKqP32FBDM3v9pJJm1nyryByi+AkvlU0tlPBuUlJpLlkgQSlDJ+gK/9kJpJtQKNt7dD Ga1vbWwukCzUDNXpBHu0mI2M3VLlVJQvnIWOsSBumKKgPANlBh5s3Y0G/xWfnv5fqoYg Qq2HbvbpLLhDpwLqh6nGX3blnfWekVG1XArxhUKmWZ0b2NM1gp8CMQWnmgqLosTUVCYg VrAA== X-Gm-Message-State: AODbwcCmmm430BnNnmvJQIwl7Kuv7SYab+4A3V7lxKwjacdchupC+YXY DKhZJ1z/AS/SpVQfl3I= X-Received: by 10.28.87.72 with SMTP id l69mr8276542wmb.111.1496320947178; Thu, 01 Jun 2017 05:42:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:47 +0200 Message-Id: <1496320911-51305-30-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PULL 29/33] i386/kvm: do not zero out segment flags if segment is unusable or not 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: Michael Chapman , Mikhail Sennikovskii , Roman Pen , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Roman Pen This is a fix for the problem [1], where VMCB.CPL was set to 0 and interrupt was taken on userspace stack. The root cause lies in the specific AMD CPU behaviour which manifests itself as unusable segment attributes on SYSRET[2= ]. Here in this patch flags are not touched even segment is unusable or is not present, therefore CPL (which is stored in DPL field) should not be lost and will be successfully restored on kvm/svm kernel side. Also current patch should not break desired behavior described in this comm= it: 4cae9c97967a ("target-i386: kvm: clear unusable segments' flags in migratio= n") since present bit will be dropped if segment is unusable or is not present. This is the second part of the whole fix of the corresponding problem [1], first part is related to kvm/svm kernel side and does exactly the same: segment attributes are not zeroed out. [1] Message id: CAJrWOzD6Xq=3D=3Db-zYCDdFLgSRMPM-NkNuTSDFEtX=3D7MreT45i7Q@m= ail.gmail.com [2] Message id: 5d120f358612d73fc909f5bfa47e7bd082db0af0.1429841474.git.lut= o@kernel.org Signed-off-by: Roman Pen Signed-off-by: Mikhail Sennikovskii Cc: Paolo Bonzini Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 Cc: Michael Chapman Cc: qemu-devel@nongnu.org Message-Id: <20170601085604.12980-1-roman.penyaev@profitbricks.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 82c72d2..6e7c197 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1301,18 +1301,14 @@ static void get_seg(SegmentCache *lhs, const struct= kvm_segment *rhs) lhs->selector =3D rhs->selector; lhs->base =3D rhs->base; lhs->limit =3D rhs->limit; - if (rhs->unusable) { - lhs->flags =3D 0; - } else { - lhs->flags =3D (rhs->type << DESC_TYPE_SHIFT) | - (rhs->present * DESC_P_MASK) | - (rhs->dpl << DESC_DPL_SHIFT) | - (rhs->db << DESC_B_SHIFT) | - (rhs->s * DESC_S_MASK) | - (rhs->l << DESC_L_SHIFT) | - (rhs->g * DESC_G_MASK) | - (rhs->avl * DESC_AVL_MASK); - } + lhs->flags =3D (rhs->type << DESC_TYPE_SHIFT) | + ((rhs->present && !rhs->unusable) * DESC_P_MASK) | + (rhs->dpl << DESC_DPL_SHIFT) | + (rhs->db << DESC_B_SHIFT) | + (rhs->s * DESC_S_MASK) | + (rhs->l << DESC_L_SHIFT) | + (rhs->g * DESC_G_MASK) | + (rhs->avl * DESC_AVL_MASK); } =20 static void kvm_getput_reg(__u64 *kvm_reg, target_ulong *qemu_reg, int set) --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322021329406.09016595590833; Thu, 1 Jun 2017 06:00:21 -0700 (PDT) Received: from localhost ([::1]:44230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPi6-0002aN-Qy for importer@patchew.org; Thu, 01 Jun 2017 09:00:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQt-00045t-QS for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQr-0005p4-Rq for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:31 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:36316) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQr-0005ow-IX for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:29 -0400 Received: by mail-wm0-x241.google.com with SMTP id k15so11051210wmh.3 for ; Thu, 01 Jun 2017 05:42:29 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=sb25EtXNGmn4Rwm+mv9UbL5D173VEGIDcMWWuwmTXMw=; b=OWOkarutuugroHpiyTR9g8eeIwQ1xOiQwzMjxyrL8TcFXI3q4633YMQ2KIXee4yyRz S8TxN+tOCVto26hnqLsYpd8rz4hr3KZQROZOJ1Dlgd5bUgbR9qxZoxs3VExXpUvKtHs8 F5hQEmWxO0FWYqaH0iei5dTcETudrjU3oU+GKK8deF3kBX4tCB2igsLCn46ECWh8w9Fw s4mPMaHDJDlPhKM47AB2xBL/0Cwjje5ar1lW+fRHqRXFngR09ysmKm4N0aXhokhP54Ke xaCQLhythCIcVuIrjVAoFcv7Y87ZtGqcDVqzZfEC7J5JLDP2EaLFWf4mzrdjpl0WbKYL dnbw== 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=sb25EtXNGmn4Rwm+mv9UbL5D173VEGIDcMWWuwmTXMw=; b=RnRsyn9XnyNJf32ttW66Mc5v2b3KIyLc5DqKDK4d87NHy6NcjwqLK4UxfYDF823CKg d8gU4ZNKg7wnPGAIJo9VnNzNbmWm0eSWjgco0PanuyApR9Vjjb7pLrgvHHQ/Go1ZlWEE OVtRp2v2mHpsDk2WbHhK2U00h1yz+tjjMnVF4vuPgxduTUUIGlmXOJbjPfyjTznqxKps QNvM8q3dBqjX6HM9zjOsyZKWs/FzLu17WHrfz355alGvb6tpYleCsZKIeMtRF7Bsb1Rc 3RwEh0UsKqdtncCVcUujtsbcjeynrX9+Mjf0R1VSi1KKQPFLguXMprG4stvNkPDsUhMA Ef2A== X-Gm-Message-State: AODbwcAuw5V4nOtwzuTa90HrcIRNX0/KtshSW3ZsaBmZGFp/NA84j3BR nk1oru5QSDXVcX/zjho= X-Received: by 10.28.126.210 with SMTP id z201mr1492282wmc.75.1496320948274; Thu, 01 Jun 2017 05:42:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:48 +0200 Message-Id: <1496320911-51305-31-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::241 Subject: [Qemu-devel] [PULL 30/33] target/i386: Add GDB XML description for SSE registers 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: Abdallah Bouassida Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Abdallah Bouassida Add an XML description for SSE registers (XMM+MXCSR) for both X86 and X86-64 architectures in the GDB stub: - configure: Define gdb_xml_files for the X86 targets (32 and 64bit). - gdb-xml/i386-32bit-sse.xml & gdb-xml/i386-64bit-sse.xml: The XML files that contain a description of the XMM + MXCSR registers. - gdb-xml/i386-32bit.xml & gdb-xml/i386-64bit.xml: wrappers that include the XML file of the core registers and the other XML file of the SSE regist= ers. - target/i386/cpu.c: Modify the gdb_core_xml_file to the new XML wrapper, modify the gdb_num_core_regs to fit the registers number defined in each XML file. Signed-off-by: Abdallah Bouassida Signed-off-by: Paolo Bonzini --- configure | 4 ++-- gdb-xml/i386-32bit-sse.xml | 52 ++++++++++++++++++++++++++++++++++++++++ gdb-xml/i386-32bit.xml | 14 +++++++++++ gdb-xml/i386-64bit-sse.xml | 60 ++++++++++++++++++++++++++++++++++++++++++= ++++ gdb-xml/i386-64bit.xml | 14 +++++++++++ target/i386/cpu.c | 8 +++---- 6 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 gdb-xml/i386-32bit-sse.xml create mode 100644 gdb-xml/i386-32bit.xml create mode 100644 gdb-xml/i386-64bit-sse.xml create mode 100644 gdb-xml/i386-64bit.xml diff --git a/configure b/configure index 139638e..aeec615 100755 --- a/configure +++ b/configure @@ -6033,11 +6033,11 @@ TARGET_ABI_DIR=3D"" =20 case "$target_name" in i386) - gdb_xml_files=3D"i386-32bit-core.xml" + gdb_xml_files=3D"i386-32bit.xml i386-32bit-core.xml i386-32bit-sse.xml" ;; x86_64) TARGET_BASE_ARCH=3Di386 - gdb_xml_files=3D"i386-64bit-core.xml" + gdb_xml_files=3D"i386-64bit.xml i386-64bit-core.xml i386-64bit-sse.xml" ;; alpha) mttcg=3D"yes" diff --git a/gdb-xml/i386-32bit-sse.xml b/gdb-xml/i386-32bit-sse.xml new file mode 100644 index 0000000..5767847 --- /dev/null +++ b/gdb-xml/i386-32bit-sse.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb-xml/i386-32bit.xml b/gdb-xml/i386-32bit.xml new file mode 100644 index 0000000..956fc7f --- /dev/null +++ b/gdb-xml/i386-32bit.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/gdb-xml/i386-64bit-sse.xml b/gdb-xml/i386-64bit-sse.xml new file mode 100644 index 0000000..e86efc9 --- /dev/null +++ b/gdb-xml/i386-64bit-sse.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb-xml/i386-64bit.xml b/gdb-xml/i386-64bit.xml new file mode 100644 index 0000000..0b2f00c --- /dev/null +++ b/gdb-xml/i386-64bit.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a638832..41978d8 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4068,11 +4068,11 @@ static void x86_cpu_common_class_init(ObjectClass *= oc, void *data) #endif cc->gdb_arch_name =3D x86_gdb_arch_name; #ifdef TARGET_X86_64 - cc->gdb_core_xml_file =3D "i386-64bit-core.xml"; - cc->gdb_num_core_regs =3D 40; + cc->gdb_core_xml_file =3D "i386-64bit.xml"; + cc->gdb_num_core_regs =3D 57; #else - cc->gdb_core_xml_file =3D "i386-32bit-core.xml"; - cc->gdb_num_core_regs =3D 32; + cc->gdb_core_xml_file =3D "i386-32bit.xml"; + cc->gdb_num_core_regs =3D 41; #endif #ifndef CONFIG_USER_ONLY cc->debug_excp_handler =3D breakpoint_handler; --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322189544261.21907808368803; Thu, 1 Jun 2017 06:03:09 -0700 (PDT) Received: from localhost ([::1]:44248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPkl-0004nF-Nb for importer@patchew.org; Thu, 01 Jun 2017 09:03:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQw-00049G-VP for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQs-0005pG-KD for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:35 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35431) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQs-0005p1-D4 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:30 -0400 Received: by mail-wm0-x243.google.com with SMTP id g15so11031517wmc.2 for ; Thu, 01 Jun 2017 05:42:30 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=hwmb3kBvL2H8nSy/vqGzbVHgXLDSRcIK8qTtpmyt3Xw=; b=snK+JC3I6mqHqNcM4f65QxNHWLhlrDh4hXXHBwhJQQnk8m1fwHDFbIBmRv01Xq04GE KmTYbTvQSliYox9NXyroDoNvXteqYQLrdgwdxltLIALPKMMO+eAe/ujeDt+zKzO5/yc+ i1OCN3dZIKOqIU8YaC5OuRkm1XFaOARfsogSPgUoIzbheMesuT1f/+GlP+MOmWskUGzN A0liggS38W33dM61ucLjS/ngFJ6T8yI0jttD1Mua+dZQ4lc0oAnor7K6gY8Cn1SUpsfG qmucNJyRtRIf9BS1ogiX4k7Eh3R963mdJ6YLiy4STl+8bf4KclPi7IeEb35+cZ8HxCdA Zgcw== 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=hwmb3kBvL2H8nSy/vqGzbVHgXLDSRcIK8qTtpmyt3Xw=; b=bKwZYQPOaGZiXLKCDKuayKfqhraMVSVdGbOomwQnTdDGW+5t3ECHJD82tuioeNcUOw qTkyGVd/7MmwqRlU+lG2WbwBQs/6OGIhFcLid4GgApLNXTOGz1DOVNuRfvR0VTopu9TP RK71GjuwB87GYPjGdWY4eldY4xnR4pAlY1X9FeXs+gWCp8yrwZgNo0Lk+dESrONlcFI7 RG0ExPftktiiwI+4DJ+ThpL9Cp2Tc2nlQ9VAcL1LzyyLI7m/YY7E+oLhjm1HF3dJ2obw bIELDxkvamEjGVUScB3LI6iOGp7OaI+4b3ketnuDT44ig5r807Jd376BlyotdXMzUxex KgCg== X-Gm-Message-State: AODbwcA4UHDUmei5b2F/2FKULqf6P59777eTodBRPKrSZo4LVYuL7/+P I+WToRMmCWCcZvlpCME= X-Received: by 10.28.27.197 with SMTP id b188mr1608430wmb.61.1496320949217; Thu, 01 Jun 2017 05:42:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:49 +0200 Message-Id: <1496320911-51305-32-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::243 Subject: [Qemu-devel] [PULL 31/33] hw/core: nmi.c can be compiled as common-obj nowadays 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: Thomas Huth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Thomas Huth The target-specific code in nmi.c has been removed with this commit: commit f7e981f29548fe4af7812f5920304fe607e5bf0d nmi: remove x86 specific nmi handling Signed-off-by: Thomas Huth Message-Id: <1496310843-28771-1-git-send-email-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- hw/core/Makefile.objs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index 91450b2..f8d7a4a 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -5,7 +5,7 @@ common-obj-y +=3D fw-path-provider.o # irq.o needed for qdev GPIO handling: common-obj-y +=3D irq.o common-obj-y +=3D hotplug.o -obj-y +=3D nmi.o +common-obj-y +=3D nmi.o =20 common-obj-$(CONFIG_EMPTY_SLOT) +=3D empty_slot.o common-obj-$(CONFIG_XILINX_AXI) +=3D stream.o --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496322566493368.17128949958794; Thu, 1 Jun 2017 06:09:26 -0700 (PDT) Received: from localhost ([::1]:44287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPqu-00028E-Vy for importer@patchew.org; Thu, 01 Jun 2017 09:09:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQw-00049J-Vh for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQt-0005pc-Nx for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:35 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:34174) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQt-0005pM-H7 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:31 -0400 Received: by mail-wm0-x243.google.com with SMTP id d127so11022233wmf.1 for ; Thu, 01 Jun 2017 05:42:31 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42:29 -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=Ufvw8bxJGjUC7GSXau2As1peAJ8DSlMaxumumGn04HU=; b=j0mGQu5FeqfruhjBO+Nlt7STI2I+EQnodiRPUaHMIiOFmoNRRq2jmnX+KgkjdlPqE9 eBl6OLnJNF7FBxwder/wsIhH+eOyWVzb94U1TOkaBHLiC9Iuv4I8AVqld2RCaksooJPY /q3pcbGpvgn0ISYw1KncefkD8zubNAa+fZsYjQKD2Yxs3SeyfBpdLe7ZOqF3Ndhs5gN1 7wtQP5yc0kKf7j0jkqvUS9eAL4ZehPtywmjQ3UYj7Ayj2q5qvhnBXytk+0TZaRNs7j6J XzbPWoqUAkqIQYi5YlIuYWuaUnLE9cX0jyOvl3QcYnenp7shXwe5NfbhmqSQMZXMJPhj pXbA== 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=Ufvw8bxJGjUC7GSXau2As1peAJ8DSlMaxumumGn04HU=; b=V6RkCbIiLjGC2FqQcByppwRlk8nFLJeUpX3eUHgZvmVVAXszXJv1qbhOycyOk5bE7s YTTEFPu+Bgm+ngqAQvqtjk3DnoNatG2s8qe6WNtr6J46931gHOo15DP88LnBGjh7Znvx hvN4HzELw5q0qowfxSpp6vz9yg6O8atirBGvlRRWxmJB7X68+dW2rawNIngOGUnlApSg ffCJtb201UOldVRdazA9WkY102Jm7txS5N0pcnjghDKC1C4tchq4MR9ZgaTjdF6tpLvZ 9r7qSiSrSE8nIvA4xePeYEa8iC2PeNRNTRfwpi+Y+p8+Yo8d8Romr54H1XGv2WUczmUp nMWw== X-Gm-Message-State: AODbwcB4vRXqXgGEU9xmDbJa0b/cO/GkJpTy0vC7blgi+fBUOe2UX3d8 6U9sFdryfwiynjOEmLI= X-Received: by 10.28.181.3 with SMTP id e3mr1455514wmf.41.1496320950160; Thu, 01 Jun 2017 05:42:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:50 +0200 Message-Id: <1496320911-51305-33-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::243 Subject: [Qemu-devel] [PULL 32/33] nbd: make it thread-safe, fix qcow2 over nbd 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" NBD is not thread safe, because it accesses s->in_flight without a CoMutex. Fixing this will be required for multiqueue. CoQueue doesn't have spurious wakeups but, when another coroutine can run between qemu_co_queue_next's wakeup and qemu_co_queue_wait's re-locking of the mutex, the wait condition can become false and a loop is necessary. In fact, it turns out that the loop is necessary even without this multi-threaded scenario. A particular sequence of coroutine wakeups is happening ~80% of the time when starting a guest with qcow2 image served over NBD (i.e. qemu-nbd --format=3Draw, and QEMU's -drive option has -format=3Dqcow2). This patch fixes that issue too. Signed-off-by: Paolo Bonzini --- block/nbd-client.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 09d955b..87d19c7 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -119,6 +119,10 @@ static int nbd_co_send_request(BlockDriverState *bs, int rc, ret, i; =20 qemu_co_mutex_lock(&s->send_mutex); + while (s->in_flight =3D=3D MAX_NBD_REQUESTS) { + qemu_co_queue_wait(&s->free_sema, &s->send_mutex); + } + s->in_flight++; =20 for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { if (s->recv_coroutine[i] =3D=3D NULL) { @@ -181,20 +185,6 @@ static void nbd_co_receive_reply(NBDClientSession *s, } } =20 -static void nbd_coroutine_start(NBDClientSession *s, - NBDRequest *request) -{ - /* Poor man semaphore. The free_sema is locked when no other request - * can be accepted, and unlocked after receiving one reply. */ - if (s->in_flight =3D=3D MAX_NBD_REQUESTS) { - qemu_co_queue_wait(&s->free_sema, NULL); - assert(s->in_flight < MAX_NBD_REQUESTS); - } - s->in_flight++; - - /* s->recv_coroutine[i] is set as soon as we get the send_lock. */ -} - static void nbd_coroutine_end(BlockDriverState *bs, NBDRequest *request) { @@ -202,13 +192,16 @@ static void nbd_coroutine_end(BlockDriverState *bs, int i =3D HANDLE_TO_INDEX(s, request->handle); =20 s->recv_coroutine[i] =3D NULL; - s->in_flight--; - qemu_co_queue_next(&s->free_sema); =20 /* Kick the read_reply_co to get the next reply. */ if (s->read_reply_co) { aio_co_wake(s->read_reply_co); } + + qemu_co_mutex_lock(&s->send_mutex); + s->in_flight--; + qemu_co_queue_next(&s->free_sema); + qemu_co_mutex_unlock(&s->send_mutex); } =20 int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, @@ -226,7 +219,6 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t= offset, assert(bytes <=3D NBD_MAX_BUFFER_SIZE); assert(!flags); =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error =3D -ret; @@ -256,7 +248,6 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, =20 assert(bytes <=3D NBD_MAX_BUFFER_SIZE); =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, qiov); if (ret < 0) { reply.error =3D -ret; @@ -291,7 +282,6 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, i= nt64_t offset, request.flags |=3D NBD_CMD_FLAG_NO_HOLE; } =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error =3D -ret; @@ -316,7 +306,6 @@ int nbd_client_co_flush(BlockDriverState *bs) request.from =3D 0; request.len =3D 0; =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error =3D -ret; @@ -342,7 +331,6 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_= t offset, int count) return 0; } =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error =3D -ret; --=20 1.8.3.1 From nobody Sun Apr 28 21:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149632235738083.06490853775074; Thu, 1 Jun 2017 06:05:57 -0700 (PDT) Received: from localhost ([::1]:44264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPnX-0007OI-P2 for importer@patchew.org; Thu, 01 Jun 2017 09:05:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGPQw-00049K-Vj for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGPQv-0005pw-A1 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:35 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33628) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGPQv-0005pq-36 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 08:42:33 -0400 Received: by mail-wm0-x243.google.com with SMTP id b84so11065812wmh.0 for ; Thu, 01 Jun 2017 05:42:32 -0700 (PDT) Received: from 640k.lan (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id g46sm6271438wrg.69.2017.06.01.05.42.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 05:42: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=PQKlGjXavOd0cep8nUfo3QDle7ci07fnvc976he2mdA=; b=MQRMSj4ATyFvF0rey7wOEWbT5Y/xMZmuL9FjZ/Sm69nN7aJPXHgFbetIyKX3Q/QtMj IuhtOa7Wq+oxBkcqDPpc3IWfczZGOeffqx4GTzKFCD8I6Fx8yfVH8YTjB56fip08i6yJ r5tFzTMLkdILOBJsrHq4SxmUpe1HVmj9PVme07GuSsrZKiKyI/UEenHWKP0tE06nfwOt IFvmZrA6XzPu17P4b4Ytgw34eNtqSe864W2C1SyqgcIMDzfuLB4QcBb0I58RFG63b/8I O4RwpVWjnwiqbGLkNq0r+XpMUBrE3IysFyVDRaxcAQoY/4zFA9n9AZh5EJ94G8Xr9gjs R3tw== 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=PQKlGjXavOd0cep8nUfo3QDle7ci07fnvc976he2mdA=; b=rW0Wpu+C2Ml/oALlFqpWQ7r32rkf2VTGO0dfedw/sR+GoAjWRMqvI8RHJOlxm/s01l qD1EFwD3v8T02pkUNDBdttjTwlIlxm4dJLbI1H66jLRp7eRIrBcW8m4M9pcjMMhPXVEu uLQj5kkD5fnuujpjVmsEYaiXUOFXhcR2i11tHz4Euuh+64zZtrwpqEj4iEQkM298hKJ/ w6zc7wBDJe2XBuu9UnCwAKTjTR3B75a8BtTrmlTMYpYmuLEE51jmdB4CNu72tXtLX+8i +1om38PUfvAWLvXHI3UbJx3mj3G8MEJMcaL0zfM/SA7mTC5w5rateUCeyXFaLoXGAVGQ ZBxQ== X-Gm-Message-State: AODbwcA+5hfHCjp6+6EdOAMq7/4HEwjgBGSHhOgGfmUE32eYEXgZ5uyl +5g9C2vKCDVqFCKwD38= X-Received: by 10.28.208.7 with SMTP id h7mr9499032wmg.53.1496320951922; Thu, 01 Jun 2017 05:42:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Jun 2017 14:41:51 +0200 Message-Id: <1496320911-51305-34-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496320911-51305-1-git-send-email-pbonzini@redhat.com> References: <1496320911-51305-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:400c:c09::243 Subject: [Qemu-devel] [PULL 33/33] kvm: don't register smram_listener when smm is off 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: Gonglei Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Gonglei If the user set disable smm by '-machine smm=3Doff', we should not register smram_listener so that we can avoid waster memory in kvm since the added sencond address space. Meanwhile we should assign value of the global kvm_state before invoking the kvm_arch_init(), because pc_machine_is_smm_enabled() may use it by kvm_has_mm(). Signed-off-by: Gonglei Message-Id: <1496316915-121196-1-git-send-email-arei.gonglei@huawei.com> Signed-off-by: Paolo Bonzini --- kvm-all.c | 4 ++-- target/i386/kvm.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 2598b1f..fb87bdc 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1748,6 +1748,8 @@ static int kvm_init(MachineState *ms) kvm_ioeventfd_any_length_allowed =3D (kvm_check_extension(s, KVM_CAP_IOEVENTFD_ANY_LENGTH) > 0); =20 + kvm_state =3D s; + ret =3D kvm_arch_init(ms, s); if (ret < 0) { goto err; @@ -1757,8 +1759,6 @@ static int kvm_init(MachineState *ms) kvm_irqchip_create(ms, s); } =20 - kvm_state =3D s; - if (kvm_eventfds_allowed) { s->memory_listener.listener.eventfd_add =3D kvm_mem_ioeventfd_add; s->memory_listener.listener.eventfd_del =3D kvm_mem_ioeventfd_del; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 6e7c197..8e3bbc5 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1255,7 +1255,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } =20 - if (kvm_check_extension(s, KVM_CAP_X86_SMM)) { + if (kvm_check_extension(s, KVM_CAP_X86_SMM) && + object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE) && + pc_machine_is_smm_enabled(PC_MACHINE(ms))) { smram_machine_done.notify =3D register_smram_listener; qemu_add_machine_init_done_notifier(&smram_machine_done); } --=20 1.8.3.1