Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp2494497qtg; Thu, 23 Mar 2023 04:47:20 -0700 (PDT) X-Google-Smtp-Source: AK7set/PN7xtjbdIzpE4HRsti7htH2tHcHOOcnuc7N7l1ABfpeN8SEzNxIrDL5VHx+Z/wJuGY3Ud X-Received: by 2002:a05:6402:c99:b0:4bc:edde:150d with SMTP id cm25-20020a0564020c9900b004bcedde150dmr6131725edb.0.1679572040354; Thu, 23 Mar 2023 04:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679572040; cv=none; d=google.com; s=arc-20160816; b=u1xnHF9XcF3d4s35RkN7uDL95ig4vl/q9pxAQzGipiM4whdFyzW9zvd3vuEddEfUaL 4Nq0ntIsF9dpJLkaPRRNAzqMlH05KR0PvByvnpfKcZ0yz37Ks8nXKp6aDMUAuQKs7b5d pad/MtEcdRbFncNXy5NztFPN8ac3pKg3mB/bXj5bpMWzulRffboT1DME7LAQbi17DIaT W30YvloYLln8vp9JspnkZss7wojcECiKfN3Cc5T0iQrH2Z7gG87QeIeREzxtgdrry7Mv ZW+EnLBTEn43I6lQff+6otOWMLwEMbmj7a/zEuP/XLbti7xjTxa2wojqx6PpFaX09umA mBgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BMD7H2kp0eSKoSxfq1PhoExu63Twb+QYc8ILXExIOt0=; b=hKW1B+j5Owo8dY4X7+uIH8LQA3yBMn/tWfyx0ERMj85IXnYJYc3g7+7ini+e5SgYUN 1tl2dRWT4/fYbPWsWj0Z3innCpPDpILQTcJYmwATnYIzGO8wMXEEdn1Zf0kRQfvyIpq8 ISab3Eo05Gujm2l3ZJQVWLhwikvGZnyczR3oDUWFzSIaWYGgaYj7glRsSMaNb+WRotXK puYALLLq0RuzBNHLJjRuIVZigWobCNj+nvnOWwqB2PXoE+VRNxcXSxW/0fZssvxoHEaq +rvV8hdbMuIUzEnyYbIQWNnRxz+Z35sJc4sTnp3Oouk7duLr8AJ71LpXk7pib8WscQNX bgWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R7dWtzTp; 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 g23-20020a17090669d700b0093b469b02b2si3467862ejs.744.2023.03.23.04.46.56; Thu, 23 Mar 2023 04:47: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=R7dWtzTp; 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 S231667AbjCWLpl (ORCPT + 99 others); Thu, 23 Mar 2023 07:45:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbjCWLpj (ORCPT ); Thu, 23 Mar 2023 07:45:39 -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 9B1B11D907 for ; Thu, 23 Mar 2023 04:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679571889; 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=BMD7H2kp0eSKoSxfq1PhoExu63Twb+QYc8ILXExIOt0=; b=R7dWtzTpD9n2TfgKI/ljFG79xAoZjHEiZfih/5Nz4fBDxChSGZg6lso0FW9ke8c9LLXA6L 60yE0xFbUT0UGgcFpLXD1JoE4jquUjf5h81cu1qLLrwQrWsx0HUWKLA0h7vayl+Qegjkls WGl8W9ZyXDtpEp8AFMEnbmSqXZefkvM= 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-596-hbP-rUTeNlOWXlSc7GrFXw-1; Thu, 23 Mar 2023 07:44:48 -0400 X-MC-Unique: hbP-rUTeNlOWXlSc7GrFXw-1 Received: by mail-ed1-f72.google.com with SMTP id t14-20020a056402240e00b004fb36e6d670so31647935eda.5 for ; Thu, 23 Mar 2023 04:44:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679571887; 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=BMD7H2kp0eSKoSxfq1PhoExu63Twb+QYc8ILXExIOt0=; b=ODwRUdFfC4a4H7gQ4zlrXADg5rYuJTWgp+HEOLM4k9caULuui9jsH4dfeCsXDnILew 2qOLja1hgPOS4Maj1M4QyWrB0sD8wtdgrZfSp+0NJ/9yJAbWwHDxyaFfvw7Se/p5flvW d1v1eEXFHGt8clGPcZbydo+L5p+qtehLfnPJPLsS7o0qHIEemRVVr9WJrQtLhtBpm5aE GIaeL5rGNS/12KaTGGkf/fuemn5NMFzTe8/8gzi9ydhRg2cvuBTiKhmWfwew9mNWz1w3 SysSQ1Gdq1b+lzI4Z3xEj/7LMxZNg+pdY7LlrCzcfeW+ywuch+yNUfkrWoxWCU6rKiIs bD4w== X-Gm-Message-State: AO0yUKUqrFUl8o0zs9WeOd8YtBh4imMIABuymp2uAfqj+zcKnfQOyAlb C8x9f3Jxd5ADWrrkMBJFo1W9L2n4v28ANFHRJa7oCewZn4mj9Ui0wgg6t3DhwTBVSYCMF/TOMIL cHuCAUR2FB7rJUOzImVsyF1qZ X-Received: by 2002:a05:6402:2920:b0:500:2cc6:36d5 with SMTP id ee32-20020a056402292000b005002cc636d5mr5727069edb.8.1679571887368; Thu, 23 Mar 2023 04:44:47 -0700 (PDT) X-Received: by 2002:a05:6402:2920:b0:500:2cc6:36d5 with SMTP id ee32-20020a056402292000b005002cc636d5mr5727043edb.8.1679571887109; Thu, 23 Mar 2023 04:44:47 -0700 (PDT) Received: from redhat.com ([2.52.143.71]) by smtp.gmail.com with ESMTPSA id w3-20020a50c443000000b004ac54d4da22sm9165128edf.71.2023.03.23.04.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 04:44:46 -0700 (PDT) Date: Thu, 23 Mar 2023 07:44:43 -0400 From: "Michael S. Tsirkin" To: Stefano Garzarella Cc: Jason Wang , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, eperezma@redhat.com, Andrey Zhadchenko , netdev@vger.kernel.org Subject: Re: [PATCH v3 8/8] vdpa_sim: add support for user VA Message-ID: <20230323074427-mutt-send-email-mst@kernel.org> References: <20230321154804.184577-1-sgarzare@redhat.com> <20230321154804.184577-4-sgarzare@redhat.com> <20230323095006.jvbbdjvkdvhzcehz@sgarzare-redhat> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230323095006.jvbbdjvkdvhzcehz@sgarzare-redhat> 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 Thu, Mar 23, 2023 at 10:50:06AM +0100, Stefano Garzarella wrote: > On Thu, Mar 23, 2023 at 11:42:07AM +0800, Jason Wang wrote: > > On Tue, Mar 21, 2023 at 11:48 PM Stefano Garzarella wrote: > > > > > > The new "use_va" module parameter (default: true) is used in > > > vdpa_alloc_device() to inform the vDPA framework that the device > > > supports VA. > > > > > > vringh is initialized to use VA only when "use_va" is true and the > > > user's mm has been bound. So, only when the bus supports user VA > > > (e.g. vhost-vdpa). > > > > > > vdpasim_mm_work_fn work is used to serialize the binding to a new > > > address space when the .bind_mm callback is invoked, and unbinding > > > when the .unbind_mm callback is invoked. > > > > > > Call mmget_not_zero()/kthread_use_mm() inside the worker function > > > to pin the address space only as long as needed, following the > > > documentation of mmget() in include/linux/sched/mm.h: > > > > > > * Never use this function to pin this address space for an > > > * unbounded/indefinite amount of time. > > > > I wonder if everything would be simplified if we just allow the parent > > to advertise whether or not it requires the address space. > > > > Then when vhost-vDPA probes the device it can simply advertise > > use_work as true so vhost core can use get_task_mm() in this case? > > IIUC set user_worker to true, it also creates the kthread in the vhost > core (but we can add another variable to avoid this). > > My biggest concern is the comment in include/linux/sched/mm.h. > get_task_mm() uses mmget(), but in the documentation they advise against > pinning the address space indefinitely, so I preferred in keeping > mmgrab() in the vhost core, then call mmget_not_zero() in the worker > only when it is running. > > In the future maybe mm will be used differently from parent if somehow > it is supported by iommu, so I would leave it to the parent to handle > this. > > Thanks, > Stefano I think iommufd is supposed to handle all this detail, yes.