Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6241771iob; Tue, 10 May 2022 13:44:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhFYgX2jRdhtsSIyBpYOp+2OQG+8QvDpZ+8PP+BT5WkKr4jNV20bIuQaQPyprBBwzKjzjX X-Received: by 2002:a17:907:1c0b:b0:6f5:64f4:91df with SMTP id nc11-20020a1709071c0b00b006f564f491dfmr19941007ejc.750.1652215477290; Tue, 10 May 2022 13:44:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1652215477; cv=pass; d=google.com; s=arc-20160816; b=xElSRdMwEF00JtAZU3JzFqbDK0BLCw07QskN9c6xQlLaxXfoJCsE9yJciAh853DeCM ENTpMhaawpv+Sk2CzJSYu6hmi+SS4xOyNuLSK3dIRWOfkkN38mIpb7DnUxqUqs0zRWQD NxbEhn35nWbsMZtqqxRpVW6YgfeATcluVycgV0yo0e+hG3XtiBInzvW1aiiwQ+AkRXBZ 1NyUVlzM/OZRMyAalI5rTM8YMwSa/w/vmuEOVzzphr5EKcwC8i0PZlZPtXLkSVKbcu8i ialw5i8VtNBf1VPSajfeqUSaXdlCtuA17ErzCh3Hc21RIWPhZQ0RS6FBxPe3UG5STIMt MQBQ== 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 :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=cgRGTzwmopzC8CQoxyorTEf4mc4vxJYIIr7gCpviWzs=; b=u+83JFdiMlbh1LxIq2y4t8SQCKM9r4IWora1bzVjT1NvAalJG0I+HIUZZT7H+EX9wt pzhTH7WHIEySKcBt0vl075znfUQ+jAR+qKeUAnvQ1vfLK/X+dpSgHABtJPWbV9TCG3Gq 4CtEiRQX4k+lngreKjxAoGJiIXH48tQGHrOakMwJXOETeGbIth56q3ZfUX8EDr8sRQZk wKoDxCDIw3YbrmIEAvHZmPKf8zJSu5kBgCQumdlqYIk49Uqhe2sZwavqAZuou6GtHRN5 rof5I045Q9Hmy9GylCSbmsK3D4mhG9QyRtMc9xNruT4TWyA+6dG5R5+On27lJEDm/sEA +NxA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=NE6BWavb; 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-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=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 7-20020a508e07000000b00425b5cafe53si206646edw.420.2022.05.10.13.44.13; Tue, 10 May 2022 13:44:37 -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=@amd.com header.s=selector1 header.b=NE6BWavb; 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-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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245741AbiEJOTu (ORCPT + 99 others); Tue, 10 May 2022 10:19:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245231AbiEJNrb (ORCPT ); Tue, 10 May 2022 09:47:31 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2078.outbound.protection.outlook.com [40.107.244.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F4CA2D3F71 for ; Tue, 10 May 2022 06:35:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lIxNG0TdYTBh11BRCcUnttO5kQ2vy95QXknTtZ0HwbWAAgU7P0+K3vc3BPPTJzyuaoAawh0+L/Z02cC0BTbPf8CRD5c0fZOj3W1u0ingcH0jXlmNGNTPhsEiYWS47P/wBOIRRqd4yxcoFNZtM7cS1HOqwW5thouf0uWCUeMUjUt9NQDhaQx2K2x7+QgT4zA9IKsqj8bIcl42J5NMLW76zMZKQuFbbnjNyKplIvj3PmWC1p14PcDrLkDYHRtNl/2TA/SsSkCEnUxc60mcZNLCN5UWOkoUD3PV9dlcaixXr6sf8SWCshfN2vHk9duPToLTU6rIWeOp7j+mYbs/KeJ+ag== 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=cgRGTzwmopzC8CQoxyorTEf4mc4vxJYIIr7gCpviWzs=; b=dU0dKIoj/mubtfq7+rLXTE3iXgD2q4ykVVjKLInc6ei/QUF2U/iarrK1K4Cjm3+Y0I4QuXRrhmVqKB0EqNTMVl73sHYpg9yfsrTpfXZ+4lrVyVZhJjL+vE6nHkSKtMVFGFu+W8F4YXNGcoQgleXxfE5JIumygqAOQddRNOx+aLTZXK0q10xXCqLQVT3UCOwDWd5c4Yl8GftTEoA/sUWhuHB89IjCtQKBpsB9mDcqvmE0x5fFAbaTeRltHwT+Rg/+jxIjOWY2USEob/fIirgy9zoPV76523+SJpcsfPV/myP6pxRNdeTmtc6K1gipwCRKzuvr3ySLqCNNEyRak2NewA== 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=cgRGTzwmopzC8CQoxyorTEf4mc4vxJYIIr7gCpviWzs=; b=NE6BWavbKDZj5e8Q8jQoqwGJ3ycjL12Ff25ixnEwFXQjf4mYUDvIarBLPtqXN0AuDT06FQ0pE/ZJZe0gGw3M+jg1BezLSuboefSejDVJAeh3fBmZ34msSTPWj1N7OmhuJe+UK38F0HSgJgjNxjcAcYHEpq2RCo21XnXuIH1zakI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by BN8PR12MB3347.namprd12.prod.outlook.com (2603:10b6:408:43::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.20; Tue, 10 May 2022 13:35:30 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::db8:5b23:acf0:6f9a]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::db8:5b23:acf0:6f9a%4]) with mapi id 15.20.5227.023; Tue, 10 May 2022 13:35:30 +0000 Message-ID: <5fe161cb-6c55-6c4d-c208-16c77e115d3f@amd.com> Date: Tue, 10 May 2022 08:35:27 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] x86/mm/cpa: set PAGE_KERNEL in __set_pages_p() Content-Language: en-US To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Rick Edgecombe , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Kirill A. Shutemov" , Tianyu Lan , "Aneesh Kumar K.V" , linux-kernel@vger.kernel.org References: <20220506051940.156952-1-42.hyeyoo@gmail.com> <56f89895-601e-44c9-bda4-5fae6782e27e@amd.com> From: Tom Lendacky In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SA9PR13CA0167.namprd13.prod.outlook.com (2603:10b6:806:28::22) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4d69c9c0-1ed9-47c2-ab08-08da3289f341 X-MS-TrafficTypeDiagnostic: BN8PR12MB3347:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z3zeQ8Er+L67NV4qctYTeMvc0UQxerqsU9BeENs5NkRkVcjaEMS3cRtehl/zzuSwekGDL0pdaJuFG+LeRhiFlCPFnqln8Nn+9nMTVWnsHHT6CiC0gDl1szY+FD2hfHgjvaJimXUBiXrOvaRHygine5I5UFlHNFMIuP7FHkM4NeJASH7/8PbNyyoOutk7ac6iw+8/QsxHJ7+yzcJ16s2qjT8iUNqg0wmMaWybDjkPaIsckAv1dts4Z61ORhoE7tH7R0MjZeaA/LqF2/cPHhmaPROoMmCw64AC+SveDnF1h5c9OuqEwEibB+yWhw/oyr7hk16qOzdav+s7Ep+TM+ff9PkgN2fv40pcszM7U4MEYmEfUMVhNlptzv7oaN6Vo3XTwvbxDAVJwozjZSTBhXyJGqJRsJViBcDw+qCgiIz5H+vS0wkEjMzWILbycdV+WMAcF9iXqSwaUYGkxsPInBt+9fYrji5zG2HT8MzYIg2wKndUs8ku8ZYNOMP8T0UBFg5wFDvrGQJfXnVJfVrou48oNWFXv7A1P83yWzDdzUCMOl2o1+ZSqSmBOnO97PghXaSCmOZKak6DfertSUvkuzcRe4Uuy9zy/lDoNRW2wxt0ri4fEEXtXHabM3xoocrN3r9Y0QcYbcH8pE7Gwp8QTnrmvr77qEJir9SzolMyUYl7qA+gmRfM7EQNs/7/DFHrfFbD8AjhkEMEVBTQP9nCz9zCy1sUzpq52rDPU2sEG6JOf/4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(6916009)(6512007)(54906003)(8936002)(86362001)(31696002)(2906002)(508600001)(6506007)(6486002)(316002)(5660300002)(36756003)(38100700002)(4326008)(53546011)(66946007)(66556008)(6666004)(31686004)(8676002)(83380400001)(186003)(2616005)(26005)(7416002)(66476007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?V1JxWHpXVUorVHgzNUxBSzR3WWxSQW1FSE1QeDJ1dmU4L21UcHpNVC95Z0dB?= =?utf-8?B?ZnFkdnN3cTJXUVZRN2pSTHdwQ0RHVFJuTnhqeEo3NTl6UGtzYVBiWFVYd3Vl?= =?utf-8?B?OEk0RFNMWWtzSThzc2lkbmowU0IzVnZveFFVM2U5UkhPQXFXMVhCOTNLVnZF?= =?utf-8?B?U041RVBiU2szUDRlYXhEYWRwU0c1RVlIenpNb0hzR2VqNk8vdmw2S3BibHNq?= =?utf-8?B?dGpRWFY0aXRNV1g0UytjTzBkc0dRVXJYQVJLdEsxT2xhNGNNWklPeHdMM29G?= =?utf-8?B?RFpreHQ5cWFYYUJQRE9FUFdESlVQOGptYkxRVU9hVkZEL0IzR2o2WFQ0UzZY?= =?utf-8?B?WDVQci9NenBvWmZLUGwxVGpBbldjUWNzVlgrcmVGV2dDTDQ0VEJFS0FvMUJF?= =?utf-8?B?NnZ4QmFmWkkrQVovSCswZmd3QnMw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25SRGcxOTVjZEdTWDEvUC9sRVZBRm53RjcvbExHdXc0blJNL2EwM2NW?= =?utf-8?B?QUpYQndmMFgzQ25LbVg3QlhhVEVXdzFoOGszWDVKY1NPTzAyYkVzQT09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d69c9c0-1ed9-47c2-ab08-08da3289f341 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2022 13:35:30.0868 (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: baWN/te16nmFKN8wXDZ7tn/go39/W4QJAvdwviXn+6xXtKRKurDvti3aQhMT5BhrvfINhgn1+xUIgYyYmX3ADg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3347 X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 5/10/22 06:57, Hyeonggon Yoo wrote: > On Mon, May 09, 2022 at 11:06:22AM -0500, Tom Lendacky wrote: >> On 5/6/22 00:19, Hyeonggon Yoo wrote: >>> __set_pages_np() not only clears _PAGE_PRESENT and _PAGE_RW, but also >>> clears _PAGE_GLOBAL to avoid confusing _PAGE_GLOBAL as _PAGE_PROTNONE >>> when the PTE is not present. >>> >>> Common usage for __set_pages_p() is to call it after __set_pages_np(). >>> Therefore calling __set_pages_p() after __set_pages_np() clears >>> _PAGE_GLOBAL, making it unable to globally shared in TLB. >>> >>> As they are called by set_direct_map_{invalid,default}_noflush(), >>> pages in direct map cannot be globally shared in TLB after being used by >>> vmalloc, secretmem, and hibernation. >>> >>> So set PAGE_KERNEL isntead of __pgprot(_PAGE_PRESENT | _PAGE_RW) in >>> __set_pages_p(). >>> >>> Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> >>> --- >>> arch/x86/mm/pat/set_memory.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c >>> index abf5ed76e4b7..fcb6147c4cd4 100644 >>> --- a/arch/x86/mm/pat/set_memory.c >>> +++ b/arch/x86/mm/pat/set_memory.c >>> @@ -2177,7 +2177,7 @@ static int __set_pages_p(struct page *page, int numpages) >>> struct cpa_data cpa = { .vaddr = &tempaddr, >>> .pgd = NULL, >>> .numpages = numpages, >>> - .mask_set = __pgprot(_PAGE_PRESENT | _PAGE_RW), >>> + .mask_set = PAGE_KERNEL, >> >> With SME/SEV, this will also (unintentionally) set the encryption bit, so I >> don't think this is correct. >> > > Thank you for catching this. > It seems PAGE_KERNEL was too much for __set_pages_p(). > > I think __pgprot_mask(_PAGE_KERNEL | _PAGE_RW | _PAGE_GLOBAL) would be correct. > Thoughts? That should work, but you are counting on this function being called in a specific situation. Should this function ever be called from some other place in the kernel, in the future, that might inadvertently apply the global setting when it shouldn't. I'm wondering if adding a specific helper that takes a boolean to indicate whether to set the global flag would be best. I'll let some of the MM maintainers comment about that. Thanks, Tom > >> Thanks, >> Tom >> >>> .mask_clr = __pgprot(0), >>> .flags = 0}; >