Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3266413pxb; Mon, 1 Nov 2021 10:47:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyHuS2OIv7FAaxIKeNdWUDvWxJQKj7g73H9NUcA88QYv4zzpOnL1aOwK1/lNk5Ull/9WdH X-Received: by 2002:a17:906:3486:: with SMTP id g6mr39090750ejb.71.1635788850551; Mon, 01 Nov 2021 10:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635788850; cv=none; d=google.com; s=arc-20160816; b=mBNT/peeCc4QdM3v2J/Lty+lFTSI11EPpHcFQ7YE83nAl7WySVUYjenspLVIFMJ+av QqTur7ZVTTPkVl35LYuqX6nR2fym0qIrN9tUiApnFg4mJL2JweiybrfnSvsClMS7NwdO utOmTstMazlztyZOBqFB71BKWpqj1+kL54Wcbt7RKxoGfOlEiM5vXdxYWObNIL34IMmv FGPPngmmC9d+JFhoY9beRCrpyq/cOsJ8dt+KMtOq0m/7leOFIdWNKJX4XtlpdduYyS3x J3VndhA0F9sNWX/jlHaIxH7wroY5ihIEhLD9IiN59iALypsK/fXFu7NdZ9+29lr3DkSl aDsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UQ6siRywOjbV4IU70GIWXbdJs7RhMmkbN5QW6jS9pb4=; b=C86rr/F2Tf5wWEfAg1TZ6h53Q8oIfPq28unZaKxmbTNp+rgWTCvsv4NSQHOaEyoxlu /XgWt1CaZ21D13nx6KY4xCLBUvH66480eM9I0NhrUTwcIjuCfGGPVkaAwiw828x7AxDp zuau+s/KPnar7mlzuYRZqptjNEZMZewjxmWEG3Ja6tJTTEn+uqdZze48qsOoLY/mnwtS Nh+C+gJIFcGZurfgDJ/n5mm+TJ6oEzdaqJ6csxeRxDk25rf9PbXfn4LNfjtSqusp53Cq z6ymBbu+KC3ZnfRoKyCeMMgjzgANFs0A3J6QMwKhvCx53ZFyhMEEoxXGRGbJ4XGafyAv c+1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ai6GsO8f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si11399969edx.464.2021.11.01.10.47.06; Mon, 01 Nov 2021 10:47:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ai6GsO8f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231841AbhKARrc (ORCPT + 99 others); Mon, 1 Nov 2021 13:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbhKARra (ORCPT ); Mon, 1 Nov 2021 13:47:30 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21948C061714 for ; Mon, 1 Nov 2021 10:44:57 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id s3so13184237ybs.9 for ; Mon, 01 Nov 2021 10:44:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UQ6siRywOjbV4IU70GIWXbdJs7RhMmkbN5QW6jS9pb4=; b=Ai6GsO8fZzOL1OMi2wZJDrN49HYzmeiktfpXN4iIrk3IuRy0Kdnltpe7mYgLR3iukz iiFO3hNRFLIvtwkJo9wMpEopuqrf6vRqkF/lsGeewSbTk0a0rSAeUN0ze+wv56QzCtLt SYSsEE9rxBBuPdSUMVuq2iwXQWymsxN/nORbuQtHm3zwVybakhGjrVKQa9/RDSPHioSn XDdEU6mFynzoL+JP1CfQi7z0F7QeAg/yn0rLocwQk4hhdISAzf2ihIui8vklt/TH0lvh e4j2P+JulU6lTgzTUnR91TE46HoLBCcIP1gCjH1lVKdCKU+1JadWSjuPISJfM34xBuXS jcJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UQ6siRywOjbV4IU70GIWXbdJs7RhMmkbN5QW6jS9pb4=; b=b8EyrSgnH9Ib6dHgKmsu3pbO0LpUrdmSDKcJ0sOvMEW+54UzAwy3XghlKMR992FBCt T4ea4okrGIJFdFbZf5zyJ6nBeLtaxmF1R8QQ/6y5zlyLBOFf9hqRJGt1h9Dl8jgftDfZ OfqrR1Vjo8RXDjcXP4oNRympyv6IxjH+ibU61PaPc4sCmhWhO16Bho9xT7iGnwUNegKN VMEli60E6IN2m2YISJiy/5p+mH0UO879L4ZzOA5s6LhQRW9qR9Ar63PnEiaqfeoolPj5 mxqGNlb+ZTaIMbRwz+8Bz0CNPqIQY2uW2P2v6mQ9KULmDeF/AuayA7zC0CZg9OF5cJbk VdQw== X-Gm-Message-State: AOAM5301401Jb+zix+iJOBsNk8ewn2wck9F5sPfYZ4bSjl7Er3YXZ81u XWudiI59HB1XZSFaWnelo5G4xRkm6Q94ilD+4scmFA== X-Received: by 2002:a25:c244:: with SMTP id s65mr35042546ybf.30.1635788695616; Mon, 01 Nov 2021 10:44:55 -0700 (PDT) MIME-Version: 1.0 References: <20211005234459.430873-1-michael.roth@amd.com> <20211005234459.430873-3-michael.roth@amd.com> <20211021033723.tfnhazbnlz4z5czl@amd.com> In-Reply-To: From: Mingwei Zhang Date: Mon, 1 Nov 2021 10:44:44 -0700 Message-ID: Subject: Re: [RFC 02/16] KVM: selftests: add hooks for managing encrypted guest memory To: Michael Roth Cc: linux-kselftest@vger.kernel.org, kvm , LKML , x86@kernel.org, Nathan Tempelman , Marc Orr , Steve Rutherford , Sean Christopherson , Brijesh Singh , Tom Lendacky , Varad Gautam , Shuah Khan , Vitaly Kuznetsov , David Woodhouse , Ricardo Koller , Jim Mattson , Wanpeng Li , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 8:48 AM Mingwei Zhang wrote: > > On Wed, Oct 20, 2021 at 8:46 PM Michael Roth wrote: > > > > On Mon, Oct 18, 2021 at 08:00:00AM -0700, Mingwei Zhang wrote: > > > > +void vm_set_memory_encryption(struct kvm_vm *vm, bool enc_by_default, bool has_enc_bit, > > > > + uint8_t enc_bit) > > > > +{ > > > > + vm->memcrypt.enabled = true; > > > > + vm->memcrypt.enc_by_default = enc_by_default; > > > > + vm->memcrypt.has_enc_bit = has_enc_bit; > > > > + vm->memcrypt.enc_bit = enc_bit; > > > > +} > > > > + > > > > +struct sparsebit * > > > > +vm_get_encrypted_phy_pages(struct kvm_vm *vm, int slot, vm_paddr_t *gpa_start, > > > > + uint64_t *size) > > > > +{ > > > > + struct userspace_mem_region *region; > > > > + struct sparsebit *encrypted_phy_pages; > > > > + > > > > + if (!vm->memcrypt.enabled) > > > > + return NULL; > > > > + > > > > + region = memslot2region(vm, slot); > > > > + if (!region) > > > > + return NULL; > > > > + > > > > + encrypted_phy_pages = sparsebit_alloc(); > > > > + sparsebit_copy(encrypted_phy_pages, region->encrypted_phy_pages); > > > > > > Do we have to make a copy for the sparsebit? Why not just return the > > > pointer? By looking at your subsequent patches, I find that this data > > > structure seems to be just read-only? > > > > Yes, it's only intended to be used for read access. But I'll if I can > > enforce that without the need to use a copy. > > > > Understood. Thanks for the clarification. Yeah, I think both making a > copy and returning a const pointer should work. I will leave that to > you then. > > Thanks. > -Mingwei Reviewed-by: Mingwei Zhang Thanks. -Mingwei