Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp744573pxb; Thu, 23 Sep 2021 09:42:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyD3bc8LM2rcjwoMTV4JF5vDyE1xmw+u9oS+jH9VxrA1akvbtF66UYco9xHSXfzQC1SV5/2 X-Received: by 2002:a05:6638:dcc:: with SMTP id m12mr4955572jaj.68.1632415328883; Thu, 23 Sep 2021 09:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632415328; cv=none; d=google.com; s=arc-20160816; b=RTOwXT2VYr+HniHvM0HTZ23x5+rjnJVzVjHMqWbYT5/DaNyYY2A7TeEdvhCThgA34K Nwv4ApAy+tbHEFohoumhDpjBUqaiVfv6714K0TNKdzpk0gsRkRctaiJXKKDBlzqapwV1 ME01cEa+KLWB9xS47QJBXknb2PK1XTMllEg+k2lOYSmONDgyIBk0WRfKVLH23YNkAS4j 8SR02ooNjcqmDUCUlvOoo1Ceor4bKXmf64Ry0OqJmwZcQJLnf9pkwyA+7/ZLkkGaFlih 90k5CgUmG7sWzsLalA/lMMEkkCs1gyR3ivesHK28gCKnkckK1sgR2wFjtbAHpi99w37M OR2A== 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; bh=KCYH98pzoIvAn/LTlEhrH5nwXjXZtQCyfVcjrKd5+Tc=; b=d9WMZVJ6/0BPZUp9TSGix6UXf3mWu78PWqZOhsNt9uNCkqni4tjdYqFQ7iM5d5p9Uj /cGjubFv0v2ppvoFfm45DPo4zypXrAcY5E6HvyaboNdRdXcGvAO1eAz8sJc1HrGQS/7m gv7PRXGd+tj4Il4JMuwI+iyEdtFo3veGFyQNJmCb/5DihNxI0oQedCOUy17D91nJ8sGU 2boM4S4GcJWYPOvG0bkVxsLYFV30ko4uX5Ufj9dxzjC4q9Ym9AbKT4Rue9pG3h/I68T3 9FlJPkXTnfSpBVrIKYzAsVEvSx/WLpdvHz1jZOylOJTW7XpgNb8Wzz+AoM4S79TcKV4J Wr0A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z9si7872225ile.172.2021.09.23.09.41.51; Thu, 23 Sep 2021 09:42:08 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242154AbhIWQm0 (ORCPT + 99 others); Thu, 23 Sep 2021 12:42:26 -0400 Received: from mga06.intel.com ([134.134.136.31]:64344 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233964AbhIWQmY (ORCPT ); Thu, 23 Sep 2021 12:42:24 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10116"; a="284901791" X-IronPort-AV: E=Sophos;i="5.85,316,1624345200"; d="scan'208";a="284901791" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2021 09:40:52 -0700 X-IronPort-AV: E=Sophos;i="5.85,316,1624345200"; d="scan'208";a="551214763" Received: from agluck-desk2.sc.intel.com (HELO agluck-desk2.amr.corp.intel.com) ([10.3.52.146]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2021 09:40:51 -0700 Date: Thu, 23 Sep 2021 09:40:50 -0700 From: "Luck, Tony" To: Thomas Gleixner Cc: Fenghua Yu , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , Dave Hansen , Lu Baolu , Joerg Roedel , Josh Poimboeuf , Dave Jiang , Jacob Jun Pan , Ashok Raj , Ravi V Shankar , iommu@lists.linux-foundation.org, x86 , linux-kernel Subject: Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting Message-ID: References: <20210920192349.2602141-1-fenghua.yu@intel.com> <20210920192349.2602141-6-fenghua.yu@intel.com> <87y27nfjel.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87y27nfjel.ffs@tglx> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 23, 2021 at 04:36:50PM +0200, Thomas Gleixner wrote: > On Mon, Sep 20 2021 at 19:23, Fenghua Yu wrote: > > > > +#ifdef CONFIG_INTEL_IOMMU_SVM > > +void pasid_put(struct task_struct *tsk, struct mm_struct *mm); > > +#else > > +static inline void pasid_put(struct task_struct *tsk, struct mm_struct *mm) { } > > +#endif > > This code is again defining that PASID is entirely restricted to > INTEL. It's true, that no other vendor supports this, but PASID is > a non-vendor specific concept. > > Sticking this into INTEL code means that any other PASID implementation > has to rip it out again from INTEL code and make it a run time property. > > The refcounting issue should be the same for all PASID mechanisms which > attach PASID to a mm. What's INTEL specific about that? > > So can we pretty please do that correct right away? It's a bit messy (surprise). There are two reasons to hold a refcount on a PASID 1) The process has done a bind on a device that uses PASIDs This one isn't dependent on Intel. 2) A task within a process is using ENQCMD (and thus holds a reference on the PASID because IA32_PASID MSR for this task has the PASID value loaded with the enable bit set). This is (currently) Intel specific (until others implement an ENQCMD-like feature to allow apps to access PASID enabled devices without going through the OS). Perhaps some better function naming might help? E.g. have a task_pasid_put() function that handles the process exit case separatley from the device unbind case. void task_pasid_put(void) { if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) return; if (current->has_valid_pasid) { mutex_lock(&pasid_mutex); iommu_sva_free_pasid(mm); mutex_unlock(&pasid_mutex); } } -Tony