Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1086065rdb; Fri, 1 Dec 2023 06:48:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGU+63PgHAuYH9swbDHCsMGdh0Cw0rLgeT/OvsSNDEdnoM4RqAeazMIa4Z2p8kJjejQWgEN X-Received: by 2002:a17:90a:a504:b0:285:569b:a0a5 with SMTP id a4-20020a17090aa50400b00285569ba0a5mr37263491pjq.11.1701442092021; Fri, 01 Dec 2023 06:48:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701442092; cv=none; d=google.com; s=arc-20160816; b=XYTHFdpg8VAdNKmnp4HApdo7JYECPMsXuBzVoUXg4AJ0xihdFTASPHbu19Q6BEgz0T syu+tmv0Qti2RIytmud4gODYGDGkwNBXwZcRgd20GWqh4B6UM9TnN3IeBg0G0INLKge5 7Yfkc509arg/JULK+JRQtG8FNXkfa8ezCw7GJHz4wutY4SxZ4c0c9M3nBD1D7rzs7Mte MNQyIJQAf62FdzNmy245jYBsEY0DgtndI3lM+bGmEKE+psSppoYRSabtrbKvnJdtBTuY SBoXQ7YJov433Dd3j0DJUCVtgk1qvz0f8KET1ENngu1riptEjAZ6bnBnTVjxnw/laV0B g3fA== 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=o0DKYjK3dHbWdZnT5RD7tpOx0HUXsQyGhREUzJYhZ0I=; fh=JqrXZ/hxBqEZkqRbynoXzQzhQXe6pWuIw9AElvFpeBU=; b=q2C01FhmqpwLX8Q62vwTY1ObWBnPtTivqHSpz1//0qqRJw8paXt+ott8CpJFGrmGmI qIEXprXWIUp8EMA1oS/E0rMQLu44HZj+FlDekhndZTbZ3kYB3JicaoFsXBvDv1HVmySP AKLBBxq8sXfS1rX8WP320jbRYX8Mj3zT+uCr75AiUWns5zWOkhK40MO9cEeiifxg209/ yHJ7cUbvh6VOHaxdHPnqJpolP794fGkRoNUEt66fMYNGTMS5QcDQi9Y8BDbevdCyGm2M pkC6kyxvztYyCXaE6HW/N38+vOrOs0PAEPa4OtS4W0DTKx1SOMaZILC0J2K3LNe2q+wq k60Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Tudmxwsb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id g3-20020a6544c3000000b00588fdd9504bsi3344736pgs.858.2023.12.01.06.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 06:48:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Tudmxwsb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 AB5438269C79; Fri, 1 Dec 2023 06:48:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379244AbjLAOry (ORCPT + 99 others); Fri, 1 Dec 2023 09:47:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379210AbjLAOrx (ORCPT ); Fri, 1 Dec 2023 09:47:53 -0500 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 DAB911700 for ; Fri, 1 Dec 2023 06:47:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701442077; 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=o0DKYjK3dHbWdZnT5RD7tpOx0HUXsQyGhREUzJYhZ0I=; b=Tudmxwsbx/ERxpd2WySW3EG5MXRj9pJxhxE/c75Ps7GEq+7BwzbIaC6r6TJH2VeOsD+OZf d1T9qCmkAOB9KjGd9LEAoFYNjQhifH+qymQYtpY5QviAv8JD8uzvMhO5NOu5Ry9t5mnGjs 8u+BtJH41h5++ej23QBJKc4rZmrZ4i8= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-92paGFiXMiCgD-J0l3OSbA-1; Fri, 01 Dec 2023 09:47:53 -0500 X-MC-Unique: 92paGFiXMiCgD-J0l3OSbA-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-5d42c43d8daso4679627b3.0 for ; Fri, 01 Dec 2023 06:47:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701442072; x=1702046872; 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=o0DKYjK3dHbWdZnT5RD7tpOx0HUXsQyGhREUzJYhZ0I=; b=anA6fmTqHsZSWSNjJvhvuKDnaDe/j4M48pb996p4+NJ3zvLeo8KPL/TxUMjfwgFf2F 2Ix2ysuMOk+m1teno1bfVE12vdQWaD1Rh0MxJhUNNiQQ/qqm43jDlj/dh0U+D2f4NZvv SxPGHLFGDKuXQNrWL9xgfNE4YjohEj7IdncsPZjWFJjelnM49+7HwoS6g0gfqI+sSsa6 bRmg+D+NK1pC20JrUtpFL9Ouiv0+yX7xteIwJd1FrLmxujFYpNhUlphcO+GKXj73ayWN MNIoaDblPPjF7OFjsb9gHwEz/MqVnysnu+6EyeKBI+zlDVW7FkRgusMGkPvoDBWdArAR j/rg== X-Gm-Message-State: AOJu0Yz3Gq9tR8KfQ5za9pl+cnFCahgb7aL94DoSbuasjDaMANII3/uj n2k46Lw38gb0OOIYNHRgZLWduJ85M70Vhk4PEK7Yu2AYxebMAGREaVNJYFstENPMqcQFLpnM0TY 52g+OrZW+ItrunyLQVv22gyBXtYoJ23kpibILRn2V X-Received: by 2002:a05:690c:2e07:b0:5ce:723:ae79 with SMTP id et7-20020a05690c2e0700b005ce0723ae79mr18248088ywb.15.1701442072633; Fri, 01 Dec 2023 06:47:52 -0800 (PST) X-Received: by 2002:a05:690c:2e07:b0:5ce:723:ae79 with SMTP id et7-20020a05690c2e0700b005ce0723ae79mr18248067ywb.15.1701442072363; Fri, 01 Dec 2023 06:47:52 -0800 (PST) MIME-Version: 1.0 References: <20231201104857.665737-1-dtatulea@nvidia.com> <20231201104857.665737-4-dtatulea@nvidia.com> In-Reply-To: <20231201104857.665737-4-dtatulea@nvidia.com> From: Eugenio Perez Martin Date: Fri, 1 Dec 2023 15:47:16 +0100 Message-ID: Subject: Re: [PATCH vhost 3/7] vdpa/mlx5: Allow modifying multiple vq fields in one modify command To: Dragos Tatulea Cc: "Michael S . Tsirkin" , Jason Wang , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Gal Pressman , Parav Pandit , Xuan Zhuo Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 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,T_SCC_BODY_TEXT_LINE 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]); Fri, 01 Dec 2023 06:48:08 -0800 (PST) On Fri, Dec 1, 2023 at 11:49=E2=80=AFAM Dragos Tatulea wrote: > > Add a bitmask variable that tracks hw vq field changes that > are supposed to be modified on next hw vq change command. > > This will be useful to set multiple vq fields when resuming the vq. > > The state needs to remain as a parameter as it doesn't make sense to > make it part of the vq struct: fw_state is updated only after a > successful command. > I don't get this paragraph, "modified_fields" is a member of "mlx5_vdpa_virtqueue". Am I missing something? > Signed-off-by: Dragos Tatulea > --- > drivers/vdpa/mlx5/net/mlx5_vnet.c | 48 +++++++++++++++++++++++++------ > 1 file changed, 40 insertions(+), 8 deletions(-) > > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/ml= x5_vnet.c > index 12ac3397f39b..d06285e46fe2 100644 > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c > @@ -120,6 +120,9 @@ struct mlx5_vdpa_virtqueue { > u16 avail_idx; > u16 used_idx; > int fw_state; > + > + u64 modified_fields; > + > struct msi_map map; > > /* keep last in the struct */ > @@ -1181,7 +1184,19 @@ static bool is_valid_state_change(int oldstate, in= t newstate) > } > } > > -static int modify_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa= _virtqueue *mvq, int state) > +static bool modifiable_virtqueue_fields(struct mlx5_vdpa_virtqueue *mvq) > +{ > + /* Only state is always modifiable */ > + if (mvq->modified_fields & ~MLX5_VIRTQ_MODIFY_MASK_STATE) > + return mvq->fw_state =3D=3D MLX5_VIRTIO_NET_Q_OBJECT_STAT= E_INIT || > + mvq->fw_state =3D=3D MLX5_VIRTIO_NET_Q_OBJECT_STAT= E_SUSPEND; > + > + return true; > +} > + > +static int modify_virtqueue(struct mlx5_vdpa_net *ndev, > + struct mlx5_vdpa_virtqueue *mvq, > + int state) > { > int inlen =3D MLX5_ST_SZ_BYTES(modify_virtio_net_q_in); > u32 out[MLX5_ST_SZ_DW(modify_virtio_net_q_out)] =3D {}; > @@ -1193,6 +1208,9 @@ static int modify_virtqueue(struct mlx5_vdpa_net *n= dev, struct mlx5_vdpa_virtque > if (mvq->fw_state =3D=3D MLX5_VIRTIO_NET_Q_OBJECT_NONE) > return 0; > > + if (!modifiable_virtqueue_fields(mvq)) > + return -EINVAL; > + I'm ok with this change, but since modified_fields is (or will be) a bitmap tracking changes to state, addresses, mkey, etc, doesn't have more sense to check it like: if (modified_fields & 1< if (!is_valid_state_change(mvq->fw_state, state)) > return -EINVAL; > > @@ -1208,17 +1226,28 @@ static int modify_virtqueue(struct mlx5_vdpa_net = *ndev, struct mlx5_vdpa_virtque > MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, uid, ndev->mvdev.res.ui= d); > > obj_context =3D MLX5_ADDR_OF(modify_virtio_net_q_in, in, obj_cont= ext); > - MLX5_SET64(virtio_net_q_object, obj_context, modify_field_select, > - MLX5_VIRTQ_MODIFY_MASK_STATE); > - MLX5_SET(virtio_net_q_object, obj_context, state, state); > + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_STATE) > + MLX5_SET(virtio_net_q_object, obj_context, state, state); > + > + MLX5_SET64(virtio_net_q_object, obj_context, modify_field_select,= mvq->modified_fields); > err =3D mlx5_cmd_exec(ndev->mvdev.mdev, in, inlen, out, sizeof(ou= t)); > kfree(in); > if (!err) > mvq->fw_state =3D state; > > + mvq->modified_fields =3D 0; > + > return err; > } > > +static int modify_virtqueue_state(struct mlx5_vdpa_net *ndev, > + struct mlx5_vdpa_virtqueue *mvq, > + unsigned int state) > +{ > + mvq->modified_fields |=3D MLX5_VIRTQ_MODIFY_MASK_STATE; > + return modify_virtqueue(ndev, mvq, state); > +} > + > static int counter_set_alloc(struct mlx5_vdpa_net *ndev, struct mlx5_vdp= a_virtqueue *mvq) > { > u32 in[MLX5_ST_SZ_DW(create_virtio_q_counters_in)] =3D {}; > @@ -1347,7 +1376,7 @@ static int setup_vq(struct mlx5_vdpa_net *ndev, str= uct mlx5_vdpa_virtqueue *mvq) > goto err_vq; > > if (mvq->ready) { > - err =3D modify_virtqueue(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJ= ECT_STATE_RDY); > + err =3D modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET= _Q_OBJECT_STATE_RDY); > if (err) { > mlx5_vdpa_warn(&ndev->mvdev, "failed to modify to= ready vq idx %d(%d)\n", > idx, err); > @@ -1382,7 +1411,7 @@ static void suspend_vq(struct mlx5_vdpa_net *ndev, = struct mlx5_vdpa_virtqueue *m > if (mvq->fw_state !=3D MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY) > return; > > - if (modify_virtqueue(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SU= SPEND)) > + if (modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_ST= ATE_SUSPEND)) > mlx5_vdpa_warn(&ndev->mvdev, "modify to suspend failed\n"= ); > > if (query_virtqueue(ndev, mvq, &attr)) { > @@ -1407,6 +1436,7 @@ static void teardown_vq(struct mlx5_vdpa_net *ndev,= struct mlx5_vdpa_virtqueue * > return; > > suspend_vq(ndev, mvq); > + mvq->modified_fields =3D 0; > destroy_virtqueue(ndev, mvq); > dealloc_vector(ndev, mvq); > counter_set_dealloc(ndev, mvq); > @@ -2207,7 +2237,7 @@ static void mlx5_vdpa_set_vq_ready(struct vdpa_devi= ce *vdev, u16 idx, bool ready > if (!ready) { > suspend_vq(ndev, mvq); > } else { > - err =3D modify_virtqueue(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJ= ECT_STATE_RDY); > + err =3D modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET= _Q_OBJECT_STATE_RDY); > if (err) { > mlx5_vdpa_warn(mvdev, "modify VQ %d to ready fail= ed (%d)\n", idx, err); > ready =3D false; > @@ -2804,8 +2834,10 @@ static void clear_vqs_ready(struct mlx5_vdpa_net *= ndev) > { > int i; > > - for (i =3D 0; i < ndev->mvdev.max_vqs; i++) > + for (i =3D 0; i < ndev->mvdev.max_vqs; i++) { > ndev->vqs[i].ready =3D false; > + ndev->vqs[i].modified_fields =3D 0; > + } > > ndev->mvdev.cvq.ready =3D false; > } > -- > 2.42.0 >