Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1459563rwl; Fri, 24 Mar 2023 10:46:19 -0700 (PDT) X-Google-Smtp-Source: AKy350arRe4qO9WqVVzzfSMn19z1ms+Ckxs9+g5Gm9CEAht/8WVwooNzjlyQcQcXsH5MpfZN43S8 X-Received: by 2002:a17:907:7dac:b0:93e:5ac2:ec2a with SMTP id oz44-20020a1709077dac00b0093e5ac2ec2amr3157390ejc.70.1679679979416; Fri, 24 Mar 2023 10:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679679979; cv=none; d=google.com; s=arc-20160816; b=YWeyAwggpT/sH7avpEBE389yDRAPhU3fem+Z68A3/b/vPrmO/yF7SHyVXktvd6UQ44 DjOOK6qQwsojROxZjO5ZbF1mkAsFzAhmZYv3QD6kgw8Yt98sjpdzpzfLKPe1czVEIvNH iDY+BMqe/VUTZh+Ha/X8AGshNArXrlDcgT770tzlNQMhzG349DFOSCiCvpEkJghunpK5 +TLIBmUQ9BaIuTDRYe/Xsip1E3h4EoVsGEA3SvHNBuMfmN3Sp17EtmdSri3SjHjKQEwY mUHB4rPAD83Q+kHDc2922UvqyP3pADvURHw8c5VAR2+nA739LInpllEnlBvmyY6X1R3U PgLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=a/T0dFPDkQ7D0O2ujKj8hG7SaoRSBTKkSxDEkTyraFI=; b=j8k3pubi8qSvaGHxD1oXF8+2wLvMtjtVaclO3h5YKGdmK8VU5umO/qs/hWc78gXS81 PmWfr/r4AlCYwTXm3MEPcC9JBz/DsahZ/I3Emt1l7Diq5uqj9jqbxFssLg5Z7AAPw+TV yjap/mrmYWWP+rfYvi2IsrNExgQHq06jt+JuvGhCmpTNBG/xuB58bBTIh7JwwptsqnHS 79sua5TG/tCyR1h6D+u/WIcUqBxUzsrlBMa2TLVm/T6TQvqQgaSb/d63uUiJXQLXh+6T XPeVEiLIrGUX4H+XvqUXBkf6g8cF8WMrlwe2NJKaaklHuQv1psHf2fVF+Zcac09Qooh3 ESWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kc3n0RfZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gr8-20020a170906e2c800b008e6266cd19csi22543032ejb.935.2023.03.24.10.45.52; Fri, 24 Mar 2023 10:46:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@google.com header.s=20210112 header.b=kc3n0RfZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231489AbjCXRbF (ORCPT + 99 others); Fri, 24 Mar 2023 13:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231411AbjCXRbD (ORCPT ); Fri, 24 Mar 2023 13:31:03 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 033ECB77E for ; Fri, 24 Mar 2023 10:31:02 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54352648c1eso25003467b3.9 for ; Fri, 24 Mar 2023 10:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679679061; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=a/T0dFPDkQ7D0O2ujKj8hG7SaoRSBTKkSxDEkTyraFI=; b=kc3n0RfZzKkSztGUKFy8tfBZbwRbC9HP1Ro6l2XBZ8iYJ7CP9CbkghVKu9syInJzdk d175b+5UpDnscaRQ1J8s3PcNuMwChBFsNUI1o1b4CigKVcUY7ezY376CZRwu4QLugj6v YAIGWKWX5LGP1ipSau6h3WZqH5jtlF+FQl8clWf7Got+iUPIHMzOMYbZPJdweIk10XaZ xNAVrONhGtnS9zBzWxNHy3qIKTzLL9udqZJGHpJjj9BJt18VkwUg7SbUiki9sdLqI4yT FfA/tAqwK/1z+bKzsSxbgjNNiDFRtj3qCdMLcvFhnGfGvtCk0cjpJ2Co9C8e1zdYfLT9 X+Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679679061; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a/T0dFPDkQ7D0O2ujKj8hG7SaoRSBTKkSxDEkTyraFI=; b=k8pVBNdgKYacajyk13ZfbW5OHeakp7bjoKDK5ySjedBvaLvRa/i3vvzl9F3TclVMkv 5LlSBvmWuCXai7xnSjv5vEnTuw7Jh0sAvrGiCSqEOOLDbbfQGjRoF/5dSMafb4DNXnKW iYJPgSrFJr/vcekYBpb8HjGxwm20FoXBgZ/5JBry5PsWTIfE2iMqkvCRudnao5AhMQDR xolW4dF1ih/PxZvBBERe9FBRIq1grB6puZvZYE6srSdPbdGCZa1G8joXBLQn2E0/wI3U 0lxhbx3W135afMAb+K4VFGPeVbXIRDJczUE5hWveMYxk5939h7wGfF0guc4rt+Olp8/w ZLQg== X-Gm-Message-State: AAQBX9farf4oayUkgOh1zfspR/gw+fEIfLGBDDdZg8YxDYbejWSNmXrh 5IiXVUXcbCwGo71thfamrMAsFNRPBsQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1205:b0:b69:fab9:de60 with SMTP id s5-20020a056902120500b00b69fab9de60mr1822442ybu.0.1679679061302; Fri, 24 Mar 2023 10:31:01 -0700 (PDT) Date: Fri, 24 Mar 2023 10:30:59 -0700 In-Reply-To: <20230110175057.715453-5-pgonda@google.com> Mime-Version: 1.0 References: <20230110175057.715453-1-pgonda@google.com> <20230110175057.715453-5-pgonda@google.com> Message-ID: Subject: Re: [PATCH V6 4/7] KVM: selftests: add support for protected vm_vaddr_* allocations From: Sean Christopherson To: Peter Gonda Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Roth , Paolo Bonzini , Vishal Annapurve , Ackerley Tng , Andrew Jones Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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-kernel@vger.kernel.org On Tue, Jan 10, 2023, Peter Gonda wrote: > From: Michael Roth > > Test programs may wish to allocate shared vaddrs for things like > sharing memory with the guest. Since protected vms will have their > memory encrypted by default an interface is needed to explicitly > request shared pages. > > Implement this by splitting the common code out from vm_vaddr_alloc() > and introducing a new vm_vaddr_alloc_shared(). > > Cc: Paolo Bonzini > Cc: Sean Christopherson > Cc: Vishal Annapurve > Cc: Ackerley Tng > cc: Andrew Jones > Signed-off-by: Michael Roth > Signed-off-by: Peter Gonda > --- > .../selftests/kvm/include/kvm_util_base.h | 1 + > tools/testing/selftests/kvm/lib/kvm_util.c | 21 +++++++++++++++---- > 2 files changed, 18 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h > index f84d7777d5ca..5f3150ecfbbf 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util_base.h > +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h > @@ -435,6 +435,7 @@ vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_mi > vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min); > vm_vaddr_t __vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min, > enum kvm_mem_region_type type); > +vm_vaddr_t vm_vaddr_alloc_shared(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min); Wrap. > vm_vaddr_t vm_vaddr_alloc_pages(struct kvm_vm *vm, int nr_pages); > vm_vaddr_t __vm_vaddr_alloc_page(struct kvm_vm *vm, > enum kvm_mem_region_type type); > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > index ba771c2d949d..0d0a7ad7632d 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -1305,15 +1305,17 @@ vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz, > return pgidx_start * vm->page_size; > } > > -vm_vaddr_t __vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min, > - enum kvm_mem_region_type type) > +static vm_vaddr_t ____vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, > + vm_vaddr_t vaddr_min, > + enum kvm_mem_region_type type, > + bool encrypt) s/encrypt/protected, or maybe mark_protected so that it's clear that it's a command. > { > uint64_t pages = (sz >> vm->page_shift) + ((sz % vm->page_size) != 0); > > virt_pgd_alloc(vm); > - vm_paddr_t paddr = vm_phy_pages_alloc(vm, pages, > + vm_paddr_t paddr = _vm_phy_pages_alloc(vm, pages, > KVM_UTIL_MIN_PFN * vm->page_size, > - vm->memslots[type]); > + vm->memslots[type], encrypt); > > /* > * Find an unused range of virtual page addresses of at least > @@ -1333,6 +1335,17 @@ vm_vaddr_t __vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min, > return vaddr_start; > } > > +vm_vaddr_t __vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min, > + enum kvm_mem_region_type type) > +{ > + return ____vm_vaddr_alloc(vm, sz, vaddr_min, type, vm->protected); > +} > + > +vm_vaddr_t vm_vaddr_alloc_shared(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min) > +{ > + return ____vm_vaddr_alloc(vm, sz, vaddr_min, MEM_REGION_TEST_DATA, false); This shouldn't be MEM_REGION_TEST_DATA, because then the ucall patches changes from MEM_REGION_DATA to MEM_REGION_TEST_DATA, which I suspect will break ARM's page_fault_test. So, we probably need to have vm_vaddr_alloc_shared() be a true mirror of the non-shared version and take @type.