Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29EE1C54EED for ; Mon, 30 Jan 2023 16:37:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237561AbjA3QhD (ORCPT ); Mon, 30 Jan 2023 11:37:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235980AbjA3QhC (ORCPT ); Mon, 30 Jan 2023 11:37:02 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062.outbound.protection.outlook.com [40.107.243.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 065BC3B0F9 for ; Mon, 30 Jan 2023 08:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aI/1G4zhBR3do1A/MNOdvXQKjsYRCQh0xNxr7AR4+nNqh/CagrvvsJKn/+55bzEnqFtCaLTmmOQ+Vv+3nB5Qn243zhxDtAJPqDjrIBF6QdziVHQlMysSlAP7d9Vw/bR33PVQtGk7PqOPrOJIVyFGcxWC+ZH+CfFE91xURsxYT2d6fsKMX3NepwanfFOvvmmGaTmWBTsR7JfK+64CsZCa7hFVdZJIax9WsP1sOa8vsZXMNvSrzHIi9GiV4N/mPOUbhxvA4qJx4vSzDCrbH64Ufu3hKmMMC0+5g5v3C1JO0MmM95Nqjgr2dDjGI97HPQ4haYNNPQ6qSWE+UGY/kNlF0w== 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=Yltb0bXeGBdfrMLqmuvefDcBjciIwfJTdPGOQrUOsbQ=; b=HWPlwAAT9gpCCtJtSTi1j4mb3Pc5CJkvs+7EHc9ZShUUOUD3HUMVfqnG1p+xJA4bqdeVvbZ/bp01a4O4Oq/X4dTY2w3rp9vZJd7KEZAnpEA6BxhtoT1xJ7frIedP6YSA7jpjvkDYmq98t0qORp6Z5XJK05BoK/8Z2GkZjSXDSWeVUZHRoZ20rAeCjXQaz/ySzhCEIYCrTxTLkZirYIoo5VCTx5BWNvFUHUcnuPOPXNMBNslkh/a6WAuoi7iqcil35CQoFS/kpitAKSZ28rer1wwVtbDxI5h4vRuwOFgfbF6tmEZlQF51kypfv5Z35589+IeWhWk+fsSa5gW6lQlvMQ== 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=Yltb0bXeGBdfrMLqmuvefDcBjciIwfJTdPGOQrUOsbQ=; b=C0OZZ+V9H+6ntnp0B016yUwKB2G91QK6nKyFofstLvAbn+axbRbq3ZwuydaY38kVnoP1AzuSNmzOuUnEejyCXEnyNQj8GFsoJIAoMOgzKlCD5ldSxnsuanY8KoVJCMmcGmK5xyR5lJzCftBFZwfOe5dtETCSC7fYnkvAu8xTC2Y= 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 MN0PR12MB5785.namprd12.prod.outlook.com (2603:10b6:208:374::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.36; Mon, 30 Jan 2023 16:36:59 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::6cc0:9c7a:bd00:441c]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::6cc0:9c7a:bd00:441c%9]) with mapi id 15.20.6043.036; Mon, 30 Jan 2023 16:36:59 +0000 Message-ID: Date: Mon, 30 Jan 2023 10:36:56 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v13 1/4] virt/coco/sev-guest: Add throttling awareness Content-Language: en-US To: Borislav Petkov , Dionna Glaze Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Joerg Roedel , Peter Gonda , Thomas Gleixner , Dave Hansen , Ingo Molnar , "H. Peter Anvin" , Venu Busireddy , Michael Roth , "Kirill A. Shutemov" , Michael Sterritt References: <20230124211455.2563674-1-dionnaglaze@google.com> <20230124211455.2563674-2-dionnaglaze@google.com> From: Tom Lendacky In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: CH0PR03CA0413.namprd03.prod.outlook.com (2603:10b6:610:11b::11) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|MN0PR12MB5785:EE_ X-MS-Office365-Filtering-Correlation-Id: ea68319d-3600-4d1f-835a-08db02e034d2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y2G63Nzcv27Yn1itIV+e774DyszglvWV0b3Ov0c2l/7SqciQvgpPoJ2jtSWaRCc1vBwMohqIq5PlH5LSVJjb+NrPk+Mo3hq794dOTwK1DOrOwvEQ7FNFZVWVvVF4ygHs4hvOl9aYC1OFuSFly1vmQvrnWvlSKql2WG3/Kgt6QPR/QHz+Cg8Fv6QlAZY0LBKalp4ak2YmyYOjvG7U3BPuHoa9nUy2JLP4YE4IpU1AxWidMveiYtkBPLq63QhU6k4KKnYdWKvOeJd7bSx43Oe7wI/ZNiKg+HDbLwwImCtgO89v1BuySom+XSQfP4YixprT/22nbNalFNNq3ZSSv+4Rf1PMDfGcY/o2QHRn0MyehFg59ZMXE9+ai1KkpgM2YvzoYjthQXyTtoRKmNsXVxwPoXTyccaE9Jwdvgr7X7mlY998O52aFMN0X+PDtFLqGqbgCRe3hfJZpcGy58DfKdC5/tOM0WAS06yAG+dcBNoE8nYCFO64m2DcnbS7a4BiBoCInuxSVWO9hLj/B8aK6pTlvj5zrZeZA4TE9qb+ohXCpGHGGuNVmy0sLZI3eu95SOh9SK5uyudaodDhQxyH2E60gSvi4lnkDXaDb+B4tGhjkuv1yV5+GyHVhB8OeMbKDO9AenQTS106+O/fIUvpx/NURTuGoW4KOWRK+VwRN7TNPvBV2nFn3AxNOkNoCcBuZiOGR/EqFQO1xOmJwxGSPiCjjJZISZBx8WPt/FKqBiKRG7w= 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:(13230025)(4636009)(136003)(396003)(366004)(376002)(39860400002)(346002)(451199018)(2906002)(316002)(186003)(6512007)(26005)(5660300002)(6506007)(53546011)(36756003)(110136005)(54906003)(2616005)(7416002)(6666004)(38100700002)(6486002)(31696002)(31686004)(83380400001)(86362001)(478600001)(4326008)(66556008)(66476007)(8676002)(66946007)(8936002)(41300700001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TG4wRGVkb1h6NFBtZTloc3pNVDVVY3V6UHJNUzNtOG5JaVpydGYzcFVpVEgy?= =?utf-8?B?ajgwRWZzQ0Zrd2JPNEdHVExmdXg2OWNKYzNuL2d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mZLejRIRSs2ZW5UOXRCUHlaRnB5UG56bzdNbGIrM3VRSjlQblkyeHpa?= =?utf-8?B?Mk9rTENrQ1A1aERKM3pQMldpS3lhWDZhMlR5cDh5VDNoTUppaHU2dFhlOGlE?= =?utf-8?B?MzFWTWFNSGRmc1l4aGkwS3JoZE1FamRrWDBvd0RwRC9pVUVXM013a0ovWENn?= =?utf-8?B?ZXdkV2xINTN5K2I1MUJZaFpkd2lna3ZwK2grQm5PUDlvdTNtb2UxZHRqbE96?= =?utf-8?Q?Qc/kQechpBEteX6RB7ckr96U0?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea68319d-3600-4d1f-835a-08db02e034d2 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2023 16:36:58.9104 (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: 9B2GpcrZ/tdZQiWjnAo8YFB95U9ablwDzE/PRSmrTi2t7c7HgOp39V2T31OiOERpprjFLKqTcbPYsmTngrF1QA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5785 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/30/23 05:13, Borislav Petkov wrote: > On Tue, Jan 24, 2023 at 09:14:52PM +0000, Dionna Glaze wrote: >> The host is permitted and encouraged to throttle guest requests to the >> AMD-SP since it is a shared resource across all VMs. Without >> throttling-awareness, the host returning an error will immediately lock >> out access to the VMPCK, which makes the VM less useful as it can't >> attest itself. Since throttling is expected to be a common occurrence, a >> cooperative host can return a VMM error code that the request was >> throttled. > > So where is this concept of guest throttling documented? > > It sounds like this is something hypervisors do and it is all fine and > great to do that but where does it say: yes, this is what we do and this > is the usual behavior that's expected from guests and HVs to adhere to > when accessing this shared resource? > > Tom, is that in the spec somewhere perhaps? Or was this decided upon on > some call? Yes, this is part of the GHCB 2.02 specification document that is in the process of being published. Thanks, Tom > > In any case, I'd like for us to document it somewhere eventually if that > hasn't happened yet so that all parties are clear on what is supposed to > happen and what the protocol is. > >> +retry: >> /* >> * Call firmware to process the request. In this function the encrypted >> * message enters shared memory with the host. So after this call the >> @@ -346,6 +347,14 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in >> */ >> rc = snp_issue_guest_request(exit_code, &snp_dev->input, &err); >> >> + /* >> + * The host may return SNP_GUEST_REQ_ERR_EBUSY if the request has been >> + * throttled. Retry in the driver to avoid returning and reusing the >> + * message sequence number on a different message. >> + */ >> + if (err == SNP_GUEST_REQ_ERR_BUSY) >> + goto retry; > > I don't like even potential endless loops. > > How about you turn this into a loop with a sufficiently large retry > count which, when depleted, gets this request failed with a -ETIMEDOUT > or what not? > > You could also stick a cond_resched() in that loop so that it can take a > breather between the requests and doesn't hammer the hw as much. > > Thx. >