From nobody Mon Feb 9 03:00:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662990487; cv=none; d=zohomail.com; s=zohoarc; b=c2u1p7Kk+/YTOSolGdytnSb8IWTd/vtDkivOl5RxIOrnOvnHTdXMkAqXn/0z+U7tWkikXw3qRS0MUQoKVAadjZfZqWxb89Iz3pVo3yBiqHwHIBLoZeA8aB5/eF2uXS6JkwwbSVuxCu7w6MDnXf+y5Kl4GHcQW4BGJLUcvejSXlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662990487; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tGSDjBSrlbU0yJBcq8i4pL/FnKWk+Xe3S0Uz9IwDZiY=; b=ghGH95ecnHfYLDm2LLUw7buB6C0942589AdHC8W6ve1eMSoP6fc4JwougFoeqxdnp0tDRsQLAhfRO2FBxdWb8cA+94q3bAtCyq86FPe1QlKBCcaMtbW5VP24Ik4e6fUREs+KjtyeRJE6NOxIk78SzYZRH47tB7Ljy8UOBpz41yk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662990487053386.55645226810634; Mon, 12 Sep 2022 06:48:07 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-479-m6dVnOFFNAqP_e87x4Urng-1; Mon, 12 Sep 2022 09:47:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EBD3C29AB45A; Mon, 12 Sep 2022 13:47:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D865440C6EC3; Mon, 12 Sep 2022 13:47:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C12E01946A4A; Mon, 12 Sep 2022 13:47:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C54A21946A48 for ; Mon, 12 Sep 2022 13:46:51 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B12A040C6EC4; Mon, 12 Sep 2022 13:46:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28E2540C6EC2 for ; Mon, 12 Sep 2022 13:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662990486; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tGSDjBSrlbU0yJBcq8i4pL/FnKWk+Xe3S0Uz9IwDZiY=; b=UDeqKnP0R31EFp01s5T8KrNP5Mj6D9Aj49gzfSk3Uw+w4tuPZ1yuBGD0aO4Ki0YkfCQ9QN KnZbv8awosPiJ0YajvTJaLN1/u3mG8oJAi95L16WBfckew8dmNxrz8vOAVg8wc9W9XIPWG 2sdJODFB3TdkZLWtkhj2OCJabQEhDJ8= X-MC-Unique: m6dVnOFFNAqP_e87x4Urng-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/4] qemu_namespace: Fix a corner case in qemuDomainGetPreservedMounts() Date: Mon, 12 Sep 2022 15:46:39 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662990488523100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When setting up namespace for QEMU we look at mount points under /dev (like /dev/pts, /dev/mqueue/, etc.) because we want to preserve those (which is done by moving them to a temp location, unshare(), and then moving them back). We have a convenience helper - qemuDomainGetPreservedMounts() - that processes the mount table and (optionally) moves the other filesystems too. This helper is also used when attempting to create a path in NS, because the path, while starting with "/dev/" prefix, may actually lead to one of those filesystems that we preserved. And here comes the corner case: while we require the parent mount table to be in shared mode (equivalent of `mount --make-rshared /'), these mount events propagate iff the target path exist inside the slave mount table (=3D QEMU's private namespace). And since we create only a subset of /dev nodes, well, that assumption is not always the case. For instance, assume that a domain is already running, no hugepages were configured for it nor any hugetlbfs is mounted. Now, when a hugetlbfs is mounted into '/dev/hugepages', this is propagated into the QEMU's namespace, but since the target dir does not exist in the private /dev, the FS is not mounted in the namespace. Fortunately, this difference between namespaces is visible when comparing /proc/mounts and /proc/$PID/mounts (where PID is the QEMU's PID). Therefore, if possible we should look at the latter. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/qemu/qemu_namespace.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 71e3366ca5..807ec37c91 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -109,6 +109,8 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfig *cf= g, * b) generate backup path for all the entries in a) * * Any of the return pointers can be NULL. Both arrays are NULL-terminated. + * Get the mount table either from @vm's PID (if running), or from the + * namespace we're in (if @vm's not running). * * Returns 0 on success, -1 otherwise (with error reported) */ @@ -123,12 +125,18 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfig *cfg, size_t nmounts =3D 0; g_auto(GStrv) paths =3D NULL; g_auto(GStrv) savePaths =3D NULL; + g_autofree char *mountsPath =3D NULL; size_t i; =20 if (ndevPath) *ndevPath =3D 0; =20 - if (virFileGetMountSubtree(QEMU_PROC_MOUNTS, "/dev", &mounts, &nmounts= ) < 0) + if (vm->pid > 0) + mountsPath =3D g_strdup_printf("/proc/%lld/mounts", (long long) vm= ->pid); + else + mountsPath =3D g_strdup(QEMU_PROC_MOUNTS); + + if (virFileGetMountSubtree(mountsPath, "/dev", &mounts, &nmounts) < 0) return -1; =20 if (nmounts =3D=3D 0) --=20 2.35.1