Received: by 10.213.65.68 with SMTP id h4csp816105imn; Wed, 28 Mar 2018 13:21:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx49TOTf5uMcOxhcZpLAujp3J0JFk2z+f9FihgoiCn1ZALstI86rX9tzijhXcTWd+hPaO/pAA X-Received: by 2002:a17:902:10c:: with SMTP id 12-v6mr5065564plb.405.1522268469282; Wed, 28 Mar 2018 13:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522268469; cv=none; d=google.com; s=arc-20160816; b=Sgwu2QI1ls8BndvPO2VgeixSe/2xfLCYhGBPHQi499SuY7oEsKHFAl5q5GjELT9CZc wme2GC304CZmMvdWM3RufIrzKYhv+SmBGOsvubv0iwPoQL7TqHtLrY0fsgBdPNjvPo+h 0zG4Rxrf6kH1VEmFopDo+sfcTmH3gwBuzAJ+h7/K4NXhEHHsv9pgvrkpI9mDGevUOp2U o18kaRV3sNyCwGqEhYdoZMs560iRAf/XpvkWk0pejhnZHczzU9tynz1PFCIuyjB8n6sA GQxj4X5bLBCFcODTMlx6iwRX9bkFqADVfXDrB0/lQ78hWLkbzxBFurL1zx54Yy6SuvvT S7OA== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=D97wQHnZIpm4hzxyjwPeCR8t7lGxr9JO0FBCusWsAnY=; b=hIAdLwRZilx3ILJ7vMBH6ByshRaPZ0u1dh0aWDW18p/OyFQxKGgrIkVIZiyXU40bkJ tWbv2T4ny18SvbCLx6cOgTghJkwr2aQ6+P9RFTEd6oN7kuRhQSKwmU+XUsaoTQCKWa3b kJgWFycB14gT3AdtLfRgHMzTYGldwyR94/k/xVoUZcISqUUkytXF9qy746xz4tIuYtYw VoyCtKl5Z94WI81xwwejzt85f0Ia/08FYJveHu8dBDe/kxrYUK5+cnAhqtgQJYuaV6J6 IVMSdjo0m+6G0EvPrtQ9xsFgXDsuUGse7G5Awqe6nQecQNPn+y3J6YZlV8G0lejLVL8+ 5ZLQ== 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 y5si2975259pgr.152.2018.03.28.13.20.54; Wed, 28 Mar 2018 13:21:09 -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 S1753320AbeC1UTz (ORCPT + 99 others); Wed, 28 Mar 2018 16:19:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54310 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752090AbeC1UTy (ORCPT ); Wed, 28 Mar 2018 16:19:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1FDF401DEA8; Wed, 28 Mar 2018 20:19:53 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-135.ams2.redhat.com [10.36.116.135]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50F5A7C3E; Wed, 28 Mar 2018 20:19:38 +0000 (UTC) Subject: Re: [RFC v2 11/12] KVM: arm/arm64: Implement KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION To: Peter Maydell References: <1522159456-10419-1-git-send-email-eric.auger@redhat.com> <1522159456-10419-12-git-send-email-eric.auger@redhat.com> Cc: Eric Auger , lkml - Kernel Mailing List , kvm-devel , kvmarm@lists.cs.columbia.edu, Marc Zyngier , Christoffer Dall , Andre Przywara , Andrew Jones , Wei Huang From: Auger Eric Message-ID: <2121af1c-a752-99d8-d51e-d500430c910e@redhat.com> Date: Wed, 28 Mar 2018 22:19:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Mar 2018 20:19:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Mar 2018 20:19:53 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 Hi Peter, On 28/03/18 20:55, Peter Maydell wrote: > 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? definitively, goto default. > >> + (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? No you're right. At the moment I only check the legacy API is not called after a first redist region has been registered (with legacy or new API). I will add this check in next version in vgic_v3_insert_redist_region(). Also something I forgot to document is the userspace must register the REDIST_REGIONS (so using the new API) starting with index 0 and continuously incrementing the index by 1. Thanks Eric > >> 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 >