From nobody Tue Dec 16 11:06:21 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 2AE8B1F7916 for ; Thu, 20 Feb 2025 14:29:54 +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=1740061797; cv=none; b=eVRlIvtumh653EPPnv3Rk8P/l4AzqJGR7nBSSQCDxXiAA5votSRaRVCZKxTbzw1BQtLVt5VmIdvG1oXrs9CNEWReDRTCfgprzn4HyDQhKlpa3plFlZAEnItZqXlH4pvx/hrl2xIbB7gxcSyZmOc04mbRoOSOZNHK8IUCFXf+Ltk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740061797; c=relaxed/simple; bh=mRGswsKourNVCaSODc/n1NTXWr1ln5mIzOK1iDX0YHA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PkN9G9ccJbW9+kVnWcYFELA5nypIRm1VcyLty7n5QdIcxCGRX/1CWqpv6M0rm1QbrcgXYnrjk3gjcN6YoMsU2fBfAalDthexH9G1Jw43MkYTyMcsv/+wjN6LlDKS5qrbxb+6BCql5GTlNTKgW4qvuIIvTjd3WSEh5Q5DZOK9Bvo= 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=Zs+qGvn+; 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="Zs+qGvn+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740061794; 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=1KVhFVLcrq0MwE18FSmJzB1oSZy7QOKz+o8BK19VMfs=; b=Zs+qGvn+NhoWd9rQaRbZGGv7wO17NNy8Dp7u1+WRgAB2OKgQTa/yskASNtac2TqpQi6rhC XuucuI5+hUhgu4HBWhE/IShxtvajzSMDekLbDtQVIP313zX1kdgolQEZC96VWr0q8cBXPZ 9KWPnWqNk12ca8CPvZtXGPSdiAyfSWY= 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-192-KrtYqZbtNOCBhzpFkT8-Zw-1; Thu, 20 Feb 2025 09:29:50 -0500 X-MC-Unique: KrtYqZbtNOCBhzpFkT8-Zw-1 X-Mimecast-MFC-AGG-ID: KrtYqZbtNOCBhzpFkT8-Zw_1740061788 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 CB85418EAB38; Thu, 20 Feb 2025 14:29:47 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.137]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D36F6180034D; Thu, 20 Feb 2025 14:29:40 +0000 (UTC) From: Sergio Lopez Date: Thu, 20 Feb 2025 15:28:50 +0100 Subject: [PATCH RFC v3 1/4] 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: <20250220-virtio-shm-page-size-v3-1-874fff6f3979@redhat.com> References: <20250220-virtio-shm-page-size-v3-0-874fff6f3979@redhat.com> In-Reply-To: <20250220-virtio-shm-page-size-v3-0-874fff6f3979@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=2407; i=slp@redhat.com; h=from:subject:message-id; bh=mRGswsKourNVCaSODc/n1NTXWr1ln5mIzOK1iDX0YHA=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBntzxIzEoUz1g/wFC1Q//VY+sr+FsTO/3gBLlvw mXnRMzGG4uJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ7c8SAAKCRD0aSeNLwwC NRqbD/98huBq6YTHgxq5tCDQvIMcqutP4qaM+w6y1tAob3ydraZ9dy5yqOmZ2V3+drotoHacQkC S3UMniJUIvIU8Ijjw0EI7epz9N/rkIasoaD88Sbl8juhA9aLgeqbVBgcyEYJIkXf0q8s7kqwM6m JzT6KY57u2bpq2fBbsWqrM1/FrUpjQdi1K16rSyXnSVueo5H2Uw+iyfqDZIJsgqQHAXTY6RFJfz Cj0e+BrwN6P4YpMU7yi0wHkh6SmSi8jyIpGVECy5NEG9niFDzzQIiOFQXFEhuhmILkgJNxcGvcD 19NLzb2cNe/7G9se9oxCHPwhbUDHAtFi0KoE/UqCal/8eZI0U3/trln3eyJZpj7da+WcN6ThCfr s5+Ok836EHG4u/304mNIzl3pd4EFklnDfSOo5DM+8VekfpvpnmR3/ybesvecPZoKPeIcYFQ9AWK StBRYfyT5WbJ4vqfBTFn84GXpJC8fwnVSTAdDdPW0ftK5023Ej1mHDhR6dXC9jzYtOh+Y+Vy/De OCz785D5nYo9eb0WV+tdT7Gsu/GK88WWq7bBUgaaUiqnA558t5CoL9exeAmfB7Ml+je7FfgpKSV bdzX0+gNSsakWSyOVyTczYMB+SLy8276s7WdFhH8vKrK5Ss6dV/ytk0pdvAA9kiMRQkGyaYK7DY dpya/prwpPWTggQ== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Introduce VIRTIO_F_SHM_PAGE_SIZE, a feature bit which indicates that the transport provides the page size for SHM regions. Reviewed-by: Dmitry Osipenko 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 5eaade7578606e4b02af0d66447417ad6aa11064..104ba08f82d4a6268240bbad153= 85dd44b3a71d6 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 Tue Dec 16 11:06:21 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 2C0F91FDA8E for ; Thu, 20 Feb 2025 14:30:01 +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=1740061803; cv=none; b=aWYBmSyOFM4W9Md4bLiUqsvVKZYQIqlvXYn2BkdM7AT5/kYWomGQ7PTN/SXcsBeHeolZW3EJb5nUTUk3w1Pg7jhxNl1zjunNZyjYsimgWQTguVU/CzPS7H0DTS/uS4Teoa3/UVF/7gPkwCpz3ClOur2NvEZx0KfzsHbhWdTpjr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740061803; c=relaxed/simple; bh=5LxP+sHlPScHwAhNeF2YvPIGaWKR1ke8nTuwj4WIQBI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bgDrPlyZ1g/0FCmAKoXu3Hrn3b1z0wIDszNhb4xT1xhOtvaeIOaZYsQVU+J1szGCkz9xqQ35bS/L/Lqeto3rJCC5w2MSwYhGz6h3gVnBzr07/m3D8jwJlxQeO+QXyf7FibBw0lVb6sIsL10hb87DaN/2b7FVDNl523MFKtbvMp0= 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=IGBB2MEj; 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="IGBB2MEj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740061800; 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=DuWHlO7udbqobuTHU8cCr/Z3aa3wiRV/dXZl36ckZYk=; b=IGBB2MEjlx7YABZ8r7LyN0GAwyMAFXO1xfc8NGfd5U9JB3Q9ShRFnCxuizt0wmAqBfieJ4 H3jxVbCDkKrvprCzZPfw9vezG3oz9v0zLe/S6gEaT90RgXoArnS6aqCCgyaAXEg6ZfKchy zzcLqwgAwR0a3rs6vM6449pi69IXVcM= 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-59-5EsmtoRTPbe31fHMI0BS2A-1; Thu, 20 Feb 2025 09:29:57 -0500 X-MC-Unique: 5EsmtoRTPbe31fHMI0BS2A-1 X-Mimecast-MFC-AGG-ID: 5EsmtoRTPbe31fHMI0BS2A_1740061795 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 0D94C18EB2C3; Thu, 20 Feb 2025 14:29:55 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.137]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5A35D1800352; Thu, 20 Feb 2025 14:29:48 +0000 (UTC) From: Sergio Lopez Date: Thu, 20 Feb 2025 15:28:51 +0100 Subject: [PATCH RFC v3 2/4] 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: <20250220-virtio-shm-page-size-v3-2-874fff6f3979@redhat.com> References: <20250220-virtio-shm-page-size-v3-0-874fff6f3979@redhat.com> In-Reply-To: <20250220-virtio-shm-page-size-v3-0-874fff6f3979@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=4869; i=slp@redhat.com; h=from:subject:message-id; bh=5LxP+sHlPScHwAhNeF2YvPIGaWKR1ke8nTuwj4WIQBI=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBntzxJ2yzF9R31mQMkFK2cU+zAROoRntun20Gs3 NGRZi0bp4OJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ7c8SQAKCRD0aSeNLwwC NTa8EACPjhsRm4GtWlGluYfnDajWttO5EHoWJb4ZNM0deo2kKq0VeTUIvNmFBHfNunkF/cUX2KL lGEpRkzH7yz8lMHtz0VZPcyTqGTGa1d0dGPjWD607iAqg4Pc8T2UrjsWmDC18t/vwqHrttfcjW3 whdyhCkxxL69Pf6y87T24DmhCNh9MUqQEM/jq+va41z94YL/NUIHznBuOxqN+a49wixooFsIbLr yxV6KHDU3mUKahKJHQ1B5vxgw0kFvvZABFD3bXA8iRkNEICpvwXwrsXY85hcfZC05PhSlMjehzd Ls3o/eEOYbd6V6ckg8gCtzcsvGiysMp8P/3AkvZif6IO1n4mILBIZMxtpQv14oKGSJ2larbAKOr 3kbR5Pwj1/PIHaPU978XHqfg/uU8k6V24OqUfVdIIkde3OIyV5tj6Tyv8hEQvQP340OJ68s6lim yftwg0vqwOyVGEIoUDJDjVVvKC6psNHmshoi/Grdl97qZZn7tyqom5JlnZTCkdHs844HxcEUMF9 zJ5QbtW4ttWNX0NS92NhHt7qFEcQswxxsA3nV9JkeJM6rsMzXep4Uiik4PIzSoOK86L36IgbcbB 9OaXn+quNNdyreRTnwCIi2jXAfu1r5s6v+TOdtDEnL9egFok2u7BuNT98lnGWodQcM0U9vL9arv 0C76CJRDpYXMpPA== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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. Reviewed-by: Dmitry Osipenko Signed-off-by: Sergio Lopez Reviewed-by: Daniel Verkamp --- drivers/virtio/virtio_mmio.c | 2 ++ drivers/virtio/virtio_pci_modern.c | 21 +++++++++++++++++---- include/linux/virtio_config.h | 1 + include/uapi/linux/virtio_pci.h | 3 ++- 4 files changed, 22 insertions(+), 5 deletions(-) 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 104ba08f82d4a6268240bbad15385dd44b3a71d6..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,6 +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 page_size; =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 *); 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 Tue Dec 16 11:06:21 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 30A6E1F9A8B for ; Thu, 20 Feb 2025 14:30:08 +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=1740061810; cv=none; b=pAfaspIlV+fu5RGSQWzdl8RDMTruL7asOQkNu+gUe3cvNcRcBjomRjj/LMaM5xuwGhGFSjv5GAl/A9w9rUphtndPM9d0cIrkguXanwxq4RuTNxxE92h0FZDWtFVGvsfUWFZupkDLuvKlWjETjSANQfoIx+mYCSyyknNND1ZzkVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740061810; c=relaxed/simple; bh=HI9Yq5I4O39ewz8THclJRiNmMRL0UMmWH7PQ7qSDiQU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H95b7n0XeJAZGjszy40f4n9vjeec0Jk2mtu70Bsv/PQ94NgYXBE2ChhK03v00WC+zSu68rU6TdIpeUJi7XT+EKml6mHqi3qfp9psHcRkpMxNTILlv4xOA6DZd9IHNmycEOuJtG+S7ezf6okm1LF+235f7nWZEkwGamSXtXW8jaA= 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=TjPcxepo; 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="TjPcxepo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740061808; 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=QdC/IAoeSMLIQ4OUOk35zjurJj/IxmY0a02LUnio0io=; b=TjPcxepoleaBQHcwWSc+s/B7OTRFn22/6cpnLDbVH2pS1/yH4s8tSrPNkXFqxKe5zVTG/H hPlH0tKu1E59+jv0KBoqGdmnGd42/5FHkNpFcz63FX/n4pMgEZXeTKk5kTVjygwuvJ9X17 3UhxVWm2nq2ZjsDkdAwjKRNJX3X1jno= 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-580-cpfN9vOrNfWVMVOLG4BHFw-1; Thu, 20 Feb 2025 09:30:04 -0500 X-MC-Unique: cpfN9vOrNfWVMVOLG4BHFw-1 X-Mimecast-MFC-AGG-ID: cpfN9vOrNfWVMVOLG4BHFw_1740061802 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 3C019180087E; Thu, 20 Feb 2025 14:30:02 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.137]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 91770180034D; Thu, 20 Feb 2025 14:29:55 +0000 (UTC) From: Sergio Lopez Date: Thu, 20 Feb 2025 15:28:52 +0100 Subject: [PATCH RFC v3 3/4] 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: <20250220-virtio-shm-page-size-v3-3-874fff6f3979@redhat.com> References: <20250220-virtio-shm-page-size-v3-0-874fff6f3979@redhat.com> In-Reply-To: <20250220-virtio-shm-page-size-v3-0-874fff6f3979@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=2146; i=slp@redhat.com; h=from:subject:message-id; bh=HI9Yq5I4O39ewz8THclJRiNmMRL0UMmWH7PQ7qSDiQU=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBntzxKYgKPqmR77A3KduYsn47cHdfHzt2CfCFH1 NDFL8L7YAyJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ7c8SgAKCRD0aSeNLwwC Nb8tD/9s45gxTwPddTHpHmXpSK/30m7AnNkqU9wxKZCfSGivH8PGfzo7V/RkAbWnoCFBLADk+LL dBZsx5onK4HDQIOEqYryzQFkIHKcSdZsCSuaLX7llc+6yZkpLVLhbGnasdD+La8+gshbF8AmJek EImP7BsDJLpk3O9ntXYQF45mSMm+17Sq1qPn0YWDVruXFw1JIiTkJU3agPJ9xCbE7xPnbiWl+vs F2urZR4xgoargHBBnkunp+MoOtmKwYRgapxLtrImADzn3zwurOBtAswq0Hs4vv2ALcggICNaNjw UvLBeZqyicVmdisMvFvwwL4GXRaj+j7PqNImmWtZ8AFuXaLBOXpgzw1HNyJaQ9aDP4/VDEJ+0Hg MtaYF1FJ/VNmnt9fzBXgu4D85DpNddaFAmnQnqCXRh1AOHsu9gfU6pQM6H24RQMob8vCmj0TBVm lwRyK48K4sK0wVz4RuqnSYycQY9vQzZ5KxGcuGV5BL82TR3R8+2FFCYo1txTP+sHJO7WKXuAavt YCEf+F9YBNvxG1bR17xYp9ZTH2ib153g1cu8oaE+wQDTyt0/eC0jKb8TBk5DkR634ysox+eaEKi nCy9rtRDcvAijO3WhEl/BtyHorc21Dau+m+xaaYn4jFF3a9TqyW0BHtxdl68La2zGxO+rO1Te4J R+28J+ArAYuLnMA== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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. Reviewed-by: Dmitry Osipenko Signed-off-by: Sergio Lopez --- 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 Tue Dec 16 11:06:21 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 B293FA29 for ; Thu, 20 Feb 2025 14:30:17 +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=1740061819; cv=none; b=k2upT0akivHTIx/d66soo2y0tcvZfaFIS9wjl065j1ySFDxONZ6QNHJpfvtoRQrA2LuHGgtZw7X48ji7u64cWILSI3+koXaRdicgf3LuanuR7sj2iiglsBXxhga8DNW3pV7mOrlq9+z8AoTW7xRjt5bmKWIezYjjDt7vbzC7CTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740061819; c=relaxed/simple; bh=1G3lJhhDiOBTd6Kzg5KWNjN2JJNHOjrLtLCcFndtJo4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gNY4kzc4xr5nUNuPxg9WV5kcsJ5Ta0v63RbDHWdfvFU+C9QJjW+LcXgojzAVTM0k0RcfNtI33Ud4efXC7c9aDMzriG0duzM33/2bt/XWgauLHMC2MTomQx/IsBTsza4ogjDF9mcIVC+rfyiGzKOIKiAVf+vgO5yA3n29teBeajY= 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=d3xYSpMu; 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="d3xYSpMu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740061816; 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=ZqVSD1LpLSPpPVhZMn461AKEdfZbFpotrJ5hf1JYSzo=; b=d3xYSpMuhktfjPPjbjLFgH20sSovwQqic+bcQH/86l7anJrYFqZePnRsK+HpD5wnetHp/R xfAy6goRM1zLIUWBY58NIR6HYSgrhHwf4MbU9Rn/itquj+HADVC3/MWXRuu/1VwOuVNKpt oAWV0nnyOX4q1l2SpcfiSlgfaiPiAqQ= 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-128-uf0q_LRMPpG2LoSXgm1CEw-1; Thu, 20 Feb 2025 09:30:11 -0500 X-MC-Unique: uf0q_LRMPpG2LoSXgm1CEw-1 X-Mimecast-MFC-AGG-ID: uf0q_LRMPpG2LoSXgm1CEw_1740061809 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 992AA19039CA; Thu, 20 Feb 2025 14:30:09 +0000 (UTC) Received: from [127.0.1.1] (unknown [10.45.225.137]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 459031800352; Thu, 20 Feb 2025 14:30:03 +0000 (UTC) From: Sergio Lopez Date: Thu, 20 Feb 2025 15:28:53 +0100 Subject: [PATCH RFC v3 4/4] 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: <20250220-virtio-shm-page-size-v3-4-874fff6f3979@redhat.com> References: <20250220-virtio-shm-page-size-v3-0-874fff6f3979@redhat.com> In-Reply-To: <20250220-virtio-shm-page-size-v3-0-874fff6f3979@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=1G3lJhhDiOBTd6Kzg5KWNjN2JJNHOjrLtLCcFndtJo4=; b=owEBbQKS/ZANAwAIAfRpJ40vDAI1AcsmYgBntzxLxj0atYWb4t3RuFehUqiLushP15onRAQtv nBUBU43ivSJAjMEAAEIAB0WIQS+1fz3US2GgJFC6KL0aSeNLwwCNQUCZ7c8SwAKCRD0aSeNLwwC NU5qD/4oOqN1KMjglbDjdDrCwRwOD9glVvH68wKnXtAWqHnRXuqRYAWeT2VjvkfWBp2+p3snYYu WOpjRh4K3/URic2NuHskA+s2Ycl9sGd4YJCEA1U3CWaSuhL7MO3cRark+9Sx/I1tWLLxFQOOf7H MI4n3+O2HX0D0mpUuWxvjK/NZobF2sX0xYbrE5NmNnCxxCCjFosxvvJJAqK/8/7OHJOi86kIl18 qQ5Nu3YhgywDCtFO/SDrARIM/pE5PA3kPYvwg56KkbuBs2L1cT1AcdbU4VwcYMuoUaxkd9cU42P A+ep7SleWjhOEIxmkoic4Ug8kiMXGyaG8j02Jp19BYGnTr3154A5DipKBjqfJfsUFOIHochyiU6 T/fR6JFZcAIqxcR2qjVNegcRC15ZhOq6sNEcf54Hp9hF9GAQ+3W1lzZDw4ipuXL1DMoxdxQGpR0 PMAt642wB1uVlopZe16qHKrTsfae+8aldacy5IoSy9k/i/gBCvRiTfTQQoryVr/9vO/v0505Q55 INTFR6Al5hD5+NMqLqfF4Tr9TMi4WKVbqF2ACwRG6a+BrCz5G4zE/tjasmmj/c/AmeimhenAiYI yfuA27v0NuaeRSYqNB6IfHZhb6dHMrp+O17fC1kfe5gou9mvTmscIo0sSe9d5sgCkwPay1HyW23 VkqlvlQWCYSgB0g== X-Developer-Key: i=slp@redhat.com; a=openpgp; fpr=BED5FCF7512D86809142E8A2F469278D2F0C0235 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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..f112b862c2de4d021fb6a54a080= f42ad75034227 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 -ENOENT; + 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