From patchwork Tue Dec 2 17:27:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 41816 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 80C9520672 for ; Tue, 2 Dec 2014 17:29:14 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id u10sf8452017lbd.2 for ; Tue, 02 Dec 2014 09:29:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=h4GeN25sBJOxDWw6Wc/6rGpyB8+1tJU9mJdpdjBcTGQ=; b=bYuLpkh9WPB+b84rFy/BgtddKyQqEADevaAXqWtcjNZXDD0+yz6thyL2WRLsHlAWFW q7lNCbnn8cme9l4mvqcYc12QmrJOzInfUUa6tqEhXTOjozjRC3YERTpTFJwJQkPYB2HU poxh7FYONLq7GD/NLaUsxxtREEkbPyK8Gz5bQKMWtf35zfqnbYQQyCIw7yZKD5xe4TdG wu+Q382A/9EYLr62qN2inxRMjnEm4bdbYGA0Z+TeKnsrTSeXhWPmKuLhf0xVPMnIHouR bmzjN+ewjl4t8CrsQtxobHVS/3oXAMGm43cqYVVgL9BouTQnpHIrI05h8/Pj2AoElRMe yZYg== X-Gm-Message-State: ALoCoQnWk2qq855LDP7zOWeqCDorXoDn8ULeeKQfnrjI0tda6RgNMVbowk4t2KwdlGCzSnJVteut X-Received: by 10.112.89.195 with SMTP id bq3mr96637lbb.9.1417541353130; Tue, 02 Dec 2014 09:29:13 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.39 with SMTP id b7ls55360lae.38.gmail; Tue, 02 Dec 2014 09:29:13 -0800 (PST) X-Received: by 10.112.52.73 with SMTP id r9mr331149lbo.15.1417541352989; Tue, 02 Dec 2014 09:29:12 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id u8si20886024lau.133.2014.12.02.09.29.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Dec 2014 09:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so11570812lbj.41 for ; Tue, 02 Dec 2014 09:29:12 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr408556lad.44.1417541352905; Tue, 02 Dec 2014 09:29:12 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp525864lbc; Tue, 2 Dec 2014 09:29:12 -0800 (PST) X-Received: by 10.180.38.98 with SMTP id f2mr6866518wik.55.1417541348277; Tue, 02 Dec 2014 09:29:08 -0800 (PST) Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com. [74.125.82.50]) by mx.google.com with ESMTPS id j9si36165924wjf.10.2014.12.02.09.29.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Dec 2014 09:29:08 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.50 as permitted sender) client-ip=74.125.82.50; Received: by mail-wg0-f50.google.com with SMTP id k14so17606962wgh.37 for ; Tue, 02 Dec 2014 09:29:08 -0800 (PST) X-Received: by 10.180.74.236 with SMTP id x12mr8167228wiv.40.1417541347967; Tue, 02 Dec 2014 09:29:07 -0800 (PST) Received: from gnx2579.gnb.st.com (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id bm1sm32765162wjb.45.2014.12.02.09.29.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Dec 2014 09:29:07 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, agraf@suse.de, gleb@kernel.org, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, a.motakis@virtualopensystems.com Subject: [PATCH] KVM: arm/arm64: vgic: add init entry to VGIC KVM device Date: Tue, 2 Dec 2014 18:27:31 +0100 Message-Id: <1417541251-20761-1-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Since the advent of dynamic initialization of VGIC, this latter is initialized very late, on the first vcpu run. This initialization could be initiated much earlier by the user, as soon as it has provided the requested dimensioning parameters: - number of IRQs and number of vCPUs, - DIST and CPU interface base address. One motivation behind being able to initialize the VGIC sooner is related to the setup of IRQ injection in VFIO use case. The VFIO signaling, especially when used along with irqfd must be set *after* vgic initialization to prevent any virtual IRQ injection before VGIC initialization. If virtual IRQ injection occurs before the VGIC init, the IRQ cannot be injected and subsequent injection is blocked due to VFIO completion mechanism (unmask/mask or forward/unforward). This patch adds a new entry to the VGIC KVM device that allows the user to manually request the VGIC init: - a new KVM_DEV_ARM_VGIC_GRP_CTRL group is introduced. - Its first attribute is KVM_DEV_ARM_VGIC_CTRL_INIT The rationale behind introducing a group is to be able to add other controls later on, if needed. Obviously, as soon as the init is done, the dimensioning parameters cannot be changed. Signed-off-by: Eric Auger --- Documentation/virtual/kvm/devices/arm-vgic.txt | 11 +++++++++++ arch/arm/include/uapi/asm/kvm.h | 2 ++ arch/arm64/include/uapi/asm/kvm.h | 2 ++ virt/kvm/arm/vgic.c | 14 +++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Documentation/virtual/kvm/devices/arm-vgic.txt b/Documentation/virtual/kvm/devices/arm-vgic.txt index df8b0c7..80db43f 100644 --- a/Documentation/virtual/kvm/devices/arm-vgic.txt +++ b/Documentation/virtual/kvm/devices/arm-vgic.txt @@ -81,3 +81,14 @@ Groups: -EINVAL: Value set is out of the expected range -EBUSY: Value has already be set, or GIC has already been initialized with default values. + + KVM_DEV_ARM_VGIC_GRP_CTRL + Attributes: + KVM_DEV_ARM_VGIC_CTRL_INIT + request the initialization of the VGIC, no additional parameter in + kvm_device_attr.addr. + Errors: + -ENXIO: distributor or CPU interface base address were not set prior + to that call + -EINVAL: number of vcpus is not known + -ENOMEM: memory shortage when allocating vgic internal data diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h index 77547bb..2499867 100644 --- a/arch/arm/include/uapi/asm/kvm.h +++ b/arch/arm/include/uapi/asm/kvm.h @@ -175,6 +175,8 @@ struct kvm_arch_memory_slot { #define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 #define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) #define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 +#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 /* KVM_IRQ_LINE irq field index values */ #define KVM_ARM_IRQ_TYPE_SHIFT 24 diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index 1ed4417..b35c95a 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -161,6 +161,8 @@ struct kvm_arch_memory_slot { #define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 #define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) #define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 +#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 /* KVM_IRQ_LINE irq field index values */ #define KVM_ARM_IRQ_TYPE_SHIFT 24 diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index b76c38c..2fe5bdb 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -2474,7 +2474,14 @@ static int vgic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) return ret; } - + case KVM_DEV_ARM_VGIC_GRP_CTRL: { + switch (attr->attr) { + case KVM_DEV_ARM_VGIC_CTRL_INIT: + r = kvm_vgic_init(dev->kvm); + return r; + } + break; + } } return -ENXIO; @@ -2553,6 +2560,11 @@ static int vgic_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr) return vgic_has_attr_regs(vgic_cpu_ranges, offset); case KVM_DEV_ARM_VGIC_GRP_NR_IRQS: return 0; + case KVM_DEV_ARM_VGIC_GRP_CTRL: + switch (attr->attr) { + case KVM_DEV_ARM_VGIC_CTRL_INIT: + return 0; + } } return -ENXIO; }