Received: by 10.223.185.116 with SMTP id b49csp3702015wrg; Tue, 13 Feb 2018 06:30:22 -0800 (PST) X-Google-Smtp-Source: AH8x226hRQJVinzKIX9vSGbUtPqQ1sx9vs7gSAq4cWsrp3zJxTKwyDlyf9lgg5DRPPK98g00h1tD X-Received: by 10.99.115.4 with SMTP id o4mr1138462pgc.206.1518532222436; Tue, 13 Feb 2018 06:30:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518532222; cv=none; d=google.com; s=arc-20160816; b=0ob1DDshx8/AvD8grY+9iprbYppEsteNPQEWbBdaELJ5tuswXaMbVmTS/GcYILz+Ln qq7W4MkVN+0lzAtYvel5B426bsf4G5kKQAzVfn8iqobelr96uZ/ZdviZET6P7ZcdJ+fp 1/9XmPfbDeFC46UaG28gisclIGFFEBEQrii9Yi3y9HmGMif19n7KUZ16QQ5N+y1y7rjU OGVFF7ILTsocbYyzw0SSmJeDHJVk5W+jGzaBNXbpoSTllU+kuyzZNEhNv/B9uMTIg4Kr 1uG/Je9UJqcO5merlmiuESo87nEP18z0yavzWS4DEWi4FtktQDRorqfTkEagQXTflZyh fv7w== 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=kdUN7iu7IpJ7vB6Z0YY6/XA4N0q+6zXQhkzmvft8+lY=; b=F+TUZ019tuglTCOxRlL79yioWAQiumPx5hzAywmpqWXgtoV6z3pGSC9zCqbN8JJPDf J58/VKVpCH+VoECpzVrJXL8aB3wBWvRw2U5cDB3BadMvqBT0JY69NOMgDQMRXfyozIJF 25CzdO/MaTrdfDTfj7VwMX/Ib1f+gUzM67XGv1dtWxEscw2mIdeaSpShLOmBmRS1LDMg sGwr+F69UuCr1C2Qu2TE6c8QuEkIgdWpEPz7N/jLryRv6oxzbsyOu3LA0lriztpz31Ui 2+XrxnXO77++RthotjEFeorzCmW2Juh4PSy2w1cFYLD456/WDM3f5spqgPMGRvvHcLcY 5Edw== 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 a28si2895872pfl.54.2018.02.13.06.30.06; Tue, 13 Feb 2018 06:30:22 -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 S935324AbeBMO1x (ORCPT + 99 others); Tue, 13 Feb 2018 09:27:53 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59186 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933612AbeBMO1w (ORCPT ); Tue, 13 Feb 2018 09:27:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E38EEAEB0; Tue, 13 Feb 2018 14:27:52 +0000 (UTC) Received: from redhat.com (ovpn-122-62.rdu2.redhat.com [10.10.122.62]) by smtp.corp.redhat.com (Postfix) with SMTP id 0B91C42223; Tue, 13 Feb 2018 14:27:46 +0000 (UTC) Date: Tue, 13 Feb 2018 16:27:46 +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: <20180213162038-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> 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.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 14:27:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 14:27:52 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 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. > > > > > >> > > >> >> +} > >> >> + > >> >> +static ssize_t fw_cfg_dma_transfer(void *address, u32 length, u32 control) > >> >> +{ > >> >> + phys_addr_t dma; > >> >> + struct fw_cfg_dma *d = NULL; > >> >> + ssize_t ret = length; > >> >> + > >> >> + d = kmalloc(sizeof(*d), GFP_KERNEL); > >> >> + if (!d) { > >> >> + ret = -ENOMEM; > >> >> + goto end; > >> >> + } > >> >> + > >> >> + *d = (struct fw_cfg_dma) { > >> >> + .address = address ? cpu_to_be64(virt_to_phys(address)) : 0, > >> >> + .length = cpu_to_be32(length), > >> >> + .control = cpu_to_be32(control) > >> >> + }; > >> >> + > >> >> + dma = virt_to_phys(d); > >> > > >> > Pls add docs on why this DMA bypasses the DMA API. > >> > >> Peter said in his patch: "fw_cfg device does not need IOMMU > >> protection, so use physical addresses > >> always. That's how QEMU implements fw_cfg. Otherwise we'll see call > >> traces during boot." > >> > >> Is that enough justification? > > > > what are the reasons for the traces exactly though? > > some kind of explanation should go into comments, and > > I think it should be a bit more detailed than just "it doesn't > > work otherwise". > > > > I can use Peter help here. My understanding is because the qemu fw-cfg > device doesn't go through iommu when doing DMA op. Whether it should > or could, I can't answer. > > thanks