From nobody Mon Nov 23 05:00:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1791363222; cv=none; d=zohomail.com; s=zohoarc; b=WYImWgl4Jrwlv5yP0ytfrtMTeCgs73TWceyaAnr2YyAzYZWpF6c6CalTgCIn4x9U6Pmcyp86pR8aqdm6Ew8W+fR3k7xdnPkTs8srYwBSvYd68sOQM01m111cntnySY3K0xQd61htuk/SG5mKRU/MHYOnZ8rEzWuqVMEsQh12xYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791363222; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5Ltu2h4mQNH63wNh6b4t2KW06UJSusNDf0EeH5Va9VI=; b=lRg3ALSomfTpZJavzvMYQjI3zG+0Vae4RllyPipH3zVgmWZszB1yCrZ8jNJ0GytSPrRDAXeSMYgclrUdo1oy55nIVle4mUrB8Aytf+EUyo3sgO9sZ5Pg2CZDMhYNvNkMGbkjtBsbJko/8cwGjGsXKVB/s3sPojo7AT4xTv9Ff7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791363222782937.6317811651367; Wed, 7 Oct 2026 01:53:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENIZ-0007SP-Pk; Wed, 07 Oct 2026 04:46:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEJsp-0001cE-GZ for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:08:32 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEJsn-0005JO-9h for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:08:03 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4a172eb31f0so11859575e9.1 for ; Tue, 06 Oct 2026 22:08:00 -0700 (PDT) Received: from DESKTOP-2SK3BJA.localdomain ([197.49.190.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a17f795f29sm33359315e9.11.2026.10.06.22.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 22:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791349679; x=1791954479; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5Ltu2h4mQNH63wNh6b4t2KW06UJSusNDf0EeH5Va9VI=; b=f003dV1hu/ZNbwx1PCA2ykJGlFsrhrWSf21Lv5qVqa16slIc8VglOaNFTYzmppyaH8 +uUhQcaN0vEeOXyWZUfPfkQAx35HuNPVXsEQLDAdBFVEiPRAeY4zw4CaBT4FHig47t9u XKQ9y9yp0KQ4zo3qoI6NDDNCsmjF6/rbpdAtzHjULGDxE/DxJuYLjv2RtwBFlXvxDg8r YFOFJmRM4FM71ve4gtzPwYyQS/1TdEVgYtuxpBxbck/zqGy+OG6ij3C/xJMtabfUhrMa CdCnK2b1CX92QobyYJEttdjhaErjQ7mFKDwSy5++CYSZrMTRVg0bxZaz/cMMyFt0gAVI 3vjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791349679; x=1791954479; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5Ltu2h4mQNH63wNh6b4t2KW06UJSusNDf0EeH5Va9VI=; b=1SXjUHgN+pehUJ/xpTdziXdMnRBO8fp8P07izZgcIj5ANYT36Mk6MMXkMqJfokzSyM U0hbtadKdVngOCPl+XF6y+MMhDX+5jdXvoTKbinInnifuQTkTQlGfdPgphmT8M1lNRRp 6MQVRb7UFuLBidqAFXYPOMsvTOUhkmZrMiB8+BVoeNxgff7tkCiQBTNpw92z6j4JDDpO mOGZO/K2fWdK5EHhN4G8tA8EOI3J7+BqWxBOcCQIwU4TQNpugM3Vl5VTb4MSHUfFQZde gHkMpSx7huir7IqZEZADLOz5760xxicAbgTseXDNZlYfjcMsvM7REnkSKevqyieAHHaZ Js3Q== X-Gm-Message-State: AFuF++lmYN3EWHoAO9cbelaFPsX8YfPyPJoteCp7xtdRgBtVlN47/sZr bEP4sYg1SmCt8dsEcE/ZQslf6Vfw9Ixa+HZ7Fm8WV8yNcKGY9I9ODPFMhWkrgaURhdE= X-Gm-Gg: AYBFou3H7V996+sa4GrkviTv9blINWoaf8hu+D+ZjD4sgntZx5f4REaienE8TpmhRFw 1yFcPZq1vFHkWuqCgEywpkrmXZMyM3FJ5jnjDaOS51ZPCuNl+Q+IdfwJe/esM+pS3aXTn29s4nk wOlUGVqrwDIGdm6E929U8b/c3mGYfuZDcy5raltB5XznzijsC7GGuTr3W5d30DRBSlwea6EZkIy ojve5ufo7UbGEWZW11t86Q6gSa+gOSir291mIM+0AM92SqB1Mvbxib5z86rYUv5o+c/OFPUvVNi t6NQrfguHERtqBr5FfqtmjxTFmUZHzHz0ibnXf8qFNPPsyhyK3q0GQQ0HG9cJJ+xTrXVSEeDUo3 Uaz1fjXgO+ZsmGi+9Z3jH/cVnihmx7R9HVxUMwVdqjOQr3sdyhohRuO7pdVwA8DfzMS4IbGrePN sngtWpF1O0mR9zHBte+6QnIAZHfuqabEsOTKdH/naAN3KNTt1uM3DeFcCEvl0KtH7g4KhGyEGVe QH/Phc2+CLYc/ODvLT3hAcwKw== X-Received: by 2002:a05:600c:810c:b0:49f:ff73:9971 with SMTP id 5b1f17b1804b1-4a180420274mr12578265e9.18.1791349679023; Tue, 06 Oct 2026 22:07:59 -0700 (PDT) From: Nariman Sayed To: qemu-devel@nongnu.org Cc: Jason Wang , "Michael S . Tsirkin" , Nariman Sayed Subject: [PATCH v2 1/3] net/tap: add tap_fd_get_mtu() to query host tap MTU Date: Wed, 7 Oct 2026 08:07:16 +0300 Message-Id: <20261007050718.926-2-narimansayed28@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261007050718.926-1-narimansayed28@gmail.com> References: <20260816043451.2547-1-narimansayed28@gmail.com> <20261007050718.926-1-narimansayed28@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=narimansayed28@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1791363224132158500 Content-Type: text/plain; charset="utf-8" Add a helper function to read the host tap device's configured MTU via SIOCGIFMTU. Since this ioctl requires a socket rather than the tap character device fd itself, a separate control socket is opened to perform the query, following the same pattern used by net/can/can_socketcan.c. This is implemented for Linux only, with stub implementations returning -1 for BSD, Solaris, and the tap-stub backend, matching the existing pattern used by tap_fd_get_ifname() and tap_fd_set_steering_ebpf() in those files. This is a preparatory patch; the function is not yet called from anywhere. Signed-off-by: Nariman Sayed Acked-by: Eugenio P=C3=A9rez --- net/tap-bsd.c | 5 +++++ net/tap-linux.c | 30 ++++++++++++++++++++++++++++++ net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap_int.h | 1 + 5 files changed, 46 insertions(+) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index c39daf9385..17cedccf9e 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -264,6 +264,11 @@ int tap_fd_get_ifname(int fd, char *ifname) return -1; } =20 +int tap_fd_get_mtu(int fd) +{ + return -1; +} + int tap_fd_set_steering_ebpf(int fd, int prog_fd) { return -1; diff --git a/net/tap-linux.c b/net/tap-linux.c index 3cd7d26710..23a10151c1 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -34,6 +34,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/cutils.h" +#include "qemu/sockets.h" =20 #define PATH_NET_TUN "/dev/net/tun" =20 @@ -346,6 +347,35 @@ int tap_fd_get_ifname(int fd, char *ifname) return 0; } =20 +int tap_fd_get_mtu(int fd) +{ + struct ifreq ifr; + int s, ret, mtu; + + memset(&ifr, 0, sizeof(ifr)); + if (tap_fd_get_ifname(fd, ifr.ifr_name) !=3D 0) { + return -1; + } + + s =3D qemu_socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + error_report("could not create control socket: %s", + strerror(errno)); + return -1; + } + + ret =3D ioctl(s, SIOCGIFMTU, &ifr); + if (ret !=3D 0) { + error_report("SIOCGIFMTU ioctl() failed: %s", strerror(errno)); + close(s); + return -1; + } + + mtu =3D ifr.ifr_mtu; + close(s); + return mtu; +} + int tap_fd_set_steering_ebpf(int fd, int prog_fd) { if (ioctl(fd, TUNSETSTEERINGEBPF, (void *) &prog_fd) !=3D 0) { diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 8704b1084b..d3bd6e6b48 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -266,6 +266,11 @@ int tap_fd_get_ifname(int fd, char *ifname) return -1; } =20 +int tap_fd_get_mtu(int fd) +{ + return -1; +} + int tap_fd_set_steering_ebpf(int fd, int prog_fd) { return -1; diff --git a/net/tap-stub.c b/net/tap-stub.c index 6aa60d96ad..756ce882a7 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -91,6 +91,11 @@ int tap_fd_get_ifname(int fd, char *ifname) return -1; } =20 +int tap_fd_get_mtu(int fd) +{ + return -1; +} + int tap_fd_set_steering_ebpf(int fd, int prog_fd) { return -1; diff --git a/net/tap_int.h b/net/tap_int.h index dc4f484006..360d61c889 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -45,6 +45,7 @@ int tap_fd_set_vnet_be(int fd, int vnet_is_be); int tap_fd_enable(int fd); int tap_fd_disable(int fd); int tap_fd_get_ifname(int fd, char *ifname); +int tap_fd_get_mtu(int fd); int tap_fd_set_steering_ebpf(int fd, int prog_fd); =20 #endif /* NET_TAP_INT_H */ --=20 2.34.1 From nobody Mon Nov 23 05:00:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1791364352; cv=none; d=zohomail.com; s=zohoarc; b=HcwdbeZt1G6vWg79SJ48kDU9O2gCTRTmbS4bexbE6DLGPJipZYHvfbwr4Gja5UXWQRnrf1MOBPGYIppVpA+lRJ/0M1wAEkUXp4/LcmL11diiTCxW9h4vrXcQVDhHHIRcjom3ZkHOUwdahNToVukI+XfrXidc1bZPHfHjbFHqIqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791364352; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d4bLU8H9HIV8nETT9y53fkVZYcaJvtDXCM34S++tplI=; b=ISBC92Oo0maPtXGnfVQrZuVRxwOC4Z8cdxLX1gFadzJGFknT75hFyclp+WyQf8okyNVsN9jlOANmtzGA+wlt29wnnIOZaigsWlC1iaoo5nCFZSBfPj1vLQCi6YIGgrT8GPbkw+ho++8fciYLrrDQdRixxX3J1Y/TbwMJON2u7+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179136435265087.7356374125003; Wed, 7 Oct 2026 02:12:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENKX-0002cO-R1; Wed, 07 Oct 2026 04:48:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEJsz-0001cv-DS for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:08:32 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEJst-0005KH-93 for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:08:08 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4a16af2a232so11123695e9.1 for ; Tue, 06 Oct 2026 22:08:05 -0700 (PDT) Received: from DESKTOP-2SK3BJA.localdomain ([197.49.190.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a17f795f29sm33359315e9.11.2026.10.06.22.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 22:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791349684; x=1791954484; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=d4bLU8H9HIV8nETT9y53fkVZYcaJvtDXCM34S++tplI=; b=iUhtijR8bs4D9szfRqnl9A3+SJMfWBJPr5b9Vq9I6zOmZuFDRpHYbMVQGDyvjm+Yfv iSRR96AJLMnLUTmyAm2jaYXBYbsyqRjgTlp45LHGwy3ssIDFxJYPytxvHNeysbfv0R53 KwmyH3nPXqAjnHk4AJzx4sTgZpNWotIH3lWf5C1xE0U0bMLvdjZhtbQ6Vd6orhC4SnYW PJMw+fhFUH2L6FAh08XZ8yBwKfkbLwmZ0oSmh/8oijMZHNeteOY6ndO0NJZTvqYfzIcE Ndp9YkY2J/k5WNTxVmQewQ6iOn0PH1amwheAtHDLO+7HAvswqj/g4kTJuOmP5qRywG4s OE9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791349684; x=1791954484; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=d4bLU8H9HIV8nETT9y53fkVZYcaJvtDXCM34S++tplI=; b=1PTxhiqMyDGxO1JuFzW4nq8RIrXiErGpQdrDmN4kxDSd19CbokJ7ZawIgovtPGwDvb 4Dpfj5og84xGmgMV/dEJKi4gYnXNAgRDT5obqwFw1cC0DPzWP6O5qgQ+TWT4xnFmEp/G w8AahelIIeC+EMStCAEzWLF2hC9hhIA6M2bcglX9LvkYiH92+/a1kQNA7GzxM5ZhV10J EycFhH7N2f8MmkeRBnq6DABkU+e9SXKjCKXW+HBxpUkJKQ7yPaWaJT1rR0udh2wHpiWv m2MQK4XPs5saJYzSVh2a2Dgy+tz/CgCchwbd83qFKhPioEbUlWFYrsj972ZZWyeBqgE9 05jQ== X-Gm-Message-State: AFuF++lhuz81F7SKz/gjMs/mVbyaCffk9eZWKE3Mqqjq7X6F9ruAqxdx 5w6l50bie2jKwmArVAsHDkPjftroH9oFKZzDeE1vmzcaOAFDS1dlsBxe/gdGiyvTrms= X-Gm-Gg: AYBFou3p5z0CphFjaC3x84PE9sB+BfM4DOQ1zH8tGKPs3RqE2kZ9YRT+hLWbkf1rQks zi6RrRi4G2AQ4K9/e6Ap4qDOU7GlHyIhk9Y5UOLH+NkCQoomwvXCR/N5SryGCsWYATmtsOSLYa+ wSXZjgbeB6uDy402cX7hzkLhy+V0D0O9JlCb86S1vIZw7so40RWRB3D7qgO+i2vdfcUf1Z863Ct k392dbnofy+Kfk/F+GAy3j2O4/nIjiMXhxB8WAhvGxK0xXzcOoAnQiVOMBDCYFRn2uHzO6bZvNV lR7PzjL83ahmk6EhJ9yCN1dhhq3SLsR4CdZIcnCRBINw6pVg45rtIw1ndkgIKf8K+uBg3F8wHvc Xm2hvIWbpu3dJmxKQomTyimNv+rLy9rEoMss2GVLnCn4mNSbGHB8P2Sy5cm4K0GQaI115RkDimL YytdYljMGdIh3GnWwcdiv6iszbeYSIA7bX/Ch7UxJ3eif0AZo4DD2teP+9enIi3QjyzX1ri5rNK Ee1vOxIl5gF9CIHr8LYHfKl X-Received: by 2002:a05:600c:810a:b0:49f:f0bd:1e40 with SMTP id 5b1f17b1804b1-4a1804557b3mr10459915e9.23.1791349684286; Tue, 06 Oct 2026 22:08:04 -0700 (PDT) From: Nariman Sayed To: qemu-devel@nongnu.org Cc: Jason Wang , "Michael S . Tsirkin" , Nariman Sayed , Eugenio Perez Martin Subject: [PATCH v2 2/3] net: add generic get_mtu NetClientInfo callback Date: Wed, 7 Oct 2026 08:07:17 +0300 Message-Id: <20261007050718.926-3-narimansayed28@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261007050718.926-1-narimansayed28@gmail.com> References: <20260816043451.2547-1-narimansayed28@gmail.com> <20261007050718.926-1-narimansayed28@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=narimansayed28@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1791364354354158500 Content-Type: text/plain; charset="utf-8" Add a get_mtu callback to NetClientInfo, along with a qemu_get_mtu() wrapper following the existing qemu_has_ufo()-style pattern, so that device models can query a netdev backend's host MTU generically without needing to know or check its backend type. Wire this up for the tap backend via tap_get_mtu(), which is now static and only referenced through net_tap_info.get_mtu, matching the existing pattern used by tap_has_ufo() and similar callbacks. This allows other backends (e.g. vhost-user, vhost-vdpa) to implement get_mtu in the future without requiring changes to any code that calls qemu_get_mtu(). Suggested-by: Eugenio Perez Martin Signed-off-by: Nariman Sayed Acked-by: Eugenio P=C3=A9rez --- include/net/net.h | 3 +++ net/net.c | 9 +++++++++ net/tap.c | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 9edfacf827..ed06814644 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -72,6 +72,7 @@ typedef bool (HasVnetHdr)(NetClientState *); typedef bool (HasVnetHdrLen)(NetClientState *, int); typedef void (SetOffload)(NetClientState *, const NetOffloads *); typedef int (GetVnetHdrLen)(NetClientState *); +typedef int (GetMtu)(NetClientState *); typedef void (SetVnetHdrLen)(NetClientState *, int); typedef bool (GetVnetHashSupportedTypes)(NetClientState *, uint32_t *); typedef int (SetVnetLE)(NetClientState *, bool); @@ -110,6 +111,7 @@ typedef struct NetClientInfo { SetSteeringEBPF *set_steering_ebpf; NetCheckPeerType *check_peer_type; GetVHostNet *get_vhost_net; + GetMtu *get_mtu; } NetClientInfo; =20 struct NetClientState { @@ -204,6 +206,7 @@ bool qemu_has_uso(NetClientState *nc); bool qemu_has_tunnel(NetClientState *nc); bool qemu_has_vnet_hdr(NetClientState *nc); bool qemu_has_vnet_hdr_len(NetClientState *nc, int len); +int qemu_get_mtu(NetClientState *nc); void qemu_set_offload(NetClientState *nc, const NetOffloads *ol); int qemu_get_vnet_hdr_len(NetClientState *nc); void qemu_set_vnet_hdr_len(NetClientState *nc, int len); diff --git a/net/net.c b/net/net.c index 0a30579ca4..9fb70e412a 100644 --- a/net/net.c +++ b/net/net.c @@ -514,6 +514,15 @@ bool qemu_has_ufo(NetClientState *nc) return nc->info->has_ufo(nc); } =20 +int qemu_get_mtu(NetClientState *nc) +{ + if (!nc || !nc->info->get_mtu) { + return -1; + } + + return nc->info->get_mtu(nc); +} + bool qemu_has_uso(NetClientState *nc) { if (!nc || !nc->info->has_uso) { diff --git a/net/tap.c b/net/tap.c index 57ffb09885..89cec2accd 100644 --- a/net/tap.c +++ b/net/tap.c @@ -379,6 +379,13 @@ int tap_get_fd(NetClientState *nc) return s->fd; } =20 +static int tap_get_mtu(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + return tap_fd_get_mtu(s->fd); +} + /* * tap_get_vhost_net() can return NULL if a tap net-device backend is * created with 'vhost=3Doff' option, 'vhostforce=3Doff' or no vhost or @@ -411,6 +418,7 @@ static NetClientInfo net_tap_info =3D { .set_vnet_be =3D tap_set_vnet_be, .set_steering_ebpf =3D tap_set_steering_ebpf, .get_vhost_net =3D tap_get_vhost_net, + .get_mtu =3D tap_get_mtu, }; =20 static TAPState *net_tap_fd_init(NetClientState *peer, --=20 2.34.1 From nobody Mon Nov 23 05:00:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1791364102; cv=none; d=zohomail.com; s=zohoarc; b=IsZiwHNMzFw7zWG9BQ6VchDbidJVMtJE4k4lVOz8DwIKPbZoM37F7pOimfW5E/lW3HtItGkngPujglXTNFdeykO78FvH6Z4ZEmm4ZKvqD8ke4DZdqYJOu+kwLa2eEtof9XQL6tIkoNvShQmx9bPkRyFOaY2ROgP8x4aTugCvxqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791364102; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gmuD2D7dO3jWUTvhm2jqXEfMN+iA6krFRyTGqZlQEkQ=; b=lyo5XNeNO6DU8gSWHmL5NWTpzqigZj8993Kny3PKd7BV817lmXwl0V7pYs85XfUoZOZcaYRakasrinbD9/HfTugtYj3IDVLGWmfuGlP1pfn4nRJXLdS9z49P+Hk0eXtI0hGDqHNor+TJ0B8UYzviqkFaRxivdgBsfNUrsTMM1wQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791364102679356.93282696059; Wed, 7 Oct 2026 02:08:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENLE-0004FP-0h; Wed, 07 Oct 2026 04:49:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEJt1-0001cw-72 for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:08:32 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEJsu-0005KP-Fj for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:08:13 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4a16c399641so14043025e9.2 for ; Tue, 06 Oct 2026 22:08:08 -0700 (PDT) Received: from DESKTOP-2SK3BJA.localdomain ([197.49.190.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a17f795f29sm33359315e9.11.2026.10.06.22.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 22:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791349687; x=1791954487; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=gmuD2D7dO3jWUTvhm2jqXEfMN+iA6krFRyTGqZlQEkQ=; b=X0JIbb6a1QLb5ITT6tiBmWtTxkxlyjUO0R0qE3AturSku6Q6ls/PkApi/yzeIBY/TX MAKgQCWpg/nCSgkhgQaSeBYf4UW2xMzglsMsNYJ6gE+m8w5VllzvFd2oHpsW/tSB49nh +zlH1BE7nAthg89WlP8lPe/PW/ys7tPWwUz9iQjZnjobk7datP0PWI2Q5NIYoPsAj/0y jGaT4aSVbbquhQWVNqY/8567ZrGq4UvTYUrqH48xYtlZ2wvc0Cx5kcMTcE2Gp6sv/cDE tK/FF5uq/ySj833CvtxJC25n362H1bS8j8hJQhFTuRUluCDpwuDP7S0KW7C9mgb4yUE0 iE6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791349687; x=1791954487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=gmuD2D7dO3jWUTvhm2jqXEfMN+iA6krFRyTGqZlQEkQ=; b=JNk1ioh8yI5yi15pqcSEnLSh12b3TCtM/pIO+p+F//5NuZ0Ume4EQYP/flu7u/MCbE i9gMQAP0CHCtvrUrC9dG6GqjkEMOJuNOZGOGNrCrHdp02c93bJ0j+MC737jshK6GGtYB j9UwM0A/AhYTHoCvuUGyJTtIxsCCcQEqYBi4ctpPzjlFhJjDAIYlYivGiVr7mndLUqqz 6W9BFbPIwWKyVNT4LuaMrHL2ROaqXcrz2j5UlwSDcR0RQEEH7gcpw3CuWrOCugkqImSs ZhWmRATvIgXfpVqhQKS3msak78z7p0iqKHKWABx2lCYKDzNXg/hXE/2+ul8PfXQRO9Wl biEA== X-Gm-Message-State: AFuF++lVtedEc4gEndxk1gmNEHXZiw6eQNaLvOqCggysCHEH3SJ4jBEz q2p/b51JpmqPkn4OL90WdRH+ziD11gkJ4uusuaXcivoaaMwQGCvah7RUHnvX/9T0lGQ= X-Gm-Gg: AYBFou0LbbbuKuJq/y2FRxIUPhelXbeiikuo4I5j+gSCgWkZMveEyeF20Zs49LqV3ib R2DQkT2ZQR5Y0pbQTtmRL41kBB3PW3z+sADANTv/j3+c+HEoM/KX8VJYQNwtwZxHahgKG+yBGwu Kq5+5Lh4DKQOr1vJlfmMyVA/rPf0NhTiZuvn/UUCEF9w/JxXUOKpiHI3E0unJt+0lG/1HyUsngj B9RNDxZS8gHyVXbxNgCmlour2PXbkp7Ua8Ri/CECZFozv4vl78WZGn6KD6jLq3L1/WvaryyNPEN Rlhi+1ObanGUSOrGD0GZosLCI0Vlq9AtqXyBQqa7ctwTqydSFz5HbTczUCDDlyytUHGLqMx07ky 1OT2hDQxUIhqYos0+kRbyYcGpizb8TBxrosEeEiXUc/lvqWYs1IncotiOJ4yzy9JqtuzwjCIUJ7 B/XkOCsQ37jbKhlzhVdqYUgN+I9ccsB0JPm3ZfGWwd9ya+ZW/EhnMjInmUAhZuXmjfD//2VMjFo IHidRf6XPBPpTfSuF+HJzKx X-Received: by 2002:a05:600c:83c4:b0:4a1:7cf8:5433 with SMTP id 5b1f17b1804b1-4a1800d3d44mr12300545e9.3.1791349686951; Tue, 06 Oct 2026 22:08:06 -0700 (PDT) From: Nariman Sayed To: qemu-devel@nongnu.org Cc: Jason Wang , "Michael S . Tsirkin" , Nariman Sayed , Aniket Sahu Subject: [PATCH v2 3/3] virtio-net: add mtu-from-tap property for automatic MTU detection Date: Wed, 7 Oct 2026 08:07:18 +0300 Message-Id: <20261007050718.926-4-narimansayed28@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261007050718.926-1-narimansayed28@gmail.com> References: <20260816043451.2547-1-narimansayed28@gmail.com> <20261007050718.926-1-narimansayed28@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=narimansayed28@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1791364103193158500 Content-Type: text/plain; charset="utf-8" Currently, exposing the host tap device's MTU to the guest via VIRTIO_NET_F_MTU requires manually specifying host_mtu=3D on the virtio-net-pci device, duplicating the MTU already configured on the host's tap interface. Add a new mtu-from-tap boolean property (default off, preserving existing behavior). When enabled, the netdev peer's MTU is queried via the generic qemu_get_mtu() and used to set net_conf.mtu and enable VIRTIO_NET_F_MTU, regardless of the backend's type. This detection must happen in virtio_net_device_realize(), before virtio_net_set_config_size() computes the virtio config space size from host_features. Performing the detection later (e.g. in the get_features_ex() callback, which runs after the NIC and its config space are already sized) results in the mtu config field falling outside the sized config space, and the guest reading back an unmapped garbage value (0xffff) instead of the intended MTU. Since qemu_new_nic() has not yet been called at this point in realize(), the peer is accessed via n->nic_conf.peers.ncs[0] (populated during property parsing, before realize() runs, via the netdev=3D property) rather than through n->nic. Signed-off-by: Nariman Sayed Tested-by: Aniket Sahu Acked-by: Eugenio P=C3=A9rez --- hw/net/virtio-net.c | 10 ++++++++++ include/hw/virtio/virtio-net.h | 1 + 2 files changed, 11 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 814b99a43d..89fb3bad10 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3901,6 +3901,15 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) n->host_features |=3D (1ULL << VIRTIO_NET_F_MTU); } =20 + if (n->net_conf.mtu_from_tap) { + NetClientState *peer =3D n->nic_conf.peers.ncs[0]; + int mtu =3D qemu_get_mtu(peer); + if (mtu > 0) { + n->net_conf.mtu =3D mtu; + n->host_features |=3D (1ULL << VIRTIO_NET_F_MTU); + } + } + if (n->net_conf.duplex_str) { if (strncmp(n->net_conf.duplex_str, "half", 5) =3D=3D 0) { n->net_conf.duplex =3D DUPLEX_HALF; @@ -4275,6 +4284,7 @@ static const Property virtio_net_properties[] =3D { DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size, VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE), DEFINE_PROP_UINT16("host_mtu", VirtIONet, net_conf.mtu, 0), + DEFINE_PROP_BOOL("mtu-from-tap", VirtIONet, net_conf.mtu_from_tap, fal= se), DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN), DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str), DEFINE_PROP_BOOL("failover", VirtIONet, failover, false), diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 371e376428..11044b6d27 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -52,6 +52,7 @@ typedef struct virtio_net_conf uint16_t rx_queue_size; uint16_t tx_queue_size; uint16_t mtu; + bool mtu_from_tap; int32_t speed; char *duplex_str; uint8_t duplex; --=20 2.34.1