From nobody Sun May 5 04:32:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1599222217; cv=none; d=zohomail.com; s=zohoarc; b=Vzfi+o0ejvBur818+piLFwIU8lpr4LyJA0TqOUnhz2v+YCDoEmK6UiZaBnJlvzAG18cqxP7gNCJsImd3UlFeiZXOP2YWvL0O6LQ2Oh8fb4P4icVP4cm65QKSWjEqDFFZlgiFVAOdLgt7KkhukOvnamyZcntj4QNWqqwreyE5L6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599222217; 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=P+LJdlgL+vWXexiIe7bIV1X+ZGtvSBu6FW/o7AaiYYc=; b=JPbA2R1R42sTYwkd3k8v8bTGOKKrnxMttzsyKkOYUqHxeEuIe+oNjA4nX2SeQzA0FzSuqbzX5LYo2jCmTzOxKIK8i7Khd15raK+q8I+r+T2GVL1SjPXh+XwuLRH+Li3/iYuiD6R19yXZj/W+L1fxRnhHN6yCsIQGDsHbwC31Nms= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599222217377214.5197532391295; Fri, 4 Sep 2020 05:23:37 -0700 (PDT) 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-297-_OICJxt3Mbe7WMMlsL9FZg-1; Fri, 04 Sep 2020 08:23:34 -0400 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 50ACF80B73A; Fri, 4 Sep 2020 12:23:27 +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 19C2D805D2; Fri, 4 Sep 2020 12:23:27 +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 0BAD818561B3; Fri, 4 Sep 2020 12:23:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 084CMZ87029430 for ; Fri, 4 Sep 2020 08:22:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1FD3F7EEDC; Fri, 4 Sep 2020 12:22:35 +0000 (UTC) Received: from carol.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 088627EEB5; Fri, 4 Sep 2020 12:22:32 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id C3EABC200C1; Fri, 4 Sep 2020 14:22:30 +0200 (CEST) X-MC-Unique: _OICJxt3Mbe7WMMlsL9FZg-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [PATCH] qemu: Do not error out when setting affinity failed Date: Fri, 4 Sep 2020 14:22:14 +0200 Message-Id: <8d147bfcdfe9bc871d07d52aef28ef9de285c151.1599222134.git.mkletzan@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable At least in a particular scenario described in the code. Basically when libvirtd is running without CAP_SYS_NICE (e.g. in a container) and it is tr= ying to set QEMU affinity to all CPUs (because there is no setting requested in = the XML) it fails. But if we ignore the failure in this particular case than y= ou can limit the CPUs used by controlling the affinity for libvirtd itself. In any other case (anything requested in the XML, pinning a live domain, et= c.) the call is still considered fatal and the action errors out. Resolves: https://bugzilla.redhat.com/1819801 Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Martin Kletzander Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index cfe09d632633..270bb37d3682 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2528,6 +2528,7 @@ qemuProcessGetAllCpuAffinity(virBitmapPtr *cpumapRet) static int qemuProcessInitCpuAffinity(virDomainObjPtr vm) { + bool settingAll =3D false; g_autoptr(virBitmap) cpumapToSet =3D NULL; virDomainNumatuneMemMode mem_mode; qemuDomainObjPrivatePtr priv =3D vm->privateData; @@ -2566,13 +2567,30 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) if (!(cpumapToSet =3D virBitmapNewCopy(vm->def->cputune.emulatorpi= n))) return -1; } else { + settingAll =3D true; if (qemuProcessGetAllCpuAffinity(&cpumapToSet) < 0) return -1; } =20 if (cpumapToSet && virProcessSetAffinity(vm->pid, cpumapToSet) < 0) { - return -1; + /* + * We only want to error out if we failed to set the affinity to + * user-requested mapping. If we are just trying to reset the aff= inity + * to all CPUs and this fails it can only be an issue if: + * 1) libvirtd does not have CAP_SYS_NICE + * 2) libvirtd does not run on all CPUs + * + * However since this scenario is very improbable, we rather skip + * reporting the error because it helps running libvirtd in a a sc= enario + * where pinning is handled by someone else. + * + * See also: https://bugzilla.redhat.com/1819801#c2 + */ + if (settingAll) + virResetLastError(); + else + return -1; } =20 return 0; @@ -2726,8 +2744,25 @@ qemuProcessSetupPid(virDomainObjPtr vm, affinity_cpumask =3D use_cpumask; =20 /* Setup legacy affinity. */ - if (affinity_cpumask && virProcessSetAffinity(pid, affinity_cpumask) <= 0) - goto cleanup; + if (affinity_cpumask && virProcessSetAffinity(pid, affinity_cpumask) <= 0) { + /* + * We only want to error out if we failed to set the affinity to + * user-requested mapping. If we are just trying to reset the aff= inity + * to all CPUs and this fails it can only be an issue if: + * 1) libvirtd does not have CAP_SYS_NICE + * 2) libvirtd does not run on all CPUs + * + * However since this scenario is very improbable, we rather skip + * reporting the error because it helps running libvirtd in a a sc= enario + * where pinning is handled by someone else. + * + * See also: https://bugzilla.redhat.com/1819801#c2 + */ + if (affinity_cpumask =3D=3D hostcpumap) + virResetLastError(); + else + goto cleanup; + } =20 /* Set scheduler type and priority, but not for the main thread. */ if (sched && --=20 2.28.0