From patchwork Wed Feb 21 03:27:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13564891 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89AAF2E3FE; Wed, 21 Feb 2024 03:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486110; cv=none; b=nWnNyXfL+WdaoxwUOgT+WaBF/JUIhTDI5Cib35ag20dgkkh6VOznDIYWbg19DL5JBnQUSi5iSxdO6GA5PwlOGQUhoSM7pw8AhEGeokmp7Xu+AAAE2K8kX3ONZS3g1SdJTu4nKiXNG1zLjQeNJ0dEunNa7vaYscezhEDyCZTx2Cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486110; c=relaxed/simple; bh=2LO805GcRBB/AS3N3iJ/k5e5Yj6b0xPw/uYIJm4sYGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XfLpGvERwVnWUY/DKjGrAwnhRbdHKaSSjXzHE+bNu3r3rko3Pehroc2jAEJKEyLjhZs/MB+w379LEa0Uged2YfGmjlIMkzfPgaC6cYVF12O6IwUgJ+NNqqhgtmSKhN17C/GJGODgVDkAaIE5dTvegU+1eLCd/AdiEcbfR1WeAQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C5s2ov7P; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C5s2ov7P" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1d944e8f367so50031055ad.0; Tue, 20 Feb 2024 19:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708486108; x=1709090908; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=evUoa/UNV/oB4oPRxAOsnBRrgjlX2PtlMy4jxi9Yd70=; b=C5s2ov7PAMYdUNvHU5lbaliD5g/y0U/a4PplRNRiSFUZ7dIlvRDzgcwCHKbWaAqI06 dZwc8GelHqJucMf4JCK1Sirxdo4YTyyBD4Gbs2N98hyuCZOkOqd3ed3ZCQZeCscn2rSr ww1kPMEDiHgiamtTDyRoucXxn3gmYmWmh+AgfOM+VFFMpjxotdJozDPEjkAPLRZJEQ6K 4GSuWdPaMbNaOt0fQGJuYyVtI8R1LMsZyMDnWUOeS0LPLRktchL6dimYRa69fF0T8UM+ v49gJXJ0Q72uDIAs+h2QusS53WX4r+ijKwSk0cwDu1oLtvSzely9tDc0CQ/imMF9MXX7 HM5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486108; x=1709090908; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=evUoa/UNV/oB4oPRxAOsnBRrgjlX2PtlMy4jxi9Yd70=; b=qZisdxo7azMfy4Z9qpzn7ujTBSmSXYL6F9LDmayB0lqzPvCTDZtbJt4ioAkCOYcicQ YPzWStgQqv/+Zpk2DsSs8zBlAvKyKbheJrJ2OvZd05FSISq5TLMGKXNUBIdTIVEZ6RdU F+AZhnrLKkMjQFfEg1kZYzX48vKkgC2cArnGqSdgrTD5BaSpS2nICm2d2OQeDrVBBHMs N2Xx4tpPVnG1v8w3YVlCsn6s4F+inf7OO5lr97hd1vvfRFfnaQGgdSbJGBshaOBPE3nW y6wqYbNfIvOBnqZIRcroqY24+hDpKdZpAUg8X/+/IONLmvp+kYg5F2NcAQhl5lxmslnw uJPA== X-Forwarded-Encrypted: i=1; AJvYcCXbe+ERwLqmCgLHA37e2ApkNdpEt8c9cD4YUS9iPre4w3TYtNbqggg89o747JzImcAwQiITP55o6FvQgJEiLoH9KiOG7k+2PwaCao6+09kTvELohpid19cvXmL4dHabfg== X-Gm-Message-State: AOJu0YxcljcwO6fR9Z64kt85izu+w1jhEg0DMuiAJINxMsQLmYMBztFW mJaIRSbvsqdsnAGi5MM6BTtzRQECIh5ULdEYDdsphB9G0qb/H6sh X-Google-Smtp-Source: AGHT+IHLUAJXOt//4pQmY07Vj7IwKrIV54Fyb24iOQkYYZFJyUxY99z1JgYADhvTB6IxvrnEmb4LgA== X-Received: by 2002:a17:902:6806:b0:1db:e7dc:302f with SMTP id h6-20020a170902680600b001dbe7dc302fmr6474108plk.17.1708486107833; Tue, 20 Feb 2024 19:28:27 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id q7-20020a170902b10700b001dc214f7353sm1246457plr.249.2024.02.20.19.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:28:27 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Marc Hartmayer , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v5 1/8] arch-run: Fix TRAP handler recursion to remove temporary files properly Date: Wed, 21 Feb 2024 13:27:50 +1000 Message-ID: <20240221032757.454524-2-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240221032757.454524-1-npiggin@gmail.com> References: <20240221032757.454524-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Migration files were not being removed when the QEMU process is interrupted (e.g., with ^C). This is becaus the SIGINT propagates to the bash TRAP handler, which recursively TRAPs due to the 'kill 0' in the handler. This eventually crashes bash. This can be observed by interrupting a long-running test program that is run with MIGRATION=yes, /tmp/mig-helper-* files remain afterwards. Removing TRAP recursion solves this problem and allows the EXIT handler to run and clean up the files. This also moves the trap handler before temp file creation, which closes the small race between creation trap handler install. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- scripts/arch-run.bash | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index d0864360a..11d47a85c 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -129,6 +129,9 @@ run_migration () return 77 fi + trap 'trap - TERM ; kill 0 ; exit 2' INT TERM + trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT + migsock=$(mktemp -u -t mig-helper-socket.XXXXXXXXXX) migout1=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX) qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX) @@ -137,9 +140,6 @@ run_migration () qmpout1=/dev/null qmpout2=/dev/null - trap 'kill 0; exit 2' INT TERM - trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT - eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \ -mon chardev=mon1,mode=control | tee ${migout1} & live_pid=`jobs -l %+ | grep "eval" | awk '{print$2}'` @@ -209,11 +209,11 @@ run_panic () return 77 fi - qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX) - - trap 'kill 0; exit 2' INT TERM + trap 'trap - TERM ; kill 0 ; exit 2' INT TERM trap 'rm -f ${qmp}' RETURN EXIT + qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX) + # start VM stopped so we don't miss any events eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \ -mon chardev=mon1,mode=control -S & From patchwork Wed Feb 21 03:27:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13564892 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C64AE2E632; Wed, 21 Feb 2024 03:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486117; cv=none; b=V3XCk7i+vCcwb0mPtl/BskudG9g0zgfkIieYTsSqxuBxHC9BblFOfhbeBPghhPnBqASo62SFoFiS1Hb+M2Q4T9ocnfTbLBfWgnXn/wVL5e+qtM3tYcRVl/fUOwE+EcHGYZTTY+oAlG6+dvvIFZSNkY8xU/GlBeeGeETbwFZ2bDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486117; c=relaxed/simple; bh=y2BU4+PN8T27EuGhaIHzmKLCmns9lA/wgYSlFtfkTGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OyaPF0vDvCoQjWvnsU9MnOLPRYqJVKNWZEqci2ERBi50rSpA1UEt/SBYydAS2sRjiKCpELqey2DG+nLgJ+xms4HMapqMcFWTZlYHjIF816lgjWEp5oozc76lSiTitGEe9WWQE/9QSCy9j2UT1rjuV4PeAAFZqzxUsAEsY3crEiU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KmCy2mfu; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KmCy2mfu" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so113380a12.1; Tue, 20 Feb 2024 19:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708486115; x=1709090915; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5FLaKcAirk3CTYgyOfE+aKJ+UIKz3IbgFgbToFNpwyg=; b=KmCy2mfu32UBKKX0VkLB0N6pDX3LnbNVU4x7TUswhyuzSrpngpYHn2cyInF3yys/1Y yTanvkHM1vRnPaW4YLfPCIZjYJnO1kooFXVF/A+5EhP+k6S9XB+eq+Gs7plNifgj1Kmk mjBNpDQIYGZAnos/ejrd/pbayejv5oRiGes9TyC+l36kzXeWjF5cJ/7ms2rVJAZ+2PXi DddIavGMqoHFxG5UVfZhXsr4zZ6GC4uJSo73FYYCprC7DuBJ95ion07T7c0NE2cP3VKK rr6tcIXoaOtnIz/ydaaWct/1r1fvtg8v/YXaTBTcjWYeJdVTA+FULCZeH5xVuPZL7eQJ lB4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486115; x=1709090915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5FLaKcAirk3CTYgyOfE+aKJ+UIKz3IbgFgbToFNpwyg=; b=wrVBVXSU+o/6Nm79wvM0Tq8YR4uCYbJUO6N9S3TjNbZf37nm4svTDCXfYd1Qs0Cqzg pFNlo+w9+p9AEEHyrTRtZfwabHWsn8oJMJoTIl/ltfQ8yQjELtb8k+xcm3ZB20Ck7QOT PxO/fcBLMgsGBO9b9CTCildJKSTjWRZ9bZbmk7POxkvj96IajX1qrLTgMf/5/XmGtBS4 TVSOraelnAHt6Cl9P1XXDiOQ0tmsv10nYIY2SM6bF37j2vUWDSVPr7fQiGYX2mPJ5uIu fMIzYk7EAqN2zCFMsCQ9yWfZLYmLbAPn0V81UTofUXpo9hZLsfAisF45wMNFmb40rb2B in7w== X-Forwarded-Encrypted: i=1; AJvYcCXoUXvHfe3rx4H6EVszVS2A5DUHMCExmeV5Au3J0sBIKkGjPQ/es7C3LUSWEu6KQvI6W0nQVMINPSzKP5jy3lUMz7osFg5EB/H//dblt4yE649A26UI/Q0OcGuSQlUDJA== X-Gm-Message-State: AOJu0YzFJmDyplEwHiLUKQolHw3Wd9D3OswK4VggNGcb1iT3GXJaRTBF fTVkfpGXdREB++EXPpFfgVlTNQtzBm0fv3aWvST+FbnnVntybAGy X-Google-Smtp-Source: AGHT+IG+5kUDxEEdP+IqiK5SZK+gSM7uxbwCRRCoyT5fAJOZNRoAtH8MrNNdmRsQBrctGqSWy5fX0Q== X-Received: by 2002:a05:6a20:d498:b0:1a0:7e2f:ad44 with SMTP id im24-20020a056a20d49800b001a07e2fad44mr19469432pzb.31.1708486114991; Tue, 20 Feb 2024 19:28:34 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id q7-20020a170902b10700b001dc214f7353sm1246457plr.249.2024.02.20.19.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:28:34 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Marc Hartmayer , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v5 2/8] arch-run: Clean up initrd cleanup Date: Wed, 21 Feb 2024 13:27:51 +1000 Message-ID: <20240221032757.454524-3-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240221032757.454524-1-npiggin@gmail.com> References: <20240221032757.454524-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rather than put a big script into the trap handler, have it call a function. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- scripts/arch-run.bash | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 11d47a85c..c1dd67abe 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -269,10 +269,21 @@ search_qemu_binary () export PATH=$save_path } +initrd_cleanup () +{ + rm -f $KVM_UNIT_TESTS_ENV + if [ "$KVM_UNIT_TESTS_ENV_OLD" ]; then + export KVM_UNIT_TESTS_ENV="$KVM_UNIT_TESTS_ENV_OLD" + else + unset KVM_UNIT_TESTS_ENV + fi + unset KVM_UNIT_TESTS_ENV_OLD +} + initrd_create () { if [ "$ENVIRON_DEFAULT" = "yes" ]; then - trap_exit_push 'rm -f $KVM_UNIT_TESTS_ENV; [ "$KVM_UNIT_TESTS_ENV_OLD" ] && export KVM_UNIT_TESTS_ENV="$KVM_UNIT_TESTS_ENV_OLD" || unset KVM_UNIT_TESTS_ENV; unset KVM_UNIT_TESTS_ENV_OLD' + trap_exit_push 'initrd_cleanup' [ -f "$KVM_UNIT_TESTS_ENV" ] && export KVM_UNIT_TESTS_ENV_OLD="$KVM_UNIT_TESTS_ENV" export KVM_UNIT_TESTS_ENV=$(mktemp) env_params From patchwork Wed Feb 21 03:27:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13564893 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D212823C9; Wed, 21 Feb 2024 03:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486124; cv=none; b=H+HvFJ3wfMfJYfEMJBAfHHUYRzkLh82kBmwwxexK7eRKRPR+PDcsyYQCg1G9QcXDmEjgJB6dW2NTkjvR7hgoREAiD1SYR+dAqsIyTqGZpeihAyPciqAfmcgNp+M26EDs7uuVYgOAcOy5zj4X8tyfMy1Wdh7JlPT2jIak9rmDc/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486124; c=relaxed/simple; bh=zWC/ztnXPY0Ut0zueLckM+4+xHH3S+YXXr6p5gm7W0Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K6LAHqmVMj/K8mEJTELHuQv8i/OhOLQbXkE3hv4fPk5rgtqJg2eZwISmW8BGhHBHAk43eTKoNci+TDCH6DRe0ht+5CO/HnlZbBuTORQwZ5ixLssfY8FbSqhq1l//IWcSGeciFNsQZPkmaKjysMUusl+DWlM9TPYH5PdWO0VpPpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AVdInWGg; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AVdInWGg" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d932f6ccfaso51154665ad.1; Tue, 20 Feb 2024 19:28:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708486122; x=1709090922; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aML22p2QMiBfalmtqZDWpeCg6Y3ng+Yw7h/JELXYVmQ=; b=AVdInWGg0p3SrS3Ei85+5lsSHVLO7vnmpm3ghe0j6Dd4VsmOHnPF2puZse0t7ACEyO ijG+OeJ+hDHB3fP0QVkyiUR4QP3WZpGCqKsDD8wyDCoKvg/PUlt27A86q9U0SjZlYWHw 4pLRnND0EYIOdfHl7rYe2yANmHJDczhCAwI3ZruWnsXhP+gwvLYQbxwXlCVYhWylQ3vP bFq/bQLU7N4RSUvBWvKekbpj+ygIg5PuYhZeFZ4oovg7tOGmpGhKGJcH5rroYcsXVgUV mjY8JILbTZe9vhXmEThUutM0X7PRF9ctpuplvm6pzDDOhlL02YFBIPdHaSb7f/4L6ona RBTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486122; x=1709090922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aML22p2QMiBfalmtqZDWpeCg6Y3ng+Yw7h/JELXYVmQ=; b=FuRRiPoXiVOOYQCf40WO7H02z95r+HQx4m5EJbDw+JXR93jeB5V1fpTse+numxP+nH 291MUcvPzsCOEufi38+2FVEiyQ4qkwBGxHVINvEzTS0zTIKKJei9TDwDxWj8tJyaHDzz /cXno0tN2rUtbmsUt7oGdfnq5qN2C75ShtnbcJRnCaMGKjH/lQKxHMkkpJ6RoX/d9EKc kqMkNsEmKdMRSi+1DDLJVbxDUAeq+b36xc1q0q0VQO/m74ViqMvc6lf3V7zjPYRyNyR8 ebDGXNOmPsP54cTF29L5HP9FuRj+XkhW2XhWtBxaLxtbnm1JDaMmWMPAIzJpL2Jhowhp 0YpA== X-Forwarded-Encrypted: i=1; AJvYcCUdqrtLu+gTrBhckHWZTqcz6I9lNP3ZhaiM5D3s0106gVIfBq3Jut2oZfuyvb6OdBsopogSsakb4ei7VZbhrBqXU7fbZnfBBm4/CUe9EJMod/4w0AGQrMLTeybquLnrjQ== X-Gm-Message-State: AOJu0YyAD+k74ja3pkNzb2sh6/2P4zXHqt2aGrAfxYRdh09IUNvZIThP CpX1Uix+Tz7nF+huoLF31SdvVhnlf+RMdxjMHWBZMsGWyeMNU0de X-Google-Smtp-Source: AGHT+IHloA4lPV1h3NnRO9wb8wmRssFTGmRoI3MuzFAdRdZDmNqGWg7XAdoSic5qIBVsB6jy4FznyQ== X-Received: by 2002:a17:902:7001:b0:1da:1e83:b961 with SMTP id y1-20020a170902700100b001da1e83b961mr14195507plk.63.1708486122293; Tue, 20 Feb 2024 19:28:42 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id q7-20020a170902b10700b001dc214f7353sm1246457plr.249.2024.02.20.19.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:28:42 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Marc Hartmayer , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v5 3/8] migration: use a more robust way to wait for background job Date: Wed, 21 Feb 2024 13:27:52 +1000 Message-ID: <20240221032757.454524-4-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240221032757.454524-1-npiggin@gmail.com> References: <20240221032757.454524-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Starting a pipeline of jobs in the background does not seem to have a simple way to reliably find the pid of a particular process in the pipeline (because not all processes are started when the shell continues to execute). The way PID of QEMU is derived can result in a failure waiting on a PID that is not running. This is easier to hit with subsequent multiple-migration support. Changing this to use $! by swapping the pipeline for a fifo is more robust. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- scripts/arch-run.bash | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index c1dd67abe..9a5aaddcc 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -130,19 +130,22 @@ run_migration () fi trap 'trap - TERM ; kill 0 ; exit 2' INT TERM - trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT + trap 'rm -f ${migout1} ${migout_fifo1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT migsock=$(mktemp -u -t mig-helper-socket.XXXXXXXXXX) migout1=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX) + migout_fifo1=$(mktemp -u -t mig-helper-fifo-stdout1.XXXXXXXXXX) qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX) qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX) fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX) qmpout1=/dev/null qmpout2=/dev/null + mkfifo ${migout_fifo1} eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \ - -mon chardev=mon1,mode=control | tee ${migout1} & - live_pid=`jobs -l %+ | grep "eval" | awk '{print$2}'` + -mon chardev=mon1,mode=control > ${migout_fifo1} & + live_pid=$! + cat ${migout_fifo1} | tee ${migout1} & # We have to use cat to open the named FIFO, because named FIFO's, unlike # pipes, will block on open() until the other end is also opened, and that @@ -150,7 +153,7 @@ run_migration () mkfifo ${fifo} eval "$@" -chardev socket,id=mon2,path=${qmp2},server=on,wait=off \ -mon chardev=mon2,mode=control -incoming unix:${migsock} < <(cat ${fifo}) & - incoming_pid=`jobs -l %+ | awk '{print$2}'` + incoming_pid=$! # The test must prompt the user to migrate, so wait for the "migrate" keyword while ! grep -q -i "Now migrate the VM" < ${migout1} ; do @@ -164,6 +167,10 @@ run_migration () sleep 1 done + # Wait until the destination has created the incoming and qmp sockets + while ! [ -S ${migsock} ] ; do sleep 0.1 ; done + while ! [ -S ${qmp2} ] ; do sleep 0.1 ; done + qmp ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1} # Wait for the migration to complete From patchwork Wed Feb 21 03:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13564894 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE71623C9; Wed, 21 Feb 2024 03:28:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486131; cv=none; b=FAjfhk5Y7MJlmSFDHp3lPa/fTd7wFJ3ftNVIu/n+DEuim41hrljr48EQJBzvbUL85Z3/6Hrkzvglcs8d9IOSLcp8cr3J+ztBSjP1hZodurGbv2KKf3wm9wFguzDbnR/n4h9i7wdnSqXhq7vaAaWpAy8nFIA768XnTYT3QFhGJ1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486131; c=relaxed/simple; bh=H1wRxzOCbQ9LlcX8uPKoxvTEVRreXVCTRDk0tZeAGFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aRev4IxfQ7rWD2rY5aY2USPG0c6M+OfuzEP49umNp5UIgRiaW6y1rdKNJe9+Ss0yrSyyzH1r9wVZs6ZXEoF03fi6Ak+s/rWmq5suthSOVCjiHRFjNUPprAGUrUmVXkrHsLT9mBgkORU1/7PgLXgi1XE5QVtmQgaI9J5KpWWmOWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SBmuNrmA; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SBmuNrmA" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d73066880eso58665865ad.3; Tue, 20 Feb 2024 19:28:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708486129; x=1709090929; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3D869cFhRopw5qITnMcIX0RsIcUf5yocR4SzD+VoOnY=; b=SBmuNrmASejYNKLVOe4kDWwgsMRJupcCrqQEAqo9ALt0wdSNG3HhvT2BAhhJgqebYe WkbhMjwduWvmkFHIGefMTt1wzh+hbcY+1alxIRIZ/4R4nMNxT7fQyIulJ4ipGPyzGiWe UQRw+hbplDnAYtOe8F3qu8RVvgKAMgmpLhOqSI3n65YsSnpbpVfeobnbWwjFqQcTmdvm iuChUqWUpR4XvvGfr9/Vgq0obBnX+sLvaSCW4sCPvcdOmko0px2QfjRKwJenGqLkOwIj pvmGnCkPyvOdGkPm2/wmY13V3oS7J7ORHWQZ9mNkv9PnpGe9vDWtpfEGn7oWkY9UC2JJ xl2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486129; x=1709090929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3D869cFhRopw5qITnMcIX0RsIcUf5yocR4SzD+VoOnY=; b=NG7rDGqvhEFukPcMcZliXTwBDYEzloHDJ6WCk0ahP+1pMo+qFfp54IYnuyLqZdPBYS qPPtaFNe3hXgdDJClwlvRvcBLRZb0UhK/8gIY7SfjxMhfb2ATlsxRllTs+JkZSXFV/TI sH2CiwICG6NfVdWEIsueo99SRtGDwko5GAJULOy/75mcpgoYyQ9fJSvVw4ibIszeurgX JDOGQdkkcxF6/a4fOTOBAH43bOMUJjEhw3NJNqMOcSdbIa4ToWl0mxdlrDuIkNZuAINN 7icFbOjiysn9Cwhl2gev5wXg7e64F5gQdH9QehUZRGGt6w421YFTpZMhGLh4rTS1F77Q jj9w== X-Forwarded-Encrypted: i=1; AJvYcCUYR4VJES8L4OpSAe4L5b/n7Obxivbcs6JIvgYrA+zOUv0pAHWC+/Se1bJZoGta2KO/2HufzEQdeLGlefU3Vv9zoQ50FtTlkwfwnkeNcBCnqDKcJsnfm1H2+VGmTAdNvg== X-Gm-Message-State: AOJu0YxqpgSpTpX6r+cv1uuK4N3YZFF4+PCfU0Bl42DhDieDueUFQOJD rnGONqahe9ee49vK3qgMYH5BUU7x66XAtTVnWh6TNbmCVutDQ6DE X-Google-Smtp-Source: AGHT+IHwwMBr2JmzFJDzZeVdYZUelRxdGLpWAB3n/eeLq7GSP7C3diyEMO0XE7I94wUzHFDofRzLAg== X-Received: by 2002:a17:902:d58a:b0:1dc:29df:277e with SMTP id k10-20020a170902d58a00b001dc29df277emr1909586plh.47.1708486129301; Tue, 20 Feb 2024 19:28:49 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id q7-20020a170902b10700b001dc214f7353sm1246457plr.249.2024.02.20.19.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:28:49 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Marc Hartmayer , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v5 4/8] migration: Support multiple migrations Date: Wed, 21 Feb 2024 13:27:53 +1000 Message-ID: <20240221032757.454524-5-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240221032757.454524-1-npiggin@gmail.com> References: <20240221032757.454524-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Support multiple migrations by flipping dest file/socket variables to source after the migration is complete, ready to start again. A new destination is created if the test outputs the migrate line again. Test cases may now switch to calling migrate() one or more times. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/migrate.c | 8 ++-- lib/migrate.h | 1 + scripts/arch-run.bash | 86 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 77 insertions(+), 18 deletions(-) diff --git a/lib/migrate.c b/lib/migrate.c index 527e63ae1..b77216594 100644 --- a/lib/migrate.c +++ b/lib/migrate.c @@ -8,8 +8,10 @@ #include #include "migrate.h" -/* static for now since we only support migrating exactly once per test. */ -static void migrate(void) +/* + * Initiate migration and wait for it to complete. + */ +void migrate(void) { puts("Now migrate the VM, then press a key to continue...\n"); (void)getchar(); @@ -19,8 +21,6 @@ static void migrate(void) /* * Initiate migration and wait for it to complete. * If this function is called more than once, it is a no-op. - * Since migrate_cmd can only migrate exactly once this function can - * simplify the control flow, especially when skipping tests. */ void migrate_once(void) { diff --git a/lib/migrate.h b/lib/migrate.h index 3c94e6af7..2af06a72d 100644 --- a/lib/migrate.h +++ b/lib/migrate.h @@ -6,4 +6,5 @@ * Author: Nico Boehr */ +void migrate(void); void migrate_once(void); diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 9a5aaddcc..c2002d7ae 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -129,12 +129,16 @@ run_migration () return 77 fi + migcmdline=$@ + trap 'trap - TERM ; kill 0 ; exit 2' INT TERM - trap 'rm -f ${migout1} ${migout_fifo1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT + trap 'rm -f ${migout1} ${migout2} ${migout_fifo1} ${migout_fifo2} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT migsock=$(mktemp -u -t mig-helper-socket.XXXXXXXXXX) migout1=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX) migout_fifo1=$(mktemp -u -t mig-helper-fifo-stdout1.XXXXXXXXXX) + migout2=$(mktemp -t mig-helper-stdout2.XXXXXXXXXX) + migout_fifo2=$(mktemp -u -t mig-helper-fifo-stdout2.XXXXXXXXXX) qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX) qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX) fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX) @@ -142,20 +146,54 @@ run_migration () qmpout2=/dev/null mkfifo ${migout_fifo1} - eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \ + mkfifo ${migout_fifo2} + + eval "$migcmdline" \ + -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \ -mon chardev=mon1,mode=control > ${migout_fifo1} & live_pid=$! cat ${migout_fifo1} | tee ${migout1} & - # We have to use cat to open the named FIFO, because named FIFO's, unlike - # pipes, will block on open() until the other end is also opened, and that - # totally breaks QEMU... + # Start the first destination QEMU machine in advance of the test + # reaching the migration point, since we expect at least one migration. + # Then destination machines are started after the test outputs + # subsequent "Now migrate the VM" messages. + do_migration || return $? + + while ps -p ${live_pid} > /dev/null ; do + # Wait for test exit or further migration messages. + if ! grep -q -i "Now migrate the VM" < ${migout1} ; then + sleep 0.1 + else + do_migration || return $? + fi + done + + wait ${live_pid} + ret=$? + + while (( $(jobs -r | wc -l) > 0 )); do + sleep 0.1 + done + + return $ret +} + +do_migration () +{ + # We have to use cat to open the named FIFO, because named FIFO's, + # unlike pipes, will block on open() until the other end is also + # opened, and that totally breaks QEMU... mkfifo ${fifo} - eval "$@" -chardev socket,id=mon2,path=${qmp2},server=on,wait=off \ - -mon chardev=mon2,mode=control -incoming unix:${migsock} < <(cat ${fifo}) & + eval "$migcmdline" \ + -chardev socket,id=mon2,path=${qmp2},server=on,wait=off \ + -mon chardev=mon2,mode=control -incoming unix:${migsock} \ + < <(cat ${fifo}) > ${migout_fifo2} & incoming_pid=$! + cat ${migout_fifo2} | tee ${migout2} & - # The test must prompt the user to migrate, so wait for the "migrate" keyword + # The test must prompt the user to migrate, so wait for the + # "Now migrate VM" console message. while ! grep -q -i "Now migrate the VM" < ${migout1} ; do if ! ps -p ${live_pid} > /dev/null ; then echo "ERROR: Test exit before migration point." >&2 @@ -164,7 +202,7 @@ run_migration () qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null return 3 fi - sleep 1 + sleep 0.1 done # Wait until the destination has created the incoming and qmp sockets @@ -176,7 +214,7 @@ run_migration () # Wait for the migration to complete migstatus=`qmp ${qmp1} '"query-migrate"' | grep return` while ! grep -q '"completed"' <<<"$migstatus" ; do - sleep 1 + sleep 0.1 if ! migstatus=`qmp ${qmp1} '"query-migrate"'`; then echo "ERROR: Querying migration state failed." >&2 echo > ${fifo} @@ -192,14 +230,34 @@ run_migration () return 2 fi done + qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null + + # keypress to dst so getchar completes and test continues echo > ${fifo} - wait $incoming_pid + rm ${fifo} + + # Ensure the incoming socket is removed, ready for next destination + if [ -S ${migsock} ] ; then + echo "ERROR: Incoming migration socket not removed after migration." >& 2 + qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null + return 2 + fi + + wait ${live_pid} ret=$? - while (( $(jobs -r | wc -l) > 0 )); do - sleep 0.5 - done + # Now flip the variables because dest becomes source + live_pid=${incoming_pid} + tmp=${migout1} + migout1=${migout2} + migout2=${tmp} + tmp=${migout_fifo1} + migout_fifo1=${migout_fifo2} + migout_fifo2=${tmp} + tmp=${qmp1} + qmp1=${qmp2} + qmp2=${tmp} return $ret } From patchwork Wed Feb 21 03:27:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13564895 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23B7423C9; Wed, 21 Feb 2024 03:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486138; cv=none; b=haY5oEPbLJRzXSyR7PCVGqogxubCS6MLqlCzaoiM7IflR5+n7wAoDs9qGSFNBcn2eQSYffr27+EMcDftB3KmocE3eo1V2fpYTDmwJu/VBX6edeBeCkcVBc4dUsO+Xd3Ecx8EGHKvNXeD1b8wJcDM98Njo2d/qyUjj2qDXRK2K6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486138; c=relaxed/simple; bh=eaAT5vTL48HoNAwY0vLoztczNG5SlDsv/2faEC4BX4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q4t9jOXWUeYzdnmeEiVsnxzyvzeaSV0xu6zwZxo5hsqNv+mA8XcxDyc2urtqBGmN/CF1HtmilAUDEkjxA87H8zEcZfIigcvbQfyzw7AnqCmU4t1v4deQXDtQAwBuaspXx6AG9PVY7RdQf83kYPAdOXKv0sRtCzGpivqR1EQHojI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lCgKxBBV; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lCgKxBBV" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d8da50bffaso31422765ad.2; Tue, 20 Feb 2024 19:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708486136; x=1709090936; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H8OprHoI60WCjUrEFrRYccBS1NmFjGjrdIyTLJzB9cM=; b=lCgKxBBVLHylKhXxVX/2oIE6HfX38q9NMvOtg3ZwSu6VMNXbH1+rWchU54Edw0ps/w ahQa/fpr0uzrxufeC7XTm0EwCMk6f5oc+OJDCIK8fdnsp8mEmE3q3VSwvxiwwV18bbo2 jCmFxhELBkfeVj8Q0uEwWNdqrkHcN99Dwb3ItxJre2PmyV8Ei85ZRNCtuIiSYh1pJ/Zx onuXuFOYLLLJ5sP7wGPmUyOnW8ebEtrDJk/FGLPQHfgqBC99NUIBFiQ3ttEg85WlDaaj CS54D62HtSQI4gN1vkqCFWTHK8W0/+iEM9/YzxcOpunytErFDIfJxCNeCMyVJMDilpD9 rvGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486136; x=1709090936; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H8OprHoI60WCjUrEFrRYccBS1NmFjGjrdIyTLJzB9cM=; b=LFX7+FQ7Uh0hPNSQ8kzJIf2/rNsWha3qJkZj2AMx/wxwudi044YaPAECnAAz+DH2WW bz1OeJLiA5tzlMPqBxUEeTfRPllhsP3IXIXAvsEO+oS7I9qxEaox4wFuNoHtG7AefwkW SLmH/RmLUQjbByXCubye6ays4po+ypFy8MQvdEMHBk6yGFc7EuyB+09UrSwALKgsiRL8 OZViGdmcSK7mbtDlF+SlSUYage/YfteWc07kxU90eQAkAC0JaTxeANvnT4Ie9jFa1gv+ XEks+Vw65NIQd+oGe5yQhB8hvM+5DMnSWP0n1Sd6IHaGTHp7iIR17nQjdwNxWHsTIdHI 2UNA== X-Forwarded-Encrypted: i=1; AJvYcCVEirQS2muIpvXzTtVScPGnxED6Q3W6hpMfG25CJcgYFYweaXyhoLQEvx8YkqwaSbN0KlpFXZl1/S7mNkVRMdQHQsM4gumyyc1h/o2dlks7xoOkI+x4xWCbGFpBSd7pGQ== X-Gm-Message-State: AOJu0YxKLLwqrAukElU3jAVvlEJH2ZESia6Ys8Ut3N5fQf9YZ8HTDh42 ttqq9wyHK+sfM7c+fjNAKuGzVx+u+J8lxj2un6pNHux4em9DUGbX X-Google-Smtp-Source: AGHT+IEAXQef3gkWLv/2fQdnRK95TAMbbzGrHIx8+Ge20qaykjwlv3LOd0VxWSLbdmK49lX4ynq9WQ== X-Received: by 2002:a17:902:b201:b0:1dc:fb2:d5fe with SMTP id t1-20020a170902b20100b001dc0fb2d5femr5082789plr.22.1708486136556; Tue, 20 Feb 2024 19:28:56 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id q7-20020a170902b10700b001dc214f7353sm1246457plr.249.2024.02.20.19.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:28:56 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Marc Hartmayer , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v5 5/8] arch-run: rename migration variables Date: Wed, 21 Feb 2024 13:27:54 +1000 Message-ID: <20240221032757.454524-6-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240221032757.454524-1-npiggin@gmail.com> References: <20240221032757.454524-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using 1 and 2 for source and destination is confusing, particularly now with multiple migrations that flip between them. Do a rename pass to 'src' and 'dst' to tidy things up. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- scripts/arch-run.bash | 111 +++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index c2002d7ae..c98429e8c 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -132,27 +132,27 @@ run_migration () migcmdline=$@ trap 'trap - TERM ; kill 0 ; exit 2' INT TERM - trap 'rm -f ${migout1} ${migout2} ${migout_fifo1} ${migout_fifo2} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT - - migsock=$(mktemp -u -t mig-helper-socket.XXXXXXXXXX) - migout1=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX) - migout_fifo1=$(mktemp -u -t mig-helper-fifo-stdout1.XXXXXXXXXX) - migout2=$(mktemp -t mig-helper-stdout2.XXXXXXXXXX) - migout_fifo2=$(mktemp -u -t mig-helper-fifo-stdout2.XXXXXXXXXX) - qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX) - qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX) - fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX) - qmpout1=/dev/null - qmpout2=/dev/null - - mkfifo ${migout_fifo1} - mkfifo ${migout_fifo2} + trap 'rm -f ${src_out} ${dst_out} ${src_outfifo} ${dst_outfifo} ${dst_incoming} ${src_qmp} ${dst_qmp} ${dst_infifo}' RETURN EXIT + + dst_incoming=$(mktemp -u -t mig-helper-socket-incoming.XXXXXXXXXX) + src_out=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX) + src_outfifo=$(mktemp -u -t mig-helper-fifo-stdout1.XXXXXXXXXX) + dst_out=$(mktemp -t mig-helper-stdout2.XXXXXXXXXX) + dst_outfifo=$(mktemp -u -t mig-helper-fifo-stdout2.XXXXXXXXXX) + src_qmp=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX) + dst_qmp=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX) + dst_infifo=$(mktemp -u -t mig-helper-fifo-stdin.XXXXXXXXXX) + src_qmpout=/dev/null + dst_qmpout=/dev/null + + mkfifo ${src_outfifo} + mkfifo ${dst_outfifo} eval "$migcmdline" \ - -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \ - -mon chardev=mon1,mode=control > ${migout_fifo1} & + -chardev socket,id=mon,path=${src_qmp},server=on,wait=off \ + -mon chardev=mon,mode=control > ${src_outfifo} & live_pid=$! - cat ${migout_fifo1} | tee ${migout1} & + cat ${src_outfifo} | tee ${src_out} & # Start the first destination QEMU machine in advance of the test # reaching the migration point, since we expect at least one migration. @@ -162,7 +162,7 @@ run_migration () while ps -p ${live_pid} > /dev/null ; do # Wait for test exit or further migration messages. - if ! grep -q -i "Now migrate the VM" < ${migout1} ; then + if ! grep -q -i "Now migrate the VM" < ${src_out} ; then sleep 0.1 else do_migration || return $? @@ -184,80 +184,81 @@ do_migration () # We have to use cat to open the named FIFO, because named FIFO's, # unlike pipes, will block on open() until the other end is also # opened, and that totally breaks QEMU... - mkfifo ${fifo} + mkfifo ${dst_infifo} eval "$migcmdline" \ - -chardev socket,id=mon2,path=${qmp2},server=on,wait=off \ - -mon chardev=mon2,mode=control -incoming unix:${migsock} \ - < <(cat ${fifo}) > ${migout_fifo2} & + -chardev socket,id=mon,path=${dst_qmp},server=on,wait=off \ + -mon chardev=mon,mode=control -incoming unix:${dst_incoming} \ + < <(cat ${dst_infifo}) > ${dst_outfifo} & incoming_pid=$! - cat ${migout_fifo2} | tee ${migout2} & + cat ${dst_outfifo} | tee ${dst_out} & # The test must prompt the user to migrate, so wait for the # "Now migrate VM" console message. - while ! grep -q -i "Now migrate the VM" < ${migout1} ; do + while ! grep -q -i "Now migrate the VM" < ${src_out} ; do if ! ps -p ${live_pid} > /dev/null ; then echo "ERROR: Test exit before migration point." >&2 - echo > ${fifo} - qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null - qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null + echo > ${dst_infifo} + qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null + qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null return 3 fi sleep 0.1 done # Wait until the destination has created the incoming and qmp sockets - while ! [ -S ${migsock} ] ; do sleep 0.1 ; done - while ! [ -S ${qmp2} ] ; do sleep 0.1 ; done + while ! [ -S ${dst_incoming} ] ; do sleep 0.1 ; done + while ! [ -S ${dst_qmp} ] ; do sleep 0.1 ; done - qmp ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1} + qmp ${src_qmp} '"migrate", "arguments": { "uri": "unix:'${dst_incoming}'" }' > ${src_qmpout} # Wait for the migration to complete - migstatus=`qmp ${qmp1} '"query-migrate"' | grep return` + migstatus=`qmp ${src_qmp} '"query-migrate"' | grep return` while ! grep -q '"completed"' <<<"$migstatus" ; do sleep 0.1 - if ! migstatus=`qmp ${qmp1} '"query-migrate"'`; then + if ! migstatus=`qmp ${src_qmp} '"query-migrate"'`; then echo "ERROR: Querying migration state failed." >&2 - echo > ${fifo} - qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null + echo > ${dst_infifo} + qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null return 2 fi migstatus=`grep return <<<"$migstatus"` if grep -q '"failed"' <<<"$migstatus"; then echo "ERROR: Migration failed." >&2 - echo > ${fifo} - qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null - qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null + echo > ${dst_infifo} + qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null + qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null return 2 fi done - qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null + qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null # keypress to dst so getchar completes and test continues - echo > ${fifo} - rm ${fifo} + echo > ${dst_infifo} + rm ${dst_infifo} # Ensure the incoming socket is removed, ready for next destination - if [ -S ${migsock} ] ; then + if [ -S ${dst_incoming} ] ; then echo "ERROR: Incoming migration socket not removed after migration." >& 2 - qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null + qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null return 2 fi wait ${live_pid} ret=$? - # Now flip the variables because dest becomes source + # Now flip the variables because destination machine becomes source + # for the next migration. live_pid=${incoming_pid} - tmp=${migout1} - migout1=${migout2} - migout2=${tmp} - tmp=${migout_fifo1} - migout_fifo1=${migout_fifo2} - migout_fifo2=${tmp} - tmp=${qmp1} - qmp1=${qmp2} - qmp2=${tmp} + tmp=${src_out} + src_out=${dst_out} + dst_out=${tmp} + tmp=${src_outfifo} + src_outfifo=${dst_outfifo} + dst_outfifo=${tmp} + tmp=${src_qmp} + src_qmp=${dst_qmp} + dst_qmp=${tmp} return $ret } @@ -280,8 +281,8 @@ run_panic () qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX) # start VM stopped so we don't miss any events - eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \ - -mon chardev=mon1,mode=control -S & + eval "$@" -chardev socket,id=mon,path=${qmp},server=on,wait=off \ + -mon chardev=mon,mode=control -S & panic_event_count=$(qmp_events ${qmp} | jq -c 'select(.event == "GUEST_PANICKED")' | wc -l) if [ "$panic_event_count" -lt 1 ]; then From patchwork Wed Feb 21 03:27:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13564896 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7184C39843; Wed, 21 Feb 2024 03:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486145; cv=none; b=tQQr9N/Ar2ZPCGTOoyOQ+jPjlihlFNdqAYNqpu8MbAvH6joYdHHn1HDbq878Pq8wsdgQmVMBqcSoGgYkQ6kQCcLfKoeo+/FMAUGOXjrp5dC5ZlF+95mweQ4LEFqKm+8Y4+j7k+oqiGqkCR3StejmT4Pq69j1TJBu57vUNj5RStw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486145; c=relaxed/simple; bh=qDu6HLAwjNl8M0s+0tLz6VpR3l1XS4W0h0eQig5mi1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=leKsGIdrDUDBwR58YaM8TPEIvj2dK8jcKQ7eJftqgmIwLA8bUukdNZ3fU2E8K8o7ToTGaQWLr6WsIvFjJFGtG2AA68CwIB8cji4IysDku3ylENQWKwVrT9O8P9NIZrKUjmpXvdexxqpf93fAUxR8cQanBVBqHe/BnPt0hWMx9Kk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EylNUC4M; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EylNUC4M" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1dba94f9201so40629865ad.0; Tue, 20 Feb 2024 19:29:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708486144; x=1709090944; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IIo+YCQIpcqZZQl5SQPpBtKwaaGVQawpmU1ARg6aVZc=; b=EylNUC4MetQBC5T7EQ/lKzuVAE3CUuC1ozcv+0bd+K6dcBnu2iVCf1Hu0MlH6eGhe8 5zFsoFFdr4wTtWTm6ZmeqENpD3v2P05sOn9sd0rv2FGhwo+juO0MsRBZNKb5BbFB4VSH xVW5+DQaNY7n6t5NlLMVQQwa4tD3Bi1sWvSTU4dc3VR9C1saNnQEQkWzLlIQdQaFv9+4 87jIipC4YHXjkuvXAhqzu5k4GCHPcClWRW8uWTalVKTSXFNUc6vesYZNSNCiDHDYrLTT r7FfxrbGGT3tsiv5ltXi1AMLllTrbRwGZgxc3ZUf4QXJcPJFXBPe7+qn9yK/+oXnPkkS 6anQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486144; x=1709090944; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IIo+YCQIpcqZZQl5SQPpBtKwaaGVQawpmU1ARg6aVZc=; b=bYihPaMB4LRf94HxvZ0Qg7rNR5K6REyMIJ5c1pKEqbF1Cms7rtka24jkyD219Nuao2 gz/jM9WEc1emVRQff0azZIRJ7HZC8uwfaaV2Hs1eAM5+4RfQ1gPNZim2Gac2eUIQIAJu rK5Vj0FIE4WeByHv5JnWuX9GLP5Z91emi/2w3AuXrJ6Lz2vUrHkQglGo4aOh9hOwhgRq KHEMmh5T5UO0YJjg92WPzmQ2nITHg4+A/rXeDlmA0EtCebLF7w/O+WRBB328GnZ0oJ6n bBtiBRhxPMjPBHfXQCBnkBqspjqwCCEvKAKtXOEsH0HwtwVUcT1kPYWQJ9cydEwSY+4X zo4w== X-Forwarded-Encrypted: i=1; AJvYcCUcqzYcpiXaanra1Vs6QUH6psvv9yocXsQh4qUywpGbV7cRNHqoA8+SMlLnln5ymp3leFkRRMpjWj9qX/zPT/+hommwZhTfws0eF7KCQ/A+VDjfMDBV84HDKI0MYXEALQ== X-Gm-Message-State: AOJu0Yz2YisyfrpScfu1HiagwpQI8x6JxD3h44YuP46pAiIvQRpFwqb/ t5Gl2ATmQVQUb4xaqUTeeVP2VHSYK3csXxizawljfWDXV4o9TqEt X-Google-Smtp-Source: AGHT+IGkE2tXMoP+uu2dMPF9yafXmDF1WYeLW14EiA+DBNvKy9Jy7TtJJX6AdHjI0vAVunFoMBALqg== X-Received: by 2002:a17:903:1211:b0:1d9:a609:dd7e with SMTP id l17-20020a170903121100b001d9a609dd7emr19873074plh.55.1708486143769; Tue, 20 Feb 2024 19:29:03 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id q7-20020a170902b10700b001dc214f7353sm1246457plr.249.2024.02.20.19.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:29:03 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Marc Hartmayer , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v5 6/8] migration: Add quiet migration support Date: Wed, 21 Feb 2024 13:27:55 +1000 Message-ID: <20240221032757.454524-7-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240221032757.454524-1-npiggin@gmail.com> References: <20240221032757.454524-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Console output required to support migration becomes quite noisy when doing lots of migrations. Provide a migrate_quiet() call that suppresses console output and doesn't log a message. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/migrate.c | 11 +++++++++++ lib/migrate.h | 1 + scripts/arch-run.bash | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/migrate.c b/lib/migrate.c index b77216594..92d1d957d 100644 --- a/lib/migrate.c +++ b/lib/migrate.c @@ -18,6 +18,17 @@ void migrate(void) report_info("Migration complete"); } +/* + * Like migrate() but suppress output and logs, useful for intensive + * migration stress testing without polluting logs. Test cases should + * provide relevant information about migration in failure reports. + */ +void migrate_quiet(void) +{ + puts("Now migrate the VM (quiet)\n"); + (void)getchar(); +} + /* * Initiate migration and wait for it to complete. * If this function is called more than once, it is a no-op. diff --git a/lib/migrate.h b/lib/migrate.h index 2af06a72d..95b9102b0 100644 --- a/lib/migrate.h +++ b/lib/migrate.h @@ -7,4 +7,5 @@ */ void migrate(void); +void migrate_quiet(void); void migrate_once(void); diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index c98429e8c..0a98e5127 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -152,7 +152,7 @@ run_migration () -chardev socket,id=mon,path=${src_qmp},server=on,wait=off \ -mon chardev=mon,mode=control > ${src_outfifo} & live_pid=$! - cat ${src_outfifo} | tee ${src_out} & + cat ${src_outfifo} | tee ${src_out} | grep -v "Now migrate the VM (quiet)" & # Start the first destination QEMU machine in advance of the test # reaching the migration point, since we expect at least one migration. @@ -190,7 +190,7 @@ do_migration () -mon chardev=mon,mode=control -incoming unix:${dst_incoming} \ < <(cat ${dst_infifo}) > ${dst_outfifo} & incoming_pid=$! - cat ${dst_outfifo} | tee ${dst_out} & + cat ${dst_outfifo} | tee ${dst_out} | grep -v "Now migrate the VM (quiet)" & # The test must prompt the user to migrate, so wait for the # "Now migrate VM" console message. From patchwork Wed Feb 21 03:27:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13564897 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA850383BF; Wed, 21 Feb 2024 03:29:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486153; cv=none; b=X3+AVmHbaFdkhwtAtLHpDgMAeh9KGvT7UKe4fgzPo9TFiYEo31WhZ1Gw8CTjnqRaihbAde9qZKU3xRf/oqHZGWj0KxcYjZuYdpH3vt5jRpfvHiD4ZLX2T6+gF5n3pzOHcUD+kloPCg+P19okjEqnuGi4D04tnKwz7bD61SMTwyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486153; c=relaxed/simple; bh=lE4WrwkyDtaQgF2D2jO1Cwot422cIfXq3YZMhla4BRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yu+22HlQkIUl0soLty36BjnYNnmjUjH6u/3eNEYr6JGGhWo6XoIsO2LOsvrYBgoRqK2q/eet7sKjBJ7InOslDKeoSnBt3iXOsXVMrLsZRjzNpmeoqjf6vryFA/55pOhqrmyDmJwmFRGYAZBZ0/wTLXKujAsHxf93jPppvQP/Y6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cgNWR1XE; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cgNWR1XE" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e466a679bfso140684b3a.1; Tue, 20 Feb 2024 19:29:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708486150; x=1709090950; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nuBjCwoeaNr8AGy/7SQu2RQwLY1MBjVxyn5YkQsjDDI=; b=cgNWR1XEMhx7Tt16+03kYqjp0+z3ds41dSwEFV8ntV0xHlc2YN3LVGp5YVbuaH5K4o rWx/N0XJnzvEfKVAfGCWTqAe1VXuIzTD7Cl9IPJRSuLyklXXyEu6UC6BJGM99PjIFtdg rw1E94KTki7k0x1NjtOscVHFksDQ+ZNGO0VegZ0f5ZNYbRI2tKy6n9WfvDwZRxgLVxXa x9l+se4R40yyQvxjyphdasFNQpq8joh4qOm6XSB9QL8pH8DzCsDh6U4RWfKUcSmoaZRi Pi1Vq9tei2UcEG5TCiFGSYA5MhuXNjMC5/xfcH8JihpLut8GrRVqNW2LDlf4qJuwL9YG 4cuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486150; x=1709090950; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nuBjCwoeaNr8AGy/7SQu2RQwLY1MBjVxyn5YkQsjDDI=; b=Y2dNekrV1XX22tl8VtlWGzn2LGNO7VrT69ikIZ7gYPjQyrmCcw4AKTU/WNTnP8xgJP sEsQqJSw20a6Hc04KcGwS5KaN9q/vayHEDH/oamJgAdtddWSd0IlQIqPEL1kL7zDVvjd dK2So3JS0wqgsSLAJjLH2BtuQo+0Yh4OTo4qG5uUoBNQ+3UJMErGUBImUwaqAkQVFBCt I4ngg8fznnYiT8xLVFsaSviFbPgOm04qEFj2oPyRaf5kelMcO7leumSHpI45jAwBKykv Z1hFXmZ8Wr0USlGUy5pOJBHLrZmW9JVRcpWq6tAq7eKNGIDO1w5fqL20QMNXtD06YMMY 0Lzg== X-Forwarded-Encrypted: i=1; AJvYcCWMrB+9Yowpku0wjpKRyyhgcPq9140yv6m/Cwi603ptXk8JjyZliL+lKUmrOBAA7AYIPr20HiUbm0enkmAkgoYMsuIWQo38Vft7QgLQgXq6n6urKFNm9bi8X81OhL5GBw== X-Gm-Message-State: AOJu0YymOJ1Cg114sEWIjA2H5HPilGzyPAdBNRv5n7krmYYkw6y4ciIp 8XhbRVH2IH3kbcOOoYeDztlUm1IRZMUPPODI0Uh6P7PuyHw/9/yE X-Google-Smtp-Source: AGHT+IFMU4gzIndebrpd/hVeeR/Ex4Y3al2xaliSFhhET1KuVUMyOzj4zCCOyaTOOsv8L4D8Foc82g== X-Received: by 2002:a05:6a20:d703:b0:19c:6fb0:2b02 with SMTP id iz3-20020a056a20d70300b0019c6fb02b02mr17269437pzb.61.1708486150696; Tue, 20 Feb 2024 19:29:10 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id q7-20020a170902b10700b001dc214f7353sm1246457plr.249.2024.02.20.19.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:29:10 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Marc Hartmayer , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v5 7/8] Add common/ directory for architecture-independent tests Date: Wed, 21 Feb 2024 13:27:56 +1000 Message-ID: <20240221032757.454524-8-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240221032757.454524-1-npiggin@gmail.com> References: <20240221032757.454524-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 x86/sieve.c is used by s390x, arm, and riscv via symbolic link. Make a new directory common/ for architecture-independent tests and move sieve.c here. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin Acked-by: Andrew Jones --- arm/sieve.c | 2 +- common/sieve.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ riscv/sieve.c | 2 +- s390x/sieve.c | 2 +- x86/sieve.c | 52 +------------------------------------------------- 5 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 common/sieve.c mode change 100644 => 120000 x86/sieve.c diff --git a/arm/sieve.c b/arm/sieve.c index 8f14a5c3d..fe299f309 120000 --- a/arm/sieve.c +++ b/arm/sieve.c @@ -1 +1 @@ -../x86/sieve.c \ No newline at end of file +../common/sieve.c \ No newline at end of file diff --git a/common/sieve.c b/common/sieve.c new file mode 100644 index 000000000..8150f2d98 --- /dev/null +++ b/common/sieve.c @@ -0,0 +1,51 @@ +#include "alloc.h" +#include "libcflat.h" + +static int sieve(char* data, int size) +{ + int i, j, r = 0; + + for (i = 0; i < size; ++i) + data[i] = 1; + + data[0] = data[1] = 0; + + for (i = 2; i < size; ++i) + if (data[i]) { + ++r; + for (j = i*2; j < size; j += i) + data[j] = 0; + } + return r; +} + +static void test_sieve(const char *msg, char *data, int size) +{ + int r; + + printf("%s:", msg); + r = sieve(data, size); + printf("%d out of %d\n", r, size); +} + +#define STATIC_SIZE 1000000 +#define VSIZE 100000000 +char static_data[STATIC_SIZE]; + +int main(void) +{ + void *v; + int i; + + printf("starting sieve\n"); + test_sieve("static", static_data, STATIC_SIZE); + setup_vm(); + test_sieve("mapped", static_data, STATIC_SIZE); + for (i = 0; i < 3; ++i) { + v = malloc(VSIZE); + test_sieve("virtual", v, VSIZE); + free(v); + } + + return 0; +} diff --git a/riscv/sieve.c b/riscv/sieve.c index 8f14a5c3d..fe299f309 120000 --- a/riscv/sieve.c +++ b/riscv/sieve.c @@ -1 +1 @@ -../x86/sieve.c \ No newline at end of file +../common/sieve.c \ No newline at end of file diff --git a/s390x/sieve.c b/s390x/sieve.c index 8f14a5c3d..fe299f309 120000 --- a/s390x/sieve.c +++ b/s390x/sieve.c @@ -1 +1 @@ -../x86/sieve.c \ No newline at end of file +../common/sieve.c \ No newline at end of file diff --git a/x86/sieve.c b/x86/sieve.c deleted file mode 100644 index 8150f2d98..000000000 --- a/x86/sieve.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "alloc.h" -#include "libcflat.h" - -static int sieve(char* data, int size) -{ - int i, j, r = 0; - - for (i = 0; i < size; ++i) - data[i] = 1; - - data[0] = data[1] = 0; - - for (i = 2; i < size; ++i) - if (data[i]) { - ++r; - for (j = i*2; j < size; j += i) - data[j] = 0; - } - return r; -} - -static void test_sieve(const char *msg, char *data, int size) -{ - int r; - - printf("%s:", msg); - r = sieve(data, size); - printf("%d out of %d\n", r, size); -} - -#define STATIC_SIZE 1000000 -#define VSIZE 100000000 -char static_data[STATIC_SIZE]; - -int main(void) -{ - void *v; - int i; - - printf("starting sieve\n"); - test_sieve("static", static_data, STATIC_SIZE); - setup_vm(); - test_sieve("mapped", static_data, STATIC_SIZE); - for (i = 0; i < 3; ++i) { - v = malloc(VSIZE); - test_sieve("virtual", v, VSIZE); - free(v); - } - - return 0; -} diff --git a/x86/sieve.c b/x86/sieve.c new file mode 120000 index 000000000..fe299f309 --- /dev/null +++ b/x86/sieve.c @@ -0,0 +1 @@ +../common/sieve.c \ No newline at end of file From patchwork Wed Feb 21 03:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13564898 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB6812E842; Wed, 21 Feb 2024 03:29:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486160; cv=none; b=faFu+UTgEQTDeoYYdK+yn0a3MXhTmi1iTMP7ZEGp2VZ49+ayT4jHdWCQndqwf2iVFCZQwsQ/EIJ01eULd5iWFFEnGnKjEneaj2dqhgTG2qaD54Gnp+U+y8dQ9mVTqqocVnFy3k0jQIyHBq6otD5PJBg/bZKy3HY+i5863msx5Eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486160; c=relaxed/simple; bh=MEerVrBTKNNzcjobYPP0RyiwtXU/Fqyl+6g7hmECOc4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CDsCl70nA75HcZGtdsKaQUeTyllqRv3E60pFppwfiDJMEPh6sywvyc/DgaMfJL/ig82uRNhr1yJXAZFfMgpfaiAIb6YKjcQqeLlpVJgGOL+IeVGA8OwxwAHsU5zxKb2FJdtZbjOr2NoxD6EmAF0SRNygZlcK0LSSf2nnO4Piclg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F5H9zgBP; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F5H9zgBP" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d911c2103aso35187175ad.0; Tue, 20 Feb 2024 19:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708486158; x=1709090958; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rKTDdfNq5MGrQ+0iUWX57avIL8YHWFp0YDpAZCY+Suc=; b=F5H9zgBPHhRR6QAq4SvhqW7AODj8MecEWcRjuEZ4P+KUzl1yn0HzO7+TLAcUfD6nP8 aoP8pxGkA0akTu7JmJ4d3M6rA7isiIrmFcRSxOwF5ER434rCf0omUGMnqCrso3MGk6C3 nrTyq1lSYxAicbzU3FTxNdAzyx01yL1PpjH0VbVOgKqYF6WlKbHQBQHEmK5iFmGLJJ/P tHz1veL4DHhmOmfgg//8ogVfHVcqlQZmq4LINILPzL7AVQyOUBN+xyCs5FRacKSJiLAQ jpBjGKrnmOFyl4xRRN64RGmpcNO9SEieGjFPt+gy9d/GRFj6XyqLYSnneNBYhGNNLETI TIAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486158; x=1709090958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rKTDdfNq5MGrQ+0iUWX57avIL8YHWFp0YDpAZCY+Suc=; b=fjgjvyzhxhcQEYjkn+56nDC8El9JZQAeaEx0PQ6zYh/CpbC9JLbbu57lxrKIOPdFRr uiFmiU1J7j974pioAHsDtfDJmS8f+Rbc9t0LoIMQyQazSK2cNgP0Z6uovBJh0JWtX64L Qig7YvtkptwR9Cq3A/3rV8kPtOmYxOkuPOHY4tG8tEGOP/Maf8qXWigUBAcuat0CSEWL cmdx7IEKVKu5P4fpFlYLonX+06UBJvlGcwFkHG+0REaYCC28Pn40P4dR9xOWg2vfVNPd YJsC0zlXFf6rnkb4TuE0hWe+CuQySOsEnsAdzupoCYH3g1nnVMFBjSVf6FH0Oml60Euy mVlg== X-Forwarded-Encrypted: i=1; AJvYcCXx36Bm3oRWxPVKO8JJ05NatYaxDBunw8uTysbfVf7R/bseVdprzEzmvIvdO/8dw13xgIY6pMZI+9QrJ9+P8uOtb5sZAdqT/SqntNDKWVimS5cQHrY3nCUKtirM+MtZfQ== X-Gm-Message-State: AOJu0YyT3dIn5l/ZsrMqc/OulF9eO953nuqv/XShk+3htvhvZ+f/xn/4 N8cWfcvJor1rtZRAG5XoaDgiTzqGaLewncjLMDeCw4T189M5TSlO X-Google-Smtp-Source: AGHT+IH1x5xMI9uoPg2lnHlSiQRJh3IyeLPtdt/kc7CIoeguyY7MUFojlqvGni7okVmY4JK8i1uByQ== X-Received: by 2002:a17:902:ccce:b0:1dc:30bb:b5cf with SMTP id z14-20020a170902ccce00b001dc30bbb5cfmr558973ple.59.1708486158130; Tue, 20 Feb 2024 19:29:18 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id q7-20020a170902b10700b001dc214f7353sm1246457plr.249.2024.02.20.19.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:29:17 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Marc Hartmayer , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v5 8/8] migration: add a migration selftest Date: Wed, 21 Feb 2024 13:27:57 +1000 Message-ID: <20240221032757.454524-9-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240221032757.454524-1-npiggin@gmail.com> References: <20240221032757.454524-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a selftest for migration support in guest library and test harness code. It performs migrations in a tight loop to irritate races and bugs in the test harness code. Include the test in s390, powerpc. Acked-by: Claudio Imbrenda (s390x) Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- common/selftest-migration.c | 29 +++++++++++++++++++++++++++++ powerpc/Makefile.common | 1 + powerpc/selftest-migration.c | 1 + powerpc/unittests.cfg | 4 ++++ s390x/Makefile | 1 + s390x/selftest-migration.c | 1 + s390x/unittests.cfg | 4 ++++ 7 files changed, 41 insertions(+) create mode 100644 common/selftest-migration.c create mode 120000 powerpc/selftest-migration.c create mode 120000 s390x/selftest-migration.c diff --git a/common/selftest-migration.c b/common/selftest-migration.c new file mode 100644 index 000000000..54b5d6b2d --- /dev/null +++ b/common/selftest-migration.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Machine independent migration tests + * + * This is just a very simple test that is intended to stress the migration + * support in the test harness. This could be expanded to test more guest + * library code, but architecture-specific tests should be used to test + * migration of tricky machine state. + */ +#include +#include + +#define NR_MIGRATIONS 30 + +int main(int argc, char **argv) +{ + int i = 0; + + report_prefix_push("migration"); + + for (i = 0; i < NR_MIGRATIONS; i++) + migrate_quiet(); + + report(true, "simple harness stress test"); + + report_prefix_pop(); + + return report_summary(); +} diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index eb88398d8..da4a7bbb8 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -6,6 +6,7 @@ tests-common = \ $(TEST_DIR)/selftest.elf \ + $(TEST_DIR)/selftest-migration.elf \ $(TEST_DIR)/spapr_hcall.elf \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ diff --git a/powerpc/selftest-migration.c b/powerpc/selftest-migration.c new file mode 120000 index 000000000..bd1eb266d --- /dev/null +++ b/powerpc/selftest-migration.c @@ -0,0 +1 @@ +../common/selftest-migration.c \ No newline at end of file diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index e71140aa5..7ce57de02 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -36,6 +36,10 @@ smp = 2 extra_params = -m 256 -append 'setup smp=2 mem=256' groups = selftest +[selftest-migration] +file = selftest-migration.elf +groups = selftest migration + [spapr_hcall] file = spapr_hcall.elf diff --git a/s390x/Makefile b/s390x/Makefile index b72f7578f..344d46d68 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -1,4 +1,5 @@ tests = $(TEST_DIR)/selftest.elf +tests += $(TEST_DIR)/selftest-migration.elf tests += $(TEST_DIR)/intercept.elf tests += $(TEST_DIR)/emulator.elf tests += $(TEST_DIR)/sieve.elf diff --git a/s390x/selftest-migration.c b/s390x/selftest-migration.c new file mode 120000 index 000000000..bd1eb266d --- /dev/null +++ b/s390x/selftest-migration.c @@ -0,0 +1 @@ +../common/selftest-migration.c \ No newline at end of file diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index f5024b6ee..a7ad522ca 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -24,6 +24,10 @@ groups = selftest # please keep the kernel cmdline in sync with $(TEST_DIR)/selftest.parmfile extra_params = -append 'test 123' +[selftest-migration] +file = selftest-migration.elf +groups = selftest migration + [intercept] file = intercept.elf