From nobody Sat Apr 11 05:44:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B8DBC7EE30 for ; Thu, 2 Mar 2023 11:35:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbjCBLfj (ORCPT ); Thu, 2 Mar 2023 06:35:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbjCBLfZ (ORCPT ); Thu, 2 Mar 2023 06:35:25 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F23D8199E1 for ; Thu, 2 Mar 2023 03:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zd9PLJS6vpKJ6CPmR9YHtESYhzkUvkwsWDxsXaqlwQ8=; b=KBPxhpEZ/FO1f2jdraRNtjAM4oXlKEWSC3qkaxMTzF7kXTUXp+a3WEs+v8R7BbU78Xd+iG xBzhuoAk3eU3W4ksdhs9KDiqIzekmxvaLOJpnZPF90MXrTwwB8aHC/OMa64QyhMlffI+xv s7JHfdWcK3NfP42WHzABqgl6tCT/bRA= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-226-Mc2WA9EfO2em5QzhmsZCrg-1; Thu, 02 Mar 2023 06:34:32 -0500 X-MC-Unique: Mc2WA9EfO2em5QzhmsZCrg-1 Received: by mail-qk1-f200.google.com with SMTP id dm13-20020a05620a1d4d00b00742a22c4239so7998870qkb.1 for ; Thu, 02 Mar 2023 03:34:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756871; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zd9PLJS6vpKJ6CPmR9YHtESYhzkUvkwsWDxsXaqlwQ8=; b=EX+/AYKnegEzkG2ezZMqO0wxExlTQw2Nj7m2bhDHSLsIXn36HUtJ6JhazEEh9ob3XZ 9CmFjp31Je7nhVIH/GVyzvjp0y4XcVUuzcqeIojau3qzBLoeDVR4fOOAq9dVHkU2KZ5n DJp0tvW5EqWtIp8Wwnyk350qcszA9bNNkylXoqGnk+2qrBgyeZU4YXxenAxdchVwbET4 TMt1ph+XcypoEj7a2jyWoUugUUfGcVOjYjXokH2KE8rpX1EzDSowUwg5SSh/iqz5OvNG jT262eR0UhWUxBQAHVmyduyKyj27QV/imSXEttOrjzdPtn28UZt+wG/IvubU/rgeO5oV notg== X-Gm-Message-State: AO0yUKWK5km27SxqUu8IPVjSz9HytrmxwJNzRKBEqv1m92Hw5NLsQK3e rxa8ZdDigtMbLJ0hS8MHsUuLVK4r/+qru1I9gfQ2K/IObEexUtW9+Q0qb0mS41Zu2uwLJgFf2kc VZFU+IqZXaJ1ybT8wdq8TJY3w X-Received: by 2002:a05:622a:14a:b0:3bf:d0b1:433d with SMTP id v10-20020a05622a014a00b003bfd0b1433dmr17172913qtw.60.1677756871625; Thu, 02 Mar 2023 03:34:31 -0800 (PST) X-Google-Smtp-Source: AK7set+LNHqJ8iSXkQnBxJNED/Dd+UhTVPKK7gC7ULHZoFWAiCyFuYmT1oYs5XX8i5qwnVYajblszQ== X-Received: by 2002:a05:622a:14a:b0:3bf:d0b1:433d with SMTP id v10-20020a05622a014a00b003bfd0b1433dmr17172896qtw.60.1677756871371; Thu, 02 Mar 2023 03:34:31 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id o12-20020ac8698c000000b003ba19e53e43sm10084156qtq.25.2023.03.02.03.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:34:30 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 1/8] vdpa: add bind_mm/unbind_mm callbacks Date: Thu, 2 Mar 2023 12:34:14 +0100 Message-Id: <20230302113421.174582-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" These new optional callbacks is used to bind/unbind the device to a specific address space so the vDPA framework can use VA when these callbacks are implemented. Suggested-by: Jason Wang Signed-off-by: Stefano Garzarella --- Notes: v2: - removed `struct task_struct *owner` param (unused for now, maybe useful to support cgroups) [Jason] - add unbind_mm callback [Jason] include/linux/vdpa.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 43f59ef10cc9..369c21394284 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -290,6 +290,14 @@ struct vdpa_map_file { * @vdev: vdpa device * @idx: virtqueue index * Returns pointer to structure device or error (NULL) + * @bind_mm: Bind the device to a specific address space + * so the vDPA framework can use VA when this + * callback is implemented. (optional) + * @vdev: vdpa device + * @mm: address space to bind + * @unbind_mm: Unbind the device from the address space + * bound using the bind_mm callback. (optional) + * @vdev: vdpa device * @free: Free resources that belongs to vDPA (optional) * @vdev: vdpa device */ @@ -351,6 +359,8 @@ struct vdpa_config_ops { int (*set_group_asid)(struct vdpa_device *vdev, unsigned int group, unsigned int asid); struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev, u16 idx); + int (*bind_mm)(struct vdpa_device *vdev, struct mm_struct *mm); + void (*unbind_mm)(struct vdpa_device *vdev); =20 /* Free device resources */ void (*free)(struct vdpa_device *vdev); --=20 2.39.2 From nobody Sat Apr 11 05:44:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14561C6FA8E for ; Thu, 2 Mar 2023 11:35:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbjCBLfo (ORCPT ); Thu, 2 Mar 2023 06:35:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbjCBLf1 (ORCPT ); Thu, 2 Mar 2023 06:35:27 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94E3E227AF for ; Thu, 2 Mar 2023 03:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iYIRvQhreJmamPTgF10vjkMAMOhZQaOaX6sUzVAfpfw=; b=hQManXAScAKWA8mgFefT9Uv+XU0ZH8HiL2J6k7qE72pVd/cT+KFy5MDd3ttUqAL4aNRLM9 OHLmtGUnwE8v1YrbAdkK4dILv8AvlxcTjr2i2Lqlgkl4+G0zR09KWgDTWH2OTyBoI+fcuL u+KYgUX7mWzqoyosTbdovsMBY49gLdQ= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-1EnjUKfBP8y_cjlR2BTFIQ-1; Thu, 02 Mar 2023 06:34:35 -0500 X-MC-Unique: 1EnjUKfBP8y_cjlR2BTFIQ-1 Received: by mail-qt1-f200.google.com with SMTP id o10-20020a05622a138a00b003bfdabf3b89so6594020qtk.13 for ; Thu, 02 Mar 2023 03:34:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iYIRvQhreJmamPTgF10vjkMAMOhZQaOaX6sUzVAfpfw=; b=6n6aUiJpk1ioK7488R2e83v0uX1TO6cQRukeI0IG3nrKxc3vXXf6XVqIYvFFRr742P QEhIhKxo0v5cTTD5CDnqTJz4H97vvhq0Df/XkxokGGDkZr4fmxWWUfvc+5Bf3mp2JNTu JEOFd2uNh2a5LCLYrDJ/EDC76gT4cXgC0RnkWet7dXdHIFCFdWJzj0rQaGfRg5VxZKrD ZoHKteAMCnjuVM4uJ3oPT0SUZ+YsQm8ELxABp9kEBQUXngn+zLPxBUjK2Kd6htk5nzgb F0Y1dzUlwFeBIkyKoAds2g+2RtDnGP2BgJTMCdwoRzk6clV8l68jihEJLC2kfzbVECw2 UbxQ== X-Gm-Message-State: AO0yUKVIoqZmkGBadCO86GAGPECDI20QVPKASOOqsnoHURymXeRgYKt+ 1SJPJJ6k8Wt2AunjNkmQUOaUB1eg7sppYlWUefqSfEvAK8CbXieOrdXZTr53zZViy05kckKG64F 9EHhH7Wal4IJJE4BRVmI6OZMa X-Received: by 2002:a05:622a:186:b0:3bf:d4c3:365d with SMTP id s6-20020a05622a018600b003bfd4c3365dmr17450754qtw.14.1677756875320; Thu, 02 Mar 2023 03:34:35 -0800 (PST) X-Google-Smtp-Source: AK7set+DEB84vy51k02CcK+JjytuJL+amad7fRxImnJYIv4nCRuUv0xkGiPSLgQZT6Jrlf+7iGe6iA== X-Received: by 2002:a05:622a:186:b0:3bf:d4c3:365d with SMTP id s6-20020a05622a018600b003bfd4c3365dmr17450741qtw.14.1677756875094; Thu, 02 Mar 2023 03:34:35 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id o12-20020ac8698c000000b003ba19e53e43sm10084156qtq.25.2023.03.02.03.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:34:34 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 2/8] vhost-vdpa: use bind_mm/unbind_mm device callbacks Date: Thu, 2 Mar 2023 12:34:15 +0100 Message-Id: <20230302113421.174582-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When the user call VHOST_SET_OWNER ioctl and the vDPA device has `use_va` set to true, let's call the bind_mm callback. In this way we can bind the device to the user address space and directly use the user VA. The unbind_mm callback is called during the release after stopping the device. Signed-off-by: Stefano Garzarella --- Notes: v2: - call the new unbind_mm callback during the release [Jason] - avoid to call bind_mm callback after the reset, since the device is not detaching it now during the reset drivers/vhost/vdpa.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index dc12dbd5b43b..1ab89fccd825 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -219,6 +219,28 @@ static int vhost_vdpa_reset(struct vhost_vdpa *v) return vdpa_reset(vdpa); } =20 +static long vhost_vdpa_bind_mm(struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa =3D v->vdpa; + const struct vdpa_config_ops *ops =3D vdpa->config; + + if (!vdpa->use_va || !ops->bind_mm) + return 0; + + return ops->bind_mm(vdpa, v->vdev.mm); +} + +static void vhost_vdpa_unbind_mm(struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa =3D v->vdpa; + const struct vdpa_config_ops *ops =3D vdpa->config; + + if (!vdpa->use_va || !ops->unbind_mm) + return; + + ops->unbind_mm(vdpa); +} + static long vhost_vdpa_get_device_id(struct vhost_vdpa *v, u8 __user *argp) { struct vdpa_device *vdpa =3D v->vdpa; @@ -711,6 +733,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *fil= ep, break; default: r =3D vhost_dev_ioctl(&v->vdev, cmd, argp); + if (!r && cmd =3D=3D VHOST_SET_OWNER) { + r =3D vhost_vdpa_bind_mm(v); + if (r) { + vhost_dev_reset_owner(&v->vdev, NULL); + break; + } + } if (r =3D=3D -ENOIOCTLCMD) r =3D vhost_vdpa_vring_ioctl(v, cmd, argp); break; @@ -1285,6 +1314,7 @@ static int vhost_vdpa_release(struct inode *inode, st= ruct file *filep) vhost_vdpa_clean_irq(v); vhost_vdpa_reset(v); vhost_dev_stop(&v->vdev); + vhost_vdpa_unbind_mm(v); vhost_vdpa_free_domain(v); vhost_vdpa_config_put(v); vhost_vdpa_cleanup(v); --=20 2.39.2 From nobody Sat Apr 11 05:44:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 884BDC6FA8E for ; Thu, 2 Mar 2023 11:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbjCBLfs (ORCPT ); Thu, 2 Mar 2023 06:35:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbjCBLfe (ORCPT ); Thu, 2 Mar 2023 06:35:34 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9509B1517F for ; Thu, 2 Mar 2023 03:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nMUvg2hEs0iMx2dm3/Jg9b5hv2Rlumo7TQ+47EWr+7I=; b=eqM4MKD4lbhRF16c0egtl+jxhsbdRBQsXRI4OHQkwG+VozXKm3UxGokgCw0Zq5uPLEPCfu NXl5vgLB/aDOCv+Zsp8zMHfkgbP7oZcEWgWf/q/o3GiDfb2GTqItxf4LidNxasFa+rhfYz 2ej4Im32XE4zOHKneIupZ+1GCn7w7rM= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-634-6luZiEUZPIePmsJYjtSOYg-1; Thu, 02 Mar 2023 06:34:39 -0500 X-MC-Unique: 6luZiEUZPIePmsJYjtSOYg-1 Received: by mail-qv1-f69.google.com with SMTP id y3-20020a0cec03000000b0056ee5b123bbso8740724qvo.7 for ; Thu, 02 Mar 2023 03:34:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756879; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nMUvg2hEs0iMx2dm3/Jg9b5hv2Rlumo7TQ+47EWr+7I=; b=Ulh+wiMhKXTnEjeOJLA/7uXFxjN8HBI+5E/aMRxir6f8kh9FgPchZy+AQw8htRF+WV +co6DCjbWvxpW+KP+QbTp6Jae7mFWHxG4yVstkVpA9trLJ5pOlZdOxScmn0ceLQ8cx85 nL20Mp07tqzyBVnr3DLgie4+MWhhQkmp9RdA6UxSYyFfYImeaNzOUcHJ84ixGyRhFRDM doiB6T8yC6uBIFHUuEFrMibW/Yzskzclu2HIPgsRfaBlwOnmf9yW1QsyD/rjqUoY+5dX jqFGAWOtjg7EkpD20UuHG8J52OU4RwulQpWHUJNMfaPoI+xJ6zS2B76P7NaQEujXzrDy k6Xw== X-Gm-Message-State: AO0yUKW3PejyuFnr4P57wWa4Exk01yf59/w58wFk386xA9VT9wfOVp0n wI/AelEh1KBCUlAOI3LAShk9HKDEnCVNfwVkKhHoCA1vHVmrJjLI+qRIA8oZ3LzKV2JXf9dZCld N6WDJgHyZVw/xDZviFsEIjRgX X-Received: by 2002:ac8:5850:0:b0:3bf:d6ad:5236 with SMTP id h16-20020ac85850000000b003bfd6ad5236mr15655317qth.32.1677756879136; Thu, 02 Mar 2023 03:34:39 -0800 (PST) X-Google-Smtp-Source: AK7set9TavRztcG0ZSYQlhYEtTPhNvB2VmTMeHABCwp3UyKfmeGcD6URaSgRaErRo454+a/9s5fAlA== X-Received: by 2002:ac8:5850:0:b0:3bf:d6ad:5236 with SMTP id h16-20020ac85850000000b003bfd6ad5236mr15655295qth.32.1677756878884; Thu, 02 Mar 2023 03:34:38 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id o12-20020ac8698c000000b003ba19e53e43sm10084156qtq.25.2023.03.02.03.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:34:38 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 3/8] vringh: replace kmap_atomic() with kmap_local_page() Date: Thu, 2 Mar 2023 12:34:16 +0100 Message-Id: <20230302113421.174582-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kmap_atomic() is deprecated in favor of kmap_local_page(). With kmap_local_page() the mappings are per thread, CPU local, can take page-faults, and can be called from any context (including interrupts). Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. kmap_atomic() is implemented like a kmap_local_page() which also disables page-faults and preemption (the latter only for !PREEMPT_RT kernels, otherwise it only disables migration). The code within the mappings/un-mappings in getu16_iotlb() and putu16_iotlb() don't depend on the above-mentioned side effects of kmap_atomic(), so that mere replacements of the old API with the new one is all that is required (i.e., there is no need to explicitly add calls to pagefault_disable() and/or preempt_disable()). Signed-off-by: Stefano Garzarella --- Notes: v2: - added this patch since checkpatch.pl complained about deprecation of kmap_atomic() touched by next patch drivers/vhost/vringh.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index a1e27da54481..0ba3ef809e48 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -1220,10 +1220,10 @@ static inline int getu16_iotlb(const struct vringh = *vrh, if (ret < 0) return ret; =20 - kaddr =3D kmap_atomic(iov.bv_page); + kaddr =3D kmap_local_page(iov.bv_page); from =3D kaddr + iov.bv_offset; *val =3D vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)from)); - kunmap_atomic(kaddr); + kunmap_local(kaddr); =20 return 0; } @@ -1241,10 +1241,10 @@ static inline int putu16_iotlb(const struct vringh = *vrh, if (ret < 0) return ret; =20 - kaddr =3D kmap_atomic(iov.bv_page); + kaddr =3D kmap_local_page(iov.bv_page); to =3D kaddr + iov.bv_offset; WRITE_ONCE(*(__virtio16 *)to, cpu_to_vringh16(vrh, val)); - kunmap_atomic(kaddr); + kunmap_local(kaddr); =20 return 0; } --=20 2.39.2 From nobody Sat Apr 11 05:44:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3D96C6FA8E for ; Thu, 2 Mar 2023 11:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbjCBLga (ORCPT ); Thu, 2 Mar 2023 06:36:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbjCBLgB (ORCPT ); Thu, 2 Mar 2023 06:36:01 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 702BA977C for ; Thu, 2 Mar 2023 03:35:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wr7wXnFCQpY1zpniPAgMpMPx/fjhLmfIKoC/NtXm0MU=; b=a5MJvr3wg9+1nqth+sk2jp4+vv1BAKm/j2EBHz7OTK42R6sygI+5yJzC3OgTjv5y2dI6Gv IXAl7J3CZXIAWWkq/cN0OO32CFOsQ60c3+aUMS4gQnH4KkC/tRtfJMD96znM6lqdtXPps+ EQQDo9oqZH+M8t89zJz+PKREW1urnqs= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-258-RwKLwvlAPMmFzQWt_QD1cQ-1; Thu, 02 Mar 2023 06:35:07 -0500 X-MC-Unique: RwKLwvlAPMmFzQWt_QD1cQ-1 Received: by mail-qv1-f70.google.com with SMTP id l13-20020ad44d0d000000b004c74bbb0affso8636417qvl.21 for ; Thu, 02 Mar 2023 03:35:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wr7wXnFCQpY1zpniPAgMpMPx/fjhLmfIKoC/NtXm0MU=; b=hrqzMJZJdzWOBNmRYR6NEqHUxfy3EwPEmqrkPmRkhlk5PWB20fua/KhSydXhJ82+KP tmhcHgeQuL8tqejFJInaPAlueI6EEqS2H7M+7OWiFaVd5XRW0T1ATSsbAExAF4gOCZoD o0js7X46+s6WOpeIBra9AO6orQIaSm6TvKG4IuttynADbSIlLG5TUeBxrVYMaCIiZvi3 50APeZrNW5io1bpFi+Zv/IlnEPzOEyWDG/4fDNEMRPQkGBVh1xqRrwE5ovTsVpBhDNJm J8VjjWdYDtvDoJhSYHQTlHojRjx9b/7IOQHNUpV/Uxop9zi/+f6btSHli+feR0tHfkEy dkiw== X-Gm-Message-State: AO0yUKWJzxiwfT69Q0YB1r06jvbs0G3KeRkFdC2hSlJF7kfJ1CqkehmY 6kcUs6nYGbeeAaKIoj9QYHPEMvU4YjOYwltigoK2Mf2Xww6X1Zr4oE8luE4lvZeMdGRjPLynL5y Cn/DnYbbYiYlitY3Y0uxSGibW X-Received: by 2002:a05:6214:20c1:b0:56e:a556:f28f with SMTP id 1-20020a05621420c100b0056ea556f28fmr18887338qve.34.1677756905280; Thu, 02 Mar 2023 03:35:05 -0800 (PST) X-Google-Smtp-Source: AK7set86Y3xWX8FFzNBNJULTR0DAk3t0Mhnai0hp6+YthKrk45BUDZ8jdC/DKPHKvqNQR5FHp9fcgw== X-Received: by 2002:a05:6214:20c1:b0:56e:a556:f28f with SMTP id 1-20020a05621420c100b0056ea556f28fmr18887295qve.34.1677756904884; Thu, 02 Mar 2023 03:35:04 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id p12-20020a37420c000000b007426ec97253sm8383058qka.111.2023.03.02.03.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:35:04 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 4/8] vringh: support VA with iotlb Date: Thu, 2 Mar 2023 12:34:17 +0100 Message-Id: <20230302113421.174582-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" vDPA supports the possibility to use user VA in the iotlb messages. So, let's add support for user VA in vringh to use it in the vDPA simulators. Signed-off-by: Stefano Garzarella Acked-by: Eugenio P=C3=A9rez Martin --- Notes: v2: - replace kmap_atomic() with kmap_local_page() [see previous patch] - fix cast warnings when build with W=3D1 C=3D1 include/linux/vringh.h | 5 +- drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 +- drivers/vhost/vringh.c | 247 ++++++++++++++++++++++++------ 4 files changed, 205 insertions(+), 53 deletions(-) diff --git a/include/linux/vringh.h b/include/linux/vringh.h index 1991a02c6431..d39b9f2dcba0 100644 --- a/include/linux/vringh.h +++ b/include/linux/vringh.h @@ -32,6 +32,9 @@ struct vringh { /* Can we get away with weak barriers? */ bool weak_barriers; =20 + /* Use user's VA */ + bool use_va; + /* Last available index we saw (ie. where we're up to). */ u16 last_avail_idx; =20 @@ -279,7 +282,7 @@ void vringh_set_iotlb(struct vringh *vrh, struct vhost_= iotlb *iotlb, spinlock_t *iotlb_lock); =20 int vringh_init_iotlb(struct vringh *vrh, u64 features, - unsigned int num, bool weak_barriers, + unsigned int num, bool weak_barriers, bool use_va, struct vring_desc *desc, struct vring_avail *avail, struct vring_used *used); diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5= _vnet.c index 3a0e721aef05..babc8dd171a6 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2537,7 +2537,7 @@ static int setup_cvq_vring(struct mlx5_vdpa_dev *mvde= v) =20 if (mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)) err =3D vringh_init_iotlb(&cvq->vring, mvdev->actual_features, - MLX5_CVQ_MAX_ENT, false, + MLX5_CVQ_MAX_ENT, false, false, (struct vring_desc *)(uintptr_t)cvq->desc_addr, (struct vring_avail *)(uintptr_t)cvq->driver_addr, (struct vring_used *)(uintptr_t)cvq->device_addr); diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index 6a0a65814626..481eb156658b 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -60,7 +60,7 @@ static void vdpasim_queue_ready(struct vdpasim *vdpasim, = unsigned int idx) struct vdpasim_virtqueue *vq =3D &vdpasim->vqs[idx]; uint16_t last_avail_idx =3D vq->vring.last_avail_idx; =20 - vringh_init_iotlb(&vq->vring, vdpasim->features, vq->num, true, + vringh_init_iotlb(&vq->vring, vdpasim->features, vq->num, true, false, (struct vring_desc *)(uintptr_t)vq->desc_addr, (struct vring_avail *) (uintptr_t)vq->driver_addr, @@ -81,7 +81,7 @@ static void vdpasim_vq_reset(struct vdpasim *vdpasim, vq->cb =3D NULL; vq->private =3D NULL; vringh_init_iotlb(&vq->vring, vdpasim->dev_attr.supported_features, - VDPASIM_QUEUE_MAX, false, NULL, NULL, NULL); + VDPASIM_QUEUE_MAX, false, false, NULL, NULL, NULL); =20 vq->vring.notify =3D NULL; } diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index 0ba3ef809e48..61c79cea44ca 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -1094,15 +1094,99 @@ EXPORT_SYMBOL(vringh_need_notify_kern); =20 #if IS_REACHABLE(CONFIG_VHOST_IOTLB) =20 -static int iotlb_translate(const struct vringh *vrh, - u64 addr, u64 len, u64 *translated, - struct bio_vec iov[], - int iov_size, u32 perm) +static int iotlb_translate_va(const struct vringh *vrh, + u64 addr, u64 len, u64 *translated, + struct iovec iov[], + int iov_size, u32 perm) { struct vhost_iotlb_map *map; struct vhost_iotlb *iotlb =3D vrh->iotlb; + u64 s =3D 0, last =3D addr + len - 1; int ret =3D 0; + + spin_lock(vrh->iotlb_lock); + + while (len > s) { + u64 size; + + if (unlikely(ret >=3D iov_size)) { + ret =3D -ENOBUFS; + break; + } + + map =3D vhost_iotlb_itree_first(iotlb, addr, last); + if (!map || map->start > addr) { + ret =3D -EINVAL; + break; + } else if (!(map->perm & perm)) { + ret =3D -EPERM; + break; + } + + size =3D map->size - addr + map->start; + iov[ret].iov_len =3D min(len - s, size); + iov[ret].iov_base =3D (void __user *)(unsigned long) + (map->addr + addr - map->start); + s +=3D size; + addr +=3D size; + ++ret; + } + + spin_unlock(vrh->iotlb_lock); + + if (translated) + *translated =3D min(len, s); + + return ret; +} + +static inline int copy_from_va(const struct vringh *vrh, void *dst, void *= src, + u64 len, u64 *translated) +{ + struct iovec iov[16]; + struct iov_iter iter; + int ret; + + ret =3D iotlb_translate_va(vrh, (u64)(uintptr_t)src, len, translated, iov, + ARRAY_SIZE(iov), VHOST_MAP_RO); + if (ret =3D=3D -ENOBUFS) + ret =3D ARRAY_SIZE(iov); + else if (ret < 0) + return ret; + + iov_iter_init(&iter, ITER_SOURCE, iov, ret, *translated); + + return copy_from_iter(dst, *translated, &iter); +} + +static inline int copy_to_va(const struct vringh *vrh, void *dst, void *sr= c, + u64 len, u64 *translated) +{ + struct iovec iov[16]; + struct iov_iter iter; + int ret; + + ret =3D iotlb_translate_va(vrh, (u64)(uintptr_t)dst, len, translated, iov, + ARRAY_SIZE(iov), VHOST_MAP_WO); + if (ret =3D=3D -ENOBUFS) + ret =3D ARRAY_SIZE(iov); + else if (ret < 0) + return ret; + + iov_iter_init(&iter, ITER_DEST, iov, ret, *translated); + + return copy_to_iter(src, *translated, &iter); +} + +static int iotlb_translate_pa(const struct vringh *vrh, + u64 addr, u64 len, u64 *translated, + struct bio_vec iov[], + int iov_size, u32 perm) +{ + struct vhost_iotlb_map *map; + struct vhost_iotlb *iotlb =3D vrh->iotlb; u64 s =3D 0, last =3D addr + len - 1; + int ret =3D 0; =20 spin_lock(vrh->iotlb_lock); =20 @@ -1141,28 +1225,61 @@ static int iotlb_translate(const struct vringh *vrh, return ret; } =20 +static inline int copy_from_pa(const struct vringh *vrh, void *dst, void *= src, + u64 len, u64 *translated) +{ + struct bio_vec iov[16]; + struct iov_iter iter; + int ret; + + ret =3D iotlb_translate_pa(vrh, (u64)(uintptr_t)src, len, translated, iov, + ARRAY_SIZE(iov), VHOST_MAP_RO); + if (ret =3D=3D -ENOBUFS) + ret =3D ARRAY_SIZE(iov); + else if (ret < 0) + return ret; + + iov_iter_bvec(&iter, ITER_SOURCE, iov, ret, *translated); + + return copy_from_iter(dst, *translated, &iter); +} + +static inline int copy_to_pa(const struct vringh *vrh, void *dst, void *sr= c, + u64 len, u64 *translated) +{ + struct bio_vec iov[16]; + struct iov_iter iter; + int ret; + + ret =3D iotlb_translate_pa(vrh, (u64)(uintptr_t)dst, len, translated, iov, + ARRAY_SIZE(iov), VHOST_MAP_WO); + if (ret =3D=3D -ENOBUFS) + ret =3D ARRAY_SIZE(iov); + else if (ret < 0) + return ret; + + iov_iter_bvec(&iter, ITER_DEST, iov, ret, *translated); + + return copy_to_iter(src, *translated, &iter); +} + static inline int copy_from_iotlb(const struct vringh *vrh, void *dst, void *src, size_t len) { u64 total_translated =3D 0; =20 while (total_translated < len) { - struct bio_vec iov[16]; - struct iov_iter iter; u64 translated; int ret; =20 - ret =3D iotlb_translate(vrh, (u64)(uintptr_t)src, - len - total_translated, &translated, - iov, ARRAY_SIZE(iov), VHOST_MAP_RO); - if (ret =3D=3D -ENOBUFS) - ret =3D ARRAY_SIZE(iov); - else if (ret < 0) - return ret; - - iov_iter_bvec(&iter, ITER_SOURCE, iov, ret, translated); + if (vrh->use_va) { + ret =3D copy_from_va(vrh, dst, src, + len - total_translated, &translated); + } else { + ret =3D copy_from_pa(vrh, dst, src, + len - total_translated, &translated); + } =20 - ret =3D copy_from_iter(dst, translated, &iter); if (ret < 0) return ret; =20 @@ -1180,22 +1297,17 @@ static inline int copy_to_iotlb(const struct vringh= *vrh, void *dst, u64 total_translated =3D 0; =20 while (total_translated < len) { - struct bio_vec iov[16]; - struct iov_iter iter; u64 translated; int ret; =20 - ret =3D iotlb_translate(vrh, (u64)(uintptr_t)dst, - len - total_translated, &translated, - iov, ARRAY_SIZE(iov), VHOST_MAP_WO); - if (ret =3D=3D -ENOBUFS) - ret =3D ARRAY_SIZE(iov); - else if (ret < 0) - return ret; - - iov_iter_bvec(&iter, ITER_DEST, iov, ret, translated); + if (vrh->use_va) { + ret =3D copy_to_va(vrh, dst, src, + len - total_translated, &translated); + } else { + ret =3D copy_to_pa(vrh, dst, src, + len - total_translated, &translated); + } =20 - ret =3D copy_to_iter(src, translated, &iter); if (ret < 0) return ret; =20 @@ -1210,20 +1322,37 @@ static inline int copy_to_iotlb(const struct vringh= *vrh, void *dst, static inline int getu16_iotlb(const struct vringh *vrh, u16 *val, const __virtio16 *p) { - struct bio_vec iov; - void *kaddr, *from; int ret; =20 /* Atomic read is needed for getu16 */ - ret =3D iotlb_translate(vrh, (u64)(uintptr_t)p, sizeof(*p), NULL, - &iov, 1, VHOST_MAP_RO); - if (ret < 0) - return ret; + if (vrh->use_va) { + struct iovec iov; + __virtio16 tmp; + + ret =3D iotlb_translate_va(vrh, (u64)(uintptr_t)p, sizeof(*p), + NULL, &iov, 1, VHOST_MAP_RO); + if (ret < 0) + return ret; =20 - kaddr =3D kmap_local_page(iov.bv_page); - from =3D kaddr + iov.bv_offset; - *val =3D vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)from)); - kunmap_local(kaddr); + ret =3D __get_user(tmp, (__virtio16 __user *)iov.iov_base); + if (ret) + return ret; + + *val =3D vringh16_to_cpu(vrh, tmp); + } else { + struct bio_vec iov; + void *kaddr, *from; + + ret =3D iotlb_translate_pa(vrh, (u64)(uintptr_t)p, sizeof(*p), + NULL, &iov, 1, VHOST_MAP_RO); + if (ret < 0) + return ret; + + kaddr =3D kmap_local_page(iov.bv_page); + from =3D kaddr + iov.bv_offset; + *val =3D vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)from)); + kunmap_local(kaddr); + } =20 return 0; } @@ -1231,20 +1360,37 @@ static inline int getu16_iotlb(const struct vringh = *vrh, static inline int putu16_iotlb(const struct vringh *vrh, __virtio16 *p, u16 val) { - struct bio_vec iov; - void *kaddr, *to; int ret; =20 /* Atomic write is needed for putu16 */ - ret =3D iotlb_translate(vrh, (u64)(uintptr_t)p, sizeof(*p), NULL, - &iov, 1, VHOST_MAP_WO); - if (ret < 0) - return ret; + if (vrh->use_va) { + struct iovec iov; + __virtio16 tmp; =20 - kaddr =3D kmap_local_page(iov.bv_page); - to =3D kaddr + iov.bv_offset; - WRITE_ONCE(*(__virtio16 *)to, cpu_to_vringh16(vrh, val)); - kunmap_local(kaddr); + ret =3D iotlb_translate_va(vrh, (u64)(uintptr_t)p, sizeof(*p), + NULL, &iov, 1, VHOST_MAP_RO); + if (ret < 0) + return ret; + + tmp =3D cpu_to_vringh16(vrh, val); + + ret =3D __put_user(tmp, (__virtio16 __user *)iov.iov_base); + if (ret) + return ret; + } else { + struct bio_vec iov; + void *kaddr, *to; + + ret =3D iotlb_translate_pa(vrh, (u64)(uintptr_t)p, sizeof(*p), NULL, + &iov, 1, VHOST_MAP_WO); + if (ret < 0) + return ret; + + kaddr =3D kmap_local_page(iov.bv_page); + to =3D kaddr + iov.bv_offset; + WRITE_ONCE(*(__virtio16 *)to, cpu_to_vringh16(vrh, val)); + kunmap_local(kaddr); + } =20 return 0; } @@ -1306,6 +1452,7 @@ static inline int putused_iotlb(const struct vringh *= vrh, * @features: the feature bits for this ring. * @num: the number of elements. * @weak_barriers: true if we only need memory barriers, not I/O. + * @use_va: true if IOTLB contains user VA * @desc: the userpace descriptor pointer. * @avail: the userpace avail pointer. * @used: the userpace used pointer. @@ -1313,11 +1460,13 @@ static inline int putused_iotlb(const struct vringh= *vrh, * Returns an error if num is invalid. */ int vringh_init_iotlb(struct vringh *vrh, u64 features, - unsigned int num, bool weak_barriers, + unsigned int num, bool weak_barriers, bool use_va, struct vring_desc *desc, struct vring_avail *avail, struct vring_used *used) { + vrh->use_va =3D use_va; + return vringh_init_kern(vrh, features, num, weak_barriers, desc, avail, used); } --=20 2.39.2 From nobody Sat Apr 11 05:44:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FF3EC7EE30 for ; Thu, 2 Mar 2023 11:36:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230104AbjCBLgk (ORCPT ); Thu, 2 Mar 2023 06:36:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbjCBLgE (ORCPT ); Thu, 2 Mar 2023 06:36:04 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E77917146 for ; Thu, 2 Mar 2023 03:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eLgIJ3s/Tx97mhsfweK6+28YKiuYY5rTS0gdVJoPPN4=; b=MUrPE4Q6uW1IREFaxtQU0JtXX4iD2sYmhQ51EZoClzBqE4ec9bN+n9XVXmSwo91ADoSRAw sqaGkLwZ/PgSKQZ5UfVt/rQbBds8N9rPWxzJDDqCix5465vLI8EJ8Hk7rZee7Vj0irDlY8 mjlhU8FkHdD8ioUXtrfD9UsDOcM66wk= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-467-wnJEaStbOJ2Sd_G8HyOxCA-1; Thu, 02 Mar 2023 06:35:09 -0500 X-MC-Unique: wnJEaStbOJ2Sd_G8HyOxCA-1 Received: by mail-qk1-f197.google.com with SMTP id eb13-20020a05620a480d00b00742be8a1a17so6496076qkb.18 for ; Thu, 02 Mar 2023 03:35:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eLgIJ3s/Tx97mhsfweK6+28YKiuYY5rTS0gdVJoPPN4=; b=acMXwvKgnjf6Fd/dk6eL9NQIPZPftOckq5Ay1e3BEbko5qMQwp1s/xJK50ZnHuDF2j U7d1YpH7+IgR8AKx/87voM5nT2vRnsHy8hav/LDsUawGRfxwkzY8PDH7ApmP3MQDyb6b 5dY4iPqH65bsxkZxZdZRmR9qIjUYlvzUCaazS+4GdcSIn8nmosCOzRy2h0tZ8Bzx+vgl m4TB5yRnHha5Db6AcI5ALqi11hzQuH6BmDMZw3ah9/fdXd24yJjoKGGtDeackiO0Hwvx WxeXgf0E35rzuIERDd/zHGWrLtBBgeRhqnDSMkDvttvh0K0zhO5z1JxUe4NQ1cXg3LKS a5Vw== X-Gm-Message-State: AO0yUKU6EBrLjzcpwWArpzHMWY8fw1TYsdf6YF13bIYYPfqyO/cEmb7Y 9uLrahqAkzIjtFi9ZCFskzRhZ9+GNufpuRNquDqQYFPCBuQxgtLAirmi2kQcnCRu/C+NBQYpDDz DezI4i9HP75Mwt1/Ls6kQqA0w X-Received: by 2002:a05:622a:1746:b0:3bf:dbd3:a014 with SMTP id l6-20020a05622a174600b003bfdbd3a014mr17136701qtk.45.1677756909325; Thu, 02 Mar 2023 03:35:09 -0800 (PST) X-Google-Smtp-Source: AK7set+7I55XBkFxw0bW+eUyOR6zvC72LFmtXSBxA9dpUftpeEGbZbGF/0NSpQjznVhJRmc2PwWsSA== X-Received: by 2002:a05:622a:1746:b0:3bf:dbd3:a014 with SMTP id l6-20020a05622a174600b003bfdbd3a014mr17136689qtk.45.1677756909086; Thu, 02 Mar 2023 03:35:09 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id p12-20020a37420c000000b007426ec97253sm8383058qka.111.2023.03.02.03.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:35:08 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 5/8] vdpa_sim: make devices agnostic for work management Date: Thu, 2 Mar 2023 12:34:18 +0100 Message-Id: <20230302113421.174582-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Let's move work management inside the vdpa_sim core. This way we can easily change how we manage the works, without having to change the devices each time. Signed-off-by: Stefano Garzarella Acked-by: Eugenio P=C3=A9rez Martin Acked-by: Jason Wang --- drivers/vdpa/vdpa_sim/vdpa_sim.h | 3 ++- drivers/vdpa/vdpa_sim/vdpa_sim.c | 17 +++++++++++++++-- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 6 ++---- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 6 ++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_= sim.h index 144858636c10..acee20faaf6a 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -45,7 +45,7 @@ struct vdpasim_dev_attr { u32 ngroups; u32 nas; =20 - work_func_t work_fn; + void (*work_fn)(struct vdpasim *vdpasim); void (*get_config)(struct vdpasim *vdpasim, void *config); void (*set_config)(struct vdpasim *vdpasim, const void *config); int (*get_stats)(struct vdpasim *vdpasim, u16 idx, @@ -78,6 +78,7 @@ struct vdpasim { =20 struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr, const struct vdpa_dev_set_config *config); +void vdpasim_schedule_work(struct vdpasim *vdpasim); =20 /* TODO: cross-endian support */ static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index 481eb156658b..a6ee830efc38 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -116,6 +116,13 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim) static const struct vdpa_config_ops vdpasim_config_ops; static const struct vdpa_config_ops vdpasim_batch_config_ops; =20 +static void vdpasim_work_fn(struct work_struct *work) +{ + struct vdpasim *vdpasim =3D container_of(work, struct vdpasim, work); + + vdpasim->dev_attr.work_fn(vdpasim); +} + struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr, const struct vdpa_dev_set_config *config) { @@ -152,7 +159,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr = *dev_attr, =20 vdpasim =3D vdpa_to_sim(vdpa); vdpasim->dev_attr =3D *dev_attr; - INIT_WORK(&vdpasim->work, dev_attr->work_fn); + INIT_WORK(&vdpasim->work, vdpasim_work_fn); spin_lock_init(&vdpasim->lock); spin_lock_init(&vdpasim->iommu_lock); =20 @@ -203,6 +210,12 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr= *dev_attr, } EXPORT_SYMBOL_GPL(vdpasim_create); =20 +void vdpasim_schedule_work(struct vdpasim *vdpasim) +{ + schedule_work(&vdpasim->work); +} +EXPORT_SYMBOL_GPL(vdpasim_schedule_work); + static int vdpasim_set_vq_address(struct vdpa_device *vdpa, u16 idx, u64 desc_area, u64 driver_area, u64 device_area) @@ -237,7 +250,7 @@ static void vdpasim_kick_vq(struct vdpa_device *vdpa, u= 16 idx) } =20 if (vq->ready) - schedule_work(&vdpasim->work); + vdpasim_schedule_work(vdpasim); } =20 static void vdpasim_set_vq_cb(struct vdpa_device *vdpa, u16 idx, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_blk.c index 5117959bed8a..eb4897c8541e 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -286,9 +285,8 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpa= sim, return handled; } =20 -static void vdpasim_blk_work(struct work_struct *work) +static void vdpasim_blk_work(struct vdpasim *vdpasim) { - struct vdpasim *vdpasim =3D container_of(work, struct vdpasim, work); bool reschedule =3D false; int i; =20 @@ -326,7 +324,7 @@ static void vdpasim_blk_work(struct work_struct *work) spin_unlock(&vdpasim->lock); =20 if (reschedule) - schedule_work(&vdpasim->work); + vdpasim_schedule_work(vdpasim); } =20 static void vdpasim_blk_get_config(struct vdpasim *vdpasim, void *config) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_net.c index 862f405362de..e61a9ecbfafe 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -192,9 +191,8 @@ static void vdpasim_handle_cvq(struct vdpasim *vdpasim) u64_stats_update_end(&net->cq_stats.syncp); } =20 -static void vdpasim_net_work(struct work_struct *work) +static void vdpasim_net_work(struct vdpasim *vdpasim) { - struct vdpasim *vdpasim =3D container_of(work, struct vdpasim, work); struct vdpasim_virtqueue *txq =3D &vdpasim->vqs[1]; struct vdpasim_virtqueue *rxq =3D &vdpasim->vqs[0]; struct vdpasim_net *net =3D sim_to_net(vdpasim); @@ -260,7 +258,7 @@ static void vdpasim_net_work(struct work_struct *work) vdpasim_net_complete(rxq, write); =20 if (tx_pkts > 4) { - schedule_work(&vdpasim->work); + vdpasim_schedule_work(vdpasim); goto out; } } --=20 2.39.2 From nobody Sat Apr 11 05:44:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 325BEC7EE33 for ; Thu, 2 Mar 2023 11:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjCBLgo (ORCPT ); Thu, 2 Mar 2023 06:36:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbjCBLgE (ORCPT ); Thu, 2 Mar 2023 06:36:04 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3C07136F2 for ; Thu, 2 Mar 2023 03:35:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=garxf7u2PYyPkA/AdwQgG8IfzxLSGUACcilXDazWE4o=; b=eYfmIggrFzs+QlJskU3P1wY5oLW8cnrT8NCG7jz8PNEMfCDXvtrKKLTBkqD5HXUNTdbB/N 1594+iYYehYrAJGWUffQ+yIXPAnIwgD3KkiRDPx9Ov6wIytgpWrkr8+TwIaPmwDi3O4RKq rUK1tysPzyQmgQR9189E3Y4G1g29Tvc= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-550-4ce3jHClP6C2VQ-cDkbndw-1; Thu, 02 Mar 2023 06:35:13 -0500 X-MC-Unique: 4ce3jHClP6C2VQ-cDkbndw-1 Received: by mail-qv1-f70.google.com with SMTP id pz4-20020ad45504000000b0056f060452adso8571212qvb.6 for ; Thu, 02 Mar 2023 03:35:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=garxf7u2PYyPkA/AdwQgG8IfzxLSGUACcilXDazWE4o=; b=lRq97CYN9pb7TXkjxK8SkfNF4u3cmd/YnNnm+0tYzmbQkNfplbXooLny4BRbYu99BF E49t1sbHSpgzv8xt4uRsdEcDClcsR0D9QW4/bnZnMUWmZUJTFq2bp9GLllG5OXmZv25f cxYdCUizCoRiVAbTvavB7Qrm3Y0g9xcGWbiifDQadNnvEUje9PM1NMRWSe31dqiNv7IC dl3zjiGcWc6SIEDtJ5N7sFAN6r+oTQKVVq2BvYRGbobKazC/Ti0c+R6GiPsfnkBPTqOF HgQAG+Co8I+z3MeOyRq19b3uAhG2szOgEDBXAc6y9iZA21VLepyO6weAX/G9NJs+8J/O ucvA== X-Gm-Message-State: AO0yUKVgm8e74Ndn4+RRg3A2zoV/EInImFVdGVGrxZ5uqNEYFGXMFBtq ssbj4Kf66z9qZxR7PrfncI6SlZzQbcsi0d/c1IQ3oXvu2zHsqAkx8e/949Ozlhl1xlxDaSBibmB pZBaOEBymYAVnwJiD2HxV86X54AVZww== X-Received: by 2002:a05:6214:ca2:b0:56e:a620:7b39 with SMTP id s2-20020a0562140ca200b0056ea6207b39mr2884830qvs.4.1677756913180; Thu, 02 Mar 2023 03:35:13 -0800 (PST) X-Google-Smtp-Source: AK7set+PZ/909SePXSEHKpmXpgvXRGxl6z5c0ldwKhD+c5TD8rRI1RDC5SJdB6Y2WkYalG0LWvNEBA== X-Received: by 2002:a05:6214:ca2:b0:56e:a620:7b39 with SMTP id s2-20020a0562140ca200b0056ea6207b39mr2884814qvs.4.1677756912950; Thu, 02 Mar 2023 03:35:12 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id p12-20020a37420c000000b007426ec97253sm8383058qka.111.2023.03.02.03.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:35:12 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 6/8] vdpa_sim: use kthread worker Date: Thu, 2 Mar 2023 12:34:19 +0100 Message-Id: <20230302113421.174582-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Let's use our own kthread to run device jobs. This allows us more flexibility, especially we can attach the kthread to the user address space when vDPA uses user's VA. Signed-off-by: Stefano Garzarella Acked-by: Jason Wang --- drivers/vdpa/vdpa_sim/vdpa_sim.h | 3 ++- drivers/vdpa/vdpa_sim/vdpa_sim.c | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_= sim.h index acee20faaf6a..ce83f9130a5d 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -57,7 +57,8 @@ struct vdpasim_dev_attr { struct vdpasim { struct vdpa_device vdpa; struct vdpasim_virtqueue *vqs; - struct work_struct work; + struct kthread_worker *worker; + struct kthread_work work; struct vdpasim_dev_attr dev_attr; /* spinlock to synchronize virtqueue state */ spinlock_t lock; diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index a6ee830efc38..6feb29726c2a 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -11,8 +11,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -116,7 +116,7 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim) static const struct vdpa_config_ops vdpasim_config_ops; static const struct vdpa_config_ops vdpasim_batch_config_ops; =20 -static void vdpasim_work_fn(struct work_struct *work) +static void vdpasim_work_fn(struct kthread_work *work) { struct vdpasim *vdpasim =3D container_of(work, struct vdpasim, work); =20 @@ -159,7 +159,13 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr= *dev_attr, =20 vdpasim =3D vdpa_to_sim(vdpa); vdpasim->dev_attr =3D *dev_attr; - INIT_WORK(&vdpasim->work, vdpasim_work_fn); + + kthread_init_work(&vdpasim->work, vdpasim_work_fn); + vdpasim->worker =3D kthread_create_worker(0, "vDPA sim worker: %s", + dev_attr->name); + if (IS_ERR(vdpasim->worker)) + goto err_iommu; + spin_lock_init(&vdpasim->lock); spin_lock_init(&vdpasim->iommu_lock); =20 @@ -212,7 +218,7 @@ EXPORT_SYMBOL_GPL(vdpasim_create); =20 void vdpasim_schedule_work(struct vdpasim *vdpasim) { - schedule_work(&vdpasim->work); + kthread_queue_work(vdpasim->worker, &vdpasim->work); } EXPORT_SYMBOL_GPL(vdpasim_schedule_work); =20 @@ -612,7 +618,8 @@ static void vdpasim_free(struct vdpa_device *vdpa) struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); int i; =20 - cancel_work_sync(&vdpasim->work); + kthread_cancel_work_sync(&vdpasim->work); + kthread_destroy_worker(vdpasim->worker); =20 for (i =3D 0; i < vdpasim->dev_attr.nvqs; i++) { vringh_kiov_cleanup(&vdpasim->vqs[i].out_iov); --=20 2.39.2 From nobody Sat Apr 11 05:44:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A8E7C7EE30 for ; Thu, 2 Mar 2023 11:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbjCBLgu (ORCPT ); Thu, 2 Mar 2023 06:36:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbjCBLgI (ORCPT ); Thu, 2 Mar 2023 06:36:08 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F4A71ABC8 for ; Thu, 2 Mar 2023 03:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gj3dXUcrOW7GQbHC3bzCmguoR9a2asK1vNem232OL7c=; b=LpHHUkYUuZjSnP377+4wqhPPWp9ul9x3fPMBvM1LzaZTktdtq5gLPJkTMnEiit1aenrVLY egBJXdD4OFIkfIpjyfkZw21dMaqMi4TBMZsbpSIBdAUkm2qqCDJ34Adi6wenQdnnimFJAN NNYpRihr1kb9ZoNJ/Ztj6cHqNOp5Ruc= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-642-Rg8IE5EVMd2D_b-msRISuA-1; Thu, 02 Mar 2023 06:35:17 -0500 X-MC-Unique: Rg8IE5EVMd2D_b-msRISuA-1 Received: by mail-qk1-f200.google.com with SMTP id pc36-20020a05620a842400b00742c715894bso6029316qkn.21 for ; Thu, 02 Mar 2023 03:35:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gj3dXUcrOW7GQbHC3bzCmguoR9a2asK1vNem232OL7c=; b=5iPvOTNev2sICXIheZ0sFmn71Q/8t/N8+MMXpRn4LygnOOcNTypaz5yEmjIBe/CB6Q yAfwrSHkRIpAC4gRP+LNQslOolggEsH94MdH8dSXSmc74Igg8PHY9cEW5ypImPEbmdse nIHNBm8xO1dTmj/EKOvAcIl/xnIT/uSiBKXQb9Tovd9PXgZpsMThkBs+K2rsqmyDXKU1 X7UBUUIEPCQqeeHQ81LOdAo5eCi0fl8rsYZdRoduwqbzg1prm96h/KjOpaYO/OG1U+nH Zm8tIr5e5Qu2sgv7mg9q+3cOkMvT6XU+T6qt/sSXXbgOK0mwhai1fGDThtvxhivBYkny tMCw== X-Gm-Message-State: AO0yUKVfDDcoafKXyLM1P2fkmnLPiypVcuXQvCpCXkmx8P1z27rZF5+n VCA/5d35W3grkeWcJ/uXrkhfEZl7jq9bnlfxBrPLflDvWFHgJV2Jx/grP2h9p6Hh0H62+MPyDDm viF1Wt/KRb2m2SFk25y00A0lt X-Received: by 2002:ac8:594f:0:b0:3a7:e9a2:4f4a with SMTP id 15-20020ac8594f000000b003a7e9a24f4amr16171736qtz.8.1677756916955; Thu, 02 Mar 2023 03:35:16 -0800 (PST) X-Google-Smtp-Source: AK7set9qGmJaKuL+3K0McFJot1ZlCw7XvULWgrVcRPD18Yd6j00eYkZLuQoDKp7LYfL8P/tkphEXgw== X-Received: by 2002:ac8:594f:0:b0:3a7:e9a2:4f4a with SMTP id 15-20020ac8594f000000b003a7e9a24f4amr16171717qtz.8.1677756916710; Thu, 02 Mar 2023 03:35:16 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id p12-20020a37420c000000b007426ec97253sm8383058qka.111.2023.03.02.03.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:35:16 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 7/8] vdpa_sim: replace the spinlock with a mutex to protect the state Date: Thu, 2 Mar 2023 12:34:20 +0100 Message-Id: <20230302113421.174582-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The spinlock we use to protect the state of the simulator is sometimes held for a long time (for example, when devices handle requests). This also prevents us from calling functions that might sleep (such as kthread_flush_work() in the next patch), and thus having to release and retake the lock. For these reasons, let's replace the spinlock with a mutex that gives us more flexibility. Suggested-by: Jason Wang Signed-off-by: Stefano Garzarella Acked-by: Jason Wang --- drivers/vdpa/vdpa_sim/vdpa_sim.h | 4 ++-- drivers/vdpa/vdpa_sim/vdpa_sim.c | 34 ++++++++++++++-------------- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 4 ++-- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 4 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_= sim.h index ce83f9130a5d..4774292fba8c 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -60,8 +60,8 @@ struct vdpasim { struct kthread_worker *worker; struct kthread_work work; struct vdpasim_dev_attr dev_attr; - /* spinlock to synchronize virtqueue state */ - spinlock_t lock; + /* mutex to synchronize virtqueue state */ + struct mutex mutex; /* virtio config according to device type */ void *config; struct vhost_iotlb *iommu; diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index 6feb29726c2a..a28103a67ae7 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -166,7 +166,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr = *dev_attr, if (IS_ERR(vdpasim->worker)) goto err_iommu; =20 - spin_lock_init(&vdpasim->lock); + mutex_init(&vdpasim->mutex); spin_lock_init(&vdpasim->iommu_lock); =20 dev =3D &vdpasim->vdpa.dev; @@ -275,13 +275,13 @@ static void vdpasim_set_vq_ready(struct vdpa_device *= vdpa, u16 idx, bool ready) struct vdpasim_virtqueue *vq =3D &vdpasim->vqs[idx]; bool old_ready; =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); old_ready =3D vq->ready; vq->ready =3D ready; if (vq->ready && !old_ready) { vdpasim_queue_ready(vdpasim, idx); } - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); } =20 static bool vdpasim_get_vq_ready(struct vdpa_device *vdpa, u16 idx) @@ -299,9 +299,9 @@ static int vdpasim_set_vq_state(struct vdpa_device *vdp= a, u16 idx, struct vdpasim_virtqueue *vq =3D &vdpasim->vqs[idx]; struct vringh *vrh =3D &vq->vring; =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); vrh->last_avail_idx =3D state->split.avail_index; - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); =20 return 0; } @@ -398,9 +398,9 @@ static u8 vdpasim_get_status(struct vdpa_device *vdpa) struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); u8 status; =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); status =3D vdpasim->status; - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); =20 return status; } @@ -409,19 +409,19 @@ static void vdpasim_set_status(struct vdpa_device *vd= pa, u8 status) { struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); vdpasim->status =3D status; - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); } =20 static int vdpasim_reset(struct vdpa_device *vdpa) { struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); vdpasim->status =3D 0; vdpasim_do_reset(vdpasim); - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); =20 return 0; } @@ -430,9 +430,9 @@ static int vdpasim_suspend(struct vdpa_device *vdpa) { struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); vdpasim->running =3D false; - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); =20 return 0; } @@ -442,7 +442,7 @@ static int vdpasim_resume(struct vdpa_device *vdpa) struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); int i; =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); vdpasim->running =3D true; =20 if (vdpasim->pending_kick) { @@ -453,7 +453,7 @@ static int vdpasim_resume(struct vdpa_device *vdpa) vdpasim->pending_kick =3D false; } =20 - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); =20 return 0; } @@ -525,14 +525,14 @@ static int vdpasim_set_group_asid(struct vdpa_device = *vdpa, unsigned int group, =20 iommu =3D &vdpasim->iommu[asid]; =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); =20 for (i =3D 0; i < vdpasim->dev_attr.nvqs; i++) if (vdpasim_get_vq_group(vdpa, i) =3D=3D group) vringh_set_iotlb(&vdpasim->vqs[i].vring, iommu, &vdpasim->iommu_lock); =20 - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); =20 return 0; } diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_blk.c index eb4897c8541e..568119e1553f 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -290,7 +290,7 @@ static void vdpasim_blk_work(struct vdpasim *vdpasim) bool reschedule =3D false; int i; =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); =20 if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) goto out; @@ -321,7 +321,7 @@ static void vdpasim_blk_work(struct vdpasim *vdpasim) } } out: - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); =20 if (reschedule) vdpasim_schedule_work(vdpasim); diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_net.c index e61a9ecbfafe..7ab434592bfe 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -201,7 +201,7 @@ static void vdpasim_net_work(struct vdpasim *vdpasim) u64 rx_drops =3D 0, rx_overruns =3D 0, rx_errors =3D 0, tx_errors =3D 0; int err; =20 - spin_lock(&vdpasim->lock); + mutex_lock(&vdpasim->mutex); =20 if (!vdpasim->running) goto out; @@ -264,7 +264,7 @@ static void vdpasim_net_work(struct vdpasim *vdpasim) } =20 out: - spin_unlock(&vdpasim->lock); + mutex_unlock(&vdpasim->mutex); =20 u64_stats_update_begin(&net->tx_stats.syncp); net->tx_stats.pkts +=3D tx_pkts; --=20 2.39.2 From nobody Sat Apr 11 05:44:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8F36C678D4 for ; Thu, 2 Mar 2023 11:37:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbjCBLh0 (ORCPT ); Thu, 2 Mar 2023 06:37:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbjCBLhI (ORCPT ); Thu, 2 Mar 2023 06:37:08 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EA33474D9 for ; Thu, 2 Mar 2023 03:35:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ei7n2l78e4NFmvUi+bOVTMUuSnDAXEzTgyerL27l10=; b=SiKWFQEsjux9pg7VcflKRjwXsMx2t4MEgSQjLUbocfexN4n7yUTyFIwasVmDxJk7tWjTSE vfsCID+KZCOf3eTyu0KKix0o1V3uCBb+3jEAvXLriy85RpzoTFSyVpP39qdFtbcuA+uTE1 Opol4lLm/zofmnMhSnlIl8IFoZBfo68= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-74-ufYSVbWwPNOQgmGCMqmw5g-1; Thu, 02 Mar 2023 06:35:45 -0500 X-MC-Unique: ufYSVbWwPNOQgmGCMqmw5g-1 Received: by mail-qt1-f197.google.com with SMTP id w16-20020ac843d0000000b003bfe50a4105so5301830qtn.10 for ; Thu, 02 Mar 2023 03:35:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756944; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8ei7n2l78e4NFmvUi+bOVTMUuSnDAXEzTgyerL27l10=; b=iVc2oSCiFGdxzp5ikjbbVOoD7glF4yPxosIV82bvo9OQI3Fk1efF4CU0sgrgmDZhy6 EwgEMhnM6U4lacNRHIFH6Ai+36MnChTQEtbcNYi2KfcukEIgMm6jD+FoKv8P0TPoI3pj J2gtqC58u5qYkCJe4xg3lQcItvmrnqXN9L/JBFQoFqbgrCKLPIxfFE6Qzqvk6J1joD61 dj/X6YzTugsX7mGAj3Cn0wals4u83ciuQxFbCPF9BBtACaay7ZbGKi2ef3HdSX9NS7mf LtXXprh44OSzBelEou0MvGkitKfAEdLzdZFcwPqZ5ShxL7NMSqGg6/7N4AknHmrkalmp 72oA== X-Gm-Message-State: AO0yUKU2u0V4tA3RQlP0DFRr43NLP2E5kyukSDB83s8cveYKI0T0kb/a T1PKEs+1Dm89SiDWpwQPmwmpc5w6RlqXhgyaQMajNwMCEUwt/TBun64AKYPwixWNmOG17mfmLbV x3iTsh5c9lrpqdgVzK0CJp3vU X-Received: by 2002:a05:6214:23cc:b0:56f:796e:c3a5 with SMTP id hr12-20020a05621423cc00b0056f796ec3a5mr15695877qvb.4.1677756944514; Thu, 02 Mar 2023 03:35:44 -0800 (PST) X-Google-Smtp-Source: AK7set8Ak8Ucf6C6K7kn5+/O12tTcTPMHjMyg5Hg/gChXMJzzgv24g/Sgnux1N4dFSCrO8nMsW3JDg== X-Received: by 2002:a05:6214:23cc:b0:56f:796e:c3a5 with SMTP id hr12-20020a05621423cc00b0056f796ec3a5mr15695849qvb.4.1677756944236; Thu, 02 Mar 2023 03:35:44 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id m26-20020ae9e01a000000b00741d87eb5d1sm10630925qkk.105.2023.03.02.03.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:35:43 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 8/8] vdpa_sim: add support for user VA Date: Thu, 2 Mar 2023 12:34:21 +0100 Message-Id: <20230302113421.174582-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The new "use_va" module parameter (default: false) is used in vdpa_alloc_device() to inform the vDPA framework that the device supports VA. vringh is initialized to use VA only when "use_va" is true and the user's mm has been bound. So, only when the bus supports user VA (e.g. vhost-vdpa). vdpasim_mm_work_fn work is used to attach the kthread to the user address space when the .bind_mm callback is invoked, and to detach it when the .unbind_mm callback is invoked. Signed-off-by: Stefano Garzarella --- Notes: v2: - `use_va` set to true by default [Eugenio] - supported the new unbind_mm callback [Jason] - removed the unbind_mm call in vdpasim_do_reset() [Jason] - avoided to release the lock while call kthread_flush_work() since we are now using a mutex to protect the device state drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 + drivers/vdpa/vdpa_sim/vdpa_sim.c | 98 +++++++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_= sim.h index 4774292fba8c..3a42887d05d9 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -59,6 +59,7 @@ struct vdpasim { struct vdpasim_virtqueue *vqs; struct kthread_worker *worker; struct kthread_work work; + struct mm_struct *mm_bound; struct vdpasim_dev_attr dev_attr; /* mutex to synchronize virtqueue state */ struct mutex mutex; diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index a28103a67ae7..eda26bc33df5 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -35,10 +35,77 @@ module_param(max_iotlb_entries, int, 0444); MODULE_PARM_DESC(max_iotlb_entries, "Maximum number of iotlb entries for each address space. 0 means unlimi= ted. (default: 2048)"); =20 +static bool use_va =3D true; +module_param(use_va, bool, 0444); +MODULE_PARM_DESC(use_va, "Enable/disable the device's ability to use VA"); + #define VDPASIM_QUEUE_ALIGN PAGE_SIZE #define VDPASIM_QUEUE_MAX 256 #define VDPASIM_VENDOR_ID 0 =20 +struct vdpasim_mm_work { + struct kthread_work work; + struct mm_struct *mm; + bool bind; + int ret; +}; + +static void vdpasim_mm_work_fn(struct kthread_work *work) +{ + struct vdpasim_mm_work *mm_work =3D + container_of(work, struct vdpasim_mm_work, work); + + mm_work->ret =3D 0; + + if (mm_work->bind) { + kthread_use_mm(mm_work->mm); + //TODO: should we attach the cgroup of the mm owner? + } else { + kthread_unuse_mm(mm_work->mm); + } +} + +static void vdpasim_worker_queue_mm(struct vdpasim *vdpasim, + struct vdpasim_mm_work *mm_work) +{ + struct kthread_work *work =3D &mm_work->work; + + kthread_init_work(work, vdpasim_mm_work_fn); + kthread_queue_work(vdpasim->worker, work); + + kthread_flush_work(work); +} + +static int vdpasim_worker_bind_mm(struct vdpasim *vdpasim, + struct mm_struct *new_mm) +{ + struct vdpasim_mm_work mm_work; + + mm_work.mm =3D new_mm; + mm_work.bind =3D true; + + vdpasim_worker_queue_mm(vdpasim, &mm_work); + + if (!mm_work.ret) + vdpasim->mm_bound =3D new_mm; + + return mm_work.ret; +} + +static void vdpasim_worker_unbind_mm(struct vdpasim *vdpasim) +{ + struct vdpasim_mm_work mm_work; + + if (!vdpasim->mm_bound) + return; + + mm_work.mm =3D vdpasim->mm_bound; + mm_work.bind =3D false; + + vdpasim_worker_queue_mm(vdpasim, &mm_work); + + vdpasim->mm_bound =3D NULL; +} static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa) { return container_of(vdpa, struct vdpasim, vdpa); @@ -59,8 +126,10 @@ static void vdpasim_queue_ready(struct vdpasim *vdpasim= , unsigned int idx) { struct vdpasim_virtqueue *vq =3D &vdpasim->vqs[idx]; uint16_t last_avail_idx =3D vq->vring.last_avail_idx; + bool va_enabled =3D use_va && vdpasim->mm_bound; =20 - vringh_init_iotlb(&vq->vring, vdpasim->features, vq->num, true, false, + vringh_init_iotlb(&vq->vring, vdpasim->features, vq->num, true, + va_enabled, (struct vring_desc *)(uintptr_t)vq->desc_addr, (struct vring_avail *) (uintptr_t)vq->driver_addr, @@ -151,7 +220,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr = *dev_attr, vdpa =3D __vdpa_alloc_device(NULL, ops, dev_attr->ngroups, dev_attr->nas, dev_attr->alloc_size, - dev_attr->name, false); + dev_attr->name, use_va); if (IS_ERR(vdpa)) { ret =3D PTR_ERR(vdpa); goto err_alloc; @@ -571,6 +640,27 @@ static int vdpasim_set_map(struct vdpa_device *vdpa, u= nsigned int asid, return ret; } =20 +static int vdpasim_bind_mm(struct vdpa_device *vdpa, struct mm_struct *mm) +{ + struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); + int ret; + + mutex_lock(&vdpasim->mutex); + ret =3D vdpasim_worker_bind_mm(vdpasim, mm); + mutex_unlock(&vdpasim->mutex); + + return ret; +} + +static void vdpasim_unbind_mm(struct vdpa_device *vdpa) +{ + struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); + + mutex_lock(&vdpasim->mutex); + vdpasim_worker_unbind_mm(vdpasim); + mutex_unlock(&vdpasim->mutex); +} + static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid, u64 iova, u64 size, u64 pa, u32 perm, void *opaque) @@ -667,6 +757,8 @@ static const struct vdpa_config_ops vdpasim_config_ops = =3D { .set_group_asid =3D vdpasim_set_group_asid, .dma_map =3D vdpasim_dma_map, .dma_unmap =3D vdpasim_dma_unmap, + .bind_mm =3D vdpasim_bind_mm, + .unbind_mm =3D vdpasim_unbind_mm, .free =3D vdpasim_free, }; =20 @@ -701,6 +793,8 @@ static const struct vdpa_config_ops vdpasim_batch_confi= g_ops =3D { .get_iova_range =3D vdpasim_get_iova_range, .set_group_asid =3D vdpasim_set_group_asid, .set_map =3D vdpasim_set_map, + .bind_mm =3D vdpasim_bind_mm, + .unbind_mm =3D vdpasim_unbind_mm, .free =3D vdpasim_free, }; =20 --=20 2.39.2