Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3850500ybb; Mon, 23 Mar 2020 08:50:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsGBX1JJIo7vfKCCfS1OjMIhnEpqOwo8mX5FlX/tySVVDR8pIw/JZXD/M4L2XVNfG8kd0Hx X-Received: by 2002:a9d:7d89:: with SMTP id j9mr17271033otn.47.1584978600577; Mon, 23 Mar 2020 08:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584978600; cv=none; d=google.com; s=arc-20160816; b=DT6eB2x2S2eZppBg59DKOS1LsEPi7B9w1of1vFU9kuW/2//dVXOJ52DpMNWWlO7PAK wWixsGjqd90I6APIa6PjqALeMkh1+ptR4DSVczXSGeaTmBtmxPmpJTcg+F625MXSU4Ed MfYy4NAwg4kWduQzOvCncoLM1rs2bzxH3MBHv0Xdn4BgxC7dUeEywX/YlqHvXnfH0hjG IfcYHoWvFS1vWc0Bql4vXgfk00f+gJSeF66Wy5gOkXAwHYT+UAuYGw9L53ArsCHSdTPw y4sucdiFtAMvx34Xko1tksCfBsA6OeH3Nxnm07HyQ/nyYsfxF91Sz+MIMkMK9+mOxDCc SGDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=dvBlRRLg3CjMYlQe8Gy70l16tflLAU7l7Cy4EhgrGo0=; b=A55UDGD3/meke8nSjU0R/bHnW4hWAkREOSLvkAZGVqrI3mJXOV2tRHBPcUHLFxMgsZ 7WG3BZnTP0Us9ed/E8DXj9rJ84YLMAdBS80rkvra0DO/DU5gkGmIHsJfi513oWGZjVcA Z4vwy5FqiJtUX9fXG1MHUd1f09PZxT7auzlL8RB50uwOA3qiHSZH3r0lRAv85gO1LcbH kCilMCCJ4WHp52EGGFHlLDggVvhycNhTh1pl+adlDaMmfl58wPrFdjQhEYVZI7K/EYZA OVXl9TXGH8VqDp6H9wv/qj+pHHr4bwXQR3HnfNDhU3ZunT48XdpkNO6M9ifWu/gdaGYw i/nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P4wwVtYa; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x8si8465846otb.140.2020.03.23.08.49.48; Mon, 23 Mar 2020 08:50:00 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=P4wwVtYa; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727361AbgCWPr4 (ORCPT + 99 others); Mon, 23 Mar 2020 11:47:56 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:30649 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727175AbgCWPr4 (ORCPT ); Mon, 23 Mar 2020 11:47:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584978474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dvBlRRLg3CjMYlQe8Gy70l16tflLAU7l7Cy4EhgrGo0=; b=P4wwVtYaxDQKUJ8RBZeHTek9AygsSXPIfHIOQ+pQvMYh2fIve8W+aZYE8KbWx0/3xfpdyb 3ZUb2lcbMg83rYw9+lQ85eEeNTXo/NR9INqNNxrJlGegfmzIG+M8wxc8Zs0X9l52eNadrV pVQi62pkodYA/zJh/QAM5V+fOPeYVzk= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-DumA1gXdMjq4pIeZrbvmrA-1; Mon, 23 Mar 2020 11:47:52 -0400 X-MC-Unique: DumA1gXdMjq4pIeZrbvmrA-1 Received: by mail-wr1-f72.google.com with SMTP id e10so5795401wru.6 for ; Mon, 23 Mar 2020 08:47:52 -0700 (PDT) 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:in-reply-to:references:date :message-id:mime-version; bh=dvBlRRLg3CjMYlQe8Gy70l16tflLAU7l7Cy4EhgrGo0=; b=olzK3b2PJfY5OQMXYVBmwFKr0WGPPu6WWveAB5HzyyiODWXZ5QxdkFizbXriW4UC5R MAi1qWPiqxEhuKP7UUHc3DV/ZJNDvZIixeVeyqOD/HRW1sO8kOIaQXSnvBAyj61bV9KM uf+aMsuRe2ju5Zc2kPPh9GEJYFntCWkowEEhfNpSb6haWjkpKOWqmXiGekJW7sxD0JJx YVgY8Hv89p3CU2em7ff1SUKAbfvbIbmrA9tGAHguo2lQ8ydpehMxeJJrh/NITEyDzk9Z PzX7Z4kZcpxljXoJcr8l/wG/ObHa1VzG5Yy5o3g40vLk0MO9KF80egzy5YPjuEbbnrrv PBXQ== X-Gm-Message-State: ANhLgQ3UIr78NYYqgqOXn3PKCf3DrnTRZHmJcfTeqsrZ62Rm5pqVA3Va Yaz7Q2aR8V4jKxNoy+ONlAoUDFkrjUm2o7qy3ekmmK8vJurc/rJ0k9BBF4jeFynTjZXrVct3FLW LByP8iFyuTKKOYuvCBFMXOuXv X-Received: by 2002:a1c:98c4:: with SMTP id a187mr6825268wme.76.1584978471553; Mon, 23 Mar 2020 08:47:51 -0700 (PDT) X-Received: by 2002:a1c:98c4:: with SMTP id a187mr6825239wme.76.1584978471254; Mon, 23 Mar 2020 08:47:51 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id h81sm24320939wme.42.2020.03.23.08.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 08:47:50 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson , Paolo Bonzini Cc: Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon , Junaid Shahid , Liran Alon , Boris Ostrovsky , John Haxby , Miaohe Lin , Tom Lendacky Subject: Re: [PATCH v3 05/37] KVM: x86: Export kvm_propagate_fault() (as kvm_inject_emulated_page_fault) In-Reply-To: <20200320212833.3507-6-sean.j.christopherson@intel.com> References: <20200320212833.3507-1-sean.j.christopherson@intel.com> <20200320212833.3507-6-sean.j.christopherson@intel.com> Date: Mon, 23 Mar 2020 16:47:49 +0100 Message-ID: <87sghz844a.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sean Christopherson writes: > Export the page fault propagation helper so that VMX can use it to > correctly emulate TLB invalidation on page faults in an upcoming patch. > > In the (hopefully) not-too-distant future, SGX virtualization will also > want access to the helper for injecting page faults to the correct level > (L1 vs. L2) when emulating ENCLS instructions. > > Rename the function to kvm_inject_emulated_page_fault() to clarify that > it is (a) injecting a fault and (b) only for page faults. WARN if it's > invoked with an exception other than PF_VECTOR. > > Signed-off-by: Sean Christopherson > --- > arch/x86/include/asm/kvm_host.h | 2 ++ > arch/x86/kvm/x86.c | 8 ++++++-- > 2 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 9a183e9d4cb1..328b1765ff76 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1447,6 +1447,8 @@ void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code); > void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr); > void kvm_requeue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code); > void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault); > +bool kvm_inject_emulated_page_fault(struct kvm_vcpu *vcpu, > + struct x86_exception *fault); > int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, > gfn_t gfn, void *data, int offset, int len, > u32 access); > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index e54c6ad628a8..64ed6e6e2b56 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -611,8 +611,11 @@ void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault) > } > EXPORT_SYMBOL_GPL(kvm_inject_page_fault); > > -static bool kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault) > +bool kvm_inject_emulated_page_fault(struct kvm_vcpu *vcpu, > + struct x86_exception *fault) > { > + WARN_ON_ONCE(fault->vector != PF_VECTOR); > + > if (mmu_is_nested(vcpu) && !fault->nested_page_fault) > vcpu->arch.nested_mmu.inject_page_fault(vcpu, fault); > else > @@ -620,6 +623,7 @@ static bool kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fau > > return fault->nested_page_fault; > } > +EXPORT_SYMBOL_GPL(kvm_inject_emulated_page_fault); We don't seem to use the return value a lot, actually, inject_emulated_exception() seems to be the only one, the rest just call it without checking the return value. Judging by the new name, I'd guess that the function returns whether it was able to inject the exception or not but this doesn't seem to be the case. My suggestion would then be to make it return 'void' and return 'fault->nested_page_fault' separately in inject_emulated_exception(). > > void kvm_inject_nmi(struct kvm_vcpu *vcpu) > { > @@ -6373,7 +6377,7 @@ static bool inject_emulated_exception(struct kvm_vcpu *vcpu) > { > struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt; > if (ctxt->exception.vector == PF_VECTOR) > - return kvm_propagate_fault(vcpu, &ctxt->exception); > + return kvm_inject_emulated_page_fault(vcpu, &ctxt->exception); > > if (ctxt->exception.error_code_valid) > kvm_queue_exception_e(vcpu, ctxt->exception.vector, With or without the change suggested above, Reviewed-by: Vitaly Kuznetsov -- Vitaly