Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp767526lkm; Wed, 22 Sep 2021 14:30:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPpN1to1SN6it31lfFrFxRzPF8hRNpIFlJZ5nLNAPljR52a5qYy+/D60/+XdBFK2PRf3JP X-Received: by 2002:a05:6402:697:: with SMTP id f23mr1627032edy.253.1632346228043; Wed, 22 Sep 2021 14:30:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632346228; cv=none; d=google.com; s=arc-20160816; b=YX2Zo0d6dcxrf9SO1rLSPenxaK9Fcx9ktI6p5N+Koxaf1XWLmaR2HQ1atb3GUNjUlb Xa/hPTVMD1UQz/XW/rQU/5NZlVORUJayQH5ybnme1JmG5I2sVqdlYRfYfhT+Al5xdTZP KLuoeIBihN48K6Wz1I+1rIKsc5c5lJhLGwze4JtJLlpw554uaLErouzx8qhOS7h5YzMZ YKEq2VQpy6DfiH/JrR8DWdpBmyMHjTQBicZTMLw/NqZsDtDUWhUKVFFdJBl21O9R+y2g KoGhp9PAbIQTfRKKzVS3E0icwiYniQaf4E6gLkwPZvSdbwfZ+GVfimJaGkACjvSW13TU HnLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :dlp-version:dlp-reaction:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=6EVRtUxc83ovI6oM3dZQcOTOoEiuxXG2Ij4TmmOzg0E=; b=xCNPrsyDMO6zIcc+UCED1/mvnqy8cUDbIGylt+GRQ0JTkGPs7HkI2+IWFOgYpeZAlI NpKkKiyp5yvhqcRqoj5c7tDiilH62h6CZL/Vp56/bw8FmZQLc4+y2u9ckZQPncTN0Owo Zw9wyg4BVEw1mdrizZXkpYPnsTjJFl36drOV7N8LoNXST/pTJhpCeQJpBCG1R0JBFu5k 03tNentklxRxEAnxUV52ay3KJ0fGhLbv0jYWsnJIXrSrI943egaS9KjLxggqgSlFsiGu ++R3Hx9ABfVjdpKlZM1Wq83K2sBpjv+NhhVOtlK3+qleZg9yLRHL+CunwLM1ySz5VmKY 5UvA== 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 j3si4422296ejj.448.2021.09.22.14.30.02; Wed, 22 Sep 2021 14:30:28 -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 S237927AbhIVV1o convert rfc822-to-8bit (ORCPT + 99 others); Wed, 22 Sep 2021 17:27:44 -0400 Received: from mga17.intel.com ([192.55.52.151]:18706 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237802AbhIVV1n (ORCPT ); Wed, 22 Sep 2021 17:27:43 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10115"; a="203859611" X-IronPort-AV: E=Sophos;i="5.85,315,1624345200"; d="scan'208";a="203859611" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 14:26:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,315,1624345200"; d="scan'208";a="435587347" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga006.jf.intel.com with ESMTP; 22 Sep 2021 14:26:11 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Wed, 22 Sep 2021 14:26:10 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Wed, 22 Sep 2021 14:26:10 -0700 Received: from fmsmsx610.amr.corp.intel.com ([10.18.126.90]) by fmsmsx610.amr.corp.intel.com ([10.18.126.90]) with mapi id 15.01.2242.012; Wed, 22 Sep 2021 14:26:10 -0700 From: "Luck, Tony" To: Peter Zijlstra , "Yu, Fenghua" CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "Hansen, Dave" , Lu Baolu , "Joerg Roedel" , Josh Poimboeuf , "Jiang, Dave" , "Pan, Jacob jun" , "Raj, Ashok" , "Shankar, Ravi V" , "iommu@lists.linux-foundation.org" , x86 , linux-kernel Subject: RE: [PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP Thread-Topic: [PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP Thread-Index: AQHXrlppUXtiT4Ul9UCq0y1lpkQn1quxBE8AgAABOoD//4u5UA== Date: Wed, 22 Sep 2021 21:26:10 +0000 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> In-Reply-To: <20210922211145.GF5106@worktop.programming.kicks-ass.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 x-originating-ip: [10.1.200.100] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >> > +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? It can't reliably do that because some other thread in the process may have re-written the memory that regs->ip points at (bizarre case, but I think Dave Hansen brought it up). So it would just add extra code, and still only be a hint. Without the check this sequence is possible: 1) Process binds an accelerator (so mm->pasid is set) 2) Task in the process executes something other than ENQCMD that gets a #GP 3) Kernel says "Oh, mm->pasid is set, I'll initialize the IA32_PASID MSR to see if that fixes it" 4) Nope. Re-executing the instruction at step #2 just gives another #GP 5) Kernel says "I already set IA32_PASID, so this must be something else ... do regular #GP actions" Now if the task catches the signal that results from step #5 and avoids termination, it will have IA32_PASID set ... but to the right value should it go on to actually execute ENQCMD at some future point. So the corner case from not knowing whether this #GP was from ENQCMD or not is harmless. -Tony