Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7116230rwl; Wed, 22 Mar 2023 22:33:57 -0700 (PDT) X-Google-Smtp-Source: AK7set+YeMgWdXAzYzTPsDb6K3DVM1AL9rg6RLTCWKyPemWM42BxmUKr0ion2fJ0PNPX2XJ4dK1o X-Received: by 2002:a05:6a20:8b14:b0:cc:d7ec:b7c with SMTP id l20-20020a056a208b1400b000ccd7ec0b7cmr2311179pzh.4.1679549637262; Wed, 22 Mar 2023 22:33:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679549637; cv=none; d=google.com; s=arc-20160816; b=lG8t2QGChvtLGrD5UNXNGfbd4QFRXpOuEx7MpZ0otKulnlLYtdJdtcXcS7g8hoXAuC SqVkE1s2h2/mZmZ6G8eDIxasqCTwtQrw9JPNlOuB/O3swh58rhdqlOq1dhyxzE9TGwb1 LCrk+hXbO96SxtdMwOWOnHWfnGTU+j3NGO2iJjJnnpLpie09FBc3hrCbFkacuWyJsTrn uzy7cSLlsbuLwqNXiQyMG9nFAyKeafvmCroBy3K88MuAiM5XTk9WgmxUa3L8OFfgx8ih fabXmX+gdk7z1TBEXC3H10TyJX4SZY7uhgb0FgDpxKYhxVTVR/l1C+4zIsuv4WPJh5Wp LBYQ== 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=z3L8PmXiSvjLVceUhGVSQ/YpVSqRUm7l08t6hYdW7rQ=; b=nvCAk6CqOZ6mpezt/cTeQAjgfUYD7liQgQtzotG1HJZJOVy61sMaR4i8HWi16sHVVv 9sCXk3UIPPtOnLMLPNmp4HYfUs5n6przwuEz8GiaWZXqGdWROqi86imsUHNLu9tIE6JZ A2gLIsr2R6/x+PGOkjankpG5FBJddEDpOjRS1a8bXq9qkvwk5Tz8jBv9MSJ3dq0w4nHr y9cvYOmBt/S3ONxUaNCeMbAWmW/dTjJRm1wcBNkU6VlrFIbdA1TYKc3hEJpxkfP7GXc7 QJpuoiMGMUqT7WqfeXxKCplz/t73gU/JVASwoOgeCCQyiBlfaJdcfA4j3IcrxEciIo4d dQEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ZcREzIu7; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a63e70c000000b004fc257265cfsi18122123pgi.267.2023.03.22.22.33.45; Wed, 22 Mar 2023 22:33:57 -0700 (PDT) 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 header.s=google header.b=ZcREzIu7; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231217AbjCWFdO (ORCPT + 99 others); Thu, 23 Mar 2023 01:33:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231140AbjCWFcg (ORCPT ); Thu, 23 Mar 2023 01:32:36 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D503331BFF for ; Wed, 22 Mar 2023 22:31:43 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id q102so6022693pjq.3 for ; Wed, 22 Mar 2023 22:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549501; 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=z3L8PmXiSvjLVceUhGVSQ/YpVSqRUm7l08t6hYdW7rQ=; b=ZcREzIu7n87MPds+0JEnBXyCnfjLevqaZTyGPMTWqzFXLsm9zhW/EGCBw9+75/b7uA dDwbU0gBfmuhRD/k48xb1fwWQd7/nBUoyYOHx0NhuBkIjegKc/UfcOdUDMyVUUejofDm N0muRXClPNJdvCQPhQYzbD75+0Sv8I2m8KzPFX0A6gVyDxkr1Cdl8W42Is3gUmgasZST nwXCw9TipfhS0fU09I3ioxtyd67i8pbD1e9ijFQ0P2NtOlYXrufpCROOS16eT2fa/XYQ W9B/lzynns5i8E/1983hOL2a1CT8jKJPwyXiNw9cNi1natn8lwssfDXpXpXJtHCd3E68 89xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549501; 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=z3L8PmXiSvjLVceUhGVSQ/YpVSqRUm7l08t6hYdW7rQ=; b=3tzMZ3pug3ILlRovAi0qrefsmpCxFb6FZr+90gyolg95OSbsroyfFkcR16nTULFSd8 ymsHaiD0kxcCKHK9bvAbVZbJIjjyVjstVJWcpUV+ilocrfI3aOed23jb7gx/YLwbaxLN jSZZgQfCUGfoVNeFhEILDw1w51vqA+u4iBfaQc9geHKXk3YDSd19teDLQx9Tyiw91BrA dU5JFbcbZGKcm3TEmKnQm7pWt9uHHCx852mQfab0n3/J3XtK6LNTPTtTm7O9YgB6nX1k bnNVFW4Zm4Jo4wUNKiTjRt09P2aXnK3GB1UcJp1EpjV1lrAp2SbXF+o3HC7mjNUF6jj7 FZZQ== X-Gm-Message-State: AO0yUKUGVHYx0C1oceAS9EySSTGPgdfrdM6EO9nbQzc/HtigMgJcpBVs tQ575emDZphJgM8XBoJ2jEdt X-Received: by 2002:a17:902:6944:b0:1a1:b3bb:cd5b with SMTP id k4-20020a170902694400b001a1b3bbcd5bmr4657750plt.62.1679549501430; Wed, 22 Mar 2023 22:31:41 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id d9-20020a170902854900b0019c90f8c831sm11419677plo.242.2023.03.22.22.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:41 -0700 (PDT) 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 v4 09/11] vduse: Signal vq trigger eventfd directly if possible Date: Thu, 23 Mar 2023 13:30:41 +0800 Message-Id: <20230323053043.35-10-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230323053043.35-1-xieyongji@bytedance.com> References: <20230323053043.35-1-xieyongji@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Now the vdpa callback will associate an trigger eventfd in some cases. For performance reasons, VDUSE can signal it directly during irq injection. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 77da3685568a..8c06f6ab960b 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -459,6 +459,7 @@ static void vduse_dev_reset(struct vduse_dev *dev) spin_lock(&vq->irq_lock); vq->cb.callback = NULL; vq->cb.private = NULL; + vq->cb.trigger = NULL; spin_unlock(&vq->irq_lock); flush_work(&vq->inject); flush_work(&vq->kick); @@ -524,6 +525,7 @@ static void vduse_vdpa_set_vq_cb(struct vdpa_device *vdpa, u16 idx, spin_lock(&vq->irq_lock); vq->cb.callback = cb->callback; vq->cb.private = cb->private; + vq->cb.trigger = cb->trigger; spin_unlock(&vq->irq_lock); } @@ -941,6 +943,23 @@ static void vduse_vq_irq_inject(struct work_struct *work) spin_unlock_irq(&vq->irq_lock); } +static bool vduse_vq_signal_irqfd(struct vduse_virtqueue *vq) +{ + bool signal = false; + + if (!vq->cb.trigger) + return false; + + spin_lock_irq(&vq->irq_lock); + if (vq->ready && vq->cb.trigger) { + eventfd_signal(vq->cb.trigger, 1); + signal = true; + } + spin_unlock_irq(&vq->irq_lock); + + return signal; +} + static int vduse_dev_queue_irq_work(struct vduse_dev *dev, struct work_struct *irq_work, int irq_effective_cpu) @@ -1243,11 +1262,14 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, if (index >= dev->vq_num) break; + ret = 0; index = array_index_nospec(index, dev->vq_num); - - vduse_vq_update_effective_cpu(dev->vqs[index]); - ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject, - dev->vqs[index]->irq_effective_cpu); + if (!vduse_vq_signal_irqfd(dev->vqs[index])) { + vduse_vq_update_effective_cpu(dev->vqs[index]); + ret = vduse_dev_queue_irq_work(dev, + &dev->vqs[index]->inject, + dev->vqs[index]->irq_effective_cpu); + } break; } case VDUSE_IOTLB_REG_UMEM: { -- 2.20.1