Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1154330rdb; Fri, 2 Feb 2024 16:11:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnBWpeFv73ZLOaj23/D9TZBiKdKud3PuoQgEr6J+viIIcQWE2DVZv9wYaHL8T6LWnrEAfw X-Received: by 2002:a67:ba12:0:b0:46c:f354:efbf with SMTP id l18-20020a67ba12000000b0046cf354efbfmr5075794vsn.35.1706919087231; Fri, 02 Feb 2024 16:11:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706919087; cv=pass; d=google.com; s=arc-20160816; b=cLBUO8l/SWuJejC7S8r7888CvTwHqyefgtP7yzz+Pj3YXIrtM5XQhCaVmCi35dvmN0 AJhYrx4VjV2YUXi3wTB2SaZ2qTIBev8QQH2EOqPYZkoNGWa62oWRoyTfYJ90XQc3fIOK qAfgqoQ91N3m7yRF84xsTQnksiyvOevRyc/Wz2f8gaqc2V9dcBCPK6pEJqh1PFyaQxJe btAUb9i1xn0z0qePIXG86ADAvLWLSL8DsihxKX8juTuqNsRFyffZ7JRcuqOg0XzuFgIX +YFw5nG7uTL+0I4fgqrDYGZsf54+qEr/fIOKJioUrpcugReQ5CVHEfOqPZy6byDBnn7b yrsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=5qit/ax01cjsi8jn+OF5XBDYnQC7hsp7dQaMdNEMAzo=; fh=v6NrVB8VXdAYzBa/1rcPu8A034nB/TIP+k090+0vXHM=; b=FeDehRm+3qJ+cmB/P0RK/zseSiq70FjDKa6qL/hOwUGWQ+Tj60wORT1Xh36i2+p8f+ 3OOh/qWL9IRpjzVjgKpw2wRJpj7Ft2TwRAHIuvKWgfhxYyOVgEmdhR6V4Ct5DiG8o26d Ee/Fi6sFUgAV9u87d2b0HqALs7+V0F0WjqqRMZcHezugu+8m79bIlr9QewphfcqqGfX2 5ajChMN/9F1sLQVueYjDe8X8zbDWPy+hv70035iQLN2WOTOH9EUbgLoopwlKI+texggS YXdpsc+mqiLdn5eALYJLHDnZnHNIVBJfnQYqmpLwl9pSyu290pgODGrf+eJJxf963Pf3 C1oQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xBbbsGRc; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-50751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50751-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUgqAKfVc6/ZOPeWSy99sZEwqCE55Kg/Garzo54E7TSBLXqQSBTrFyPYJxDpLmu61EeFOfC0ABfSYNgMcZ8sZxVgaTg7vPtP/gbxHPKaw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g7-20020ad45147000000b0068c5dffc2dasi3109690qvq.283.2024.02.02.16.11.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 16:11:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xBbbsGRc; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-50751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50751-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 A7D9D1C20DB2 for ; Sat, 3 Feb 2024 00:11:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F12210A09; Sat, 3 Feb 2024 00:09:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xBbbsGRc" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDD628F72 for ; Sat, 3 Feb 2024 00:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706918973; cv=none; b=BCRwm1tOpCiCuoVqXb//9Rbifd6WHrZycOXKup75BjrTrydz6TSAod1+ZK4nl9LErm9dZawFNi/m5eyxSWiK3i2Lki8+FZ659iyAffeZqQ5HG9/CJxEx4xW1TPv2tVLdNeilwFCD67a+A5rV1yE4WGk8CwuTgtAkQM2BWTs53cM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706918973; c=relaxed/simple; bh=eEsuDAyYhqh0PRIkmb2mwUAqWJ2Pol0Ha6iX400H8fc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DzKOSTIUy5qTwO7bUYFfYXLbC7lLz/skpTIbSAa3v+439+NIR8pO0/dM+zlrkX/5ESXGkmrjZLBlM/uAEAX1C5+rAb5Hk6KmLEdPHED3Z892KVPs2/AdYobkQElFFPeQKh7LzSagHWfXHH84yjX1PCasGE82v71iIP99RXlBg1Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xBbbsGRc; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6041e5b4367so38749347b3.3 for ; Fri, 02 Feb 2024 16:09:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706918971; x=1707523771; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=5qit/ax01cjsi8jn+OF5XBDYnQC7hsp7dQaMdNEMAzo=; b=xBbbsGRczX9e6fFUaFftX9mbr+YTAnGcrCF0wxijp5Pg0y8c3hL4zKqkKl2xF/++5D Qim+Kmq+PowZDSCqlfAv9A+iXYl/+3ohyQgHXTg/y9sYDBo6CB3PeKihRh2PuFzG/vWM oYN9q1jqfaxZELkUhzKGnfj8+FDEV4lSRKD1GErcojnu3+G42PzdXbHdqk5pY88gZ8ri qtbJNHCkoIzt1l3duR7NYpH9GYgFAPXIlYmODppjNjbFZ5IozElMJgX9jl5+u+XtxyP9 9ysVF4a5cUaYz3xO0pwbtqUDVs0vbIW0AqlkqtN7KdYYWowJqEdkRiO3cSDrDR9iVb4K jEpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706918971; x=1707523771; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5qit/ax01cjsi8jn+OF5XBDYnQC7hsp7dQaMdNEMAzo=; b=FZsZJACWwYeiaSYRfvbwIcW2LdYaq9aQA7l6cMminLAL/lRYD2SWKapPhwrfVLIXIw yj3GLK+gUWIC/SIU0ECuBkoUzee3gOL7QotNWmSJYzhbyC4P4sOkj2KET3W/QyAGGuAg EWdbPQHUJ2rgcR+5EfSxg/o0+CjYvlKgZweCCH55I2Yg68BDIFqLlJgCSbzATVZm1262 /zrQ6Q0QWfg+dSZdzRYbjuiQpZZNcBw21Y4NrKp1GZEYnn7T5vQEDZgGrrVyi9iXsp4m crrV+TmsQ+vD+zuCTOrT53equijy7QbSJDL5SYVSbZIikZW71HMVLLEIq8TE5D8r88X/ l+RA== X-Gm-Message-State: AOJu0YxpCKN3SF/VZS8NQu0ncMzRqOv9UvlnoMmJFzJ+aFXcqm0n4P+O 1Y0F/euo28k3QkImBFGt592tjzDRgXexEp9ABVgBU3mzaqlU4ra6WzmzKleE/nFJk8CD3brMUhl aCQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:4cd5:0:b0:602:d83f:bf36 with SMTP id z204-20020a814cd5000000b00602d83fbf36mr1585025ywa.0.1706918970863; Fri, 02 Feb 2024 16:09:30 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 2 Feb 2024 16:09:11 -0800 In-Reply-To: <20240203000917.376631-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240203000917.376631-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240203000917.376631-6-seanjc@google.com> Subject: [PATCH v8 05/10] KVM: selftests: Add support for protected vm_vaddr_* allocations From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: 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 Content-Type: text/plain; charset="UTF-8" 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 * -- 2.43.0.594.gd9cf4e227d-goog