From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B18FC433EF for ; Mon, 20 Jun 2022 14:11:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350971AbiFTOLS (ORCPT ); Mon, 20 Jun 2022 10:11:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352992AbiFTN50 (ORCPT ); Mon, 20 Jun 2022 09:57:26 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0348437A3D for ; Mon, 20 Jun 2022 06:23:14 -0700 (PDT) Received: from zn.tnic (p200300ea974657f0329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:9746:57f0:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id E81721EC0657; Mon, 20 Jun 2022 15:22:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1655731333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=LrGpaF007OQqZrjEUL4cOEK+6b5ptHcd1OgrPbOBhQc=; b=kWLHioT5UQlaSJoVi5j86oOVwPwb26iLxGk6Lbs+ei26Nq/TNiLbkDhLvIBEcM1dDW7PwE REHLuI7rtdbxYZJ11zXspxBMbDlwr0roQw/RaMWMbPlZlmUydz0+9GqupSWNQ5iHJDtzLd ZDKnGzQwg1BILxQITGEggBx6lvjZ+IE= Date: Mon, 20 Jun 2022 15:22:08 +0200 From: Borislav Petkov To: Juergen Gross , Tom Lendacky Cc: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Subject: Re: [PATCH v2] x86/pat: fix x86_has_pat_wp() Message-ID: References: <20220620113441.23961-1-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220620113441.23961-1-jgross@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + Tom. On Mon, Jun 20, 2022 at 01:34:41PM +0200, Juergen Gross wrote: > x86_has_pat_wp() is using a wrong test, as it relies on the normal > PAT configuration used by the kernel. In case the PAT MSR has been > setup by another entity (e.g. BIOS or Xen hypervisor) it might return > false even if the PAT configuration is allowing WP mappings. ... because Xen doesn't allow writing the PAT MSR. Please explain exactly what happens because we will forget. > The correct way to test for WP support is: > > 1. Get the PTE protection bits needed to select WP mode by reading > __cachemode2pte_tbl[_PAGE_CACHE_MODE_WP] (depending on the PAT MSR > setting this might return protection bits for a stronger mode, e.g. > UC-) > 2. Translate those bits back into the real cache mode selected by those > PTE bits by reading __pte2cachemode_tbl[__pte2cm_idx(prot)] > 3. Test for the cache mode to be _PAGE_CACHE_MODE_WP Yes, this is a good explanation albeit a bit too verbose. You can stick a shorter version of it as a comment over the function so that we don't have to swap it all back in next time. > Fixes: 1f6f655e01ad ("x86/mm: Add a x86_has_pat_wp() helper") If anything, this should be: f88a68facd9a ("x86/mm: Extend early_memremap() support with additional attrs") Also, I'm thinking CC:stable here. > Signed-off-by: Juergen Gross > --- > V2: > - fix indexing into __pte2cachemode_tbl[] Yes, in any case, I see it now. The key aspect being in the comment above it: * Index into __pte2cachemode_tbl[] are the caching attribute bits of the pte * (_PAGE_PWT, _PAGE_PCD, _PAGE_PAT) at index bit positions 0, 1, 2. which is how one should index into that array. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette