Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76D78C74A5B for ; Tue, 21 Mar 2023 15:49:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231787AbjCUPtB (ORCPT ); Tue, 21 Mar 2023 11:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231140AbjCUPs7 (ORCPT ); Tue, 21 Mar 2023 11:48:59 -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 1A5C4127 for ; Tue, 21 Mar 2023 08:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679413690; 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=FrIqaFYwyTmRX9vIpLtwNdbcxX+HkfxwISKF0JNI/H0=; b=hzhrAdO49YFT4RK/dMJ+Flocix+E+tO5xZGIERqzUTO9GT5MeIAvfEf5KdYYw1QrJg7JOo thZHYY/bsJ1P6r9qR+St4eDCHFky2IvyRlxQzPrkvNmefbXfga7Adx+BezZyQsg2SjGi7c qnsEqa7/MUccdNF3qlQtKTjLgwpkRVc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-208-SR36Wsj2MO-4HeE4ypuCvQ-1; Tue, 21 Mar 2023 11:48:08 -0400 X-MC-Unique: SR36Wsj2MO-4HeE4ypuCvQ-1 Received: by mail-wm1-f71.google.com with SMTP id m27-20020a05600c3b1b00b003ee502f1b16so74882wms.9 for ; Tue, 21 Mar 2023 08:48:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679413687; 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=FrIqaFYwyTmRX9vIpLtwNdbcxX+HkfxwISKF0JNI/H0=; b=OjJc+QdFvMZpcGPsLglqoBssChPnKjsqMIKCh82P80YG2LfXH0Wk71Qyv3LYeMywyS +l8Tf4xNfUx8hmqpQHluzZlFhO1I0+m1miUQJY3SUQ60bZO6Th72Q1uIp0ojuiSDEmS8 nwYsqEBmRwFpsBVUriWQqxHsSvMoCUx01Wu7y2dsDofjqNHSdr6X+cxhfLn/skj22KtN ++7MZNqxi6Px6vFs+xy/OKyeFWI90EWRM4AgceBlwBNWY2aPz1vUiPE90aaJUNUYl/60 KivhoIQQqnIYRva1D1Pd0y4gMiu+j8ThVC0wLVVTJS1FhHtYRnskJn480hRCCwCyyk/Z IfBw== X-Gm-Message-State: AO0yUKXMTf5epw/UTVeYMUaBBFlFc0D0kTm3a3wUTLoFzW5Tzn8Zm6b9 eWTljSGWBV10BxmO8TVTh56059WFcwTJhaCA0rn5pgAPjaxpohC3j5XMjPL/OUW7zprXFEkwM44 r1U6tQwCIwSeivfNWK1ioSAwb X-Received: by 2002:a5d:55c5:0:b0:2c5:5a65:79a0 with SMTP id i5-20020a5d55c5000000b002c55a6579a0mr2537874wrw.53.1679413687683; Tue, 21 Mar 2023 08:48:07 -0700 (PDT) X-Google-Smtp-Source: AK7set8zJ+3kU4lOVXwdoOWRljg1S9AH57DH/uZni/ASmZK83u/KzxIRohwIvakFGtA2eZrEDXXjFg== X-Received: by 2002:a5d:55c5:0:b0:2c5:5a65:79a0 with SMTP id i5-20020a5d55c5000000b002c55a6579a0mr2537860wrw.53.1679413687398; Tue, 21 Mar 2023 08:48:07 -0700 (PDT) Received: from step1.redhat.com (host-82-57-51-170.retail.telecomitalia.it. [82.57.51.170]) by smtp.gmail.com with ESMTPSA id z15-20020a5d44cf000000b002ce9f0e4a8fsm11692694wrr.84.2023.03.21.08.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 08:48:06 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , kvm@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, eperezma@redhat.com, "Michael S. Tsirkin" , Andrey Zhadchenko , netdev@vger.kernel.org, Stefano Garzarella Subject: [PATCH v3 5/8] vdpa_sim: make devices agnostic for work management Date: Tue, 21 Mar 2023 16:48:01 +0100 Message-Id: <20230321154804.184577-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230321154228.182769-1-sgarzare@redhat.com> References: <20230321154228.182769-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-type: text/plain Content-Transfer-Encoding: 8bit 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 47cdf2a1f5b8..f6329900e61a 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