Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp691149pxa; Wed, 5 Aug 2020 10:24:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmOO01PUpGlxbD4F115YSGhCXn9glPZWCySVfXTugc+tPzyyXCwNVpqnSMMabDQOKMD6tr X-Received: by 2002:a17:906:a3d5:: with SMTP id ca21mr259875ejb.453.1596648284760; Wed, 05 Aug 2020 10:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596648284; cv=none; d=google.com; s=arc-20160816; b=RfZ6g0z0SYNQd3r+oaWhxhtBzFj9bSKKP3YwgPWMcQ5PEyzJfrnzashK/dXyg2aXTH xXVnarudaJ7rKhvPpVqseem8JtZ6ftWhhyWf8rC4kzZl62UKANAFTvpEdx1TComcQh2E b6ZrIqIhZkyYqcmOkwS8TQmgzNkiFYVemCrLb+K45u2Jlur2JOySYGL8t8Sxj4iN29yO TNXYLiVPj6Yu0sLf45M3oeTdlYE87iY5yltKI2TKR813fSYzbJH60opcbBNl/yN8bWFt BVSv/F1FjTPtxOUYQePHa5aqxPlRRpA0xSAW17g5i8L8tsc5OZ3H4a8gmv2zyxC8GG37 8hmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lad+l1QsVGACWdbh/Js4EqT43VIKUvJSAKVohar8Uec=; b=psTmdRQLj9l/p/l5Vt0U7+KgneXRpUQitlAjwIDHmlmpKZP0C1lg99r8txEX6IUB5r xdXi7qt87P/Lc0PRvo4UrtuDyHosz+iqltPCmjb9eYBsWE07dzyxlA5HnGc+72+r6OW2 SrbijMCGu160JOiJcRiKR4gGnVaWQ18QqHHbIiobrspIwCX+MKzUroGLatYryjzyrT7O /U924yBn0mKb4VQy8A/Jvzc2rIk5Nqafg3RdTt7KwrbkTQNmeEGW6hcUxtU9QDWMT8iY AiPhgUYeJsiBEjoiL6xHiq9yam4l5nhA6+MN2DRx2Vtd8jy1ChfZ/cIJRdRobJfKarYC O0ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=geGxxXXI; 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 x23si1912747edi.416.2020.08.05.10.24.21; Wed, 05 Aug 2020 10:24:44 -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=geGxxXXI; 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 S1728371AbgHERX6 (ORCPT + 99 others); Wed, 5 Aug 2020 13:23:58 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34098 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728485AbgHERQF (ORCPT ); Wed, 5 Aug 2020 13:16:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596647763; 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=lad+l1QsVGACWdbh/Js4EqT43VIKUvJSAKVohar8Uec=; b=geGxxXXI5N6UvtmH5+Th8NT6nsUOKyjiAAzwNPda72ts1kdnSMpY4OAaceZXsPaJWsot+k UdyiofWAjjmk/Rb96oQL0gcmiM4NPQwdhNw2nOqvd+U5i7YHKrPEcYvulCnnt/G9XaFx9W u81nnO08lRFDRAiSyUU4BI2Efh1N2a0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291-WY5JIb6JMEOlT1wXyPPUUA-1; Wed, 05 Aug 2020 07:40:20 -0400 X-MC-Unique: WY5JIb6JMEOlT1wXyPPUUA-1 Received: by mail-wr1-f72.google.com with SMTP id e12so13538114wra.13 for ; Wed, 05 Aug 2020 04:40:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=lad+l1QsVGACWdbh/Js4EqT43VIKUvJSAKVohar8Uec=; b=s3YAd+wlXGjLRp1AwSxn5Q7Sy/sbmPNBuC6TO5J06m8b6UcCt1bCH7d+OiRY9z1hyf tUzXcqfKqm5Qx/9kTzSg0RrJkCE/Hiv46/EllQg6Qzb+e9Ubh+nMM5XeWfNPTgWW74E4 0mUbT6PccIs21ExPqJvr8+Tvjw2vgy5QRoFO5VVUPqGKX9YndGY0F07C+OlxqMdqULXj 7CCOae02VD5iE1/Z4a/uRAbTU/LU6KObuzeR3FzVqXjeUPjHjto7RhMndHIWHtxKYb8J XE/pw6BytMBf+ZaBTMqO2VOwDeefafVqUGetNorawbNmeqHao+Tef/luoXogQ3Bd8MaB O74g== X-Gm-Message-State: AOAM531cNFS1Ig7IjcznhuuGmm8KLYl8q5YvzoaAzK8OBcFVQwbOe1J7 Yg7/IgSDlMXSh2kCzMNdLlu//9VsOi5Bgv1xm1+SAak25Ycq7fZe5oPlCpy440dB6OHqa3QmP6V 6c8zASI89Q00wSeolcsMlVRTM X-Received: by 2002:a05:600c:2154:: with SMTP id v20mr2905540wml.186.1596627619070; Wed, 05 Aug 2020 04:40:19 -0700 (PDT) X-Received: by 2002:a05:600c:2154:: with SMTP id v20mr2905517wml.186.1596627618867; Wed, 05 Aug 2020 04:40:18 -0700 (PDT) Received: from redhat.com (bzq-79-180-0-181.red.bezeqint.net. [79.180.0.181]) by smtp.gmail.com with ESMTPSA id d14sm2409261wre.44.2020.08.05.04.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 04:40:17 -0700 (PDT) Date: Wed, 5 Aug 2020 07:40:15 -0400 From: "Michael S. Tsirkin" To: Jason Wang Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v2 19/24] vdpa: make sure set_features in invoked for legacy Message-ID: <20200805073929-mutt-send-email-mst@kernel.org> References: <20200803205814.540410-1-mst@redhat.com> <20200803205814.540410-20-mst@redhat.com> <9e47d227-f220-4651-dcb9-7a11f059a715@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9e47d227-f220-4651-dcb9-7a11f059a715@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 05, 2020 at 02:14:07PM +0800, Jason Wang wrote: > > On 2020/8/4 上午5:00, Michael S. Tsirkin wrote: > > Some legacy guests just assume features are 0 after reset. > > We detect that config space is accessed before features are > > set and set features to 0 automatically. > > Note: some legacy guests might not even access config space, if this is > > reported in the field we might need to catch a kick to handle these. > > > I wonder whether it's easier to just support modern device? > > Thanks Well hardware vendors are I think interested in supporting legacy guests. Limiting vdpa to modern only would make it uncompetitive. > > > > > Signed-off-by: Michael S. Tsirkin > > --- > > drivers/vdpa/vdpa.c | 1 + > > include/linux/vdpa.h | 34 ++++++++++++++++++++++++++++++++++ > > 2 files changed, 35 insertions(+) > > > > diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c > > index de211ef3738c..7105265e4793 100644 > > --- a/drivers/vdpa/vdpa.c > > +++ b/drivers/vdpa/vdpa.c > > @@ -96,6 +96,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, > > vdev->dev.release = vdpa_release_dev; > > vdev->index = err; > > vdev->config = config; > > + vdev->features_valid = false; > > err = dev_set_name(&vdev->dev, "vdpa%u", vdev->index); > > if (err) > > diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h > > index 239db794357c..29b8296f1414 100644 > > --- a/include/linux/vdpa.h > > +++ b/include/linux/vdpa.h > > @@ -33,12 +33,14 @@ struct vdpa_notification_area { > > * @dma_dev: the actual device that is performing DMA > > * @config: the configuration ops for this device. > > * @index: device index > > + * @features_valid: were features initialized? for legacy guests > > */ > > struct vdpa_device { > > struct device dev; > > struct device *dma_dev; > > const struct vdpa_config_ops *config; > > unsigned int index; > > + bool features_valid; > > }; > > /** > > @@ -266,4 +268,36 @@ static inline struct device *vdpa_get_dma_dev(struct vdpa_device *vdev) > > { > > return vdev->dma_dev; > > } > > + > > +static inline void vdpa_reset(struct vdpa_device *vdev) > > +{ > > + const struct vdpa_config_ops *ops = vdev->config; > > + > > + vdev->features_valid = false; > > + ops->set_status(vdev, 0); > > +} > > + > > +static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) > > +{ > > + const struct vdpa_config_ops *ops = vdev->config; > > + > > + vdev->features_valid = true; > > + return ops->set_features(vdev, features); > > +} > > + > > + > > +static inline void vdpa_get_config(struct vdpa_device *vdev, unsigned offset, > > + void *buf, unsigned int len) > > +{ > > + const struct vdpa_config_ops *ops = vdev->config; > > + > > + /* > > + * Config accesses aren't supposed to trigger before features are set. > > + * If it does happen we assume a legacy guest. > > + */ > > + if (!vdev->features_valid) > > + vdpa_set_features(vdev, 0); > > + ops->get_config(vdev, offset, buf, len); > > +} > > + > > #endif /* _LINUX_VDPA_H */