All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Mastro <amastro@fb.com>
To: Alex Williamson <alex@shazbot.org>
Cc: David Matlack <dmatlack@google.com>,
	Shuah Khan <shuah@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
	<kvm@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/4] vfio: selftests: add iova range query helpers
Date: Tue, 11 Nov 2025 09:59:00 -0800	[thread overview]
Message-ID: <aRN5ZBWJ16I/TtY5@devgpu015.cco6.facebook.com> (raw)
In-Reply-To: <20251111105202.3aa734aa.alex@shazbot.org>

On Tue, Nov 11, 2025 at 10:52:02AM -0700, Alex Williamson wrote:
> On Tue, 11 Nov 2025 09:35:31 -0800
> Alex Mastro <amastro@fb.com> wrote:
> 
> > On Tue, Nov 11, 2025 at 10:09:48AM -0700, Alex Williamson wrote:
> > > On Tue, 11 Nov 2025 06:52:02 -0800
> > > Alex Mastro <amastro@fb.com> wrote:  
> > > > diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> > > > index a381fd253aa7..7a523e3f2dce 100644
> > > > --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> > > > +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> > > > @@ -29,6 +29,173 @@
> > > >  	VFIO_ASSERT_EQ(__ret, 0, "ioctl(%s, %s, %s) returned %d\n", #_fd, #_op, #_arg, __ret); \
> > > >  } while (0)
> > > >  
> > > > +static struct vfio_info_cap_header *next_cap_hdr(void *buf, size_t bufsz,
> > > > +						 size_t *cap_offset)
> > > > +{
> > > > +	struct vfio_info_cap_header *hdr;
> > > > +
> > > > +	if (!*cap_offset)
> > > > +		return NULL;
> > > > +
> > > > +	VFIO_ASSERT_LT(*cap_offset, bufsz);
> > > > +	VFIO_ASSERT_GE(bufsz - *cap_offset, sizeof(*hdr));
> > > > +
> > > > +	hdr = (struct vfio_info_cap_header *)((u8 *)buf + *cap_offset);
> > > > +
> > > > +	if (hdr->next)
> > > > +		VFIO_ASSERT_GT(hdr->next, *cap_offset);  
> > > 
> > > This might be implementation, but I don't think it's a requirement.
> > > The vfio capability chains are based on PCI capabilities, which have no
> > > ordering requirement.  Thanks,  
> > 
> > My main interest was to enforce that the chain doesn't contain a cycle, and
> > checking for monotonically increasing cap offset was the simplest way I could
> > think of to guarantee such.
> > 
> > If there isn't such a check, and kernel vends a malformed cycle-containing
> > chain, chain traversal would infinite loop.
> > 
> > Given the location of this test code coupled to the kernel tree, do you think
> > such assumptions about implementation still reach too far? If yes, I can either
> > remove this check, or try to make cycle detection more relaxed about offsets
> > potentially going backwards.
> 
> I've seen cycle detection in PCI config space implemented as just a
> depth/ttl counter.  Max cycles is roughly (buffer-size/header-size).  I
> think that would be sufficient if we want to include that sanity
> testing.  Thanks,

Thanks, that's a good suggestion -- will take this in v3.

> 
> Alex

  reply	other threads:[~2025-11-11 17:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-11 14:52 [PATCH v2 0/4] vfio: selftests: update DMA mapping tests to use queried IOVA ranges Alex Mastro
2025-11-11 14:52 ` [PATCH v2 1/4] vfio: selftests: add iova range query helpers Alex Mastro
2025-11-11 17:09   ` Alex Williamson
2025-11-11 17:35     ` Alex Mastro
2025-11-11 17:52       ` Alex Williamson
2025-11-11 17:59         ` Alex Mastro [this message]
2025-11-11 14:52 ` [PATCH v2 2/4] vfio: selftests: fix map limit tests to use last available iova Alex Mastro
2025-11-11 14:52 ` [PATCH v2 3/4] vfio: selftests: add iova allocator Alex Mastro
2025-11-11 14:52 ` [PATCH v2 4/4] vfio: selftests: replace iova=vaddr with allocated iovas Alex Mastro
2025-11-11 17:09   ` Alex Williamson
2025-11-11 17:21     ` Alex Mastro
2025-11-11 17:10 ` [PATCH v2 0/4] vfio: selftests: update DMA mapping tests to use queried IOVA ranges Alex Williamson
2025-11-11 17:41 ` David Matlack
2025-11-11 18:49   ` Alex Mastro

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=aRN5ZBWJ16I/TtY5@devgpu015.cco6.facebook.com \
    --to=amastro@fb.com \
    --cc=alex@shazbot.org \
    --cc=dmatlack@google.com \
    --cc=jgg@ziepe.ca \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.