From nobody Thu Dec 18 20:16:00 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 28A8426B0B1 for ; Thu, 13 Feb 2025 15:50:33 +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=1739461836; cv=none; b=O/NnIVDpDhXgJb+ZNcA+Ezl53PVsw6CRg4LvLEvzE3Urq5Fz1oWtttKst1LqziAga3uoHhXkrn0R9w1hSuy8ENi3ic1a0371FXHlqDSyaCA4Zs5dTj+yQX/rbhveYsy6w7a2ThU84twYJQZBDfGWmRH5+ePkYUkp0IZ0FxEd57g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739461836; c=relaxed/simple; bh=+qQii47gVXmTejLfeLZU+l1N1V1AmJTe9gWUPiChZlk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rlT1wnY1h5txw4CAtX+dlEvNJ/D/xPTGuFBys8vr5uMC6xjbIyDwS6l1ye42JI7/EzN998kz5QAJaGAGG9dDtOTpvbnDzEw82C/NsT9n+UprzJ3EwZERo/A/22lvUgPBOs/S0wTPsxiGOPeP+Nk7475mODtUmy2UI7yxQXPnNRY= 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=FykfgLlM; 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="FykfgLlM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739461833; 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=1fVXikV8P1LkgFcbRBlcEvzt5syfU3+P/BigpIdLnzk=; b=FykfgLlM5wSGJmtAsD+1Ycxqu7vaN0tvlHI8p32Qj5aPDc6QfUtbg6cQ+poBieyPKq1PYU RwSc89JXmYPRs7y+Gfh8eIYRWaROPa+LXIhpyjOSaTTl0f8NSWAPmOdsmq83qKOMde6ZGZ i1oaQMoFmUSs2g/+eH4Kf2M5l7tHeZ0= 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-187-J6oyb48CNzyxvZ0MBGqsig-1; Thu, 13 Feb 2025 10:50:27 -0500 X-MC-Unique: J6oyb48CNzyxvZ0MBGqsig-1 X-Mimecast-MFC-AGG-ID: J6oyb48CNzyxvZ0MBGqsig_1739461825 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 0E8BB1801A10; Thu, 13 Feb 2025 15:50:25 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.44.33.58]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 772DC1800360; Thu, 13 Feb 2025 15:50:18 +0000 (UTC) From: Sergio Lopez Date: Thu, 13 Feb 2025 16:49:15 +0100 Subject: [PATCH RFC 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: <20250213-virtio-shm-page-size-v1-1-5ee1f9984350@redhat.com> References: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> In-Reply-To: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> To: "Michael S. Tsirkin" , 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=1763; i=slp@redhat.com; h=from:subject:message-id; bh=+qQii47gVXmTejLfeLZU+l1N1V1AmJTe9gWUPiChZlk=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBnrhSshG64fW01+xhzuZqXCMLC7NXEfn5yLipGi IaFlLqd0BSJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ64UrAAKCRD0aSeNLwwC NbXfD/9qFc2tvGOvmLc1hX9AToxwFuJLODy+wh/JCKJ0kVlIFFawHMAuv7YgbNDQy8TaKg4SqYb 2l4J66ckcb+K8r5LScEQQ5h5LuCFPrl9vMg5KRXqpAJDHGmSh5R1v0wZg+1bJLQ97cIl5HnokjR 7CDf1ixnq+TBit7ow8qqwXUM5gSYnr4CUmElqLa8Iuhoc7PO52Qq4Wi3L9bLyrUxowu4evOvG9o /lAiFt2lgcWobvolGEet7TF61vsM1WrgwZTMOJhHUw3gXYFumykNve7r2xsDfeyn1NjIeN1U+rO 49ExshVLhu9aYwqs/d9/PIZsGZcdxBAu2qhW7v8WBQ6nK+tc7/c64gME11wPCDWYFG1BhOgF+Di gl3TbTEeIgWnfLlPfh9l1xESbAuJ7g9neaJjt3kyFd4AhsqHLnk0+v/9VQtd9cZH9cFG78qCgMB QVraengJqP/e7MyUDG48qaZjpXY4lLU0qVjKBiazMJ9ULgXwKMRpynKZ2jyHmTyBDpxvED0jwY9 k5es/7dEPsLKgLwem7D3bvevy3vUdraHeHjxW0Tj3S+ow4L0m7Pov1nMVzeIoEMX21T4dVVXF10 vPJvo7erwJyeMkD4GTHVq2wA6glxZHtHekYcjCJ2QLn83LMNKkW1VfPe4ON8gr/OSrl7tFFSAxM VTT2zDaCu+V1hyg== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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..cd0a0407659517e6a318b117ba6= 7258c59f1f983 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 >> 12; + return true; } =20 diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci= _modern.c index 5eaade7578606e4b02af0d66447417ad6aa11064..4e6c28aacd1b5dfc117337a689a= 25d668805e334 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 >> 12; =20 return true; } diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 169c7d367facb36dcabf9596068580ea8b8516c7..21ada8fcdf655894bb725045f54= c9db3a1492b13 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; + u16 page_size; /* PAGE_SIZE >> 12 */ }; =20 typedef void vq_callback_t(struct virtqueue *); --=20 2.48.1 From nobody Thu Dec 18 20:16:00 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 5DD231DDC33 for ; Thu, 13 Feb 2025 15:50:42 +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=1739461845; cv=none; b=dhs86fJZU1JMKEy5t2UozLPlE+VnZlpWoHwi4MvtLdjf00KlV+FwZGb8P2eBhc94Zm1UMtTQY5zNC+oKJaQ5UFYgR1WbBh1YValUMzQSs4tYZAz9ZxGNnvW+PIUZZQhIjaWsssIC9ENLP2DUZ9phmcjdXDrvzH0YSSCNQZTkVic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739461845; c=relaxed/simple; bh=QFdyFSfT3/4SWG9ZxXlf5iQzWwyJCONhEMZSH8OxQDM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oTYnLpgYgNciNwEGSkuEOJeuWRJ0vZ/xFxMOuXT0GqcfK/iqF8FbOkAxDhpAxUtA5X4ttLZtZ9AAGK6vAOu/iQ7SBxepZRs84vkw4qVqu4XngvPz+7AcSUr8BcO9a4+yybnEeeoRAv+etJPqALhY4N8+idZhNyZtEOTVkFN7Q1U= 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=SjIEHs7T; 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="SjIEHs7T" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739461842; 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=6TQz/AuXSm/jcXE77n/JSiGUw0PfjU842fJdja2/VcI=; b=SjIEHs7TRAbm/FHHHtK86P3l4HEJmWaiw78E6KeX0dQYjpMiGe49EAarH85FoDUbrO2esV DJCiUV9pgSCemoP7QjypMV5ufZuV6L5heV7cHLBfry2Zf2nNI0gkJP2G+ClPf+bQJ9kc3l j8pJYrVLVUExqVrDqhCEVUeqijskb4I= Received: from mx-prod-mc-06.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-324-52usUm0fP0qRHnq_Qf1pew-1; Thu, 13 Feb 2025 10:50:33 -0500 X-MC-Unique: 52usUm0fP0qRHnq_Qf1pew-1 X-Mimecast-MFC-AGG-ID: 52usUm0fP0qRHnq_Qf1pew_1739461831 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4AD4818004A7; Thu, 13 Feb 2025 15:50:31 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.44.33.58]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 93C9B1800365; Thu, 13 Feb 2025 15:50:25 +0000 (UTC) From: Sergio Lopez Date: Thu, 13 Feb 2025 16:49:16 +0100 Subject: [PATCH RFC 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: <20250213-virtio-shm-page-size-v1-2-5ee1f9984350@redhat.com> References: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> In-Reply-To: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> To: "Michael S. Tsirkin" , 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=QFdyFSfT3/4SWG9ZxXlf5iQzWwyJCONhEMZSH8OxQDM=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBnrhStylNLMTT77Zr70CH3mC0kJqxktuN3LCCsg tnCFcVTa3yJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ64UrQAKCRD0aSeNLwwC NZqmD/9DXwIcQu7/ILLvZOWvdxn9+Ye3CGeCADk5JnxPU0Z81fskxGRGa5lTCHCY87Gl6QFEQvG UINwli3B85/HdKrWo022BePUxPTQLp5FozatRSG+T0//2+1gw0lolaTesnkIjXxfCgXGxh5s4gD gon6X0A+PtUWkum0UJokqKyxVxoIHg1SeQGpSYZwBzKNuTx8gNz4CVmaIZIx3lEFL8/UjduIzY6 aYA+EwkVMrmxdpdNPHRoWvl/qnurDh2eLUqHeHt61PzwaxUmoSZZgxhjxc9/44WZUI4PIJdQtZe xFZlFVIGMrMPlEHk98UIIdgre9Np2XB3mhuntMoP+7LEDp8EYOBxvMPxWWQkTL/M/8s0BqAjKjG ja3grjYBvXaEPT8F8MJmsRnDKCJb57A2Wi6mQE+YBQ6TKLR0lKp0GzbLm05FuQWigxRhQnDa/qA Yztgpc4cpiZRsgqBs37g/+/S4c6sv8EcKtD/M0Wy7SA0yQtKPHVJglGxTwgguF89CqM7rW3Ozg4 QslBotsRTVlGACVi9qQwHmSKL1Rb/AWw8sz9OviHsYVkGwWpR8J81ToeFq4Zvd8luCRQhlD73kW YpvG7lyZEUdPEhyAkRDZaQ4IP4BQlHcQTm4Wu7fedAfdWYWFB1tJYWPx1lonn8AbXvZxppC4Qf3 TkqlXm2Fs5sykTQ== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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 --- 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 4e6c28aacd1b5dfc117337a689a25d668805e334..79616ce5057bf3b2b88cae7e8fb= 7729efa9dd632 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 Thu Dec 18 20:16:00 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 493B51E7C3A for ; Thu, 13 Feb 2025 15:50:45 +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=1739461847; cv=none; b=p0trAp9NLMju6A5aFA9gFFXgz/eGbrqQXONTRM1txfqf2D71Tvcew4tIYJfF+LK6PYZGF6jc7hi9cFD36oGHmfcrCP0RphtzWqnn4J0+T2F9EwbtdZj7i6mINNFHMrMj54BSJvolEUOzHZ27P2WGMutNw3ghOrUqfWOx4sWHmeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739461847; c=relaxed/simple; bh=th8ICZQzwvAj4jti147i6LTZteZNR2JRdjJgrinPxuc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Rg5LpSrWh7fycY0WnALGDtf940e+D86RwNaDQqyAYGOetp6tg0iBePL7+bhNaV9A3uJ1SOPvCjvEuviRSP935Q/TUKpqi21mFdKbwie+giY9WkbyyX3gBabtf5Uu10MVKpToLcB1ndW6Xo2/M4PdauAKio202XKFfbfvrSNmQW4= 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=EFUW/REI; 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="EFUW/REI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739461844; 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=xk1Yohdv6xG1LIYdCE6weZxWdHnGQzZeQusGiNbS4YE=; b=EFUW/REICNRI3Cl0+qB07QS05TWJN6+NLFcWO4XqznDnl2dnr6Je6AAC4WrVG6GeZBwFkC pxFECUr7IFfmjsfa8XlsXdBk79Wi4Ajv2ML19DMAKmHVAV/cKQnIjJYK3U/qKETIoS1Yfx R0GF97t3Ca8ddZMmw2AsitS2hRhmllk= 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-369-xQRG1M1ZOk2Exaus-VHC1w-1; Thu, 13 Feb 2025 10:50:40 -0500 X-MC-Unique: xQRG1M1ZOk2Exaus-VHC1w-1 X-Mimecast-MFC-AGG-ID: xQRG1M1ZOk2Exaus-VHC1w Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 95E9A1801A1A; Thu, 13 Feb 2025 15:50:38 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.44.33.58]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D250E1800365; Thu, 13 Feb 2025 15:50:31 +0000 (UTC) From: Sergio Lopez Date: Thu, 13 Feb 2025 16:49:17 +0100 Subject: [PATCH RFC 3/5] virtio-pci: extend virtio_pci_cap to hold 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: <20250213-virtio-shm-page-size-v1-3-5ee1f9984350@redhat.com> References: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> In-Reply-To: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> To: "Michael S. Tsirkin" , 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=3726; i=slp@redhat.com; h=from:subject:message-id; bh=th8ICZQzwvAj4jti147i6LTZteZNR2JRdjJgrinPxuc=; b=kA0DAAgB9GknjS8MAjUByyZiAGeuFK6g0IYF5gNoVdDWEYIgYw+KDGgrgUaUt6Ss3HnaKn8f5 okCMwQAAQgAHRYhBL7V/PdRLYaAkULoovRpJ40vDAI1BQJnrhSuAAoJEPRpJ40vDAI12zkP/iYs PuEmv6T8Yt/q5MJgGj+Z3qujU/ygCd+imitAs8P6jGFZsAI82+UupJ+bTmoQpp9gsV7yR+5sLmT ik8o0shqm97DkSwU26UmT4Ny7pHoeo4fOxmMw+7KIxIbIsIUk/zDfT0xGGygXkKKfOy6l9BDL6j pyYQ8cG8JUfoCauMj/dwTcAUg+t3S9xq6+artRq85AS38zrlte2kgQqwZwajyjd9Z9+XFZW+cLf mbllQF7x8RlU+ibEnds0qwScmLx47kZi6G/K8FlcUpe197W3LlUZkHYmQINMvHeGtN5qUJgDRK+ Ks8xl0mD2q52Rn0vRnbWElGjQ16fvg/opYjr5uBie3u5W4xbRxovh7xjZbAXM1wyycaNllgLUfv JyvrzCpRa2K/R8HNgwySlpZqlf7ybsSHK+Swy6Yl3K3qtqJuS0NhbAh8OhN1xda92SBtflPibBw ZlHWC1q89oEjcAORxPJOrHUslXx1NJbuprjTNJntzJwNBmSZmcypQgc0GfYeF0OxLNKUd8X9z+z M3F/grb33qsAgdcVRnOhEM5RIQf/LH+DDBYdryYWRgAYK5QHWRuYrhcgDRH7BS1t6SJk8VpSdGV 4bzh2p+K0TvpZ39fD1Vjwpij0LncXAWsMEJ54MDZxZUYAhvUL79Y+50S2Zjs4C9SC6hDYIgeeeh HcTcN X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Turn the 16 bit padding into a page_size field to allow the device to pass its required page size with format PAGE_SIZE >> 12. Signed-off-by: Sergio Lopez --- drivers/virtio/virtio_pci_modern.c | 29 +++++++++++++++++++++++++---- include/uapi/linux/virtio_pci.h | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci= _modern.c index 79616ce5057bf3b2b88cae7e8fb7729efa9dd632..26e9cd5148c0f10209c34d12e65= d64490a855d75 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -770,14 +770,16 @@ 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, + u16 *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; + u16 res_psize =3D 0; u32 tmp32; u64 res_offset, res_length; =20 @@ -808,6 +810,23 @@ static int virtio_pci_find_shm_cap(struct pci_dev *dev= , u8 required_id, * Looks good. */ =20 + if (__virtio_test_bit(vdev, VIRTIO_F_SHM_PAGE_SIZE)) { + pci_read_config_word(dev, pos + offsetof(struct virtio_pci_cap, + page_size), &res_psize); + if (!res_psize) { + dev_err(&dev->dev, "%s: shm cap with invalid page size on " + "a device with VIRTIO_F_SHM_PAGE_SIZE feature\n", + __func__); + res_psize =3D 4096 >> 12; + } + } + + /* For backwards compatibility, if the device didn't specify a + * page size, assume it to be 4096. + */ + if (!res_psize) + res_psize =3D 4096 >> 12; + /* Read the lower 32bit of length and offset */ pci_read_config_dword(dev, pos + offsetof(struct virtio_pci_cap, offset), &tmp32); @@ -829,6 +848,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 res_psize; =20 return pos; } @@ -841,11 +861,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; + u16 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 +886,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 >> 12; + 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..fb0ccb7a125d8178c1f78333c4d= 2f43540e1764b 100644 --- a/include/uapi/linux/virtio_pci.h +++ b/include/uapi/linux/virtio_pci.h @@ -127,7 +127,7 @@ 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. */ + __u16 page_size; /* Device page size (PAGE_SIZE >> 12). */ __le32 offset; /* Offset within bar. */ __le32 length; /* Length of the structure, in bytes. */ }; --=20 2.48.1 From nobody Thu Dec 18 20:16:00 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 A84011EEA36 for ; Thu, 13 Feb 2025 15:50:52 +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=1739461854; cv=none; b=NqIZyN7w8rYqz6WFejNr3qY4rR46GWuXCVFgS8gEGVbKbq8wBxrVI6FUNuG7/FuHLj7PHBqv/QRBMf6blSRo/8Mj6PODeY4oD/kFzZ+qnJDkVJfqV4vxUBlTFjJNiyRPwPFU6B8On0+buIhU6pzGYcF523LEjxxjcTrYPksR/jI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739461854; c=relaxed/simple; bh=4BHYqTf3/QJ4WE/gAmQswAKbmL+cD4+SAvyJx3zmY/M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cw5PUegR3cJMnO4hSHBrvZbxs2noPqbDYRj27AP+Le4WmRnLnlFC2TNZzscFdfJhtbih/h7WU6E/YhsfbSMB9aA/K0E71hRgCocayl0hhtRqs5Z8P6KnYsl4BvCPkGPzxOy2GELSGVA5vPzZ0j6CCf/bd1kyl3IGXExR2CnxfkA= 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=ZmaAZsf3; 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="ZmaAZsf3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739461851; 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=CPDMwS7WtZbaodmU1wGmDq5U/O9YW9budAUbZ3K875k=; b=ZmaAZsf3BnyjX42m2BiOBWXd5n4PHSky2DcFBpDSIdEenv6mQ/Je5qiExONI596iVnmXtX 1HSTo8vsWcypGBOHemI3vOOvcHwmhAyYsR8s2xlfIi1kh/7YiJ/lt/mJ7l0SMK/sGJMDCM vxpqWtn5WKZrJZWmk0U+UdoAYtXiUI8= Received: from mx-prod-mc-06.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-687-_FzdwdRkNT2W6LkuU2I1vA-1; Thu, 13 Feb 2025 10:50:47 -0500 X-MC-Unique: _FzdwdRkNT2W6LkuU2I1vA-1 X-Mimecast-MFC-AGG-ID: _FzdwdRkNT2W6LkuU2I1vA Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 41D03180087A; Thu, 13 Feb 2025 15:50:45 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.44.33.58]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 399FD1800365; Thu, 13 Feb 2025 15:50:38 +0000 (UTC) From: Sergio Lopez Date: Thu, 13 Feb 2025 16:49:18 +0100 Subject: [PATCH RFC 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: <20250213-virtio-shm-page-size-v1-4-5ee1f9984350@redhat.com> References: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> In-Reply-To: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> To: "Michael S. Tsirkin" , 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=2018; i=slp@redhat.com; h=from:subject:message-id; bh=4BHYqTf3/QJ4WE/gAmQswAKbmL+cD4+SAvyJx3zmY/M=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBnrhSvDxI+WiTFN3JL/Qzuc2xiWNP3Mq2/qlssR XCntYrlp4eJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ64UrwAKCRD0aSeNLwwC NcgyEACLL8igsV/fv85sL628B2GV9AZjCunwvzxWR2iisluQIOSnZCHY+0QygQbUzoiTicAsuDm pc1Lt/w68Q2kicl2BPqt00LuLWEJW+dqD6KHg1QL8y81xwyr0o/9TJtcTGMTKpnVKCNUt78FELL 3p57CcqBHqx1XnB4zA6g55eXVRCLgeFcDQTU+To18nWO/TGBA9tqZ7LGwUQ4xoS9QLnfLTdxKDw 4uxV2jlWwcM7aF/b9ppSvaysZmSz7u9CRjE1Yj2a2+fuMuIJ0e23kh7Vswkq5XVYKfpRrxqt5S9 K0BiVzJfXX8tnsw03vVv6O1BoNoLtpCmJF/5tk8XklLuLWl/TPX3vMhTgrPwVWfMHp4wDgyOe92 ApmaolMa0EFOSkFnBKQChdy8mVndj199Lv6m5VVn84Os8FjryN5U56IxiK1d7BW3spvROFbDSDc JHZEDzzTlDwWvBdXaflKCl91v4TEbM/+DCClnJog/We9b7Lc2IjhZOogQByvtLYzuA7gJilev7/ R4upFNDmmJyR/R0s5BCDFtsD84ksi+zIVGSAfAuWsGhMtH+FgX4QM4YYLwR7VzszydWHVWcraSZ wZpZscSrkW3Y58y80OkSFnAEmy1fROyRuNV2eFZJnQsfaWKvEQ7qIYoQgBhEq6K94FZBN13SQkB 3SflZNBJcWr/tvQ== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Use the newly introduced SHM_PAGE_SIZE register to read the page size and store it into virtio_shm_region. Signed-off-by: Sergio Lopez --- drivers/virtio/virtio_mmio.c | 13 ++++++++++++- include/uapi/linux/virtio_mmio.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index cd0a0407659517e6a318b117ba67258c59f1f983..92590c77901bee453d8c1a1ac60= ad9cca90d1b59 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); + u16 page_size =3D 0; u64 len, addr; =20 /* Select the region we're interested in */ @@ -560,7 +561,17 @@ static bool vm_get_shm_region(struct virtio_device *vd= ev, =20 region->addr =3D addr; =20 - region->page_size =3D 4096 >> 12; + /* If supported by the device transport, read the region page size */ + if (__virtio_test_bit(vdev, VIRTIO_F_SHM_PAGE_SIZE)) + page_size =3D (u16) readl(vm_dev->base + VIRTIO_MMIO_SHM_PAGE_SIZE); + + /* For backwards compatibility, if the device didn't specify a + * page size, assume it to be 4096. + */ + if (page_size =3D=3D 0) + page_size =3D 4096 >> 12; + + region->page_size =3D page_size; =20 return true; } diff --git a/include/uapi/linux/virtio_mmio.h b/include/uapi/linux/virtio_m= mio.h index 0650f91bea6c70f935764070d825d181a2379afb..c5a1cdad5a1c9bc954d7facfd8c= 05e2acbb28e96 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 size, in format PAGE_SIZE >> 12 */ +#define VIRTIO_MMIO_SHM_PAGE_SIZE 0x0c4 + /* Configuration atomicity value */ #define VIRTIO_MMIO_CONFIG_GENERATION 0x0fc =20 --=20 2.48.1 From nobody Thu Dec 18 20:16:00 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 8F2A31E3DED for ; Thu, 13 Feb 2025 15:50:59 +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=1739461861; cv=none; b=lnNJ34VJedStMSo8QLqmD4oYmuxYZiB/JZGdAwHnGH92OwSGZAAdtPzAdXtDRvM9WTwCnmElRYga8sy7vZUj0wxOKDGTszN3InVvjQa2LAcVEiZeMHE9s727PSfUxVunWqf/GkhfaDpKeDpHYxE1/8zSInNmcvJPKIhzUwXFRYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739461861; c=relaxed/simple; bh=/aoLSKIJznnbsjZ5Jh4GqZ88soBWly62WzaVs9lwiik=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NXm+ZAjqFxIeKdKOryA/7ZL1Q6mGO8RzBBp4Yao/r0epAIo5Gh+ySJd9YMnskW4STKmKVnGSaVVcP9j4/Angjl48MPJk4Jex5swFRNtZtYAz9A7f0v03Y1ptr5I887zIo/cYoEm68D10Bi3Oj8FinfSGA4/YlPFibi+fd07N8lc= 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=Grc/TklO; 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="Grc/TklO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739461858; 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=Grc/TklOlm7jeIK20gL4KiSrCYRar2vLZrxgAM6Lioz8lfzGFZH4V23Dk3diyKDydowSsf jBJe8GfrR+ah2l0YTidtGabe4+qqp5tc/y8jom6MOGJ2d2Nw/Ud501mFIlSZntLLA6bUfU BAHM7MPBDp+87I37NxqJ31VKXj1/7Tw= Received: from mx-prod-mc-06.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-250-fWiTjEI6PDuewe8qZoXD2A-1; Thu, 13 Feb 2025 10:50:54 -0500 X-MC-Unique: fWiTjEI6PDuewe8qZoXD2A-1 X-Mimecast-MFC-AGG-ID: fWiTjEI6PDuewe8qZoXD2A_1739461852 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EC8641800873; Thu, 13 Feb 2025 15:50:51 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.44.33.58]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 005321800360; Thu, 13 Feb 2025 15:50:45 +0000 (UTC) From: Sergio Lopez Date: Thu, 13 Feb 2025 16:49:19 +0100 Subject: [PATCH RFC 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: <20250213-virtio-shm-page-size-v1-5-5ee1f9984350@redhat.com> References: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> In-Reply-To: <20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com> To: "Michael S. Tsirkin" , 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/ZANAwAIAfRpJ40vDAI1AcsmYgBnrhSwhjgi2huewIbD11jfJzeBM0pBvdx+QXdjZ 3DYvQQ1INGJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ64UsAAKCRD0aSeNLwwC NYbtD/9ctHlsRxX0qc3/D6Bh638ZBZMa+fSdL8lFea6UYOw7mU4npndqsYsJPx/wr7U7n83Vaxr tUcKqrDkgaw8ya+Vm/2cD1JWs4+37Bf1qUBHArqwpTPzeNuBPJk4Z624Bma7rYalRNE9BHYmttg ImMXqognhOLVo3GvnG5GKufzxW6Q56ta8LMoQi3/otB0Lp4bwE/tevyOgBJRInuGjoj1MmKTNR8 pcEbm65Nhdy1yhGxL1iJKVJCBaofqq2g1oNS8uq/mSaT9onuqhHdr3COGV9tlM5LoTJXN/kuNnk nChP1pIDBub/qUL495/Jxj90CDmmCxth/VET+s8B49dpCFNGj3SNzcVwjqj4bikjlObwuPv8NXA 0FBpGgpFLq3OdCDvd6e3TlrZMZ9MZp1U923btfwXJ7m65WU9MqRf67O4q2Vdw3/bzU1b6hUMR2x fULusPSIv6m+k7thSDqtWNrwAFSRQ3x4mrBCJDX2KryPkldQ3Qtj4NZOlnVCYAT+fL/XB7yfY5o c8YEStKGghk9W8RXB+Wfcvz2+uA9yPrpx3lZc6kG4W7YwSfciZm4c1upgMPktnF+HT68I65/Ksu fcvqVqY/pWDtFQgTriHjX6Xwbu3Uz+sAUwRcmODokFmPENr6xR4zb+qq8y8HB+1OVBvazTtTTej b1Xw9a5umUDKO/A== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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