Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1195491rwi; Fri, 14 Oct 2022 14:33:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7yw1q/GMprWgh+xZHIi70psLuTJmT6ANFP4kDkUVV70LFTxXv7BLaRQVNS9e120GYZJ4xe X-Received: by 2002:a62:84d1:0:b0:565:b27c:8140 with SMTP id k200-20020a6284d1000000b00565b27c8140mr7420888pfd.14.1665783228343; Fri, 14 Oct 2022 14:33:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1665783228; cv=pass; d=google.com; s=arc-20160816; b=RUvcOtaULYDMtqvW3KvSEWDijyAEkLXuMvCtwsKrA+TYfDpTtyxOogXfpYQ0gx361W ukujNRMQ+khGBk6RMPwnk7m5RM+A+9Ty2dJsoB/n66+sg5kWVAO2O8mr7LNnXfNsa18+ FM6gKsadnFQDR9xT/+H7d1SDitVPJBY77pObwlRcWvRtgnS7dYsXFv7hiUjb9pQR3R+d l/TE9pAv2dK5w6c+i3Zq0ylS7z00u1820v8H6pctuGols+4EP7ros92uCtJhErAYnCJF AnHcjufNXUOPBTHkYlKoSgY5cNMh0YlXJQDdZ1a+mfTHPZjVLpI74A57WzoP9IcQ+1so ZHAQ== 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:references:cc:to:from:content-language:subject :user-agent:date:message-id:dkim-signature; bh=M3GyVn3QcoEbANDuf5loWPqQW7uLPAxqx0xcMbsO3D0=; b=aSjfoe4wxBHbslJynxBa8jVE5B3MRk6sb9VefQD3IrTaFbAe9bR64zSi4uwSQmtwJR xuLjaUHLoNNA+6CpcUBkZvbw/nMughJVFNZXsjrneKrClk9xfikhOZ1Jt0JohYHU8zmm qYzDg3GBIzM2gEEJ6f3mOMALSJ/Web68Uuws4BQdnmljz4UPbhaIqencRUIqaUUlrq/0 aoqwHrboshnhPzFD3mwxvRbE6NPbcmJv+6LElLIwDpXz3C1SLURGJsgZxuJOXSB1EdkS wssPJ4FH2CbbbZY2t31z4WlqLVo3bvzdzTNnGG6TJWy6f12lbGrfQsQqLmM0hau2zOqn zS4A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="b/DlwYC+"; 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 r17-20020a63d911000000b0045f8411933bsi3650311pgg.866.2022.10.14.14.33.30; Fri, 14 Oct 2022 14:33:48 -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="b/DlwYC+"; 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 S229646AbiJNVb4 (ORCPT + 99 others); Fri, 14 Oct 2022 17:31:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbiJNVbx (ORCPT ); Fri, 14 Oct 2022 17:31:53 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2079.outbound.protection.outlook.com [40.107.93.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B117531DC6; Fri, 14 Oct 2022 14:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z3xdYcE7uTnge03/l4N2vU3jcGj/vTl2GDvHeiJzApGbbzUp0XSt9RmfGyteSOhIMAqBFRxOKJC/3VTX/7kMpx5dp5ZrvVKiseKrQdT1TlxEC1v67BLHAvBM0qawyXlFylTxeBXNUbOXItTY62g6BPSJw+/c8dnPrW7GBjMwIHihnOLZHVEfpPItxYczFyJx8DmdpXoPUep4Mk8TvCicVer1d21wK53Fm32p5eE5gVajTQ4S4TGNgP2x2JKvo5lDK9WwZFmQMUdIOGbadIHaktgsDsSwrqWPXzF1Hrhu5T3qj85kp7DS8O8xbq1pMJibd5eQA+SgwokYbeTrIpH8vg== 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=M3GyVn3QcoEbANDuf5loWPqQW7uLPAxqx0xcMbsO3D0=; b=fxWX/YAFcIII0OX/K0vgY3j3z4hn+sm8vQtLu+jIuwXNTqHm5nANtmdE4C6XzX2RRwbsvvxOa0DcL8vXH1CZ8gN/gi91oBfB3XTckFurEK/4NoiQoOdYn9NLIb0SMUGtW3JN9iAKnTNFkBRGpCsN+EyRuJB7LtfguY6bZhUxWU37B97Evcgd1NuezdBhUF/C/2KFQCtbgaDTGHazF0oywZodXefIC8ppsrw351BkXzfttzgYSZ2iBN4ZHpnQsC7cPTwQKP5QK/MIKJUx8goR0/5re9otRdULoAOv06cdVt7I1TYPn0xvFweidkRyGYAdnGkquOn3TWS/D5Lz8rBOEw== 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=M3GyVn3QcoEbANDuf5loWPqQW7uLPAxqx0xcMbsO3D0=; b=b/DlwYC+aqTylKo4OjTa8CEOaZspjlVx181iyRosJOOQFlO4KvZz7kVM7q/vJgFy85tyCv5xGWoJuf43pKE9lndFwl4SQ62cQMraoJG8KWUPUkboUS3EHDDHU3kJ8iy0MXDPjWW62+tAl11zYSc7u7NT6331rGy/DZimRoPLoPw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by BY5PR12MB4919.namprd12.prod.outlook.com (2603:10b6:a03:1d6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.29; Fri, 14 Oct 2022 21:31:48 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::6dad:12a0:10d6:5967]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::6dad:12a0:10d6:5967%7]) with mapi id 15.20.5723.026; Fri, 14 Oct 2022 21:31:48 +0000 Message-ID: Date: Fri, 14 Oct 2022 16:31:42 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH Part2 v6 12/49] crypto: ccp: Add support to initialize the AMD-SP for SEV-SNP Content-Language: en-US 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, thomas.lendacky@amd.com, 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, michael.roth@amd.com, 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 References: <87a0481526e66ddd5f6192cbb43a50708aee2883.1655761627.git.ashish.kalra@amd.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: CH2PR11CA0002.namprd11.prod.outlook.com (2603:10b6:610:54::12) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR12MB2767:EE_|BY5PR12MB4919:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ef3b5d9-1c72-4d6c-9779-08daae2b800e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ntba88K3Z9QL4YyIgmUSxx2alM3gkeMEDxMKdhumawQYEaZ0phycpibvvmaLkCxa2GFgr2mIVtUipo5hrdxfgZJI/2W1dK/M4sicq9rDz+vhqGKb7rN29ROy9mzD6o8zvTumUluZppgRpcIZ5Fz3Fsal2FCvPvF2yEnsyCyXU78mdosjB5+BYLqyQ3iiP0/y4PCSFX8scHPMpKzBOtBM2LdqnfadJI02p6T3fvv9cLb27iweg+mE1YVVvDfq93XXIqstH2Sr1zJp6HSTV6sFCMIzXS0PIZNozUMZzG5P+HD9614SlCGJUb1btQiUpuVLfOZQk2T/xNx2IGFF0fE+RQ4mrFRBpSSiPkPlxUIqdBZd4W1ps7HDOnZSlLqPYQferfQ0Tqqso5US1MJbsQ/3tbn5I4gk571F3QP7sZ/84J+9grBPZ9SkrTBTvYcgjGtLImxP3F1Wb3owOJyqPD8cU+z1wa5iOjRMe8EIoQgvIU9VWSB32BnPrjdOhqKMKjL9cWYIFQg9gGfHOsATUFgfX5ComMT07oxaj/gzovDCf4STCshmEfEZU37AqbEZLjbvlKzPzT59Z4l72Dx3AjlC0MhvuWMGW+H8aHTdK1807HvwS5+p0WcpdtJlmbCTidBFFRzjKzFP4T+ltZUf+ZUonGKLCn1p/KpKHk5M4IMLUe74wfUa8RIWzg7rWdpi6PCyg7rhkfF26b6aZB0qITBgjIj4DPtXogWbbCt16UUiGtJ+EcTByBpG2ThR6TfX+8ye1hOibmf6orPJ3P4KTg8dJZ/IBCZc6q2qtlP1vpTlOQM= 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:(13230022)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(451199015)(7416002)(7406005)(26005)(41300700001)(6666004)(6512007)(8936002)(36756003)(5660300002)(4326008)(6506007)(66946007)(66556008)(8676002)(66476007)(38100700002)(31696002)(86362001)(186003)(2906002)(2616005)(83380400001)(478600001)(6486002)(31686004)(316002)(6916009)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?NkNweGZuNVE5Tks0eXgycVNpS3JWZENPaEdSTHphU1dSSjk2SkFwOXBDbUdN?= =?utf-8?B?RnVqOWQzUU1nemZDSHRLdUlHTnY0S2xKQ2xzdFhjMTFYaTFkRDg4Ync0YkhZ?= =?utf-8?B?aktHaS8wYWpyV3ZhdlRUQ002cmI2VDlLNXZYZ1QrVlNPbjM3eXI3Z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G9EcWxGNlNGRnlrd3hoVk9LR0RVQkpuYmtqWFRV?= =?utf-8?B?eUZCMDl1VTBnTi9vcmFwQmJUb0VRUFFqKzdiV0N3U2ZXNXdpeGN0NysvanhS?= =?utf-8?B?anZQWCtHWjViNFBmazVBRkZqZ081cFNmUlZVaHlQeWVKV1hDMjNwdTlxTFRH?= =?utf-8?Q?26tx7bb4Sk/Pj4AWJMEtz4XVh?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ef3b5d9-1c72-4d6c-9779-08daae2b800e X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2022 21:31:48.2863 (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: SZLxUdV40JTyL5x+Pa1xN+Lt1gyDOYUMO5OnjDd9LfaFaEsckfxhkNNLmGBHtNGb4nUGn7P1Krea/q9gRsOSPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4919 X-Spam-Status: No, score=-5.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 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 Some more follow up regarding avoiding the second IPI: >> >>> +    rc = __sev_do_cmd_locked(SEV_CMD_SNP_INIT, NULL, error); >>> +    if (rc) >>> +        return rc; >>> + >>> +    /* Prepare for first SNP guest launch after INIT */ >>> +    wbinvd_on_all_cpus(); >> >> Can you put a wbinvd() in snp_set_hsave_pa() instead and save yourself >> the second IPI? >> >> Or is that order of the commands: >> >>     1. clear MSR IPI >>     2. SNP_INIT >>     3. WBINVD IPI >>     4. ... >> >> mandatory? >> > > Yes, we need to do: > > wbinvd_on_all_cpus(); > SNP_DF_FLUSH > > Need to ensure all the caches are clear before launching the first guest > and this has to be a combination of WBINVD and SNP_DF_FLUSH command. > I had related discussions with the HW architect: SNP firmware will fail ACTIVATE if DFFLUSH isn't called, and DFFLUSH requires the WBINVD on all cores. By requiring WBIDVD on all cores, we're a) requiring the caches to be flushed, and b) forcing the hypervisor to exit all guests at least once since SEV/SNP has been enabled, since the WBINVDs must be done in host mode. The order is: VM_HSAVE_PA IPI SNP_INIT WBIVND (IPI) DF_FLUSH so that means we can't combine the IPIs. Also, this is not a performance critical path, so should we really be so concerned about it? Thanks, Ashish