Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3012940pxb; Mon, 18 Oct 2021 06:36:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpp0/99eXnNl8yfvvN2klpP4LaVuA17uTeqoG2PVzqBEAMTreAfyAlRn2jKHd1+LoCfT6X X-Received: by 2002:a63:7247:: with SMTP id c7mr19065292pgn.365.1634564161397; Mon, 18 Oct 2021 06:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564161; cv=none; d=google.com; s=arc-20160816; b=G+RKtmnQNBNF8Jr3Yi5M/9ZK02DCjtQm42d/BI0onWZKCYSPi1HwyqolUXJl66TU09 DVCVcOZXlvQDeLcSjyt6wUEEJEF5RCuFNlpYT8VMaabFuCvklzx1kWelfmY7wo9DiJ0/ kr978SfFuMcRzFb/z5hjYOtM6e7I1etUazGgUWwPmE5yGV8rBVhFA5wMNbI+cwmBeqD6 dOr4f1hRn/fis6c0wPos/WwRlvZfXXuPtTWwvmD2AMOltGO6Vz231gilsg+QqW5x5AT5 uku2covBLe7qK2XQ+wNy3fUvOtKoC61HXZ109UsafsAYwSAoVOP+mFO2wkngeXlhInuS gk3w== 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=2Lw0MHggysmIS9Q3COABqHItQLJteLAbG8zt7a/uUnw=; b=ZnYa3hnvp1qZYxrDwZyFg/t0fzHiNV2obUsMKMutUrvuJtfiahXszyW11AjE/anXTK TOHBrXKpwyBhgWfXXflU3SLuDlIyqM5Z91kB9atRfE0W4L7LZznYW43Z0H9BmAF8i9/U WV8bQxR7H/Xxg0NlwIe7H9i+pizsRN4y/0XSO38frTJGOpvurlStErLWXjVzjScAGipC 9TqNGdKAx+xMCKc+ZxlRyyfbckkg7GsXcoF5G5XODJV5Qr6S14OAplw9GrDkYjwSYHPb DRQyKLCpDKZg7ReHwZ61+tKfyVHtmWjSjz1vfutBlu8ory8mmoqG3pUwuwk0AB3gOb/q 4BSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Gdv1bea2; 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 e12si23086379plh.126.2021.10.18.06.35.47; Mon, 18 Oct 2021 06:36:01 -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=Gdv1bea2; 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 S232708AbhJRNg4 (ORCPT + 99 others); Mon, 18 Oct 2021 09:36:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:43996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232017AbhJRNfO (ORCPT ); Mon, 18 Oct 2021 09:35:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 11F96613A4; Mon, 18 Oct 2021 13:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563829; bh=jD8RYwNjAbLG2BhPBlqkqpOOhpaeDebe4lEESR7TIdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gdv1bea20BvEunYe0IbpAysR0+VSMTitNU5KtHKN4XYkySA94HRBVDO9xzigMqpLh eLGpGt1b6fbNc8UXwEBs8zAV/pgABI7JRI/36GwZcAAYJINvw8Y6H01RlqA/VWBSPD m1EmO8/byt95r9EFklfUvlPQUVwhvY/QbGLcW74M= 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.4 31/69] virtio: write back F_VERSION_1 before validate Date: Mon, 18 Oct 2021 15:24:29 +0200 Message-Id: <20211018132330.513541343@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132329.453964125@linuxfoundation.org> References: <20211018132329.453964125@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 @@ -225,6 +225,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