From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2370C4708F for ; Wed, 2 Jun 2021 07:05:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B818A61361 for ; Wed, 2 Jun 2021 07:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230264AbhFBHH3 (ORCPT ); Wed, 2 Jun 2021 03:07:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48061 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231459AbhFBHHZ (ORCPT ); Wed, 2 Jun 2021 03:07:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622617542; 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=N7AFjn1kAaIwJ7yXpW9H7ltpl4fJk13y2xBWVC0JT2Y=; b=XQqwCCK83td8iyoCHwRbkrQJfEEViyskBWWP/l5JN3SqssOiB3yMB6dPzjfcNOqMzOXr7p 1Yic3raL4w0t0qJ72DkimFZ4cHj0N3l/QYpNNi0jcikfqsOrFkW9RvfryA21GQu1F05/ES rDTkd9i6rTk4v9S+SkUbq3CxcRukN0A= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-slffrRzrNVWEM6l1IwxmdQ-1; Wed, 02 Jun 2021 03:05:41 -0400 X-MC-Unique: slffrRzrNVWEM6l1IwxmdQ-1 Received: by mail-pj1-f72.google.com with SMTP id z3-20020a17090a4683b029015f6c19f126so1111110pjf.1 for ; Wed, 02 Jun 2021 00:05:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=N7AFjn1kAaIwJ7yXpW9H7ltpl4fJk13y2xBWVC0JT2Y=; b=WcodhSiNoEuGNki0EzVinXVM68YFKWSB5dGcdebXGUawnHb1VF/oyrmtNczy4RXOeM 13sQrjMG9Sy7/52yueiTfyahBtzdFg5R+doyt7kmtvjfPXqKergYY2ERZjMPNiRM0Y2A A+9WmtTv4E0L4rbjj98CGlDmPfEpFaDIs7F1pB4JDSkK0o8gMBdMS+KeU1MSt7hXNTcc H5LWUTAMSMT5qsBxvVnUENmJr4Q2cZk0AvPldRokUgMcZe9tSawGoAd6/hSGfIlZHRPa P7z3x651aMKW2xsGZw9uf7zzoYjJquxst4S2VVYw6yiCopVgi1aE0fzu8UOqdF8aIVUw X/zQ== X-Gm-Message-State: AOAM530HghbUcPOtSQkvsSyeLOUaTPapAnN/f2JzEWAUonOMB2ViJZ1p pe1AbMinEl0rlDR49M4IW7RXtkRmXEUpGxQGtwndAGb821JmQS3WMG8RoMNR9ykKjhOkm2+NTPH i77OYNsRxJUyz X-Received: by 2002:a63:d908:: with SMTP id r8mr17698730pgg.414.1622617540708; Wed, 02 Jun 2021 00:05:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxi1fo5eUxqSSq1jhRLtWR5oM/z3BQO8r5DzrHXf+icFTZlIa8TZoB63MRifCqrns7bI6/5cA== X-Received: by 2002:a63:d908:: with SMTP id r8mr17698704pgg.414.1622617540453; Wed, 02 Jun 2021 00:05:40 -0700 (PDT) Received: from wangxiaodeMacBook-Air.local ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id x19sm15554961pgj.66.2021.06.02.00.05.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Jun 2021 00:05:40 -0700 (PDT) Subject: Re: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset To: Eli Cohen Cc: mst@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org, eli@mellanox.com References: <20210602021043.39201-1-jasowang@redhat.com> <20210602021043.39201-4-jasowang@redhat.com> <20210602061324.GA8662@mtl-vdi-166.wap.labs.mlnx> From: Jason Wang Message-ID: <091dc6d0-8754-7b2a-64ec-985ef9db6329@redhat.com> Date: Wed, 2 Jun 2021 15:05:35 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <20210602061324.GA8662@mtl-vdi-166.wap.labs.mlnx> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org ÔÚ 2021/6/2 ÏÂÎç2:13, Eli Cohen дµÀ: > On Wed, Jun 02, 2021 at 10:10:42AM +0800, Jason Wang wrote: >> We used to fail the set_vq_state() since it was not supported yet by >> the virtio spec. But if the bus tries to set the state which is equal >> to the device initial state after reset, we can let it go. >> >> This is a must for virtio_vdpa() to set vq state during probe which is >> required for some vDPA parents. >> >> Signed-off-by: Jason Wang >> --- >> drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++--- >> 1 file changed, 39 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c >> index c76ebb531212..18bf4a422772 100644 >> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c >> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c >> @@ -210,13 +210,49 @@ static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid, >> return -EOPNOTSUPP; >> } >> >> +static int vp_vdpa_set_vq_state_split(struct vdpa_device *vdpa, >> + const struct vdpa_vq_state *state) >> +{ >> + const struct vdpa_vq_state_split *split = &state->split; >> + >> + if (split->avail_index == 0) >> + return 0; >> + >> + return -EOPNOTSUPP; >> +} >> + >> +static int vp_vdpa_set_vq_state_packed(struct vdpa_device *vdpa, >> + const struct vdpa_vq_state *state) >> +{ >> + const struct vdpa_vq_state_packed *packed = &state->packed; >> + >> + if (packed->last_avail_counter == 1 && > Can you elaborate on the requirement on last_avail_counter and > last_used_counter? This is required by the virtio spec: " 2.7.1 Driver and Device Ring Wrap Counters Each of the driver and the device are expected to maintain, internally, a single-bit ring wrap counter initialized to 1. " For virtio-pci device, since there's no way to assign the value of those counters, the counters will be reset to 1 after reset, otherwise the driver can't work. Thanks > >> + packed->last_avail_idx == 0 && >> + packed->last_used_counter == 1 && >> + packed->last_used_idx == 0) >> + return 0; >> + >> + return -EOPNOTSUPP; >> +} >> + >> static int vp_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid, >> const struct vdpa_vq_state *state) >> { >> - /* Note that this is not supported by virtio specification, so >> - * we return -ENOPOTSUPP here. This means we can't support live >> - * migration, vhost device start/stop. >> + struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa); >> + >> + /* Note that this is not supported by virtio specification. >> + * But if the state is by chance equal to the device initial >> + * state, we can let it go. >> */ >> + if ((vp_modern_get_status(mdev) & VIRTIO_CONFIG_S_FEATURES_OK) && >> + !vp_modern_get_queue_enable(mdev, qid)) { >> + if (vp_modern_get_driver_features(mdev) & >> + BIT_ULL(VIRTIO_F_RING_PACKED)) >> + return vp_vdpa_set_vq_state_packed(vdpa, state); >> + else >> + return vp_vdpa_set_vq_state_split(vdpa, state); >> + } >> + >> return -EOPNOTSUPP; >> } >> >> -- >> 2.25.1 >>