Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7972136rwl; Tue, 10 Jan 2023 07:34:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXt2or0CMjBsmmlmK2Jd6iE7vHUoEAV0P8TUXlUIutSuj7lR1UQPMEuRZNi37THUh5Yxo+PZ X-Received: by 2002:a17:902:b68c:b0:192:4ed3:e919 with SMTP id c12-20020a170902b68c00b001924ed3e919mr70415557pls.34.1673364871153; Tue, 10 Jan 2023 07:34:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673364871; cv=pass; d=google.com; s=arc-20160816; b=kbhfVR+pWV8pFjaiNlipKLF3PwUt3NQFOxoB4Vg5mymsonZdQMwiL0Ma+82aQB7wfl qnSnKbRekkBCU5ISyS+ewF5e9dFKA6RT81ZoA3JdohKnxzkWc1PVntUyde8BrqOxYBt6 pVMOPjcckQa584tiO/qT1CEXR7gObD5q9pxo8VSCLm7z699mHyMpFtYYu5qRueFAXZT2 jCsACIoRwUo/wnLSkiXpWxupg3flSZW80JTq8UtYkfxNNfBRzaaWSzeAhIN2H+AMkEsF D2f+TSZsD3+qsfRONDsVb/N5wvNY0mMzO/JKkpTM7v4dJHo0MUdS9usbfFWnuTB6JYyr 1KhQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :msip_labels:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=DVjL/qiavLOfUhHpAs9qTk3d9eBRp5JhVoS1GkVfx/A=; b=V7d/UCaJ4oZR0jmyahlk5vjBw1+QmQxn0eC410KzVy8WMuaWEmBvfN20bW1nGMV3ne wk21f9eU18iLFnOpNm7y00Z8pHWmpBgEYqAcMTA1Q1go3cRlszWVEPFLPgqUpV12I93Q BOsqWF4feIaVQvEZWzGDHgSoOkEDh4JvI70v4wqy8VeJTBEsSKOrUCYuPFolDHo4qhnc Ia8a6B6PwQ+27nrISXjSGjr5NDbORlVeAVfCveAUBuLDOwSCviSt6mXqxfQkfGZOD0Ej kKbdWsiDtmgRUBHMaiHYSl813sIts00lhcZZSx8tsoiRNIC1+HlaX+p7D2Se2AIy5gYD ggzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=imi2NIVF; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g11-20020a170902934b00b00189feee4923si11142398plp.534.2023.01.10.07.34.23; Tue, 10 Jan 2023 07:34:31 -0800 (PST) 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=@microsoft.com header.s=selector2 header.b=imi2NIVF; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238466AbjAJPXA (ORCPT + 55 others); Tue, 10 Jan 2023 10:23:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238723AbjAJPWf (ORCPT ); Tue, 10 Jan 2023 10:22:35 -0500 Received: from DM6FTOPR00CU001-vft-obe.outbound.protection.outlook.com (mail-cusazon11020018.outbound.protection.outlook.com [52.101.61.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C7141788E for ; Tue, 10 Jan 2023 07:22:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mS7XQICSqFgu+3OCNVMM5f6DRurv9Oa1OzBjFSw6zgQKodV2qbCpznDN5GlvHYOKBETloqCXFJbO+tyq1VsCzmnNzKAOczTovvs204vQT9+I8UGJJV3np9EczK7unp3mPqEWDo+wyV6Sd7f5mxHaJdvR3AibBKElqIatYFfjD2WmyiQ52c2bP0lApbJm2YB9B77wOb48JeQRul1OApucdkbQtfLryoESruKjFHDim4E29SINfHX0Hc6AwJzaDCZ3Yw+7hg52VDpi8aFKfQ0ITka9tDb6325ON/LiTM43323avLHkOEMv+xJmlM7xLsNedOCP0OL5+3SLNpVpo3Cqfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DVjL/qiavLOfUhHpAs9qTk3d9eBRp5JhVoS1GkVfx/A=; b=bqsg4lIqKGwqXnnZ8yGXgdN5NMoxeyTxHOxcgWiEepVz4aZFy8qxhWUKfRM32dVzhJ4TyEYFqRFcykQWzWmJoO3FNnRsll0gnb2U1G+Fr23j4G6FcmK61n2YPrXNelynMT+HW/vbBLpjde+C1HyTZbW9lng1aGR+MLm7gxi+jRg47ARtR/LhUO3fmD+6uCrB18hLZpjRzFUL1VVovISzEGjHGU/mr7JNJBfSTLh3vcImeZVK1eaCJtE4+B+bpVBq0JTY3KeArQqMDOMfCVa/Rn28SbPb8MOU/PJupzSZ4XGqFMMAWpQ8BiL1JcJpHaRs42saQm2pQYgccWSMGJtlkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DVjL/qiavLOfUhHpAs9qTk3d9eBRp5JhVoS1GkVfx/A=; b=imi2NIVF6yxAISnHXOaUQnrwtp0CS8e5NpBbK9gyrH+Pgz3i/U0Y765qY5obdONDuYdLu3tPgfenGlKq18Kkal9sIPH4FxA1aiGYNTkKJdmT3Ywgf5/U4zx7ou/9KGi3MNNClK3LZpynvuTKAumEoTqD4K2lWhvaW7GmHJe/Fpk= Received: from BYAPR21MB1688.namprd21.prod.outlook.com (2603:10b6:a02:bf::26) by PH0PR21MB2005.namprd21.prod.outlook.com (2603:10b6:510:48::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.4; Tue, 10 Jan 2023 15:22:31 +0000 Received: from BYAPR21MB1688.namprd21.prod.outlook.com ([fe80::9a9e:c614:a89f:396e]) by BYAPR21MB1688.namprd21.prod.outlook.com ([fe80::9a9e:c614:a89f:396e%7]) with mapi id 15.20.6023.004; Tue, 10 Jan 2023 15:22:31 +0000 From: "Michael Kelley (LINUX)" To: Juergen Gross , "linux-kernel@vger.kernel.org" , "x86@kernel.org" CC: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: RE: [PATCH] x86/pat: fix pat_x_mtrr_type() for MTRR disabled case Thread-Topic: [PATCH] x86/pat: fix pat_x_mtrr_type() for MTRR disabled case Thread-Index: AQHZJMBmxZ2wfUHQ3UWiDX8chmoK+66XwvYw Date: Tue, 10 Jan 2023 15:22:31 +0000 Message-ID: References: <20230110065427.20767-1-jgross@suse.com> In-Reply-To: <20230110065427.20767-1-jgross@suse.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=1f557fb9-7c87-433b-bede-7fa6285b1692;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2023-01-10T15:14:28Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BYAPR21MB1688:EE_|PH0PR21MB2005:EE_ x-ms-office365-filtering-correlation-id: 413afac9-8407-4a6c-fbdd-08daf31e7e00 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: gGSPdyt23EakMIaJK563zYpZ3KomlM4AAjIczti4j3CL5/0A+njjLgrCa8IxxrplM9Huz2jkI9ZCe5twJH2FYl9Ahf6BVhAvaPN7pFl4MLXFyPgDUZl/CC95MKQAxMVwoVHCR9m9bJDSvjk7nNi2kEK1RHT800vfFipc1Yi/8aGGdExg2VRrLInryZuXYvuyQqeWzYzOXzqiPHU5ocxX7Vpelle3LJBA9koJSZJ92BWCANOwj0786TYLE+pLf7ZkwSqLHN4pOE0NkdkS6CWKjq1cq6DDz7JxzIiQZwobQ2uC6j0R4eLD4EPdoyrjGyhV7jIrbRw3q7sGlYEwdoRbFbuIdhBJBmEOcxeRVnHdrVMIGy7bjV8xavkoUR+wUARBRq297XR1zgilW+4RhP81epBHttRVpK5vquqGey1ldMhGjHsdqpSLreQ23e6Q3qP6aK74VI+39/Ez3wVBkRnrk33dMiCtFS7ey2SRS3+jO8Z8PDfv/lAyylUt5CP7dhzHdruhvEuVgaKFJnTXIVUZaXRCFwuIMMmdDJG+axcHxUArIOShamrLffShdNky2V4ATkQZfUp6MV14t/r4yUAhC/zK/SlA2yAL3VKET8W3BAAl2iL+rj8o6CRhnwM36RuH4Xb7ifzkeNWMyunBa3ieKKnwQaHlcRTt3RJUhJAIGYxlQ5GMufS2xUgmNT9AphHdfuYHoXBi+2uYfWI5k5CX5BpocwK5j5k7Jr4u85lR3ZLJySBVbSdkXB2DxZiHcJuc x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR21MB1688.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(39860400002)(346002)(366004)(136003)(396003)(451199015)(33656002)(54906003)(110136005)(478600001)(10290500003)(316002)(86362001)(38070700005)(55016003)(38100700002)(122000001)(82960400001)(82950400001)(83380400001)(6506007)(186003)(26005)(9686003)(5660300002)(7416002)(66446008)(64756008)(2906002)(8990500004)(7696005)(71200400001)(41300700001)(52536014)(8676002)(66556008)(66476007)(4326008)(76116006)(8936002)(66946007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?tV7n0ohyai0f9Zr1TI2a8QkbwKhlLhTuHB6F+K0AGcdv+LhPLGnvARKNJWdV?= =?us-ascii?Q?qumLDie6bnQ73SzjqABtRgQg62U/wmgNsBhRy0b/ISvBeJ18bQ7rSauEWK2j?= =?us-ascii?Q?lWBcgtMBVQA4a6ZlnuqQvH5Macu6M0YF2VJdBLSVmlFJJMAXXzQeEUFtGNbX?= =?us-ascii?Q?3RH/wKLABaUggXtCfldc84SPFB1bw0G1Bb/kut2sQtoBvM3/ssHSqeyXV1/T?= =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bukbT3WGI2lfWuLw+cUpc0dmq6+?= =?us-ascii?Q?02JB8+A4P7wk0LCTe+bPOeLvIQAvvSPJ9P9Zn2N4g5VUvTZ/LG/dGw2VGMg2?= =?us-ascii?Q?d7KVdX+mRwAt93Oi9by2cNNYQB3qlQAS2S1+StcVCpQ9CWNHfcPZ5XFVDQ1h?= =?us-ascii?Q?LfJ+JZskiTx0+v1Gth5YeXteCwtoOc4CAB/pPTEcJq4akY3AKA9Ba2tBkkFo?= =?us-ascii?Q?TRV0Q3vEb3A7wxhb+2R8VnYcoNlR04O+6Uo8M9cp7uM+lFaHdHAdr3imcF49?= =?us-ascii?Q?MaOgYwZViBR+47Wdv2c4G2Js4M8nZ8pJbW0UXQIDd7CQ4hsMkn6qEoMw+WtL?= =?us-ascii?Q?G4LF7XL0Qz4wOcEClhBkH6WbJO6AHuntFtQ5oRbrD8QtD7dmPPZU24iSHjQ4?= =?us-ascii?Q?JQU4C0qO3/XHl7jtHT1YAhP0qQnI9cRD6kz+hRDAUr4c6OftXOq7FULP6F/1?= =?us-ascii?Q?0mp0tlDC5Dm252biCWhtbST8PnM2sh3AYnNj04BMi9JqB8h6ysD0VeBhTOZy?= =?us-ascii?Q?/A=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR21MB1688.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 413afac9-8407-4a6c-fbdd-08daf31e7e00 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jan 2023 15:22:31.4439 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: HnjHfOQboFK+w0Vq46MegQkwfTYU+Q7752nnC2dp+9l4f6ICmN8keFSxB8ZyuMT4pizP6FiTzxKD2K19LsT25IHFRWu88Y14UHIx2dEcNZE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR21MB2005 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no 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 From: Juergen Gross Sent: Monday, January 9, 2023 10:54 P= M >=20 > Since commit 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly > reflect state when running on Xen") PAT can be enabled without MTRR. >=20 > This has resulted in problems e.g. for a SEV-SNP guest running under > Hyper-V, when trying to establish a new mapping via memremap() with > WB caching mode, as pat_x_mtrr_type() will call mtrr_type_lookup(), > which in turn is returning MTRR_TYPE_INVALID due to MTRR being > disabled in this configuration. The result is a mapping with UC- > caching, leading to severe performance degradation. >=20 > Fix that by handling MTRR_TYPE_INVALID the same way as MTRR_TYPE_WRBACK > in pat_x_mtrr_type(). >=20 > Fixes: 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state = when running on Xen") > Reported-by: Michael Kelley (LINUX) > Signed-off-by: Juergen Gross > --- > arch/x86/mm/pat/memtype.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c > index 46de9cf5c91d..fb4b1b5e0dea 100644 > --- a/arch/x86/mm/pat/memtype.c > +++ b/arch/x86/mm/pat/memtype.c > @@ -387,7 +387,8 @@ static unsigned long pat_x_mtrr_type(u64 start, u64 e= nd, > u8 mtrr_type, uniform; >=20 > mtrr_type =3D mtrr_type_lookup(start, end, &uniform); > - if (mtrr_type !=3D MTRR_TYPE_WRBACK) > + if (mtrr_type !=3D MTRR_TYPE_WRBACK && > + mtrr_type !=3D MTRR_TYPE_INVALID) > return _PAGE_CACHE_MODE_UC_MINUS; >=20 > return _PAGE_CACHE_MODE_WB; > -- > 2.35.3 This looks good to me. I've tested my specific use case of a SEV-SNP guest running under Hyper-V, where the MTRRs are not visible in the guest but the PAT is functional. Previously, this use case showed many "uncached-minus" entries in /sys/kernel/debug/x86/pat_memtype_list even though the mapping requests were made as WB. With this patch, those entries show "write-back"= , as expected. Thanks! Reviewed-by: Michael Kelley Tested-by: Michael Kelley