From patchwork Thu Mar 23 05:30:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2738240wrt; Wed, 22 Mar 2023 22:52:24 -0700 (PDT) X-Google-Smtp-Source: AK7set9a9enCw/qvM4jHi12AlzZT4VGlN+2sET9r8BDva4j5ElN9ICs7uhk/kkmGDZlsG23a4KvE X-Received: by 2002:a17:902:e1d4:b0:19c:e666:a678 with SMTP id t20-20020a170902e1d400b0019ce666a678mr4331374pla.50.1679550744411; Wed, 22 Mar 2023 22:52:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679550744; cv=none; d=google.com; s=arc-20160816; b=BSCpZ2htnuFlRrPMc9sUahRq22Qt8idkrJTXs98YBcvQX9RnTXnjkWc5utbntuvftE TIJ/7lftR8JQwG77fPRTURzLQvr/ZdkjlIAMzSmSb1+VgJelfp889Ojm9Nqdbs0i6Nuj ZWTnt8P4I/4WDbBADx3+gzJDhtG/gYmoXwpHXBxxt+7YNZUOTbLpUACsXEsM9H1zm5MX PE2mtT3/kooDN2cMF9bIjUOMMhP1avXw6LOmkuAH2CNCDuFyiqHJbQshg3VVp6AskVCW Lahb1AVQdMsyv3iofZVga6coJK77xB4C/W/A+dYObZ8+9KWgDdD6rlYNlqG8Z9XLIaVd xulQ== 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=m3DhZ6b2/Cat//geb2wYI+Q6V+P6wWnnhrfxNudLCpk=; b=I/QSgHiIVBO+h2JlF7efFb5vI8FrRyv+vZ5G814hhN9+5FfQuHgI/8VrWBUAzA6HG7 R5Jt2X1XWB7/Ufeut/fqsQYLj5CQ40Du4AYDXizlhVa1dFpk8Lxeq8o3puKYuBB2ZhoX cr6pd+O7OWHRRM8NsgpWdEvNMqsAuMPwVW24iJkN6j8vJFzQXSEHDkeX6pSSpBoXGWv0 zC6WNgcNxsAk5NEpcTqNnjKDsFqK6nf2KmNkBq/WeXgS+PsMHKOBxdEoprkap97ZI4qz 3FjLhIXwXJBIBMODlszU133PLxRjee3xEj7tLF0htRqz8srA07nWOzcvu0XVLN9VqiNR E5mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=e6HcJuDF; 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 a23-20020a630b57000000b0050fad17282dsi4866793pgl.217.2023.03.22.22.52.10; Wed, 22 Mar 2023 22:52:24 -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=e6HcJuDF; 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 S231153AbjCWFco (ORCPT + 99 others); Thu, 23 Mar 2023 01:32:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230484AbjCWFcV (ORCPT ); Thu, 23 Mar 2023 01:32:21 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2160622018 for ; Wed, 22 Mar 2023 22:31:20 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id le6so21291175plb.12 for ; Wed, 22 Mar 2023 22:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549476; 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=m3DhZ6b2/Cat//geb2wYI+Q6V+P6wWnnhrfxNudLCpk=; b=e6HcJuDFL4JYzLtGSwoRmFcMtNkc0XY58kIpmAnTCLtZgo9O5haDVBc/i4Cid4cH7v crtFyTSRHTwyeQYit4X5M6KWBNNTTHfPgJ1kOFnl9UWwrrKE08k6jzyLO14WPuRyn2Nd Rw2kl4tHknYtTyZEr6cDPVpHOvPNXjPfWzAuf5Z8ADcAvvc7lZYHbZWwKtbo4jwfqh+/ 6mtBBrigpvPgeV/+C/7hP82YR1SCUEXYgP9r8dVti3dduEzir+f7TuPeOf2sxQl628Oe 0fonCwiRBMB/2E6qW+W2HFZaXg0asiY1y03TEVWUa34y9bt67UbbAlohXzmllkBjA73J VuhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549476; 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=m3DhZ6b2/Cat//geb2wYI+Q6V+P6wWnnhrfxNudLCpk=; b=hFSUmVoXWjZ0rt6LmqRNU319CSXERxFRd4kRm0eLTUrP8EQp8+1QQNEvZKXPRxuKtN VFpm9pfQGFJDcBTT7+au19fIar6jwneKYN+VoUelLYl7zjxtFFMrBQskvgoD6mAscABQ 5Ph6sWIRKpaKmu4Ax3qbVDCrU0S4sJBDsUYw+xQm7F/GUHblRu9Rza49W5wxe0zageHH 3g0KfbBTZgYrQ1CCaHalTpgPBxXHsMQBu4PDeOP9kawxK0YxFqZe4YLOM3XBg0kv/g43 jzuPuhYUg6aBH+Ow1KaCKAGCvZM2UXB+TtfPEPQIzWGJ5a28qcWDSEXypPlQL2IuK59/ bzUw== X-Gm-Message-State: AO0yUKUsLm7eAsmDlijMWYK3JA98DEFVokI74sD9WM3q244nOLp6/R4u 1TOna2136rT0YQpCJDQwRdIb X-Received: by 2002:a17:90b:17d2:b0:22c:816e:d67d with SMTP id me18-20020a17090b17d200b0022c816ed67dmr6798965pjb.24.1679549475944; Wed, 22 Mar 2023 22:31:15 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id m3-20020a170902bb8300b0019a7d58e595sm11443864pls.143.2023.03.22.22.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:15 -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 01/11] lib/group_cpus: Export group_cpus_evenly() Date: Thu, 23 Mar 2023 13:30:33 +0800 Message-Id: <20230323053043.35-2-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?1761136601368213754?= X-GMAIL-MSGID: =?utf-8?q?1761136601368213754?= Export group_cpus_evenly() so that some modules can make use of it to group CPUs evenly according to NUMA and CPU locality. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- lib/group_cpus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 9c837a35fef7..aa3f6815bb12 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -426,3 +426,4 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps) return masks; } #endif /* CONFIG_SMP */ +EXPORT_SYMBOL_GPL(group_cpus_evenly); From patchwork Thu Mar 23 05:30:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2742144wrt; Wed, 22 Mar 2023 23:05:06 -0700 (PDT) X-Google-Smtp-Source: AK7set84QYXXB07YLS4pbHaAdpqRlokl29IMgYMwlVxz8DiYDLn+qavMHE6NMUPaR04tlaommE5P X-Received: by 2002:aa7:d74d:0:b0:4fd:2290:976d with SMTP id a13-20020aa7d74d000000b004fd2290976dmr8624889eds.37.1679551506110; Wed, 22 Mar 2023 23:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679551506; cv=none; d=google.com; s=arc-20160816; b=aih6Fq3UOADDRnKAjnGSNH5z2eT8ndxycOOKRBBmXsT10YGRrh5cUy5Snz80+Wboez wDv3ebAapC4dLlWL6QZR2SqkSboMO7LSWiyu9acbKOMnLlAV/JU+itvGdvrhAEjUBg/U oYyY5XnC2m+8X/etitJ0qUIpEjNaKCVGIG9Lg1BdTP4Ei5cNEOJDpTDcp4OZ6BWRaie8 W7pEexmmec4Kb7ZvG4l+cWVLyUUVIzs+663rSYXdglV0MIV78QQxxTdhP2t6QTSSjIkp +PsjeRT0fOTGBUiDqDTaQoDGVtntj04TUb2emuNeL+Vmis9bxP9p9Ms1Mw4CpjsVm0/e no1A== 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=ihxW9QIYwW7geYYIsi25taexnQY98X1VOl5aytZk5u4=; b=NyQuyCFWZHICukNLIxCbyIH546o7lPK2rlEdPFXabSfceKTDMZhnYY8iqk2+FwkbEp D0zyWZjGmTL6QW2WHB3PvNkFdqExzP7hXTDiC6Qe2bPtfDalnj/sTEpqoPhLC90tQBOQ u7E2PH7JXPuZer5aiabChxytyA1F4dfo4c3HUM6in13v5ODDluPgTYtBdCZWm2SmGo/a e4e+W1s9Lt2m0G0g1RW2uAVUu3t2PmImBhcOzOzEHUJiAVPVSkMgrS+26rhk5BGoKtyw ws3NHIyCSiXyf7Em7LKMnCxVFVj2IlIszmBhQiHi5j9qCYfT8zl6En4AGvh2LU7qRJu/ w1Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=kIURKCtR; 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 e21-20020a50fb95000000b004fb3426ea95si18311814edq.322.2023.03.22.23.04.42; Wed, 22 Mar 2023 23:05:06 -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=kIURKCtR; 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 S231162AbjCWFcq (ORCPT + 99 others); Thu, 23 Mar 2023 01:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbjCWFcX (ORCPT ); Thu, 23 Mar 2023 01:32:23 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 246D82BF12 for ; Wed, 22 Mar 2023 22:31:21 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id o11so21336423ple.1 for ; Wed, 22 Mar 2023 22:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549479; 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=ihxW9QIYwW7geYYIsi25taexnQY98X1VOl5aytZk5u4=; b=kIURKCtRiCNlA/czcj4Vbbn/aPsD7HY6PBQRckQpSqqq6tcuS8WO695O85xiYDI7IN mj7F/qgUN6n/E4wc+SBODKr2dmT6S0Mxa6W6VLKt+s0eEF+lZkTQOyBVOT0F0s3DWh48 OAfvD8YdDYpxZ0m5mG39Suz/wYhEJcgo88I8+odM8Cr8qlmKUH63CnuPgiMCzWsVS5ap ghhRHepFPg99tHTLSyjPQHFnCFcjbbPBJ0V8+fd86fp4ep5JDV6PpOZV6G//DkAFLYAt lV3qsnaZk9q8KMlbZbmRM7g+gpjuhaG0dZ3CkhJLEkwk5CKYb8yc0jvlPmAVEMPhc9BP CmOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549479; 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=ihxW9QIYwW7geYYIsi25taexnQY98X1VOl5aytZk5u4=; b=MCQStOKVHhqb845bUs5DKMXQLdSeyV70EZGg/hYcgesVvwJ30mhlCIRLnt0vdWzBMU pKSVYClU1ZJqTq3GG+CN3DhJGNPodikKzzUy+WUwt1k1f/Ai3lS0zrmZ3+idzeVyZw4H vIXbBNnH5cVdRebsdOH4JX6Mf7ZjXnnOaUASKuvU0ECP8U7R3lIdQYSG9DGQYjNn4b/B MZ8IaCAcgVQvnl0dPWp9XZQC1oUeUe39QT+EYsJC9xX61DOofksncCVP1A7IEZeRv/uZ 8e7Uw3o0+Wli/5oskood/k4Vmx8Cym5lv1o8O4DSKv05eZzUVAq3qBGs5Z+Xh0eoP1Bf vLWA== X-Gm-Message-State: AO0yUKULMXD87+KTt/T6BM6EiXdJmYbGW9qkt8VT0Wkbfqwh2RRT5E18 Hx3aPa8RMaIj1wQfcS+TI29ATZSbFZMw5b+VGQ== X-Received: by 2002:a05:6a20:ba87:b0:d9:949e:a72 with SMTP id fb7-20020a056a20ba8700b000d9949e0a72mr1560552pzb.60.1679549479099; Wed, 22 Mar 2023 22:31:19 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id p14-20020a62ab0e000000b0062505afff9fsm10953459pff.126.2023.03.22.22.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:18 -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 02/11] vdpa: Add set/get_vq_affinity callbacks in vdpa_config_ops Date: Thu, 23 Mar 2023 13:30:34 +0800 Message-Id: <20230323053043.35-3-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?1761137400284439029?= X-GMAIL-MSGID: =?utf-8?q?1761137400284439029?= This introduces set/get_vq_affinity callbacks in vdpa_config_ops to support virtqueue affinity management for vdpa device drivers. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/virtio/virtio_vdpa.c | 28 ++++++++++++++++++++++++++++ include/linux/vdpa.h | 13 +++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index d7f5af62ddaa..f72696b4c1c2 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -337,6 +337,32 @@ static const char *virtio_vdpa_bus_name(struct virtio_device *vdev) return dev_name(&vdpa->dev); } +static int virtio_vdpa_set_vq_affinity(struct virtqueue *vq, + const struct cpumask *cpu_mask) +{ + struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vq->vdev); + struct vdpa_device *vdpa = vd_dev->vdpa; + const struct vdpa_config_ops *ops = vdpa->config; + unsigned int index = vq->index; + + if (ops->set_vq_affinity) + return ops->set_vq_affinity(vdpa, index, cpu_mask); + + return 0; +} + +static const struct cpumask * +virtio_vdpa_get_vq_affinity(struct virtio_device *vdev, int index) +{ + struct vdpa_device *vdpa = vd_get_vdpa(vdev); + const struct vdpa_config_ops *ops = vdpa->config; + + if (ops->get_vq_affinity) + return ops->get_vq_affinity(vdpa, index); + + return NULL; +} + static const struct virtio_config_ops virtio_vdpa_config_ops = { .get = virtio_vdpa_get, .set = virtio_vdpa_set, @@ -349,6 +375,8 @@ static const struct virtio_config_ops virtio_vdpa_config_ops = { .get_features = virtio_vdpa_get_features, .finalize_features = virtio_vdpa_finalize_features, .bus_name = virtio_vdpa_bus_name, + .set_vq_affinity = virtio_vdpa_set_vq_affinity, + .get_vq_affinity = virtio_vdpa_get_vq_affinity, }; static void virtio_vdpa_release_dev(struct device *_d) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 43f59ef10cc9..e52c9a37999c 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -250,6 +250,15 @@ struct vdpa_map_file { * @vdev: vdpa device * Returns the iova range supported by * the device. + * @set_vq_affinity: Set the affinity of virtqueue (optional) + * @vdev: vdpa device + * @idx: virtqueue index + * @cpu_mask: the affinity mask + * Returns integer: success (0) or error (< 0) + * @get_vq_affinity: Get the affinity of virtqueue (optional) + * @vdev: vdpa device + * @idx: virtqueue index + * Returns the affinity mask * @set_group_asid: Set address space identifier for a * virtqueue group (optional) * @vdev: vdpa device @@ -340,6 +349,10 @@ 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); + int (*set_vq_affinity)(struct vdpa_device *vdev, u16 idx, + const struct cpumask *cpu_mask); + const struct cpumask *(*get_vq_affinity)(struct vdpa_device *vdev, + u16 idx); /* DMA ops */ int (*set_map)(struct vdpa_device *vdev, unsigned int asid, From patchwork Thu Mar 23 05:30:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73829 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2739067wrt; Wed, 22 Mar 2023 22:55:43 -0700 (PDT) X-Google-Smtp-Source: AK7set9hNPPgdHRPpaY1PvOGYBLYOzt2updcw2r1O4D+FqhNJEsbjQHp65OjOPUDDzh2pF4A/357 X-Received: by 2002:a62:84d0:0:b0:628:184f:2c5 with SMTP id k199-20020a6284d0000000b00628184f02c5mr5549232pfd.14.1679550942830; Wed, 22 Mar 2023 22:55:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679550942; cv=none; d=google.com; s=arc-20160816; b=Bspa9lyrHHEcUvCvgVERBab8qHO1vpOOHXPM4svE4eqjLQGA3u1N4E8y9hfWrcSl1d Y7X/bK3HtOvk7nkz7M1QjaE1nMIUT36ImM6vzQjUZE/947rVcYqI8sJgHvSroqklLRbc wlQjT1gUDF+YqI/cl4qsl3o4wl+eAhj11I9RqJJCpitOUJ6PTAix4jK1BU4Wgxc1bGEz Xdhy8knNMMcKlqaVVL45yWjVN7aNl/YAcRgNxjGWyXeLcYvThDAEhWIMS3B64AydWJzZ wUdMKii34R1QqJlj8nLblmRTRzxiHOxb2KWZlPlQklWof8sGjMJusEfQzpvMNUL9zX+H mj8g== 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=QcDeLFrXedHSKuPyT2iyCEdMTIpqJ+T19wOg244Ts4I=; b=hWu1DrN+4tMNKBqjZBhi1+qUMjY5ZwqQ24QD8lpTMWHtqN31xzp4YU31fjBRoGMnDK YY4BWjG+r0iLFJsRYoTx2zqZES0GRrTNiabEkv4YLeySWOCmYCUjhUb+x8U3sWdsmcXF zY53pr+zVf08e2JtMpGFLOXbTZBUcg6sro8qWlf9yYWOsIJjsEXNVnSJijXVGpz39vJi hXPZKyAo9Mh2z2oz2gMrgnz2LC5FELqH+Z/cc3jxrJRktYNb3ZatpNXY4OO20L40wnhp raS5OHPnT+NS7XJRea8k5p1iC6T8K50tm2CVMG6+HG8DfEaQoURH3ZWF5TWd/tOzwf0U aFzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=W9SSFngk; 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 x185-20020a6386c2000000b005089e773be5si18839869pgd.661.2023.03.22.22.55.29; Wed, 22 Mar 2023 22:55:42 -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=W9SSFngk; 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 S230457AbjCWFcf (ORCPT + 99 others); Thu, 23 Mar 2023 01:32:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbjCWFcB (ORCPT ); Thu, 23 Mar 2023 01:32:01 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9635C31BCD for ; Wed, 22 Mar 2023 22:31:23 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id kq3so8919736plb.13 for ; Wed, 22 Mar 2023 22:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549482; 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=QcDeLFrXedHSKuPyT2iyCEdMTIpqJ+T19wOg244Ts4I=; b=W9SSFngkB1ECAtiQ37iuP109gTcmletw6vq+zRxp/NRGzpExnhGsK4kPrjj1ak5b4L aeyffW2TlZUySj70RZs94gUF8zv5FdUiHpxw15qAr9fH0T05eV+3IiKo4jC8gWqa8YLa C8kTUg6jzQNubyAjSltIJFxWsVlc+4h+aIUvW50QX7Q25sCZj/FO5DpLggKQ0Zelmlj4 JLQavFZ9OYxOYqJK22eDQHcjDTrs3xbkJBLEkNO5E/KweCY+9fTUSkHmbs7CRWVKEo5f 3nf9rgKyv8tVgNS3os7wQGnVJgwRKAuN0q0f6TRupP3UlA9jIH0YdL7GfJhPp4ZuNSxJ b4ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549482; 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=QcDeLFrXedHSKuPyT2iyCEdMTIpqJ+T19wOg244Ts4I=; b=z4VQNziPIDW33eFUuzDtYlXG+WSqYSiipwuqznLducSuUjMk4McuIZewSbgwZd/rrE G/T4CpQ+x2mKVJAr9tpd/IKAr4psGCpLwztnVYLfs7r3gtlV1Ex6YmAOJwVZfG1Rw4EI OigHIfQmSNSE1JdokNDZvtFL9V03qo/nAYb9u4QwlwciC138xPCJQPbcSgzc94PjBeKc dNA9ZsXqSDLP0n1Hdo8Ly7Hq/F5hrM41rD12cF6A9cxFYcS9lhA5JK6cCNG76fdque4r d0Cs/j8zaqsDdiZDKmY4JoeEbbM4evWOIxqYSnQUSup2MZhdt+p5tk55EpNGQ/0cJtfe Sszw== X-Gm-Message-State: AO0yUKUTkt/zlsu4GqS79O+BUW7Ky9YOBFjjqs5w6Kr2spcas13yYWyL HDsJznXSu2rWIGjBY6X6MBSaiN+OJM/LUK5A2A== X-Received: by 2002:a17:90b:1e42:b0:23d:39e0:13b with SMTP id pi2-20020a17090b1e4200b0023d39e0013bmr6254179pjb.43.1679549482181; Wed, 22 Mar 2023 22:31:22 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id d9-20020a17090a6a4900b0023c8a23005asm431804pjm.49.2023.03.22.22.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:22 -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 03/11] virtio-vdpa: Support interrupt affinity spreading mechanism Date: Thu, 23 Mar 2023 13:30:35 +0800 Message-Id: <20230323053043.35-4-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?1761136809622036277?= X-GMAIL-MSGID: =?utf-8?q?1761136809622036277?= To support interrupt affinity spreading mechanism, this makes use of group_cpus_evenly() to create an irq callback affinity mask for each virtqueue of vdpa device. Then we will unify set_vq_affinity callback to pass the affinity to the vdpa device driver. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/virtio/virtio_vdpa.c | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index f72696b4c1c2..f3826f42b704 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -272,6 +273,66 @@ static void virtio_vdpa_del_vqs(struct virtio_device *vdev) virtio_vdpa_del_vq(vq); } +static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs) +{ + affd->nr_sets = 1; + affd->set_size[0] = affvecs; +} + +static struct cpumask * +create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd) +{ + unsigned int affvecs = 0, curvec, usedvecs, i; + struct cpumask *masks = NULL; + + if (nvecs > affd->pre_vectors + affd->post_vectors) + affvecs = nvecs - affd->pre_vectors - affd->post_vectors; + + if (!affd->calc_sets) + affd->calc_sets = default_calc_sets; + + affd->calc_sets(affd, affvecs); + + if (!affvecs) + return NULL; + + masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL); + if (!masks) + return NULL; + + /* Fill out vectors at the beginning that don't need affinity */ + for (curvec = 0; curvec < affd->pre_vectors; curvec++) + cpumask_setall(&masks[curvec]); + + for (i = 0, usedvecs = 0; i < affd->nr_sets; i++) { + unsigned int this_vecs = affd->set_size[i]; + int j; + struct cpumask *result = group_cpus_evenly(this_vecs); + + if (!result) { + kfree(masks); + return NULL; + } + + for (j = 0; j < this_vecs; j++) + cpumask_copy(&masks[curvec + j], &result[j]); + kfree(result); + + curvec += this_vecs; + usedvecs += this_vecs; + } + + /* Fill out vectors at the end that don't need affinity */ + if (usedvecs >= affvecs) + curvec = affd->pre_vectors + affvecs; + else + curvec = affd->pre_vectors + usedvecs; + for (; curvec < nvecs; curvec++) + cpumask_setall(&masks[curvec]); + + return masks; +} + static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, struct virtqueue *vqs[], vq_callback_t *callbacks[], @@ -282,9 +343,15 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vdev); struct vdpa_device *vdpa = vd_get_vdpa(vdev); const struct vdpa_config_ops *ops = vdpa->config; + struct irq_affinity default_affd = { 0 }; + struct cpumask *masks; struct vdpa_callback cb; int i, err, queue_idx = 0; + masks = create_affinity_masks(nvqs, desc ? desc : &default_affd); + if (!masks) + return -ENOMEM; + for (i = 0; i < nvqs; ++i) { if (!names[i]) { vqs[i] = NULL; @@ -298,6 +365,7 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, err = PTR_ERR(vqs[i]); goto err_setup_vq; } + ops->set_vq_affinity(vdpa, i, &masks[i]); } cb.callback = virtio_vdpa_config_cb; From patchwork Thu Mar 23 05:30:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2737001wrt; Wed, 22 Mar 2023 22:47:41 -0700 (PDT) X-Google-Smtp-Source: AK7set/54CBx9IDLsRs54dNb9hs5CahMLyimK4VzcqRX2pd3iDHoRhTsmU6KmfSB5p/DKDoud9XZ X-Received: by 2002:a17:902:f947:b0:1a1:8860:70d7 with SMTP id kx7-20020a170902f94700b001a1886070d7mr3866258plb.48.1679550461337; Wed, 22 Mar 2023 22:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679550461; cv=none; d=google.com; s=arc-20160816; b=MiR6n1gKwot/zOQHULFAOVRlbx7aTEoEbwY92pDutYPHOl/p6cx651UWxq29NJKM4k FD+i/rJqbadn/VKuKA0qhWS/7rLHm2RObgLzghC1D/E5g8+YEAtirygmO5I7PWNgNM32 5LFeH57CMQB0Qoxty8jrY3hPleymOe8DWHMXPVEK48gDvdDrkJAjZl05/azH30D11NsI lrqBzJqxtpQ2pXCEzygCRh0a+IqJqklcZag++mX1wdz6IKXDr7O818qdtsCzNmFuG6Qs JQK0XW1VXH4hLrpV+PtD+dfWaKRRLyJYWE2RHY9Tkw/++Ec6L37Ph5DmTEsie4z/fU3T N3oQ== 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=sPERv8sXud0KxJcvENIsE+Ngn3x88OA7gINkyBoEiFY=; b=nZea0T7G7gROg4HSOnxsbF32jLKRO7hZ+VVUkid+R5FTWzp6kTcDeJLI1DxhRc/vOi 2sRceIT1YfP0DTS5obRa45Wod4KFSX3J417sixATFCfJFnbk8y89CgBooxlagsgurdjm iwF3ZcFahawwHfFWV0Yp/K1YNXOevgccnrepBuJNHiB6yLxQ7M3eByFt1H+neOFk1xfW ocKSKtI1gdyXRP1hz8qRPgTQlFWaJ3XNIifwh3avfQxPkIPd3GusDrH1NNA6IzcaS4Ss lYXiShccsXhkUQZKEvLs7JF79HllTxVbdGXBRQ7qy5gQZT8SW/IQ49Qzy2r/DRvSl9wV ne1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=HDo3fOcu; 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 e33-20020a630f21000000b004ce76fa9ebdsi17979394pgl.387.2023.03.22.22.47.28; Wed, 22 Mar 2023 22:47:41 -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=HDo3fOcu; 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 S231126AbjCWFdI (ORCPT + 99 others); Thu, 23 Mar 2023 01:33:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230436AbjCWFc3 (ORCPT ); Thu, 23 Mar 2023 01:32:29 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEF1122113 for ; Wed, 22 Mar 2023 22:31:26 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id z19so10902464plo.2 for ; Wed, 22 Mar 2023 22:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549485; 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=sPERv8sXud0KxJcvENIsE+Ngn3x88OA7gINkyBoEiFY=; b=HDo3fOcuMDvIymivNHkUpjQGPYRVKheiptaARLg89wfeHm1n0nsX1k+GwXh1pIqqpR xBuZlOWINzdJh+EeazlKZoYzqJnO/reSswiMHYx9loTvjvEEu9O3/ElDcZAFNi51zUm5 3FI9fiQWLll+Skq4pkVR/6lEH6ftSo8Ez03nHZEbRxMROTzaLR1awG9pqS7CEUVkVd/+ QGILWR0V6bQsFTi/CiGatEJqM/uSe53jXqHlfjsUT8HiUTcbn18sHN2agxiOqUYC2RK6 aEmWpH2jRgMwIkAgWXws1j5DesbXbP+2leiFspt/7mlY/qAh1ZYgqe+NhNw7KgjntHqz O2eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549485; 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=sPERv8sXud0KxJcvENIsE+Ngn3x88OA7gINkyBoEiFY=; b=k/GlEIpHIN2Cx/YPJsETCEDxQSohpzFQIVK2r/xMrWPUaTZpUiukqP8TrEaxsyyof5 K8mgUOeP1CDHni4y4iyEcjVLNBr9udFhSKjvaEHH3++vWsPatD8a92RPHocdAmruygRa sxuJHvCqLHuJ1fhL8yw3ic6vtZh/l+l/41cpzW8JFtvu1m+4CdF4LYhcxq4qFjd9oNAI p1ElQ6Ot3APYVzuKjRuDn+WqMa3c96yk+rVKdZSv6ePsT3hFs4KpneL7NMUmS+uM7SgU 9EdZr5IJ7N19eHhGQDp+W+XpfSUBcbGLRn8HFfO9nOem6+3eT1fg8GJOMuXz0DgFnXlX ZJ3w== X-Gm-Message-State: AO0yUKWVTUMoAwKTN294D8BRd6dfpdj5T5zEq3N0SiXVLZHr/2wmqKDe YREC2igCLrT99JhFQqklunOv X-Received: by 2002:a05:6a20:2098:b0:d6:7264:f44e with SMTP id b24-20020a056a20209800b000d67264f44emr1693121pza.3.1679549485470; Wed, 22 Mar 2023 22:31:25 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id c26-20020a631c5a000000b00507249cde91sm10538807pgm.91.2023.03.22.22.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:25 -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 04/11] vduse: Refactor allocation for vduse virtqueues Date: Thu, 23 Mar 2023 13:30:36 +0800 Message-Id: <20230323053043.35-5-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?1761136304122471315?= X-GMAIL-MSGID: =?utf-8?q?1761136304122471315?= Allocate memory for vduse virtqueues one by one instead of doing one allocation for all of them. This is a preparation for adding sysfs interface for virtqueues. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 98 ++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 32 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 0c3b48616a9f..98359d87a06f 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -76,7 +76,7 @@ struct vduse_umem { struct vduse_dev { struct vduse_vdpa *vdev; struct device *dev; - struct vduse_virtqueue *vqs; + struct vduse_virtqueue **vqs; struct vduse_iova_domain *domain; char *name; struct mutex lock; @@ -434,7 +434,7 @@ static void vduse_dev_reset(struct vduse_dev *dev) flush_work(&dev->inject); for (i = 0; i < dev->vq_num; i++) { - struct vduse_virtqueue *vq = &dev->vqs[i]; + struct vduse_virtqueue *vq = dev->vqs[i]; vq->ready = false; vq->desc_addr = 0; @@ -466,7 +466,7 @@ static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx, u64 device_area) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; vq->desc_addr = desc_area; vq->driver_addr = driver_area; @@ -500,7 +500,7 @@ static void vduse_vq_kick_work(struct work_struct *work) static void vduse_vdpa_kick_vq(struct vdpa_device *vdpa, u16 idx) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; if (!eventfd_signal_allowed()) { schedule_work(&vq->kick); @@ -513,7 +513,7 @@ static void vduse_vdpa_set_vq_cb(struct vdpa_device *vdpa, u16 idx, struct vdpa_callback *cb) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; spin_lock(&vq->irq_lock); vq->cb.callback = cb->callback; @@ -524,7 +524,7 @@ static void vduse_vdpa_set_vq_cb(struct vdpa_device *vdpa, u16 idx, static void vduse_vdpa_set_vq_num(struct vdpa_device *vdpa, u16 idx, u32 num) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; vq->num = num; } @@ -533,7 +533,7 @@ static void vduse_vdpa_set_vq_ready(struct vdpa_device *vdpa, u16 idx, bool ready) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; vq->ready = ready; } @@ -541,7 +541,7 @@ static void vduse_vdpa_set_vq_ready(struct vdpa_device *vdpa, static bool vduse_vdpa_get_vq_ready(struct vdpa_device *vdpa, u16 idx) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; return vq->ready; } @@ -550,7 +550,7 @@ static int vduse_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 idx, const struct vdpa_vq_state *state) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; if (dev->driver_features & BIT_ULL(VIRTIO_F_RING_PACKED)) { vq->state.packed.last_avail_counter = @@ -569,7 +569,7 @@ static int vduse_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 idx, struct vdpa_vq_state *state) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; if (dev->driver_features & BIT_ULL(VIRTIO_F_RING_PACKED)) return vduse_dev_get_vq_state_packed(dev, vq, &state->packed); @@ -624,8 +624,8 @@ static u16 vduse_vdpa_get_vq_num_max(struct vdpa_device *vdpa) int i; for (i = 0; i < dev->vq_num; i++) - if (num_max < dev->vqs[i].num_max) - num_max = dev->vqs[i].num_max; + if (num_max < dev->vqs[i]->num_max) + num_max = dev->vqs[i]->num_max; return num_max; } @@ -863,7 +863,7 @@ static int vduse_kickfd_setup(struct vduse_dev *dev, return -EINVAL; index = array_index_nospec(eventfd->index, dev->vq_num); - vq = &dev->vqs[index]; + vq = dev->vqs[index]; if (eventfd->fd >= 0) { ctx = eventfd_ctx_fdget(eventfd->fd); if (IS_ERR(ctx)) @@ -889,7 +889,7 @@ static bool vduse_dev_is_ready(struct vduse_dev *dev) int i; for (i = 0; i < dev->vq_num; i++) - if (!dev->vqs[i].num_max) + if (!dev->vqs[i]->num_max) return false; return true; @@ -1130,7 +1130,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; index = array_index_nospec(config.index, dev->vq_num); - dev->vqs[index].num_max = config.max_size; + dev->vqs[index]->num_max = config.max_size; ret = 0; break; } @@ -1148,7 +1148,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; index = array_index_nospec(vq_info.index, dev->vq_num); - vq = &dev->vqs[index]; + vq = dev->vqs[index]; vq_info.desc_addr = vq->desc_addr; vq_info.driver_addr = vq->driver_addr; vq_info.device_addr = vq->device_addr; @@ -1198,7 +1198,7 @@ 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); + ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject); break; } case VDUSE_IOTLB_REG_UMEM: { @@ -1339,6 +1339,49 @@ static const struct file_operations vduse_dev_fops = { .llseek = noop_llseek, }; +static void vduse_dev_deinit_vqs(struct vduse_dev *dev) +{ + int i; + + if (!dev->vqs) + return; + + for (i = 0; i < dev->vq_num; i++) + kfree(dev->vqs[i]); + kfree(dev->vqs); +} + +static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) +{ + int i; + + dev->vq_align = vq_align; + dev->vq_num = vq_num; + dev->vqs = kcalloc(dev->vq_num, sizeof(*dev->vqs), GFP_KERNEL); + if (!dev->vqs) + return -ENOMEM; + + for (i = 0; i < vq_num; i++) { + dev->vqs[i] = kzalloc(sizeof(*dev->vqs[i]), GFP_KERNEL); + if (!dev->vqs[i]) + goto err; + + dev->vqs[i]->index = i; + 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); + spin_lock_init(&dev->vqs[i]->irq_lock); + } + + return 0; +err: + while (i--) + kfree(dev->vqs[i]); + kfree(dev->vqs); + dev->vqs = NULL; + return -ENOMEM; +} + static struct vduse_dev *vduse_dev_create(void) { struct vduse_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL); @@ -1396,7 +1439,7 @@ static int vduse_destroy_dev(char *name) device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); idr_remove(&vduse_idr, dev->minor); kvfree(dev->config); - kfree(dev->vqs); + vduse_dev_deinit_vqs(dev); vduse_domain_destroy(dev->domain); kfree(dev->name); vduse_dev_destroy(dev); @@ -1486,7 +1529,7 @@ ATTRIBUTE_GROUPS(vduse_dev); static int vduse_create_dev(struct vduse_dev_config *config, void *config_buf, u64 api_version) { - int i, ret; + int ret; struct vduse_dev *dev; ret = -EEXIST; @@ -1513,19 +1556,10 @@ static int vduse_create_dev(struct vduse_dev_config *config, dev->config = config_buf; dev->config_size = config->config_size; - dev->vq_align = config->vq_align; - dev->vq_num = config->vq_num; - dev->vqs = kcalloc(dev->vq_num, sizeof(*dev->vqs), GFP_KERNEL); - if (!dev->vqs) - goto err_vqs; - for (i = 0; i < dev->vq_num; i++) { - dev->vqs[i].index = i; - 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); - spin_lock_init(&dev->vqs[i].irq_lock); - } + ret = vduse_dev_init_vqs(dev, config->vq_align, config->vq_num); + if (ret) + goto err_vqs; ret = idr_alloc(&vduse_idr, dev, 1, VDUSE_DEV_MAX, GFP_KERNEL); if (ret < 0) @@ -1546,7 +1580,7 @@ static int vduse_create_dev(struct vduse_dev_config *config, err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: - kfree(dev->vqs); + vduse_dev_deinit_vqs(dev); err_vqs: vduse_domain_destroy(dev->domain); err_domain: From patchwork Thu Mar 23 05:30:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2741861wrt; Wed, 22 Mar 2023 23:04:11 -0700 (PDT) X-Google-Smtp-Source: AK7set/DoyTQNkRtsyTu4vj1j9gdhBIq4/LwHBSt3s72vng6dNnbn5eX3gcRahg9K6JoAlkycNGr X-Received: by 2002:a05:6a20:8b14:b0:d9:840f:79c2 with SMTP id l20-20020a056a208b1400b000d9840f79c2mr2431141pzh.2.1679551451005; Wed, 22 Mar 2023 23:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679551450; cv=none; d=google.com; s=arc-20160816; b=azlxP+CazLNIwU3T8GWBfg4IV/6qWnu9Daw5UtqwwUUlB27l4NsYtY84UJ4SSnnPzl /bfBsOnCGKAqgNkbNHRf47OLa2RysLnqEt4LkXIYLqMjPNpGntND7ccwl6/u7pUIVrj2 ZoSUe5OcNBvMKnOJ0rZYwqeFKH83tFFJMef0baMVmub6VmZY4BHC3pQgSr3nBxAHE/Ch K8AsnisIJuHA3LSxPVHuHF10A1sqzEzlDb10LVXK/O9FYz7Xrr8dyB995DRCcDt5xXmS lbmDtHfvZOJGo3fxRF/FXPNzGkiGS84PAiGIG6X6pqB2qRfiDXNLP0kOVJzqWGVdRANz L7Sw== 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=1c2pCL4c/YcHpCNIUgvAUe+YLzVLpglkTSZZiab5oRI=; b=F8q8tE9/iWLolKt4gvbUCFxgrdWr6HwRF6ik6vSk5+eRPlrygYHocILbRxcXt1kdiQ gOTZjbeykgFRSLMubShEh1c1s9BXlEOoMJzpy0Ks5K3CotEMcIVIP6ujvmNjfScZjyDW u4SBPfTMP/ZOGKx73mh6AYlAooAZ5rAIJJaTr2yk27galmeHY2gKH66GP55BOFKVvQlZ UEa5WbbDD96V3KzFCPDJYn295lpPzdGhXUwZLsyj7YaJwJCWV66iXsKgzUHyIiB/+KRh /Ktj3cE2F3tGzX159ynAqbscmz31g8+88H84+frB4dWRL23294PbhikjwIe33se2rFXd StyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Q3RqfJ+f; 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 a21-20020a63e855000000b0050bc7aa2dc5si18931956pgk.649.2023.03.22.23.03.58; Wed, 22 Mar 2023 23:04:10 -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=Q3RqfJ+f; 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 S231189AbjCWFd3 (ORCPT + 99 others); Thu, 23 Mar 2023 01:33:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbjCWFcv (ORCPT ); Thu, 23 Mar 2023 01:32:51 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7171C227A4 for ; Wed, 22 Mar 2023 22:31:33 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id p13-20020a17090a284d00b0023d2e945aebso2822642pjf.0 for ; Wed, 22 Mar 2023 22:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549488; 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=1c2pCL4c/YcHpCNIUgvAUe+YLzVLpglkTSZZiab5oRI=; b=Q3RqfJ+fcU+ntq9/ObJf7xvYpbcxtcltDKNe8/H69IU2YAkp154MvVHSCXJMtUYMCZ HvMdaHNzflIYHBTCnuJA86HxfxLRMk2/8Hy9skLVYtCqc4UCIAUrj0mLHalDgSEHiR8q 3SrXNONsGlA/nBVo1C15XDcWDWbcV16j8vLjspSuMg8X5g5URanMng0Fa6MnhSPBS5Id zemDBNkQAsrFscuIO+ng5Dx0El08TQcTiwgalcg788LCQcrTzoNrOZTEQxrAPivHMktY uIQcFiz/YGG7r5j9dAliyTZQt0FvrWr+6dXeyh7oa9eVgg2TadiTLTQwQbEqt3P18UAh 7tUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549488; 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=1c2pCL4c/YcHpCNIUgvAUe+YLzVLpglkTSZZiab5oRI=; b=1iHKVmVLgt3cVaxgsh/Rifk/qOOo+GT7QITsbtee2p0JJBBv4/82VI9bUrcMy/DJ3k Q72CADDh1S4yq0TKZQDGIaw5z0lXV2PBUboQ6qWSwTAUeT5lONGBSCxqyaLeIs5cjNEd lpSJZKwcXDxuiezM2Zb7PCnPwaggM2dFgqBMy2FPVgySXGDlUzrqs6K4IbrnhqDkLNdw oL1BVVOACebNEsRtFLWk8CbSN+ZKedmnAEERDacUzxvAEOa8Wm3y9bPvytwxfpXw9iEv bkefSn1vp7Au4QUzAPnJJYsaEkl724HS6WqbkHdf5A5T0+paQS2PHxglenYYIdHMlo4S x34w== X-Gm-Message-State: AO0yUKWuLgw/5X1v0QNy2ZPb5/J7sLy0LhvHqRMfRCmfDyamJ8+18xsh MY46yPgLrQr0YDH7PvjvRpiNid8l9DMoyidHuA== X-Received: by 2002:a17:902:e1d3:b0:1a1:a722:104f with SMTP id t19-20020a170902e1d300b001a1a722104fmr3741627pla.24.1679549488596; Wed, 22 Mar 2023 22:31:28 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id g11-20020a170902934b00b00199203a4fa3sm11395057plp.203.2023.03.22.22.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:28 -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 05/11] vduse: Support set_vq_affinity callback Date: Thu, 23 Mar 2023 13:30:37 +0800 Message-Id: <20230323053043.35-6-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?1761137342314056734?= X-GMAIL-MSGID: =?utf-8?q?1761137342314056734?= Since virtio-vdpa bus driver already support interrupt affinity spreading mechanism, let's implement the set_vq_affinity callback to bring it to vduse device. After we get the virtqueue's affinity, we can spread IRQs between CPUs in the affinity mask, in a round-robin manner, to run the irq callback. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 61 ++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 98359d87a06f..45aa8703c4b5 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -41,6 +41,8 @@ #define VDUSE_IOVA_SIZE (128 * 1024 * 1024) #define VDUSE_MSG_DEFAULT_TIMEOUT 30 +#define IRQ_UNBOUND -1 + struct vduse_virtqueue { u16 index; u16 num_max; @@ -57,6 +59,8 @@ struct vduse_virtqueue { struct vdpa_callback cb; struct work_struct inject; struct work_struct kick; + int irq_effective_cpu; + struct cpumask irq_affinity; }; struct vduse_dev; @@ -128,6 +132,7 @@ static struct class *vduse_class; static struct cdev vduse_ctrl_cdev; static struct cdev vduse_cdev; static struct workqueue_struct *vduse_irq_wq; +static struct workqueue_struct *vduse_irq_bound_wq; static u32 allowed_device_id[] = { VIRTIO_ID_BLOCK, @@ -708,6 +713,15 @@ static u32 vduse_vdpa_get_generation(struct vdpa_device *vdpa) return dev->generation; } +static int vduse_vdpa_set_vq_affinity(struct vdpa_device *vdpa, u16 idx, + const struct cpumask *cpu_mask) +{ + struct vduse_dev *dev = vdpa_to_vduse(vdpa); + + cpumask_copy(&dev->vqs[idx]->irq_affinity, cpu_mask); + return 0; +} + static int vduse_vdpa_set_map(struct vdpa_device *vdpa, unsigned int asid, struct vhost_iotlb *iotlb) @@ -758,6 +772,7 @@ static const struct vdpa_config_ops vduse_vdpa_config_ops = { .get_config = vduse_vdpa_get_config, .set_config = vduse_vdpa_set_config, .get_generation = vduse_vdpa_get_generation, + .set_vq_affinity = vduse_vdpa_set_vq_affinity, .reset = vduse_vdpa_reset, .set_map = vduse_vdpa_set_map, .free = vduse_vdpa_free, @@ -917,7 +932,8 @@ static void vduse_vq_irq_inject(struct work_struct *work) } static int vduse_dev_queue_irq_work(struct vduse_dev *dev, - struct work_struct *irq_work) + struct work_struct *irq_work, + int irq_effective_cpu) { int ret = -EINVAL; @@ -926,7 +942,11 @@ static int vduse_dev_queue_irq_work(struct vduse_dev *dev, goto unlock; ret = 0; - queue_work(vduse_irq_wq, irq_work); + if (irq_effective_cpu == IRQ_UNBOUND) + queue_work(vduse_irq_wq, irq_work); + else + queue_work_on(irq_effective_cpu, + vduse_irq_bound_wq, irq_work); unlock: up_read(&dev->rwsem); @@ -1029,6 +1049,22 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, return ret; } +static void vduse_vq_update_effective_cpu(struct vduse_virtqueue *vq) +{ + int curr_cpu = vq->irq_effective_cpu; + + while (true) { + curr_cpu = cpumask_next(curr_cpu, &vq->irq_affinity); + if (cpu_online(curr_cpu)) + break; + + if (curr_cpu >= nr_cpu_ids) + curr_cpu = IRQ_UNBOUND; + } + + vq->irq_effective_cpu = curr_cpu; +} + static long vduse_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -1111,7 +1147,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; } case VDUSE_DEV_INJECT_CONFIG_IRQ: - ret = vduse_dev_queue_irq_work(dev, &dev->inject); + ret = vduse_dev_queue_irq_work(dev, &dev->inject, IRQ_UNBOUND); break; case VDUSE_VQ_SETUP: { struct vduse_vq_config config; @@ -1198,7 +1234,10 @@ 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); + + 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: { @@ -1367,10 +1406,12 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) goto err; dev->vqs[i]->index = i; + dev->vqs[i]->irq_effective_cpu = IRQ_UNBOUND; 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); spin_lock_init(&dev->vqs[i]->irq_lock); + cpumask_setall(&dev->vqs[i]->irq_affinity); } return 0; @@ -1858,12 +1899,15 @@ static int vduse_init(void) if (ret) goto err_cdev; + ret = -ENOMEM; vduse_irq_wq = alloc_workqueue("vduse-irq", WQ_HIGHPRI | WQ_SYSFS | WQ_UNBOUND, 0); - if (!vduse_irq_wq) { - ret = -ENOMEM; + if (!vduse_irq_wq) goto err_wq; - } + + vduse_irq_bound_wq = alloc_workqueue("vduse-irq-bound", WQ_HIGHPRI, 0); + if (!vduse_irq_bound_wq) + goto err_bound_wq; ret = vduse_domain_init(); if (ret) @@ -1877,6 +1921,8 @@ static int vduse_init(void) err_mgmtdev: vduse_domain_exit(); err_domain: + destroy_workqueue(vduse_irq_bound_wq); +err_bound_wq: destroy_workqueue(vduse_irq_wq); err_wq: cdev_del(&vduse_cdev); @@ -1896,6 +1942,7 @@ static void vduse_exit(void) { vduse_mgmtdev_exit(); vduse_domain_exit(); + destroy_workqueue(vduse_irq_bound_wq); destroy_workqueue(vduse_irq_wq); cdev_del(&vduse_cdev); device_destroy(vduse_class, vduse_major); From patchwork Thu Mar 23 05:30:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2738029wrt; Wed, 22 Mar 2023 22:51:34 -0700 (PDT) X-Google-Smtp-Source: AK7set+RAw2StZqN6cmjCFS5dOfedVkphCaUEudjGb4CTa4lukcVaF36Z9nVCLnaiQGwEjqT6sN5 X-Received: by 2002:a17:903:2347:b0:1a1:adb0:ed72 with SMTP id c7-20020a170903234700b001a1adb0ed72mr5961821plh.4.1679550694365; Wed, 22 Mar 2023 22:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679550694; cv=none; d=google.com; s=arc-20160816; b=OUZZQfoK+XydZRhDlJMnbbw3H+V+rPwloY4/CZfNB9EE4aLizhzQIAQ0BnqBbjV3Gf 1XAFq9zc7zl8k61k48sqJH5A78bq3TlPCYs3uJ+1OjPLEiagE4G34rBafKOQFQcYrfK2 Qh4Kw9VWSt6rpcsjcE3aZhBdw8+z+cEjYP4NME34UXUVBjbfwtgbuJToi5s2n8I2fIjE p+9r886h3F6ny4xc0pL5T9Gs0WLuEIImP94us9ae3DRyf/xMb5fC3NLJ6ref13hvYEuf 6qGDLpV+w6W3/kjuxERZj4rUzqs0cNZlgBFPpn74JeiMQFZw60bAzNe5OBWKWCRmzuvB cplA== 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=0GCcooak9WK1xh4TRDY1XJvbDD37iAfzUGzKvOhf7XM=; b=qaIRVA4VI7My5RQuzCcWLGduLlqG5UfnhBEpIstWHkYzqtlx158Wjp2LgyQlc3Tf0s r6zbpNoL02aDh8qJ3//b6PPvSr7MYk8H64MzlvudzLmJNzKxFlXdAGayoRgvUoRFvAIa zl4SMy6080tXiaB2YGlhNWQ2CFx1v0OkZWcqPIaI3vVE8p9gdz2F6eKxk+h2vqfMV+nB jTgh+yXzzNFfhNpzmXonGZM5g/dHKMhZTfCSpBxxUKCv6azCB6l0OxfHLSuwMyJR9lyG /0yM+IJxB5IxratmnpInwDZMe+yVZICCXoXVyGU7LafDPAas85xkit1kNgLXAUqaxtOC 8Xmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=P8Dro5H8; 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 i5-20020a17090332c500b001a19248bfcdsi19370257plr.436.2023.03.22.22.51.22; Wed, 22 Mar 2023 22:51:34 -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=P8Dro5H8; 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 S229951AbjCWFc7 (ORCPT + 99 others); Thu, 23 Mar 2023 01:32:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbjCWFc1 (ORCPT ); Thu, 23 Mar 2023 01:32:27 -0400 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 DB19431E3D for ; Wed, 22 Mar 2023 22:31:33 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id qe8-20020a17090b4f8800b0023f07253a2cso903257pjb.3 for ; Wed, 22 Mar 2023 22:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549491; 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=0GCcooak9WK1xh4TRDY1XJvbDD37iAfzUGzKvOhf7XM=; b=P8Dro5H8Ds+eHTQPRptLcDET6KgNFGOLOsOaZgHItGzVIwsDQbEDQHhqVh23D00GXH HnzW7+BQkt71sZwJ/XlUBHjudQ94Mwd5jv9FwG4Dmcs1fS1hbZXb+1v6DqiU5o/A/yBt 9/uPwzL79/8g3AADp/fbvuLKnxCGZ7kJbDa4LJAJuTQDjI4beHCDDRg58firhEcJVtyJ bBsPYaUy2sHGBA6PRnDm86gUQ1ftjUweQi+YfoNvKZz2TEMMmfZ+OlFsJbGcwL2IfbKf 8+4Rwmt0Tk6LOuVkwAiUQvyulo+njqjFRmiZaIHYLrUmmDoBhDvaJ95JoMKqf5dvc28r 1GGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549491; 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=0GCcooak9WK1xh4TRDY1XJvbDD37iAfzUGzKvOhf7XM=; b=2gyxE7/3GL6TMop3MRKyo/fGmsjU4r+dOeGiXx9tl9odyyTLL6HqwAQTh0M2Uf4Rft YpHMo7Ftt4irezvn51gLDfODmFN/oUCo7Lj5B8qzAe5qzkzumwkOTyMZiYzayFDe2L4b Ig+ZnhpjVUTUZw6z8OiCyFcDvF+NS/bD2exHLRsqZix5HrQUrnPC73hrpWXIyU5eprJf gcrOqY3VHiYC6TFWAUtsj0NsWM6ub7O6NmtGolqW8PQtiF8Qw+SLMU8E6fl4B/FiPpzD JMEpZQke8T4Y6NLUE1NURgmHN3RqDmEbbaQP9QUdKOscg4Dkzork9ZpdkLEjDNPO6cvd SOKw== X-Gm-Message-State: AO0yUKWVY1cvFQTNT3bnIz6dQQHNxn/3WpheG79ouyIlbkqWyeIMZUAK cFwHhuYowOTIg6LRg+hQWl3R X-Received: by 2002:a05:6a20:6048:b0:d7:4339:fad9 with SMTP id s8-20020a056a20604800b000d74339fad9mr1864404pza.7.1679549491654; Wed, 22 Mar 2023 22:31:31 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id x5-20020aa784c5000000b006262520ac59sm10741817pfn.127.2023.03.22.22.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:31 -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 06/11] vduse: Support get_vq_affinity callback Date: Thu, 23 Mar 2023 13:30:38 +0800 Message-Id: <20230323053043.35-7-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?1761136548786339345?= X-GMAIL-MSGID: =?utf-8?q?1761136548786339345?= This implements get_vq_affinity callback so that the virtio-blk driver can build the blk-mq queues based on the irq callback affinity. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 45aa8703c4b5..cefabd0dab9c 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -722,6 +722,14 @@ static int vduse_vdpa_set_vq_affinity(struct vdpa_device *vdpa, u16 idx, return 0; } +static const struct cpumask * +vduse_vdpa_get_vq_affinity(struct vdpa_device *vdpa, u16 idx) +{ + struct vduse_dev *dev = vdpa_to_vduse(vdpa); + + return &dev->vqs[idx]->irq_affinity; +} + static int vduse_vdpa_set_map(struct vdpa_device *vdpa, unsigned int asid, struct vhost_iotlb *iotlb) @@ -773,6 +781,7 @@ static const struct vdpa_config_ops vduse_vdpa_config_ops = { .set_config = vduse_vdpa_set_config, .get_generation = vduse_vdpa_get_generation, .set_vq_affinity = vduse_vdpa_set_vq_affinity, + .get_vq_affinity = vduse_vdpa_get_vq_affinity, .reset = vduse_vdpa_reset, .set_map = vduse_vdpa_set_map, .free = vduse_vdpa_free, From patchwork Thu Mar 23 05:30:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2741362wrt; Wed, 22 Mar 2023 23:02:52 -0700 (PDT) X-Google-Smtp-Source: AK7set8ZaddXn2f4eQIuGt9xVHBSTWkE2CAYYrT7+NhQpU9mDUAJwma+uOIcUflCidofv4lJRIhP X-Received: by 2002:a17:903:41c6:b0:1a0:4046:23f7 with SMTP id u6-20020a17090341c600b001a0404623f7mr6379361ple.44.1679551372670; Wed, 22 Mar 2023 23:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679551372; cv=none; d=google.com; s=arc-20160816; b=GD9KFta2s07jFnpdKrVIcca31XtADaO9ZTv8DPUQMkXCov9NEsqVU2IysZcphntuPY gjCbIOZDITzpOcur2gx0aq5xlgiSbonmEm1CP09sjRgY9XEIHyd8JhzKIaYBQB9+Ynk4 94z9zONXRs0Loc0EMReyPWUjkJOoeKWke0DCFtce7JvpiZ0jhQnTWFCJ72fm+xs8WlLU L5Ue6CTeVzsL5Q0ZMvP0ivi74ZIGsUTy/QE/SlgE8HgB4LTtg2t5/Tuq+jFmIsDfmcVo 4PA9OzT2qUJgQ2nfIzCc61PTXrDJQhjZTxJMDxOdOEjsKQh7aCIkGTiV8VL6Wo8g5i3a M+Yw== 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=TL2Dnn/bucJdLF0dm9z8HJ4wRhbVCYyNvRp5emR3AUo=; b=uw4x3qnqThFpJ1V9ZCVKSW66zzoizlN9egyW8VwwejRXfdIOpgQVxP9ZoX2nDqT6vO OJJu4SqwDwXpI4obo7R4cs0P5xaYBOxz3KCjCm/HMEcxFVQFEYa4BXQlTf9igSad4OhP bD/hfpJLJgKrfeMGbdQsBqj0brqfMg+R0hCULTY/wIVtOx4yQ/yOcVUgtmiPnyA2fiNq MZp59nvybcQIk58XzLQhVrB7LgZYp36fvnC09X/VMBu3DykKYubHQg40VltTR/+e1bsS pLCNGarZPjPE2xirlxTsjmyMlr9gqbuKm4XTJAvDM7mlrwVGN1jh7UXhSY+06WTDOVJe VdgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=i3Quh5Fd; 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 j3-20020a170903028300b001a1f5044b02si3032886plr.51.2023.03.22.23.02.39; Wed, 22 Mar 2023 23:02:52 -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=i3Quh5Fd; 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 S230340AbjCWFdY (ORCPT + 99 others); Thu, 23 Mar 2023 01:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231166AbjCWFcv (ORCPT ); Thu, 23 Mar 2023 01:32:51 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D2953250B for ; Wed, 22 Mar 2023 22:31:36 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id c18so21301547ple.11 for ; Wed, 22 Mar 2023 22:31:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549495; 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=TL2Dnn/bucJdLF0dm9z8HJ4wRhbVCYyNvRp5emR3AUo=; b=i3Quh5FdSnsK5S8yceJvpITNjicWODJB65IpP5laC2v+d9NcrwzKw/WQfHDMT9Ji97 MkPTfdS913ShF1NuItbU+hJpE1X76gey4LsAKWecnaE22peXx4HaX1Xj/YgnNbVHnj2/ EkQIxPHo0ZjbaGbDk4BbG7vaSC2JjODW4O/D+0x0z24SdNxLv86wynLP5OL4DtTK2VuQ Y3mqYJJosdXQ9tnufUDnf8iWplzP8CZbrVKcUSs/1ONccQGc8fFzq69b2m+BW2ak5YUT rJHmzu7y3iSDu+Q9YF37M6NM2TENqWpNutdn5Nfmn56vVVC3TFcsk3afeTv51914FNdL TUvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549495; 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=TL2Dnn/bucJdLF0dm9z8HJ4wRhbVCYyNvRp5emR3AUo=; b=0GZhU1rWrVgSGxALuDvVOMxUVt7rfGYkZh6IluXQcVX45WZB9tixbp8NgzI6smuImh mDOP0QkotTpX/qj1v+ta1rPhgGjkKxYH3SyBfDCf5NjYdKTuJsesoFmnOS7aFOglhCrf OyDFzM/57Taw6VvNHE8dS7MaJobFBDPsv6dn2YNJ5NBkX0CgeHrrLWOl3hUt/HjOZ0mG UvBx8J5ej7IXDBKmeZ6ToeEqFJUISZhJs2WHAKddODP+qgdlR+Qo6ZKvLVNIqfH5o1Ya JCoTQvmgwU8cwLwGDCKjARECKhbx8uCpBarPDOlPMPjBTaO9aclAdSA6AtZgl9iQZ158 DwRA== X-Gm-Message-State: AO0yUKXQpZw4CznEVuAJ/kyWzKuqtMI8TBLL7CVdWBpG6Hr8M5jNcQhh hFEyrmCxOBm6hILLuFXRBVd2paEpZ0JDX//T8g== X-Received: by 2002:a17:90b:33c2:b0:23f:7ff6:eba with SMTP id lk2-20020a17090b33c200b0023f7ff60ebamr7028841pjb.0.1679549494930; Wed, 22 Mar 2023 22:31:34 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id 21-20020a170902ee5500b0019aafc422fcsm11407530plo.240.2023.03.22.22.31.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:34 -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 07/11] vduse: Add sysfs interface for irq callback affinity Date: Thu, 23 Mar 2023 13:30:39 +0800 Message-Id: <20230323053043.35-8-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?1761137259846662260?= X-GMAIL-MSGID: =?utf-8?q?1761137259846662260?= Add sysfs interface for each vduse virtqueue to get/set the affinity for irq callback. This might be useful for performance tuning when the irq callback affinity mask contains more than one CPU. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 124 ++++++++++++++++++++++++++--- 1 file changed, 113 insertions(+), 11 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index cefabd0dab9c..77da3685568a 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -61,6 +61,7 @@ struct vduse_virtqueue { struct work_struct kick; int irq_effective_cpu; struct cpumask irq_affinity; + struct kobject kobj; }; struct vduse_dev; @@ -1387,6 +1388,96 @@ static const struct file_operations vduse_dev_fops = { .llseek = noop_llseek, }; +static ssize_t irq_cb_affinity_show(struct vduse_virtqueue *vq, char *buf) +{ + return sprintf(buf, "%*pb\n", cpumask_pr_args(&vq->irq_affinity)); +} + +static ssize_t irq_cb_affinity_store(struct vduse_virtqueue *vq, + const char *buf, size_t count) +{ + cpumask_var_t new_value; + int ret; + + if (!zalloc_cpumask_var(&new_value, GFP_KERNEL)) + return -ENOMEM; + + ret = cpumask_parse(buf, new_value); + if (ret) + goto free_mask; + + ret = -EINVAL; + if (!cpumask_intersects(new_value, cpu_online_mask)) + goto free_mask; + + cpumask_copy(&vq->irq_affinity, new_value); + ret = count; +free_mask: + free_cpumask_var(new_value); + return ret; +} + +struct vq_sysfs_entry { + struct attribute attr; + ssize_t (*show)(struct vduse_virtqueue *vq, char *buf); + ssize_t (*store)(struct vduse_virtqueue *vq, const char *buf, + size_t count); +}; + +static struct vq_sysfs_entry irq_cb_affinity_attr = __ATTR_RW(irq_cb_affinity); + +static struct attribute *vq_attrs[] = { + &irq_cb_affinity_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(vq); + +static ssize_t vq_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct vduse_virtqueue *vq = container_of(kobj, + struct vduse_virtqueue, kobj); + struct vq_sysfs_entry *entry = container_of(attr, + struct vq_sysfs_entry, attr); + + if (!entry->show) + return -EIO; + + return entry->show(vq, buf); +} + +static ssize_t vq_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) +{ + struct vduse_virtqueue *vq = container_of(kobj, + struct vduse_virtqueue, kobj); + struct vq_sysfs_entry *entry = container_of(attr, + struct vq_sysfs_entry, attr); + + if (!entry->store) + return -EIO; + + return entry->store(vq, buf, count); +} + +static const struct sysfs_ops vq_sysfs_ops = { + .show = vq_attr_show, + .store = vq_attr_store, +}; + +static void vq_release(struct kobject *kobj) +{ + struct vduse_virtqueue *vq = container_of(kobj, + struct vduse_virtqueue, kobj); + kfree(vq); +} + +static const struct kobj_type vq_type = { + .release = vq_release, + .sysfs_ops = &vq_sysfs_ops, + .default_groups = vq_groups, +}; + static void vduse_dev_deinit_vqs(struct vduse_dev *dev) { int i; @@ -1395,13 +1486,13 @@ static void vduse_dev_deinit_vqs(struct vduse_dev *dev) return; for (i = 0; i < dev->vq_num; i++) - kfree(dev->vqs[i]); + kobject_put(&dev->vqs[i]->kobj); kfree(dev->vqs); } static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) { - int i; + int ret, i; dev->vq_align = vq_align; dev->vq_num = vq_num; @@ -1411,8 +1502,10 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) for (i = 0; i < vq_num; i++) { dev->vqs[i] = kzalloc(sizeof(*dev->vqs[i]), GFP_KERNEL); - if (!dev->vqs[i]) + if (!dev->vqs[i]) { + ret = -ENOMEM; goto err; + } dev->vqs[i]->index = i; dev->vqs[i]->irq_effective_cpu = IRQ_UNBOUND; @@ -1421,15 +1514,23 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) spin_lock_init(&dev->vqs[i]->kick_lock); spin_lock_init(&dev->vqs[i]->irq_lock); cpumask_setall(&dev->vqs[i]->irq_affinity); + + kobject_init(&dev->vqs[i]->kobj, &vq_type); + ret = kobject_add(&dev->vqs[i]->kobj, + &dev->dev->kobj, "vq%d", i); + if (ret) { + kfree(dev->vqs[i]); + goto err; + } } return 0; err: while (i--) - kfree(dev->vqs[i]); + kobject_put(&dev->vqs[i]->kobj); kfree(dev->vqs); dev->vqs = NULL; - return -ENOMEM; + return ret; } static struct vduse_dev *vduse_dev_create(void) @@ -1607,10 +1708,6 @@ static int vduse_create_dev(struct vduse_dev_config *config, dev->config = config_buf; dev->config_size = config->config_size; - ret = vduse_dev_init_vqs(dev, config->vq_align, config->vq_num); - if (ret) - goto err_vqs; - ret = idr_alloc(&vduse_idr, dev, 1, VDUSE_DEV_MAX, GFP_KERNEL); if (ret < 0) goto err_idr; @@ -1624,14 +1721,19 @@ static int vduse_create_dev(struct vduse_dev_config *config, ret = PTR_ERR(dev->dev); goto err_dev; } + + ret = vduse_dev_init_vqs(dev, config->vq_align, config->vq_num); + if (ret) + goto err_vqs; + __module_get(THIS_MODULE); return 0; +err_vqs: + device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: - vduse_dev_deinit_vqs(dev); -err_vqs: vduse_domain_destroy(dev->domain); err_domain: kfree(dev->name); From patchwork Thu Mar 23 05:30:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2736402wrt; Wed, 22 Mar 2023 22:45:22 -0700 (PDT) X-Google-Smtp-Source: AK7set87xQsCdEPmFuHZIK3VusEvALA110sUk5pXUNog3hI9LZkhEcnllU6Nn75DroGZL7SSEykU X-Received: by 2002:aa7:9423:0:b0:627:fae5:b3d0 with SMTP id y3-20020aa79423000000b00627fae5b3d0mr5534865pfo.24.1679550321891; Wed, 22 Mar 2023 22:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679550321; cv=none; d=google.com; s=arc-20160816; b=xV/rso0+MeXPwcEnJ+xYDQtvztYbJmOOX2PBxnJ+sRKfySVwrilI64zBM6DKgkSezz yWfd9sl/aBf/Hqhxwl2akTwa0CLCqwwQdmFv9vdtvfDxraNZGutFKacOKCOz5mhZzkxB IsMkYH5oXrSjo3ySMCnXdHdM2JGLIwWmhNRcIyJfXvxMgOD5Mk/e0SGOcVTyFa7oLXto 6JsGlmxiuF3lqxCxKxKgfQ4xuh6DQyFNrjCT5YofC9eIsXBNGNczSs1k5DAOvlyvHUDd fV0/ipBX9zInG5PeMAIZAiquiGDnyL3RlSC4570mc6fou86g8ST431IFE5fIgO10856/ 4ctg== 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=MgyyzGdPYlLmRb+LUWqhPpBI8LjddO/ZyliZeTEMlT4=; b=uga5sDZw4tFUpXgKA0X7iBqadRoTFgqSNJofk9DWU/osudpg9RJbcdyEMTPyF9nhrb xaOP7jdvRyfzmLL9JbWYlJFY9Vt73iAAE49GHFC1qftMJjr5NgOoHEq8xphvhDtCkOhG /tMRND9MrKChFbYxhRlkjB8dPyTytv8GMg40UvpFCst8SvPmZfiUJilSg4KU8U89LFh3 FGrEzspA2ndVUinzGEnMPqXmLMblW7MnISxp9jNQO+0+H9vnIFcWwmRtVk66SMZpReVc zmuBke4mP5a0tMO/6klahbFY51OlwWr5cw0sckdjj/OfLMS5ziL5lHwCSMm9bZvXuyI0 dpqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=R51Z7g8e; 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 a23-20020a630b57000000b0050fad17282dsi4857044pgl.217.2023.03.22.22.45.08; Wed, 22 Mar 2023 22:45:21 -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=R51Z7g8e; 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 S231237AbjCWFdd (ORCPT + 99 others); Thu, 23 Mar 2023 01:33:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbjCWFcz (ORCPT ); Thu, 23 Mar 2023 01:32:55 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CBD43252C for ; Wed, 22 Mar 2023 22:31:39 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id a16so16172495pjs.4 for ; Wed, 22 Mar 2023 22:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549498; 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=MgyyzGdPYlLmRb+LUWqhPpBI8LjddO/ZyliZeTEMlT4=; b=R51Z7g8eJ5Fc1tp1TH+HFYbvpmoLVJ5oZcRDp7my9huauSYN/wOxi6RF7q1p1s/LGq oIQMTHofE0VcWFzMzZy5jAEg1fmofuXjG79p+0c4WbJyo3A9hlrurDSvx+TlsgOgU7RL nC/Uvxq7f9IoFYsm5pnJw1mSjtc7yZtQYftbbcDcAV3UZ+0Z0A+8vl3Eztx9yaywJUO/ QlCwGZezutqsBHkrLch0kUUl1x24GgMRfO+EFelgH8pJAQazBzdK/dkTZMf03juzVRVJ FamN5U2qDZQJf/IoRKFAwQ9wPpXDdid9G0pOwqrvkkKuBNpTv8bNJD+QTNCljiE+PovE mHcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549498; 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=MgyyzGdPYlLmRb+LUWqhPpBI8LjddO/ZyliZeTEMlT4=; b=I4iynMXjauq8uo47i2QtSAKfS/OuzHP2l46PjGrTxLYG2nZCTlKk7GfuHnbUmHhC58 Lzy3ho+O9UkUnEFSM1+oTkJk8Fi7/jsgkVEzoai6Iq3eYrt9+BzZrjPZruV0mmNXTIl8 pD+GOYib3YrYUUHiSFAJt2lW6oRLI/zhWi2hmfNaK0RtE6H4R/xHIujthHrfTqv78cqt 707PTurnQXezFiFxf314S+VzQ09EjWXkyuf2BoQGJN3xL1ECkaeRKVZBhKjSYLYjVkLr ZUxArAK0nZYoh9TNdBTCdqxZOwup1D2bkvf9d87AKK/BXa6PxzqBBJgBOj2hZUKpEHFd hPtQ== X-Gm-Message-State: AAQBX9ekgRZE5CXTvzAb8ECMjIvFoWvDsLbyJ2ZPMm0UYsV7KDIcwgTO AYGANbDo7sIZQnBNmu4soyBX X-Received: by 2002:a17:90a:1608:b0:240:1e0b:a7b7 with SMTP id n8-20020a17090a160800b002401e0ba7b7mr1863560pja.39.1679549498150; Wed, 22 Mar 2023 22:31:38 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id d9-20020a17090a6a4900b0023c8a23005asm432283pjm.49.2023.03.22.22.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:37 -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 08/11] vdpa: Add eventfd for the vdpa callback Date: Thu, 23 Mar 2023 13:30:40 +0800 Message-Id: <20230323053043.35-9-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?1761136158433480041?= X-GMAIL-MSGID: =?utf-8?q?1761136158433480041?= Add eventfd for the vdpa callback so that user can signal it directly instead of triggering the callback. It will be used for vhost-vdpa case. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vhost/vdpa.c | 2 ++ drivers/virtio/virtio_vdpa.c | 1 + include/linux/vdpa.h | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 7be9d9d8f01c..9cd878e25cff 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -599,9 +599,11 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, if (vq->call_ctx.ctx) { cb.callback = vhost_vdpa_virtqueue_cb; cb.private = vq; + cb.trigger = vq->call_ctx.ctx; } else { cb.callback = NULL; cb.private = NULL; + cb.trigger = NULL; } ops->set_vq_cb(vdpa, idx, &cb); vhost_vdpa_setup_vq_irq(v, idx); diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index f3826f42b704..2a095f37f26b 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -196,6 +196,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, /* Setup virtqueue callback */ cb.callback = callback ? virtio_vdpa_virtqueue_cb : NULL; cb.private = info; + cb.trigger = NULL; ops->set_vq_cb(vdpa, index, &cb); ops->set_vq_num(vdpa, index, virtqueue_get_vring_size(vq)); diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index e52c9a37999c..0372b2e3d38a 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -13,10 +13,16 @@ * struct vdpa_calllback - vDPA callback definition. * @callback: interrupt callback function * @private: the data passed to the callback function + * @trigger: the eventfd for the callback (Optional). + * When it is set, the vDPA driver must guarantee that + * signaling it is functional equivalent to triggering + * the callback. Then vDPA parent can signal it directly + * instead of triggering the callback. */ struct vdpa_callback { irqreturn_t (*callback)(void *data); void *private; + struct eventfd_ctx *trigger; }; /** 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: { From patchwork Thu Mar 23 05:30:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73830 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2739737wrt; Wed, 22 Mar 2023 22:58:19 -0700 (PDT) X-Google-Smtp-Source: AK7set89+LY1F8yzdYT3giOdeC6sWjQQ2N5XHZxLZJ3bpMY5YyE8vxKIkeI33DZIPjXeH4vl93k+ X-Received: by 2002:a05:6a00:5a:b0:627:fc3b:4ca9 with SMTP id i26-20020a056a00005a00b00627fc3b4ca9mr4333180pfk.0.1679551099498; Wed, 22 Mar 2023 22:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679551099; cv=none; d=google.com; s=arc-20160816; b=e8a5twDmqYjdOCw+Uz6PM2hhFoH5WEOutKTHY4BNUGCixRPfMNNK9iXi58ul9Xeo0k j/B30wMwhoRnvRTZl3y1P7Msrrq8aXPfMGZpfipg7fStT70nz6MEoF8ntwN5adIgptqb kRjoqG84+Z/MWTaOJv059XPi9Dij8Bh8IKCynWXwHJK1bQD8TvBfwVnX+OD+mD3DhDKK Gl7zDwvLyxRYAFGnEc5PkjqlrPh341tI2qR/BZM2scX1TcjhCsroURLJo45qdhnGnblq cIcjjc2BT0BRp+DBEgdhqWQ8ah26jWTBbhLL1jxQptd1Cb/hnCVf6fYA6q1nMAVQYDU2 sujw== 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=zPmWWrpSgaPOGhUBOkIMLmxdo25WMNikMv3Jin+/Fz0=; b=m8xVIu0XH43Q1eo6NJPjro8c5d95VkV0Jsb0e6h5X7sozJL974B7CUnduYTO5g/uTm tlVxUBikhDTzjQNdSRlb/wXATYiSEVkG27lSJD4G2N/NpoUFOzK7k0siA7//oBz4a0z+ mw0k2dlckpaQCInOs9tN5mIz9m4uffJeKy2zVxqlrh9K8rDqgk/JDGvnTiPgs3cFqQko 0QviKnzB7fDqw8188Bre4sU7DN2WWLN5hkXWCzD59IIzOfp+gn6gNhvCj4dQTg2+ZN9s DERgQ0XwWeZPnpnFrzLB0L7+cs7r7RWUS4OBUZmTnjUDsT16QcwuQmSIjMJlLbGYFKlC nt/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=btCCImtE; 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 x185-20020a6386c2000000b005089e773be5si18839869pgd.661.2023.03.22.22.58.06; Wed, 22 Mar 2023 22:58:19 -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=btCCImtE; 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 S230026AbjCWFdn (ORCPT + 99 others); Thu, 23 Mar 2023 01:33:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbjCWFdC (ORCPT ); Thu, 23 Mar 2023 01:33:02 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B43B2F05E for ; Wed, 22 Mar 2023 22:31:46 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id lr16-20020a17090b4b9000b0023f187954acso906796pjb.2 for ; Wed, 22 Mar 2023 22:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549504; 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=zPmWWrpSgaPOGhUBOkIMLmxdo25WMNikMv3Jin+/Fz0=; b=btCCImtEbx8h8b5MD0xvsC/Msz/cOhLuDrbLg0UodbNPkO2mHUq11NP+bQKtb0oenJ ijTDX4qMzrOxRN8Q6m6QdHKsRDBa76hJsly6iCT01NSBqpkAQDe92CfLIZiuWEoBVMth aPzzyKYC1lrr0yhkDkhOBJCgUVryj7L3C+/W3RgS/IjjsoznZU7iTadcsrnVzciP+mpU wibTJbNT2kcHf4OTU7b2/kApuwKfm2BqzuBvmpHRrKqg+RIDVrZSc9iubeSdvWMR1rRR E50p9m2g+chyR2K+FXF/HExk9tuZNlFHaAzgDs8Hns1KSqmj9gv9dK6mg1K4OW6F83RR yhEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549504; 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=zPmWWrpSgaPOGhUBOkIMLmxdo25WMNikMv3Jin+/Fz0=; b=FdYPAAIVtjFSJzGMrKTSSyjwg7LJo6zfoduR9ocoGaZbNeP2tw6UcpwbO/YV+89ZTa hcdvCeVqGkK30O5PdkeZw++9r2j5RxKO4gw0VCUAFo1+iw92ewmqKHH0VkTJR53U6IKN iH3SovaxaMAFFMZW3WkW38i4g61Q2pu7GfjevHoVEY4BB3gOmSClE9mo3mO73m5kM8Ga fLCak4KVSHQdFp5ouWbjAor+c76yyg7XbD2OU5bD7w3y5kHXHos4ZjExX0cZ54ktpWAb A2j4X5y5AjkixjQ/JzkyrlH5OtgVWkLVaVfJLyF8fKIwmbRxsWfKm3NNGFlaATXgv/R2 AzPA== X-Gm-Message-State: AAQBX9eyxy66AJQgx5SRgqyxzP1UQTZK8HJENFchHv/ESH4clS1VL1KC tx9tSuKQgN7p58f6sUdE1bVB X-Received: by 2002:a17:903:32d1:b0:1a1:abc9:198f with SMTP id i17-20020a17090332d100b001a1abc9198fmr4732456plr.4.1679549504645; Wed, 22 Mar 2023 22:31:44 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id p9-20020a63f449000000b0050bf1d1cdc8sm10687768pgk.21.2023.03.22.22.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:44 -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 10/11] vduse: Delay iova domain creation Date: Thu, 23 Mar 2023 13:30:42 +0800 Message-Id: <20230323053043.35-11-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?1761136973774461426?= X-GMAIL-MSGID: =?utf-8?q?1761136973774461426?= Delay creating iova domain until the vduse device is registered to vdpa bus. This is a preparation for adding sysfs interface to support specifying bounce buffer size for the iova domain. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 75 +++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 8c06f6ab960b..ccca84d51a28 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -111,6 +111,8 @@ struct vduse_dev { u32 vq_align; struct vduse_umem *umem; struct mutex mem_lock; + unsigned int bounce_size; + struct mutex domain_lock; }; struct vduse_dev_msg { @@ -425,7 +427,7 @@ static void vduse_dev_reset(struct vduse_dev *dev) struct vduse_iova_domain *domain = dev->domain; /* The coherent mappings are handled in vduse_dev_free_coherent() */ - if (domain->bounce_map) + if (domain && domain->bounce_map) vduse_domain_reset_bounce_map(domain); down_write(&dev->rwsem); @@ -993,6 +995,9 @@ static int vduse_dev_dereg_umem(struct vduse_dev *dev, goto unlock; ret = -EINVAL; + if (!dev->domain) + goto unlock; + if (dev->umem->iova != iova || size != dev->domain->bounce_size) goto unlock; @@ -1019,7 +1024,7 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, unsigned long npages, lock_limit; int ret; - if (!dev->domain->bounce_map || + if (!dev->domain || !dev->domain->bounce_map || size != dev->domain->bounce_size || iova != 0 || uaddr & ~PAGE_MASK) return -EINVAL; @@ -1109,7 +1114,6 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, struct vduse_iotlb_entry entry; struct vhost_iotlb_map *map; struct vdpa_map_file *map_file; - struct vduse_iova_domain *domain = dev->domain; struct file *f = NULL; ret = -EFAULT; @@ -1120,8 +1124,13 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, if (entry.start > entry.last) break; - spin_lock(&domain->iotlb_lock); - map = vhost_iotlb_itree_first(domain->iotlb, + mutex_lock(&dev->domain_lock); + if (!dev->domain) { + mutex_unlock(&dev->domain_lock); + break; + } + spin_lock(&dev->domain->iotlb_lock); + map = vhost_iotlb_itree_first(dev->domain->iotlb, entry.start, entry.last); if (map) { map_file = (struct vdpa_map_file *)map->opaque; @@ -1131,7 +1140,8 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, entry.last = map->last; entry.perm = map->perm; } - spin_unlock(&domain->iotlb_lock); + spin_unlock(&dev->domain->iotlb_lock); + mutex_unlock(&dev->domain_lock); ret = -EINVAL; if (!f) break; @@ -1284,8 +1294,10 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, sizeof(umem.reserved))) break; + mutex_lock(&dev->domain_lock); ret = vduse_dev_reg_umem(dev, umem.iova, umem.uaddr, umem.size); + mutex_unlock(&dev->domain_lock); break; } case VDUSE_IOTLB_DEREG_UMEM: { @@ -1299,15 +1311,15 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, if (!is_mem_zero((const char *)umem.reserved, sizeof(umem.reserved))) break; - + mutex_lock(&dev->domain_lock); ret = vduse_dev_dereg_umem(dev, umem.iova, umem.size); + mutex_unlock(&dev->domain_lock); break; } case VDUSE_IOTLB_GET_INFO: { struct vduse_iova_info info; struct vhost_iotlb_map *map; - struct vduse_iova_domain *domain = dev->domain; ret = -EFAULT; if (copy_from_user(&info, argp, sizeof(info))) @@ -1321,18 +1333,24 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, sizeof(info.reserved))) break; - spin_lock(&domain->iotlb_lock); - map = vhost_iotlb_itree_first(domain->iotlb, + mutex_lock(&dev->domain_lock); + if (!dev->domain) { + mutex_unlock(&dev->domain_lock); + break; + } + spin_lock(&dev->domain->iotlb_lock); + map = vhost_iotlb_itree_first(dev->domain->iotlb, info.start, info.last); if (map) { info.start = map->start; info.last = map->last; info.capability = 0; - if (domain->bounce_map && map->start == 0 && - map->last == domain->bounce_size - 1) + if (dev->domain->bounce_map && map->start == 0 && + map->last == dev->domain->bounce_size - 1) info.capability |= VDUSE_IOVA_CAP_UMEM; } - spin_unlock(&domain->iotlb_lock); + spin_unlock(&dev->domain->iotlb_lock); + mutex_unlock(&dev->domain_lock); if (!map) break; @@ -1355,7 +1373,10 @@ static int vduse_dev_release(struct inode *inode, struct file *file) { struct vduse_dev *dev = file->private_data; - vduse_dev_dereg_umem(dev, 0, dev->domain->bounce_size); + mutex_lock(&dev->domain_lock); + if (dev->domain) + vduse_dev_dereg_umem(dev, 0, dev->domain->bounce_size); + mutex_unlock(&dev->domain_lock); spin_lock(&dev->msg_lock); /* Make sure the inflight messages can processed after reconncection */ list_splice_init(&dev->recv_list, &dev->send_list); @@ -1564,6 +1585,7 @@ static struct vduse_dev *vduse_dev_create(void) mutex_init(&dev->lock); mutex_init(&dev->mem_lock); + mutex_init(&dev->domain_lock); spin_lock_init(&dev->msg_lock); INIT_LIST_HEAD(&dev->send_list); INIT_LIST_HEAD(&dev->recv_list); @@ -1613,7 +1635,8 @@ static int vduse_destroy_dev(char *name) idr_remove(&vduse_idr, dev->minor); kvfree(dev->config); vduse_dev_deinit_vqs(dev); - vduse_domain_destroy(dev->domain); + if (dev->domain) + vduse_domain_destroy(dev->domain); kfree(dev->name); vduse_dev_destroy(dev); module_put(THIS_MODULE); @@ -1722,11 +1745,7 @@ static int vduse_create_dev(struct vduse_dev_config *config, if (!dev->name) goto err_str; - dev->domain = vduse_domain_create(VDUSE_IOVA_SIZE - 1, - VDUSE_BOUNCE_SIZE); - if (!dev->domain) - goto err_domain; - + dev->bounce_size = VDUSE_BOUNCE_SIZE; dev->config = config_buf; dev->config_size = config->config_size; @@ -1756,8 +1775,6 @@ static int vduse_create_dev(struct vduse_dev_config *config, err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: - vduse_domain_destroy(dev->domain); -err_domain: kfree(dev->name); err_str: vduse_dev_destroy(dev); @@ -1924,9 +1941,23 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, if (ret) return ret; + mutex_lock(&dev->domain_lock); + if (!dev->domain) + dev->domain = vduse_domain_create(VDUSE_IOVA_SIZE - 1, + dev->bounce_size); + mutex_unlock(&dev->domain_lock); + if (!dev->domain) { + put_device(&dev->vdev->vdpa.dev); + return -ENOMEM; + } + ret = _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num); if (ret) { put_device(&dev->vdev->vdpa.dev); + mutex_lock(&dev->domain_lock); + vduse_domain_destroy(dev->domain); + dev->domain = NULL; + mutex_unlock(&dev->domain_lock); return ret; } From patchwork Thu Mar 23 05:30:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 73823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2737858wrt; Wed, 22 Mar 2023 22:50:55 -0700 (PDT) X-Google-Smtp-Source: AK7set+0zry+m8wQe+GEXf60Y6Og8efmWS1StsO4uWDOvMFqhO1CAygLBTuLrnPrzqcduRjCqJub X-Received: by 2002:a17:90b:3a83:b0:23f:d662:2c20 with SMTP id om3-20020a17090b3a8300b0023fd6622c20mr6120338pjb.26.1679550654842; Wed, 22 Mar 2023 22:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679550654; cv=none; d=google.com; s=arc-20160816; b=mRR6qjw5neeEAxLp/+JASyE2wNpeALd32Nt0sQ+SzoMsiqjXHtO87L9ckbuvI3URnO El97hsRdE6FyloPU5tMAw1eh48HGlQcbrO4RtCCaGfSZuu1lPmUCT7MlyLZ+ZVPDQND/ YEICluoXHrnKwQ+uDxMBwLpXO0qRAw2eRFv3n09WqSR+MXx0irmsSgW0ulPuJj3OMXeO 7RcUwl8x1adgkjVlNLZGTG4qGqhZajEndjHAFelWgl6U30EUFLYHDnO8QaO1NhHsL2/F t7RLHGDm660R896h6qFZWZEW1NqrZ3hp/QpFhOrXDdPXgxZmQFe4qbe0sXZ+cN+LhHE3 cAmg== 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=i7Y4Ia2snWtMWEm2g6DOKe7n5pYzTJA+X6topb6lq9g=; b=bWJGwhJz4MJJhD+ZA6/y/WTu5xixdiYru9uldesW8Kf1YtyiBNSmdPLhAsXTprvRQ9 Z9Fky6Y/hVmSYpko1HuY4v7kpENIzsxb3gmIBuiAl/3SqGvLu5HJaU7U4dTsRqkQEFFO eHGFs5mGcqomlcRKuutR9Qc76QuhXDE854sCwZGYWWKVULHi+cTBILFvyPPa/Z94n/KK P+RVUJoFVUSDpEgTqN1lBfa1QQgfRZZMjfkiAQQyMOaD0vSLjQl8gTpyK2uVIPWSCuCQ 3BGIgcEE4Q0vYv+BDhc/7PE/O9/jmuDitY/C5T05BgzJHPytIECzrADu8IJpqA/ZV7zp pOHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=jLB0M001; 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 x185-20020a6386c2000000b005089e773be5si18839869pgd.661.2023.03.22.22.50.41; Wed, 22 Mar 2023 22:50:54 -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=jLB0M001; 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 S230476AbjCWFdu (ORCPT + 99 others); Thu, 23 Mar 2023 01:33:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbjCWFdP (ORCPT ); Thu, 23 Mar 2023 01:33:15 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56D4421A37 for ; Wed, 22 Mar 2023 22:31:50 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so885571pjt.2 for ; Wed, 22 Mar 2023 22:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679549508; 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=i7Y4Ia2snWtMWEm2g6DOKe7n5pYzTJA+X6topb6lq9g=; b=jLB0M001ArNDXvBdu4Kkz2tvdm0SNwF9y87GgxRVEWG9OfmGbGvycogmZUQ0FSM20K XMkCUgjgk7ACFbdaAwoQc0cNGY1c/fK6F58j4XoVaSZCIieE8PLt5w6Hy/qXaCsFpIVw peyrCRoYs23OcPOCATbMoxIJUjya3ZGeVTTYS1kQ/x7/A6LXlhbz4LCZ3EdISXDWgj1W TiZHNGQoMhosOP9VO4LyWP4H6J+aMQhwOR8MenYmNS0WN21IjVTDyyWxrxH5fB7EXLZl ltZC03ojIDGTIJZ1hmMaMUXPyDTbGFapwpSUnEm9FEfQ4ER94vL/o2tBAZ3A4bBosFOa ut2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679549508; 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=i7Y4Ia2snWtMWEm2g6DOKe7n5pYzTJA+X6topb6lq9g=; b=f6np4QJPIPjJZYISkhdAbyMH0i7IJcq/me97cvO94Z/0r1nHzKypwLpdcJOCOsE22V wGxbIwvicfyOoTcdjI6o9mmd36cIDBsftnZXJz0d8lr4saqoohIcmOTs3b/I+lmrjEjZ d+et8YXPzhvCxVoY3tv5oM+zGe2zUeDy50xDIQuecTwM0KnyeFZzYQHRMqWq12oYBMpS 3Y1hIPcMvl7lNodDY8AEp1oulHxXhOSfz/mMzZHAXZGhGStUvlFPRJSfFZ92FwkPUPV0 1QFvlhXUB3DHEa98Dlvhkh86aIuNTN/Ac8a1vSBO4Bft5h1xaoh+4cnKAOZD+8mqn61w PzDQ== X-Gm-Message-State: AO0yUKU+zAdf/3lXSl9ofAsh3L9JDluoe5egjIWAPgQzLRfNDaQ4+/47 ZA9y+VTpnNb02T4RxjY/OgE4 X-Received: by 2002:a17:90b:1b45:b0:23f:7770:9e75 with SMTP id nv5-20020a17090b1b4500b0023f77709e75mr6342770pjb.47.1679549508205; Wed, 22 Mar 2023 22:31:48 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id j12-20020a17090aeb0c00b00230b8431323sm455495pjz.30.2023.03.22.22.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 22:31:47 -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 11/11] vduse: Support specifying bounce buffer size via sysfs Date: Thu, 23 Mar 2023 13:30:43 +0800 Message-Id: <20230323053043.35-12-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?1761136507276705917?= X-GMAIL-MSGID: =?utf-8?q?1761136507276705917?= As discussed in [1], this adds sysfs interface to support specifying bounce buffer size in virtio-vdpa case. It would be a performance tuning parameter for high throughput workloads. [1] https://lore.kernel.org/netdev/e8f25a35-9d45-69f9-795d-bdbbb90337a3@redhat.com/ Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 45 +++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index ccca84d51a28..34eebdf030af 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -37,8 +37,11 @@ #define DRV_LICENSE "GPL v2" #define VDUSE_DEV_MAX (1U << MINORBITS) +#define VDUSE_MAX_BOUNCE_SIZE (1024 * 1024 * 1024) +#define VDUSE_MIN_BOUNCE_SIZE (1024 * 1024) #define VDUSE_BOUNCE_SIZE (64 * 1024 * 1024) -#define VDUSE_IOVA_SIZE (128 * 1024 * 1024) +/* 128 MB reserved for virtqueue creation */ +#define VDUSE_IOVA_SIZE (VDUSE_MAX_BOUNCE_SIZE + 128 * 1024 * 1024) #define VDUSE_MSG_DEFAULT_TIMEOUT 30 #define IRQ_UNBOUND -1 @@ -1715,8 +1718,48 @@ static ssize_t msg_timeout_store(struct device *device, static DEVICE_ATTR_RW(msg_timeout); +static ssize_t bounce_size_show(struct device *device, + struct device_attribute *attr, char *buf) +{ + struct vduse_dev *dev = dev_get_drvdata(device); + + return sysfs_emit(buf, "%u\n", dev->bounce_size); +} + +static ssize_t bounce_size_store(struct device *device, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct vduse_dev *dev = dev_get_drvdata(device); + unsigned int bounce_size; + int ret; + + ret = -EPERM; + mutex_lock(&dev->domain_lock); + if (dev->domain) + goto unlock; + + ret = kstrtouint(buf, 10, &bounce_size); + if (ret < 0) + goto unlock; + + ret = -EINVAL; + if (bounce_size > VDUSE_MAX_BOUNCE_SIZE || + bounce_size < VDUSE_MIN_BOUNCE_SIZE) + goto unlock; + + dev->bounce_size = bounce_size & PAGE_MASK; + ret = count; +unlock: + mutex_unlock(&dev->domain_lock); + return ret; +} + +static DEVICE_ATTR_RW(bounce_size); + static struct attribute *vduse_dev_attrs[] = { &dev_attr_msg_timeout.attr, + &dev_attr_bounce_size.attr, NULL };