From patchwork Wed Apr 6 17:33:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 558324 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp1120159map; Wed, 6 Apr 2022 10:35:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywh8jP2eQWG8zzTA7sCFvdlrvg5+40N5aKW96sBViPGJlqSnEjxV0m13YNd4nn97ipmCl4 X-Received: by 2002:a5b:7cf:0:b0:623:df1c:b83d with SMTP id t15-20020a5b07cf000000b00623df1cb83dmr7199509ybq.75.1649266526533; Wed, 06 Apr 2022 10:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649266526; cv=none; d=google.com; s=arc-20160816; b=NaTqlpzCGmXeEJYtkV1XgRHxR66R38onocxiOX0HVDHe9mJgWdIOfP++VCzdUH5/29 l3CLXRr+JXqTylpHasl5RLDEzNCMNa/cwAoqIFUKabDao9Sc7DmNLWpQxhEc12hseiNx 0uX/C+f1QyeiXMWCmLuLnYOfTwaGnn86VVyeBRON7RUC+DdrtRu5ztJmMefCbFafUTIr JAUHb3M0qBiaVadW1KNv2e+AcjFwqMDVddrSa6c8MuWv2VAxxyRb2sFg4tAVOFgvBQ1t xbKCROAb+uBzSmWSsqrIa9BpG/XxSVawxKKf24KfMRy1ycCb+/YZ8GxjhnSTHFwyPuKR xphg== 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=zJhJE0L1jlhUd2sHuMKxqOvmmtQD0eXyLIqAEEV6JQ4=; b=f9FUHiuh9fxkiDzSHzd4lycofDNiynUTm9ZhmIa3ZY04+D7ArNG9qGWSXJO0L6788r 4My9TOG6FEEd9Gr0TvfysvrG89niHhgioOs1x5wUcmNZPjO0queJZTxpaZtNuESIweSz 5uUGfki17/YDtoUdG+KiMHqLrCNW1f7EBCEhoLvA+zSxYT3VY68IEcLu0yYvaiq60CnO z/evNcyjfqCmrkn3r3S2gQBL3zMMeDclLy/xskcuAXx7t4ck81Hh1bjWGH/uXHXCZQdc FHdhxI0gb/KIILnp7nnvvSbu85VLGw6VRfZOa+sWY24wWCbfmhMsjfi3xdqPWjSEY39H FVsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TXn5Y0AE; 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 b5-20020a251b05000000b00633994043e0si12123998ybb.74.2022.04.06.10.35.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Apr 2022 10:35:26 -0700 (PDT) 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=TXn5Y0AE; 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]:55086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nc9Z0-0002wu-1Y for patch@linaro.org; Wed, 06 Apr 2022 13:35:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nc9Xm-0002wl-Cg for qemu-devel@nongnu.org; Wed, 06 Apr 2022 13:34:10 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:42956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nc9Xk-0002P2-JT for qemu-devel@nongnu.org; Wed, 06 Apr 2022 13:34:10 -0400 Received: by mail-ej1-x634.google.com with SMTP id i27so5727545ejd.9 for ; Wed, 06 Apr 2022 10:34:07 -0700 (PDT) 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=zJhJE0L1jlhUd2sHuMKxqOvmmtQD0eXyLIqAEEV6JQ4=; b=TXn5Y0AESTrepH955fOd8bd2N4wlfRVidu4imVaUyHvy/sh3Y25UdbQtwOdPSZFlZ8 yyw5QMigkDXiMM18Uc1+lqZWmbjZHrF7AOxpyJ4bxJ+Un0hHh9rmbCiyyEVnMsOXV8MG YgLvvL5Q9KnfFh6eR4wbxojQHFYOXKNuy8sD4r50jntFO1jQCwn1/Y6FQKdM1DO+cGWJ 83pTjRuy2vKlWFBsWBCP5GrrvWZh4pc/jF4bwWSIxFK0yaUaLGuLLyLTJiXosO6vVUS2 kuvVyvH+wJLg9dz6ahz+ZzWkAr9xjxxZKYhCBnryTUPk+1WiIDjgrD/Uv5dKQSwx/f0c vfpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zJhJE0L1jlhUd2sHuMKxqOvmmtQD0eXyLIqAEEV6JQ4=; b=DcXQPVCazP9WcmhEwqc89b4tDjFpqRLZnnBqNsTGTuekQ2PGjT0/Gv3SWEn8Q4+zao PzCKp6ro1O4ti7Ki33n2LuRQlsTzAQIJArBJIHxFMa9qWmjOdCxJknOnfVWdLNqJIvkP ++q0IOjZ7iVVuMuRs9SOucM/ud7eOu6Wghf9KurDDXdjbLGAB9E+IjztXDlSUWkRgUu1 kmKrfgUPK/sZ+hHtE3KOZJ7d6oxsFNUVSCvxSIPWQnDgQh/7vXL7RNl7OphUMBdfOIOp Ffp+TEPuQxlf+WKMkr9fUQi+pSEYOe+ShkUex3O+B20aJKRt9LuJjrw6uppkTA3XqMgL og2w== X-Gm-Message-State: AOAM533+1Efia6yfNmPuZqjiPIxbHZkN+4cfNMt6gpJKcXpb+zLYHJyo aaR5MANkpc5lJV1Ur6j2r57UmA== X-Received: by 2002:a17:907:6ea2:b0:6e0:4ef5:1a2c with SMTP id sh34-20020a1709076ea200b006e04ef51a2cmr9309231ejc.350.1649266446506; Wed, 06 Apr 2022 10:34:06 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o17-20020a056402439100b0041938757232sm8198513edc.17.2022.04.06.10.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 10:34:05 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7CF671FFB7; Wed, 6 Apr 2022 18:34:04 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH] tests/qtest: properly initialise the vring used idx Date: Wed, 6 Apr 2022 18:33:56 +0100 Message-Id: <20220406173356.1891500-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Michael S . Tsirkin" , Raphael Norwitz , Eric Auger , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Eric noticed while attempting to enable the vhost-user-blk-test for Aarch64 that that things didn't work unless he put in a dummy guest_malloc() at the start of the test. Without it qvirtio_wait_used_elem() would assert when it reads a junk value for idx resulting in: qvirtqueue_get_buf: idx:2401 last_idx:0 qvirtqueue_get_buf: 0x7ffcb6d3fe74, (nil) qvirtio_wait_used_elem: 3000000/0 ERROR:../../tests/qtest/libqos/virtio.c:226:qvirtio_wait_used_elem: assertion failed (got_desc_idx == desc_idx): (50331648 == 0) Bail out! ERROR:../../tests/qtest/libqos/virtio.c:226:qvirtio_wait_used_elem: assertion failed (got_desc_idx == desc_idx): (50331648 == 0) What was actually happening is the guest_malloc() effectively pushed the allocation of the vring into the next page which just happened to have clear memory. After much tedious tracing of the code I could see that qvring_init() does attempt initialise a bunch of the vring structures but skips the vring->used.idx value. It is probably not wise to assume guest memory is zeroed anyway. Once the ring is properly initialised the hack is no longer needed to get things working. Thanks-to: John Snow for helping debug Cc: Eric Auger Cc: Stefan Hajnoczi Cc: Michael S. Tsirkin Cc: Raphael Norwitz Signed-off-by: Alex Bennée Reviewed-by: Stefan Hajnoczi Reviewed-by: Eric Auger Tested-by: Eric Auger --- tests/qtest/libqos/virtio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/qtest/libqos/virtio.c b/tests/qtest/libqos/virtio.c index 6fe7bf9555..fba9186659 100644 --- a/tests/qtest/libqos/virtio.c +++ b/tests/qtest/libqos/virtio.c @@ -260,6 +260,8 @@ void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq, /* vq->used->flags */ qvirtio_writew(vq->vdev, qts, vq->used, 0); + /* vq->used->idx */ + qvirtio_writew(vq->vdev, qts, vq->used + 2, 0); /* vq->used->avail_event */ qvirtio_writew(vq->vdev, qts, vq->used + 2 + sizeof(struct vring_used_elem) * vq->size, 0);