From patchwork Mon Dec 5 09:02:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29615 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2145765wrr; Mon, 5 Dec 2022 01:22:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf5TvyC/4CsivS/mSImasP3h4FgWEgJuMcEqZ7ANJYGjQUrrISy7UNdnNBh2ezeJZkzzc586 X-Received: by 2002:a17:906:3fce:b0:7ad:bb54:75d3 with SMTP id k14-20020a1709063fce00b007adbb5475d3mr67833967ejj.484.1670232125542; Mon, 05 Dec 2022 01:22:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670232125; cv=none; d=google.com; s=arc-20160816; b=rk6wk4nReHnIzWg4CRC1CyipzPWbgozYATd0KHN/aFEdZ0+nzG8eVwrbZtUHlHJFqG YFVJTT7qfe/0ctysAAgSLi4fgl6V0LanJq4EPhZnRGmpgEYbwXUhVOvel6p9fFMyEIiI VgGk1wP7HhXCQjuEHoATnbkAxXCER39nNtgKjDw6gFGJF5ZUQa7ymOuoxbv98dJsxTiF 3GT9TkSG3NBFm6abLDmAufDZC+wJyOb0Qmtphphiy33CBuM8mV18m+1okSEZiLkZ2Rdz 5ZBD62OAkhQsl+MTwafwdp/TdySUQXmAIMG7mSpmrdgwXrg49eC9YNaztHvBSVbsoQ5q tjoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0F4aYFXGksQtN5NYEODlVl4Bem8OEWuiuWQxHQeKgGE=; b=fXeFiExdWvHWYXqG8Lu1GV1sM8VjxoHIV5XYGuYeIyWzTQDaPBI0JQfvShFRouy6J3 UyBcMKRilVXtU0a1Cu/8xSbm1ujcRg586CN/W1kR93M17BafqwKItXbNH16icA8EWim0 eBnHaBE+feY6kwSkJ1e37/jSaOwBx/tdLQ7iTZg7m/I5iLwCVB32nmF5YrD0pPFmYgci 9VvR1vFuXeJTkSoP4iciMRSwuR4u7fyGb/mbjYrEOY/TcODkUi57Gw4Le+OQ3x4SJq2O unOL+0AugquTc8IpFq6qBckvH3jYZpW8nMUiwiS/61rifVhxt57kMXhaJaqvU6SxXFR8 5UEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=sSKC7gm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr12-20020a170907720c00b007ae545e330csi7308629ejc.218.2022.12.05.01.21.41; Mon, 05 Dec 2022 01:22:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=sSKC7gm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232517AbiLEJEP (ORCPT + 99 others); Mon, 5 Dec 2022 04:04:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232082AbiLEJD3 (ORCPT ); Mon, 5 Dec 2022 04:03:29 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6161FD31 for ; Mon, 5 Dec 2022 01:03:01 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id q17-20020a17090aa01100b002194cba32e9so14171560pjp.1 for ; Mon, 05 Dec 2022 01:03:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0F4aYFXGksQtN5NYEODlVl4Bem8OEWuiuWQxHQeKgGE=; b=sSKC7gm8zRkAoVolXgWwlic+bvrd4CBsX+FKLhQCPFbXrSE8ntYCq5UdeliPa8D05J 0YMmvSG2P33BN6mUU7ELEG6JrfbhRF5q6JH9ANXTQlFjHhOy/qH8GN0iIozIE0qwBnZN i/GUVYoB21hXkIX/Ky4/JI6FkaPw1vJiqukaLZhqX/A2Hx0RxTIBCib/TbO17+voDGCE EpqTQOBCyn8+IYbWeahD6HmHhb72hjirua9v6ou8Ues8ON0gqGOd3bkxvfeDOox9/T5E OccwffpJ+FahYu+qRoXDRIhhtCVi7gUO+htOEDHcQ4WPtRo5vniEYPlZ5lyGkLZDI4tz MWXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0F4aYFXGksQtN5NYEODlVl4Bem8OEWuiuWQxHQeKgGE=; b=5/+2denMbjJBFJy/IRE/FpHJbzYeZjKwkz0hamAHSySzlkvzmKgPPKhoKPr27ZV13T yLN0YuNpc7Zz3vwpcqJVGB0CuuFIoivei511sihS+RXqDM1y3B/We2UUETMczUTS6EIW mdBvGc7akvx2Ij9RSHVWAdnTmN7qONOjcnHfbBoL1VZZMLFZZ50wEHxh2TxKegxbPWDv zx3MgyrcPeJT89NtXaiSU2KYvo5zwE20pTpQCHqlVKntIlQOIoy5p+xZEZZjpUSQr1pv mbPn9oOzLYz5Cdm35qniBqPLtvssKZO3UAHpZYFfWNqCaEPIF+qWHGvzDY1OtkNYo916 i5GQ== X-Gm-Message-State: ANoB5plmqgdOJglyDv4oybbmnjtnTxZQGxozWaZlAjJQ6frNznAXN2Tv YZrYQkrkwZBGmQzkg6OBZsRo X-Received: by 2002:a17:903:240a:b0:188:abb9:290 with SMTP id e10-20020a170903240a00b00188abb90290mr63732725plo.86.1670230981430; Mon, 05 Dec 2022 01:03:01 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id z189-20020a6365c6000000b00460c67afbd5sm7900683pgb.7.2022.12.05.01.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 01:03:01 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/11] vduse: Add enable_irq_wq sysfs interface for virtqueues Date: Mon, 5 Dec 2022 17:02:41 +0800 Message-Id: <20221205090243.791-3-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205090243.791-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> <20221205090243.791-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751365321676718283?= X-GMAIL-MSGID: =?utf-8?q?1751365321676718283?= Add enable_irq_wq sysfs interface to control whether use workqueue to inject irq or not. The vhost-vdpa case can benefit from it. Signed-off-by: Xie Yongji --- drivers/vdpa/vdpa_user/vduse_dev.c | 50 +++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index c65f84100e30..ed06c7afd484 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -62,6 +62,7 @@ struct vduse_virtqueue { struct cpumask irq_affinity; spinlock_t irq_affinity_lock; struct kobject kobj; + bool enable_irq_wq; }; struct vduse_dev; @@ -1013,6 +1014,26 @@ static int vduse_dev_queue_irq_work(struct vduse_dev *dev, return ret; } +static int vduse_dev_inject_vq_irq(struct vduse_dev *dev, + struct vduse_virtqueue *vq) +{ + int ret = -EINVAL; + + down_read(&dev->rwsem); + if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK)) + goto unlock; + + ret = 0; + spin_lock_irq(&vq->irq_lock); + if (vq->ready && vq->cb.callback) + vq->cb.callback(vq->cb.private); + spin_unlock_irq(&vq->irq_lock); +unlock: + up_read(&dev->rwsem); + + return ret; +} + static int vduse_dev_dereg_umem(struct vduse_dev *dev, u64 iova, u64 size) { @@ -1278,8 +1299,12 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; index = array_index_nospec(index, dev->vq_num); - ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject, + if (dev->vqs[index]->enable_irq_wq) + ret = vduse_dev_queue_irq_work(dev, + &dev->vqs[index]->inject, dev->vqs[index]->irq_effective_cpu); + else + ret = vduse_dev_inject_vq_irq(dev, dev->vqs[index]); break; } case VDUSE_IOTLB_REG_UMEM: { @@ -1420,6 +1445,26 @@ static const struct file_operations vduse_dev_fops = { .llseek = noop_llseek, }; +static ssize_t enable_irq_wq_show(struct vduse_virtqueue *vq, char *buf) +{ + return sprintf(buf, "%d\n", vq->enable_irq_wq); +} + +static ssize_t enable_irq_wq_store(struct vduse_virtqueue *vq, + const char *buf, size_t count) +{ + bool enabled; + int ret; + + ret = kstrtobool(buf, &enabled); + if (ret) + return ret; + + vq->enable_irq_wq = enabled; + + return count; +} + static ssize_t irq_cb_affinity_show(struct vduse_virtqueue *vq, char *buf) { return sprintf(buf, "%*pb\n", cpumask_pr_args(&vq->irq_affinity)); @@ -1480,10 +1525,12 @@ struct vq_sysfs_entry { static struct vq_sysfs_entry irq_cb_affinity_attr = __ATTR_RO(irq_cb_affinity); static struct vq_sysfs_entry irq_cb_effective_affinity_attr = __ATTR_RW(irq_cb_effective_affinity); +static struct vq_sysfs_entry enable_irq_wq_attr = __ATTR_RW(enable_irq_wq); static struct attribute *vq_attrs[] = { &irq_cb_affinity_attr.attr, &irq_cb_effective_affinity_attr.attr, + &enable_irq_wq_attr.attr, NULL, }; ATTRIBUTE_GROUPS(vq); @@ -1565,6 +1612,7 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) dev->vqs[i]->index = i; dev->vqs[i]->irq_effective_cpu = -1; + dev->vqs[i]->enable_irq_wq = true; INIT_WORK(&dev->vqs[i]->inject, vduse_vq_irq_inject); INIT_WORK(&dev->vqs[i]->kick, vduse_vq_kick_work); spin_lock_init(&dev->vqs[i]->kick_lock);