Received: by 2002:a05:7412:85a1:b0:e2:908c:2ebd with SMTP id n33csp168076rdh; Mon, 30 Oct 2023 18:26:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQM+Q+2Pt8qSrNS2v152Tko++mdxk8DEaoQKhelNoFCIourz0ZR7dK2fOm38GtA9UrWPsC X-Received: by 2002:a05:6358:94a6:b0:169:7dad:fee1 with SMTP id i38-20020a05635894a600b001697dadfee1mr2706984rwb.4.1698715587780; Mon, 30 Oct 2023 18:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698715587; cv=none; d=google.com; s=arc-20160816; b=Tr40NhvZSMpRHTsRR69pvcibzgktumeHQc/bxTLdzt7kjWgULb60z25kCgnUbwgFgq MktrPsg/eEX8jTeB40MlnYKQJGikZS+CQAqbZfkVeVImP/F1AWKdWbLx1ChHMr73E27j nUhGPBHs3Wvi3cicFQTZx/mhFCzn7WJRQMDp6aTrh7akSY7fjDcRktZbTvJMgqYrakGx AnP5GyvrS+QZoigaLQKZRwE0/94nGp6/gbj7b3mcYRJ0CnT0PaU6pcADzMAaUV++ZvFD Z8J/mLRbwAfmZiaWUVuNOU6CQ1dAhIBaixeL9FQaQ/iw9fpfSmCItJgQ6IDuW3ULIRJT p05Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=o31v5GZG9TcPdikJNjmUFZp5YmRhl08i97z1mloYIzw=; fh=A4UuBHzsiBPnNL9Mki0KmcymCDgpeCQvtN0bUSj3GuU=; b=oE39IGd0LLW3wnPKpSW+yfmW0inPcXRHEnx+Do5xFOCxM1Wj7cMFEmd/VDiEjAHfRY u+ZtJv8vxSluB/1urUsLU+3fWWVEdVPpAMgJN8NROwFwUrSw0XjM5yz360HI6/xwgyfR E6HE03OVx0D8wQzkVV3LirakXMaXdVdteQOk31f4zOMDduK0aW4BtPm0yvVTmuviS7IG NLBl9NeWM0ouTbHiqbneCG7/QzeKzEcyKOFCx2E0K7/M2/pCR2oziXJGBiNufqdT419j QQ+iZ01HhlOWcS8+VTwUmQXMGCFfi0BVURpf1b1PBTavZVGlkRkIjKUkASRJfagK71MO 2bbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AxLSqds0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id j65-20020a638b44000000b005b999980278si251212pge.660.2023.10.30.18.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 18:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AxLSqds0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DDA71805CAC1; Mon, 30 Oct 2023 18:26:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbjJaB0N (ORCPT + 99 others); Mon, 30 Oct 2023 21:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjJaB0M (ORCPT ); Mon, 30 Oct 2023 21:26:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5EEDEE for ; Mon, 30 Oct 2023 18:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698715523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o31v5GZG9TcPdikJNjmUFZp5YmRhl08i97z1mloYIzw=; b=AxLSqds0DosISLMqayf9eg1MA0UKuBoIHCvNI2rjgWzOF4d0x2xo/g2ULCQF+pNuUpPAgQ fVwZr26rOIyFbY4JFAL5DAhO1soaZcwerlEhueSN5HqAe3E72whkqJuPL7RNAQ9PB/h6jK +pCeOjM249p3NKcSEA8xYq82NIyxuGY= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-245-oUEMAyC0NPmBTimakqKP0w-1; Mon, 30 Oct 2023 21:25:21 -0400 X-MC-Unique: oUEMAyC0NPmBTimakqKP0w-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-50798a25ebaso3135532e87.0 for ; Mon, 30 Oct 2023 18:25:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698715520; x=1699320320; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o31v5GZG9TcPdikJNjmUFZp5YmRhl08i97z1mloYIzw=; b=beLhcW/LE1WQP3mFcrxM6jMl/kekGRa9Q6Rbia7H6XoGxbcpc0sMLsD7raydYazHrb q67dyTPzwTTZiEQSIRElBkUVEv0oaALJtFdseaoyKyqlEORarSrUfCXVDlfUVmpG5y1r ub6fJ3q0wjtwlGb3wSIdrCke4SIZtZd0XChtl4gzUePFD1xov+jAxDCjjogdfiAXrpKW 7eENPmnrfy6r40jOViYmamSTbWpxN2VGSvr1ShvwUzVHABC1pagemAzmN5JunCWc8/b3 LzuZay0fR0hGEQgZre6hDUoh1f/NCKh9SBL4Wl5v8X2oMnN6DqAaNh7SkffgQw9TJbzb Ie4A== X-Gm-Message-State: AOJu0Yx2InFRSyDRb+f7yaKTklxFMG9eP963TyBRVhm31jlnuGNl6L6i wolQc0Zb9WJj6wsZQB46RomnCUuIQCKQqZKFGhT893RJ+x2xIJsCFbBoEu2v2hLYZvl1DrZDcbF 6dnIffCXgctgR4WEp7ULkCn3gGs6Fy6S2myITunON X-Received: by 2002:a19:a40f:0:b0:509:1eca:4ae2 with SMTP id q15-20020a19a40f000000b005091eca4ae2mr360830lfc.16.1698715519646; Mon, 30 Oct 2023 18:25:19 -0700 (PDT) X-Received: by 2002:a19:a40f:0:b0:509:1eca:4ae2 with SMTP id q15-20020a19a40f000000b005091eca4ae2mr360825lfc.16.1698715519287; Mon, 30 Oct 2023 18:25:19 -0700 (PDT) MIME-Version: 1.0 References: <1698350834-415881-1-git-send-email-steven.sistare@oracle.com> In-Reply-To: From: Jason Wang Date: Tue, 31 Oct 2023 09:25:07 +0800 Message-ID: Subject: Re: [RFC] vdpa/mlx5: preserve CVQ vringh index To: Steven Sistare Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Eli Cohen , Si-Wei Liu , Dragos Tatulea , Xuan Zhuo Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 30 Oct 2023 18:26:25 -0700 (PDT) On Mon, Oct 30, 2023 at 10:06=E2=80=AFPM Steven Sistare wrote: > > On 10/27/2023 2:31 AM, Jason Wang wrote: > > On Fri, Oct 27, 2023 at 4:07=E2=80=AFAM Steve Sistare wrote: > >> > >> mlx5_vdpa does not preserve userland's view of vring base for the cont= rol > >> 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 =3D 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_de= v *mvdev) > >> struct mlx5_control_vq *cvq =3D &mvdev->cvq; > >> int err =3D 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 =3D cvq->vring.last_avail_idx; > >> + > >> err =3D vringh_init_iotlb(&cvq->vring, mvdev->actual_f= eatures, > >> 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); > > > > Btw, vringh_set_base_iotlb() deserves an independent patch and it > > seems it is not specific to IOTLB, > > Agreed on both. I initially submitted the smallest change needed to show= the problem. > > so we probably need an indirection > > to have vringh_set_base() first. > > Not sure what you mean. I have defined: > > static inline int __vringh_set_base() ... > > int vringh_set_base_iotlb() > return __vringh_set_base(vrh, idx, putu16_iotlb); > > to which I would add: > > int vringh_set_base_user() > return __vringh_set_base(vrh, idx, putu16_user); > > int vringh_set_base_kern() > return __vringh_set_base(vrh, idx, putu16_kern; > > all in the same patch. > > The call site in mlx5_vnet.c would be a 2nd patch. Right, so we just need to split it. > > - Steve > > > Or I wonder if it's better to just introduce a new parameter to > > vringh_init_iotlb()... > > I considered that, but IMO the parameter list there is already large, and= it would > be strange to add a parameter for the initial value of avail, but not for= used, and > no one needs the latter. Fine. Thanks > > - Steve > > >> + } > >> 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 =3D putu16(vrh, &vrh->vring.avail->idx, idx); > >> + if (ret) > >> + return ret; > >> + > >> + ret =3D putu16(vrh, &vrh->vring.used->idx, idx); > >> + if (ret) > >> + return ret; > >> + > >> + vrh->last_avail_idx =3D vrh->last_used_idx =3D idx; > >> + return 0; > >> +} > >> + > >> /* Userspace access helpers: in this case, addresses are really users= pace. */ > >> static inline int getu16_user(const struct vringh *vrh, u16 *val, con= st __virtio16 *p) > >> { > >> @@ -1456,6 +1474,18 @@ void vringh_set_iotlb(struct vringh *vrh, struc= t 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 wit= h > >> * 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 f= eatures, > >> 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, > >> -- > >> 2.39.3 > >> > > >