From nobody Sun Feb 8 18:35:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 16372251308964.184417545482916; Thu, 18 Nov 2021 00:45:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-440-m0wrTfArOyCrw1puhjtmNg-1; Thu, 18 Nov 2021 03:45:27 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C027915721; Thu, 18 Nov 2021 08:45:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78E625BB12; Thu, 18 Nov 2021 08:45:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 93E18181A1D1; Thu, 18 Nov 2021 08:45:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1AI8hcvH013314 for ; Thu, 18 Nov 2021 03:43:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8A5082026D46; Thu, 18 Nov 2021 08:43:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 85B5D2026D64 for ; Thu, 18 Nov 2021 08:43:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7A428011A5 for ; Thu, 18 Nov 2021 08:43:34 +0000 (UTC) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-40-OjyOvf0KONegYHJtXIUiEQ-1; Thu, 18 Nov 2021 03:43:33 -0500 Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 3AA1C40019 for ; Thu, 18 Nov 2021 08:43:30 +0000 (UTC) Received: by mail-lf1-f71.google.com with SMTP id i1-20020a056512318100b003ffd4e89eb9so3479402lfe.19 for ; Thu, 18 Nov 2021 00:43:30 -0800 (PST) Received: from ws.lan.d-node.is ([95.165.29.203]) by smtp.gmail.com with ESMTPSA id t12sm243207ljg.63.2021.11.18.00.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 00:43:29 -0800 (PST) X-MC-Unique: m0wrTfArOyCrw1puhjtmNg-1 X-MC-Unique: OjyOvf0KONegYHJtXIUiEQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=maz0IKkc8Y50bGR2qZunjNv45wSUneVR8Cj8pHVa0N0=; b=PISuEE8s4UIwhZMhtBnyJoRD1p5O7y/VFG7A+8mfGQVMR4g+AcxDJdi2LkOka+qvvg tBV6kbe7jziXhcDgNyUiadv+HLSdKjcJChs/ImGJtryGTRdmPa3TR3uc/RgSZDJMjHSG 8leRkl4GhGw1yc0t0dxUCnD2er/MskqT9/+3FcWg2htzMWX7AKDY9l2RaSf5EQ1uDKPm NQ+qbQlNaF3EwEvOC3z3V/nrCgDesHnCB/LpMcUuVj4ORFSBklnwg6YJ6c7SSXEAqpnN UOkv1h1hISDLDn4QVcjY8BZqL1SlVK/WqEC+cGYl3wZ4hrVXLdlOMyEyQYSf0cELSVAN r3sw== X-Gm-Message-State: AOAM5323MazYT1V0aLt/sRd11cmvoq59rKhU84wd+/agVryoeIpWwQ3C EniRvLjHcn/ctMJdF0gN0325NDrQhGlEkxOFSvlI8wvEGYqkWoBjimOMSEOQoi3gsdg6H+ah+io 0MAloztRgqv0KrKkcoEXSg3epOQi1fYRiJg== X-Received: by 2002:a2e:1646:: with SMTP id 6mr15269593ljw.492.1637225009600; Thu, 18 Nov 2021 00:43:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7j91ykvVEEkJNisGbE66VQNCXDP9coqPezyMXgV5NQs9sgNO5YSWLsX/vdtupAQzEylJshg== X-Received: by 2002:a2e:1646:: with SMTP id 6mr15269570ljw.492.1637225009398; Thu, 18 Nov 2021 00:43:29 -0800 (PST) From: Dmitrii Shcherbakov To: dmitrii.shcherbakov@canonical.com, libvir-list@redhat.com Subject: [libvirt PATCH v5 3/3] Ignore EPERM on implicit clearing of VF VLAN ID Date: Thu, 18 Nov 2021 11:43:26 +0300 Message-Id: <20211118084326.29204-4-dmitrii.shcherbakov@canonical.com> In-Reply-To: <20211118084326.29204-1-dmitrii.shcherbakov@canonical.com> References: <20211118084326.29204-1-dmitrii.shcherbakov@canonical.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1AI8hcvH013314 X-loop: libvir-list@redhat.com Cc: laine@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1637225131818100001 Content-Type: text/plain; charset="utf-8" SmartNIC DPUs may not expose some privileged eswitch operations to the hypervisor hosts. For example, this happens with Bluefield devices running in the ECPF (default) mode for security reasons. While VF MAC address programming is possible via an RTM_SETLINK operation, trying to set a VLAN ID in the same operation will fail with EPERM. The equivalent ip link commands below provide an illustration: 1. This works: sudo ip link set enp130s0f0 vf 2 mac de:ad:be:ef:ca:fe 2. Setting (or clearing) a VLAN fails with EPERM: sudo ip link set enp130s0f0 vf 2 vlan 0 RTNETLINK answers: Operation not permitted 3. This is what Libvirt attempts to do today (when trying to clear a VF VLAN at the same time as programming a VF MAC). sudo ip link set enp130s0f0 vf 2 vlan 0 mac de:ad:be:ef:ca:fe RTNETLINK answers: Operation not permitted If setting an explicit VLAN ID results in an EPERM, clearing a VLAN (setting a VLAN ID to 0) can be handled gracefully by ignoring the EPERM error with the rationale being that if we cannot set this state in the first place, we cannot clear it either. In order to keep explicit clearing of VLAN ID working as it used to be passing a NULL pointer for VLAN ID is used. Signed-off-by: Dmitrii Shcherbakov --- NEWS.rst | 15 +++++++++++++++ src/util/virnetdev.c | 11 ++++++++++- tests/virnetdevtest.c | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index a71b84c363..f12f8deea1 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -30,6 +30,21 @@ v7.10.0 (unreleased) Libvirt is now able to report interface information from the guest's perspective (using guest agent). =20 + * virnetdev: Ignore EPERM on implicit clearing of VF VLAN ID + + Libvirt will now ignore EPERM errors on attempts to implicitly clear a + VLAN ID (when a VLAN is not explicitly provided via an interface XML + using a 0 or a non-zero value) as SmartNIC DPUs do not expose VLAN + programming capabilities to the hypervisor host. This allows Libvirt + clients to avoid specifying a VLAN and expect VF configuration to work + since Libvirt tries to clear a VLAN in the same operation + as setting a MAC address for VIR_DOMAIN_NET_TYPE_HOSTDEV devices which + is now split into two distinct operations. EPERM errors received while + trying to program a non-zero VLAN ID or explicitly program a VLAN ID 0 + will still cause errors as before so there is no change in behavior + in those cases. + + * **Bug fixes** =20 =20 diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index cee23e1a0c..e7679d0189 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1631,12 +1631,21 @@ virNetDevSetVfVlan(const char *ifname, int vf, cons= t int *vlanid) requestError =3D virNetDevSendVfSetLinkRequest(ifname, IFLA_VF_VLAN, &ifla_vf_vlan, sizeof(ifl= a_vf_vlan)); =20 - if (requestError) { + /* If vlanid is NULL - we are attempting to implicitly clear an existi= ng VLAN id. + * An EPERM received at this stage is an indicator that the embedded + * switch is not exposed to this host and the network driver is not + * able to set a VLAN for a VF, whereas the Libvirt client has not + * explicitly configured a VLAN or requested it to be cleared via vid = 0. */ + if (requestError =3D=3D -EPERM && vlanid =3D=3D NULL) { + rc =3D 0; + } else if (requestError) { virReportSystemError(-requestError, _("Cannot set interface vlanid to %d " "for ifname %s vf %d"), ifla_vf_vlan.vlan, ifname ? ifname : "(unspec= ified)", vf); rc =3D requestError; + } else { + rc =3D 0; } VIR_DEBUG("RTM_SETLINK %s vf %d vlanid=3D%d - %s", ifname, vf, diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c index 5a787fa0f1..f969898b94 100644 --- a/tests/virnetdevtest.c +++ b/tests/virnetdevtest.c @@ -234,7 +234,7 @@ testVirNetDevSetVfVlan(const void *opaque G_GNUC_UNUSED) }; =20 const struct nullVlanTestCase nullVLANTestCases[] =3D { - { .ifname =3D "fakeiface-eperm", .vf_num =3D 1, .rc =3D -EPERM }, + { .ifname =3D "fakeiface-eperm", .vf_num =3D 1, .rc =3D 0 }, { .ifname =3D "fakeiface-eagain", .vf_num =3D 1, .rc =3D -EAGAIN }, /* Successful requests with vlan id 0 need to have a zero return c= ode. */ { .ifname =3D "fakeiface-ok", .vf_num =3D 1, .rc =3D 0 }, --=20 2.32.0