From patchwork Wed Dec 7 00:46:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junaid Shahid X-Patchwork-Id: 9463649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A14476022E for ; Wed, 7 Dec 2016 00:46:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93089284FB for ; Wed, 7 Dec 2016 00:46:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86C1C28500; Wed, 7 Dec 2016 00:46:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBE97284FC for ; Wed, 7 Dec 2016 00:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753766AbcLGAqY (ORCPT ); Tue, 6 Dec 2016 19:46:24 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:36823 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753168AbcLGAqV (ORCPT ); Tue, 6 Dec 2016 19:46:21 -0500 Received: by mail-pf0-f173.google.com with SMTP id 189so73340245pfz.3 for ; Tue, 06 Dec 2016 16:46:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uol4YJ+n8ob+TbmZxykMva+/JDbO8vGST7XZRijoKzQ=; b=IH7U9YzBMuXL5Q2ZwzdGpgHlU9s7kTcCqU44HZscZhV9I8SfTJCvCQOxqotZ9kJzo9 2vqEPu47OSC7ActFC6yJW9l4hJ5UlAKmQsNAoOPKW8jWsC0hFjvjIAiheOPdTjoQus2V pONNV7V7jASzoZZaPVuHa4lxIzWnIZfWAQ1bbLUv7opE4y/RGZPUvzZSAPlmJYR0rq8v W1WDE82DMf2fjNVhV003VHT3wRnfUG3dYpA1ctWOAsfB/aIHJJh8AO1mKYM7uWtbUa8a w2/9xIer6cwMlvFlId3gcrp50+wcQaE6UBS4MIRC23iLs3HBfjpUvwlBAa8g29QC1dLw 7OxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uol4YJ+n8ob+TbmZxykMva+/JDbO8vGST7XZRijoKzQ=; b=IBvqF5W0m2SWd23BYvqq5Qf1m5VX8JuAHSKeF1EZ4/UvQmMHozRwUbjUCyBaL3ksRU qgHi9QQb9x9JoieLrW/Ujl+eQG+zgyPSb1c9x6cjHPWhLfUHZYByCWVIKAyrcfeJpLhV w9QhwQhSbtJjMx3X8lLyMPuBRzMnglO5sUjDwDkFLrtVLB8o/3x7nA0W+wKrWpY68BbC HfR3r8zxq2M3WxKqu65sBPNDfctaHHz30rHrh60Ba/4vJbipbyIeE4aoOxxfc7Um2fy+ R4N3WBQiWNo5rnUty+tywPyEXbQQ1A4LS2Rvz7Ki6Cokp0J8I18ZO3uBxoWthbiVP3H5 lyXA== X-Gm-Message-State: AKaTC00POKbkAHUiSgFcbY0/rEXj3GWh2Bn3LRcGb5aj0dLNoj5s4vwVOXwyUrujPbdW6jCr X-Received: by 10.98.202.72 with SMTP id n69mr66337799pfg.24.1481071580394; Tue, 06 Dec 2016 16:46:20 -0800 (PST) Received: from js-desktop.mtv.corp.google.com ([172.17.128.41]) by smtp.gmail.com with ESMTPSA id 13sm37459009pfz.30.2016.12.06.16.46.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 16:46:19 -0800 (PST) From: Junaid Shahid To: kvm@vger.kernel.org Cc: andreslc@google.com, pfeiner@google.com, pbonzini@redhat.com, guangrong.xiao@linux.intel.com Subject: [PATCH v3 1/8] kvm: x86: mmu: Use symbolic constants for EPT Violation Exit Qualifications Date: Tue, 6 Dec 2016 16:46:10 -0800 Message-Id: <1481071577-40250-2-git-send-email-junaids@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1481071577-40250-1-git-send-email-junaids@google.com> References: <1481071577-40250-1-git-send-email-junaids@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change adds some symbolic constants for VM Exit Qualifications related to EPT Violations and updates handle_ept_violation() to use these constants instead of hard-coded numbers. Signed-off-by: Junaid Shahid Reviewed-by: Xiao Guangrong --- arch/x86/include/asm/vmx.h | 16 ++++++++++++++++ arch/x86/kvm/vmx.c | 22 ++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 20e5e31..659e402 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -469,6 +469,22 @@ struct vmx_msr_entry { #define ENTRY_FAIL_VMCS_LINK_PTR 4 /* + * Exit Qualifications for EPT Violations + */ +#define EPT_VIOLATION_READ_BIT 0 +#define EPT_VIOLATION_WRITE_BIT 1 +#define EPT_VIOLATION_INSTR_BIT 2 +#define EPT_VIOLATION_READABLE_BIT 3 +#define EPT_VIOLATION_WRITABLE_BIT 4 +#define EPT_VIOLATION_EXECUTABLE_BIT 5 +#define EPT_VIOLATION_READ (1 << EPT_VIOLATION_READ_BIT) +#define EPT_VIOLATION_WRITE (1 << EPT_VIOLATION_WRITE_BIT) +#define EPT_VIOLATION_INSTR (1 << EPT_VIOLATION_INSTR_BIT) +#define EPT_VIOLATION_READABLE (1 << EPT_VIOLATION_READABLE_BIT) +#define EPT_VIOLATION_WRITABLE (1 << EPT_VIOLATION_WRITABLE_BIT) +#define EPT_VIOLATION_EXECUTABLE (1 << EPT_VIOLATION_EXECUTABLE_BIT) + +/* * VM-instruction error numbers */ enum vm_instruction_error_number { diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 0e86219..eb6b589 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -6113,14 +6113,20 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); trace_kvm_page_fault(gpa, exit_qualification); - /* it is a read fault? */ - error_code = (exit_qualification << 2) & PFERR_USER_MASK; - /* it is a write fault? */ - error_code |= exit_qualification & PFERR_WRITE_MASK; - /* It is a fetch fault? */ - error_code |= (exit_qualification << 2) & PFERR_FETCH_MASK; - /* ept page table is present? */ - error_code |= (exit_qualification & 0x38) != 0; + /* Is it a read fault? */ + error_code = (exit_qualification & EPT_VIOLATION_READ) + ? PFERR_USER_MASK : 0; + /* Is it a write fault? */ + error_code |= (exit_qualification & EPT_VIOLATION_WRITE) + ? PFERR_WRITE_MASK : 0; + /* Is it a fetch fault? */ + error_code |= (exit_qualification & EPT_VIOLATION_INSTR) + ? PFERR_FETCH_MASK : 0; + /* ept page table entry is present? */ + error_code |= (exit_qualification & + (EPT_VIOLATION_READABLE | EPT_VIOLATION_WRITABLE | + EPT_VIOLATION_EXECUTABLE)) + ? PFERR_PRESENT_MASK : 0; vcpu->arch.exit_qualification = exit_qualification;