Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1810001ybz; Sun, 26 Apr 2020 04:49:30 -0700 (PDT) X-Google-Smtp-Source: APiQypLm32etuAoVL/PK56iLAusQtVwY3umfI2MU2MA2rQSiEm4zsnCoVlHsS1l6lL3dhtKigSLr X-Received: by 2002:a17:907:41b3:: with SMTP id na3mr15896307ejb.250.1587901770446; Sun, 26 Apr 2020 04:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587901770; cv=none; d=google.com; s=arc-20160816; b=PennPnkrnc/6ZwPUPafvzQ/mtomKr1KMHfQyHmXt9hUGjuavIx7V2BbCUSAI0OxjuO UfVoJSPr6gk84o0ncSHS6AIvZnkffhjkj7bZFfitPIExlcc27GnCgQasSfAZ80Sk8GGJ HfTEmRotoAQpqUdfaG7QYSF4X44/qSyr0y9+ICIaA3kOIkDIJ8er7zB22F7dU1PXo5dA uhik6xuaZjBNf/8VR9rGHxw+H+n8HJwSzSEWSQhS7/MgXlFDKxbFoYuyVsXTxoy17F3e CAE7mo0U/KzqHoy+Ph7/uFI13ZERrVXxfKfZsXMIS86vxkAv+OuQGcxyLv1AsG+BqOqP ue2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=dgUJuZhpJvqqfnya/B8PipA5hgnxNrZ35mqkLP1v+QQ=; b=ZsKcwEBjNlnhTYhIP4DVT32o9oO3eAYE3HtjZV14wsyDB66sW+qnViGExYne/9BdnE otUUfsyy9NLCXcD3N4IpodvlboCJXclTqHJ9cZLPGQc5poKDCQRFjgMrvleuimGKoIcY dYBJ1ejtTCbvfgIiRB2bmdVO6+qojGF1yUw+v0cL6gu8KZ09iE3e7CfIVM8eNvEhGrsf 9C+9RLbsCpyRaz6DSqrdlBODXpIvshq2xOBM+F0ov2G4xstMSP4JHJqbGcufPPSTAL4V ATQoL46FkvlZxQ7fiILGnh5FEtSPD6d6Q0mqtfwOFtn7JRH8KFmQM5i05jMyPK6mDn6z 6H4g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x61si6549971ede.23.2020.04.26.04.48.54; Sun, 26 Apr 2020 04:49:30 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726185AbgDZLqp (ORCPT + 99 others); Sun, 26 Apr 2020 07:46:45 -0400 Received: from mga05.intel.com ([192.55.52.43]:11883 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbgDZLqp (ORCPT ); Sun, 26 Apr 2020 07:46:45 -0400 IronPort-SDR: PlZnLfSujQeR3HqofkJqsF1Dx5ZXOLuafCfCVRknTID7pe8Siq0Whnu2yamhOltHosjxUuP/1A boIsBtgobeoA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2020 04:46:44 -0700 IronPort-SDR: l+ZU0uhM0fxpY3LvQhJVkAac5hdBqVKU5u4s2Wb6ZNGuq+NNTTZcRu8FEH0NND0ZP3glmyncmI rJpxW7D11GAA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,320,1583222400"; d="scan'208";a="275155044" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.79]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2020 04:46:41 -0700 From: Zhu Lingshan To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, jasowang@redhat.com Cc: lulu@redhat.com, dan.daly@intel.com, cunming.liang@intel.com, Zhu Lingshan Subject: [PATCH V4 1/3] vdpa: Support config interrupt in vhost_vdpa Date: Sun, 26 Apr 2020 19:43:24 +0800 Message-Id: <1587901406-27400-2-git-send-email-lingshan.zhu@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1587901406-27400-1-git-send-email-lingshan.zhu@intel.com> References: <1587901406-27400-1-git-send-email-lingshan.zhu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit implements config interrupt support in vhost_vdpa layer. Signed-off-by: Zhu Lingshan --- drivers/vhost/vdpa.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ 2 files changed, 51 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 421f02a..c370ec5 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "vhost.h" @@ -70,6 +71,7 @@ struct vhost_vdpa { int nvqs; int virtio_id; int minor; + struct eventfd_ctx *config_ctx; }; static DEFINE_IDA(vhost_vdpa_ida); @@ -101,6 +103,17 @@ static irqreturn_t vhost_vdpa_virtqueue_cb(void *private) return IRQ_HANDLED; } +static irqreturn_t vhost_vdpa_config_cb(void *private) +{ + struct vhost_vdpa *v = private; + struct eventfd_ctx *config_ctx = v->config_ctx; + + if (config_ctx) + eventfd_signal(config_ctx, 1); + + return IRQ_HANDLED; +} + static void vhost_vdpa_reset(struct vhost_vdpa *v) { struct vdpa_device *vdpa = v->vdpa; @@ -288,6 +301,36 @@ static long vhost_vdpa_get_vring_num(struct vhost_vdpa *v, u16 __user *argp) return 0; } +static void vhost_vdpa_config_put(struct vhost_vdpa *v) +{ + if (v->config_ctx) + eventfd_ctx_put(v->config_ctx); +} + +static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) +{ + struct vdpa_callback cb; + int fd; + struct eventfd_ctx *ctx; + + cb.callback = vhost_vdpa_config_cb; + cb.private = v->vdpa; + if (copy_from_user(&fd, argp, sizeof(fd))) + return -EFAULT; + + ctx = fd == VHOST_FILE_UNBIND ? NULL : eventfd_ctx_fdget(fd); + swap(ctx, v->config_ctx); + + if (!IS_ERR_OR_NULL(ctx)) + eventfd_ctx_put(ctx); + + if (IS_ERR(v->config_ctx)) + return PTR_ERR(v->config_ctx); + + v->vdpa->config->set_config_cb(v->vdpa, &cb); + + return 0; +} static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, void __user *argp) { @@ -398,6 +441,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, case VHOST_SET_LOG_FD: r = -ENOIOCTLCMD; break; + case VHOST_VDPA_SET_CONFIG_CALL: + r = vhost_vdpa_set_config_call(v, argp); + break; default: r = vhost_dev_ioctl(&v->vdev, cmd, argp); if (r == -ENOIOCTLCMD) @@ -734,6 +780,7 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep) vhost_dev_stop(&v->vdev); vhost_vdpa_iotlb_free(v); vhost_vdpa_free_domain(v); + vhost_vdpa_config_put(v); vhost_dev_cleanup(&v->vdev); kfree(v->vdev.vqs); mutex_unlock(&d->mutex); diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index 9fe72e4..0c23496 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -15,6 +15,8 @@ #include #include +#define VHOST_FILE_UNBIND -1 + /* ioctls */ #define VHOST_VIRTIO 0xAF @@ -140,4 +142,6 @@ /* Get the max ring size. */ #define VHOST_VDPA_GET_VRING_NUM _IOR(VHOST_VIRTIO, 0x76, __u16) +/* Set event fd for config interrupt*/ +#define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int) #endif -- 1.8.3.1