Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp917957pxb; Wed, 29 Sep 2021 12:28:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwv/ecFQcOv3S7UUjqu1u25nruPlkeovi7xi3R9Aa5vhvIhnskzbFsW5ziRQchQjP4NyZtb X-Received: by 2002:a05:6402:847:: with SMTP id b7mr2080507edz.242.1632943722372; Wed, 29 Sep 2021 12:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632943722; cv=none; d=google.com; s=arc-20160816; b=qmX0hSWgzemKBUsZDHjbrQN5+x7SVYtlOsi2lgYMV9NXIXhMPDxHIMBIAaWr5lzGe/ gfGUvutZSytrsXV2CSrHnFkUwRHC99GBr7kJh63llmEvdgFY60fYjNdEgDGuNr5L30Mi s3TeeG4uPWgCE3CRltv6s94lx5xJHq+pMjKHcm/6r3KhiV2d+D4Hh8pFbvSWtHDTWfXi hpniIDV50TLnE1e60cnAdbep9OzGtJ0FVeubNpq0szJMxiQ7LSJDxMCcyO91839K8jRK 4rZZzwSIy163bhGfezXFy28Wiq8ItudNoxRy7wDXfSL4zNLeTQw0wGXx/SobpnUcZp6W rR6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=vaniConmABBbdutP7L0twJbo/66ZWvCQnJpopgzeFNU=; b=WvzQhKMBkG1570z+qKLw7xTm7vDxeoPgeN8aRWKTyW/dx5YDMR/Z2Y3oTBBrgT18tk z3u/A8Vp5bzf12fwmvDA5IBQqG6s5kINVDBMGvWxNP7zzb3tD0y6/JwAXMW3A2o5pOAD dN7xbta3LvwrhFwfPLaGUyKgC/LTfOOwA/gegY43Hx5I6j+JJyH2ypV4dmBYwr5C/m57 onevJOTJoFhYCYV4wBYJopbRSUIwa1yurH/ZXjNan1cyzqUfCx6SQyNEObmq4TKFNJrM KB87g52Ar8suaB3zARb1m+sGVXM7U7hwJHANnhUdV3OcJ5TSQOqfy3VVI3VFpIVGGbry esQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JUXaf/PU"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz15si812353ejc.86.2021.09.29.12.28.12; Wed, 29 Sep 2021 12:28:42 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JUXaf/PU"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344888AbhI2RB0 (ORCPT + 99 others); Wed, 29 Sep 2021 13:01:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:53226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344809AbhI2RBZ (ORCPT ); Wed, 29 Sep 2021 13:01:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 40053613D1; Wed, 29 Sep 2021 16:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632934783; bh=NIb8p1udmU2cyyxgdKTASy2CHdIukYGs/zoSTQfFkTo=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=JUXaf/PU8zljz7WC6Nq05HvgArXrLqToUQ1ZwS6h6AisXMXNfCYy1rRmH/E9gILcm fBe8b58GTWuoDqSGlWgsbKMZAX0BSNwQBPuQgZ+yIlXKCSA7MUZkL1fqld8f8nY3JK 72grjrOBGxS4d74bnNQ2kyZR8nSEZ9PmcUSts6Janc2AADE1d/g/ZcZ8MNvkxc4OuX lIFCscyzIf6jaD200C6wFbHJ9qEUj/lzukmjwSpfBAdRsZmrko55fyRgg62RhP/0no AHV/HzoAzi8A/LxCNU+iYq3GB2898pCWft87k/IL9O5AGmVIyiZlwXLhUeUxjs2Gtp QcK7gWdplJdNw== Message-ID: <75e95acc-6730-ddcf-d722-66e575076256@kernel.org> Date: Wed, 29 Sep 2021 09:59:42 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting Content-Language: en-US To: Thomas Gleixner , Peter Zijlstra Cc: Tony Luck , Fenghua Yu , Ingo Molnar , Borislav Petkov , 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 References: <20210920192349.2602141-1-fenghua.yu@intel.com> <20210920192349.2602141-6-fenghua.yu@intel.com> <87y27nfjel.ffs@tglx> <87o88jfajo.ffs@tglx> <87k0j6dsdn.ffs@tglx> <87r1d78t2e.ffs@tglx> From: Andy Lutomirski In-Reply-To: <87r1d78t2e.ffs@tglx> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/29/21 05:28, Thomas Gleixner wrote: > On Wed, Sep 29 2021 at 11:54, Peter Zijlstra wrote: >> On Fri, Sep 24, 2021 at 04:03:53PM -0700, Andy Lutomirski wrote: >>> I think the perfect and the good are a bit confused here. If we go for >>> "good", then we have an mm owning a PASID for its entire lifetime. If >>> we want "perfect", then we should actually do it right: teach the >>> kernel to update an entire mm's PASID setting all at once. This isn't >>> *that* hard -- it involves two things: >>> >>> 1. The context switch code needs to resync PASID. Unfortunately, this >>> adds some overhead to every context switch, although a static_branch >>> could minimize it for non-PASID users. >> >>> 2. A change to an mm's PASID needs to sent an IPI, but that IPI can't >>> touch FPU state. So instead the IPI should use task_work_add() to >>> make sure PASID gets resynced. >> >> What do we need 1 for? Any PASID change can be achieved using 2 no? >> >> Basically, call task_work_add() on all relevant tasks [1], then IPI >> spray the current running of those and presto. >> >> [1] it is nigh on impossible to find all tasks sharing an mm in any sane >> way due to CLONE_MM && !CLONE_THREAD. > > Why would we want any of that at all? > > Process starts, no PASID assigned. > > bind to device -> PASID is allocated and assigned to the mm > > some task of the process issues ENQCMD -> #GP -> write PASID MSR > > After that the PASID is saved and restored as part of the XSTATE and > there is no extra overhead in context switch or return to user space. > > All tasks of the process which did never use ENQCMD don't care and their > PASID xstate is in init state. > > There is absolutely no point in enforcing that all tasks of the process > have the PASID activated immediately when it is assigned. If they need > it they get it via the #GP fixup and everything just works. > > Looking at that patch again, none of this muck in fpu__pasid_write() is > required at all. The whole exception fixup is: > > if (!user_mode(regs)) > return false; > > if (!current->mm->pasid) > return false; > > if (current->pasid_activated) > return false; <-- preemption or BH here: kaboom. > > wrmsrl(MSR_IA32_PASID, current->mm->pasid); This needs the actual sane fpstate writing helper -- see other email.