Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6955918rwl; Mon, 9 Jan 2023 15:43:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXsFOsZui9Wj7KcSiHiW3w7RkfYY9FLvjmoicaXcGqdjcNYoIiaCEkljJ8TFUefJgkmtyXUj X-Received: by 2002:a17:907:8b89:b0:7c1:6f86:eeb with SMTP id tb9-20020a1709078b8900b007c16f860eebmr54275157ejc.7.1673307786372; Mon, 09 Jan 2023 15:43:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673307786; cv=pass; d=google.com; s=arc-20160816; b=jgfmzDx9O48BuJrWTM8FO2s2G0XWGNmFMcMzzzaciWeYqIlQQg6XSd4palJMf8e0Zs iBdayH9FJ5Fxxr7hhagS5BRmp2SIFxbohuU8eye/3WhqSE9jJemtnGRXFQDwJ96NwlBG 7vzq5MFeMSChWrvyVyKnkrHNwlo+GWIBhhEGKULPwLkDB+PfB4OgNBoOSwbWCtccRfGq TIWiH0gbS/Twg24/XUVimRjVUHSIHSKY45IWzP4X+WYOvvf4/lDmDqsyqijk7oq/AO1g h9o7NZKWOo/rwNtsM7F+lLWYXWHAZxr5SnFZYatP43j5d2O25AF7rdBqGsV45MsEHI47 sr/A== 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=gmeTiDNoQqv1YgkX7prYJcWbdgX4PMXoJ48PGIYJfz4=; b=mFJuvWHvKBULu41VJ8+DdQj8Umv+hAm/S17JhiCFngailm10APkg0875nUcVqNvBiz 1m5w4yNNOHltK1gl9hVYfwxSpureyNaDBYtSrPlRR76NrtRh3fgcpoRssFjbB/hudOq7 CVd36hE8wIolQoUUJFM/W58c3xLL77+h941xllc+ez6m14LqyZAJPaT6J8LV5nK2FgRO 8fvZf2ZujCrxWhC2hUlGa6p883pIYV1uS/p1XeUI2iIjjEIqMJUJrWC+cSkMUdN39cM8 9uVgvL6SGBSSRZ8noo9bYcNOVy0F8deGzmkj/NY1twfIHehjtPuipqwNg48VrI1ZK/i/ 6Zpw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=JXdf1JpQ; 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 sa18-20020a1709076d1200b007ae4717bf08si11769391ejc.359.2023.01.09.15.42.35; Mon, 09 Jan 2023 15:43:06 -0800 (PST) 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=JXdf1JpQ; 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 S234809AbjAIXlS (ORCPT + 99 others); Mon, 9 Jan 2023 18:41:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236528AbjAIXlR (ORCPT ); Mon, 9 Jan 2023 18:41:17 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B47463C9; Mon, 9 Jan 2023 15:41:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PMOMrybMGvyr5mX+CDyGkm88PW2je1MOCy0N/21RKUCmCqHdjU7JuZgDHHYvmLWYoNbMh9Wy3OLoZ4Z/kyjvrD7xGV/w4m/KfE5QN/2LGX7tR/gfaTge6J2N96kD3bkzyVvWa+Zcj7ZoZjh3sz/q1Ms2zvvvAofKZpTU9ajKDk8x2jr37dujF3n0/cd4cRH6G5NEJo/jCUAa0666P18nlzqXKKFBrgSQXqIW1P2+xUcd2AFTISZz5Cef7cG4dV3Y9+PI2bLIydWJZFmXNrHoMUwKLEnXi4TRLw1bKZ6COei9qqG4NBWm7lZrLEwjQyvgdG2AYcNGA75YlZKdegvEcQ== 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=gmeTiDNoQqv1YgkX7prYJcWbdgX4PMXoJ48PGIYJfz4=; b=B9X+wMq2RA9dfLqZLdvnwKZAeH7hox78U01H+ixbEHMKX1skWHDDJGMDzo3BQ/RlO3mFl9+DOeikgwAGIkpgwikO+rALl7eE4lmIsBddN+p/4Kf++bzyxYdVYqqtKXDwZFdZozfYqMUllRSPLJYEXP7XP0VIx2FcsyyiUdl2UewYpm2goHcIoKgpBqJkfX2JXliGl5tn5lYOLqoBRmGAdQ/Qo8B477Ruzr2SKBMEoD344fxO8vBn9QtwdyOnqCw9NeTZ9yBgdF+qmK+MtC1x/VE9hEx3cVUNZEo2ZqkkURfo1bf5Zi6vC+OVj93ops+3mJtLTDSTFDVGUdImws6I0A== 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=gmeTiDNoQqv1YgkX7prYJcWbdgX4PMXoJ48PGIYJfz4=; b=JXdf1JpQkOev4f26x6CqMLUBQ6+1NujNmr01Eo9SW/RphIoDGBnVtbX6OAPG+bzv6qSF52E0NpzIePZS7QVLf7OpgN1fkKagcLZh040mH3XhsIiLMH7y41CRUGlvUydZVb30OfEBWcMwFeQLEew27IPFc2komBq0PwnChGKI0KQ= 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 SA0PR12MB4509.namprd12.prod.outlook.com (2603:10b6:806:9e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan 2023 23:41:13 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::5317:fa3f:5cbe:45e9]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::5317:fa3f:5cbe:45e9%3]) with mapi id 15.20.5986.018; Mon, 9 Jan 2023 23:41:12 +0000 Message-ID: <66039193-14ca-5edb-d8d4-ca732d8c13a6@amd.com> Date: Mon, 9 Jan 2023 17:41:07 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH RFC v7 52/64] KVM: SVM: Provide support for SNP_GUEST_REQUEST NAE event Content-Language: en-US To: Alexey Kardashevskiy , Michael Roth , kvm@vger.kernel.org Cc: linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@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, wanpengli@tencent.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, bp@alien8.de, 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, harald@profian.com, Brijesh Singh References: <20221214194056.161492-1-michael.roth@amd.com> <20221214194056.161492-53-michael.roth@amd.com> From: "Kalra, Ashish" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MN2PR19CA0067.namprd19.prod.outlook.com (2603:10b6:208:19b::44) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR12MB2767:EE_|SA0PR12MB4509:EE_ X-MS-Office365-Filtering-Correlation-Id: d4b582fe-0167-49a5-dad4-08daf29afdfa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tCU58gzVyvegwDD3t2AnFFEBRw0OV2vIlydxPOnWkrwhaot9BlbsyA3gsuwBRUNpBuWTHUPXSPUE7pucJkUeIZyAhJ5irwYHlje2Ej9nzAn/zuGLdo2N/vW9qFvu1nxXBXMaBiZHrAC0RI8YrtzIJ2XB+o1XQu2qEE/kds2B+NFclYhXxVkI2bZuDTgqbkelLKsIcsSohIxbq/g+xvloe7b9brHkFjyfcfFpi7zp9UVgVYaFDYkIoE95tszEtTzNsgYJ9PLgddVxkVCRUQ3xDJOa3Y3zkrRSb/pDSNx0yO82NcHpj0v7tSHEc+19JWPAv+YUGQRUsEl5Q8yDwcqYvfsC18Lo5CwFqWwVB9lEtMWrj5MuH3b7i0AEhRpRW9eWa1qzzbBvTZH2gUTjNgEWjrddRxL5unDkT/79W2oYNCtzJY8qJle3WhuSUchXEKxI2Mre/HbTfVCdj/+CTZMfWTD8tLjEfIfVvucDICn+4yLUQoGEBLM22zp8ORD78BJvyhexyZu72RINWFVrUhyaNOS9TnOpcSignM5gg3qDcZP6R4ov4lDJqFHjZa87Hpom8YyRkmf0LqpHfi1vL0uxJTsLPlsg0Ppqh9xgUSqD8epAMSEkTALC9xZEl9HuWGHksdsHOit71hlp9jUMYKEbpaKxka2NKQvD7PBXVvhynurrovCctj7qfgMEZabKaB3rfGBjwOpW34EtP6DFlo8KQMhE9obWrxXks7cssICGcSFv6p7AN8k9KRpGmSINnwvAI6uXShg0MkyzeAqgER+pOw== 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)(366004)(136003)(346002)(39860400002)(396003)(376002)(451199015)(36756003)(186003)(8936002)(26005)(6666004)(53546011)(6506007)(6512007)(2616005)(66946007)(5660300002)(66476007)(7416002)(66556008)(7406005)(4326008)(316002)(86362001)(31696002)(38100700002)(478600001)(110136005)(41300700001)(6486002)(31686004)(8676002)(83380400001)(2906002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?T0FhYUxaVWNscEhWUGdyYkdZa0dObk9ITkxYTUxJRHRVTk52YkNIalpLRGNB?= =?utf-8?B?Zmx5bzB1djROTm96SUhNcXRhMXdMSHNxZGpNSFd6T2h4YTFUNi9JYzZ6Ly9T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sN281cjBnWExCaHJjMlg2b2poc3JUOHVu?= =?utf-8?B?T3IwK3h6eUtzZmR0Q3p2dDY0aUg1OWVTQjdMOEtycEhVL0tuWmpmK3JvQklT?= =?utf-8?B?QVZsQmdHeGgyVkxRbTFHVnVZWHFjcVhUb0Rab1craWdqUytXTzZ5QnlVemxS?= =?utf-8?B?bStUYUQyWS9JK3ZndEZsV0RNNkJFNFo2anBrbWZnSWROSkNCOFNjQmdNNG9G?= =?utf-8?Q?96E8u27ovDTAajcCswu8gKz6q?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4b582fe-0167-49a5-dad4-08daf29afdfa X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 23:41:12.8182 (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: 4+MxYI/rGr1alxRC74ygmG2l9Wi28V7S8STneRHKJAZCDrbc2SUX68PV5VnoYP1laNWyyecFmgvmP049rJVbng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4509 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-crypto@vger.kernel.org On 1/8/2023 9:33 PM, Alexey Kardashevskiy wrote: > On 15/12/22 06:40, Michael Roth wrote: >> From: Brijesh Singh >> >> Version 2 of GHCB specification added the support for two SNP Guest >> Request Message NAE events. The events allows for an SEV-SNP guest to >> make request to the SEV-SNP firmware through hypervisor using the >> SNP_GUEST_REQUEST API define in the SEV-SNP firmware specification. >> >> The SNP_EXT_GUEST_REQUEST is similar to SNP_GUEST_REQUEST with the >> difference of an additional certificate blob that can be passed through >> the SNP_SET_CONFIG ioctl defined in the CCP driver. The CCP driver >> provides snp_guest_ext_guest_request() that is used by the KVM to get >> both the report and certificate data at once. >> >> Signed-off-by: Brijesh Singh >> Signed-off-by: Ashish Kalra >> Signed-off-by: Michael Roth >> --- >>   arch/x86/kvm/svm/sev.c | 185 +++++++++++++++++++++++++++++++++++++++-- >>   arch/x86/kvm/svm/svm.h |   2 + >>   2 files changed, 181 insertions(+), 6 deletions(-) >> >> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c >> index 5f2b2092cdae..18efa70553c2 100644 >> --- a/arch/x86/kvm/svm/sev.c >> +++ b/arch/x86/kvm/svm/sev.c >> @@ -331,6 +331,7 @@ static int sev_guest_init(struct kvm *kvm, struct >> kvm_sev_cmd *argp) >>           if (ret) >>               goto e_free; >> +        mutex_init(&sev->guest_req_lock); >>           ret = sev_snp_init(&argp->error, false); >>       } else { >>           ret = sev_platform_init(&argp->error); >> @@ -2051,23 +2052,34 @@ int sev_vm_move_enc_context_from(struct kvm >> *kvm, unsigned int source_fd) >>    */ >>   static void *snp_context_create(struct kvm *kvm, struct kvm_sev_cmd >> *argp) >>   { >> +    struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; >>       struct sev_data_snp_addr data = {}; >> -    void *context; >> +    void *context, *certs_data; >>       int rc; >> +    /* Allocate memory used for the certs data in SNP guest request */ >> +    certs_data = kzalloc(SEV_FW_BLOB_MAX_SIZE, GFP_KERNEL_ACCOUNT); >> +    if (!certs_data) >> +        return NULL; >> + >>       /* Allocate memory for context page */ >>       context = snp_alloc_firmware_page(GFP_KERNEL_ACCOUNT); >>       if (!context) >> -        return NULL; >> +        goto e_free; >>       data.gctx_paddr = __psp_pa(context); >>       rc = __sev_issue_cmd(argp->sev_fd, SEV_CMD_SNP_GCTX_CREATE, >> &data, &argp->error); >> -    if (rc) { >> -        snp_free_firmware_page(context); >> -        return NULL; >> -    } >> +    if (rc) >> +        goto e_free; >> + >> +    sev->snp_certs_data = certs_data; >>       return context; >> + >> +e_free: >> +    snp_free_firmware_page(context); >> +    kfree(certs_data); >> +    return NULL; >>   } >>   static int snp_bind_asid(struct kvm *kvm, int *error) >> @@ -2653,6 +2665,8 @@ static int snp_decommission_context(struct kvm >> *kvm) >>       snp_free_firmware_page(sev->snp_context); >>       sev->snp_context = NULL; >> +    kfree(sev->snp_certs_data); >> + >>       return 0; >>   } >> @@ -3174,6 +3188,8 @@ static int sev_es_validate_vmgexit(struct >> vcpu_svm *svm, u64 *exit_code) >>       case SVM_VMGEXIT_UNSUPPORTED_EVENT: >>       case SVM_VMGEXIT_HV_FEATURES: >>       case SVM_VMGEXIT_PSC: >> +    case SVM_VMGEXIT_GUEST_REQUEST: >> +    case SVM_VMGEXIT_EXT_GUEST_REQUEST: >>           break; >>       default: >>           reason = GHCB_ERR_INVALID_EVENT; >> @@ -3396,6 +3412,149 @@ static int snp_complete_psc(struct kvm_vcpu >> *vcpu) >>       return 1; >>   } >> +static unsigned long snp_setup_guest_buf(struct vcpu_svm *svm, >> +                     struct sev_data_snp_guest_request *data, >> +                     gpa_t req_gpa, gpa_t resp_gpa) >> +{ >> +    struct kvm_vcpu *vcpu = &svm->vcpu; >> +    struct kvm *kvm = vcpu->kvm; >> +    kvm_pfn_t req_pfn, resp_pfn; >> +    struct kvm_sev_info *sev; >> + >> +    sev = &to_kvm_svm(kvm)->sev_info; >> + >> +    if (!IS_ALIGNED(req_gpa, PAGE_SIZE) || !IS_ALIGNED(resp_gpa, >> PAGE_SIZE)) >> +        return SEV_RET_INVALID_PARAM; >> + >> +    req_pfn = gfn_to_pfn(kvm, gpa_to_gfn(req_gpa)); >> +    if (is_error_noslot_pfn(req_pfn)) >> +        return SEV_RET_INVALID_ADDRESS; >> + >> +    resp_pfn = gfn_to_pfn(kvm, gpa_to_gfn(resp_gpa)); >> +    if (is_error_noslot_pfn(resp_pfn)) >> +        return SEV_RET_INVALID_ADDRESS; >> + >> +    if (rmp_make_private(resp_pfn, 0, PG_LEVEL_4K, 0, true)) >> +        return SEV_RET_INVALID_ADDRESS; >> + >> +    data->gctx_paddr = __psp_pa(sev->snp_context); >> +    data->req_paddr = __sme_set(req_pfn << PAGE_SHIFT); >> +    data->res_paddr = __sme_set(resp_pfn << PAGE_SHIFT); >> + >> +    return 0; >> +} >> + >> +static void snp_cleanup_guest_buf(struct sev_data_snp_guest_request >> *data, unsigned long *rc) >> +{ >> +    u64 pfn = __sme_clr(data->res_paddr) >> PAGE_SHIFT; >> +    int ret; >> + >> +    ret = snp_page_reclaim(pfn); >> +    if (ret) >> +        *rc = SEV_RET_INVALID_ADDRESS; >> + >> +    ret = rmp_make_shared(pfn, PG_LEVEL_4K); >> +    if (ret) >> +        *rc = SEV_RET_INVALID_ADDRESS; >> +} >> + >> +static void snp_handle_guest_request(struct vcpu_svm *svm, gpa_t >> req_gpa, gpa_t resp_gpa) >> +{ >> +    struct sev_data_snp_guest_request data = {0}; >> +    struct kvm_vcpu *vcpu = &svm->vcpu; >> +    struct kvm *kvm = vcpu->kvm; >> +    struct kvm_sev_info *sev; >> +    unsigned long rc; >> +    int err; >> + >> +    if (!sev_snp_guest(vcpu->kvm)) { >> +        rc = SEV_RET_INVALID_GUEST; >> +        goto e_fail; >> +    } >> + >> +    sev = &to_kvm_svm(kvm)->sev_info; >> + >> +    mutex_lock(&sev->guest_req_lock); >> + >> +    rc = snp_setup_guest_buf(svm, &data, req_gpa, resp_gpa); >> +    if (rc) >> +        goto unlock; >> + >> +    rc = sev_issue_cmd(kvm, SEV_CMD_SNP_GUEST_REQUEST, &data, &err); > > > This one goes via sev_issue_cmd_external_user() and uses sev-fd... > >> +    if (rc) >> +        /* use the firmware error code */ >> +        rc = err; >> + >> +    snp_cleanup_guest_buf(&data, &rc); >> + >> +unlock: >> +    mutex_unlock(&sev->guest_req_lock); >> + >> +e_fail: >> +    svm_set_ghcb_sw_exit_info_2(vcpu, rc); >> +} >> + >> +static void snp_handle_ext_guest_request(struct vcpu_svm *svm, gpa_t >> req_gpa, gpa_t resp_gpa) >> +{ >> +    struct sev_data_snp_guest_request req = {0}; >> +    struct kvm_vcpu *vcpu = &svm->vcpu; >> +    struct kvm *kvm = vcpu->kvm; >> +    unsigned long data_npages; >> +    struct kvm_sev_info *sev; >> +    unsigned long rc, err; >> +    u64 data_gpa; >> + >> +    if (!sev_snp_guest(vcpu->kvm)) { >> +        rc = SEV_RET_INVALID_GUEST; >> +        goto e_fail; >> +    } >> + >> +    sev = &to_kvm_svm(kvm)->sev_info; >> + >> +    data_gpa = vcpu->arch.regs[VCPU_REGS_RAX]; >> +    data_npages = vcpu->arch.regs[VCPU_REGS_RBX]; >> + >> +    if (!IS_ALIGNED(data_gpa, PAGE_SIZE)) { >> +        rc = SEV_RET_INVALID_ADDRESS; >> +        goto e_fail; >> +    } >> + >> +    mutex_lock(&sev->guest_req_lock); >> + >> +    rc = snp_setup_guest_buf(svm, &req, req_gpa, resp_gpa); >> +    if (rc) >> +        goto unlock; >> + >> +    rc = snp_guest_ext_guest_request(&req, (unsigned >> long)sev->snp_certs_data, >> +                     &data_npages, &err); > > but this one does not and jump straight to drivers/crypto/ccp/sev-dev.c > ignoring sev->fd. Why different? Can these two be unified? > sev_issue_cmd_external_user() only checks if fd is /dev/sev which is > hardly useful. > > "[PATCH RFC v7 32/64] crypto: ccp: Provide APIs to query extended > attestation report" added this one. SNP_EXT_GUEST_REQUEST additionally returns a certificate blob and that's why it goes through the CCP driver interface snp_guest_ext_guest_request() that is used to get both the report and certificate data/blob at the same time. All the FW API calls on the KVM side go through sev_issue_cmd() and sev_issue_cmd_external_user() interfaces and that i believe uses sev->fd more of as a sanity check. Thanks, Ashish > > Besides, is sev->fd really needed in the sev struct at all? Thanks, > > >> +    if (rc) { >> +        /* >> +         * If buffer length is small then return the expected >> +         * length in rbx. >> +         */ >> +        if (err == SNP_GUEST_REQ_INVALID_LEN) >> +            vcpu->arch.regs[VCPU_REGS_RBX] = data_npages; >> + >> +        /* pass the firmware error code */ >> +        rc = err; >> +        goto cleanup; >> +    } >> + >> +    /* Copy the certificate blob in the guest memory */ >> +    if (data_npages && >> +        kvm_write_guest(kvm, data_gpa, sev->snp_certs_data, >> data_npages << PAGE_SHIFT)) >> +        rc = SEV_RET_INVALID_ADDRESS; >> + >> +cleanup: >> +    snp_cleanup_guest_buf(&req, &rc); >> + >> +unlock: >> +    mutex_unlock(&sev->guest_req_lock); >> + >> +e_fail: >> +    svm_set_ghcb_sw_exit_info_2(vcpu, rc); >> +} >> + >>   static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) >>   { >>       struct vmcb_control_area *control = &svm->vmcb->control; >> @@ -3629,6 +3788,20 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) >>           vcpu->run->vmgexit.ghcb_msr = ghcb_gpa; >>           vcpu->arch.complete_userspace_io = snp_complete_psc; >>           break; >> +    case SVM_VMGEXIT_GUEST_REQUEST: { >> +        snp_handle_guest_request(svm, control->exit_info_1, >> control->exit_info_2); >> + >> +        ret = 1; >> +        break; >> +    } >> +    case SVM_VMGEXIT_EXT_GUEST_REQUEST: { >> +        snp_handle_ext_guest_request(svm, >> +                         control->exit_info_1, >> +                         control->exit_info_2); >> + >> +        ret = 1; >> +        break; >> +    } >>       case SVM_VMGEXIT_UNSUPPORTED_EVENT: >>           vcpu_unimpl(vcpu, >>                   "vmgexit: unsupported event - exit_info_1=%#llx, >> exit_info_2=%#llx\n", >> diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h >> index 12b9f4d539fb..7c0f9d00950f 100644 >> --- a/arch/x86/kvm/svm/svm.h >> +++ b/arch/x86/kvm/svm/svm.h >> @@ -101,6 +101,8 @@ struct kvm_sev_info { >>       u64 snp_init_flags; >>       void *snp_context;      /* SNP guest context page */ >>       spinlock_t psc_lock; >> +    void *snp_certs_data; >> +    struct mutex guest_req_lock; >>   }; >>   struct kvm_svm { >