From nobody Tue May 7 22:58:06 2024 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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=1638885678; cv=none; d=zohomail.com; s=zohoarc; b=SbSp84kOffho3vcP/GmQK/jdenr5QxdqIyH25QLal+OxUtpAjsFj6fEaT9BOVDQHZW8ucf7NhNNGxgwFJI19GZgX94Cg2lvPvCA6UB2dE2dUrV9paIXy77wLVhyhnxLdDAtj0dGaDwlaFnZuPPHg5cBJePcfeq1h563lfxcUGU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638885678; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=RibhbQiIvgJuIIci9o7su7j0uNBxU3WutTDuuidOp1g=; b=LD7nyfGb+gzHn7XMHnnOaOAAWVSkB2tnlWPfv1jx8wdh7qHRar/tpaMzvS7iXMQcia9XxN6EDXyUUSP9BvLstmrOq+K4fijKIuoRAdwDL6EUg752Sa1FSe23GQ93wWJYe6BvsIaKpq0AXBDpxFLneTcwafiRvX2/DAk3EaW94AQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1638885678363758.6977690520913; Tue, 7 Dec 2021 06:01:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-278-WmnrojyhPreWerGTuFfsOg-1; Tue, 07 Dec 2021 09:01:13 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A758F100D698; Tue, 7 Dec 2021 14:00:42 +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 D9E7C5D6CF; Tue, 7 Dec 2021 14:00:40 +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 88A9D180B617; Tue, 7 Dec 2021 14:00:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B7E0ZLR013199 for ; Tue, 7 Dec 2021 09:00:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 50FDF5D9C0; Tue, 7 Dec 2021 14:00:35 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 268725DF34 for ; Tue, 7 Dec 2021 14:00:35 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id C185C243CC3; Tue, 7 Dec 2021 15:00:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638885677; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RibhbQiIvgJuIIci9o7su7j0uNBxU3WutTDuuidOp1g=; b=NNRepbSHTzi0FgVzjncsPuka0u9iJawnA+Bnqg0FskanwIxjo1ZvYZx+JM0xipBl14A2Sh Nc2ggH83vd2qE45N0cjSUFS8HZBHCGgcwk8EemosQ9BLfpUZUPl+PpTItwnuDAmhxjJPv+ nJD1dmon/DzJiWpnlodhIh35W5ZL9UU= X-MC-Unique: WmnrojyhPreWerGTuFfsOg-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH v3] qemu: Enable unprivileged userfaultfd for post-copy migration Date: Tue, 7 Dec 2021 15:00:31 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@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.15 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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1638885711556100001 Content-Type: text/plain; charset="utf-8" Userfaultfd is by default allowed only for privileged processes. Since libvirt runs QEMU unprivileged, we need to enable unprivileged access to userfaultfd to enable post-copy migration. https://bugzilla.redhat.com/show_bug.cgi?id=3D1945420 Signed-off-by: Jiri Denemark Reviewed-by: Daniel P. Berrang=C3=A9 --- Notes: If you wonder about the 60-* prefix of the installed sysctl file, we al= ready install 60-libvirtd.conf so I think it makes sense to use the same pref= ix for all sysctl configuration installed by libvirt. =20 Version 2: - setting unprivileged_userfaultfd only when it is not already enabled - virReportSystemError replaced with VIR_WARN =20 Version 3: - set the knob via a sysctl conf file instead libvirt.spec.in | 1 + src/qemu/meson.build | 8 ++++++++ src/qemu/postcopy-migration.sysctl | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 src/qemu/postcopy-migration.sysctl diff --git a/libvirt.spec.in b/libvirt.spec.in index 5a079cdaf3..3aa4cc75b5 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1859,6 +1859,7 @@ exit 0 %files daemon-driver-qemu %config(noreplace) %{_sysconfdir}/sysconfig/virtqemud %config(noreplace) %{_sysconfdir}/libvirt/virtqemud.conf +%config(noreplace) %{_prefix}/lib/sysctl.d/60-qemu-postcopy-migration.conf %{_datadir}/augeas/lenses/virtqemud.aug %{_datadir}/augeas/lenses/tests/test_virtqemud.aug %{_unitdir}/virtqemud.service diff --git a/src/qemu/meson.build b/src/qemu/meson.build index 3898d23877..66ef594006 100644 --- a/src/qemu/meson.build +++ b/src/qemu/meson.build @@ -170,6 +170,14 @@ if conf.has('WITH_QEMU') 'file': files('virtqemud.sysconf'), } =20 + if conf.has('WITH_SYSCTL') + install_data( + 'postcopy-migration.sysctl', + install_dir: prefix / 'lib' / 'sysctl.d', + rename: [ '60-qemu-postcopy-migration.conf' ], + ) + endif + virt_install_dirs +=3D [ localstatedir / 'lib' / 'libvirt' / 'qemu', runstatedir / 'libvirt' / 'qemu', diff --git a/src/qemu/postcopy-migration.sysctl b/src/qemu/postcopy-migrati= on.sysctl new file mode 100644 index 0000000000..aa8f015ae0 --- /dev/null +++ b/src/qemu/postcopy-migration.sysctl @@ -0,0 +1,6 @@ +# This is needed to support post-copy migration for QEMU run by libvirt, +# i.e., unprivileged, as userfaultfd is by default only available to +# privileged processes. +# It can be safely overridden by a file in /etc/sysctl.d/ in case post-copy +# migration is not used on the host. +vm.unprivileged_userfaultfd =3D 1 --=20 2.34.1