All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/1] virtio_bt: Fix alignment in configuration struct
@ 2022-10-18 19:19 ` Igor Skalkin
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-18 19:19 UTC (permalink / raw)
  To: virtualization, luiz.dentz, mst
  Cc: marcel, johan.hedberg, jasowang, linux-bluetooth, linux-kernel,
	Igor Skalkin

According to specification [1], "For the device-specific configuration
space, the driver MUST use 8 bit wide accesses for 8 bit wide fields,
16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide
and aligned accesses for 32 and 64 bit wide fields.".

Current version of the configuration structure has non-aligned 16bit
fields.

This patch adds a second, aligned  version of the configuration structure
and a new feature bit indicating that this version is being used.

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf

Changes in v3:
  v2 had been sent from the wrong address, fixed.
Changes in v2:
  The first version of this patch just changed the configuration
  structure in uapi/linux/virtio_bt.h
  This can not be done, because it will break the userspace, so the
  second version offers a less radical approach - it introduces a new
  feature bit and a new configuration structure that both the device
  and the driver will use if this bit is negotiated.

Igor Skalkin (1):
  virtio_bt: Fix alignment in configuration struct

 drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
 include/uapi/linux/virtio_bt.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

--
2.37.2


Please mind our privacy notice<https://www.opensynergy.com/datenschutzerklaerung/privacy-notice-for-business-partners-pursuant-to-article-13-of-the-general-data-protection-regulation-gdpr/> pursuant to Art. 13 GDPR. // Unsere Hinweise zum Datenschutz gem. Art. 13 DSGVO finden Sie hier.<https://www.opensynergy.com/de/datenschutzerklaerung/datenschutzhinweise-fuer-geschaeftspartner-gem-art-13-dsgvo/>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 0/1] virtio_bt: Fix alignment in configuration struct
@ 2022-10-18 19:19 ` Igor Skalkin
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-18 19:19 UTC (permalink / raw)
  To: virtualization, luiz.dentz, mst
  Cc: johan.hedberg, linux-kernel, linux-bluetooth, marcel

According to specification [1], "For the device-specific configuration
space, the driver MUST use 8 bit wide accesses for 8 bit wide fields,
16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide
and aligned accesses for 32 and 64 bit wide fields.".

Current version of the configuration structure has non-aligned 16bit
fields.

This patch adds a second, aligned  version of the configuration structure
and a new feature bit indicating that this version is being used.

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf

Changes in v3:
  v2 had been sent from the wrong address, fixed.
Changes in v2:
  The first version of this patch just changed the configuration
  structure in uapi/linux/virtio_bt.h
  This can not be done, because it will break the userspace, so the
  second version offers a less radical approach - it introduces a new
  feature bit and a new configuration structure that both the device
  and the driver will use if this bit is negotiated.

Igor Skalkin (1):
  virtio_bt: Fix alignment in configuration struct

 drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
 include/uapi/linux/virtio_bt.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

--
2.37.2


Please mind our privacy notice<https://www.opensynergy.com/datenschutzerklaerung/privacy-notice-for-business-partners-pursuant-to-article-13-of-the-general-data-protection-regulation-gdpr/> pursuant to Art. 13 GDPR. // Unsere Hinweise zum Datenschutz gem. Art. 13 DSGVO finden Sie hier.<https://www.opensynergy.com/de/datenschutzerklaerung/datenschutzhinweise-fuer-geschaeftspartner-gem-art-13-dsgvo/>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 1/1] virtio_bt: Fix alignment in configuration struct
  2022-10-18 19:19 ` Igor Skalkin
@ 2022-10-18 19:19   ` Igor Skalkin
  -1 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-18 19:19 UTC (permalink / raw)
  To: virtualization, luiz.dentz, mst
  Cc: marcel, johan.hedberg, jasowang, linux-bluetooth, linux-kernel,
	Igor Skalkin

The current version of the configuration structure has unaligned
16-bit fields, but according to the specification [1], access to
the configuration space must be aligned.

Add a second, aligned  version of the configuration structure
and a new feature bit indicating that this version is being used.

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf

Signed-off-by: Igor Skalkin <Igor.Skalkin@opensynergy.com>
---
 drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
 include/uapi/linux/virtio_bt.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
