netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: fei phung <feiphung27@gmail.com>
Cc: feiphung@hotmail.com, netdev@vger.kernel.org
Subject: Re: Question on ptr_ring linux header
Date: Fri, 1 Feb 2019 10:36:00 -0500	[thread overview]
Message-ID: <20190201102519-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <CAF8QhUgBEy7F1kTp=0w4e7+U1d2vSkrJfHAnTLEw5Yjz8KLyoA@mail.gmail.com>

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

  reply	other threads:[~2019-02-01 15:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17  3:51 Question on ptr_ring linux header fei phung
2019-01-31  5:16 ` fei phung
2019-01-31 14:39   ` Michael S. Tsirkin
2019-02-01  8:12     ` fei phung
2019-02-01 15:36       ` Michael S. Tsirkin [this message]
2019-02-15  3:03         ` fei phung
2019-03-01  3:20           ` fei phung
  -- strict thread matches above, loose matches on Subject: below --
2019-01-16  7:00 fei phung
2019-01-15 17:10 fei phung
2019-01-15 18:13 ` Michael S. Tsirkin
     [not found]   ` <SG2PR06MB3176FA4C12888C84990F109BC1820@SG2PR06MB3176.apcprd06.prod.outlook.com>
2019-01-16 14:09     ` Michael S. Tsirkin
2019-01-15  4:33 fei phung
2019-01-15 12:48 ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190201102519-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=feiphung27@gmail.com \
    --cc=feiphung@hotmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).