From patchwork Thu Sep 29 01:45:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12993364 X-Patchwork-Delegate: kuba@kernel.org 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 B839CC04A95 for ; Thu, 29 Sep 2022 01:54:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234141AbiI2ByS (ORCPT ); Wed, 28 Sep 2022 21:54:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231419AbiI2ByQ (ORCPT ); Wed, 28 Sep 2022 21:54:16 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E4E822B3C; Wed, 28 Sep 2022 18:54: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=1664416454; x=1695952454; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=afMekNlPbl2PpdEGr4IwA97D38+TBDd0zzrloo6xahk=; b=Y0XGqunotSUO5FMlzn9sF3pU/3l/mKZaJDTXncNSfLhZJaYm99PPxTwx QmLh3OsI+MJCii3D5kO5qXv23GAest2M/GuO5Q+GTGoPHBNd3iWh9gmf2 yTONAXidL7QtQzXl1UGK4uW+Nt1SAi00o1nlkJPgHu0JCt60LmTKaX0XO +tkyrlEREy4Ag0QnUZSMInoq/2aasp6MBy7P3cCZqwM3JDlxd9zI74/dr tluyBHOz35rboBjeospPLEzKL9PYh5J1zpmPdjq8jRMtpnpLIwM5QYEn6 Q24Zin6aC+xKJ4EV+XxJ1UycNFe/BJMB4iGyIAtn5pHyCABr2TpYq+q3o A==; X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="365813985" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="365813985" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:13 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="950931650" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="950931650" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:14 -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 V3 1/6] vDPA: allow userspace to query features of a vDPA device Date: Thu, 29 Sep 2022 09:45:50 +0800 Message-Id: <20220929014555.112323-2-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220929014555.112323-1-lingshan.zhu@intel.com> References: <20220929014555.112323-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 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 | 16 +++++++++++----- include/uapi/linux/vdpa.h | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index c06c02704461..1363b42c9d28 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -815,10 +815,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 +832,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 Thu Sep 29 01:45:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12993365 X-Patchwork-Delegate: kuba@kernel.org 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 1A97AC04A95 for ; Thu, 29 Sep 2022 01:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234517AbiI2ByV (ORCPT ); Wed, 28 Sep 2022 21:54:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231419AbiI2ByU (ORCPT ); Wed, 28 Sep 2022 21:54:20 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35B4848E80; Wed, 28 Sep 2022 18:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664416456; x=1695952456; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y7l7xFJT97zU1BKhh36MFM4wiXm5W6x1xg/x3P6bd9Y=; b=ZcjqSfiU8ShCooHOxBbS/sIkdE2OA3DL9SZi3p7npgRjHb1p5vPqqQaP J1Js0DerEDYIKwWCKQHoW+4Qnziu0ka67KYgrnr29e9dWPifdNggx3Sb9 HQ75SVBR7ZBxe6omgEZ9U74oR3+sOBsornyr9Fm+4Ww80X4h2EaBamtex 7owIdVnoTINcYpo0NPC/pCPFulN4iYLRmmkht9LIOl7Z+4cSSMfeu6CC5 1zh2U6p0PfzpuTwL4FiD49LmU2Y8MdNKX+tmqpuQldrFuscFJV3KwK74i cmtCzEvclV7YMs0kg32QvCYOqx29n6EIkPYM0hRw6G8Vj2Q99qTiEmZLz A==; X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="365813990" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="365813990" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:15 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="950931679" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="950931679" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:15 -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 V3 2/6] vDPA: only report driver features if FEATURES_OK is set Date: Thu, 29 Sep 2022 09:45:51 +0800 Message-Id: <20220929014555.112323-3-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220929014555.112323-1-lingshan.zhu@intel.com> References: <20220929014555.112323-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 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 1363b42c9d28..52b7f5d23127 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_device, features_driver; + u64 features_device; u16 val_u16; vdev->config->get_config(vdev, 0, &config, sizeof(config)); @@ -832,11 +832,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, @@ -850,6 +845,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; @@ -873,6 +870,17 @@ 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 */ + 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 Thu Sep 29 01:45:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12993366 X-Patchwork-Delegate: kuba@kernel.org 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 1EFEBC54EE9 for ; Thu, 29 Sep 2022 01:54:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234594AbiI2By3 (ORCPT ); Wed, 28 Sep 2022 21:54:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234515AbiI2ByV (ORCPT ); Wed, 28 Sep 2022 21:54:21 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 051937B2B5; Wed, 28 Sep 2022 18:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664416458; x=1695952458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b33SD8HDAWV7qaNky28KuKEyYahR5SVNndzd9VjTGYc=; b=DU8YAesLu4OeV1Srl76fbu6nBofzZ3U0Ixy50nYFJgRbJovurCWk89Cu bYkwCxpWZy3p9c1A8hnYrXUcM4QWhvEkPcMhWvigNt4NJzIWQ7qN2pfOA DxqdPcIzPJPXqCiAPhGnNYsdmM4zSSA4F4VYeOFmWyOSdVFXcnwapbNGX GPWgr+Cf5BGgU9Clwr0f2TsRz/1FVKBpKzkQoKd5yySEm7LSBeNUmWQ5Q Fp5jmfe+P4/6Y/78Wo30pyjn218x66cu5iaSfIvzHlmhy2+qsUWZF9f+V o6wCUlwZGI/9QaKKLtj6X+gJ1d4hG1Y7+2kSP0n253iFS/OreqaNPofhn A==; X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="365813994" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="365813994" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:17 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="950931690" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="950931690" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:17 -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 V3 3/6] vDPA: check VIRTIO_NET_F_RSS for max_virtqueue_paris's presence Date: Thu, 29 Sep 2022 09:45:52 +0800 Message-Id: <20220929014555.112323-4-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220929014555.112323-1-lingshan.zhu@intel.com> References: <20220929014555.112323-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 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 52b7f5d23127..70448deb9cd9 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -799,13 +799,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 Thu Sep 29 01:45:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12993367 X-Patchwork-Delegate: kuba@kernel.org 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 E63E5C04A95 for ; Thu, 29 Sep 2022 01:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234612AbiI2Byc (ORCPT ); Wed, 28 Sep 2022 21:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234551AbiI2By3 (ORCPT ); Wed, 28 Sep 2022 21:54:29 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F81CB2DA2; Wed, 28 Sep 2022 18:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664416461; x=1695952461; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D7pnvgGbf6rMBGEOr+3yoyC4/Q3xM67IRtf+uHK0JCk=; b=GBsVZ1C6qw6kkNsANTkf4qgdtNAp1MMmTHIZfOUrh34hyX53KrNBF6Qp 4CUEhRUXyC8xBk8P+uktxIClLsqPTlwZ/9R3bWuS/9ISraK64q2/NZOWf jP7VUp268ZvFPt44E/8zjDUZCto7cxCtGLhv35JaOOQuuQeBWbJHifx55 491f3bUfYSXkjvFwCmTd/NCzD7aE3H1WDmFVyNQpyyFTvIGNxCS8WU/4d BwRaOkTHINqS6EG6OCgcjeDzTQQklHeFh/ZFXgyNCHfjQMpRSsiX8Y8eD zhTpYbKIrxXDz1HjGVMQQRPuOToJXaA+eRFBZ3mEUlezU7enZPgx/f2MI A==; X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="365813997" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="365813997" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:19 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="950931697" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="950931697" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:19 -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 V3 4/6] vDPA: check virtio device features to detect MQ Date: Thu, 29 Sep 2022 09:45:53 +0800 Message-Id: <20220929014555.112323-5-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220929014555.112323-1-lingshan.zhu@intel.com> References: <20220929014555.112323-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 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 70448deb9cd9..4b13bb7f355d 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -838,7 +838,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 Thu Sep 29 01:45:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12993368 X-Patchwork-Delegate: kuba@kernel.org 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 E8035C32771 for ; Thu, 29 Sep 2022 01:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234701AbiI2Byo (ORCPT ); Wed, 28 Sep 2022 21:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234595AbiI2Bya (ORCPT ); Wed, 28 Sep 2022 21:54:30 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 119EB120BD6; Wed, 28 Sep 2022 18:54: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=1664416462; x=1695952462; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m7nbGYvfVKm8H9yHeHgCQyHCtntkkvKbVAT9Sh7K1VU=; b=L6eB+2gCj6pIK/mW/0h9oitb1kSC+TRXRDDe9TyY9/5Qr4MkpBcS8li9 QOwJ/Fvhf7vYXDE1by59seWoK1r8XJiGYp2lhm0JeLEPDZBhjweNEvkRi fvcux0DjFq8D+n6vA0Ypas1hccCunybZm7WPmtuR4aG5t5mYqqR7c2YIe s+L594o0CGOWp9RArCWhWpyjOrWLsD4NURLcM29e7diD8dH5AfEm2zoBt 0590Jom32aWgRCsU2nCEBm1uAaG8U8bEfOkXhYaMK9BW9DoU5Ptb1nekx ZkKWU30LqQUHkasI3ocJ7FXb9xT0Cbvww72dEp9NvoO8VXb9me29XZuIN g==; X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="365814000" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="365814000" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:21 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="950931704" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="950931704" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:21 -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 V3 5/6] vDPA: fix spars cast warning in vdpa_dev_net_mq_config_fill Date: Thu, 29 Sep 2022 09:45:54 +0800 Message-Id: <20220929014555.112323-6-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220929014555.112323-1-lingshan.zhu@intel.com> References: <20220929014555.112323-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 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 4b13bb7f355d..f10403c86af7 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -808,7 +808,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 Thu Sep 29 01:45:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 12993369 X-Patchwork-Delegate: kuba@kernel.org 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 C8FF3C04A95 for ; Thu, 29 Sep 2022 01:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234723AbiI2Byp (ORCPT ); Wed, 28 Sep 2022 21:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234427AbiI2Bya (ORCPT ); Wed, 28 Sep 2022 21:54:30 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74678121673; Wed, 28 Sep 2022 18:54: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=1664416463; x=1695952463; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mMliWXU6KdhclVWyLRKEy2skGyJDxxSV6rh3wTGWiC8=; b=aVJTSqusWoRRwEY7AQIrk8dpFfa/zKiqPlnNcFS/d4j5q5sKkvJqI69K rVPabP0eEY0Ki5zTJnrj03gsmyYiHfctgZCgqsFp48yqJBd+bhU8yh+oC w45s/MpxHuQbUlOIEY/otKHr7iMLBXbb3xmnlSAP/bVKp81n8zhwJvZ83 9X+cLR0f9GnS5pI9uZcGuVVQgTbNvldv/RX8eQueHLz0UHzbQ8tPWg3x4 wE29rAe4JnMuBArSmwyUDcafDsIR2/r/XHgETsMujWG8+8xBTw4Jl6UZZ GYcPBMJWtJ8n2ZyPrLmoRkrzT+gK0LxvV7ekZk0veZ58auKCdjcaqKRpg w==; X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="365814004" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="365814004" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:23 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="950931715" X-IronPort-AV: E=Sophos;i="5.93,353,1654585200"; d="scan'208";a="950931715" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 18:54:23 -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 V3 6/6] vDPA: conditionally read MTU and MAC in dev cfg space Date: Thu, 29 Sep 2022 09:45:55 +0800 Message-Id: <20220929014555.112323-7-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220929014555.112323-1-lingshan.zhu@intel.com> References: <20220929014555.112323-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 f10403c86af7..02491341f9ee 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -813,6 +813,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 = {}; @@ -821,24 +844,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); }