Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932446AbcLLRvQ (ORCPT ); Mon, 12 Dec 2016 12:51:16 -0500 Received: from mail-by2nam01on0044.outbound.protection.outlook.com ([104.47.34.44]:41328 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754193AbcLLRvN (ORCPT ); Mon, 12 Dec 2016 12:51:13 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Subject: Re: [PATCH v2 3/3] kvm: svm: Use the hardware provided GPA instead of page walk To: Paolo Bonzini References: <147992048887.27638.17559991037474542240.stgit@brijesh-build-machine> <147992052008.27638.18095073174935903705.stgit@brijesh-build-machine> <65a10dd8-5fae-350f-b597-f8f0261da766@redhat.com> <9820037d-e3ca-0131-3b04-2e51f2abc883@amd.com> <657442146.2535029.1481298111651.JavaMail.zimbra@redhat.com> CC: , , thomas lendacky , , , , , , , , From: Brijesh Singh Message-ID: <6e1fd4ba-016c-99ea-5b98-24f89479da4b@amd.com> Date: Mon, 12 Dec 2016 11:51:01 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <657442146.2535029.1481298111651.JavaMail.zimbra@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR21CA0061.namprd21.prod.outlook.com (10.172.93.151) To BLUPR12MB0657.namprd12.prod.outlook.com (10.163.217.27) X-MS-Office365-Filtering-Correlation-Id: bc68f320-5c12-44dd-4b48-08d422b773f9 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BLUPR12MB0657; X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0657;3:wZe4uy9Rt8FN4NfsRSuf4A24HwryuNyDjq3nU2Jl/j3cpE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Vg7QMXsYDeOTMa77PWiRspMYmtkmucuL2BvUkqVh37xgF67v4f7nfywjzT70GkJX5NGjCiQq9ybI3bV4oAcH8EJISOjWVYKUMjasWPiZrjjjyafeDzba6o8HVYifPeMq5XjDCHjypnkcDw3GlqxXO1guV4IADPzHNAHCoTKsuPedwIe1TMnMxoCn6efBurJpYYYA3xDkSp2MuK2tsTsTbLQpEgmYooxvc4KrJLd8WCqQQ3ss1PWYoo5PrJMaGo1I+8ywhrE/Jb8VPbGKDvZXjWhjZBJQ/vjPclfypqHrM6F6/Zh1LZTjKXWZ0Lz1VT84sQ1oSXTIp6ohXDHaHuOhaUNtShlFmLETtVXdlesMWoCKH7YQ9W/3lQaYX7lOL2bA0nHisSsKh71CF//I7ZXOCWCnRdR/WjS8JItKY3cqdjfD X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(6072148);SRVR:BLUPR12MB0657;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0657; X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0657;4:lfxAWoY3jCMbln5XRMAZbrubDwZdWLDroMn1v5zlLuwyy7mcUutaZ75rqoCXyukRC5+P0rUR9flBkmN89bfQbqWxgJhi2teNddhwz8h1zFrSqV8r36E7m/vFnLpAfUNUIBi56ZN6qUzHuPJvy5ON9NvK+IADAZxdLoDYhaPJl1/sew/SwIqd8yntiaVWR+No0RtfWI0hMyZDhRHNWZJCj5CefYrrEse1QmgHx8KXwqXvJPby6vxaRUOWofoTe6SLkhWfOqVWAIiotEgV6TrJ0UholdAuJkqDelc16G9PmtcL9RZBGja4CX2wqBwFlfdpWhRrEno+l59zoSbeM/HluQz6Cf6cA7XWtRo8T0U7M13V1NQ9Is5K4enZERC39G3iJTeINGvGUqSZA7/WC5Px+DT6m1+7Ogac/FmPtHSdwCgfyBDmqF2Z9grAuL6+K4DevYHbId073BxVUCg1q6RmH3UQyWJQwjEIKkBxguJBdCQSnKB6ShjosyZD4MbgnJj8fzK4KrxrbnLV/vPu+39tYbY1KHXGkiyy3D836li7uorBr/11gCxyk4w3990orv4qj9x0r9QxznF4nH9Qire8kD5LD5a5WVpNhyskixsoivR/6Dgi5G1oYHaMVID3OGiOqwzvhodgFgluVHc7Gg4xt2runkkufWLQ460bCFB0Okk= X-Forefront-PRVS: 0154C61618 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(979002)(6049001)(6009001)(7916002)(39840400002)(39450400003)(39850400002)(39860400002)(39410400002)(24454002)(189002)(377454003)(199003)(6666003)(36756003)(76176999)(106356001)(110136003)(2950100002)(2906002)(105586002)(6916009)(47776003)(66066001)(65956001)(50466002)(65806001)(230700001)(64126003)(7416002)(54356999)(42186005)(31686004)(50986999)(5660300001)(6116002)(4326007)(3846002)(101416001)(92566002)(65826007)(68736007)(81166006)(83506001)(8676002)(7736002)(97736004)(81156014)(4001350100001)(189998001)(23676002)(229853002)(90366009)(305945005)(77096006)(38730400001)(93886004)(6486002)(86362001)(31696002)(33646002)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR12MB0657;H:[10.236.136.62];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTFVQUjEyTUIwNjU3OzIzOjFEazR1UzJMRzRhUnNmSWRMWTlsQW1QZUpi?= =?utf-8?B?Rmd0dlg1bk1vclQvc1lUODFFV2dEVUxLcEdlaVF4QTRzUVl4L1NIZGlXYnBI?= =?utf-8?B?ZXg5OElCZkxvczdzY2JoSHVuYm9iSWRrSWZ4emY4UzZib3JWYnIyYmNRQndM?= =?utf-8?B?RFp0R09ReG5QaHBtd2lzUGNaOW9DQlZwS2hHN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w2j9tJ2gOdj16j6hYgxBiTg8r1C39MSUOWEj42BbZkM/Z2lZ1jghTtnV7/wezRfr98YNp1OSDjVIrKEf1ztLC1jc+2hw2ZEdqCmDVgZy2MWhHzEobgSv/O6rbNMEF5tvqBhxa/NFW5gZvupWHj7Qg2MGK+Qr0HsGhsWfphOwFtMCOKoBCunnnEDjwS4+jWex707/NtLZX1WAOWuV4Quwvg1j1AsP89vyz9JtSjTHr+0lyDYMkrsmzuzX3Jm9eqzcDy7zaB2clsxnO0kpwVGzOAeC0KSaAzZtzqdLBcdJaeK596N67HSiqAss7KuzwHM3nvnt/fk6MkieYvk0Boldbm2P4dU5BB9qcSu1jGuIg+/RpKUAvTZdstc9W05M4+g617kELkRIG3BewQjPKlKXMnl9cFwW+OdYRqYigX7P7v/yahUl3JEXJ0OPQ==;20:CeB/WWKXFczGCAEyt3mhw5TAsbIJZVICO26JkTEmRw7umrJOr9oIuxO1ohuuEg0dyQSCy6+ep2JzQ3+lm/k+GeH67kWrguP3UKyiGIneC7u/FzTezofe0buyupnmtOeMG+BvVw2CWPS3QZH3/PH2GAOQMXYiI1S6fk+fDoAABJ6x6VdHzV4X8vHezSX6CPMVpgNAaFq3ovUqyXdJWl8Aio+ds91ko+SKIBkMWQa4V2/xjpoU1l0Oqxx5k9NS6enQ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2016 17:51:06.8655 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0657 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9178 Lines: 258 Hi Paolo, On 12/09/2016 09:41 AM, Paolo Bonzini wrote: > >> I am able to reproduce it on AMD HW using kvm-unit-tests. Looking at >> test, the initial thought is "push mem" has two operands (the memory >> being pushed and the stack pointer). The provided GPA could be either >> one of those. > > Aha, this makes sense---and it's easy to handle too, since you can just > add a flag to the decode table and extend the string op case to cover > that flag too. Detecting cross-page MMIO is more problematic, I don't > have an idea offhand of how to solve it. > I added a new flag "TwoMemOp" and this seems to be passing the "push mem" and "pop mem" tests. If you are okay with this then I can convert it into a patch for review. diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 0ea543e..c86dc1d 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -171,6 +171,7 @@ #define NearBranch ((u64)1 << 52) /* Near branches */ #define No16 ((u64)1 << 53) /* No 16 bit operand */ #define IncSP ((u64)1 << 54) /* SP is incremented before ModRM calc */ +#define TwoMemOp ((u64)1 << 55) /* Instruction has two memory operand */ #define DstXacc (DstAccLo | SrcAccHi | SrcWrite) @@ -4104,7 +4105,7 @@ static const struct opcode group1[] = { }; static const struct opcode group1A[] = { - I(DstMem | SrcNone | Mov | Stack | IncSP, em_pop), N, N, N, N, N, N, N, + I(DstMem | SrcNone | Mov | Stack | IncSP | TwoMemOp, em_pop), N, N, N, N, N, N, N, }; static const struct opcode group2[] = { @@ -4142,7 +4143,7 @@ I(SrcMemFAddr | ImplicitOps, em_jmp_far), - I(SrcMem | Stack, em_push), D(Undefined), + I(SrcMem | Stack | TwoMemOp, em_push), D(Undefined), static const struct opcode group6[] = { @@ -4331,8 +4332,8 @@ I(DstReg | SrcMem | ModRM | Src2ImmByte, em_imul_3op), - I2bvIP(SrcSI | DstDX | String, em_out, outs, check_perm_out), /* outsb, outsw/outsd */ + b, insw/insd */ + */ /* 0x80 - 0x87 */ @@ -4360,13 +4361,13 @@ static const struct opcode opcode_table[256] = { /* 0xA0 - 0xA7 */ I2bv(DstAcc | SrcMem | Mov | MemAbs, em_mov), I2bv(DstMem | SrcAcc | Mov | MemAbs | PageTable, em_mov), - I2bv(SrcSI | DstDI | Mov | String, em_mov), - F2bv(SrcSI | DstDI | String | NoWrite, em_cmp_r), + I2bv(SrcSI | DstDI | Mov | String | TwoMemOp, em_mov), + F2bv(SrcSI | DstDI | String | NoWrite | TwoMemOp, em_cmp_r), /* 0xA8 - 0xAF */ F2bv(DstAcc | SrcImm | NoWrite, em_test), - I2bv(SrcAcc | DstDI | Mov | String, em_mov), - I2bv(SrcSI | DstAcc | Mov | String, em_mov), - F2bv(SrcAcc | DstDI | String | NoWrite, em_cmp_r), + I2bv(SrcAcc | DstDI | Mov | String | TwoMemOp, em_mov), + I2bv(SrcSI | DstAcc | Mov | String | TwoMemOp, em_mov), + F2bv(SrcAcc | DstDI | String | NoWrite | TwoMemOp, em_cmp_r), /* 0xB0 - 0xB7 */ X8(I(ByteOp | DstReg | SrcImm | Mov, em_mov)), /* 0xB8 - 0xBF */ @@ -5484,10 +5485,7 @@ void emulator_writeback_register_cache(struct x86_emulate_ctxt *ctxt) writeback_registers(ctxt); } -bool emulator_is_string_op(struct x86_emulate_ctxt *ctxt) +bool emulator_is_two_memory_op(struct x86_emulate_ctxt *ctxt) { - if (ctxt->d & String) - return true; - - return false; + return ctxt->d & TwoMemOp ? true : false; } >> If we can detect those cases, we should not set the gpa_available on >> them (like what we do with string move). > > It would forbid usage of "push/pop mem" instructions with MMIO for SEV, > right? It probably doesn't happen much in practice, but it's unfortunate. > As per the AMD BKDG [1] Section 2.7.1, we should not be using any of these instruction for MMIO access, the behavior is undefined. The question is, do we really need to add logic to detect the cross-page MMIO accesses and push/pop mem operations so that we pass the kvm-unit-test or we should update the unit test? Like you said cross-page MMIO access detection is going to be a bit tricky. Thoughts ? [1] http://support.amd.com/TechDocs/52740_16h_Models_30h-3Fh_BKDG.pdf > Paolo > >> We probably haven't hit this case in guest booting. Will investigate bit >> further and provide a updated patch to handle it. >> >>> -Brijesh >>>> The VMX patch to set gpa_available is just this: >>>> >>>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >>>> index 25d48380c312..5d7b60d4795b 100644 >>>> --- a/arch/x86/kvm/vmx.c >>>> +++ b/arch/x86/kvm/vmx.c >>>> @@ -6393,6 +6393,7 @@ static int handle_ept_violation(struct kvm_vcpu >>>> *vcpu) >>>> /* ept page table is present? */ >>>> error_code |= (exit_qualification & 0x38) != 0; >>>> >>>> + vcpu->arch.gpa_available = true; >>>> vcpu->arch.exit_qualification = exit_qualification; >>>> >>>> return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0); >>>> @@ -6410,6 +6411,7 @@ static int handle_ept_misconfig(struct kvm_vcpu >>>> *vcpu) >>>> } >>>> >>>> ret = handle_mmio_page_fault(vcpu, gpa, true); >>>> + vcpu->arch.gpa_available = true; >>>> if (likely(ret == RET_MMIO_PF_EMULATE)) >>>> return x86_emulate_instruction(vcpu, gpa, 0, NULL, 0) == >>>> EMULATE_DONE; >>>> @@ -8524,6 +8526,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu) >>>> u32 vectoring_info = vmx->idt_vectoring_info; >>>> >>>> trace_kvm_exit(exit_reason, vcpu, KVM_ISA_VMX); >>>> + vcpu->arch.gpa_available = false; >>>> >>>> /* >>>> * Flush logged GPAs PML buffer, this will make dirty_bitmap more >>>> >>>> Thanks, >>>> >>>> Paolo >>>> >>>>> --- >>>>> arch/x86/include/asm/kvm_emulate.h | 3 +++ >>>>> arch/x86/include/asm/kvm_host.h | 3 +++ >>>>> arch/x86/kvm/svm.c | 2 ++ >>>>> arch/x86/kvm/x86.c | 17 ++++++++++++++++- >>>>> 4 files changed, 24 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/arch/x86/include/asm/kvm_emulate.h >>>>> b/arch/x86/include/asm/kvm_emulate.h >>>>> index e9cd7be..2d1ac09 100644 >>>>> --- a/arch/x86/include/asm/kvm_emulate.h >>>>> +++ b/arch/x86/include/asm/kvm_emulate.h >>>>> @@ -344,6 +344,9 @@ struct x86_emulate_ctxt { >>>>> struct read_cache mem_read; >>>>> }; >>>>> >>>>> +/* String operation identifier (matches the definition in emulate.c) */ >>>>> +#define CTXT_STRING_OP (1 << 13) >>>>> + >>>>> /* Repeat String Operation Prefix */ >>>>> #define REPE_PREFIX 0xf3 >>>>> #define REPNE_PREFIX 0xf2 >>>>> diff --git a/arch/x86/include/asm/kvm_host.h >>>>> b/arch/x86/include/asm/kvm_host.h >>>>> index 77cb3f9..fd5b1c8 100644 >>>>> --- a/arch/x86/include/asm/kvm_host.h >>>>> +++ b/arch/x86/include/asm/kvm_host.h >>>>> @@ -668,6 +668,9 @@ struct kvm_vcpu_arch { >>>>> >>>>> int pending_ioapic_eoi; >>>>> int pending_external_vector; >>>>> + >>>>> + /* GPA available (AMD only) */ >>>>> + bool gpa_available; >>>>> }; >>>>> >>>>> struct kvm_lpage_info { >>>>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c >>>>> index 5e64e656..1bbd04c 100644 >>>>> --- a/arch/x86/kvm/svm.c >>>>> +++ b/arch/x86/kvm/svm.c >>>>> @@ -4246,6 +4246,8 @@ static int handle_exit(struct kvm_vcpu *vcpu) >>>>> return 1; >>>>> } >>>>> >>>>> + vcpu->arch.gpa_available = (exit_code == SVM_EXIT_NPF); >>>>> + >>>>> return svm_exit_handlers[exit_code](svm); >>>>> } >>>>> >>>>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >>>>> index c30f62dc..5002eea 100644 >>>>> --- a/arch/x86/kvm/x86.c >>>>> +++ b/arch/x86/kvm/x86.c >>>>> @@ -4441,7 +4441,19 @@ static int vcpu_mmio_gva_to_gpa(struct >>>>> kvm_vcpu *vcpu, unsigned long gva, >>>>> return 1; >>>>> } >>>>> >>>>> - *gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, >>>>> exception); >>>>> + /* >>>>> + * If the exit was due to a NPF we may already have a GPA. >>>>> + * If the GPA is present, use it to avoid the GVA to GPA table >>>>> + * walk. Note, this cannot be used on string operations since >>>>> + * string operation using rep will only have the initial GPA >>>>> + * from when the NPF occurred. >>>>> + */ >>>>> + if (vcpu->arch.gpa_available && >>>>> + !(vcpu->arch.emulate_ctxt.d & CTXT_STRING_OP)) >>>>> + *gpa = exception->address; >>>>> + else >>>>> + *gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, >>>>> + exception); >>>>> >>>>> if (*gpa == UNMAPPED_GVA) >>>>> return -1; >>>>> @@ -5563,6 +5575,9 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, >>>>> } >>>>> >>>>> restart: >>>>> + /* Save the faulting GPA (cr2) in the address field */ >>>>> + ctxt->exception.address = cr2; >>>>> + >>>>> r = x86_emulate_insn(ctxt); >>>>> >>>>> if (r == EMULATION_INTERCEPTED) >>>>> >>>>> -- >>>>> To unsubscribe from this list: send the line "unsubscribe kvm" in >>>>> the body of a message to majordomo@vger.kernel.org >>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>>>> >>