From patchwork Thu Mar 23 05:30:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2741702wrt; Wed, 22 Mar 2023 23:03:43 -0700 (PDT) X-Google-Smtp-Source: AK7set/WgLvFiGK1dCXVeurelfQSoemt9evxhd54FmIU3LwC5HY9deKOLTvsGtRGcFE6fGBLNkWS X-Received: by 2002:a17:90b:1e01:b0:23f:81de:6a74 with SMTP id pg1-20020a17090b1e0100b0023f81de6a74mr6646507pjb.39.1679551423279; Wed, 22 Mar 2023 23:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679551423; cv=none; d=google.com; s=arc-20160816; b=RvMql/pJvVRQY9MvyMcueYsCoBt1AjZAckTeb6eNbJN+jBhyrBp8+z303G/2qvZyff bhvdldddFMKQznrSxeWmQlTQAax9JbAWaO8WaKiMrbxZwnYbzaru0hn3ogGCSsF7vshU oiTE7eWDBrg6gJxgtmC1I0cpiUUGsEmcuaTA6rel+amhLXMfmxmMvdm2w23oPCLQegi8 RTOCsbEcrIsA34/n1SvgkelJe5CoPsiIIe53F+187PhECzODUJDTowEjwfn0WKZkGKWC wQnVq1S6i9sxqnM2myrGqiuyAS6jG3bGyjjjlMGgOGI99t1oLJVDbsdwuqcw31pN62tz /v5g== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r18-20020a170902c7d200b0019ca5ddecfesi16471254pla.92.2023.03.22.23.03.30; Wed, 22 Mar 2023 23:03:43 -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 S231218AbjCWFdP (ORCPT + 99 others); Thu, 23 Mar 2023 01:33:15 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761137313033246129?= X-GMAIL-MSGID: =?utf-8?q?1761137313033246129?= 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: {