Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1937068iob; Fri, 29 Apr 2022 16:58:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6xYoKbgg/0Px2QsE4KrC1/vc2l6SIbXflIgLjWgTk9Gm8O+ZPWuBzBcYuJCvJPmlYJf+i X-Received: by 2002:a2e:8346:0:b0:24d:ac67:42c7 with SMTP id l6-20020a2e8346000000b0024dac6742c7mr997033ljh.323.1651276694469; Fri, 29 Apr 2022 16:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651276694; cv=none; d=google.com; s=arc-20160816; b=XdB8HfvqTMtc1BQDBx8wYzj/UIXJcdOF4TyBhDn/R8zY2Qt0U0PMnc6qxFOj8hePFG 3sBsQFFSziCJ8yMU85cCXsW04NPV36JYGCeNqB4ovOeDOAG7yp48E3F6qMzdchwic8WA fcxYSMGbpnYu95yvE71hasKNEkOh/PIh4ZJAF9UUqyrTvudVfAKmHy1eBpCxCuETtmtF sat1OlwfDfOfTmcUmk7TzidMj2ruOSDJ8EDA4lslEsO5Bv/SX9YbSXMMMcPVIuMS6vCh eZ9m91HLcR2dB5ZLhSSuTYufaUh36ijF2Iox/S0UHKDcabPALza9a05ulk/X6HhayRl1 qZGA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+JgX6+p1OdAnFfOUU0z/DeAgU4m0JA/XJm17IP3jZwc=; b=zlSXdKvCJT7I+b9cqGnWVD4bNtt5mUJQkwCuGzGWdqDJ+DxMo54ZsoIRumRX/tO5Je PRbmZ+lTyDCIaeN/QeQmWIXCM4RHkFASK2m1+UTCp+tnFlIXNP0GOTDeTKj4V+4LqemH dujpNcFe00UR2J941F94JhRbJMW0H1f8wbP/HM6ZE+jENosAqVC9wDkUvNSFu9gNTshQ ujjAWQmAce2zpClWWuRlktuiUsbZoHAtBy25l2Oo2t3Aa7KUbC7IRO3KeJ0qL3ESD/Zs A7woq2sgQ8VsLnl+OcFJD3xR0V7XWZPV0Mcpj7Ugjd2Hlupns/417RIz/j0S/pJSgirS bgkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q+R2uzwB; 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 u2-20020a2e2e02000000b0024da0839470si7447782lju.192.2022.04.29.16.57.44; Fri, 29 Apr 2022 16:58:14 -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=Q+R2uzwB; 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 S236751AbiD2NyL (ORCPT + 99 others); Fri, 29 Apr 2022 09:54:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376432AbiD2NyH (ORCPT ); Fri, 29 Apr 2022 09:54:07 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BC5F4F447 for ; Fri, 29 Apr 2022 06:50:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651240248; x=1682776248; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=I1IC3ER1bbr2Gmvx8B3VxE2I1iNqvQIOt1Apf8a8gjM=; b=Q+R2uzwBMxC0zni3P1Ice41Jm3MswIW3NLiAtrj/h/bVxDLffWHKH37x /GmWZyDwiXwgHieorh/pXGRqkllXqP2i+C2CfzLONwL2o3dkQu1WNoMRW rR6Cv9gniF1wnz4LA7rz+2hRx9dyWhc5CjhjAjZM25t0iAwC+cXAfYkaq qtywpsJ1HHl3HHUTQ9GJe4/H1ZbDGlCAyCGw4+f5QGt5Nxwqmln7ERifS 6I/4ld0N6b7aYp6xhXoWY3f8F8SgmdLlSb9nKspf7Op6ZtpP2rQk+dd7A vOcZV3ntnMyFq5tHmhBihNBjeWFgx1O4s03QsCstOG9cQNGPTwkB7sBGr A==; X-IronPort-AV: E=McAfee;i="6400,9594,10331"; a="254034670" X-IronPort-AV: E=Sophos;i="5.91,185,1647327600"; d="scan'208";a="254034670" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2022 06:50:48 -0700 X-IronPort-AV: E=Sophos;i="5.91,185,1647327600"; d="scan'208";a="560349710" Received: from fyu1.sc.intel.com ([172.25.103.126]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2022 06:50:47 -0700 Date: Fri, 29 Apr 2022 06:51:17 -0700 From: Fenghua Yu To: Baolu Lu Cc: Jean-Philippe Brucker , Dave Hansen , 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 Subject: Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit Message-ID: 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> <044595e6-e5d0-26c2-af8e-fc9d06906179@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <044595e6-e5d0-26c2-af8e-fc9d06906179@linux.intel.com> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Hi, Baolu, On Fri, Apr 29, 2022 at 03:53:57PM +0800, Baolu Lu wrote: > On 2022/4/28 16:39, Jean-Philippe Brucker wrote: > > > 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? On both ARM and X86, sva_bind() calls mmu_notifier_register()->mmgrab() and sva_unbind() calls mmu_notifier_unregister()/mmu_notifier_put()->mmdrop(). So mm->mm_count are already counted in existing ARM and X86 binding and unbinding. The fix patch just frees the PASID in __mmdrop() after no more mm->mm_count. There is no need to add extra mmgrab() and mmdrop() pair. Thanks. -Fenghua