Received: by 10.223.185.116 with SMTP id b49csp3685574wrg; Tue, 13 Feb 2018 06:15:35 -0800 (PST) X-Google-Smtp-Source: AH8x2254axdCGC6cY7OaKA9+M+o7lhvC8ES0DYa2WfuwD34LQfLRtcKS/Yv4a7Pd0sd3pp2biwjO X-Received: by 2002:a17:902:8f86:: with SMTP id z6-v6mr1265194plo.352.1518531335520; Tue, 13 Feb 2018 06:15:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518531335; cv=none; d=google.com; s=arc-20160816; b=YN7Kq+NSNoEAXqPCvyC0Y6ycg7asrPe2IbRDQ1AsBpe0b+el/CquqSGj+fGSu9VwUC HUPczZ37ZqBawI7MKBS0xniBKIbM7JX98Om/VThGUc0aLmpbTXRAArFSwBlwbosU2Vgp ZIlcwB8HLkVctTAvDQnn6oknStgsI0Hqwi27dNrNjOHD1bQQgVJSTWQCRsR0U1yHdZKX wOPjHsgU+75HEs3Vn1W3e/lQsQB7qAEbVyAv5GTjduK9KGpOypidfGjTbfbfYFZeAA/5 lVCelbXLx2oa9Fh5psA9MV/feQSQfxDRperYySXQG3ud6h1xyjE08UwTrlU7FIsW1Hr4 WxpA== 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=Px1bmh0xlIIfltsjnFl+qa3LO14BeJmnBVBblNohl9o=; b=eGUUm36moC4+ra06/Fs0J1/MsFoJH+CO3lEeyV9BZ1mh5X+RH8HzI3BPzTkmyRwfmv fmGg5feyh5zmH8wl+gBtWC50eXY7yVsQYy890NP8aqn5+YSdaGOva1gjOZhznWqaA/RC cPLhrFGweahgCjZmYmf0lYNp519UWeufXkqfr1wk2pzvMOJWa5zrri/oSEbqEIfso/gO mAcV5hgB3sg42w0zZT6tPnif/44mQ1P9aYKe28nCKzVLGsFzuybVa/xXtY0oKs/1cZ1B f+KsWB4QPf/5gy0Jo3Hn4S2qA+N1GKCq9wctc9bM2DaY4huXn5lBNBsY88H/vamY+K6W L9Ew== 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 e9-v6si5827042pli.474.2018.02.13.06.15.20; Tue, 13 Feb 2018 06:15:35 -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 S965087AbeBMOOF (ORCPT + 99 others); Tue, 13 Feb 2018 09:14:05 -0500 Received: from mail-qk0-f195.google.com ([209.85.220.195]:36401 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964935AbeBMOOE (ORCPT ); Tue, 13 Feb 2018 09:14:04 -0500 Received: by mail-qk0-f195.google.com with SMTP id 15so22590548qkl.3 for ; Tue, 13 Feb 2018 06:14:04 -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=Px1bmh0xlIIfltsjnFl+qa3LO14BeJmnBVBblNohl9o=; b=QbeciBIoP4PbMKy8Poae4uaNOjIoZIBSiKZT6PLZGL30zmExhuPXZHypt78/yfdGl2 v4F8nSvKm46AvtLqvmQ0rnrK+2LUS/kYoHGY+fo/PNT5u+vC9tIy1cK8Mk8UEAZyE3mY C4Xs6d/rAnGrJyfVmfWEljppgBBAakrwRMa0snZt+7fii/Ndk6Qe51MLJ6MJ8Uq/YZ6K Ukfrbm2Mf/8drhzC0dTmkIUwaeKaNtGB51VzqhfC1MtBb0+O5FfK2Tz5IzY3Qz97VNZo 0bWtnff0/WgIcK40EU7XEc/8LifypheMu39wnxRLCdu9iKn0cmEDpzkh0bqGJX3U4ue/ YPyA== X-Gm-Message-State: APf1xPAc15hxJ120Emf3E3bhV5yzq1WOVIUHEz9Fnt62E+lwSy9ZLm6H sWYBMgvN5/gGiMVpC7LrZL9wPEXAccE+CVlqckGhMMVE X-Received: by 10.55.13.206 with SMTP id 197mr2062909qkn.115.1518531243844; Tue, 13 Feb 2018 06:14:03 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.146.213 with HTTP; Tue, 13 Feb 2018 06:14:03 -0800 (PST) In-Reply-To: <20180212160849-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> From: Marc-Andre Lureau Date: Tue, 13 Feb 2018 15:14:03 +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 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; } > > >> > >> >> +} >> >> + >> >> +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