Received: by 10.213.65.68 with SMTP id h4csp693389imn; Tue, 27 Mar 2018 07:06:54 -0700 (PDT) X-Google-Smtp-Source: AG47ELsqb651qtrR6lmM1ZQOGowtuCGLnhNAU4tItkzAwt/M8Y1PbJs8Gr1Kt+vW6WyR5GmS9+Eq X-Received: by 2002:a17:902:8212:: with SMTP id x18-v6mr36225964pln.372.1522159614378; Tue, 27 Mar 2018 07:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522159614; cv=none; d=google.com; s=arc-20160816; b=lHDjxUpluGuJOLhqd+lsEBxB4wDDcOkVHZZZNrOzY4WoZtpkU0ChXFGd8fpq3rk6fY 1Mp0dEL7bu6WfhFRS1KlvM07ZCtzHBL4akDz/1zA2vm5C328A7UKaqEISr7OV4fv/FRE 3xUNlLKt8imadwl29+RjDQfjj7duLRv8HEupP2ZcEkbHh8AHze2lJrvkkuRdGgChg1mw LhOCit8qcEbdaUQ1h6zsUZX5dJSQYS/JthtVBMEYHLVoqmm6xuHhX4laxgLJLw2F9FIe xN1+yC0unh1cJArlxb7mCxEjrmDR/JQLEjkB2hRZmMGUvZ2/EyASlKDksvGCsoeq/1RW Jfow== 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=CfhaHG/57S3x66TKBUvQMuFRbbyur6dvZc+LQ/XoVUE=; b=diy1+ulYBmYf6ZG1Fwf6CTvsx2WUjVNW27cOrb/N7H5wrAwYxNtOCU9SbUWseM8RE4 8fDLSr+LVVtcCe70kdb4WZrOiH6mgHqStrRonm5an6zaNWUUnqy1DyrUHuk0EXJr7xp3 ltLYRq+lxEUVn2UZlSPbePK3E9oV5aXTo3WBASaUbNuROLeCfRWjYicj5cp9C+sNwjo9 Sakjev+hfVdQlmrrxPXFlOYKB/GDxowya3FighGGTezwg+So/lY0HzJpRWTFKAUaPtVr E58mx/eiq2UYDAC+prH+ZNjTsoYPHV6NR74ABJDebntQ1QB7rIuKr1SVkADpgDUVhpTz rUQg== 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 q3si897526pgv.794.2018.03.27.07.06.40; Tue, 27 Mar 2018 07:06:54 -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 S1753129AbeC0OEw (ORCPT + 99 others); Tue, 27 Mar 2018 10:04:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52538 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752963AbeC0OEt (ORCPT ); Tue, 27 Mar 2018 10:04:49 -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 1C53340201A4; Tue, 27 Mar 2018 14:04:49 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-135.ams2.redhat.com [10.36.116.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20B37215CDB5; Tue, 27 Mar 2018 14:04:46 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, cdall@kernel.org, peter.maydell@linaro.org Cc: andre.przywara@arm.com, drjones@redhat.com, wei@redhat.com Subject: [RFC v2 11/12] KVM: arm/arm64: Implement KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION Date: Tue, 27 Mar 2018 16:04:15 +0200 Message-Id: <1522159456-10419-12-git-send-email-eric.auger@redhat.com> In-Reply-To: <1522159456-10419-1-git-send-email-eric.auger@redhat.com> References: <1522159456-10419-1-git-send-email-eric.auger@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.6]); Tue, 27 Mar 2018 14:04:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 27 Mar 2018 14:04:49 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now all the internals are ready to handle multiple redistributor regions, let's allow the userspace to register them. Signed-off-by: Eric Auger --- virt/kvm/arm/vgic/vgic-kvm-device.c | 40 +++++++++++++++++++++++++++++++++++-- virt/kvm/arm/vgic/vgic-mmio-v3.c | 4 ++-- virt/kvm/arm/vgic/vgic.h | 9 ++++++++- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-kvm-device.c b/virt/kvm/arm/vgic/vgic-kvm-device.c index e7b5a86..a2b99e4 100644 --- a/virt/kvm/arm/vgic/vgic-kvm-device.c +++ b/virt/kvm/arm/vgic/vgic-kvm-device.c @@ -65,7 +65,8 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) { int r = 0; struct vgic_dist *vgic = &kvm->arch.vgic; - phys_addr_t *addr_ptr, alignment; + phys_addr_t *addr_ptr = NULL; + phys_addr_t alignment; uint64_t undef_value = VGIC_ADDR_UNDEF; mutex_lock(&kvm->lock); @@ -92,7 +93,7 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) if (r) break; if (write) { - r = vgic_v3_set_redist_base(kvm, *addr); + r = vgic_v3_set_redist_base(kvm, 0, *addr, 0); goto out; } rdreg = list_first_entry(&vgic->rd_regions, @@ -103,6 +104,40 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) addr_ptr = &rdreg->base; break; } + case KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION: + { + struct vgic_redist_region *rdreg; + uint8_t index; + + r = vgic_check_type(kvm, KVM_DEV_TYPE_ARM_VGIC_V3); + if (r) + break; + + index = *addr & KVM_VGIC_V3_RDIST_INDEX_MASK; + + if (write) { + gpa_t base = *addr & KVM_VGIC_V3_RDIST_BASE_MASK; + uint32_t count = (*addr & KVM_VGIC_V3_RDIST_COUNT_MASK) + >> KVM_VGIC_V3_RDIST_COUNT_SHIFT; + uint8_t flags = (*addr & KVM_VGIC_V3_RDIST_FLAGS_MASK) + >> KVM_VGIC_V3_RDIST_FLAGS_SHIFT; + + if (!count || flags) + r = -EINVAL; + else + r = vgic_v3_set_redist_base(kvm, index, + base, count); + goto out; + } + + rdreg = vgic_v3_rdist_region_from_index(kvm, index); + if (!rdreg) + r = -ENODEV; + + *addr_ptr = rdreg->base & index & + (uint64_t)rdreg->count << KVM_VGIC_V3_RDIST_COUNT_SHIFT; + break; + } default: r = -ENODEV; } @@ -674,6 +709,7 @@ static int vgic_v3_has_attr(struct kvm_device *dev, switch (attr->attr) { case KVM_VGIC_V3_ADDR_TYPE_DIST: case KVM_VGIC_V3_ADDR_TYPE_REDIST: + case KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION: return 0; } break; diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c index 89faadc..45287a0 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c @@ -766,11 +766,11 @@ static int vgic_v3_insert_redist_region(struct kvm *kvm, uint32_t index, return ret; } -int vgic_v3_set_redist_base(struct kvm *kvm, u64 addr) +int vgic_v3_set_redist_base(struct kvm *kvm, u32 index, u64 addr, u32 count) { int ret; - ret = vgic_v3_insert_redist_region(kvm, 0, addr, 0); + ret = vgic_v3_insert_redist_region(kvm, index, addr, count); if (ret) return ret; diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index 7feaad6..5c70bfd 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -96,6 +96,13 @@ /* we only support 64 kB translation table page size */ #define KVM_ITS_L1E_ADDR_MASK GENMASK_ULL(51, 16) +#define KVM_VGIC_V3_RDIST_INDEX_MASK GENMASK_ULL(11, 0) +#define KVM_VGIC_V3_RDIST_FLAGS_MASK GENMASK_ULL(15, 12) +#define KVM_VGIC_V3_RDIST_FLAGS_SHIFT 12 +#define KVM_VGIC_V3_RDIST_BASE_MASK GENMASK_ULL(51, 16) +#define KVM_VGIC_V3_RDIST_COUNT_MASK GENMASK_ULL(63, 52) +#define KVM_VGIC_V3_RDIST_COUNT_SHIFT 52 + /* Requires the irq_lock to be held by the caller. */ static inline bool irq_is_pending(struct vgic_irq *irq) { @@ -198,7 +205,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info); int vgic_v3_map_resources(struct kvm *kvm); int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq); int vgic_v3_save_pending_tables(struct kvm *kvm); -int vgic_v3_set_redist_base(struct kvm *kvm, u64 addr); +int vgic_v3_set_redist_base(struct kvm *kvm, u32 index, u64 addr, u32 count); int vgic_register_redist_iodev(struct kvm_vcpu *vcpu); bool vgic_v3_check_base(struct kvm *kvm); -- 2.5.5