From patchwork Thu May 10 14:04:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 10391847 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 338BD6028E for ; Thu, 10 May 2018 14:09:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21BD528A42 for ; Thu, 10 May 2018 14:09:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1504828A62; Thu, 10 May 2018 14:09:28 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 859C528A42 for ; Thu, 10 May 2018 14:09:27 +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=CWpykKhGN7pbKlInpbPVZOmUKBPm7Q4TsiFxyV5Tgh8=; b=lQ6P43ec11czmdgq95ZsA+HWtZ sYrW9zaDnZdFrRnngND/VOa3t7A/p/xGnwsUURSulV5mjjl9372Q+DL/1ieTQLnxXLZIZpB2v/Nm/ wg2XxggIg4w7xpNp6yQJXry/sUWxrrBIhgiCkfpH6QOx/HoIAH/Sk+ChvDJ79xmlCzY95lo76u9qb GMJHXGctX6tJhVtxd6T2h++1pAKo8Nm8Y3Uf0lPycmu6RuwNT3keU3uUPViOTPJ8A/gm+Gqk9rhe+ wFpqzmCYBZtrxOngLuaPteEOTuGKTPQwdF11Y3YuVXl8Us/TCiqgmsH1SRqMJ1VIGtju/JwXbsLi9 hfs6EgeQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fGmFw-0001cu-Ru; Thu, 10 May 2018 14:09:16 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fGmBt-0006jx-3e for linux-arm-kernel@lists.infradead.org; Thu, 10 May 2018 14:05:12 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1DAA5165D; Thu, 10 May 2018 07:04:54 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1072D3F318; Thu, 10 May 2018 07:04:52 -0700 (PDT) From: Julien Grall To: linux-arm-kernel@lists.infradead.org Subject: [RFC 03/13] virtio/scsi: Allow to use multiple banks Date: Thu, 10 May 2018 15:04:31 +0100 Message-Id: <20180510140441.24573-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180510140441.24573-1-julien.grall@arm.com> References: <20180510140441.24573-1-julien.grall@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180510_070505_224216_41FB20C0 X-CRM114-Status: GOOD ( 16.33 ) 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@arm.com, Julien Grall , will.deacon@arm.com, suzuki.poulose@arm.com 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 At the moment, virtio scsi only register a bank starting at 0. On some architectures this may not be true and the guest may have multiple memory region. Register all the memory regions to vhost by browsing kvm->mem_banks. The code is based on the virtio_net__vhost_init implementation. Signed-off-by: Julien Grall --- This code was not tested as I don't have any setup with scsi. --- virtio/scsi.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/virtio/scsi.c b/virtio/scsi.c index 58d2353..ee58e5f 100644 --- a/virtio/scsi.c +++ b/virtio/scsi.c @@ -182,24 +182,29 @@ static struct virtio_ops scsi_dev_virtio_ops = { static void virtio_scsi_vhost_init(struct kvm *kvm, struct scsi_dev *sdev) { + struct kvm_mem_bank *bank; struct vhost_memory *mem; u64 features; - int r; + int r, i; sdev->vhost_fd = open("/dev/vhost-scsi", O_RDWR); if (sdev->vhost_fd < 0) die_perror("Failed openning vhost-scsi device"); - mem = calloc(1, sizeof(*mem) + sizeof(struct vhost_memory_region)); + mem = calloc(1, sizeof(*mem) + kvm->mem_slots * sizeof(struct vhost_memory_region)); if (mem == NULL) die("Failed allocating memory for vhost memory map"); - mem->nregions = 1; - mem->regions[0] = (struct vhost_memory_region) { - .guest_phys_addr = 0, - .memory_size = kvm->ram_size, - .userspace_addr = (unsigned long)kvm->ram_start, - }; + i = 0; + list_for_each_entry(bank, &kvm->mem_banks, list) { + mem->regions[0] = (struct vhost_memory_region) { + .guest_phys_addr = bank->guest_phys_addr, + .memory_size = bank->size, + .userspace_addr = (unsigned long)bank->host_addr, + }; + + } + mem->nregions = i; r = ioctl(sdev->vhost_fd, VHOST_SET_OWNER); if (r != 0)