Message ID | 20230302113421.174582-3-sgarzare@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4184592wrd; Thu, 2 Mar 2023 03:37:39 -0800 (PST) X-Google-Smtp-Source: AK7set8j3P/nLVuHyN4BWiG2+e7SHqRLoI4EUzVKFLHEUSPpz6TdAZF0haQkW+W8DiSegdRMoY8V X-Received: by 2002:a17:906:4887:b0:8af:54d2:36af with SMTP id v7-20020a170906488700b008af54d236afmr9246189ejq.76.1677757059417; Thu, 02 Mar 2023 03:37:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677757059; cv=none; d=google.com; s=arc-20160816; b=ZciHXauRrgJflKTTdpSy+G7Cz/s0LBa7YwzCcTKy1AeOzDrCvsx018J7YMCsGnfM09 miLrAiQTjRPThmqcVAFmQTzn3wBDU4dqyc7SjXK3sQhgaYqdTQjHdXNmLtctzAVsR2U4 W9Bvdwx4r1aQSSHFAdTFWGVrR+Wn6QLPvl+5oDGU8wQ5X3WLDJ0jU7fHnb4eUyIEmre7 gPQOKDrCdDaQIin6eKe0iQRZSVR6gMpSSOiuUeAZI19SrfmIkm/ivQ48dTVdxF8AIypY dx7AMhCxMbsj0sR1/P+uTt1aYbkOeQ68vu7KBttKjiqj55OX8WngMbkakvC+wslNlSYS 6/pg== 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=iYIRvQhreJmamPTgF10vjkMAMOhZQaOaX6sUzVAfpfw=; b=A5wOJ7wFvsgAdFoZuNv7Ju8dkuCoP8DUahfXiE0W60ggBcoLMpmH3dCbP9C15IlK/N Ub6DZHdA2QG94pnfQyiUCgBOpt2TrNsUnUlDECrrNtAJb42B4vCbFrue/3x6bBiU4wpJ gSR0waEh5wKxh/imnXnmhJOhOrx4tZQdAZKstsVaahPMsJN9zzDyAPjVD8/S0j18OWxG Iwg8g4afcXN/8pMCyBIjttXXlag6woBmIC+SSlT7FvkcP41kw9Pua33QEnz0x4pI96Cq Tmz4R9WyjFkpHKNylKHDuEXgK7U61uqingOK+4rWq2oVT1XYPQOturb3rlNyzV/a5GuO MNbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hQManXAS; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j12-20020a170906830c00b008b17e6556c3si15960021ejx.587.2023.03.02.03.37.16; Thu, 02 Mar 2023 03:37:39 -0800 (PST) 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=hQManXAS; 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 S229899AbjCBLfm (ORCPT <rfc822;davidbtadokoro@gmail.com> + 99 others); Thu, 2 Mar 2023 06:35:42 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <linux-kernel@vger.kernel.org>; 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-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 <sgarzare@redhat.com> To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>, eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang <jasowang@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, kvm@vger.kernel.org, Stefano Garzarella <sgarzare@redhat.com> 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-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759255786046129006?= X-GMAIL-MSGID: =?utf-8?q?1759255786046129006?= |
Series |
vdpa_sim: add support for user VA
|
|
Commit Message
Stefano Garzarella
March 2, 2023, 11:34 a.m. UTC
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 <sgarzare@redhat.com>
---
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(+)
Comments
On Thu, Mar 2, 2023 at 7:34 PM Stefano Garzarella <sgarzare@redhat.com> wrote: > > 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 <sgarzare@redhat.com> > --- > > 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); > } > > +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; > @@ -711,6 +733,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, > break; > default: > r = vhost_dev_ioctl(&v->vdev, cmd, argp); > + if (!r && cmd == VHOST_SET_OWNER) { > + r = vhost_vdpa_bind_mm(v); > + if (r) { > + vhost_dev_reset_owner(&v->vdev, NULL); > + break; > + } > + } Nit: is it better to have a new condition/switch branch instead of putting them under default? (as what vring_ioctl did). Thanks > if (r == -ENOIOCTLCMD) > r = vhost_vdpa_vring_ioctl(v, cmd, argp); > break; > @@ -1285,6 +1314,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_free_domain(v); > vhost_vdpa_config_put(v); > vhost_vdpa_cleanup(v); > -- > 2.39.2 >
On Tue, Mar 14, 2023 at 11:48:33AM +0800, Jason Wang wrote: >On Thu, Mar 2, 2023 at 7:34 PM Stefano Garzarella <sgarzare@redhat.com> wrote: >> >> 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 <sgarzare@redhat.com> >> --- >> >> 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); >> } >> >> +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; >> @@ -711,6 +733,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, >> break; >> default: >> r = vhost_dev_ioctl(&v->vdev, cmd, argp); >> + if (!r && cmd == VHOST_SET_OWNER) { >> + r = vhost_vdpa_bind_mm(v); >> + if (r) { >> + vhost_dev_reset_owner(&v->vdev, NULL); >> + break; >> + } >> + } > >Nit: is it better to have a new condition/switch branch instead of >putting them under default? (as what vring_ioctl did). Yep, I agree! I'll change it. Thanks, Stefano
On Thu, Mar 16, 2023 at 9:31 AM Stefano Garzarella <sgarzare@redhat.com> wrote: > > On Tue, Mar 14, 2023 at 11:48:33AM +0800, Jason Wang wrote: > >On Thu, Mar 2, 2023 at 7:34 PM Stefano Garzarella <sgarzare@redhat.com> wrote: > >> > >> 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 <sgarzare@redhat.com> > >> --- > >> > >> 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); > >> } > >> > >> +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; > >> @@ -711,6 +733,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, > >> break; > >> default: > >> r = vhost_dev_ioctl(&v->vdev, cmd, argp); > >> + if (!r && cmd == VHOST_SET_OWNER) { > >> + r = vhost_vdpa_bind_mm(v); > >> + if (r) { > >> + vhost_dev_reset_owner(&v->vdev, NULL); > >> + break; > >> + } > >> + } > > > >Nit: is it better to have a new condition/switch branch instead of > >putting them under default? (as what vring_ioctl did). > > Yep, I agree! > > I'll change it. Or maybe I can simply add `case VHOST_SET_OWNER` on this switch and call vhost_dev_set_owner() and vhost_vdpa_bind_mm(), I mean something like this: diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 331d4a718bf6..20250c3418b2 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -731,15 +731,16 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, case VHOST_VDPA_RESUME: r = vhost_vdpa_resume(v); break; + case VHOST_SET_OWNER: + r = vhost_dev_set_owner(d); + if (r) + break; + r = vhost_vdpa_bind_mm(v); + if (r) + vhost_dev_reset_owner(d, NULL); + break; default: r = vhost_dev_ioctl(&v->vdev, cmd, argp); - if (!r && cmd == VHOST_SET_OWNER) { - r = vhost_vdpa_bind_mm(v); - if (r) { - vhost_dev_reset_owner(&v->vdev, NULL); - break; - } - } if (r == -ENOIOCTLCMD) r = vhost_vdpa_vring_ioctl(v, cmd, argp); break; WDYT? Thanks, Stefano
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); } +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; @@ -711,6 +733,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, break; default: r = vhost_dev_ioctl(&v->vdev, cmd, argp); + if (!r && cmd == VHOST_SET_OWNER) { + r = vhost_vdpa_bind_mm(v); + if (r) { + vhost_dev_reset_owner(&v->vdev, NULL); + break; + } + } if (r == -ENOIOCTLCMD) r = vhost_vdpa_vring_ioctl(v, cmd, argp); break; @@ -1285,6 +1314,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_free_domain(v); vhost_vdpa_config_put(v); vhost_vdpa_cleanup(v);