From patchwork Tue Sep 27 02:50:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989766 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 033E2C07E9D for ; Tue, 27 Sep 2022 03:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231367AbiI0DCA (ORCPT ); Mon, 26 Sep 2022 23:02:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230410AbiI0DAp (ORCPT ); Mon, 26 Sep 2022 23:00:45 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B0E6109A; Mon, 26 Sep 2022 19:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664247531; x=1695783531; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0tvi8CCSJdCmQYmFGRgxTRRxHPAxB2B0MDkHtxBOnDs=; b=Og8qJagn7LhpwfO31Vt79KUjjymxV7QU5Qz9Tm+ecklUpGyELG6xFjDG Vz0U2qZL7GLK3tqCI/qyAEKR++IFzH8rQ33NTfP8BBQsZE8LmcNnF2B1F hdTYdOGHIYb+ONgTgPXfciS+jwg/OOYPfA8a+wQKvw8AdKC656c1s8V1R 5mxQiIONluMZqVOZ09Z5+T4yQNKIZ9nBc1gzhXc04O/W5Ap4r1j0MIQde jKbUJbwIZCvkjAM9nO1ZqAcB/YK26MD7YkWynfm8Hlt6P+JktUqf500o7 KstYBlpC1u/TH61o4i2S6O4k1/sJCju48AtAVz2u4KMAU4gBCq0S+MPOt Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="387490743" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="387490743" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:50 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652105637" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652105637" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:48 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Zhu Lingshan Subject: [PATCH V2 1/6] vDPA: allow userspace to query features of a vDPA device Date: Tue, 27 Sep 2022 10:50:30 +0800 Message-Id: <20220927025035.4972-2-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927025035.4972-1-lingshan.zhu@intel.com> References: <20220927025035.4972-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. This commit invokes vdpa_config_ops.get_config() rather than vdpa_get_config_unlocked() to read the device config spcae, so no raeces in vdpa_set_features_unlocked() Userspace tool iproute2 example: $ vdpa dev config show vdpa0 vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 4 mtu 1500 negotiated_features MRG_RXBUF CTRL_VQ MQ VERSION_1 ACCESS_PLATFORM dev_features MTU MAC MRG_RXBUF CTRL_VQ MQ ANY_LAYOUT VERSION_1 ACCESS_PLATFORM Signed-off-by: Zhu Lingshan --- drivers/vdpa/vdpa.c | 17 ++++++++++++----- include/uapi/linux/vdpa.h | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index c06c02704461..2035700d6fc8 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -491,6 +491,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m err = -EMSGSIZE; goto msg_err; } + if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_SUPPORTED_FEATURES, mdev->supported_features, VDPA_ATTR_PAD)) { err = -EMSGSIZE; @@ -815,10 +816,10 @@ 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)); + vdev->config->get_config(vdev, 0, &config, sizeof(config)); if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac), config.mac)) @@ -832,12 +833,18 @@ 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..07474183fdb3 100644 --- a/include/uapi/linux/vdpa.h +++ b/include/uapi/linux/vdpa.h @@ -46,12 +46,16 @@ enum vdpa_attr { VDPA_ATTR_DEV_NEGOTIATED_FEATURES, /* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS, /* u32 */ + /* virtio features that are supported by the vDPA management device */ VDPA_ATTR_DEV_SUPPORTED_FEATURES, /* u64 */ VDPA_ATTR_DEV_QUEUE_INDEX, /* u32 */ VDPA_ATTR_DEV_VENDOR_ATTR_NAME, /* string */ VDPA_ATTR_DEV_VENDOR_ATTR_VALUE, /* u64 */ + /* virtio features that are supported by the vDPA device */ + VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, /* u64 */ + /* new attributes must be added above here */ VDPA_ATTR_MAX, }; From patchwork Tue Sep 27 02:50:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989767 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 EFE15C07E9D for ; Tue, 27 Sep 2022 03:02:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231397AbiI0DCE (ORCPT ); Mon, 26 Sep 2022 23:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231396AbiI0DAq (ORCPT ); Mon, 26 Sep 2022 23:00:46 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B515D55B0; Mon, 26 Sep 2022 19:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664247532; x=1695783532; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s2lA+Ycgcd4GvWEVH0oc8utZsq2+n/HosRqNW2xvB5E=; b=NHi4l7gNrkKfW8L7yQxYa2ret2o20FWtKY80+m/0KfBCHoublESjKW2j iLtCaHmvqA/hHc/0XISRdICFD5/mjCaRAYKZmdvyX41QcDqy4iSI6fBnO q+kfpRjSEqohHrZ8eXfOX3FtndL9aichzirE1AFPTMvdHGsxJQpZUFLo1 2QsXv96J4dlhKTSMFkl/Qy0IycFIIy9NtpgpLYP2HMgaXny26TnhazP5L /VRU4lokbeTJpEnKevGbTIF6pHxdzeIvHRQ73Jydsi5fbBIGhIZmNcdIx a7/nyCpclG/FbfDD4y4JOynz5q6ZTdHeKvyDr3cH7sYp40g6FHxDRLrbO Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="387490747" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="387490747" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:52 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652105651" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652105651" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:50 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Zhu Lingshan Subject: [PATCH V2 2/6] vDPA: only report driver features if FEATURES_OK is set Date: Tue, 27 Sep 2022 10:50:31 +0800 Message-Id: <20220927025035.4972-3-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927025035.4972-1-lingshan.zhu@intel.com> References: <20220927025035.4972-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This commit reports driver features to user space only after FEATURES_OK is features negotiation is done. Signed-off-by: Zhu Lingshan --- drivers/vdpa/vdpa.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 2035700d6fc8..e7765953307f 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -816,7 +816,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_device, features_driver; + u64 features_device; u16 val_u16; vdev->config->get_config(vdev, 0, &config, sizeof(config)); @@ -833,11 +833,6 @@ 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_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, @@ -851,6 +846,8 @@ static int vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq, int flags, struct netlink_ext_ack *extack) { + u64 features_driver; + u8 status = 0; u32 device_id; void *hdr; int err; @@ -874,6 +871,19 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, goto msg_err; } + /* only read driver features after the feature negotiation is done */ + if (vdev->config->get_status) + status = vdev->config->get_status(vdev); + + if (status & VIRTIO_CONFIG_S_FEATURES_OK) { + features_driver = vdev->config->get_driver_features(vdev); + if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver, + VDPA_ATTR_PAD)) { + err = -EMSGSIZE; + goto msg_err; + } + } + switch (device_id) { case VIRTIO_ID_NET: err = vdpa_dev_net_config_fill(vdev, msg); From patchwork Tue Sep 27 02:50:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989768 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 9BBF7C32771 for ; Tue, 27 Sep 2022 03:02:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231398AbiI0DCP (ORCPT ); Mon, 26 Sep 2022 23:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbiI0DAr (ORCPT ); Mon, 26 Sep 2022 23:00:47 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADDAC6545; Mon, 26 Sep 2022 19:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664247534; x=1695783534; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2YQiwSWKHyCzhjsVYpVZs2o9N9e+lxz8vW92n7gfnJ4=; b=mMwv5SjwjsFc5FYzxGEamK8bU4mDVJd2gNIxAw6H7qv0RSIYkyit0JIN ibB05gM6VjT51N/j8wlXx7AhP4RmxTL2VoIj6cF4mdiRsMLRF0ojgp5ha L/+u2LKpG2MfiJPBycu8OUPe39+4tYxTYpy3Rroiu8NdsM2kOsjAcCj9a srjccsDvaO5O9+jKI03zJ/OEHC1CqqLE7NGUPH3tACrtNUHyhXaZEUWmY SAi+xzheRWLmWZbks79X0F2bwWNbcrP/P9/ubV9ToIzxTmCZBf9F9s84a 2V8t9Mh1w+LJWu55X41BIHWp0CxNNTA6sJtTdFdSLQS5IIR1D/PTDBVWi Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="387490752" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="387490752" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:54 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652105656" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652105656" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:52 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Zhu Lingshan Subject: [PATCH V2 3/6] vDPA: check VIRTIO_NET_F_RSS for max_virtqueue_paris's presence Date: Tue, 27 Sep 2022 10:50:32 +0800 Message-Id: <20220927025035.4972-4-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927025035.4972-1-lingshan.zhu@intel.com> References: <20220927025035.4972-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org virtio 1.2 spec says: max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ or VIRTIO_NET_F_RSS is set. So when reporint MQ to userspace, it should check both VIRTIO_NET_F_MQ and VIRTIO_NET_F_RSS. unused parameter struct vdpa_device *vdev is removed 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 e7765953307f..829fd4cfc038 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -800,13 +800,13 @@ static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callba return msg->len; } -static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev, - struct sk_buff *msg, u64 features, +static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features, const struct virtio_net_config *config) { u16 val_u16; - if ((features & BIT_ULL(VIRTIO_NET_F_MQ)) == 0) + if ((features & BIT_ULL(VIRTIO_NET_F_MQ)) == 0 && + (features & BIT_ULL(VIRTIO_NET_F_RSS)) == 0) return 0; val_u16 = le16_to_cpu(config->max_virtqueue_pairs); From patchwork Tue Sep 27 02:50:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989769 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 D5186C07E9D for ; Tue, 27 Sep 2022 03:02:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbiI0DCX (ORCPT ); Mon, 26 Sep 2022 23:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbiI0DAr (ORCPT ); Mon, 26 Sep 2022 23:00:47 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FB1E64D8; Mon, 26 Sep 2022 19:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664247536; x=1695783536; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q9QLny4+YlxEhFriZ4xrznw5yE/fEeF6yuJd395Sp48=; b=mcYiLAgyjgAkpoFaSLdv8mGvkv+1wa1Fk4tdQxvx/kLu2e+PNTGa859C RxxeZm5Jui0O7vR/T3NtbRUOpbMHGMVJsNpYMxva5erh3ePAkcIx/6Amz 2JpRQ3ygliFnFuicVwr7Sx6ot9yGIe/n2f/hL5qyCurJpQ8IeT1kSW/9H h6YkLNjutR/lMeF0OtgQI+/WIYoyd1tl2qK+NODAs1aEqjdemK8NENgpH EzH5byMSwcvXOf9KDwRHQoz6o2bTDCa8ZKMOvpMx/iy3M6mU8es3kLOQn MkFE4hq1YD2GqNLN4cqv6eS7yf9wK/xr4DuaV8Yz0I3QYVJr9LAOQ9+jP w==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="387490760" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="387490760" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:56 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652105664" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652105664" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:54 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Zhu Lingshan Subject: [PATCH V2 4/6] vDPA: check virtio device features to detect MQ Date: Tue, 27 Sep 2022 10:50:33 +0800 Message-Id: <20220927025035.4972-5-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927025035.4972-1-lingshan.zhu@intel.com> References: <20220927025035.4972-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org vdpa_dev_net_mq_config_fill() should checks device features for MQ than driver features. Signed-off-by: Zhu Lingshan --- drivers/vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 829fd4cfc038..84a0c3877d7c 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -839,7 +839,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(msg, features_device, &config); } static int From patchwork Tue Sep 27 02:50:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989770 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 E7350C6FA82 for ; Tue, 27 Sep 2022 03:02:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230446AbiI0DC1 (ORCPT ); Mon, 26 Sep 2022 23:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230441AbiI0DA5 (ORCPT ); Mon, 26 Sep 2022 23:00:57 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9237D65B3; Mon, 26 Sep 2022 19:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664247538; x=1695783538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MHeKxmQI7dzVqsMFENR/yfS8078fH4WgIzsF3Ed1w8E=; b=iZgPI08RylYt0WGX1wyH7Q9Xt8ClPBtWAYnI6BsszDF4Qq60Rz0skxCk RE19aE5xKXi3HwZyt3LQnerD5DGp1qZf4jgZDkYFcFUWxK0u7a2s2kxDp /x4+K9fJ/PM8SJiedAUP3HgqwZNRpsCbc948KdDp3aBtMQdkyFr1THcFL 4WjYhnWADhvaa1Ug1U34cruez4Pmzt7iFKoVvEe/5AWWACh2OHVf2QBce fXPgec+6+AuQfc67UxilMXC8CtWDwEoc98/3EvPuK0FW1vADvXp5bJrry Ykotc4rKm1w+/DrPrUhMzAcBXN9t9Q/ebohjLfU3rj3GF75WY6AFOBt1Z A==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="387490762" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="387490762" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:58 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652105671" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652105671" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:56 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Zhu Lingshan Subject: [PATCH V2 5/6] vDPA: fix spars cast warning in vdpa_dev_net_mq_config_fill Date: Tue, 27 Sep 2022 10:50:34 +0800 Message-Id: <20220927025035.4972-6-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927025035.4972-1-lingshan.zhu@intel.com> References: <20220927025035.4972-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_mq_config_fill() Signed-off-by: Zhu Lingshan --- drivers/vdpa/vdpa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 84a0c3877d7c..fa7f65279f79 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -809,7 +809,8 @@ static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features, (features & BIT_ULL(VIRTIO_NET_F_RSS)) == 0) return 0; - val_u16 = le16_to_cpu(config->max_virtqueue_pairs); + val_u16 = __virtio16_to_cpu(true, config->max_virtqueue_pairs); + return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, val_u16); } From patchwork Tue Sep 27 02:50:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989771 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 3DA73C6FA82 for ; Tue, 27 Sep 2022 03:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231430AbiI0DCb (ORCPT ); Mon, 26 Sep 2022 23:02:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231140AbiI0DBC (ORCPT ); Mon, 26 Sep 2022 23:01:02 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88CB2A464; Mon, 26 Sep 2022 19:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664247540; x=1695783540; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=COzcN3Qbisu/0MjCDWrAxFQOe27JKz2nAsFAG8KBs8s=; b=GJjACwanVbTfSiNPmGyv/vlUoJ4pwSdjbRCrQKchybe74498yI4iVo8N I82l0lEcE/TuiCoJNERuCNVux3s+L8O2DIKZWCIL9+ND0LcoZWGxJJuuN PE5QFYuFLtR2tHfHFS1KAu+enKjA2uUhYVo4bQQXKw4jpSFSidNS5C9+/ cQfJFj1bPYuJzXEcA0kLSVn7gsAkq2fis3S2lHBbduLaWLGDV4GHvrrV1 +MB8fezYjMHO/MvtjjPz3Mw/rDAYYtafERveSFAxJlTCAoXzK3M+oZvy6 KgHIoKT993OhRh+8lu8GPpcybEvx5RvjX3ox2JjsH2KqYzOlfe5vO/wpK g==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="387490766" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="387490766" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:59:00 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652105676" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652105676" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 19:58:58 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Zhu Lingshan Subject: [PATCH V2 6/6] vDPA: conditionally read MTU and MAC in dev cfg space Date: Tue, 27 Sep 2022 10:50:35 +0800 Message-Id: <20220927025035.4972-7-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927025035.4972-1-lingshan.zhu@intel.com> References: <20220927025035.4972-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The spec says: mtu only exists if VIRTIO_NET_F_MTU is set The mac address field always exists (though is only valid if VIRTIO_NET_F_MAC is set) So vdpa_dev_net_config_fill() should read MTU and MAC conditionally on the feature bits. Signed-off-by: Zhu Lingshan Acked-by: Jason Wang --- drivers/vdpa/vdpa.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index fa7f65279f79..3d2cf8caff7c 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -814,6 +814,29 @@ static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features, return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, val_u16); } +static int vdpa_dev_net_mtu_config_fill(struct sk_buff *msg, u64 features, + const struct virtio_net_config *config) +{ + u16 val_u16; + + if ((features & BIT_ULL(VIRTIO_NET_F_MTU)) == 0) + return 0; + + val_u16 = __virtio16_to_cpu(true, config->mtu); + + return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16); +} + +static int vdpa_dev_net_mac_config_fill(struct sk_buff *msg, u64 features, + const struct virtio_net_config *config) +{ + if ((features & BIT_ULL(VIRTIO_NET_F_MAC)) == 0) + return 0; + + return nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, + sizeof(config->mac), config->mac); +} + static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg) { struct virtio_net_config config = {}; @@ -822,24 +845,22 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms vdev->config->get_config(vdev, 0, &config, sizeof(config)); - if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac), - config.mac)) - return -EMSGSIZE; - val_u16 = __virtio16_to_cpu(true, config.status); if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16)) return -EMSGSIZE; - val_u16 = __virtio16_to_cpu(true, config.mtu); - if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16)) - 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; + if (vdpa_dev_net_mtu_config_fill(msg, features_device, &config)) + return -EMSGSIZE; + + if (vdpa_dev_net_mac_config_fill(msg, features_device, &config)) + return -EMSGSIZE; + return vdpa_dev_net_mq_config_fill(msg, features_device, &config); }