Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4307874pxb; Mon, 27 Sep 2021 14:06:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLiOSMOZRSPL8GIt0KCQt0yv24x7l5bcMJ1Iof1jMC6LxcLkOaQdwutCWBBmP9cFCV/V6v X-Received: by 2002:a17:906:b782:: with SMTP id dt2mr2580222ejb.310.1632776802209; Mon, 27 Sep 2021 14:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632776802; cv=none; d=google.com; s=arc-20160816; b=pHu5lds6aM+57z6PgqLCMXIlOMRXW9lvh+X9kclibNoYIbKo2vPyCLLNZEWqjjucLd eKWZMYV0z61alfr7xZPsSj/3C7uhUsBehMlM6ZqmmIFaYRWUSDj+MnDg4LBViVOC8h6U 0zU7QOhey9iPuXbO4vBAhzx06vT4XwFFYB6Ai9f+EFtocjphMkROnt/3BEKiP5kQiA8R okw0OqY4QPEjInymxsulmebwdb1I7UVAlqvLHfUBz5NaKMbRSnftoPD7wsTiRl4z1F/4 xY3KUToBsf6WJtvo3+KCKuNvKkSBo921dGCVg/l/q6WMggf9iQAQyybvfhGDJNJHSYqD v2tw== 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=Gafj98+d8La0Urp+PTgzM1VUtkYXgw1pOV31N3u3HAs=; b=kcnGV1zJBPt2a+11ncphtIVp2039cbj9/mRZM+RKCX9XQD1hz42gcztxFIPxqLm68l jFect5QbbdOTxd7pZxtVr9Aw25UMPT0B1j2VRd7IQ7MNQn9jgmTwRBcWVbe/uvKeQtNQ eBT1P4bUmjMdF7WL6ndipSaes7l4nbvfYy6lPTnheP/umYRQL7mRDo0skeLgMIGIzNru Z2XkuFAL+OEhrA/V7xmiTOs634pQ077wIUcjgv9g4EclBE1ihS9mRxyIz6Ej5+OWvHeb HbR9MkeejkCrtQvKcli9fWxGCzbyypdPGv+63LBMvG8yemBdqp//J+JbUZfd8rDbs0fo fVeg== 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 27si19031760ejr.209.2021.09.27.14.06.18; Mon, 27 Sep 2021 14:06: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; 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 S236743AbhI0VE3 (ORCPT + 99 others); Mon, 27 Sep 2021 17:04:29 -0400 Received: from mga09.intel.com ([134.134.136.24]:13996 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237016AbhI0VE2 (ORCPT ); Mon, 27 Sep 2021 17:04:28 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10120"; a="224599680" X-IronPort-AV: E=Sophos;i="5.85,327,1624345200"; d="scan'208";a="224599680" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2021 14:02:50 -0700 X-IronPort-AV: E=Sophos;i="5.85,327,1624345200"; d="scan'208";a="518731694" 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; 27 Sep 2021 14:02:50 -0700 Date: Mon, 27 Sep 2021 14:02:48 -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 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> <1aae375d-3cd4-4ab8-9c64-9e387916e6c0@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1aae375d-3cd4-4ab8-9c64-9e387916e6c0@www.fastmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 23, 2021 at 04:17:05PM -0700, Andy Lutomirski wrote: > > + fpregs_lock(); > > + > > + /* > > + * If the task's FPU doesn't need to be loaded or is valid, directly > > + * write the IA32_PASID MSR. Otherwise, write the PASID state and > > + * the MSR will be loaded from the PASID state before returning to > > + * the user. > > + */ > > + if (!test_thread_flag(TIF_NEED_FPU_LOAD) || > > + fpregs_state_valid(fpu, smp_processor_id())) { > > + wrmsrl(MSR_IA32_PASID, msr_val); > > Let me try to decode this. > > If the current task's FPU state is live or if the state is in memory but the CPU regs just happen to match the copy in memory, then write the MSR. Else write the value to memory. > > This is wrong. If !TIF_NEED_FPU_LOAD && fpregs_state_valid, you MUST NOT MODIFY FPU STATE. This is not negotiable -- you will break coherence between CPU regs and the memory image. The way you modify the current task's state is either you modify it in CPU regs (if the kernel knows that the CPU regs are the one and only source of truth) OR you modify it in memory and invalidate any preserved copies (by zapping last_cpu). > > In any event, that particular bit of logic really doesn't belong in here -- it belongs in some helper that gets it right, once. Andy, A helper sounds like a good idea. Can you flesh out what you would like that to look like? Is it just the "where is the live register state?" so the above could be written: if (xsave_state_in_memory(args ...)) update pasid bit of xsave state in memory else wrmsrl(MSR_IA32_PASID, msr_val); Or are you thinking of a helper that does both the check and the update ... so the code here could be: update_one_xsave_feature(XFEATURE_PASID, &msr_val, sizeof(msr_val)); With the helper being something like: void update_one_xsave_feature(enum xfeature xfeature, void *data, size_t size) { if (xsave_state_in_memory(args ...)) { addr = get_xsave_addr(xsave, xfeature); memcpy(addr, data, size); xsave->header.xfeatures |= (1 << xfeature); return; } switch (xfeature) { case XFEATURE_PASID: wrmsrl(MSR_IA32_PASID, *(u64 *)data); break; case each_of_the_other_XFEATURE_enums: code to update registers for that XFEATURE } } either way needs the definitive correct coding for xsave_state_in_memory() -Tony