Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp449617imu; Tue, 22 Jan 2019 22:58:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN5rPpGC1ksIsivoPUrfxjUxdf3csw8mTfIp+k7YPXtrNeGOqM4eLeGAWR9csWZHnnlHMP+6 X-Received: by 2002:a62:2cf:: with SMTP id 198mr1036719pfc.67.1548226680040; Tue, 22 Jan 2019 22:58:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548226680; cv=none; d=google.com; s=arc-20160816; b=a/iA+ri9hh6C65jImrAiamLr4705WIIMBgXGouUl/oiQlEB67z0nhyjx7+WPHAewHR jt2pk6eSOK5DGx8raNL3vKDkwW9BV4tQChONnEnQYu4ie3jWkOsQYSb3LgdFeHIDY3WI nsazjXuOWODfsEz2CI0Q3Xg1Iae2rloRWwLZF2jYn71UIoDgtuEc2rzg8fLbQegH+8oZ tehCvWWtfVw+r09Fm1AFiDd4rcwU099mI2i5hKHJw/4YuykQAIcHKv6omFL+Q0RmYwrs qbcyd/zCy0NKRctBz27hB0Gs7mOI+zAQ3gBZ/Tp027WzMXRaUuYonLQJn8PetClFjBCc CXJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=wRuxJY+MALIFLsOVdBU9Is7DSd8T6qQmTkCVw94Dqrc=; b=HOLUF1bd8GUoiZ0zIowR9hc0yuWMd+eMHA3NldZwlFumi93TJdujp2ctwgERqfNFGP yyzmh5u1+JY0beWR6QNqrIJLfPvxDtK13rb8EBB1Yx9NNLG9H/wAll9hTlf9AkDQe1R5 PelRljLBwvy8rs+3dVNykpKOeTreW0mbQ7Mmoc8Ib5y3Bif0BKwhHDr+OCtODIQukZ30 omXJZLqgQ75uoEkZn2ZzVRJ9kSkJNrzT0CQVQSwPkeofLRw4m50xWYvM74c90vcxZtoX UogeL1a6IWdu9jrfYuBOAvPz0nnmBux3kkn+G/BaeqtnuhZYY7sl7D9afAXvh6BaEjvp VGoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t75si17553539pfa.170.2019.01.22.22.57.45; Tue, 22 Jan 2019 22:58:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726811AbfAWG4I (ORCPT + 99 others); Wed, 23 Jan 2019 01:56:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36160 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726057AbfAWG4I (ORCPT ); Wed, 23 Jan 2019 01:56:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03CAB107AB; Wed, 23 Jan 2019 06:56:08 +0000 (UTC) Received: from [10.72.12.105] (ovpn-12-105.pek2.redhat.com [10.72.12.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7861F4519; Wed, 23 Jan 2019 06:56:03 +0000 (UTC) Subject: Re: [virtio-dev] [PATCH] virtio: support VIRTIO_F_ORDER_PLATFORM To: "Michael S. Tsirkin" Cc: Tiwei Bie , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, virtio-dev@lists.oasis-open.org References: <20190122170346.6279-1-tiwei.bie@intel.com> <20190122224203-mutt-send-email-mst@kernel.org> From: Jason Wang Message-ID: <7f07c837-d3d0-b5c0-9ecb-29b545b377c3@redhat.com> Date: Wed, 23 Jan 2019 14:56:00 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190122224203-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 23 Jan 2019 06:56:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/1/23 上午11:49, Michael S. Tsirkin wrote: > On Wed, Jan 23, 2019 at 11:08:04AM +0800, Jason Wang wrote: >> On 2019/1/23 上午1:03, Tiwei Bie wrote: >>> This patch introduces the support for VIRTIO_F_ORDER_PLATFORM. >>> When this feature is negotiated, driver will use the barriers >>> suitable for hardware devices. >>> >>> Signed-off-by: Tiwei Bie >>> --- >>> drivers/virtio/virtio_ring.c | 8 ++++++++ >>> include/uapi/linux/virtio_config.h | 6 ++++++ >>> 2 files changed, 14 insertions(+) >>> >>> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c >>> index cd7e755484e3..27d3f057493e 100644 >>> --- a/drivers/virtio/virtio_ring.c >>> +++ b/drivers/virtio/virtio_ring.c >>> @@ -1609,6 +1609,9 @@ static struct virtqueue *vring_create_virtqueue_packed( >>> !context; >>> vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX); >>> + if (virtio_has_feature(vdev, VIRTIO_F_ORDER_PLATFORM)) >>> + vq->weak_barriers = false; >>> + >>> vq->packed.ring_dma_addr = ring_dma_addr; >>> vq->packed.driver_event_dma_addr = driver_event_dma_addr; >>> vq->packed.device_event_dma_addr = device_event_dma_addr; >>> @@ -2079,6 +2082,9 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, >>> !context; >>> vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX); >>> + if (virtio_has_feature(vdev, VIRTIO_F_ORDER_PLATFORM)) >>> + vq->weak_barriers = false; >>> + >>> vq->split.queue_dma_addr = 0; >>> vq->split.queue_size_in_bytes = 0; >>> @@ -2213,6 +2219,8 @@ void vring_transport_features(struct virtio_device *vdev) >>> break; >>> case VIRTIO_F_RING_PACKED: >>> break; >>> + case VIRTIO_F_ORDER_PLATFORM: >>> + break; >>> default: >>> /* We don't understand this bit. */ >>> __virtio_clear_bit(vdev, i); >>> diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h >>> index 1196e1c1d4f6..ff8e7dc9d4dd 100644 >>> --- a/include/uapi/linux/virtio_config.h >>> +++ b/include/uapi/linux/virtio_config.h >>> @@ -78,6 +78,12 @@ >>> /* This feature indicates support for the packed virtqueue layout. */ >>> #define VIRTIO_F_RING_PACKED 34 >>> +/* >>> + * This feature indicates that memory accesses by the driver and the >>> + * device are ordered in a way described by the platform. >>> + */ >>> +#define VIRTIO_F_ORDER_PLATFORM 36 >>> + >>> /* >>> * Does the device support Single Root I/O Virtualization? >>> */ >> >> I wonder whether or not this is sufficient. Is dma barrier implies a mmio >> barrier? Looks not. > IIUC we don't need an mmio barrier because we are using a > serializing API: Documentation/memory-barriers.txt says: > > Note that, when using writel(), a prior > wmb() is not needed to guarantee that the cache coherent memory writes > have completed before writing to the MMIO region. Ah, I get this. > > >> See ia64/include/asm/barrier.h: >> >>  * Note: "mb()" and its variants cannot be used as a fence to order >>  * accesses to memory mapped I/O registers.  For that, mf.a needs to >>  * be used.  However, we don't want to always use mf.a because (a) >>  * it's (presumably) much slower than mf and (b) mf.a is supported for >>  * sequential memory pages only. >>  */ >> #define mb()            ia64_mf() >> #define rmb()           mb() >> #define wmb()           mb() >> >> #define dma_rmb()       mb() >> =>efine dma_wmb()       mb() >> >> Thanks > Frankly no idea about ia64. Neither did me. > Sorry. Are any less esoteric platforms > affected? > E.g ppc64? define dma_wmb()       __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memo\ ry") /*  * Enforce synchronisation of stores vs. spin_unlock  * (this does it explicitly, though our implementation of spin_unlock  * does it implicitely too)  */ static inline void mmiowb(void) {         unsigned long tmp;         __asm__ __volatile__("sync; li %0,0; stb %0,%1(13)"         : "=&r" (tmp) : "i" (offsetof(struct paca_struct, io_sync))         : "memory"); } dma_wmb() is lwsync which is more lightweight than sync I guess? Thanks