Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp254607rdb; Wed, 14 Feb 2024 21:29:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVjCQRylCt2INsjEHZrwnlhTrnNXMWIKv4MwP43hGBZI4CuZ+iZNXhN2wqCtrpB75jhtFe0mA+RxLvz2AjQkDh9AiL/EiG/k5YRbh+wlw== X-Google-Smtp-Source: AGHT+IFBtJKvFFAhG9/sogeMuR2AoBjY/GVaJPblV3UwG/XBUAUBUoT4xHOrjHxoufksmejGu3GI X-Received: by 2002:a17:906:1d4d:b0:a3d:5ba3:1182 with SMTP id o13-20020a1709061d4d00b00a3d5ba31182mr407320ejh.30.1707974997416; Wed, 14 Feb 2024 21:29:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707974997; cv=pass; d=google.com; s=arc-20160816; b=z7iS3O7rORerDX0U1REi1x845Twid9v1w+t0lLls1rVTbTbAXroDIMMYUvUhBB8AEZ zxcPbYA8sEWC2k6a66BddlUa9Zq4AtPpx6JmU7JfYKmUDr8kcrePtxnEnTLizm+BFLsk 8ajvg+/HLRlccRb4RA43FS44dxGXN43r5lYYrShCX4yj5Q1rFJZYG1pcqqsk6RyN4g0h D4TA+n0UqMrOnijDUn6FFSyQwFM53Cb91E5GN1t9C3xSvTGpG1zuE4reD7lTPdagfG12 8KvpcNnbk7Ubn+wMB4d7Y4XX1GtwWrN8/v7yH3anc5517meBgkMa7TAQe7uNEM2yqahV k+xw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=DJo0Z4lBIwPC8cwQYpRIOozyv+hDmIUKGggHbYocrU8=; fh=wSIZtv79dNXyrqHImut/sJftuLbTwBBWRSI6I5CZGf0=; b=OhhBEQAsRgmn8x35fRONn4+CNwFo6X3UyMptCYtDyRUKBdHOyl0gqZBiQvGkk0/UW/ xJSSN+lccxyhgQpm64pt8aas2YaOji8d2GZhtCa8Kz+L8TfIkH6ONUp1ItZyk/yg+aBj pgqb2PLyo5IFj4Tx4MuNk3EP2cHoeeZpYl1onnC2FIXhESqvC18nCoxTrW1+VfCdZlot o4FeK2o4pW5hCKAA2mU+Xip8HJUolp9HJs9HB8LnIdjBF29fbFnanA1Z4fHjGc/g4MRx KEpqc+uU2xma6sqxWRAlEILq3TnQihACrCMPf1ol00f2UypzO7OPy1gL2NTKx7QzxIDQ Swjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JMvt0zE8; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-66310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id br14-20020a170906d14e00b00a3d67fcabccsi288222ejb.914.2024.02.14.21.29.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 21:29:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JMvt0zE8; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-66310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2FCE11F21F81 for ; Thu, 15 Feb 2024 05:29:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA47EBA2D; Thu, 15 Feb 2024 05:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="JMvt0zE8" Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (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 F05824A12; Thu, 15 Feb 2024 05:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707974984; cv=none; b=K/11ss6VsG0WirrI0KWf5Xr38RCB/VuZoQw0QIhU9B8GkdQYwmArq9q/Syc4MYIYMXhGn5/tYSTK9uLA+vccAH3HcDsgSeEwmsQFXgoqzySKRJtuGwD6OrAusZ4sVrORKoNWSWQhi/rxwG3KzVj7FWLfqxrTbGaAbicc571Kk9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707974984; c=relaxed/simple; bh=uxfb1c2RaLDUFG8vm19/j7Iy8u7uEX3/DuKkwKNBZ4M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mjIis3SLFSPbJoKXtRLayJ3OkiG/YACuaA1csYmyMXm1FqHRjjSDQtHL6P6Tby5sqBExrG+VmoEpvHoCT2sBl6lsxKpDavzm+CUEYaK+TKQEl0aqfcHMR7+uOHf7iz4xwfpT9WhNWBk19dFjc7g9vmrD9e1GVAWLZTDwH+B3onQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=JMvt0zE8; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Thu, 15 Feb 2024 14:29:28 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707974980; 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: in-reply-to:in-reply-to:references:references; bh=DJo0Z4lBIwPC8cwQYpRIOozyv+hDmIUKGggHbYocrU8=; b=JMvt0zE8GQid/p0MkbZRVsrGi+W1t/zzYgVElcer9c55Q/gCxwMPmPwlihKR9pJE5PDW6a 3TReNnyec55HT7lqFR8vxrbuXYbBEtah7kNXvaRJcOH5q6IAqYdGrmnRZNi1baOoo8DGHb bAuguauFjnb5bxQGCxF8X/D8yC0/wLM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Itaru Kitayama To: Sean Christopherson Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Vishal Annapurve , Ackerley Tng , Andrew Jones , Tom Lendacky , Michael Roth , Peter Gonda Subject: Re: [PATCH v8 05/10] KVM: selftests: Add support for protected vm_vaddr_* allocations Message-ID: References: <20240203000917.376631-1-seanjc@google.com> <20240203000917.376631-6-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240203000917.376631-6-seanjc@google.com> X-Migadu-Flow: FLOW_OUT On Fri, Feb 02, 2024 at 04:09:11PM -0800, Sean Christopherson 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: Ackerly Tng > cc: Andrew Jones > Cc: Tom Lendacky > Cc: Michael Roth > Signed-off-by: Michael Roth > Signed-off-by: Peter Gonda > Signed-off-by: Sean Christopherson > --- > .../selftests/kvm/include/kvm_util_base.h | 3 +++ > tools/testing/selftests/kvm/lib/kvm_util.c | 26 +++++++++++++++---- > 2 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h > index a82149305349..cb3159af6db3 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util_base.h > +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h > @@ -590,6 +590,9 @@ 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, > + enum kvm_mem_region_type type); > 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 ea677aa019ef..e7f4f84f2e68 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -1431,15 +1431,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 protected) > { > 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, > - KVM_UTIL_MIN_PFN * vm->page_size, > - vm->memslots[type]); > + vm_paddr_t paddr = __vm_phy_pages_alloc(vm, pages, > + KVM_UTIL_MIN_PFN * vm->page_size, > + vm->memslots[type], protected); > > /* > * Find an unused range of virtual page addresses of at least > @@ -1459,6 +1461,20 @@ 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_arch_has_protected_memory(vm)); > +} > + > +vm_vaddr_t vm_vaddr_alloc_shared(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, false); > +} > + > /* > * VM Virtual Address Allocate > * Reviewied-by: Itaru Kitayama > -- > 2.43.0.594.gd9cf4e227d-goog >