Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1179003rwe; Thu, 1 Sep 2022 13:57:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR7c5T5VvbftnpdDGFvk5HQrXyTOzxJqb2CXlizeS0GZ0s8ciyGjJJQrPTQdPavSYz4kQYpK X-Received: by 2002:a17:902:c401:b0:16f:b59:85a7 with SMTP id k1-20020a170902c40100b0016f0b5985a7mr32098396plk.115.1662065866782; Thu, 01 Sep 2022 13:57:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1662065866; cv=pass; d=google.com; s=arc-20160816; b=0lS5Q5jDNe3Zy/v9Ea1TdVkUnNIebCwak5f3tBpKyDiT285HzWNAhUgtrABjkFPSht tupTWQCAu0/gTj4Lq3wqsRMxUyP+BcUkyFPNhduQng4Mt2cT32JPEFSbgbcCqjNWUPiL tDvlhBbUk7Gl/wrJ83rLljsttrMpQrS8jVEHdfAFeifEDfIUXcsRRGTimqrzGNyBGC4e GDhDvU1w5w4QqqRNS/zMXp0RucibM3k7RpS2w8fLT+dX4LfGZexicMeJxLyWNSywVXcb VqovQ0amoqb6yDq1UJGFvqhAltNuoiu3FMZriF2Pd/jee4Q32WlzrgVhL4lzlqiJYSAz lXIg== 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_label_4342314e-0df4-4b58-84bf-38bed6170a0f_contentbits :msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_actionid :msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_siteid :msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_name :msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_method :msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_setdate :msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_enabled:msip_labels :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=8z39LTGoqPC0gcqHK5cQackmxlAmSNi7bjy1vJ1zQzs=; b=xOCKeIZxJK2mKECNyE0c0NL5XVXOxvbsgrcRroH/Ryc4knikrgF3v7lpnSNTwCjH62 hnpifURHlZfmSDDD8PctJwybo9ieHP8VIWV3N49g9SeR1yKTQ7Ox2bh4L2vXkFGf/e0Z JdGCoabvl1nKM14Vika9TaLkiPUZ9W0ZgR/JEDzBaLB+jC1QKGPaoMYWUghD2HH7/LIv lF5rRc9BpwaoIoE5rFPLFu9VhnEicDrDqF1poPwrwRg83ciS5ANZMEHSZ1n/O1BLdKON VsMrO6Wp23MqM9SON4AMuN7OAXhIBBueZ1gMdFICsQDvq0eVcNJyGgbXol8pqpFPbcgF cj9Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=rMZMq5hi; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a170902789600b00174a7230e39si5995pll.329.2022.09.01.13.57.10; Thu, 01 Sep 2022 13:57:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@amd.com header.s=selector1 header.b=rMZMq5hi; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231815AbiIAUcl (ORCPT + 99 others); Thu, 1 Sep 2022 16:32:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbiIAUck (ORCPT ); Thu, 1 Sep 2022 16:32:40 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2082.outbound.protection.outlook.com [40.107.244.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DA377961B; Thu, 1 Sep 2022 13:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NCHntLMJeSicaMAY0wH/JqRXECod3GdYxCSwbCJRzb44u4EcaXcs7dCm7WQCge5H4C+Ixik4c2O8a2Gb0lEx0B4+c96+YJ2lg9Xd1aCGXjhsqfpAKpsiMDIC3oezq6l9pqjgh6q34ksYi7EDkpLxzJwXQ/3H5dVsKT31eqg/WsgU8RCNxJDdCmxjIG385X/8qLky+xEoyivrJspqPXlr3E6JsiBcZGcWRDww1cr/VKgifB7HfSCvvgmUtD80h6baYLgZNWAYXW9/cYef2oSUI+LBIRwZyikz0l8LcN4CzIypFTL0+suWp3Nk8IeDMJeC2sL/lYdFI+mAIM+h4WlYDw== 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=8z39LTGoqPC0gcqHK5cQackmxlAmSNi7bjy1vJ1zQzs=; b=RNO0j9Qrr1ElZCYUdKc77DvURnqQlUNCK8FtZE0DWKpMLsZK1wdv8BMuAoCYugMUrFfZR6/EvvQ6PJUQhclbjnDsL7kk6vya6RI7WsFPSN8hiisGTQgLZLywby2Ogzc71IUlRxufenaGSKUNTqS3Hn2AkQPW5gk/Sy41qztDujDr5Rj3dNrjZFllsHiN6+ojQzrdhnvcedenEA6oJKHuFqRbGwd3YSJSrTteZQpvO0htkNTJoklXxncrYdhw2NR998JIp1PAPAa/5+MXNe05tMRgK02ueg9qLoAnRQ4BMAeC+Bik1hUCuHAEv1aAW/zyvMgq0R+0OXwKeVekYdxq6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8z39LTGoqPC0gcqHK5cQackmxlAmSNi7bjy1vJ1zQzs=; b=rMZMq5hi21jdVmbgb9olYx0Ecc7nr9ZPzxogVH9Vps41B0ECF1Bqol91FgC6ErHNQ/TjdNcy89EQDP6L3gDRtUspcQfJn4iNqgN8IJy3EldL6mTVqqbgEEknrfT2y/Wo+kzUGZ6EsEaVJyIRic0zBDOW1EH7Vl7bMeqEbk0l238= Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by BY5PR12MB4259.namprd12.prod.outlook.com (2603:10b6:a03:202::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Thu, 1 Sep 2022 20:32:36 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::e47d:1a95:23d5:922c]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::e47d:1a95:23d5:922c%7]) with mapi id 15.20.5588.010; Thu, 1 Sep 2022 20:32:36 +0000 From: "Kalra, Ashish" To: Borislav Petkov CC: "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "linux-coco@lists.linux.dev" , "linux-mm@kvack.org" , "linux-crypto@vger.kernel.org" , "tglx@linutronix.de" , "mingo@redhat.com" , "jroedel@suse.de" , "Lendacky, Thomas" , "hpa@zytor.com" , "ardb@kernel.org" , "pbonzini@redhat.com" , "seanjc@google.com" , "vkuznets@redhat.com" , "jmattson@google.com" , "luto@kernel.org" , "dave.hansen@linux.intel.com" , "slp@redhat.com" , "pgonda@google.com" , "peterz@infradead.org" , "srinivas.pandruvada@linux.intel.com" , "rientjes@google.com" , "dovmurik@linux.ibm.com" , "tobin@ibm.com" , "Roth, Michael" , "vbabka@suse.cz" , "kirill@shutemov.name" , "ak@linux.intel.com" , "tony.luck@intel.com" , "marcorr@google.com" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "alpergun@google.com" , "dgilbert@redhat.com" , "jarkko@kernel.org" Subject: RE: [PATCH Part2 v6 09/49] x86/fault: Add support to handle the RMP fault for user address Thread-Topic: [PATCH Part2 v6 09/49] x86/fault: Add support to handle the RMP fault for user address Thread-Index: AQHYrBDc30zm/ve2UUW13wSedLDd3a2nIMnggADB+gCAAMFX8IAieiDA Date: Thu, 1 Sep 2022 20:32:35 +0000 Message-ID: References: <0ecb0a4781be933fcadeb56a85070818ef3566e7.1655761627.git.ashish.kalra@amd.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Enabled=true; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SetDate=2022-08-10T21:14:04Z; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Method=Standard; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Name=General; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ActionId=39eeec9b-b36e-48b8-a410-dbbaae721fe1; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ContentBits=1 msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_enabled: true msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_setdate: 2022-09-01T20:32:33Z msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_method: Standard msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_name: General msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_siteid: 3dd8961f-e488-4e60-8e11-a82d994e183d msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_actionid: d457c7cb-9ee6-4bed-95ef-d6ce5b1e22bd msip_label_4342314e-0df4-4b58-84bf-38bed6170a0f_contentbits: 0 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3bcfb976-df37-4480-1b90-08da8c591b08 x-ms-traffictypediagnostic: BY5PR12MB4259:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: K3XVUbOYgCU9svDfd26fFZu+348F1R3MMIpX7y0e8QAdO8osFeN9JB30FSRE3Pr/LVymFknB48MCMEW/7pGgs8JeweJaRPXqteC4dU0xOQtONPGooBCId0FQD6mcCphIyDWx8FM+/5z7qsgeJD26gxRKRgC2McOSKE4Iyzh0Aod6Ji0YYIPLutxjqoPfbpzrz9iIL9p6CoEVbzNImgeO6m18ZlBSEjr+Kx4U3iCfJFNcaNKf3T5pZi9qyJ/n9lgP/3q0cw84TYjTYTyvv9+MQj7ft0bfUkunL/QhTTsPiyZlMcTDbudHuzpUqb6kmfCJL4qMSXIXlGEl6+QjZnneSsoOwQiM8KLPqjLn8RSH2FEKbkX7E0cYfYQ9AczhX74yQxDq9QEg+un35udvzlbvkJBgyHjGVc3WFQmh6h3Q0QIZM5KcLDF2JLB0DcwkaXqUWJALhrItz5JQqefYQMuYaLqT4+29mBNYcXR9SntAPPeoahwq/wztndZNMbgpmEcsLiaLZLuz6Jdnh/esCMtNw2IcLcUcNx3Yj4gwTg6CYhIcLbDj+KBOUh63Hua8amqoavt7gsZ2/dVW/0hgGE5E7ny5OgYzNgFOt4/H7NBg+w2aqMbdflgPZ2b7Lch5n8sCtCwjw+S1AwTnQVaIOJBqU0iJGNfCIi+JmlAtsYDds0lYwciPkza2gjayu3vH3jIUTODChyI3q5khqzn7loogN3jqNEbIE+F+FFPtKM3cO+7KkS4TX0K9ofbtjf/YCrTm2gZC2w3wtPQCNRR35RVcmw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(346002)(376002)(366004)(136003)(39860400002)(396003)(7406005)(52536014)(8936002)(5660300002)(7416002)(41300700001)(33656002)(76116006)(64756008)(478600001)(8676002)(66946007)(66476007)(66446008)(55016003)(4326008)(186003)(66556008)(86362001)(38070700005)(26005)(71200400001)(2906002)(7696005)(6506007)(9686003)(122000001)(38100700002)(6916009)(54906003)(316002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?qzbav50R4JBChx3ZSz9n8K4iGM05eMCi5Yh7FSTwpyeTHwMIJ/dLxJTp8MoL?= =?us-ascii?Q?xKu4ft7fqFlYnv4JvS4iNb5vyuULFiC7cjjVcR6Z2UFRolKbtqtOJtIKjvNL?= =?us-ascii?Q?gxf7udF+0e3VfZZXFQNqszyiTwLcYG/iW6pP8iyySOd31Gj0BnHUhP61c+Co?= =?us-ascii?Q?2WJipmSotcf74jG0r9niqnB9kI+HLv71iuSKJSn1gafztOjEWwsmsXY8aK/m?= =?us-ascii?Q?HghLxMVqUQmxHhXz0g3jJy1Ubzc8a7WmedzUowP1oF9UfwEMLWHXFlHP/63n?= =?us-ascii?Q?tLR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6UgjNi793d5JBtNq?= =?us-ascii?Q?RCaMsZGXr6NcANkOR44WXmGTd5t0v9fCc4NUFdD4cjlD2LrzPpB8sPLu8ds5?= =?us-ascii?Q?okF1kNRgOQd22rBHSgEPkmyHHIZlHwKCbsCN29G9NL7vvF532UH/BnxuQ84n?= =?us-ascii?Q?1u7pntl+XvbTxpO3uBu0v9BP0qZyrHIWksM2FbVPFn89Xeb0Ur3wSavDSYj8?= =?us-ascii?Q?DptoPKgSAQhDsr4IX8A+eFmzaxf1gojP/6WSQREIFbRAOrOx16ECJj/LF4ND?= =?us-ascii?Q?PpyKPDuP97pMequlmLKTuMQAxHFe7hCQrH0R1zvtsmGaubXmDQ0aHNBERCgP?= =?us-ascii?Q?pmoD8O/AZSQ/OpOa9XqeiqSj9oEPeRItH+muV4lOmpLIXKw+SDLMPTgsfprf?= =?us-ascii?Q?4dxD/Mf45+j/ZVqB0JQ=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3bcfb976-df37-4480-1b90-08da8c591b08 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Sep 2022 20:32:35.9215 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ngY8nOfNxEO+NDJVvLRn4U/sDR7CCkKXwnUqa62XZOOaU44Gq14TeB20zuCRlHFFc8DoaolATWttdbsnuu9eEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4259 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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-crypto@vger.kernel.org [AMD Official Use Only - General] Hello Boris, >> It is basically an index into the 4K page within the hugepage mapped=20 >> in the RMP table or in other words an index into the RMP table entry=20 >> for 4K page(s) corresponding to a hugepage. >So pte_index(address) and for 1G pages, pmd_index(address). >So no reinventing the wheel if we already have helpers for that. >Yes that makes sense and pte_index(address) is exactly what is required fo= r 2M hugepages. >Will use pte_index() for 2M pages and pmd_index() for 1G pages.=20 Had a relook into this.=20 As I mentioned earlier, this is computing an index into a 4K page within a = hugepage mapping, therefore, though pte_index() works for 2M pages, but pmd_index() will not = work for 1G pages. We basically need to do : pfn |=3D (address >> PAGE_SHIFT) & mask; where mask is the (number of 4K pages per hugepage) - 1 So this still needs the original code but with a fix for mask computation a= s following :=20 static inline size_t pages_per_hpage(int level) return page_level_size(level) / PAGE_SIZE; } =20 static int handle_user_rmp_page_fault(struct pt_regs *regs, unsigned long e= rror_code, unsigned long address) { =20 ...=20 pfn =3D pte_pfn(*pte); =20 /* If its large page then calculte the fault pfn */ if (level > PG_LEVEL_4K) { + /* + * index into the 4K page within the hugepage mapping + * in the RMP table + */ unsigned long mask; =20 - mask =3D pages_per_hpage(level) - pages_per_hpage(level - 1= ); + mask =3D pages_per_hpage(level) - 1; pfn |=3D (address >> PAGE_SHIFT) & mask; Thanks, Ashish