From patchwork Tue May 9 08:56:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9717367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3C22660365 for ; Tue, 9 May 2017 09:08:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22A8828389 for ; Tue, 9 May 2017 09:08:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1474E283F2; Tue, 9 May 2017 09:08:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A871828389 for ; Tue, 9 May 2017 09:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Bmnccx0neouPwJzYgiXnxhueEGndFKV5eEX9iQRWe1I=; b=EW6KNeAC5l35B3bnqWzk5Xg1mN 2WS8k8vpPQsM0it0DiLirD7+8XZWIbqqLeuIxgYxFOSCHykpqZJxJqJ8Oz9ecNKzOD5xPblUJrOr8 HuQssoqBdP/2jvL5uXwy1p2z2T4dUTSGf/pUCXNrNRfNXmvcgQeNWOiRjUgODWm15GXgFR4mKdzu7 GJfuXB4Kg8xZ/DURLymuxG7PC3GOKS/ELuAEbmRw+VB2miBErRzrjxWM0Ywjtefb4Ls1OW+e/QTJ4 SLY/OtwmG/fVTw5dQEEwdeIDML0YUqSIuW1IanG9gTyxUoaetT0dwN/olnBb30US1lztJKGKQr0Qa FzUuhiMA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d818E-0001iw-Q2; Tue, 09 May 2017 09:08:34 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d80wq-0002I0-FU for linux-arm-kernel@lists.infradead.org; Tue, 09 May 2017 08:56:51 +0000 Received: by mail-wm0-x232.google.com with SMTP id m123so92390123wma.0 for ; Tue, 09 May 2017 01:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c1lskPXDxBs3FtPb2JrYEx6tY7javDHPnxMcfs+jupE=; b=EhxDp4ZjgdwrTtrHC3Yimg3dHSuQ2v+/qbfSQM3fxKUv7GHWVm/LnSraiIcYt+9F4D 3MtSFPAOBOwpvbZx6X+NOx+UIMOvbOiP5LLCZk57ofKMhkY2w/Z+BFUOFet8j12660VO 2A/OXPNmFBvgIwRcwnk8Xm0OzoKRoQfE94s9I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=c1lskPXDxBs3FtPb2JrYEx6tY7javDHPnxMcfs+jupE=; b=cH3QGIZ0t4RrAu1Vm168DcOI257jz6zHcojPYau94rGAbzgmf/QMfj897CRuq2Kpsa ddoEJevFZYieEFfP6jqelxSpBR7rKKQ9q2eD1eqEGa1McpEWQ8tOmDCtw1v9Hi+pTfPX v3eEQknE5NgQzRNvhRlFovtuWaAbU/J3cV9yqz2hrD+Cv69eH2hCGuI/NVlgMecAAqdR LYqABhgeKWlKP7FqZnJSz+4GYrQq0QRbvKkIGE13raqR7dYXZSR9YsdCt66BSgARHEur vOsO/k3NA1i5KThlIhZPx2BOm6S7DuEmU5YgAee2/44wbG0hl/rh9kOzzgu7s8vtCcCE 2JTA== X-Gm-Message-State: AN3rC/5zO2KI7uEx1SY4BoU6DDcqdKrQzZTXuJ+8w1D9hZOdJ0aDji+Z Z05Wf8x0rHPkvfPn X-Received: by 10.80.213.29 with SMTP id u29mr23521504edi.47.1494320187519; Tue, 09 May 2017 01:56:27 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id f40sm8376265edb.7.2017.05.09.01.56.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 May 2017 01:56:27 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 03/11] KVM: Add kvm_vcpu_get_idx to get vcpu index in kvm->vcpus Date: Tue, 9 May 2017 10:56:10 +0200 Message-Id: <20170509085618.28311-4-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170509085618.28311-1-cdall@linaro.org> References: <20170509085618.28311-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170509_015648_750714_519CBB51 X-CRM114-Status: GOOD ( 11.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Eric Auger , kvm@vger.kernel.org, Christoffer Dall MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP There are occasional needs to use the index of vcpu in the kvm->vcpus array to map something related to a VCPU. For example, unlike the vcpu->vcpu_id, the vcpu index is guaranteed to not be sparse across all vcpus which is useful when allocating a memory area for each vcpu. Signed-off-by: Christoffer Dall Reviewed-by: Eric Auger --- include/linux/kvm_host.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 2c14ad9..12eb26d 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -490,6 +490,17 @@ static inline struct kvm_vcpu *kvm_get_vcpu_by_id(struct kvm *kvm, int id) return NULL; } +static inline int kvm_vcpu_get_idx(struct kvm_vcpu *vcpu) +{ + struct kvm_vcpu *tmp; + int idx; + + kvm_for_each_vcpu(idx, tmp, vcpu->kvm) + if (tmp == vcpu) + return idx; + BUG(); +} + #define kvm_for_each_memslot(memslot, slots) \ for (memslot = &slots->memslots[0]; \ memslot < slots->memslots + KVM_MEM_SLOTS_NUM && memslot->npages;\