Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp11505pxk; Wed, 23 Sep 2020 20:29:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdzSzvsEMDxf7b+xgHdvOctWYKBmDkU2ELfIgOTpeZnTOCNt3uv7JnEKxV/xpqyK8I6dYV X-Received: by 2002:a50:875b:: with SMTP id 27mr2457483edv.117.1600918185250; Wed, 23 Sep 2020 20:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600918185; cv=none; d=google.com; s=arc-20160816; b=fQYk7q6al8TKR6e+jQ0dACuc1ekG+Ba/PH5fOJ4mN1sGIALRZN6wXnS2feNl9MJZPA FGB8LOgKtV1MBbbTG8tzFU5tZDSLw18oa/kg6HkiWwUq1f2Avslu2hE+5x38wuXmG8lX +NKxnEv2tydk883ESKbcWDkqXMFRlN5ii7iRUL4+/k9Zd2Kp7QN0mpi96/KRIAK6ByLD dosORuys5favviMyIvwUI2g3sHxu4fTJDrW+5wkYiLIcfDA3GKLkI6xWPA+MMKORJizs e18LuiPw+p2gFk/YSjJs5/f1TmRggt/hulDsEvHGPZurh5sYLaLwjCM5kwrEIH+saS44 9iRQ== 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=JdWFZT9fAjP/0OXJ+0TueGjoxru0MJjQg1dkRacC8Lo=; b=X6jC2CzvSfMgf5F6RlRvJlCjdWCMlLqn5wGZqQNXNtYTEgY9wreP3lPdxBMkTH8bUL zD9k9V2SICJlF7b6CsrlXQVelrVRWI5xKouJeRSHgglm3Qo/pAUfFfJa+SIoaRnqjzMb 2vRYe1JG79u9K4w/qdmjksDFOgIZmgVkTeckpaIESs54t7/yr9JO1OfOAuoY/pb5X6fb SkgX160LXDmfWDYHEgF4sPOWDPBodPNJzfstYF4eo/hyEr8A20JIXCjz3j4fyMVskVtA oRuD3PIt2JKGe0NplMGfM3mep7lciFLNouPIzoowG/amsGhoSBCbGKXFZSPibHFJ68IY nbMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RtuEGX+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si1170989ejo.55.2020.09.23.20.29.21; Wed, 23 Sep 2020 20:29:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RtuEGX+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727121AbgIXD0H (ORCPT + 99 others); Wed, 23 Sep 2020 23:26:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60578 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgIXD0F (ORCPT ); Wed, 23 Sep 2020 23:26:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600917964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JdWFZT9fAjP/0OXJ+0TueGjoxru0MJjQg1dkRacC8Lo=; b=RtuEGX+Ue2sYQcHFVaJKrq85w482pEwBtAUXoUbrlrmO43kT7+bOtsF4yjE7xXvPQYo4hy eB0ueJ+ghaNsk7fSIkWUsNkMs5XdJ0uv2bNmjZUTJYFYVDi0EAmEBJkughZsrjth4i1jmG UsryNFwaaQ38QH5CG4Yr4DHH0rR2x5k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-ZvvYi0pWN4eM__stVZzYFA-1; Wed, 23 Sep 2020 23:26:00 -0400 X-MC-Unique: ZvvYi0pWN4eM__stVZzYFA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80ED181CAFC; Thu, 24 Sep 2020 03:25:58 +0000 (UTC) Received: from jason-ThinkPad-X1-Carbon-6th.redhat.com (ovpn-13-193.pek2.redhat.com [10.72.13.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D0A83782; Thu, 24 Sep 2020 03:25:46 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: lulu@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, rob.miller@broadcom.com, lingshan.zhu@intel.com, eperezma@redhat.com, hanand@xilinx.com, mhabets@solarflare.com, eli@mellanox.com, amorenoz@redhat.com, maxime.coquelin@redhat.com, stefanha@redhat.com, sgarzare@redhat.com Subject: [RFC PATCH 22/24] vdpa_sim: factor out buffer completion logic Date: Thu, 24 Sep 2020 11:21:23 +0800 Message-Id: <20200924032125.18619-23-jasowang@redhat.com> In-Reply-To: <20200924032125.18619-1-jasowang@redhat.com> References: <20200924032125.18619-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch factors out the buffer completion logic in order to support future features. Signed-off-by: Jason Wang --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 33 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index ca5c2d0db905..b21670e054ba 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -155,6 +155,22 @@ static void vdpasim_reset(struct vdpasim *vdpasim) ++vdpasim->generation; } +static void vdpasim_complete(struct vdpasim_virtqueue *vq, size_t len) +{ + /* Make sure data is wrote before advancing index */ + smp_wmb(); + + vringh_complete_iotlb(&vq->vring, vq->head, len); + + /* Make sure used is visible before rasing the interrupt. */ + smp_wmb(); + + local_bh_disable(); + if (vq->cb) + vq->cb(vq->private); + local_bh_enable(); +} + static void vdpasim_work(struct work_struct *work) { struct vdpasim *vdpasim = container_of(work, struct @@ -203,21 +219,8 @@ static void vdpasim_work(struct work_struct *work) total_write += write; } - /* Make sure data is wrote before advancing index */ - smp_wmb(); - - vringh_complete_iotlb(&txq->vring, txq->head, 0); - vringh_complete_iotlb(&rxq->vring, rxq->head, total_write); - - /* Make sure used is visible before rasing the interrupt. */ - smp_wmb(); - - local_bh_disable(); - if (txq->cb) - txq->cb(txq->private); - if (rxq->cb) - rxq->cb(rxq->private); - local_bh_enable(); + vdpasim_complete(txq, 0); + vdpasim_complete(rxq, total_write); if (++pkts > 4) { schedule_work(&vdpasim->work); -- 2.20.1