From patchwork Tue Feb 16 09:44:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF5CDC433E0 for ; Tue, 16 Feb 2021 09:46:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 976C764DDA for ; Tue, 16 Feb 2021 09:46:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbhBPJqu (ORCPT ); Tue, 16 Feb 2021 04:46:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33576 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbhBPJqh (ORCPT ); Tue, 16 Feb 2021 04:46:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DCpAAD0R3f5DpHYdniOmpnpZ0gH4EPVC6kj5APUQyNw=; b=ZERLiRIaklb9TzbbDmWFdbD0eGRfnqBXNmfnoL9cq+Xmla/0WUC/igKMpiGRKoi3E9LT5f 3Ye6MMMFndvpgHelPFbG5S4NZJGnvAtyfbNQ9wbDGs0YNjW+DPygk4v2aohysEEGQzSboU zPjQi7nUSYEE8bV9/28ETIJugaSK8zU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-Hw12bHLRO-2iSN7t9QeHiw-1; Tue, 16 Feb 2021 04:45:07 -0500 X-MC-Unique: Hw12bHLRO-2iSN7t9QeHiw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95A9D801965; Tue, 16 Feb 2021 09:45:06 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 609555D9C0; Tue, 16 Feb 2021 09:45:03 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 01/10] vdpa: add get_config_size callback in vdpa_config_ops Date: Tue, 16 Feb 2021 10:44:45 +0100 Message-Id: <20210216094454.82106-2-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This new callback is used to get the size of the configuration space of vDPA devices. Signed-off-by: Stefano Garzarella --- include/linux/vdpa.h | 4 ++++ drivers/vdpa/ifcvf/ifcvf_main.c | 6 ++++++ drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++ drivers/vdpa/vdpa_sim/vdpa_sim.c | 9 +++++++++ 4 files changed, 25 insertions(+) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 4ab5494503a8..fddf42b17573 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -150,6 +150,9 @@ struct vdpa_iova_range { * @set_status: Set the device status * @vdev: vdpa device * @status: virtio device status + * @get_config_size: Get the size of the configuration space + * @vdev: vdpa device + * Returns size_t: configuration size * @get_config: Read from device specific configuration space * @vdev: vdpa device * @offset: offset from the beginning of @@ -231,6 +234,7 @@ struct vdpa_config_ops { u32 (*get_vendor_id)(struct vdpa_device *vdev); u8 (*get_status)(struct vdpa_device *vdev); void (*set_status)(struct vdpa_device *vdev, u8 status); + size_t (*get_config_size)(struct vdpa_device *vdev); void (*get_config)(struct vdpa_device *vdev, unsigned int offset, void *buf, unsigned int len); void (*set_config)(struct vdpa_device *vdev, unsigned int offset, diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 7c8bbfcf6c3e..2443271e17d2 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -332,6 +332,11 @@ static u32 ifcvf_vdpa_get_vq_align(struct vdpa_device *vdpa_dev) return IFCVF_QUEUE_ALIGNMENT; } +static size_t ifcvf_vdpa_get_config_size(struct vdpa_device *vdpa_dev) +{ + return sizeof(struct virtio_net_config); +} + static void ifcvf_vdpa_get_config(struct vdpa_device *vdpa_dev, unsigned int offset, void *buf, unsigned int len) @@ -392,6 +397,7 @@ static const struct vdpa_config_ops ifc_vdpa_ops = { .get_device_id = ifcvf_vdpa_get_device_id, .get_vendor_id = ifcvf_vdpa_get_vendor_id, .get_vq_align = ifcvf_vdpa_get_vq_align, + .get_config_size = ifcvf_vdpa_get_config_size, .get_config = ifcvf_vdpa_get_config, .set_config = ifcvf_vdpa_set_config, .set_config_cb = ifcvf_vdpa_set_config_cb, diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 10e9b09932eb..78043ee567b6 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1814,6 +1814,11 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status) ndev->mvdev.status |= VIRTIO_CONFIG_S_FAILED; } +static size_t mlx5_vdpa_get_config_size(struct vdpa_device *vdev) +{ + return sizeof(struct virtio_net_config); +} + static void mlx5_vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, void *buf, unsigned int len) { @@ -1900,6 +1905,7 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = { .get_vendor_id = mlx5_vdpa_get_vendor_id, .get_status = mlx5_vdpa_get_status, .set_status = mlx5_vdpa_set_status, + .get_config_size = mlx5_vdpa_get_config_size, .get_config = mlx5_vdpa_get_config, .set_config = mlx5_vdpa_set_config, .get_generation = mlx5_vdpa_get_generation, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index d5942842432d..779ae6c144d7 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -439,6 +439,13 @@ static void vdpasim_set_status(struct vdpa_device *vdpa, u8 status) spin_unlock(&vdpasim->lock); } +static size_t vdpasim_get_config_size(struct vdpa_device *vdpa) +{ + struct vdpasim *vdpasim = vdpa_to_sim(vdpa); + + return vdpasim->dev_attr.config_size; +} + static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset, void *buf, unsigned int len) { @@ -566,6 +573,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = { .get_vendor_id = vdpasim_get_vendor_id, .get_status = vdpasim_get_status, .set_status = vdpasim_set_status, + .get_config_size = vdpasim_get_config_size, .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, .get_generation = vdpasim_get_generation, @@ -593,6 +601,7 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { .get_vendor_id = vdpasim_get_vendor_id, .get_status = vdpasim_get_status, .set_status = vdpasim_set_status, + .get_config_size = vdpasim_get_config_size, .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, .get_generation = vdpasim_get_generation, From patchwork Tue Feb 16 09:44:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCB80C433DB for ; Tue, 16 Feb 2021 09:47:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8684464DA1 for ; Tue, 16 Feb 2021 09:47:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230029AbhBPJqz (ORCPT ); Tue, 16 Feb 2021 04:46:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30486 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbhBPJqj (ORCPT ); Tue, 16 Feb 2021 04:46:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sL2HoPks3VzKpFvhRVHLVH8gFjTz1o9yXUZfovhuAAk=; b=YwsF7jVw++VFQA6tE+GgpiaN2vSYiNvQSK7D1pD2VxI0raz88mHERQ6eD/ARGcDiOPDQgG rN0H2/sTpPbFbMndGIVrnKukWoU/KMuYVgNHY5niFT61wvRacMbk8MeAm5h66Pg4TXrrq9 QfQUnd5a2OlbiwyT3si5+YNsC+DKEAw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-394-lntx5zuyNCyODqqUmRpAag-1; Tue, 16 Feb 2021 04:45:09 -0500 X-MC-Unique: lntx5zuyNCyODqqUmRpAag-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4367E801989; Tue, 16 Feb 2021 09:45:08 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBCD45D9C0; Tue, 16 Feb 2021 09:45:06 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 02/10] vdpa: check vdpa_get_config() parameters and return bytes read Date: Tue, 16 Feb 2021 10:44:46 +0100 Message-Id: <20210216094454.82106-3-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now we have the 'get_config_size()' callback available, so we can check that 'offset' and 'len' parameters are valid. When these exceed boundaries, we limit the reading to the available configuration space in the device, and we return the amount of bytes read. We also move vdpa_get_config() implementation in drivers/vdpa/vdpa.c, since the function are growing. Signed-off-by: Stefano Garzarella --- include/linux/vdpa.h | 16 ++-------------- drivers/vdpa/vdpa.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index fddf42b17573..8a679c98f8b1 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -332,20 +332,8 @@ static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) return ops->set_features(vdev, features); } - -static inline void vdpa_get_config(struct vdpa_device *vdev, unsigned offset, - void *buf, unsigned int len) -{ - const struct vdpa_config_ops *ops = vdev->config; - - /* - * Config accesses aren't supposed to trigger before features are set. - * If it does happen we assume a legacy guest. - */ - if (!vdev->features_valid) - vdpa_set_features(vdev, 0); - ops->get_config(vdev, offset, buf, len); -} +int vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, + void *buf, unsigned int len); /** * vdpa_mgmtdev_ops - vdpa device ops diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 3d997b389345..9ed6c779c63c 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -51,6 +51,41 @@ static struct bus_type vdpa_bus = { .remove = vdpa_dev_remove, }; +static int vdpa_config_size_wrap(struct vdpa_device *vdev, unsigned int offset, + unsigned int len) +{ + const struct vdpa_config_ops *ops = vdev->config; + unsigned int config_size = ops->get_config_size(vdev); + + if (offset > config_size || len > config_size) + return -1; + + return min(len, config_size - offset); +} + +int vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, + void *buf, unsigned int len) +{ + const struct vdpa_config_ops *ops = vdev->config; + int bytes_get; + + bytes_get = vdpa_config_size_wrap(vdev, offset, len); + if (bytes_get <= 0) + return bytes_get; + + /* + * Config accesses aren't supposed to trigger before features are set. + * If it does happen we assume a legacy guest. + */ + if (!vdev->features_valid) + vdpa_set_features(vdev, 0); + + ops->get_config(vdev, offset, buf, bytes_get); + + return bytes_get; +} +EXPORT_SYMBOL_GPL(vdpa_get_config); + static void vdpa_release_dev(struct device *d) { struct vdpa_device *vdev = dev_to_vdpa(d); From patchwork Tue Feb 16 09:44:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA6C4C433E0 for ; Tue, 16 Feb 2021 09:47:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A120464DCF for ; Tue, 16 Feb 2021 09:47:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229930AbhBPJrJ (ORCPT ); Tue, 16 Feb 2021 04:47:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52338 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbhBPJqj (ORCPT ); Tue, 16 Feb 2021 04:46:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zgJXmECmOauhfYDJPw4bn7OxQRQZ97Yc1PJaarzr/ps=; b=hoDqqolm4UfyS3nv8CooXswFswMsOF159g5b0hlFHIVXAiJE1vaf3Q+Tv8JxGhJ0dQAtiv 6sDMdUGFEKKyM/yXoiJIbYpibTksZxyyIDnv1N/PAb02J+RKhrw449PyiPGDwlcDW7+8RV DlGtuEryGZen25NdIZFbyFbw5A82OuA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-87-VmUvdcoDMjK1N8CpeqbGyA-1; Tue, 16 Feb 2021 04:45:11 -0500 X-MC-Unique: VmUvdcoDMjK1N8CpeqbGyA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF698100AA21; Tue, 16 Feb 2021 09:45:09 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B2F35D9C0; Tue, 16 Feb 2021 09:45:08 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 03/10] vdpa: add vdpa_set_config() helper Date: Tue, 16 Feb 2021 10:44:47 +0100 Message-Id: <20210216094454.82106-4-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's add a function similar to vpda_get_config() to check the 'offset' and 'len' parameters, call the set_config() device callback, and return the amount of bytes written. Signed-off-by: Stefano Garzarella --- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 8a679c98f8b1..562fcd14f4b5 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -334,6 +334,8 @@ static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) int vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, void *buf, unsigned int len); +int vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, + const void *buf, unsigned int len); /** * vdpa_mgmtdev_ops - vdpa device ops diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 9ed6c779c63c..825afc690a7e 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -86,6 +86,22 @@ int vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, } EXPORT_SYMBOL_GPL(vdpa_get_config); +int vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, + const void *buf, unsigned int len) +{ + const struct vdpa_config_ops *ops = vdev->config; + int bytes_set; + + bytes_set = vdpa_config_size_wrap(vdev, offset, len); + if (bytes_set <= 0) + return bytes_set; + + ops->set_config(vdev, offset, buf, bytes_set); + + return bytes_set; +} +EXPORT_SYMBOL_GPL(vdpa_set_config); + static void vdpa_release_dev(struct device *d) { struct vdpa_device *vdev = dev_to_vdpa(d); From patchwork Tue Feb 16 09:44:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF7BCC433E6 for ; Tue, 16 Feb 2021 09:47:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B23C764DCF for ; Tue, 16 Feb 2021 09:47:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbhBPJrh (ORCPT ); Tue, 16 Feb 2021 04:47:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38790 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbhBPJrG (ORCPT ); Tue, 16 Feb 2021 04:47:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aKEudwAL0ABOP6RtR9S4wa4bhOuDErjR+HWjbOMiYD4=; b=DUb+tMgnBUKYLVZxauhNws1TvQ9V8Mct26pEGhIQ8NxDlGeCsRzQW1gZijKjbKpAf2p4s7 dpmm7nnp1tC9jJbbIRRMEaUtJHaQ4I+iRTLkwdBRR4XhCB+fAXUrL2LJoZx7hARrRkROcw F3T9T/T2iQ3MKXds+4xMJRBI8YfOJLs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-WHfg1IYJPuup6N6pV86-aQ-1; Tue, 16 Feb 2021 04:45:36 -0500 X-MC-Unique: WHfg1IYJPuup6N6pV86-aQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA36BAFA80; Tue, 16 Feb 2021 09:45:35 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 569F0163F1; Tue, 16 Feb 2021 09:45:31 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 04/10] vdpa: remove param checks in the get/set_config callbacks Date: Tue, 16 Feb 2021 10:44:48 +0100 Message-Id: <20210216094454.82106-5-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org vdpa_get_config() and vdpa_set_config() now check parameters before calling callbacks, so we can remove these redundant checks. Signed-off-by: Stefano Garzarella --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 +-- drivers/vdpa/vdpa_sim/vdpa_sim.c | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 78043ee567b6..ab63dc9b8432 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1825,8 +1825,7 @@ static void mlx5_vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); - if (offset + len <= sizeof(struct virtio_net_config)) - memcpy(buf, (u8 *)&ndev->config + offset, len); + memcpy(buf, (u8 *)&ndev->config + offset, len); } static void mlx5_vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, const void *buf, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 779ae6c144d7..392180c6f2cf 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -451,9 +451,6 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset, { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); - if (offset + len > vdpasim->dev_attr.config_size) - return; - if (vdpasim->dev_attr.get_config) vdpasim->dev_attr.get_config(vdpasim, vdpasim->config); @@ -465,9 +462,6 @@ static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset, { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); - if (offset + len > vdpasim->dev_attr.config_size) - return; - memcpy(vdpasim->config + offset, buf, len); if (vdpasim->dev_attr.set_config) From patchwork Tue Feb 16 09:44:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D00D6C433E0 for ; Tue, 16 Feb 2021 09:47:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93B9B64DDA for ; Tue, 16 Feb 2021 09:47:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbhBPJrY (ORCPT ); Tue, 16 Feb 2021 04:47:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52504 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230053AbhBPJrG (ORCPT ); Tue, 16 Feb 2021 04:47:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=epeDldi/RqZNzvZCpZ/Dw6am7oNc4937HhZPeBnWnoI=; b=A1ZfPInofDJI9EUGMfX6upEk8GMxBk6K7EF3dJDCAO1IBKR1LgzBjLXMzuOT6GAhfDHSmO Z/g+LfXaoftsLq439zyM6ljlEmxuIWCD7WG7HI5/fuM2wUT5wZxAhKadhDbm8WujNObJn8 oTxFvQAaSbrKq6L4Y/kzJEwu40TcWrg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-436-YetAxVWXOEmKjMEu6GCXKw-1; Tue, 16 Feb 2021 04:45:38 -0500 X-MC-Unique: YetAxVWXOEmKjMEu6GCXKw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65573100A689; Tue, 16 Feb 2021 09:45:37 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 109B216D5E; Tue, 16 Feb 2021 09:45:35 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 05/10] vdpa: remove WARN_ON() in the get/set_config callbacks Date: Tue, 16 Feb 2021 10:44:49 +0100 Message-Id: <20210216094454.82106-6-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org vdpa_get_config() and vdpa_set_config() now check parameters before calling callbacks, so we can remove these warnings. Signed-off-by: Stefano Garzarella --- Maybe we can skip this patch and leave the WARN_ONs in place. What do you recommend? --- drivers/vdpa/ifcvf/ifcvf_base.c | 3 +-- drivers/vdpa/ifcvf/ifcvf_main.c | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c b/drivers/vdpa/ifcvf/ifcvf_base.c index f2a128e56de5..5941ecf934d0 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.c +++ b/drivers/vdpa/ifcvf/ifcvf_base.c @@ -222,7 +222,6 @@ void ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset, u8 old_gen, new_gen, *p; int i; - WARN_ON(offset + length > sizeof(struct virtio_net_config)); do { old_gen = ifc_ioread8(&hw->common_cfg->config_generation); p = dst; @@ -240,7 +239,7 @@ void ifcvf_write_net_config(struct ifcvf_hw *hw, u64 offset, int i; p = src; - WARN_ON(offset + length > sizeof(struct virtio_net_config)); + for (i = 0; i < length; i++) ifc_iowrite8(*p++, hw->net_cfg + offset + i); } diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 2443271e17d2..e55f88c57461 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -343,7 +343,6 @@ static void ifcvf_vdpa_get_config(struct vdpa_device *vdpa_dev, { struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); - WARN_ON(offset + len > sizeof(struct virtio_net_config)); ifcvf_read_net_config(vf, offset, buf, len); } @@ -353,7 +352,6 @@ static void ifcvf_vdpa_set_config(struct vdpa_device *vdpa_dev, { struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); - WARN_ON(offset + len > sizeof(struct virtio_net_config)); ifcvf_write_net_config(vf, offset, buf, len); } From patchwork Tue Feb 16 09:44:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EFB5C433E9 for ; Tue, 16 Feb 2021 09:47:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5FFC64DDA for ; Tue, 16 Feb 2021 09:47:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbhBPJrl (ORCPT ); Tue, 16 Feb 2021 04:47:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30230 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbhBPJrI (ORCPT ); Tue, 16 Feb 2021 04:47:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HBRaTQc7Ttw1kohIDA1m2qTU6L8be75odJdy+4tgCL8=; b=LQop7jixI3dp3ed+TmkJx6L/FRb5xPcmt/SaBVhw16xi+C4wNW0Uh23eHS3iUq+E6g+Ghl zvbuSPQYThfgaC9XfVC5PqkDSDUYrEsEjOH1xXkjnm5K5hwDWcPNhter8WgSlIBwqawDMD jsKc1Bs5riZF/7Sh2E0jJ4pwsZrxqDA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-LEkPaDiQMqOnRTuseGIZ_A-1; Tue, 16 Feb 2021 04:45:40 -0500 X-MC-Unique: LEkPaDiQMqOnRTuseGIZ_A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18ED5801962; Tue, 16 Feb 2021 09:45:39 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA50F1851D; Tue, 16 Feb 2021 09:45:37 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 06/10] virtio_vdpa: use vdpa_set_config() Date: Tue, 16 Feb 2021 10:44:50 +0100 Message-Id: <20210216094454.82106-7-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Instead of calling the 'set_config' callback directly, we call the new vdpa_set_config() helper which also checks the parameters. Signed-off-by: Stefano Garzarella --- drivers/virtio/virtio_vdpa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index e28acf482e0c..2f1c4a2dd241 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -65,9 +65,8 @@ static void virtio_vdpa_set(struct virtio_device *vdev, unsigned offset, const void *buf, unsigned len) { struct vdpa_device *vdpa = vd_get_vdpa(vdev); - const struct vdpa_config_ops *ops = vdpa->config; - ops->set_config(vdpa, offset, buf, len); + vdpa_set_config(vdpa, offset, buf, len); } static u32 virtio_vdpa_generation(struct virtio_device *vdev) From patchwork Tue Feb 16 09:44:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4225AC433DB for ; Tue, 16 Feb 2021 09:48:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09FD764DC3 for ; Tue, 16 Feb 2021 09:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbhBPJrv (ORCPT ); Tue, 16 Feb 2021 04:47:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32502 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbhBPJrM (ORCPT ); Tue, 16 Feb 2021 04:47:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/Z8IX9Mkudp3/Hl+TsF7v2vmeC6C7k+WY1X8lrddSYc=; b=MrBaGVQEpt+o3LyQZlMgS/efKRwwIRhBhlhdwadknDofr1Ck7WvRFHQpHbSeX5vBKf+Y8u E9/GBULpicOEVRDueIvxiV7lJNTIteFqjcdhedue0P4G9wsktPvgybNDSIlkgmHiVxzRcs /I55l5msXMvzthMfb3Ky9MsE3zrwxXA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-583-_DVXtfshNqq4q2UNYiJkjg-1; Tue, 16 Feb 2021 04:45:43 -0500 X-MC-Unique: _DVXtfshNqq4q2UNYiJkjg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85B091005501; Tue, 16 Feb 2021 09:45:42 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73552163F1; Tue, 16 Feb 2021 09:45:39 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 07/10] vhost/vdpa: use vdpa_set_config() Date: Tue, 16 Feb 2021 10:44:51 +0100 Message-Id: <20210216094454.82106-8-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Instead of calling the 'set_config' callback directly, we call the new vdpa_set_config() helper which also checks the parameters. Signed-off-by: Stefano Garzarella --- drivers/vhost/vdpa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index ef688c8c0e0e..cdd8f24168b2 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -236,7 +236,6 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, struct vhost_vdpa_config __user *c) { struct vdpa_device *vdpa = v->vdpa; - const struct vdpa_config_ops *ops = vdpa->config; struct vhost_vdpa_config config; unsigned long size = offsetof(struct vhost_vdpa_config, buf); u8 *buf; @@ -250,7 +249,7 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, if (IS_ERR(buf)) return PTR_ERR(buf); - ops->set_config(vdpa, config.off, buf, config.len); + vdpa_set_config(vdpa, config.off, buf, config.len); kvfree(buf); return 0; From patchwork Tue Feb 16 09:44:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 602ECC433E0 for ; Tue, 16 Feb 2021 09:48:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EAEC64DCF for ; Tue, 16 Feb 2021 09:48:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230160AbhBPJsP (ORCPT ); Tue, 16 Feb 2021 04:48:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53724 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbhBPJrk (ORCPT ); Tue, 16 Feb 2021 04:47:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BUO68bTCohFMIGXH82qxXbnohw7EihHHCgax44jVeHQ=; b=HuSw1D8Bc34sPEVU68ZQdqw2tVNsQDQvpxjQQpl0dC6PrRufdfdPBIcq9e5b3dKzHPjViz BM5kpW1dcVCKyAgcDNXEe1e8xXL9y+MCYwlweqhqRNh3/KYmohjtGgqRNWj5sl+v2rVtb+ Jb1gtpjKfvJhILNOu7zJTGdFIym+xh4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-nkQI-Q60Pt-r3dfjPIQN8w-1; Tue, 16 Feb 2021 04:46:10 -0500 X-MC-Unique: nkQI-Q60Pt-r3dfjPIQN8w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76CD7107ACC7; Tue, 16 Feb 2021 09:46:09 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED4215C6AB; Tue, 16 Feb 2021 09:46:03 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 08/10] vhost/vdpa: allow user space to pass buffers bigger than config space Date: Tue, 16 Feb 2021 10:44:52 +0100 Message-Id: <20210216094454.82106-9-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org vdpa_get_config() and vdpa_set_config() now are able to read/write only the bytes available in the device configuration space, also if the buffer provided is bigger than that. Let's use this feature to allow the user space application to pass any buffer. We limit the size of the internal bounce buffer allocated with the device config size. Signed-off-by: Stefano Garzarella --- drivers/vhost/vdpa.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index cdd8f24168b2..544f8582a42b 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -185,10 +185,10 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp) return 0; } -static int vhost_vdpa_config_validate(struct vhost_vdpa *v, - struct vhost_vdpa_config *c) +static ssize_t vhost_vdpa_config_validate(struct vhost_vdpa *v, + struct vhost_vdpa_config *c) { - long size = 0; + u32 size = 0; switch (v->virtio_id) { case VIRTIO_ID_NET: @@ -199,10 +199,7 @@ static int vhost_vdpa_config_validate(struct vhost_vdpa *v, if (c->len == 0) return -EINVAL; - if (c->len > size - c->off) - return -E2BIG; - - return 0; + return min(c->len, size); } static long vhost_vdpa_get_config(struct vhost_vdpa *v, @@ -211,19 +208,23 @@ static long vhost_vdpa_get_config(struct vhost_vdpa *v, struct vdpa_device *vdpa = v->vdpa; struct vhost_vdpa_config config; unsigned long size = offsetof(struct vhost_vdpa_config, buf); + ssize_t config_size; u8 *buf; if (copy_from_user(&config, c, size)) return -EFAULT; - if (vhost_vdpa_config_validate(v, &config)) - return -EINVAL; - buf = kvzalloc(config.len, GFP_KERNEL); + + config_size = vhost_vdpa_config_validate(v, &config); + if (config_size <= 0) + return config_size; + + buf = kvzalloc(config_size, GFP_KERNEL); if (!buf) return -ENOMEM; - vdpa_get_config(vdpa, config.off, buf, config.len); + vdpa_get_config(vdpa, config.off, buf, config_size); - if (copy_to_user(c->buf, buf, config.len)) { + if (copy_to_user(c->buf, buf, config_size)) { kvfree(buf); return -EFAULT; } @@ -238,18 +239,21 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, struct vdpa_device *vdpa = v->vdpa; struct vhost_vdpa_config config; unsigned long size = offsetof(struct vhost_vdpa_config, buf); + ssize_t config_size; u8 *buf; if (copy_from_user(&config, c, size)) return -EFAULT; - if (vhost_vdpa_config_validate(v, &config)) - return -EINVAL; - buf = vmemdup_user(c->buf, config.len); + config_size = vhost_vdpa_config_validate(v, &config); + if (config_size <= 0) + return config_size; + + buf = vmemdup_user(c->buf, config_size); if (IS_ERR(buf)) return PTR_ERR(buf); - vdpa_set_config(vdpa, config.off, buf, config.len); + vdpa_set_config(vdpa, config.off, buf, config_size); kvfree(buf); return 0; From patchwork Tue Feb 16 09:44:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6CE5C433E0 for ; Tue, 16 Feb 2021 09:49:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A20C64DCF for ; Tue, 16 Feb 2021 09:49:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230138AbhBPJs6 (ORCPT ); Tue, 16 Feb 2021 04:48:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29446 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbhBPJru (ORCPT ); Tue, 16 Feb 2021 04:47:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468776; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ULZ9mxEQQ5U088rlkJrSxlHpglsfEQ5hn0PApjo9dE8=; b=U8lPKLEhsAvIy5Qo4aWfWBaf8DhJiGvwPG7c/kCPPtVzUL7lzJLuKp53REfBHlJWfzVF8g VvAKm76a3xCLWA/joCZUMw220oET3p2RXmTdLxVQGf7LJBNZVP+gJ+eIte/6YGVXK+y3sI FC+9o2CCDXIA46F2A3JrL8FrJER4EJc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-293-cX6kWrRxOIm8XKId-k-NiA-1; Tue, 16 Feb 2021 04:46:12 -0500 X-MC-Unique: cX6kWrRxOIm8XKId-k-NiA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1DB02801965; Tue, 16 Feb 2021 09:46:11 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id B745C5C6AB; Tue, 16 Feb 2021 09:46:09 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 09/10] vhost/vdpa: use get_config_size callback in vhost_vdpa_config_validate() Date: Tue, 16 Feb 2021 10:44:53 +0100 Message-Id: <20210216094454.82106-10-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's use the new 'get_config_size()' callback available instead of using the 'virtio_id' to get the size of the device config space. Signed-off-by: Stefano Garzarella --- drivers/vhost/vdpa.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 544f8582a42b..21eea2be5afa 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -188,13 +188,8 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp) static ssize_t vhost_vdpa_config_validate(struct vhost_vdpa *v, struct vhost_vdpa_config *c) { - u32 size = 0; - - switch (v->virtio_id) { - case VIRTIO_ID_NET: - size = sizeof(struct virtio_net_config); - break; - } + struct vdpa_device *vdpa = v->vdpa; + u32 size = vdpa->config->get_config_size(vdpa); if (c->len == 0) return -EINVAL; From patchwork Tue Feb 16 09:44:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 12089727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23FE1C433DB for ; Tue, 16 Feb 2021 09:49:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E98C764DCF for ; Tue, 16 Feb 2021 09:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230169AbhBPJtI (ORCPT ); Tue, 16 Feb 2021 04:49:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49663 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbhBPJru (ORCPT ); Tue, 16 Feb 2021 04:47:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613468776; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DqmUyCUnnwzMfzlfbC6vrvnV937tFThxMW/Rg8TVcvM=; b=Cz1gE34Ubg6zUA2ODCgpI4qgUdgWoCqE5N2yl5637S6YRDXKHaaDyqffyhpgjTZa8bRtKf dDxxRj1yI0eYVMcHF9hqQLuHrlQ04bKMa/1x1fZi4NE+xNl8nhE7yMXInrFqy3WiwlQfRT 5dxE9Zn619WxsnwxTHYVAOVhhOVGfeo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-EoGMOIL1PqOL3nSI57bJzQ-1; Tue, 16 Feb 2021 04:46:14 -0500 X-MC-Unique: EoGMOIL1PqOL3nSI57bJzQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDC2B18A08BD; Tue, 16 Feb 2021 09:46:12 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81BDA63747; Tue, 16 Feb 2021 09:46:11 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang Subject: [RFC PATCH 10/10] vhost/vdpa: return configuration bytes read and written to user space Date: Tue, 16 Feb 2021 10:44:54 +0100 Message-Id: <20210216094454.82106-11-sgarzare@redhat.com> In-Reply-To: <20210216094454.82106-1-sgarzare@redhat.com> References: <20210216094454.82106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org vdpa_get_config() and vdpa_set_config() now return the amount of bytes read and written, so let's return them to the user space. We also modify vhost_vdpa_config_validate() to return 0 (bytes read or written) instead of an error, when the buffer length is 0. Signed-off-by: Stefano Garzarella --- drivers/vhost/vdpa.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 21eea2be5afa..b754c53171a7 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -191,9 +191,6 @@ static ssize_t vhost_vdpa_config_validate(struct vhost_vdpa *v, struct vdpa_device *vdpa = v->vdpa; u32 size = vdpa->config->get_config_size(vdpa); - if (c->len == 0) - return -EINVAL; - return min(c->len, size); } @@ -204,6 +201,7 @@ static long vhost_vdpa_get_config(struct vhost_vdpa *v, struct vhost_vdpa_config config; unsigned long size = offsetof(struct vhost_vdpa_config, buf); ssize_t config_size; + long ret; u8 *buf; if (copy_from_user(&config, c, size)) @@ -217,15 +215,18 @@ static long vhost_vdpa_get_config(struct vhost_vdpa *v, if (!buf) return -ENOMEM; - vdpa_get_config(vdpa, config.off, buf, config_size); - - if (copy_to_user(c->buf, buf, config_size)) { - kvfree(buf); - return -EFAULT; + ret = vdpa_get_config(vdpa, config.off, buf, config_size); + if (ret < 0) { + ret = -EFAULT; + goto out; } + if (copy_to_user(c->buf, buf, config_size)) + ret = -EFAULT; + +out: kvfree(buf); - return 0; + return ret; } static long vhost_vdpa_set_config(struct vhost_vdpa *v, @@ -235,6 +236,7 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, struct vhost_vdpa_config config; unsigned long size = offsetof(struct vhost_vdpa_config, buf); ssize_t config_size; + long ret; u8 *buf; if (copy_from_user(&config, c, size)) @@ -248,10 +250,12 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, if (IS_ERR(buf)) return PTR_ERR(buf); - vdpa_set_config(vdpa, config.off, buf, config_size); + ret = vdpa_set_config(vdpa, config.off, buf, config_size); + if (ret < 0) + ret = -EFAULT; kvfree(buf); - return 0; + return ret; } static long vhost_vdpa_get_features(struct vhost_vdpa *v, u64 __user *featurep)