Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3295337pxb; Wed, 13 Oct 2021 03:12:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbWaoVZwtkJUo7NYWWJhqLW8pYofKAeZGKanBgSpeblAbOVVhZD4/IGslUyCZNTrBR20D/ X-Received: by 2002:a63:cd48:: with SMTP id a8mr27333029pgj.180.1634119953779; Wed, 13 Oct 2021 03:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634119953; cv=none; d=google.com; s=arc-20160816; b=D/Jb0I3Jb43RZlP/pr6qr0qewAvtuxBoKTmM+SxJQiHeXySEfxb81L/TYGmyVkZsUM vKfKDSSkvD5TgfJlpGgnBI5qJ4bq3BntWOID4bAtz2haPxYFFgPieHNf23ibhq96z42H OSbrqvEztDipp5Y7Q+aX3PE7/GuJhOhiYLs/NyobQuwjn5BZ9ktNwvvki3/V+I5CLxpu TY2Ji/2A03BcU4XL4Y40SP9Xeo/I0q514epUteRuRX36L9lloZ5K5ZwzvK5qxlOB6TZQ /ZqS4stEWyhh1xMlVbN+iI/AyfN0Zq3lCrMVMwpJQEcOcw+QAZXtUEm+ya7zcmuaQQ2s Y5gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XIV6EWlf8IYh7mOxA5NB+uuQJyLxn6kGVxkuMI5GYog=; b=pbvXWJejUh0twFF+VjRNnTC9rTrjqxIwhzpTl+nWlMjWNn8mfvsuJjbtrRv6qhP8N6 wyeamGBi5TQ32B1PgVsl/E5aJjMmpglEnOh43LGkpnAKHYkvCUPsSMlOgpD2DJCPLfss i74U+ekTbV9HDxhtQEzkx0NbSfX10hmonzE9Cwz2oVGtLAa6EZH7F2j8sw8l6wPY6Jxz OHLwlr8fBbzyOlMENFMtHtAQ54t83nAfNGXwDx9pHXPPwRh7VB5FydQk65IdJG5JQzq4 ACVkOPK/Za82tV0rbWWbD8UoJB7y3mfSFtasxdvv2owFO98wDXy6F38d2IbCW7lFUWX4 5ZBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bsGly8ZB; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i6si4022904plr.36.2021.10.13.03.12.21; Wed, 13 Oct 2021 03:12:33 -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=@redhat.com header.s=mimecast20190719 header.b=bsGly8ZB; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239124AbhJMKMU (ORCPT + 99 others); Wed, 13 Oct 2021 06:12:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52269 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbhJMKMT (ORCPT ); Wed, 13 Oct 2021 06:12:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634119816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XIV6EWlf8IYh7mOxA5NB+uuQJyLxn6kGVxkuMI5GYog=; b=bsGly8ZB84YYvX2eeaAnMpAK+4QdXYnJ6Yq9s9K8I2nvyQBa5fu16RHLd4OGAEAfmEaFAF cVHVBEQBwijOqKjvlTd51weOsrFi8T3rBWl5JuXAjF8pMV+n3cYcQPFcnDQF96xjKow792 B/J+A7JltqQ2C2qwxBVVxOvjYpqdrGs= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-444-bLts38bLMlK6FLgrrKT4eQ-1; Wed, 13 Oct 2021 06:10:15 -0400 X-MC-Unique: bLts38bLMlK6FLgrrKT4eQ-1 Received: by mail-wr1-f71.google.com with SMTP id d13-20020adf9b8d000000b00160a94c235aso1595085wrc.2 for ; Wed, 13 Oct 2021 03:10:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XIV6EWlf8IYh7mOxA5NB+uuQJyLxn6kGVxkuMI5GYog=; b=qGbUVtWzLiU6Zz+vtPaJYYF7taF9pX18wC8tKTtCiJa0cnmfQDUD7v0Iv0zUtdCUe+ UjJ+DWFJ8/yycZkkvPSYrNGOqG0VUvTAJnZPSmJGqksSMy/95q6apVQT+kusFPEXuPkp V+ir5TJd+RDHmUFsunFBWmkSlZ+qESz1u9BMQuavCT92jI/I6nPIlqFpFOve3VIKYVzi 8c1TfMq3nvoAimXVY3pN3EdnpLfQoxBv7Y5lZ6ovKeTpKcd8lP/koFXYQeRaA5P30e4i PHYTUfXPPgjquOvs4l1UWc9Epv+/9J1wzyyiOdUgoawHqJ+2uWG+7e73jJfwmyfe+Vus RtTQ== X-Gm-Message-State: AOAM530Ymf+uzBW4AlnPfYmS9HiKczKOQmuDShjV6FyQ2F9KmEf3SOy3 IqADD/Wbo+J1iEdQHFnXK5rNaOuxEhYUFVjQZOeOM5zBkjepHrlxSOD1Sg+6YYHYDmDws0zb20/ AJynp51wvFMPTDSP9XoYwSrkC X-Received: by 2002:a5d:6c65:: with SMTP id r5mr38598494wrz.26.1634119814027; Wed, 13 Oct 2021 03:10:14 -0700 (PDT) X-Received: by 2002:a5d:6c65:: with SMTP id r5mr38598465wrz.26.1634119813789; Wed, 13 Oct 2021 03:10:13 -0700 (PDT) Received: from redhat.com ([2.55.30.112]) by smtp.gmail.com with ESMTPSA id p25sm4782688wma.2.2021.10.13.03.10.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 03:10:13 -0700 (PDT) Date: Wed, 13 Oct 2021 06:10:09 -0400 From: "Michael S. Tsirkin" To: Halil Pasic Cc: Jason Wang , Xie Yongji , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, markver@us.ibm.com, Cornelia Huck , Christian Borntraeger , linux-s390@vger.kernel.org, stefanha@redhat.com, Raphael Norwitz , qemu-devel@nongnu.org Subject: Re: [PATCH v3 1/1] virtio: write back F_VERSION_1 before validate Message-ID: <20211013060923-mutt-send-email-mst@kernel.org> References: <20211011053921.1198936-1-pasic@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211011053921.1198936-1-pasic@linux.ibm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 11, 2021 at 07:39:21AM +0200, Halil Pasic wrote: > 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 OK this looks good! How about a QEMU patch to make it spec compliant on BE? > --- > > @Connie: I made some more commit message changes to accommodate Michael's > requests. I just assumed these will work or you as well and kept your > r-b. Please shout at me if it needs to be dropped :) > --- > drivers/virtio/virtio.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c > index 0a5b54034d4b..236081afe9a2 100644 > --- a/drivers/virtio/virtio.c > +++ b/drivers/virtio/virtio.c > @@ -239,6 +239,17 @@ static int virtio_dev_probe(struct device *_d) > 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 > > base-commit: 60a9483534ed0d99090a2ee1d4bb0b8179195f51 > -- > 2.25.1