Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp355189pxb; Thu, 9 Sep 2021 02:30:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQtMyuna/2xNQujVnO3hgMFktgGQ/fwDcn9kvKxZWvTklcZD86clTQvMudW0gLDV7Bsvsp X-Received: by 2002:aa7:d51a:: with SMTP id y26mr2186680edq.163.1631179845208; Thu, 09 Sep 2021 02:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631179845; cv=none; d=google.com; s=arc-20160816; b=UPDi9PRyakGZndCBBHfLc7ideZy+VEcLQ6mtvQKmnXvB6/RSls5kZxxwqjVMjTzmAt 210l38/9wMzoeaT+PupGeNOI2EvNiP9eHFOMWAuWqWs5NYHjqIEYMhoWGyaqZQcPqEsa 21I/Cn4O2BOXBBAeZhyhrX+1x108TCjI62X2mamd7JSiKhNmTDAdbi5OZQNYENTOl75W JvYEXKurQU1MujY2FKmse7XPpxWDS8kahEDI2KASs6PES6YSC1ROedKon14PLc/wk1MT j08KYdxNQnRMGVzg0Wmf6K44KALMKcAkLeBi+kY4t9D5vD7ZPg7ZhO/LNse8LF1Mb4r6 CvLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=E7MPTrkICD3dS44O34dSkNV5ikqasNKbp3eO9uY/CQQ=; b=fMlkuI1CQ1zY+zkHi8pbcXGgg9DLCANIGRZlJRU2ZNEbxdFZgSMt8Mb4QiPsW8wHeh o6QZ5FsKkqM+0yuD77/dNyglF7ENjMqM0j+NG6rZAbVJfXPZzWsDRASNfIYN7WIZrOKN nJ6466sB0HHRcSpfm7uhtzOGCacE3unpLfifVFOEvMa9g9r4fcj2oEhxQTwmmdNoGZEm AcIXY8p5AhnrVA538o/7Rh/0s/nqc7BgSugiszua1jE3FSxi4vkBRFOVhyGb1mhU4rlT c1LH9nis4DNeV7uyo7xMSEN2my/0fZFCVCNbELDwVHkFiTBixuLRxylYgOHNUT3Y/KKq 8Gjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fE9tS3Wr; 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 w18si1294161edu.157.2021.09.09.02.30.19; Thu, 09 Sep 2021 02:30:45 -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=fE9tS3Wr; 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 S232782AbhIIJ3u (ORCPT + 99 others); Thu, 9 Sep 2021 05:29:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57941 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232262AbhIIJ3t (ORCPT ); Thu, 9 Sep 2021 05:29:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631179720; 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=E7MPTrkICD3dS44O34dSkNV5ikqasNKbp3eO9uY/CQQ=; b=fE9tS3WrbBpAr2AccDZV/eBWI2x0RZFrKHJZaJH5q4y7TO9N2170EH8n6VIMDQQg0k5DZ8 Cef8BxVVnlTPikbZKvBktFLW2p30mYPUIxu3TbjrSy/5/93RVrZGprj7pSolM9uJJ3mTRq yiQr1F0G11cczxTjZS2opzKHibc8nhw= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-PYxuWxCgM5KtN5a_rjX_Pw-1; Thu, 09 Sep 2021 05:28:39 -0400 X-MC-Unique: PYxuWxCgM5KtN5a_rjX_Pw-1 Received: by mail-lf1-f72.google.com with SMTP id n5-20020a19ef05000000b003e224cd5844so500385lfh.12 for ; Thu, 09 Sep 2021 02:28:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=E7MPTrkICD3dS44O34dSkNV5ikqasNKbp3eO9uY/CQQ=; b=fbarEFCUB1aWpX1fWRZ1ARr3kCELDE4OIXgsCLYout5yXD3hbmrGZ4umE1p33LQD7Q oieM+q3Z2yjbW6GtEK5QMuhUdzWPrIYTqodMz8DKWotkAJdXTsmyE0k5wUFrCFbi6EZN 7GLf7FCvtvxDPlWkHlFWx6mL2iWWWi4/pa1kod9Jfo3l1T7coMyzwl0w3EG1LOTk0Gxj ann4/8poQCnchDh8tk/gj3bzKvQr4OGSLFklbBQ9xYSkIYutf/I0TFGx/yo+3VPkEjFK ds5Ja4ejVssem0MhllLdX3tRX5/4GBbdSokpiOA3uVAk88IYqtyeCmFbt9aGPJQrTiOe VJFg== X-Gm-Message-State: AOAM531t+u7Dl5be1pZiOmgypA/T1PoxeAB0Ys3vJcEUf4LZxGLattEb s4O3VdN1UalYhQQM9h7dvVujF7LM7pNvRAmj8Iyg1oohE/Igmft0AYX3Igrcj8954eiwwTiH39c bWIwnR6vg3cj7O93WfaUX17rw7sUC+R9623aNS9tQ X-Received: by 2002:a2e:7018:: with SMTP id l24mr1461010ljc.277.1631179717363; Thu, 09 Sep 2021 02:28:37 -0700 (PDT) X-Received: by 2002:a2e:7018:: with SMTP id l24mr1460994ljc.277.1631179717047; Thu, 09 Sep 2021 02:28:37 -0700 (PDT) MIME-Version: 1.0 References: <20210909080157.GA17383@L-PF27918B-1352.localdomain> In-Reply-To: <20210909080157.GA17383@L-PF27918B-1352.localdomain> From: Jason Wang Date: Thu, 9 Sep 2021 17:28:26 +0800 Message-ID: Subject: Re: [PATCH 5/6] vdpa: add get_vq_num_unchangeable callback in vdpa_config_ops To: Wu Zongyong Cc: virtualization , linux-kernel , mst , wei.yang1@linux.alibaba.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 9, 2021 at 4:02 PM Wu Zongyong wrote: > > On Thu, Sep 09, 2021 at 10:55:03AM +0800, Jason Wang wrote: > > On Wed, Sep 8, 2021 at 8:23 PM Wu Zongyong wrote: > > > > > > This new callback is used to indicate whether the vring size can be > > > change or not. It is useful when we have a legacy virtio pci device as > > > the vdpa device for there is no way to negotiate the vring num by the > > > specification. > > > > So I'm not sure it's worth bothering. E.g what if we just fail > > VHOST_SET_VRING_NUM it the value doesn't match what hardware has? > > > > Thanks > > > I think we should not call VHOST_SET_VRING_NUM in that case. > > If the hardware reports that the virtqueue size cannot be changed, we > should call VHOST_GET_VRING_NUM to get the static virtqueue size > firstly, then allocate the same size memory for the virtqueues and write > the address to hardware finally. > > For QEMU, we will ignore the properties rx/tx_queue_size and just get it > from the hardware if this new callback return true. This will break live migration. My understanding is that we can advertise those capability/limitation via the netlink management protocol then management layer can choose to use the correct queue size. Thanks > > What do you think? > > > > > > Signed-off-by: Wu Zongyong > > > --- > > > drivers/vhost/vdpa.c | 19 +++++++++++++++++++ > > > drivers/virtio/virtio_vdpa.c | 5 ++++- > > > include/linux/vdpa.h | 4 ++++ > > > include/uapi/linux/vhost.h | 2 ++ > > > 4 files changed, 29 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c > > > index 9479f7f79217..2204d27d1e5d 100644 > > > --- a/drivers/vhost/vdpa.c > > > +++ b/drivers/vhost/vdpa.c > > > @@ -350,6 +350,22 @@ static long vhost_vdpa_get_iova_range(struct vhost_vdpa *v, u32 __user *argp) > > > return 0; > > > } > > > > > > +static long vhost_vdpa_get_vring_num_unchangeable(struct vhost_vdpa *v, > > > + u32 __user *argp) > > > +{ > > > + struct vdpa_device *vdpa = v->vdpa; > > > + const struct vdpa_config_ops *ops = vdpa->config; > > > + bool unchangeable = false; > > > + > > > + if (ops->get_vq_num_unchangeable) > > > + unchangeable = ops->get_vq_num_unchangeable(vdpa); > > > + > > > + if (copy_to_user(argp, &unchangeable, sizeof(unchangeable))) > > > + return -EFAULT; > > > + > > > + return 0; > > > +} > > > + > > > static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, > > > void __user *argp) > > > { > > > @@ -487,6 +503,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, > > > case VHOST_VDPA_GET_IOVA_RANGE: > > > r = vhost_vdpa_get_iova_range(v, argp); > > > break; > > > + case VHOST_VDPA_GET_VRING_NUM_UNCHANGEABLE: > > > + r = vhost_vdpa_get_vring_num_unchangeable(v, argp); > > > + break; > > > default: > > > r = vhost_dev_ioctl(&v->vdev, cmd, argp); > > > if (r == -ENOIOCTLCMD) > > > diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c > > > index 72eaef2caeb1..afb47465307a 100644 > > > --- a/drivers/virtio/virtio_vdpa.c > > > +++ b/drivers/virtio/virtio_vdpa.c > > > @@ -146,6 +146,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, > > > struct vdpa_vq_state state = {0}; > > > unsigned long flags; > > > u32 align, num; > > > + bool may_reduce_num = true; > > > int err; > > > > > > if (!name) > > > @@ -171,8 +172,10 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, > > > > > > /* Create the vring */ > > > align = ops->get_vq_align(vdpa); > > > + if (ops->get_vq_num_unchangeable) > > > + may_reduce_num = !ops->get_vq_num_unchangeable(vdpa); > > > vq = vring_create_virtqueue(index, num, align, vdev, > > > - true, true, ctx, > > > + true, may_reduce_num, ctx, > > > virtio_vdpa_notify, callback, name); > > > if (!vq) { > > > err = -ENOMEM; > > > diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h > > > index 35648c11e312..f809b7ada00d 100644 > > > --- a/include/linux/vdpa.h > > > +++ b/include/linux/vdpa.h > > > @@ -195,6 +195,9 @@ struct vdpa_iova_range { > > > * @vdev: vdpa device > > > * Returns the iova range supported by > > > * the device. > > > + * @get_vq_num_unchangeable Check if size of virtqueue is unchangeable (optional) > > > + * @vdev: vdpa device > > > + * Returns boolean: unchangeable (true) or not (false) > > > * @set_map: Set device memory mapping (optional) > > > * Needed for device that using device > > > * specific DMA translation (on-chip IOMMU) > > > @@ -262,6 +265,7 @@ struct vdpa_config_ops { > > > const void *buf, unsigned int len); > > > u32 (*get_generation)(struct vdpa_device *vdev); > > > struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev); > > > + bool (*get_vq_num_unchangeable)(struct vdpa_device *vdev); > > > > > > /* DMA ops */ > > > int (*set_map)(struct vdpa_device *vdev, struct vhost_iotlb *iotlb); > > > diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h > > > index c998860d7bbc..184f1f7f8498 100644 > > > --- a/include/uapi/linux/vhost.h > > > +++ b/include/uapi/linux/vhost.h > > > @@ -150,4 +150,6 @@ > > > /* Get the valid iova range */ > > > #define VHOST_VDPA_GET_IOVA_RANGE _IOR(VHOST_VIRTIO, 0x78, \ > > > struct vhost_vdpa_iova_range) > > > +/* Check if the vring size can be change */ > > > +#define VHOST_VDPA_GET_VRING_NUM_UNCHANGEABLE _IOR(VHOST_VIRTIO, 0X79, bool) > > > #endif > > > -- > > > 2.31.1 > > > >