Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5958437rwb; Tue, 9 Aug 2022 07:01:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR7vg/9uid6NzJkcL8lbzPZn1DKHOOFvjTJU1/Py5IasoBJFAhzZsjzlevTWKBve7sBq0YLr X-Received: by 2002:a17:902:f082:b0:16f:18b6:71d7 with SMTP id p2-20020a170902f08200b0016f18b671d7mr23913100pla.94.1660053707023; Tue, 09 Aug 2022 07:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660053707; cv=none; d=google.com; s=arc-20160816; b=FHhnNXSFb3cYKDBaNvr0xcSMOUl1wAg1FxXZvfiuVS16uk3bmChdSb6IZfy6ZHnz23 NCvgCRnSHmksMfAgc/AJwpmGn8qSkEl6l+R/lrIfIEEmWIlBf9TIV4chHB2GBvG48hRE WpnTm6uF1dgorc04h19GpPXsyuxtb5b07GQ9BLUc7NrHtW7Thf6G089cN2HX8fQ0v/Vp Q6tdR9EGdbTL0va2DaK2q7hsE1MsvGUMdUnE+5zcT/GaKgq4MjMr/6aWD01dIp41/T4S ETRmaGp6swZHSQDXF1tOUQhzvfVNvVAzXljGgGScEFYIbzDqWRs/MO5cMsFE3LJbdrkf U8MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=odYNCkcIAQcBKQptQexLin/WRKzdil3fPD/Uqu4HkkI=; b=MGUgj9YJWfv14wTikq7n1eDNwk9rfXTksYnz9wEme44KZqoFgW6htRMMg7AHzK9S+d pQkFyUeK/DrYmyasK6NZ1mgZTWSQHGF5UbAYODuRzygrvp+/rrKIDhuDYMbw2Zr2Xl+z 75Uzt6zUVY69RLAlYbIBACFH5BynBPCTQhLA7IZY/jtIP9qE2ucZKGyt1wHw3gNducnL sy94fgOvtbPLWRCJDvWcCVabmunxkI6l4Y6zNG2qoM6AFhywTN757boZkczEt2psd+9J icf1RDzqTfNayjoWgbAYUBAF3qGLeAYPb3teNhPQJyWA3juYBB7ZkVMqp3/ikwwm3CHP Frbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=aEFzcalQ; 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=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a056a00180b00b0052acaf4a3c0si15813425pfa.17.2022.08.09.07.01.21; Tue, 09 Aug 2022 07:01:47 -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=@amazon.com header.s=amazon201209 header.b=aEFzcalQ; 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=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241406AbiHIN4s (ORCPT + 99 others); Tue, 9 Aug 2022 09:56:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244780AbiHIN4W (ORCPT ); Tue, 9 Aug 2022 09:56:22 -0400 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEAC518368; Tue, 9 Aug 2022 06:56:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1660053382; x=1691589382; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=odYNCkcIAQcBKQptQexLin/WRKzdil3fPD/Uqu4HkkI=; b=aEFzcalQ97hAG4bs2JdRqWh1VYvGCJfnHi664tJe/d/FqlvKXVw2DGNF 0sl4Mb77jMqaH3pw2ip5ztIa2t/6kYAuQ4kVNeWE0WSFPGYG3tWmustKj S1MyZYCrFhh3nnAJx34sgJL686GkGPuP7OCHq+najECXbN6sNphKBVeTe U=; Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-b09d0114.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 13:56:08 +0000 Received: from EX13D24EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1a-b09d0114.us-east-1.amazon.com (Postfix) with ESMTPS id 35EAD80383; Tue, 9 Aug 2022 13:55:58 +0000 (UTC) Received: from dev-dsk-sabrapan-1c-164a86ac.eu-west-1.amazon.com (10.43.162.227) by EX13D24EUC003.ant.amazon.com (10.43.164.217) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Tue, 9 Aug 2022 13:55:48 +0000 From: Sabin Rapan To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH Part2 v6 26/49] KVM: SVM: Add KVM_SEV_SNP_LAUNCH_UPDATE command Date: Tue, 9 Aug 2022 13:55:35 +0000 Message-ID: <20220809135535.88234-1-sabrapan@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.43.162.227] X-ClientProxiedBy: EX13D40UWC003.ant.amazon.com (10.43.162.246) To EX13D24EUC003.ant.amazon.com (10.43.164.217) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_SPF_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-crypto@vger.kernel.org > +static bool is_hva_registered(struct kvm *kvm, hva_t hva, size_t len) > +{ > + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; > + struct list_head *head = &sev->regions_list; > + struct enc_region *i; > + > + lockdep_assert_held(&kvm->lock); > + > + list_for_each_entry(i, head, list) { > + u64 start = i->uaddr; > + u64 end = start + i->size; > + > + if (start <= hva && end >= (hva + len)) > + return true; > + } > + > + return false; > +} Since KVM_MEMORY_ENCRYPT_REG_REGION should be called for every memory region the user gives to kvm, is the regions_list any different from kvm's memslots? > + > +static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp) > +{ > + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; > + struct sev_data_snp_launch_update data = {0}; > + struct kvm_sev_snp_launch_update params; > + unsigned long npages, pfn, n = 0; > + int *error = &argp->error; > + struct page **inpages; > + int ret, i, level; > + u64 gfn; > + > + if (!sev_snp_guest(kvm)) > + return -ENOTTY; > + > + if (!sev->snp_context) > + return -EINVAL; > + > + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, sizeof(params))) > + return -EFAULT; > + > + /* Verify that the specified address range is registered. */ > + if (!is_hva_registered(kvm, params.uaddr, params.len)) > + return -EINVAL; > + > + /* > + * The userspace memory is already locked so technically we don't > + * need to lock it again. Later part of the function needs to know > + * pfn so call the sev_pin_memory() so that we can get the list of > + * pages to iterate through. > + */ > + inpages = sev_pin_memory(kvm, params.uaddr, params.len, &npages, 1); > + if (!inpages) > + return -ENOMEM; sev_pin_memory will call pin_user_pages() which fails for PFNMAP vmas that you would get if you use memory allocated from an IO driver. Using gfn_to_pfn instead will make this work with vmas backed by pages or raw pfn mappings. Amazon Development Center (Romania) S.R.L. registered office: 27A Sf. Lazar Street, UBC5, floor 2, Iasi, Iasi County, 700045, Romania. Registered in Romania. Registration number J22/2621/2005.