Received: by 10.223.185.116 with SMTP id b49csp3776589wrg; Tue, 13 Feb 2018 07:36:34 -0800 (PST) X-Google-Smtp-Source: AH8x224CrTqxGkgfLe1hMM9H0S2g01jLvkTRFIll9HzvprS9ORE0UXN4hgjH6tFlO0BknyrskyOA X-Received: by 2002:a17:902:6b89:: with SMTP id p9-v6mr1475890plk.377.1518536193860; Tue, 13 Feb 2018 07:36:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518536193; cv=none; d=google.com; s=arc-20160816; b=S7H1u99fFlQ2oySH2BgsOuGxUzBPHIIUUPqX7sGeUx5frLb9f/6OP6vA8WDDVd2KZq RF0dRZT6ckTWhhq+e+7JH9Tw9jPcyjOR2jVHxtBYqLqxRbx4MFuQMPvx9QAKRKe1DGjC P7VPvg/rq9+/Oi7GBSDyELM/2ZfYMvSMLjcyP7qSJNmoWG/BhTPQVMV9O8zAzPEsy7nz PQw8Mv9EM66cjp3VWIkI1eQkLxfZ5gdrV/+ssjNmlEthsxGy2IiWfGu5T6CNzT8TjWzb g4srH0mqHUyPSNWL9/DeI3jIT4+jWvZ3VWHICcmPxAntu/QkrQ2FJSOy+tKNmeIy8c5b Gi4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:arc-authentication-results; bh=ICBjR1nM0oQD7LEUdcMq9eiTkColiWy5fXpbAarhqs0=; b=B3aTdMxRXgc9iTuUxydv8pMbkLEl4+LNsqGk22LKI9nI/9376xLJQQbU2LQY3DGSKc w8nOOIo0IuSKVm4Cj7FtXIsvM2c7knB7TbYFVgy66OA9XyZCxQANMuwOdv12VR1KXFge +lqheyiFA5zsydqdNXJHqXK2pZz85zfnEX0C7hHAdMOW2YfzPV+Mtyngfoq+gz9MopMp essN8RZPIyhPBpOGfWMf0FM8l255Hm6QzcP3IaM2PeniJOOU5CG+RP/9BD9/m/6PBgfb 7L+TUNfyvbO1v2pKWPGyQwlI6CC1+XZe6/UWFeS1dQf3H/fyWvUBrnQYACb2eLgt+gmY ffeg== 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 72-v6si5717574ple.299.2018.02.13.07.36.19; Tue, 13 Feb 2018 07:36:33 -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 S933764AbeBMPff (ORCPT + 99 others); Tue, 13 Feb 2018 10:35:35 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:36101 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933442AbeBMPfd (ORCPT ); Tue, 13 Feb 2018 10:35:33 -0500 Received: by mail-qk0-f196.google.com with SMTP id 15so22907263qkl.3 for ; Tue, 13 Feb 2018 07:35:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ICBjR1nM0oQD7LEUdcMq9eiTkColiWy5fXpbAarhqs0=; b=EtU0uMBdvf4dulYI4lne7yIXMSYjkJU7srJ90H4+OnSr6lOMGk1PzQcNNaGPbtDKmR swUkadskXJ1ju4v+0HWgmWX42/tOacnCDf0Z0ov1b+Lkf0Dt448nE0rXALSbqSgh1dNc cydVVle6E4qUm3Sgccj0Jpk2GxjD8NoAfQP9833P+aHYXnRdgUUa1mfMIpO25lYFqgcG w0cZDS0LgxY6XIUjhL+kHTqz8jKnD89XitdRkHH6QeJfyJh8B6pSh9rXItTHS2vFOwIa ogO3xOFmpuDKk0QtuYr2stNZw9z5DQfWRr1NjcoZZI9QHfacXSMbHleZVIEW8OpPULNU fD4A== X-Gm-Message-State: APf1xPBBwMzOjHPABfqqqG+Gp1MzxkeqrFBcWrTOKTt8suWxXOqp2rXJ VYQLmNfB69yRYclAN3UyfnYd3QlL4/dTuSSFP9+Vow== X-Received: by 10.55.220.197 with SMTP id v188mr2468260qki.147.1518536132387; Tue, 13 Feb 2018 07:35:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.146.213 with HTTP; Tue, 13 Feb 2018 07:35:32 -0800 (PST) In-Reply-To: <20180213171647-mutt-send-email-mst@kernel.org> References: <20180207013525.1634-1-marcandre.lureau@redhat.com> <20180207013525.1634-4-marcandre.lureau@redhat.com> <20180212053104-mutt-send-email-mst@kernel.org> <20180212160849-mutt-send-email-mst@kernel.org> <20180213162038-mutt-send-email-mst@kernel.org> <20180213171647-mutt-send-email-mst@kernel.org> From: Marc-Andre Lureau Date: Tue, 13 Feb 2018 16:35:32 +0100 Message-ID: Subject: Re: [PATCH v13 3/4] fw_cfg: write vmcoreinfo details To: "Michael S. Tsirkin" Cc: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= , Linux Kernel Mailing List , Sergio Lopez Pascual , Baoquan He , "Somlo, Gabriel" , xiaolong.ye@intel.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 13, 2018 at 4:19 PM, Michael S. Tsirkin wrote: > On Tue, Feb 13, 2018 at 04:16:08PM +0100, Marc-Andre Lureau wrote: >> Hi >> >> On Tue, Feb 13, 2018 at 3:27 PM, Michael S. Tsirkin wrote: >> > On Tue, Feb 13, 2018 at 03:14:03PM +0100, Marc-Andre Lureau wrote: >> >> Hi >> >> >> >> On Mon, Feb 12, 2018 at 10:00 PM, Michael S. Tsirkin wrote: >> >> > On Mon, Feb 12, 2018 at 11:04:49AM +0100, Marc-Andre Lureau wrote: >> >> >> >> +} >> >> >> >> + >> >> >> >> +/* qemu fw_cfg device is sync today, but spec says it may become async */ >> >> >> >> +static void fw_cfg_wait_for_control(struct fw_cfg_dma *d) >> >> >> >> +{ >> >> >> >> + do { >> >> >> >> + u32 ctrl = be32_to_cpu(READ_ONCE(d->control)); >> >> >> >> + >> >> >> >> + if ((ctrl & ~FW_CFG_DMA_CTL_ERROR) == 0) >> >> >> >> + return; >> >> >> >> + >> >> >> >> + usleep_range(50, 100); >> >> >> >> + } while (true); >> >> >> > >> >> >> > And you need an smp rmb here. >> >> > >> >> > I'd just do rmb() in fact. >> >> > >> >> >> Could you explain? thanks >> >> > >> >> > See Documentation/memory-barriers.txt >> >> > You know that control is valid, but following read of >> >> > the structure could be reordered. So you need that barrier there. >> >> > Same for write: wmb. >> >> >> >> Is this ok? >> >> @@ -103,10 +104,14 @@ static ssize_t fw_cfg_dma_transfer(void >> >> *address, u32 length, u32 control) >> >> dma = virt_to_phys(d); >> >> >> >> iowrite32be((u64)dma >> 32, fw_cfg_reg_dma); >> >> + /* force memory to sync before notifying device via MMIO */ >> >> + wmb(); >> >> iowrite32be(dma, fw_cfg_reg_dma + 4); >> >> >> >> fw_cfg_wait_for_control(d); >> >> >> >> + /* do not reorder the read to d->control */ >> >> + rmb(); >> >> if (be32_to_cpu(READ_ONCE(d->control)) & FW_CFG_DMA_CTL_ERROR) { >> >> ret = -EIO; >> >> } >> > >> > I think you need an rmb after the read of d->control. >> > >> >> >> There are two reads of d->control, one in fw_cfg_wait_for_control() to >> wait for completion, and the other one here to handle error. Do you >> mean that for clarity rmb() should be moved at the end of >> fw_cfg_wait_for_control() instead? >> >> thanks > > > IMHO that's a reasonable way to do it, yes. > OTOH is looking at DMA data the only way to detect DMA is complete? > Isn't there an IO register for that? That's the only thing that indicate completion it seems: https://git.qemu.org/?p=qemu.git;a=blob;f=hw/nvram/fw_cfg.c;hb=HEAD#l389 The spec doesn't describe other ways either: https://git.qemu.org/?p=qemu.git;a=blob;f=docs/specs/fw_cfg.txt