From patchwork Fri Jul 1 13:28:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12903307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB5DEC433EF for ; Fri, 1 Jul 2022 13:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231297AbiGANgR (ORCPT ); Fri, 1 Jul 2022 09:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231361AbiGANgP (ORCPT ); Fri, 1 Jul 2022 09:36:15 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73A7B167C9 for ; Fri, 1 Jul 2022 06:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656682574; x=1688218574; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h9JuejVy5sfA85HHvW6hE2dzeY7YiQJl4dEbEkp7nKM=; b=HKTevylEU/ufaohktz2pftrBoh+FvfwB12Ap+mR95Y9auae/rNMuppfJ fhWf673yAXHgNhQEGUtRscFiuKqc1z9F6eT9pgn8UwxFMOLzHIu1W62N7 NkXq5wF2+4J8xQrEesOCyLUCr7GCZDUjVrRYQPHhOfzWQgEJURbLHD1G3 YM8n/W/Us+856yFdxJ5QQMqfyrj0cu0MOAZmSn0oe/2pluelEfyxCODF3 CwbKv7lAm260VJswr9/8BLCf6qe2DuxSBguMK1R20iK6UJqvLUptpfstF bU8AEpPzH0u5w1bNCJei7GFnZs9xGrfR6mGd8lV+fhlYT70RpdsEraFOo Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10394"; a="282682896" X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="282682896" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:14 -0700 X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="648349618" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:12 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, parav@nvidia.com, xieyongji@bytedance.com, gautam.dawar@amd.com, Zhu Lingshan Subject: [PATCH V3 1/6] vDPA/ifcvf: get_config_size should return a value no greater than dev implementation Date: Fri, 1 Jul 2022 21:28:21 +0800 Message-Id: <20220701132826.8132-2-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220701132826.8132-1-lingshan.zhu@intel.com> References: <20220701132826.8132-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org ifcvf_get_config_size() should return a virtio device type specific value, however the ret_value should not be greater than the onboard size of the device implementation. E.g., for virtio_net, config_size should be the minimum value of sizeof(struct virtio_net_config) and the onboard cap size. Signed-off-by: Zhu Lingshan --- drivers/vdpa/ifcvf/ifcvf_base.c | 13 +++++++++++-- drivers/vdpa/ifcvf/ifcvf_base.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c b/drivers/vdpa/ifcvf/ifcvf_base.c index 48c4dadb0c7c..fb957b57941e 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.c +++ b/drivers/vdpa/ifcvf/ifcvf_base.c @@ -128,6 +128,7 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) break; case VIRTIO_PCI_CAP_DEVICE_CFG: hw->dev_cfg = get_cap_addr(hw, &cap); + hw->cap_dev_config_size = le32_to_cpu(cap.length); IFCVF_DBG(pdev, "hw->dev_cfg = %p\n", hw->dev_cfg); break; } @@ -233,15 +234,23 @@ int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features) u32 ifcvf_get_config_size(struct ifcvf_hw *hw) { struct ifcvf_adapter *adapter; + u32 net_config_size = sizeof(struct virtio_net_config); + u32 blk_config_size = sizeof(struct virtio_blk_config); + u32 cap_size = hw->cap_dev_config_size; u32 config_size; adapter = vf_to_adapter(hw); + /* If the onboard device config space size is greater than + * the size of struct virtio_net/blk_config, only the spec + * implementing contents size is returned, this is very + * unlikely, defensive programming. + */ switch (hw->dev_type) { case VIRTIO_ID_NET: - config_size = sizeof(struct virtio_net_config); + config_size = cap_size >= net_config_size ? net_config_size : cap_size; break; case VIRTIO_ID_BLOCK: - config_size = sizeof(struct virtio_blk_config); + config_size = cap_size >= blk_config_size ? blk_config_size : cap_size; break; default: config_size = 0; diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h index 115b61f4924b..f5563f665cc6 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.h +++ b/drivers/vdpa/ifcvf/ifcvf_base.h @@ -87,6 +87,8 @@ struct ifcvf_hw { int config_irq; int vqs_reused_irq; u16 nr_vring; + /* VIRTIO_PCI_CAP_DEVICE_CFG size */ + u32 cap_dev_config_size; }; struct ifcvf_adapter { From patchwork Fri Jul 1 13:28:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12903308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 581FEC43334 for ; Fri, 1 Jul 2022 13:36:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231435AbiGANgV (ORCPT ); Fri, 1 Jul 2022 09:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbiGANgR (ORCPT ); Fri, 1 Jul 2022 09:36:17 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 932CD167C9 for ; Fri, 1 Jul 2022 06:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656682576; x=1688218576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TeySH30IitlNkryD+dU4O+wR5NVGcicABDK0hQigNu4=; b=CbvuIhqcKEeJ08xozOV+gVIu6qSNt5qx6//gtpLRkrJ5Te54DOdcXa6k HBQJeUjWe1AOGJ5Pdrv1vdytMIwsafC+dU2QCYJyqitf+V7z/3iT8lkhE GqqoMtlkTbvVt28OwyMSOfQWquQOW3CcqS0Kq7glQRWNTVlq6A1yySO6B m7+r0av6nRWgtMzNAeBzY31czfI5vNdafpuq3lRu5Hg70QBoaOTP20Fen vjLktadoYEaSocVESQpgPdvAbIisGhMWB7DKGGZxhV+MJgEec4vSrsO2o KhcEH+USXQ/9pJ20igVnD3pSgNaEBwS4wuz+KyCTHBmOBEHm00F/PqzZs Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10394"; a="282682904" X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="282682904" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:16 -0700 X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="648349627" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:14 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, parav@nvidia.com, xieyongji@bytedance.com, gautam.dawar@amd.com, Zhu Lingshan Subject: [PATCH V3 2/6] vDPA/ifcvf: support userspace to query features and MQ of a management device Date: Fri, 1 Jul 2022 21:28:22 +0800 Message-Id: <20220701132826.8132-3-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220701132826.8132-1-lingshan.zhu@intel.com> References: <20220701132826.8132-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Adapting to current netlink interfaces, this commit allows userspace to query feature bits and MQ capability of a management device. Signed-off-by: Zhu Lingshan --- drivers/vdpa/ifcvf/ifcvf_base.c | 12 ++++++++++++ drivers/vdpa/ifcvf/ifcvf_base.h | 1 + drivers/vdpa/ifcvf/ifcvf_main.c | 3 +++ 3 files changed, 16 insertions(+) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c b/drivers/vdpa/ifcvf/ifcvf_base.c index fb957b57941e..7c5f1cc93ad9 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.c +++ b/drivers/vdpa/ifcvf/ifcvf_base.c @@ -346,6 +346,18 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num) return 0; } +u16 ifcvf_get_max_vq_pairs(struct ifcvf_hw *hw) +{ + struct virtio_net_config __iomem *config; + u16 val, mq; + + config = hw->dev_cfg; + val = vp_ioread16((__le16 __iomem *)&config->max_virtqueue_pairs); + mq = le16_to_cpu((__force __le16)val); + + return mq; +} + static int ifcvf_hw_enable(struct ifcvf_hw *hw) { struct virtio_pci_common_cfg __iomem *cfg; diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h index f5563f665cc6..d54a1bed212e 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.h +++ b/drivers/vdpa/ifcvf/ifcvf_base.h @@ -130,6 +130,7 @@ u64 ifcvf_get_hw_features(struct ifcvf_hw *hw); int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features); u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid); int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num); +u16 ifcvf_get_max_vq_pairs(struct ifcvf_hw *hw); struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw); int ifcvf_probed_virtio_net(struct ifcvf_hw *hw); u32 ifcvf_get_config_size(struct ifcvf_hw *hw); diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 0a5670729412..3ff7096d30f1 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -791,6 +791,9 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, vf->hw_features = ifcvf_get_hw_features(vf); vf->config_size = ifcvf_get_config_size(vf); + ifcvf_mgmt_dev->mdev.max_supported_vqs = ifcvf_get_max_vq_pairs(vf); + ifcvf_mgmt_dev->mdev.supported_features = vf->hw_features; + adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev; ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring); if (ret) { From patchwork Fri Jul 1 13:28:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12903309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E6FAC433EF for ; Fri, 1 Jul 2022 13:36:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231407AbiGANgW (ORCPT ); Fri, 1 Jul 2022 09:36:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231361AbiGANgT (ORCPT ); Fri, 1 Jul 2022 09:36:19 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFBD217040 for ; Fri, 1 Jul 2022 06:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656682578; x=1688218578; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Reo8CxYRewxfHBU6WtEXtmO9UgPYY/KQX9B0Ypt+ZUg=; b=WGpzEXuDm2QTOB5ZmBDRRyfmxKotvBc27rsGooxdKjT1jDLT/0kMRp+c 8HOj9BvZLbu+S2Z5D5wmgilT13PXFJxWdHipUglbdaVeIEelKSteS+c2r U8RydvHijg0TTTW48ip5yVAALSK2qVTnFU7Xfz8IZaF/AaoqQeUxKXNjD PuSbnaCDFCXMFO75YKl1Cm0BtMIVYvyN0+F8O6LpyjE+Efr8zlofv/g07 /S+y56JBGp/GElvvmba878MPxMZbR2PXY/psbz5rZWbyvGWXcPSFnnxG0 c30SLm9BJpytZI2BGZP4rSspQRBnE0qAI2d/SyvZse6XwkOZ7jXuP9Wxc A==; X-IronPort-AV: E=McAfee;i="6400,9594,10394"; a="282682911" X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="282682911" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:18 -0700 X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="648349635" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:16 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, parav@nvidia.com, xieyongji@bytedance.com, gautam.dawar@amd.com, Zhu Lingshan Subject: [PATCH V3 3/6] vDPA: allow userspace to query features of a vDPA device Date: Fri, 1 Jul 2022 21:28:23 +0800 Message-Id: <20220701132826.8132-4-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220701132826.8132-1-lingshan.zhu@intel.com> References: <20220701132826.8132-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This commit adds a new vDPA netlink attribution VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES. Userspace can query features of vDPA devices through this new attr. Fixes: a64917bc2e9b vdpa: (Provide interface to read driver feature) Signed-off-by: Zhu Lingshan --- drivers/vdpa/vdpa.c | 13 +++++++++---- include/uapi/linux/vdpa.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index ebf2f363fbe7..9b0e39b2f022 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -815,7 +815,7 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev, static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg) { struct virtio_net_config config = {}; - u64 features; + u64 features_device, features_driver; u16 val_u16; vdpa_get_config_unlocked(vdev, 0, &config, sizeof(config)); @@ -832,12 +832,17 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16)) return -EMSGSIZE; - features = vdev->config->get_driver_features(vdev); - if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features, + features_driver = vdev->config->get_driver_features(vdev); + if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver, + VDPA_ATTR_PAD)) + return -EMSGSIZE; + + features_device = vdev->config->get_device_features(vdev); + if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device, VDPA_ATTR_PAD)) return -EMSGSIZE; - return vdpa_dev_net_mq_config_fill(vdev, msg, features, &config); + return vdpa_dev_net_mq_config_fill(vdev, msg, features_driver, &config); } static int diff --git a/include/uapi/linux/vdpa.h b/include/uapi/linux/vdpa.h index 25c55cab3d7c..39f1c3d7c112 100644 --- a/include/uapi/linux/vdpa.h +++ b/include/uapi/linux/vdpa.h @@ -47,6 +47,7 @@ enum vdpa_attr { VDPA_ATTR_DEV_NEGOTIATED_FEATURES, /* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS, /* u32 */ VDPA_ATTR_DEV_SUPPORTED_FEATURES, /* u64 */ + VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, /* u64 */ VDPA_ATTR_DEV_QUEUE_INDEX, /* u32 */ VDPA_ATTR_DEV_VENDOR_ATTR_NAME, /* string */ From patchwork Fri Jul 1 13:28:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12903310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6943EC43334 for ; Fri, 1 Jul 2022 13:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231466AbiGANgY (ORCPT ); Fri, 1 Jul 2022 09:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231429AbiGANgV (ORCPT ); Fri, 1 Jul 2022 09:36:21 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D200A17589 for ; Fri, 1 Jul 2022 06:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656682580; x=1688218580; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V6w/dAG4EE5bDzyLtgiiTv060y/2l8ouvlrLcz0KnS0=; b=SeE2x/kLRXmMJPZa3SkDbtIVcB6L9n0XZiSN/5exBIiVKfHags9EtZ2b hPvTNBRqG5INlIlZsniClEaODbpp/GlVZisRB8sQ92EOJB9BXZkUnEeM+ yRpI9jABjLzT/UeulMLb1TAWpuYjfgj1giOUGfFMZstw/tAbf15E/PDLp u6keFmsacNN16QsK0VW3KiANWR40xnWifURLhP1BKNuVIcOS1PZ2bgOgR xCDSvJx8aiX6erA3j7kcTcmWZzKL5ydiqkkraNNlGtN3OFnwG7ZjpdIGu azkTjPabup7L6X182FflwZmXwQaHNA/uEJIfNh7Yf5/2idYRF6+aqwu/6 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10394"; a="282682917" X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="282682917" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:20 -0700 X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="648349643" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:18 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, parav@nvidia.com, xieyongji@bytedance.com, gautam.dawar@amd.com, Zhu Lingshan Subject: [PATCH V3 4/6] vDPA: !FEATURES_OK should not block querying device config space Date: Fri, 1 Jul 2022 21:28:24 +0800 Message-Id: <20220701132826.8132-5-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220701132826.8132-1-lingshan.zhu@intel.com> References: <20220701132826.8132-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Users may want to query the config space of a vDPA device, to choose a appropriate one for a certain guest. This means the users need to read the config space before FEATURES_OK, and the existence of config space contents does not depend on FEATURES_OK. The spec says: The device MUST allow reading of any device-specific configuration field before FEATURES_OK is set by the driver. This includes fields which are conditional on feature bits, as long as those feature bits are offered by the device. Fixes: 30ef7a8ac8a07 (vdpa: Read device configuration only if FEATURES_OK) Signed-off-by: Zhu Lingshan --- drivers/vdpa/vdpa.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 9b0e39b2f022..d76b22b2f7ae 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -851,17 +851,9 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, { u32 device_id; void *hdr; - u8 status; int err; down_read(&vdev->cf_lock); - status = vdev->config->get_status(vdev); - if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) { - NL_SET_ERR_MSG_MOD(extack, "Features negotiation not completed"); - err = -EAGAIN; - goto out; - } - hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags, VDPA_CMD_DEV_CONFIG_GET); if (!hdr) { From patchwork Fri Jul 1 13:28:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12903311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE6ADC43334 for ; Fri, 1 Jul 2022 13:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231470AbiGANga (ORCPT ); Fri, 1 Jul 2022 09:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231426AbiGANgX (ORCPT ); Fri, 1 Jul 2022 09:36:23 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45BF21706B for ; Fri, 1 Jul 2022 06:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656682583; x=1688218583; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nA6aAOQL4jOKPW3ch4cEZ/9/EOxMkwzBotlCyalcNDE=; b=QluRVHLF9U2Zk20os52ZI0mxLXks51sqmBQ8TPHBM+tQEH29bVtLK/9A 9+FeXYel5LcOlZdWfcdqnZy/yXK1a0ZopC0n4I5pEb4euRR0NgT9kK8zo 2LCK2qxB2KErK2j3t6cErFw64jmd7xed0RbD0FRBzjZOvS5tW76So21B9 E00dQ1cIpzyMMdPxhaMw1/20Pn1T4oDB+ylfrRSFFU2h7tROlSijrOf4f 5lvqqXVQ9w05foO6yzwCZpWdN31mPMlKGp+zCGuW562Oam5WLREHRxV3u yCmZjbOjHEogpgTsNwcHVFm75r0OzLMAqlOTnMugMwqBaWVY+/w1DmbtU A==; X-IronPort-AV: E=McAfee;i="6400,9594,10394"; a="282682924" X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="282682924" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:23 -0700 X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="648349647" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:20 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, parav@nvidia.com, xieyongji@bytedance.com, gautam.dawar@amd.com, Zhu Lingshan Subject: [PATCH V3 5/6] vDPA: answer num of queue pairs = 1 to userspace when VIRTIO_NET_F_MQ == 0 Date: Fri, 1 Jul 2022 21:28:25 +0800 Message-Id: <20220701132826.8132-6-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220701132826.8132-1-lingshan.zhu@intel.com> References: <20220701132826.8132-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If VIRTIO_NET_F_MQ == 0, the virtio device should have one queue pair, so when userspace querying queue pair numbers, it should return mq=1 than zero. Function vdpa_dev_net_config_fill() fills the attributions of the vDPA devices, so that it should call vdpa_dev_net_mq_config_fill() so the parameter in vdpa_dev_net_mq_config_fill() should be feature_device than feature_driver for the vDPA devices themselves Before this change, when MQ = 0, iproute2 output: $vdpa dev config show vdpa0 vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 0 mtu 1500 After applying this commit, when MQ = 0, iproute2 output: $vdpa dev config show vdpa0 vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 1 mtu 1500 Fixes: a64917bc2e9b (vdpa: Provide interface to read driver features) Signed-off-by: Zhu Lingshan --- drivers/vdpa/vdpa.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index d76b22b2f7ae..846dd37f3549 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -806,9 +806,10 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev, u16 val_u16; if ((features & BIT_ULL(VIRTIO_NET_F_MQ)) == 0) - return 0; + val_u16 = 1; + else + val_u16 = __virtio16_to_cpu(true, config->max_virtqueue_pairs); - val_u16 = le16_to_cpu(config->max_virtqueue_pairs); return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, val_u16); } @@ -842,7 +843,7 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms VDPA_ATTR_PAD)) return -EMSGSIZE; - return vdpa_dev_net_mq_config_fill(vdev, msg, features_driver, &config); + return vdpa_dev_net_mq_config_fill(vdev, msg, features_device, &config); } static int From patchwork Fri Jul 1 13:28:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12903312 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF10EC433EF for ; Fri, 1 Jul 2022 13:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbiGANgb (ORCPT ); Fri, 1 Jul 2022 09:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiGANg3 (ORCPT ); Fri, 1 Jul 2022 09:36:29 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86B7617E28 for ; Fri, 1 Jul 2022 06:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656682585; x=1688218585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PSHnAfe8LQ//2rWp6Lo496ExCrGTLYCKJo/7E2AZ/Kc=; b=oGiihEIHJDFMKJ08470GASzdN1qsLtHE40pqUjx2lOF2321cxzlpEmwl dXg+iQAkioLf/lto43qBUrswQYFcjh94n1yE+ojM9cRZrEID3QQx/FHDs 9xv7NQMJfpOxkVGRL6SLYp5dkyBcu9Hw9vEO2vaijcM1ULI//y2LXxah7 VAPQFqDh4M3/uaGPMDcG23feWnUXhb/Fpt0EvYHDd7tn3nlzlWymArs1k adc2U7D+OVOISmj5fYD3UVC5I0bS/kwjnqf0ViSL8EXzYf+Lyqa6+fZQ9 lkcsU5N6YCEGoBnZyEu3OBTC5S37yZRa4YNM0VkY9MKixyQDMbLqi+k9R Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10394"; a="282682931" X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="282682931" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:25 -0700 X-IronPort-AV: E=Sophos;i="5.92,237,1650956400"; d="scan'208";a="648349652" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2022 06:36:23 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, parav@nvidia.com, xieyongji@bytedance.com, gautam.dawar@amd.com, Zhu Lingshan Subject: [PATCH V3 6/6] vDPA: fix 'cast to restricted le16' warnings in vdpa.c Date: Fri, 1 Jul 2022 21:28:26 +0800 Message-Id: <20220701132826.8132-7-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220701132826.8132-1-lingshan.zhu@intel.com> References: <20220701132826.8132-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This commit fixes spars warnings: cast to restricted __le16 in function vdpa_dev_net_config_fill() and vdpa_fill_stats_rec() Signed-off-by: Zhu Lingshan --- drivers/vdpa/vdpa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 846dd37f3549..ed49fe46a79e 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -825,11 +825,11 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms config.mac)) return -EMSGSIZE; - val_u16 = le16_to_cpu(config.status); + val_u16 = __virtio16_to_cpu(true, config.status); if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16)) return -EMSGSIZE; - val_u16 = le16_to_cpu(config.mtu); + val_u16 = __virtio16_to_cpu(true, config.mtu); if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16)) return -EMSGSIZE; @@ -911,7 +911,7 @@ static int vdpa_fill_stats_rec(struct vdpa_device *vdev, struct sk_buff *msg, } vdpa_get_config_unlocked(vdev, 0, &config, sizeof(config)); - max_vqp = le16_to_cpu(config.max_virtqueue_pairs); + max_vqp = __virtio16_to_cpu(true, config.max_virtqueue_pairs); if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, max_vqp)) return -EMSGSIZE;