Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3027963pxb; Mon, 18 Oct 2021 06:54:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLUJ4lOK7M0M/wJQwNmnlih2RKhvEEYqA+n8ESPFosCze6gly4QRlOMKA75BdvZAkdxMMI X-Received: by 2002:a17:903:2303:b0:13f:e63:e27d with SMTP id d3-20020a170903230300b0013f0e63e27dmr27075646plh.84.1634565290016; Mon, 18 Oct 2021 06:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565290; cv=none; d=google.com; s=arc-20160816; b=ZH6iu3l6TXA5LTMpGC4hNaZvXcttYM9dtxzd9L29vN8b2ioLmfru+4xc6rnEcXwQcx ooN+ldFVVa/vTxNDaIEfKZ/KwEHLjABuCnSrYgYu98M0ZqlypoLgNGCp+kRBOJyYHEgb Kbfkqm0bZC3gcuSoDrLRSUSQR2bwkqSr5uOZW41KXHhnFtcOO50xKvRfY2pcaZFE0alm 8qNY1e+lXHyl0brNDYJJH2EWo+QHr6BxPLw4nF7Mh2JncuqWLduYg8dpjDXqOqQf/Dvi 90VJXrLE76HLKJsru+5y4bocy5R8tD7KbFwIhoR/pwvQXurlqpDqCubkaXo2/egm6hVU 4CUQ== 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=MlXDz78YvqMvIaDt/Egz+AUJFHcyMDUxdITDLgW0nGw=; b=F72dAoofhBXubftkScqNT5+2j1irI83MQ8Jfro9uex+3cobs2aB4LpNyiawv6HJ4vO jGK38ggoZgNkDWKluLgKTcST90IEl9zS1ReSRAvWBDl4xCJVqL/daxClBciI4V9jNJBi 1SJZjo9fvEFi4uj1xnBeGzQ/Sg3Zd/+hrHW/qenD+bFPc7xu7/fvg2S188+V5bNdN4W4 donxdD4ufWaMTo5FBmfoLjMYFs1lvDQajpbkgiLLmO+tHFpPRgEtRSwxT8iw2Q6frZ+K m8nxNO5Qaav99R2hjSuGUyBbI0c0/rB0QDhuR2vWajVrCkhZu3CogfvP0lXOll6wM9Cx TnRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CYGFXIe3; 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 g17si14907785pgk.528.2021.10.18.06.54.37; Mon, 18 Oct 2021 06:54:50 -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=CYGFXIe3; 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 S233428AbhJRNzs (ORCPT + 99 others); Mon, 18 Oct 2021 09:55:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:57710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234308AbhJRNxS (ORCPT ); Mon, 18 Oct 2021 09:53:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0BF51619E1; Mon, 18 Oct 2021 13:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564348; bh=wt1KKO2f0iDH4FjTaEdSsFZ8qzOlJAGvLTZBFhVvTpg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CYGFXIe3oMDi7hCGU6gPsj8UpOBy2vnoGr3mzm0G9VoUI77WCBSDspQGjIobbb1iG gDAFuA2RAtohLuE75bAGZgoNkSTl0b0oBgdE11JdypSBDY7Mq3IdiMfcOAokM9ywQa vvO0hnSHV1dlXjXYCIcc3FaYuo39N1CDzwuSZ8P4= 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 5.14 055/151] virtio: write back F_VERSION_1 before validate Date: Mon, 18 Oct 2021 15:23:54 +0200 Message-Id: <20211018132342.485325805@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132340.682786018@linuxfoundation.org> References: <20211018132340.682786018@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 @@ -238,6 +238,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