Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1286291ybt; Thu, 2 Jul 2020 01:24:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTqM20qkOY+T635VgNuyqv5rQPSmfS1bukbReee5d6iC8sHa3qr5tIHqiJKV9/WUDTreGv X-Received: by 2002:aa7:d744:: with SMTP id a4mr33176510eds.94.1593678261666; Thu, 02 Jul 2020 01:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593678261; cv=none; d=google.com; s=arc-20160816; b=N1CpdA+zO9LuBUKkDGi0ickMNrNkYdOurQef4vW4Kdq9OGJfjP3YbQTrmvKgHU7stI 1qKWrDkJSyA+XQPZBKGehm3ljC9KgMijqi9ebktrJz/VhSo5atDIorOpXUo1nPo8UIyE F2FP250grNxdaeSxahs5svj/71TaXe6sJrOALRqjqgOVPZV5ZfOkywVAvOU1gb2yGN9N iwkZDYsvDl8MISh1GeyLybjIdyUCouuQUIuUlHqCbV+z5d86LQZvHVefJWz5KVPTItLC LiGG3pUgBxvTIRUFJFz7mNNFXZkDQPRAH0PZ0hSQuPX+i0dWnVedjzOAJDWvluPDBn26 ucNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=JPB+vJhEmEbr7wwXfNji0ZXjBCp2o1x06a2a2R9o46s=; b=yA+5MIi2AZpsvh4+csNL81UgMR9J4zH7fi7TXqPpDbXknNXuzfPVjYVSLyXdb1i/E5 raFDwPu3Kd1z/zUHJ3SNjSJNPS4TcKEbW+2UoPQpvjgA/F+Ivx9ZOfUTZmIAnfnfHrhf Jr1qn7X2FtRJJ2Ffp9ucZC8J7v7PhSk7cSq+wYK1Qf2Nq6/6ejLrkjsF24Ty5nDzz7F5 b4SyuGN03Elj0XvojBafMG87uZv0HtgqEEZYkj3MaVcu8tN/Z9InxUUOx0+FE6vXSFjL ++eTCQdDCFcL7xIOtq1HGxW0h9qLBur9g646ZcQA5EIYpEt8GA13AWXgvaSDCorANUrL Klxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=NTB4WUvW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si5362627edh.256.2020.07.02.01.23.58; Thu, 02 Jul 2020 01:24:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=NTB4WUvW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728570AbgGBIXL (ORCPT + 99 others); Thu, 2 Jul 2020 04:23:11 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:55304 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728550AbgGBIXJ (ORCPT ); Thu, 2 Jul 2020 04:23:09 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0628MwtA042318; Thu, 2 Jul 2020 03:22:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1593678178; bh=JPB+vJhEmEbr7wwXfNji0ZXjBCp2o1x06a2a2R9o46s=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=NTB4WUvWIwRjwR4PEyvNndWbHFmbpB3bHQ/bjfZA4D488oQ/PPwZMpG8QVgVEECfl GirS8Zv5wtU6kWNfh8qRzOwRe3jDX36NKWLH6IAzNFElVyTE8WUhGN+Gh+6mDie4th ehSVLDopPkGuaZZq1dslHla/kif2QjPpAYyNCWHw= Received: from DFLE110.ent.ti.com (dfle110.ent.ti.com [10.64.6.31]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0628Mw7t031199 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 2 Jul 2020 03:22:58 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Thu, 2 Jul 2020 03:22:58 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Thu, 2 Jul 2020 03:22:58 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0628LiYO006145; Thu, 2 Jul 2020 03:22:53 -0500 From: Kishon Vijay Abraham I To: Ohad Ben-Cohen , Bjorn Andersson , Jon Mason , Dave Jiang , Allen Hubbe , Lorenzo Pieralisi , Bjorn Helgaas , "Michael S. Tsirkin" , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , Stefano Garzarella CC: , , , , , , , Subject: [RFC PATCH 12/22] virtio: Add ops to allocate and free buffer Date: Thu, 2 Jul 2020 13:51:33 +0530 Message-ID: <20200702082143.25259-13-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200702082143.25259-1-kishon@ti.com> References: <20200702082143.25259-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add ops to allocate and free buffer in struct virtio_config_ops. Certain vhost devices can have restriction on the range of memory it can access on the virtio. The virtio drivers attached to such vhost devices reserves memory that can be accessed by vhost. This function allocates buffer for such reserved region. For instance when virtio-vhost is used by two hosts connected to NTB, the vhost can access only memory exposed by memory windows and the size of the memory window can be limited. Here the NTB virtio driver can reserve a small region (few MBs) and provide buffer address from this pool whenever requested by virtio client driver. Signed-off-by: Kishon Vijay Abraham I --- include/linux/virtio_config.h | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index bb4cc4910750..419f733017c2 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -65,6 +65,9 @@ struct irq_affinity; * the caller can then copy. * @set_vq_affinity: set the affinity for a virtqueue (optional). * @get_vq_affinity: get the affinity for a virtqueue (optional). + * @alloc_buffer: Allocate and provide buffer addresses that can be + * accessed by both virtio and vhost + * @free_buffer: Free the allocated buffer address */ typedef void vq_callback_t(struct virtqueue *); struct virtio_config_ops { @@ -88,6 +91,9 @@ struct virtio_config_ops { const struct cpumask *cpu_mask); const struct cpumask *(*get_vq_affinity)(struct virtio_device *vdev, int index); + void * (*alloc_buffer)(struct virtio_device *vdev, size_t size); + void (*free_buffer)(struct virtio_device *vdev, void *addr, + size_t size); }; /* If driver didn't advertise the feature, it will never appear. */ @@ -232,6 +238,42 @@ const char *virtio_bus_name(struct virtio_device *vdev) return vdev->config->bus_name(vdev); } +/** + * virtio_alloc_buffer - Allocate buffer from the reserved memory + * @vdev: Virtio device which manages the reserved memory + * @size: Size of the buffer to be allocated + * + * Certain vhost devices can have restriction on the range of memory + * it can access on the virtio. The virtio drivers attached to + * such vhost devices reserves memory that can be accessed by + * vhost. This function allocates buffer for such reserved region. + */ +static inline void * +virtio_alloc_buffer(struct virtio_device *vdev, size_t size) +{ + if (!vdev->config->alloc_buffer) + return NULL; + + return vdev->config->alloc_buffer(vdev, size); +} + +/** + * virtio_free_buffer - Free the allocated buffer + * @vdev: Virtio device which manages the reserved memory + * @addr: Address returned by virtio_alloc_buffer() + * @size: Size of the buffer that has to be freed + * + * Free the allocated buffer address given by virtio_alloc_buffer(). + */ +static inline void +virtio_free_buffer(struct virtio_device *vdev, void *addr, size_t size) +{ + if (!vdev->config->free_buffer) + return; + + return vdev->config->free_buffer(vdev, addr, size); +} + /** * virtqueue_set_affinity - setting affinity for a virtqueue * @vq: the virtqueue -- 2.17.1