Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2993472rwb; Fri, 20 Jan 2023 09:47:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXsz1m1uT1s/5sihszK/fRCA3BZuzmXgTp0gKeAj/0lVMoQTvSsPLiQ8nuo3VGGdhydWaAuD X-Received: by 2002:a17:90a:1a04:b0:22b:b448:e88 with SMTP id 4-20020a17090a1a0400b0022bb4480e88mr2129206pjk.5.1674236870054; Fri, 20 Jan 2023 09:47:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674236870; cv=pass; d=google.com; s=arc-20160816; b=XVKfGc1vOIOvO7xMZy3ZMv8TTcUESG0ddby3vDPZWHvQz0sDNqe6iU9e6Z3o9Hh75F UUYGYH0KnPHG8H6OVfjnjcjzFDCpIbnYrJDrii1aHbFliMAcDQEZRVif5uOLEnZTuqJZ xNZpdPGlPN++FP3XYZ5I20D8Zq9SHDJC+r0cG9nVvLIQQOySW4b3A85Fun4cAbmyeZiP Wb6j5yB0q4UPtCYMQqzdTCxw/ASklAo44dJItZhgMPdyCR4NuGssVyWGQKpCapM0cFhx 383ZAyLkB3bguwIt0t2i9m3m4L8Dc43aJvNfmEQfS1uJG1FyAWkYg4GWCd4NxcWF7oXA EQyA== 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:content-language:references:cc:to:subject :user-agent:date:message-id:dkim-signature; bh=gDQGUover6l5wdOuwh76GjgYxm9N29J582/L1r/j0Eg=; b=gcda8MHGyA7gHrt3Xx09fozIizM89zYvIA07yScgH+UbdWBsXgo6p5FY5kJzJLc/MI GfeQWgRwUC9G9Ckj9kRsqbnsQfGN/IOTMlDSHshkAr11Y5krtDUECRzoScpC/fBAkL+g xbkRiZ/vLsBMxrVYr2/tXvZdGA/MMbI8vXAJOOAOJEQU+eVNtefxY6ltnnPVtd2vQDYL 8sEhCLepK76nov52BSTjUGi1h5f03MhKtj8+ja5a3RWDSEo6OqjKU4TvVzzJJNoyTdmC WhOCkhvGaVjxIz3IF3p4t5j/EzYKJcLLt8oddWDCLb00uVU2QdT+dflrHZKm2bcuvER5 YX+Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=0C17GLMs; 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 e68-20020a636947000000b004d23c2c5f75si4932083pgc.90.2023.01.20.09.47.44; Fri, 20 Jan 2023 09:47:50 -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=@amd.com header.s=selector1 header.b=0C17GLMs; 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 S229901AbjATRQB (ORCPT + 50 others); Fri, 20 Jan 2023 12:16:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjATRQA (ORCPT ); Fri, 20 Jan 2023 12:16:00 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2047.outbound.protection.outlook.com [40.107.101.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95D726E411; Fri, 20 Jan 2023 09:15:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d0yTtEaumMqVN6rfTBeMdOYgzm6uPYVxizeyS9pv71rPiri+twT7deXLP4gRzn45U8rJDj2rnrcjzX4akAPtBo5/d/yqsCSw7Vb1nN2++vl7uqVMxeq9G6EGsAuHYbdfD5RyyB0w5b5L2p9v5g17Bjy06zD0Vpu9yIbWLKyKdutYU1vKVvOoMXG9xCOwk7nVQEQYPR4CGrQn37aPK6iLXgbqtLy8tEzsQrwS/bfH6+SO1F5E+OhQwCfhiWf+O0/HgFLUp13RKd5MF9Pk9g2iwwNuxW1EXO0ruwURtmZNY9hCFp/3a7PfhiFN8Lt1YFE1Zk8C6P4BFX6ojaLHBIUlhA== 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=gDQGUover6l5wdOuwh76GjgYxm9N29J582/L1r/j0Eg=; b=YTXsM5IGSCIWexsDTXus1CChA/ejftHrTniTU4zcMhyD6IMbPQm/5pRrmznMZYsuj2HmcGS6U2knVjZC4eHyXIDXdBb/xmMafG6B1n7cwWWCNIH3Sot++tpd+K8619BCgEOR6SyWkaAZJ6tfinxIhEtfVQ6JEF6XgMbSuJM1pmrqum0gDZB5JkNWIBEBJKC4oanOwXRe14h8ykh/J3/DzZfpbbXpJC38fTC7gs5MTTS8hHAquwN6WRemrxVg0uop4d/5P7P/xA4l7smJB86ENFCpWPRcvcZpTm3UDamjYPK7cqtlR7hbFAzJqyHVggTNzBc+A7kFZLGsSagbCtK5Yw== 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=gDQGUover6l5wdOuwh76GjgYxm9N29J582/L1r/j0Eg=; b=0C17GLMsBWYTR80IEXDvgMzReeochXLLzJUC4Ts3goDXcEf8a0370X1iVNtoCkgd37CMTr6akKD3lTgfBtjGE5WqHIPCQKarh8rFvwjr1TsoRpkShP2bZdzWVePwqAK0Ou88Ap2y7nAPCVgL2iDBz4O2z1MAx/mmSuED/gsaVmA= 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 CH0PR12MB5188.namprd12.prod.outlook.com (2603:10b6:610:bb::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.27; Fri, 20 Jan 2023 17:15:50 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::8200:4042:8db4:63d7]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::8200:4042:8db4:63d7%3]) with mapi id 15.20.6002.013; Fri, 20 Jan 2023 17:15:50 +0000 Message-ID: <61e64ce5-df76-f34a-1dc8-a0f1a856e2e5@amd.com> Date: Fri, 20 Jan 2023 11:15:48 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v3 2/2] kvm: sev: If ccp is busy, report throttled to guest To: Dionna Glaze , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Ashish Kalra Cc: Paolo Bonzini , Joerg Roedel , Peter Gonda , Borislav Petkov References: <20230119213426.379312-1-dionnaglaze@google.com> <20230119213426.379312-3-dionnaglaze@google.com> Content-Language: en-US From: Tom Lendacky In-Reply-To: <20230119213426.379312-3-dionnaglaze@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SN4PR0501CA0027.namprd05.prod.outlook.com (2603:10b6:803:40::40) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|CH0PR12MB5188:EE_ X-MS-Office365-Filtering-Correlation-Id: 965d10a3-a21e-4753-bde1-08dafb09fa85 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4qyNArWW3PuKJHUz8Iv+uAK5Fg88DQ1C5zQVSsUsrVpOSRqHurDSXTNBhuLPX49kHxtxc/uufgdU3ZtHGlr6sVi02hwzqFEmW8ZVpXY6oKPQCXqftsK3lYOd81YBWUyFATK8+RyOph8hqD5FT2yKbgcUwGs9dnu4GJlK+Lt91YB17+Ah+nuLARuOYOqP2GXPyPnseyYrYBPX1Bc92p8NE8d2PhPYIAnu94YvxWVrbLAywRhU/6KBaLaqmfi908fH0Cp3mTPk44AEgDqfRHhPRujN6xUZtoMbGMb5eFgddvCqo/c7LzrLAjxDh1dUE7S1NcI/7PwIk8YcvX5m3fEYwbsFIXaCsHmN2Xn17h9JGCq39VYVGiEbblY7mZj5x1VOfZdpAcYCXzHbrzQlJenyzN4/wUW/szQsFr/cewqxNFMfPT7OFzvkuMQJdf+XTjKSgU4a7PTDDlAOKJW1KDEpmZsNZgsSFGG9gp7pkvKVN6tiF7PGX4EEaaKNg1M8NcI9D3HxaQ8PD/IOcMdiFEwsnRFXpI7A5xxQN1FTuPKAkNF+tzEdIFlkn8kQvTX6/ThMXRoFI2sZDwSk8fZEwxkXIxlM2NbhiO8ABph235GehiFrazS6pC3NLlt6p9mIQJj+zCd5AbIBTNlFd4caeSdTEo0QZ+s3TelQoA7T5vBAoB0Ae4D6avMZ1BVhciKq/ophRvOcYtC0o9+yOqb6nGZAZI54BSELlrEA69ldd5BRzCM= 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:(13230022)(4636009)(346002)(376002)(136003)(39860400002)(396003)(366004)(451199015)(6506007)(478600001)(6636002)(54906003)(53546011)(6486002)(31686004)(110136005)(66476007)(66556008)(66946007)(186003)(316002)(26005)(6512007)(4326008)(8936002)(41300700001)(2616005)(36756003)(5660300002)(2906002)(83380400001)(31696002)(86362001)(38100700002)(8676002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VHArbnU4MmFISUhnSnc0NTF1bXZaN3cyb1hCSGFHWmxHNFUvZDZwczI2d2I3?= =?utf-8?B?RCtZaVBRdU1ucDNkaHFKSWJaNUNTSmw0MUZIOGhZaWYrRmk5YnE2SVhzYi9w?= =?utf-8?B?Q0MrY09ZVDNDa2V0YmhTNjFzM1dKZGdtTkFxd2l2YXVSVE5RU25zRjM3c29U?= =?utf-8?B?eGk1Qm82K2N5anE2aENHZkFzbmx5a1VHZm5sdlNPdng0ZjNjNjlYeVBQaHh5?= =?utf-8?B?VktHNVVHb0dzdG84eUY5OXlRRzhNUXU5NEVJTmdGSE1zR0c5ME9qeUUydlBl?= =?utf-8?B?cldRLzlDNjFObDFFaytaUlRDWnA0amEvbTlUUTNqQVdOZDAwOSsyWmZuMkl2?= =?utf-8?B?QklNdDRsdXRhUGFZNTF2bGlrbXJiTFVDRjNhei9WYktVVFVTTmE2a1hJSnpq?= =?utf-8?B?M2JMdVFweHMwMlZnYkE3K2pnN1lBRS9yVTJMUVBVMDN4ZGlvMVAxaj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kZGSEVZS1VSdWRPSUhC?= =?utf-8?B?SEw3dXM4TVVGWk1sdHR1eitHOWpaUTRyam9kUHRiWEFQZEtTalVURW94a2h3?= =?utf-8?B?L3JMUUV3aTU1NzQ5TnY1VDJMdGNSenFpaW5heWc4YVBWc29kc3pOT29jaEVK?= =?utf-8?B?dEhGV25ZWEpnNUZxcm1heWFBcG1yQ3QvV1FpaVp0ckFqdlhiWmtyT0Vscm5T?= =?utf-8?B?UEVadjFvdE52aGVDRWxCSU96NTZIdlEvWHNmb0g2RGFXSGVFRFhWRWx3YVIr?= =?utf-8?B?RnBINDFzUzFuaHcxTVpkTEhOM1l2dndYOXFGQU41RG5ST0xoNnVqRG5KenpM?= =?utf-8?B?cE01ZzNGK3Npai9CNEo1MGUrbFp6ZzlzTEVYTHF3aktydFhCUUVDZTFXaUNq?= =?utf-8?B?SERNTUhRYnhhNjBMMkN0TUFzT3libGN2MS9uaTVOQzNadVVCakNJSjNENVB6?= =?utf-8?B?b0VqMFpZbWUwbjRaeEtHT094bmJSQVpBRTh3TFNqd015dWg2NU9PeXVOTXl4?= =?utf-8?B?cy9HcitxeUlwYTVXU2kyMS8vTGdMYkpiR3h6Y0dvZ1dIUTVnWVFCai81eGV4?= =?utf-8?B?R3I3RERBSHROTFV2d2tRclJBNkVvNDM4MWlFS0d5Z2pSdkhYOUgrMG5SQ2pS?= =?utf-8?B?TzQwMmxoeDVHTytiWkk4OEJ6MG9ySDdJcTZIdEJUR25BZXZaZ2xGWW4rdmd5?= =?utf-8?B?VVBNWm1mTXRUTE9sMm15bXZ5QUVQYktSWnFTQ1lCQS9rYlZ2eXZXcWhxcG9r?= =?utf-8?Q?MiFn4ORfQQw0L9xJh8YZ3t1m9?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 965d10a3-a21e-4753-bde1-08dafb09fa85 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2023 17:15:50.4879 (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: cN6PufOqXoSzJ4f2U5Q2lHXXT5WQBs/9JDmld8W4fMgj42ImsheygiwXuwWDBDnbqK0iuSuJyXs9B8nKRNTItQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5188 X-Spam-Status: No, score=-2.2 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 1/19/23 15:34, Dionna Glaze wrote: Since you're building on SNP hypervisor patches, please keep @Ashish on direct copy. > The ccp driver can be overloaded even with 1 HZ throttling. The return > value of -EBUSY means that there is no firmware error to report back to > user space, so the guest VM would see this as exitinfo2 = 0. The false > success can trick the guest to update its the message sequence number > when it shouldn't have. > > Instead, when ccp returns -EBUSY, that is reported to userspace as the > throttling return value. Except the CCP driver doesn't return -EBUSY because it is overloaded. It will simply try to acquire the mutex and continue once it has it. There are a couple of places that return -EBUSY in the driver for other reasons, as well as other -E* values. It looks like these need to be handled properly by the SNP hypervisor patches so that a "success" isn't reported back. So this patch isn't necessary, but any -E* return value without having actually called the firmware needs to be handled properly. @Ashish, please work with Dionna on this. Thanks, Tom > > Cc: Thomas Lendacky > Cc: Paolo Bonzini > Cc: Joerg Roedel > Cc: Peter Gonda > Cc: Borislav Petkov > > Signed-off-by: Dionna Glaze > --- > arch/x86/kvm/svm/sev.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index cd9372ce6fc2..7da1cc300d7b 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c > @@ -3642,7 +3642,14 @@ static void snp_handle_guest_request(struct vcpu_svm *svm, gpa_t req_gpa, gpa_t > goto unlock; > > rc = sev_issue_cmd(kvm, SEV_CMD_SNP_GUEST_REQUEST, &data, &err); > - if (rc) > + > + /* > + * The ccp driver can return -EBUSY if the PSP is overloaded, so signal > + * the request has been throttled. > + */ > + if (rc == -EBUSY) > + rc = SNP_GUEST_REQ_THROTTLED; > + else if (rc) > /* use the firmware error code */ > rc = err; > > @@ -3713,7 +3720,14 @@ static void snp_handle_ext_guest_request(struct vcpu_svm *svm, gpa_t req_gpa, gp > if (sev->snp_certs_len) > data_npages = sev->snp_certs_len >> PAGE_SHIFT; > > - if (rc) { > + /* > + * The ccp driver can return -EBUSY if the PSP is overloaded, so signal > + * the request has been throttled. > + */ > + if (rc == -EBUSY) { > + rc = SNP_GUEST_REQ_THROTTLED; > + goto cleanup; > + } else if (rc) { > /* > * If buffer length is small then return the expected > * length in rbx.