From patchwork Mon Oct 24 22:46:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp723574wru; Mon, 24 Oct 2022 17:29:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5xPr2KIkIU9axZP8Nes9ykP6t1c8sG2PcTgKxupVIlajPooiStXfbIbd2obLWg/YgxlCkY X-Received: by 2002:a17:906:9b83:b0:730:b3ae:343 with SMTP id dd3-20020a1709069b8300b00730b3ae0343mr31100405ejc.670.1666657775407; Mon, 24 Oct 2022 17:29:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666657775; cv=none; d=google.com; s=arc-20160816; b=I/OezcLe0JnwiltbAYFmTgvtsXnQzm9378v8xLfBWYO7s4CTCtNVjYaz9C9t8O5b+8 oIvBcW1owoOTLfO/fxjoWnVxQnEeMB/WYURwb7lQJfYTYyAS8nexrUHHmgBnDBcBomWo nsG0sxOT9mWofuCH7qAvXGis8QQ5yBOFhB/c4ajPotNAZJxifhCVGyzsj+2/tPkXvjLn sGvavGLNFkYnuqqtSCfwpmDNgQmJgqpTIF2iONYWhlBunilmmH4+DKKmbwgh3q0UC0W+ sDzI0tU/lmLx0immrQFGjeJS+t/I+w4MB+pqDdeF0B7zp5JCbdspoJrUs4V/YJxJXTjq R0YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=AwCVjIH3fuXtFw6RC7AMHfdiXpbNVRxho1cvQpgLuOk=; b=D2+N14LslrC1rYSkdnis8tsO+/Y2uUqngptnCQCyAZbgqCkRm38e2X1+Rvb0VAdMot zyIAMNX8sSIImGPg3lK067pSly7vluUGx8pV4wElQHf559ACtBs2gjtZ3h+AMaySq+54 03UF5Cl2GVQEP9xlqBravhLhcu9vo6JYXAKCQYJytZjUj21uErnT794KzH4bIfDPDlKw ICpQEYFDnx6Z/Ar3SMz1tV0TNYavDTnpKaS7KFwODe7bDpc9tTMXD1g725mzdtDMHTPi J7UMOr30zSlaTZfdOlP/9x56aHxgdV3DWBLZ17WByehnXeqP1HQyT4rPvctQ4+6o7wFr F2fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="MiCR/3mN"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a13-20020a1709066d4d00b007804b5a2c48si1089646ejt.521.2022.10.24.17.29.11; Mon, 24 Oct 2022 17:29:35 -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=@google.com header.s=20210112 header.b="MiCR/3mN"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231209AbiJYAXr (ORCPT + 99 others); Mon, 24 Oct 2022 20:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbiJYAXZ (ORCPT ); Mon, 24 Oct 2022 20:23:25 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08C5210C4FF for ; Mon, 24 Oct 2022 15:47:01 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id l185-20020a6388c2000000b004610d11faddso5220473pgd.1 for ; Mon, 24 Oct 2022 15:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=AwCVjIH3fuXtFw6RC7AMHfdiXpbNVRxho1cvQpgLuOk=; b=MiCR/3mNpnr11BBjH3q1p/mmj/KYq1dJcrlyj302pTCZ99GrpG21yCIWInryUWsYZO NahMPSx10izNkzXzGNu6VuMqvS9PDVKRTmuekqbnd9+81WcCEoY2+sk5UfeOAQs6zAV7 fFjN2hwGqdyEbUsCyHre3QVnMTMQuZ+4CHJHlAx6bTE/u9gcMci2n1FAPJj8gdDog/3R MU/dE9tG3+BnpLNXBJFE+AzKK9U+p3SVFvYCBlqhvODCgSU7io0wxiMliLuLoCzdT+hH Es2B3h9Onr5vjws3lVIX3/Q0+dM+uxCe4S+YEfQkQkgpsz4gLAlKd0HD68TJIvdismvx kVEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AwCVjIH3fuXtFw6RC7AMHfdiXpbNVRxho1cvQpgLuOk=; b=PVtJxBKqDkO0pn1jlUwSy5QbKcKro4enpAIMdesQB8SgxuI+P7MY1BhX5Yd0Aj5bE1 f5L6iuOAGRz4R5JHsiRMT/4iwbWWJk3pGOY74VNKJC1vBswafkC+Es0gPtgVNncOV7UQ 6cOT1dn0IogcaVuG4cXzjdViibiAoSMOl+YwdbgueXW7fp01k5VDEOPxYV5VOc86h1y0 2i2YCVsEogqGPa98e23qlW65zoEuyp8TSrs4iO2FyenCe9vaHMU4FWwg/lpz0AIQFrTX pAFo7o4/8KFgADm6coJbxpBF/RCgjumSsQyYMDWB1fkdYAClMaVSnktkIt9nBSeta90c ZLyQ== X-Gm-Message-State: ACrzQf1ATmZK+l1eu4ge8efeLv0urBu3rlzRiGN7Ui3ufirxA/HCK5Vs mInN4kzNQyczSM4NHHcO8ckGwUQ3g6ILQyF+qXmSwzGD+MJjeMOx8ZuHVdCnTAeoL2iGF/+VFJk kAsKjqYN9ClCIdZcfgKrseBe4mlt5H9EoMufZrwNECj2nQredcQucc4xEL6yiEvR1ZCApw9cAV3 ipD1Z87lM= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:aa7:8011:0:b0:567:70cc:5b78 with SMTP id j17-20020aa78011000000b0056770cc5b78mr31698384pfi.29.1666651620446; Mon, 24 Oct 2022 15:47:00 -0700 (PDT) Date: Mon, 24 Oct 2022 22:46:53 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221024224657.2917482-1-dionnaglaze@google.com> Subject: [PATCH v4 0/4] Add throttling detection to sev-guest From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Tom Lendacky , Paolo Bonzini , Joerg Roedel , Peter Gonda , Thomas Gleixner , Dave Hansen X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747617343226020163?= X-GMAIL-MSGID: =?utf-8?q?1747617343226020163?= The guest request synchronous API from SEV-SNP VMs to the host's security processor consumes a global resource. For this reason, AMD's docs recommend that the host implements a throttling mechanism. In order for the guest to know it's been throttled and should try its request again, we need some good-faith communication from the host that the request has been throttled. These patches work with the existing /dev/sev-guest ABI to detect a throttling code. Changes from v3: * sev-guest ratelimits itself to one request twice a second. * Fixed a type signature to use u64 instead of unsigned int * Set *exitinfo2 unconditionally after the ghcb_hv_call. Changes from v2: * Codified the non-firmware-call firmware error code as (u32)-1. * Changed sev_issue_guest_request unsigned long *fw_err argument to u64 *exitinfo2 to more accurately and type-safely describe the value that it outputs. * Changed sev_issue_guest_request to always set its exitinfo2 argument to either the non-firmware-call error code, the EXIT_INFO_2 returned from the VMM if the request failed, or 0 on success. This fixes a bug that returned uninitialized kernel stack memory to the user when there is no error. * Changed the throttle behavior to retry in the driver instead of returning -EAGAIN, due to possible message sequence number reuse on different message contents. Changes from v1: * Changed throttle error code to 2 Cc: Tom Lendacky Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Peter Gonda Cc: Thomas Gleixner Cc: Dave Hansen Signed-off-by: Dionna Glaze Dionna Glaze (4): ccp: Name -1 return value as SEV_RET_NO_FW_CALL x86/sev: Change snp_guest_issue_request's fw_err virt/coco/sev-guest: Remove err in handle_guest_request virt/coco/sev-guest: interpret VMM errors from guest request arch/x86/include/asm/sev.h | 4 +- arch/x86/kernel/sev.c | 10 ++-- drivers/crypto/ccp/sev-dev.c | 2 +- drivers/virt/coco/sev-guest/sev-guest.c | 61 ++++++++++++++++++++----- include/uapi/linux/psp-sev.h | 7 +++ include/uapi/linux/sev-guest.h | 18 +++++++- 6 files changed, 82 insertions(+), 20 deletions(-)