From nobody Sun May 5 14:36:35 2024 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=1638460659; cv=none; d=zohomail.com; s=zohoarc; b=BvEkKgBI7D80HBAazafjnB3ZOMmATEIJGyoGMfXWWbJRWbZRxyncGxcLC3zGsRLlT72mGZQ2WMTu8ncOhwc/rJVsa/+q9puw23854SaTXFzlD/zxPupQ7p22v4U3HuN7TNb4JH5w5Q1+qbOI+vklKRkQ6mr7fWEu8Ml2dF7rT9g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638460659; 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=dIXbBorUpM5a7MhvAJmcXPxIdQSHgf2PjjGmnoboFto=; b=mF+sEl47YoPvLIje/9JL0TZGoLaicNFRdCFdAbG+uIunaa12d/755g9pomjpFchZ6rEdH8eZZsjpx32+j1BST+4RjGOrUH7YOIRUhH921zzXlQeqgu5V6b0Nb4ggzxdI72zBQz3IyWWQix5KT8woHhEdO+be0KmfLxeJgNI4J+s= 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 1638460659544917.6309757791113; Thu, 2 Dec 2021 07:57:39 -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-509-dAdfzS9_MdeJXwOC3TS12g-1; Thu, 02 Dec 2021 10:57:36 -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 4687383DD20; Thu, 2 Dec 2021 15:57:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B9FC660843; Thu, 2 Dec 2021 15:57:29 +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 9286F4BB7C; Thu, 2 Dec 2021 15:57:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2FvPAW006059 for ; Thu, 2 Dec 2021 10:57:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 395D610023B8; Thu, 2 Dec 2021 15:57:25 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F9C7101E589 for ; Thu, 2 Dec 2021 15:56:52 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id EAB79240207; Thu, 2 Dec 2021 16:56:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638460658; 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=dIXbBorUpM5a7MhvAJmcXPxIdQSHgf2PjjGmnoboFto=; b=feskiURR0hm9RQGd67SVMxxkTrh2DddHqMYGH4Urtc252a7/s6QUPsqeWH2o8i0q/8F3XJ m6Q1Tvz6rEeZGZvU7ytGXcCce13Bk08p82MrWqn2BIb5yDU2jt1wSeac7kDF67Zs75MT3H Z3wSd4IxuT2RGdgy9PLFhqk5edOPC6E= X-MC-Unique: dAdfzS9_MdeJXwOC3TS12g-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH] qemu: Enable unprivileged userfaultfd for post-copy migration Date: Thu, 2 Dec 2021 16:56:49 +0100 Message-Id: <8815ca4f94c2e713e4b4b2cf1c8bf751f5b2da65.1638460609.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1638460660487100001 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 before starting post-copy migration. Rather than providing a static sysctl configuration file, we set the sysctl knob in runtime once post-copy migration is requested. This way unprivileged_userfaultfd is only enabled once actually used. https://bugzilla.redhat.com/show_bug.cgi?id=3D1945420 Signed-off-by: Jiri Denemark Reviewed-by: Michal Privoznik --- src/qemu/qemu_migration_params.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_par= ams.c index dbc3219826..a9449ed1ff 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -804,6 +804,24 @@ qemuMigrationCapsToJSON(virBitmap *caps, } =20 =20 +static void +qemuMigrationParamsEnableUserfaultfd(virDomainObj *vm) +{ + const char *sysctl =3D "/proc/sys/vm/unprivileged_userfaultfd"; + + if (!virFileExists(sysctl)) + return; + + VIR_DEBUG("Enabling unprivileged userfaultfd for post-copy migration o= f " + "domain %s", vm->def->name); + + if (virFileWriteStr(sysctl, "1", 0) < 0) { + virReportSystemError(errno, "%s", + _("failed to enable unprivileged userfaultfd"= )); + } +} + + /** * qemuMigrationParamsApply * @driver: qemu driver @@ -839,6 +857,13 @@ qemuMigrationParamsApply(virQEMUDriver *driver, goto cleanup; } } else { + /* userfaultfd may only be enabled for privileged processes by def= ault, + * we need to make sure QEMU can use it before enabling post-copy + * migration */ + if (virBitmapIsBitSet(priv->migrationCaps, QEMU_MIGRATION_CAP_POST= COPY) && + virBitmapIsBitSet(migParams->caps, QEMU_MIGRATION_CAP_POSTCOPY= )) + qemuMigrationParamsEnableUserfaultfd(vm); + if (!(caps =3D qemuMigrationCapsToJSON(priv->migrationCaps, migPar= ams->caps))) goto cleanup; =20 --=20 2.34.1