Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1296094rwl; Fri, 24 Mar 2023 08:41:54 -0700 (PDT) X-Google-Smtp-Source: AKy350bXrxgkMSbkxXK7/dswZ3qaivjclLx50sQSY+o14eWifsuuiibf2iBBGOr9xQbNh689opr1 X-Received: by 2002:aa7:de0f:0:b0:4fc:73dc:5df3 with SMTP id h15-20020aa7de0f000000b004fc73dc5df3mr3380758edv.29.1679672514322; Fri, 24 Mar 2023 08:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679672514; cv=none; d=google.com; s=arc-20160816; b=hhS++C3UGY3I//Cg/mqKO/8m4i5jPuWAQoGDmWODJb2pp6CyDAUPBVY65bZOwqXnap tLPQmacB1iif+3X2OEoeJR5uUg7gc5Sjo5MDprKfkimD1GBKRXXsN9YZgoCB5rf+kpLm ONJigpatrYkme+/pUX9yxdjKsbxvFQYVOSDyNuWwA9rukhjWXAy1l0jsWHvu/OK07PfL Bn8Ij4DqdQhAoPOwIfKjQlZlAGM96GEAVDr4Ic0mG2gr6xDVdm8vBKLWR2d2RxAqK0e8 yrTVJwu33rFWbn5+x4Sbe8jTCY9QgIk12CiIYTEKvMvEs7DeceD7iohPK84vnrB2guKq h/dQ== 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=dJgV3Uny0vAQYBeBkJItoY2HRKhsGCmVf+cCCim+XIk=; b=cPXwheVKre/2WXnFHuF4fsRaxK84mZ7YVfZA5FPowA3bfzY5pSVmIqDJayVn3h1Yt5 U/QwjdepQXUVbmT8iiaoVaRZzMMkM2yyIIe0VmzXZucwwqlNduEroUckj2BbHVd/BUfd Yds5tS4905fyk6cAdgFMy7KNMffWT2HycCV6M4GKd8eP/rmHz6t7c/5mXL/CxR91U0Ju RWl1f28F3EQktDrX+/6IxSJjvKfPuxWdIx6zgDBWfLMQNxFgwxZz1InD5Lwk1xfhVjt9 my9gPZEli985+AtHz6BgZLGvV2cYrdnqeM3FU8QfeWrrt2X40S89yF/xNkDvkAQrHvzW 7X1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=en6VYq2d; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a05640207cc00b0050202fbb587si5772885edy.352.2023.03.24.08.41.30; Fri, 24 Mar 2023 08:41: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=@redhat.com header.s=mimecast20190719 header.b=en6VYq2d; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232392AbjCXPkk (ORCPT + 99 others); Fri, 24 Mar 2023 11:40:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232187AbjCXPkd (ORCPT ); Fri, 24 Mar 2023 11:40:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EB1F2007A for ; Fri, 24 Mar 2023 08:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679672382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dJgV3Uny0vAQYBeBkJItoY2HRKhsGCmVf+cCCim+XIk=; b=en6VYq2dfWkn4AQkw2R92tyllByGZwHNzsiG68QdJJ+d8ZBPyvnc6+s7kJt27xYxO5cdGi nPCbruM3z7Ji6Aujt3JGPm9MpDyjbVeSqodKpfoawfx4TWpvouHQp7B3zki9IHfK7lCXNF jEBNCv1rVLYhjT0F3Cgb865I6195vf8= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-180-iXfXSNIHMCivI2CBQXZktg-1; Fri, 24 Mar 2023 11:39:41 -0400 X-MC-Unique: iXfXSNIHMCivI2CBQXZktg-1 Received: by mail-ed1-f70.google.com with SMTP id j21-20020a508a95000000b004fd82403c91so3760579edj.3 for ; Fri, 24 Mar 2023 08:39:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679672380; 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=dJgV3Uny0vAQYBeBkJItoY2HRKhsGCmVf+cCCim+XIk=; b=Q1Iq1ypjwYINKcaKn5OpF3+SuRMHwYdwx8qB5lG9HIuu9b5Mel+S+GJrni1CqM9OAI oimMuGsXMO35FvHoFvKjme0fMvHsmNgPZgmsngSf7vUj2S/3ihvlUjIDBYYzDo0nBD/5 teR+E2TD+2L+4nJ/FQ32hbTFLY1lE1wVTZInPshz+gPFrw7PNLrlsQA1tYJF29l31a/H AN4g3FGNAu8XzL2phFn6nlVO2BmBqCIYfr/FimRghbs6hIRjIN4vkh+yXSMw/CZJa52u Lgz6RPBS7crEYld/1Wc/7BJAqYSpxN0+ZsEyx0+DedZVIXlXPC4UKDgozvoSSirTG7dm dYow== X-Gm-Message-State: AAQBX9fjfKPCV2ZKD0ap6ZkxXnUeFcgHIhZFdCrAKA9z+EQifmRJZsik 5HHtncy16USY4zk18jbEThzwGM23iZ+rF/IYjsAKK/OXjVGMoxN2C5m02VJUl1po2+WG4UHcUIv NmJ8RUSP9E1UtJEcdE7sDEeKO X-Received: by 2002:a17:906:3607:b0:92d:44ca:1137 with SMTP id q7-20020a170906360700b0092d44ca1137mr3426156ejb.43.1679672380057; Fri, 24 Mar 2023 08:39:40 -0700 (PDT) X-Received: by 2002:a17:906:3607:b0:92d:44ca:1137 with SMTP id q7-20020a170906360700b0092d44ca1137mr3426143ejb.43.1679672379807; Fri, 24 Mar 2023 08:39:39 -0700 (PDT) Received: from localhost.localdomain (host-82-53-134-98.retail.telecomitalia.it. [82.53.134.98]) by smtp.gmail.com with ESMTPSA id ot17-20020a170906ccd100b008e51a1fd7bfsm10581350ejb.172.2023.03.24.08.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 08:39:38 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , Jason Wang , eperezma@redhat.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org, stefanha@redhat.com, "Michael S. Tsirkin" , Stefano Garzarella Subject: [PATCH v4 6/9] vdpa_sim: make devices agnostic for work management Date: Fri, 24 Mar 2023 16:39:29 +0100 Message-Id: <20230324153929.47670-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324153607.46836-1-sgarzare@redhat.com> References: <20230324153607.46836-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,PP_MIME_FAKE_ASCII_TEXT, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 Let's move work management inside the vdpa_sim core. This way we can easily change how we manage the works, without having to change the devices each time. Acked-by: Eugenio PĂ©rez Martin Acked-by: Jason Wang Signed-off-by: Stefano Garzarella --- drivers/vdpa/vdpa_sim/vdpa_sim.h | 3 ++- drivers/vdpa/vdpa_sim/vdpa_sim.c | 17 +++++++++++++++-- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 6 ++---- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 6 ++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h index 144858636c10..acee20faaf6a 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -45,7 +45,7 @@ struct vdpasim_dev_attr { u32 ngroups; u32 nas; - work_func_t work_fn; + void (*work_fn)(struct vdpasim *vdpasim); void (*get_config)(struct vdpasim *vdpasim, void *config); void (*set_config)(struct vdpasim *vdpasim, const void *config); int (*get_stats)(struct vdpasim *vdpasim, u16 idx, @@ -78,6 +78,7 @@ struct vdpasim { struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr, const struct vdpa_dev_set_config *config); +void vdpasim_schedule_work(struct vdpasim *vdpasim); /* TODO: cross-endian support */ static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index eea23c630f7c..2df5227e0b62 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -127,6 +127,13 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim) static const struct vdpa_config_ops vdpasim_config_ops; static const struct vdpa_config_ops vdpasim_batch_config_ops; +static void vdpasim_work_fn(struct work_struct *work) +{ + struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); + + vdpasim->dev_attr.work_fn(vdpasim); +} + struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr, const struct vdpa_dev_set_config *config) { @@ -163,7 +170,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr, vdpasim = vdpa_to_sim(vdpa); vdpasim->dev_attr = *dev_attr; - INIT_WORK(&vdpasim->work, dev_attr->work_fn); + INIT_WORK(&vdpasim->work, vdpasim_work_fn); spin_lock_init(&vdpasim->lock); spin_lock_init(&vdpasim->iommu_lock); @@ -214,6 +221,12 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr, } EXPORT_SYMBOL_GPL(vdpasim_create); +void vdpasim_schedule_work(struct vdpasim *vdpasim) +{ + schedule_work(&vdpasim->work); +} +EXPORT_SYMBOL_GPL(vdpasim_schedule_work); + static int vdpasim_set_vq_address(struct vdpa_device *vdpa, u16 idx, u64 desc_area, u64 driver_area, u64 device_area) @@ -248,7 +261,7 @@ static void vdpasim_kick_vq(struct vdpa_device *vdpa, u16 idx) } if (vq->ready) - schedule_work(&vdpasim->work); + vdpasim_schedule_work(vdpasim); } static void vdpasim_set_vq_cb(struct vdpa_device *vdpa, u16 idx, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c index 5117959bed8a..eb4897c8541e 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -286,9 +285,8 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasim, return handled; } -static void vdpasim_blk_work(struct work_struct *work) +static void vdpasim_blk_work(struct vdpasim *vdpasim) { - struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); bool reschedule = false; int i; @@ -326,7 +324,7 @@ static void vdpasim_blk_work(struct work_struct *work) spin_unlock(&vdpasim->lock); if (reschedule) - schedule_work(&vdpasim->work); + vdpasim_schedule_work(vdpasim); } static void vdpasim_blk_get_config(struct vdpasim *vdpasim, void *config) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index 862f405362de..e61a9ecbfafe 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -192,9 +191,8 @@ static void vdpasim_handle_cvq(struct vdpasim *vdpasim) u64_stats_update_end(&net->cq_stats.syncp); } -static void vdpasim_net_work(struct work_struct *work) +static void vdpasim_net_work(struct vdpasim *vdpasim) { - struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); struct vdpasim_virtqueue *txq = &vdpasim->vqs[1]; struct vdpasim_virtqueue *rxq = &vdpasim->vqs[0]; struct vdpasim_net *net = sim_to_net(vdpasim); @@ -260,7 +258,7 @@ static void vdpasim_net_work(struct work_struct *work) vdpasim_net_complete(rxq, write); if (tx_pkts > 4) { - schedule_work(&vdpasim->work); + vdpasim_schedule_work(vdpasim); goto out; } } -- 2.39.2