From patchwork Thu Sep 30 18:50:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 514970 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp65207jaf; Thu, 30 Sep 2021 11:54:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtf3rHuPk3UgVeqECDgSUCwPzGKXuCStZb5bivK64OmPEZg0T1W8huZpV5Q9QIo9GM6NXn X-Received: by 2002:a05:6638:160c:: with SMTP id x12mr6299836jas.80.1633028041728; Thu, 30 Sep 2021 11:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633028041; cv=none; d=google.com; s=arc-20160816; b=vhumLAbv1bboQr/34AY4Wq+8hS/xIhUxFjLtEGjeU3/U/QmkK/i2yS59QTQRIuuWGl EjWaK8CMaehlOT+iHstLAtR6wlT2rKDx5OM8ZRsrqZe2RQ+sMtFLRjOS8bFKr/KOhA53 7jOE4ZSqddF0BhoFwXd+jVORcTtszMIIn4LHy7gjGY3mlPv1vYFFqryZkuMeHKSfB+qY iptHIQfYjT7BOhppjTYX/tcJ+roslUI6iSi+nK5QsS5mhd+W4DuUqGksDfn/Jnv7MP2G 3txfwSB5cIdEVcMj9J+/mFmlbP8WO7GonTvL8Vf6G/8RQ81evW8iF4as2hl6razHv36N 4Rug== 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=APTVDF/D3IubpWB8qDVO2Zw8T5nSgcTbPJqBTW5jp90=; b=xmSb8SMcdis9iURdXP8QXP1XQyufSW2PL+5RYFZEC36qELlgIncZwG14UpBOwO53fZ y4bNCO37TE1wTxiLkuk8t0UxeSfQirGnKJaYn1RfBaMlG6qJhCs3AFiw9dOiG9dlRQ7U UWoD7leBYtHWPaZky2ZKeEWyABXnBywS8Jkv2q9zXaDx4qebKVnpkv8c1Hh0zdP3ZtT0 JuKzGoeIjQmwga3RVuAgZ7pUr4qzP8/V+aE4W86MFkoOrfb0Gy+3m1DqZhkcpyyFXoFz UtxEukqrnM873+qbBwWqctG1ju5FNCI1/ww+vcbws77A2i3/36OG/9bhTGx7paf9KfGW Ndgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tTzael8P; 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 p16si5842430iov.22.2021.09.30.11.54.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Sep 2021 11:54:01 -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=tTzael8P; 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]:43632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mW1Bx-0001Fu-4w for patch@linaro.org; Thu, 30 Sep 2021 14:54:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mW1AW-0001CZ-WC for qemu-devel@nongnu.org; Thu, 30 Sep 2021 14:52:33 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:41765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mW1AS-0004J8-U3 for qemu-devel@nongnu.org; Thu, 30 Sep 2021 14:52:32 -0400 Received: by mail-wm1-x32e.google.com with SMTP id g19-20020a1c9d13000000b003075062d4daso5101091wme.0 for ; Thu, 30 Sep 2021 11:52: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=APTVDF/D3IubpWB8qDVO2Zw8T5nSgcTbPJqBTW5jp90=; b=tTzael8PJ9J8ctwCzLKvCf5IXAySj5qvoJUlqCT+rRLOV3gsnNvWv1ce9/eoi1rfkb Veni2SCcuUxJ5nbTa1e/6Rj6ne/rfQCVaES6ryLnwogbWn5FLnhjhLDvkwLfglhCdtYz foCYa1JlACNeVwc2Fr05LhJ9ABsEBp5hz3N6I3NjSmJI8h4fBzE7Ee9tMLP4hBHPOmlg fajBjXKdhXJlu84xuQlOiz7CDGdbS8n23QdPLC3o/MGdpJWJHW8/7hbLuX1cBt8eGFYM r9WIxzGZ7a0DIqDwnB5Ur+nEKrk0tE6dwfS+98uqhTjQgmqYi6f2UDZVoDD4mUSNMhz9 EjHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=APTVDF/D3IubpWB8qDVO2Zw8T5nSgcTbPJqBTW5jp90=; b=gCrQoGpG+d3V/bKbX4h685198ODkmlB5hN4c13PZpgHyEH0gvmxH4qZLYspDk77MA5 KudKscLPFlCCzkfzkuYLELsFNxu9j9nm6zBj9TiPdTluGa3tZBQj5VHbWmu7Wx2uYTEs p7T/q7Sa9AlRxPEv66Q1GLkienpsw8o13wRTCW5RP3lvO9OvDmOStmIamvgoo4dhGNCL 2JJIK6eOLwadSADRZ0FWuwLBZL4dsnZpQSb2SrXt2oH7GhLO7y8fqaTOR0yDwMB2OK3Y j/46sRZ88TNHjtRKSbf/D+SbuWWKo16YHMoAdzqUYhJsxH8BzkpC0oLZtp24YULJ6eeR NaXQ== X-Gm-Message-State: AOAM532utCQRzpSB5ybC+VcyMqQXUFhyIqCdn8wm5Zywl8epXbnujXau 2z5kPuGttoLYr10jp1A6tnBSBA== X-Received: by 2002:a1c:7e53:: with SMTP id z80mr779727wmc.152.1633027946857; Thu, 30 Sep 2021 11:52:26 -0700 (PDT) Received: from localhost.localdomain (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id l124sm5487151wml.8.2021.09.30.11.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 11:52:26 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com Subject: [PATCH 1/3] NOMERGE: virtio-iommu: Add definitions for VIRTIO_IOMMU_F_BYPASS_CONFIG Date: Thu, 30 Sep 2021 19:50:49 +0100 Message-Id: <20210930185050.262759-2-jean-philippe@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210930185050.262759-1-jean-philippe@linaro.org> References: <20210930185050.262759-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x32e.google.com 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: Jean-Philippe Brucker , qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Pull VIRTIO_IOMMU_F_BYPASS_CONFIG changes from Linux (not upstream yet). Signed-off-by: Jean-Philippe Brucker --- include/standard-headers/linux/virtio_iommu.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.33.0 diff --git a/include/standard-headers/linux/virtio_iommu.h b/include/standard-headers/linux/virtio_iommu.h index b9443b83a1..d14808e3fb 100644 --- a/include/standard-headers/linux/virtio_iommu.h +++ b/include/standard-headers/linux/virtio_iommu.h @@ -13,9 +13,10 @@ #define VIRTIO_IOMMU_F_INPUT_RANGE 0 #define VIRTIO_IOMMU_F_DOMAIN_RANGE 1 #define VIRTIO_IOMMU_F_MAP_UNMAP 2 -#define VIRTIO_IOMMU_F_BYPASS 3 +#define VIRTIO_IOMMU_F_BYPASS 3 /* Deprecated */ #define VIRTIO_IOMMU_F_PROBE 4 #define VIRTIO_IOMMU_F_MMIO 5 +#define VIRTIO_IOMMU_F_BYPASS_CONFIG 6 struct virtio_iommu_range_64 { uint64_t start; @@ -36,6 +37,8 @@ struct virtio_iommu_config { struct virtio_iommu_range_32 domain_range; /* Probe buffer size */ uint32_t probe_size; + uint8_t bypass; + uint8_t reserved[7]; }; /* Request types */ @@ -66,11 +69,14 @@ struct virtio_iommu_req_tail { uint8_t reserved[3]; }; +#define VIRTIO_IOMMU_ATTACH_F_BYPASS (1 << 0) + struct virtio_iommu_req_attach { struct virtio_iommu_req_head head; uint32_t domain; uint32_t endpoint; - uint8_t reserved[8]; + uint32_t flags; + uint8_t reserved[4]; struct virtio_iommu_req_tail tail; }; From patchwork Thu Sep 30 18:50:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 514973 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp67826jaf; Thu, 30 Sep 2021 11:57:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe/qU3N2ErdhKDDUtodrrtw1/4Qi6HHvlVA0rvTH18nrRn7KV3snGZl2vAAyQB1HiM2sSU X-Received: by 2002:aca:afcc:: with SMTP id y195mr663917oie.71.1633028240366; Thu, 30 Sep 2021 11:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633028240; cv=none; d=google.com; s=arc-20160816; b=e4oKyLl/TlnnbFmLiFmRQcqB5ik+s3tpBC/+CPqik3gzbhuY+NpzZgXvLU+sPy7q12 Rc5mOWDUqtLAtLrgPAKYiniEzDqDciEoIWLLybtcZJaY0rrxcvDNz8qeXrrdAA9i5QcI IZOfXPzl7o0FeLpN8jJMHXxPiqentNAhIHIrYcgL2LfDFCleYjS7V5tcMjKKb1HHAzKl SQsv+70UrFEm3f2NHRr4EoSXnOCXSdzG27hWmgRRaZuSoI11USHWDopTvBO9cTsRWcIa 4mqLkevDCDfUT/RHHLwjL4xXqViAqUj4LSBpelIfjKQDcd9E6ApbBFPeLpdel67wdBo/ q6hw== 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=0TV0wMhSKf6e9khlOa9LUicDSxf5nPKoH9SuDHumuR0=; b=feOZksbECFeTR8gQeLKAZWn1P5TneaC5ktxyZNDulA2KK72AV6sWiEsbqIISzvLxPV 90xb/+w8o4VSWZ87O5pREjzKNTKltibf82+QywHgWCybnxg73LeV1mItlRBRciHKK0om 6TK3g27rU3x377937/KdPixDie+ZlpnEH/fGzWr6+tSOjwvGbchnsL93owcENLSqpCgf hU/1nrg0Vqf8BS/weJe/E1rlojhSJRuQ6xk5sBcvi/NYSstVmDAHadzGfc1gAR8ZQF0S 9lYDv4EWASeRm2CmUaNSpQFzaONRU/qv1qSG+618b+JpGN2mrggv1YV13w9ntWDxtn/G XhbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HGya6g2h; 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 w9si3476344oou.14.2021.09.30.11.57.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Sep 2021 11:57: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=HGya6g2h; 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]:50160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mW1F9-0005c1-Nk for patch@linaro.org; Thu, 30 Sep 2021 14:57:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mW1AV-0001CC-Se for qemu-devel@nongnu.org; Thu, 30 Sep 2021 14:52:31 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:46617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mW1AT-0004KY-6K for qemu-devel@nongnu.org; Thu, 30 Sep 2021 14:52:31 -0400 Received: by mail-wm1-x331.google.com with SMTP id d207-20020a1c1dd8000000b00307e2d1ec1aso5064968wmd.5 for ; Thu, 30 Sep 2021 11:52: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=0TV0wMhSKf6e9khlOa9LUicDSxf5nPKoH9SuDHumuR0=; b=HGya6g2hznXn5ohs1XMF0NGxyDBKtxO+UnyGXLFdxzCsO6BrNutEG6Cw7hZcIm/olR BmwO4x3eB9m39x215v0SsI9w55yKEJKiGz2Gn7CXdsh8U6e5arFgJuQS9Pa3rqMvApeS 8T90tnA1vSLIs51jorFcSObtqSBVLGYWe488lxwN0Xunz9482mdifEWySnuUC+hVcMUT 0xZF/oHYjnLRMRmgqNwdrxj+XAr/aAZQoT0eCJ4JRN+Ah/vn+9ICk1vmYbo7NTnVmdCE VA7Mb6NolvhlaoGVSO8giqKoBOJ2mb/VhazL726hhbeznRvDhhMbplMTjVkfhzS9KLpR rQ0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0TV0wMhSKf6e9khlOa9LUicDSxf5nPKoH9SuDHumuR0=; b=oWp10rXSblwPwpb+MpJLeeH6AaDlFwRaYiwQMg4E+jKN9rRBxsN9mAiibq7SLKVoMR utaGSZsGyrNEWYiJgYDTok2wvdMqKUuY4tjYKm0jKkReX+BvoGTpwDCfL4ZCBN3JqAVp /iR5MCanu7XN/TWdHt0zWxABDmdkDClJKTwsvkdDiL5wa3qebCDo1o4j/RmgV9E0CFmI HM8RKdqrIFPz7axrxKoDjBtZxAhYY8yijJFS37r0U9nkvf4fRUk1omlHNSrZrSBwKtpb eQnoW1rTJ2qhyOK2OqesYOS24Gx/r60jlB3K6KA5fRaRW+F0nm96Nu0hTFHjFNcUJZhn uZfA== X-Gm-Message-State: AOAM531WZ26rsZqfBn512dYAnaYXc08pmEhTHJSuqBtsKpJOEJ45t5Mi 5ht71rS/q48GkX8CGwT0ZXFsyPGJxviC9w== X-Received: by 2002:a05:600c:4fc7:: with SMTP id o7mr773623wmq.91.1633027947709; Thu, 30 Sep 2021 11:52:27 -0700 (PDT) Received: from localhost.localdomain (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id l124sm5487151wml.8.2021.09.30.11.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 11:52:27 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com Subject: [PATCH 2/3] virtio-iommu: Default to bypass during boot Date: Thu, 30 Sep 2021 19:50:50 +0100 Message-Id: <20210930185050.262759-3-jean-philippe@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210930185050.262759-1-jean-philippe@linaro.org> References: <20210930185050.262759-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x331.google.com 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: Jean-Philippe Brucker , qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently the virtio-iommu device must be programmed before it allows DMA from any PCI device. This can make the VM entirely unusable when a virtio-iommu driver isn't present, for example in a bootloader that loads the OS from storage. Similarly to the other vIOMMU implementations, default to DMA bypassing the IOMMU during boot. Add a "boot-bypass" option that lets users change this behavior. Signed-off-by: Jean-Philippe Brucker --- include/hw/virtio/virtio-iommu.h | 1 + hw/virtio/virtio-iommu.c | 28 +++++++++++++++++++++++----- hw/virtio/trace-events | 4 ++-- 3 files changed, 26 insertions(+), 7 deletions(-) -- 2.33.0 diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h index 273e35c04b..4c66989ca4 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -58,6 +58,7 @@ struct VirtIOIOMMU { GTree *domains; QemuMutex mutex; GTree *endpoints; + bool boot_bypass; }; #endif diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 1b23e8e18c..82edeaa101 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -728,8 +728,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 = s->config.bypass; sid = virtio_iommu_get_bdf(sdev); @@ -828,7 +827,8 @@ static void virtio_iommu_get_config(VirtIODevice *vdev, uint8_t *config_data) config->input_range.start, config->input_range.end, config->domain_range.end, - config->probe_size); + config->probe_size, + config->bypass); memcpy(config_data, &dev->config, sizeof(struct virtio_iommu_config)); } @@ -836,13 +836,29 @@ static void virtio_iommu_set_config(VirtIODevice *vdev, const uint8_t *config_data) { struct virtio_iommu_config config; + VirtIOIOMMU *dev = VIRTIO_IOMMU(vdev); memcpy(&config, config_data, sizeof(struct virtio_iommu_config)); + + if (config.bypass != dev->config.bypass) { + if (!virtio_vdev_has_feature(vdev, VIRTIO_IOMMU_F_BYPASS_CONFIG)) { + virtio_error(vdev, "cannot set config.bypass"); + return; + } + if (config.bypass != 0 && config.bypass != 1) { + warn_report("invalid config.bypass value '%d'", config.bypass); + dev->config.bypass = 0; + return; + } + dev->config.bypass = config.bypass; + } + 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.bypass); } static uint64_t virtio_iommu_get_features(VirtIODevice *vdev, uint64_t f, @@ -986,6 +1002,7 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) s->config.input_range.end = -1UL; s->config.domain_range.end = 32; s->config.probe_size = VIOMMU_PROBE_SIZE; + s->config.bypass = s->boot_bypass; virtio_add_feature(&s->features, VIRTIO_RING_F_EVENT_IDX); virtio_add_feature(&s->features, VIRTIO_RING_F_INDIRECT_DESC); @@ -993,9 +1010,9 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) virtio_add_feature(&s->features, VIRTIO_IOMMU_F_INPUT_RANGE); virtio_add_feature(&s->features, VIRTIO_IOMMU_F_DOMAIN_RANGE); virtio_add_feature(&s->features, VIRTIO_IOMMU_F_MAP_UNMAP); - virtio_add_feature(&s->features, VIRTIO_IOMMU_F_BYPASS); virtio_add_feature(&s->features, VIRTIO_IOMMU_F_MMIO); virtio_add_feature(&s->features, VIRTIO_IOMMU_F_PROBE); + virtio_add_feature(&s->features, VIRTIO_IOMMU_F_BYPASS_CONFIG); qemu_mutex_init(&s->mutex); @@ -1169,6 +1186,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(), }; diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 8ed19e9d0c..6bc3821ba3 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -90,8 +90,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, uint8_t bypass) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_range=%d probe_size=0x%x bypass=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, uint8_t bypass) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x bypass=0x%x" 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 Thu Sep 30 18:50:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 514971 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp65224jaf; Thu, 30 Sep 2021 11:54:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJluHJ+fj41X/Hkh2UN4t6ro2t5jigJnmHVNcPmUN7CkxTgPs4vfr+Jq07C4l/6LkBZzp5 X-Received: by 2002:ac8:1e86:: with SMTP id c6mr8201099qtm.21.1633028042845; Thu, 30 Sep 2021 11:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633028042; cv=none; d=google.com; s=arc-20160816; b=NzIRD3XvHemWP5ThDq9IWjgEFDDPVj6bU8qqt5jFwbCRoWv2cClNG9wndUrp87uJMK h53L9LRVrxZvdZXzhXMuU1hNLxoKuMdbhF3ZWw/8Wv5lOQjuYgw0umnRHQ5yiidaPJBW HCsvnhPqnBFsLISMOiqzN2wOXmnnwSBHRCTMNmQtyWm+vqTRQ0pntsHUm/FfRT/sB3/2 p9qPD5N3qeAe059u3AaRxK4zlvLLuCtR7A1A/I9piXCmO/bVohU7/39xbmc+ZSWPyLPa rjitSxpX207PHe03Sx0E3MXNzr65qegCpLBpND8Q4C8j7VSuzvWXPpytODvfNyovWsp8 tZ5Q== 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=m263Z0MNZ9eUo84q1kegZSPB7SgF/ZysplashCzc5DE=; b=HGgca5r+FbVxpEs3QDPRgwIPtWJos8dLyzCcNuru8WmubM3WqrQgZU9agTKBYXMNL0 5qBZXkgzE1smar7XDPhaaJFywH2PwYUZDQMPZJTQjQ9bRRA7zC+PmJfteKxQ93ZOabPs Nc7snLZ63YVvcfXD1JAmSqRiNXcsmK4b2+xaL8AJOsjCd686yGjg5yMH1Lk6EOlDP33a GWAmvj/QjYRQdzOknsAqXEUVWR0b2OEUFFYCSoewzLVf5uNqrlVYYfAiC8FKs8h5AEIF 8WDWFr+kZOUaeM5LINc52vsFL8LbnDm7O861+eaGAFRcLKaPH7NnXlJYbePLI2ncoWOj YBmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Qzb02E1v; 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 k11si2306407qtg.226.2021.09.30.11.54.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Sep 2021 11:54:02 -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=Qzb02E1v; 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]:43614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mW1By-0001F2-5I for patch@linaro.org; Thu, 30 Sep 2021 14:54:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mW1AV-0001C9-Oh for qemu-devel@nongnu.org; Thu, 30 Sep 2021 14:52:31 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:50690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mW1AT-0004LE-P7 for qemu-devel@nongnu.org; Thu, 30 Sep 2021 14:52:31 -0400 Received: by mail-wm1-x32b.google.com with SMTP id j27so5473517wms.0 for ; Thu, 30 Sep 2021 11:52: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=m263Z0MNZ9eUo84q1kegZSPB7SgF/ZysplashCzc5DE=; b=Qzb02E1vvwhwz9YJulKPE033dXvAppjtW6r8b7nywLNXl0coowTcU53r/19Fz3NJLb dLve29YhnYx2GrseAD/2yq7hR5jxg1I3b/NQviN+ISKoSHOwZOylFI/mmA1ibsGavAxw ItXy4T2x0CIPSbidH67QlNza1Xc7n3KsB5xlvDi9eZoXvv60cElelbSczohu8p6F5+nP n/KpLp1P9KBZEHNXz+Kw9WHnVcNAPTa2LXNeKdYR5uDW+dB9/5YFxM/XvJFiEubM5HLJ jFYTGIIAxvlAqf/UuQ/mGb2EV7D4OMgSKKhGTuQyhWR+kUTZdvlR1KOHi4N3YNIn0gZi lH/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m263Z0MNZ9eUo84q1kegZSPB7SgF/ZysplashCzc5DE=; b=fgieLzkQgl37bFzkvVNiVhdQYELX6Wqn22yv5iycDXRFkVj7+XZpINmhN0hfYvn7ST Z+H1kepgbYWOC/Eg3xY2TdWFxREO8hUxjfmYlWrX0on4pFGetx5n9RVZXthJj4HW2GRJ AsUEaFo24sS9qdo6peZeMdkQf9ULnpyLxtlBIHtT4LRoIfiPvQIuFgf7rbJ/Vdg4rJD6 M1aIk6casaH6CJDRyaMR10EhzCfWw4go2j6OskoXfUOhk37dG3zgRF/YMqozHzzbhwwn YaZgPewIoLgfqXHhpIt+dnSC6rQyuBgqZgcyclKKH46U1R/LJGCb80GNp8sw7P0KNhE6 5Q2Q== X-Gm-Message-State: AOAM5306mDLM86eHIzwVJCKa4tcaIt8mgovvXRWzpIeNePpI6OvzbreT JsN3au37eZwKWybWmvWa+ZRlTg== X-Received: by 2002:a05:600c:41c2:: with SMTP id t2mr704530wmh.16.1633027948494; Thu, 30 Sep 2021 11:52:28 -0700 (PDT) Received: from localhost.localdomain (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id l124sm5487151wml.8.2021.09.30.11.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 11:52:28 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com Subject: [PATCH 3/3] virtio-iommu: Support bypass domain Date: Thu, 30 Sep 2021 19:50:51 +0100 Message-Id: <20210930185050.262759-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210930185050.262759-1-jean-philippe@linaro.org> References: <20210930185050.262759-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) 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: Jean-Philippe Brucker , qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The driver can create a bypass domain by passing the VIRTIO_IOMMU_ATTACH_F_BYPASS flag on the ATTACH request. Bypass domains perform slightly better than domains with identity mappings since they skip translation. Signed-off-by: Jean-Philippe Brucker --- hw/virtio/virtio-iommu.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) -- 2.33.0 diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 82edeaa101..4f0207a3eb 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -42,6 +42,7 @@ typedef struct VirtIOIOMMUDomain { uint32_t id; + bool bypass; GTree *mappings; QLIST_HEAD(, VirtIOIOMMUEndpoint) endpoint_list; } VirtIOIOMMUDomain; @@ -257,12 +258,16 @@ static void virtio_iommu_put_endpoint(gpointer data) } static VirtIOIOMMUDomain *virtio_iommu_get_domain(VirtIOIOMMU *s, - uint32_t domain_id) + uint32_t domain_id, + bool bypass) { VirtIOIOMMUDomain *domain; domain = g_tree_lookup(s->domains, GUINT_TO_POINTER(domain_id)); if (domain) { + if (domain->bypass != bypass) { + return NULL; + } return domain; } domain = g_malloc0(sizeof(*domain)); @@ -270,6 +275,7 @@ static VirtIOIOMMUDomain *virtio_iommu_get_domain(VirtIOIOMMU *s, domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp, NULL, (GDestroyNotify)g_free, (GDestroyNotify)g_free); + domain->bypass = bypass; g_tree_insert(s->domains, GUINT_TO_POINTER(domain_id), domain); QLIST_INIT(&domain->endpoint_list); trace_virtio_iommu_get_domain(domain_id); @@ -333,11 +339,16 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, { uint32_t domain_id = le32_to_cpu(req->domain); uint32_t ep_id = le32_to_cpu(req->endpoint); + uint32_t flags = le32_to_cpu(req->flags); VirtIOIOMMUDomain *domain; VirtIOIOMMUEndpoint *ep; trace_virtio_iommu_attach(domain_id, ep_id); + if (flags & ~VIRTIO_IOMMU_ATTACH_F_BYPASS) { + return VIRTIO_IOMMU_S_INVAL; + } + ep = virtio_iommu_get_endpoint(s, ep_id); if (!ep) { return VIRTIO_IOMMU_S_NOENT; @@ -355,7 +366,12 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, } } - domain = virtio_iommu_get_domain(s, domain_id); + domain = virtio_iommu_get_domain(s, domain_id, + flags & VIRTIO_IOMMU_ATTACH_F_BYPASS); + if (!domain) { + /* Incompatible flags */ + return VIRTIO_IOMMU_S_INVAL; + } QLIST_INSERT_HEAD(&domain->endpoint_list, ep, next); ep->domain = domain; @@ -418,6 +434,10 @@ static int virtio_iommu_map(VirtIOIOMMU *s, return VIRTIO_IOMMU_S_NOENT; } + if (domain->bypass) { + return VIRTIO_IOMMU_S_INVAL; + } + interval = g_malloc0(sizeof(*interval)); interval->low = virt_start; @@ -463,6 +483,11 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, if (!domain) { return VIRTIO_IOMMU_S_NOENT; } + + if (domain->bypass) { + return VIRTIO_IOMMU_S_INVAL; + } + interval.low = virt_start; interval.high = virt_end; @@ -779,6 +804,9 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, entry.perm = flag; } goto unlock; + } else if (ep->domain->bypass) { + entry.perm = flag; + goto unlock; } found = g_tree_lookup_extended(ep->domain->mappings, (gpointer)(&interval),