Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1028257pxb; Thu, 23 Sep 2021 16:24:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzot+6qVIPtpo0Y3JT9p5wHWQXZlCggdGsUDAf77EnOQB6OvQ/iDAUhLRX/DtYVko5rOJT5 X-Received: by 2002:a50:8226:: with SMTP id 35mr1724517edf.81.1632439467953; Thu, 23 Sep 2021 16:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632439467; cv=none; d=google.com; s=arc-20160816; b=NiwW2cOINIkbDOyR3yUUhyyOog1eKw2L3UzBuxLO3saUpYYWCNT0SN+tarY6f/iEUm V5as3CJFc+iwpOnxumzZiOqZapmIaFWT8bsJuopMcrZZtTeEL54FVyRAQm0ig0KQJzfX RGN3uAt7C6g/AtMrV08QSPkIuv7hmxFUK5Ty22vjWUqT7KLxUScHGaiQOwHBz2qNEgWd tSKIhuoTfUFJn4GXhILQOlM/DEgxbvG6WdLSClYHgK0Q2oCx/Aj7rXRmv5N73q297Rmq T09e+6ovitd1wJJLnMFQ/WGTfkky5MAaudSqFfdKLArv0sRqjX8o2r3C9KFG9/O0n9bR mI9Q== 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=8OG4jLz6KJdZP/9rPpcUJ9E5wxkQdqF3rYBYMu3AcIk=; b=m4ODwm/Qff3CbFqRcsBHReI+v2yTJzOiqxlKUGt6HFNozyzxaR4gYCnN97C/3BHz/S FEArehBNtzXfu4+5teQhYijqghBFLvy4B0JGG6r+MFWnr7U9QNhWadBQT1SQchCjb5mO Ln0afbBHZM9XRyXnWdvtwOCXbtgkCM0Vz9XgUHMEnwg5Q/lxVclvHydZxgFax0yQ0+3u cU6XeROgInvfo02ffOR8wWP/dLtmdwgTg3PltGAOrfD5F/QS5x3/aker+0pudVDYTBKM 7no5cNKhO/ZDo4Ozi+/DCMG24CJ73sk4HE3abDQmflmJi6OyjLgwqPhOGsBBJjWNzuSB /H3w== 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 f17si7958559ejt.20.2021.09.23.16.24.03; Thu, 23 Sep 2021 16:24:27 -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 S243400AbhIWXYK (ORCPT + 99 others); Thu, 23 Sep 2021 19:24:10 -0400 Received: from mga06.intel.com ([134.134.136.31]:38482 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235628AbhIWXYJ (ORCPT ); Thu, 23 Sep 2021 19:24:09 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10116"; a="284976067" X-IronPort-AV: E=Sophos;i="5.85,318,1624345200"; d="scan'208";a="284976067" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2021 16:22:37 -0700 X-IronPort-AV: E=Sophos;i="5.85,318,1624345200"; d="scan'208";a="514303216" Received: from agluck-desk2.sc.intel.com (HELO agluck-desk2.amr.corp.intel.com) ([10.3.52.146]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2021 16:22:37 -0700 Date: Thu, 23 Sep 2021 16:22:35 -0700 From: "Luck, Tony" To: Andy Lutomirski Cc: Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Peter Zijlstra (Intel)" , Dave Hansen , Lu Baolu , Joerg Roedel , Josh Poimboeuf , Dave Jiang , Jacob Jun Pan , Raj Ashok , "Shankar, Ravi V" , iommu@lists.linux-foundation.org, the arch/x86 maintainers , Linux Kernel Mailing List 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 23, 2021 at 04:09:18PM -0700, Andy Lutomirski wrote: > On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > I think this is unnecessarily complicated because it's buying in to the > existing ISA misconception that PASID has anything to do with a task. > A PASID belongs to an mm, full stop. Now the ISA is nasty and we have > tasks that have *noticed* that their mm has a PASID and tasks that have > not noticed this fact, but that should be irrelevant to essentially > everything except the fault handler. > > So just refcount the thing the obvious way: take a reference when you > stick the PASID in the mm_struct and drop the reference in __mmdrop(). > Problem solved. You could probably drop it more aggressively in > __mmput(), and the comment explaining why is left as an exercise to the > reader -- if a kernel thread starts doing ENQCMD, we have worse things > to worry about :) That doesn't match well with the non-x86 usage of PASIDs. The code there bumps the reference count on each device bind, and decrements on each device unbind. If we don't keep a reference count for each task that has IA32_PASID set up we could have this sequence 1) Process binds to a PASID capable device 2) Task uses ENQCMD, so PASID MSR is set up. 3) Process unbinds the device, reference count on PASID goes to zero. PASID is freed. PASID is reallocated to another task. 4) Task from step #2 uses ENQCMD to submit a descriptor and device now processes virtual addresses based on mappings in the new task. Now you might say that at step 3 we need to hunt down all the tasks that have PASID enabled and disabled ... but that's the same painful code that we avoided when we said that we would not make Linux hand out a PASID to all existing tasks in a process on the first bind operation. -Tony