From nobody Mon Nov 17 01:27:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1602177533; cv=none; d=zohomail.com; s=zohoarc; b=RHBGwUlAAOxUHLNBfyCCJUdtA1e9wpMCUbMqeJa1ZrfPjuLPKAx0Z4Dk1b9hFFJjqProamEaQMf/UslRh2Hp6XQ0fSwcRH7CvECy0fuq9atexOf4NOIBW1W4Bu1XjopSTdWIdLOMKE81y+XW751ho4PKGOI6h59dpXavIuOPdYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602177533; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7wgbcRbIFliMePbKm6Q5mkeuUC4ljzQPMAK2NaADXH4=; b=NlM8g+usauoOERS3s59ruxsAq904bidSO/FElhM3bhxTQwJXSkogRoPHm698V9cvgC5EnhXvPtUfap9B9u4OagkWKVFIgoQYOUWhp1D2rmrgVAHbVkAcqm/e7a1VALmLXQ0qjKySD2XKyhKcDYnznST0K9AJSmJ7t0Il+YfwL5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602177533377395.5897613531055; Thu, 8 Oct 2020 10:18:53 -0700 (PDT) Received: from localhost ([::1]:50808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZZ6-0006ev-3a for importer@patchew.org; Thu, 08 Oct 2020 13:18:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXJ-0004wR-R7 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:17:01 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:39760) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXH-0006fh-W2 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:17:01 -0400 Received: by mail-wm1-x343.google.com with SMTP id d3so7298077wma.4 for ; Thu, 08 Oct 2020 10:16:59 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:57 -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=7wgbcRbIFliMePbKm6Q5mkeuUC4ljzQPMAK2NaADXH4=; b=rgYl28lo9ds5EHPl0QJhjUSisk9hqTi+rpnJ+tzy1oNSxphqXM+RSDQ+kUTk5a3SeO OHw4Hr8d4NQsXhQdJI+0jRq8+kqTArBO47w2Kun2wxsye3bNsGj41MlpTcGYwOoGn6+0 VT1detNeMxGshnx85IFnUMLBK7LmrvzT9bRDNoGSrJl1fMiPzRljktUvHXHPuqDAENzU HfCfYwdnjKaFLRy6+ctuyQNS9+qEvrn1IXRjdwBWizSiWOr6dloJjVJl6tEJ5/RqHua2 A3clYucgXXTD5kUkD6lxjM+ka4Trt4ObNM7vRpFBhPu+aE0Ckiy5s1ohlfPKdjgk/KG1 OxVg== 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=7wgbcRbIFliMePbKm6Q5mkeuUC4ljzQPMAK2NaADXH4=; b=ZTwh1BpvyWMoKXh5fqjPfD2lwYBNbZspih0WowPYn8+/eovcyILFk6RcSlGfXjkD5A +bXcbJEoJoRSTUhoGWMch/WR0ca3THTLhW3nU5y2nNQUvyK7Ns6qbeWhPVQBKFTkmOqJ 8THrf6QpdNu8W4BlPT16Wd5Hfw8H2FjFb5ETxYOYwvgRvkHg6zBwsrF8KiZdx/3Si4rV rfK+LjQ7bg94PyPmc10Gn1bSbtbvePIgGJRArS0WKyyG6P0qC5lGqSmhLSWFdLBZEw00 7RjVme3J8XD+94GSxw63BcWoXAJ1jxSAZJZCo9ePEX4fK3fJiNUL9yJj2CM4pRMm75Co D3bw== X-Gm-Message-State: AOAM533PoLcWfmVLLTl2iqLIZAJvhSoth/rtBZXf8MI9NI7yP3JbxLsF mTLrMsEofI/P7uw2sV1UGGzUDQ== X-Google-Smtp-Source: ABdhPJw7Hs3XKpGnf7TX8L0e5srtXTzJGGpauZIcG45vs78HB+CHxcBJCukiCuECFnYOQ8zOoW8XDg== X-Received: by 2002:a1c:b103:: with SMTP id a3mr10049448wmf.68.1602177418602; Thu, 08 Oct 2020 10:16:58 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 09/10] virtio-iommu: Set supported page size mask Date: Thu, 8 Oct 2020 19:15:57 +0200 Message-Id: <20201008171558.410886-10-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-1-jean-philippe@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x343.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: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Bharat Bhushan The virtio-iommu device can deal with arbitrary page sizes for virtual endpoints, but for endpoints assigned with VFIO it must follow the page granule used by the host IOMMU driver. Implement the interface to set the vIOMMU page size mask, called by VFIO for each endpoint. We assume that all host IOMMU drivers use the same page granule (the host page granule). Override the page_size_mask field in the virtio config space. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker --- v10: Use global page mask, allowing VFIO to override it until boot. --- hw/virtio/virtio-iommu.c | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 8823bfc804a..dd0b3093d1b 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -914,6 +914,56 @@ static int virtio_iommu_notify_flag_changed(IOMMUMemor= yRegion *iommu_mr, return 0; } =20 +static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr, + uint64_t page_size_mask, + Error **errp) +{ + int new_granule, old_granule; + IOMMUDevice *sdev =3D container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s =3D sdev->viommu; + + if (!page_size_mask) { + return -1; + } + + new_granule =3D ctz64(page_size_mask); + old_granule =3D ctz64(s->config.page_size_mask); + + /* + * Modifying the page size after machine initialization isn't supporte= d. + * Having a different mask is possible but the guest will use sub-opti= mal + * block sizes, so warn about it. + */ + if (qdev_hotplug) { + if (new_granule !=3D old_granule) { + error_setg(errp, + "virtio-iommu page mask 0x%"PRIx64 + " is incompatible with mask 0x%"PRIx64, + s->config.page_size_mask, page_size_mask); + return -1; + } else if (page_size_mask !=3D s->config.page_size_mask) { + warn_report("virtio-iommu page mask 0x%"PRIx64 + " does not match 0x%"PRIx64, + s->config.page_size_mask, page_size_mask); + } + return 0; + } + + /* + * Disallow shrinking the page size. For example if an endpoint only + * supports 64kB pages, we can't globally enable 4kB pages. But that + * shouldn't happen, the host is unlikely to setup differing page gran= ules. + * The other bits are only hints describing optimal block sizes. + */ + if (new_granule < old_granule) { + error_setg(errp, "memory region shrinks the virtio-iommu page gran= ule"); + return -1; + } + + s->config.page_size_mask =3D page_size_mask; + return 0; +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -1146,6 +1196,7 @@ static void virtio_iommu_memory_region_class_init(Obj= ectClass *klass, imrc->translate =3D virtio_iommu_translate; imrc->replay =3D virtio_iommu_replay; imrc->notify_flag_changed =3D virtio_iommu_notify_flag_changed; + imrc->iommu_set_page_size_mask =3D virtio_iommu_set_page_size_mask; } =20 static const TypeInfo virtio_iommu_info =3D { --=20 2.28.0