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 28969C6FD19 for ; Thu, 16 Mar 2023 10:12:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbjCPKMM (ORCPT ); Thu, 16 Mar 2023 06:12:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbjCPKMA (ORCPT ); Thu, 16 Mar 2023 06:12:00 -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 BC370B78B3 for ; Thu, 16 Mar 2023 03:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678961480; 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=eBYYYx6ebaSPMy4LYead5i1f9hXn4823DINswCsrSc8=; b=Pqh4h9jblfSfE5EYOlcoggGCvmODNMhQLkCh3rV48bO9eCCX9BNNZYoOgIQceK6kTZxV+s NlC8nIAQsAJ2uxCtccq3wpTWo3n0tZ2KCGhETArvkvBUCnX9ydZnADZYbZG8nx2uSoHSwz MZggBcObaMWby6C/9RlV/sxHKlecQEc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-i9-YXJtkOyGFmkKGHBWIRQ-1; Thu, 16 Mar 2023 06:11:19 -0400 X-MC-Unique: i9-YXJtkOyGFmkKGHBWIRQ-1 Received: by mail-wr1-f72.google.com with SMTP id g14-20020a5d64ee000000b002cfe47b8ec4so176318wri.10 for ; Thu, 16 Mar 2023 03:11:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678961478; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eBYYYx6ebaSPMy4LYead5i1f9hXn4823DINswCsrSc8=; b=5GltX9K2HOin6v/oGunNT81eMwnZ75ZWbCpqrc7EHb7EjMraIhb+FOSHdxND/3IjwQ kmSVjtjSdzAI9RJtRet5iUaJDUUYVF6mREVfhZqH7b+U4vp+fzrDFpMywhyjTbqAEjsu 6nP4A5lj9FJZbLD199GDN5U9nnhtii8xRimQFcwtRPBjhzEQbKv2Ap5oM7jfgcy3xE/m nqZpYL4+JkB5tlkGY05xCAnFs9XMKoZ9I2gov5SYQk6HA8qDBAax/ffgjctEH/LSusli ZgBCH9O1dKPcDX0QzJYITlkK1fcqu0BO1X0rgPGbl8D7NRiReq1f3RP4QJXLuMiWL4l+ IfNA== X-Gm-Message-State: AO0yUKUnlS2NM1tqVGoT5rClKm0ugL5ETaOVBLImU2CpfYDKSB7zrKB3 1gVl/eRxuhMG6DlcQlVHR0dp6racgIjFZ0cVUMV+vnhDrGB54xRBEtZh1mC/TcyGCSzlrR9lV8Y xw5HqE4BQSRRPUDrJWfXciqGU X-Received: by 2002:a05:600c:35cd:b0:3e9:f4c2:b604 with SMTP id r13-20020a05600c35cd00b003e9f4c2b604mr22373478wmq.24.1678961478532; Thu, 16 Mar 2023 03:11:18 -0700 (PDT) X-Google-Smtp-Source: AK7set/Lu433zhP9PilHomJbmSQWYVXOQWWKmTm0C09FAmF8pzNNFzHUbJzlyQH+yr7BXNl3vtwXzw== X-Received: by 2002:a05:600c:35cd:b0:3e9:f4c2:b604 with SMTP id r13-20020a05600c35cd00b003e9f4c2b604mr22373453wmq.24.1678961478236; Thu, 16 Mar 2023 03:11:18 -0700 (PDT) Received: from sgarzare-redhat (host-82-57-51-170.retail.telecomitalia.it. [82.57.51.170]) by smtp.gmail.com with ESMTPSA id o23-20020a05600c511700b003ed29b332b8sm5045142wms.35.2023.03.16.03.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 03:11:17 -0700 (PDT) Date: Thu, 16 Mar 2023 11:11:15 +0100 From: Stefano Garzarella To: Jason Wang Cc: virtualization@lists.linux-foundation.org, Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: Re: [PATCH v2 2/8] vhost-vdpa: use bind_mm/unbind_mm device callbacks Message-ID: References: <20230302113421.174582-1-sgarzare@redhat.com> <20230302113421.174582-3-sgarzare@redhat.com> <20230316083122.hliiktgsymrfpozy@sgarzare-redhat> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230316083122.hliiktgsymrfpozy@sgarzare-redhat> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 16, 2023 at 9:31 AM Stefano Garzarella 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 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: > >> 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