Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp747853lqt; Fri, 19 Apr 2024 09:13:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXxpVzxN56ST0hXHFDnUHjLDSRpV1AXRAgq+nnGnWk6AP5uKEAT3vqTlcuU98kpplVTbQJJNpPBnbAsEmtNtfA631rUKZcXBFiSkqRGfg== X-Google-Smtp-Source: AGHT+IGuB58tHP2fg2JmB7eVJdRZR4ELjduknlVZtzhHQA3HhYp1qUyCrVir9BdUvTvtt+dcP/Zm X-Received: by 2002:a05:622a:60b:b0:434:6f65:8acd with SMTP id z11-20020a05622a060b00b004346f658acdmr3249149qta.39.1713543187898; Fri, 19 Apr 2024 09:13:07 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z12-20020ac87f8c000000b00432c49655ccsi4049035qtj.77.2024.04.19.09.13.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 09:13:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b=Bpc2mp6S; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-151728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151728-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 027361C20AE3 for ; Fri, 19 Apr 2024 16:13:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED34212F394; Fri, 19 Apr 2024 16:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Bpc2mp6S" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CD31130A72 for ; Fri, 19 Apr 2024 16:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713543150; cv=none; b=T7EdQf41gn5POh5G5qgB8VnjpdxG8tGARp4DNX+ZvLMnoHBghLYDamvaNL4pU942RFomYWkhPUcPf5T5LePHXl/KPHqBIvT2I2NC40OqpXTBqQtgEUuYUVE7CVB3vezpRYbni+cbzE+0BRgHM8PnuxonPBwtYyUElZ84U2HscLY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713543150; c=relaxed/simple; bh=BoY/Dy3UEpWzAlEVCqDQTE76CEu5CAwU1Yr/gwGs0FU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=h5FogOH2PDI8ZaypJO1BhQWqrPPUY8u7AvRJKvXN4xcgzf61gvkMehcQqKiRcz9WeOyE310KsGwJUZdYMmI2xj48AHQCzLszgnQd47SrrrkZClY25hednU6nV9vBpDQUq1ZZXD7tgEEsnWmNq+8ARTQgXllnEI1ukoNrqMzuXVY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Bpc2mp6S; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713543147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9uBiWyy2Y6aSUbUd2veflvDo2gmH6uQXxYZf3A1GRsI=; b=Bpc2mp6SLG7zIQdxlmAKtdIxjFmShYq7tjJaZ+Rn28vu9VxFhO1io2a7EX3WfzX2gqzvqL r/009oZ14Cvn/A882ptEdpPfDG25PiYvHsarV8Bwd+d4tDzx/TaICQXMYgqmD68jqZy7Gh bYiqar9zJ8SFjsHzAnb6+ZYej0rElCY= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-nllKYZofM5ibf0YE6IiCMA-1; Fri, 19 Apr 2024 12:12:24 -0400 X-MC-Unique: nllKYZofM5ibf0YE6IiCMA-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3473168c856so1346682f8f.1 for ; Fri, 19 Apr 2024 09:12:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713543143; x=1714147943; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9uBiWyy2Y6aSUbUd2veflvDo2gmH6uQXxYZf3A1GRsI=; b=ddEl1d6Hd0fVIbLXrUvonFsTIjhd21LZnNMhkSvLqBlJ7m8qMc9yTdATp6hz+zNzKw 0BXPK1lorqZOcQ6jLKYxR3XBAK/CWZEuD1UfvQzq2aMgduVfP2lMAsd2/xwqzvXdsOAu 3qsHuHeeYUS4OG6AJXQSCbfitjS4k1Nowpt06+MBPQX8+k66gCRecLLewTM2CeQz2qDC JqUSuZHi6KlIRdCfbX+bvm2w1Zh7Il94x0g/5DPeSzcdyo7KLzNYCdjbEa0o4jE/hrBh DobvcfUK8CxQ/up06mBZXtZgPdV+OGGPpcyxBA8K6HGEZJcmVVHhz3pb6CDGLDpPGOPT AWYA== X-Forwarded-Encrypted: i=1; AJvYcCXFcbxVLAdlxDxgBtoGqkip9K3kOFFq7JUccThLuf2VbmsmD7C0pUMJ3mmRqcq9bDWG5bSDwOkjGxqym38fBlJTc76aGOdDyiE6yXoh X-Gm-Message-State: AOJu0YxRkxwywgj6lMCQIbJManPTkX5rYKLdQVL6rxzFcq25mA15gnYt Vv9WI6OlufLFXtwzwxuDprODC2tl+s8+t7LCZJ1Vtk2PmA9MLO5ko9cFAFKO1dASh7e96J7m0S8 7v/N3/LJg8ijLSvJt8DnZzt3Ee5k+P01zJJY6RU6DcMYhYAT6wEbiyt1lgriv5EihNqwOJBbUJY kYL9H6916EHwDXKsS3+x67+Mnh/KS9g6VMB2vy X-Received: by 2002:a05:6000:f:b0:34a:72d:8dae with SMTP id h15-20020a056000000f00b0034a072d8daemr1744526wrx.22.1713543142973; Fri, 19 Apr 2024 09:12:22 -0700 (PDT) X-Received: by 2002:a05:6000:f:b0:34a:72d:8dae with SMTP id h15-20020a056000000f00b0034a072d8daemr1744478wrx.22.1713543142601; Fri, 19 Apr 2024 09:12:22 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240418194133.1452059-1-michael.roth@amd.com> <20240418194133.1452059-11-michael.roth@amd.com> In-Reply-To: From: Paolo Bonzini Date: Fri, 19 Apr 2024 18:12:11 +0200 Message-ID: Subject: Re: [PATCH v13 10/26] KVM: SEV: Add KVM_SEV_SNP_LAUNCH_UPDATE command To: Michael Roth Cc: kvm@vger.kernel.org, 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, seanjc@google.com, vkuznets@redhat.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, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, jarkko@kernel.org, ashish.kalra@amd.com, nikunj.dadhania@amd.com, pankaj.gupta@amd.com, liam.merwick@oracle.com, Brijesh Singh Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 19, 2024 at 1:56=E2=80=AFPM Paolo Bonzini = wrote: > > + ret =3D kvm_gmem_populate(kvm, params.gfn_start, u64_to_user_pt= r(params.uaddr), > > + npages, sev_gmem_post_populate, &sev_po= pulate_args); > > + if (ret < 0) { > > + argp->error =3D sev_populate_args.fw_error; > > + pr_debug("%s: kvm_gmem_populate failed, ret %d (fw_erro= r %d)\n", > > + __func__, ret, argp->error); > > + } else if (ret < npages) { > > + params.len =3D ret * PAGE_SIZE; > > + ret =3D -EINTR; > > This probably should 1) update also gfn_start and uaddr 2) return 0 > for consistency with the planned KVM_PRE_FAULT_MEMORY ioctl (aka > KVM_MAP_MEMORY). To be more precise, params.len should be set to the number of bytes *left*,= i.e. params.len -=3D ret * PAGE_SIZE; params.gfn_start +=3D ret * PAGE_SIZE; if (params.type !=3D KVM_SEV_SNP_PAGE_TYPE_ZERO) params.uaddr +=3D ret * PAGE_SIZE; Also this patch needs some other changes: 1) snp_launch_update() should have something like this: src =3D params.type =3D=3D KVM_SEV_SNP_PAGE_TYPE_ZERO ? NULL : u64_to_user_ptr(params.uaddr),; so that then... > + vaddr =3D kmap_local_pfn(pfn + i); > + ret =3D copy_from_user(vaddr, src + i * PAGE_SIZE, PAGE_S= IZE); > + if (ret) { > + pr_debug("Failed to copy source page into GFN 0x%= llx\n", gfn); > + goto out_unmap; > + } .. the copy can be done only if src is non-NULL 2) the struct should have some more fields > + struct kvm_sev_snp_launch_update { > + __u64 gfn_start; /* Guest page number to load/enc= rypt data into. */ > + __u64 uaddr; /* Userspace address of data to = be loaded/encrypted. */ > + __u32 len; /* 4k-aligned length in bytes to= copy into guest memory.*/ > + __u8 type; /* The type of the guest pages b= eing initialized. */ __u8 pad0; __u16 flags; // must be zero __u64 pad1[5]; with accompanying flags check in snp_launch_update(). If you think IMI can be implemented already (with a bit in flags) go ahead and do it. Paolo