Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2725780iog; Mon, 20 Jun 2022 03:28:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sCl8GiSVIZ7N//mr+LvXueLgbJZrwI/qKgBnQQBYXCTC2GnYUHEPEB7gDhWyanfoYYIIrc X-Received: by 2002:a05:6402:51d4:b0:42f:b38d:dbb9 with SMTP id r20-20020a05640251d400b0042fb38ddbb9mr29235000edd.255.1655720889096; Mon, 20 Jun 2022 03:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655720889; cv=none; d=google.com; s=arc-20160816; b=d5g6WD9Qq1qaQKGuKRtqT0a1vuXX8nmpVZ0Jnt/ZzlejxEIx30JAmoelFctFu6L65F ECJjMTPR3tdpDCin0/b0nJXe/GvIHkqJckABzu7X0j6Sf2rUEbwPjjm0TH6Hi+r6O+zM Xm6nx/AXYvlEW+V3ikWIsCY98/u7F/HdhH/24QPFy1gLBYbjFERTWDmi+wHpEhFJyOR9 +k+AvMXPkeyTRG0NbMhQhxyw1pQYRKTJAPeFnDBr+imKNcg/qSVf/WssfcqyB08hGxjt wBJvXM2WSenDYAZvKcysOhH72ddvxaNmKgfgjFn914lHuuXEulVZxhCsyLiVBhUja+gT 35bw== 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:dkim-signature; bh=q17a9XDpjwTWrwYDkkTaQRPmMqGL4q0bN7aju6sX8fc=; b=dUdwdx8CcA/TycDb//sb4WOBzSeFhRsS41X33i+IA+wUBBcq019mWl5RtX50oTHxap qPEQETRpfnFjTFtCmnWXbiXfGtsH1btczbQY86R/aYNFwmMoUKJIh4Muu+xXBvLCFbnb 2ojHU0+oJ8N82aPeXnIj1fauJJ4051ITlYBeteIV0S+n6DJxc7DqVkQZnVocCvGepQZx 7ARsCQvMOWKYNOMDaJcfTPlOzEgAblxJv+iK6Yblnc/jYF+qqmotnDzPGrKnjap+/RJk ZD2CSwrW6KK1x2UzkzRPTKZgx3kiybRaT+sKXukV2MGJ4i9i2K9xjSYwo8Bmwsgnoh/Q f7+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ot3uDji6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fj4-20020a1709069c8400b006fec2f4c252si13297740ejc.135.2022.06.20.03.27.43; Mon, 20 Jun 2022 03:28:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ot3uDji6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239937AbiFTK0T (ORCPT + 99 others); Mon, 20 Jun 2022 06:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239999AbiFTK0M (ORCPT ); Mon, 20 Jun 2022 06:26:12 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92AD713F88 for ; Mon, 20 Jun 2022 03:26:06 -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 D9D7D1EC05ED; Mon, 20 Jun 2022 12:26:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1655720760; 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=q17a9XDpjwTWrwYDkkTaQRPmMqGL4q0bN7aju6sX8fc=; b=ot3uDji6ieMC7dhTqMOPLpRfYZ+D/oOGVFqRzqgKnfa0kcNpM/bfgTF0HcgcUwm1ytR3UF ZcxLVAfRbqvIk7ehY+JDCg/3PXcH03o7yOuj7hy3MWW6UBKZz+alWlDdoJiftWvYpq7DOu W9CoStDuS1uK4u2ui87Jeq2OESCWxlw= Date: Mon, 20 Jun 2022 12:26:27 +0200 From: Borislav Petkov To: Juergen Gross Cc: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org, jbeulich@suse.com, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Subject: Re: [PATCH 1/2] x86/pat: fix x86_has_pat_wp() Message-ID: References: <20220503132207.17234-1-jgross@suse.com> <20220503132207.17234-2-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220503132207.17234-2-jgross@suse.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 03, 2022 at 03:22:06PM +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. > > Fixes: 1f6f655e01ad ("x86/mm: Add a x86_has_pat_wp() helper") > Signed-off-by: Juergen Gross > --- > arch/x86/mm/init.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c > index d8cfce221275..71e182ebced3 100644 > --- a/arch/x86/mm/init.c > +++ b/arch/x86/mm/init.c > @@ -80,7 +80,8 @@ static uint8_t __pte2cachemode_tbl[8] = { > /* Check that the write-protect PAT entry is set for write-protect */ > bool x86_has_pat_wp(void) > { > - return __pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] == _PAGE_CACHE_MODE_WP; > + return __pte2cachemode_tbl[__cachemode2pte_tbl[_PAGE_CACHE_MODE_WP]] == > + _PAGE_CACHE_MODE_WP; So this code always makes my head spin... especially after vacation but lemme take a stab: __pte2cachemode_tbl indices are of type enum page_cache_mode. What you've done is index with __cachemode2pte_tbl[_PAGE_CACHE_MODE_WP] which gives uint16_t. So, if at all, this should do __pte2cm_idx(_PAGE_CACHE_MODE_WP) to index into it. But I'm still unclear on the big picture. Looking at Jan's explanation, there's something about PAT init being skipped due to MTRRs not being emulated by Xen.... or something to that effect. So if that's the case, the Xen guest code should init PAT in its own way, so that the generic code works with this without doing hacks. But I'm only guessing - this needs a *lot* more elaboration and explanation why exactly this is needed. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette