From patchwork Thu May 2 07:26:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Doron X-Patchwork-Id: 1094016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="M08Tkbow"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44vnH80HRkz9s9y for ; Thu, 2 May 2019 17:40:20 +1000 (AEST) Received: from localhost ([127.0.0.1]:46656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM6KI-00052o-0U for incoming@patchwork.ozlabs.org; Thu, 02 May 2019 03:40:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM69W-0004P3-HM for qemu-devel@nongnu.org; Thu, 02 May 2019 03:29:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hM69R-0002TF-N9 for qemu-devel@nongnu.org; Thu, 02 May 2019 03:29:09 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:39151) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hM69M-0000mD-3M for qemu-devel@nongnu.org; Thu, 02 May 2019 03:29:04 -0400 Received: by mail-wr1-x442.google.com with SMTP id a9so1794635wrp.6 for ; Thu, 02 May 2019 00:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fq+y9Y8taPmtsyd8oOc7f9ZWDD3UWEkWOvqVLG/Lt40=; b=M08TkbowMNzKjXu92BROOswqomQg3jQWqbVYbvAvdoHrrKtXdFl0obLqqWyvJP5OoB 4qYoQbNTUN45z7e+KP8IfqAz+DGywmg8d4hv7q5VJKvRX2JuqaO0wzup4JpCT0v3nkfc rPgkEJH8qIea0F4daMLm9VRGLnJUF14vt7L3kPjG6ayI2+Q0mjpy5t0JL9HL60lcI4DC 0SmC0hLkAu7M0KFJcO2i51kJfZ6TsQh6rPf2P2TYpKDSMM1B3e4a4SABc9+DW5oSGWt6 hPELVUb69eZoAt0me0SvboRVXu1DsOdBuSsG3mc5st3d6ASLGCuHlg7+A33S2nFyjYne YOwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fq+y9Y8taPmtsyd8oOc7f9ZWDD3UWEkWOvqVLG/Lt40=; b=AfNj4UUvkU29WHNyft/tg7g8ug7J1gEGX4z0Yx0RtqMb5s5feJqVvVBot3JZbgWqbl RFtKQM4Ue6TP4wtncjS8cMcuD5dqGvgmW08lahORqGz+Led50Q2AbV5ThW6Xt+XXi8Yr z//TUllDKOxRKnzwMJtn88mXk6LOeeVCZVp50wQQdT0hwOndo8Nrv7m49ZXrBGgid4ae pmy5fjdLh90VVfpUzoZDUn413jcGqlnyXLFBLp3aSXzjZbw8MUdSaqB5uMkQIlqykS2M vxVPc+Zz3CkDg/lREeObsgP90eptaLuLuOmnZR74FOnymL+WUgc6bIh1rcM3TrvKT/UL 5uyA== X-Gm-Message-State: APjAAAXpPrOeH1K0Wqu7S7lN7LLpmOocIWjq4n8kw3pcY/qDsh75R5Br 3VM8e+4y1up2VzwRodsYmBBfvRkc X-Google-Smtp-Source: APXvYqwQo9wX6s6DwDn0wXKvrFc9LVj12oKft45CJXj997Yt16iABIyk2dEv1BrFAhOzR5Q0jDusIA== X-Received: by 2002:a05:6000:45:: with SMTP id k5mr1575120wrx.261.1556782056515; Thu, 02 May 2019 00:27:36 -0700 (PDT) Received: from localhost.localdomain ([176.230.64.186]) by smtp.gmail.com with ESMTPSA id z5sm8769289wre.70.2019.05.02.00.27.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 00:27:35 -0700 (PDT) From: Jon Doron To: qemu-devel@nongnu.org Date: Thu, 2 May 2019 10:26:39 +0300 Message-Id: <20190502072641.4667-26-arilou@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502072641.4667-1-arilou@gmail.com> References: <20190502072641.4667-1-arilou@gmail.com> 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::442 Subject: [Qemu-devel] [PATCH v8 25/27] kvm: Add API to read/write a CPU MSR value X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: liran.alon@oracle.com, alex.bennee@linaro.org, Jon Doron Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Jon Doron --- accel/kvm/kvm-all.c | 39 +++++++++++++++++++++++++++++++++++++++ include/sysemu/kvm.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 524c4ddfbd..35207d910b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2444,6 +2444,45 @@ void kvm_remove_all_breakpoints(CPUState *cpu) } #endif /* !KVM_CAP_SET_GUEST_DEBUG */ +int kvm_arch_read_msr(CPUState *cpu, uint32_t index, uint64_t *value) +{ + struct { + struct kvm_msrs info; + struct kvm_msr_entry entries[1]; + } msr_data; + int ret; + + msr_data.info.nmsrs = 1; + msr_data.entries[0].index = index; + ret = kvm_vcpu_ioctl(cpu, KVM_GET_MSRS, &msr_data); + if (ret < 0) { + return ret; + } + + *value = msr_data.entries[0].data; + return 0; +} + +int kvm_arch_write_msr(CPUState *cpu, uint32_t index, uint64_t value) +{ + struct { + struct kvm_msrs info; + struct kvm_msr_entry entries[1]; + } msr_data; + int ret; + + msr_data.info.nmsrs = 1; + msr_data.entries[0].index = index; + msr_data.entries[0].reserved = 0; + msr_data.entries[0].data = value; + ret = kvm_vcpu_ioctl(cpu, KVM_SET_MSRS, &msr_data); + if (ret < 0) { + return ret; + } + + return 0; +} + static int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset) { KVMState *s = kvm_state; diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index a6d1cd190f..409b1a5444 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -462,6 +462,8 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension); uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, uint32_t index, int reg); uint32_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index); +int kvm_arch_read_msr(CPUState *cpu, uint32_t index, uint64_t *value); +int kvm_arch_write_msr(CPUState *cpu, uint32_t index, uint64_t value); void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);