Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2784449pxb; Mon, 25 Apr 2022 02:19:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/MlGYjOBFSBKnlkzEykamP3gI1m7vbI0P2rrJrhXYRK+MFccLazBmUjcHEF70QCB6OLQt X-Received: by 2002:a17:90a:77c8:b0:1d2:f7f3:53d2 with SMTP id e8-20020a17090a77c800b001d2f7f353d2mr19599266pjs.83.1650878379218; Mon, 25 Apr 2022 02:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650878379; cv=none; d=google.com; s=arc-20160816; b=J6pRMdauVPMfYbXZEPEYju6s8Nl0qj1GITFVX5JdiCkjxosdE6/TYq6Jg7p5qFGSK+ L6/UUjBJXIux24gT73KbAGVFxkc1tz7UY/rvBJ41EedVlbpUXqKw+ldAL/wYqqQcsp6b yoB56yMLrvVnqVXruEPSiFOkDyjZJOFe3DT17qa0ZpW0omJFRZRHmWXbWTXxYgYRGAop cJ5Y7bVqiz6b8hSHoZIiuTVVV53dltdMJJZyJ+qFrT4MicqRFG825M/di8fLmNpQCFvc nqaMRw5k3RRxZBkMb1ZSMrvCA1CQkU+ZuB7rYre7EK50Qpk/7vXXnpS59fUrb9reHkeS ruDA== 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=tfSu6KrqWUap3cnUn9mXIRBQNV5IMT/hsaDS1Qe8rF0=; b=bqxkwHzYH3HgFpW2EmekgqZBCO/Mu+Ht/4q1MIQg34loWbXU9act6+7I5166J/dntJ cqT/xlVssoxEmDaAIUStB6k4lld4QZZSvDIKjvGivgsX+mLhDzCjNU6wQi7OsGrbo9MN 05SbAkLkSUp69cv0qIPI+Y7UT8On29VQ3z0rtUyLV1P4KdqYRWX8tYXLJnW+ayq6lyZR jCp6fE7BGRE8d2mZPObe//UxiqjpNdXCqhI1p7xVcUsyELcjcupi84tMDai+xj4EgdFK IG/vpWZlc+csSsKZU8PSpcXpCP+whzxdsAOMnMt4YWvdMAdeNJDXQgh61PxQU901yAGZ 4aRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dD2SVIk1; 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 d3-20020a170903230300b00153b2d164edsi5641559plh.245.2022.04.25.02.19.24; Mon, 25 Apr 2022 02:19:39 -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=dD2SVIk1; 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 S240429AbiDYCsL (ORCPT + 99 others); Sun, 24 Apr 2022 22:48:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240444AbiDYCsJ (ORCPT ); Sun, 24 Apr 2022 22:48:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C3FA42BE6 for ; Sun, 24 Apr 2022 19:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650854701; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tfSu6KrqWUap3cnUn9mXIRBQNV5IMT/hsaDS1Qe8rF0=; b=dD2SVIk11tYT5ETh5UF8JobSDHHFX7J+II2LGcYmB/Q+zJ1P4aWY6rn9zE9VxZxThkGW4C ZHggxz5HuY8pzsighznr7PXR9/B1JUYJGcYK8EX1HlWSYryHnD2qMtwyLGLfLKT23XwMfi o8N8+GmvpdZ5xEMbOZPdf4WhrBr4apk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-493-LT8PTN37N5a4jbvSb7fDjg-1; Sun, 24 Apr 2022 22:44:58 -0400 X-MC-Unique: LT8PTN37N5a4jbvSb7fDjg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 318A2811E76; Mon, 25 Apr 2022 02:44:57 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECDC89E6E; Mon, 25 Apr 2022 02:44:51 +0000 (UTC) From: Jason Wang To: jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: sgarzare@redhat.com, eperezma@redhat.com, lulu@redhat.com, tglx@linutronix.de, peterz@infradead.org, paulmck@kernel.org, maz@kernel.org, pasic@linux.ibm.com, cohuck@redhat.com Subject: [PATCH V3 3/9] virtio: introduce config op to synchronize vring callbacks Date: Mon, 25 Apr 2022 10:44:12 +0800 Message-Id: <20220425024418.8415-4-jasowang@redhat.com> In-Reply-To: <20220425024418.8415-1-jasowang@redhat.com> References: <20220425024418.8415-1-jasowang@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 This patch introduces new virtio config op to vring callbacks. Transport specific method is required to make sure the write before this function is visible to the vring_interrupt() that is called after the return of this function. For the transport that doesn't provide synchronize_vqs(), use synchornize_rcu() which synchronize with IRQ implicitly as a fallback. Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: "Paul E. McKenney" Cc: Marc Zyngier Cc: Halil Pasic Cc: Cornelia Huck Signed-off-by: Jason Wang --- include/linux/virtio_config.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index b341dd62aa4d..14fe89ff99c7 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -57,6 +57,10 @@ struct virtio_shm_region { * include a NULL entry for vqs unused by driver * Returns 0 on success or error status * @del_vqs: free virtqueues found by find_vqs(). + * @synchronize_cbs: synchronize with the virtqueue callbacks (optional) + * Make sure the writes commited before this method is visible to + * vring_interrupt() which is called after this method. + * vdev: the virtio_device * @get_features: get the array of feature bits for this device. * vdev: the virtio_device * Returns the first 64 feature bits (all we currently need). @@ -89,6 +93,7 @@ struct virtio_config_ops { const char * const names[], const bool *ctx, struct irq_affinity *desc); void (*del_vqs)(struct virtio_device *); + void (*synchronize_cbs)(struct virtio_device *); u64 (*get_features)(struct virtio_device *vdev); int (*finalize_features)(struct virtio_device *vdev); const char *(*bus_name)(struct virtio_device *vdev); @@ -217,6 +222,25 @@ int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs, desc); } +/** + * virtio_synchronize_cbs - synchronize with virtqueue callbacks + * @vdev: the device + */ +static inline +void virtio_synchronize_cbs(struct virtio_device *dev) +{ + if (dev->config->synchronize_cbs) { + dev->config->synchronize_cbs(dev); + } else { + /* + * A best effort fallback to synchronize with + * interrupts, preemption and softirq. See comment + * above synchronize_rcu(). + */ + synchronize_rcu(); + } +} + /** * virtio_device_ready - enable vq use in probe function * @vdev: the device -- 2.25.1