Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1699387pxb; Tue, 26 Oct 2021 14:08:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1b6ErXkOIBL42p/FX/PlnD4zOoj7CJvsHBO6WNUWq96j1e+G2E05DNyBMxnAhE1bP/b/p X-Received: by 2002:a05:6a00:198b:b0:47b:ac2d:68f4 with SMTP id d11-20020a056a00198b00b0047bac2d68f4mr27463350pfl.1.1635282533403; Tue, 26 Oct 2021 14:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635282533; cv=none; d=google.com; s=arc-20160816; b=ipY5D+ora2MJYdcni7Hz63J7Cle9qKF20RSaGDo7vcIryECMb1YP9XIPLB6drLh6oe Iib2EOnvTtq4GZfe5OJCuH27ml5NQaQK+yg35dt3AAIk+dUe+DzZD7lyYtqE3H36Tb1G L/0/IXihmzn8/EDKgnPLq4NguxgD0ZqGg1wYVDbLGDXWvD3zT6tvGZiHKQLCWijThhW0 2AvyNu0ikv+fCZtXJLMt6xAtIueu2TjusRA81tjOgeDtijixUEOdZeCHosfrpK9yPQ6G uy5r8s4IVkASw47sIGcRggKeqxyUIJQ/1b8/em7LtOdJzegFTZLuRIt/SzRoxuYuOlzI a33w== 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=9bVpuD1Y0J9AqmF+3g16iWc8OCZsFp8I5PNhkQ+ZVF8=; b=UbvPoBL12ksuxd2KEYo4Y1gel2PB0PAuUL8MzDqmwelsZ85YWqnDQJt0bFq72uP5n4 Jh8EemNpF9619m/sYRYOT8ngYwhFgfmazXBoSXcctkOBdp/vs1zTZ8CSJPFx1z7Fyo9E kFQUA0LutcU3oYnONld9saQJAR3qyV7nY4ki4JFbZM9NcPLSe5mfaL81mDe/DR87RSLp sKSbaicDuJmQVVk/tjO7baULdOT0Ht4DKgDoxleKqD97nL/lee2v8AUqqpY4unozQQUG WHDfZUcELSsApZ5y1tNSIlHLIBNW7hu0IVLI7elqNtqbFVDQ1Idy+OibWdrv3nPn/P2m 3lKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ETLLMFRo; 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 i2si10253646pgf.595.2021.10.26.14.08.38; Tue, 26 Oct 2021 14:08:53 -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=ETLLMFRo; 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 S237101AbhJZPvj (ORCPT + 99 others); Tue, 26 Oct 2021 11:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237105AbhJZPvZ (ORCPT ); Tue, 26 Oct 2021 11:51:25 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1611C061220 for ; Tue, 26 Oct 2021 08:49:00 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id i9so36002627ybi.8 for ; Tue, 26 Oct 2021 08:49:00 -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=9bVpuD1Y0J9AqmF+3g16iWc8OCZsFp8I5PNhkQ+ZVF8=; b=ETLLMFRoQJtWWgBJT0RT3eQfsBfYysOXlgNe2DEvEZ1QazSwauaMIoM44pYme32Cmf 5wDxSE86ikalKtUTF8YaP1Vkcs/bOKBzt0fci7rR3EbizNznCCEx/0w0v70ni5jpJVBn Sh62U8y41huL0JAATtLmBuahL1Xvkh1iSGtriC0Ko45kmdHgePn3PtuEZZHBjRrSzBBJ dGjnlJj7MYVxr1qqvL87tedwzYyPKh3xKjvudUVGo7CSSjA3VfLQ9uqL4RjTuNMod5w7 zMBED7gaNA16iIjHd5Hnj6vSRP7OvuF+zHyueWTRLv5g9HUUT/3huLUFxWp7eKQl28lK 6V9w== 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=9bVpuD1Y0J9AqmF+3g16iWc8OCZsFp8I5PNhkQ+ZVF8=; b=BoVWOkbEoi+8xzUul/YFQMBuwIIFpghfJdz5mbfjs04w2l3W81x5q8VSyofv4BxSK4 5Zgo5GB9+I16cyf6C/OElwI6NItruPO3AapdlURvSyuCy3NFRgh1R2Du1eSiQvNeo7kw 1x7eW7r0flWur5NVAsFSf/L1JhHjnKlDbCQmcsi/NC7tY4qS/1VY8FJ6EjUO5E2/rBpD C0ECXhOjbpiznzCJxyxMQD15sO1qabypWp2ZKsOt2nKb5XOEz64Hv/71mwkLLztYIEUt 06L+IIKAmk/NrEtel/c2azdwJHJNux6lUF4Q1Qjf1rao2j0s/roMtFned9n20bd4EiJD dKHw== X-Gm-Message-State: AOAM532rPl3wN94oDO+GKg1JiErH32/NAKnydbg250pFTZuQDHtoXA8V paLaYAVJlmezSkBmmyyIyLmk/28VUBpz/0w195gApA== X-Received: by 2002:a25:2514:: with SMTP id l20mr26110968ybl.30.1635263339751; Tue, 26 Oct 2021 08:48:59 -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: <20211021033723.tfnhazbnlz4z5czl@amd.com> From: Mingwei Zhang Date: Tue, 26 Oct 2021 08:48:48 -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 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