From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FGFSdwXI; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 4688A5A061A for ; Wed, 03 Dec 2025 07:34:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764743647; 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=lN3wVGlBHNWU/9UlqGTodR7QeUzMvvGFI7+h7O6QuZ4=; b=FGFSdwXIOlbmz1YPBB6DqDuNWs3GT7Ebpt4NCWQcNf7QrVm1MX9I5qmfqpyoz/r2ULZE8U WP0SoDED+EPdZQvmiWuoTjpnHZ0BS5h+OSE/rPxdbi6KzgD/H7Ikf5FBRxZr28ZonxtRaJ VZuQzhrR/aNH3g5gAzNvMj4GCkxpiuE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-67-LvNgGzoyOcaK4PWmZ3zbUQ-1; Wed, 03 Dec 2025 01:34:05 -0500 X-MC-Unique: LvNgGzoyOcaK4PWmZ3zbUQ-1 X-Mimecast-MFC-AGG-ID: LvNgGzoyOcaK4PWmZ3zbUQ_1764743644 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4779d8fd4ecso2369005e9.1 for ; Tue, 02 Dec 2025 22:34:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764743644; x=1765348444; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lN3wVGlBHNWU/9UlqGTodR7QeUzMvvGFI7+h7O6QuZ4=; b=iSW45Jj0l5W/pL9lf/KA5Egyq6qGew0oGoSljvFNHt0uueJg3X4xsRA8eMBKEENbNB ZifYBHIPMZxTxnTeSm64S2jcwSOw3+N/z2HTb9D7pUpKlSucCXUN0QBileK9XfBuMwIp zvyBiptctEZ6Uek8Z0qBhmhYdRrCIDB2fLIAkeWbCvfKVgpq9f784JsdN1u1EGjlifZu NZ3ioXPpJJmEAjbXWPJ3l5wlCqpugBLZ30OfpnMeAEiYEQw+t9J2t7mg1FAPsRd8/wXs LuX4i4he6/gzTh/jofZDjimpvzSAbX7H7u5AnLwT30C+wX20aIfZnpW3VxrgBcLyCPDu ac9A== X-Gm-Message-State: AOJu0YxlGGkba5kuBB/zTsuWalAEaf80SYVdMJwxRiW1HHLSxBU/lFZG cEnnVcAR9fwZLUp4dQyeiTYaYkjw4YIwyckfEFnFN6kxoGdhbRtKChuLhrUPkl/tYljLDWwtYNq fPRAx4cv163AT39RYjk+67WuY4+w9lrb6fOb5eICq0JbwEni3M4OyDUGL7Qhdhw== X-Gm-Gg: ASbGncvcvg026tgfNYPvo07BrFlLS3J9XvVQL4QSEpY6BsaY4G+yatf7G5wonEJLEC6 EfAKg8qB9ADyMsBzHb0Yra+o9tqYJDAaxsq0zuctUfzFazhZK9rqgaj0qPYNLUHQceRRPXk7nB3 p5B5wvq2YTiCA0I/0Jk+t+PZckgeL3m8GdTI3vLzM1LZA6ZUenMxpzC0ws1OtyLG2iwdaorylfR awm5aF3Tmqh7FQd1THjvJGp7NprezBV833aMBdiVPxwClMxovr2JqBfCumBpyp7wVuL/TVUQ0PL PsgXfJK5noPGsHrPmZ0vXij0SlqS0OOYGOIHp7fZJGlzDF9H2L/q34eHui56aCZ6Gob5EEMB/4S H9CSwwX+e/oWMRst80fuN X-Received: by 2002:a05:600c:4695:b0:46f:a2ba:581f with SMTP id 5b1f17b1804b1-4792af522b1mr10180665e9.16.1764743643819; Tue, 02 Dec 2025 22:34:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEeFpPD4BD1WwZ4MKiqryb/p7HmpVFCMDS/RzhMojcMAixGgujh7dnz62WcUf9HwegMRvr7JA== X-Received: by 2002:a05:600c:4695:b0:46f:a2ba:581f with SMTP id 5b1f17b1804b1-4792af522b1mr10180495e9.16.1764743643359; Tue, 02 Dec 2025 22:34:03 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4792a8ccbf3sm28880935e9.12.2025.12.02.22.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 22:34:02 -0800 (PST) Date: Wed, 3 Dec 2025 07:34:01 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v5 02/15] util: Extend sock_probe_mem() to sock_probe_features() Message-ID: <20251203073401.375b6c47@elisabeth> In-Reply-To: <20251202040215.2351792-3-david@gibson.dropbear.id.au> References: <20251202040215.2351792-1-david@gibson.dropbear.id.au> <20251202040215.2351792-3-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: BwIuvUV1tRtQ5RSjtl8WfIuvNnLu4yAqjwjrl7wZRXc_1764743644 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: MIEJCYJFHEWSKZVSTRMCRVT4GDS6A67Z X-Message-ID-Hash: MIEJCYJFHEWSKZVSTRMCRVT4GDS6A67Z X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 2 Dec 2025 15:02:02 +1100 David Gibson wrote: > sock_probe_mem() currently checks whether we're able to allocate large > socket buffers. Extend it to also check whether the SO_BINDTODEVICE > socket option is available. Rename to sock_probe_features() to reflect the > new functionality. > > Signed-off-by: David Gibson > --- > passt.c | 2 +- > passt.h | 2 ++ > util.c | 19 +++++++++++++++++-- > util.h | 2 +- > 4 files changed, 21 insertions(+), 4 deletions(-) > > diff --git a/passt.c b/passt.c > index 4964427d..0b84ac6c 100644 > --- a/passt.c > +++ b/passt.c > @@ -381,7 +381,7 @@ int main(int argc, char **argv) > if (setrlimit(RLIMIT_NOFILE, &limit)) > die_perror("Failed to set current limit for open files"); > > - sock_probe_mem(&c); > + sock_probe_features(&c); > > conf(&c, argc, argv); > trace_init(c.trace); > diff --git a/passt.h b/passt.h > index 15801b44..79d01ddb 100644 > --- a/passt.h > +++ b/passt.h > @@ -204,6 +204,7 @@ struct ip6_ctx { > * @freebind: Allow binding of non-local addresses for forwarding > * @low_wmem: Low probed net.core.wmem_max > * @low_rmem: Low probed net.core.rmem_max > + * @no_bindtodevice: Unprivileged SO_BINDTODEVICE not available > * @vdev: vhost-user device > * @device_state_fd: Device state migration channel > * @device_state_result: Device state migration result > @@ -281,6 +282,7 @@ struct ctx { > > int low_wmem; > int low_rmem; > + int no_bindtodevice; > > struct vu_dev *vdev; > > diff --git a/util.c b/util.c > index 347f34f5..bad38129 100644 > --- a/util.c > +++ b/util.c > @@ -233,12 +233,13 @@ int sock_unix(char *sock_path) > } > > /** > - * sock_probe_mem() - Check if setting high SO_SNDBUF and SO_RCVBUF is allowed > + * sock_probe_features() - Probe for socket features we might use > * @c: Execution context > */ > -void sock_probe_mem(struct ctx *c) > +void sock_probe_features(struct ctx *c) > { > int v = INT_MAX / 2, s; > + const char lo[] = "lo"; > socklen_t sl; > > s = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); > @@ -247,6 +248,7 @@ void sock_probe_mem(struct ctx *c) > return; > } > > + /* Check if setting high SO_SNDBUF and SO_RCVBUF is allowed */ > sl = sizeof(v); > if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &v, sizeof(v)) || > getsockopt(s, SOL_SOCKET, SO_SNDBUF, &v, &sl) || > @@ -259,6 +261,19 @@ void sock_probe_mem(struct ctx *c) > (size_t)v < RCVBUF_BIG) > c->low_rmem = 1; > > + /* Check if SO_BINDTODEVICE is available > + * > + * Supported since kernel version 5.7, commit c427bfec18f2 ("net: core: > + * enable SO_BINDTODEVICE for non-root users"). Some distro kernels may > + * have backports, of course. Record whether we can use it so that we > + * can give more useful diagnostics. > + */ > + if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, lo, sizeof(lo)-1)) { Nit: our coding style uses spaces around arithmetic operators... I took the liberty of fixing this up on merge, though. -- Stefano