Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3010246pxb; Mon, 18 Oct 2021 06:32:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsaTlFUHo/qpJ5ehCSANuilR8dURcu07frXZQDjKfxHL9NQZr9UfQcrmk+W3swCPJ7WdYl X-Received: by 2002:a62:7752:0:b0:44c:eb65:8561 with SMTP id s79-20020a627752000000b0044ceb658561mr28993087pfc.43.1634563976946; Mon, 18 Oct 2021 06:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634563976; cv=none; d=google.com; s=arc-20160816; b=GIrPj+s6Twb/4u5SjyucW9Vw93Zj+oPPN5sUyCXCj/50UTZA5jTc85T2gVNyFjGbBf ln6FtHGED06srSSJK6fsWaf+cWG1ZkPDVx5ZBvsOGDJ3OY0j2V+JyldWaKSFyS8q3kWI IqOsHtH4u6F/3fvqwpstJcVP3n0v9yQ07Mm2gZTdQW5SkZod2xUz1qbXRbwfAt0YaSdd DuXi2BSBbfbhFpYtfdylDuqgeh/IOFZskrPNQ/7utJLLGYd/PPq3o83lPSMOueSL8K7M uT3ISs2LaQhhZAs3A6A6dmOlDBIw//P3PfTjLjJUWuAtJOnv8Td49eRzhCNexAjadCSP HY2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FdM0lSWLaowjLb3Wyf18QqctL+aQK5HjofT+vDEm54g=; b=CnBJo4nHEcfOgTQfTiWiYlznlU239iu4Y5XlhtJqApHnZg4fOHLMqznIQPgad7ii5W Yr43JXdUPKt7TJQul7o0CvfwlGztTVp2kLiV7rMQqBaXMXbGnL2L0HhHsiJlCxyLOzpy ZfL+8eU16dnXvM4K9SLrvijXxC2Bk1vcCF9ACQldS6ZTNtP81/7jMgPTtu2SchMpLXgI m96RG8tsxY/xr5xaxWGbY27ZAwcjlcYjgjTI/+bZPIKlzlgQr8h/vb1reA616KtgogHX KWKhPrGl/OxBWkmog0jTqu7CBetqqnsJ1ErFKFvst48atEZB1ybSmYD5zKV7at5j9hrF 2VbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LrdD8MjR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w70si20543183pgd.322.2021.10.18.06.32.42; Mon, 18 Oct 2021 06:32:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LrdD8MjR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbhJRNd1 (ORCPT + 99 others); Mon, 18 Oct 2021 09:33:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:43774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232450AbhJRNbd (ORCPT ); Mon, 18 Oct 2021 09:31:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1880D6128E; Mon, 18 Oct 2021 13:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563729; bh=1ADLGrEstFCqSsIQZXS9I2KSEQd1t78SzVMETSn9TUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LrdD8MjRKFkpw39VDjAQVu9kjMj/rHBgWh0Ys40mmmlX8yNmXLS2Al9HhoTQ0EqN+ n2hYGPVr+yFXOQtu8yxjjIdHr7sWFRuufM9KifkkI6UcJtd/Z1gQeVUoZuC5Cptf2z YA+tjUDZrnRTF7n34WjinHqa1Mo44qsZdWpjKqwA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Halil Pasic , markver@us.ibm.com, Cornelia Huck , "Michael S. Tsirkin" Subject: [PATCH 4.19 24/50] virtio: write back F_VERSION_1 before validate Date: Mon, 18 Oct 2021 15:24:31 +0200 Message-Id: <20211018132327.338374122@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132326.529486647@linuxfoundation.org> References: <20211018132326.529486647@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Halil Pasic commit 2f9a174f918e29608564c7a4e8329893ab604fb4 upstream. The virtio specification virtio-v1.1-cs01 states: "Transitional devices MUST detect Legacy drivers by detecting that VIRTIO_F_VERSION_1 has not been acknowledged by the driver." This is exactly what QEMU as of 6.1 has done relying solely on VIRTIO_F_VERSION_1 for detecting that. However, the specification also says: "... the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device ..." before setting FEATURES_OK. In that case, any transitional device relying solely on VIRTIO_F_VERSION_1 for detecting legacy drivers will return data in legacy format. In particular, this implies that it is in big endian format for big endian guests. This naturally confuses the driver which expects little endian in the modern mode. It is probably a good idea to amend the spec to clarify that VIRTIO_F_VERSION_1 can only be relied on after the feature negotiation is complete. Before validate callback existed, config space was only read after FEATURES_OK. However, we already have two regressions, so let's address this here as well. The regressions affect the VIRTIO_NET_F_MTU feature of virtio-net and the VIRTIO_BLK_F_BLK_SIZE feature of virtio-blk for BE guests when virtio 1.0 is used on both sides. The latter renders virtio-blk unusable with DASD backing, because things simply don't work with the default. See Fixes tags for relevant commits. For QEMU, we can work around the issue by writing out the feature bits with VIRTIO_F_VERSION_1 bit set. We (ab)use the finalize_features config op for this. This isn't enough to address all vhost devices since these do not get the features until FEATURES_OK, however it looks like the affected devices actually never handled the endianness for legacy mode correctly, so at least that's not a regression. No devices except virtio net and virtio blk seem to be affected. Long term the right thing to do is to fix the hypervisors. Cc: #v4.11 Signed-off-by: Halil Pasic Fixes: 82e89ea077b9 ("virtio-blk: Add validation for block size in config space") Fixes: fe36cbe0671e ("virtio_net: clear MTU when out of range") Reported-by: markver@us.ibm.com Reviewed-by: Cornelia Huck Link: https://lore.kernel.org/r/20211011053921.1198936-1-pasic@linux.ibm.com Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- drivers/virtio/virtio.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -222,6 +222,17 @@ static int virtio_dev_probe(struct devic driver_features_legacy = driver_features; } + /* + * Some devices detect legacy solely via F_VERSION_1. Write + * F_VERSION_1 to force LE config space accesses before FEATURES_OK for + * these when needed. + */ + if (drv->validate && !virtio_legacy_is_little_endian() + && device_features & BIT_ULL(VIRTIO_F_VERSION_1)) { + dev->features = BIT_ULL(VIRTIO_F_VERSION_1); + dev->config->finalize_features(dev); + } + if (device_features & (1ULL << VIRTIO_F_VERSION_1)) dev->features = driver_features & device_features; else