From nobody Fri Jan 27 17:45:14 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P3Q2f6GZYz3bLc8; Fri, 27 Jan 2023 17:45:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P3Q2f5kq6z3vt7; Fri, 27 Jan 2023 17:45:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674841514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vrx+CpygeF9lgba1Jvw7JVm1l4c2zlqCS275Xjc6LMc=; b=XIgD2aqfBSf7zdW+nsanLAQOjoBWcq3Wz6Kwi8JDDsJ3ZFhUbhR9d2IITuBzeGMHVAkKKf W6ubL3XRKKIU936g2bPrFhGcP4YUlepyn11ymSvoGl1C4dqCOY0dGbdPsqfecwpeJ8sw/Y GpLe36TR2wu0aslraJnqPlhwbtjQ07IZM6DsS43PXAsOZzX93kocS/sDEmzZEXsYKczCIn 8oNPJGnk+mJaQqKukCe8/UzREenQa98TfXgR49wmWoq/QEh7thKlRn5ZOapAG+azM9TDUm nI1Unqc7pCU98EKGZiL4L+Z6rA/DFee9F+FQbXgAZRNhP14TFfpnShm4MkER2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674841514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vrx+CpygeF9lgba1Jvw7JVm1l4c2zlqCS275Xjc6LMc=; b=rUE6UWgxR3no7Rw8O3rJC6yCnoW/1beJ+p/axvgZyANV5crHY+p3wwmwhP0gfrqJFd+/Om qlNF0mbHpx/dLP3HyPUKTK0HZkWNUtWKPiv9yN8PBaKc56/5roZvgtnc6yOR9a3uSyBdSf WscdCg3SEduzrHsmbpylI1l97dox8an+iYJgSQ7zaKvuDpn7zgOQWoSnNe8tNWsIbSaOCi nCd+ZUM0RSbMivAwVtb7zRFN7ZyMx9+L1je1Np5Mj6fBW6yaYYcmcFRbSfCxvGgMOPQ0ky 6ZQt7dN3aAf161gCrAlMC9IZOgIU3NKxex/8Oos410fnH16E4eBevZHY6WqL5A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674841514; a=rsa-sha256; cv=none; b=BPXRDLBkGZMt647gGdwmiB0kn8whcHtQMSQkB6hN5f7SiiAQcPUBIjZ+R+kxQ0ceTMsCnA qWfFqwY+baCNOGZZxrmG4V/cpaKCzGbImnjFN7GFS1DkoVnoHl33EPUrq50P79OlGAIUC+ lTRIGhqQPbzNTYXsocM+GQSNFcJbDk3NBQRvvzGTXxYG7fV8Ga5E+kVDAheXPNB2qtR8S0 pphSAn3OlXchwnBCMoLUs0TBk1popJGgqrFrbCe41ftXLt/bdpOoohsV0RUs4PZV4eM5En t+mB91/HmnTAyhrqyUCcU/31OZeTpXw+Kq67/pzTuxMqDCvGyyWcVfDyH9nqJQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P3Q2f4rNKzJBb; Fri, 27 Jan 2023 17:45:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30RHjES9085898; Fri, 27 Jan 2023 17:45:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30RHjEnq085897; Fri, 27 Jan 2023 17:45:14 GMT (envelope-from git) Date: Fri, 27 Jan 2023 17:45:14 GMT Message-Id: <202301271745.30RHjEnq085897@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 153643a5bc8a - main - amd64: do not enable PKRU if user disabled saving PKRU register in xsave mask List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 153643a5bc8ac3b1d47fc8e4de18d8c8a59817da Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=153643a5bc8ac3b1d47fc8e4de18d8c8a59817da commit 153643a5bc8ac3b1d47fc8e4de18d8c8a59817da Author: Konstantin Belousov AuthorDate: 2023-01-27 10:45:02 +0000 Commit: Konstantin Belousov CommitDate: 2023-01-27 17:44:49 +0000 amd64: do not enable PKRU if user disabled saving PKRU register in xsave mask This is done by reverting CR4_PKE bit, because we perform %CR4 initialization in initializecpu(), and the function is called before xsave_mask is read. To not redo the whole early initialization sequence for the corner case, this should be good enough. Reported by: jhb Reviewed by: jhb, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D38219 --- sys/amd64/amd64/fpu.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index e9b058f175b0..64974a7210a9 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -372,6 +372,7 @@ void fpuinit(void) { register_t saveintr; + uint64_t cr4; u_int mxcsr; u_short control; @@ -379,7 +380,22 @@ fpuinit(void) fpuinit_bsp1(); if (use_xsave) { - load_cr4(rcr4() | CR4_XSAVE); + cr4 = rcr4(); + + /* + * Revert enablement of PKRU if user disabled its + * saving on context switches by clearing the bit in + * the xsave mask. Also redundantly clear the bit in + * cpu_stdext_feature2 to prevent pmap from ever + * trying to set the page table bits. + */ + if ((cpu_stdext_feature2 & CPUID_STDEXT2_PKU) != 0 && + (xsave_mask & XFEATURE_ENABLED_PKRU) == 0) { + cr4 &= ~CR4_PKE; + cpu_stdext_feature2 &= ~CPUID_STDEXT2_PKU; + } + + load_cr4(cr4 | CR4_XSAVE); load_xcr(XCR0, xsave_mask); }