Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp961270imp; Wed, 20 Feb 2019 12:19:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IbBE/HgF8zU3pdiHdJhRN/5zTkCaOaHjTMZvXQchaD+dwD/4d2HT8r6cycadMMDU+uyFUZ+ X-Received: by 2002:aa7:8101:: with SMTP id b1mr37283363pfi.148.1550693993808; Wed, 20 Feb 2019 12:19:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550693993; cv=none; d=google.com; s=arc-20160816; b=HpQ1Nwh2DIF6L9+3MNANvEL8Y5Ka2dCd9sHFC4QjT3Vl1jpOK9ew5vEvmIFS8IViPO k4w/hN4ZzvA8rhRT7p+taBnA/4rO8D8MpopRf6KcydqQFKX7jT7jk/tbhWaVDbrdylUY FKQfsHAZUKQjqzRUB2wcE7eoLqSTYMEo3prJ052OVdOENbhpdv8gXTcn56k+vxrdYvcC thDMa7eDWlV7mBxgqHT/rucozamWAzAzUzsTLGehgCmUe5lFS0cuLUEUsbeaGu6X7fvW Unmw1xyZDBlNxvsZ4dE8tTCnA3G+wk5kOQbgRibK/Z/9a97yFUczviLrjuYZaGlVKkiq 02iw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tmD778ESsfRwNMq9An4G52B5oKCiX42JyVamao6ufmw=; b=gE5jijUotxBpTF8J1CWlUWb9/dpguvhVNRx6AX/jX4xtFXxFJ+CgBrb9MwdUXm2OBD ZmgL5awvrqRczS2SDd2bvxmBw9W0KLTx09q4Nw61WkCpX9a9qodpm2lMDsV+Eb5MH8k/ gIjgGb4p+6E7o2mX8sdlxdmpiOWMn8hnUyWo2fUNxts1/n70jVouBNjTZv5Yd45qJCex WNptx0difb30TTB6Lx7mTATPmmfvpbTveFEIymx4bIdP4xf9fnXQ15wamgS25nZhTHCl dT2I8j+dcfYrW/D4NvYaYZrpiVXBRX1yqzVDNHFRrnWs2CiV+8wOjjmFx9xz3yqJc7HA AnDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=TAF37CCy; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si8471818pfn.285.2019.02.20.12.19.38; Wed, 20 Feb 2019 12:19:53 -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=@oracle.com header.s=corp-2018-07-02 header.b=TAF37CCy; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727505AbfBTURt (ORCPT + 99 others); Wed, 20 Feb 2019 15:17:49 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:33014 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbfBTURr (ORCPT ); Wed, 20 Feb 2019 15:17:47 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1KK8Vnk087437; Wed, 20 Feb 2019 20:17:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=tmD778ESsfRwNMq9An4G52B5oKCiX42JyVamao6ufmw=; b=TAF37CCyat1YdR1UjRk+dJuoA5zlEnM4afilHLYTgTx8Kc04kxyCiXmxs9Naoerb2cQy uw6u4CmGw4WcJ9VnEG2+v3ir2kF3JSpqKDxxfGPlOo5DB4m9hFDI3n7H+QCvyu3sI4L+ Paz8FjEKZWHzSapv9LDktDuOOUd7KuGvPZwOSehojytBmUYMUodZLdMUz52zt/t23awU nb7FUhixGDSbotApDUPFTNQM/7/vo8LhO+WGserT0vfDgwoHTOLa3WhZOMSRuDu/1ZP2 ohtcPI4ycz6NO6vRQVEPto9xzVF8ecNkSDNJ47EiRrExoAPxBmQY0gGEKJYvDRn1hynz wQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2qp81ec39c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Feb 2019 20:17:33 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1KKHWjQ025954 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Feb 2019 20:17:32 GMT Received: from abhmp0022.oracle.com (abhmp0022.oracle.com [141.146.116.28]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1KKHW0X018398; Wed, 20 Feb 2019 20:17:32 GMT Received: from paddy.lan (/94.61.137.133) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 20 Feb 2019 12:17:31 -0800 From: Joao Martins To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ankur Arora , Boris Ostrovsky , Joao Martins , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH RFC 12/39] KVM: x86/xen: store virq when assigning evtchn Date: Wed, 20 Feb 2019 20:15:42 +0000 Message-Id: <20190220201609.28290-13-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190220201609.28290-1-joao.m.martins@oracle.com> References: <20190220201609.28290-1-joao.m.martins@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9173 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=941 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902200138 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable virq offload to the hypervisor. The primary user for this is the timer virq. Signed-off-by: Joao Martins --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/xen.c | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index f31fcaf8fa7c..92b76127eb43 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -550,6 +550,8 @@ struct kvm_vcpu_xen { gpa_t steal_time_addr; struct vcpu_runstate_info *steal_time; struct kvm_xen_callback cb; +#define KVM_XEN_NR_VIRQS 24 + unsigned int virq_to_port[KVM_XEN_NR_VIRQS]; }; struct kvm_vcpu_arch { diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 1fbdfa7c4356..42c1fe01600d 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -101,6 +101,20 @@ static void kvm_xen_evtchnfd_upcall(struct kvm_vcpu *vcpu, struct evtchnfd *e) kvm_xen_do_upcall(vcpu->kvm, e->vcpu, vx->cb.via, vx->cb.vector, 0); } +void kvm_xen_set_virq(struct kvm *kvm, struct evtchnfd *evt) +{ + int virq = evt->virq.type; + struct kvm_vcpu_xen *vcpu_xen; + struct kvm_vcpu *vcpu; + + vcpu = kvm_get_vcpu(kvm, evt->vcpu); + if (!vcpu) + return; + + vcpu_xen = vcpu_to_xen_vcpu(vcpu); + vcpu_xen->virq_to_port[virq] = evt->port; +} + int kvm_xen_set_evtchn(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, int irq_source_id, int level, bool line_status) @@ -620,6 +634,10 @@ static int kvm_xen_eventfd_assign(struct kvm *kvm, struct idr *port_to_evt, return PTR_ERR(eventfd); } + if (args->type == XEN_EVTCHN_TYPE_VIRQ && + args->virq.type >= KVM_XEN_NR_VIRQS) + return -EINVAL; + evtchnfd = kzalloc(sizeof(struct evtchnfd), GFP_KERNEL); if (!evtchnfd) return -ENOMEM; @@ -636,8 +654,11 @@ static int kvm_xen_eventfd_assign(struct kvm *kvm, struct idr *port_to_evt, GFP_KERNEL); mutex_unlock(port_lock); - if (ret >= 0) + if (ret >= 0) { + if (evtchnfd->type == XEN_EVTCHN_TYPE_VIRQ) + kvm_xen_set_virq(kvm, evtchnfd); return 0; + } if (ret == -ENOSPC) ret = -EEXIST; -- 2.11.0