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 X-Spam-Level: X-Spam-Status: No, score=-7.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF6B1C4338F for ; Sat, 31 Jul 2021 15:42:08 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0B7ED60F46 for ; Sat, 31 Jul 2021 15:42:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0B7ED60F46 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=me.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:34770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9r7m-0003zv-Ph for qemu-devel@archiver.kernel.org; Sat, 31 Jul 2021 11:42:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9r78-0003KG-9I for qemu-devel@nongnu.org; Sat, 31 Jul 2021 11:41:26 -0400 Received: from pv34p98im-ztdg02172101.me.com ([17.143.234.142]:56597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9r76-0005uF-O8 for qemu-devel@nongnu.org; Sat, 31 Jul 2021 11:41:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1627746078; bh=31N1n9LDYN9v8O9cW+bYHTEiBlg9kNEUFPw10SV46Ag=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:To; b=L2NW/lwJlh/qdnQYoMKEv1YcHbafefWHS5jbYLbelImYdX2ZoBzL8c4mNS7bjlMr2 xJklueGVl1cTetgyKcEQt1141Vqe5+LFy8+Zh6eAuPkHK9ix/McHfSY2mo7i4JG/mM snbXFaVoewDYWFKAej5vcgJ29yC8QzRsYZCisXYpTlD9lRGBEuYIaxNXpDcQkAPGgt MWU1etTMsslgtNOOtQHVwpxUMk76Um1rRuN5thgtgtF5Lp4QS2kdWQerTCf7xyTftb MoseB9drKQJVFQz4IDsarAe+GQy5UFuu3nX17PgN+gFDHFhqu5W7ADjS+78aUwHMOU KILzon3TKQI/Q== Received: from smtpclient.apple (c-67-180-181-196.hsd1.ca.comcast.net [67.180.181.196]) by pv34p98im-ztdg02172101.me.com (Postfix) with ESMTPSA id 125615400D9 for ; Sat, 31 Jul 2021 15:41:17 +0000 (UTC) From: Jason Thorpe Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3690.0.1\)) Subject: Please help me understand VIRTIO_F_IOMMU_PLATFORM Message-Id: Date: Sat, 31 Jul 2021 08:41:17 -0700 To: qemu-devel@nongnu.org X-Mailer: Apple Mail (2.3690.0.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-31_05:2021-07-30, 2021-07-31 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=317 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2009150000 definitions=main-2107310088 Received-SPF: pass client-ip=17.143.234.142; envelope-from=thorpej@me.com; helo=pv34p98im-ztdg02172101.me.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Hey folks =E2=80=94 I=E2=80=99d like to be able to use VirtIO with qemu-system-alpha but, at = least on a NetBSD x86_64 host, it does not currently work. This is = because virtio_bus_device_plugged() in hw/virtio/virtio-bus.c ends up = picking address_space_memory as the DMA address space for the = VirtIODevice. This does not work for alpha because the CPU and PCI have = different views of system memory. All that=E2=80=99s needed to fix it = is for virtio_bus_device_plugged() to call = klass->get_dma_as(qbus->parent), but the code only does that if: bool has_iommu =3D virtio_host_has_feature(vdev, = VIRTIO_F_IOMMU_PLATFORM);=20 So, obviously, VIRTIO_F_IOMMU_PLATFORM is not getting set for an = emulated alpha system, despite the alpha platform having one[*]. But = it=E2=80=99s not clear to me that it=E2=80=99s appropriate for alpha to = use VIRTIO_F_IOMMU_PLATFORM, at least from my reading of how it=E2=80=99s = used. In any case, the following extremely simple change allows me to use = VirtIO devices in qemu-system-alpha with a NetBSD/alpha guest (and I=E2=80= =99m told this also fixes using VirtIO devices in qemu-system-sparc64 = for a NetBSD/sparc64 guest): diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 859978d248..c083e8d737 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -85,6 +85,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, = Error **errp) if (klass->get_dma_as !=3D NULL && has_iommu) { virtio_add_feature(&vdev->host_features, = VIRTIO_F_IOMMU_PLATFORM); vdev->dma_as =3D klass->get_dma_as(qbus->parent); + } else if (klass->get_dma_as !=3D NULL) { + vdev->dma_as =3D klass->get_dma_as(qbus->parent); } else { vdev->dma_as =3D &address_space_memory; } So, VirtIO experts, please weigh in on the correctness of this change=E2=80= =A6 if it is, I=E2=80=99ll post the patch formally. [*] The way the alpha platform works is that the IOMMU is used if the = PCI device performs a memory access to a DMA window where SGMAPs are = enabled. If SGMAPs are not enabled in the DMA window the PCI device is = accessing, the translation is performed directly by subtracting the = address from the window=E2=80=99s Window Base and appending the result = to the window=E2=80=99s Translated Base. A typical alpha PCI platform = has a 1GB DMA window at 1GB from the PCI=E2=80=99s perspective, which = maps to 0-1GB in the system address map, and an alpha system with 1GB or = less of RAM would thus not need to use the IOMMU, but the translation = take place regardless. -- thorpej