From patchwork Fri Aug 21 16:28:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 248132 Delivered-To: patch@linaro.org Received: by 2002:a54:3b12:0:0:0:0:0 with SMTP id j18csp447423ect; Fri, 21 Aug 2020 09:31:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDWQu+XGECq09ZEtJP9nRzb6VMwGUZj4ye5oowcNU9blxUdi7BPl9IUpXPynaf0XUWsOwt X-Received: by 2002:aa7:9552:: with SMTP id w18mr3140359pfq.150.1598027505338; Fri, 21 Aug 2020 09:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598027505; cv=none; d=google.com; s=arc-20160816; b=eHGz3MvW0vKVsk3qHHwYlVV2ZSJIKqnG/VHbx+7Yow+c1z76Bou+nzbM9NAywMrAl4 GNWF/izntfi6/Ma3B7Tk/9qZjZVjo3hj4BQ6pculAfddHcgI3p6RbA64TlT0zR46oNXq 7RchorHlCMdqkuvDBlBd3BaXNHhcqQHe0GDGIFBHUAHDeSU9qf9x3cFlsqNqFC5jKvcp KqMFFuKo0HVrZXq6qk1I8lUIn2F0RyxK6vBcEuaA4EGDz6ifTH+FdE6oBTjJe5L0D7pe 7rmb9g56nb27EtkJj5VtqEfaFvVFh7AWBe9GIszhoDRsZtrWHJF+p7JTo2km2f096SHL phXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=OuI8xnJndStSpo+ETjU3EU4hq5mCXR/FiYpus8sMWls=; b=uej/N1ZPfKL5CtqaN+e9Ej9VrAgRcIjm+OKt6uKKeUWQeUe33WmaYtNTvo3cyrlOB3 Al+OrH3LjfcyUF5pWaEpGuFX7vyYFiCbmIRoAUXCVK/DMTsICXVV7zeGg5l2vt9FOui7 C518eMydeyVGuDaUbEM5RSzwaBGU0VOjf/SFo1Y9Ja/RsvXQZUrg3uQ7U3VxiU7PL5Em upIgGyva6ls1lWCevNTOr5YvLylXFk8mEL0fDlSXO1hqqcEBSQD6wfgyQZnQDvf7mLIM bMtx411LVF0aXq02q5XDtEqkzer+RdQsMYSKV1JcUEnCtn/nkEgaONeg0rEnpsBxGt3N J1jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="RtBd0+/t"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x19si1873928plr.213.2020.08.21.09.31.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Aug 2020 09:31:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="RtBd0+/t"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k99x8-0008Je-VC for patch@linaro.org; Fri, 21 Aug 2020 12:31:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k99vx-0007tc-Rp for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:30 -0400 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]:32796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k99vt-0006na-KE for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:29 -0400 Received: by mail-ej1-x644.google.com with SMTP id u21so2335586ejz.0 for ; Fri, 21 Aug 2020 09:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OuI8xnJndStSpo+ETjU3EU4hq5mCXR/FiYpus8sMWls=; b=RtBd0+/tA0QB1kHWt9+BsloshL2hCQZsnr/oWm+0HJJVwqLPFyn6AT+SofxvLmuImX PsAfS3QcpNvxXPTTMzY3cg6GuW96O0nt20YxLWuOGab+e7ycvFO3onzdsygv0zXeSGCm gYk+MvS8rqcGAYFuVDwVYaUqZk7juHUkq9QcyCJc/eXlChsskoDjukYCLbfPuTNafalP QDS9V8yzFoUdYxgtAC7XBfW5fVgxkgfXSNcj86Ohb4gMrHsqlCCf0qhOsxs6Lr3MgLT4 cfYA588+j0y5p9YHHNgRaceedtGSBwmhCMKDLafRTMjagMg3ykvVBSqTwK/dVu4jpvJe a1rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OuI8xnJndStSpo+ETjU3EU4hq5mCXR/FiYpus8sMWls=; b=g7gt+i2CVTcVEBdcaLTOciHqx772YhugYi5iJGHkeAv/TIeA8apiy/tlEwK3dRew31 CulBLMaaVYPi3YB9om0gjl4Ty7/vmjjc7vEgVPd6AH/vgrws9r5kVnzbd3f9c7/OFlgT YxJZB2GCGwrxBiJs8V6zhV7SsYuX4MHVKRNnyOJ0PLIHhvhgAcZsm51fy/mtoSvKr3L6 wZoLWnJv1pMtcG8mFpDtdGvdmmqYmONmiVtJUXaQWHEhDxvohvXfChq3Zze4hcMmw/7e OpwEbQvwzMs6NcKLB4MfTauGa0zwKJ2L0OJrrgOKUWGJxikdVR7vJuVMPPxKp/1BTOVl XYvw== X-Gm-Message-State: AOAM531w/oJan7q+fqTM7IAebVer3In/B0U80jcRzbK0JEfADOVrotkY zweDQG5BDud5kddDALoD0yXElw== X-Received: by 2002:a17:906:3e06:: with SMTP id k6mr3616203eji.37.1598027423946; Fri, 21 Aug 2020 09:30:23 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id dk28sm1398030edb.90.2020.08.21.09.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 09:30:23 -0700 (PDT) From: Jean-Philippe Brucker To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 1/5] virtio-iommu: Default to bypass during boot Date: Fri, 21 Aug 2020 18:28:35 +0200 Message-Id: <20200821162839.3182051-2-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200821162839.3182051-1-jean-philippe@linaro.org> References: <20200821162839.3182051-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::644; envelope-from=jean-philippe@linaro.org; helo=mail-ej1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Cc: peter.maydell@linaro.org, ehabkost@redhat.com, mst@redhat.com, eric.auger@redhat.com, Jean-Philippe Brucker , pbonzini@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When a virtio-iommu is present, we currently require the guest to configure it before it can use DMA in any other PCI device. This prevents, for example, a bootloader that doesn't know how to drive virtio-iommu from loading an OS from storage. Add the "boot-bypass" option, defaulting to true, to let DMA bypass the virtio-iommu during boot similarly to the other vIOMMUs. It makes the system vulnerable to malicious endpoints during boot, but that isn't much of a concern in virtual systems. Signed-off-by: Jean-Philippe Brucker --- include/hw/virtio/virtio-iommu.h | 1 + hw/virtio/virtio-iommu.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) -- 2.28.0 diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h index 49eb105cd84..ae57efab1f3 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -58,6 +58,7 @@ typedef struct VirtIOIOMMU { GTree *domains; QemuMutex mutex; GTree *endpoints; + bool boot_bypass; } VirtIOIOMMU; #endif diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 5d56865e569..3b821fc005d 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -595,6 +595,24 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason, } +static bool virtio_iommu_bypass_is_allowed(VirtIOIOMMU *s) +{ + VirtIODevice *vdev = &s->parent_obj; + /* + * Allow bypass if: + * - boot_bypass is enabled and the BYPASS feature hasn't yet been + * acknowledged. + * - the BYPASS feature has been negotiated. + */ + if (s->boot_bypass && !(vdev->status & VIRTIO_CONFIG_S_FEATURES_OK)) { + return true; + } + if (virtio_vdev_has_feature(vdev, VIRTIO_IOMMU_F_BYPASS)) { + return true; + } + return false; +} + static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, IOMMUAccessFlags flag, int iommu_idx) @@ -621,8 +639,7 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, .perm = IOMMU_NONE, }; - bypass_allowed = virtio_vdev_has_feature(&s->parent_obj, - VIRTIO_IOMMU_F_BYPASS); + bypass_allowed = virtio_iommu_bypass_is_allowed(s); sid = virtio_iommu_get_bdf(sdev); @@ -947,6 +964,7 @@ static const VMStateDescription vmstate_virtio_iommu = { static Property virtio_iommu_properties[] = { DEFINE_PROP_LINK("primary-bus", VirtIOIOMMU, primary_bus, "PCI", PCIBus *), + DEFINE_PROP_BOOL("boot-bypass", VirtIOIOMMU, boot_bypass, true), DEFINE_PROP_END_OF_LIST(), }; From patchwork Fri Aug 21 16:28:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 248136 Delivered-To: patch@linaro.org Received: by 2002:a54:3b12:0:0:0:0:0 with SMTP id j18csp448854ect; Fri, 21 Aug 2020 09:33:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZJHdlWYyidvh4jghknQu66rXTkWHC4PDahwSIK4+SfSfDAoIOJHNBAvQL3H13nYvXnAnz X-Received: by 2002:a25:2005:: with SMTP id g5mr4816850ybg.75.1598027636792; Fri, 21 Aug 2020 09:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598027636; cv=none; d=google.com; s=arc-20160816; b=aymcryH0jnv+fJZY/D37q2uuyLayIO1/6VWRU+r5Dt1nR2n5Yve8eskIM25pGGsHkS arsDAZO0gfu1DOFmM4zqqmtBUAe6E5uIIkSfxRstWPbaThnmhrQOJPtarNuKj0veu2JA gtPrFXKhkIa4z7upvmY+6fVKlmXgJXrAy9/IEDyWwpKqpCTcLPB+h5sDD6arlGfRmDaj 5OhHbdZPEY1gFNbdWkXVlbcQa4B6gjQ4gMibW8BWSea6TkEWPiWvp3W+WWeGK95M3mna FJeG1JHm1Ib/B8qzWrpzsGj3r4IYkxcaa0Ddk65zM9e7Yp9MmdNCOOe8XSY7B9mnS2sa AG6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=cfGEtVcjgxqVubuTMIgt6HrOoNGCRwyjjLNrvoUWZIE=; b=BbXnaTXBHxvMb+i2hnKvUKPI+n++RG+PNRyrjMdZ71H2VoW+/K7S7HZO1Hz69IbjSJ 9I2GO5VIBZGRis+E/YejBy0/LXvlmgf1inM+ihdGjxFKHRLNCKPeujHDK/ln6bd7/p05 yj3VRVnUi1F7Xz+MvUXCrIOVij5A0hcfYEMmuGITtMfo5vPCEZwoTxxTj1Gzws6y/zrp td8F1tsqi90Nx/tf7bairn8gGJxtMiWZ5UKqF7//yDLycL9jhc4LWvsIuyHSXL61NX0M YDn+/lyLKhnLJXASygXsp9n1BNkkQE1jmlV3ukb46ffITZxXL6CqgtgocZ1ycrk++VNF jwFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="FcVI/YAV"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u15si2878087ybc.411.2020.08.21.09.33.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Aug 2020 09:33:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="FcVI/YAV"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k99zI-00042c-75 for patch@linaro.org; Fri, 21 Aug 2020 12:33:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k99vz-0007u9-3w for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:31 -0400 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]:33843) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k99vv-0006nm-K8 for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:30 -0400 Received: by mail-ej1-x643.google.com with SMTP id o23so3030129ejr.1 for ; Fri, 21 Aug 2020 09:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cfGEtVcjgxqVubuTMIgt6HrOoNGCRwyjjLNrvoUWZIE=; b=FcVI/YAV+PBNs/h35+luBqIu5MBgP4JC3OJUnM+kHCHF8ZyBBS5CkJCszjSsrW53QR YY3GkGj2Lf01ntsQIcD/7onmQKw9EeGyAjZX4BjlVFjH7m44yVGxOyu0OYcdsrCop0Wv 1Z16aIRw/4al5FceE09chtSY4OibYq+/HOsq0oZuuIn2gW6w+CAcIUs+jbGb2731gsyS DtcrE4QQmJ8v00DC7ktgUZHN4ORb1qjBh+GRrAVFhusNI1ZZfQBiDfNI+OLxxLu7dex4 SP5gdCu7ykqhNMW2y9C/uShqtv48zYfuvxd20DThCDj2EJKLHtdceZtLiLUpPoVkgi9n uHvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cfGEtVcjgxqVubuTMIgt6HrOoNGCRwyjjLNrvoUWZIE=; b=V1d6EOLKxsGU3fYrsEfOf3rca15dB0auuYZwoZcbF43yZqDziy3tbxri8+CsYUgHxP Qc2qONwpyc1yyN1kqOn2TPj/PyyXuXiJjbQYsvjtLZrtNCdWOQqy9FiXp//eoR5NS2Cv ISWM4ukqmS6JFJJPQuXSfhCTCHl6V3mP0odpyY/l0LqDPds1pDKGiKWnyGqo52nNPxxt LTAk21Pe6/fhFxAINK4NP/gAkWiym8Ll6e9o/ulHigGdZpHdt+qnER98kGER5Gsh1Wb/ XubsnMRWRAhStjeTOYpPpSZiffIU2SB5SEnnynxXalQUN8fL1TLJhzFONvm42NuOvIYl 9miw== X-Gm-Message-State: AOAM53242XsuR8tTmNhY3arFv4nsFQCxehhHztPUtJEEt7a5rzEGF7pi BBp2JoZgrxQbXxHZKNkx5WJ7Jw== X-Received: by 2002:a17:906:9989:: with SMTP id af9mr3498328ejc.385.1598027425104; Fri, 21 Aug 2020 09:30:25 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id dk28sm1398030edb.90.2020.08.21.09.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 09:30:24 -0700 (PDT) From: Jean-Philippe Brucker To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 2/5] linux headers: Import virtio-iommu header from Linux Date: Fri, 21 Aug 2020 18:28:36 +0200 Message-Id: <20200821162839.3182051-3-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200821162839.3182051-1-jean-philippe@linaro.org> References: <20200821162839.3182051-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::643; envelope-from=jean-philippe@linaro.org; helo=mail-ej1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Cc: peter.maydell@linaro.org, ehabkost@redhat.com, mst@redhat.com, eric.auger@redhat.com, Jean-Philippe Brucker , pbonzini@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Import virtio-iommu topology definitions from Linux. These changes haven't been upstreamed yet. Signed-off-by: Jean-Philippe Brucker --- include/standard-headers/linux/virtio_iommu.h | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) -- 2.28.0 diff --git a/include/standard-headers/linux/virtio_iommu.h b/include/standard-headers/linux/virtio_iommu.h index b9443b83a13..ee158c37c36 100644 --- a/include/standard-headers/linux/virtio_iommu.h +++ b/include/standard-headers/linux/virtio_iommu.h @@ -16,6 +16,7 @@ #define VIRTIO_IOMMU_F_BYPASS 3 #define VIRTIO_IOMMU_F_PROBE 4 #define VIRTIO_IOMMU_F_MMIO 5 +#define VIRTIO_IOMMU_F_TOPOLOGY 6 struct virtio_iommu_range_64 { uint64_t start; @@ -27,6 +28,17 @@ struct virtio_iommu_range_32 { uint32_t end; }; +struct virtio_iommu_topo_config { + /* Number of topology description structures */ + uint16_t count; + /* + * Offset to the first topology description structure + * (virtio_iommu_topo_*) from the start of the virtio_iommu config + * space. Aligned on 8 bytes. + */ + uint16_t offset; +}; + struct virtio_iommu_config { /* Supported page sizes */ uint64_t page_size_mask; @@ -36,6 +48,38 @@ struct virtio_iommu_config { struct virtio_iommu_range_32 domain_range; /* Probe buffer size */ uint32_t probe_size; + struct virtio_iommu_topo_config topo_config; +}; + +#define VIRTIO_IOMMU_TOPO_PCI_RANGE 0x1 +#define VIRTIO_IOMMU_TOPO_MMIO 0x2 + +struct virtio_iommu_topo_pci_range { + /* VIRTIO_IOMMU_TOPO_PCI_RANGE */ + uint8_t type; + uint8_t reserved; + /* Length of this structure */ + uint16_t length; + /* First endpoint ID in the range */ + uint32_t endpoint_start; + /* PCI domain number */ + uint16_t segment; + /* PCI Bus:Device.Function range */ + uint16_t bdf_start; + uint16_t bdf_end; + uint16_t padding; +}; + +struct virtio_iommu_topo_mmio { + /* VIRTIO_IOMMU_TOPO_MMIO */ + uint8_t type; + uint8_t reserved; + /* Length of this structure */ + uint16_t length; + /* Endpoint ID */ + uint32_t endpoint; + /* Address of the first MMIO region */ + uint64_t address; }; /* Request types */ From patchwork Fri Aug 21 16:28:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 248133 Delivered-To: patch@linaro.org Received: by 2002:a54:3b12:0:0:0:0:0 with SMTP id j18csp447510ect; Fri, 21 Aug 2020 09:31:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcyRZcaSch/mzT1WZbsMAMS+DJ44FsLoqpwfrnkH9wOHvfjeGsovbYo02/Vw1rdXOAr+Xh X-Received: by 2002:a65:664a:: with SMTP id z10mr2846380pgv.352.1598027513147; Fri, 21 Aug 2020 09:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598027513; cv=none; d=google.com; s=arc-20160816; b=Z+vFzLbgV1raTXhx90Ql3xdNBYJL3j/fLzECYC0YMgONU2HUqMvVsQn0QkqUNsSV3W JmXTDfvI6QKGyZDC4/9E4hFQV7Rzbcp64XLHJDE0LGChSVfOv0wp63+NZ+G0W5hY2aCA 2U/jwSRFTHRjva8tijp8pXxjLordsCXdOu/OxLcct5hSL/iwppp2k5KWOndHxJfLSQrb h5DUBLFFZ+scVjQkUESlvQ0IbW44tSBe4VVsW/wKTrMB5IOd0y8f4ijYWOrXRu6gfAPP ifjb2R9SHols7ONdwWI3ju7+vdlsUb8/koVrrqXsXwxM0qoJce1or5mhGJvecuQN8OLh aSMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=TxGD9EzF0atjNPI3j2WNYptRLPX7AMvR+MeE+NZH67c=; b=h6PqpjkYyMryE6j6TYYTqhTKheWgcKCsIEVT/VqA6sDm+X3YJ6cFFcqqY99wBMk8Ez TP7bl0KSx5BBDCP7D/nVnTKgKUWkDv5UX6FkjoE4g1//+Tus5fZx+nJWxR7M7GJZZyIf FKO9LdI/WMzwAYWMNBWYt7Dk353z+NFUOs5fPYYjdDTT//TmpL8WZAlHjAr/YqJX71Er 4FAxbicoXHYSIFj4U6UobKXD5cfAZfUNnXacLUUtTaeDalXJCtPh2CaBtKr0BcekLyfS iAgC8h/svmflZDpkZgd9HQRc6+8hfcoB7JgZsVBOofsi9XMnjEkiFWAaYduiOO0aGC+n 28lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kO3g8v1q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m24si1847976pjz.132.2020.08.21.09.31.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Aug 2020 09:31:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kO3g8v1q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k99xG-0008Sa-Ir for patch@linaro.org; Fri, 21 Aug 2020 12:31:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k99vz-0007ut-Ri for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:33 -0400 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]:34488) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k99vv-0006oC-KG for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:31 -0400 Received: by mail-ed1-x543.google.com with SMTP id bs17so1953410edb.1 for ; Fri, 21 Aug 2020 09:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TxGD9EzF0atjNPI3j2WNYptRLPX7AMvR+MeE+NZH67c=; b=kO3g8v1q0f7H3hTLphPPV3FBTUrC4poIBwQrOkiQ5YjlAeyRY/IITAyhLYuiRHSXFh c3NB7mo/7qnxxY/ihLkoHeg8/18q0nDWDfDvZuTYey8yKzlZcJEYC9/66cwVdlh+OX7U jhLvNcpG5ypJgcmlWNVnt5AaCZlW4+HeWmhgbH2XU5tvjoK873ogHchZCoenXe8LOSz2 Ib1y+dHARnQqGYhJvd+MY35KiSc2wo5OaMJhxH3tgOqL3D+lvm57Y83p9XbSaq1v6wGa V7Fnj00TSWZCNfJEVuJfUain8Ra5POsr34dzX3JUFm5IQBuwzAxtpVrInvLTZ1q+G93O IR8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TxGD9EzF0atjNPI3j2WNYptRLPX7AMvR+MeE+NZH67c=; b=mAEEyQwQ5S6hCRNwCtoIiJgSemV0vbi+nPO2NHQYbyMZD88jw2Qx/0xlkmBJHAo3eu DP8UgH05KipkRwhQZiCx8FwRM5MwfB3O78kQC0McvhmDdQkD2/Fx8p+QP5Kd5MDWzDth OERRsJEc7rZbRJ6nIGxItYadLC5wOArNJ0EfiLA7TwB0kiR0r2bFF2RaWeleM68eFMdV E6hWoe8Ek4jelsXKluE2Sa+ocB6pAhVfnOdMDkdQMzn+j70/K295L+8F60bbAcud4ZTq MIQPnN+ZYm3yOd1S8MR4g9vuLlMxAHcF7iJcfRZcEowgA/azTQvarc8cC+droDQVJ2ot mBXg== X-Gm-Message-State: AOAM533+AGori5fcyasXzfuEX3LwoqvUzcwthg/0WrSoZH7TrBfsLxcy eiGAu/LbmiL1Xu0u2mhvGeHWcw== X-Received: by 2002:a05:6402:22ab:: with SMTP id cx11mr3816150edb.102.1598027426267; Fri, 21 Aug 2020 09:30:26 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id dk28sm1398030edb.90.2020.08.21.09.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 09:30:25 -0700 (PDT) From: Jean-Philippe Brucker To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 3/5] virtio-iommu: Declare topology in config space Date: Fri, 21 Aug 2020 18:28:37 +0200 Message-Id: <20200821162839.3182051-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200821162839.3182051-1-jean-philippe@linaro.org> References: <20200821162839.3182051-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::543; envelope-from=jean-philippe@linaro.org; helo=mail-ed1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Cc: peter.maydell@linaro.org, ehabkost@redhat.com, mst@redhat.com, eric.auger@redhat.com, Jean-Philippe Brucker , pbonzini@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When requested on the command-line, by adding topology=on to the virtio-iommu device, provide the IOMMU topology in the virtio config space. It describes which endpoints are managed by the IOMMU - all PCI devices - and allows to support: * virtio-iommu for platforms without ACPI or DT (e.g. microvm), * virtio-iommu for ACPI platforms, temporarily. A new ACPI table will be introduced to handle those, but this provides a boot method in the meantime. Signed-off-by: Jean-Philippe Brucker --- include/hw/virtio/virtio-iommu.h | 3 +++ hw/virtio/virtio-iommu.c | 40 ++++++++++++++++++++++++++++---- hw/virtio/trace-events | 4 ++-- 3 files changed, 40 insertions(+), 7 deletions(-) -- 2.28.0 diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h index ae57efab1f3..7ba1dacf75d 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -49,6 +49,7 @@ typedef struct VirtIOIOMMU { VirtQueue *req_vq; VirtQueue *event_vq; struct virtio_iommu_config config; + struct virtio_iommu_topo_pci_range pci_topo; uint64_t features; GHashTable *as_by_busptr; IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX]; @@ -59,6 +60,8 @@ typedef struct VirtIOIOMMU { QemuMutex mutex; GTree *endpoints; bool boot_bypass; + /* Declare topology in config space */ + bool topology; } VirtIOIOMMU; #endif diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 3b821fc005d..08ab457ccf1 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -731,15 +731,24 @@ unlock: static void virtio_iommu_get_config(VirtIODevice *vdev, uint8_t *config_data) { + off_t offset; VirtIOIOMMU *dev = VIRTIO_IOMMU(vdev); struct virtio_iommu_config *config = &dev->config; + struct virtio_iommu_topo_pci_range *pci_topo = &dev->pci_topo; trace_virtio_iommu_get_config(config->page_size_mask, config->input_range.start, config->input_range.end, config->domain_range.end, - config->probe_size); - memcpy(config_data, &dev->config, sizeof(struct virtio_iommu_config)); + config->probe_size, + config->topo_config.offset, + config->topo_config.count); + memcpy(config_data, config, sizeof(*config)); + + offset = config->topo_config.offset; + if (offset) { + memcpy(config_data + offset, pci_topo, sizeof(*pci_topo)); + } } static void virtio_iommu_set_config(VirtIODevice *vdev, @@ -747,12 +756,14 @@ static void virtio_iommu_set_config(VirtIODevice *vdev, { struct virtio_iommu_config config; - memcpy(&config, config_data, sizeof(struct virtio_iommu_config)); + memcpy(&config, config_data, sizeof(config)); trace_virtio_iommu_set_config(config.page_size_mask, config.input_range.start, config.input_range.end, config.domain_range.end, - config.probe_size); + config.probe_size, + config.topo_config.offset, + config.topo_config.count); } static uint64_t virtio_iommu_get_features(VirtIODevice *vdev, uint64_t f, @@ -776,9 +787,10 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOIOMMU *s = VIRTIO_IOMMU(dev); + size_t aligned_config_size = QEMU_ALIGN_UP(sizeof(s->config), 8); virtio_init(vdev, "virtio-iommu", VIRTIO_ID_IOMMU, - sizeof(struct virtio_iommu_config)); + aligned_config_size + sizeof(s->pci_topo)); memset(s->iommu_pcibus_by_bus_num, 0, sizeof(s->iommu_pcibus_by_bus_num)); @@ -791,6 +803,12 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) s->config.domain_range.end = 32; s->config.probe_size = VIOMMU_PROBE_SIZE; + if (s->topology) { + s->config.topo_config.offset = aligned_config_size; + s->config.topo_config.count = 1; + virtio_add_feature(&s->features, VIRTIO_IOMMU_F_TOPOLOGY); + } + virtio_add_feature(&s->features, VIRTIO_RING_F_EVENT_IDX); virtio_add_feature(&s->features, VIRTIO_RING_F_INDIRECT_DESC); virtio_add_feature(&s->features, VIRTIO_F_VERSION_1); @@ -810,6 +828,17 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) } else { error_setg(errp, "VIRTIO-IOMMU is not attached to any PCI bus!"); } + + if (s->topology) { + s->pci_topo = (struct virtio_iommu_topo_pci_range) { + .type = cpu_to_le16(VIRTIO_IOMMU_TOPO_PCI_RANGE), + .length = cpu_to_le16(sizeof(s->pci_topo)), + .endpoint_start = 0, + .segment = 0, + .bdf_start = 0, + .bdf_end = 0xffff, + }; + } } static void virtio_iommu_device_unrealize(DeviceState *dev) @@ -965,6 +994,7 @@ static const VMStateDescription vmstate_virtio_iommu = { static Property virtio_iommu_properties[] = { DEFINE_PROP_LINK("primary-bus", VirtIOIOMMU, primary_bus, "PCI", PCIBus *), DEFINE_PROP_BOOL("boot-bypass", VirtIOIOMMU, boot_bypass, true), + DEFINE_PROP_BOOL("topology", VirtIOIOMMU, topology, false), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 045e89cae69..6c5830ca47c 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -59,8 +59,8 @@ virtio_mmio_setting_irq(int level) "virtio_mmio setting IRQ %d" virtio_iommu_device_reset(void) "reset!" virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx64 virtio_iommu_device_status(uint8_t status) "driver status = %d" -virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_range=%d probe_size=0x%x" -virtio_iommu_set_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x" +virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size, uint16_t topo_offset, uint16_t topo_count) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_range=%d probe_size=0x%x topo_off=0x%x topo_count=%u" +virtio_iommu_set_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size, uint16_t topo_offset, uint16_t topo_count) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x topo_off=0x%x topo_count=%u" virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_map(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 " phys_start=0x%"PRIx64" flags=%d" From patchwork Fri Aug 21 16:28:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 248135 Delivered-To: patch@linaro.org Received: by 2002:a54:3b12:0:0:0:0:0 with SMTP id j18csp448657ect; Fri, 21 Aug 2020 09:33:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylhDOf0HfguGw8k0TVsYOyo26Ej2tGimtAn0PJfUwGUD7Z8eqsmFfJjIVvQQ05Nw1vj2TX X-Received: by 2002:a25:2311:: with SMTP id j17mr4557791ybj.65.1598027618610; Fri, 21 Aug 2020 09:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598027618; cv=none; d=google.com; s=arc-20160816; b=lBRxs0BCxV+avhzZVNLKrtLO27i0pHZWJWu+8uoAvi1+mHQVjJPVMFc7uunIbjmJiR o0uPgoXnptOTeNxj6SSYtPZmqmboLlX6LNotykP8K6VHX57bbCtyk7h3Z/oXnUe+4kyZ vi3drR39VJJ41pqbAxwUWaJl4yHZCBHeWyjzOwNWI5DbnKOK9YCfrfPWUYkKj/gktZeU FQofaTy+48Y/TY125SLlpp9kzgtFhiD92I3ItEsqQQGo0ddVNZu9grQ3pWI1GaIOxkP1 /XP87oQL5VI902VK5fwQFR9vzGTnR/apCQK4HFMemhSBnS4me37CeuSa0hfSRqY1qLxz XkPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=2+K4uxN0kyhXy6kN+ijSa8qFKCUtC4za1XiAKyb7Tws=; b=FdiKQAX4UJ77y6tXRt7E9FbtbDKK9+4vaEs+hDliqw6trsl2yikVeeKPkGXJczRPVf scwjrKj63bnFs7SXOJrFDa5q/XXK3wvwuua4vHsS9s3IS14jrvF1QV6vrPF69PhaSmjo CnVj4fkwVNCqwOxwPG+czANXsQ4t4xJEOvvQydcf3dQxp7L/W8t7Wn+iodTD8OEqAMkx 1maQnioSxKFdtrQp9ANrVqAs3ovttPwKgVlmW5jgFk/SBSnZr1O0cl+Ez7AVfC5MDgzG fLsQi6jt+1rvQxGaa5/HwnFcvF9ZjnvHCGe8+IOLXvoKRQdhfW+9wOqJUvXt1O8pPJzq wJ0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=abinKzoj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d192si2470425ybf.426.2020.08.21.09.33.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Aug 2020 09:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=abinKzoj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k99z0-0004Um-2W for patch@linaro.org; Fri, 21 Aug 2020 12:33:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k99w1-0007w6-LP for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:33 -0400 Received: from mail-ej1-x641.google.com ([2a00:1450:4864:20::641]:41121) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k99vw-0006og-U6 for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:33 -0400 Received: by mail-ej1-x641.google.com with SMTP id t10so2996474ejs.8 for ; Fri, 21 Aug 2020 09:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2+K4uxN0kyhXy6kN+ijSa8qFKCUtC4za1XiAKyb7Tws=; b=abinKzoj5alQRqRp3d9/Y8vcOnoqK1So6bFU7ki3PlKlt1uvNdKbCPdngAzKsy+y5W OiHVOyZwhIeMR2BcuDAYXgAk1APbs4CV2S2fPd2D0+YlQDbzD+AVHl1Q+usVPUibVRQz 5RVjIt8AbuNJIv5DrBzz9ScYlA8i0Xa9wXdALwwG/0LGLXznK0Nwbl3Luk7tfG4dvBaq eGUs4kBH/Lgaoagre6TlxJQ85DG9o65B+tuQovOEobP4vja1JlZkys8FrODbhoVAo25i ZN5HzeYw5T1hKUXYIBBScrItkssCoWKu1V0E8N3hmRJbqhfFByZ8xDOivB0exQ0srG6U 0AOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2+K4uxN0kyhXy6kN+ijSa8qFKCUtC4za1XiAKyb7Tws=; b=OmUnTDEATtjW9RnB5Ro5FVYlvIFdyyLhGhndV7M/K7mtIBBScQe0E3NVm/hCpny4Iy CT0N0Bx61Tv6nF0RibnPWW5jz4+nydIlcjioeZj1Rub8q/B1Jsnx2PYb49ZMNv+C1d0F OgU/I6kauqgr5gtlIx1t6+1GZdcDNzkiBMsrNfep/TQBC01CgxqcMD5lDecC5a3R6i6o Fkdpprc+VuxuaBFQAks13GM9MvCZ55cnU4L4815s/2SQg/zt0F9Ui6VM176JpQmFgIcE FoFiQNduvK7RrZGWi8f781eu3tPr3eZ9NDCvUnqfyHGg7TKoyS5NTIs2LbXiuiPWtnow jGug== X-Gm-Message-State: AOAM5329AqxjCQ6i1fOHO3vXOuBEVPsHxQTvRWkPVok/xcLmsMTiY9h3 RGaRFvEAjR5FkIWLW+XiMoGqHQ== X-Received: by 2002:a17:907:7292:: with SMTP id dt18mr3849992ejc.512.1598027427415; Fri, 21 Aug 2020 09:30:27 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id dk28sm1398030edb.90.2020.08.21.09.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 09:30:26 -0700 (PDT) From: Jean-Philippe Brucker To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 4/5] hw/arm/virt: Remove device-tree restriction on virtio-iommu Date: Fri, 21 Aug 2020 18:28:38 +0200 Message-Id: <20200821162839.3182051-5-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200821162839.3182051-1-jean-philippe@linaro.org> References: <20200821162839.3182051-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::641; envelope-from=jean-philippe@linaro.org; helo=mail-ej1-x641.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Cc: peter.maydell@linaro.org, ehabkost@redhat.com, mst@redhat.com, eric.auger@redhat.com, Jean-Philippe Brucker , pbonzini@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Now that the virtio-iommu has a built-in topology mechanism, it can be used without a device tree. Remove the restriction on !ACPI or !firmware. Signed-off-by: Jean-Philippe Brucker --- hw/arm/virt.c | 10 ++-------- hw/virtio/virtio-iommu-pci.c | 2 -- 2 files changed, 2 insertions(+), 10 deletions(-) -- 2.28.0 diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ecfee362a18..2742c28054a 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2358,16 +2358,10 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine, DeviceState *dev) { if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE) || - (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM))) { + object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { return HOTPLUG_HANDLER(machine); } - if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { - VirtMachineState *vms = VIRT_MACHINE(machine); - - if (!vms->bootinfo.firmware_loaded || !virt_is_acpi_enabled(vms)) { - return HOTPLUG_HANDLER(machine); - } - } return NULL; } diff --git a/hw/virtio/virtio-iommu-pci.c b/hw/virtio/virtio-iommu-pci.c index ba62d60a0a0..240e85e6363 100644 --- a/hw/virtio/virtio-iommu-pci.c +++ b/hw/virtio/virtio-iommu-pci.c @@ -54,8 +54,6 @@ static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) error_append_hint(errp, "Check your machine implements a hotplug handler " "for the virtio-iommu-pci device\n"); - error_append_hint(errp, "Check the guest is booted without FW or with " - "-no-acpi\n"); return; } for (int i = 0; i < s->nb_reserved_regions; i++) { From patchwork Fri Aug 21 16:28:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 248134 Delivered-To: patch@linaro.org Received: by 2002:a54:3b12:0:0:0:0:0 with SMTP id j18csp447827ect; Fri, 21 Aug 2020 09:32:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsep8I9RJJkjWpTH3WQo5zZ1kvKJPZKvIFCBar/uirwsSmW7wfnDCdC/LFK0bBpPym7Sor X-Received: by 2002:a67:f502:: with SMTP id u2mr1962684vsn.111.1598027540963; Fri, 21 Aug 2020 09:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598027540; cv=none; d=google.com; s=arc-20160816; b=uaMaYwp49zOlaf+KNJ00ESAAzI2XNCrptTN3M9Oo4GEoDQMBE+Owy3iYDBrNZpD3MB lrP4rvAOXEC4FrnkjyU+sJLB1dV1HOJRRtBGmG3qzUCu27eb6dlvtN22ClrcTLvpDuLI T2/3upeCHeA6VfkpcN6zm38Y3wB4lHaGoeTkImRuHf+wGAyLWuFWlLkStEAjGKSdGQZZ jmp7J3wr7G7mLB7UlIi+4+nqCiagvXImzhmPugVG8DpNmozYcigWCRpf2dwm+OqiWqoW 2bNfkmCoa6rUa07wYRfm7Zbhq6lgviPf8LBtIp0rzaYubwH6RXK2XActgH5SFI65mpfg ffJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=5joFadNGRqyI9ygkH+sBW3/GPpVUuhHiLgETPkq0zN0=; b=YgnnCjoquFr35TR5zshRe3i7Dd8LxfOT8WdJ1Bxy5Oa+XUHiIMp0Ri09hEEuHwTbzT GugPOdfQAIXHNMRJGg/wS0FT4TZ1H9MRGIypBhC/AFAdNCAdRtlp3cNV+bsrxQ5VIFrX IzIvVM/lvpPCGPZqskpgsfsguNsvWLPIe4kOv2gEHIjSVaL7ULgWgI1kQixWSTsab+Ii ZGmkiVBuX/6Hk97SoGSvwbDadi0ySkOB/30+s70aFAM/cQEhP1193kJZyq8JanazGyjt StHRJDy0gBdl4yBpwYK0f3hAG32MFk9ayJNiFuC4ZYrdqBALDfCsIbsadqF8Xtiro3nj HIsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jntCwjwl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v24si537717ual.182.2020.08.21.09.32.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Aug 2020 09:32:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jntCwjwl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k99xk-0000tb-9U for patch@linaro.org; Fri, 21 Aug 2020 12:32:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k99w3-0007yf-2Y for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:35 -0400 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]:37850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k99vy-0006pb-0c for qemu-devel@nongnu.org; Fri, 21 Aug 2020 12:30:34 -0400 Received: by mail-ej1-x643.google.com with SMTP id qc22so3011602ejb.4 for ; Fri, 21 Aug 2020 09:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5joFadNGRqyI9ygkH+sBW3/GPpVUuhHiLgETPkq0zN0=; b=jntCwjwlK6crnSoYOahrPvHKLeFtEckXfw2hh1SxYdy8zvZRkGBTDC7kyuk+AJ4irn Vd55WK82KWEK389HYCg5/i8x/nsjNVwPhom0R7zpGPQG5/QEzYuucs8ZvUumzaOQcVpm geyPsJSuCj+KSksJx+KRTvVWA5dxqb1ywvYYQ3XIeL6PgyA+DsUJ9trFRE/+lMsJ4N43 NVPAYfVd0ttx31V148K8N4GYmK7hoj0iBoZbmQ79NRdn8jq+GkqNtdqfRBvd+X0Pr6Aa J/e88DIeNq0Enx0PVMS00hV3q6XDys/PanmjcxMz9Ag1YNkrcDkzd7WY86PDrHBIywWX yQXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5joFadNGRqyI9ygkH+sBW3/GPpVUuhHiLgETPkq0zN0=; b=a0B7GM46+kWyJgGTXcuStlD8VuIgv/39TQAfjp+sRzJsdSpUECm0Fhj8uNtMHISzBM stcHrJ7kIbVtbDyf3CBYKD+8r7or+LHxyafVj5joN91xMs20N2DGPgn3b+NXyn+RRMSa 2o8JOLlEwd5ecpnOdZQ7K3hQatDrjJsWAqLmECxEn/wr25X6yaVI6olKDs43JkvJGOzq Z4XEN8J3FILjnKc3UmdKv7D3MXkS7R5dmGAIJuLBQ3wAkfg7CZJ5B1HfonJX7fqpxYDf yLF/Y3P+pDCnARF7hAgCPGaXRUMtcof4xg1xJg1XN0SjOWD6eSABXoRbb4fIjVjiK5Cx zoKQ== X-Gm-Message-State: AOAM531LycN5HaJTcELdm3iSZ11IwMHhXf7i552LAjN4HA8svbiNBK/L vm8sgIO4w6OGazUWQAq7chgJ2w== X-Received: by 2002:a17:906:cc51:: with SMTP id mm17mr3734323ejb.137.1598027428558; Fri, 21 Aug 2020 09:30:28 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id dk28sm1398030edb.90.2020.08.21.09.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 09:30:27 -0700 (PDT) From: Jean-Philippe Brucker To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 5/5] hw/i386/pc: Add support for virtio-iommu-pci Date: Fri, 21 Aug 2020 18:28:39 +0200 Message-Id: <20200821162839.3182051-6-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200821162839.3182051-1-jean-philippe@linaro.org> References: <20200821162839.3182051-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::643; envelope-from=jean-philippe@linaro.org; helo=mail-ej1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Cc: peter.maydell@linaro.org, ehabkost@redhat.com, mst@redhat.com, eric.auger@redhat.com, Jean-Philippe Brucker , pbonzini@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger The virtio-iommu-pci is instantiated through the -device QEMU option. Declare the [0xfee00000 - 0xfeefffff] MSI reserved region so that it gets bypassed by the IOMMU. Signed-off-by: Eric Auger Signed-off-by: Jean-Philippe Brucker --- hw/i386/pc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.28.0 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 47c5ca3e342..79ab7e06066 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -89,6 +89,7 @@ #include "standard-headers/asm-x86/bootparam.h" #include "hw/virtio/virtio-pmem-pci.h" #include "hw/virtio/virtio-mem-pci.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/mem/memory-device.h" #include "sysemu/replay.h" #include "qapi/qmp/qerror.h" @@ -1698,6 +1699,11 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { pc_virtio_md_pci_pre_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + /* we declare a VIRTIO_IOMMU_RESV_MEM_T_MSI region */ + qdev_prop_set_uint32(dev, "len-reserved-regions", 1); + qdev_prop_set_string(dev, "reserved-regions[0]", + "0xfee00000:0xfeefffff:1"); } } @@ -1752,7 +1758,8 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || object_dynamic_cast(OBJECT(dev), TYPE_CPU) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || - object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { return HOTPLUG_HANDLER(machine); }