From nobody Sun Feb 8 18:39:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165093033826395.78888547250301; Mon, 25 Apr 2022 16:45:38 -0700 (PDT) Received: from localhost ([::1]:55510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Of-00076R-3T for importer@patchew.org; Mon, 25 Apr 2022 19:45:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8ID-0006rH-OP for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:38:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:36574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IB-0007hm-GO for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:38:56 -0400 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-77-bIsJXW0sPEifw9C8oOi2fw-1; Mon, 25 Apr 2022 19:38:51 -0400 Received: by mail-io1-f70.google.com with SMTP id t1-20020a056602140100b0065393cc1dc3so12552290iov.5 for ; Mon, 25 Apr 2022 16:38:51 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4IWpV0bLKv2V8Tzv3MqkG3QZdqlBVwJmDqV3FtfObSI=; b=PE0qQdP8IYO3IvG2H0Hxi6u4h6ltuLVUvUwEoVqYaTkbdEc/oSSZq6wH1G70p3SpmdQtyL Y7JtAfQqsTwnGGjOyFV51TqmiAldor/2P7dkaPgeQ5l168JFazwN8e9yoEEzMWZf7HND4T nihC8azZ+IBrkDlfO2kKyAZBEXYtk+U= X-MC-Unique: bIsJXW0sPEifw9C8oOi2fw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4IWpV0bLKv2V8Tzv3MqkG3QZdqlBVwJmDqV3FtfObSI=; b=2MjwRC3QAzdj6LtOO0AVraJDG0uAiGxxhE3gSts+58FHVnr+GoCR7GK6i1oNYFAIbQ /v/xBeTlgh0DzvQmc6ohgqMcnYDxwA4X30AMhirJA/TZ4wDQTzemavf0yW/+5Zfv8MuX Eb3s2l98ByGevTQknTRuWFNDlCE0JDnOx1DD2IGVUooHavnD/spS/tMACr18EE6hkBUM GzfaWo4GWhpaQT4I+syUciTZPDqhh7pa3oc0epEzwBuTl/9bZXQRzVeo/YsaK1h1MfGH SHL/dfmNFuipcHtwVI506/CoOps4dMBRs+5BTDOfmsjwlEsS8WCr7ytxdwmm8rGG4EEH vN2A== X-Gm-Message-State: AOAM5311u1zvav3O+d4HqQWSGNNToQ0Yp3y68bJ+85NsoOJJtD8oG7if 9+7Lb2M3x3TDWM0ifJCPH8MC4EW/Bw3B1hjRiLpJnNuiyMlAxF+T1x4TI9a5KhT0doo/ahOlqG6 8Qe6iDvxhFNyiJUMkRAqnlQXzDu7RKs8qg7yc6wJxx8PE5eua/wmnARCnActFIHPc X-Received: by 2002:a05:6638:3183:b0:32a:7cb1:a13 with SMTP id z3-20020a056638318300b0032a7cb10a13mr8505242jak.89.1650929931104; Mon, 25 Apr 2022 16:38:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5ZAyHNGRimpeJvvw3JxiloGQipHpae1uS+K5wLvMmpeX9GYf5Whcy+3+g/g8mTScOzIXsvQ== X-Received: by 2002:a05:6638:3183:b0:32a:7cb1:a13 with SMTP id z3-20020a056638318300b0032a7cb10a13mr8505228jak.89.1650929930771; Mon, 25 Apr 2022 16:38:50 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 01/21] tests: fix encoding of IP addresses in x509 certs Date: Mon, 25 Apr 2022 19:38:27 -0400 Message-Id: <20220425233847.10393-2-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930339647100002 From: Daniel P. Berrang=C3=A9 We need to encode just the address bytes, not the whole struct sockaddr data. Add a test case to validate that we're matching on SAN IP addresses correctly. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/crypto-tls-x509-helpers.c | 16 +++++++++++++--- tests/unit/test-crypto-tlssession.c | 11 +++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/unit/crypto-tls-x509-helpers.c b/tests/unit/crypto-tls-x= 509-helpers.c index fc609b3fd4..e9937f60d8 100644 --- a/tests/unit/crypto-tls-x509-helpers.c +++ b/tests/unit/crypto-tls-x509-helpers.c @@ -168,9 +168,19 @@ test_tls_get_ipaddr(const char *addrstr, hints.ai_flags =3D AI_NUMERICHOST; g_assert(getaddrinfo(addrstr, NULL, &hints, &res) =3D=3D 0); =20 - *datalen =3D res->ai_addrlen; - *data =3D g_new(char, *datalen); - memcpy(*data, res->ai_addr, *datalen); + if (res->ai_family =3D=3D AF_INET) { + struct sockaddr_in *in =3D (struct sockaddr_in *)res->ai_addr; + *datalen =3D sizeof(in->sin_addr); + *data =3D g_new(char, *datalen); + memcpy(*data, &in->sin_addr, *datalen); + } else if (res->ai_family =3D=3D AF_INET6) { + struct sockaddr_in6 *in =3D (struct sockaddr_in6 *)res->ai_addr; + *datalen =3D sizeof(in->sin6_addr); + *data =3D g_new(char, *datalen); + memcpy(*data, &in->sin6_addr, *datalen); + } else { + g_assert_not_reached(); + } freeaddrinfo(res); } =20 diff --git a/tests/unit/test-crypto-tlssession.c b/tests/unit/test-crypto-t= lssession.c index 5f0da9192c..a6935d8497 100644 --- a/tests/unit/test-crypto-tlssession.c +++ b/tests/unit/test-crypto-tlssession.c @@ -512,12 +512,19 @@ int main(int argc, char **argv) false, true, "wiki.qemu.org", NULL); =20 TEST_SESS_REG(altname4, cacertreq.filename, + servercertalt1req.filename, clientcertreq.filename, + false, false, "192.168.122.1", NULL); + TEST_SESS_REG(altname5, cacertreq.filename, + servercertalt1req.filename, clientcertreq.filename, + false, false, "fec0::dead:beaf", NULL); + + TEST_SESS_REG(altname6, cacertreq.filename, servercertalt2req.filename, clientcertreq.filename, false, true, "qemu.org", NULL); - TEST_SESS_REG(altname5, cacertreq.filename, + TEST_SESS_REG(altname7, cacertreq.filename, servercertalt2req.filename, clientcertreq.filename, false, false, "www.qemu.org", NULL); - TEST_SESS_REG(altname6, cacertreq.filename, + TEST_SESS_REG(altname8, cacertreq.filename, servercertalt2req.filename, clientcertreq.filename, false, false, "wiki.qemu.org", NULL); =20 --=20 2.32.0 From nobody Sun Feb 8 18:39:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165093017136730.882377593121873; Mon, 25 Apr 2022 16:42:51 -0700 (PDT) Received: from localhost ([::1]:47164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Lx-0001UI-S1 for importer@patchew.org; Mon, 25 Apr 2022 19:42:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8ID-0006rG-Ly for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:38:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32976) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IA-0007hh-Un for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:38:56 -0400 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-257-rVAQaOCCN124MWOr0wDEIA-1; Mon, 25 Apr 2022 19:38:53 -0400 Received: by mail-io1-f70.google.com with SMTP id k20-20020a5e9314000000b00649d55ffa67so12528253iom.20 for ; Mon, 25 Apr 2022 16:38:53 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u5X9bt/3RAsZQjwKglbnsbx8v9F0z8+wpzsDpKL6Fdo=; b=b/1d438bygHY1xcTcAsGNBGGDFL4RDawx6xXPomZrkMISFEqunSINRhKJJ4O8RweHtqPdS ydUIAvfN+2h1o5jaOrjvoiNy01aK/Mv6JEcrPTJ4D5hcPSizbxbBtQd8+UaLsSgHsClIaZ tCsxBfjR+rBpMVt8UFCOTSK7YchDeT4= X-MC-Unique: rVAQaOCCN124MWOr0wDEIA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u5X9bt/3RAsZQjwKglbnsbx8v9F0z8+wpzsDpKL6Fdo=; b=HHRAI9XfvuOXV1euzOq2ZrSUYjJfPZrCgjO26kRT0/aa8NhO+PgUQKozhVvGPGkklS ZKnH9n4F4FZ4PygQyQLGXtYeLXQYnMN+ahvnNFkftGvLP2eOM6tEDGE0635ic2jVi+ut wRTyKHBZFrwrgmCFOXIKCwvhjmGF6kTtj0dL056voPGIZADDCYNlqCAti6pQChsHWYgJ L2BntQTFUCK7MadJAVveLlUHdtlmLrLbbdObtXK+OMLECFiqFIHNrB2sGvVgun5Njq+Y yxHHsdUAlthu87zGRsCjohSVn8d/PlaGZuWxwO1t/KQTXT3m6EIXpFNvV4AxR/fA2Apv 5hTg== X-Gm-Message-State: AOAM533lSwyY/f8ELOyrP73yDsa8WASRhJhtJH6Mnn2yH8BwNn/d7Iqw /ekREeFWTtUTTHhLSYKHtVZ71waKEUMDZBozuqmmSYfK1U04oOOOYwrnl0mgTxrG3pf1Vdyj9wZ U24AWizG+0wcneIj4f4EMwJVXn3wo+U+cqfL+ANaYCy8ququI8uGk0Q6dTjUx9pLZ X-Received: by 2002:a5e:930e:0:b0:649:d7f0:ebc5 with SMTP id k14-20020a5e930e000000b00649d7f0ebc5mr8152868iom.80.1650929932460; Mon, 25 Apr 2022 16:38:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4ZGsA4VU05kSkval1TzG4Mt9akMHE0HflCtXMA8YKzMo85PXBtyv5Y78L4Wh4bYnILrGl5g== X-Received: by 2002:a5e:930e:0:b0:649:d7f0:ebc5 with SMTP id k14-20020a5e930e000000b00649d7f0ebc5mr8152857iom.80.1650929932209; Mon, 25 Apr 2022 16:38:52 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 02/21] tests: add more helper macros for creating TLS x509 certs Date: Mon, 25 Apr 2022 19:38:28 -0400 Message-Id: <20220425233847.10393-3-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930173274100003 From: Daniel P. Berrang=C3=A9 These macros are more suited to the general consumers of certs in the test suite, where we don't need to exercise every single possible permutation. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/crypto-tls-x509-helpers.h | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/unit/crypto-tls-x509-helpers.h b/tests/unit/crypto-tls-x= 509-helpers.h index cf6329e653..247e7160eb 100644 --- a/tests/unit/crypto-tls-x509-helpers.h +++ b/tests/unit/crypto-tls-x509-helpers.h @@ -26,6 +26,9 @@ #include =20 =20 +#define QCRYPTO_TLS_TEST_CLIENT_NAME "ACME QEMU Client" +#define QCRYPTO_TLS_TEST_CLIENT_HOSTILE_NAME "ACME Hostile Client" + /* * This contains parameter about how to generate * certificates. @@ -118,6 +121,56 @@ void test_tls_cleanup(const char *keyfile); }; \ test_tls_generate_cert(&varname, NULL) =20 +# define TLS_ROOT_REQ_SIMPLE(varname, fname) \ + QCryptoTLSTestCertReq varname =3D { \ + .filename =3D fname, \ + .cn =3D "qemu-CA", \ + .basicConstraintsEnable =3D true, \ + .basicConstraintsCritical =3D true, \ + .basicConstraintsIsCA =3D true, \ + .keyUsageEnable =3D true, \ + .keyUsageCritical =3D true, \ + .keyUsageValue =3D GNUTLS_KEY_KEY_CERT_SIGN, \ + }; \ + test_tls_generate_cert(&varname, NULL) + +# define TLS_CERT_REQ_SIMPLE_CLIENT(varname, cavarname, cname, fname) \ + QCryptoTLSTestCertReq varname =3D { \ + .filename =3D fname, \ + .cn =3D cname, \ + .basicConstraintsEnable =3D true, \ + .basicConstraintsCritical =3D true, \ + .basicConstraintsIsCA =3D false, \ + .keyUsageEnable =3D true, \ + .keyUsageCritical =3D true, \ + .keyUsageValue =3D \ + GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT, \ + .keyPurposeEnable =3D true, \ + .keyPurposeCritical =3D true, \ + .keyPurposeOID1 =3D GNUTLS_KP_TLS_WWW_CLIENT, \ + }; \ + test_tls_generate_cert(&varname, cavarname.crt) + +# define TLS_CERT_REQ_SIMPLE_SERVER(varname, cavarname, fname, \ + hostname, ipaddr) \ + QCryptoTLSTestCertReq varname =3D { \ + .filename =3D fname, \ + .cn =3D hostname ? hostname : ipaddr, \ + .altname1 =3D hostname, \ + .ipaddr1 =3D ipaddr, \ + .basicConstraintsEnable =3D true, \ + .basicConstraintsCritical =3D true, \ + .basicConstraintsIsCA =3D false, \ + .keyUsageEnable =3D true, \ + .keyUsageCritical =3D true, \ + .keyUsageValue =3D \ + GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT, \ + .keyPurposeEnable =3D true, \ + .keyPurposeCritical =3D true, \ + .keyPurposeOID1 =3D GNUTLS_KP_TLS_WWW_SERVER, \ + }; \ + test_tls_generate_cert(&varname, cavarname.crt) + extern const asn1_static_node pkix_asn1_tab[]; =20 #endif --=20 2.32.0 From nobody Sun Feb 8 18:39:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930177505761.7241273081187; Mon, 25 Apr 2022 16:42:57 -0700 (PDT) Received: from localhost ([::1]:47498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8M4-0001kA-16 for importer@patchew.org; Mon, 25 Apr 2022 19:42:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IE-0006s3-9w for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:38:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IC-0007is-6f for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:38:57 -0400 Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-rOZYtp7hMrGiulSs-sGkuQ-1; Mon, 25 Apr 2022 19:38:54 -0400 Received: by mail-il1-f200.google.com with SMTP id u11-20020a056e021a4b00b002cc315db462so6944362ilv.4 for ; Mon, 25 Apr 2022 16:38:54 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kW04nyDhP67HP3IT05mr3ws63S05cuU1BR7QhBBf5/4=; b=XUUBOv4/n14Z8DCi9PenqSlAR46o/WN8rkbMw/XTNXoaEWRDOqISenlFCFnW9XsXYpAIdi 996vwQwK6LG7ZKkh2NIUy+91ohQdzazq9xKYTuNroE7GTZwmzZqLVzQELB1paFDgvk0j9s DuHty/6hRKQrXmpja2CAIxuKe7KeGj8= X-MC-Unique: rOZYtp7hMrGiulSs-sGkuQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kW04nyDhP67HP3IT05mr3ws63S05cuU1BR7QhBBf5/4=; b=NVORr7gYUPE2nqEK80vLJ/REZA+fQFlgntzpt2i9rZnhDLS8hAB37gVPx4lLoG6Xrb Yt6peIdbcpRlXvAozDXte6qwqDrcLzs/4SihB7tk7uPCCWIAvPcUFp1T1f9cdChtY0dZ aVpHltBuK+M2eEl7OOHjU0ie5qjiANomuI5AOVX+xIMAPCzQdJBhQ4ykUz2hRQKlBhQl Ninb2yeYA3mjkb09pO/pgsvWOAe5WTHDEHC1jNG1ZRXFP7rGMSqVZ8xWNIQOV1MJ1jG8 wyLBq1TuFMypipSUs1siqnqOB6sTgHfws+/HqnDEgK5Qip6MDGfWuejckJwMeDU4XPhi SVyg== X-Gm-Message-State: AOAM533V5psZM/plsv+NE0xZeAmgb/V/rMTHmhJavxpbRowWE6h84U7/ gUcQS6Cl/c72gSxQRzCJP34HsUq5bjbJxX3ZzZLr6t2U13D3nPQP1e9mFcwiwHe+VJ8K6wOQsN7 yP+iNVaItT40+VzMeIOE26HgMT8HBRKAtxPDqJXHuffUndAORZVl/UrZrTUWRA6Nl X-Received: by 2002:a92:7f11:0:b0:2ca:50f9:63d6 with SMTP id a17-20020a927f11000000b002ca50f963d6mr8242698ild.150.1650929933617; Mon, 25 Apr 2022 16:38:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWFTN7R9ejHFL6woyONtwRHexUFop4YjfL1qt9QogBWSFSjOiPEIfQRYdJlBGsC0euc0sztw== X-Received: by 2002:a92:7f11:0:b0:2ca:50f9:63d6 with SMTP id a17-20020a927f11000000b002ca50f963d6mr8242684ild.150.1650929933278; Mon, 25 Apr 2022 16:38:53 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 03/21] tests: add migration tests of TLS with PSK credentials Date: Mon, 25 Apr 2022 19:38:29 -0400 Message-Id: <20220425233847.10393-4-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930178868100003 From: Daniel P. Berrang=C3=A9 This validates that we correctly handle migration success and failure scenarios when using TLS with pre shared keys. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qtest/meson.build | 7 +- tests/qtest/migration-test.c | 159 +++++++++++++++++++++++++++- tests/unit/crypto-tls-psk-helpers.c | 18 +++- tests/unit/crypto-tls-psk-helpers.h | 1 + 4 files changed, 177 insertions(+), 8 deletions(-) diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 22e1361210..ec14559e73 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -271,13 +271,18 @@ endif =20 tpmemu_files =3D ['tpm-emu.c', 'tpm-util.c', 'tpm-tests.c'] =20 +migration_files =3D [files('migration-helpers.c')] +if gnutls.found() + migration_files +=3D [files('../unit/crypto-tls-psk-helpers.c'), gnutls] +endif + qtests =3D { 'bios-tables-test': [io, 'boot-sector.c', 'acpi-utils.c', 'tpm-emu.c'], 'cdrom-test': files('boot-sector.c'), 'dbus-vmstate-test': files('migration-helpers.c') + dbus_vmstate1, 'erst-test': files('erst-test.c'), 'ivshmem-test': [rt, '../../contrib/ivshmem-server/ivshmem-server.c'], - 'migration-test': files('migration-helpers.c'), + 'migration-test': migration_files, 'pxe-test': files('boot-sector.c'), 'qos-test': [chardev, io, qos_test_ss.apply(config_host, strict: false).= sources()], 'tpm-crb-swtpm-test': [io, tpmemu_files], diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 2af36c16a3..f733aa352e 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -23,9 +23,13 @@ #include "qapi/qapi-visit-sockets.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" +#include "crypto/tlscredspsk.h" =20 #include "migration-helpers.h" #include "tests/migration/migration-test.h" +#ifdef CONFIG_GNUTLS +# include "tests/unit/crypto-tls-psk-helpers.h" +#endif /* CONFIG_GNUTLS */ =20 /* For dirty ring test; so far only x86_64 is supported */ #if defined(__linux__) && defined(HOST_X86_64) @@ -640,6 +644,100 @@ static void test_migrate_end(QTestState *from, QTestS= tate *to, bool test_dest) cleanup("dest_serial"); } =20 +#ifdef CONFIG_GNUTLS +struct TestMigrateTLSPSKData { + char *workdir; + char *workdiralt; + char *pskfile; + char *pskfilealt; +}; + +static void * +test_migrate_tls_psk_start_common(QTestState *from, + QTestState *to, + bool mismatch) +{ + struct TestMigrateTLSPSKData *data =3D + g_new0(struct TestMigrateTLSPSKData, 1); + QDict *rsp; + + data->workdir =3D g_strdup_printf("%s/tlscredspsk0", tmpfs); + data->pskfile =3D g_strdup_printf("%s/%s", data->workdir, + QCRYPTO_TLS_CREDS_PSKFILE); + mkdir(data->workdir, 0700); + test_tls_psk_init(data->pskfile); + + if (mismatch) { + data->workdiralt =3D g_strdup_printf("%s/tlscredspskalt0", tmpfs); + data->pskfilealt =3D g_strdup_printf("%s/%s", data->workdiralt, + QCRYPTO_TLS_CREDS_PSKFILE); + mkdir(data->workdiralt, 0700); + test_tls_psk_init_alt(data->pskfilealt); + } + + rsp =3D wait_command(from, + "{ 'execute': 'object-add'," + " 'arguments': { 'qom-type': 'tls-creds-psk'," + " 'id': 'tlscredspsk0'," + " 'endpoint': 'client'," + " 'dir': %s," + " 'username': 'qemu'} }", + data->workdir); + qobject_unref(rsp); + + rsp =3D wait_command(to, + "{ 'execute': 'object-add'," + " 'arguments': { 'qom-type': 'tls-creds-psk'," + " 'id': 'tlscredspsk0'," + " 'endpoint': 'server'," + " 'dir': %s } }", + mismatch ? data->workdiralt : data->workdir); + qobject_unref(rsp); + + migrate_set_parameter_str(from, "tls-creds", "tlscredspsk0"); + migrate_set_parameter_str(to, "tls-creds", "tlscredspsk0"); + + return data; +} + +static void * +test_migrate_tls_psk_start_match(QTestState *from, + QTestState *to) +{ + return test_migrate_tls_psk_start_common(from, to, false); +} + +static void * +test_migrate_tls_psk_start_mismatch(QTestState *from, + QTestState *to) +{ + return test_migrate_tls_psk_start_common(from, to, true); +} + +static void +test_migrate_tls_psk_finish(QTestState *from, + QTestState *to, + void *opaque) +{ + struct TestMigrateTLSPSKData *data =3D opaque; + + test_tls_psk_cleanup(data->pskfile); + if (data->pskfilealt) { + test_tls_psk_cleanup(data->pskfilealt); + } + rmdir(data->workdir); + if (data->workdiralt) { + rmdir(data->workdiralt); + } + + g_free(data->workdiralt); + g_free(data->pskfilealt); + g_free(data->workdir); + g_free(data->pskfile); + g_free(data); +} +#endif /* CONFIG_GNUTLS */ + static int migrate_postcopy_prepare(QTestState **from_ptr, QTestState **to_ptr, MigrateStart *args) @@ -911,7 +1009,7 @@ static void test_precopy_common(MigrateCommon *args) test_migrate_end(from, to, args->result =3D=3D MIG_TEST_SUCCEED); } =20 -static void test_precopy_unix(void) +static void test_precopy_unix_plain(void) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); MigrateCommon args =3D { @@ -922,6 +1020,19 @@ static void test_precopy_unix(void) test_precopy_common(&args); } =20 +static void test_precopy_unix_tls_psk(void) +{ + g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D uri, + .start_hook =3D test_migrate_tls_psk_start_match, + .finish_hook =3D test_migrate_tls_psk_finish, + }; + + test_precopy_common(&args); +} + static void test_precopy_unix_dirty_ring(void) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); @@ -1026,7 +1137,7 @@ static void test_xbzrle_unix(void) test_xbzrle(uri); } =20 -static void test_precopy_tcp(void) +static void test_precopy_tcp_plain(void) { MigrateCommon args =3D { .listen_uri =3D "tcp:127.0.0.1:0", @@ -1035,6 +1146,34 @@ static void test_precopy_tcp(void) test_precopy_common(&args); } =20 +#ifdef CONFIG_GNUTLS +static void test_precopy_tcp_tls_psk_match(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_psk_start_match, + .finish_hook =3D test_migrate_tls_psk_finish, + }; + + test_precopy_common(&args); +} + +static void test_precopy_tcp_tls_psk_mismatch(void) +{ + MigrateCommon args =3D { + .start =3D { + .hide_stderr =3D true, + }, + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_psk_start_mismatch, + .finish_hook =3D test_migrate_tls_psk_finish, + .result =3D MIG_TEST_FAIL, + }; + + test_precopy_common(&args); +} +#endif /* CONFIG_GNUTLS */ + static void *test_migrate_fd_start_hook(QTestState *from, QTestState *to) { @@ -1497,8 +1636,20 @@ int main(int argc, char **argv) qtest_add_func("/migration/postcopy/unix", test_postcopy); qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery); qtest_add_func("/migration/bad_dest", test_baddest); - qtest_add_func("/migration/precopy/unix", test_precopy_unix); - qtest_add_func("/migration/precopy/tcp", test_precopy_tcp); + qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plai= n); +#ifdef CONFIG_GNUTLS + qtest_add_func("/migration/precopy/unix/tls/psk", + test_precopy_unix_tls_psk); +#endif /* CONFIG_GNUTLS */ + + qtest_add_func("/migration/precopy/tcp/plain", test_precopy_tcp_plain); +#ifdef CONFIG_GNUTLS + qtest_add_func("/migration/precopy/tcp/tls/psk/match", + test_precopy_tcp_tls_psk_match); + qtest_add_func("/migration/precopy/tcp/tls/psk/mismatch", + test_precopy_tcp_tls_psk_mismatch); +#endif /* CONFIG_GNUTLS */ + /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */ qtest_add_func("/migration/xbzrle/unix", test_xbzrle_unix); qtest_add_func("/migration/fd_proto", test_migrate_fd_proto); diff --git a/tests/unit/crypto-tls-psk-helpers.c b/tests/unit/crypto-tls-ps= k-helpers.c index 4bea7c6fa2..511e08cc9c 100644 --- a/tests/unit/crypto-tls-psk-helpers.c +++ b/tests/unit/crypto-tls-psk-helpers.c @@ -24,7 +24,8 @@ #include "crypto-tls-psk-helpers.h" #include "qemu/sockets.h" =20 -void test_tls_psk_init(const char *pskfile) +static void +test_tls_psk_init_common(const char *pskfile, const char *user, const char= *key) { FILE *fp; =20 @@ -33,11 +34,22 @@ void test_tls_psk_init(const char *pskfile) g_critical("Failed to create pskfile %s: %s", pskfile, strerror(er= rno)); abort(); } - /* Don't do this in real applications! Use psktool. */ - fprintf(fp, "qemu:009d5638c40fde0c\n"); + fprintf(fp, "%s:%s\n", user, key); fclose(fp); } =20 +void test_tls_psk_init(const char *pskfile) +{ + /* Don't hard code a key like this in real applications! Use psktool.= */ + test_tls_psk_init_common(pskfile, "qemu", "009d5638c40fde0c"); +} + +void test_tls_psk_init_alt(const char *pskfile) +{ + /* Don't hard code a key like this in real applications! Use psktool.= */ + test_tls_psk_init_common(pskfile, "qemu", "10ffa6a2c42f0388"); +} + void test_tls_psk_cleanup(const char *pskfile) { unlink(pskfile); diff --git a/tests/unit/crypto-tls-psk-helpers.h b/tests/unit/crypto-tls-ps= k-helpers.h index faa645c629..67f8bdda71 100644 --- a/tests/unit/crypto-tls-psk-helpers.h +++ b/tests/unit/crypto-tls-psk-helpers.h @@ -24,6 +24,7 @@ #include =20 void test_tls_psk_init(const char *keyfile); +void test_tls_psk_init_alt(const char *keyfile); void test_tls_psk_cleanup(const char *keyfile); =20 #endif --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930338601818.8847355031439; Mon, 25 Apr 2022 16:45:38 -0700 (PDT) Received: from localhost ([::1]:55576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Of-00079l-BL for importer@patchew.org; Mon, 25 Apr 2022 19:45:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IG-0006uO-GM for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8ID-0007jI-SM for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:38:59 -0400 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-164-berkxsLDM_uNx1G2QqTTZQ-1; Mon, 25 Apr 2022 19:38:55 -0400 Received: by mail-io1-f70.google.com with SMTP id k20-20020a5e9314000000b00649d55ffa67so12528300iom.20 for ; Mon, 25 Apr 2022 16:38:55 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ouKYpdwGEGmWYs3o2Z5/+NwNQykEjUK6/pW0BTiY6R4=; b=La8ph+Blkc440FM51XClnWgp3GwGyZji09XlXLPljChH6CYi2VrYe/3Tj9WE/e63oM33EB +0PUQtrmxs2ovslrjwUBkEYmFR5ESXXUzdBmWRFL8TRuZS83W0CXyXmOs5gKEk36hiG87Y n7OMH4eNeoXS6fpNXH4tUo2f5osRYtw= X-MC-Unique: berkxsLDM_uNx1G2QqTTZQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ouKYpdwGEGmWYs3o2Z5/+NwNQykEjUK6/pW0BTiY6R4=; b=yXCpYrfWlTvpzslKIG8D+zcTDbg9KCGoX1gPbfz7nkMdDPk0XhUxQjyvZD8YdGiBeq VPW3rtqGvTNxXg7+ZfOCD08bGyaLS9YrIzpMQo6iDHPjQxOsIw8yx7H0F3+wVdD3ywWC m30CRXWGY09nqanzjoLtyhjS5h+JLvClNFPyohwhqq/gMlUVZXivlTksD2n+m+MoZXNp CXbRsNh7gIC3jhSaa8sSu0Wktx8Fdmsx+fbl4pE1TedyAawqv+skkA24RUN5V0QC2EhB Ud35e6bghbI1KD0OnDQBOe/t0BXGzCOQg14Lw/pEXxOgk0+Kxv4ANhx1FY52znUunjZ/ BWLw== X-Gm-Message-State: AOAM532PxjSeuCn40wXFgd7v3ZT8w2pXYCDObOK8O7XIk8xt01lXMCGU T3xpr6rhE5iC83GAEWJQ+O1jvTP+B6m4Tlse8piaIc1wnSOyEEq3xtOvhQq2h8yASdV8oWZ5tPB gSze83RYX/MjyAAdygb0oTTmzD2/gabiTmuy96r5QfljpYY/lluAkjlFzEbjwvTP4 X-Received: by 2002:a05:6638:3794:b0:32a:9f1e:a1d0 with SMTP id w20-20020a056638379400b0032a9f1ea1d0mr8454068jal.257.1650929934777; Mon, 25 Apr 2022 16:38:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCZjZMOoNZoXD3vdiD7w9BHU4r4NLRIGDnmkJcE1uqFsyUSze1uuiX6UzjYdwZwi1lsSiNVA== X-Received: by 2002:a05:6638:3794:b0:32a:9f1e:a1d0 with SMTP id w20-20020a056638379400b0032a9f1ea1d0mr8454047jal.257.1650929934454; Mon, 25 Apr 2022 16:38:54 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 04/21] tests: add migration tests of TLS with x509 credentials Date: Mon, 25 Apr 2022 19:38:30 -0400 Message-Id: <20220425233847.10393-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930339645100001 From: Daniel P. Berrang=C3=A9 This validates that we correctly handle migration success and failure scenarios when using TLS with x509 certificates. There are quite a few different scenarios that matter in relation to hostname validation. Signed-off-by: Daniel P. Berrang=C3=A9 --- meson.build | 1 + tests/qtest/meson.build | 5 + tests/qtest/migration-test.c | 382 ++++++++++++++++++++++++++++++++++- 3 files changed, 386 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index d083c6b7bf..d1231b23ae 100644 --- a/meson.build +++ b/meson.build @@ -1565,6 +1565,7 @@ config_host_data.set('CONFIG_KEYUTILS', keyutils.foun= d()) config_host_data.set('CONFIG_GETTID', has_gettid) config_host_data.set('CONFIG_GNUTLS', gnutls.found()) config_host_data.set('CONFIG_GNUTLS_CRYPTO', gnutls_crypto.found()) +config_host_data.set('CONFIG_TASN1', tasn1.found()) config_host_data.set('CONFIG_GCRYPT', gcrypt.found()) config_host_data.set('CONFIG_NETTLE', nettle.found()) config_host_data.set('CONFIG_QEMU_PRIVATE_XTS', xts =3D=3D 'private') diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index ec14559e73..af7c31d611 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -274,6 +274,11 @@ tpmemu_files =3D ['tpm-emu.c', 'tpm-util.c', 'tpm-test= s.c'] migration_files =3D [files('migration-helpers.c')] if gnutls.found() migration_files +=3D [files('../unit/crypto-tls-psk-helpers.c'), gnutls] + + if tasn1.found() + migration_files +=3D [files('../unit/crypto-tls-x509-helpers.c', + '../unit/pkix_asn1_tab.c'), tasn1] + endif endif =20 qtests =3D { diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index f733aa352e..c730697f74 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -29,6 +29,9 @@ #include "tests/migration/migration-test.h" #ifdef CONFIG_GNUTLS # include "tests/unit/crypto-tls-psk-helpers.h" +# ifdef CONFIG_TASN1 +# include "tests/unit/crypto-tls-x509-helpers.h" +# endif /* CONFIG_TASN1 */ #endif /* CONFIG_GNUTLS */ =20 /* For dirty ring test; so far only x86_64 is supported */ @@ -736,6 +739,234 @@ test_migrate_tls_psk_finish(QTestState *from, g_free(data->pskfile); g_free(data); } + +#ifdef CONFIG_TASN1 +typedef struct { + char *workdir; + char *keyfile; + char *cacert; + char *servercert; + char *serverkey; + char *clientcert; + char *clientkey; +} TestMigrateTLSX509Data; + +typedef struct { + bool verifyclient; + bool clientcert; + bool hostileclient; + bool authzclient; + const char *certhostname; + const char *certipaddr; +} TestMigrateTLSX509; + +static void * +test_migrate_tls_x509_start_common(QTestState *from, + QTestState *to, + TestMigrateTLSX509 *args) +{ + TestMigrateTLSX509Data *data =3D g_new0(TestMigrateTLSX509Data, 1); + QDict *rsp; + + data->workdir =3D g_strdup_printf("%s/tlscredsx5090", tmpfs); + data->keyfile =3D g_strdup_printf("%s/key.pem", data->workdir); + + data->cacert =3D g_strdup_printf("%s/ca-cert.pem", data->workdir); + data->serverkey =3D g_strdup_printf("%s/server-key.pem", data->workdir= ); + data->servercert =3D g_strdup_printf("%s/server-cert.pem", data->workd= ir); + if (args->clientcert) { + data->clientkey =3D g_strdup_printf("%s/client-key.pem", data->wor= kdir); + data->clientcert =3D g_strdup_printf("%s/client-cert.pem", data->w= orkdir); + } + + mkdir(data->workdir, 0700); + + test_tls_init(data->keyfile); + g_assert(link(data->keyfile, data->serverkey) =3D=3D 0); + if (args->clientcert) { + g_assert(link(data->keyfile, data->clientkey) =3D=3D 0); + } + + TLS_ROOT_REQ_SIMPLE(cacertreq, data->cacert); + if (args->clientcert) { + TLS_CERT_REQ_SIMPLE_CLIENT(servercertreq, cacertreq, + args->hostileclient ? + QCRYPTO_TLS_TEST_CLIENT_HOSTILE_NAME : + QCRYPTO_TLS_TEST_CLIENT_NAME, + data->clientcert); + } + + TLS_CERT_REQ_SIMPLE_SERVER(clientcertreq, cacertreq, + data->servercert, + args->certhostname, + args->certipaddr); + + rsp =3D wait_command(from, + "{ 'execute': 'object-add'," + " 'arguments': { 'qom-type': 'tls-creds-x509'," + " 'id': 'tlscredsx509client0'," + " 'endpoint': 'client'," + " 'dir': %s," + " 'sanity-check': true," + " 'verify-peer': true} }", + data->workdir); + qobject_unref(rsp); + migrate_set_parameter_str(from, "tls-creds", "tlscredsx509client0"); + if (args->certhostname) { + migrate_set_parameter_str(from, "tls-hostname", args->certhostname= ); + } + + rsp =3D wait_command(to, + "{ 'execute': 'object-add'," + " 'arguments': { 'qom-type': 'tls-creds-x509'," + " 'id': 'tlscredsx509server0'," + " 'endpoint': 'server'," + " 'dir': %s," + " 'sanity-check': true," + " 'verify-peer': %i} }", + data->workdir, args->verifyclient); + qobject_unref(rsp); + migrate_set_parameter_str(to, "tls-creds", "tlscredsx509server0"); + + if (args->authzclient) { + rsp =3D wait_command(to, + "{ 'execute': 'object-add'," + " 'arguments': { 'qom-type': 'authz-simple'," + " 'id': 'tlsauthz0'," + " 'identity': %s} }", + "CN=3D" QCRYPTO_TLS_TEST_CLIENT_NAME); + migrate_set_parameter_str(to, "tls-authz", "tlsauthz0"); + } + + return data; +} + +/* + * The normal case: match server's cert hostname against + * whatever host we were telling QEMU to connect to (if any) + */ +static void * +test_migrate_tls_x509_start_default_host(QTestState *from, + QTestState *to) +{ + TestMigrateTLSX509 args =3D { + .verifyclient =3D true, + .clientcert =3D true, + .certipaddr =3D "127.0.0.1" + }; + return test_migrate_tls_x509_start_common(from, to, &args); +} + +/* + * The unusual case: the server's cert is different from + * the address we're telling QEMU to connect to (if any), + * so we must give QEMU an explicit hostname to validate + */ +static void * +test_migrate_tls_x509_start_override_host(QTestState *from, + QTestState *to) +{ + TestMigrateTLSX509 args =3D { + .verifyclient =3D true, + .clientcert =3D true, + .certhostname =3D "qemu.org", + }; + return test_migrate_tls_x509_start_common(from, to, &args); +} + +/* + * The unusual case: the server's cert is different from + * the address we're telling QEMU to connect to, and so we + * expect the client to reject the server + */ +static void * +test_migrate_tls_x509_start_mismatch_host(QTestState *from, + QTestState *to) +{ + TestMigrateTLSX509 args =3D { + .verifyclient =3D true, + .clientcert =3D true, + .certipaddr =3D "10.0.0.1", + }; + return test_migrate_tls_x509_start_common(from, to, &args); +} + +static void * +test_migrate_tls_x509_start_friendly_client(QTestState *from, + QTestState *to) +{ + TestMigrateTLSX509 args =3D { + .verifyclient =3D true, + .clientcert =3D true, + .authzclient =3D true, + .certipaddr =3D "127.0.0.1", + }; + return test_migrate_tls_x509_start_common(from, to, &args); +} + +static void * +test_migrate_tls_x509_start_hostile_client(QTestState *from, + QTestState *to) +{ + TestMigrateTLSX509 args =3D { + .verifyclient =3D true, + .clientcert =3D true, + .hostileclient =3D true, + .authzclient =3D true, + .certipaddr =3D "127.0.0.1", + }; + return test_migrate_tls_x509_start_common(from, to, &args); +} + +/* + * The case with no client certificate presented, + * and no server verification + */ +static void * +test_migrate_tls_x509_start_allow_anon_client(QTestState *from, + QTestState *to) +{ + TestMigrateTLSX509 args =3D { + .certipaddr =3D "127.0.0.1", + }; + return test_migrate_tls_x509_start_common(from, to, &args); +} + +/* + * The case with no client certificate presented, + * and server verification rejecting + */ +static void * +test_migrate_tls_x509_start_reject_anon_client(QTestState *from, + QTestState *to) +{ + TestMigrateTLSX509 args =3D { + .verifyclient =3D true, + .certipaddr =3D "127.0.0.1", + }; + return test_migrate_tls_x509_start_common(from, to, &args); +} + +static void +test_migrate_tls_x509_finish(QTestState *from, + QTestState *to, + void *opaque) +{ + TestMigrateTLSX509Data *data =3D opaque; + + test_tls_cleanup(data->keyfile); + unlink(data->cacert); + unlink(data->servercert); + unlink(data->serverkey); + unlink(data->clientcert); + unlink(data->clientkey); + rmdir(data->workdir); + + g_free(data->workdir); + g_free(data->keyfile); + g_free(data); +} +#endif /* CONFIG_TASN1 */ #endif /* CONFIG_GNUTLS */ =20 static int migrate_postcopy_prepare(QTestState **from_ptr, @@ -1020,6 +1251,21 @@ static void test_precopy_unix_plain(void) test_precopy_common(&args); } =20 +static void test_precopy_unix_dirty_ring(void) +{ + g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateCommon args =3D { + .start =3D { + .use_dirty_ring =3D true, + }, + .listen_uri =3D uri, + .connect_uri =3D uri, + }; + + test_precopy_common(&args); +} + +#ifdef CONFIG_GNUTLS static void test_precopy_unix_tls_psk(void) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); @@ -1033,19 +1279,38 @@ static void test_precopy_unix_tls_psk(void) test_precopy_common(&args); } =20 -static void test_precopy_unix_dirty_ring(void) +#ifdef CONFIG_TASN1 +static void test_precopy_unix_tls_x509_default_host(void) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); MigrateCommon args =3D { .start =3D { - .use_dirty_ring =3D true, + .hide_stderr =3D true, }, + .connect_uri =3D uri, .listen_uri =3D uri, + .start_hook =3D test_migrate_tls_x509_start_default_host, + .finish_hook =3D test_migrate_tls_x509_finish, + .result =3D MIG_TEST_FAIL_DEST_QUIT_ERR, + }; + + test_precopy_common(&args); +} + +static void test_precopy_unix_tls_x509_override_host(void) +{ + g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateCommon args =3D { .connect_uri =3D uri, + .listen_uri =3D uri, + .start_hook =3D test_migrate_tls_x509_start_override_host, + .finish_hook =3D test_migrate_tls_x509_finish, }; =20 test_precopy_common(&args); } +#endif /* CONFIG_TASN1 */ +#endif /* CONFIG_GNUTLS */ =20 #if 0 /* Currently upset on aarch64 TCG */ @@ -1172,6 +1437,97 @@ static void test_precopy_tcp_tls_psk_mismatch(void) =20 test_precopy_common(&args); } + +#ifdef CONFIG_TASN1 +static void test_precopy_tcp_tls_x509_default_host(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_x509_start_default_host, + .finish_hook =3D test_migrate_tls_x509_finish, + }; + + test_precopy_common(&args); +} + +static void test_precopy_tcp_tls_x509_override_host(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_x509_start_override_host, + .finish_hook =3D test_migrate_tls_x509_finish, + }; + + test_precopy_common(&args); +} + +static void test_precopy_tcp_tls_x509_mismatch_host(void) +{ + MigrateCommon args =3D { + .start =3D { + .hide_stderr =3D true, + }, + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_x509_start_mismatch_host, + .finish_hook =3D test_migrate_tls_x509_finish, + .result =3D MIG_TEST_FAIL_DEST_QUIT_ERR, + }; + + test_precopy_common(&args); +} + +static void test_precopy_tcp_tls_x509_friendly_client(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_x509_start_friendly_client, + .finish_hook =3D test_migrate_tls_x509_finish, + }; + + test_precopy_common(&args); +} + +static void test_precopy_tcp_tls_x509_hostile_client(void) +{ + MigrateCommon args =3D { + .start =3D { + .hide_stderr =3D true, + }, + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_x509_start_hostile_client, + .finish_hook =3D test_migrate_tls_x509_finish, + .result =3D MIG_TEST_FAIL, + }; + + test_precopy_common(&args); +} + +static void test_precopy_tcp_tls_x509_allow_anon_client(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_x509_start_allow_anon_client, + .finish_hook =3D test_migrate_tls_x509_finish, + }; + + test_precopy_common(&args); +} + +static void test_precopy_tcp_tls_x509_reject_anon_client(void) +{ + MigrateCommon args =3D { + .start =3D { + .hide_stderr =3D true, + }, + .listen_uri =3D "tcp:127.0.0.1:0", + .start_hook =3D test_migrate_tls_x509_start_reject_anon_client, + .finish_hook =3D test_migrate_tls_x509_finish, + .result =3D MIG_TEST_FAIL, + }; + + test_precopy_common(&args); +} +#endif /* CONFIG_TASN1 */ #endif /* CONFIG_GNUTLS */ =20 static void *test_migrate_fd_start_hook(QTestState *from, @@ -1640,6 +1996,12 @@ int main(int argc, char **argv) #ifdef CONFIG_GNUTLS qtest_add_func("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); +#ifdef CONFIG_TASN1 + qtest_add_func("/migration/precopy/unix/tls/x509/default-host", + test_precopy_unix_tls_x509_default_host); + qtest_add_func("/migration/precopy/unix/tls/x509/override-host", + test_precopy_unix_tls_x509_override_host); +#endif /* CONFIG_TASN1 */ #endif /* CONFIG_GNUTLS */ =20 qtest_add_func("/migration/precopy/tcp/plain", test_precopy_tcp_plain); @@ -1648,6 +2010,22 @@ int main(int argc, char **argv) test_precopy_tcp_tls_psk_match); qtest_add_func("/migration/precopy/tcp/tls/psk/mismatch", test_precopy_tcp_tls_psk_mismatch); +#ifdef CONFIG_TASN1 + qtest_add_func("/migration/precopy/tcp/tls/x509/default-host", + test_precopy_tcp_tls_x509_default_host); + qtest_add_func("/migration/precopy/tcp/tls/x509/override-host", + test_precopy_tcp_tls_x509_override_host); + qtest_add_func("/migration/precopy/tcp/tls/x509/mismatch-host", + test_precopy_tcp_tls_x509_mismatch_host); + qtest_add_func("/migration/precopy/tcp/tls/x509/friendly-client", + test_precopy_tcp_tls_x509_friendly_client); + qtest_add_func("/migration/precopy/tcp/tls/x509/hostile-client", + test_precopy_tcp_tls_x509_hostile_client); + qtest_add_func("/migration/precopy/tcp/tls/x509/allow-anon-client", + test_precopy_tcp_tls_x509_allow_anon_client); + qtest_add_func("/migration/precopy/tcp/tls/x509/reject-anon-client", + test_precopy_tcp_tls_x509_reject_anon_client); +#endif /* CONFIG_TASN1 */ #endif /* CONFIG_GNUTLS */ =20 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */ --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930351640659.7489962441522; Mon, 25 Apr 2022 16:45:51 -0700 (PDT) Received: from localhost ([::1]:56094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Os-0007Tc-L2 for importer@patchew.org; Mon, 25 Apr 2022 19:45:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IG-0006uM-H3 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52166) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IE-0007jP-8h for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:38:59 -0400 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-467-bLYNoeGvN8WFqaH70vt4Fg-1; Mon, 25 Apr 2022 19:38:56 -0400 Received: by mail-io1-f69.google.com with SMTP id b1-20020a05660214c100b006572ddc92f7so11384278iow.2 for ; Mon, 25 Apr 2022 16:38:56 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dWLaqbfdjriZjFTSAHj1/ZnERyPkrPEVGBxqmeZ10yU=; b=H/jbteG/tui3eGQ9m1zS8iloD54uZiB6t6hOn/HkfJxt1mrOhu2sMNq4fz+nEziV8898tY qlglDRtmHpsgn4k7iVBaPUbL3kfi/9nj4ISryNxluHFtcta2HnvbRQMGGRw6dK96qKA4oL d0b/kBm81YaDFXeUFDa+8RZb6bJUkZU= X-MC-Unique: bLYNoeGvN8WFqaH70vt4Fg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dWLaqbfdjriZjFTSAHj1/ZnERyPkrPEVGBxqmeZ10yU=; b=3XTeVndIRhYtOfG8tUQ2mjkxpsFcxRmEQgSen90cvJKYi/gz/or1RgHT53Mneh9UBO G3A+oYFLuFxYtUVgc0/O9bj7Pl+hOdfjQtAIE3t8p+GVZ7Z0ShHtyOutZu9SAxr7okGS FcPxAintf68CpSnG0a7+Z4xAS/SiiJTYX3OB6TnfwKMqC1ewNzh0kpXop2Vx0Tw4BdM2 XFqeSvgMIXrfk03WwRiR9z7tveOW9Jx4mSooT+6pkHVWJ1uwD0YmmURB+xX2RRh5USib 2gnHpnz52XrmsDHRP0hAzb/g41GvECqXgn7hcm52hXwi9ZSNpM6+uFn9iFqC3gDzjbwL SW6A== X-Gm-Message-State: AOAM533f3oWJpV+HCfa9UkC1zi5RGhwjEfFXRAM8zxToQgcgn3XdL77W nmd8FvBUBzmMDKUZe5PaKPwuAoA/6OOXImn9o5rv4VPv6S1i7dhaf5o8EmuH6rIp+XeN4bDeoW+ 5B1Kjg2GUbouU6qsCuft1eUroUri7vAtUQtSZF7axPcTsJ8ojwt48Ft7XWWTC4I8z X-Received: by 2002:a05:6638:4605:b0:32a:dd1f:7e4f with SMTP id bw5-20020a056638460500b0032add1f7e4fmr5138157jab.217.1650929935796; Mon, 25 Apr 2022 16:38:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytp6648Hzvue55DU7vgFoA06lTYDzoQ4+6/LPi5MqnfIbZdcnvAQB+/vPj6la1h53ga4a/rg== X-Received: by 2002:a05:6638:4605:b0:32a:dd1f:7e4f with SMTP id bw5-20020a056638460500b0032add1f7e4fmr5138144jab.217.1650929935526; Mon, 25 Apr 2022 16:38:55 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 05/21] tests: convert XBZRLE migration test to use common helper Date: Mon, 25 Apr 2022 19:38:31 -0400 Message-Id: <20220425233847.10393-6-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930353847100001 From: Daniel P. Berrang=C3=A9 Most of the XBZRLE migration test logic is common with the rest of the precopy tests, so it can use the helper with just one small tweak. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qtest/migration-test.c | 67 ++++++++++++++---------------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index c730697f74..043ae94089 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1174,6 +1174,9 @@ typedef struct { /* This test should fail, dest qemu should fail with abnormal stat= us */ MIG_TEST_FAIL_DEST_QUIT_ERR, } result; + + /* Optional: set number of migration passes to wait for */ + unsigned int iterations; } MigrateCommon; =20 static void test_precopy_common(MigrateCommon *args) @@ -1219,7 +1222,13 @@ static void test_precopy_common(MigrateCommon *args) qtest_set_expected_status(to, 1); } } else { - wait_for_migration_pass(from); + if (args->iterations) { + while (args->iterations--) { + wait_for_migration_pass(from); + } + } else { + wait_for_migration_pass(from); + } =20 migrate_set_parameter_int(from, "downtime-limit", CONVERGE_DOWNTIM= E); =20 @@ -1349,57 +1358,31 @@ static void test_ignore_shared(void) } #endif =20 -static void test_xbzrle(const char *uri) +static void * +test_migrate_xbzrle_start(QTestState *from, + QTestState *to) { - MigrateStart args =3D {}; - QTestState *from, *to; - - if (test_migrate_start(&from, &to, uri, &args)) { - return; - } - - /* - * We want to pick a speed slow enough that the test completes - * quickly, but that it doesn't complete precopy even on a slow - * machine, so also set the downtime. - */ - /* 1 ms should make it not converge*/ - migrate_set_parameter_int(from, "downtime-limit", 1); - /* 1GB/s */ - migrate_set_parameter_int(from, "max-bandwidth", 1000000000); - migrate_set_parameter_int(from, "xbzrle-cache-size", 33554432); =20 migrate_set_capability(from, "xbzrle", true); migrate_set_capability(to, "xbzrle", true); - /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); =20 - migrate_qmp(from, uri, "{}"); - - wait_for_migration_pass(from); - /* Make sure we have 2 passes, so the xbzrle cache gets a workout */ - wait_for_migration_pass(from); - - /* 1000ms should converge */ - migrate_set_parameter_int(from, "downtime-limit", 1000); - - if (!got_stop) { - qtest_qmp_eventwait(from, "STOP"); - } - qtest_qmp_eventwait(to, "RESUME"); - - wait_for_serial("dest_serial"); - wait_for_migration_complete(from); - - test_migrate_end(from, to, true); + return NULL; } =20 -static void test_xbzrle_unix(void) +static void test_precopy_unix_xbzrle(void) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D uri, + + .start_hook =3D test_migrate_xbzrle_start, =20 - test_xbzrle(uri); + .iterations =3D 2, + }; + + test_precopy_common(&args); } =20 static void test_precopy_tcp_plain(void) @@ -1993,6 +1976,7 @@ int main(int argc, char **argv) qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery); qtest_add_func("/migration/bad_dest", test_baddest); qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plai= n); + qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbz= rle); #ifdef CONFIG_GNUTLS qtest_add_func("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); @@ -2029,7 +2013,6 @@ int main(int argc, char **argv) #endif /* CONFIG_GNUTLS */ =20 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */ - qtest_add_func("/migration/xbzrle/unix", test_xbzrle_unix); qtest_add_func("/migration/fd_proto", test_migrate_fd_proto); qtest_add_func("/migration/validate_uuid", test_validate_uuid); qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_er= ror); --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930351001562.681360566421; Mon, 25 Apr 2022 16:45:51 -0700 (PDT) Received: from localhost ([::1]:56122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Os-0007Ui-2j for importer@patchew.org; Mon, 25 Apr 2022 19:45:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IH-0006xV-RO for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25868) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IG-0007je-6I for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:01 -0400 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-pKCoLr8ZNHCg7jck_n4SCw-1; Mon, 25 Apr 2022 19:38:57 -0400 Received: by mail-io1-f69.google.com with SMTP id o9-20020a0566022e0900b00654b599b1eeso12490845iow.21 for ; Mon, 25 Apr 2022 16:38:57 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Fv6RBBdjH1ilfW+mVsC6jnSqV2KdI0wkPM5+dS84Yk=; b=cKz7wVManjfX3D5RnBu0CxHGNJyA9sUAdjDMaa4UsM+37K3uzqYBw3siqqqI7jeWStvXl5 nA/QdIfFFPy25ajb4y5L2tdZ4ZaCo2A8hUjOkw2YeL8+gYUCR/PDWK3Z6M/i8oLsaWhLj5 0qI2dgFrysjinByDcssITPmfm3GgUto= X-MC-Unique: pKCoLr8ZNHCg7jck_n4SCw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Fv6RBBdjH1ilfW+mVsC6jnSqV2KdI0wkPM5+dS84Yk=; b=62t7ZGHGKBwrnjkQTFlB8zAtCHegI3mBzU4va3cS3T7TgobwwiSwBbjpzn4jeGe5wo 9fAzD9gLhVHKwve4grNCQvPhxfpbMIINzkfk0+9pAyWlnnqGvPXumbccZ8inopNywS0y 71QbuGTvukAkzeWYWCOtk4DkZ4apIHhpsZAVkI7eoeEb5lU89aipGlJ2zpO8owxfYzhu fWfIqGcYDrn/LbdpsimB+GlqaYQ1MT1dLdza1WhYBeHzliuh0xeCkz90mZWoJSJQ7ftS acrPczIw7HYrMzUAwliVtSkV8FNF9U8WG9ieqVnKOP3QN0cB+VJdM8tTPODSg9Fp8kTk tS9A== X-Gm-Message-State: AOAM5335mGj7gfFPVAZsLjDzwDsvd4zmNYxgCvT1irbbTYR6rNkFWyFr mjsT8UgrnHrp2ILRuYkUXG0mkpPP/BX6PpiDJwuQ/ffuBjCJm29+ceqJx36SrfO3RHDDluB9HwG KXUzx2MabMdu30gOMDh0DXY1ITu2Nrc/RkMr+0pAZi4Gf+lNDiDgs1DJjfvDF6yox X-Received: by 2002:a05:6e02:20c8:b0:2cd:95fd:7336 with SMTP id 8-20020a056e0220c800b002cd95fd7336mr3174636ilq.261.1650929936904; Mon, 25 Apr 2022 16:38:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxtUMh3oeyNptP3NsLTRI8Pig5lOB63Km6adCL15GOmfcJBkYp1mbu8/QzyCjKfBHwP2jkFw== X-Received: by 2002:a05:6e02:20c8:b0:2cd:95fd:7336 with SMTP id 8-20020a056e0220c800b002cd95fd7336mr3174622ilq.261.1650929936640; Mon, 25 Apr 2022 16:38:56 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 06/21] tests: convert multifd migration tests to use common helper Date: Mon, 25 Apr 2022 19:38:32 -0400 Message-Id: <20220425233847.10393-7-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930351639100001 From: Daniel P. Berrang=C3=A9 Most of the multifd migration test logic is common with the rest of the precopy tests, so it can use the helper without difficulty. The only exception of the multifd cancellation test which tries to run multiple migrations in a row. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qtest/migration-test.c | 77 +++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 043ae94089..c1b0b3aca4 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1739,26 +1739,12 @@ static void test_migrate_auto_converge(void) test_migrate_end(from, to, true); } =20 -static void test_multifd_tcp(const char *method) +static void * +test_migrate_precopy_tcp_multifd_start_common(QTestState *from, + QTestState *to, + const char *method) { - MigrateStart args =3D {}; - QTestState *from, *to; QDict *rsp; - g_autofree char *uri =3D NULL; - - if (test_migrate_start(&from, &to, "defer", &args)) { - return; - } - - /* - * We want to pick a speed slow enough that the test completes - * quickly, but that it doesn't complete precopy even on a slow - * machine, so also set the downtime. - */ - /* 1 ms should make it not converge*/ - migrate_set_parameter_int(from, "downtime-limit", 1); - /* 1GB/s */ - migrate_set_parameter_int(from, "max-bandwidth", 1000000000); =20 migrate_set_parameter_int(from, "multifd-channels", 16); migrate_set_parameter_int(to, "multifd-channels", 16); @@ -1774,41 +1760,58 @@ static void test_multifd_tcp(const char *method) " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}"); qobject_unref(rsp); =20 - /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); - - uri =3D migrate_get_socket_address(to, "socket-address"); - - migrate_qmp(from, uri, "{}"); - - wait_for_migration_pass(from); + return NULL; +} =20 - migrate_set_parameter_int(from, "downtime-limit", CONVERGE_DOWNTIME); +static void * +test_migrate_precopy_tcp_multifd_start(QTestState *from, + QTestState *to) +{ + return test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); +} =20 - if (!got_stop) { - qtest_qmp_eventwait(from, "STOP"); - } - qtest_qmp_eventwait(to, "RESUME"); +static void * +test_migrate_precopy_tcp_multifd_zlib_start(QTestState *from, + QTestState *to) +{ + return test_migrate_precopy_tcp_multifd_start_common(from, to, "zlib"); +} =20 - wait_for_serial("dest_serial"); - wait_for_migration_complete(from); - test_migrate_end(from, to, true); +#ifdef CONFIG_ZSTD +static void * +test_migrate_precopy_tcp_multifd_zstd_start(QTestState *from, + QTestState *to) +{ + return test_migrate_precopy_tcp_multifd_start_common(from, to, "zstd"); } +#endif /* CONFIG_ZSTD */ =20 static void test_multifd_tcp_none(void) { - test_multifd_tcp("none"); + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start_hook =3D test_migrate_precopy_tcp_multifd_start, + }; + test_precopy_common(&args); } =20 static void test_multifd_tcp_zlib(void) { - test_multifd_tcp("zlib"); + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start_hook =3D test_migrate_precopy_tcp_multifd_zlib_start, + }; + test_precopy_common(&args); } =20 #ifdef CONFIG_ZSTD static void test_multifd_tcp_zstd(void) { - test_multifd_tcp("zstd"); + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start_hook =3D test_migrate_precopy_tcp_multifd_zstd_start, + }; + test_precopy_common(&args); } #endif =20 --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165093017642332.46123286655802; Mon, 25 Apr 2022 16:42:56 -0700 (PDT) Received: from localhost ([::1]:47514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8M3-0001kU-CS for importer@patchew.org; Mon, 25 Apr 2022 19:42:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8II-0006yC-3F for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26734) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IG-0007jm-GX for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:01 -0400 Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-82-YF5BHg5JOPGXheG1J17IGQ-1; Mon, 25 Apr 2022 19:38:58 -0400 Received: by mail-il1-f197.google.com with SMTP id h28-20020a056e021d9c00b002cc403e851aso6909331ila.12 for ; Mon, 25 Apr 2022 16:38:58 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1TaW6msKlcAMMbgF4fLjrd4EFijbFPLZDkGeOUvG8wc=; b=MvB0++ZLhdd2tLQfD6UnvFUJZrQDm1eell2jSYCCyYHqB0oilI4ihumBATPMFwUqbn3dxW xbPGT/PUXMJdjcVBX9ZvdCqDDKrT0fQtDnUBxhqlnue1W0ImnR3VantDSpN94b9Gr5dANS k0Xth5C57rSrA986lnRmyMtVKqf5hp4= X-MC-Unique: YF5BHg5JOPGXheG1J17IGQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1TaW6msKlcAMMbgF4fLjrd4EFijbFPLZDkGeOUvG8wc=; b=2iSvb36x3jRPop40nnj3jVYShBU2hBDKOAt2bsYBKkiyoD3mNRGB2hDiJ6o+pTnsVH pjaEQEpBeyjoYCBnwTSba6p65zA48l24rZgCfqibOaxmjq6RxSwser0AkUcchwl2u0sZ mvtK7PjN0zqKx+Ne/0JYHlzG3fm5DnhYGjbxsVbIdAIswS8CxIgsU4qG49rAsHys91hw cRXimf0eeguX3cXEWfNrL+DQS+2xxZ0uyLDKoPtF+rtxVOkltQRL68maT6FhnG0XTfU6 Kct2dmIA0Koi9Sa9djFC3dVJ9mPIoKqPcU2x4qbXF7QJ0Li4tCXV8tVYwMwUb2Df+qrG uqzg== X-Gm-Message-State: AOAM532FVz4ci5KLJov4P+2de3dsSid2k+mzyifC8TDJJZIvEk5ZuWIC CnCWqhBzNj71cfH78Sk7G40Divz+nt/ZOIC2W/xQVEFtW9bfCb6gThFMZGKLksNVQxHHWCz8Gpb tnFIFboyuMzfQOiaw5tD5V1tKrbpc2oxS75AV1CpsLykQ4BOCCUaS3EmxKyOnknSD X-Received: by 2002:a05:6e02:12b4:b0:2ca:e755:ee4a with SMTP id f20-20020a056e0212b400b002cae755ee4amr8150264ilr.65.1650929937960; Mon, 25 Apr 2022 16:38:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrMqMJoDlcildnbWjSf83BSaC/mk+SxWdtBOPmM2af6vly+Ooy8dJLHENB0zRN2siBywwYrw== X-Received: by 2002:a05:6e02:12b4:b0:2ca:e755:ee4a with SMTP id f20-20020a056e0212b400b002cae755ee4amr8150250ilr.65.1650929937725; Mon, 25 Apr 2022 16:38:57 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 07/21] tests: add multifd migration tests of TLS with PSK credentials Date: Mon, 25 Apr 2022 19:38:33 -0400 Message-Id: <20220425233847.10393-8-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930176819100001 From: Daniel P. Berrang=C3=A9 This validates that we correctly handle multifd migration success and failure scenarios when using TLS with pre shared keys. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qtest/migration-test.c | 60 +++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index c1b0b3aca4..f47e4797e2 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1815,6 +1815,48 @@ static void test_multifd_tcp_zstd(void) } #endif =20 +#ifdef CONFIG_GNUTLS +static void * +test_migrate_multifd_tcp_tls_psk_start_match(QTestState *from, + QTestState *to) +{ + test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); + return test_migrate_tls_psk_start_match(from, to); +} + +static void * +test_migrate_multifd_tcp_tls_psk_start_mismatch(QTestState *from, + QTestState *to) +{ + test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); + return test_migrate_tls_psk_start_mismatch(from, to); +} + +static void test_multifd_tcp_tls_psk_match(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start_hook =3D test_migrate_multifd_tcp_tls_psk_start_match, + .finish_hook =3D test_migrate_tls_psk_finish, + }; + test_precopy_common(&args); +} + +static void test_multifd_tcp_tls_psk_mismatch(void) +{ + MigrateCommon args =3D { + .start =3D { + .hide_stderr =3D true, + }, + .listen_uri =3D "defer", + .start_hook =3D test_migrate_multifd_tcp_tls_psk_start_mismatch, + .finish_hook =3D test_migrate_tls_psk_finish, + .result =3D MIG_TEST_FAIL, + }; + test_precopy_common(&args); +} +#endif /* CONFIG_GNUTLS */ + /* * This test does: * source target @@ -2025,12 +2067,22 @@ int main(int argc, char **argv) test_validate_uuid_dst_not_set); =20 qtest_add_func("/migration/auto_converge", test_migrate_auto_converge); - qtest_add_func("/migration/multifd/tcp/none", test_multifd_tcp_none); - qtest_add_func("/migration/multifd/tcp/cancel", test_multifd_tcp_cance= l); - qtest_add_func("/migration/multifd/tcp/zlib", test_multifd_tcp_zlib); + qtest_add_func("/migration/multifd/tcp/plain/none", + test_multifd_tcp_none); + qtest_add_func("/migration/multifd/tcp/plain/cancel", + test_multifd_tcp_cancel); + qtest_add_func("/migration/multifd/tcp/plain/zlib", + test_multifd_tcp_zlib); #ifdef CONFIG_ZSTD - qtest_add_func("/migration/multifd/tcp/zstd", test_multifd_tcp_zstd); + qtest_add_func("/migration/multifd/tcp/plain/zstd", + test_multifd_tcp_zstd); #endif +#ifdef CONFIG_GNUTLS + qtest_add_func("/migration/multifd/tcp/tls/psk/match", + test_multifd_tcp_tls_psk_match); + qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch", + test_multifd_tcp_tls_psk_mismatch); +#endif /* CONFIG_GNUTLS */ =20 if (kvm_dirty_ring_supported()) { qtest_add_func("/migration/dirty_ring", --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930516248113.53488573974289; Mon, 25 Apr 2022 16:48:36 -0700 (PDT) Received: from localhost ([::1]:35824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8RW-0004UK-LX for importer@patchew.org; Mon, 25 Apr 2022 19:48:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IJ-00072n-OM for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:26126) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IH-0007k1-Qr for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:03 -0400 Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-177-MD15zIeMMCmQCQdnhwBfyA-1; Mon, 25 Apr 2022 19:38:59 -0400 Received: by mail-io1-f71.google.com with SMTP id k20-20020a5e9314000000b00649d55ffa67so12528367iom.20 for ; Mon, 25 Apr 2022 16:38:59 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CT/FgeDFU3KaQ+xOqXSypN9L0YEqphcA8dJYQb7JqyY=; b=cPHojK0HdG6RRuFtVEqeJYTTmmN81b3ewBq1sxe9rj55VOHoA7Tps6W+P79FDsZj89XrSn SZPFHfpEFQDf8N7yhyjqFahcjxGhmsNI7hhCYz39Q+uAiJusH1f6BvUOAXJ1LH8iiLUbLi HooEqAsDj1rEOJ8xMVJ85btjOrIijN8= X-MC-Unique: MD15zIeMMCmQCQdnhwBfyA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CT/FgeDFU3KaQ+xOqXSypN9L0YEqphcA8dJYQb7JqyY=; b=YFIE/EHNu+8SEIlzgYe9blWzBAt5YJ4kKJx4VWk21isEVyXarRXZzzgjrRwYmA7TVw mIJu7tacYNbpI8oXT4RHCUJEcEy+Z2mLAMKOBseSaYrRsXSxd6EQFvS5XoLusm9R0JY2 vO5mXrnsIEyIUh4R5NEf28gVijionJrpEwWrjV/N+jLz0epSgvu4LNL4Kv8BPh26ZxMZ NGU61qBp12BCvmnwSVRyffiRYPYBgPaHa/sXnyH2eHaLQmYhwSXbDDRQjwTFCtStJb/3 isfrMkn66Yqv3WtA+m8S9Bgx/GOzrG/A8nSUnGh26dul6jiLvnbj/kenZzCaB9vUlBMx W7mg== X-Gm-Message-State: AOAM532qb2KzSlNETMyt41Sp/gcRhdBwgwzIvuoA/E/tz/7b8AUyu8o+ vBawhxpy/ZarpU7YiDPLc2hdEzthHgK96T9rc0glC/fYDaCrDd/E2jn0qJPcV/zRJc4tkouNF+K 2tCzmeo8NtCDIe0ArcWvBVlvSu0V8hYOJ1RE7Ah5TIcezAh1xjmKYP2w5ER9AyR4w X-Received: by 2002:a05:6602:1481:b0:657:2836:587c with SMTP id a1-20020a056602148100b006572836587cmr8419801iow.194.1650929939132; Mon, 25 Apr 2022 16:38:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcaZHM9xnjrIVPoYdaI1vWPpxbJ8WogWHNTCMdjAR0BFlnQTuVPbtnFu6wz/cXDF0xZuBdMw== X-Received: by 2002:a05:6602:1481:b0:657:2836:587c with SMTP id a1-20020a056602148100b006572836587cmr8419786iow.194.1650929938890; Mon, 25 Apr 2022 16:38:58 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 08/21] tests: add multifd migration tests of TLS with x509 credentials Date: Mon, 25 Apr 2022 19:38:34 -0400 Message-Id: <20220425233847.10393-9-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930518445100001 From: Daniel P. Berrang=C3=A9 This validates that we correctly handle multifd migration success and failure scenarios when using TLS with x509 certificates. There are quite a few different scenarios that matter in relation to hostname validation, but we skip a couple as we can assume that the non-multifd coverage applies to some extent. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qtest/migration-test.c | 127 +++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index f47e4797e2..5ea0b9360a 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1832,6 +1832,48 @@ test_migrate_multifd_tcp_tls_psk_start_mismatch(QTes= tState *from, return test_migrate_tls_psk_start_mismatch(from, to); } =20 +#ifdef CONFIG_TASN1 +static void * +test_migrate_multifd_tls_x509_start_default_host(QTestState *from, + QTestState *to) +{ + test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); + return test_migrate_tls_x509_start_default_host(from, to); +} + +static void * +test_migrate_multifd_tls_x509_start_override_host(QTestState *from, + QTestState *to) +{ + test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); + return test_migrate_tls_x509_start_override_host(from, to); +} + +static void * +test_migrate_multifd_tls_x509_start_mismatch_host(QTestState *from, + QTestState *to) +{ + test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); + return test_migrate_tls_x509_start_mismatch_host(from, to); +} + +static void * +test_migrate_multifd_tls_x509_start_allow_anon_client(QTestState *from, + QTestState *to) +{ + test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); + return test_migrate_tls_x509_start_allow_anon_client(from, to); +} + +static void * +test_migrate_multifd_tls_x509_start_reject_anon_client(QTestState *from, + QTestState *to) +{ + test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); + return test_migrate_tls_x509_start_reject_anon_client(from, to); +} +#endif /* CONFIG_TASN1 */ + static void test_multifd_tcp_tls_psk_match(void) { MigrateCommon args =3D { @@ -1855,6 +1897,79 @@ static void test_multifd_tcp_tls_psk_mismatch(void) }; test_precopy_common(&args); } + +#ifdef CONFIG_TASN1 +static void test_multifd_tcp_tls_x509_default_host(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start_hook =3D test_migrate_multifd_tls_x509_start_default_host, + .finish_hook =3D test_migrate_tls_x509_finish, + }; + test_precopy_common(&args); +} + +static void test_multifd_tcp_tls_x509_override_host(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start_hook =3D test_migrate_multifd_tls_x509_start_override_host, + .finish_hook =3D test_migrate_tls_x509_finish, + }; + test_precopy_common(&args); +} + +static void test_multifd_tcp_tls_x509_mismatch_host(void) +{ + /* + * This has different behaviour to the non-multifd case. + * + * In non-multifd case when client aborts due to mismatched + * cert host, the server has already started trying to load + * migration state, and so it exits with I/O failure. + * + * In multifd case when client aborts due to mismatched + * cert host, the server is still waiting for the other + * multifd connections to arrive so hasn't started trying + * to load migration state, and thus just aborts the migration + * without exiting + */ + MigrateCommon args =3D { + .start =3D { + .hide_stderr =3D true, + }, + .listen_uri =3D "defer", + .start_hook =3D test_migrate_multifd_tls_x509_start_mismatch_host, + .finish_hook =3D test_migrate_tls_x509_finish, + .result =3D MIG_TEST_FAIL, + }; + test_precopy_common(&args); +} + +static void test_multifd_tcp_tls_x509_allow_anon_client(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start_hook =3D test_migrate_multifd_tls_x509_start_allow_anon_cli= ent, + .finish_hook =3D test_migrate_tls_x509_finish, + }; + test_precopy_common(&args); +} + +static void test_multifd_tcp_tls_x509_reject_anon_client(void) +{ + MigrateCommon args =3D { + .start =3D { + .hide_stderr =3D true, + }, + .listen_uri =3D "defer", + .start_hook =3D test_migrate_multifd_tls_x509_start_reject_anon_cl= ient, + .finish_hook =3D test_migrate_tls_x509_finish, + .result =3D MIG_TEST_FAIL, + }; + test_precopy_common(&args); +} +#endif /* CONFIG_TASN1 */ #endif /* CONFIG_GNUTLS */ =20 /* @@ -2082,6 +2197,18 @@ int main(int argc, char **argv) test_multifd_tcp_tls_psk_match); qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch", test_multifd_tcp_tls_psk_mismatch); +#ifdef CONFIG_TASN1 + qtest_add_func("/migration/multifd/tcp/tls/x509/default-host", + test_multifd_tcp_tls_x509_default_host); + qtest_add_func("/migration/multifd/tcp/tls/x509/override-host", + test_multifd_tcp_tls_x509_override_host); + qtest_add_func("/migration/multifd/tcp/tls/x509/mismatch-host", + test_multifd_tcp_tls_x509_mismatch_host); + qtest_add_func("/migration/multifd/tcp/tls/x509/allow-anon-client", + test_multifd_tcp_tls_x509_allow_anon_client); + qtest_add_func("/migration/multifd/tcp/tls/x509/reject-anon-client", + test_multifd_tcp_tls_x509_reject_anon_client); +#endif /* CONFIG_TASN1 */ #endif /* CONFIG_GNUTLS */ =20 if (kvm_dirty_ring_supported()) { --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930522654901.4807330469779; Mon, 25 Apr 2022 16:48:42 -0700 (PDT) Received: from localhost ([::1]:36316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Rd-0004pz-46 for importer@patchew.org; Mon, 25 Apr 2022 19:48:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IL-00076u-JB for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54317) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8II-0007kG-Tf for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:04 -0400 Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-575-Yrxf86-UOViZkTVz5477wA-1; Mon, 25 Apr 2022 19:39:01 -0400 Received: by mail-il1-f198.google.com with SMTP id u11-20020a056e021a4b00b002cc315db462so6944417ilv.4 for ; Mon, 25 Apr 2022 16:39:01 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.38.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bA/Coxr0OviSm7/62XvQBXQFLB77tNKSIqC7Wwapa78=; b=YXNHgY4ri0YW0OvtYMVDndoUKfWUgCPpVpGBbsYufKcmZBegYTTBz5o1ap7PI9Koa8ZCW5 OUEP4z6CXpuIirb5bLjXRZy9bfn1k5e10sEHTRDG8OCx8ATbIenODDCAqIQ4gVWPvxqxZs wBZlhlWLvIIyg0iKEXrq4CvKa2FJGR8= X-MC-Unique: Yrxf86-UOViZkTVz5477wA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bA/Coxr0OviSm7/62XvQBXQFLB77tNKSIqC7Wwapa78=; b=yVJds6JZpVfXhcKgPASg9ho7p7k4SiyQfbi1J785xqmkBr3ur43KHyBMEwT5hC25WF sTsDZc5B4y9Fx/MbByxZ0+smuoJWryx2+AnPwMAQwz7vU75I6FzftN4rdIYBpVoBFGyH AjGrF/6cmCqqJQOW0azsA0OlkcaGTb/QVnagdlItZpp0BaDy7B5daXP6M7WDK8PLJneq fMSm+lBSJHSF0r1bfX9Ykn5+sx6KMughtng0vHEv2EuMd+o3WFZx4qXzl97wcQE/E+nO ylPiDxnKyVquRzn4EQEvUc/M8FpZ8kTF0tyaBehOom5j9vPkEfeIjSIwSDpf9CSbSI4e DQVQ== X-Gm-Message-State: AOAM533HNgpSy96rj0f//b6t+xEwHskueAtAp7BHmpLIbmjbM5gigecp jLVFTIYkiXy0gpuo11wj0cd5pKyj9tQ/B67Yl8gpGo9aidSN+Eel+uxRfIl/san+81OFSM0yOlS ywY/+0EPOQg5Cwd1+yrynrl/+3YpPIGzOUeWiafy7Wxh7sPnEWowA64wi9cB6aGd8 X-Received: by 2002:a6b:ed06:0:b0:649:d35f:852c with SMTP id n6-20020a6bed06000000b00649d35f852cmr8503394iog.186.1650929940355; Mon, 25 Apr 2022 16:39:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPjxXwdHJxnBWLuYC89mHFrh2h2CZq9q3isF4jIAQNuhqmuei0MQOYKWP5Fsovu5YljiSfkQ== X-Received: by 2002:a6b:ed06:0:b0:649:d35f:852c with SMTP id n6-20020a6bed06000000b00649d35f852cmr8503381iog.186.1650929940113; Mon, 25 Apr 2022 16:39:00 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 09/21] tests: ensure migration status isn't reported as failed Date: Mon, 25 Apr 2022 19:38:35 -0400 Message-Id: <20220425233847.10393-10-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930524356100001 From: Daniel P. Berrang=C3=A9 Various methods in the migration test call 'query_migrate' to fetch the current status and then access a particular field. Almost all of these cases expect the migration to be in a non-failed state. In the case of 'wait_for_migration_pass' in particular, if the status is 'failed' then it will get into an infinite loop. By validating that the status is not 'failed' the test suite will assert rather than hang when getting into an unexpected state. Reviewed-by: Peter Xu Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qtest/migration-helpers.c | 13 +++++++++++++ tests/qtest/migration-helpers.h | 1 + tests/qtest/migration-test.c | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index 4ee26014b7..a6aa59e4e6 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -107,6 +107,19 @@ QDict *migrate_query(QTestState *who) return wait_command(who, "{ 'execute': 'query-migrate' }"); } =20 +QDict *migrate_query_not_failed(QTestState *who) +{ + const char *status; + QDict *rsp =3D migrate_query(who); + status =3D qdict_get_str(rsp, "status"); + if (g_str_equal(status, "failed")) { + g_printerr("query-migrate shows failed migration: %s\n", + qdict_get_str(rsp, "error-desc")); + } + g_assert(!g_str_equal(status, "failed")); + return rsp; +} + /* * Note: caller is responsible to free the returned object via * g_free() after use diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helper= s.h index 555adafce1..d07e0fb748 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -26,6 +26,7 @@ G_GNUC_PRINTF(3, 4) void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...); =20 QDict *migrate_query(QTestState *who); +QDict *migrate_query_not_failed(QTestState *who); =20 void wait_for_migration_status(QTestState *who, const char *goal, const char **ungoals); diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 5ea0b9360a..d9f444ea14 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -181,7 +181,7 @@ static int64_t read_ram_property_int(QTestState *who, c= onst char *property) QDict *rsp_return, *rsp_ram; int64_t result; =20 - rsp_return =3D migrate_query(who); + rsp_return =3D migrate_query_not_failed(who); if (!qdict_haskey(rsp_return, "ram")) { /* Still in setup */ result =3D 0; @@ -198,7 +198,7 @@ static int64_t read_migrate_property_int(QTestState *wh= o, const char *property) QDict *rsp_return; int64_t result; =20 - rsp_return =3D migrate_query(who); + rsp_return =3D migrate_query_not_failed(who); result =3D qdict_get_try_int(rsp_return, property, 0); qobject_unref(rsp_return); return result; @@ -213,7 +213,7 @@ static void read_blocktime(QTestState *who) { QDict *rsp_return; =20 - rsp_return =3D migrate_query(who); + rsp_return =3D migrate_query_not_failed(who); g_assert(qdict_haskey(rsp_return, "postcopy-blocktime")); qobject_unref(rsp_return); } --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930665269148.21951209514987; Mon, 25 Apr 2022 16:51:05 -0700 (PDT) Received: from localhost ([::1]:44212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Tw-0001hp-7P for importer@patchew.org; Mon, 25 Apr 2022 19:51:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IM-00079C-3h for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21073) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IK-0007kQ-A2 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:05 -0400 Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-428-GeevIfcPNUW_gO0yLtfQmw-1; Mon, 25 Apr 2022 19:39:02 -0400 Received: by mail-io1-f71.google.com with SMTP id g16-20020a05660203d000b005f7b3b0642eso102713iov.16 for ; Mon, 25 Apr 2022 16:39:02 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bmwBWn3HuKl7CinqBKqF4WztBjlQylQ6C2I873h1Ezo=; b=eRxEwrm6Uw6XWJkX3BNACDZPYcWfwvNsa7TwK2obOoUGTTSor8RyGapxK/aFJMAVb9RqEt bOkWZWfj8czoLzN1JsL5j1f3aWHPPcGwcr1JdgifTiz1ZZ9N3c4M1iK4L8jDrAgEyOSm5L zXpbSyBr3LDJM/DwxkJA6uhhp4Q7BFs= X-MC-Unique: GeevIfcPNUW_gO0yLtfQmw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bmwBWn3HuKl7CinqBKqF4WztBjlQylQ6C2I873h1Ezo=; b=DOpmHPxBjPhHzSJCXL6FKBxrRtZUSmXj2F0okYIzPs5/jwY72QA+XOpVFK/U6JYbQ5 TaR8KCWfJ6v3FS2jdpZUPRAW8pQmn/kwhg020zJQoTZZ8KnENtddM3T8zOkPVcspIvAH Xs9GgcvXCWXIKNcrhRQPTRfBsnH7/12Hrk22wFxB5mBNtDaubat6BBctFkpBEd0AYDy1 junB5r37b1ABfEqafU2eojWExLldoXcch8pw6ZPrmnXs0cGNkgnxjeZsGDrLtXMVH3BA emAIUiCPirXeQIa2vjcQyL/er05tJkTiTBQWt5k1pKQV1uQp4dELD2GXz/KNRFki6/fz hWCg== X-Gm-Message-State: AOAM530YigwukYcb1oEBn00A6stkLnSEVFGK8JdMjYm8hF3tgqRT1Rms xP60zQidNRskXl7Nb2xQ9uaSp2Ce4UfsU2ueXu+DHo6bllE/7JVrMKnnd+YHjEy7MsdXXaSIH2B 3pUrODKn+geNmGQ4/PJThmCa0IuIvyqZf6OzLOMzCdZMPYOWXl5JDmGU58gpWN+Of X-Received: by 2002:a6b:f80b:0:b0:649:a265:bcc3 with SMTP id o11-20020a6bf80b000000b00649a265bcc3mr7912726ioh.18.1650929941445; Mon, 25 Apr 2022 16:39:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyECpnK6ddeNh5+kQ1J2twdrDb74QaptrJnY0j/Jjd30DIoR/lIxD8MIPnt9yyYEYtriERszw== X-Received: by 2002:a6b:f80b:0:b0:649:a265:bcc3 with SMTP id o11-20020a6bf80b000000b00649a265bcc3mr7912710ioh.18.1650929941129; Mon, 25 Apr 2022 16:39:01 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 10/21] migration: Add postcopy-preempt capability Date: Mon, 25 Apr 2022 19:38:36 -0400 Message-Id: <20220425233847.10393-11-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930667073100001 Content-Type: text/plain; charset="utf-8" Firstly, postcopy already preempts precopy due to the fact that we do unqueue_page() first before looking into dirty bits. However that's not enough, e.g., when there're host huge page enabled, when sending a precopy huge page, a postcopy request needs to wait until the who= le huge page that is sending to finish. That could introduce quite some delay, the bigger the huge page is the larger delay it'll bring. This patch adds a new capability to allow postcopy requests to preempt exis= ting precopy page during sending a huge page, so that postcopy requests can be serviced even faster. Meanwhile to send it even faster, bypass the precopy stream by providing a standalone postcopy socket for sending requested pages. Since the new behavior will not be compatible with the old behavior, this w= ill not be the default, it's enabled only when the new capability is set on both src/dst QEMUs. This patch only adds the capability itself, the logic will be added in foll= ow up patches. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/migration.c | 23 +++++++++++++++++++++++ migration/migration.h | 1 + qapi/migration.json | 8 +++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 5a31b23bd6..75d9185c3a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1236,6 +1236,11 @@ static bool migrate_caps_check(bool *cap_list, error_setg(errp, "Postcopy is not compatible with ignore-share= d"); return false; } + + if (cap_list[MIGRATION_CAPABILITY_MULTIFD]) { + error_setg(errp, "Multifd is not supported in postcopy"); + return false; + } } =20 if (cap_list[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) { @@ -1279,6 +1284,13 @@ static bool migrate_caps_check(bool *cap_list, return false; } =20 + if (cap_list[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) { + if (!cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + error_setg(errp, "Postcopy preempt requires postcopy-ram"); + return false; + } + } + return true; } =20 @@ -2626,6 +2638,15 @@ bool migrate_background_snapshot(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHO= T]; } =20 +bool migrate_postcopy_preempt(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]; +} + /* migration thread support */ /* * Something bad happened to the RP stream, mark an error @@ -4236,6 +4257,8 @@ static Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-compress", MIGRATION_CAPABILITY_COMPRESS), DEFINE_PROP_MIG_CAP("x-events", MIGRATION_CAPABILITY_EVENTS), DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RA= M), + DEFINE_PROP_MIG_CAP("x-postcopy-preempt", + MIGRATION_CAPABILITY_POSTCOPY_PREEMPT), DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO), DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM), DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK), diff --git a/migration/migration.h b/migration/migration.h index a863032b71..af4bcb19c2 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -394,6 +394,7 @@ int migrate_decompress_threads(void); bool migrate_use_events(void); bool migrate_postcopy_blocktime(void); bool migrate_background_snapshot(void); +bool migrate_postcopy_preempt(void); =20 /* Sending on the return path - generic and then for each message type */ void migrate_send_rp_shut(MigrationIncomingState *mis, diff --git a/qapi/migration.json b/qapi/migration.json index 409eb086a2..f381a94c98 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -463,6 +463,12 @@ # procedure starts. The VM RAM is saved with running= VM. # (since 6.0) # +# @postcopy-preempt: If enabled, the migration process will allow postcopy +# requests to preempt precopy stream, so postcopy reque= sts +# will be handled faster. This is a performance featur= e and +# should not affect the correctness of postcopy migrati= on. +# (since 7.1) +# # Features: # @unstable: Members @x-colo and @x-ignore-shared are experimental. # @@ -476,7 +482,7 @@ 'block', 'return-path', 'pause-before-switchover', 'multifd', 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, - 'validate-uuid', 'background-snapshot'] } + 'validate-uuid', 'background-snapshot', 'postcopy-preempt'] } =20 ## # @MigrationCapabilityStatus: --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165093067521491.6470627735365; Mon, 25 Apr 2022 16:51:15 -0700 (PDT) Received: from localhost ([::1]:44838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8U5-000282-PB for importer@patchew.org; Mon, 25 Apr 2022 19:51:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IO-0007Il-QW for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IM-0007kk-Al for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:08 -0400 Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-14-12rjUF2mMSWmGUktvl3Iqw-1; Mon, 25 Apr 2022 19:39:04 -0400 Received: by mail-il1-f199.google.com with SMTP id i22-20020a056e021d1600b002cd69a8f421so4772234ila.6 for ; Mon, 25 Apr 2022 16:39:04 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZCLjsViY5BxwJ6GhW+PS5cj/nCYo8CydPsCmpu5mEz4=; b=ZjKAFbvl/sdWN1EX1I9VfZmRilj0ADpd1zZuURfsY4eN6mpL0WFT3x/Rrj77/GX1cyJWE+ OAWgGN15kPcHeEf+QuTZOTUrtK4NjdRR4hJEpNViJ6lqmhooKS1musZ8dOqRYp3F6eCe+m 8v05GTGikJ4NkPAQqt9aSoaqiYj22Kk= X-MC-Unique: 12rjUF2mMSWmGUktvl3Iqw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZCLjsViY5BxwJ6GhW+PS5cj/nCYo8CydPsCmpu5mEz4=; b=aVsrW9I9B/IExP9dK9PJTAE8mcnVZdZQKKJX2Dq9Bn+aj7YTVLz+KGCCWjT/82mgXK 9FHX5l21rrnT0shKmrciVb4s+F9JjbtX4+Zmlb5WnhmBZo4+KJGY52LCFFKoTH+Jzbbn rYlz1pzdNMZfRqyRo+tokod0EVbUwk/xAAG31t2NFJk2nZgDnomot0P44aIoBBNZlvPs 1VcioKnyYModerCxMP/sdqag5t3tBWxzbPIeuNtdPQv9ug4sQYvviECpBs6P/2ShqT8i Y9yXECkt66IqSKHn98YP4l041xuITxnRAH/PsoHVbz5uoyqTjeCqdCyCY3FGLG6qfPJx 1Olg== X-Gm-Message-State: AOAM530e8Xr2Bo6pNrMAL3Zdc7Z1vs3+pHQmq+QHCwGFqEHgxw3dZChw ++NsJ0Bl89t2Kn4tNCfBGb64qJ7PKvsz81Why8Pmi+ODy8iIzF4XVgFADXTvu+6dPP15/7vYsFa Z2kHn3RPXzce747eAn6+s1JnBnl8oUS3r9bCYgYSvc36g12jhcu0OAbO04xyBJC+K X-Received: by 2002:a92:6e11:0:b0:2c7:a32b:733d with SMTP id j17-20020a926e11000000b002c7a32b733dmr7711739ilc.196.1650929942988; Mon, 25 Apr 2022 16:39:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGnPkNXF1Ezz51zOnfZdd+e5dmGFI4hrTin9nStm/qBXi6ccYAXoflKJC8G14/0H1VwbahWA== X-Received: by 2002:a92:6e11:0:b0:2c7:a32b:733d with SMTP id j17-20020a926e11000000b002c7a32b733dmr7711717ilc.196.1650929942400; Mon, 25 Apr 2022 16:39:02 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 11/21] migration: Postcopy preemption preparation on channel creation Date: Mon, 25 Apr 2022 19:38:37 -0400 Message-Id: <20220425233847.10393-12-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.999, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URG_BIZ=0.573 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930677148100001 Create a new socket for postcopy to be prepared to send postcopy requested pages via this specific channel, so as to not get blocked by precopy pages. A new thread is also created on dest qemu to receive data from this new cha= nnel based on the ram_load_postcopy() routine. The ram_load_postcopy(POSTCOPY) branch and the thread has not started to function, and that'll be done in follow up patches. Cleanup the new sockets on both src/dst QEMUs, meanwhile look after the new thread too to make sure it'll be recycled properly. Signed-off-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-By tag in my next post? --- migration/migration.c | 62 +++++++++++++++++++++++---- migration/migration.h | 8 ++++ migration/postcopy-ram.c | 92 ++++++++++++++++++++++++++++++++++++++-- migration/postcopy-ram.h | 10 +++++ migration/ram.c | 25 ++++++++--- migration/ram.h | 4 +- migration/savevm.c | 20 ++++----- migration/socket.c | 22 +++++++++- migration/socket.h | 1 + migration/trace-events | 5 ++- 10 files changed, 218 insertions(+), 31 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 75d9185c3a..e27aa306bc 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -321,6 +321,12 @@ void migration_incoming_state_destroy(void) mis->page_requested =3D NULL; } =20 + if (mis->postcopy_qemufile_dst) { + migration_ioc_unregister_yank_from_file(mis->postcopy_qemufile_dst= ); + qemu_fclose(mis->postcopy_qemufile_dst); + mis->postcopy_qemufile_dst =3D NULL; + } + yank_unregister_instance(MIGRATION_YANK_INSTANCE); } =20 @@ -714,15 +720,21 @@ void migration_fd_process_incoming(QEMUFile *f, Error= **errp) migration_incoming_process(); } =20 +static bool migration_needs_multiple_sockets(void) +{ + return migrate_use_multifd() || migrate_postcopy_preempt(); +} + void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); Error *local_err =3D NULL; bool start_migration; + QEMUFile *f; =20 if (!mis->from_src_file) { /* The first connection (multifd may have multiple) */ - QEMUFile *f =3D qemu_fopen_channel_input(ioc); + f =3D qemu_fopen_channel_input(ioc); =20 if (!migration_incoming_setup(f, errp)) { return; @@ -730,13 +742,18 @@ void migration_ioc_process_incoming(QIOChannel *ioc, = Error **errp) =20 /* * Common migration only needs one channel, so we can start - * right now. Multifd needs more than one channel, we wait. + * right now. Some features need more than one channel, we wait. */ - start_migration =3D !migrate_use_multifd(); + start_migration =3D !migration_needs_multiple_sockets(); } else { /* Multiple connections */ - assert(migrate_use_multifd()); - start_migration =3D multifd_recv_new_channel(ioc, &local_err); + assert(migration_needs_multiple_sockets()); + if (migrate_use_multifd()) { + start_migration =3D multifd_recv_new_channel(ioc, &local_err); + } else if (migrate_postcopy_preempt()) { + f =3D qemu_fopen_channel_input(ioc); + start_migration =3D postcopy_preempt_new_channel(mis, f); + } if (local_err) { error_propagate(errp, local_err); return; @@ -761,11 +778,20 @@ void migration_ioc_process_incoming(QIOChannel *ioc, = Error **errp) bool migration_has_all_channels(void) { MigrationIncomingState *mis =3D migration_incoming_get_current(); - bool all_channels; =20 - all_channels =3D multifd_recv_all_channels_created(); + if (!mis->from_src_file) { + return false; + } + + if (migrate_use_multifd()) { + return multifd_recv_all_channels_created(); + } + + if (migrate_postcopy_preempt()) { + return mis->postcopy_qemufile_dst !=3D NULL; + } =20 - return all_channels && mis->from_src_file !=3D NULL; + return true; } =20 /* @@ -1862,6 +1888,12 @@ static void migrate_fd_cleanup(MigrationState *s) qemu_fclose(tmp); } =20 + if (s->postcopy_qemufile_src) { + migration_ioc_unregister_yank_from_file(s->postcopy_qemufile_src); + qemu_fclose(s->postcopy_qemufile_src); + s->postcopy_qemufile_src =3D NULL; + } + assert(!migration_is_active(s)); =20 if (s->state =3D=3D MIGRATION_STATUS_CANCELLING) { @@ -3237,6 +3269,11 @@ static void migration_completion(MigrationState *s) qemu_savevm_state_complete_postcopy(s->to_dst_file); qemu_mutex_unlock_iothread(); =20 + /* Shutdown the postcopy fast path thread */ + if (migrate_postcopy_preempt()) { + postcopy_preempt_shutdown_file(s); + } + trace_migration_completion_postcopy_end_after_complete(); } else { goto fail; @@ -4124,6 +4161,15 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) } } =20 + /* This needs to be done before resuming a postcopy */ + if (postcopy_preempt_setup(s, &local_err)) { + error_report_err(local_err); + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_FAILED); + migrate_fd_cleanup(s); + return; + } + if (resume) { /* Wakeup the main migration thread to do the recovery */ migrate_set_state(&s->state, MIGRATION_STATUS_POSTCOPY_PAUSED, diff --git a/migration/migration.h b/migration/migration.h index af4bcb19c2..caa910d956 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -23,6 +23,7 @@ #include "io/channel-buffer.h" #include "net/announce.h" #include "qom/object.h" +#include "postcopy-ram.h" =20 struct PostcopyBlocktimeContext; =20 @@ -112,6 +113,11 @@ struct MigrationIncomingState { * enabled. */ unsigned int postcopy_channels; + /* QEMUFile for postcopy only; it'll be handled by a separate thread */ + QEMUFile *postcopy_qemufile_dst; + /* Postcopy priority thread is used to receive postcopy requested page= s */ + QemuThread postcopy_prio_thread; + bool postcopy_prio_thread_created; /* * An array of temp host huge pages to be used, one for each postcopy * channel. @@ -192,6 +198,8 @@ struct MigrationState { QEMUBH *cleanup_bh; /* Protected by qemu_file_lock */ QEMUFile *to_dst_file; + /* Postcopy specific transfer channel */ + QEMUFile *postcopy_qemufile_src; QIOChannelBuffer *bioc; /* * Protects to_dst_file/from_dst_file pointers. We need to make sure = we diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index a66dd536d9..e92db0556b 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -33,6 +33,9 @@ #include "trace.h" #include "hw/boards.h" #include "exec/ramblock.h" +#include "socket.h" +#include "qemu-file-channel.h" +#include "yank_functions.h" =20 /* Arbitrary limit on size of each discard command, * keeps them around ~200 bytes @@ -567,6 +570,11 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingSta= te *mis) { trace_postcopy_ram_incoming_cleanup_entry(); =20 + if (mis->postcopy_prio_thread_created) { + qemu_thread_join(&mis->postcopy_prio_thread); + mis->postcopy_prio_thread_created =3D false; + } + if (mis->have_fault_thread) { Error *local_err =3D NULL; =20 @@ -1102,8 +1110,13 @@ static int postcopy_temp_pages_setup(MigrationIncomi= ngState *mis) int err, i, channels; void *temp_page; =20 - /* TODO: will be boosted when enable postcopy preemption */ - mis->postcopy_channels =3D 1; + if (migrate_postcopy_preempt()) { + /* If preemption enabled, need extra channel for urgent requests */ + mis->postcopy_channels =3D RAM_CHANNEL_MAX; + } else { + /* Both precopy/postcopy on the same channel */ + mis->postcopy_channels =3D 1; + } =20 channels =3D mis->postcopy_channels; mis->postcopy_tmp_pages =3D g_malloc0_n(sizeof(PostcopyTmpPage), chann= els); @@ -1170,7 +1183,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingStat= e *mis) return -1; } =20 - postcopy_thread_create(mis, &mis->fault_thread, "postcopy/fault", + postcopy_thread_create(mis, &mis->fault_thread, "fault-default", postcopy_ram_fault_thread, QEMU_THREAD_JOINABLE= ); mis->have_fault_thread =3D true; =20 @@ -1185,6 +1198,16 @@ int postcopy_ram_incoming_setup(MigrationIncomingSta= te *mis) return -1; } =20 + if (migrate_postcopy_preempt()) { + /* + * This thread needs to be created after the temp pages because + * it'll fetch RAM_CHANNEL_POSTCOPY PostcopyTmpPage immediately. + */ + postcopy_thread_create(mis, &mis->postcopy_prio_thread, "fault-fas= t", + postcopy_preempt_thread, QEMU_THREAD_JOINAB= LE); + mis->postcopy_prio_thread_created =3D true; + } + trace_postcopy_ram_enable_notify(); =20 return 0; @@ -1514,3 +1537,66 @@ void postcopy_unregister_shared_ufd(struct PostCopyF= D *pcfd) } } } + +bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile) +{ + /* + * The new loading channel has its own threads, so it needs to be + * blocked too. It's by default true, just be explicit. + */ + qemu_file_set_blocking(file, true); + mis->postcopy_qemufile_dst =3D file; + trace_postcopy_preempt_new_channel(); + + /* Start the migration immediately */ + return true; +} + +int postcopy_preempt_setup(MigrationState *s, Error **errp) +{ + QIOChannel *ioc; + + if (!migrate_postcopy_preempt()) { + return 0; + } + + if (!migrate_multi_channels_is_allowed()) { + error_setg(errp, "Postcopy preempt is not supported as current " + "migration stream does not support multi-channels."); + return -1; + } + + ioc =3D socket_send_channel_create_sync(errp); + + if (ioc =3D=3D NULL) { + return -1; + } + + migration_ioc_register_yank(ioc); + s->postcopy_qemufile_src =3D qemu_fopen_channel_output(ioc); + + trace_postcopy_preempt_new_channel(); + + return 0; +} + +void *postcopy_preempt_thread(void *opaque) +{ + MigrationIncomingState *mis =3D opaque; + int ret; + + trace_postcopy_preempt_thread_entry(); + + rcu_register_thread(); + + qemu_sem_post(&mis->thread_sync_sem); + + /* Sending RAM_SAVE_FLAG_EOS to terminate this thread */ + ret =3D ram_load_postcopy(mis->postcopy_qemufile_dst, RAM_CHANNEL_POST= COPY); + + rcu_unregister_thread(); + + trace_postcopy_preempt_thread_exit(); + + return ret =3D=3D 0 ? NULL : (void *)-1; +} diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 07684c0e1d..34b1080cde 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -183,4 +183,14 @@ int postcopy_wake_shared(struct PostCopyFD *pcfd, uint= 64_t client_addr, int postcopy_request_shared_page(struct PostCopyFD *pcfd, RAMBlock *rb, uint64_t client_addr, uint64_t offset); =20 +/* Hard-code channels for now for postcopy preemption */ +enum PostcopyChannels { + RAM_CHANNEL_PRECOPY =3D 0, + RAM_CHANNEL_POSTCOPY =3D 1, + RAM_CHANNEL_MAX, +}; + +bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); +int postcopy_preempt_setup(MigrationState *s, Error **errp); + #endif diff --git a/migration/ram.c b/migration/ram.c index a2489a2699..f5615e0a76 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3644,15 +3644,15 @@ int ram_postcopy_incoming_init(MigrationIncomingSta= te *mis) * rcu_read_lock is taken prior to this being called. * * @f: QEMUFile where to send the data + * @channel: the channel to use for loading */ -int ram_load_postcopy(QEMUFile *f) +int ram_load_postcopy(QEMUFile *f, int channel) { int flags =3D 0, ret =3D 0; bool place_needed =3D false; bool matches_target_page_size =3D false; MigrationIncomingState *mis =3D migration_incoming_get_current(); - /* Currently we only use channel 0. TODO: use all the channels */ - PostcopyTmpPage *tmp_page =3D &mis->postcopy_tmp_pages[0]; + PostcopyTmpPage *tmp_page =3D &mis->postcopy_tmp_pages[channel]; =20 while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { ram_addr_t addr; @@ -3676,7 +3676,7 @@ int ram_load_postcopy(QEMUFile *f) flags =3D addr & ~TARGET_PAGE_MASK; addr &=3D TARGET_PAGE_MASK; =20 - trace_ram_load_postcopy_loop((uint64_t)addr, flags); + trace_ram_load_postcopy_loop(channel, (uint64_t)addr, flags); if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE)) { block =3D ram_block_from_stream(mis, f, flags); @@ -3717,10 +3717,10 @@ int ram_load_postcopy(QEMUFile *f) } else if (tmp_page->host_addr !=3D host_page_from_ram_block_offset(block, addr)) { /* not the 1st TP within the HP */ - error_report("Non-same host page detected. " + error_report("Non-same host page detected on channel %d: " "Target host page %p, received host page %p " "(rb %s offset 0x"RAM_ADDR_FMT" target_pages = %d)", - tmp_page->host_addr, + channel, tmp_page->host_addr, host_page_from_ram_block_offset(block, addr), block->idstr, addr, tmp_page->target_pages); ret =3D -EINVAL; @@ -4107,7 +4107,12 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) */ WITH_RCU_READ_LOCK_GUARD() { if (postcopy_running) { - ret =3D ram_load_postcopy(f); + /* + * Note! Here RAM_CHANNEL_PRECOPY is the precopy channel of + * postcopy migration, we have another RAM_CHANNEL_POSTCOPY to + * service fast page faults. + */ + ret =3D ram_load_postcopy(f, RAM_CHANNEL_PRECOPY); } else { ret =3D ram_load_precopy(f); } @@ -4269,6 +4274,12 @@ static int ram_resume_prepare(MigrationState *s, voi= d *opaque) return 0; } =20 +void postcopy_preempt_shutdown_file(MigrationState *s) +{ + qemu_put_be64(s->postcopy_qemufile_src, RAM_SAVE_FLAG_EOS); + qemu_fflush(s->postcopy_qemufile_src); +} + static SaveVMHandlers savevm_ram_handlers =3D { .save_setup =3D ram_save_setup, .save_live_iterate =3D ram_save_iterate, diff --git a/migration/ram.h b/migration/ram.h index ded0a3a086..5d90945a6e 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -61,7 +61,7 @@ void ram_postcopy_send_discard_bitmap(MigrationState *ms); /* For incoming postcopy discard */ int ram_discard_range(const char *block_name, uint64_t start, size_t lengt= h); int ram_postcopy_incoming_init(MigrationIncomingState *mis); -int ram_load_postcopy(QEMUFile *f); +int ram_load_postcopy(QEMUFile *f, int channel); =20 void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); =20 @@ -73,6 +73,8 @@ int64_t ramblock_recv_bitmap_send(QEMUFile *file, const char *block_name); int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *rb); bool ramblock_page_is_discarded(RAMBlock *rb, ram_addr_t start); +void postcopy_preempt_shutdown_file(MigrationState *s); +void *postcopy_preempt_thread(void *opaque); =20 /* ram cache */ int colo_init_ram_cache(void); diff --git a/migration/savevm.c b/migration/savevm.c index d9076897b8..ecee05e631 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2575,16 +2575,6 @@ static bool postcopy_pause_incoming(MigrationIncomin= gState *mis) { int i; =20 - /* - * If network is interrupted, any temp page we received will be useless - * because we didn't mark them as "received" in receivedmap. After a - * proper recovery later (which will sync src dirty bitmap with receiv= edmap - * on dest) these cached small pages will be resent again. - */ - for (i =3D 0; i < mis->postcopy_channels; i++) { - postcopy_temp_page_reset(&mis->postcopy_tmp_pages[i]); - } - trace_postcopy_pause_incoming(); =20 assert(migrate_postcopy_ram()); @@ -2613,6 +2603,16 @@ static bool postcopy_pause_incoming(MigrationIncomin= gState *mis) /* Notify the fault thread for the invalidated file handle */ postcopy_fault_thread_notify(mis); =20 + /* + * If network is interrupted, any temp page we received will be useless + * because we didn't mark them as "received" in receivedmap. After a + * proper recovery later (which will sync src dirty bitmap with receiv= edmap + * on dest) these cached small pages will be resent again. + */ + for (i =3D 0; i < mis->postcopy_channels; i++) { + postcopy_temp_page_reset(&mis->postcopy_tmp_pages[i]); + } + error_report("Detected IO failure for postcopy. " "Migration paused."); =20 diff --git a/migration/socket.c b/migration/socket.c index 05705a32d8..a7f345b353 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -26,7 +26,7 @@ #include "io/channel-socket.h" #include "io/net-listener.h" #include "trace.h" - +#include "postcopy-ram.h" =20 struct SocketOutgoingArgs { SocketAddress *saddr; @@ -39,6 +39,24 @@ void socket_send_channel_create(QIOTaskFunc f, void *dat= a) f, data, NULL, NULL); } =20 +QIOChannel *socket_send_channel_create_sync(Error **errp) +{ + QIOChannelSocket *sioc =3D qio_channel_socket_new(); + + if (!outgoing_args.saddr) { + object_unref(OBJECT(sioc)); + error_setg(errp, "Initial sock address not set!"); + return NULL; + } + + if (qio_channel_socket_connect_sync(sioc, outgoing_args.saddr, errp) <= 0) { + object_unref(OBJECT(sioc)); + return NULL; + } + + return QIO_CHANNEL(sioc); +} + int socket_send_channel_destroy(QIOChannel *send) { /* Remove channel */ @@ -158,6 +176,8 @@ socket_start_incoming_migration_internal(SocketAddress = *saddr, =20 if (migrate_use_multifd()) { num =3D migrate_multifd_channels(); + } else if (migrate_postcopy_preempt()) { + num =3D RAM_CHANNEL_MAX; } =20 if (qio_net_listener_open_sync(listener, saddr, num, errp) < 0) { diff --git a/migration/socket.h b/migration/socket.h index 891dbccceb..dc54df4e6c 100644 --- a/migration/socket.h +++ b/migration/socket.h @@ -21,6 +21,7 @@ #include "io/task.h" =20 void socket_send_channel_create(QIOTaskFunc f, void *data); +QIOChannel *socket_send_channel_create_sync(Error **errp); int socket_send_channel_destroy(QIOChannel *send); =20 void socket_start_incoming_migration(const char *str, Error **errp); diff --git a/migration/trace-events b/migration/trace-events index 1aec580e92..4bc787cf0c 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -91,7 +91,7 @@ migration_bitmap_clear_dirty(char *str, uint64_t start, u= int64_t size, unsigned migration_throttle(void) "" ram_discard_range(const char *rbname, uint64_t start, size_t len) "%s: sta= rt: %" PRIx64 " %zx" ram_load_loop(const char *rbname, uint64_t addr, int flags, void *host) "%= s: addr: 0x%" PRIx64 " flags: 0x%x host: %p" -ram_load_postcopy_loop(uint64_t addr, int flags) "@%" PRIx64 " %x" +ram_load_postcopy_loop(int channel, uint64_t addr, int flags) "chan=3D%d a= ddr=3D0x%" PRIx64 " flags=3D0x%x" ram_postcopy_send_discard_bitmap(void) "" ram_save_page(const char *rbname, uint64_t offset, void *host) "%s: offset= : 0x%" PRIx64 " host: %p" ram_save_queue_pages(const char *rbname, size_t start, size_t len) "%s: st= art: 0x%zx len: 0x%zx" @@ -278,6 +278,9 @@ postcopy_request_shared_page(const char *sharer, const = char *rb, uint64_t rb_off postcopy_request_shared_page_present(const char *sharer, const char *rb, u= int64_t rb_offset) "%s already %s offset 0x%"PRIx64 postcopy_wake_shared(uint64_t client_addr, const char *rb) "at 0x%"PRIx64"= in %s" postcopy_page_req_del(void *addr, int count) "resolved page req %p total %= d" +postcopy_preempt_new_channel(void) "" +postcopy_preempt_thread_entry(void) "" +postcopy_preempt_thread_exit(void) "" =20 get_mem_fault_cpu_index(int cpu, uint32_t pid) "cpu: %d, pid: %u" =20 --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930518351124.89001880957267; Mon, 25 Apr 2022 16:48:38 -0700 (PDT) Received: from localhost ([::1]:35900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8RZ-0004Xb-21 for importer@patchew.org; Mon, 25 Apr 2022 19:48:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IQ-0007MD-0f for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39355) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IM-0007kt-UB for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:09 -0400 Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-591-nC7TI4o6MumwO9AGrdqdcA-1; Mon, 25 Apr 2022 19:39:05 -0400 Received: by mail-il1-f199.google.com with SMTP id j7-20020a056e02218700b002cd9e2f0ac7so1472362ila.16 for ; Mon, 25 Apr 2022 16:39:05 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ICyA2vtBfkJt/z2/jdR+KPX9Y/XCMeACN4O8urPf8xw=; b=RlDYuYhDBSJiyfLX9PuWJcRIsRjuiv/3VZ4HFaTt6qlsGOEidrLVjJ1ValBL/OGfpwiViE pLF8KAbOaUEszfbqG4he96Ywg5AH6jRG6ioE+3kCtFDuvNoJLGHY8aiWhlcL+Sq68cGaNw qYcKj/HxKhEuQk8VY6V0My67uvFvNDg= X-MC-Unique: nC7TI4o6MumwO9AGrdqdcA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ICyA2vtBfkJt/z2/jdR+KPX9Y/XCMeACN4O8urPf8xw=; b=PIWIlVbd3hrSR1afdRFp4FTEkWd6Y5Ab7O3+InAkbp6oKCzzB8rbl8lKhp1pDAaM7j YB2sBZGlKNeUnsAmlHR49yNfcG+pCpYstjUA58ezm5EaW8Zqkxdq2/U91aOFzeWKkEPl LkUSfh7e8oc0RVGkJNfkjW4wN0sGdM7gbD3ytBG7mSTT1583tbt4uYZiO/RFkIX0t2qd lteXXofx8sguNkvDOPTQb+dD8CKuYnn9W+7ncYsG7Leufh+otYZNc6DKvrJAg31Sbkt4 +2xkEuo2CnaosbZyY07DpEUcazmsOycfIhCloTyZJnKu+5IlALnOu1b/kECqsHAOpIap PvOQ== X-Gm-Message-State: AOAM532/pm48/dd75bRENlbLyih/0M/LtIj6sN623H2Iy86j0mUEebe7 uz+0UeNvEq8UrnDhnEAp8laxlDXAFtUjqhtGqdRINiN4WxcVOsKGfJSlYwndrMWnlRVcMI1drIK 0E6ndnfa1l2ElHIe6kBSlnljtmdu/iJwxJ8hHpdHXw2tKcJV4bbO/g1/7BXhLtsc2 X-Received: by 2002:a05:6602:1489:b0:657:45a8:f428 with SMTP id a9-20020a056602148900b0065745a8f428mr8131055iow.157.1650929944159; Mon, 25 Apr 2022 16:39:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbAd/yc6t/AzQ+NF9CIDqaZ8OBv3mMdoUhPP1F99ghTDrbTaneNCvhxJYZj7WmRweT/BC4yg== X-Received: by 2002:a05:6602:1489:b0:657:45a8:f428 with SMTP id a9-20020a056602148900b0065745a8f428mr8131035iow.157.1650929943478; Mon, 25 Apr 2022 16:39:03 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 12/21] migration: Postcopy preemption enablement Date: Mon, 25 Apr 2022 19:38:38 -0400 Message-Id: <20220425233847.10393-13-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930520391100003 Content-Type: text/plain; charset="utf-8" This patch enables postcopy-preempt feature. It contains two major changes to the migration logic: (1) Postcopy requests are now sent via a different socket from precopy background migration stream, so as to be isolated from very high page request delays. (2) For huge page enabled hosts: when there's postcopy requests, they can n= ow intercept a partial sending of huge host pages on src QEMU. After this patch, we'll live migrate a VM with two channels for postcopy: (= 1) PRECOPY channel, which is the default channel that transfers background pag= es; and (2) POSTCOPY channel, which only transfers requested pages. There's no strict rule of which channel to use, e.g., if a requested page is already being transferred on precopy channel, then we will keep using the s= ame precopy channel to transfer the page even if it's explicitly requested. In= 99% of the cases we'll prioritize the channels so we send requested page via the postcopy channel as long as possible. On the source QEMU, when we found a postcopy request, we'll interrupt the PRECOPY channel sending process and quickly switch to the POSTCOPY channel. After we serviced all the high priority postcopy pages, we'll switch back to PRECOPY channel so that we'll continue to send the interrupted huge page ag= ain. There's no new thread introduced on src QEMU. On the destination QEMU, one new thread is introduced to receive page data = from the postcopy specific socket (done in the preparation patch). This patch has a side effect: after sending postcopy pages, previously we'll assume the guest will access follow up pages so we'll keep sending from the= re. Now it's changed. Instead of going on with a postcopy requested page, we'l= l go back and continue sending the precopy huge page (which can be intercepted b= y a postcopy request so the huge page can be sent partially before). Whether that's a problem is debatable, because "assuming the guest will continue to access the next page" may not really suite when huge pages are used, especially if the huge page is large (e.g. 1GB pages). So that local= ity hint is much meaningless if huge pages are used. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/migration.c | 2 + migration/migration.h | 2 +- migration/ram.c | 251 +++++++++++++++++++++++++++++++++++++++-- migration/trace-events | 7 ++ 4 files changed, 253 insertions(+), 9 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index e27aa306bc..8264b03d4d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3157,6 +3157,8 @@ static int postcopy_start(MigrationState *ms) MIGRATION_STATUS_FAILED); } =20 + trace_postcopy_preempt_enabled(migrate_postcopy_preempt()); + return ret; =20 fail_closefb: diff --git a/migration/migration.h b/migration/migration.h index caa910d956..b8aacfe3af 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -68,7 +68,7 @@ typedef struct { struct MigrationIncomingState { QEMUFile *from_src_file; /* Previously received RAM's RAMBlock pointer */ - RAMBlock *last_recv_block; + RAMBlock *last_recv_block[RAM_CHANNEL_MAX]; /* A hook to allow cleanup at the end of incoming migration */ void *transport_data; void (*transport_cleanup)(void *data); diff --git a/migration/ram.c b/migration/ram.c index f5615e0a76..a4b39e3675 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -295,6 +295,20 @@ struct RAMSrcPageRequest { QSIMPLEQ_ENTRY(RAMSrcPageRequest) next_req; }; =20 +typedef struct { + /* + * Cached ramblock/offset values if preempted. They're only meaningfu= l if + * preempted=3D=3Dtrue below. + */ + RAMBlock *ram_block; + unsigned long ram_page; + /* + * Whether a postcopy preemption just happened. Will be reset after + * precopy recovered to background migration. + */ + bool preempted; +} PostcopyPreemptState; + /* State of RAM for migration */ struct RAMState { /* QEMUFile used for this migration */ @@ -349,6 +363,14 @@ struct RAMState { /* Queue of outstanding page requests from the destination */ QemuMutex src_page_req_mutex; QSIMPLEQ_HEAD(, RAMSrcPageRequest) src_page_requests; + + /* Postcopy preemption informations */ + PostcopyPreemptState postcopy_preempt_state; + /* + * Current channel we're using on src VM. Only valid if postcopy-pree= mpt + * is enabled. + */ + unsigned int postcopy_channel; }; typedef struct RAMState RAMState; =20 @@ -356,6 +378,11 @@ static RAMState *ram_state; =20 static NotifierWithReturnList precopy_notifier_list; =20 +static void postcopy_preempt_reset(RAMState *rs) +{ + memset(&rs->postcopy_preempt_state, 0, sizeof(PostcopyPreemptState)); +} + /* Whether postcopy has queued requests? */ static bool postcopy_has_request(RAMState *rs) { @@ -1947,6 +1974,55 @@ void ram_write_tracking_stop(void) } #endif /* defined(__linux__) */ =20 +/* + * Check whether two addr/offset of the ramblock falls onto the same host = huge + * page. Returns true if so, false otherwise. + */ +static bool offset_on_same_huge_page(RAMBlock *rb, uint64_t addr1, + uint64_t addr2) +{ + size_t page_size =3D qemu_ram_pagesize(rb); + + addr1 =3D ROUND_DOWN(addr1, page_size); + addr2 =3D ROUND_DOWN(addr2, page_size); + + return addr1 =3D=3D addr2; +} + +/* + * Whether a previous preempted precopy huge page contains current request= ed + * page? Returns true if so, false otherwise. + * + * This should really happen very rarely, because it means when we were se= nding + * during background migration for postcopy we're sending exactly the page= that + * some vcpu got faulted on on dest node. When it happens, we probably do= n't + * need to do much but drop the request, because we know right after we re= store + * the precopy stream it'll be serviced. It'll slightly affect the order = of + * postcopy requests to be serviced (e.g. it'll be the same as we move cur= rent + * request to the end of the queue) but it shouldn't be a big deal. The m= ost + * imporant thing is we can _never_ try to send a partial-sent huge page o= n the + * POSTCOPY channel again, otherwise that huge page will got "split brain"= on + * two channels (PRECOPY, POSTCOPY). + */ +static bool postcopy_preempted_contains(RAMState *rs, RAMBlock *block, + ram_addr_t offset) +{ + PostcopyPreemptState *state =3D &rs->postcopy_preempt_state; + + /* No preemption at all? */ + if (!state->preempted) { + return false; + } + + /* Not even the same ramblock? */ + if (state->ram_block !=3D block) { + return false; + } + + return offset_on_same_huge_page(block, offset, + state->ram_page << TARGET_PAGE_BITS); +} + /** * get_queued_page: unqueue a page from the postcopy requests * @@ -1962,9 +2038,17 @@ static bool get_queued_page(RAMState *rs, PageSearch= Status *pss) RAMBlock *block; ram_addr_t offset; =20 +again: block =3D unqueue_page(rs, &offset); =20 - if (!block) { + if (block) { + /* See comment above postcopy_preempted_contains() */ + if (postcopy_preempted_contains(rs, block, offset)) { + trace_postcopy_preempt_hit(block->idstr, offset); + /* This request is dropped */ + goto again; + } + } else { /* * Poll write faults too if background snapshot is enabled; that's * when we have vcpus got blocked by the write protected pages. @@ -2180,6 +2264,117 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) return ram_save_page(rs, pss); } =20 +static bool postcopy_needs_preempt(RAMState *rs, PageSearchStatus *pss) +{ + /* Not enabled eager preempt? Then never do that. */ + if (!migrate_postcopy_preempt()) { + return false; + } + + /* If the ramblock we're sending is a small page? Never bother. */ + if (qemu_ram_pagesize(pss->block) =3D=3D TARGET_PAGE_SIZE) { + return false; + } + + /* Not in postcopy at all? */ + if (!migration_in_postcopy()) { + return false; + } + + /* + * If we're already handling a postcopy request, don't preempt as this= page + * has got the same high priority. + */ + if (pss->postcopy_requested) { + return false; + } + + /* If there's postcopy requests, then check it up! */ + return postcopy_has_request(rs); +} + +/* Returns true if we preempted precopy, false otherwise */ +static void postcopy_do_preempt(RAMState *rs, PageSearchStatus *pss) +{ + PostcopyPreemptState *p_state =3D &rs->postcopy_preempt_state; + + trace_postcopy_preempt_triggered(pss->block->idstr, pss->page); + + /* + * Time to preempt precopy. Cache current PSS into preempt state, so t= hat + * after handling the postcopy pages we can recover to it. We need to= do + * so because the dest VM will have partial of the precopy huge page k= ept + * over in its tmp huge page caches; better move on with it when we ca= n. + */ + p_state->ram_block =3D pss->block; + p_state->ram_page =3D pss->page; + p_state->preempted =3D true; +} + +/* Whether we're preempted by a postcopy request during sending a huge pag= e */ +static bool postcopy_preempt_triggered(RAMState *rs) +{ + return rs->postcopy_preempt_state.preempted; +} + +static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss) +{ + PostcopyPreemptState *state =3D &rs->postcopy_preempt_state; + + assert(state->preempted); + + pss->block =3D state->ram_block; + pss->page =3D state->ram_page; + /* This is not a postcopy request but restoring previous precopy */ + pss->postcopy_requested =3D false; + + trace_postcopy_preempt_restored(pss->block->idstr, pss->page); + + /* Reset preempt state, most importantly, set preempted=3D=3Dfalse */ + postcopy_preempt_reset(rs); +} + +static void postcopy_preempt_choose_channel(RAMState *rs, PageSearchStatus= *pss) +{ + MigrationState *s =3D migrate_get_current(); + unsigned int channel; + QEMUFile *next; + + channel =3D pss->postcopy_requested ? + RAM_CHANNEL_POSTCOPY : RAM_CHANNEL_PRECOPY; + + if (channel !=3D rs->postcopy_channel) { + if (channel =3D=3D RAM_CHANNEL_PRECOPY) { + next =3D s->to_dst_file; + } else { + next =3D s->postcopy_qemufile_src; + } + /* Update and cache the current channel */ + rs->f =3D next; + rs->postcopy_channel =3D channel; + + /* + * If channel switched, reset last_sent_block since the old sent b= lock + * may not be on the same channel. + */ + rs->last_sent_block =3D NULL; + + trace_postcopy_preempt_switch_channel(channel); + } + + trace_postcopy_preempt_send_host_page(pss->block->idstr, pss->page); +} + +/* We need to make sure rs->f always points to the default channel elsewhe= re */ +static void postcopy_preempt_reset_channel(RAMState *rs) +{ + if (migrate_postcopy_preempt() && migration_in_postcopy()) { + rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; + rs->f =3D migrate_get_current()->to_dst_file; + trace_postcopy_preempt_reset_channel(); + } +} + /** * ram_save_host_page: save a whole host page * @@ -2211,7 +2406,16 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) return 0; } =20 + if (migrate_postcopy_preempt() && migration_in_postcopy()) { + postcopy_preempt_choose_channel(rs, pss); + } + do { + if (postcopy_needs_preempt(rs, pss)) { + postcopy_do_preempt(rs, pss); + break; + } + /* Check the pages is dirty and if it is send it */ if (migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { tmppages =3D ram_save_target_page(rs, pss); @@ -2235,6 +2439,19 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) /* The offset we leave with is the min boundary of host page and block= */ pss->page =3D MIN(pss->page, hostpage_boundary); =20 + /* + * When with postcopy preempt mode, flush the data as soon as possible= for + * postcopy requests, because we've already sent a whole huge page, so= the + * dst node should already have enough resource to atomically filling = in + * the current missing page. + * + * More importantly, when using separate postcopy channel, we must do + * explicit flush or it won't flush until the buffer is full. + */ + if (migrate_postcopy_preempt() && pss->postcopy_requested) { + qemu_fflush(rs->f); + } + res =3D ram_save_release_protection(rs, pss, start_page); return (res < 0 ? res : pages); } @@ -2276,8 +2493,17 @@ static int ram_find_and_save_block(RAMState *rs) found =3D get_queued_page(rs, &pss); =20 if (!found) { - /* priority queue empty, so just search for something dirty */ - found =3D find_dirty_block(rs, &pss, &again); + /* + * Recover previous precopy ramblock/offset if postcopy has + * preempted precopy. Otherwise find the next dirty bit. + */ + if (postcopy_preempt_triggered(rs)) { + postcopy_preempt_restore(rs, &pss); + found =3D true; + } else { + /* priority queue empty, so just search for something dirt= y */ + found =3D find_dirty_block(rs, &pss, &again); + } } =20 if (found) { @@ -2405,6 +2631,8 @@ static void ram_state_reset(RAMState *rs) rs->last_page =3D 0; rs->last_version =3D ram_list.version; rs->xbzrle_enabled =3D false; + postcopy_preempt_reset(rs); + rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; } =20 #define MAX_WAIT 50 /* ms, half buffered_file limit */ @@ -3043,6 +3271,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } qemu_mutex_unlock(&rs->bitmap_mutex); =20 + postcopy_preempt_reset_channel(rs); + /* * Must occur before EOS (or any QEMUFile operation) * because of RDMA protocol. @@ -3112,6 +3342,8 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) ram_control_after_iterate(f, RAM_CONTROL_FINISH); } =20 + postcopy_preempt_reset_channel(rs); + if (ret >=3D 0) { multifd_send_sync_main(rs->f); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); @@ -3194,11 +3426,13 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr= , void *host) * @mis: the migration incoming state pointer * @f: QEMUFile where to read the data from * @flags: Page flags (mostly to see if it's a continuation of previous bl= ock) + * @channel: the channel we're using */ static inline RAMBlock *ram_block_from_stream(MigrationIncomingState *mis, - QEMUFile *f, int flags) + QEMUFile *f, int flags, + int channel) { - RAMBlock *block =3D mis->last_recv_block; + RAMBlock *block =3D mis->last_recv_block[channel]; char id[256]; uint8_t len; =20 @@ -3225,7 +3459,7 @@ static inline RAMBlock *ram_block_from_stream(Migrati= onIncomingState *mis, return NULL; } =20 - mis->last_recv_block =3D block; + mis->last_recv_block[channel] =3D block; =20 return block; } @@ -3679,7 +3913,7 @@ int ram_load_postcopy(QEMUFile *f, int channel) trace_ram_load_postcopy_loop(channel, (uint64_t)addr, flags); if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE)) { - block =3D ram_block_from_stream(mis, f, flags); + block =3D ram_block_from_stream(mis, f, flags, channel); if (!block) { ret =3D -EINVAL; break; @@ -3930,7 +4164,8 @@ static int ram_load_precopy(QEMUFile *f) =20 if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) { - RAMBlock *block =3D ram_block_from_stream(mis, f, flags); + RAMBlock *block =3D ram_block_from_stream(mis, f, flags, + RAM_CHANNEL_PRECOPY); =20 host =3D host_from_ram_block_offset(block, addr); /* diff --git a/migration/trace-events b/migration/trace-events index 4bc787cf0c..69f311169a 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -111,6 +111,12 @@ ram_load_complete(int ret, uint64_t seq_iter) "exit_co= de %d seq iteration %" PRI ram_write_tracking_ramblock_start(const char *block_id, size_t page_size, = void *addr, size_t length) "%s: page_size: %zu addr: %p length: %zu" ram_write_tracking_ramblock_stop(const char *block_id, size_t page_size, v= oid *addr, size_t length) "%s: page_size: %zu addr: %p length: %zu" unqueue_page(char *block, uint64_t offset, bool dirty) "ramblock '%s' offs= et 0x%"PRIx64" dirty %d" +postcopy_preempt_triggered(char *str, unsigned long page) "during sending = ramblock %s offset 0x%lx" +postcopy_preempt_restored(char *str, unsigned long page) "ramblock %s offs= et 0x%lx" +postcopy_preempt_hit(char *str, uint64_t offset) "ramblock %s offset 0x%"P= RIx64 +postcopy_preempt_send_host_page(char *str, uint64_t offset) "ramblock %s o= ffset 0x%"PRIx64 +postcopy_preempt_switch_channel(int channel) "%d" +postcopy_preempt_reset_channel(void) "" =20 # multifd.c multifd_new_send_channel_async(uint8_t id) "channel %u" @@ -176,6 +182,7 @@ migration_thread_low_pending(uint64_t pending) "%" PRIu= 64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, uint64_t ban= dwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " band= width %" PRIu64 " max_size %" PRId64 process_incoming_migration_co_end(int ret, int ps) "ret=3D%d postcopy-stat= e=3D%d" process_incoming_migration_co_postcopy_end_main(void) "" +postcopy_preempt_enabled(bool value) "%d" =20 # channel.c migration_set_incoming_channel(void *ioc, const char *ioctype) "ioc=3D%p i= octype=3D%s" --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930585667868.9111095018898; Mon, 25 Apr 2022 16:49:45 -0700 (PDT) Received: from localhost ([::1]:39234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Sd-0006lx-8V for importer@patchew.org; Mon, 25 Apr 2022 19:49:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IQ-0007Ms-9h for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24825) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IN-0007l1-Qn for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:09 -0400 Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-330-EATrXA_RN-mPHx3oxmgPjw-1; Mon, 25 Apr 2022 19:39:06 -0400 Received: by mail-il1-f200.google.com with SMTP id 7-20020a056e0220c700b002cd8179e79dso2096850ilq.7 for ; Mon, 25 Apr 2022 16:39:05 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4WpCe/XE1KQWMMV0faD+58O0d22460mMHj1rl90L8fQ=; b=T0yDTv0t9cAqOZzbYnEnTUBb9jyzUnL10S0hjV4oP+eao3upSl553/32ATiNdoHNheTQaH n1P0Z2sdIp85YaEzeJ49PE3vxcRS/0XXon24JpvMSxRTL4igX1p7knsdFhFCC4W7gVHtdU NzfRRFZYiGoWq0MC7D6IZ4v8MOQ8v8U= X-MC-Unique: EATrXA_RN-mPHx3oxmgPjw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4WpCe/XE1KQWMMV0faD+58O0d22460mMHj1rl90L8fQ=; b=oVpTHAXxLYKSPGx90gvfLuU8Q7PguCz7/rY2iAF4T4DAQGpYt2bFpP7yBpxqgGq2Nl sDhreCHlZE8j2wC+ou1rlF5ScqX+nlbXtERlsdCxy0BZ0b5X0LvswbklabcUofRiVigX sKuZ/lVj5iP6/6rSo7xkO4iMdKe+vFe8zS/dVpE3GBgNjSCfLIt95odfT3wrFqHseE94 xPrRGDHSRzt+iA4lYcShhN0GsYDH/sgYnPbKj4N05E37mqwTd0fwBAzLLihEpmmc1oIp A7Mf/uXHeuAlIzhUpuZeKvd2vLjGFanqxpYb+RenvtAeu2MyhV3IRNSvTUprBwoeTJs9 Emkw== X-Gm-Message-State: AOAM533S7omlYqGjz3Ug6zBwowxKBIXpyYuDrUC+SDPw7g9cyYDmbJHI ZxQoM83k/i6ZMzYuRlCarptJY2RA01DxHPY2TLtaaE3wTm2iVVlno0cWd+39ZJ77rMeuutmBMtV fwNWuNk/kUiO315X4dPuJU+NhY4aZKUKsmgkGoDREU8HzyZ6+jLwS6i4EUKp68Lew X-Received: by 2002:a05:6e02:1847:b0:2cd:9343:8363 with SMTP id b7-20020a056e02184700b002cd93438363mr3375946ilv.298.1650929944992; Mon, 25 Apr 2022 16:39:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVq5p+AVtbbhQxrkO7+WppJ7lBj78MpEA3d0qGV/lR5MnO41WWsspv1aPOBDnhszQYwUG/kg== X-Received: by 2002:a05:6e02:1847:b0:2cd:9343:8363 with SMTP id b7-20020a056e02184700b002cd93438363mr3375927ilv.298.1650929944540; Mon, 25 Apr 2022 16:39:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 13/21] migration: Postcopy recover with preempt enabled Date: Mon, 25 Apr 2022 19:38:39 -0400 Message-Id: <20220425233847.10393-14-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930586797100001 Content-Type: text/plain; charset="utf-8" To allow postcopy recovery, the ram fast load (preempt-only) dest QEMU thre= ad needs similar handling on fault tolerance. When ram_load_postcopy() fails, instead of stopping the thread it halts with a semaphore, preparing to be kicked again when recovery is detected. A mutex is introduced to make sure there's no concurrent operation upon the socket. To make it simple, the fast ram load thread will take the mutex du= ring its whole procedure, and only release it if it's paused. The fast-path soc= ket will be properly released by the main loading thread safely when there's network failures during postcopy with that mutex held. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/migration.c | 27 +++++++++++++++++++++++---- migration/migration.h | 19 +++++++++++++++++++ migration/postcopy-ram.c | 25 +++++++++++++++++++++++-- migration/qemu-file.c | 27 +++++++++++++++++++++++++++ migration/qemu-file.h | 1 + migration/savevm.c | 26 ++++++++++++++++++++++++-- migration/trace-events | 2 ++ 7 files changed, 119 insertions(+), 8 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 8264b03d4d..a0db5de685 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -215,9 +215,11 @@ void migration_object_init(void) current_incoming->postcopy_remote_fds =3D g_array_new(FALSE, TRUE, sizeof(struct PostCopyFD)); qemu_mutex_init(¤t_incoming->rp_mutex); + qemu_mutex_init(¤t_incoming->postcopy_prio_thread_mutex); qemu_event_init(¤t_incoming->main_thread_load_event, false); qemu_sem_init(¤t_incoming->postcopy_pause_sem_dst, 0); qemu_sem_init(¤t_incoming->postcopy_pause_sem_fault, 0); + qemu_sem_init(¤t_incoming->postcopy_pause_sem_fast_load, 0); qemu_mutex_init(¤t_incoming->page_request_mutex); current_incoming->page_requested =3D g_tree_new(page_request_addr_cmp); =20 @@ -697,9 +699,9 @@ static bool postcopy_try_recover(void) =20 /* * Here, we only wake up the main loading thread (while the - * fault thread will still be waiting), so that we can receive + * rest threads will still be waiting), so that we can receive * commands from source now, and answer it if needed. The - * fault thread will be woken up afterwards until we are sure + * rest threads will be woken up afterwards until we are sure * that source is ready to reply to page requests. */ qemu_sem_post(&mis->postcopy_pause_sem_dst); @@ -3470,6 +3472,18 @@ static MigThrError postcopy_pause(MigrationState *s) qemu_file_shutdown(file); qemu_fclose(file); =20 + /* + * Do the same to postcopy fast path socket too if there is. No + * locking needed because no racer as long as we do this before se= tting + * status to paused. + */ + if (s->postcopy_qemufile_src) { + migration_ioc_unregister_yank_from_file(s->postcopy_qemufile_s= rc); + qemu_file_shutdown(s->postcopy_qemufile_src); + qemu_fclose(s->postcopy_qemufile_src); + s->postcopy_qemufile_src =3D NULL; + } + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_POSTCOPY_PAUSED); =20 @@ -3525,8 +3539,13 @@ static MigThrError migration_detect_error(MigrationS= tate *s) return MIG_THR_ERR_FATAL; } =20 - /* Try to detect any file errors */ - ret =3D qemu_file_get_error_obj(s->to_dst_file, &local_error); + /* + * Try to detect any file errors. Note that postcopy_qemufile_src will + * be NULL when postcopy preempt is not enabled. + */ + ret =3D qemu_file_get_error_obj_any(s->to_dst_file, + s->postcopy_qemufile_src, + &local_error); if (!ret) { /* Everything is fine */ assert(!local_error); diff --git a/migration/migration.h b/migration/migration.h index b8aacfe3af..91f845e9e4 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -118,6 +118,18 @@ struct MigrationIncomingState { /* Postcopy priority thread is used to receive postcopy requested page= s */ QemuThread postcopy_prio_thread; bool postcopy_prio_thread_created; + /* + * Used to sync between the ram load main thread and the fast ram load + * thread. It protects postcopy_qemufile_dst, which is the postcopy + * fast channel. + * + * The ram fast load thread will take it mostly for the whole lifecycle + * because it needs to continuously read data from the channel, and + * it'll only release this mutex if postcopy is interrupted, so that + * the ram load main thread will take this mutex over and properly + * release the broken channel. + */ + QemuMutex postcopy_prio_thread_mutex; /* * An array of temp host huge pages to be used, one for each postcopy * channel. @@ -147,6 +159,13 @@ struct MigrationIncomingState { /* notify PAUSED postcopy incoming migrations to try to continue */ QemuSemaphore postcopy_pause_sem_dst; QemuSemaphore postcopy_pause_sem_fault; + /* + * This semaphore is used to allow the ram fast load thread (only when + * postcopy preempt is enabled) fall into sleep when there's network + * interruption detected. When the recovery is done, the main load + * thread will kick the fast ram load thread using this semaphore. + */ + QemuSemaphore postcopy_pause_sem_fast_load; =20 /* List of listening socket addresses */ SocketAddressList *socket_address_list; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index e92db0556b..b3c81b46f6 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1580,6 +1580,15 @@ int postcopy_preempt_setup(MigrationState *s, Error = **errp) return 0; } =20 +static void postcopy_pause_ram_fast_load(MigrationIncomingState *mis) +{ + trace_postcopy_pause_fast_load(); + qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); + qemu_sem_wait(&mis->postcopy_pause_sem_fast_load); + qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); + trace_postcopy_pause_fast_load_continued(); +} + void *postcopy_preempt_thread(void *opaque) { MigrationIncomingState *mis =3D opaque; @@ -1592,11 +1601,23 @@ void *postcopy_preempt_thread(void *opaque) qemu_sem_post(&mis->thread_sync_sem); =20 /* Sending RAM_SAVE_FLAG_EOS to terminate this thread */ - ret =3D ram_load_postcopy(mis->postcopy_qemufile_dst, RAM_CHANNEL_POST= COPY); + qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); + while (1) { + ret =3D ram_load_postcopy(mis->postcopy_qemufile_dst, + RAM_CHANNEL_POSTCOPY); + /* If error happened, go into recovery routine */ + if (ret) { + postcopy_pause_ram_fast_load(mis); + } else { + /* We're done */ + break; + } + } + qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); =20 rcu_unregister_thread(); =20 trace_postcopy_preempt_thread_exit(); =20 - return ret =3D=3D 0 ? NULL : (void *)-1; + return NULL; } diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 1479cddad9..397652f0ba 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -139,6 +139,33 @@ int qemu_file_get_error_obj(QEMUFile *f, Error **errp) return f->last_error; } =20 +/* + * Get last error for either stream f1 or f2 with optional Error*. + * The error returned (non-zero) can be either from f1 or f2. + * + * If any of the qemufile* is NULL, then skip the check on that file. + * + * When there is no error on both qemufile, zero is returned. + */ +int qemu_file_get_error_obj_any(QEMUFile *f1, QEMUFile *f2, Error **errp) +{ + int ret =3D 0; + + if (f1) { + ret =3D qemu_file_get_error_obj(f1, errp); + /* If there's already error detected, return */ + if (ret) { + return ret; + } + } + + if (f2) { + ret =3D qemu_file_get_error_obj(f2, errp); + } + + return ret; +} + /* * Set the last error for stream f with optional Error* */ diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 3f36d4dc8c..2564e5e1c7 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -156,6 +156,7 @@ void qemu_file_update_transfer(QEMUFile *f, int64_t len= ); void qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate); int64_t qemu_file_get_rate_limit(QEMUFile *f); int qemu_file_get_error_obj(QEMUFile *f, Error **errp); +int qemu_file_get_error_obj_any(QEMUFile *f1, QEMUFile *f2, Error **errp); void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err); void qemu_file_set_error(QEMUFile *f, int ret); int qemu_file_shutdown(QEMUFile *f); diff --git a/migration/savevm.c b/migration/savevm.c index ecee05e631..050874650a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2152,6 +2152,13 @@ static int loadvm_postcopy_handle_resume(MigrationIn= comingState *mis) */ qemu_sem_post(&mis->postcopy_pause_sem_fault); =20 + if (migrate_postcopy_preempt()) { + /* The channel should already be setup again; make sure of it */ + assert(mis->postcopy_qemufile_dst); + /* Kick the fast ram load thread too */ + qemu_sem_post(&mis->postcopy_pause_sem_fast_load); + } + return 0; } =20 @@ -2597,6 +2604,21 @@ static bool postcopy_pause_incoming(MigrationIncomin= gState *mis) mis->to_src_file =3D NULL; qemu_mutex_unlock(&mis->rp_mutex); =20 + /* + * NOTE: this must happen before reset the PostcopyTmpPages below, + * otherwise it's racy to reset those fields when the fast load thread + * can be accessing it in parallel. + */ + if (mis->postcopy_qemufile_dst) { + qemu_file_shutdown(mis->postcopy_qemufile_dst); + /* Take the mutex to make sure the fast ram load thread halted */ + qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); + migration_ioc_unregister_yank_from_file(mis->postcopy_qemufile_dst= ); + qemu_fclose(mis->postcopy_qemufile_dst); + mis->postcopy_qemufile_dst =3D NULL; + qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); + } + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, MIGRATION_STATUS_POSTCOPY_PAUSED); =20 @@ -2634,8 +2656,8 @@ retry: while (true) { section_type =3D qemu_get_byte(f); =20 - if (qemu_file_get_error(f)) { - ret =3D qemu_file_get_error(f); + ret =3D qemu_file_get_error_obj_any(f, mis->postcopy_qemufile_dst,= NULL); + if (ret) { break; } =20 diff --git a/migration/trace-events b/migration/trace-events index 69f311169a..0e385c3a07 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -270,6 +270,8 @@ mark_postcopy_blocktime_begin(uint64_t addr, void *dd, = uint32_t time, int cpu, i mark_postcopy_blocktime_end(uint64_t addr, void *dd, uint32_t time, int af= fected_cpu) "addr: 0x%" PRIx64 ", dd: %p, time: %u, affected_cpu: %d" postcopy_pause_fault_thread(void) "" postcopy_pause_fault_thread_continued(void) "" +postcopy_pause_fast_load(void) "" +postcopy_pause_fast_load_continued(void) "" postcopy_ram_fault_thread_entry(void) "" postcopy_ram_fault_thread_exit(void) "" postcopy_ram_fault_thread_fds_core(int baseufd, int quitfd) "ufd: %d quitf= d: %d" --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930807833785.6163039604514; Mon, 25 Apr 2022 16:53:27 -0700 (PDT) Received: from localhost ([::1]:52600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8WE-0007RC-Nm for importer@patchew.org; Mon, 25 Apr 2022 19:53:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IQ-0007PB-Ns for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:59734) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IO-0007lJ-R5 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:10 -0400 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-527-yk2MuEtOPpu2rH5rsr0CkQ-1; Mon, 25 Apr 2022 19:39:07 -0400 Received: by mail-io1-f72.google.com with SMTP id u18-20020a5d8712000000b0064c7a7c497aso12501919iom.18 for ; Mon, 25 Apr 2022 16:39:07 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BsM5BPNa2FImfWHhVVrmnaKWQXhjdEE/jidXE0uGgKA=; b=ci5/I6D5S6qna7yUdkzgEV9l23IVMz1oaVqcVi/98HA+nHAPvFDnbWaIKWNBA+IbRiw26K 07xOt6IQHNz5bgAcCKa+7kdsPcUvafJRTvQlG0hvfe07Yx339wgzZ0H/GNuRUg74Bqnc+u oyTCeeCx/J+D93Pn3je/5egDmzvfEUA= X-MC-Unique: yk2MuEtOPpu2rH5rsr0CkQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BsM5BPNa2FImfWHhVVrmnaKWQXhjdEE/jidXE0uGgKA=; b=23/PHZ52yi7X4Uxu0pEkPdOktmo6fKUvCSBrkUpDL+9xU2VuNZYFUBSzk8+T+suNWs N8MQS/6yfFuKT0600EVO9StWgsx27rYc9KugPmktx2dt77FPeY6oVIMm5VC4UeZVY/kB v2Ou1Puw/w56zeeC6bI++xnghp9r5QrXeDEnZQCmfCjipaKGZNgxroThofuisAFhKTmv NJ9IUioXYoKm2pOjc/xzgEFkZJPszwCA4v1roa2Npbez+vmy9t1SC4MG+W/VBkldFqxQ QiRDmhNJpqHWwHahJvl1DfqsXN5v6PnRU/UaSlvp2RIMrHm9rA5HquPMRJxkyCw07Cau LE9Q== X-Gm-Message-State: AOAM533ToG+ePs4W2uqaMOLIN9yqpAFN3s3xILAkGnHZJMo3PS1/Fskn yZrzpYXk1U2i+Iv+Ar3R8SEoev+Zx05he2HXzEL1TOOjhYEaYfSDa2ouQE+qj6ZqeO/xrp3kdJd fKMMkMI9yGJx4uH7XjDNuTVXbR8PWiPUk3taBI0jcZVkqtBX1nLC2bwjxRLtvQmVg X-Received: by 2002:a05:6e02:15c6:b0:2c2:5ab0:948 with SMTP id q6-20020a056e0215c600b002c25ab00948mr7856342ilu.171.1650929946291; Mon, 25 Apr 2022 16:39:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYORy0sRw1T2pMcA7Gh/GP0FMV8iyVsU9lslWT8eqEAYiI/CylzbeFKfA+OfLz7n1DrGb+mw== X-Received: by 2002:a05:6e02:15c6:b0:2c2:5ab0:948 with SMTP id q6-20020a056e0215c600b002c25ab00948mr7856326ilu.171.1650929945924; Mon, 25 Apr 2022 16:39:05 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 14/21] migration: Create the postcopy preempt channel asynchronously Date: Mon, 25 Apr 2022 19:38:40 -0400 Message-Id: <20220425233847.10393-15-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930809700100001 Content-Type: text/plain; charset="utf-8" This patch allows the postcopy preempt channel to be created asynchronously. The benefit is that when the connection is slow, we won't take the BQL (and potentially block all things like QMP) for a long time without releasing. A function postcopy_preempt_wait_channel() is introduced, allowing the migration thread to be able to wait on the channel creation. The channel is always created by the main thread, in which we'll kick a new semaphore to tell the migration thread that the channel has created. We'll need to wait for the new channel in two places: (1) when there's a new postcopy migration that is starting, or (2) when there's a postcopy migration to resume. For the start of migration, we don't need to wait for this channel until when we want to start postcopy, aka, postcopy_start(). We'll fail the migration if we found that the channel creation failed (which should probably not happen at all in 99% of the cases, because the main channel is using the same network topology). For a postcopy recovery, we'll need to wait in postcopy_pause(). In that case if the channel creation failed, we can't fail the migration or we'll crash the VM, instead we keep in PAUSED state, waiting for yet another recovery. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Manish Mishra --- migration/migration.c | 16 ++++++++++++ migration/migration.h | 7 +++++ migration/postcopy-ram.c | 56 +++++++++++++++++++++++++++++++--------- migration/postcopy-ram.h | 1 + 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index a0db5de685..cce741e20e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3020,6 +3020,12 @@ static int postcopy_start(MigrationState *ms) int64_t bandwidth =3D migrate_max_postcopy_bandwidth(); bool restart_block =3D false; int cur_state =3D MIGRATION_STATUS_ACTIVE; + + if (postcopy_preempt_wait_channel(ms)) { + migrate_set_state(&ms->state, ms->state, MIGRATION_STATUS_FAILED); + return -1; + } + if (!migrate_pause_before_switchover()) { migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_POSTCOPY_ACTIVE); @@ -3501,6 +3507,14 @@ static MigThrError postcopy_pause(MigrationState *s) if (s->state =3D=3D MIGRATION_STATUS_POSTCOPY_RECOVER) { /* Woken up by a recover procedure. Give it a shot */ =20 + if (postcopy_preempt_wait_channel(s)) { + /* + * Preempt enabled, and new channel create failed; loop + * back to wait for another recovery. + */ + continue; + } + /* * Firstly, let's wake up the return path now, with a new * return path channel. @@ -4360,6 +4374,7 @@ static void migration_instance_finalize(Object *obj) qemu_sem_destroy(&ms->postcopy_pause_sem); qemu_sem_destroy(&ms->postcopy_pause_rp_sem); qemu_sem_destroy(&ms->rp_state.rp_sem); + qemu_sem_destroy(&ms->postcopy_qemufile_src_sem); error_free(ms->error); } =20 @@ -4406,6 +4421,7 @@ static void migration_instance_init(Object *obj) qemu_sem_init(&ms->rp_state.rp_sem, 0); qemu_sem_init(&ms->rate_limit_sem, 0); qemu_sem_init(&ms->wait_unplug_sem, 0); + qemu_sem_init(&ms->postcopy_qemufile_src_sem, 0); qemu_mutex_init(&ms->qemu_file_lock); } =20 diff --git a/migration/migration.h b/migration/migration.h index 91f845e9e4..f898b8547a 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -219,6 +219,13 @@ struct MigrationState { QEMUFile *to_dst_file; /* Postcopy specific transfer channel */ QEMUFile *postcopy_qemufile_src; + /* + * It is posted when the preempt channel is established. Note: this is + * used for both the start or recover of a postcopy migration. We'll + * post to this sem every time a new preempt channel is created in the + * main thread, and we keep post() and wait() in pair. + */ + QemuSemaphore postcopy_qemufile_src_sem; QIOChannelBuffer *bioc; /* * Protects to_dst_file/from_dst_file pointers. We need to make sure = we diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index b3c81b46f6..1bb603051a 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1552,10 +1552,50 @@ bool postcopy_preempt_new_channel(MigrationIncoming= State *mis, QEMUFile *file) return true; } =20 -int postcopy_preempt_setup(MigrationState *s, Error **errp) +static void +postcopy_preempt_send_channel_new(QIOTask *task, gpointer opaque) { - QIOChannel *ioc; + MigrationState *s =3D opaque; + QIOChannel *ioc =3D QIO_CHANNEL(qio_task_get_source(task)); + Error *local_err =3D NULL; + + if (qio_task_propagate_error(task, &local_err)) { + /* Something wrong happened.. */ + migrate_set_error(s, local_err); + error_free(local_err); + } else { + migration_ioc_register_yank(ioc); + s->postcopy_qemufile_src =3D qemu_fopen_channel_output(ioc); + trace_postcopy_preempt_new_channel(); + } + + /* + * Kick the waiter in all cases. The waiter should check upon + * postcopy_qemufile_src to know whether it failed or not. + */ + qemu_sem_post(&s->postcopy_qemufile_src_sem); + object_unref(OBJECT(ioc)); +} =20 +/* Returns 0 if channel established, -1 for error. */ +int postcopy_preempt_wait_channel(MigrationState *s) +{ + /* If preempt not enabled, no need to wait */ + if (!migrate_postcopy_preempt()) { + return 0; + } + + /* + * We need the postcopy preempt channel to be established before + * starting doing anything. + */ + qemu_sem_wait(&s->postcopy_qemufile_src_sem); + + return s->postcopy_qemufile_src ? 0 : -1; +} + +int postcopy_preempt_setup(MigrationState *s, Error **errp) +{ if (!migrate_postcopy_preempt()) { return 0; } @@ -1566,16 +1606,8 @@ int postcopy_preempt_setup(MigrationState *s, Error = **errp) return -1; } =20 - ioc =3D socket_send_channel_create_sync(errp); - - if (ioc =3D=3D NULL) { - return -1; - } - - migration_ioc_register_yank(ioc); - s->postcopy_qemufile_src =3D qemu_fopen_channel_output(ioc); - - trace_postcopy_preempt_new_channel(); + /* Kick an async task to connect */ + socket_send_channel_create(postcopy_preempt_send_channel_new, s); =20 return 0; } diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 34b1080cde..6147bf7d1d 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -192,5 +192,6 @@ enum PostcopyChannels { =20 bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); int postcopy_preempt_setup(MigrationState *s, Error **errp); +int postcopy_preempt_wait_channel(MigrationState *s); =20 #endif --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930716847552.7596957748995; Mon, 25 Apr 2022 16:51:56 -0700 (PDT) Received: from localhost ([::1]:47624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Ul-00044U-R0 for importer@patchew.org; Mon, 25 Apr 2022 19:51:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IR-0007S6-KU for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IQ-0007lW-12 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:11 -0400 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-537-nn9xTvJzNkSbee9Pmd-d4w-1; Mon, 25 Apr 2022 19:39:08 -0400 Received: by mail-io1-f72.google.com with SMTP id x8-20020a056602160800b00654b3a46b66so12501734iow.19 for ; Mon, 25 Apr 2022 16:39:08 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929949; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gtNv1DxIePLTzveSRj6tKkTCkAbWSCUPFKNOY6OzAIg=; b=METkfk96rNUsfUbsqk+c+gZNTVuctFUHhdzjn/nfuNR2RUYEGMKYHM2C6KXr5ZIylfGfoY GDhJ9o6ZmQWkemM7Tzf+/W7HEsn7Ku6gS/nFK/LE5XPPhX/7xkjWTCVnww+vbhs+10/H0H VQLcNMh4XiOKHcPN2bQ7xLYZ0H6vmDk= X-MC-Unique: nn9xTvJzNkSbee9Pmd-d4w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gtNv1DxIePLTzveSRj6tKkTCkAbWSCUPFKNOY6OzAIg=; b=I5bTC6ZZfDLiGgRCjqGpgwueE937JfTJxuVh378ynPrwyxL/unzZybr6nPrq58FSa8 JgSPmGME52A5hf1+wWH48suATu9bBX6UqMuzBhUCbEsYXLhupeFi6rHHRXFq6ev7f1eV CzcCIJjz2ds76SSS751AW1UWbrcisOegFdBJf2L9hbfUP5iflW6gMI+n+NuPJwFBYKer DNBtEe0L67jrxAGKDAsQrj+ul1IRb03mZmaYCDwq1aSQch9609Ydn+lnOQvyBoeEThwe rdVkogYtGybskvZt6J01/H0GufbC4lYby/lXLK3uT5vOhk25BqXFgr2FaUqE8w9ope+8 e51g== X-Gm-Message-State: AOAM533qBmqUYMex82kdbZui5jqagVCYQITrGswcbuML7nxGxj59urMn E4PIL+APHDYkQ9F7iJ/uoqbmkR09AMfUggOCCv4URukWZ+/nUli8Fq7LsB78tpNzlHKOgmfv/2L cRDpJ0TezoEUxGDfzilIwIz9cWbufvfS08xRhdrJEvJrD7y8vO8Go6s7YMKxukgam X-Received: by 2002:a05:6602:2d06:b0:655:3324:4cc8 with SMTP id c6-20020a0566022d0600b0065533244cc8mr8596283iow.74.1650929947409; Mon, 25 Apr 2022 16:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnKIJRW7V+59IEcEwI2vPvoO9DZXWCZfl+yEAmh33fTim1XAJffdhEzg4jkvIQ3Fx4uZraIA== X-Received: by 2002:a05:6602:2d06:b0:655:3324:4cc8 with SMTP id c6-20020a0566022d0600b0065533244cc8mr8596270iow.74.1650929947127; Mon, 25 Apr 2022 16:39:07 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 15/21] migration: Parameter x-postcopy-preempt-break-huge Date: Mon, 25 Apr 2022 19:38:41 -0400 Message-Id: <20220425233847.10393-16-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930717294100001 Content-Type: text/plain; charset="utf-8" Add a parameter that can conditionally disable the "break sending huge page" behavior in postcopy preemption. By default it's enabled. It should only be used for debugging purposes, and we should never remove the "x-" prefix. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Manish Mishra --- migration/migration.c | 2 ++ migration/migration.h | 7 +++++++ migration/ram.c | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index cce741e20e..cd9650f2e2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -4329,6 +4329,8 @@ static Property migration_properties[] =3D { DEFINE_PROP_SIZE("announce-step", MigrationState, parameters.announce_step, DEFAULT_MIGRATE_ANNOUNCE_STEP), + DEFINE_PROP_BOOL("x-postcopy-preempt-break-huge", MigrationState, + postcopy_preempt_break_huge, true), =20 /* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), diff --git a/migration/migration.h b/migration/migration.h index f898b8547a..6ee520642f 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -340,6 +340,13 @@ struct MigrationState { bool send_configuration; /* Whether we send section footer during migration */ bool send_section_footer; + /* + * Whether we allow break sending huge pages when postcopy preempt is + * enabled. When disabled, we won't interrupt precopy within sending a + * host huge page, which is the old behavior of vanilla postcopy. + * NOTE: this parameter is ignored if postcopy preempt is not enabled. + */ + bool postcopy_preempt_break_huge; =20 /* Needed by postcopy-pause state */ QemuSemaphore postcopy_pause_sem; diff --git a/migration/ram.c b/migration/ram.c index a4b39e3675..f3a79c8556 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2266,11 +2266,18 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) =20 static bool postcopy_needs_preempt(RAMState *rs, PageSearchStatus *pss) { + MigrationState *ms =3D migrate_get_current(); + /* Not enabled eager preempt? Then never do that. */ if (!migrate_postcopy_preempt()) { return false; } =20 + /* If the user explicitly disabled breaking of huge page, skip */ + if (!ms->postcopy_preempt_break_huge) { + return false; + } + /* If the ramblock we're sending is a small page? Never bother. */ if (qemu_ram_pagesize(pss->block) =3D=3D TARGET_PAGE_SIZE) { return false; --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165093096087385.15934979343649; Mon, 25 Apr 2022 16:56:00 -0700 (PDT) Received: from localhost ([::1]:59572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Yh-0003ga-E4 for importer@patchew.org; Mon, 25 Apr 2022 19:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8Ib-0007e9-3u for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IU-0007mI-2r for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:19 -0400 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-498-EPDf6R8hNkWvaQeVM97KXQ-1; Mon, 25 Apr 2022 19:39:09 -0400 Received: by mail-io1-f70.google.com with SMTP id a17-20020a056602209100b006549a9cd480so12526524ioa.15 for ; Mon, 25 Apr 2022 16:39:09 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eBQDwvtmOZY5wk96SFWQkFT//BSK1OTV7nmeGyxu89o=; b=OKcnzMoMie9taTgmuK7O0QXx8y7K0c18zkQMYLhnhkC9liF58qzIUJQhKawi/MQbtZL7Qi XqxCy8dXdYtbGoCjzZ6sfXM+Pt58JvWIGyetSIKoDOsXhdcwzm0+s0yjLfuDMsFObk7r7t k5Bk4UjdceAGB/Gsb4faAHN+0dlhuWg= X-MC-Unique: EPDf6R8hNkWvaQeVM97KXQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eBQDwvtmOZY5wk96SFWQkFT//BSK1OTV7nmeGyxu89o=; b=3Dtew5y9O1BpPTWHJk298bix73GUe8UQ8AwQTfBiBV83rmRrIFL+RNXpKapbnU3n2p OPzCVyjo1fys8UOGqw5cur+5Rc0Od/h+sB3c2FBxPzG0LkiEMjBBG0Mr9UtzgYqDlsdi CxuWCqHFC4SGXTYvJPMLF/ptokPM6h0e6WCuoL5kGQEJJfajMxwTq+wOyhuk2x5P7EXX ETXFkvcui8daygVM/BmBk+cxXMkgPF2JH3WnKX1O6jjA6llL/q6FiTCvBCxXKVpEOlP3 nR2IQx3+ArpwAimTZahHe0Rb6kk/JPmgLB1qvbIRenHM9vHgKGdvX+tgJufuaVmrEpoI lYow== X-Gm-Message-State: AOAM533PIq5L84nbgWiB1GDPJGe0fHj9Sp5sBUkCvTBp/zaUHY4N0jrj Y5fwO0pNuAdFamHntXFSuUyThVqi1aZWv6EoSgj/Xs5Q01xXJ8zepXlk9EAvMZAo1BCnmgSKLSB cG84H90Q7SVCI7hV36L9jYMxOr1SbM+N6Lyz84tCJ+ZsOPVM6ECCfXuxGMHC8YGwe X-Received: by 2002:a6b:4e12:0:b0:653:7683:2e32 with SMTP id c18-20020a6b4e12000000b0065376832e32mr8296072iob.165.1650929948675; Mon, 25 Apr 2022 16:39:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1OKf2zwMLfWyLRHer8ilsZDHEfxPNXUOV3EHx27LvH/+LzWPFIoHo2De2sTWWO2fjh4+eBw== X-Received: by 2002:a6b:4e12:0:b0:653:7683:2e32 with SMTP id c18-20020a6b4e12000000b0065376832e32mr8296061iob.165.1650929948299; Mon, 25 Apr 2022 16:39:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 16/21] migration: Add helpers to detect TLS capability Date: Mon, 25 Apr 2022 19:38:42 -0400 Message-Id: <20220425233847.10393-17-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930962396100001 Content-Type: text/plain; charset="utf-8" Add migrate_tls_enabled() to detect whether TLS is configured. Add migrate_channel_requires_tls() to detect whether the specific channel requires TLS. No functional change intended. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/channel.c | 10 ++-------- migration/migration.c | 8 ++++++++ migration/migration.h | 2 ++ migration/multifd.c | 7 +------ migration/tls.c | 9 +++++++++ migration/tls.h | 4 ++++ 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index c6a8dcf1d7..36e59eaeec 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -38,10 +38,7 @@ void migration_channel_process_incoming(QIOChannel *ioc) trace_migration_set_incoming_channel( ioc, object_get_typename(OBJECT(ioc))); =20 - if (s->parameters.tls_creds && - *s->parameters.tls_creds && - !object_dynamic_cast(OBJECT(ioc), - TYPE_QIO_CHANNEL_TLS)) { + if (migrate_channel_requires_tls(ioc)) { migration_tls_channel_process_incoming(s, ioc, &local_err); } else { migration_ioc_register_yank(ioc); @@ -71,10 +68,7 @@ void migration_channel_connect(MigrationState *s, ioc, object_get_typename(OBJECT(ioc)), hostname, error); =20 if (!error) { - if (s->parameters.tls_creds && - *s->parameters.tls_creds && - !object_dynamic_cast(OBJECT(ioc), - TYPE_QIO_CHANNEL_TLS)) { + if (migrate_channel_requires_tls(ioc)) { migration_tls_channel_connect(s, ioc, hostname, &error); =20 if (!error) { diff --git a/migration/migration.c b/migration/migration.c index cd9650f2e2..71a50b5c37 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -49,6 +49,7 @@ #include "trace.h" #include "exec/target_page.h" #include "io/channel-buffer.h" +#include "io/channel-tls.h" #include "migration/colo.h" #include "hw/boards.h" #include "hw/qdev-properties.h" @@ -4250,6 +4251,13 @@ void migration_global_dump(Monitor *mon) ms->clear_bitmap_shift); } =20 +bool migrate_tls_enabled(void) +{ + MigrationState *s =3D migrate_get_current(); + + return s->parameters.tls_creds && *s->parameters.tls_creds; +} + #define DEFINE_PROP_MIG_CAP(name, x) \ DEFINE_PROP_BOOL(name, MigrationState, enabled_capabilities[x], false) =20 diff --git a/migration/migration.h b/migration/migration.h index 6ee520642f..db176ea749 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -436,6 +436,8 @@ bool migrate_use_events(void); bool migrate_postcopy_blocktime(void); bool migrate_background_snapshot(void); bool migrate_postcopy_preempt(void); +/* Whether TLS is enabled for migration? */ +bool migrate_tls_enabled(void); =20 /* Sending on the return path - generic and then for each message type */ void migrate_send_rp_shut(MigrationIncomingState *mis, diff --git a/migration/multifd.c b/migration/multifd.c index 9ea4f581e2..19e3c44491 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -782,17 +782,12 @@ static bool multifd_channel_connect(MultiFDSendParams= *p, QIOChannel *ioc, Error *error) { - MigrationState *s =3D migrate_get_current(); - trace_multifd_set_outgoing_channel( ioc, object_get_typename(OBJECT(ioc)), migrate_get_current()->hostname, error); =20 if (!error) { - if (s->parameters.tls_creds && - *s->parameters.tls_creds && - !object_dynamic_cast(OBJECT(ioc), - TYPE_QIO_CHANNEL_TLS)) { + if (migrate_channel_requires_tls(ioc)) { multifd_tls_channel_connect(p, ioc, &error); if (!error) { /* diff --git a/migration/tls.c b/migration/tls.c index 32c384a8b6..bd1fa01048 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -166,3 +166,12 @@ void migration_tls_channel_connect(MigrationState *s, NULL, NULL); } + +bool migrate_channel_requires_tls(QIOChannel *ioc) +{ + if (!migrate_tls_enabled()) { + return false; + } + + return !object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS); +} diff --git a/migration/tls.h b/migration/tls.h index de4fe2cafd..a54c1dcec7 100644 --- a/migration/tls.h +++ b/migration/tls.h @@ -37,4 +37,8 @@ void migration_tls_channel_connect(MigrationState *s, QIOChannel *ioc, const char *hostname, Error **errp); + +/* Whether the QIO channel requires further TLS handshake? */ +bool migrate_channel_requires_tls(QIOChannel *ioc); + #endif --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930882729993.5524953782208; Mon, 25 Apr 2022 16:54:42 -0700 (PDT) Received: from localhost ([::1]:56082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8XR-0001Kf-QP for importer@patchew.org; Mon, 25 Apr 2022 19:54:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IT-0007af-RA for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:45424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IS-0007lz-8O for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:13 -0400 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-593-_i5z48EeOy24h6m9CUtm5A-1; Mon, 25 Apr 2022 19:39:10 -0400 Received: by mail-io1-f70.google.com with SMTP id u18-20020a5d8712000000b0064c7a7c497aso12501997iom.18 for ; Mon, 25 Apr 2022 16:39:10 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jWB5t2bSp3j+jHVW/XuQFC5BecwH4sNtQvM+SEkuOr4=; b=Rx6eRz0/D2npzigpqUdXft7jAofTWcXVsf64p/q7CwgDUWXiP9Y+3+oBlxhPxktwQqeRb6 uDDMgF3kcKWpmP3VkRMpzv4uWOBPQL7fksk5y/e++LPqzdPlBdBScP+WA+nwHoTrFb6zM3 EcqCmh09bI+KkQoYb7uAQY38OR5Fp0A= X-MC-Unique: _i5z48EeOy24h6m9CUtm5A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jWB5t2bSp3j+jHVW/XuQFC5BecwH4sNtQvM+SEkuOr4=; b=w8qVnpIPo553u6eoszXGNQy8EvoZkY01vLzQGlE2N8wi22TivPOIW4w+0fWxFUEaZT aAbDQmVZF9xCshBCE+ggzxqO8zjwFZt7PRTOLNWTCwODkOo26Jx85foMGlYWsUpvadYY TRlLf54UUpzQoOB1K72ia/KbqyuvyEvcs57N5tonIo9q/Dg1Gwla25HH4m/4sfOwC+57 BnqMOdJHsJkNy/m4TUIoYAIZbYDa2Ekke7tpjqkdJZ3x612cWBJ6zLQYpQxu4g8CfaJn lmR7UZqwE8ZOwPLIZAqmhH1BezHwCXSYcrz2U11/hyI43mT8i5DO+cA8V4HuSOjT27ne dcHw== X-Gm-Message-State: AOAM533bDRiwoc/HJkxvMvjWH2vsmKTqUXSh0dO2K/SxIUEJxFvVnqW5 67558qYXDTlBE9RX/BSpe69tdTfIjs8lTQr1OUZSiiMqXi6dcjnr0COa52e+8gNhwHl3sqn54cN 5X9Is711h5+uoK6thFxuT67Kjkf2oPotUXNCjRw1rJmQb5fxPeC3c7ShXvSkaKDaX X-Received: by 2002:a05:6638:144b:b0:321:589b:a8ea with SMTP id l11-20020a056638144b00b00321589ba8eamr8702890jad.296.1650929949779; Mon, 25 Apr 2022 16:39:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBxtpnS/9bPkha9BeXzonNEc3xMvBX4zwuoSsYbjDL7IWvAF6FlA3xe2PSCapWDE9z3AgcJA== X-Received: by 2002:a05:6638:144b:b0:321:589b:a8ea with SMTP id l11-20020a056638144b00b00321589ba8eamr8702880jad.296.1650929949549; Mon, 25 Apr 2022 16:39:09 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 17/21] migration: Export tls-[creds|hostname|authz] params to cmdline too Date: Mon, 25 Apr 2022 19:38:43 -0400 Message-Id: <20220425233847.10393-18-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930884041100001 Content-Type: text/plain; charset="utf-8" It's useful for specifying tls credentials all in the cmdline (along with the -object tls-creds-*), especially for debugging purpose. The trick here is we must remember to not free these fields again in the finalize() function of migration object, otherwise it'll cause double-free. The thing is when destroying an object, we'll first destroy the properties that bound to the object, then the object itself. To be explicit, when destroy the object in object_finalize() we have such sequence of operations: object_property_del_all(obj); object_deinit(obj, ti); So after this change the two fields are properly released already even before reaching the finalize() function but in object_property_del_all(), hence we don't need to free them anymore in finalize() or it's double-free. This also fixes a trivial memory leak for tls-authz as we forgot to free it before this patch. Signed-off-by: Peter Xu --- migration/migration.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 71a50b5c37..b0f2de1e09 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -4339,6 +4339,9 @@ static Property migration_properties[] =3D { DEFAULT_MIGRATE_ANNOUNCE_STEP), DEFINE_PROP_BOOL("x-postcopy-preempt-break-huge", MigrationState, postcopy_preempt_break_huge, true), + DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds), + DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_host= name), + DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), =20 /* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), @@ -4372,12 +4375,9 @@ static void migration_class_init(ObjectClass *klass,= void *data) static void migration_instance_finalize(Object *obj) { MigrationState *ms =3D MIGRATION_OBJ(obj); - MigrationParameters *params =3D &ms->parameters; =20 qemu_mutex_destroy(&ms->error_mutex); qemu_mutex_destroy(&ms->qemu_file_lock); - g_free(params->tls_hostname); - g_free(params->tls_creds); qemu_sem_destroy(&ms->wait_unplug_sem); qemu_sem_destroy(&ms->rate_limit_sem); qemu_sem_destroy(&ms->pause_sem); --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930823255599.7103706728718; Mon, 25 Apr 2022 16:53:43 -0700 (PDT) Received: from localhost ([::1]:53404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8WT-0007y0-KA for importer@patchew.org; Mon, 25 Apr 2022 19:53:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8Ia-0007c8-08 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22714) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IT-0007mA-8O for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:14 -0400 Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-RzXLxdRDO4ahEMPC8jxIjA-1; Mon, 25 Apr 2022 19:39:11 -0400 Received: by mail-io1-f71.google.com with SMTP id m206-20020a6b3fd7000000b00657a48f1a70so7547ioa.4 for ; Mon, 25 Apr 2022 16:39:11 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=97LnQX+iWnm8/SAWY3ZLNjNkHl1aDQ7WHKhz4ajwKNo=; b=K1sVJfsRTcch0X5Aaxd63pnJuhkaFaRNA+mbP2YO5e7aCn+4SjxIsFb/H03GUoOCUlftuZ wuBsYo3tLEJXFLEiUWfFJe52Ewi9877/jTJ4eZsWqw+RMIhPCVif65XKekOVxo2ZvG68FJ XDII6rKPMA0uCU9MCZ+I/FGkbPnpn+0= X-MC-Unique: RzXLxdRDO4ahEMPC8jxIjA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=97LnQX+iWnm8/SAWY3ZLNjNkHl1aDQ7WHKhz4ajwKNo=; b=Ke5c6MxafOLRTETODnR73wQmgxYAjg5dE+D2TVX26F7smAaP+mEYsIPqTQ0reLUdzN CaIh2nx9qlBDmm6vX2UWC7rsBtQK5j+aFOwV290kNMOGf1d9NWqXg5OGiU8l/FnlvmJ+ caGYluzLorm4OY0B9jIUCOCY5WCAHxir3P1JZVnlY8xQHjPMNEThKtI8EImRA1dhp2sX JdA/wqg7ccj50D+/BHTZ7yjNTeEnVJdyosgDNl/eLP16Kxasb5XfHpKnU1EH6o52nJMp owiiSFJuePvqFfmSC3NsTxMLAubfplmZKaZZoezqUIE1Gruy7PMK6MPuOjWJF5TcrtAH lunw== X-Gm-Message-State: AOAM531sJGGBwjOS8fHCOkLmkZ+MpkO74WKfLTSMxfa1FxMHYilVKr2l X3JzlD5gxo1wa9RZ3Kd+edJzXB3dxj7KhBdTcZGa4E2A3fowo2lEEPQF/a9gfbzXQyjtz1yM+CJ H1EAsq17PfMRQ+UvlkM4SFVePmPHS5GnBhnOyg6K1B7RmeKsDi8SBsMdy6hCNCMKo X-Received: by 2002:a02:a68d:0:b0:32a:f755:821f with SMTP id j13-20020a02a68d000000b0032af755821fmr2212534jam.185.1650929950812; Mon, 25 Apr 2022 16:39:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBI9Tad2Ea8iLqabEDhBhnV3YgRlRuyEp2TN2pH/tEs8NZvWtyUW8E96wg0M2atjA2Bgc6cw== X-Received: by 2002:a02:a68d:0:b0:32a:f755:821f with SMTP id j13-20020a02a68d000000b0032af755821fmr2212520jam.185.1650929950479; Mon, 25 Apr 2022 16:39:10 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 18/21] migration: Enable TLS for preempt channel Date: Mon, 25 Apr 2022 19:38:44 -0400 Message-Id: <20220425233847.10393-19-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930824067100001 Content-Type: text/plain; charset="utf-8" This patch is based on the async preempt channel creation. It continues wiring up the new channel with TLS handshake to destionation when enabled. Note that only the src QEMU needs such operation; the dest QEMU does not need any change for TLS support due to the fact that all channels are established synchronously there, so all the TLS magic is already properly handled by migration_tls_channel_process_incoming(). Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 57 ++++++++++++++++++++++++++++++++++------ migration/trace-events | 1 + 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 1bb603051a..4a4da16389 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -36,6 +36,7 @@ #include "socket.h" #include "qemu-file-channel.h" #include "yank_functions.h" +#include "tls.h" =20 /* Arbitrary limit on size of each discard command, * keeps them around ~200 bytes @@ -1552,15 +1553,15 @@ bool postcopy_preempt_new_channel(MigrationIncoming= State *mis, QEMUFile *file) return true; } =20 +/* + * Setup the postcopy preempt channel with the IOC. If ERROR is specified, + * setup the error instead. This helper will free the ERROR if specified. + */ static void -postcopy_preempt_send_channel_new(QIOTask *task, gpointer opaque) +postcopy_preempt_send_channel_done(MigrationState *s, + QIOChannel *ioc, Error *local_err) { - MigrationState *s =3D opaque; - QIOChannel *ioc =3D QIO_CHANNEL(qio_task_get_source(task)); - Error *local_err =3D NULL; - - if (qio_task_propagate_error(task, &local_err)) { - /* Something wrong happened.. */ + if (local_err) { migrate_set_error(s, local_err); error_free(local_err); } else { @@ -1574,7 +1575,47 @@ postcopy_preempt_send_channel_new(QIOTask *task, gpo= inter opaque) * postcopy_qemufile_src to know whether it failed or not. */ qemu_sem_post(&s->postcopy_qemufile_src_sem); - object_unref(OBJECT(ioc)); +} + +static void +postcopy_preempt_tls_handshake(QIOTask *task, gpointer opaque) +{ + g_autoptr(QIOChannel) ioc =3D QIO_CHANNEL(qio_task_get_source(task)); + MigrationState *s =3D opaque; + Error *local_err =3D NULL; + + qio_task_propagate_error(task, &local_err); + postcopy_preempt_send_channel_done(s, ioc, local_err); +} + +static void +postcopy_preempt_send_channel_new(QIOTask *task, gpointer opaque) +{ + g_autoptr(QIOChannel) ioc =3D QIO_CHANNEL(qio_task_get_source(task)); + MigrationState *s =3D opaque; + QIOChannelTLS *tioc; + Error *local_err =3D NULL; + + if (qio_task_propagate_error(task, &local_err)) { + goto out; + } + + if (migrate_channel_requires_tls(ioc)) { + tioc =3D migration_tls_client_create(s, ioc, s->hostname, &local_e= rr); + if (!tioc) { + goto out; + } + trace_postcopy_preempt_tls_handshake(); + qio_channel_set_name(QIO_CHANNEL(tioc), "migration-tls-preempt"); + qio_channel_tls_handshake(tioc, postcopy_preempt_tls_handshake, + s, NULL, NULL); + /* Setup the channel until TLS handshake finished */ + return; + } + +out: + /* This handles both good and error cases */ + postcopy_preempt_send_channel_done(s, ioc, local_err); } =20 /* Returns 0 if channel established, -1 for error. */ diff --git a/migration/trace-events b/migration/trace-events index 0e385c3a07..a34afe7b85 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -287,6 +287,7 @@ postcopy_request_shared_page(const char *sharer, const = char *rb, uint64_t rb_off postcopy_request_shared_page_present(const char *sharer, const char *rb, u= int64_t rb_offset) "%s already %s offset 0x%"PRIx64 postcopy_wake_shared(uint64_t client_addr, const char *rb) "at 0x%"PRIx64"= in %s" postcopy_page_req_del(void *addr, int count) "resolved page req %p total %= d" +postcopy_preempt_tls_handshake(void) "" postcopy_preempt_new_channel(void) "" postcopy_preempt_thread_entry(void) "" postcopy_preempt_thread_exit(void) "" --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930667749680.8383481031694; Mon, 25 Apr 2022 16:51:07 -0700 (PDT) Received: from localhost ([::1]:44384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8Ty-0001ot-Kb for importer@patchew.org; Mon, 25 Apr 2022 19:51:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8Id-0007kZ-Cr for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55052) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IV-0007mV-Nr for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:23 -0400 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-62-JUYsyVQmNcmTQ4FNrsD7ug-1; Mon, 25 Apr 2022 19:39:12 -0400 Received: by mail-io1-f70.google.com with SMTP id y20-20020a5e8714000000b0065494b96af2so12522483ioj.10 for ; Mon, 25 Apr 2022 16:39:12 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QH87Re7xe36gxEh/hBeSf4W8MAZ344BFMLvEumNToms=; b=IRhrzRD/LaEdPgVZnD8kzD7QLOMomDSODO877qF8f2r83+8GlZggqVuTwQ4I3nHTMjWKji o5xFWrPMzJ4pZxgTJjmW7Q5gzzqhcCZvUSgirbkMTaZd0HZdFfNVN+8LCWk6zvR/F38tCv NQJLGvze4LJllrpOIIlrBIjk1+odwdw= X-MC-Unique: JUYsyVQmNcmTQ4FNrsD7ug-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QH87Re7xe36gxEh/hBeSf4W8MAZ344BFMLvEumNToms=; b=FtC9mrfb4rdvrxG/gb72Ne7Z3T5pwBipApHMWh1gD9uuXpz9DRgZEuHbXu/EkIr8+X Ry5J7wZ3AvkzZ2Uenngmgn3Rk/3CslU0oY4RUT+6AT0ipvqFqzfueEEsqLuD/nzRcAK9 r6yYDyTj8GgrbHcmLdwZJMeW/UTqhx77YB0jj27K0DBkd5J5PROcurNjyR7hMTGiF01s f2hsEC44Vbf1XTxVaQWDch0Y4ZZSJaRuucYDrANjTunQzmF1zSz6SfByWIQIzvarA51i D7qXaJG7YAVCO0tYNOL0CjnW6ajqTxyuDOfMQc0mvUazKfcO5Q6ySx0WWuo2rOfMQHuP rvAw== X-Gm-Message-State: AOAM530g2hvdIbOn+kYqr+lhYmYdCVUXe89qFEI2oi/3QF+JVUyBXk+R kOzdFt7F2jVWr5rH0hL4PynoGpTfebZpmq7v3TpRmvqtdUlLhZ6rbaWOG2cEYOa3T1N4GyEdUP5 8orhSag3fTFik8kLqS1tMjtD2l8fdx6vansxvH8JN58GJoq+uToHGqIpkUuoy621d X-Received: by 2002:a05:6638:40a5:b0:326:3bad:fe1 with SMTP id m37-20020a05663840a500b003263bad0fe1mr8945138jam.127.1650929951901; Mon, 25 Apr 2022 16:39:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+wJjjhgl7pOQ0uCaqDLOJNgFng51Bolxom7+1yLBA9rsYP140DvnEZCabCBZhfPO2MkhhFw== X-Received: by 2002:a05:6638:40a5:b0:326:3bad:fe1 with SMTP id m37-20020a05663840a500b003263bad0fe1mr8945122jam.127.1650929951644; Mon, 25 Apr 2022 16:39:11 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 19/21] tests: Add postcopy tls migration test Date: Mon, 25 Apr 2022 19:38:45 -0400 Message-Id: <20220425233847.10393-20-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930669040100003 Content-Type: text/plain; charset="utf-8" We just added TLS tests for precopy but not postcopy. Add the corresponding test for vanilla postcopy. Rename the vanilla postcopy to "postcopy/plain" because all postcopy tests will only use unix sockets as channel. Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 50 +++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index d9f444ea14..c32b350aea 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -481,6 +481,10 @@ typedef struct { bool only_target; /* Use dirty ring if true; dirty logging otherwise */ bool use_dirty_ring; + /* Whether use TLS channels for postcopy test? */ + bool postcopy_tls; + /* Used only if postcopy_tls=3D=3Dtrue, to cache the data object */ + void *postcopy_tls_data; const char *opts_source; const char *opts_target; } MigrateStart; @@ -980,6 +984,10 @@ static int migrate_postcopy_prepare(QTestState **from_= ptr, return -1; } =20 + if (args->postcopy_tls) { + args->postcopy_tls_data =3D test_migrate_tls_psk_start_match(from,= to); + } + migrate_set_capability(from, "postcopy-ram", true); migrate_set_capability(to, "postcopy-ram", true); migrate_set_capability(to, "postcopy-blocktime", true); @@ -1004,7 +1012,8 @@ static int migrate_postcopy_prepare(QTestState **from= _ptr, return 0; } =20 -static void migrate_postcopy_complete(QTestState *from, QTestState *to) +static void migrate_postcopy_complete(QTestState *from, QTestState *to, + MigrateStart *args) { wait_for_migration_complete(from); =20 @@ -1015,19 +1024,38 @@ static void migrate_postcopy_complete(QTestState *f= rom, QTestState *to) read_blocktime(to); } =20 + if (args->postcopy_tls) { + assert(args->postcopy_tls_data); + test_migrate_tls_psk_finish(from, to, args->postcopy_tls_data); + args->postcopy_tls_data =3D NULL; + } + test_migrate_end(from, to, true); } =20 -static void test_postcopy(void) +static void test_postcopy_common(MigrateStart *args) { - MigrateStart args =3D {}; QTestState *from, *to; =20 - if (migrate_postcopy_prepare(&from, &to, &args)) { + if (migrate_postcopy_prepare(&from, &to, args)) { return; } migrate_postcopy_start(from, to); - migrate_postcopy_complete(from, to); + migrate_postcopy_complete(from, to, args); +} + +static void test_postcopy(void) +{ + MigrateStart args =3D { }; + + test_postcopy_common(&args); +} + +static void test_postcopy_tls_psk(void) +{ + MigrateStart args =3D { .postcopy_tls =3D true }; + + test_postcopy_common(&args); } =20 static void test_postcopy_recovery(void) @@ -1089,7 +1117,7 @@ static void test_postcopy_recovery(void) /* Restore the postcopy bandwidth to unlimited */ migrate_set_parameter_int(from, "max-postcopy-bandwidth", 0); =20 - migrate_postcopy_complete(from, to); + migrate_postcopy_complete(from, to, &args); } =20 static void test_baddest(void) @@ -2132,7 +2160,15 @@ int main(int argc, char **argv) =20 module_call_init(MODULE_INIT_QOM); =20 - qtest_add_func("/migration/postcopy/unix", test_postcopy); + qtest_add_func("/migration/postcopy/plain", test_postcopy); +#ifdef CONFIG_GNUTLS + /* + * NOTE: psk test is enough for postcopy, as other types of TLS + * channels are tested under precopy. Here what we want to test is the + * general postcopy path that has TLS channel enabled. + */ + qtest_add_func("/migration/postcopy/tls/psk", test_postcopy_tls_psk); +#endif /* CONFIG_GNUTLS */ qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery); qtest_add_func("/migration/bad_dest", test_baddest); qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plai= n); --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650930811307244.1475539689079; Mon, 25 Apr 2022 16:53:31 -0700 (PDT) Received: from localhost ([::1]:52806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8WG-0007ZS-RG for importer@patchew.org; Mon, 25 Apr 2022 19:53:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8Io-0008Bn-4c for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21838) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8IW-0007mb-Ib for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:33 -0400 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-280-NpLRJFuCPVe_7u58TF2gsw-1; Mon, 25 Apr 2022 19:39:14 -0400 Received: by mail-io1-f72.google.com with SMTP id m206-20020a6b3fd7000000b00657a48f1a70so7597ioa.4 for ; Mon, 25 Apr 2022 16:39:14 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ts1uN9p/nQEwVhWU7ctTqCBXAIjCW69+L43U9lwrDx8=; b=bQagWPcnq2AXDPgEleDKBXDxOjVBsoKryv4QaCH2s2R/CMPHtUCn+H/FVRG5/PGfR/mxc0 Kla/prNSFpwefHpsSk3BHD445M6yBSEkKW1otOc7W2815snYl0i7AJo3PGR3hDKBhcond8 C6H4nzJwNfgmbCADM0TLjZQPvGxO1Ps= X-MC-Unique: NpLRJFuCPVe_7u58TF2gsw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ts1uN9p/nQEwVhWU7ctTqCBXAIjCW69+L43U9lwrDx8=; b=FcdnRlooh8bOHiiqlOp2vBtaQOp+D72OwR9Po/xo6gTri3ztNiMrU0kThwC/h4ZcIl odQ+7Fhlw1GU/VPDV4Vh8JDHWASoiHQGvLrDtalo9aqEfLs/omRXrmXmrr6uyBka4639 LdX5SglYgDf91ekkeA3Rv7Dgl/tyyy6q+9vtQBiODrJjvrzDnznC7QEUIzvqJhth8Pj3 M805baFSAIjnBTIdHmtEilZUtgYMiWICQmjJ7L4Nt54M1HWu88LxRIoRoEEQxXmyCbsv 858GObQeAq+Zdi3UdwUE/xbmbL2WRIttyUxVme/23iqwsZr0I/Umm9TZi5ACzB0L15GY bQEQ== X-Gm-Message-State: AOAM530aTYxxl5rYyLSp7FdyCxwqCE7OtqlqfW2sM97L5SUlz4e5b9oH Cl2CwQorfdFmEPfsTZdv417O8HYuaPvuWyqf/Yb3SIpYjOBwfRd+LybG+hKiBvK/OHR2e3qnoqQ 3mQyXm0LXPca/GgU/8EfXOIMwvcYUEljBuK6sa2MdSUuo4ps5Gg3hWnXLLQRUhHqZ X-Received: by 2002:a05:6e02:c28:b0:2ca:8380:8390 with SMTP id q8-20020a056e020c2800b002ca83808390mr7661968ilg.174.1650929953160; Mon, 25 Apr 2022 16:39:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwzjcOWZR4krks/Qum4727E1TmSS+WOU7qVgg1SNrLUNnHwnpTMnA8VLE0WwwGstCiX5HEvg== X-Received: by 2002:a05:6e02:c28:b0:2ca:8380:8390 with SMTP id q8-20020a056e020c2800b002ca83808390mr7661957ilg.174.1650929952883; Mon, 25 Apr 2022 16:39:12 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 20/21] tests: Add postcopy tls recovery migration test Date: Mon, 25 Apr 2022 19:38:46 -0400 Message-Id: <20220425233847.10393-21-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650930811701100003 Content-Type: text/plain; charset="utf-8" It's easy to build this upon the postcopy tls test. Rename the old postcopy recovery test to postcopy/recovery/plain. Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index c32b350aea..cbcf3f73a4 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1058,15 +1058,15 @@ static void test_postcopy_tls_psk(void) test_postcopy_common(&args); } =20 -static void test_postcopy_recovery(void) +static void test_postcopy_recovery_common(MigrateStart *args) { - MigrateStart args =3D { - .hide_stderr =3D true, - }; QTestState *from, *to; g_autofree char *uri =3D NULL; =20 - if (migrate_postcopy_prepare(&from, &to, &args)) { + /* Always hide errors for postcopy recover tests since they're expecte= d */ + args->hide_stderr =3D true; + + if (migrate_postcopy_prepare(&from, &to, args)) { return; } =20 @@ -1117,7 +1117,21 @@ static void test_postcopy_recovery(void) /* Restore the postcopy bandwidth to unlimited */ migrate_set_parameter_int(from, "max-postcopy-bandwidth", 0); =20 - migrate_postcopy_complete(from, to, &args); + migrate_postcopy_complete(from, to, args); +} + +static void test_postcopy_recovery(void) +{ + MigrateStart args =3D { }; + + test_postcopy_recovery_common(&args); +} + +static void test_postcopy_recovery_tls_psk(void) +{ + MigrateStart args =3D { .postcopy_tls =3D true }; + + test_postcopy_recovery_common(&args); } =20 static void test_baddest(void) @@ -2169,7 +2183,12 @@ int main(int argc, char **argv) */ qtest_add_func("/migration/postcopy/tls/psk", test_postcopy_tls_psk); #endif /* CONFIG_GNUTLS */ - qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery); + qtest_add_func("/migration/postcopy/recovery/plain", + test_postcopy_recovery); +#ifdef CONFIG_GNUTLS + qtest_add_func("/migration/postcopy/recovery/tls/psk", + test_postcopy_recovery_tls_psk); +#endif /* CONFIG_GNUTLS */ qtest_add_func("/migration/bad_dest", test_baddest); qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plai= n); qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbz= rle); --=20 2.32.0 From nobody Sun Feb 8 18:39:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650931055061883.6073297610748; Mon, 25 Apr 2022 16:57:35 -0700 (PDT) Received: from localhost ([::1]:34258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj8aE-0005kJ-2b for importer@patchew.org; Mon, 25 Apr 2022 19:57:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8Ie-0007nG-3t for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20858) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj8Ia-0007ml-RQ for qemu-devel@nongnu.org; Mon, 25 Apr 2022 19:39:23 -0400 Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-357-Vzrp2tvxPSamAaUy5bqhDg-1; Mon, 25 Apr 2022 19:39:15 -0400 Received: by mail-il1-f198.google.com with SMTP id o17-20020a92c691000000b002c2c04aebe7so6917415ilg.8 for ; Mon, 25 Apr 2022 16:39:15 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h7-20020a92c087000000b002cd809af4e4sm5435072ile.56.2022.04.25.16.39.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Apr 2022 16:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650929958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nbdXbPV/yHeCCxJoGKJzal9ZTZudP9VhG+RawmxDOkM=; b=GuySpFm7mN6upGsrF1WaIFQ+qead9Dg5H/cgmJjZuCZmR53qK0oDwj3mh2gK9lEJP/qzKD AucWz/ZoEoBWPJfEAWGxu+qjClrA92EhJNc82d9Ro2um0gCnwOPmhj+vONKBwFzwgx7XFC K8s1fuYQJCzuWxLyL1+lskMe3ctr6o8= X-MC-Unique: Vzrp2tvxPSamAaUy5bqhDg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nbdXbPV/yHeCCxJoGKJzal9ZTZudP9VhG+RawmxDOkM=; b=vBzYd8jRnYSgWBY3HKFyDMQ12wjcwx2aPxafm1+lfAicPlBKl3NSH3cZNOpWX+cmbK XXJS+J5GupkBcyTlnphoob8j4eQ7hED7DhWLsuRxhSsmtGVDG+N3a6ped8Xs0wEoqodC f4gciKen6LSNOXa02odnWEIzDC1Iqs+5y+Ko+47JeeOybOy+6Q6v486nBILsOgh9ndXp C9A1vWQS5mMYERzzNBAlxqooYJa5MLlQFP2q002hvKG7Y0AzCBpURvdnOu5xyDD1pSxV 2YtlRfqPc/idAeLrMinqm4d6FsvYXxizukI8UqL+Y8FcYhjuWOLe/lpkKDzo8AvMrqBs 7WSw== X-Gm-Message-State: AOAM531A38yr6OI3qQyCqrcZa5eqNm9gt0V2SVHdHR1k9xpOcIuy0MTx x7L4QGomEbrWevASmdJ/BJLsB4P/R0yjaOkyu3QGIgoMrM39mC1TgFseeLVZWjXz8XIH7ixDVFg VIuknOuD0HUYywnXwHoLeylfHXnqsij/FhxuqIyRHBtGmxBgIz9Dug24Iy8/mOvzj X-Received: by 2002:a92:c548:0:b0:2cc:47f1:815 with SMTP id a8-20020a92c548000000b002cc47f10815mr7892929ilj.257.1650929954384; Mon, 25 Apr 2022 16:39:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoCMMULNLVsVMgTdFSqqy/0zuibb91VTKZ4d/s4OGMpQ4cE7yaxccsxl6cDfNBXe14qO8bGg== X-Received: by 2002:a92:c548:0:b0:2cc:47f1:815 with SMTP id a8-20020a92c548000000b002cc47f10815mr7892912ilj.257.1650929954093; Mon, 25 Apr 2022 16:39:14 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v5 21/21] tests: Add postcopy preempt tests Date: Mon, 25 Apr 2022 19:38:47 -0400 Message-Id: <20220425233847.10393-22-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425233847.10393-1-peterx@redhat.com> References: <20220425233847.10393-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650931056848100001 Content-Type: text/plain; charset="utf-8" Four tests are added for preempt mode: - Postcopy plain - Postcopy recovery - Postcopy tls - Postcopy tls+recovery Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index cbcf3f73a4..af8d33c898 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -477,6 +477,7 @@ typedef struct { */ bool hide_stderr; bool use_shmem; + bool postcopy_preempt; /* only launch the target process */ bool only_target; /* Use dirty ring if true; dirty logging otherwise */ @@ -992,6 +993,11 @@ static int migrate_postcopy_prepare(QTestState **from_= ptr, migrate_set_capability(to, "postcopy-ram", true); migrate_set_capability(to, "postcopy-blocktime", true); =20 + if (args->postcopy_preempt) { + migrate_set_capability(from, "postcopy-preempt", true); + migrate_set_capability(to, "postcopy-preempt", true); + } + /* We want to pick a speed slow enough that the test completes * quickly, but that it doesn't complete precopy even on a slow * machine, so also set the downtime. @@ -1058,6 +1064,25 @@ static void test_postcopy_tls_psk(void) test_postcopy_common(&args); } =20 +static void test_postcopy_preempt(void) +{ + MigrateStart args =3D { + .postcopy_preempt =3D true, + }; + + test_postcopy_common(&args); +} + +static void test_postcopy_preempt_tls_psk(void) +{ + MigrateStart args =3D { + .postcopy_preempt =3D true, + .postcopy_tls =3D true, + }; + + test_postcopy_common(&args); +} + static void test_postcopy_recovery_common(MigrateStart *args) { QTestState *from, *to; @@ -1134,6 +1159,24 @@ static void test_postcopy_recovery_tls_psk(void) test_postcopy_recovery_common(&args); } =20 +static void test_postcopy_preempt_recovery(void) +{ + MigrateStart args =3D { .postcopy_preempt =3D true }; + + test_postcopy_recovery_common(&args); +} + +/* This contains preempt+recovery+tls test altogether */ +static void test_postcopy_preempt_all(void) +{ + MigrateStart args =3D { + .postcopy_preempt =3D true, + .postcopy_tls =3D true, + }; + + test_postcopy_recovery_common(&args); +} + static void test_baddest(void) { MigrateStart args =3D { @@ -2189,6 +2232,17 @@ int main(int argc, char **argv) qtest_add_func("/migration/postcopy/recovery/tls/psk", test_postcopy_recovery_tls_psk); #endif /* CONFIG_GNUTLS */ + + qtest_add_func("/migration/postcopy/preempt/plain", test_postcopy_pree= mpt); + qtest_add_func("/migration/postcopy/preempt/recovery/plain", + test_postcopy_preempt_recovery); +#ifdef CONFIG_GNUTLS + qtest_add_func("/migration/postcopy/preempt/tls/psk", + test_postcopy_preempt_tls_psk); + qtest_add_func("/migration/postcopy/preempt/recovery/tls/psk", + test_postcopy_preempt_all); +#endif /* CONFIG_GNUTLS */ + qtest_add_func("/migration/bad_dest", test_baddest); qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plai= n); qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbz= rle); --=20 2.32.0