From patchwork Thu Jul 28 13:55:02 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: 594071 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp526499maz; Thu, 28 Jul 2022 07:06:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uBypUqWn8JJkp+tB+UTe1sxmnEY+5sqEUOnhMmNRavNOcrRtPcn7VbNza8W2pmJ9j/7qgO X-Received: by 2002:a05:6214:234d:b0:474:6000:44a4 with SMTP id hu13-20020a056214234d00b00474600044a4mr13500778qvb.6.1659017190014; Thu, 28 Jul 2022 07:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659017190; cv=none; d=google.com; s=arc-20160816; b=tm9Zm0DW+ByLWYcf8DNEXfsyMbt+MaPKYk0nYGLQZ1DM8ZT1DyXbXxY6UZs1Lf6gFd I/HP8fLFVb6TK7Ca++TvAbVHJhbFmJTFAAUJxmeZf0cqVMzHx+A1Iwrxp978P5i3luf2 6ZcE3OsGf+ILA44Uz587HM0jYetLhwfG2alqXiu++cfr6JgCfipbwtjHH57Ni9PgNyIK k2aSdkG3/2+EX+zYY6wXhYImwnVw0RIvalxqw9uFknHkobGjT1tzM8Wo3kD9txabhySG E0GLYCmaOKSHJTCEeuYsnz7oTbB+5tItGN97KyMVpZw4urnrdBvcV2I8PUvtz+lbFMl7 FsUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qn9sIffAzV9IF+yjjzIzifr78tit+1ZOBIt0UyqO2Rk=; b=CzrFrBpI5qHIxgOqi4D4ZurxG+eM8FgfmhOwD2AdeWOkRbHNFzHQ4XRbXkfivw+FhY L6npi/foQrpNDOw7hVUH0kQ2cY4MliyjkIdPWMSyQ9dVq+VF5cV8bokRU+gPwkmd5ofh 0ucO9EQnsAshaAGhX+dAgmYLP5sQs/QZE04L4GSnrYQFWgATBTllzI+6SqARrwcX5AJ9 zfEZtU7hj9Vhi8P+pdLXDrdwiUShezvzUw/vzaGO3RTwmBfjzzcyhRPol6MaWD5np7YY yw5VglJPTFZDzqbxG15jgSx0FN7zO1VUmVLww9jFYiuKt1pLtAaykdBER+kZa71wRy5k qvqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sgPyErci; 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=pass (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 hf4-20020a0562140e8400b00474835244d7si546566qvb.125.2022.07.28.07.06.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jul 2022 07:06:30 -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=pass header.i=@linaro.org header.s=google header.b=sgPyErci; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oH49l-0003Xd-Hp for patch@linaro.org; Thu, 28 Jul 2022 10:06:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oH3zC-00040t-N0 for qemu-devel@nongnu.org; Thu, 28 Jul 2022 09:55:35 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:38778) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oH3yw-0000OI-B6 for qemu-devel@nongnu.org; Thu, 28 Jul 2022 09:55:34 -0400 Received: by mail-wr1-x435.google.com with SMTP id k8so106449wrd.5 for ; Thu, 28 Jul 2022 06:55:12 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=qn9sIffAzV9IF+yjjzIzifr78tit+1ZOBIt0UyqO2Rk=; b=sgPyErciTNQttlWPS4JPv27YVf7tmojFhsZR9M/WZngizsHWCfovQpwMgyaCu3WxyN +ZWRwuKuS4XX1chuuVcV6JTIEVeywSGfzz0iMHQ7+hBO0Uz10nO0wZxtdfuriBZeI3su +WuGzOonIXeVtU4Y1YQmHHXd6NwFNlE0NZs4HBGRSVbCdBSKjKPsYQqHfTYae42/tMcN RRMYRD1sNkK77Vmg5WXBTcOWeT+O9blgS8mWNLbpOqbL94u+RaJiqAK1NBDLduRTjOSI bW+S01sSi2lvy/XJudEcIXf20iGdBa/He+6CG6I2scyT48KHrG1+RD3jZrt8lgUPARd6 mz9A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=qn9sIffAzV9IF+yjjzIzifr78tit+1ZOBIt0UyqO2Rk=; b=0hGtfqPMELLiBe8nt6XgaDKdXKDoyVmDtlQG0/y0yR+i1dG9D9ERTvRQa13TL8tQfR QZ0R/JrrirLF5It5u8Lay3zCHIcay5rRM0fhU5c2iSasbNMyxFsYPitpex4SpHzNFsqU 3D3YR4oCMA8bAjfMUS02R/iNyd8Bj+t2baf6zTjoSqOgtvTrmgZxtDd8oJ/ll1geq+EC otsk06DdPxnaUK1Q5gfhgiKRjzFkDGphL+sHH/g6AC8Rf3tOjveixp7LsHh+cvzAYpX+ Emuc7AlnIVEAvRO0+MNLZXuqoq4eLu+OxPm5VOmXdhY7QaY45T7427EJrqKJBGM6vwVH lQpQ== X-Gm-Message-State: AJIora++aRlZ7oK1Pw8NM4Ry4bCLL+eYKAZaANbpnzPqZ2XkCS/GOBeD U9uSY360pC8bhXgmUvoh2zGlxNi+LMuB7w== X-Received: by 2002:a5d:6642:0:b0:21e:f918:b093 with SMTP id f2-20020a5d6642000000b0021ef918b093mr2098786wrw.173.1659016509030; Thu, 28 Jul 2022 06:55:09 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id l21-20020a05600c1d1500b003a326b84340sm6114560wms.44.2022.07.28.06.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jul 2022 06:55:04 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DB9871FFBB; Thu, 28 Jul 2022 14:55:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: mst@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v2 3/4] hw/virtio: handle un-configured shutdown in virtio-pci Date: Thu, 28 Jul 2022 14:55:02 +0100 Message-Id: <20220728135503.1060062-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220728135503.1060062-1-alex.bennee@linaro.org> References: <20220728135503.1060062-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x435.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, 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The assert() protecting against leakage is a little aggressive and causes needless crashes if a device is shutdown without having been configured. In this case no descriptors are lost because none have been assigned. Signed-off-by: Alex Bennée Message-Id: <20220726192150.2435175-9-alex.bennee@linaro.org> --- hw/virtio/virtio-pci.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 45327f0b31..5ce61f9b45 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -996,9 +996,14 @@ static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) nvqs = MIN(nvqs, VIRTIO_QUEUE_MAX); - /* When deassigning, pass a consistent nvqs value - * to avoid leaking notifiers. + /* + * When deassigning, pass a consistent nvqs value to avoid leaking + * notifiers. But first check we've actually been configured, exit + * early if we haven't. */ + if (!assign && !proxy->nvqs_with_notifiers) { + return 0; + } assert(assign || nvqs == proxy->nvqs_with_notifiers); proxy->nvqs_with_notifiers = nvqs;