Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp318003pxb; Thu, 23 Sep 2021 00:07:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzESU/VbZkAO++skf51LqpZd4hRHbb9rBchRAgfqx8UKtWXYInVpqdCxMkAqSwErQ5OnxAy X-Received: by 2002:a17:906:1e0c:: with SMTP id g12mr3494171ejj.155.1632380879339; Thu, 23 Sep 2021 00:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632380879; cv=none; d=google.com; s=arc-20160816; b=ErFvqspqi3ooVrfdSzG6NhU4cgjLbxwZDUrkIaIDEttPvZ7D29P+nV5SQzU9fnaeoc hiuUuii1LCnASzLgLU4W8+Rgruj77m+yuUqQdLPJ/CoW/SHtvEjvouaASwM68iIGCHTE eoKKwUPjiVFsU8e+9x77RaDGp/ZVRMEwQRnmn4FdNL69SifH9oL+qurqPlUMF5tL0CGm 1Bn//ntxvBsNvPSyob/ctxwFEL/Am0MkzDPkTtagszVOrKAZIbBLVztQz1oVWN32v13/ wv46Jz+ol2xvM77SLW1tZzpnUTNGmPw6X9VYtVO3HsNFMu1RwvZY+B57PudKpUiG6MRb xkZA== 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=MKyCSBe17569FQKUN9uYPzsBrtR6yhh1quExeWYo6x0=; b=HwxyR1P1optQ5IxmIv+Wcv2qkrEMq6Rb7U6Heozvs+pHV5lxvEFlPFYaEl3Dmob2FG o9QHZt/2uP1JkyPHxN23zTu7iPGm/y0/a7owsuBmIggHwcIY8QM1lZVre+f1LhJ3hVRv tN2dR95OotVqDl8/yLbE036ktusEeIR+Z179gqTmYw4sdx9R5a13e4gMdDJcec4kiO+w 2+BWsmdAzhyrRmI8rVMANOU9f2XBJB7DxStGePtNLRMWB7Wie83JYviymcPIXaBabv+b 8Zwcx2mEhU/vDrSVuKimPdTBfQi87zKrK2IDCmjAKN6XDyw5OWif5+/pwBBjUbIR717d B53Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Gpo+PfTG; 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 w10si6293447ejv.754.2021.09.23.00.07.11; Thu, 23 Sep 2021 00:07:59 -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=@infradead.org header.s=desiato.20200630 header.b=Gpo+PfTG; 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 S239523AbhIWHGt (ORCPT + 99 others); Thu, 23 Sep 2021 03:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239358AbhIWHGs (ORCPT ); Thu, 23 Sep 2021 03:06:48 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 852AAC061574 for ; Thu, 23 Sep 2021 00:05:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MKyCSBe17569FQKUN9uYPzsBrtR6yhh1quExeWYo6x0=; b=Gpo+PfTGtMC8bYFUnWTsGSG9j4 s0FMMEqMgrIKFtOlEb1F7pdyyPMDdV/ByQsx8MU5bOf0DloJ2sUkVZzUHKyZmltUO7uj6Gvp16LFJ HzH1RQJch2GuXtgFu25vuzUer5+PypWZps9jjdO38l7Ts0bHfeFcfLuVmWBxvwGbyu/eexrndoLOm 7Zdm0mQJizR2xX/uV+yvZWC6rVtg8r/VufBfqnFYKOVN//+5UnOyeVvQjC6pm9Og67M3R7tJ2Vbpm H21id5PPRfLhs+xu2hrA483NLoPQ0CeOjeb8Tdk/BW53H313pr55NgNPo8HpRQfHxdyjaNdUox+ki 9A9HDhZQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTImz-005AUz-Fy; Thu, 23 Sep 2021 07:05:01 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 1631C300250; Thu, 23 Sep 2021 09:05:01 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F102F2C0D22ED; Thu, 23 Sep 2021 09:05:00 +0200 (CEST) Date: Thu, 23 Sep 2021 09:05:00 +0200 From: Peter Zijlstra To: Dave Hansen Cc: Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Tony Luck , 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 4/8] x86/traps: Demand-populate PASID MSR via #GP Message-ID: References: <20210920192349.2602141-1-fenghua.yu@intel.com> <20210920192349.2602141-5-fenghua.yu@intel.com> <20210922210722.GV4323@worktop.programming.kicks-ass.net> <20210922211145.GF5106@worktop.programming.kicks-ass.net> 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 Wed, Sep 22, 2021 at 02:33:09PM -0700, Dave Hansen wrote: > On 9/22/21 2:11 PM, Peter Zijlstra wrote: > >>> +static bool fixup_pasid_exception(void) > >>> +{ > >>> + if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) > >>> + return false; > >>> + > >>> + return __fixup_pasid_exception(); > >>> +} > > That is, shouldn't the above at the very least decode the instruction > > causing the #GP and check it's this ENQCMD thing? > > To reiterate: on systems with no X86_FEATURE_ENQCMD, there is basically > no additional overhead. It isn't worth doing decoding there. Well, they won't get past the X86_FEATURE check anyway, so who cares. > On systems with X86_FEATURE_ENQCMD, but where it is unused, the #GP > handler gets some new overhead on every #GP. Basically: > > > + pasid = current->mm->pasid; > > + if (pasid == PASID_DISABLED) > > + return false; > > That's still pretty cheap. Probably not worth doing decoding there either. > > So, that leaves us with if you are: > 1. On system with X86_FEATURE_ENQCMD > 2. In a process/mm that has an allocated pasid > 3. Your *task* does not have the MSR set > 4. You get a #GP for some other reason > > Then, you'll do this double-#GP dance. > > So, instruction decoding could absolutely be added between steps 3 and > 4. It would absolutely save doing the double-#GP in cases where 1/2/3 > are met. But, I wouldn't move it up above and of the 1/2/3 checks > because they're way cheaper than instruction decoding. > > In the end, it didn't seem worth it to me to be optimizing a relatively > rare path which 99% of the time ends up in a crash. > > If you want instruction decoding in here, though, just say the word. :) Instruction deoding makes it obvious you only consume your own #GP, the alternative is a comment that explains this reasoning. Having neither gets you confusion as per this thread.