Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2824066pxb; Mon, 17 Jan 2022 06:32:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNSZF79O7tjOpWg+OY6c9+5sdBxpoIkilvQdH35rYKksJ8CJBL2PTb18IY3ClNhNC5fyV0 X-Received: by 2002:a17:902:6b49:b0:149:9809:7747 with SMTP id g9-20020a1709026b4900b0014998097747mr22012809plt.125.1642429928592; Mon, 17 Jan 2022 06:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642429928; cv=none; d=google.com; s=arc-20160816; b=qpBt4HFa/UQFfnpeFgRK2nlmhR4lmOtkxtoTl+hlKDGZFMNfr8swjAEIHgFpxpv6IE pAZLmBqu4R7OfHqBFe45rf3w3S9B8Ct6M9yJZWaKg+9caLH4dZ0h3+HOdMyyQDLaE5+k XcLNFutswfjReJsyVgPpk4v6rLEW25YupHuvKFFu8EUD0vDLg0bGorAR8vdJSRi78Rqu qA9J2VyaSc4RDsMs+ynV8o+OiVTV1gjJicFJi1AXkr3QqqmAgSCqhYD/v52mMcBW4A+z W33ckG1SyOck7qS4PYVRWi1LdLragccD1Ar0CVp2g+usNuITJtm3k2BVUqXRj2L02FB5 Vxxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ermpWLzpnf2+eleUkI4QP6TV2e0rXLT1tCR2h6immvo=; b=CA+gm0PIOeoSRrZnDLoqK4LDDEwLZaGYqsRttdvTsCfL/WYk6D4THb4z/rlU2KibmK Hi1mRTnP4cBUNsje5EhqZH0gnyV6bKlezCkBwSeJVfU8TWLGyeWFao6zgE/OfnuQ+XJT IVaGnyFSBkSVOv6AfygYJ/vsYIzl8a0DPT/7PaoT2kkrakM7gbT+iH1gG2ZSEzf1lV1m rnP1s+DVrsQigr3fJpobvAikyqXRGpCZTMYgnkqsOjhk8DiILqEkEQRBa3/AzPJteZRW zTtHy1HJ2hKqj69a9xma9+l1D+tVs3gx9foqt3EVbVOsJEStcnCSIgb29MfU8NO0B3Mu FohA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dbm3yQlW; 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 m7si12561334pls.478.2022.01.17.06.31.53; Mon, 17 Jan 2022 06:32:08 -0800 (PST) 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=Dbm3yQlW; 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 S234706AbiAQGb5 (ORCPT + 99 others); Mon, 17 Jan 2022 01:31:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39093 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbiAQGb5 (ORCPT ); Mon, 17 Jan 2022 01:31:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642401116; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ermpWLzpnf2+eleUkI4QP6TV2e0rXLT1tCR2h6immvo=; b=Dbm3yQlWZTRM22P1PEXwk//n4CfIGWxmQ3Ub+ejKubuPc87saaImL7R3xdW7jtWPu/z0K4 Uo7YCZEBCYm06eLBrLAMWJw0zXetm+aehEsVrYDjtEDnvGaaDMywtkjROJXOWNf6QmfI8J wcY3pL6FpMNj1hc5w7UT0b4ub6Y4VhQ= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-374-fGZRJ1eiN4eqHMYhZrQFsg-1; Mon, 17 Jan 2022 01:31:55 -0500 X-MC-Unique: fGZRJ1eiN4eqHMYhZrQFsg-1 Received: by mail-pg1-f197.google.com with SMTP id u133-20020a63798b000000b0034c0630b044so2526088pgc.3 for ; Sun, 16 Jan 2022 22:31:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ermpWLzpnf2+eleUkI4QP6TV2e0rXLT1tCR2h6immvo=; b=ZWFUS9c3SGmnsp2lEZuLW5budV4JZrUkzeoEOsNBG8a/cHXNWH4/oYKSJmqvDWrl/9 qo55Et66HO6CN2hr9i0bdY0HrkwX97Mx28vdRs042iO9VERv5KHBOo7XV5ejGYXM5BZZ Ya0Bthfu85ZQJI1oRUjPVMkggqCj7cxgj1dITPkz+SirPoE4BZu9aRPy8kd7mWt3GbgD 8mKDB0WeJp5RO/MWBsWDbNsz3z2jgVIzgA0EwhjoBo/rr99Wqv0zK6/Awgw6xYVqqcfF vHYUB2kHIYyhi/YGymheKzhaf3jn1Vdm06IrHTvW23B4bu7Wgcy3J9grEqaFpgyTkFRL iTkw== X-Gm-Message-State: AOAM532ElYySIeX3T7cJ9Aj35PLDeb9PbOk0/I5BoyKwtxfayfJ0rTbs vgM8DrfmtLmK3TA5TfzKuwhh5PfKJPf1Wy/1FAsOjA1rlZuRrSkvGDpMmqsRvDv3bWPLP9Gh6Z6 Dk6Z7KUc3TwJBP9Qdf8pBzUkX X-Received: by 2002:a17:902:7d93:b0:14a:bf7b:926d with SMTP id a19-20020a1709027d9300b0014abf7b926dmr2435719plm.22.1642401113986; Sun, 16 Jan 2022 22:31:53 -0800 (PST) X-Received: by 2002:a17:902:7d93:b0:14a:bf7b:926d with SMTP id a19-20020a1709027d9300b0014abf7b926dmr2435694plm.22.1642401113728; Sun, 16 Jan 2022 22:31:53 -0800 (PST) Received: from [10.72.13.251] ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o184sm12743628pfb.90.2022.01.16.22.31.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 16 Jan 2022 22:31:53 -0800 (PST) Message-ID: Date: Mon, 17 Jan 2022 14:31:49 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] virtio: acknowledge all features before access Content-Language: en-US To: "Michael S. Tsirkin" , linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, Halil Pasic , Cornelia Huck , virtualization@lists.linux-foundation.org References: <20220114200744.150325-1-mst@redhat.com> From: Jason Wang In-Reply-To: <20220114200744.150325-1-mst@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/1/15 上午4:09, Michael S. Tsirkin 写道: > The feature negotiation was designed in a way that > makes it possible for devices to know which config > fields will be accessed by drivers. > > This is broken since commit 404123c2db79 ("virtio: allow drivers to > validate features") with fallout in at least block and net. > We have a partial work-around in commit 2f9a174f918e ("virtio: write > back F_VERSION_1 before validate") which at least lets devices > find out which format should config space have, but this > is a partial fix: guests should not access config space > without acknowledging features since otherwise we'll never > be able to change the config space format. > > As a side effect, this also reduces the amount of hypervisor accesses - > we now only acknowledge features once unless we are clearing any > features when validating. > > Cc: stable@vger.kernel.org > Fixes: 404123c2db79 ("virtio: allow drivers to validate features") > Fixes: 2f9a174f918e ("virtio: write back F_VERSION_1 before validate") > Cc: "Halil Pasic" > Signed-off-by: Michael S. Tsirkin > --- > > Halil, I thought hard about our situation with transitional and > today I finally thought of something I am happy with. > Pls let me know what you think. Testing on big endian would > also be much appreciated! > > drivers/virtio/virtio.c | 31 +++++++++++++++++-------------- > 1 file changed, 17 insertions(+), 14 deletions(-) > > diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c > index d891b0a354b0..2ed6e2451fd8 100644 > --- a/drivers/virtio/virtio.c > +++ b/drivers/virtio/virtio.c > @@ -168,12 +168,10 @@ EXPORT_SYMBOL_GPL(virtio_add_status); > > static int virtio_finalize_features(struct virtio_device *dev) > { > - int ret = dev->config->finalize_features(dev); > unsigned status; > + int ret; > > might_sleep(); > - if (ret) > - return ret; > > ret = arch_has_restricted_virtio_memory_access(); > if (ret) { > @@ -244,17 +242,6 @@ 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 > @@ -265,10 +252,22 @@ static int virtio_dev_probe(struct device *_d) > if (device_features & (1ULL << i)) > __virtio_set_bit(dev, i); > > + err = dev->config->finalize_features(dev); > + if (err) > + goto err; > + > if (drv->validate) { > + u64 features = dev->features; > + > err = drv->validate(dev); > if (err) > goto err; > + > + if (features != dev->features) { > + err = dev->config->finalize_features(dev); > + if (err) > + goto err; > + } > } > > err = virtio_finalize_features(dev); > @@ -495,6 +494,10 @@ int virtio_device_restore(struct virtio_device *dev) > /* We have a driver! */ > virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER); > > + ret = dev->config->finalize_features(dev); > + if (ret) > + goto err; Is this part of code related? Thanks > + > ret = virtio_finalize_features(dev); > if (ret) > goto err;