From patchwork Fri Nov 10 19:19:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10053589 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 5887A60631 for ; Fri, 10 Nov 2017 19:18:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A4462B418 for ; Fri, 10 Nov 2017 19:18:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EE9B2B41C; Fri, 10 Nov 2017 19:18:25 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B87282B418 for ; Fri, 10 Nov 2017 19:18:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753832AbdKJTSW (ORCPT ); Fri, 10 Nov 2017 14:18:22 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33780 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753627AbdKJTSV (ORCPT ); Fri, 10 Nov 2017 14:18:21 -0500 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 1099514; Fri, 10 Nov 2017 11:18:21 -0800 (PST) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.210.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 484A63F5AF; Fri, 10 Nov 2017 11:18:20 -0800 (PST) From: Jean-Philippe Brucker To: kvm@vger.kernel.org Cc: will.deacon@arm.com, kraxel@redhat.com Subject: [PATCH kvmtool 1/3] virtio: Save negotiated features Date: Fri, 10 Nov 2017 19:19:57 +0000 Message-Id: <20171110191959.25608-2-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171110191959.25608-1-jean-philippe.brucker@arm.com> References: <20171110191959.25608-1-jean-philippe.brucker@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We're going to need the features bits negotiated between host and guest in the core code. Save them in the virtio_device structure. Signed-off-by: Jean-Philippe Brucker --- include/kvm/virtio.h | 4 ++++ virtio/core.c | 9 +++++++++ virtio/mmio.c | 4 ++-- virtio/pci.c | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h index 00a791acf0f8..69856d9ef4e7 100644 --- a/include/kvm/virtio.h +++ b/include/kvm/virtio.h @@ -141,6 +141,7 @@ struct virtio_device { void *virtio; struct virtio_ops *ops; u16 endian; + u32 features; }; struct virtio_ops { @@ -180,4 +181,7 @@ static inline void virtio_init_device_vq(struct virtio_device *vdev, vq->endian = vdev->endian; } +void virtio_set_guest_features(struct kvm *kvm, struct virtio_device *vdev, + void *dev, u32 features); + #endif /* KVM__VIRTIO_H */ diff --git a/virtio/core.c b/virtio/core.c index d6ac289d450e..e98241f04fcd 100644 --- a/virtio/core.c +++ b/virtio/core.c @@ -198,6 +198,15 @@ bool virtio_queue__should_signal(struct virt_queue *vq) return false; } +void virtio_set_guest_features(struct kvm *kvm, struct virtio_device *vdev, + void *dev, u32 features) +{ + /* TODO: fail negotiation if features & ~host_features */ + + vdev->features = features; + vdev->ops->set_guest_features(kvm, dev, features); +} + int virtio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev, struct virtio_ops *ops, enum virtio_trans trans, int device_id, int subsys_id, int class) diff --git a/virtio/mmio.c b/virtio/mmio.c index 005257fcb8f1..629127528bf0 100644 --- a/virtio/mmio.c +++ b/virtio/mmio.c @@ -159,8 +159,8 @@ static void virtio_mmio_config_out(struct kvm_cpu *vcpu, case VIRTIO_MMIO_GUEST_FEATURES: if (vmmio->hdr.guest_features_sel == 0) { val = ioport__read32(data); - vdev->ops->set_guest_features(vmmio->kvm, - vmmio->dev, val); + virtio_set_guest_features(vmmio->kvm, vdev, + vmmio->dev, val); } break; case VIRTIO_MMIO_GUEST_PAGE_SIZE: diff --git a/virtio/pci.c b/virtio/pci.c index 4ce111108100..2054c7bac472 100644 --- a/virtio/pci.c +++ b/virtio/pci.c @@ -267,7 +267,7 @@ static bool virtio_pci__io_out(struct ioport *ioport, struct kvm_cpu *vcpu, u16 switch (offset) { case VIRTIO_PCI_GUEST_FEATURES: val = ioport__read32(data); - vdev->ops->set_guest_features(kvm, vpci->dev, val); + virtio_set_guest_features(kvm, vdev, vpci->dev, val); break; case VIRTIO_PCI_QUEUE_PFN: val = ioport__read32(data);