Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7527510rwi; Mon, 24 Oct 2022 16:15:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5/t+izCpDUOhXBxkJqFsuGGnDpGdq+oPKvydhMnJdqTWs5pll478Bh0/ldOexEKwbOHLx9 X-Received: by 2002:a05:6402:c45:b0:442:c549:8e6b with SMTP id cs5-20020a0564020c4500b00442c5498e6bmr33027982edb.123.1666653316431; Mon, 24 Oct 2022 16:15:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666653316; cv=none; d=google.com; s=arc-20160816; b=i4xp7z24w1jdSxjlRwV7K5h6zR6ZHhumYGXENHabb5L7oiKQiK6raacJm8z8KUd7/N vkyopqHI7IjXl22CMu3U2ec+1h5DEy/sq2XVPnmfQf9fRgFRq4mcnu+1bEeIcBFvlyID 2x9JVdDdSvF6rWP8HMOSCBREq1EUwViySlQtd/8NQ+4uV9AVPtARLjkecWlK2PU3G9HT 8MuuTkYsraY2n1xGEAVchjVM9sUNUzrYYH9J2Vo1z3ZBUemM5SrEZXiK01WN/PvdqzYR XlmUJGw8I9KwgZ1/sVGJtu1VCawh1M7XkF7GGSzLw3vLGvZJeWOjnprhbI2+feegtJdq zItA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=lpmvn6r7dh60+tXCwg9HVv88NIhkpPaXAz7PN44Ep2g=; b=VgpfSHqAMZCbSLK7iNc2rCR+PNRRzrZ8fMRyo+XifXkDCxgwGR02S+dkLg+Ejpd8hA osJdk1gehvU0jilT9KBv7HCDGMteBhjR9xCVFhy45+2aACNERlEwDbNDxsyGsek45WSI iQD4U6nDbY4zAVGKGyWVa4e38JUCApA7OnrIJZS/9thpd0H4WdJVMlOV1J7ZFRd24sVY DC5bOklzp928ShR1KuMbv+eowENr0aIKWmSxfgOW2MD5J/arPHCe+NIIniheeuuosRwl Xwwp1UXGRZxEC8vnDRireFjLtke1XYBUut3Hiy5gymBqxFKtdT1O5wHwxxGAW4fKfaFw qQyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oa5GbDJ8; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa23-20020a1709076d1700b0078d9c0e8971si1057387ejc.752.2022.10.24.16.14.46; Mon, 24 Oct 2022 16:15:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oa5GbDJ8; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbiJXXGH (ORCPT + 99 others); Mon, 24 Oct 2022 19:06:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbiJXXFd (ORCPT ); Mon, 24 Oct 2022 19:05:33 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2704928E07C; Mon, 24 Oct 2022 14:26:55 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id be13so18776412lfb.4; Mon, 24 Oct 2022 14:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=lpmvn6r7dh60+tXCwg9HVv88NIhkpPaXAz7PN44Ep2g=; b=oa5GbDJ8fcj7npsls3OssMNUVigy+PTewvlQmBBoDoi3MrZ0aMwPLyxD1uf8fqcLZ0 MCi6fqWraBirLQPpYixafFBpK2g1WUoP2WdN22To+uCTHC1vAS/YgEMed90lHKp/9il5 bVRFf3AVaeYJ41tZ59RxKw9W8Fqx2PVQd74JNxkvseXvdIt2kArF2ENlU+wwKl2TnvP3 dqqsLzJF/WYEhjOQgs6+3CHSnzYzifpc4+MQtJkNeYPj5uzU7M3R5+UCaQV2luYlwSl3 gWn37ygBR6JXvLYPWcuCBPtUmVgXklWh3qUvimaFuhw0skGPxdBcSCIICJVlNBgT5o59 mjPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lpmvn6r7dh60+tXCwg9HVv88NIhkpPaXAz7PN44Ep2g=; b=l7wTndwJg3QyqM6hPlKfvCsai9iriCOYdWc9HoxIBeghJTsil5iB7Ph7aquZ1D6Di4 dfRbhELvp7h9mgcb27NYVzC33f+OgbO6sHGlTFVNY5OKBR/PULoHuLgyX7eJd/jDPHzA Mr2dcMOx/9QTWbaPwZ5GRZMeHIumy/XmrVOVVPg/rTXGeJbCBkBqpUynyDPzEoKXOjCk HOpQ6utDqyoCSEfM+IRVdvXxCfWnhNiO3IG4d3Hw6ZItXUY8fOnin2q5X34gEAaMeKAx yncoMegI/lYnxspAJ8bFy2JyIA6JbwpX0n5sL0MJQPa+LM7nxxaNLHL5slQgJzcWDkSY vMOg== X-Gm-Message-State: ACrzQf2B2eI4EYdnOkAHP54GQIFUAersrxXF6oo7grrgCgdKFXhVgrSJ iHKJVrmIbc/fH0hDb3E4F9VC1SZ4uD7wxlPtL/qYOuGlOAM= X-Received: by 2002:a05:651c:4ce:b0:26f:e2fd:57ed with SMTP id e14-20020a05651c04ce00b0026fe2fd57edmr13810523lji.161.1666644876485; Mon, 24 Oct 2022 13:54:36 -0700 (PDT) MIME-Version: 1.0 References: <20221018191911.589564-1-Igor.Skalkin@opensynergy.com> <20221024134033.30142-1-Igor.Skalkin@opensynergy.com> <20221024134033.30142-2-Igor.Skalkin@opensynergy.com> In-Reply-To: <20221024134033.30142-2-Igor.Skalkin@opensynergy.com> From: Luiz Augusto von Dentz Date: Mon, 24 Oct 2022 13:54:24 -0700 Message-ID: Subject: Re: [PATCH v4 1/1] virtio_bt: Fix alignment in configuration struct To: Igor Skalkin Cc: virtualization@lists.linux-foundation.org, mst@redhat.com, marcel@holtmann.org, johan.hedberg@gmail.com, jasowang@redhat.com, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Igor, On Mon, Oct 24, 2022 at 6:41 AM Igor Skalkin 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 > --- > 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