From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C89E3C282D8 for ; Fri, 1 Feb 2019 15:36:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D7F1218EA for ; Fri, 1 Feb 2019 15:36:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730174AbfBAPgB (ORCPT ); Fri, 1 Feb 2019 10:36:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58188 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729867AbfBAPgB (ORCPT ); Fri, 1 Feb 2019 10:36:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39B8CC03D47D; Fri, 1 Feb 2019 15:36:01 +0000 (UTC) Received: from redhat.com (ovpn-124-68.rdu2.redhat.com [10.10.124.68]) by smtp.corp.redhat.com (Postfix) with SMTP id 9B5D560C55; Fri, 1 Feb 2019 15:36:00 +0000 (UTC) Date: Fri, 1 Feb 2019 10:36:00 -0500 From: "Michael S. Tsirkin" To: fei phung Cc: feiphung@hotmail.com, netdev@vger.kernel.org Subject: Re: Question on ptr_ring linux header Message-ID: <20190201102519-mutt-send-email-mst@kernel.org> References: <20190131093342-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 01 Feb 2019 15:36:01 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, Feb 01, 2019 at 04:12:46PM +0800, fei phung wrote: > > I am not sure what does assignment of pointers mean in this context. > > ptr_ring is designed for a single producer and a single consumer. For > > why it works see explanation about data dependencies in > > Documentation/memory-barriers.txt. You will have to be more specific > > about the data race that you see if you expect more specific answers. > > Hi, > > ptr_ring_produce_any(sc->recv[chnl]->msgs, > &item_recv_push[item_recv_push_index]) needs to have > non-NULL pointer assigned for item_recv_push[item_recv_push_index] , right ? No that's irrelevant. If your item_recv_push_index isn't getting out of bounds then &item_recv_push[item_recv_push_index] won't be NULL and that's all ptr_ring cares about. > Note: > ptr_ring_produce_any() occurs in interrupt handler, while > ptr_ring_consume_any() occurs in thread. > > https://gist.github.com/promach/7716ee8addcaa33fda140d74d1ad94d6/cdc6599b8313e265bdfb073a65a124e1ba3303a2#file-riffa_driver_ptr_ring-c-L306-L320 > > // TX (PC receive) scatter gather buffer is read. > if (vect & (1<<((5*i)+1))) { > recv = 1; > > item_recv_push[item_recv_push_index].val1 = EVENT_SG_BUF_READ; > item_recv_push[item_recv_push_index].val2 = 0; > > // Keep track so the thread can handle this. > if (ptr_ring_produce_any(sc->recv[chnl]->msgs, > &item_recv_push[item_recv_push_index])) { > printk(KERN_ERR "riffa: fpga:%d chnl:%d, recv sg buf > read msg queue full\n", sc->id, chnl); > } > DEBUG_MSG(KERN_INFO "riffa: fpga:%d chnl:%d, recv sg buf > read\n", sc->id, chnl); > > item_recv_push_index++; > } > > > The kernel log points me to ptr_ring_consume_any(). So, this is > definitely data race issue > with my own ptr_ring interfacing code. > > besides, I am also getting a reference to zero-length ring for the > kernel dmesg log. > I am not sure how this is related to the data race though. > > The kernel log points to > https://github.com/torvalds/linux/blame/master/include/linux/ptr_ring.h#L175 > (click open git blame on this line) > > Regards, > Phung Sorry I'm not sure what you are trying to say here. If I had to guess I'd say the way you play with indices is probably racy so you are producing an invalid index. -- MST