From patchwork Thu Oct 26 20:11:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Sistare X-Patchwork-Id: 158677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp142228vqb; Thu, 26 Oct 2023 13:11:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQ36ORqzqp9eEdXbe/1NFvKuD/6nIpOn9lYLSzMJkd4YdS6ZWOoHv9+nhluh7cchmjEm+M X-Received: by 2002:a25:e695:0:b0:da0:5997:5fcf with SMTP id d143-20020a25e695000000b00da059975fcfmr410718ybh.51.1698351105050; Thu, 26 Oct 2023 13:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698351105; cv=none; d=google.com; s=arc-20160816; b=cBzPdR+utpaAv4sy51Y5yklgN9v61HxVUo+yHRQo4g/KCw4UZ5wv9vvqN/1dVu1edc VAM9gPlVOxwuY5K3VbUIhtM/t1LIiDzFZX3eCNS5uJp2DjwNhWEgcRh9MH5k16V1udqb tvLflpjsPVuMgYHzzebX5AD1GOFpIOS8xa7fLdKkQcNuAvHu/vtNfb59Ot7QcC1JqnXH NHR0W9C/ai89UZcg3+evFSsTS+AWqm9Xh/LIzHj9GxTzrVd4hjMTyn7wB7vecvuPonYK jnNp0qXeekqD9NSgvo3DThsBykZwXP1FhMBDssn88ck42XT6i4p46Umb0uhSTG88UCFO e7CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=sEJaHi8D5zE3GzzOYXpgBAdryXTBPVqu/owy7NkIqfI=; fh=6UhrjP6Q/YZA9J6U0/MoVS8E5EmSIy0SdvdeO86I0Ks=; b=AlTQO/lUpUf8YKG7bAIK9LwZ2trkRNEVEiONLttEHsTwd6J/Enm7ch78YR7GhuVRii H39yTPJfl1K999Q1O5mb+SSDtMjjy9BXGgk+F54m0CEDtZHAbNXxhs5bKWKqH8FiLGyW byRTs0ITOyV0N6g28K7+5bmkPI/9b9WAE917Yx39gsxb97VaKjy7JvpidVT2YEKYI/AY /aLfPxRdmvG5+r4uQXTj4gyE9dDkEbd5lJdx0OPtY7dbahFfJtt+yv+O0xkEuLjtj5xq YY7ydpDRWcNg38YI2zv/uk7Su/3FRGQkr3iNDD3xv1jdBvppvGX7d3FgDxYtYa85xOwq fytQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=ozndSAJH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id o185-20020a2573c2000000b00d9a62c80de5si227746ybc.219.2023.10.26.13.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 13:11:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=ozndSAJH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8EFBC828C4AE; Thu, 26 Oct 2023 13:11:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344732AbjJZUL3 (ORCPT + 26 others); Thu, 26 Oct 2023 16:11:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231546AbjJZUL1 (ORCPT ); Thu, 26 Oct 2023 16:11:27 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FC37129 for ; Thu, 26 Oct 2023 13:11:25 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39QJsZXs022995; Thu, 26 Oct 2023 20:11:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2023-03-30; bh=sEJaHi8D5zE3GzzOYXpgBAdryXTBPVqu/owy7NkIqfI=; b=ozndSAJHokav5q61a9/P99h+OXZT7nFE2XOTsG9fbvsjRCMiFsg9cq6tfPQyXQLm9sWZ jLAgLxBu2IbunBBEeZp4p4JNlnqj6PkRrj6FZM3Depchcg5ZqU+hHVzjfmV+JDYQ4nKn 2QbaPiO2324I5AjIULWX3IOAUaoSl0h3TV2LRoAIyBM19o0P6UOaU8FnAX9mvPZzATL1 vpbmrtVBy8e0vXgy/T6prD4CR0MsUipA4b3bSEdQW9XxPMgAdrD31vI8nBG5/IaqMLwJ CXE9/uIEthlGjFUl653vuznIha0hqhavzamOo0usMD5spruSaw97tTj/mTbMqqdBV2AZ AA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tywuc84mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Oct 2023 20:11:17 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39QImmU8008100; Thu, 26 Oct 2023 20:11:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3tywqhjy4p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Oct 2023 20:11:16 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39QKBGDo004951; Thu, 26 Oct 2023 20:11:16 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3tywqhjy4c-1; Thu, 26 Oct 2023 20:11:16 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Eli Cohen , Si-Wei Liu , Dragos Tatulea , Xuan Zhuo , Steve Sistare Subject: [RFC] vdpa/mlx5: preserve CVQ vringh index Date: Thu, 26 Oct 2023 13:11:15 -0700 Message-Id: <1698351075-415989-1-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-26_19,2023-10-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2310260174 X-Proofpoint-ORIG-GUID: uDbtsfEWjIDO3JobeStHxQ99AMXzJ-_w X-Proofpoint-GUID: uDbtsfEWjIDO3JobeStHxQ99AMXzJ-_w X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 26 Oct 2023 13:11:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780849954103928730 X-GMAIL-MSGID: 1780850208818438496 mlx5_vdpa does not preserve userland's view of vring base for the control queue in the following sequence: ioctl VHOST_SET_VRING_BASE ioctl VHOST_VDPA_SET_STATUS VIRTIO_CONFIG_S_DRIVER_OK mlx5_vdpa_set_status() setup_cvq_vring() vringh_init_iotlb() vringh_init_kern() vrh->last_avail_idx = 0; ioctl VHOST_GET_VRING_BASE To fix, restore the value of cvq->vring.last_avail_idx after calling vringh_init_iotlb. Signed-off-by: Steve Sistare --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 7 ++++++- drivers/vhost/vringh.c | 30 ++++++++++++++++++++++++++++++ include/linux/vringh.h | 2 ++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 946488b8989f..f64758143115 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2795,13 +2795,18 @@ static int setup_cvq_vring(struct mlx5_vdpa_dev *mvdev) struct mlx5_control_vq *cvq = &mvdev->cvq; int err = 0; - if (mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)) + if (mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)) { + u16 last_avail_idx = cvq->vring.last_avail_idx; + err = vringh_init_iotlb(&cvq->vring, mvdev->actual_features, MLX5_CVQ_MAX_ENT, false, (struct vring_desc *)(uintptr_t)cvq->desc_addr, (struct vring_avail *)(uintptr_t)cvq->driver_addr, (struct vring_used *)(uintptr_t)cvq->device_addr); + if (!err) + vringh_set_base_iotlb(&cvq->vring, last_avail_idx); + } return err; } diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index 7b8fd977f71c..799762c83007 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -595,6 +595,24 @@ static inline void __vringh_notify_disable(struct vringh *vrh, } } +static inline int __vringh_set_base(struct vringh *vrh, u16 idx, + int (*putu16)(const struct vringh *vrh, + __virtio16 *p, u16 val)) +{ + int ret; + + ret = putu16(vrh, &vrh->vring.avail->idx, idx); + if (ret) + return ret; + + ret = putu16(vrh, &vrh->vring.used->idx, idx); + if (ret) + return ret; + + vrh->last_avail_idx = vrh->last_used_idx = idx; + return 0; +} + /* Userspace access helpers: in this case, addresses are really userspace. */ static inline int getu16_user(const struct vringh *vrh, u16 *val, const __virtio16 *p) { @@ -1456,6 +1474,18 @@ void vringh_set_iotlb(struct vringh *vrh, struct vhost_iotlb *iotlb, } EXPORT_SYMBOL(vringh_set_iotlb); +/** + * vringh_set_base_iotlb - set avail_idx and used_idx + * @vrh: the vring + * @idx: the value to set + */ +int vringh_set_base_iotlb(struct vringh *vrh, u16 idx) +{ + return __vringh_set_base(vrh, idx, putu16_iotlb); +} +EXPORT_SYMBOL(vringh_set_base_iotlb); + + /** * vringh_getdesc_iotlb - get next available descriptor from ring with * IOTLB. diff --git a/include/linux/vringh.h b/include/linux/vringh.h index c3a8117dabe8..e9b8af4e6a5e 100644 --- a/include/linux/vringh.h +++ b/include/linux/vringh.h @@ -306,6 +306,8 @@ int vringh_init_iotlb_va(struct vringh *vrh, u64 features, struct vring_avail *avail, struct vring_used *used); +int vringh_set_base_iotlb(struct vringh *vrh, u16 idx); + int vringh_getdesc_iotlb(struct vringh *vrh, struct vringh_kiov *riov, struct vringh_kiov *wiov,