netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brett Creeley <bcreeley@amd.com>
To: Jason Gunthorpe <jgg@nvidia.com>, Brett Creeley <brett.creeley@amd.com>
Cc: kvm@vger.kernel.org, netdev@vger.kernel.org,
	alex.williamson@redhat.com, yishaih@nvidia.com,
	shameerali.kolothum.thodi@huawei.com, kevin.tian@intel.com,
	shannon.nelson@amd.com, drivers@pensando.io
Subject: Re: [PATCH v9 vfio 4/7] vfio/pds: Add VFIO live migration support
Date: Fri, 5 May 2023 08:42:44 -0700	[thread overview]
Message-ID: <07abb13c-b60e-f35c-8e26-13857a97866f@amd.com> (raw)
In-Reply-To: <ZFPwaa40glVrms02@nvidia.com>



On 5/4/2023 10:50 AM, Jason Gunthorpe wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> On Fri, Apr 21, 2023 at 06:06:39PM -0700, Brett Creeley wrote:
> 
>> +static int
>> +pds_vfio_dma_map_lm_file(struct device *dev, enum dma_data_direction dir,
>> +                      struct pds_vfio_lm_file *lm_file)
>> +{
>> +     struct pds_lm_sg_elem *sgl, *sge;
>> +     struct scatterlist *sg;
>> +     dma_addr_t sgl_addr;
>> +     size_t sgl_size;
>> +     int err;
>> +     int i;
>> +
>> +     if (!lm_file)
>> +             return -EINVAL;
>> +
>> +     /* dma map file pages */
>> +     err = dma_map_sgtable(dev, &lm_file->sg_table, dir, 0);
>> +     if (err)
>> +             return err;
>> +
>> +     lm_file->num_sge = lm_file->sg_table.nents;
>> +
>> +     /* alloc sgl */
>> +     sgl_size = lm_file->num_sge * sizeof(struct pds_lm_sg_elem);
>> +     sgl = kzalloc(sgl_size, GFP_KERNEL);
>> +     if (!sgl) {
>> +             err = -ENOMEM;
>> +             goto err_alloc_sgl;
>> +     }
>> +
>> +     sgl_addr = dma_map_single(dev, sgl, sgl_size, DMA_TO_DEVICE);
>> +     if (dma_mapping_error(dev, sgl_addr)) {
>> +             err = -EIO;
>> +             goto err_map_sgl;
>> +     }
>> +
>> +     lm_file->sgl = sgl;
>> +     lm_file->sgl_addr = sgl_addr;
>> +
>> +     /* fill sgl */
>> +     sge = sgl;
>> +     for_each_sgtable_dma_sg(&lm_file->sg_table, sg, i) {
>> +             sge->addr = cpu_to_le64(sg_dma_address(sg));
>> +             sge->len  = cpu_to_le32(sg_dma_len(sg));
>> +             dev_dbg(dev, "addr = %llx, len = %u\n", sge->addr, sge->len);
>> +             sge++;
>> +     }
> 
> This sequence is in the wrong order, the dma_map_single() has to be
> after the data is written to the memory as it synchronizes the caches
> on some arches

This is an easy enough fix and I'll keep this in mind moving forward. 
Thanks for pointing it out.

> 
>> +
>> +     return 0;
>> +
>> +err_map_sgl:
>> +     kfree(sgl);
>> +err_alloc_sgl:
>> +     dma_unmap_sgtable(dev, &lm_file->sg_table, dir, 0);
>> +     return err;
> 
> And why is the goto error unwind in a messed up order? Error unwinds
> should always be strictly in the opposite order of the success
> path. Check them all when you are fixing the "come from" notation
> 
> Jason

Yeah, this wasn't on purpose. Thanks again for pointing things like this 
out. As you noted I will go through the entire series to make sure the 
goto labels are named by what they are freeing/clearing and also that 
they are in the correct opposite order.

Thanks again for the review.

Brett

  reply	other threads:[~2023-05-05 15:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-22  1:06 [PATCH v9 vfio 0/7] pds_vfio driver Brett Creeley
2023-04-22  1:06 ` [PATCH v9 vfio 1/7] vfio: Commonize combine_ranges for use in other VFIO drivers Brett Creeley
2023-04-22  1:06 ` [PATCH v9 vfio 2/7] vfio/pds: Initial support for pds_vfio VFIO driver Brett Creeley
2023-05-04 17:26   ` Jason Gunthorpe
2023-05-04 20:20     ` Jakub Kicinski
2023-05-04 22:41       ` Jason Gunthorpe
2023-05-04 23:40         ` Jakub Kicinski
2023-05-05 13:29           ` Jason Gunthorpe
2023-05-05 15:35     ` Brett Creeley
2023-05-04 17:31   ` Jason Gunthorpe
2023-05-05 15:36     ` Brett Creeley
2023-06-02 22:05     ` Brett Creeley
2023-04-22  1:06 ` [PATCH v9 vfio 3/7] vfio/pds: register with the pds_core PF Brett Creeley
2023-04-22  1:06 ` [PATCH v9 vfio 4/7] vfio/pds: Add VFIO live migration support Brett Creeley
2023-05-04 17:34   ` Jason Gunthorpe
2023-05-05 15:37     ` Brett Creeley
2023-05-04 17:40   ` Jason Gunthorpe
2023-05-05 15:39     ` Brett Creeley
2023-05-04 17:50   ` Jason Gunthorpe
2023-05-05 15:42     ` Brett Creeley [this message]
2023-04-22  1:06 ` [PATCH v9 vfio 5/7] vfio/pds: Add support for dirty page tracking Brett Creeley
2023-05-04 18:21   ` Jason Gunthorpe
2023-04-22  1:06 ` [PATCH v9 vfio 6/7] vfio/pds: Add support for firmware recovery Brett Creeley
2023-04-22  1:06 ` [PATCH v9 vfio 7/7] vfio/pds: Add Kconfig and documentation Brett Creeley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07abb13c-b60e-f35c-8e26-13857a97866f@amd.com \
    --to=bcreeley@amd.com \
    --cc=alex.williamson@redhat.com \
    --cc=brett.creeley@amd.com \
    --cc=drivers@pensando.io \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=shannon.nelson@amd.com \
    --cc=yishaih@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).