Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1410359rwi; Fri, 14 Oct 2022 18:45:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48lAMLnZdYN+uywMarD0exdeZ0S/zJZ0G51BBeB2bgkXOJE20A4tIrX1AOy60He25r6Bw4 X-Received: by 2002:a17:907:724a:b0:782:3754:ecb3 with SMTP id ds10-20020a170907724a00b007823754ecb3mr567290ejc.282.1665798350963; Fri, 14 Oct 2022 18:45:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665798350; cv=none; d=google.com; s=arc-20160816; b=AyMVQQuow2P2PHbyERm7tmTtQ1K6SDtRLl85ZCUICiEpXGGd79iiWxcuiutK6uPrpI 0YeBTxrujMapkkHip7I70M0B6UsyPxkxZ1XHD2nhcx5CJxCjPUQcLK0mvfp6YMnKhOeS xLTAAmPJhs+tiKnYMIo6aOOdwvVgU+Q2j0NwDLFK5deOJCX+1tZoq+h1pEIgrZ4GgOQf AsmOn6qQpMVqv9TBu5+O771RcS+whHUxUqKIwwqLYiU/dx+YdfxLns5tfBu7uaphZiDR yc+vlLtgDyWjFPOKbSwaOF8yzW+4mUMKAJYuGlCG7i/sDyaIOydfwU8WDo67ciFDUELY EJ7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=cSVJI1bSDiyO0vZzhdwXj6L1TMUgHBA1v+QaHDOHvCc=; b=ed5uehlZ5HCwTBN2eyOJwI+bD1UjYTJB8aTbgUDqpO3RLCVWKHQWDyNK41XVB+reYN avDFPbY/PwtC82rD8OG1g6S+JDVeEOYLlR+ZA3cvWlXxnPTvRJcZ6na+64r/7pq61sZl QWDK9DltSu4R0MNZgWf/KRKxSiILMBLHTXj5UGW9nCymDryG7S+kVXm6sFsFUSn/RwM4 zItCxvYHSZXps3C1IuE9IYwsrmF+lHehiG0s6kbokLwN8frpFMxtiObQoYlM7Lj6seF7 e2fonh90h4diWRGdZvrTt5KIg+ixqLgREKbWy4g6fuTX8tTq73JPAJi7yPKpFNYy8Xk4 Abeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=IfuHSZym; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w7-20020a05640234c700b0045cfa0b1f46si4066205edc.11.2022.10.14.18.45.25; Fri, 14 Oct 2022 18:45:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=IfuHSZym; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229573AbiJOBeD (ORCPT + 99 others); Fri, 14 Oct 2022 21:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbiJOBdy (ORCPT ); Fri, 14 Oct 2022 21:33:54 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8966E53D2C for ; Fri, 14 Oct 2022 18:33:53 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29F0u44H027651; Sat, 15 Oct 2022 01:33:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=cSVJI1bSDiyO0vZzhdwXj6L1TMUgHBA1v+QaHDOHvCc=; b=IfuHSZymM5RMkxtJ+U+/2s+yzdRXI2qrxmh1qt7g/xINHzSpuwvWGYLpD+ZLqPaWn4XZ +t83Tbd5S8DX/B+CMloJlPJp8iq6VrUjGhEuClCjd6I+9sa9AoWRXf9JuyxC2OvMfBOI ekM7Mg9nn2+gR+/1VhObn/yAayDtUTG7uAju25nLz8hsQkWLdtICxauI9H8QPiZdrcR3 nbHPvKgimozGqOMk9mYFSTpPDoBB+t3zcOkpMUYVyO9s2cTqy22sjc0XxubYLF+J1xR6 D0EL22W9NDhTP93zHHIaWow21ZWblL6EefakdXsXon1DhuMqO9LV5CYwDugfHLdXccG7 0g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3k7acvh0yj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 15 Oct 2022 01:33:50 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29F1X479008564; Sat, 15 Oct 2022 01:33:49 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3k7ka180am-4; Sat, 15 Oct 2022 01:33:49 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] vdpa: show dev config as-is in "vdpa dev show" output Date: Fri, 14 Oct 2022 17:28:09 -0700 Message-Id: <1665793690-28120-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1665793690-28120-1-git-send-email-si-wei.liu@oracle.com> References: <1665793690-28120-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-14_13,2022-10-14_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 adultscore=0 mlxscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210150007 X-Proofpoint-GUID: F5060o5C_sKBkBOOjs3KTnP9fY_LiCyX X-Proofpoint-ORIG-GUID: F5060o5C_sKBkBOOjs3KTnP9fY_LiCyX X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Live migration of vdpa would typically require re-instate vdpa device with an idential set of configs on the destination node, same way as how source node created the device in the first place. In order to save orchestration software from memorizing and keeping track of vdpa config, it will be helpful if the vdpa tool provides the aids for exporting the initial configs from which vdpa device was created as-is. The "vdpa dev show" command seems to be the right vehicle for that. It is unlike the "vdpa dev config show" command output that usually goes with the live value in the device config space, which is not quite reliable subject to the dynamics of feature negotiation and possible change in device config space. Examples: 1) Create vDPA by default without any config attribute $ vdpa dev add mgmtdev pci/0000:41:04.2 name vdpa0 $ vdpa dev show vdpa0 vdpa0: type network mgmtdev pci/0000:41:04.2 vendor_id 5555 max_vqs 9 max_vq_size 256 $ vdpa dev -jp show vdpa0 { "dev": { "vdpa0": { "type": "network", "mgmtdev": "pci/0000:41:04.2", "vendor_id": 5555, "max_vqs": 9, "max_vq_size": 256, } } } 2) Create vDPA with config attribute(s) specified $ vdpa dev add mgmtdev pci/0000:41:04.2 name vdpa0 \ mac e4:11:c6:d3:45:f0 max_vq_pairs 4 $ vdpa dev show vdpa0: type network mgmtdev pci/0000:41:04.2 vendor_id 5555 max_vqs 9 max_vq_size 256 mac e4:11:c6:d3:45:f0 max_vq_pairs 4 $ vdpa dev -jp show { "dev": { "vdpa0": { "type": "network", "mgmtdev": "pci/0000:41:04.2", "vendor_id": 5555, "max_vqs": 9, "max_vq_size": 256, "mac": "e4:11:c6:d3:45:f0", "max_vq_pairs": 4 } } } Signed-off-by: Si-Wei Liu --- drivers/vdpa/vdpa.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 566c1c6..91eca6d 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -677,6 +677,41 @@ static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *i } static int +vdpa_dev_cfgattrs_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 device_id) +{ + struct vdpa_dev_set_config *cfg = &vdev->vdev_cfg; + int err = -EMSGSIZE; + + if (!cfg->mask) + return 0; + + switch (device_id) { + case VIRTIO_ID_NET: + if ((cfg->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR)) != 0 && + nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, + sizeof(cfg->net.mac), cfg->net.mac)) + return err; + if ((cfg->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) != 0 && + nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, cfg->net.mtu)) + return err; + if ((cfg->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) != 0 && + nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, + cfg->net.max_vq_pairs)) + return err; + break; + default: + break; + } + + if ((cfg->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) != 0 && + nla_put_u64_64bit(msg, VDPA_ATTR_DEV_FEATURES, + cfg->device_features, VDPA_ATTR_PAD)) + return err; + + return 0; +} + +static int vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq, int flags, struct netlink_ext_ack *extack) { @@ -715,6 +750,10 @@ static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *i if (nla_put_u16(msg, VDPA_ATTR_DEV_MIN_VQ_SIZE, min_vq_size)) goto msg_err; + err = vdpa_dev_cfgattrs_fill(vdev, msg, device_id); + if (err) + goto msg_err; + genlmsg_end(msg, hdr); return 0; -- 1.8.3.1