From patchwork Thu Oct 24 16:27:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 177589 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp2487000ill; Thu, 24 Oct 2019 10:20:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqycpcUixKRA6tx3mdORSriiKQdM3mlPSDC8ps332YzaqtNZVaJQxj36zuzcQxFGikN3yjYV X-Received: by 2002:ac8:3142:: with SMTP id h2mr5607892qtb.182.1571937604293; Thu, 24 Oct 2019 10:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571937604; cv=none; d=google.com; s=arc-20160816; b=gJNJaIQDg7torOh0OUFMcYtWRwOXWSRiMNIa/1mvthh4cJMkWcaP0Ibhp9YaN2nB/B bC6JUJfrdBsHPMnyjRC9gSkgALztbhLEC+0g59ZlW/SgiklN8DU40GT5Xqe4pIxjW5RV 7RvxHCxiEQosK6Y5hPGtpYybJxq0DqzrJsP+3oB61jN1C3PE0Fr7Z7AJ/IJyaWUJNLyE A99+zteSg5y6rRhZ4QpET9sNg+IPPJ+nhU3krZskL9ZOn5Tbt2X5V0lsbQ2cI/+f9jBl 34aBcGt0iH8ln4NiKj7Fnc6V1/BRYadcpSNSMGbJGUxnDCIpZxigvpbZaawhuKqQOZ0P LFHQ== 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=0ZlsAUBDsUyvYREq9UC6PUhIuy2cFHkEmU/zq4fnk1M=; b=vB/tKazEWR0qvi3K7R3o/fhKfGXWJQutnOrs0eA0Z5L5Ju0zSXQvMQd0xgxhWQtCAa thuWH75+/SuxOcnKkbc3iEo14Q8icMdsWdFN16cVG0WnRdskSZE7JEo1TqTnAmcY2T8o uQJI4bASka3FKF8bOlFUTo/uqmh7qyGZF3Ri8vg0XUDrTBQQl3EVsrVOBqMpW1n6kwxf I/0AO/3B/ad5OjnBDDG+0rG/FyWOW1Ka8QfrwDGIScjbKHU52sK5MN4xMstKgveGIN7z qmIBlNG0+5FFGK38vhOBkflQfg9y94upZ0HQpGwpJZ+jXyrDA74emKnh27XllT+wynGy cNlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ron7P1Kt; 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 a18si15135829qka.78.2019.10.24.10.20.04 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Oct 2019 10:20:04 -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=Ron7P1Kt; 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]:48560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNgmJ-0006Od-2c for patch@linaro.org; Thu, 24 Oct 2019 13:20:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58246) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNfyI-0008HV-Cg for qemu-devel@nongnu.org; Thu, 24 Oct 2019 12:28:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNfyG-00012a-0G for qemu-devel@nongnu.org; Thu, 24 Oct 2019 12:28:22 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:44677) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNfyF-00012K-Pz for qemu-devel@nongnu.org; Thu, 24 Oct 2019 12:28:19 -0400 Received: by mail-wr1-x42d.google.com with SMTP id z11so3426426wro.11 for ; Thu, 24 Oct 2019 09:28:19 -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=0ZlsAUBDsUyvYREq9UC6PUhIuy2cFHkEmU/zq4fnk1M=; b=Ron7P1Kt2i5RKXFToDi+kwl7uGK+AxvNo1pO1MP/jp7ROARYQ795E1kCn1ORVCDvQY WsjTpBhdhPYejrnHX2ZYAD8o3iqPLB88xyQy34giOURqftcOCyVwDrmTgI/pEv4a1t0c o9cuK4N0qg/XTGh5eLYqoEqPg6uFO/K5z35DaWMpwVjgkSWiky6wgw8azSqGS9cAMIwa QATAqevuzY7GTF/aRuSwmWysULHGnUlUQFmvFRTFyiGrY0Veur96TOCpEoRwPoW1ANmt 0/V07LePZxDzop38LO8d/BeeBmsaYAO1agfHov5YQUhzReawF13cviMdQRfLdEx7ywpJ Fg+w== 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=0ZlsAUBDsUyvYREq9UC6PUhIuy2cFHkEmU/zq4fnk1M=; b=BRYfm/Mq9WjUzzsOi6+DaW/5QuWTy0apzk5gxKodWzZw/S1sPPgaIEzHKYfjqSU71U fHJ+T6QR4mVBqLHaktzcTHtdxAZa5B0PhaC7nTVmSoMCIPyuHn64s8+JkTeptADhwXVp 9blorl+kFdkkTVJXqZBhmw3i1ja9pJzgCagbFk2ipyLIN32xQHjjGGpp1fy7Qcdf9x5M fLo2VRHjektfjIcTv2KyZ0iBIJ0xtJwVSZS4JTtV7+ld3ohMgfIPihSVnEBQYbpx654J I5o2phtFCTBNGstoQ+Qajk1hwpNtBx2j6dy+aK/9tX/5mWFSd1dDfyWWg5NTw5zsa7xZ AtbA== X-Gm-Message-State: APjAAAV8WsLeGf+dCO52ney5VdA706uQdTKwNA7RcyKRUiPvhrKoJ1MG d0HMhyNqsbkhxoWdKpkzVsBKQa7gv6M= X-Received: by 2002:a5d:4d46:: with SMTP id a6mr4836250wru.196.1571934498255; Thu, 24 Oct 2019 09:28:18 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id r27sm42606124wrc.55.2019.10.24.09.28.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 09:28:17 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 41/51] target/arm/kvm: scratch vcpu: Preserve input kvm_vcpu_init features Date: Thu, 24 Oct 2019 17:27:14 +0100 Message-Id: <20191024162724.31675-42-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191024162724.31675-1-peter.maydell@linaro.org> References: <20191024162724.31675-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::42d 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: 20191024121808.9612-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;