Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp220763iob; Mon, 2 May 2022 17:37:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnU9zj0Hugz3nViYmi3sa7dCGZdJlM1Z7saVnkgkuP7rOpp01XCw6mgma9o2jsn90aDyI0 X-Received: by 2002:a17:90a:343:b0:1cb:234a:a975 with SMTP id 3-20020a17090a034300b001cb234aa975mr1963218pjf.83.1651538239380; Mon, 02 May 2022 17:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651538239; cv=none; d=google.com; s=arc-20160816; b=ovm1VOR+jmdSmudagGSqzuPqzhX8VqjsYlHUkL05kWTElz8vMTKLCuHQE0kNmfEE86 GAq3f0iwbYR027ov/oeF7gN2md453B9mpfoe916eFSoHDFEyAallnWAd7tLmMjRroMxv TJ0hJZSQkN7wksp0h5rzbwa2D3giCBBnCxnTAAcl0zSa902rEKHk+m0P0z41eLqMy4wI +qdPFggW63UYiad9QPLqumj8elmnsNWDsffFZY29O0SBsa3xGupxYMsO7JGqhjN/xwpy P+FnA7xAF/jM9UUDAu8DWZlsQTUTjt5rlpIpPZEwr7qZ/W/o7lGiSIlEapNA418kx3N7 PKWw== 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=MNfUquSBQXRdU8AFXuKgswA3BnrGyLe9et79dGaHCHo=; b=Ycd3wb5hVmefIXIiKe+xw3UpxgRVLHccqM5J8A+8QfpO6v3f07zIvph1ThlEF0n6Da YBYFeRATFj+5RdLH6qQ31hE9pzbrOl3vSiAQMrsM/k4eOe3AmHbsQlkJ/UyGGCU/e12N OQSXwXfNOaQclAfToO8S+EEIpnl9LjjdkqrVnFae3SP7q6YlDhxGlOlxXahnI/HuCE+p t7NCaMiYMzRyo4yj9XTsOZ11ZFahHJuqeyoBbvZ6Ha+XJRcfO3PCNgFNGVUPVapCAJ83 omIXMHjk5QKrjvdt5eVCuaT8m+eQgGq6cK8/ntYaO1gt+rP1te7A9gnH5eu4dbYmh2Pg ajDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aCrclNQa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d71-20020a63364a000000b003c1d56c081bsi2970391pga.212.2022.05.02.17.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 17:37:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aCrclNQa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BDDF044A3C; Mon, 2 May 2022 17:29:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356614AbiD2OiX (ORCPT + 99 others); Fri, 29 Apr 2022 10:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344646AbiD2OiV (ORCPT ); Fri, 29 Apr 2022 10:38:21 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDEC72A71A for ; Fri, 29 Apr 2022 07:35:02 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id c190-20020a1c35c7000000b0038e37907b5bso7185553wma.0 for ; Fri, 29 Apr 2022 07:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MNfUquSBQXRdU8AFXuKgswA3BnrGyLe9et79dGaHCHo=; b=aCrclNQan4DsysNx5+Nj3TiV0fkI/4mECyTS4zEiZJ1dbrslZNfdTJXWueSAZWJnj9 DwSOotBRoD0nJ/o2/tSmtSJ5R306TVL+nnpVT5ZaYo5fsHtkNVj8ZEHVmr176n4+JxPx SjomnHzojd/oFkir7xR7lTB3rXs3zZOZtmb3rziM8Pbx95QK36YxjUQC9D7AUyOGlfPJ 6pXmo870wnuuYI1pL69PpSShVXLUfeCJy82zRSiD0TAKehsScy7PPWZdcH+jqaCj02QL kFZCgZunayVK8ji/YGjOacvZv+7UCpBUAbWAN+ZvMnrNGupxBZg4rfrn4HU1c5SoPpA/ JKcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MNfUquSBQXRdU8AFXuKgswA3BnrGyLe9et79dGaHCHo=; b=i3MNFuPOVGB0T2I3QvWpwl4jnDBTlMtkwod6dVpU/0nTKsTfcpoJgiwubb+1nwf9gD G86Cbv6cNwHnMeG0y80DvPSChITXnBUESXyjZAt8QR6LricAwmcnrLCv9LjSX95z0xYz SZrRjfJNbY06RQa7Y40O5Q0QwUBDcLHp2IsBp+5wQrh9o20SfGi2A10RB5s/wuh+mm0K jZCyal6MVzbH2mKu8MixJmy4+KMyvN71B53zHXQbgvAB1RpnB+7/aReE7jDdMmTLybGb b8mPFTmntFKiktDJ6r2WwszC6j0warCHbCbaVKKhi8x1o6qbfo8dQrZjOMjt1kQaQQEA mDjw== X-Gm-Message-State: AOAM53222ARsdhQqcWZJH7IZ15riMouO7Koa2v3AvdmglV3iG3TKtkdm I+t76Q0qfo0CcYsWNQW3IuYG0w== X-Received: by 2002:a05:600c:2e08:b0:394:24c:2da4 with SMTP id o8-20020a05600c2e0800b00394024c2da4mr3532185wmf.134.1651242901408; Fri, 29 Apr 2022 07:35:01 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id m35-20020a05600c3b2300b00393ebe201a6sm7075995wms.44.2022.04.29.07.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 07:35:00 -0700 (PDT) Date: Fri, 29 Apr 2022 15:34:36 +0100 From: Jean-Philippe Brucker To: Fenghua Yu Cc: Baolu Lu , 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: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Fri, Apr 29, 2022 at 06:51:17AM -0700, Fenghua Yu wrote: > 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(). Yes, although for Arm I realized the mmu_notifier grab wasn't sufficient so I sent a separate fix that should go in 5.18 as well https://lore.kernel.org/linux-iommu/20220426130444.300556-1-jean-philippe@linaro.org/ The Arm driver still touches the arch mm context after mmu_notifier_put(). I don't think X86 has that problem. Thanks, Jean > 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 > >