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 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E88B9C433EF for ; Wed, 15 Jun 2022 10:14:08 +0000 (UTC) Received: from localhost ([::1]:41780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1Q2I-00083r-Ob for qemu-devel@archiver.kernel.org; Wed, 15 Jun 2022 06:14:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1Q0J-0006Ku-Qy for qemu-devel@nongnu.org; Wed, 15 Jun 2022 06:12:04 -0400 Received: from ssh.movementarian.org ([139.162.205.133]:47102 helo=movementarian.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1Q0D-00067O-Rv for qemu-devel@nongnu.org; Wed, 15 Jun 2022 06:12:02 -0400 Received: from movement by movementarian.org with local (Exim 4.94.2) (envelope-from ) id 1o1Q07-001Jlt-Ij; Wed, 15 Jun 2022 11:11:51 +0100 Date: Wed, 15 Jun 2022 11:11:51 +0100 From: John Levon To: Klaus Jensen Cc: Keith Busch , Jinhao Fan , qemu-devel@nongnu.org Subject: Re: [PATCH 1/2] hw/nvme: Implement shadow doorbell buffer support Message-ID: References: <0CC03CA7-1BC5-4FDF-92BA-4256778AD113@ict.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://www.movementarian.org/ Received-SPF: pass client-ip=139.162.205.133; envelope-from=movement@movementarian.org; helo=movementarian.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Wed, Jun 15, 2022 at 11:33:02AM +0200, Klaus Jensen wrote: > > BTW I'm surprised that this patch has just this: > > > > +static void nvme_update_sq_eventidx(const NvmeSQueue *sq) > > +{ > > + pci_dma_write(&sq->ctrl->parent_obj, sq->ei_addr, &sq->tail, > > + sizeof(sq->tail)); > > +} > > > > Isn't this racy against the driver? Compare > > https://github.com/spdk/spdk/blob/master/lib/nvmf/vfio_user.c#L1317 > > > > thanks > > john > > QEMU has full memory barriers on dma read/write, so I believe this is > safe? But don't you need to re-read the tail still, for example: driver device eventidx is 3 write 4 to tail read tail of 4 write 5 to tail read eventidx of 3 nvme_dbbuf_need_event (1) set eventidx to 4 go to sleep at (1), our tail update of 4->5 doesn't straddle the eventidx, so we don't send any MMIO, and the device won't wake up. This is why the above code checks the tail twice for any concurrent update. regards john