Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3565407iob; Sun, 1 May 2022 22:56:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7mcwIIytGeqMFgBpUCeJ0KPlabjOwlvj9sm2Gget23mqQOKE5cUFr8VYyRl3zhECn9N29 X-Received: by 2002:a17:902:a581:b0:154:8c7d:736a with SMTP id az1-20020a170902a58100b001548c7d736amr10466392plb.74.1651471019524; Sun, 01 May 2022 22:56:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651471019; cv=none; d=google.com; s=arc-20160816; b=dOxquXrXUE0zVkElPG9CbI9sJ0duuNHE4w5HOBHV80slRCIDbZhGl8QlEbHncj3Wsf 9hw6pui8MYnkKrg71wciqBL92MS7pT1KzVM5ofbOaTVKjQZCAYME/oE0BHA7vVM7hCt6 8pvhkCFG+Ws6Bo5w+VvGEct7GlzLzbZWFyjkkTMMQs2XqcSeozZFvM3gIjilYxhHnY7k 8I8AiZnIt0Od2/DDpswWFh4mjHdiKJm47DEYWL2Bao7m+OT65KeFQkBX6ulsNJX+oc6P 3COLZAmlyu6Hd9FlmQSvbaXiVHZiQeBDvHM5CcjhdZ/sjLMp6FrbAJaSHOQ5qcFjK1J0 LMEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=rKoHQV20Sk5VNv8NaNXHACXTGELUB5kP5GGPCzXqVW4=; b=kwqTq1BAh1RWCSJaFSdi35HYxstBjNKjVv15Ig3YhTaVocrPUpkEioje8CfnnUpCyq 9kuuVnFJbjY58p/9wzKrhfwmhOHQgXBrwXmR+RKNd3vmXKR9zGLjuRn348tHPkgSIFiY KWEtvehKBqgKYXrEwqDc8k4XoS+hA5AmmvZnRMeME7NkwEjhi5jbFUfXJpTTD9Z7rUgl W4JCsgxQs07E2bb/9BrrCC75os2yUYRjLuHrwhKlxYqL/BFrNQqk3KolItrgex2acMzd 60QPNzBJVktKyDJOh0YSaEmBWeknVL+w/PbQoDZ3eST2rneD1sKTe0Nt/fgVyUzOW0Wc qI3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mKFqM85G; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10-20020a63ce0a000000b003c232c574c8si1213344pgf.342.2022.05.01.22.56.43; Sun, 01 May 2022 22:56:59 -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=@intel.com header.s=Intel header.b=mKFqM85G; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355266AbiD2H5Y (ORCPT + 99 others); Fri, 29 Apr 2022 03:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355255AbiD2H5W (ORCPT ); Fri, 29 Apr 2022 03:57:22 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42868B1897 for ; Fri, 29 Apr 2022 00:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651218845; x=1682754845; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=sZOMqFBA+sb3zh0RoDJhE1INTls5iHdZxwMbS5aX+wk=; b=mKFqM85G5rXS6U2dWlj7hsCI7U/uoFYCxcrJsK8hbpQ8xzZYGQnpHe97 wo07Q26xJ6GCQYbcJ7v/AwNoXklGwlKk4vsNItvclT3D99M6wIdSCEvzt tIsFqUw2Bq5yXSIBRpohL4IDYBqm3/9oebam6yzwSs/W7P4E9GovRkuN2 jOGE1NdIxZeGZK78ohjIjY/joPArb24zIKAOPJydhips6167I6TzI549l SytK6RevJogCjIm1nbNM1pv6Ps+208j+Ef/ApTNz+DmFbx3Nf1HGYNiBA BXwcxHujSQ+LECC/ETxmyaRnmWVT7p3bURgoMbL9GuEtOxmvYQeGSfx6g w==; X-IronPort-AV: E=McAfee;i="6400,9594,10331"; a="291736611" X-IronPort-AV: E=Sophos;i="5.91,297,1647327600"; d="scan'208";a="291736611" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2022 00:54:04 -0700 X-IronPort-AV: E=Sophos;i="5.91,297,1647327600"; d="scan'208";a="581971987" Received: from lye4-mobl.ccr.corp.intel.com (HELO [10.249.170.95]) ([10.249.170.95]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2022 00:53:59 -0700 Message-ID: <044595e6-e5d0-26c2-af8e-fc9d06906179@linux.intel.com> Date: Fri, 29 Apr 2022 15:53:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit Content-Language: en-US To: Jean-Philippe Brucker , Dave Hansen Cc: Fenghua Yu , Tony Luck , Ashok Raj , Ravi V Shankar , Peter Zijlstra , robin.murphy@arm.com, Dave Hansen , x86 , linux-kernel , iommu , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Josh Poimboeuf , zhangfei.gao@linaro.org, Thomas Gleixner , will@kernel.org References: <76ec6342-0d7c-7c7b-c132-2892e4048fa1@intel.com> <22b659c7-e972-7a56-2bd7-8df3b4820d4e@intel.com> <8c044e49-74bb-df56-8a60-663013c0910e@intel.com> <63582490-a794-fd11-0380-44b27cc660b7@intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 2022/4/28 16:39, Jean-Philippe Brucker wrote: > On Tue, Apr 26, 2022 at 04:31:57PM -0700, Dave Hansen wrote: >> On 4/26/22 09:48, Jean-Philippe Brucker wrote: >>> On Tue, Apr 26, 2022 at 08:27:00AM -0700, Dave Hansen wrote: >>>> On 4/25/22 09:40, Jean-Philippe Brucker wrote: >>>>> The problem is that we'd have to request the device driver to stop DMA >>>>> before we can destroy the context and free the PASID. We did consider >>>>> doing this in the release() MMU notifier, but there were concerns about >>>>> blocking mmput() for too long (for example >>>>> https://lore.kernel.org/linux-iommu/4d68da96-0ad5-b412-5987-2f7a6aa796c3@amd.com/ >>>>> though I think there was a more recent discussion). We also need to drain >>>>> the PRI and fault queues to get rid of all references to that PASID. >>>> Is the concern truly about blocking mmput() itself? Or, is it about >>>> releasing the resources associated with the mm? >>> The latter I think, this one was about releasing pages as fast as possible >>> if the process is picked by the OOM killer. >> >> We're tying the PASID to the life of the mm itself, not the mm's address >> space. That means the PASID should be tied to >> mmgrab()/mmdrop()/mm->mm_count. >> >> The address space is what the OOM killer is after. That gets refcounted >> with mmget()/mmput()/mm->mm_users. The OOM killer is satiated by the >> page freeing done in __mmput()->exit_mmap(). >> >> Also, all the VMAs should be gone after exit_mmap(). So, even if >> vma->vm_file was holding a reference to a device driver, that reference >> should be gone by the time __mmdrop() is actually freeing the PASID. > > I agree with all that. The concern was about tearing down the PASID in the > IOMMU and device from the release() MMU notifier, which would happen in > exit_mmap(). But doing the teardown at or before __mmdrop() is fine. And > since the IOMMU drivers need to hold mm->mm_count anyway between bind() > and unbind(), I think Fenghua's fix works. But I didn't find mmgrab()/mmdrop() get called in both arm and intel IOMMU drivers. $ git grep mmgrab drivers/iommu/ [no output] Do we need to add these in a separated fix patch, or I missed anything here? Best regards, baolu