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 A118CC6FD1F for ; Thu, 16 Mar 2023 08:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbjCPIck (ORCPT ); Thu, 16 Mar 2023 04:32:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbjCPIcf (ORCPT ); Thu, 16 Mar 2023 04:32:35 -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 038C05D458 for ; Thu, 16 Mar 2023 01:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678955488; 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=X/1UEGyWZZrbvStEgLaSVShuWDRxe0yPRa+3kY6NxaI=; b=IYJprkW1OtGCrEF2tI/Z48yXTIZTz1RV8Ys1KgziE+F6Spy8wYk5KyvU/G00TEf+LSxOi6 EoDiEYpSUsvIZji2VjKObgxeUmt9QR+Q1/ZPsz8OW5VoMTSCT0uTuP0Yg9mLypM4BGZWSR urjd+943k1XIGiGc1s8dDiFSomMDxc4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-13-sAUsOuckM32CU82usJZ82g-1; Thu, 16 Mar 2023 04:31:27 -0400 X-MC-Unique: sAUsOuckM32CU82usJZ82g-1 Received: by mail-wm1-f69.google.com with SMTP id bg13-20020a05600c3c8d00b003ed40f09355so432869wmb.5 for ; Thu, 16 Mar 2023 01:31:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678955486; 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=X/1UEGyWZZrbvStEgLaSVShuWDRxe0yPRa+3kY6NxaI=; b=YvwTJMZtgXpYjWiE5Ij0GxXs6CncFwDbdiED5QgWlRD0ewlOnBPWnDhshecUBoQcfm sXREB84GQw4058dQ8aO8f/cNbHIA6OJqCTV/XDyxtn6HyolXVLJPrPESjwyi/YqitSpU VdOwv3ioB2gY6kRc2LP+dsUgRlu0npVcOqTK/nggsFqnwu/BOgj6sj8yblCavCktC3j/ wOH17qoDIQP/c/cBAzWFLq5hquVz2s2ETaIU/XuygxDUqigRtqDYc9NCBWleu10pAD1l hQp7DDp/mhE3ItM2PX0FI6RLaArtQHbaqeUTSdgPqFoaK3DzBxCQ7x5Ny/q0uqq6VnMq BP9g== X-Gm-Message-State: AO0yUKUXCxUMwES6Mq65MwinwXjE+B/+uc/PRuK2YcJtAC91XQCCAzOc oJ91BdJnBQhZe4jk/t22qkFHyFpl0cnMFuBHRaHDvaEe9D1e3Pw9GGGhsXRV0StWFSoa1Hl4IFI tWJ9RZUMkijHdKIgof5H8piy4ESsGRtO9 X-Received: by 2002:a5d:5955:0:b0:2cf:e29f:d7f5 with SMTP id e21-20020a5d5955000000b002cfe29fd7f5mr3576310wri.25.1678955486054; Thu, 16 Mar 2023 01:31:26 -0700 (PDT) X-Google-Smtp-Source: AK7set8XgT/fkEa6oyHpuwgit2NX40Fpv+7C8AxfojZlS6SqwfkBRFQgzp3vx+Buq6H4mrLWafU74w== X-Received: by 2002:a5d:5955:0:b0:2cf:e29f:d7f5 with SMTP id e21-20020a5d5955000000b002cfe29fd7f5mr3576292wri.25.1678955485799; Thu, 16 Mar 2023 01:31:25 -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 c10-20020adffb0a000000b002d1bfe3269esm1518738wrr.59.2023.03.16.01.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 01:31:25 -0700 (PDT) Date: Thu, 16 Mar 2023 09:31:22 +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: <20230316083122.hliiktgsymrfpozy@sgarzare-redhat> References: <20230302113421.174582-1-sgarzare@redhat.com> <20230302113421.174582-3-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks, Stefano