Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3722026rwb; Mon, 7 Aug 2023 19:44:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAtGWdMDjZGwFj8IJ7nfQej8DebUgjqj79V4nf87+P4JvaAwNAfx+pAbu4Tm5uiAd2q6WN X-Received: by 2002:a05:6402:1111:b0:522:ca7c:df80 with SMTP id u17-20020a056402111100b00522ca7cdf80mr9106612edv.0.1691462646627; Mon, 07 Aug 2023 19:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691462646; cv=none; d=google.com; s=arc-20160816; b=yARLXvWOh24wD/mFZYJhvmGsbq2VmMVh276FI4FHDfPpqDK0RWnPWfkHrlQaV4ZUmq GAac159QwrAsNDOTwgfvTRoy7OIx3aEN0eoqwHH4NAefGrnk55uP8LeRGlF9lK2rItZR nJVzJ6VY0qRivmjS7ZFm0Qmivel5UTMBGjQw8P1Dul2BP5Q5h9ixhwluNB5S4yCqfTDN QgQAKkMeI9ubvkMwcVlkf6BY+Aa3aBfwjdDjExdwt22TWSz/1ghFghcn3X3BKJa5Ag3y ThtW9vQn2vGJiOnCJWbAd62jD1CwaF99TdhKreVqaktOBdofqQqF5F3sf/4V1mShwoas gzTw== 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=O6ADKvrj6NKuTG8K0De5TN5TBG7YUj/XYIH2D8dp568=; fh=Rl/qW3PCWhd+eVRSUZU2b6Mfxfc4uHUP1s/ljR5inrE=; b=HQEU1POKi9He7wcPz9rdkGonOara8kLaezPpfBjHVyhFxXEUm+Q1DMcMfND2KKxiI4 HugMJOYC2Sprirseu+jOoA3ZYTPYpDkI4cjDE53Kx1gG/AVTXHIFbhmlXZl3bpuj198+ 7Szva+IVxaNYqZ8Io9ZajfjVDLjDf6eC1IodLBf29YNPmj/Afy+6mFboKhQdJBGomU1a SQ4kTlEIE7EVaUh7NEjNgQucL9FRKcDJqSOwPL3nL9QzAbtLFdRkB39hxqzjjJooIJL9 ziqPC50ZsmP0Ebm+NvwJqYXczPpAqwnf6/1IX3IWaSY7zCe2N06cqqZDFtVtfSxk0AxR NyZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=rHwQlDZD; 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 k25-20020aa7c399000000b005233fb6b8c7si1187314edq.35.2023.08.07.19.43.42; Mon, 07 Aug 2023 19:44:06 -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=rHwQlDZD; 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 S229630AbjHGXSL (ORCPT + 99 others); Mon, 7 Aug 2023 19:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbjHGXRx (ORCPT ); Mon, 7 Aug 2023 19:17:53 -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 C00F61705 for ; Mon, 7 Aug 2023 16:17:51 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-57320c10635so58780097b3.3 for ; Mon, 07 Aug 2023 16:17:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691450271; x=1692055071; h=cc:to:from:subject:message-id:mime-version:in-reply-to:date:from:to :cc:subject:date:message-id:reply-to; bh=O6ADKvrj6NKuTG8K0De5TN5TBG7YUj/XYIH2D8dp568=; b=rHwQlDZDzym7DX7JPTeHFjVedtFRUtAMiKX2VU1EjC3DDPS+GKehZ420ny5GaoR1ql DJZSgsfTVJl3vHuTgVdsaoMbYWxHvGzjOU0b7lDeewUWBnmHCx4rEyCV+u7mMO4LYlh5 X/eCH8/74nhTzgvQgUg3W7ew8mnRsIapj5OejxlfXYe7B7oIEIOpl62BZW0oI322fnfO 0Voq/X8G0TvKlJzbTSRNfra4zE+z5UETF5mjVUp3srNKrf5MdQ1+J9GDHb9R/7Klrk79 sQ7ciz1qdHaVGW7a/1FblT/tag2WVBkp7Xupx92Rz9XtAvp0t79KGYAXs3GugjDd4DWz Be4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691450271; x=1692055071; 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=O6ADKvrj6NKuTG8K0De5TN5TBG7YUj/XYIH2D8dp568=; b=FYBai2PRSMNGKbR6D4T+iGrv6TYewbc0pxqtoHjT7NUnxNsH7aXDyVNencPEcZ5bgC kpRA6JKMhHQy12Pf6DwMisPr/yhFz+9ScEJUTYGxxskbpCFUyVCzklMiW+wr18LDQSbl r4x64qhgU5k0v1uggm8+10EIAPdljeTWaFfsZAlSL3E5oE0eAlWYtwzTypiD7k8LGtFg SyMMOP+cJ5jwvjJAJWUx63g1FIunNpt4UMn7wSYuVY0Q1DiFFrw4ohUpmqNlrKTLqAwP 6Ep3sbq5qlFHkp3vq62n4hEXpwBFVBFpuO2htWl4Y7p2wus5Pys3d+tXkVrOu4UgmFrE HvMg== X-Gm-Message-State: AOJu0YzxY2Sj9x9WjzaqLaYwGtQU3zY6snUBr5loKk4KM4eDcQrQgWnp M1zhGcHEa5vL9yEiD9y+qq+wbwsMrM6q4yCi6g== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a25:ce50:0:b0:d4f:d7a5:ba3b with SMTP id x77-20020a25ce50000000b00d4fd7a5ba3bmr34924ybe.8.1691450270921; Mon, 07 Aug 2023 16:17:50 -0700 (PDT) Date: Mon, 07 Aug 2023 23:17:49 +0000 In-Reply-To: <20230718234512.1690985-28-seanjc@google.com> (message from Sean Christopherson on Tue, 18 Jul 2023 16:45:10 -0700) Mime-Version: 1.0 Message-ID: Subject: Re: [RFC PATCH v11 27/29] KVM: selftests: Expand set_memory_region_test to validate 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=ham 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: > From: Chao Peng > > Expand set_memory_region_test to exercise various positive and negative > testcases for private memory. > > - Non-guest_memfd() file descriptor for private memory > - guest_memfd() from different VM > - Overlapping bindings > - Unaligned bindings > > Signed-off-by: Chao Peng > Co-developed-by: Ackerley Tng > Signed-off-by: Ackerley Tng > [sean: trim the testcases to remove duplicate coverage] > Signed-off-by: Sean Christopherson > --- > .../selftests/kvm/include/kvm_util_base.h | 10 ++ > .../selftests/kvm/set_memory_region_test.c | 99 +++++++++++++++++++ > 2 files changed, 109 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h > index 334df27a6f43..39b38c75b99c 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util_base.h > +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h > @@ -789,6 +789,16 @@ static inline struct kvm_vm *vm_create_barebones(void) > return ____vm_create(VM_SHAPE_DEFAULT); > } > > > + > +static void test_add_private_memory_region(void) > +{ > + struct kvm_vm *vm, *vm2; > + int memfd, i; > + > + pr_info("Testing ADD of KVM_MEM_PRIVATE memory regions\n"); > + > + vm = vm_create_barebones_protected_vm(); > + > + test_invalid_guest_memfd(vm, vm->kvm_fd, 0, "KVM fd should fail"); > + test_invalid_guest_memfd(vm, vm->fd, 0, "VM's fd should fail"); > + > + memfd = kvm_memfd_alloc(MEM_REGION_SIZE, false); > + test_invalid_guest_memfd(vm, vm->fd, 0, "Regular memfd() should fail"); This should be test_invalid_guest_memfd(vm, memfd, 0, "Regular memfd() should fail"); > + close(memfd); > + > + vm2 = vm_create_barebones_protected_vm(); > + memfd = vm_create_guest_memfd(vm2, MEM_REGION_SIZE, 0); > + test_invalid_guest_memfd(vm, memfd, 0, "Other VM's guest_memfd() should fail"); > + > + vm_set_user_memory_region2(vm2, MEM_REGION_SLOT, KVM_MEM_PRIVATE, > + MEM_REGION_GPA, MEM_REGION_SIZE, 0, memfd, 0); > + close(memfd); > + kvm_vm_free(vm2); > + > + memfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0); > + for (i = 1; i < PAGE_SIZE; i++) > + test_invalid_guest_memfd(vm, memfd, i, "Unaligned offset should fail"); > + > + vm_set_user_memory_region2(vm, MEM_REGION_SLOT, KVM_MEM_PRIVATE, > + MEM_REGION_GPA, MEM_REGION_SIZE, 0, memfd, 0); > + close(memfd); > + > + kvm_vm_free(vm); > +} > + >