Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Breno Leitao <leitao@debian.org>
To: Allison Henderson <achender@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	Shuah Khan <shuah@kernel.org>,
	 linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-rdma@vger.kernel.org,  rds-devel@oss.oracle.com,
	linux-kselftest@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH net-next 2/2] selftests: net: rds: add getsockopt() conversion test
Date: Fri, 5 Jun 2026 03:09:47 -0700	[thread overview]
Message-ID: <aiKgGJpCWs8zxNKx@gmail.com> (raw)
In-Reply-To: <134c50a1ca2d2f2bc06336072c89ff011a9842cb.camel@kernel.org>

On Fri, Jun 05, 2026 at 02:56:09AM -0700, Allison Henderson wrote:
> Hi Breno,
> 
> Thanks for working on this.  Your test covers a lot of socket behavior that the
> existing packet test doesn't get into, so I definitely think it's worth adding.
> I ran it locally under vng and it passes for me.  I did notice one nit below, but
> otherwise I think it looks really good.

Good, thanks for the direction and review!

> > +TEST_F(rds, info_counters_snapshot)
> > +{
> > +	struct rds_info_counter *ctr;
> > +	socklen_t need = 0, len;
> > +	long pagesz = sysconf(_SC_PAGESIZE);
> > +	unsigned int i, n;
> > +	char *region, *buf;
> > +	int ret;
> > +
> > +	/* Probe for the required size. */
> > +	getsockopt(self->fd, SOL_RDS, RDS_INFO_COUNTERS, NULL, &need);
> > +	ASSERT_GT(need, 0);
> > +
> > +	region = mmap(NULL, 2 * pagesz, PROT_READ | PROT_WRITE,
> > +		      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> 
> The 2-page mapping (and the ASSERT_LE guarding it) ties the test to the snapshot
> fitting in two pages.  This works right now, but ideally the region here should
> account for the number of counters that come back from RDS_INFO_COUNTERS so that
> if the total number of counters were to grow later, we don't overrun a region
> that's set to a fixed number of pages.  So in this case, we'd want the need + offset,
> and then page align that so we can mmap it:
> 
> 	offset	= pagesz - 64; 
> 	map_len	= ((offset + need + pagesz - 1) / pagesz) * pagesz;  /* round (off+need) up to whole pages */
> 	region  = mmap(NULL, map_len, ...);                 

Good point - sizing the mapping from the probed length keeps it correct if the
counter set ever grows. In v2 I'll derive map_len from need + offset and drop
the fixed 2-page assumption:

        long pagesz = sysconf(_SC_PAGESIZE);
        size_t offset, map_len;
        ...
        getsockopt(self->fd, SOL_RDS, RDS_INFO_COUNTERS, NULL, &need);
        ASSERT_GT(need, 0);

        /* Unaligned start that runs past the first page boundary. */
        offset  = pagesz - 64;
        map_len = ((offset + need + pagesz - 1) / pagesz) * pagesz;

        region = mmap(NULL, map_len, PROT_READ | PROT_WRITE,
                      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
        ASSERT_NE(MAP_FAILED, region);

        buf = region + offset;

with the ASSERT_LE() dropped and munmap(region, map_len) at the end.

Thanks for the review,
--breno

      reply	other threads:[~2026-06-05 10:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 16:11 [PATCH net-next 0/2] net: rds: convert rds to getsockopt_iter Breno Leitao
2026-06-03 16:11 ` [PATCH net-next 1/2] rds: convert " Breno Leitao
2026-06-05  2:20   ` Allison Henderson
2026-06-05 10:07     ` Breno Leitao
2026-06-03 16:11 ` [PATCH net-next 2/2] selftests: net: rds: add getsockopt() conversion test Breno Leitao
2026-06-05  9:56   ` Allison Henderson
2026-06-05 10:09     ` Breno Leitao [this message]

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=aiKgGJpCWs8zxNKx@gmail.com \
    --to=leitao@debian.org \
    --cc=achender@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rds-devel@oss.oracle.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox