Received: by 10.223.185.116 with SMTP id b49csp5808587wrg; Tue, 27 Feb 2018 22:04:36 -0800 (PST) X-Google-Smtp-Source: AH8x225A7lhlmOCDqCyHGRxMPZicaKn0qUnROiaCac7lNr11qTPnplaIDeBwnSRaccHDG0kHLgte X-Received: by 2002:a17:902:9343:: with SMTP id g3-v6mr17103322plp.319.1519797876007; Tue, 27 Feb 2018 22:04:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519797875; cv=none; d=google.com; s=arc-20160816; b=mtEDNjiP8oeRO5qQKKof3Y4WYsMZACeC6CvtdwDjX/wHVJqMKMcSnU/lQwpD5KVPNI LYINHtUvAXigSSzbp8xrp6vu5Ofnk7li9IW3VOLGkawKdte9M88FVKn7tOWYznU9x2Ae +apIQyM89f4tY53OAXUd3KMzEJqYHf5BY/qTkA3fjEnXAxSx6kb02/GpjJ+yiS9mhENE vRHlPX+/LaEAP9Uo26Hp0XbY4DFW9UcOGjZFuIa6RA3mpP+qoA1MxYf921WJkOrroHNI XlnP/pAlzFcnN9zOokPjTG7XyNwN/UpcBZiIKHRu5n+IHAQ7FboUsEiESfEHOEPW5VpH tiAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=MA0qOqmJsPS2H7YD3S5NSSg2FEZMb+zSlnuv/RH6djw=; b=KcrWD1t5gAs3eHD3VElAG0451/GDSnSbqqLnRGuVMSvwcu48cbaTQWoTNQEXxddzK8 HRRjq9qU4PWm9rQ8SHu/U2sLNhBHhMdmPAlZnzpSR8F+6YNY8/krjMdEQUQ+dd7jhMy3 qNCG2zLbmZC4oyVMSVXcX/S13jlpF4RABRP7IACJ+ZOyyxe1rX667Z5iPj7m6Dd0T+0Y mjLMhyNEg2h6RGMBmLLQiIVAuDJIcqCFXl0SX0MAf7UlfQwcmW3O6EjL6/NPGRf5g+eR RxgkrnmHsO0KrfhY/l+tiQsRo6VRYfyiwa9ft+2IwMw65nu/U1rZJsGwM4u14M5R+X80 sU+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ofbun8j9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6-v6si739037plh.287.2018.02.27.22.04.20; Tue, 27 Feb 2018 22:04:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ofbun8j9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751819AbeB1GDj (ORCPT + 99 others); Wed, 28 Feb 2018 01:03:39 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:38506 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751027AbeB1GDh (ORCPT ); Wed, 28 Feb 2018 01:03:37 -0500 Received: by mail-io0-f195.google.com with SMTP id g21so1932619ioj.5; Tue, 27 Feb 2018 22:03:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MA0qOqmJsPS2H7YD3S5NSSg2FEZMb+zSlnuv/RH6djw=; b=Ofbun8j9l2wxPsE04j0YfKPHzbPWHaiJ99b18EMRrOSy4J8Qaq8rtynRcIdZ+wBxqL a+wRkHySqPb4tmcjSuPCrPEvUPLtFq2u8FzbLezHqHcst3K/G/5gXa0S9RKI3CI0hgd/ 6003V5P9bdBQG7boE2XUAVYJxo/rJsWwQpo2rfQv4V9Fu3EoH4WSYrZDp6VqucBcRwT9 oZC2/AKT7molEFg9F8EauaNRcsQXK8pIJoHuT3xIyxBzks7IZXwCUFxfBqMn0U4Tqj5b nal1Bqh8LrBQ9aLUJzHEIQX9rJn/occOIBGxaEfqO1Qjja6DFxerXYxGbM9jukfetF/y q8lg== 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:mime-version :content-transfer-encoding; bh=MA0qOqmJsPS2H7YD3S5NSSg2FEZMb+zSlnuv/RH6djw=; b=cMyolx1arGGZiwZ8l1YI5iLlz9Dz02g3cqNvqiML70j1W06hiVy94FrpUsX5Lhekcq yhEW65ruKemWyTi6QUfGWoZ2IaRv71/7Sgca5W+6xZWfD/41UJG3/ufrUQwTB6FEIrLU 4CtqF3KjnkP1MemsVlmfIZYk7eH5qpCbFYFUQPn2g+hOmfirIuveKycp2qJWDiMrWglf lLpWVodHTozc6g01XcRUZ5oad90s6gyTBzzrSIUL0tpC1BxMJR3d2xey8K5I6qB1+OJO qumaTr4jykqU0GCOLeNpWUKWNS/4RcmvQ4Jeu2EFs6PVzHFxZm53mtrof3AzXlVVqoAm GBnw== X-Gm-Message-State: APf1xPCd3PB6luZzyhsOUz7ZasvEWJB5EJGoA2iaNrtnI42uRC3stc1I 9ua6NupEAmm5MW2ucKKLiqOpdQ== X-Received: by 10.107.160.74 with SMTP id j71mr8987895ioe.10.1519797817022; Tue, 27 Feb 2018 22:03:37 -0800 (PST) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id h63sm852096ith.32.2018.02.27.22.03.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 22:03:36 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Liran Alon , Nadav Amit , Borislav Petkov , Tom Lendacky Subject: [PATCH RESEND v5 1/2] KVM: X86: Introduce kvm_get_msr_feature() Date: Wed, 28 Feb 2018 14:03:30 +0800 Message-Id: <1519797811-4560-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li Introduce kvm_get_msr_feature() to handle the msrs which are supported by different vendors and sharing the same emulation logic. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Liran Alon Cc: Nadav Amit Cc: Borislav Petkov Cc: Tom Lendacky Signed-off-by: Wanpeng Li --- arch/x86/kvm/x86.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d4985a9..efc8554 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1062,13 +1062,25 @@ static u32 msr_based_features[] = { static unsigned int num_msr_based_features; +static int kvm_get_msr_feature(struct kvm_msr_entry *msr) +{ + switch (msr->index) { + default: + if (kvm_x86_ops->get_msr_feature(msr)) + return 1; + } + return 0; +} + static int do_get_msr_feature(struct kvm_vcpu *vcpu, unsigned index, u64 *data) { struct kvm_msr_entry msr; + int r; msr.index = index; - if (kvm_x86_ops->get_msr_feature(&msr)) - return 1; + r = kvm_get_msr_feature(&msr); + if (r) + return r; *data = msr.data; @@ -4538,7 +4550,7 @@ static void kvm_init_msr_list(void) struct kvm_msr_entry msr; msr.index = msr_based_features[i]; - if (kvm_x86_ops->get_msr_feature(&msr)) + if (kvm_get_msr_feature(&msr)) continue; if (j < i) -- 2.7.4