Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2137917pxa; Mon, 3 Aug 2020 08:22:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrRCX4WPEDbcM3C9DmBKtkSXZFMnU7h05I693f3l/VKbseD2qeTAC42Jdms13Vwe2obVC7 X-Received: by 2002:a17:906:af72:: with SMTP id os18mr16830604ejb.43.1596468173546; Mon, 03 Aug 2020 08:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596468173; cv=none; d=google.com; s=arc-20160816; b=t2WQZv1fKS8jbp23x5Ouv0dJk6mIws/QWdE8Q6oemZIe67nuMH5BYzEDZztzff0vQ2 L1e3SR6RP4OWcSBujlJHgNhxhraB50KYXtrdWHXJqr/cfzrNyeBUHJTjrOputrtuHpcT 9kOSpsO/uf3ZnI/D3kViEVUw7Uul+GscSTHWK0UA3cJ8wqyOg/+Fre+1zkfjZeq3UEfZ Eetzs+g5QfqGhodOKNB4VZyDvCD6HahwsyIdyl9nrIjjqvougepGKmL3LGyPLvF8S8b2 NtjKak3oqQsPstsZeGgkhmJxSmLl+vKBHpPl0Msq7DnbIIfLohfVBWAEAU6DlUbmeGLi j/Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=8edKsDJHvbmutTlBeJ7N77EI+dl5pHvbmumaGiGT3mw=; b=C0+uLpwMcbpP43oF0yd5WZlxu2QzOV+cGhqGu9xPahRj0BhWT3vzfO5tA8q9TUbJ/w KjAcbi916Bp8jOQK40f/fOJWBbhaaiZ+vVIfvwxzh0Nj+mRhZD9v6rNMfGQok0xXa8XI foerP7QQ0HzPHyJhHhTWBnuNjaeCWgqhFuEJC6dx4hR7b/nP8KkNXLg3ml8O8q/hADDl 2/v9f5J7h9M7iEt4tpT3fxVOfsvYl/oGQjta4Iu8o11d5NLEIFWCDzI9p8n9CL16hm9g RErN1KbvFC4gdga4f1g8JZAclzAgK9Igjd/xrdO13qg1jH9Jm3oV2pvLPmpKTXVgNcYJ l/rw== 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 d19si10606460ejj.468.2020.08.03.08.22.30; Mon, 03 Aug 2020 08:22:53 -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 S1728048AbgHCPTX (ORCPT + 99 others); Mon, 3 Aug 2020 11:19:23 -0400 Received: from mga06.intel.com ([134.134.136.31]:34140 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgHCPTX (ORCPT ); Mon, 3 Aug 2020 11:19:23 -0400 IronPort-SDR: ON6ovHxlkWgbwAaDcH5vlGsEt8Ba9aPzuDppjUKcxQ0IlsAn54AMNYm6NVpQy/PEvuH07UqmNC ywsn1lcDxuvg== X-IronPort-AV: E=McAfee;i="6000,8403,9702"; a="213653670" X-IronPort-AV: E=Sophos;i="5.75,430,1589266800"; d="scan'208";a="213653670" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2020 08:19:21 -0700 IronPort-SDR: G0CjCKxyQN08Sca20ML1Bsnx7p1bnKn36NhasF0+OG9kDqMZzCPmnowotiPrSoudbZAq71rwjl YBYDIsTbgPxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,430,1589266800"; d="scan'208";a="305870584" Received: from otc-nc-03.jf.intel.com (HELO otc-nc-03) ([10.54.39.25]) by orsmga002.jf.intel.com with ESMTP; 03 Aug 2020 08:19:21 -0700 Date: Mon, 3 Aug 2020 08:19:21 -0700 From: "Raj, Ashok" To: Andy Lutomirski Cc: Dave Hansen , Fenghua Yu , Thomas Gleixner , Joerg Roedel , Ingo Molnar , Borislav Petkov , Peter Zijlstra , H Peter Anvin , David Woodhouse , Lu Baolu , Felix Kuehling , Tony Luck , Jean-Philippe Brucker , Christoph Hellwig , Jacob Jun Pan , Dave Jiang , Sohil Mehta , Ravi V Shankar , linux-kernel , x86 , iommu , amd-gfx , Ashok Raj Subject: Re: [PATCH v6 12/12] x86/traps: Fix up invalid PASID Message-ID: <20200803151921.GA387967@otc-nc-03> References: <1594684087-61184-1-git-send-email-fenghua.yu@intel.com> <1594684087-61184-13-git-send-email-fenghua.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 03, 2020 at 08:12:18AM -0700, Andy Lutomirski wrote: > On Mon, Aug 3, 2020 at 8:03 AM Dave Hansen wrote: > > > > On 7/31/20 4:34 PM, Andy Lutomirski wrote: > > >> Thomas suggested to provide a reason for the #GP caused by executing ENQCMD > > >> without a valid PASID value programmed. #GP error codes are 16 bits and all > > >> 16 bits are taken. Refer to SDM Vol 3, Chapter 16.13 for details. The other > > >> choice was to reflect the error code in an MSR. ENQCMD can also cause #GP > > >> when loading from the source operand, so its not fully comprehending all > > >> the reasons. Rather than special case the ENQCMD, in future Intel may > > >> choose a different fault mechanism for such cases if recovery is needed on > > >> #GP. > > > Decoding the user instruction is ugly and sets a bad architecture > > > precedent, but we already do it in #GP for UMIP. So I'm unconvinced. > > > > I'll try to do one more bit of convincing. :) > > > > In the end, we need a way to figure out if the #GP was from a known "OK" > > source that we can fix up. You're right that we could fire up the > > instruction decoder to help answer that question. But, it (also) > > doesn't easily yield a perfect answer as to the source of the #GP, it > > always involves a user copy, and it's a larger code impact than what > > we've got. > > > > I think I went and looked at fixup_umip_exception(), and compared it to > > the alternative which is essentially just these three lines of code: > > > > > + /* > > > + * If the current task already has a valid PASID in the MSR, > > > + * the #GP must be for some other reason. > > > + */ > > > + if (current->has_valid_pasid) > > > + return false; > > ...> + /* Now the current task has a valid PASID in the MSR. */ > > > + current->has_valid_pasid = 1; > > > > and *I* was convinced that instruction decoding wasn't worth it. > > > > There's a lot of stuff that fixup_umip_exception() does which we don't > > have to duplicate, but it's going to be really hard to get it anywhere > > near as compact as what we've got. > > > > I could easily be convinced that the PASID fixup is so trivial and so > obviously free of misfiring in a way that causes an infinite loop that > this code is fine. But I think we first need to answer the bigger > question of why we're doing a lazy fixup in the first place. We choose lazy fixup for 2 reasons. - If some threads were already created before the MSR is programmed, then we need to fixup those in a race free way. scheduling some task-work etc. We did do that early on, but decided it was ugly. - Not all threads need to submit ENQCMD, force feeding the MSR probably isn't even required for all. Yes the overhead isn't probably big, but might not even be required for all threads. We needed to fixup MSR in two different way. To keep the code simple, the choice was to only fixup on #GP, that eliminated the extra code we need to support case1. Cheers, Ashok