index 67c21263f9e0..35f8041722c8 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -306,7 +306,12 @@ static int virtbt_probe(struct virtio_device *vdev)
        if (virtio_has_feature(vdev, VIRTIO_BT_F_VND_HCI)) {
                __u16 vendor;

-               virtio_cread(vdev, struct virtio_bt_config, vendor, &vendor);
+               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
+                       virtio_cread(vdev, struct virtio_bt_config_v2,
+                                    vendor, &vendor);
+               else
+                       virtio_cread(vdev, struct virtio_bt_config,
+                                    vendor, &vendor);

                switch (vendor) {
                case VIRTIO_BT_CONFIG_VENDOR_ZEPHYR:
@@ -339,8 +344,12 @@ static int virtbt_probe(struct virtio_device *vdev)
        if (virtio_has_feature(vdev, VIRTIO_BT_F_MSFT_EXT)) {
                __u16 msft_opcode;

-               virtio_cread(vdev, struct virtio_bt_config,
-                            msft_opcode, &msft_opcode);
+               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
+                       virtio_cread(vdev, struct virtio_bt_config_v2,
+                                    msft_opcode, &msft_opcode);
+               else
+                       virtio_cread(vdev, struct virtio_bt_config,
+                                    msft_opcode, &msft_opcode);

                hci_set_msft_opcode(hdev, msft_opcode);
        }
@@ -387,6 +396,7 @@ static const unsigned int virtbt_features[] = {
        VIRTIO_BT_F_VND_HCI,
        VIRTIO_BT_F_MSFT_EXT,
        VIRTIO_BT_F_AOSP_EXT,
+       VIRTIO_BT_F_CONFIG_V2,
 };

 static struct virtio_driver virtbt_driver = {
diff --git a/include/uapi/linux/virtio_bt.h b/include/uapi/linux/virtio_bt.h
index a7bd48daa9a9..af798f4c9680 100644
--- a/include/uapi/linux/virtio_bt.h
+++ b/include/uapi/linux/virtio_bt.h
@@ -9,6 +9,7 @@
 #define VIRTIO_BT_F_VND_HCI    0       /* Indicates vendor command support */
 #define VIRTIO_BT_F_MSFT_EXT   1       /* Indicates MSFT vendor support */
 #define VIRTIO_BT_F_AOSP_EXT   2       /* Indicates AOSP vendor support */
+#define VIRTIO_BT_F_CONFIG_V2  3       /* Use second version configuration */

 enum virtio_bt_config_type {
        VIRTIO_BT_CONFIG_TYPE_PRIMARY   = 0,
@@ -28,4 +29,11 @@ struct virtio_bt_config {
        __u16 msft_opcode;
 } __attribute__((packed));

+struct virtio_bt_config_v2 {
+       __u8  type;
+       __u8  alignment;
+       __u16 vendor;
+       __u16 msft_opcode;
+};
+
 #endif /* _UAPI_LINUX_VIRTIO_BT_H */
--
2.37.2


Please mind our privacy notice<https://www.opensynergy.com/datenschutzerklaerung/privacy-notice-for-business-partners-pursuant-to-article-13-of-the-general-data-protection-regulation-gdpr/> pursuant to Art. 13 GDPR. // Unsere Hinweise zum Datenschutz gem. Art. 13 DSGVO finden Sie hier.<https://www.opensynergy.com/de/datenschutzerklaerung/datenschutzhinweise-fuer-geschaeftspartner-gem-art-13-dsgvo/>

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 1/1] virtio_bt: Fix alignment in configuration struct
@ 2022-10-18 19:19   ` Igor Skalkin
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-18 19:19 UTC (permalink / raw)
  To: virtualization, luiz.dentz, mst
  Cc: johan.hedberg, linux-kernel, linux-bluetooth, marcel

The current version of the configuration structure has unaligned
16-bit fields, but according to the specification [1], access to
the configuration space must be aligned.

Add a second, aligned  version of the configuration structure
and a new feature bit indicating that this version is being used.

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf

Signed-off-by: Igor Skalkin <Igor.Skalkin@opensynergy.com>
---
 drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
 include/uapi/linux/virtio_bt.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
index 67c21263f9e0..35f8041722c8 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -306,7 +306,12 @@ static int virtbt_probe(struct virtio_device *vdev)
        if (virtio_has_feature(vdev, VIRTIO_BT_F_VND_HCI)) {
                __u16 vendor;

-               virtio_cread(vdev, struct virtio_bt_config, vendor, &vendor);
+               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
+                       virtio_cread(vdev, struct virtio_bt_config_v2,
+                                    vendor, &vendor);
+               else
+                       virtio_cread(vdev, struct virtio_bt_config,
+                                    vendor, &vendor);

                switch (vendor) {
                case VIRTIO_BT_CONFIG_VENDOR_ZEPHYR:
@@ -339,8 +344,12 @@ static int virtbt_probe(struct virtio_device *vdev)
        if (virtio_has_feature(vdev, VIRTIO_BT_F_MSFT_EXT)) {
                __u16 msft_opcode;

-               virtio_cread(vdev, struct virtio_bt_config,
-                            msft_opcode, &msft_opcode);
+               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
+                       virtio_cread(vdev, struct virtio_bt_config_v2,
+                                    msft_opcode, &msft_opcode);
+               else
+                       virtio_cread(vdev, struct virtio_bt_config,
+                                    msft_opcode, &msft_opcode);

                hci_set_msft_opcode(hdev, msft_opcode);
        }
@@ -387,6 +396,7 @@ static const unsigned int virtbt_features[] = {
        VIRTIO_BT_F_VND_HCI,
        VIRTIO_BT_F_MSFT_EXT,
        VIRTIO_BT_F_AOSP_EXT,
+       VIRTIO_BT_F_CONFIG_V2,
 };

 static struct virtio_driver virtbt_driver = {
diff --git a/include/uapi/linux/virtio_bt.h b/include/uapi/linux/virtio_bt.h
index a7bd48daa9a9..af798f4c9680 100644
--- a/include/uapi/linux/virtio_bt.h
+++ b/include/uapi/linux/virtio_bt.h
@@ -9,6 +9,7 @@
 #define VIRTIO_BT_F_VND_HCI    0       /* Indicates vendor command support */
 #define VIRTIO_BT_F_MSFT_EXT   1       /* Indicates MSFT vendor support */
 #define VIRTIO_BT_F_AOSP_EXT   2       /* Indicates AOSP vendor support */
+#define VIRTIO_BT_F_CONFIG_V2  3       /* Use second version configuration */

 enum virtio_bt_config_type {
        VIRTIO_BT_CONFIG_TYPE_PRIMARY   = 0,
@@ -28,4 +29,11 @@ struct virtio_bt_config {
        __u16 msft_opcode;
 } __attribute__((packed));

+struct virtio_bt_config_v2 {
+       __u8  type;
+       __u8  alignment;
+       __u16 vendor;
+       __u16 msft_opcode;
+};
+
 #endif /* _UAPI_LINUX_VIRTIO_BT_H */
--
2.37.2


Please mind our privacy notice<https://www.opensynergy.com/datenschutzerklaerung/privacy-notice-for-business-partners-pursuant-to-article-13-of-the-general-data-protection-regulation-gdpr/> pursuant to Art. 13 GDPR. // Unsere Hinweise zum Datenschutz gem. Art. 13 DSGVO finden Sie hier.<https://www.opensynergy.com/de/datenschutzerklaerung/datenschutzhinweise-fuer-geschaeftspartner-gem-art-13-dsgvo/>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* RE: virtio_bt: Fix alignment in configuration struct
  2022-10-18 19:19   ` Igor Skalkin
  (?)
@ 2022-10-18 19:54   ` bluez.test.bot
  2022-10-18 20:31     ` Luiz Augusto von Dentz
  -1 siblings, 1 reply; 18+ messages in thread
From: bluez.test.bot @ 2022-10-18 19:54 UTC (permalink / raw)
  To: linux-bluetooth, igor.skalkin

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----
error: patch failed: drivers/bluetooth/virtio_bt.c:306
error: drivers/bluetooth/virtio_bt.c: patch does not apply
error: patch failed: include/uapi/linux/virtio_bt.h:9
error: include/uapi/linux/virtio_bt.h: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch


Please resolve the issue and submit the patches again.


---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: virtio_bt: Fix alignment in configuration struct
  2022-10-18 19:54   ` bluez.test.bot
@ 2022-10-18 20:31     ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 18+ messages in thread
From: Luiz Augusto von Dentz @ 2022-10-18 20:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: igor.skalkin

Hi Igor,

On Tue, Oct 18, 2022 at 12:58 PM <bluez.test.bot@gmail.com> wrote:
>
> This is an automated email and please do not reply to this email.
>
> Dear Submitter,
>
> Thank you for submitting the patches to the linux bluetooth mailing list.
> While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
>
> ----- Output -----
> error: patch failed: drivers/bluetooth/virtio_bt.c:306
> error: drivers/bluetooth/virtio_bt.c: patch does not apply
> error: patch failed: include/uapi/linux/virtio_bt.h:9
> error: include/uapi/linux/virtio_bt.h: patch does not apply
> hint: Use 'git am --show-current-patch' to see the failed patch
>
>
> Please resolve the issue and submit the patches again.

This is very likely due to your mail server changing the format of the
patch, you can use gmail to send the email like you did previously,
that doesn't affect the commit author which is what needs to match the
Signed-off-by.

>
> ---
> Regards,
> Linux Bluetooth
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 0/1] virtio_bt: Fix alignment in configuration struct
  2022-10-18 19:19 ` Igor Skalkin
@ 2022-10-24 13:40   ` Igor Skalkin
  -1 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-24 13:40 UTC (permalink / raw)
  To: virtualization, luiz.dentz, mst
  Cc: johan.hedberg, linux-kernel, linux-bluetooth, marcel

According to specification [1], "For the device-specific configuration
space, the driver MUST use 8 bit wide accesses for 8 bit wide fields,
16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide
and aligned accesses for 32 and 64 bit wide fields.".

Current version of the configuration structure has non-aligned 16bit
fields.

This patch adds a second, aligned  version of the configuration structure
and a new feature bit indicating that this version is being used.

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf

Changes in v4:
  v3 was corrupted by our smtp server.
Changes in v3:
  v2 had been sent from the wrong address, fixed.
Changes in v2:
  The first version of this patch just changed the configuration
  structure in uapi/linux/virtio_bt.h
  This can not be done, because it will break the userspace, so the
  second version offers a less radical approach - it introduces a new
  feature bit and a new configuration structure that both the device
  and the driver will use if this bit is negotiated.

Igor Skalkin (1):
  virtio_bt: Fix alignment in configuration struct

 drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
 include/uapi/linux/virtio_bt.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

-- 
2.37.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 0/1] virtio_bt: Fix alignment in configuration struct
@ 2022-10-24 13:40   ` Igor Skalkin
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-24 13:40 UTC (permalink / raw)
  To: virtualization, luiz.dentz, mst
  Cc: marcel, johan.hedberg, jasowang, linux-bluetooth, linux-kernel,
	Igor Skalkin

According to specification [1], "For the device-specific configuration
space, the driver MUST use 8 bit wide accesses for 8 bit wide fields,
16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide
and aligned accesses for 32 and 64 bit wide fields.".

Current version of the configuration structure has non-aligned 16bit
fields.

This patch adds a second, aligned  version of the configuration structure
and a new feature bit indicating that this version is being used.

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf

Changes in v4:
  v3 was corrupted by our smtp server.
Changes in v3:
  v2 had been sent from the wrong address, fixed.
Changes in v2:
  The first version of this patch just changed the configuration
  structure in uapi/linux/virtio_bt.h
  This can not be done, because it will break the userspace, so the
  second version offers a less radical approach - it introduces a new
  feature bit and a new configuration structure that both the device
  and the driver will use if this bit is negotiated.

Igor Skalkin (1):
  virtio_bt: Fix alignment in configuration struct

 drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
 include/uapi/linux/virtio_bt.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

-- 
2.37.2


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v4 1/1] virtio_bt: Fix alignment in configuration struct
  2022-10-24 13:40   ` Igor Skalkin
@ 2022-10-24 13:40     ` Igor Skalkin
  -1 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-24 13:40 UTC (permalink / raw)
  To: virtualization, luiz.dentz, mst
  Cc: johan.hedberg, linux-kernel, linux-bluetooth, marcel

The current version of the configuration structure has unaligned
16-bit fields, but according to the specification [1], access to
the configuration space must be aligned.

Add a second, aligned  version of the configuration structure
and a new feature bit indicating that this version is being used.

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf

Signed-off-by: Igor Skalkin <Igor.Skalkin@opensynergy.com>
---
 drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
 include/uapi/linux/virtio_bt.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
index 67c21263f9e0..35f8041722c8 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -306,7 +306,12 @@ static int virtbt_probe(struct virtio_device *vdev)
 	if (virtio_has_feature(vdev, VIRTIO_BT_F_VND_HCI)) {
 		__u16 vendor;
 
-		virtio_cread(vdev, struct virtio_bt_config, vendor, &vendor);
+		if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
+			virtio_cread(vdev, struct virtio_bt_config_v2,
+				     vendor, &vendor);
+		else
+			virtio_cread(vdev, struct virtio_bt_config,
+				     vendor, &vendor);
 
 		switch (vendor) {
 		case VIRTIO_BT_CONFIG_VENDOR_ZEPHYR:
@@ -339,8 +344,12 @@ static int virtbt_probe(struct virtio_device *vdev)
 	if (virtio_has_feature(vdev, VIRTIO_BT_F_MSFT_EXT)) {
 		__u16 msft_opcode;
 
-		virtio_cread(vdev, struct virtio_bt_config,
-			     msft_opcode, &msft_opcode);
+		if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
+			virtio_cread(vdev, struct virtio_bt_config_v2,
+				     msft_opcode, &msft_opcode);
+		else
+			virtio_cread(vdev, struct virtio_bt_config,
+				     msft_opcode, &msft_opcode);
 
 		hci_set_msft_opcode(hdev, msft_opcode);
 	}
@@ -387,6 +396,7 @@ static const unsigned int virtbt_features[] = {
 	VIRTIO_BT_F_VND_HCI,
 	VIRTIO_BT_F_MSFT_EXT,
 	VIRTIO_BT_F_AOSP_EXT,
+	VIRTIO_BT_F_CONFIG_V2,
 };
 
 static struct virtio_driver virtbt_driver = {
diff --git a/include/uapi/linux/virtio_bt.h b/include/uapi/linux/virtio_bt.h
index a7bd48daa9a9..af798f4c9680 100644
--- a/include/uapi/linux/virtio_bt.h
+++ b/include/uapi/linux/virtio_bt.h
@@ -9,6 +9,7 @@
 #define VIRTIO_BT_F_VND_HCI	0	/* Indicates vendor command support */
 #define VIRTIO_BT_F_MSFT_EXT	1	/* Indicates MSFT vendor support */
 #define VIRTIO_BT_F_AOSP_EXT	2	/* Indicates AOSP vendor support */
+#define VIRTIO_BT_F_CONFIG_V2	3	/* Use second version configuration */
 
 enum virtio_bt_config_type {
 	VIRTIO_BT_CONFIG_TYPE_PRIMARY	= 0,
@@ -28,4 +29,11 @@ struct virtio_bt_config {
 	__u16 msft_opcode;
 } __attribute__((packed));
 
+struct virtio_bt_config_v2 {
+	__u8  type;
+	__u8  alignment;
+	__u16 vendor;
+	__u16 msft_opcode;
+};
+
 #endif /* _UAPI_LINUX_VIRTIO_BT_H */
-- 
2.37.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v4 1/1] virtio_bt: Fix alignment in configuration struct
@ 2022-10-24 13:40     ` Igor Skalkin
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-24 13:40 UTC (permalink / raw)
  To: virtualization, luiz.dentz, mst
  Cc: marcel, johan.hedberg, jasowang, linux-bluetooth, linux-kernel,
	Igor Skalkin

The current version of the configuration structure has unaligned
16-bit fields, but according to the specification [1], access to
the configuration space must be aligned.

Add a second, aligned  version of the configuration structure
and a new feature bit indicating that this version is being used.

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf

Signed-off-by: Igor Skalkin <Igor.Skalkin@opensynergy.com>
---
 drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
 include/uapi/linux/virtio_bt.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
index 67c21263f9e0..35f8041722c8 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -306,7 +306,12 @@ static int virtbt_probe(struct virtio_device *vdev)
 	if (virtio_has_feature(vdev, VIRTIO_BT_F_VND_HCI)) {
 		__u16 vendor;
 
-		virtio_cread(vdev, struct virtio_bt_config, vendor, &vendor);
+		if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
+			virtio_cread(vdev, struct virtio_bt_config_v2,
+				     vendor, &vendor);
+		else
+			virtio_cread(vdev, struct virtio_bt_config,
+				     vendor, &vendor);
 
 		switch (vendor) {
 		case VIRTIO_BT_CONFIG_VENDOR_ZEPHYR:
@@ -339,8 +344,12 @@ static int virtbt_probe(struct virtio_device *vdev)
 	if (virtio_has_feature(vdev, VIRTIO_BT_F_MSFT_EXT)) {
 		__u16 msft_opcode;
 
-		virtio_cread(vdev, struct virtio_bt_config,
-			     msft_opcode, &msft_opcode);
+		if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
+			virtio_cread(vdev, struct virtio_bt_config_v2,
+				     msft_opcode, &msft_opcode);
+		else
+			virtio_cread(vdev, struct virtio_bt_config,
+				     msft_opcode, &msft_opcode);
 
 		hci_set_msft_opcode(hdev, msft_opcode);
 	}
@@ -387,6 +396,7 @@ static const unsigned int virtbt_features[] = {
 	VIRTIO_BT_F_VND_HCI,
 	VIRTIO_BT_F_MSFT_EXT,
 	VIRTIO_BT_F_AOSP_EXT,
+	VIRTIO_BT_F_CONFIG_V2,
 };
 
 static struct virtio_driver virtbt_driver = {
diff --git a/include/uapi/linux/virtio_bt.h b/include/uapi/linux/virtio_bt.h
index a7bd48daa9a9..af798f4c9680 100644
--- a/include/uapi/linux/virtio_bt.h
+++ b/include/uapi/linux/virtio_bt.h
@@ -9,6 +9,7 @@
 #define VIRTIO_BT_F_VND_HCI	0	/* Indicates vendor command support */
 #define VIRTIO_BT_F_MSFT_EXT	1	/* Indicates MSFT vendor support */
 #define VIRTIO_BT_F_AOSP_EXT	2	/* Indicates AOSP vendor support */
+#define VIRTIO_BT_F_CONFIG_V2	3	/* Use second version configuration */
 
 enum virtio_bt_config_type {
 	VIRTIO_BT_CONFIG_TYPE_PRIMARY	= 0,
@@ -28,4 +29,11 @@ struct virtio_bt_config {
 	__u16 msft_opcode;
 } __attribute__((packed));
 
+struct virtio_bt_config_v2 {
+	__u8  type;
+	__u8  alignment;
+	__u16 vendor;
+	__u16 msft_opcode;
+};
+
 #endif /* _UAPI_LINUX_VIRTIO_BT_H */
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v4 1/1] virtio_bt: Fix alignment in configuration struct
  2022-10-24 13:40     ` Igor Skalkin
  (?)
@ 2022-10-24 20:54     ` Luiz Augusto von Dentz
  2022-10-25 20:17         ` Igor Skalkin
  -1 siblings, 1 reply; 18+ messages in thread
From: Luiz Augusto von Dentz @ 2022-10-24 20:54 UTC (permalink / raw)
  To: Igor Skalkin
  Cc: virtualization, mst, marcel, johan.hedberg, jasowang,
	linux-bluetooth, linux-kernel

Hi Igor,

On Mon, Oct 24, 2022 at 6:41 AM Igor Skalkin
<Igor.Skalkin@opensynergy.com> wrote:
>
> The current version of the configuration structure has unaligned
> 16-bit fields, but according to the specification [1], access to
> the configuration space must be aligned.
>
> Add a second, aligned  version of the configuration structure
> and a new feature bit indicating that this version is being used.
>
> [1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf
>
> Signed-off-by: Igor Skalkin <Igor.Skalkin@opensynergy.com>
> ---
>  drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
>  include/uapi/linux/virtio_bt.h |  8 ++++++++
>  2 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
> index 67c21263f9e0..35f8041722c8 100644
> --- a/drivers/bluetooth/virtio_bt.c
> +++ b/drivers/bluetooth/virtio_bt.c
> @@ -306,7 +306,12 @@ static int virtbt_probe(struct virtio_device *vdev)
>         if (virtio_has_feature(vdev, VIRTIO_BT_F_VND_HCI)) {
>                 __u16 vendor;
>
> -               virtio_cread(vdev, struct virtio_bt_config, vendor, &vendor);
> +               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
> +                       virtio_cread(vdev, struct virtio_bt_config_v2,
> +                                    vendor, &vendor);
> +               else
> +                       virtio_cread(vdev, struct virtio_bt_config,
> +                                    vendor, &vendor);
>
>                 switch (vendor) {
>                 case VIRTIO_BT_CONFIG_VENDOR_ZEPHYR:
> @@ -339,8 +344,12 @@ static int virtbt_probe(struct virtio_device *vdev)
>         if (virtio_has_feature(vdev, VIRTIO_BT_F_MSFT_EXT)) {
>                 __u16 msft_opcode;
>
> -               virtio_cread(vdev, struct virtio_bt_config,
> -                            msft_opcode, &msft_opcode);
> +               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
> +                       virtio_cread(vdev, struct virtio_bt_config_v2,
> +                                    msft_opcode, &msft_opcode);
> +               else
> +                       virtio_cread(vdev, struct virtio_bt_config,
> +                                    msft_opcode, &msft_opcode);
>
>                 hci_set_msft_opcode(hdev, msft_opcode);
>         }
> @@ -387,6 +396,7 @@ static const unsigned int virtbt_features[] = {
>         VIRTIO_BT_F_VND_HCI,
>         VIRTIO_BT_F_MSFT_EXT,
>         VIRTIO_BT_F_AOSP_EXT,
> +       VIRTIO_BT_F_CONFIG_V2,
>  };

So this introduces a new flag which must be checked when attempting to
config, right? But is this backward compatible? What happens if for
some reason the userspace doesn't use the new struct are we able to
detect that?

>  static struct virtio_driver virtbt_driver = {
> diff --git a/include/uapi/linux/virtio_bt.h b/include/uapi/linux/virtio_bt.h
> index a7bd48daa9a9..af798f4c9680 100644
> --- a/include/uapi/linux/virtio_bt.h
> +++ b/include/uapi/linux/virtio_bt.h
> @@ -9,6 +9,7 @@
>  #define VIRTIO_BT_F_VND_HCI    0       /* Indicates vendor command support */
>  #define VIRTIO_BT_F_MSFT_EXT   1       /* Indicates MSFT vendor support */
>  #define VIRTIO_BT_F_AOSP_EXT   2       /* Indicates AOSP vendor support */
> +#define VIRTIO_BT_F_CONFIG_V2  3       /* Use second version configuration */
>
>  enum virtio_bt_config_type {
>         VIRTIO_BT_CONFIG_TYPE_PRIMARY   = 0,
> @@ -28,4 +29,11 @@ struct virtio_bt_config {
>         __u16 msft_opcode;
>  } __attribute__((packed));
>
> +struct virtio_bt_config_v2 {
> +       __u8  type;
> +       __u8  alignment;
> +       __u16 vendor;
> +       __u16 msft_opcode;
> +};
> +
>  #endif /* _UAPI_LINUX_VIRTIO_BT_H */
> --
> 2.37.2
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: [v4,1/1] virtio_bt: Fix alignment in configuration struct
  2022-10-24 13:40     ` Igor Skalkin
  (?)
  (?)
@ 2022-10-24 21:15     ` bluez.test.bot
  -1 siblings, 0 replies; 18+ messages in thread
From: bluez.test.bot @ 2022-10-24 21:15 UTC (permalink / raw)
  To: linux-bluetooth, igor.skalkin

[-- Attachment #1: Type: text/plain, Size: 1430 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=688397

---Test result---

Test Summary:
CheckPatch                    PASS      1.80 seconds
GitLint                       PASS      1.02 seconds
SubjectPrefix                 FAIL      0.90 seconds
BuildKernel                   PASS      34.59 seconds
BuildKernel32                 PASS      31.04 seconds
Incremental Build with patchesPASS      45.75 seconds
TestRunner: Setup             PASS      515.95 seconds
TestRunner: l2cap-tester      PASS      17.43 seconds
TestRunner: iso-tester        PASS      16.58 seconds
TestRunner: bnep-tester       PASS      6.65 seconds
TestRunner: mgmt-tester       PASS      106.36 seconds
TestRunner: rfcomm-tester     PASS      10.56 seconds
TestRunner: sco-tester        PASS      10.04 seconds
TestRunner: ioctl-tester      PASS      11.22 seconds
TestRunner: mesh-tester       PASS      8.12 seconds
TestRunner: smp-tester        PASS      9.89 seconds
TestRunner: userchan-tester   PASS      6.90 seconds

Details
##############################
Test: SubjectPrefix - FAIL - 0.90 seconds
Check subject contains "Bluetooth" prefix
"Bluetooth: " is not specified in the subject



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/1] virtio_bt: Fix alignment in configuration struct
  2022-10-24 13:40   ` Igor Skalkin
@ 2022-10-25  4:04     ` Michael S. Tsirkin
  -1 siblings, 0 replies; 18+ messages in thread
From: Michael S. Tsirkin @ 2022-10-25  4:04 UTC (permalink / raw)
  To: Igor Skalkin
  Cc: virtualization, luiz.dentz, marcel, johan.hedberg, jasowang,
	linux-bluetooth, linux-kernel

On Mon, Oct 24, 2022 at 03:40:32PM +0200, Igor Skalkin wrote:
> According to specification [1], "For the device-specific configuration
> space, the driver MUST use 8 bit wide accesses for 8 bit wide fields,
> 16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide
> and aligned accesses for 32 and 64 bit wide fields.".
> 
> Current version of the configuration structure has non-aligned 16bit
> fields.
> 
> This patch adds a second, aligned  version of the configuration structure
> and a new feature bit indicating that this version is being used.


subject should be v4 but besides that, ok.
Will a spec patch be forthcoming?

> [1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf
> 
> Changes in v4:
>   v3 was corrupted by our smtp server.
> Changes in v3:
>   v2 had been sent from the wrong address, fixed.
> Changes in v2:
>   The first version of this patch just changed the configuration
>   structure in uapi/linux/virtio_bt.h
>   This can not be done, because it will break the userspace, so the
>   second version offers a less radical approach - it introduces a new
>   feature bit and a new configuration structure that both the device
>   and the driver will use if this bit is negotiated.
> 
> Igor Skalkin (1):
>   virtio_bt: Fix alignment in configuration struct
> 
>  drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
>  include/uapi/linux/virtio_bt.h |  8 ++++++++
>  2 files changed, 21 insertions(+), 3 deletions(-)
> 
> -- 
> 2.37.2


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/1] virtio_bt: Fix alignment in configuration struct
@ 2022-10-25  4:04     ` Michael S. Tsirkin
  0 siblings, 0 replies; 18+ messages in thread
From: Michael S. Tsirkin @ 2022-10-25  4:04 UTC (permalink / raw)
  To: Igor Skalkin
  Cc: johan.hedberg, linux-kernel, virtualization, linux-bluetooth,
	luiz.dentz, marcel

On Mon, Oct 24, 2022 at 03:40:32PM +0200, Igor Skalkin wrote:
> According to specification [1], "For the device-specific configuration
> space, the driver MUST use 8 bit wide accesses for 8 bit wide fields,
> 16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide
> and aligned accesses for 32 and 64 bit wide fields.".
> 
> Current version of the configuration structure has non-aligned 16bit
> fields.
> 
> This patch adds a second, aligned  version of the configuration structure
> and a new feature bit indicating that this version is being used.


subject should be v4 but besides that, ok.
Will a spec patch be forthcoming?

> [1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.pdf
> 
> Changes in v4:
>   v3 was corrupted by our smtp server.
> Changes in v3:
>   v2 had been sent from the wrong address, fixed.
> Changes in v2:
>   The first version of this patch just changed the configuration
>   structure in uapi/linux/virtio_bt.h
>   This can not be done, because it will break the userspace, so the
>   second version offers a less radical approach - it introduces a new
>   feature bit and a new configuration structure that both the device
>   and the driver will use if this bit is negotiated.
> 
> Igor Skalkin (1):
>   virtio_bt: Fix alignment in configuration struct
> 
>  drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
>  include/uapi/linux/virtio_bt.h |  8 ++++++++
>  2 files changed, 21 insertions(+), 3 deletions(-)
> 
> -- 
> 2.37.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v4 1/1] virtio_bt: Fix alignment in configuration struct
  2022-10-24 20:54     ` Luiz Augusto von Dentz
@ 2022-10-25 20:17         ` Igor Skalkin
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-25 20:17 UTC (permalink / raw)
  To: Luiz Augusto von Dentz
  Cc: virtualization, mst, marcel, johan.hedberg, jasowang,
	linux-bluetooth, linux-kernel

Hi Luiz Augusto,

On 10/24/22 22:54, Luiz Augusto von Dentz wrote:
> Hi Igor,
> 
> On Mon, Oct 24, 2022 at 6:41 AM Igor Skalkin
> <Igor.Skalkin@opensynergy.com> wrote:
>>
>> The current version of the configuration structure has unaligned
>> 16-bit fields, but according to the specification [1], access to
>> the configuration space must be aligned.
>>
>> Add a second, aligned  version of the configuration structure
>> and a new feature bit indicating that this version is being used.
>>
>> [1] https://ddec1-0-en-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fdocs.oasis%2dopen.org%2fvirtio%2fvirtio%2fv1.1%2fvirtio%2dv1.1.pdf&umid=db3482bc-5b84-4bde-bbb0-41d837955a7a&auth=53c7c7de28b92dfd96e93d9dd61a23e634d2fbec-d27a9d4c2c971f9ecc5d00d40d5cd9b45c4b5f63
>>
>> Signed-off-by: Igor Skalkin <Igor.Skalkin@opensynergy.com>
>> ---
>>  drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
>>  include/uapi/linux/virtio_bt.h |  8 ++++++++
>>  2 files changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
>> index 67c21263f9e0..35f8041722c8 100644
>> --- a/drivers/bluetooth/virtio_bt.c
>> +++ b/drivers/bluetooth/virtio_bt.c
>> @@ -306,7 +306,12 @@ static int virtbt_probe(struct virtio_device *vdev)
>>         if (virtio_has_feature(vdev, VIRTIO_BT_F_VND_HCI)) {
>>                 __u16 vendor;
>>
>> -               virtio_cread(vdev, struct virtio_bt_config, vendor, &vendor);
>> +               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
>> +                       virtio_cread(vdev, struct virtio_bt_config_v2,
>> +                                    vendor, &vendor);
>> +               else
>> +                       virtio_cread(vdev, struct virtio_bt_config,
>> +                                    vendor, &vendor);
>>
>>                 switch (vendor) {
>>                 case VIRTIO_BT_CONFIG_VENDOR_ZEPHYR:
>> @@ -339,8 +344,12 @@ static int virtbt_probe(struct virtio_device *vdev)
>>         if (virtio_has_feature(vdev, VIRTIO_BT_F_MSFT_EXT)) {
>>                 __u16 msft_opcode;
>>
>> -               virtio_cread(vdev, struct virtio_bt_config,
>> -                            msft_opcode, &msft_opcode);
>> +               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
>> +                       virtio_cread(vdev, struct virtio_bt_config_v2,
>> +                                    msft_opcode, &msft_opcode);
>> +               else
>> +                       virtio_cread(vdev, struct virtio_bt_config,
>> +                                    msft_opcode, &msft_opcode);
>>
>>                 hci_set_msft_opcode(hdev, msft_opcode);
>>         }
>> @@ -387,6 +396,7 @@ static const unsigned int virtbt_features[] = {
>>         VIRTIO_BT_F_VND_HCI,
>>         VIRTIO_BT_F_MSFT_EXT,
>>         VIRTIO_BT_F_AOSP_EXT,
>> +       VIRTIO_BT_F_CONFIG_V2,
>>  };
> 
> So this introduces a new flag which must be checked when attempting to
> config, right? But is this backward compatible? What happens if for
> some reason the userspace doesn't use the new struct are we able to
> detect that?

Yes, it's backwards compatible.

[q]Each virtio device offers all the features it understands. During
device initialization, the driver reads this and tells the device the
subset that it accepts. The only way to renegotiate is to reset the device.
This allows for forwards and backwards compatibility: if the device is
enhanced with a new feature bit, older drivers will not write that
feature bit back to the device. Similarly, if a driver is enhanced with
a feature that the device doesn’t support, it see the new feature is not
offered.[/q]

So, in our case:

old device - new driver:
The device does not offer VIRTIO_BT_F_CONFIG_V2 feature and uses the old
configuration structure.
The driver also uses the old configuration structure because
VIRTIO_BT_F_CONFIG_V2 bit was not negotiated.

new device - old driver:
The device offers this bit, the driver reads it but cannot support it,
so it does not write this bit back to the device during feature negotiation.
The device verifies that this bit is not negotiated and continues to use
the old configuration structure.


I tested this patch, it
a) works fine with a new device that supports VIRTIO_BT_F_CONFIG_V2.
b) uses the old configuration structure when working with an old device.
   Our device does not offer the VIRTIO_BT_F_VND_HCI feature bit, so the
driver does not tries to read unaligned "vendor" and "msft_opcode"
fields and everything is fine.
But, if the VIRTIO_BT_F_VND_HCI feature is set for the device for test
purposes, our middle layer asserts unaligned accesses to the
configuration space.

P.S. But, as Michael S. Tsirkin rightly stated, [q]Will a spec patch be
forthcoming?[/q], this patch requires a specification update.
I could not find any virtio_bt specification, do you have one?
That would be great. Otherwise, would you mind if I try to write some
initial draft?
>>  static struct virtio_driver virtbt_driver = {
>> diff --git a/include/uapi/linux/virtio_bt.h b/include/uapi/linux/virtio_bt.h
>> index a7bd48daa9a9..af798f4c9680 100644
>> --- a/include/uapi/linux/virtio_bt.h
>> +++ b/include/uapi/linux/virtio_bt.h
>> @@ -9,6 +9,7 @@
>>  #define VIRTIO_BT_F_VND_HCI    0       /* Indicates vendor command support */
>>  #define VIRTIO_BT_F_MSFT_EXT   1       /* Indicates MSFT vendor support */
>>  #define VIRTIO_BT_F_AOSP_EXT   2       /* Indicates AOSP vendor support */
>> +#define VIRTIO_BT_F_CONFIG_V2  3       /* Use second version configuration */
>>
>>  enum virtio_bt_config_type {
>>         VIRTIO_BT_CONFIG_TYPE_PRIMARY   = 0,
>> @@ -28,4 +29,11 @@ struct virtio_bt_config {
>>         __u16 msft_opcode;
>>  } __attribute__((packed));
>>
>> +struct virtio_bt_config_v2 {
>> +       __u8  type;
>> +       __u8  alignment;
>> +       __u16 vendor;
>> +       __u16 msft_opcode;
>> +};
>> +
>>  #endif /* _UAPI_LINUX_VIRTIO_BT_H */
>> --
>> 2.37.2


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v4 1/1] virtio_bt: Fix alignment in configuration struct
@ 2022-10-25 20:17         ` Igor Skalkin
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Skalkin @ 2022-10-25 20:17 UTC (permalink / raw)
  To: Luiz Augusto von Dentz
  Cc: johan.hedberg, mst, linux-kernel, virtualization,
	linux-bluetooth, marcel

Hi Luiz Augusto,

On 10/24/22 22:54, Luiz Augusto von Dentz wrote:
> Hi Igor,
> 
> On Mon, Oct 24, 2022 at 6:41 AM Igor Skalkin
> <Igor.Skalkin@opensynergy.com> wrote:
>>
>> The current version of the configuration structure has unaligned
>> 16-bit fields, but according to the specification [1], access to
>> the configuration space must be aligned.
>>
>> Add a second, aligned  version of the configuration structure
>> and a new feature bit indicating that this version is being used.
>>
>> [1] https://ddec1-0-en-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fdocs.oasis%2dopen.org%2fvirtio%2fvirtio%2fv1.1%2fvirtio%2dv1.1.pdf&umid=db3482bc-5b84-4bde-bbb0-41d837955a7a&auth=53c7c7de28b92dfd96e93d9dd61a23e634d2fbec-d27a9d4c2c971f9ecc5d00d40d5cd9b45c4b5f63
>>
>> Signed-off-by: Igor Skalkin <Igor.Skalkin@opensynergy.com>
>> ---
>>  drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
>>  include/uapi/linux/virtio_bt.h |  8 ++++++++
>>  2 files changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
>> index 67c21263f9e0..35f8041722c8 100644
>> --- a/drivers/bluetooth/virtio_bt.c
>> +++ b/drivers/bluetooth/virtio_bt.c
>> @@ -306,7 +306,12 @@ static int virtbt_probe(struct virtio_device *vdev)
>>         if (virtio_has_feature(vdev, VIRTIO_BT_F_VND_HCI)) {
>>                 __u16 vendor;
>>
>> -               virtio_cread(vdev, struct virtio_bt_config, vendor, &vendor);
>> +               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
>> +                       virtio_cread(vdev, struct virtio_bt_config_v2,
>> +                                    vendor, &vendor);
>> +               else
>> +                       virtio_cread(vdev, struct virtio_bt_config,
>> +                                    vendor, &vendor);
>>
>>                 switch (vendor) {
>>                 case VIRTIO_BT_CONFIG_VENDOR_ZEPHYR:
>> @@ -339,8 +344,12 @@ static int virtbt_probe(struct virtio_device *vdev)
>>         if (virtio_has_feature(vdev, VIRTIO_BT_F_MSFT_EXT)) {
>>                 __u16 msft_opcode;
>>
>> -               virtio_cread(vdev, struct virtio_bt_config,
>> -                            msft_opcode, &msft_opcode);
>> +               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
>> +                       virtio_cread(vdev, struct virtio_bt_config_v2,
>> +                                    msft_opcode, &msft_opcode);
>> +               else
>> +                       virtio_cread(vdev, struct virtio_bt_config,
>> +                                    msft_opcode, &msft_opcode);
>>
>>                 hci_set_msft_opcode(hdev, msft_opcode);
>>         }
>> @@ -387,6 +396,7 @@ static const unsigned int virtbt_features[] = {
>>         VIRTIO_BT_F_VND_HCI,
>>         VIRTIO_BT_F_MSFT_EXT,
>>         VIRTIO_BT_F_AOSP_EXT,
>> +       VIRTIO_BT_F_CONFIG_V2,
>>  };
> 
> So this introduces a new flag which must be checked when attempting to
> config, right? But is this backward compatible? What happens if for
> some reason the userspace doesn't use the new struct are we able to
> detect that?

Yes, it's backwards compatible.

[q]Each virtio device offers all the features it understands. During
device initialization, the driver reads this and tells the device the
subset that it accepts. The only way to renegotiate is to reset the device.
This allows for forwards and backwards compatibility: if the device is
enhanced with a new feature bit, older drivers will not write that
feature bit back to the device. Similarly, if a driver is enhanced with
a feature that the device doesn’t support, it see the new feature is not
offered.[/q]

So, in our case:

old device - new driver:
The device does not offer VIRTIO_BT_F_CONFIG_V2 feature and uses the old
configuration structure.
The driver also uses the old configuration structure because
VIRTIO_BT_F_CONFIG_V2 bit was not negotiated.

new device - old driver:
The device offers this bit, the driver reads it but cannot support it,
so it does not write this bit back to the device during feature negotiation.
The device verifies that this bit is not negotiated and continues to use
the old configuration structure.


I tested this patch, it
a) works fine with a new device that supports VIRTIO_BT_F_CONFIG_V2.
b) uses the old configuration structure when working with an old device.
   Our device does not offer the VIRTIO_BT_F_VND_HCI feature bit, so the
driver does not tries to read unaligned "vendor" and "msft_opcode"
fields and everything is fine.
But, if the VIRTIO_BT_F_VND_HCI feature is set for the device for test
purposes, our middle layer asserts unaligned accesses to the
configuration space.

P.S. But, as Michael S. Tsirkin rightly stated, [q]Will a spec patch be
forthcoming?[/q], this patch requires a specification update.
I could not find any virtio_bt specification, do you have one?
That would be great. Otherwise, would you mind if I try to write some
initial draft?
>>  static struct virtio_driver virtbt_driver = {
>> diff --git a/include/uapi/linux/virtio_bt.h b/include/uapi/linux/virtio_bt.h
>> index a7bd48daa9a9..af798f4c9680 100644
>> --- a/include/uapi/linux/virtio_bt.h
>> +++ b/include/uapi/linux/virtio_bt.h
>> @@ -9,6 +9,7 @@
>>  #define VIRTIO_BT_F_VND_HCI    0       /* Indicates vendor command support */
>>  #define VIRTIO_BT_F_MSFT_EXT   1       /* Indicates MSFT vendor support */
>>  #define VIRTIO_BT_F_AOSP_EXT   2       /* Indicates AOSP vendor support */
>> +#define VIRTIO_BT_F_CONFIG_V2  3       /* Use second version configuration */
>>
>>  enum virtio_bt_config_type {
>>         VIRTIO_BT_CONFIG_TYPE_PRIMARY   = 0,
>> @@ -28,4 +29,11 @@ struct virtio_bt_config {
>>         __u16 msft_opcode;
>>  } __attribute__((packed));
>>
>> +struct virtio_bt_config_v2 {
>> +       __u8  type;
>> +       __u8  alignment;
>> +       __u16 vendor;
>> +       __u16 msft_opcode;
>> +};
>> +
>>  #endif /* _UAPI_LINUX_VIRTIO_BT_H */
>> --
>> 2.37.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v4 1/1] virtio_bt: Fix alignment in configuration struct
  2022-10-25 20:17         ` Igor Skalkin
  (?)
@ 2022-10-25 20:32         ` Luiz Augusto von Dentz
  -1 siblings, 0 replies; 18+ messages in thread
From: Luiz Augusto von Dentz @ 2022-10-25 20:32 UTC (permalink / raw)
  To: Igor Skalkin
  Cc: virtualization, mst, marcel, johan.hedberg, jasowang,
	linux-bluetooth, linux-kernel

Hi Igor,

On Tue, Oct 25, 2022 at 1:17 PM Igor Skalkin
<igor.skalkin@opensynergy.com> wrote:
>
> Hi Luiz Augusto,
>
> On 10/24/22 22:54, Luiz Augusto von Dentz wrote:
> > Hi Igor,
> >
> > On Mon, Oct 24, 2022 at 6:41 AM Igor Skalkin
> > <Igor.Skalkin@opensynergy.com> wrote:
> >>
> >> The current version of the configuration structure has unaligned
> >> 16-bit fields, but according to the specification [1], access to
> >> the configuration space must be aligned.
> >>
> >> Add a second, aligned  version of the configuration structure
> >> and a new feature bit indicating that this version is being used.
> >>
> >> [1] https://ddec1-0-en-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fdocs.oasis%2dopen.org%2fvirtio%2fvirtio%2fv1.1%2fvirtio%2dv1.1.pdf&umid=db3482bc-5b84-4bde-bbb0-41d837955a7a&auth=53c7c7de28b92dfd96e93d9dd61a23e634d2fbec-d27a9d4c2c971f9ecc5d00d40d5cd9b45c4b5f63
> >>
> >> Signed-off-by: Igor Skalkin <Igor.Skalkin@opensynergy.com>
> >> ---
> >>  drivers/bluetooth/virtio_bt.c  | 16 +++++++++++++---
> >>  include/uapi/linux/virtio_bt.h |  8 ++++++++
> >>  2 files changed, 21 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
> >> index 67c21263f9e0..35f8041722c8 100644
> >> --- a/drivers/bluetooth/virtio_bt.c
> >> +++ b/drivers/bluetooth/virtio_bt.c
> >> @@ -306,7 +306,12 @@ static int virtbt_probe(struct virtio_device *vdev)
> >>         if (virtio_has_feature(vdev, VIRTIO_BT_F_VND_HCI)) {
> >>                 __u16 vendor;
> >>
> >> -               virtio_cread(vdev, struct virtio_bt_config, vendor, &vendor);
> >> +               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
> >> +                       virtio_cread(vdev, struct virtio_bt_config_v2,
> >> +                                    vendor, &vendor);
> >> +               else
> >> +                       virtio_cread(vdev, struct virtio_bt_config,
> >> +                                    vendor, &vendor);
> >>
> >>                 switch (vendor) {
> >>                 case VIRTIO_BT_CONFIG_VENDOR_ZEPHYR:
> >> @@ -339,8 +344,12 @@ static int virtbt_probe(struct virtio_device *vdev)
> >>         if (virtio_has_feature(vdev, VIRTIO_BT_F_MSFT_EXT)) {
> >>                 __u16 msft_opcode;
> >>
> >> -               virtio_cread(vdev, struct virtio_bt_config,
> >> -                            msft_opcode, &msft_opcode);
> >> +               if (virtio_has_feature(vdev, VIRTIO_BT_F_CONFIG_V2))
> >> +                       virtio_cread(vdev, struct virtio_bt_config_v2,
> >> +                                    msft_opcode, &msft_opcode);
> >> +               else
> >> +                       virtio_cread(vdev, struct virtio_bt_config,
> >> +                                    msft_opcode, &msft_opcode);
> >>
> >>                 hci_set_msft_opcode(hdev, msft_opcode);
> >>         }
> >> @@ -387,6 +396,7 @@ static const unsigned int virtbt_features[] = {
> >>         VIRTIO_BT_F_VND_HCI,
> >>         VIRTIO_BT_F_MSFT_EXT,
> >>         VIRTIO_BT_F_AOSP_EXT,
> >> +       VIRTIO_BT_F_CONFIG_V2,
> >>  };
> >
> > So this introduces a new flag which must be checked when attempting to
> > config, right? But is this backward compatible? What happens if for
> > some reason the userspace doesn't use the new struct are we able to
> > detect that?
>
> Yes, it's backwards compatible.
>
> [q]Each virtio device offers all the features it understands. During
> device initialization, the driver reads this and tells the device the
> subset that it accepts. The only way to renegotiate is to reset the device.
> This allows for forwards and backwards compatibility: if the device is
> enhanced with a new feature bit, older drivers will not write that
> feature bit back to the device. Similarly, if a driver is enhanced with
> a feature that the device doesn’t support, it see the new feature is not
> offered.[/q]
>
> So, in our case:
>
> old device - new driver:
> The device does not offer VIRTIO_BT_F_CONFIG_V2 feature and uses the old
> configuration structure.
> The driver also uses the old configuration structure because
> VIRTIO_BT_F_CONFIG_V2 bit was not negotiated.
>
> new device - old driver:
> The device offers this bit, the driver reads it but cannot support it,
> so it does not write this bit back to the device during feature negotiation.
> The device verifies that this bit is not negotiated and continues to use
> the old configuration structure.
>
>
> I tested this patch, it
> a) works fine with a new device that supports VIRTIO_BT_F_CONFIG_V2.
> b) uses the old configuration structure when working with an old device.
>    Our device does not offer the VIRTIO_BT_F_VND_HCI feature bit, so the
> driver does not tries to read unaligned "vendor" and "msft_opcode"
> fields and everything is fine.
> But, if the VIRTIO_BT_F_VND_HCI feature is set for the device for test
> purposes, our middle layer asserts unaligned accesses to the
> configuration space.

Great, thanks for the explanation.

> P.S. But, as Michael S. Tsirkin rightly stated, [q]Will a spec patch be
> forthcoming?[/q], this patch requires a specification update.
> I could not find any virtio_bt specification, do you have one?
> That would be great. Otherwise, would you mind if I try to write some
> initial draft?

Yep, I don't think we have one so feel free to start one, also while
at it we could perhaps attempt to write a tester for it so we can test
it using our CI, assuming virtio works with virtual devices created by
vhci driver.

> >>  static struct virtio_driver virtbt_driver = {
> >> diff --git a/include/uapi/linux/virtio_bt.h b/include/uapi/linux/virtio_bt.h
> >> index a7bd48daa9a9..af798f4c9680 100644
> >> --- a/include/uapi/linux/virtio_bt.h
> >> +++ b/include/uapi/linux/virtio_bt.h
> >> @@ -9,6 +9,7 @@
> >>  #define VIRTIO_BT_F_VND_HCI    0       /* Indicates vendor command support */
> >>  #define VIRTIO_BT_F_MSFT_EXT   1       /* Indicates MSFT vendor support */
> >>  #define VIRTIO_BT_F_AOSP_EXT   2       /* Indicates AOSP vendor support */
> >> +#define VIRTIO_BT_F_CONFIG_V2  3       /* Use second version configuration */
> >>
> >>  enum virtio_bt_config_type {
> >>         VIRTIO_BT_CONFIG_TYPE_PRIMARY   = 0,
> >> @@ -28,4 +29,11 @@ struct virtio_bt_config {
> >>         __u16 msft_opcode;
> >>  } __attribute__((packed));
> >>
> >> +struct virtio_bt_config_v2 {
> >> +       __u8  type;
> >> +       __u8  alignment;
> >> +       __u16 vendor;
> >> +       __u16 msft_opcode;
> >> +};
> >> +
> >>  #endif /* _UAPI_LINUX_VIRTIO_BT_H */
> >> --
> >> 2.37.2
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v4 1/1] virtio_bt: Fix alignment in configuration struct
  2022-10-24 13:40     ` Igor Skalkin
                       ` (2 preceding siblings ...)
  (?)
@ 2022-10-25 22:40     ` patchwork-bot+bluetooth
  -1 siblings, 0 replies; 18+ messages in thread
From: patchwork-bot+bluetooth @ 2022-10-25 22:40 UTC (permalink / raw)
  To: Igor Skalkin
  Cc: virtualization, luiz.dentz, mst, marcel, johan.hedberg, jasowang,
	linux-bluetooth, linux-kernel, Igor.Skalkin

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 24 Oct 2022 15:40:33 +0200 you wrote:
> The current version of the configuration structure has unaligned
> 16-bit fields, but according to the specification [1], access to
> the configuration space must be aligned.
> 
> Add a second, aligned  version of the configuration structure
> and a new feature bit indicating that this version is being used.
> 
> [...]

Here is the summary with links:
  - [v4,1/1] virtio_bt: Fix alignment in configuration struct
    https://git.kernel.org/bluetooth/bluetooth-next/c/57dc0d471d27

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-10-25 22:40 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 19:19 [PATCH v3 0/1] virtio_bt: Fix alignment in configuration struct Igor Skalkin
2022-10-18 19:19 ` Igor Skalkin
2022-10-18 19:19 ` [PATCH v3 1/1] " Igor Skalkin
2022-10-18 19:19   ` Igor Skalkin
2022-10-18 19:54   ` bluez.test.bot
2022-10-18 20:31     ` Luiz Augusto von Dentz
2022-10-24 13:40 ` [PATCH v3 0/1] " Igor Skalkin
2022-10-24 13:40   ` Igor Skalkin
2022-10-24 13:40   ` [PATCH v4 1/1] " Igor Skalkin
2022-10-24 13:40     ` Igor Skalkin
2022-10-24 20:54     ` Luiz Augusto von Dentz
2022-10-25 20:17       ` Igor Skalkin
2022-10-25 20:17         ` Igor Skalkin
2022-10-25 20:32         ` Luiz Augusto von Dentz
2022-10-24 21:15     ` [v4,1/1] " bluez.test.bot
2022-10-25 22:40     ` [PATCH v4 1/1] " patchwork-bot+bluetooth
2022-10-25  4:04   ` [PATCH v3 0/1] " Michael S. Tsirkin
2022-10-25  4:04     ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.