From patchwork Thu Sep 14 01:55:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13384116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 298E6EE0217 for ; Thu, 14 Sep 2023 01:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JAUpXbAohkYsaePtVieO0CL7XnnGRqqXqhV9i0Q4ALw=; b=MghNmGl8TpRHd0 xgFV3qkiwPzcDMcouz+4S6gGdmIO+tM0J7B5blH1FQovYPUqq2KSIMuVPz7AjOeRWse31wzKyYjve wbI+8Y1UeTQT5iEw+I7sR4MXKcguEqbh9zKyQiNvwzWyPqBK8wrJzUBgtOlYsqNBVf+CfW+c3xEUM fMbRLy4HFw8hK8xdOVzO6xWd1o569X4Qat58JD+05drnrtE5gLgpnh7bmNT2r1qBNZH4g5mGTocHT WbfpxNSgPi5zQVRVQ/Lo214Q/vfHm88xZAyEARQSK947CND0Gl6wfo09ZVOdr89WrLu991ZhvG71U 2G49rl1u9886DUrkh+Ig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgbdJ-00762p-0y; Thu, 14 Sep 2023 01:59:05 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgbat-0073gr-2R for linux-arm-kernel@bombadil.infradead.org; Thu, 14 Sep 2023 01:56:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To:Sender: Content-Transfer-Encoding:Content-ID:Content-Description; bh=UjBddbZXLqwDqs/dRSKLKY4HwUhf6Ai3WxLtYL+KxyQ=; b=FfYil/pPNLZiuipBUINYrllqYI yCnnPYgweIfthuoeTy5pPcWQbBPonmA5MT6evrF6fj4ANrmBroQNzkL0HXd6103vcKCG86GCqLKI3 yhU3LMRwVMClS5qpFgdiNMsbPHRmcJxaTVLNeKmLlHpCCO0s6VWfWj/bejwisUEADGM1yIy7aSUgv +jcGmIQIk7wKZA/+Ola38kqFqWFTCne6DL1YW+j0gKoSeQjjuG7kE4yPlHsXaHd1EP69rWDF4Sozk sk+sKKVr96fHbBSp6wWYl+x9FJ1EzcC0+sL0qG7qcsK14596hNKb1RtbR/7OjDJ1x5EIXFmDxB5GQ CCwwftxg==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgban-007TgT-2u for linux-arm-kernel@lists.infradead.org; Thu, 14 Sep 2023 01:56:33 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-594e1154756so6572647b3.2 for ; Wed, 13 Sep 2023 18:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694656588; x=1695261388; darn=lists.infradead.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=UjBddbZXLqwDqs/dRSKLKY4HwUhf6Ai3WxLtYL+KxyQ=; b=QLOrSiFKVBBCVyzycKQZRMqvzI/UHu6NZ8Tl0te7u20XBaYi7XZDyrL92/Mg8iFOky xWV+m9weaJxWStTI1NIzYHI0pLIjxl4x9tFlBhhrMyjtGh5OosQxYfYjXEkLtWKi4BKM EWyVFyld+2T4HtFqM5xUIIdl9UrIgRhivUPF5vMjcE6rY/GaHHawfrPpa6wxVS54FLVY KfTis5O6h8THti1GPqgKdOn0hHEJmJ+gHv+QCbhXwsw5Dqva9jQmUyxDZw9Opbnq1saa s7lm0x/tyAO3m5GcmgilVinRds4egjD/hX90IXzQSFbrwo8aYzXMtccMUk/o7lEeikN4 IOfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694656588; x=1695261388; 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=UjBddbZXLqwDqs/dRSKLKY4HwUhf6Ai3WxLtYL+KxyQ=; b=iDEdYusJfc/zIpx8835O8q8Nw5qvc4u+MUnKATy0fzrQ3aq+BBNjJNeK7WVZK/mtCH u8P3FjnnbDFPWIEAOson6B976PUlHGRJAzxkQJ3YeeDjN4BWvFgbwqEwW5Z5dTSbXpES EBo/FofeWxuk+ujG2vYrStf/rpAE4mO+MQG3m9wv8LFsny00AOmFIgvgLa2RsHErxhWj CHLO5PHjH9asQC7hag1uDslcX5MDgagz7vMnRc+VOO/+uhEdK9MzQ1SNwJF/SKQJFxBF C/80J656tiwcRZNl/BhmDG6wXwxItxrTajUSQQqLtRu6X4GzlIPR029iAFVlNd8Wgxcl HxEA== X-Gm-Message-State: AOJu0YyVlLX/8NrTWW3fihjgCcqdqfDKOoBT7f2tNV/TjUIQI0HbvstG HG0od4dlXZjZI5PhwzTgf9wpRjNfXhM= X-Google-Smtp-Source: AGHT+IH0gGeX6zOzLjc3uszP5L1cVBy/yaTsK9vfF/9VEoisKrc6F33BJumlmtJCwJ85BnFPZfgq0s7SPdg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:2e05:b0:59b:e1db:5633 with SMTP id et5-20020a05690c2e0500b0059be1db5633mr53066ywb.1.1694656588217; Wed, 13 Sep 2023 18:56:28 -0700 (PDT) Date: Wed, 13 Sep 2023 18:55:24 -0700 In-Reply-To: <20230914015531.1419405-1-seanjc@google.com> Mime-Version: 1.0 References: <20230914015531.1419405-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230914015531.1419405-27-seanjc@google.com> Subject: [RFC PATCH v12 26/33] KVM: selftests: Add helpers to do KVM_HC_MAP_GPA_RANGE hypercalls (x86) From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Sean Christopherson , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , Yu Zhang , Isaku Yamahata , Xu Yilun , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230914_025631_587899_3F18FBD9 X-CRM114-Status: UNSURE ( 9.79 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vishal Annapurve Add helpers for x86 guests to invoke the KVM_HC_MAP_GPA_RANGE hypercall, which KVM will forward to userspace and thus can be used by tests to coordinate private<=>shared conversions between host userspace code and guest code. Signed-off-by: Vishal Annapurve [sean: drop shared/private helpers (let tests specify flags)] Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 4fd042112526..1911c12d5bad 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -15,6 +15,7 @@ #include #include +#include #include #include "../kvm_util.h" @@ -1171,6 +1172,20 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t __xen_hypercall(uint64_t nr, uint64_t a0, void *a1); void xen_hypercall(uint64_t nr, uint64_t a0, void *a1); +static inline uint64_t __kvm_hypercall_map_gpa_range(uint64_t gpa, + uint64_t size, uint64_t flags) +{ + return kvm_hypercall(KVM_HC_MAP_GPA_RANGE, gpa, size >> PAGE_SHIFT, flags, 0); +} + +static inline void kvm_hypercall_map_gpa_range(uint64_t gpa, uint64_t size, + uint64_t flags) +{ + uint64_t ret = __kvm_hypercall_map_gpa_range(gpa, size, flags); + + GUEST_ASSERT(!ret); +} + void __vm_xsave_require_permission(uint64_t xfeature, const char *name); #define vm_xsave_require_permission(xfeature) \