From nobody Fri Dec 19 04:51:03 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB246266EE1 for ; Fri, 14 Feb 2025 15:17:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546248; cv=none; b=Ij7vqJLuBq43Q4p6lIasjEy0FUghkymog+U0FaaZ4KraIsqxQv9JZWZvUaju0eHvLTNNflwuP6tAUwSSgQTv+2awT3odNT/Bkv4V4GwR3jHU7+3ex/3hUs6jxeNxW+QwZkT33yZa+frJjvNGDtl2L7qPyN7Cw3JqFWVSV3KT7Xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546248; c=relaxed/simple; bh=8Gsx73LZ9WPOVGpMBiCSKKybBmw0f/p67JPch1vqO7A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NWR6jo6u2rqLKdAEBe4O02U7qonYcatRZsdUsjgqLEfTk9/t6A5gCVxVJLqOJhIl0LSxwMBIKtdmf4mOC/UhYkuR6N7A67zQLTbztMQmkSXS25jMocSMjDavXyezGJCw+xxw5aFHhK79fnVtl2QSnz3Rk5P4C6sZQMkTlJgvATU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Vikq2uAW; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Vikq2uAW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739546246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nrLVSx70Fg0TM3/b/6u0W/Ki7vueT18k7SYrETRcIbc=; b=Vikq2uAWSOEA7m5djieLoY8JBoGQchKtpzRq3RYcZjOIFmkTAxR7M+XI9kGKSRyz2W7258 K/EGquX5c3Sj2I4aGnnVWt8/bUT3OxuUM0f+eJiKPWRizVV0AW7/puhlt8RDBipCIcMP2p lhmxlhjgSDXTnNBM9ZsHIZSpF8TdvGw= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-48-trFNyZdhOTWBOp6J3u-xhw-1; Fri, 14 Feb 2025 10:17:22 -0500 X-MC-Unique: trFNyZdhOTWBOp6J3u-xhw-1 X-Mimecast-MFC-AGG-ID: trFNyZdhOTWBOp6J3u-xhw_1739546240 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 939AA1944D00; Fri, 14 Feb 2025 15:17:20 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.8]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DCA19191D7CE; Fri, 14 Feb 2025 15:17:13 +0000 (UTC) From: Sergio Lopez Date: Fri, 14 Feb 2025 16:16:55 +0100 Subject: [PATCH RFC v2 1/5] virtio_config: add page_size field to virtio_shm_region Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250214-virtio-shm-page-size-v2-1-aa1619e6908b@redhat.com> References: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> In-Reply-To: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> To: "Michael S. Tsirkin" , Daniel Verkamp , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Simona Vetter , Rob Clark , Dmitry Osipenko , fnkl.kernel@gmail.com Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Sergio Lopez X-Developer-Signature: v=1; a=openpgp-sha256; l=1729; i=slp@redhat.com; h=from:subject:message-id; bh=8Gsx73LZ9WPOVGpMBiCSKKybBmw0f/p67JPch1vqO7A=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBnr15sWESJ+OzItEn3E8aaGSdbpX3pjWcxS8IOP b8BlyFqbsSJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ69ebAAKCRD0aSeNLwwC NdCFEACKtfP+IDc9rU4MZKQUdP0BbdgCZvIPrMqQ3S7fOP3xQN6FfkE0nn3/328NZUcR6GioIDs dfJH//humQuU77NKJ2b1r8RdCtAcD/zoktVOND1pRocXLBVEthAUnB5849+dTVpQn5gUvlLQjwt 2WWkL3GFigTp3FWcHc2eWhfYZbOBVIG56aEvMsXsJvaERigb0mIuMRgm7UdvIgcZTrYwnRRoSUW Th/rKyGZBLXEZujoVAvG5ZkJ/yw5GPBC0hv3Jc1XT7glnD56bRcmIrVY+NzMyU4J8uEpr4V9m+E 90N6qNYALgXYU9p6qbp70W4RBlLg6RbPbXovzl9fGjbVlJvEw4s3HA9I5C7of4nB6aH5n9G9fIh Au4nmVaG/B9C+FOsEbU3macr9EcCQisemNfAA4BFpRLWWZobW8MvJ6y/1vBV32yYyglb/QKjnH2 X7c30s4RSpdqBSm9qfUz7sf8E472OM7OubFHMEl4IXgWYoGgS6PQZQbJliYtNCvzsoiKKqfWMoV 2zMMDNbsPcug6VyQXKTX/v8n+6Rfr/Wlp0ysyPQrfCT2EOr7TfoWXFT/V50OW2w3JA6f9krV8rW BRla51VKOG/wdZErOX3fckyC/54y0hgre/gYkbD9nILZKizKRRERN4aIrl08PI9LwZa17tqp9kC Y4NLiuXBnbPBDUg== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Add a page_size field to virtio_shm_region to store page size supported by the device. This is required to support running VMs with a page size smaller than the host, among other potential scenarios. Signed-off-by: Sergio Lopez --- drivers/virtio/virtio_mmio.c | 2 ++ drivers/virtio/virtio_pci_modern.c | 1 + include/linux/virtio_config.h | 1 + 3 files changed, 4 insertions(+) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index 5d78c2d572abfcfe2b84cdd82df622320fe97d5d..1f594b626d7a7734e8ec5876673= 7a118c26bad94 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -560,6 +560,8 @@ static bool vm_get_shm_region(struct virtio_device *vde= v, =20 region->addr =3D addr; =20 + region->page_size =3D 4096; + return true; } =20 diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci= _modern.c index 5eaade7578606e4b02af0d66447417ad6aa11064..d7aeb2e50a3c499dfb68d58cb89= b829ea2e50454 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -862,6 +862,7 @@ static bool vp_get_shm_region(struct virtio_device *vde= v, =20 region->len =3D len; region->addr =3D (u64) phys_addr + offset; + region->page_size =3D 4096; =20 return true; } diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 169c7d367facb36dcabf9596068580ea8b8516c7..c1b2ce71ea55e81978e18db0549= 4deab193fa4fb 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -14,6 +14,7 @@ struct irq_affinity; struct virtio_shm_region { u64 addr; u64 len; + u32 page_size; }; =20 typedef void vq_callback_t(struct virtqueue *); --=20 2.48.1 From nobody Fri Dec 19 04:51:03 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 344452586F3 for ; Fri, 14 Feb 2025 15:17:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546257; cv=none; b=cCuxgKTtB+PM81hEEERkSMuaIEmvGbXsCh/VMwWQVNz08bv6hA7F3jp6CHp5vRbjA+V8VeGonmMbw0WSbHrh3BZ71JTyi2FBvKXH6ic8Snx+nXoBBGKPdYkMWh7KO9fn93sEQE7+OIR5usQXpAB5GltE0ABo/XCy2QnvZIetYqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546257; c=relaxed/simple; bh=4QcTCYeEiFXjqS+XrMv1FhbL69PRzpsj9vK8zReTdEE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KiCWeoOO2Vpzuunhp5VHI7AE02LjRIuFe0ks3dF0di9dk5hPxXJ68cemduPQao5/lYnc+f8YT4jE2EqhFqp8VOCvx0nzBIvpG4iqvP5jj3NTuv/ciIHUcaykfnKeq+WjaFyseYsZ7/5gSaK+dUuPbSbykbjrtx7f5p9EOcdNnww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TodWrV9A; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TodWrV9A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739546254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Uvb7bYa9Ne8SlfnrGE22VOdL8DG3p7aSwPX9jSVaTk=; b=TodWrV9A+Ypv5ei39X6sefWlWsvEWK2c2kGLFXWbBT3KD+WSyO5wfnMDv/Y68cuXxV5WFB /aQrliq+4jTTUAnewtIQn9WhFP2hz5TbOtojxQHSQb7HTYtgFuVa7TaRsYxuAjXs8mmImg PVpz1FqafTTir1NN4VNDKS4FDceO8f0= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-55-f8IZxBFHP5yk8uRYiD9qVQ-1; Fri, 14 Feb 2025 10:17:30 -0500 X-MC-Unique: f8IZxBFHP5yk8uRYiD9qVQ-1 X-Mimecast-MFC-AGG-ID: f8IZxBFHP5yk8uRYiD9qVQ_1739546247 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 702101800874; Fri, 14 Feb 2025 15:17:27 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.8]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 210F219373C4; Fri, 14 Feb 2025 15:17:20 +0000 (UTC) From: Sergio Lopez Date: Fri, 14 Feb 2025 16:16:56 +0100 Subject: [PATCH RFC v2 2/5] virtio: introduce VIRTIO_F_SHM_PAGE_SIZE Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250214-virtio-shm-page-size-v2-2-aa1619e6908b@redhat.com> References: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> In-Reply-To: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> To: "Michael S. Tsirkin" , Daniel Verkamp , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Simona Vetter , Rob Clark , Dmitry Osipenko , fnkl.kernel@gmail.com Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Sergio Lopez X-Developer-Signature: v=1; a=openpgp-sha256; l=2345; i=slp@redhat.com; h=from:subject:message-id; bh=4QcTCYeEiFXjqS+XrMv1FhbL69PRzpsj9vK8zReTdEE=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBnr15tvWt9Axv+YNZc1miTy/xjWRzL/C+1gA9YT fvZe6xw9OiJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ69ebQAKCRD0aSeNLwwC NUWLD/0a6MqcTXdKDD5awJeigZBKrFm0xA1a3LKLfHry0m5xXJwW8mQ74DGHp9xfJtcMl59ZhDy 26UXYmVAKc3AAX+mTbg2qHa0MtFsnSf3WbddjQfOKaf9/NDzUHi8CqOVE8w/mv5Gph3eY61d3mF pWd9/BAcmh+o5QdlPgzlg0wo0HG/3rfPH9z4yc3x/pHEUj61cbplLrXb5iTCM26WzrzO7Pr/t0E 95mBwNMK21+cu0VPXpYacuje2cXqj0A2xQ5Wj7WyhcA0tMOFzXYpSUe+NS/ULNFws0GvBCkUq9e 7tHDhOINcocGdmn21+0wDp1rh3hjq4S4i5ODDBUquMYoQ4+0CcfbyYJSE7u6mcOz3iFj0ok7Gwg hS7R8Foa7iWI+U0FcYXZc1fOrq8l7IEAVxZ6CvhOe6QJtDAJNVXqXCHBtuxK9947k59aowNloCq 4b15XpGnSVJkFYXYg33a8mNxhU5C+1mBJpKiQdXBh8pVDtBcKMuV20s0+ypBdmaSZnxGsZrePOr km5c7MB7nZZZq8sjWT1q5fleg6ETy5x/7nOv+zdfXSa5OpqdojBADgReKI0FLcG4ihD6Az6MFzm AU21wzwI2uCPVrcTHDaCls5bKCeZ4TSeW0+Mv8qkcelXCTrNK/0QN2UP1UkKVabQ9Pm2xaGUStN zyu2o7/TSETOcZA== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Introduce VIRTIO_F_SHM_PAGE_SIZE, a feature bit which indicates that the transport provides the page size for SHM regions. Signed-off-by: Sergio Lopez Reviewed-by: Dmitry Osipenko --- drivers/virtio/virtio_pci_modern.c | 3 +++ drivers/virtio/virtio_ring.c | 2 ++ include/uapi/linux/virtio_config.h | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci= _modern.c index d7aeb2e50a3c499dfb68d58cb89b829ea2e50454..ab0e1d9148057c431676bfacfe5= f68cc97eebb12 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -367,6 +367,9 @@ static void vp_transport_features(struct virtio_device = *vdev, u64 features) =20 if (features & BIT_ULL(VIRTIO_F_ADMIN_VQ)) __virtio_set_bit(vdev, VIRTIO_F_ADMIN_VQ); + + if (features & BIT_ULL(VIRTIO_F_SHM_PAGE_SIZE)) + __virtio_set_bit(vdev, VIRTIO_F_SHM_PAGE_SIZE); } =20 static int __vp_check_common_size_one_feature(struct virtio_device *vdev, = u32 fbit, diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index fdd2d2b07b5a2aca864bc917306536685afb66a6..d853d5cf7e553be8bbe0ff461dc= 7312b258c6e58 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2983,6 +2983,8 @@ void vring_transport_features(struct virtio_device *v= dev) break; case VIRTIO_F_NOTIFICATION_DATA: break; + case VIRTIO_F_SHM_PAGE_SIZE: + break; default: /* We don't understand this bit. */ __virtio_clear_bit(vdev, i); diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio= _config.h index 2445f365bce74b4e926c6929322b269252ab6830..3171e3792263c2cd472ac09da18= e593ab400751d 100644 --- a/include/uapi/linux/virtio_config.h +++ b/include/uapi/linux/virtio_config.h @@ -52,7 +52,7 @@ * rest are per-device feature bits. */ #define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 42 +#define VIRTIO_TRANSPORT_F_END 43 =20 #ifndef VIRTIO_CONFIG_NO_LEGACY /* Do we get callbacks when the ring is completely used, even if we've @@ -120,4 +120,9 @@ */ #define VIRTIO_F_ADMIN_VQ 41 =20 +/* + * This feature indicates that the transport provides the SHM page size. + */ +#define VIRTIO_F_SHM_PAGE_SIZE 42 + #endif /* _UAPI_LINUX_VIRTIO_CONFIG_H */ --=20 2.48.1 From nobody Fri Dec 19 04:51:03 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 335222673AD for ; Fri, 14 Feb 2025 15:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546262; cv=none; b=tmgB3A+GXDdGY3ZfZPTLGiRaft7sIKboSN181MG8+UBHsDPC+Cwc6/DaMbjkWxx2abLBxqrqKcQSaZ5Bew3acgf/xzV8aw9l2yJ/VlrUEAZscsE6HtwVPYNGoQrLUI2v5fy7ABZhb6yS87RVX7WFA4qwcbuRv7RkV1Z8SOvUIIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546262; c=relaxed/simple; bh=7EDZ4tXBkHpIJ9CoAo/NVeLfmDjVx9PeVjky5GHdvhY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rP2BTpZahCHpbfJf3xf47+m9Aeq8IonQv1IwWjl2DxZODJt6aTuEho5brlg2JmlWFEaZRg9rcpkkMKTEWO8S7Q4QfCe8yL3nbtZh1P9Z0CUqBZy4C6aTmK+5sLGQccyUMBNL3EFKq+zxmFb25Y+WqvAuzc4obLhk7WuxFgP9THg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fc4y4bbv; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fc4y4bbv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739546260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DekdyXlfpswcUHk0jxahOCfTGUZTgIpr9Gk6V3yn7pg=; b=fc4y4bbvVoOWSWybRnxbzXlNboCoSG+th2JbY/kWkwVHCogzl5Bak2f19FqqtmOV7GuEuM wUJgFc97ZDR8t1iSf5l+uKC0C0j3PGsVWwhKEZQYdBnxRrj1n5rrWlZaoBp3WWxhfb3jk4 3F7b2SkK/tvleIWvb4hlI5vmMx0pceM= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-q-KyvkXDMtiAAc9C7OVc4A-1; Fri, 14 Feb 2025 10:17:37 -0500 X-MC-Unique: q-KyvkXDMtiAAc9C7OVc4A-1 X-Mimecast-MFC-AGG-ID: q-KyvkXDMtiAAc9C7OVc4A_1739546255 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D4B55196E078; Fri, 14 Feb 2025 15:17:34 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.8]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F0EFE19373C4; Fri, 14 Feb 2025 15:17:27 +0000 (UTC) From: Sergio Lopez Date: Fri, 14 Feb 2025 16:16:57 +0100 Subject: [PATCH RFC v2 3/5] virtio-pci: extend virtio_pci_cap with page_shift Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250214-virtio-shm-page-size-v2-3-aa1619e6908b@redhat.com> References: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> In-Reply-To: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> To: "Michael S. Tsirkin" , Daniel Verkamp , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Simona Vetter , Rob Clark , Dmitry Osipenko , fnkl.kernel@gmail.com Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Sergio Lopez X-Developer-Signature: v=1; a=openpgp-sha256; l=3924; i=slp@redhat.com; h=from:subject:message-id; bh=7EDZ4tXBkHpIJ9CoAo/NVeLfmDjVx9PeVjky5GHdvhY=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBnr15uwGf8F4G/kehICMQxKpgR7le2iueBrH1IB aoMt7iEgSGJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ69ebgAKCRD0aSeNLwwC Ndz6EAC6GcgM/kZfZqEP8xpFrXioeEAjpawCwoV+Askh+9a1h8ZJSu/SpecP0DwgyTlPUbMgZeK YHSLk3xb1lrg/CSGqca6U6H+P69Lqbp43umLKMSWxHfna4X6ZoXvBNAlj/HyD2GK8vi3+fFZ9nN iDuhIegUdr+PUJ0ciB/1QCEv34SQBs4ERnXzEA1QEN3P99xMxElEq0HT9BCnOengxeMN9+448L6 kFd0qcQ0oSud1d6Y7PGauuNTYfZSnENgRadBPWG0/5kvU2vJSIeox0m9+cYvTimqivcr7z9rZNV WTph/DVUzY5OtdSh1ouGYxuu0rtVZ5ndpJMcAz4aa/YVmuMIl9ulgwdfStEsawj6g5SQZYREif/ qTy2x/rWqU7pYnX9F2tWJ82s1oecKgeI1U+bxjxs5/Z5Pky6HDtCDZeDK/ptbd3s53Re3Xc+baF uorEbyAOwX7w4z3pcHn6F9Bgha0Mol55K07rFhFC5o9yxvV7PoEQbgr/foJ0Ez/Ef1zZIiPaNsc c9CIjO+g/XNz2TT4NlcHWbgJda5E2u+FD5PASOoqNcYUZ8SPVV/ReLstfgnbfDQDnQ/4fGs193p sMLz9TFusIuGNc+TtTQcUprSUdgf6HMXZtmLdAZDP7dkNb7Z/iLxBjq+E8L4V+Ozwr++sitQwGC yCBsbwv4qVmJrEg== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 If VIRTIO_F_SHM_PAGE_SIZE has been negotiated and cfg_type is VIRTIO_PCI_CAP_SHARED_MEMORY_CFG, the driver must read the page_shift field, derive the supported page size from it, and honor it when requesting the map of memory into the shared memory region to the device. Extend virtio_pci_cap to hold that field, and use it to feed virtio_shm_region with the corresponding page size. Signed-off-by: Sergio Lopez Reviewed-by: Dmitry Osipenko --- drivers/virtio/virtio_pci_modern.c | 22 +++++++++++++++++----- include/uapi/linux/virtio_pci.h | 3 ++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci= _modern.c index ab0e1d9148057c431676bfacfe5f68cc97eebb12..562a8e1c2bfe6876cffabe26f02= cd61ad7fea2cd 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -770,14 +770,15 @@ static void del_vq(struct virtio_pci_vq_info *info) vring_del_virtqueue(vq); } =20 -static int virtio_pci_find_shm_cap(struct pci_dev *dev, u8 required_id, - u8 *bar, u64 *offset, u64 *len) +static int virtio_pci_find_shm_cap(struct virtio_device *vdev, struct pci_= dev *dev, + u8 required_id, u8 *bar, u64 *offset, u64 *len, + u32 *page_size) { int pos; =20 for (pos =3D pci_find_capability(dev, PCI_CAP_ID_VNDR); pos > 0; pos =3D pci_find_next_capability(dev, pos, PCI_CAP_ID_VNDR)) { - u8 type, cap_len, id, res_bar; + u8 type, cap_len, id, res_bar, page_shift =3D 0; u32 tmp32; u64 res_offset, res_length; =20 @@ -808,6 +809,15 @@ static int virtio_pci_find_shm_cap(struct pci_dev *dev= , u8 required_id, * Looks good. */ =20 + /* Read the page shift if supported. The page_shift variable is + * initialized to zero above, so if this feature isn't supported it + * will result in a page_size of 4096, a default safe value. + */ + if (__virtio_test_bit(vdev, VIRTIO_F_SHM_PAGE_SIZE)) { + pci_read_config_byte(dev, pos + offsetof(struct virtio_pci_cap, + page_shift), &page_shift); + } + /* Read the lower 32bit of length and offset */ pci_read_config_dword(dev, pos + offsetof(struct virtio_pci_cap, offset), &tmp32); @@ -829,6 +839,7 @@ static int virtio_pci_find_shm_cap(struct pci_dev *dev,= u8 required_id, *bar =3D res_bar; *offset =3D res_offset; *len =3D res_length; + *page_size =3D 1 << (page_shift + 12); =20 return pos; } @@ -841,11 +852,12 @@ static bool vp_get_shm_region(struct virtio_device *v= dev, struct virtio_pci_device *vp_dev =3D to_vp_device(vdev); struct pci_dev *pci_dev =3D vp_dev->pci_dev; u8 bar; + u32 page_size; u64 offset, len; phys_addr_t phys_addr; size_t bar_len; =20 - if (!virtio_pci_find_shm_cap(pci_dev, id, &bar, &offset, &len)) + if (!virtio_pci_find_shm_cap(vdev, pci_dev, id, &bar, &offset, &len, &pag= e_size)) return false; =20 phys_addr =3D pci_resource_start(pci_dev, bar); @@ -865,7 +877,7 @@ static bool vp_get_shm_region(struct virtio_device *vde= v, =20 region->len =3D len; region->addr =3D (u64) phys_addr + offset; - region->page_size =3D 4096; + region->page_size =3D page_size; =20 return true; } diff --git a/include/uapi/linux/virtio_pci.h b/include/uapi/linux/virtio_pc= i.h index 8549d4571257142ac6c9dad5c01369923791a85a..1a76df52b4eccf548df78a8ee7d= 3a04591f55522 100644 --- a/include/uapi/linux/virtio_pci.h +++ b/include/uapi/linux/virtio_pci.h @@ -127,7 +127,8 @@ struct virtio_pci_cap { __u8 cfg_type; /* Identifies the structure. */ __u8 bar; /* Where to find it. */ __u8 id; /* Multiple capabilities of the same type */ - __u8 padding[2]; /* Pad to full dword. */ + __u8 page_shift; /* Page shift for VIRTIO_PCI_CAP_SHARED_MEMORY_CFG. */ + __u8 padding[1]; /* Pad to full dword. */ __le32 offset; /* Offset within bar. */ __le32 length; /* Length of the structure, in bytes. */ }; --=20 2.48.1 From nobody Fri Dec 19 04:51:03 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53BD92673A8 for ; Fri, 14 Feb 2025 15:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546270; cv=none; b=NYRIw4QU08qvb0W7QDsMupQwgl6O9LFUV2BtlmmkUqrppx7PXGyA4jvYSIpVcSsBfhFB53EpQTjlEoNLOXIMUxHV6S1TKfyCgQHTC6I4TfDmy7hHl9QzxC8G3WM0C4bi59JQkBk+lKeX00LiESllxDwz2GPv5dhyDOQfSZri4SI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546270; c=relaxed/simple; bh=bFNAeiutqaKlzP1FD1cFK1Z9ZYhJkQlnMXqcmyttT0U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BQ6LEBQDKvHkk35PD+aF9Zonp/5K0oGSK5XKOSqueFd77uL3F31UjcraNXJIDrbEhLnsyB5qUsedWxutZaOKNxFeMUYP2kMwpSlWnnRWI7BxnfEs7RBFjp2txMiYe7XAzuZ4b4nwP8ug8fmSGyzX5oxWBbiTO6oaCnPBSqzmDG4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bePewpOe; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bePewpOe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739546267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=70XUhg1h3eaHyrcsKI0iPpsHIUl4Ui2L6Ps666PmFIk=; b=bePewpOe2QazhZTaQO8QXj4Zoan+rhliabtljKqiCNoa1RbSHzkboe05cZNqaz/qYms3qs O8kaSccnKxit0DvMZzyLqSrSd8hiu4jNds1C9iZpxSR9N/HXP96SfWMxsq2qXFuJpFGEMo NWOjS56QpGaJsY0UjP7L2/8rrvp4Aok= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-8wcthZH6NKqoVpfwU0TUpA-1; Fri, 14 Feb 2025 10:17:43 -0500 X-MC-Unique: 8wcthZH6NKqoVpfwU0TUpA-1 X-Mimecast-MFC-AGG-ID: 8wcthZH6NKqoVpfwU0TUpA_1739546261 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 61C631955F28; Fri, 14 Feb 2025 15:17:41 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.8]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 637C819373C4; Fri, 14 Feb 2025 15:17:35 +0000 (UTC) From: Sergio Lopez Date: Fri, 14 Feb 2025 16:16:58 +0100 Subject: [PATCH RFC v2 4/5] virtio-mmio: read shm region page size Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250214-virtio-shm-page-size-v2-4-aa1619e6908b@redhat.com> References: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> In-Reply-To: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> To: "Michael S. Tsirkin" , Daniel Verkamp , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Simona Vetter , Rob Clark , Dmitry Osipenko , fnkl.kernel@gmail.com Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Sergio Lopez X-Developer-Signature: v=1; a=openpgp-sha256; l=2084; i=slp@redhat.com; h=from:subject:message-id; bh=bFNAeiutqaKlzP1FD1cFK1Z9ZYhJkQlnMXqcmyttT0U=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBnr15vpsuLOT4QGRMWMhOlh38UgELGNfZ10v1z9 7t1WHXIhlmJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ69ebwAKCRD0aSeNLwwC NShRD/0euxKei/j8TGZULeworXe/uhUTALV4XHBFlpYT9nZtUDghsMKu0ELFUbSvmX/PydQPyBK MxRu0qTEcSd7gNnNRNwxdOFSAbGtYLPJfSjnkU+0HLJrX2Dp/zrDYlogJ4QaKhPgYAylfYv3+B0 if9t7wq8vXf9oa5bWgKt8Ihc2JRS93R8N8kD7j2QJ7eskFiuXyFViaCUGEDgpejov8hsGXVQaz1 WPBf2vEmgL9q/jOyRNd22AGUitAu8F1Z09lO6+KTlkNbM7FLi32gayd6ll8OPjP5EuN41H2dq6U vYeLI0Rw+8WpS+4RXAVsAetyiqC6qTuorAn36Y8Hu8T84YqOnHfr3z4rphxHyTQT8tNvYd2yu83 6bfVFDIfJZoZhHDzinIk0PBWkggStpR7NHPswEvK7OZva3V6ntHYWLwD9WNVsXOULf95Whcoclu SykvVezLdDgVLAZdXSR+weC3EV6XUgLOhohZe8tyMhLR/LQcew75/mxnQ+oiiVIZaPNFWP7nSQ0 wN3OI3r5mFCFzf2rqaTduUYwUk5nBFNbqKle7KsqGn8xOjeX7Bhksrb+sBlNKKMnbZ+slSOuUH/ 0c1BG2XCZ/JJZ79C0DxNh3gfIjF92x+TA2KtVrW9ZRYwoaBasQ2/4lzxYwksdiZ0P5+nUlWh5C9 NzJam9SWZ4kmtLw== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Use the newly introduced SHM_PAGE_SHIFT register to read the page shift for the shared memory region, derive the page size from it and store the resulting value into virtio_shm_region. Signed-off-by: Sergio Lopez Reviewed-by: Dmitry Osipenko --- drivers/virtio/virtio_mmio.c | 11 ++++++++++- include/uapi/linux/virtio_mmio.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index 1f594b626d7a7734e8ec58766737a118c26bad94..0f892770739ea84b3e7be561533= 2773049b10ab1 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -537,6 +537,7 @@ static bool vm_get_shm_region(struct virtio_device *vde= v, struct virtio_shm_region *region, u8 id) { struct virtio_mmio_device *vm_dev =3D to_virtio_mmio_device(vdev); + u8 page_shift =3D 0; u64 len, addr; =20 /* Select the region we're interested in */ @@ -560,7 +561,15 @@ static bool vm_get_shm_region(struct virtio_device *vd= ev, =20 region->addr =3D addr; =20 - region->page_size =3D 4096; + /* If supported by the device transport, read the region page size. + * The page_shift variable is initialized to zero above, so if this + * feature isn't supported it will result in a page_size of 4096, a + * default safe value. + */ + if (__virtio_test_bit(vdev, VIRTIO_F_SHM_PAGE_SIZE)) + page_shift =3D (u8) readl(vm_dev->base + VIRTIO_MMIO_SHM_PAGE_SHIFT); + + region->page_size =3D 1 << (page_shift + 12); =20 return true; } diff --git a/include/uapi/linux/virtio_mmio.h b/include/uapi/linux/virtio_m= mio.h index 0650f91bea6c70f935764070d825d181a2379afb..43348be30eff90ee228b6490b9d= 3c35ba4c50aa5 100644 --- a/include/uapi/linux/virtio_mmio.h +++ b/include/uapi/linux/virtio_mmio.h @@ -133,6 +133,9 @@ #define VIRTIO_MMIO_SHM_BASE_LOW 0x0b8 #define VIRTIO_MMIO_SHM_BASE_HIGH 0x0bc =20 +/* Shared memory region page shift */ +#define VIRTIO_MMIO_SHM_PAGE_SHIFT 0x0c4 + /* Configuration atomicity value */ #define VIRTIO_MMIO_CONFIG_GENERATION 0x0fc =20 --=20 2.48.1 From nobody Fri Dec 19 04:51:03 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2445022E3F1 for ; Fri, 14 Feb 2025 15:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546276; cv=none; b=tYzqWGPhyr+2P4jUBqNbpz8rJLrajbcW89772Y7PxPJV0Q+rlcERY9TPP5sTb5a9WG8aFr0301EdJGW1nJ0iRYWMOZMmrcGlIPpDh5MjkOjIEX3+2/AUi0Mq3LslhHY7+WyS5c10XCLn+67Oreq6TyeXObBnSsNUKUMY4ECce/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739546276; c=relaxed/simple; bh=/aoLSKIJznnbsjZ5Jh4GqZ88soBWly62WzaVs9lwiik=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BkuRdbuzPmvNxKk2Q3oByVg89ReCgzKmx3k3xC+MvxW1tQAogdP3K++NMD/Pdl5gw72eF3W2nEFC1R70akPyzobrS1HWh+k6PpMAD3ZdGc2GHAPAstED9EA7VHaP7NV0LJ3xNxDx4e0TF5yZySMPnPxHpe8TSATGbdHl/ULUKs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GaVtVsqe; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GaVtVsqe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739546274; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PjmfsPFlVVF5AWgzzAtVJttyvI0k7JVXMhFtVMQApJc=; b=GaVtVsqem7zTZ0qdsiZlzGXrwSGPOCAkCf15FSfI2Ex44haa8ErU6xHcSGmQvn+P89B2g0 g+XIlqIc0BvBhiLSYblkLdc1UC6TH//RsaNFuoR5nsfyst560fJMauUNmZdLgul5Jf4tVj 2+0rYVREoW7lPSm9FkE7dMX9Y3FREx0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-Tj8BzwX_MPymrsacXgN4bg-1; Fri, 14 Feb 2025 10:17:50 -0500 X-MC-Unique: Tj8BzwX_MPymrsacXgN4bg-1 X-Mimecast-MFC-AGG-ID: Tj8BzwX_MPymrsacXgN4bg_1739546269 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A444318D9585; Fri, 14 Feb 2025 15:17:48 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.8]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E508919373C4; Fri, 14 Feb 2025 15:17:41 +0000 (UTC) From: Sergio Lopez Date: Fri, 14 Feb 2025 16:16:59 +0100 Subject: [PATCH RFC v2 5/5] drm/virtio: add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE to params Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250214-virtio-shm-page-size-v2-5-aa1619e6908b@redhat.com> References: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> In-Reply-To: <20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com> To: "Michael S. Tsirkin" , Daniel Verkamp , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Simona Vetter , Rob Clark , Dmitry Osipenko , fnkl.kernel@gmail.com Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Sergio Lopez X-Developer-Signature: v=1; a=openpgp-sha256; l=1826; i=slp@redhat.com; h=from:subject:message-id; bh=/aoLSKIJznnbsjZ5Jh4GqZ88soBWly62WzaVs9lwiik=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBnr15wk7cRkC8T/4bZJS1Sw62+SpzC/oEbqVusM iKcBZiAxJSJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ69ecAAKCRD0aSeNLwwC Nf33EAC1hAU5vFGUYPj0EZ6y7b8HSZ+J+/SSavSEjVx4NxdlUjeQA4kK8+A3wJh5g8gpPN0vgU4 I/+B6kZVyAPIYGHvkdioxNXNE4QLCqn7QAzuCSAxC3akm9cetbveC9AZgjUab4/j1QC5Wl1rRv9 SmdpYcN8gsVx5BeE4+UiE/5UA97nx+RonYYYIXau8nJjtTksRRIMBgmP8r4lK9YdzsJecuvVeOJ cul3DhmClUpcrc/LjdWHxggus6HgNGcpOnJUnEJIlOWfBFFAIZOp6JybOb6rM5J3A18xhtZLrst gW9LR2g2n8ASZeLisMwrfxovc4nGCbgLsy4Z8yH8PBGtcn7TZN8FFGlvYEr/8z6J1unkuHBxLDZ CIVVhVtPT3sXBN/wRs1pX6Y5aV8DWMjhj3hiNolLqp3wsZ+QrVdSeMkZpOWY5stAZ8nVNk83Tdp PlnhQdya6zCw67j9gbfmFq0QdPWxksH3NkzwPySH6OdoeUFRuuTyAiB08w53UbmkOT8RrMzlEhb 0ApQWtNOFNbtS01aM0TdHfNJk2yUMhrSt/rxuQjoLME7b2UkpmYtesH3Rc3UbrR+vFNulZ6HaHY mWa6RT/VU9jMsKyT/gOvYzGljtaxdXJja6dSmOFFTGa/gWaTrB77oWvM+NqxEwDo1m6xdyIWhjl eQltadZ/+ZIcf7w== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE as a param that can be read with VIRTGPU_GETPARAM by userspace applications running in the guest to obtain the host's page size and find out the right alignment to be used in shared memory allocations. Signed-off-by: Sergio Lopez --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++ include/uapi/drm/virtgpu_drm.h | 1 + 2 files changed, 6 insertions(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virti= o/virtgpu_ioctl.c index c33c057365f85a2ace536f91655c903036827312..4b49635b4fe1d4256f219823341= cef8e5fa8f029 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -117,6 +117,11 @@ static int virtio_gpu_getparam_ioctl(struct drm_device= *dev, void *data, case VIRTGPU_PARAM_EXPLICIT_DEBUG_NAME: value =3D vgdev->has_context_init ? 1 : 0; break; + case VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE: + if (!vgdev->has_host_visible) + return -EINVAL; + value =3D vgdev->host_visible_region.page_size; + break; default: return -EINVAL; } diff --git a/include/uapi/drm/virtgpu_drm.h b/include/uapi/drm/virtgpu_drm.h index c2ce71987e9bb816d13a300679336cb756f1cbcf..72db6b3339e0dcaf550acbf5ac4= 381a6e5c2216d 100644 --- a/include/uapi/drm/virtgpu_drm.h +++ b/include/uapi/drm/virtgpu_drm.h @@ -98,6 +98,7 @@ struct drm_virtgpu_execbuffer { #define VIRTGPU_PARAM_CONTEXT_INIT 6 /* DRM_VIRTGPU_CONTEXT_INIT */ #define VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs 7 /* Bitmask of supported capab= ility set ids */ #define VIRTGPU_PARAM_EXPLICIT_DEBUG_NAME 8 /* Ability to set debug name f= rom userspace */ +#define VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE 9 /* Host SHM page size, with for= mat PAGE_SIZE >> 12 */ =20 struct drm_virtgpu_getparam { __u64 param; --=20 2.48.1