Received: by 10.223.185.116 with SMTP id b49csp3759209wrg; Tue, 13 Feb 2018 07:21:01 -0800 (PST) X-Google-Smtp-Source: AH8x224VBXSiyAD9q13jnoKsDx1bIrHyMJGIUmh2LP/SIo9QgTH2jxo2TZnoDvpq0UPdMNnE8rkg X-Received: by 2002:a17:902:4601:: with SMTP id o1-v6mr1437602pld.210.1518535261416; Tue, 13 Feb 2018 07:21:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518535261; cv=none; d=google.com; s=arc-20160816; b=ATOEXltnF1T4w7jBqTE1OjvIJjdqTkAGzpQR5QWmxPL6BK5QneFjBVOUAckkeBYNUr hr7JGjst349frlerL2K96NR6KTbhWItuSmKpkPe4wKvpzm7UJPE9GrbCAVqSTej+rHY3 84s0JVCwbX0MUVhYFlm4GJ2xjpJd3Ewfj5yOJBdkHWRk3xI1CRdsx+okau8lzXpY2UIl p/hRBCDPK2EBe+3oZaNQGCIlfezZ9P7zxkStsnMAAy+859+hbhkLF46EQwBXdpwJ2Fqb 53FnTd3MtmMP6qTU+J3xDB5CjKDBKLCm3RNKZpipK1qeRnCTAyWa2ouPGes1KqJf8HuZ u08A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=c9+ze9RruslxDrGfr//7q8ocYYLwZVzp4+YD5j2VaQs=; b=sC84aggosCENVrUiZ+Ha3t3Wk2hWU6mVX0kmpq9HTP16tOzG8Yb5sWzXVOro6GyoVz 9by20fN2br2/Z6xo099DkVNDqipwVqZia0RPQgmb7HnUNv1BBee5WepljBFDQ8jFAuDs Kb1HuNVyoSzqIZH3xe97bhN52yGHwEYuzmc47de8vY5kqvZQbOcGXRnhJQqcZQaNCJxP FcsELLsJ1WqkTROhq6Mm186MC+mW6hF9bRcSPKdzX9YfBfAs/iBll4JWEMkvnQBrZFUO XZ/WNsxmHA4u7va6rc8b6okjY6ccZvj1KKC4iEdQ4ROe8vnvCJ5hMA0ckExS++MpKOH0 2WSg== 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 t77si1739413pfi.382.2018.02.13.07.20.46; Tue, 13 Feb 2018 07:21:01 -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 S965034AbeBMPTb (ORCPT + 99 others); Tue, 13 Feb 2018 10:19:31 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33016 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965000AbeBMPTa (ORCPT ); Tue, 13 Feb 2018 10:19:30 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1828FB649; Tue, 13 Feb 2018 15:19:29 +0000 (UTC) Received: from redhat.com (ovpn-125-92.rdu2.redhat.com [10.10.125.92]) by smtp.corp.redhat.com (Postfix) with SMTP id 7CB18215671B; Tue, 13 Feb 2018 15:19:28 +0000 (UTC) Date: Tue, 13 Feb 2018 17:19:28 +0200 From: "Michael S. Tsirkin" To: Marc-Andre Lureau Cc: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Linux Kernel Mailing List , Sergio Lopez Pascual , Baoquan He , "Somlo, Gabriel" , xiaolong.ye@intel.com Subject: Re: [PATCH v13 3/4] fw_cfg: write vmcoreinfo details Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 15:19:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 15:19:29 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' 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 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?