Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3590452rwb; Mon, 7 Aug 2023 16:42:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGslpLjj6n1rzBtjWcboalLXIRooaGRjIWTd2Nijj5i64OlYLD49zF85tI8lOKneMZprDhI X-Received: by 2002:a05:6870:e888:b0:1be:cee3:f3d with SMTP id q8-20020a056870e88800b001becee30f3dmr13385120oan.56.1691451757804; Mon, 07 Aug 2023 16:42:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691451757; cv=none; d=google.com; s=arc-20160816; b=ffUS0k1SAE3ON+os4vpP0Riyh7fIDlNYTSECEI/0gPjQFt6c465WVOcknQi9lb0R+8 j49PliAxbF72bjolgCc1Rtl4xNKKWOa6gwjYHaM/OvpQtf5kF0G5vc36ocpOGion48x/ JsugyHP5K8ARTKnKEx4otm4sJ7vU28M1Yb+L6PVQRlr+UicODUrFC1uTIcBkokZHd76N sswDEF8RHZLQrmPgxqkbjZphgJzCcyRCT0pfEKA3Efs7TP32L6aW0Ji6OYUVbpE6uL1a cUhOV0RDiJgZBPFpEy8FugneCIklWrL52MvY6fdkZ5SQsnvTrr4KMw+QqtKFyjMjFKqq vEMg== 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=1Ut/hDJ+qFMS0sDMssVLi/Qh1tossNoTViyk+Sv5I6I=; fh=Rl/qW3PCWhd+eVRSUZU2b6Mfxfc4uHUP1s/ljR5inrE=; b=m617lxOaEcKDEgzY8O3p4Cym4A17a9qqJa95si/PFeNNsgGY6mKu+YE9LF14F/bXwY sHkkSWw1zTWC0WidJGtUsFVBhVD6lm1beh7TVwyENYVMJgp8nRtcZULMfc4pCm2yGeT0 p9AcDbjb2ASbJtxSGxn6Dyj5aeTJ5yNVZJK0zQHKKrEyo/LuQewrkYsWGvAW9phJAzQV TvUU+EpxT3EZO2y7LoR/f8UOJ2ZiverHJI3n/buK9ddGF0is7Xw9X+sGtaiEO/z3wON2 06mhNDS6EAaQcdYuvf0ieiENY84x/DdD/14lz+aAEj7R8xu+kfKbVBgvE75LOewwzZQh 223g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=OnbGVA8I; 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 v10-20020a63f20a000000b0056514d0595fsi326185pgh.296.2023.08.07.16.42.24; Mon, 07 Aug 2023 16:42:37 -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=OnbGVA8I; 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 S229901AbjHGXUV (ORCPT + 99 others); Mon, 7 Aug 2023 19:20:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbjHGXUT (ORCPT ); Mon, 7 Aug 2023 19:20:19 -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 36F16170B for ; Mon, 7 Aug 2023 16:20:17 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5868992ddd4so58933747b3.0 for ; Mon, 07 Aug 2023 16:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691450416; x=1692055216; h=cc:to:from:subject:message-id:mime-version:in-reply-to:date:from:to :cc:subject:date:message-id:reply-to; bh=1Ut/hDJ+qFMS0sDMssVLi/Qh1tossNoTViyk+Sv5I6I=; b=OnbGVA8IPnrsdTREsUm581mRdehgXJT0uL+ALPcn3gfxErJrXCtKmSomsOKaQATGMh f0VvgjqMIW5HLukSt/TZqta9FHSpbW8xuPg/WJY9Y8dBtzBXk68FxKvGTf0SBMt/xuPE yb72/yaLEWHxd2i86q/oL/iyLDDk998ORMSoUHaZduqRHpQmcSBeRXdyojnyjv3Pm4Gp 0hyU2N4jgt9pJV3/SHK5m7Gafo6teeA6CAaXNJJ1Z5NngK3Yas1VVpJwsDY8b342oTWb +N+E2aHGEdoYFXjyTrvdzsHzrQ8RpCJH9Ba/1//rKN61ZJdF3SLJ42ybI7Ydk3RiGWfT qyWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691450416; x=1692055216; 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=1Ut/hDJ+qFMS0sDMssVLi/Qh1tossNoTViyk+Sv5I6I=; b=Q5fwRDb3rnsTBc5GcDsEvmvkP2XUakPqJG5AlVzg5fRCOS9yeDur+KBf0tC8J1Dc5/ szL+GRKAsR6qXarWSoGcXDjNfWfGB1+j7W5+PuZ9n8otunNTtVdWkdhskHeR5a5yf+xB WPkrXLvhDXVmevgPDeSu9EX/BJsnbxxL4qyuNyTOcOIGeYKUAOAia7nx26fjNhNIBhm4 I9X/3COCGNTxKvglzK4hdMPtYNAQULaMMPnPOGQ5CrzBC4mu74GWCt6+wk/GslBAiaO/ MmnUlhEMEy07rKgDx0y4m9bdgp9A5lZFI9GXeZQ3Z890idYnKjeXVJ39+EVUqqW4OeCQ 2a1w== X-Gm-Message-State: AOJu0Ywg5nH+1Jd9tqj/E8mgA6D2dZoLNSG8N1RPFzPFfutK8NFjXqPP mc8kcx6dKoa69FKHVpHajzX3BEELvmb/12xr7g== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a81:af45:0:b0:581:7b58:5e70 with SMTP id x5-20020a81af45000000b005817b585e70mr85942ywj.5.1691450416406; Mon, 07 Aug 2023 16:20:16 -0700 (PDT) Date: Mon, 07 Aug 2023 23:20:15 +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(): > > + file descriptor created with the guest_memfd() ioctl does not allow > read/write/mmap operations > + file size and block size as returned from fstat are as expected > + fallocate on the fd checks that offset/length on > fallocate(FALLOC_FL_PUNCH_HOLE) should be page aligned > > > + > +static void test_fallocate(int fd, size_t page_size, size_t total_size) > +{ > + int ret; > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, total_size); > + TEST_ASSERT(!ret, "fallocate with aligned offset and size should succeed"); > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, > + page_size - 1, page_size); > + TEST_ASSERT(ret, "fallocate with unaligned offset should fail"); > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, total_size, page_size); > + TEST_ASSERT(ret, "fallocate beginning at total_size should fail"); > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, total_size + page_size, page_size); > + TEST_ASSERT(ret, "fallocate beginning at total_size should fail"); This should be TEST_ASSERT(ret, "fallocate beginning after total_size should fail"); > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, > + total_size, page_size); > + TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) at total_size should succeed"); > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, > + total_size + page_size, page_size); > + TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) after total_size should succeed"); > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, > + page_size, page_size - 1); > + TEST_ASSERT(ret, "fallocate with unaligned size should fail"); > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, > + page_size, page_size); > + TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) with aligned offset and size should succeed"); > + > + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, page_size, page_size); > + TEST_ASSERT(!ret, "fallocate to restore punched hole should succeed"); > +} >