Received: by 10.213.65.68 with SMTP id h4csp745083imn; Wed, 28 Mar 2018 11:56:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/y1CQB6qSQOk5k8KCUfYPBXRI8YubnWja7jHT7Gt7R1pXs2IKz+3SM/eYNcu0QDDBJ0iGu X-Received: by 2002:a17:902:5388:: with SMTP id c8-v6mr4957450pli.90.1522263417301; Wed, 28 Mar 2018 11:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522263417; cv=none; d=google.com; s=arc-20160816; b=qCcAXypNiLNDYFslimLwLyU0IcL1P4fdU60WImzRzYsPbmRLExmSchnDHbtmqBUlOu h35KoiQ/XxeaREWq34GiWGZC4Cnp4NV7BFNLjxB6va7cmfsJJkPDZkRrVFq20lWhDDM+ vlKYZEcu6cePy0zGfuDDifQeZnYkUK//zCxGavynbZlxjTeH1YN7BsVq2V5Ty8n6/2hM ZINO/n4mlDGZIquIYGBro5IGnnbGKHyhsc/Tt6W0RS4aqRJJZ/V7zLasXFEK04O+OQa4 k3mzh2bDqMB5r0ukyz9jYuUNj57iUhMB5Y61z4D6T32XoIWGWwVY2it+5kAFhvkFSvQ1 ikDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=CDyt2CzEAp5TVuwXYTESzO+zi9C+A4qpT+MiTI3gakQ=; b=XWIC352P8qhKnkRtL4d6C/bDgQuoFg4BSDfDb7dbYZY2JpDugP9fwloDKdeWp7aIaB pqmyv3foqFAENrDLxbr0ODM19YsyRB1ETM/wG7VNrZ0Q+ngpU5g44NlaeXHQCdfGGDqp UYoyl+RcR7WQR1aqRfzvoDTa+FjjyJnkvI0fiQ4squSShfOi0vbrvncpWGAoOJ+0ITgK ES/OboMj+bOpC2V55drGGtRLbdzxmS1VtdSjQ0CEMTp6f5l8FVtxGDQm4cgqB2iFlVou vkujr+5OdoDOMy8k9483G0DHWX9iHB0GYhY/saOJ+fWzGJk2LqUy0lzLWTzqzuej2pvP a0bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=crEt//Oh; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m72si3205857pfi.236.2018.03.28.11.56.42; Wed, 28 Mar 2018 11:56:57 -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=@linaro.org header.s=google header.b=crEt//Oh; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753295AbeC1Szr (ORCPT + 99 others); Wed, 28 Mar 2018 14:55:47 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:35079 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752377AbeC1Szp (ORCPT ); Wed, 28 Mar 2018 14:55:45 -0400 Received: by mail-oi0-f68.google.com with SMTP id z8-v6so3058732oix.2 for ; Wed, 28 Mar 2018 11:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=CDyt2CzEAp5TVuwXYTESzO+zi9C+A4qpT+MiTI3gakQ=; b=crEt//OhEk30v9bIp3PFKAuiYbjst4cW94IURrXvicgVr0Pm++m30Zip/CM2/qY61t BOL5uhNzcc4a5qLOBlooEudw0pnRl5SXDy/QZiLN23l05zgKWMc41KgTLMsIqDMcnG+A smEir/BnFnXdbwEZfhvRvJPwP3jRFPUFvchvk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=CDyt2CzEAp5TVuwXYTESzO+zi9C+A4qpT+MiTI3gakQ=; b=K8yLm62JFCk8Ct9KBl6Os79MVmaMIbLr79yX8qGoPtEPoH7CMN9xBwM1swBr3m6rp1 XQ2CI8tkaN1RrSGhxpktIQQdowcADS/VkfZhyeNr7IWFmRjuKSPpmmkSsYpeZ0m5PcZo QbJa+kgmYOTzQShIXeCWTebESG8Db42lNbMUgHwsfTvgV1I+arUe9MQ6UEufZzZSfwp3 1ypnBgyIlwpTLfsd5Vt/yUxk6RQ6UpM6eQ9U6OWTrPhZaOc0Gj9rTT6tsDNOIGHa7SDV 836AA/intl6cAoo+XSTorSJkJgEQ9EcBZGSYwo+J1RpVguaxnyWo3K/GVcsc7cGlt2tk OjuA== X-Gm-Message-State: ALQs6tBhxf3yHET3GBOyz1yrM4GjqSrmo5RnWhsptXCUdBxwY/HcjAbs UGTjfHTQxN3Q8m99fUNWZSgcGtHV8RyI0ORjzG8SXyv/rZ8= X-Received: by 10.202.212.85 with SMTP id l82mr2874878oig.102.1522263344642; Wed, 28 Mar 2018 11:55:44 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2286:0:0:0:0:0 with HTTP; Wed, 28 Mar 2018 11:55:24 -0700 (PDT) In-Reply-To: <1522159456-10419-12-git-send-email-eric.auger@redhat.com> References: <1522159456-10419-1-git-send-email-eric.auger@redhat.com> <1522159456-10419-12-git-send-email-eric.auger@redhat.com> From: Peter Maydell Date: Wed, 28 Mar 2018 19:55:24 +0100 Message-ID: Subject: Re: [RFC v2 11/12] KVM: arm/arm64: Implement KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION To: Eric Auger Cc: Eric Auger , lkml - Kernel Mailing List , kvm-devel , kvmarm@lists.cs.columbia.edu, Marc Zyngier , Christoffer Dall , Andre Przywara , Andrew Jones , Wei Huang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27 March 2018 at 15:04, Eric Auger wrote: > 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; Here you check whether rdreg is NULL... > + > + *addr_ptr = rdreg->base & index & ...but here you dereference it anyway. Missing "goto out"/break/other control flow? > + (uint64_t)rdreg->count << KVM_VGIC_V3_RDIST_COUNT_SHIFT; > + break; > + } I was looking for the code which checked "EINVAL if you already used KVM_VGIC_V3_ADDR_TYPE_REDIST", but couldn't see it. Is that handled by one of the helper functions? > 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; thanks -- PMM