From patchwork Tue Jan 31 23:22:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 51084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp90651wrn; Tue, 31 Jan 2023 15:24:53 -0800 (PST) X-Google-Smtp-Source: AK7set+L/XiJrYJbKJuaPaWA7ySUgqmgDM5Z7ULtyy3e5cVBfKsJiaUDPQs/+uJeYFElZcqcDaC3 X-Received: by 2002:a17:90a:53:b0:22b:e5e1:9d3 with SMTP id 19-20020a17090a005300b0022be5e109d3mr32644070pjb.25.1675207492733; Tue, 31 Jan 2023 15:24:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675207492; cv=none; d=google.com; s=arc-20160816; b=IuIogFHXT/fcl2YJyeFNsFvmNzJ01zBfRRAYptV6nsl0bLY1U4NDM80vHgtn0PaTSV MH38gKOUdRAxxA0wsm8qnriFF66yYFTkVaxhDXc1346vNpKIIJZGHZC6crCTM7e7V3jL cgWKJ1fGa+QqYdSc90kJG1dPU3bwGyeHHPlFu5HbaL80TBNt9pjZqPEkpnZll26yBpmI hrxopXE7y64k9UG6gdtSJfSPKfd6KZCum/gxysSJQj0ggKE5bOUY289Y8SFHjdBW6+wm kGOZaJt6Wu/Jrs/3PZ6c1IKo8OlFI7ChFMKFxsmYIKG9WIRdmciFbbNOsYDSQQigZ1HJ hGVA== 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=uNARmj9DqSK4eCVCfxVvrQGxRGB/k+87LR5p1WvHgfk=; b=sgss+3G0Xnfu843ffK5XLYguoYZSNCyVtmi1t1Y8kB6PMb/3pBbaweLdgBt6UnfZuW BlI0ToMTRbRAT4xPZ5PljL1FPTspLw8B9Wbl46+cP3ht5TJyMKcAvoCj08bie+H8ZPsD S4MBb7Ffg5Nt92UdirtHr2NkWXBJkUnYKx9O4fyW7LpATWEK9rJq+HhVn/gK6STe+ttC TebO8YR0yvRFDvYGx6v5NHIaUUJTYm0V7RTQWk0PExyW8v/JNiJBaTKzHpDgrvltsayJ hHlPkdAgIKhoSavDf2ZKqp9QGiKcs1RneX2PLMTFh+mSMsVJbgN9ZMN9O8FtngDh+kiH 6LIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=UL8g25Tu; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x14-20020a17090a2b0e00b00229a752dafdsi20192210pjc.142.2023.01.31.15.24.40; Tue, 31 Jan 2023 15:24:52 -0800 (PST) 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=UL8g25Tu; 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 S232198AbjAaXWi (ORCPT + 99 others); Tue, 31 Jan 2023 18:22:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbjAaXWa (ORCPT ); Tue, 31 Jan 2023 18:22:30 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03C7844A7 for ; Tue, 31 Jan 2023 15:22:30 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30VIi8cs006462; Tue, 31 Jan 2023 23:22:26 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=uNARmj9DqSK4eCVCfxVvrQGxRGB/k+87LR5p1WvHgfk=; b=UL8g25TuoC2eBTr3pfCVHsUNt0VrHPGkep1+dY5IjItWwzPIuKZT+TLsYs/9qd4DMqPD P38e1fHIIVu9D1uHBsUQcZK4MbUzrIx3cQgrMY36wn1n+fUUlpgwR1DTQxLM1P8g9GgX /Hoqfchf2Wf5hBUt5nP5j+iPEahgOxGvrkPF0hsGb8HMPWgl5PcH8Tajgw7euPFG+6vl vauLEt/BRiMJyXAkfiZKdSMP3E2DDNQqDFhXuME5kSf3VYDSGT01HVGyDsUhcIcJiQBZ fYOIMZvuRoB1SrysDi6rs8rcYj/nT1f9Mz1oQR+y9LG7OmFUfxaKH/8I5Rbsys12QT4P sQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvp171fc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 23:22:25 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30VMuk9M031540; Tue, 31 Jan 2023 23:22:24 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3nct5d8c94-3; Tue, 31 Jan 2023 23:22:24 +0000 From: Si-Wei Liu To: mst@redhat.com, jasowang@redhat.com, parav@nvidia.com, elic@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] vdpa: conditionally read STATUS in config space Date: Tue, 31 Jan 2023 15:22:03 -0800 Message-Id: <1675207327-22289-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> References: <1675207327-22289-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_08,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310201 X-Proofpoint-GUID: ufcRi-sJNv1PtvmeD0N4mw-BtCCUGQvB X-Proofpoint-ORIG-GUID: ufcRi-sJNv1PtvmeD0N4mw-BtCCUGQvB 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756582371773248486?= X-GMAIL-MSGID: =?utf-8?q?1756582371773248486?= The spec says: status only exists if VIRTIO_NET_F_STATUS is set Similar to MAC and MTU, vdpa_dev_net_config_fill() should read STATUS conditionally depending on the feature bits. Signed-off-by: Si-Wei Liu --- drivers/vdpa/vdpa.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 5e57935..5f4883b 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -848,18 +848,25 @@ static int vdpa_dev_net_mac_config_fill(struct sk_buff *msg, u64 features, sizeof(config->mac), config->mac); } +static int vdpa_dev_net_status_config_fill(struct sk_buff *msg, u64 features, + const struct virtio_net_config *config) +{ + u16 val_u16; + + if ((features & BIT_ULL(VIRTIO_NET_F_STATUS)) == 0) + return 0; + + val_u16 = __virtio16_to_cpu(true, config->status); + return nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16); +} + static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg) { struct virtio_net_config config = {}; u64 features_device; - u16 val_u16; vdev->config->get_config(vdev, 0, &config, sizeof(config)); - val_u16 = __virtio16_to_cpu(true, config.status); - if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16)) - return -EMSGSIZE; - features_device = vdev->config->get_device_features(vdev); if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_FEATURES, features_device, @@ -872,6 +879,9 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms if (vdpa_dev_net_mac_config_fill(msg, features_device, &config)) return -EMSGSIZE; + if (vdpa_dev_net_status_config_fill(msg, features_device, &config)) + return -EMSGSIZE; + return vdpa_dev_net_mq_config_fill(msg, features_device, &config); }