Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7019266rwl; Wed, 22 Mar 2023 20:28:20 -0700 (PDT) X-Google-Smtp-Source: AK7set8gtGVI1ZGg66f2UpeT4N0rEnml9njleowAGUE6E1TmaaUhASXopyIq6h4vkvuK+TJf3Ota X-Received: by 2002:aa7:d14b:0:b0:4fb:2296:30af with SMTP id r11-20020aa7d14b000000b004fb229630afmr9008796edo.20.1679542100378; Wed, 22 Mar 2023 20:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679542100; cv=none; d=google.com; s=arc-20160816; b=mlhA8GOxSpS73Gj77DrKXx3KumV6nPr+a4EcJ2chOI60+tWVk1yYMoJFsA4SXGcXhD Qf32gebIC9c1iOlaGb/OR7LRYxUJrAXuOni0oaLrWC62+4RwVtgNFjzSQ7RRSQHARrMu 01TIiPy0+32bxgSv5DK7D1XExpeeLxT3/SnAVVNRc/PIDNUK8/otRsahyMZuaCDColWW Rc552q5desmx1JQ4rfR6p6sQzfXGZz/iZrPyz8kKSkXjOdKaA+HwO9WBGSQptlaw2kqG z4u1qg+UEnPEFjkY7wuMG0zNMscMdRXiZnJc9vNlN5N1GQjWwZvLJeDTzKuilnj21EEC 1hZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=V020neUbbZWaZoIFJtWjwKXZ29/hnOcn6337E3R+7Xs=; b=ykjv30l7GPKA66sHDHG2kJ2Ev+8joZZp8eqqOwzmjCZdFbaUrXKerHVZ1UaEXJG2Ge wOOLmrcgctwEYJaf3s2urCOHcZcsZZFkklZs59EqGepU11D0bLjVMFq9DXSuy4zihn5K 1+MeSwBkXjx3LKPyWibuFJu9m3sudzDdgmuHyparC8z7bK/HaNxLChe+C6NfIE9x7kap slO/LUmd/NLrJ7DY8qr3ay7udb6H/fo7MmjiSb/6ou1IredH+Fd1xxDvJYRLmPZ4xsLy QaHm96v4rFCAliTj6l1F96w7QtjxXyNNNpiGyMXBeF+XWn9IcmLSq8iLD/pJ9Yzs4V13 kl4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aw63qbmQ; 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 l18-20020aa7c312000000b0049fc45a6102si17288568edq.381.2023.03.22.20.27.56; Wed, 22 Mar 2023 20:28:20 -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=aw63qbmQ; 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 S229870AbjCWDCk (ORCPT + 99 others); Wed, 22 Mar 2023 23:02:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjCWDCj (ORCPT ); Wed, 22 Mar 2023 23:02:39 -0400 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 EBB4FE18C for ; Wed, 22 Mar 2023 20:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679540513; 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=V020neUbbZWaZoIFJtWjwKXZ29/hnOcn6337E3R+7Xs=; b=aw63qbmQF7fZKF/MPeJNqCgR1hpYHbsh6OcceSsYf8YNeb5D76WPnKUENKWiVGXmj7SoNd bl4b4evfIr3qL0r99mhu1gDleHzHTR9jhTSScN9Ge8JcTVyvg7LpEbEW9AnIc9KxQ9IL2u gwgmRDATvAVX8PUu1oUZpO4v2ZdjoY8= Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-5w-fXbItObenwtwIqLwKoQ-1; Wed, 22 Mar 2023 23:01:51 -0400 X-MC-Unique: 5w-fXbItObenwtwIqLwKoQ-1 Received: by mail-oo1-f71.google.com with SMTP id q18-20020a4a3312000000b0053b61757527so2427155ooq.9 for ; Wed, 22 Mar 2023 20:01:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679540511; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V020neUbbZWaZoIFJtWjwKXZ29/hnOcn6337E3R+7Xs=; b=4r6XDiYxnpqog823bhx1rY7pKKiBXbFJjv30odxxtDCbehs7XofzbxJNuJmTaahAk5 SpO7FVjn0ZWxTmrQBAMV1aJfYR5pJUwJjmi11MnofhPoAxGD+77EUMgo/5770gV2fxBr kwuiHr3F3g5riEdwYUb1zYMJNnKg+u7C9NNC6VIGpaD53tNMQ4IYza9zySZ6aN4XxOrx 4h0N2zwoyJUruhnmrcbSNU6dAes1qbILWlkYNypILliAtu9GWsFLqJz34dYZMSIRXQoq ZfA7rP4SwjhWavRdeCCyUnnfZnzwqqTw5KbQanE/A8zXxKtbDLOpvSaPT9CdgSTxiYH8 pGwA== X-Gm-Message-State: AO0yUKVGVNvICDMFShy7sWcbLKVDIlLce2aDT4OvgbizdBiYgOKGqpxi GsWA7lKlB3h4Pr00ozEjhiYANnivRJsONTHDRRAibIY8lCtPdXKUOMtRhnOUyF9W066ULYGvvR7 xsg9mWVV8KxXxTmXT2THLcer9TAhBHCpVEfc8e8Ne X-Received: by 2002:a4a:da03:0:b0:536:c774:d6cc with SMTP id e3-20020a4ada03000000b00536c774d6ccmr1503655oou.0.1679540511131; Wed, 22 Mar 2023 20:01:51 -0700 (PDT) X-Received: by 2002:a4a:da03:0:b0:536:c774:d6cc with SMTP id e3-20020a4ada03000000b00536c774d6ccmr1503644oou.0.1679540510894; Wed, 22 Mar 2023 20:01:50 -0700 (PDT) MIME-Version: 1.0 References: <20230321154228.182769-1-sgarzare@redhat.com> <20230321154228.182769-3-sgarzare@redhat.com> In-Reply-To: <20230321154228.182769-3-sgarzare@redhat.com> From: Jason Wang Date: Thu, 23 Mar 2023 11:01:39 +0800 Message-ID: Subject: Re: [PATCH v3 2/8] vhost-vdpa: use bind_mm/unbind_mm device callbacks To: Stefano Garzarella Cc: virtualization@lists.linux-foundation.org, stefanha@redhat.com, "Michael S. Tsirkin" , Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Tue, Mar 21, 2023 at 11:42=E2=80=AFPM Stefano Garzarella 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 > --- > > Notes: > 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 | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c > index 7be9d9d8f01c..20250c3418b2 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 =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 *ar= gp) > { > struct vdpa_device *vdpa =3D v->vdpa; > @@ -709,6 +731,14 @@ static long vhost_vdpa_unlocked_ioctl(struct file *f= ilep, > case VHOST_VDPA_RESUME: > r =3D vhost_vdpa_resume(v); > break; > + case VHOST_SET_OWNER: > + r =3D vhost_dev_set_owner(d); Nit: I'd stick to the current way of passing the cmd, argp to vhost_dev_ioctl() and introduce a new switch after the vhost_dev_ioctl(). In this way, we are immune to any possible changes of dealing with VHOST_SET_OWNER in vhost core. Others look good. Thanks > + if (r) > + break; > + r =3D vhost_vdpa_bind_mm(v); > + if (r) > + vhost_dev_reset_owner(d, NULL); > + break; > default: > r =3D vhost_dev_ioctl(&v->vdev, cmd, argp); > if (r =3D=3D -ENOIOCTLCMD) > @@ -1287,6 +1317,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 >