Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4476740ybz; Tue, 28 Apr 2020 11:58:09 -0700 (PDT) X-Google-Smtp-Source: APiQypJMijPlNpXdqFRjjNaIM0Uxz2zA2sB2QMq4YvoVN7UJLVyTYpLcA4ITFdz0sSEyLiPebs95 X-Received: by 2002:a05:6402:1717:: with SMTP id y23mr23641148edu.361.1588100289563; Tue, 28 Apr 2020 11:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588100289; cv=none; d=google.com; s=arc-20160816; b=heKZfjROI2xeMdgscz9JSb5VmhDqjsyRfommdaT/dYMW4LtxUcwJvCr/lmaCbhZUBY rKRSIdpuQa+ovyk9fPc2A/3ajasOwlBBGe9J13B7r9SLO9kcINXG1h7CykjXVmvOdnDN Fa8kfURD39HT5Juj0c3h61C8BBo2EYJ6vT+vXHq4CywOVWob2YbiSfdIUfnZrzFP1W1i 68tqWWaNwmbnr7D+15dcWGsp7taELnWG/TRQPMTu4QQfDOEz8NQ45nMVQmT1mU9h/THQ ueMaWBv9qM1hlZMmo7/sLig5r1RyqPxvpX3pKPtFHebUrETKmljTp5xNdzgMZx914GLe eXAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=sVXF0NrO6Y4wLjx2ekTtyGEMsNaMHjRfpQ7/yCJFCOk=; b=yOWjPO22OmYaWgXEW4jnYDm1ufOvLX1yiEH91/SQ1osN5aI4gG8gewZQC5uUjKH1Ce 8GmcxNn9qqRyEHjFgZRnL3on0ufvpXfH4/qxqkbvc/IUcRSP2EJaB+mPzo8tGtcDNeo3 tzPGSVpe3l7hr5nafbozSyz9e1s3dOJ6MLoy41oadE/c4rXKTV8yLQhpzBOgk/eAh4kN bNG78/HdibaXnA+Xvgl9nHmld52PG6dAXtqJ7WHOzjF0hEtaCXDYSMDTTtSYLEoORRue TPRbG2DTQL0F36xE6dyHq3mtS9FGNsGO6qNZBEMnrtavfHG0dkgrvYxx77PC4Llr2rpz q9fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o14si2289966ejm.511.2020.04.28.11.57.46; Tue, 28 Apr 2020 11:58:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730780AbgD1SyX (ORCPT + 99 others); Tue, 28 Apr 2020 14:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729263AbgD1SyV (ORCPT ); Tue, 28 Apr 2020 14:54:21 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3438C03C1AB for ; Tue, 28 Apr 2020 11:54:21 -0700 (PDT) Received: from p5de0bf0b.dip0.t-ipconnect.de ([93.224.191.11] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jTVMo-0002sR-0A; Tue, 28 Apr 2020 20:54:02 +0200 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id 40B54100FC0; Tue, 28 Apr 2020 20:54:01 +0200 (CEST) From: Thomas Gleixner To: "Jacob Pan \(Jun\)" Cc: Fenghua Yu , Ingo Molnar , Borislav Petkov , H Peter Anvin , David Woodhouse , Lu Baolu , Dave Hansen , Tony Luck , Ashok Raj , Dave Jiang , Sohil Mehta , Ravi V Shankar , linux-kernel , x86 , iommu@lists.linux-foundation.org, jacob.jun.pan@intel.com Subject: Re: [PATCH 5/7] x86/mmu: Allocate/free PASID In-Reply-To: <20200428112113.000033bd@intel.com> References: <1585596788-193989-1-git-send-email-fenghua.yu@intel.com> <1585596788-193989-6-git-send-email-fenghua.yu@intel.com> <87pnbus3du.fsf@nanos.tec.linutronix.de> <20200428112113.000033bd@intel.com> Date: Tue, 28 Apr 2020 20:54:01 +0200 Message-ID: <87tv13o306.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Jacob Pan (Jun)" writes: > On Sun, 26 Apr 2020 16:55:25 +0200 > Thomas Gleixner wrote: >> Fenghua Yu writes: >> > The PASID is freed when the process exits (so no need to keep >> > reference counts on how many SVM devices are sharing the PASID). >> >> I'm not buying that. If there is an outstanding request with the PASID >> of a process then tearing down the process address space and freeing >> the PASID (which might be reused) is fundamentally broken. >> > Device driver unbind PASID is tied to FD release. So when a process > exits, FD close causes driver to do the following: > > 1. stops DMA > 2. unbind PASID (clears the PASID entry in IOMMU, flush all TLBs, drain > in flight page requests) Fair enough. Explaining that somewhere might be helpful. > For bare metal SVM, if the last mmdrop always happens after FD release, > we can ensure no outstanding requests at the point of ioasid_free(). > Perhaps this is a wrong assumption? If fd release cleans up then how should there be something in flight at the final mmdrop? > For guest SVM, there will be more users of a PASID. I am also > working on adding refcounting to ioasid. ioasid_free() will not release > the PASID back to the pool until all references are dropped. What does more users mean? >> > + if (mm && mm->context.pasid && !(flags & >> > SVM_FLAG_PRIVATE_PASID)) { >> > + /* >> > + * Once a PASID is allocated for this mm, the PASID >> > + * stays with the mm until the mm is dropped. Reuse >> > + * the PASID which has been already allocated for >> > the >> > + * mm instead of allocating a new one. >> > + */ >> > + ioasid_set_data(mm->context.pasid, svm); >> >> So if the PASID is reused several times for different SVMs then every >> time ioasid_data->private is set to a different SVM. How is that >> supposed to work? >> > For the lifetime of the mm, there is only one PASID. svm_bind/unbind_mm > could happen many times with different private data: intel_svm. > Multiple devices can bind to the same PASID as well. But private data > don't change within the first bind and last unbind. Ok. I read through that spaghetti of intel_svm_bind_mm() again and now I start to get an idea how that is supposed to work. What a mess. That function really wants to be restructured in a way so it is understandable to mere mortals. Thanks, tglx