From patchwork Fri Nov 1 08:51:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 178284 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp180526ill; Fri, 1 Nov 2019 01:58:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGIXd4Ne2FttNb9ZooaUDV/f30Be2SphfJsK0hfrXoYSOE72wJyXu6oVnYMqaGAXAYkyJa X-Received: by 2002:aed:3be9:: with SMTP id s38mr284592qte.175.1572598718648; Fri, 01 Nov 2019 01:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572598718; cv=none; d=google.com; s=arc-20160816; b=Fx+P4fqB5LNECxf9co7MtM2vQ2mVYMK7+9GI6NPJP6oSYOaxOpKuvBrocugynhR2Hk JeZrqy60gLVu84yJ/vU1i6yyvDfCkaLDusY0Cvwd4PkOqehvJJ4T+dAAlr0Cwo5oJIYz VwP+DmQXGX2QXB7cYRDV04sMpkwKRV/yvG3OLkYH2RLYU25ds1MzKNoHTYs0FduR9hvm o+zGNr/EThZLk0RRHRFvrOuPm75IpZCcdWbg95oa+TMICt3+8pExVP1Cr0t6unWwtQb4 TD7wdmIFy35ax0hPyEl1Upq69W/Z0Qt/ilO0R2Mpc1ELM5cEo0c3828+JgnYQUJcgrMc +bLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=62TpCPLeToJz0pC4qYB0g1aPcp75KDGFrfBiQCUjf5E=; b=ETum/TYfuFvfTCa8xUzK3NKbOMHLkFihUmY5yb/lfqmcu245PsEY1EdX+cS88Xfv03 UV50S2kF8C/wav9FAfmFZJfHj7F73y92zYURpv9JVyaDfLtO9IPovS8JDH7Cm26mPDHI 108aGzZw/ZiNZhJZjLnjHiIIybxUVH1XJPTMmy1U+AUIyiL2UD7H49ZBnBxKytj+CGQd o3oysHCSWQL6bbT60ZPmnPovvc9T3QehCjU/m55yENt67rNFhL094DgXNUPAeiew2ARq CVNV0sy8ZACEPnLrYhF372ioxQf/Ly/rwnsmPGCo0xigsN0lHudRy5sLG9UYxYxVnoCS aLWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OyqCk5FH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w185si6271468qka.122.2019.11.01.01.58.38 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Nov 2019 01:58:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OyqCk5FH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQSlR-0000I2-4i for patch@linaro.org; Fri, 01 Nov 2019 04:58:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56535) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQSf0-0001AC-4B for qemu-devel@nongnu.org; Fri, 01 Nov 2019 04:52:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQSew-0000W6-PK for qemu-devel@nongnu.org; Fri, 01 Nov 2019 04:51:56 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:54541) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iQSew-0000Ge-IW for qemu-devel@nongnu.org; Fri, 01 Nov 2019 04:51:54 -0400 Received: by mail-wm1-x336.google.com with SMTP id c12so4039918wml.4 for ; Fri, 01 Nov 2019 01:51:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=62TpCPLeToJz0pC4qYB0g1aPcp75KDGFrfBiQCUjf5E=; b=OyqCk5FHlgxu2t/T8mcCa0D9rXfQQyESK6j8dZu5gI7rHeKAZSjb7gvgzb4lY16vcp tOUd3gEVpDd8fjPZ6iPCVdOXNgyR2vHhwEBsslyqcPifV52+H3kahF63oM9kvm/NDrXO qmwXn28jVwPAECQPlNoeo2xbRNHBB7P+/424CzH10O9lHVXE6UNUbhkzECjqtqTmNF6y FlOkzIrNGcifiQVlGKkdYAwViB0cIM8yWSShruorhHqUuGihC50MNfsykXKCoBbs1G3m 0SLd4OU7TM3i7xYK0yVi77GY3Oj81KAmt9vwLx3COEFX0OKjtKI/xG8uWXBuwlxbUw14 xBOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=62TpCPLeToJz0pC4qYB0g1aPcp75KDGFrfBiQCUjf5E=; b=JneXSkzM9tTqkmJ6Ce4uODfWNwixEaom09neo1C2DnPs4OJjPCBpnoBVlWVWW/JjIC F4dGeS2aXEMPNqKCszg/zGwUWmT0utUdn4ijpHK47OZJgj1augwLLLMOTJ1sKrdUxKk9 0ZL65rTzg860YYYowSJspjoCCM560uVG3BLTfVjsYJrhY2qXNLgyZJrzN6WxXGPmcjHq ZGgd7ndNxoDFvOB5kaHjYfHNCV/vHfx50Q+pCrgYLAw4CbGoo6AHox6x3FL+dZrh/Tso qJD+ltlZqo/kOfpH4+UsPRDOussBR1eckULIYxk72mnnQ/luPn0Bon9oaz2JftlWjYBd NXWw== X-Gm-Message-State: APjAAAV0EfCjoK4x6/3nHsFgYrlYYwW6qJqhAaWDcKWo5C7gLqoK+pJX LQoiktXeoMfRdFhjWfgZW4yEiIkdJhPpVZI0 X-Received: by 2002:a05:600c:228b:: with SMTP id 11mr9375776wmf.112.1572598311316; Fri, 01 Nov 2019 01:51:51 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id d20sm8818922wra.4.2019.11.01.01.51.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2019 01:51:50 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 07/11] target/arm/kvm: scratch vcpu: Preserve input kvm_vcpu_init features Date: Fri, 1 Nov 2019 08:51:36 +0000 Message-Id: <20191101085140.5205-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191101085140.5205-1-peter.maydell@linaro.org> References: <20191101085140.5205-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::336 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Andrew Jones kvm_arm_create_scratch_host_vcpu() takes a struct kvm_vcpu_init parameter. Rather than just using it as an output parameter to pass back the preferred target, use it also as an input parameter, allowing a caller to pass a selected target if they wish and to also pass cpu features. If the caller doesn't want to select a target they can pass -1 for the target which indicates they want to use the preferred target and have it passed back like before. Signed-off-by: Andrew Jones Reviewed-by: Richard Henderson Reviewed-by: Eric Auger Tested-by: Masayoshi Mizuma Reviewed-by: Beata Michalska Message-id: 20191031142734.8590-8-drjones@redhat.com Signed-off-by: Peter Maydell --- target/arm/kvm.c | 20 +++++++++++++++----- target/arm/kvm32.c | 6 +++++- target/arm/kvm64.c | 6 +++++- 3 files changed, 25 insertions(+), 7 deletions(-) -- 2.20.1 diff --git a/target/arm/kvm.c b/target/arm/kvm.c index f07332bbda3..5b82cefef60 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -66,7 +66,7 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, int *fdarray, struct kvm_vcpu_init *init) { - int ret, kvmfd = -1, vmfd = -1, cpufd = -1; + int ret = 0, kvmfd = -1, vmfd = -1, cpufd = -1; kvmfd = qemu_open("/dev/kvm", O_RDWR); if (kvmfd < 0) { @@ -86,7 +86,14 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, goto finish; } - ret = ioctl(vmfd, KVM_ARM_PREFERRED_TARGET, init); + if (init->target == -1) { + struct kvm_vcpu_init preferred; + + ret = ioctl(vmfd, KVM_ARM_PREFERRED_TARGET, &preferred); + if (!ret) { + init->target = preferred.target; + } + } if (ret >= 0) { ret = ioctl(cpufd, KVM_ARM_VCPU_INIT, init); if (ret < 0) { @@ -98,10 +105,12 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, * creating one kind of guest CPU which is its preferred * CPU type. */ + struct kvm_vcpu_init try; + while (*cpus_to_try != QEMU_KVM_ARM_TARGET_NONE) { - init->target = *cpus_to_try++; - memset(init->features, 0, sizeof(init->features)); - ret = ioctl(cpufd, KVM_ARM_VCPU_INIT, init); + try.target = *cpus_to_try++; + memcpy(try.features, init->features, sizeof(init->features)); + ret = ioctl(cpufd, KVM_ARM_VCPU_INIT, &try); if (ret >= 0) { break; } @@ -109,6 +118,7 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, if (ret < 0) { goto err; } + init->target = try.target; } else { /* Treat a NULL cpus_to_try argument the same as an empty * list, which means we will fail the call since this must diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c index 2451a2d4bbe..32bf8d6757c 100644 --- a/target/arm/kvm32.c +++ b/target/arm/kvm32.c @@ -53,7 +53,11 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) QEMU_KVM_ARM_TARGET_CORTEX_A15, QEMU_KVM_ARM_TARGET_NONE }; - struct kvm_vcpu_init init; + /* + * target = -1 informs kvm_arm_create_scratch_host_vcpu() + * to use the preferred target + */ + struct kvm_vcpu_init init = { .target = -1, }; if (!kvm_arm_create_scratch_host_vcpu(cpus_to_try, fdarray, &init)) { return false; diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 850da1b5e6a..c7ecefbed72 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -502,7 +502,11 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) KVM_ARM_TARGET_CORTEX_A57, QEMU_KVM_ARM_TARGET_NONE }; - struct kvm_vcpu_init init; + /* + * target = -1 informs kvm_arm_create_scratch_host_vcpu() + * to use the preferred target + */ + struct kvm_vcpu_init init = { .target = -1, }; if (!kvm_arm_create_scratch_host_vcpu(cpus_to_try, fdarray, &init)) { return false;