Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4426234ioa; Wed, 27 Apr 2022 03:43:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykw4jkKNeFeMrqTscxxxO68JMesUg0Y7T4CEarzJt5tn9MOBZ04E4orkuWW9CLFLjdBJl0 X-Received: by 2002:a17:90b:4f82:b0:1d1:b8fd:7e36 with SMTP id qe2-20020a17090b4f8200b001d1b8fd7e36mr43115849pjb.194.1651056190199; Wed, 27 Apr 2022 03:43:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651056190; cv=none; d=google.com; s=arc-20160816; b=oB+CL3AP2OhEdAg6TkdhaMVf/cYGzK/XZjK1DVIzChjEcRM7R1bUt+jJjBvBuSPzzF nn2SP1yKM1ueOJzaYlp7Fb4aH8XXZA6pV5xM33HOX6ZnTPTQu3pt7zfKb93mW2F00a9d LfFMa+4ZLKJThyVIGHZTbS4q5cLPxZdtZo2/DHJjqFPSnVakUJtMUWg3XCcvDtnlkdNG xnLHZ5LKNQQhQyDQ+C4P8+bRS9O/lDQDiloKymRtr0pukhjfgXJzCVFX/Hw3mofL1zUw co5Mo41Y9WIFf0hGy2DiWcNrWMotkYYrJrSYlek99Q1nE+sXZ1PaUXf47kGgyeYzNOrl BCMw== 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=xmQNHke9g7xOnw1PZQZgAnYGKAPH7c38WgoMWyxQyjQ=; b=zes/WMEAUmPoscz7wsMgVPtkXkJ3Fr+xAuRZFet42xPfFF3m5JeOyWuy7yneLOMDgK 2+1iymXCaQxOKm7eC2fd+JMrh7qc4E/QJ4c8DZts9QaLm9yjuoGMoYY6oMoeE6sWQ+Av ++mc+D9aaU7f9NhOv9PmmhRZzodc8Vck60DEfnmLeMp2JQZyqjHV8nqTr/IlCAwoBeAK RJAxdvOoXyKjl4pqK+5sguu9yF7L/PIrqxE/XjI+wkt5B5xNI39rnC9LSK3kKrQVSTR4 98ikTx9Vk0AN+yBgrDE/cmqDuZB/8R5PejuxKrIkX4gf0oGw82z2rni6yyygNAgix4D5 8T9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lUfBO0gT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n13-20020a170902e54d00b0015d06426f70si1403576plf.249.2022.04.27.03.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:43:10 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lUfBO0gT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0007E3DA2B6; Wed, 27 Apr 2022 02:52:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356082AbiDZXcR (ORCPT + 99 others); Tue, 26 Apr 2022 19:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240844AbiDZXcQ (ORCPT ); Tue, 26 Apr 2022 19:32:16 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADB75BC88 for ; Tue, 26 Apr 2022 16:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651015746; x=1682551746; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=J8JmQdIC2PvJ9tfgakqcAYqNpk0tOSg7F3URbm6mlRk=; b=lUfBO0gTdyjS7LgZe7/sG8gv0amoDEm8+fUuwkw5A+J6Al5B/n1L2L9g y2b+tE5sHeZBrRcZkhbFasmA86KX35n5Fzp+Xq/K2r80x93pzOApVvlVH TMdqDGI8GbUBxluPQEByaxZEr6tb1CpaxzHYl0Ng++yWfVB3wjZPeKaCF md5GCSSWwqcKU3ChNQMEe67r0aSjrEzUuo2IIsLu1D4QCm7vCD1pAopgi 3EmbWlgMkbOXmFQ0oLa6zoZwoKPOr0MsRYorN7B588Rz9adbWtAl4DASP 1W+AekNuwKKzBQCw2ZnIa3KRwHSrkJVtd8QXyXAqT95mxPbymPES+YT2v w==; X-IronPort-AV: E=McAfee;i="6400,9594,10329"; a="263345433" X-IronPort-AV: E=Sophos;i="5.90,292,1643702400"; d="scan'208";a="263345433" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 16:29:06 -0700 X-IronPort-AV: E=Sophos;i="5.90,292,1643702400"; d="scan'208";a="580226562" Received: from dsocek-mobl2.amr.corp.intel.com (HELO [10.212.69.119]) ([10.212.69.119]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 16:29:04 -0700 Message-ID: <63582490-a794-fd11-0380-44b27cc660b7@intel.com> Date: Tue, 26 Apr 2022 16:31:57 -0700 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 Cc: "zhangfei.gao@foxmail.com" , Fenghua Yu , Joerg Roedel , Ravi V Shankar , Tony Luck , Ashok Raj , Peter Zijlstra , Dave Hansen , x86 , linux-kernel , iommu , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Josh Poimboeuf , Thomas Gleixner , will@kernel.org, robin.murphy@arm.com, zhangfei.gao@linaro.org References: <76ec6342-0d7c-7c7b-c132-2892e4048fa1@intel.com> <22b659c7-e972-7a56-2bd7-8df3b4820d4e@intel.com> <8c044e49-74bb-df56-8a60-663013c0910e@intel.com> From: Dave Hansen In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_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 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.