Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1294312rwl; Fri, 24 Mar 2023 08:40:21 -0700 (PDT) X-Google-Smtp-Source: AKy350Z7b4yqX5ia95PinK2N1IpLVppM1KV6P8EdIH+nK7+BYtLco/0p7JnAKxP5W45RgSUaB5ww X-Received: by 2002:a17:906:578c:b0:88f:a236:69e6 with SMTP id k12-20020a170906578c00b0088fa23669e6mr3296172ejq.7.1679672421598; Fri, 24 Mar 2023 08:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679672421; cv=none; d=google.com; s=arc-20160816; b=G5f+avhfhcbHSD23AODkIW1JTQJDxp4qFYLQ4C7SdQrhTsquzX7AInkF6zjVUeKzvB br3ivDpSHBl870yWuTUMvjShC7N+gQN/UfiniqAbq36+JaKa8vXiGBt/9cmWNot13gd7 l67cT38Z5TAgnGBvVXUiwJm83Sb7Ak4R5ZLFoJelhX+ldT5Q/fVjZVlMAKwAAQ0lIhjv YoQE+dD8ydR2d4tSJskN/K7F91b28YteN2g+jvEHKy9fCovPf0BZbzeNWvzZxtcAkd+V A9J2pq+eUZjhPWrCyAAsqiGXa7/6+BHpnJlo2t/c8yeRDfKMf2ni92CaFdO4fS5lqZRr QlQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4MlJ8boSBAN33TyWlK9MdNtuYbz66i2Pl/D7dBKo3iE=; b=MqtQnh304pzcXhQUJ5PieebK+ypK8siCQxKrjSZRVRwyKqOQkc6Fu1upPceHuvMPZV FmOGaJ2tXi8fh35Tgf2mW4+1JmqDXTH5Rr8SmaidJNnXP9CM9TT41r03GUVFuiroqUfu 0zbszWNB0fYFuFNKFyrwyqWOBBNv5eRE/enqaVkLs1+PYFOnI+od4dc7o1cx3WhRUmu4 MLuM81ogvzNW7uDU9/XGkNDSGYSMxqDuzBMtGNnwoQBicsCVRcig9ypGHbdMxRzPtXXc dtOC26Ef1HwQtu828nK13TVNSGMzSB5PlxSGYdOFWLyoPwk+eRv8iivhJtm2EVqKYARj ht7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cUboR778; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr12-20020a1709073f8c00b009333f8775a1si21379732ejc.182.2023.03.24.08.39.57; Fri, 24 Mar 2023 08:40:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cUboR778; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232331AbjCXPhr (ORCPT + 99 others); Fri, 24 Mar 2023 11:37:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231937AbjCXPhk (ORCPT ); Fri, 24 Mar 2023 11:37:40 -0400 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 8FD0D20A3F for ; Fri, 24 Mar 2023 08:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679672184; 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=4MlJ8boSBAN33TyWlK9MdNtuYbz66i2Pl/D7dBKo3iE=; b=cUboR778KpKd1GmvNtCHbLGJpDevVFxJ3Ly+6aC1tYwc/ia9GiBPZ8J8JJkWj469kCd5QH L3z8MYU9oSZD3jLRxIqz5L2pm2qaK0Gds1dCGHE8flP140/InX358G0KfTMwVWMRLj3oVV t9ZJKzetnYRNIhtCXBQw8PoLPlZieCA= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-94-ghBU36WOO1SKQsST29Z3ng-1; Fri, 24 Mar 2023 11:36:23 -0400 X-MC-Unique: ghBU36WOO1SKQsST29Z3ng-1 Received: by mail-ed1-f72.google.com with SMTP id es16-20020a056402381000b004fa3e04c882so3735219edb.10 for ; Fri, 24 Mar 2023 08:36:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679672182; 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=4MlJ8boSBAN33TyWlK9MdNtuYbz66i2Pl/D7dBKo3iE=; b=NwxcSNfZUY00UswhNDPc47g/zbX8cWQwiwHeudIwlxpAkcLSuf+R9DbW5WEy3kUDOw zEPW2QyD0q3GKeoGA56zOMDi+8bivL8P+TFr3z3elxl5N/2/MLqF2r0QL/SEeQ92AwAn W+YeQ64quF0aGTWT1IVskZTrcJt18lZTGJEVDZ3bXRDtTPaESl3g7Cd56ewFOkI5nfWA rRRg2Q11CgHO4euFx87DfsknVw/mA1H1Q/iBpY5gY66BlJ7p1TDdl9oLXmwN9fLb2qE9 ZpYy4T5b7RxJHSWdGBfnPihHK33cjjKdbU+0P0uquaazoAO/h6zeq7UXOGX4Yi+d6eDW DtbA== X-Gm-Message-State: AAQBX9eeMFBLaY3Pq7Q+2OYzl49P0ZBllrw0OPX/xImLROGoxtdgAEib atic6ZV9lhNLbvoDV2QKXLjEiXs5xn3ZFdkgiLlkeZc+hQC4dSULDiCzgRoLkoQzp/QgpX3NWOT dun+YJaS542OIMTAS1W8swpzp X-Received: by 2002:aa7:c790:0:b0:4fc:d837:2c44 with SMTP id n16-20020aa7c790000000b004fcd8372c44mr3252026eds.35.1679672181884; Fri, 24 Mar 2023 08:36:21 -0700 (PDT) X-Received: by 2002:aa7:c790:0:b0:4fc:d837:2c44 with SMTP id n16-20020aa7c790000000b004fcd8372c44mr3252001eds.35.1679672181598; Fri, 24 Mar 2023 08:36:21 -0700 (PDT) Received: from localhost.localdomain (host-82-53-134-98.retail.telecomitalia.it. [82.53.134.98]) by smtp.gmail.com with ESMTPSA id a27-20020a509b5b000000b00501dd53dbfbsm5468613edj.75.2023.03.24.08.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 08:36:20 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: stefanha@redhat.com, Jason Wang , linux-kernel@vger.kernel.org, Andrey Zhadchenko , "Michael S. Tsirkin" , kvm@vger.kernel.org, netdev@vger.kernel.org, eperezma@redhat.com, Stefano Garzarella Subject: [PATCH v4 2/9] vhost-vdpa: use bind_mm/unbind_mm device callbacks Date: Fri, 24 Mar 2023 16:36:00 +0100 Message-Id: <20230324153607.46836-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324153607.46836-1-sgarzare@redhat.com> References: <20230324153607.46836-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: v4: - added new switch after vhost_dev_ioctl() [Jason] v3: - added `case VHOST_SET_OWNER` in vhost_vdpa_unlocked_ioctl() [Jason] 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 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 7be9d9d8f01c..3824c249612f 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); } +static long vhost_vdpa_bind_mm(struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa = v->vdpa; + const struct vdpa_config_ops *ops = 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 = v->vdpa; + const struct vdpa_config_ops *ops = 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 = v->vdpa; @@ -716,6 +738,17 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, break; } + if (r) + goto out; + + switch (cmd) { + case VHOST_SET_OWNER: + r = vhost_vdpa_bind_mm(v); + if (r) + vhost_dev_reset_owner(d, NULL); + break; + } +out: mutex_unlock(&d->mutex); return r; } @@ -1287,6 +1320,7 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep) vhost_vdpa_clean_irq(v); vhost_vdpa_reset(v); vhost_dev_stop(&v->vdev); + vhost_vdpa_unbind_mm(v); vhost_vdpa_config_put(v); vhost_vdpa_cleanup(v); mutex_unlock(&d->mutex); -- 2.39.2