Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3019002pxb; Mon, 18 Oct 2021 06:43:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzS4nwF4nev/X01dglCG22fwPGm2bk11kgm6FIW+6p9KfyXiguqfJ6WDi9P2+Zzcs1miyc X-Received: by 2002:a17:902:7fcf:b0:13e:c994:ee67 with SMTP id t15-20020a1709027fcf00b0013ec994ee67mr27221853plb.12.1634564606040; Mon, 18 Oct 2021 06:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564606; cv=none; d=google.com; s=arc-20160816; b=BNcPb2O65Z3P0Jggnyfni0C6DH3yJLWO7pAqMEHriinhd2ZktCuNwk3EupjPRddO0e pp4OnYfp9/8oCgHDM1eDp0aNbZuRJbTpRFVz/zpC4caGOfck8eQeMkfbU5xEXmYuVhQo NhphDLaHFPY00hQvx3HxoIcifG2Gjukw73FEei2E8RiQtY+qM1vRMhlnevuolW0HjFMu G8r42BSyPAYFOMuCfGs6O+h/Q0/42rp+ItFFcJ/yuZYIaoyCZ3JgRLtA4eWJAkzj9SNF rL0Aqyiqj8Zh5ObvuyHtMG92t5p/89M/lNK6JutPpO2H0/m5SXG4O/5MFtFPgmNA1qbe qjUQ== 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=o9/5beFzI2/Gpo5Z5e1CfEiDJn5jWQpXe2430nL0jAE=; b=SiKsXl74FXTbVqkWF3eHAKpYUnwX0f4cKxXOtpHgAiIb1eIHDOHCrtEBv3ShiwTlfi MoFvG7H3gfiCwvj+oe7qnwhW76uBd7aS16gp25IPipzgIASy1Cxyy8EYDXQLgRaDONzD bEojhjFHqP5iuELAL1nKbdyfJNpad7g5h/OoGZjkJRqk6WQfRX9R/4i8Bzrhl78Hewug P5VJ+EkYNmFtqh/IlpF8oKn8NPFtLXKSrY7SUYcQ37169JPCx9jIa7ihO/GHLANh6AnQ kWgZc4N57XCR4POK8M6fd8isOU6J6W3BNM6luxq/ULEmHnIPYNvtq5snLSUJ3K6eh/89 M9+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=STzmMvBv; 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 l13si23357455pls.248.2021.10.18.06.43.12; Mon, 18 Oct 2021 06:43:26 -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=STzmMvBv; 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 S233674AbhJRNoM (ORCPT + 99 others); Mon, 18 Oct 2021 09:44:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:39094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232934AbhJRNmN (ORCPT ); Mon, 18 Oct 2021 09:42:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1B26961502; Mon, 18 Oct 2021 13:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564040; bh=UIDBhV2mo5XJ6O4cTODOgyRET1/Q1EOHmTKga8/6W+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=STzmMvBvUfGirkdZ01AC2q/BLaqVsP8ontAvs8fcCz1vPKEywtYv6YD98Mbqjte2T neueMWfZcOmNo55ooI4bEtV3S99/HYyo148WD1IDJbKD+EzRP35vn5YRi0o71Ey1dk aujLFQACdn/qojRdpCO2e/Usksr0CNGKzRL7fd+Y= 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.10 041/103] virtio: write back F_VERSION_1 before validate Date: Mon, 18 Oct 2021 15:24:17 +0200 Message-Id: <20211018132336.097237458@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132334.702559133@linuxfoundation.org> References: <20211018132334.702559133@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 @@ -240,6 +240,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