Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp430068rwb; Thu, 12 Jan 2023 22:46:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXt2TijdpGQeYPypWIPEYKG4lPQv96CqjjTLIYmWCMkgBjMvUSGBtq8qJN72Gih3xxsTX6Nz X-Received: by 2002:a17:902:8e81:b0:192:d5dc:c842 with SMTP id bg1-20020a1709028e8100b00192d5dcc842mr39153310plb.44.1673592418285; Thu, 12 Jan 2023 22:46:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673592418; cv=none; d=google.com; s=arc-20160816; b=AvhRDANL9mYM8j3WsOF6mhMhOtRerQDlpQnOvSlOWL5Zm9QfJM02XudRD6s2BQipVk H/foKXL5QyuF36yU908Dl309kmDmoeDLtYc22oJufYXPMPtlsawuYydMI7xoGs+BQGD3 idGVFpxs1I15t2U21oaj98ZAMv6pVYCXmSNiXx/E692HSlIdhZTtaUSTR1ly+/yNYmo9 Mv5VOwLRdpxuLFZc/uJG7SuLpQXU5y1BrEAq6btrZsdAD/Z+NwNahGNEnXD/FNmEoRTY uHXpQeAx14HXo+TSjnzK6t5PSnr8eN4MJZgJm3peF5PFTQLUltz0VwZUerCK21Lhi5BX aqSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZA/WXC5prDy/5mOBtGNQhQSiRmA3vqaLzTAXUcArX8A=; b=WoDu8G2E/V53Nf68FhtzL5s83ix5+yXXKCoa3jw/zY3QNgwlRoBycbsMIfXieW3pYP WJogZCwEzbmPUFm8YL9RDiiJ3Qhb7G+q51tdpQuKtI4DF3IgehZ1MPB4v95Uei8X2dlP ieNJyQ8CK+i4tMPNv6tc6YGIXMQ0Yr8I8ytfTSwnnd6eSN2Qb9NqsEp4IDd9/rW+GIcX +fX0BtOYjfGbtAWXwpQGXW5eyV7JY6mRtxxDaOkJyOEPsZg99hbXp6Jpxe/eKCCmRwuk APXr9nEDs0OtEbJ8QGZoGfzB8dHyzXh0N/pDf/GaP+nws1Qq8PqH84fADaR/SvNo7a6B pSQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JDgkpmr6; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a7-20020a170902ecc700b00192a1df8776si10026221plh.511.2023.01.12.22.46.51; Thu, 12 Jan 2023 22:46:58 -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=@redhat.com header.s=mimecast20190719 header.b=JDgkpmr6; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239173AbjAMGWZ (ORCPT + 50 others); Fri, 13 Jan 2023 01:22:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235409AbjAMGVF (ORCPT ); Fri, 13 Jan 2023 01:21:05 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BEFC625E6 for ; Thu, 12 Jan 2023 22:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673590817; 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: in-reply-to:in-reply-to:references:references; bh=ZA/WXC5prDy/5mOBtGNQhQSiRmA3vqaLzTAXUcArX8A=; b=JDgkpmr69D1meVHd+XYL0Pupd5Mh18N9LkQ/F1pUmp8lEkQaf6jvkLuh9OcNilu1mcXLFR 8qXjbrYN+juokgtUEQoJJpfH15LQnNH8i5ZTQwdwr8/4s1/o/3f/YGO6pUn4t4MVyXmhln Mjn+D/Md9ju4LhUPFmg8eqiAiS7aRuo= Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-34-kT8kc44YO-28Z8HeTYBcyQ-1; Fri, 13 Jan 2023 01:20:16 -0500 X-MC-Unique: kT8kc44YO-28Z8HeTYBcyQ-1 Received: by mail-oo1-f72.google.com with SMTP id j23-20020a4a92d7000000b004f23fe5feb8so2618150ooh.16 for ; Thu, 12 Jan 2023 22:20:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=ZA/WXC5prDy/5mOBtGNQhQSiRmA3vqaLzTAXUcArX8A=; b=RSBABwRMvCvmwQvpyh4rJU/GBYyX6Rei2x4pX8yZj8zrIWCuRE8xWy8UI7D3nXfU+Y aVvqF5eEQoux0fhozpDs4m/MRZt1H1RSmrY/z+3MvYIFbLGp0g82em51T70wPDnOXRcY Dpf+JE3nLlv4mFi2Y2OiG7/n9+8MfqEb586Xu4153RaTAcBYg78WJAbpDIKYwnztXp50 mUGZRgFPyJypX4oSV7xc8Nb+MFZlW14ApTxgfDGffC9L6nRh9boqcehSeGtKMvR+ndFR q/9CTwMyKLp5SptY3RyvVtHzepO0cZj1tMOkA2qNzozODyA7LVe4nbyhgu/kTMxpMTVe FJ2A== X-Gm-Message-State: AFqh2koVAmLRzrOHonPDtuhDy88RXYSwwTnXL75N0rNcQ64WsYVQylGu A3rtrmXW68OC92PnrcCOvuidRHALPvrrMdtIfnPLKIPp76KKx1OF2n2ueJI6qL7dCDhVGMeK98z J2kokEMrRyT6m8rfyxy2LPHBL+fmWK1HkXZAq/Ebg X-Received: by 2002:a54:4e89:0:b0:35c:303d:fe37 with SMTP id c9-20020a544e89000000b0035c303dfe37mr3472240oiy.35.1673590815534; Thu, 12 Jan 2023 22:20:15 -0800 (PST) X-Received: by 2002:a54:4e89:0:b0:35c:303d:fe37 with SMTP id c9-20020a544e89000000b0035c303dfe37mr3472233oiy.35.1673590815235; Thu, 12 Jan 2023 22:20:15 -0800 (PST) MIME-Version: 1.0 References: <20221207145428.31544-1-gautam.dawar@amd.com> <20221207145428.31544-9-gautam.dawar@amd.com> <289dc054-4cb7-e31c-69b4-b02a62a2fe16@amd.com> In-Reply-To: <289dc054-4cb7-e31c-69b4-b02a62a2fe16@amd.com> From: Jason Wang Date: Fri, 13 Jan 2023 14:20:03 +0800 Message-ID: Subject: Re: [PATCH net-next 08/11] sfc: implement device status related vdpa config operations To: Gautam Dawar Cc: Gautam Dawar , linux-net-drivers@amd.com, netdev@vger.kernel.org, eperezma@redhat.com, tanuj.kamde@amd.com, Koushik.Dutta@amd.com, harpreet.anand@amd.com, Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 On Fri, Jan 13, 2023 at 2:11 PM Gautam Dawar wrote: > > > On 1/13/23 09:58, Jason Wang wrote: > > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > > > > On Wed, Jan 11, 2023 at 2:36 PM Jason Wang wrote: > >> On Mon, Jan 9, 2023 at 6:21 PM Gautam Dawar wrote: > >>> > >>> On 12/14/22 12:15, Jason Wang wrote: > >>>> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > >>>> > >>>> > >>>> On Wed, Dec 7, 2022 at 10:57 PM Gautam Dawar wrote: > >>>>> vDPA config opertions to handle get/set device status and device > >>>>> reset have been implemented. > >>>>> > >>>>> Signed-off-by: Gautam Dawar > >>>>> --- > >>>>> drivers/net/ethernet/sfc/ef100_vdpa.c | 7 +- > >>>>> drivers/net/ethernet/sfc/ef100_vdpa.h | 1 + > >>>>> drivers/net/ethernet/sfc/ef100_vdpa_ops.c | 133 ++++++++++++++++++++++ > >>>>> 3 files changed, 140 insertions(+), 1 deletion(-) > >>>>> > >>>>> diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c > >>>>> index 04d64bfe3c93..80bca281a748 100644 > >>>>> --- a/drivers/net/ethernet/sfc/ef100_vdpa.c > >>>>> +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c > >>>>> @@ -225,9 +225,14 @@ static int vdpa_allocate_vis(struct efx_nic *efx, unsigned int *allocated_vis) > >>>>> > >>>>> static void ef100_vdpa_delete(struct efx_nic *efx) > >>>>> { > >>>>> + struct vdpa_device *vdpa_dev; > >>>>> + > >>>>> if (efx->vdpa_nic) { > >>>>> + vdpa_dev = &efx->vdpa_nic->vdpa_dev; > >>>>> + ef100_vdpa_reset(vdpa_dev); > >>>> Any reason we need to reset during delete? > >>> ef100_reset_vdpa_device() does the necessary clean-up including freeing > >>> irqs, deleting filters and deleting the vrings which is required while > >>> removing the vdpa device or unloading the driver. > >> That's fine but the name might be a little bit confusing since vDPA > >> reset is not necessary here. > >> > >>>>> + > >>>>> /* replace with _vdpa_unregister_device later */ > >>>>> - put_device(&efx->vdpa_nic->vdpa_dev.dev); > >>>>> + put_device(&vdpa_dev->dev); > >>>>> efx->vdpa_nic = NULL; > >>>>> } > >>>>> efx_mcdi_free_vis(efx); > >>>>> diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h > >>>>> index a33edd6dda12..1b0bbba88154 100644 > >>>>> --- a/drivers/net/ethernet/sfc/ef100_vdpa.h > >>>>> +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h > >>>>> @@ -186,6 +186,7 @@ int ef100_vdpa_add_filter(struct ef100_vdpa_nic *vdpa_nic, > >>>>> enum ef100_vdpa_mac_filter_type type); > >>>>> int ef100_vdpa_irq_vectors_alloc(struct pci_dev *pci_dev, u16 nvqs); > >>>>> void ef100_vdpa_irq_vectors_free(void *data); > >>>>> +int ef100_vdpa_reset(struct vdpa_device *vdev); > >>>>> > >>>>> static inline bool efx_vdpa_is_little_endian(struct ef100_vdpa_nic *vdpa_nic) > >>>>> { > >>>>> diff --git a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c > >>>>> index 132ddb4a647b..718b67f6da90 100644 > >>>>> --- a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c > >>>>> +++ b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c > >>>>> @@ -251,6 +251,62 @@ static bool is_qid_invalid(struct ef100_vdpa_nic *vdpa_nic, u16 idx, > >>>>> return false; > >>>>> } > >>>>> > >>>>> +static void ef100_reset_vdpa_device(struct ef100_vdpa_nic *vdpa_nic) > >>>>> +{ > >>>>> + int i; > >>>>> + > >>>>> + WARN_ON(!mutex_is_locked(&vdpa_nic->lock)); > >>>>> + > >>>>> + if (!vdpa_nic->status) > >>>>> + return; > >>>>> + > >>>>> + vdpa_nic->vdpa_state = EF100_VDPA_STATE_INITIALIZED; > >>>>> + vdpa_nic->status = 0; > >>>>> + vdpa_nic->features = 0; > >>>>> + for (i = 0; i < (vdpa_nic->max_queue_pairs * 2); i++) > >>>>> + reset_vring(vdpa_nic, i); > >>>>> +} > >>>>> + > >>>>> +/* May be called under the rtnl lock */ > >>>>> +int ef100_vdpa_reset(struct vdpa_device *vdev) > >>>>> +{ > >>>>> + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); > >>>>> + > >>>>> + /* vdpa device can be deleted anytime but the bar_config > >>>>> + * could still be vdpa and hence efx->state would be STATE_VDPA. > >>>>> + * Accordingly, ensure vdpa device exists before reset handling > >>>>> + */ > >>>>> + if (!vdpa_nic) > >>>>> + return -ENODEV; > >>>>> + > >>>>> + mutex_lock(&vdpa_nic->lock); > >>>>> + ef100_reset_vdpa_device(vdpa_nic); > >>>>> + mutex_unlock(&vdpa_nic->lock); > >>>>> + return 0; > >>>>> +} > >>>>> + > >>>>> +static int start_vdpa_device(struct ef100_vdpa_nic *vdpa_nic) > >>>>> +{ > >>>>> + int rc = 0; > >>>>> + int i, j; > >>>>> + > >>>>> + for (i = 0; i < (vdpa_nic->max_queue_pairs * 2); i++) { > >>>>> + if (can_create_vring(vdpa_nic, i)) { > >>>>> + rc = create_vring(vdpa_nic, i); > >>>> So I think we can safely remove the create_vring() in set_vq_ready() > >>>> since it's undefined behaviour if set_vq_ready() is called after > >>>> DRIVER_OK. > >>> Is this (undefined) behavior documented in the virtio spec? > >> This part is kind of tricky: > >> > >> PCI transport has a queue_enable field. And recently, > >> VIRTIO_F_RING_RESET was introduced. Let's start without that first: > >> > >> In > >> > >> 4.1.4.3.2 Driver Requirements: Common configuration structure layout > >> > >> It said: > >> > >> "The driver MUST configure the other virtqueue fields before enabling > >> the virtqueue with queue_enable." > >> > >> and > >> > >> "The driver MUST NOT write a 0 to queue_enable." > >> > >> My understanding is that: > >> > >> 1) Write 0 is forbidden > >> 2) Write 1 after DRIVER_OK is undefined behaviour (or need to clarify) > >> > >> With VIRTIO_F_RING_RESET is negotiated: > >> > >> " > >> If VIRTIO_F_RING_RESET has been negotiated, after the driver writes 1 > >> to queue_reset to reset the queue, the driver MUST NOT consider queue > >> reset to be complete until it reads back 0 in queue_reset. The driver > >> MAY re-enable the queue by writing 1 to queue_enable after ensuring > >> that other virtqueue fields have been set up correctly. The driver MAY > >> set driver-writeable queue configuration values to different values > >> than those that were used before the queue reset. (see 2.6.1). > >> " > >> > >> Write 1 to queue_enable after DRIVER_OK and after the queue is reset is allowed. > >> > >> Thanks > > Btw, I just realized that we need to stick to the current behaviour, > > that is to say, to allow set_vq_ready() to be called after DRIVER_OK. > > So, both set_vq_ready() and DRIVER_OK are required for vring creation > and their order doesn't matter. Is that correct? Yes. > > Also, will set_vq_ready(0) after DRIVER_OK result in queue deletion? I think it should be treated as suspended or stopped. Since the device should survive from kicking the vq even if the driver does set_vq_ready(0). Thanks > > > > > It is needed for the cvq trap and migration for control virtqueue: > > > > https://www.mail-archive.com/qemu-devel@nongnu.org/msg931491.html > > > > Thanks > > > > > >> > >>> If so, can > >>> you please point me to the section of virtio spec that calls this order > >>> (set_vq_ready() after setting DRIVER_OK) undefined? Is it just that the > >>> queue can't be enabled after DRIVER_OK or the reverse (disabling the > >>> queue) after DRIVER_OK is not allowed? > >>>>> + if (rc) > >>>>> + goto clear_vring; > >>>>> + } > >>>>> + } > >>>>> + vdpa_nic->vdpa_state = EF100_VDPA_STATE_STARTED; > >>>>> + return rc; > >>>>> + > >>>>> +clear_vring: > >>>>> + for (j = 0; j < i; j++) > >>>>> + if (vdpa_nic->vring[j].vring_created) > >>>>> + delete_vring(vdpa_nic, j); > >>>>> + return rc; > >>>>> +} > >>>>> + > >>>>> static int ef100_vdpa_set_vq_address(struct vdpa_device *vdev, > >>>>> u16 idx, u64 desc_area, u64 driver_area, > >>>>> u64 device_area) > >>>>> @@ -568,6 +624,80 @@ static u32 ef100_vdpa_get_vendor_id(struct vdpa_device *vdev) > >>>>> return EF100_VDPA_VENDOR_ID; > >>>>> } > >>>>> > >>>>> +static u8 ef100_vdpa_get_status(struct vdpa_device *vdev) > >>>>> +{ > >>>>> + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); > >>>>> + u8 status; > >>>>> + > >>>>> + mutex_lock(&vdpa_nic->lock); > >>>>> + status = vdpa_nic->status; > >>>>> + mutex_unlock(&vdpa_nic->lock); > >>>>> + return status; > >>>>> +} > >>>>> + > >>>>> +static void ef100_vdpa_set_status(struct vdpa_device *vdev, u8 status) > >>>>> +{ > >>>>> + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); > >>>>> + u8 new_status; > >>>>> + int rc; > >>>>> + > >>>>> + mutex_lock(&vdpa_nic->lock); > >>>>> + if (!status) { > >>>>> + dev_info(&vdev->dev, > >>>>> + "%s: Status received is 0. Device reset being done\n", > >>>>> + __func__); > >>>>> + ef100_reset_vdpa_device(vdpa_nic); > >>>>> + goto unlock_return; > >>>>> + } > >>>>> + new_status = status & ~vdpa_nic->status; > >>>>> + if (new_status == 0) { > >>>>> + dev_info(&vdev->dev, > >>>>> + "%s: New status same as current status\n", __func__); > >>>>> + goto unlock_return; > >>>>> + } > >>>>> + if (new_status & VIRTIO_CONFIG_S_FAILED) { > >>>>> + ef100_reset_vdpa_device(vdpa_nic); > >>>>> + goto unlock_return; > >>>>> + } > >>>>> + > >>>>> + if (new_status & VIRTIO_CONFIG_S_ACKNOWLEDGE && > >>>>> + vdpa_nic->vdpa_state == EF100_VDPA_STATE_INITIALIZED) { > >>>> As replied before, I think there's no need to check > >>>> EF100_VDPA_STATE_INITIALIZED, otherwise it could be a bug somewhere. > >>> Ok. Will remove the check against EF100_VDPA_STATE_INITIALIZED. > >>>>> + vdpa_nic->status |= VIRTIO_CONFIG_S_ACKNOWLEDGE; > >>>>> + new_status &= ~VIRTIO_CONFIG_S_ACKNOWLEDGE; > >>>>> + } > >>>>> + if (new_status & VIRTIO_CONFIG_S_DRIVER && > >>>>> + vdpa_nic->vdpa_state == EF100_VDPA_STATE_INITIALIZED) { > >>>>> + vdpa_nic->status |= VIRTIO_CONFIG_S_DRIVER; > >>>>> + new_status &= ~VIRTIO_CONFIG_S_DRIVER; > >>>>> + } > >>>>> + if (new_status & VIRTIO_CONFIG_S_FEATURES_OK && > >>>>> + vdpa_nic->vdpa_state == EF100_VDPA_STATE_INITIALIZED) { > >>>>> + vdpa_nic->status |= VIRTIO_CONFIG_S_FEATURES_OK; > >>>>> + vdpa_nic->vdpa_state = EF100_VDPA_STATE_NEGOTIATED; > >>>> I think we can simply map EF100_VDPA_STATE_NEGOTIATED to > >>>> VIRTIO_CONFIG_S_FEATURES_OK. > >>>> > >>>> E.g the code doesn't fail the feature negotiation by clearing the > >>>> VIRTIO_CONFIG_S_FEATURES_OK when ef100_vdpa_set_driver_feature fails? > >>> Ok. > >>>> Thanks > >>> Regards, > >>> > >>> Gautam > >>> >