From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0100BCA9ECF for ; Fri, 1 Nov 2019 08:57:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C13B2204FD for ; Fri, 1 Nov 2019 08:57:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OyqCk5FH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C13B2204FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQSkV-0007BX-Uo for qemu-devel@archiver.kernel.org; Fri, 01 Nov 2019 04:57:39 -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-Google-Smtp-Source: APXvYqzRPCxQu90lty6bAbYVWChe/HbVLl4hLyZlWesx/t5ljE91z/51kLvRJi2b06Iy70HGFRZIpA== 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 Content-Transfer-Encoding: 8bit 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+qemu-devel=archiver.kernel.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(-) 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; -- 2.20.1