Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp487226imn; Fri, 29 Jul 2022 13:15:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uUjnLYe8q3BZEtqKe4TPcH63n8voYA1cq6fHDLlkHimbJGaHS+Ae7OCy/RyasiGMBpCCnP X-Received: by 2002:aa7:db8a:0:b0:43b:75b1:92e9 with SMTP id u10-20020aa7db8a000000b0043b75b192e9mr5053114edt.223.1659125745364; Fri, 29 Jul 2022 13:15:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659125745; cv=pass; d=google.com; s=arc-20160816; b=N/1q3BDtQAuJPby3QdNhJpyuKryZ1mtGKJN57W9uUd8AeW6cBLIfnkijuGca2gl1uy jVDZlp7hu0OrX0H81OAeB1x3CB3YVdrkdohPRfYirsASB8d25mGsG7XJLc/THtUq60oP wHkTDHShvkMwRyIZTokxhZAC0OmswgdKGuED6/3b5KBJ2vT0j3yo9CH0OkyA9yt19v6z t+q0WFjVxT7fP4pwntBQjGPp5O8EuyGdkUViZyFVZbYbXqC2nWWAfNKjiN6ah0F1A8me 4TQvIWsBoi+7yXC5lhvWSlnYXC5k1JgcujGZL30ckZVls0pRxUJQo1hcyIhIRGSuTnAr kUkw== 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=c65aZY+cTHp9LB0d+j6F1NbEme0FckOKveGAfZJbnjw=; b=Lr17aIsnvFVT3WptF3TOn5JBpzYGMp2W75/nUja+ri4RokE/8FYS4ZWtOMePIUHxdo FNkoFgXPeeZWGfIrCgNjvYv6xyNX7WFItgQbwcXsCk9x2A097/qU7xI1qtlRWG6r3YD6 lXGQnJ8ehW6QmiB4/1fnSbHu/u7FOc1FbCfYxISEcQdbejbSPz3xcKUs6J47VS1KGVrc NN76kGpw167wXZhrmI/xUmEFhUV5vgxkz4emFkMUovc388Pyiy/mxP31WN4M75YfE44N Kqcm6OXRQ4lQotqytpdp6lmGQPqhQLQ24y9bUBwg0lPziXE8uBXxGpGf16hknquS08/0 bITQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=cp9KeQdA; 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 e3-20020a056402330300b0043bdfb85e8asi235164eda.450.2022.07.29.13.15.20; Fri, 29 Jul 2022 13:15:45 -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=cp9KeQdA; 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 S239122AbiG2UMK (ORCPT + 99 others); Fri, 29 Jul 2022 16:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239023AbiG2UMI (ORCPT ); Fri, 29 Jul 2022 16:12:08 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2068.outbound.protection.outlook.com [40.107.244.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4748C85F85 for ; Fri, 29 Jul 2022 13:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FrPziedb01eG5CAJ4fM4nB9LvsPEqHOrbhXxrlEpCeIp/sIMa4AsEBcEjSVPJ772hgUhNMQ0AFEwEL9S2admaKuEx6OCrj4q9xGujkTy1ecw5TVi2JoFcOynou7RNkqm78mtSq4jzmsYANj2GvEBLh6nMpqP83X6G1eRhqqgbAtT87B3FBBfLVPT3eUuKPhEgsuK6enwvr+unw1BhePZ6yCzX5XnTbBI1mvF1hPUgcz923Ip8SEuk7Vv70hYuzg/9sinl5zL20VdR82rUX6AFbplOUWmS1VFZIvJu+CY4XEYKORMILEBIN7+QwCPD22lMnEeHD8kiI9adssBgjRQqw== 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=c65aZY+cTHp9LB0d+j6F1NbEme0FckOKveGAfZJbnjw=; b=eHFzCInYBS/E9r8HqkjjyNDjNkSHPAhZqv5UhhFgPbBAGkwufAW0L4JFqxJjFLsEUaxb/HvxNclxe4Q4GJAqmAFWoH2Be+aU6emaZVbJg1C1q0cLjlckZpAHW4mDiaJlS58/LiGpmAuK9VXstULYY4QIyhlUzKIrEetvE9rxn53GDYWM8RHCqRU020AaAXbW5DbpL7q4PQNNQYdRnPdb96nOitQBqYqzp65PeVwM1FBStKYNkkql4xLKkVLiEP+ONdFVuZ8PqFeY7mjzHfsZ91cO5DS0uaBvJmYhhQc36JpRNxvhZS70byE/QiN3wM2qGmh3opVCzbB5vB8/+3+Kqw== 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=c65aZY+cTHp9LB0d+j6F1NbEme0FckOKveGAfZJbnjw=; b=cp9KeQdApNIS7ByiH6R1mNcP/UqOi8qCSAUXCGt3MtPgpK0J1R2ijrDhIUsl37GM9QE6+rEsUCxfLTNillyjRB/DWWJP0QMNcmY4YDZM1t26MELsiAbsV6vdvEy6f3TIsz2HfGwYc42jD/BkF83+ufYCavlHYFBDmZaM+HHIeaE= 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 MWHPR12MB1629.namprd12.prod.outlook.com (2603:10b6:301:3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.12; Fri, 29 Jul 2022 20:12:05 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::1dac:1301:78a3:c0d0]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::1dac:1301:78a3:c0d0%4]) with mapi id 15.20.5482.012; Fri, 29 Jul 2022 20:12:05 +0000 Message-ID: <1b50311c-448b-96aa-1d96-f4bfed409c1f@amd.com> Date: Fri, 29 Jul 2022 15:12:03 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1 1/2] x86/sev: Use per-CPU PSC structure in prep for unaccepted memory support Content-Language: en-US To: Dave Hansen , linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "Kirill A. Shutemov" , "H. Peter Anvin" , Michael Roth , Joerg Roedel , Andy Lutomirski , Peter Zijlstra References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> <658c455c40e8950cb046dd885dd19dc1c52d060a.1659103274.git.thomas.lendacky@amd.com> <9da5204f-5c8f-b47b-bcc6-d68ca63db08d@amd.com> <377f6c30-bdfc-55a4-bda7-f29c60c53300@intel.com> <70a5c939-16a6-d5e0-2e38-ac7adbed5fc1@intel.com> From: Tom Lendacky In-Reply-To: <70a5c939-16a6-d5e0-2e38-ac7adbed5fc1@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: DM6PR11CA0060.namprd11.prod.outlook.com (2603:10b6:5:14c::37) 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: e13aa24a-bcd3-4057-18ec-08da719e9b44 X-MS-TrafficTypeDiagnostic: MWHPR12MB1629:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Trhi5mPLSpqqudw9sTe+fs6gmrqwKHNbUuuCB6UAaTFwbCEcs1bOQOZiDKYZjgqdcUEZVuCyZE0mkEiK9xm6UGKmU4ir3Z/Kwitxtqar3cDWUAiezQ03GT1CxPOOsLYCDi9IepfIwa13wAjR+k9o01pSElhDW+x828EVO6JsVeXQ2j7gY/7mu8InHW3wdy+m2VkX09lNn25xmRdSEoRhTJlP4KM90Rdp4fUbmLvkI6Zj3h32vVSOczQz1wpuNFjUyNlB+JBVvuFbMia3Q4I5ECU/0horzV4VZtaRn7FrlnDL+i0DaTTMzx1JhsvGQ7rDF/qsPMfTBEqEr0zkOTonUUSQBZwjNwqE8sMMJswBEvOhb+5kSQ1396BclK6ERTl3qp5FVZgRZsj6qvkyDaafmTMM1VlIDgccozYRYwSxXVKVdkE7SN5/e5p/rHHoVagivf0mP1poKTQmGV6T8uVqq+m08n0ntoWQWQ5HiTH8UtA11dwhUqpSOYN2Ad+iu0kp6DtKc0MIo12WcXtIcNl8SKmDPFTRhVqLDGb+6drjASFV2g5xsQuMNrw1vwojkIMjKJ2GLTG3fN0KpXRFXPXMi/gnXUEjEEmFzOQpFMuLbHzlAYx2XNSptEEl5wba9HFZgp5dHCFkfA21PfomJkNWBLKrV8PiTdPL0GhCtbo1hj7pcH0b4c+FFxWNnNu71T0gIOAb5CEquKwpUPy7m0/bNWQ8vEsTK8LqtO9+skki1eB/3zsHCI01Aj3msyRGvb6rLN07GuY3ahsluA4uAMfZdoiWXZdXgfnvftAhdv6LVvUfkKKZD5Y/xSSdaWdl/ag00OPC+2ESYpuzd+ZPcEP5Pg== 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:(13230016)(4636009)(376002)(39860400002)(396003)(366004)(346002)(136003)(2616005)(83380400001)(54906003)(186003)(53546011)(6512007)(36756003)(6506007)(31686004)(41300700001)(26005)(7416002)(2906002)(86362001)(5660300002)(66946007)(8676002)(66556008)(66476007)(316002)(31696002)(478600001)(6486002)(8936002)(38100700002)(4326008)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SkJCNDJCeHNFY3hnQ09hdkdMVlhhUGN5cmxtcGNKbmt1bDFabWpROWtPN2l4?= =?utf-8?B?Q1cvUlBMdTJmdGlDRlNKaDZseU9EM21qeUpXejV1S1A5cGFwZE1zaEZOcUxq?= =?utf-8?B?THRGU1llMDJUNTRuRXVCd05GcVZGUFJPY3Zlb1llTkExWnJmRjFjM2hkWE5D?= =?utf-8?B?NUYreG9jSnUxM1pQbjhTMVJrM1M1M2pqSkgyWUpySXowT0hOMkZlV2dDbDBs?= =?utf-8?B?Y0FhV0NnV0t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8?B?RjBid3JrL1V5OTRlSlF6eFk4OUxiQkV1T21aaThZR3R1SnEreEZkdm9MWGRM?= =?utf-8?Q?JY6rLmDaEiaPXFTeJK+reE9sn?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e13aa24a-bcd3-4057-18ec-08da719e9b44 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2022 20:12:05.0830 (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: 4mhf56X/lL9YNMBMMbOqbf5CtO29WDNksxK9KJTzKUEhAx2SnbllDaxdUAzccPaTwRcDqBNLdD5kdZoSLDTeCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1629 X-Spam-Status: No, score=-2.1 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 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 7/29/22 14:28, Dave Hansen wrote: > On 7/29/22 12:22, Tom Lendacky wrote: >>> I think this tidbit from the changelog threw me off: >>> >>>> Protect the use of the per-CPU structure by disabling interrupts during >>>> memory acceptance. >>> >>> Could you please revise that to accurately capture the impact of this >>> change? >> >> Is s/memory acceptance/page state changes/ enough of what you are >> looking for or something more? > > That, plus a reminder of when "page state changes" are performed would > be nice. How frequent are they? Are they performance sensitive? > That'll help us decide if the design here is appropriate or not. Without submitting a v2, here's what the updated paragraph would look like: Page state changes occur whenever DMA memory is allocated or memory needs to be shared with the hypervisor (kvmclock, attestation reports, etc.). A per-CPU structure is chosen over a single PSC structure protected with a lock because these changes can be initiated from interrupt or soft-interrupt context (e.g. the NVMe driver). Protect the use of the per-CPU structure by disabling interrupts during page state changes. Since the set_pages_state() path is the only path into vmgexit_psc(), rename vmgexit_psc() to __vmgexit_psc() and remove the calls to disable interrupts which are now performed by set_pages_state(). Hopefully there aren't a lot of page state changes occurring once a system has booted, so maybe a static struct with a lock would work. I am a bit worried about an NMI occurring during a page state change that requires a lock. I suppose, in_nmi() can be used to detect that and go the MSR protocol route to avoid a deadlock. I can investigate that if the 2K-extra per-CPU is not desired. Thanks, Tom