Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3696963rwb; Mon, 7 Aug 2023 19:07:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6dXpZ2g8EkmWgfXiCWOa8o4vVvUl9lOZXHf4j9PGNa8x6zijiZe9Yp6Kkgkk7tNn0GSJ7 X-Received: by 2002:a17:907:1dd0:b0:994:54fd:31aa with SMTP id og16-20020a1709071dd000b0099454fd31aamr8925838ejc.15.1691460447386; Mon, 07 Aug 2023 19:07:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691460447; cv=none; d=google.com; s=arc-20160816; b=oIDGN+e3EOGaJD94LkDPGgY4nKCQ4Cezlnsqs0Ub1+4L4YrGX0zg50uKvd5XGJ1K1J ZlKNm7/QJV5E52HmvNecC7Vyqvw7kjPP8ecpk0EimuQIhKEN/ZtLf4MouHf6F+L9qiSc GgFYyTELND59SHeEnz9bFt5hsERoo5BjzaTwMxFY0PTxRnqPjWr8dSbgA7k7MXPlRogn ToSM/j8g6uf8SPS3gPTraM3JFxeEF//cHGqoTOVOTeyoHhgvGTd8JWRYjM6UzdCJap+0 9hlDQTug1K7jaqthnXjp6zh7+w4Q9v4u09CjyqX6Lr4/Y0KMzay9W1HxYWjboaR+C4Ux SAYw== 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:mime-version :in-reply-to:date:dkim-signature; bh=iwb23aAhSO8tTiEFGOvNlQCsoOox6vBjb8gCypJE4mI=; fh=Rl/qW3PCWhd+eVRSUZU2b6Mfxfc4uHUP1s/ljR5inrE=; b=Fg6FWqDd31RWNNEI3SpWlTAxijsXvEe+XuZ2tbIgiSm69OLedcikPxIYwJmUIcPL2s 7epCDvRfTf2tagpV6ySETi2gGHeoCsLyc17wOgBPHR2HxxF8g9CnUm1SvP5jG4SMhXTX eC78bpHXSVhkHIG609/unp5qwI7ZHz/G1iW+0iuNrG8d+BX1S2KB3+IpryeRw6+UxCXp XlxMUdAS0DtWEnP95Ahr9yQa3fVuPGeAeNDq+dZ5kE4AOOcWRS+G1FjAlWYkfXXK0GXE k8LXEYWPCvSVBhSS40W5iIeEWBdcGeYtBJGHl0QCr9rIqKSP29eJ0h9Yiw0uht04Ia5L ghvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=R4PwviCR; 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 md26-20020a170906ae9a00b0099bd56894d8si5117805ejb.71.2023.08.07.19.07.02; Mon, 07 Aug 2023 19:07:27 -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=20221208 header.b=R4PwviCR; 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 S230212AbjHGXZI (ORCPT + 99 others); Mon, 7 Aug 2023 19:25:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbjHGXZH (ORCPT ); Mon, 7 Aug 2023 19:25:07 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22B0A180 for ; Mon, 7 Aug 2023 16:25:05 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d41bfd5e507so4646484276.3 for ; Mon, 07 Aug 2023 16:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691450704; x=1692055504; h=cc:to:from:subject:message-id:mime-version:in-reply-to:date:from:to :cc:subject:date:message-id:reply-to; bh=iwb23aAhSO8tTiEFGOvNlQCsoOox6vBjb8gCypJE4mI=; b=R4PwviCR8DjVobdiirsmlaUW+2G2OreWXDR1oudY0WdYIlf/tRBxovHV7VVaY5H2D7 s6z9nsA/hZZOzOlAXwj0GlLszUfPpUcqxoVPBkJopNIVm5p7oN0Kjjk8CNCU0uvTetel 32HvbTwQx+uTw/DQ0hiV2GccLkJL/LCqkzOCOWamh7kng72/soRCwM6up6P8iJdnPSBO x/GLCUjk6m180XrAeVCUYgLoKf2lX03dUyg16yLerbR/XPy1Dd0ljJbOlBwH8tdW8OEH 2D0Guisqm80uErrMhMIOa5wS5t40qQeuRJl0ljw9a+5siKs8Y3hopoVBYIWmqvB1hWx2 ivOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691450704; x=1692055504; h=cc:to:from:subject:message-id:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iwb23aAhSO8tTiEFGOvNlQCsoOox6vBjb8gCypJE4mI=; b=JS7VDn722OetFmg5KN3JWk36Ig8i39ZcCcHRJjkkwfI9IUVXtskHNlOD1vlWicoaZR sXXNO540VtN5JZxtzqG/GTbIIzUqn3BOuoWhXNrfJaqUx4Mh2ggNMZ+hG70g2o5gMiFO 5JGzOJST7l40nVpWAJ+I9izi980tcCJ0XI6TDu5/Vj6VtbniMg0WX61kHCw31E1l4ctN 7E++wFPYGqXGUsyq10KMUgYWaSOZ7V3NuBoj3Xna5LEM9vnu9nbzyECixxnn/wcr38rk PyfWFAt+kH46mg6TOcfa0nVfD5IYDpW1qF5wM4VhcZon+hac2P55ZvHYJxxHmmygdVG1 kTnw== X-Gm-Message-State: AOJu0Yz/G0Sgycv3fxkl1sCiDvxFbV7CIdwSB2NVAcsuHaSpqQAqNOt3 Oz/YLXGFLUEJdbTQglP/EYFre/9tWsUjnUc0ng== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a25:445:0:b0:d4c:2a34:aeab with SMTP id 66-20020a250445000000b00d4c2a34aeabmr47419ybe.11.1691450704306; Mon, 07 Aug 2023 16:25:04 -0700 (PDT) Date: Mon, 07 Aug 2023 23:25:02 +0000 In-Reply-To: <20230718234512.1690985-29-seanjc@google.com> (message from Sean Christopherson on Tue, 18 Jul 2023 16:45:11 -0700) Mime-Version: 1.0 Message-ID: Subject: Re: [RFC PATCH v11 28/29] KVM: selftests: Add basic selftest for guest_memfd() From: Ackerley Tng To: Sean Christopherson Cc: pbonzini@redhat.com, maz@kernel.org, oliver.upton@linux.dev, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, willy@infradead.org, akpm@linux-foundation.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, 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.p.peng@linux.intel.com, tabba@google.com, jarkko@kernel.org, yu.c.zhang@linux.intel.com, vannapurve@google.com, mail@maciej.szmigiero.name, vbabka@suse.cz, david@redhat.com, qperret@google.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 Sean Christopherson writes: > Add a selftest to verify the basic functionality of guest_memfd(): > > Here's one more test: From 72dc6836f01bdd613d64d4c6a4f2af8f2b777ba2 Mon Sep 17 00:00:00 2001 From: Ackerley Tng Date: Tue, 1 Aug 2023 18:02:50 +0000 Subject: [PATCH] KVM: selftests: Add tests - invalid inputs for KVM_CREATE_GUEST_MEMFD Test that invalid inputs for KVM_CREATE_GUEST_MEMFD, such as non-page-aligned page size and invalid flags, are rejected by the KVM_CREATE_GUEST_MEMFD with EINVAL Signed-off-by: Ackerley Tng --- tools/testing/selftests/kvm/guest_memfd_test.c | 17 +++++++++++++++++ .../selftests/kvm/include/kvm_util_base.h | 11 +++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index eb93c608a7e0..ad20f11b2d2c 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -90,6 +90,21 @@ static void test_fallocate(int fd, size_t page_size, size_t total_size) TEST_ASSERT(!ret, "fallocate to restore punched hole should succeed"); } +static void test_create_guest_memfd_invalid(struct kvm_vm *vm, size_t page_size) +{ + int fd; + + /* Non-page-aligned page_size */ + fd = __vm_create_guest_memfd(vm, 1, 0); + ASSERT_EQ(fd, -1); + ASSERT_EQ(errno, EINVAL); + + /* Invalid flags */ + fd = __vm_create_guest_memfd(vm, page_size, 99); + ASSERT_EQ(fd, -1); + ASSERT_EQ(errno, EINVAL); +} + int main(int argc, char *argv[]) { @@ -103,6 +118,8 @@ int main(int argc, char *argv[]) vm = vm_create_barebones(); + test_create_guest_memfd_invalid(vm, page_size); + fd = vm_create_guest_memfd(vm, total_size, 0); test_file_read_write(fd); diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 39b38c75b99c..8bdfadd72349 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -474,7 +474,8 @@ static inline uint64_t vm_get_stat(struct kvm_vm *vm, const char *stat_name) } void vm_create_irqchip(struct kvm_vm *vm); -static inline int vm_create_guest_memfd(struct kvm_vm *vm, uint64_t size, + +static inline int __vm_create_guest_memfd(struct kvm_vm *vm, uint64_t size, uint64_t flags) { struct kvm_create_guest_memfd gmem = { @@ -482,7 +483,13 @@ static inline int vm_create_guest_memfd(struct kvm_vm *vm, uint64_t size, .flags = flags, }; - int fd = __vm_ioctl(vm, KVM_CREATE_GUEST_MEMFD, &gmem); + return __vm_ioctl(vm, KVM_CREATE_GUEST_MEMFD, &gmem); +} + +static inline int vm_create_guest_memfd(struct kvm_vm *vm, uint64_t size, + uint64_t flags) +{ + int fd = __vm_create_guest_memfd(vm, size, flags); TEST_ASSERT(fd >= 0, KVM_IOCTL_ERROR(KVM_CREATE_GUEST_MEMFD, fd)); return fd; -- 2.41.0.640.ga95def55d0-goog