From patchwork Fri Dec 13 09:54:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 181531 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp407753ile; Fri, 13 Dec 2019 01:58:49 -0800 (PST) X-Google-Smtp-Source: APXvYqzkRhBG4h+ant4lWDaIvNoRRQvh6XI/ppASeNB1qz5XhwSrVVwAyu6pBKAbZ0KhCSKjK3Nl X-Received: by 2002:a9d:6b06:: with SMTP id g6mr13869224otp.93.1576231129593; Fri, 13 Dec 2019 01:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576231129; cv=none; d=google.com; s=arc-20160816; b=Fv411fDzfiUIfkbSzbltGCXFk047SHs0M1OtEAVck8xeVWDcVMfIqBhgAqsPoNBeEm Lw1fQPlpTToYn/qvSUdAOHvRbiJgiKXjnReNeDqZRGBtRLqGZFwlcLzgzOVz9eqeEtQy emtLSki4KOrEHK4/cUss6QsoxLZrhq+VWefhpLC4pbSiDksrcJPzRTxJOxN+14JNA6r2 bUbWHaCItpd4vxexfsTIzLTpRzsvE2IoUBG9+fz2dUH/SZOeEb8VAMWLg86skSD3p1an snz0tPiuctlWkSGVQx3ZhgZjNT7aOkC2tm/iK1SKySfFcjkTokPJPP75j41lg5vRV0UT r7Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=rc863mpgWMbIDtGydzeePchhIO4jO4tkazPeQWspVtQ=; b=EeObkqJwfYMSWuF8lh0P8jR56ka+uxic/wffvVo8hFyabB8sjWOlQ2rmJ20791bEXy cYdLj6ATWVadMr1ihqtmj7ERJ8EELqMDdFnW57neE4+Veu5+C2vMk961Y8Ok0WNOMOzF XIwP171QAM0mj7yjbSCj6WeXwv12G+ZCtak1f0Cz+kN6CriRQG4ju0aVylgfswk5mMnp 1eYp06tJKp/rh8CisgDJ5aP49JioQ2hPllqNpF8PHbzm7K8aMQkEdJ2PGgdhtbnG/DFd vrycfQXslcZAodluaNc7yEO6lSq+8Sm/ygE1lJKn6diWW5Y1oZaAkFT8vYZJLSZjOCUy WWAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rwv+J8Dk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d20si4874475otq.157.2019.12.13.01.58.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Dec 2019 01:58:49 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rwv+J8Dk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifhij-0004od-0g for patch@linaro.org; Fri, 13 Dec 2019 04:58:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53685) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifhia-0004oX-LI for qemu-devel@nongnu.org; Fri, 13 Dec 2019 04:58:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifhiZ-0004hp-9F for qemu-devel@nongnu.org; Fri, 13 Dec 2019 04:58:40 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:44307) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ifhiZ-0004eA-1n for qemu-devel@nongnu.org; Fri, 13 Dec 2019 04:58:39 -0500 Received: by mail-wr1-x441.google.com with SMTP id q10so5921432wrm.11 for ; Fri, 13 Dec 2019 01:58:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rc863mpgWMbIDtGydzeePchhIO4jO4tkazPeQWspVtQ=; b=rwv+J8Dk8zicF6PQMqfISUo+MB/gNW3NHpuoa/UD3F1fQiJOjK+6uA9DdlDo5Jtsii 3TWkOvp/UYelHlU4F7VuT41lAxxaJdP01GemAF/LE6mQDt6zlmjygiG5AnzuNoWadlmS SlyTyu4p5+VzklyRC5IZCkc1R643iNmFLnEZgma3oLlVrH0jXYe6GNnKgzlnPxqXmxCr 8ggyYR8JS+PEJrXkPsTozc9BEsBTB43O1T5n2KqyOmHj+VzImrQW0w9c4cYfRkoZGnET 1Idoo6nxAelW03GjMskxMyTrzmf0wHva4O+3+ed3RMk3MANdw5OwbzY8jfMEBZ/Rb81Z O0Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rc863mpgWMbIDtGydzeePchhIO4jO4tkazPeQWspVtQ=; b=LajIqBdk9+QkU+OvpvdvtvIExMT0BB6btxc9gNqAYXegI1seU0P/ETiqAGc3AhBI91 OnkHeUgkC1RkcvyDNxRzk12Ir876IX5TrkMCn+UEIQ3q4souPnrQHwfAo5favPZc/jBX vH2bhO/wL3m6ZVJt2NyO+tW5KrHMfByfDkZK+GTCXEyayvZ8G35pyJPPsTBTskTaEwKx nSIBWDbjdBg0Ff6MFnW01/KWF+yfOFv2K9U3ziTp5LOPMPw6traRhIt66T2BfISRitAM pnYsprKeooA1yHOW2oa7wML2D8KqVLhM0jRpvMo6fFGKiJ29YX817cMRJTi+w5kGm04h e8tw== X-Gm-Message-State: APjAAAWgdCR3mEACZLmCQ2L8GIi7J5pgteVgt/KrTIpzmk6MJRYTvUlT cFBiZGeakxudtF/xff7n32kcX+ocrUw= X-Received: by 2002:a5d:5381:: with SMTP id d1mr10691117wrv.259.1576231116841; Fri, 13 Dec 2019 01:58:36 -0800 (PST) Received: from localhost.localdomain (adsl-84-227-176-239.adslplus.ch. [84.227.176.239]) by smtp.gmail.com with ESMTPSA id b17sm9417051wrp.49.2019.12.13.01.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2019 01:58:36 -0800 (PST) From: Jean-Philippe Brucker To: qemu-devel@nongnu.org Subject: [PATCH] virtio-mmio: Clear v2 transport state on soft reset Date: Fri, 13 Dec 2019 10:54:10 +0100 Message-Id: <20191213095410.1516119-1-jean-philippe@linaro.org> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: slp@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" At the moment when the guest writes a status of 0, we only reset the virtio core state but not the virtio-mmio state. The virtio-mmio specification says (v1.1 cs01, 4.2.2.1 Device Requirements: MMIO Device Register Layout): Upon reset, the device MUST clear all bits in InterruptStatus and ready bits in the QueueReady register for all queues in the device. The core already takes care of InterruptStatus by clearing isr, but we still need to clear QueueReady. It would be tempting to clean all registers, but since the specification doesn't say anything more, guests could rely on the registers keeping their state across reset. Linux for example, relies on this for GuestPageSize in the legacy MMIO tranport. Fixes: 44e687a4d9ab ("virtio-mmio: implement modern (v2) personality (virtio-1)") Signed-off-by: Jean-Philippe Brucker --- This fixes kexec of a Linux guest that uses the modern virtio-mmio transport. --- hw/virtio/virtio-mmio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.24.0 Reviewed-by: Sergio Lopez diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 94d934c44b..ef40b7a9b2 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -65,6 +65,19 @@ static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy) virtio_bus_stop_ioeventfd(&proxy->bus); } +static void virtio_mmio_soft_reset(VirtIOMMIOProxy *proxy) +{ + int i; + + if (proxy->legacy) { + return; + } + + for (i = 0; i < VIRTIO_QUEUE_MAX; i++) { + proxy->vqs[i].enabled = 0; + } +} + static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size) { VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque; @@ -378,6 +391,7 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, if (vdev->status == 0) { virtio_reset(vdev); + virtio_mmio_soft_reset(proxy); } break; case VIRTIO_MMIO_QUEUE_DESC_LOW: