From patchwork Tue Sep 27 03:01:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989803 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 87C98C32771 for ; Tue, 27 Sep 2022 03:12:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231161AbiI0DMX (ORCPT ); Mon, 26 Sep 2022 23:12:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbiI0DL3 (ORCPT ); Mon, 26 Sep 2022 23:11:29 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC50310; Mon, 26 Sep 2022 20:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664248171; x=1695784171; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=seVF5/jELUBPIdInogzKyMqz5go1Mgay8X224linJj0=; b=lirwWfGxytaJAlJaz2sGceHpRSYdGQjk/6cwUz90z3xRKtZURs1CAEgq Opfz3eUSi6ENVjFDsi/jCemIp/YKSjot5RJNmrfsSNchPZ86C2T+lm8AZ 2uCvhLp/LvWfDnwUhlPRXVoaiMPimVKlozjJv7YykrOyWsBGbHkOOS+/4 aR+ux6i1KGSDm3scvrPCfX+AbImDuN8cg+Xo2yyY910SvjrfTwaSAP1Ts AvmOnTV4llW5Uhxw/M9vmqW6DI0MUIzjA95QlGmAjtMCgSzEPVl9rrqUy 2SM/MXx54px0yeVIxyjlacVFe3O+kAL2Xog4F9d7AZvChSKOQi6e3ARcZ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="327558437" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="327558437" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:31 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="710387752" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="710387752" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:29 -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 RESEND 1/6] vDPA: allow userspace to query features of a vDPA device Date: Tue, 27 Sep 2022 11:01:12 +0800 Message-Id: <20220927030117.5635-2-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927030117.5635-1-lingshan.zhu@intel.com> References: <20220927030117.5635-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@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 races 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 03:01:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989804 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 583FCC07E9D for ; Tue, 27 Sep 2022 03:12:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231180AbiI0DM1 (ORCPT ); Mon, 26 Sep 2022 23:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231164AbiI0DLb (ORCPT ); Mon, 26 Sep 2022 23:11:31 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43ACD2AEB; Mon, 26 Sep 2022 20:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664248174; x=1695784174; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s2lA+Ycgcd4GvWEVH0oc8utZsq2+n/HosRqNW2xvB5E=; b=lWgfq2SRvRTgGmGp8Y6yrB2DQWBtDZyuqqkxZsYmMD4H4E+3/i6fgtfK /dmYCLUdRmEKyZQydmWZIlAuxfD6WVQXliUqmwo4/UrNqQ6WisoLXPU5b KvSvls8PyI2nXHAizprFsGCH20yjxbY+pM+er1NC92NztXCqhxbhYvGSF Tqe3PKR2iDLoocHuNUzyEbCo8jfjhAeKIcePsHlzOXiKxuLf4PrdyN1MW DoaOKJNWCAX4SLyy73wVsbfrRJLpJ8ArDmbAm3rnOX3K3A78QBuBXQ3ZY bhWSFh53ZjjX56M0cP37mmoRbteQrAZ0u0ZCPYZV7DEPJDyFSET0RZ/7U g==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="327558441" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="327558441" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:33 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="710387758" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="710387758" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:31 -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 RESEND 2/6] vDPA: only report driver features if FEATURES_OK is set Date: Tue, 27 Sep 2022 11:01:13 +0800 Message-Id: <20220927030117.5635-3-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927030117.5635-1-lingshan.zhu@intel.com> References: <20220927030117.5635-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@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 03:01:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989805 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 BF3FBC07E9D for ; Tue, 27 Sep 2022 03:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231239AbiI0DMn (ORCPT ); Mon, 26 Sep 2022 23:12:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231232AbiI0DLn (ORCPT ); Mon, 26 Sep 2022 23:11:43 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F23A9120B2; Mon, 26 Sep 2022 20:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664248180; x=1695784180; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2YQiwSWKHyCzhjsVYpVZs2o9N9e+lxz8vW92n7gfnJ4=; b=hq9NS1+gpH2pGcJQxEO3n4qTI5vktrLha5THkAV7toDBUP0OgdIC0lqd 1zLe6++NFmvAkS2YSJXQNPy4RpB8ip4gTc1xAhnBIlSChzIvpKKfkoZqz nPUJm7SckdINFAoDusWaGrM4LIO1926W3OEgd0ctVAJzYx6owMD2AICQP TXgT6G0CLcuePZfLMpPBQFAGR1qNM2prPnBDRnn8tTdoexOaQgwi3NOoH 3AyG+BSb98/bfIWamPc3WNwsPn1Y14qYN6hCvyMQhSpKoirMCBOghw33/ E/j57MZDse76PI9mznJ+2/vCvZdFBjcLqaSjoHfiSJ2JjkszdNb0cs5tE A==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="299922312" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="299922312" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:35 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="710387770" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="710387770" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:33 -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 RESEND 3/6] vDPA: check VIRTIO_NET_F_RSS for max_virtqueue_paris's presence Date: Tue, 27 Sep 2022 11:01:14 +0800 Message-Id: <20220927030117.5635-4-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927030117.5635-1-lingshan.zhu@intel.com> References: <20220927030117.5635-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@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 Acked-by: Jason Wang --- 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 03:01:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989806 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 B7507C07E9D for ; Tue, 27 Sep 2022 03:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231415AbiI0DMp (ORCPT ); Mon, 26 Sep 2022 23:12:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231244AbiI0DLu (ORCPT ); Mon, 26 Sep 2022 23:11:50 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6099A17A91; Mon, 26 Sep 2022 20:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664248180; x=1695784180; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q9QLny4+YlxEhFriZ4xrznw5yE/fEeF6yuJd395Sp48=; b=Q+086vxP9nG3AtkVt3aqOp/pQwSe6wCjOdWVnAvZTfjJ9yx3Zr132NAI Ll8RbO/Eb+TWH1N8aCVnTcMImZmkec5/OT1PYXl+XcIe2EC/5rjyS9xaV kw3ztm1+ecAAC4I8ycGkrEJ6b2ciDCuRzigmLOQjEe0EJEXmmDyOyDhqh LlfCYWNvDS66tWqDOX8IZ1odVNDU04pExfXo9Kp6z5zkjXrvuuoBL8T9h lb9XUYpNTA9B+0x2SUsmgVOzWAl1xNhLc3rXWxmauACtkf9/0YGbUvV4I bRxbsz6lRf2muwRsI4mQNDBrKjo39Nv2D+hGUj1+MbvJ5VPPAKQO55Vmr A==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="299922317" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="299922317" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:37 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="710387774" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="710387774" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:35 -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 RESEND 4/6] vDPA: check virtio device features to detect MQ Date: Tue, 27 Sep 2022 11:01:15 +0800 Message-Id: <20220927030117.5635-5-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927030117.5635-1-lingshan.zhu@intel.com> References: <20220927030117.5635-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org vdpa_dev_net_mq_config_fill() should checks device features for MQ than driver features. Signed-off-by: Zhu Lingshan Acked-by: Jason Wang --- 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 03:01:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989807 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 CF08DC07E9D for ; Tue, 27 Sep 2022 03:12:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230248AbiI0DM4 (ORCPT ); Mon, 26 Sep 2022 23:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231286AbiI0DL5 (ORCPT ); Mon, 26 Sep 2022 23:11:57 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05D5D13D51; Mon, 26 Sep 2022 20:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664248188; x=1695784188; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MHeKxmQI7dzVqsMFENR/yfS8078fH4WgIzsF3Ed1w8E=; b=NY7l4oIui/MkEmG80W/t9eHWL2QYzfXSWlr68fgnwcnCn9fqYu5999ip kqef+t7KE6vJNwhmbeR3y0G5ZfI3V25jnviuRquY+Bc/pHMTMvjF9988Y zZmQSR8OLqEyrAFlDZ/5c7Vy1DGTUIskXPOAt/WhdgqIlxwQkPCk8txLb WhUUzDL6GKRbWGuT0fbta0BxypQl23TnNCDB7FH8AZrZcsUB62u25oZHS R3lwduZ4QJVhYQx0Yb9NOmMEOoztejdfnFcN2/JQxeYDkqffYoj401qt1 EiIgP04C3o0EBgI7gHwzFPPmWOwpJ/FhHYdGknjiomBrrUobR8ksbK9ln g==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="299922322" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="299922322" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="710387782" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="710387782" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:37 -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 RESEND 5/6] vDPA: fix spars cast warning in vdpa_dev_net_mq_config_fill Date: Tue, 27 Sep 2022 11:01:16 +0800 Message-Id: <20220927030117.5635-6-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927030117.5635-1-lingshan.zhu@intel.com> References: <20220927030117.5635-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@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 Acked-by: Jason Wang --- 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 03:01:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12989808 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 41C84C07E9D for ; Tue, 27 Sep 2022 03:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231444AbiI0DNB (ORCPT ); Mon, 26 Sep 2022 23:13:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230450AbiI0DMH (ORCPT ); Mon, 26 Sep 2022 23:12:07 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 755891C93F; Mon, 26 Sep 2022 20:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664248188; x=1695784188; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=COzcN3Qbisu/0MjCDWrAxFQOe27JKz2nAsFAG8KBs8s=; b=envEKnHPJTvQ83A3njiIr3Vu/0xykJQStFImlmDq/DKoUytSzeJj93UW +E1nHDY5CRry4wPXoyKOh3KAh5glCD6VRFHb8GQ67th+0F0dZujqF95kF KXy0WWMjOHubTobPzpV/f5n/O7jZRKKa7KNZVJtvb0IPDrPd3FoH9aoVA /SY+SYVlcpwgwUQxOLUbMNqqtlwclbkWn3go/CiYiA8YQTufQGSZZhpEQ iedinGoUY/67PxKeyPJcVor4S8l/kulFwc4UkRRcNqea/Q8WVYkZSW7fk s5BtUnVljETCxafyfFduiFgHbuujD3isRIhqoxYyRoBA9pOSP2AzoHMIa g==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="299922328" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="299922328" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:41 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="710387786" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="710387786" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2022 20:09:39 -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 RESEND 6/6] vDPA: conditionally read MTU and MAC in dev cfg space Date: Tue, 27 Sep 2022 11:01:17 +0800 Message-Id: <20220927030117.5635-7-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220927030117.5635-1-lingshan.zhu@intel.com> References: <20220927030117.5635-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@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); }