From patchwork Tue Oct 15 16:01:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 176382 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6109707ill; Tue, 15 Oct 2019 09:05:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzA51hlFLdS5HNDtLgJtDmQjACly2wYIC0yB0Exf3vbqxlChV2QmzQ3n2N6CUji8105VYZF X-Received: by 2002:a92:da47:: with SMTP id p7mr7008408ilq.166.1571155518995; Tue, 15 Oct 2019 09:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571155518; cv=none; d=google.com; s=arc-20160816; b=rc4h6LKHJJbCmesRiREaqsJ+xEEJh6aqskEeJT+X9BTUGu4DbcL//oyk+GRmwCfE63 CTihVULQirh6V5lEBWMDfXfptHJBHKSA5+nYlZ36makSGQ/u6PCb0zRX4KzHvxYw+wxn rCFm6co0NMLCZUJ/mYBnlkjj4bYIp5qoOpwkr70fLRHir01HcHfPBogF9clMQ/dSJDeV MMFsdHa3ms328ukUNoRvhwHsnpAEYuAWR9Qy8+F4rdpwEb+xyevF1ntjPE+WmiyWsWwc 16g8QM2T9KYxbSAYvr9LbhR8WwaeXUWY3ew3GTTcHOR4JgmOOraFFzNFI4WfBJ0dgnO3 bfJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:message-id:date:to:from:delivered-to; bh=YGJ83AQ96AqO1i+Q+x40AR85vJ/WALvPMV75xhfyTsQ=; b=mMTFOd+NU+FVuHM8KBy1ifbSdYAGiZ+cWuS/Ql2pbe18cLUOUlO5Rk09MV8hzADeOY oYKj0THqr/cuEGUMGC6X4/GVvDXTk1oyeqxRov/r9/mfnhMQdBzPAa142Bt7N4zCHj/W 3dHnuNar8HmFvew8KOGHhNLwUQAhrddpGowHIoG/u2BjCJU5rCLCak20RsPgkW8IH6at zUhB+BJ579qVDelX2c9K9+w/ccevKGQpSVWfkPXIn/wznL5ZlGH2g6bG6n3J/+FafjyK 7PIHqeDg5DJGHoS9Iece4Ru2SAJj9OYinrUgggPbTbMot0bxVyZAtrlVDAz76NzAYQRY GEOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id r26si33147581ioj.66.2019.10.15.09.05.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Oct 2019 09:05:18 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3A7C3082E42; Tue, 15 Oct 2019 16:05:16 +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 14F1360BE2; Tue, 15 Oct 2019 16:05:16 +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 69F824E58A; Tue, 15 Oct 2019 16:05:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FG19u0028387 for ; Tue, 15 Oct 2019 12:01:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id A70F5194BB; Tue, 15 Oct 2019 16:01:09 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.bos.redhat.com (dhcp-17-175.bos.redhat.com [10.18.17.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36E4119C58; Tue, 15 Oct 2019 16:01:06 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 15 Oct 2019 12:01:38 -0400 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Jonathon Jongsma Subject: [libvirt] [PATCH] qemu: caps: Use unique key for domCaps caching 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 15 Oct 2019 16:05:17 +0000 (UTC) When searching qemuCaps->domCapsCache for existing domCaps data, we check for a matching pair of arch+virttype+machine+emulator. However for the hash table key we only use the machine string. So if the cache already contains: x86_64 + kvm + pc + /usr/bin/qemu-kvm But a new VM is defined with x86_64 + qemu + pc + /usr/bin/qemu-kvm We correctly fail to find matching cached domCaps, but then attempt to use a colliding key with virHashAddEntry Fix this by building a hash key from the 4 values, not just machine Signed-off-by: Cole Robinson --- qemu_domain.c validation should be affected, but it is covered up by another bug, fixed here: https://www.redhat.com/archives/libvir-list/2019-October/msg00708.html src/qemu/qemu_conf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) -- 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Reviewed-by: Daniel Henrique Barboza Reviewed-by: Jonathon Jongsma diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 08cd784054..64ac8cbdd3 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1396,6 +1396,8 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver, domCaps = virHashSearch(domCapsCache, virQEMUDriverSearchDomcaps, &data, NULL); if (!domCaps) { + VIR_AUTOFREE(char *) key = NULL; + /* hash miss, build new domcaps */ if (!(domCaps = virDomainCapsNew(data.path, data.machine, data.arch, data.virttype))) @@ -1406,7 +1408,14 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver, cfg->firmwares, cfg->nfirmwares) < 0) return NULL; - if (virHashAddEntry(domCapsCache, machine, domCaps) < 0) + if (virAsprintf(&key, "%d:%d:%s:%s", + data.arch, + data.virttype, + NULLSTR(data.machine), + NULLSTR(data.path)) < 0) + return NULL; + + if (virHashAddEntry(domCapsCache, key, domCaps) < 0) return NULL; }