Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2134675imm; Wed, 16 May 2018 08:22:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpWibWPVW23cIFIjBjl2lYNt9rofbwkFp3PdVBfDowPLMOyX5+JZVvaDc8U38AZOgk00T0O X-Received: by 2002:a62:df4c:: with SMTP id u73-v6mr1411041pfg.10.1526484176947; Wed, 16 May 2018 08:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526484176; cv=none; d=google.com; s=arc-20160816; b=cubW8Kzlh2uj4caXQN6I802XgHe9F6krTwaQu4BBia7bJlVN6M0FZf9P2e4fI8paAN FvqJbYIlff8Fgxm5Sn76ZAEwNFjMh5RLm1krSagNKTT402Y/LySOzqjr5GsFRZV55Oh4 UChwLLbzhWhGzRPEkPR8gqgmW6d4QOm0L7LRcBB8ukn0wACQlWaIindwBiXui6sgmqNI HOLlNj9U7u8hWpAU8CwbyZjH8i3B+OtlNwHK1HtCa1KmodWoow22ROrwTIcAmz5ylR3X xq/R2wdRY9+kAy+3GQJXPbf6AwroIu4M8Dct9v93zAXFBp02LDi/gCN9r/MATIbsddmY MmWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=A4n44fSv/ftXhcRuu8y0B6IHsUHqNLuJmBvPNG3UDIQ=; b=TMiioMYPFXp4WXL/QhmjovaZnEQgTWOYbUe/zW0l7SXATyJ5s4UxUUE1UOoNJNP9/3 NNjzNMpEbYohADnMEB2bmQB46/Q6R4INHq6bC1OEERhOeQihIpskm4Q0hYzATzgfSFc3 1udAdABQxHihOvDG9LfffBM76CIkvsCl4HaE+0HntasnOP4cKxp3FzcpGIH1q7rdgT/x //aWiod/WYc7V88vb4TnkO1+4oUvCEkzSR25W4+kdqwEmaHBgKx54RGyHVCscqQZznLP PBpVepUMy4Uta5W1M8WXHvTSe0aPg7GiON3LVNh5DpUFRw6+hbmFBCgyg80rFSK7ydsM lIzw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 g10-v6si2281847pgq.302.2018.05.16.08.22.42; Wed, 16 May 2018 08:22:56 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752163AbeEPPVt (ORCPT + 99 others); Wed, 16 May 2018 11:21:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58208 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752022AbeEPPVn (ORCPT ); Wed, 16 May 2018 11:21:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B293A400E9BA; Wed, 16 May 2018 15:21:42 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB2B1215CDA7; Wed, 16 May 2018 15:21:40 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: x86@kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Roman Kagan , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Mohammed Gamal , Cathy Avery , linux-kernel@vger.kernel.org Subject: [PATCH v4 4/8] KVM: x86: hyperv: do rep check for each hypercall separately Date: Wed, 16 May 2018 17:21:27 +0200 Message-Id: <20180516152131.30689-5-vkuznets@redhat.com> In-Reply-To: <20180516152131.30689-1-vkuznets@redhat.com> References: <20180516152131.30689-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 16 May 2018 15:21:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 16 May 2018 15:21:42 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkuznets@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prepare to support TLB flush hypercalls, some of which are REP hypercalls. Also, return HV_STATUS_INVALID_HYPERCALL_INPUT as it seems more appropriate. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index dcfeae2deafa..edb1ac44d628 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1311,7 +1311,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) { u64 param, ingpa, outgpa, ret = HV_STATUS_SUCCESS; uint16_t code, rep_idx, rep_cnt; - bool fast, longmode; + bool fast, longmode, rep; /* * hypercall generates UD from non zero cpl and real mode @@ -1344,28 +1344,31 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) fast = !!(param & HV_HYPERCALL_FAST_BIT); rep_cnt = (param >> HV_HYPERCALL_REP_COMP_OFFSET) & 0xfff; rep_idx = (param >> HV_HYPERCALL_REP_START_OFFSET) & 0xfff; + rep = !!(rep_cnt || rep_idx); trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa); - /* Hypercall continuation is not supported yet */ - if (rep_cnt || rep_idx) { - ret = HV_STATUS_INVALID_HYPERCALL_CODE; - goto set_result; - } - switch (code) { case HVCALL_NOTIFY_LONG_SPIN_WAIT: + if (unlikely(rep)) { + ret = HV_STATUS_INVALID_HYPERCALL_INPUT; + break; + } kvm_vcpu_on_spin(vcpu, true); break; case HVCALL_SIGNAL_EVENT: + if (unlikely(rep)) { + ret = HV_STATUS_INVALID_HYPERCALL_INPUT; + break; + } ret = kvm_hvcall_signal_event(vcpu, fast, ingpa); if (ret != HV_STATUS_INVALID_PORT_ID) break; /* maybe userspace knows this conn_id: fall through */ case HVCALL_POST_MESSAGE: /* don't bother userspace if it has no way to handle it */ - if (!vcpu_to_synic(vcpu)->active) { - ret = HV_STATUS_INVALID_HYPERCALL_CODE; + if (unlikely(rep || !vcpu_to_synic(vcpu)->active)) { + ret = HV_STATUS_INVALID_HYPERCALL_INPUT; break; } vcpu->run->exit_reason = KVM_EXIT_HYPERV; -- 2.14.3