All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Mohamed Mediouni" <mohamed@unpredictable.fr>,
	"Thomas Huth" <thuth@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH] tests/functional: Check for nested virtualization to run KVM tests
Date: Fri, 16 Jan 2026 09:59:56 +0000	[thread overview]
Message-ID: <aWoMHGNxzHVdh2CT@redhat.com> (raw)
In-Reply-To: <20260116070438.31869-1-philmd@linaro.org>

On Fri, Jan 16, 2026 at 08:04:38AM +0100, Philippe Mathieu-Daudé wrote:
> On Apple Silicon, nested virtualization starts to be usable
> with M3 models and later. Check for the CPU model to avoid
> failure on pre-M3:
> 
>   qemu-system-aarch64: unable to find CPU model 'cortex-a72'
> 
> Now tests are correctly skipped, i.e. on M1:
> 
>   ok 1 test_kvm.Aarch64VirtKVMTests.test_aarch64_nvhe_selftest # SKIP Nested Virtualization not available on Apple M1 Pro
>   ok 2 test_kvm.Aarch64VirtKVMTests.test_aarch64_vhe_selftest # SKIP Nested Virtualization not available on Apple M1 Pro
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  tests/functional/aarch64/test_kvm.py | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/tests/functional/aarch64/test_kvm.py b/tests/functional/aarch64/test_kvm.py
> index 7545f5ed554..b26c849ec67 100755
> --- a/tests/functional/aarch64/test_kvm.py
> +++ b/tests/functional/aarch64/test_kvm.py
> @@ -29,8 +29,31 @@ class Aarch64VirtKVMTests(LinuxKernelTest):
>      # base of tests
>      KUT_BASE = "/usr/share/kvm-unit-tests/"
>  
> +    def require_nested_virtualization(self):
> +        """
> +        Requires the accelerator to support nested virtualization for the test
> +        to continue
> +
> +        If the check fails, the test is canceled.
> +        """
> +        import platform, re, subprocess
> +
> +        if platform.system() != 'Darwin':
> +            return
> +        r = subprocess.run(['sysctl', '-n', 'machdep.cpu.brand_string'],
> +                           text=True, capture_output=True)
> +        if r.returncode != 0:
> +            return
> +        m = re.match(r"Apple M(\d+)( .*)?", r.stdout)

I tend to prefer check_call/check_output over the plain 'run',
in this case check_output is suitble

    try
       data = subprocess.check_output([..args..], encoding='utf8')
    except CalledProcessError
       return
    m = re.match(r"Apple M(\d+)( .*)?", data)


> +        if m:
> +            if int(m.group(1)) < 3:
> +                self.skipTest("Nested Virtualization not available"
> +                              " on %s" % r.stdout.strip())

Please add this as a decorator in tests/functional/qemu_tests/decorators.py
called something like  "skipUnlessNestedVirtSupported".

> +
>      def _launch_guest(self, kvm_mode="nvhe"):
>  
> +        self.require_nested_virtualization()
> +
>          self.set_machine('virt')
>          kernel_path = self.ASSET_KVM_TEST_KERNEL.fetch()
>  
> -- 
> 2.52.0
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



      reply	other threads:[~2026-01-16 10:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16  7:04 [PATCH] tests/functional: Check for nested virtualization to run KVM tests Philippe Mathieu-Daudé
2026-01-16  9:59 ` Daniel P. Berrangé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aWoMHGNxzHVdh2CT@redhat.com \
    --to=berrange@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=mohamed@unpredictable.fr \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.