Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2344651rdb; Thu, 21 Sep 2023 16:19:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUbHy/1hj+Llvp4dL9D7xaUICVLXvZdb3XuJYudQ5i6JcvioYq3ECGKxpXUk2kVDUGJ3Yu X-Received: by 2002:a05:6870:4411:b0:1c8:c128:c38e with SMTP id u17-20020a056870441100b001c8c128c38emr7504338oah.15.1695338355287; Thu, 21 Sep 2023 16:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695338355; cv=none; d=google.com; s=arc-20160816; b=FbUV5gdhBC5YUWH69arugAvZDHta9+2KnXRTTY5bCdbareoyRNNa0KN0zLULg8TCf/ ZB5VX7bbbSVLyAn36PHsrKu4JkNi6S7ZFkjx/YcB0UyNWVPaQRvJ4TetWpxWYYfw5Z3e wztTc6ievKEeoxz/y1WgEmNr/u7RHxvOmpIadPhlbeLEzYauFgiyMHEpFjhSQPRPIVVm sbl1a2FMP/d3QU814HZTApP355XH+QOJFXw9gBiV8wFdZ4zCiBPLSxEnslYm2iCuS5rZ L4iNNKdNlYypLw7KgXE1c95Y8SNPmjvV0ApVbRjcxqib/KnPYJhBhc8eREC62Fy6OijG 6kMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CJS48tTY7QUpbXV5rb9qaKa8C5LJvXPM27U+SZxJ5vw=; fh=ANS6iRpdj3ntKSmwSzT4LEHUH9ZAudCj9zvP8/EeThQ=; b=LsZR997hzdz9sjkI/Ovin2CQj96JLpb16tMr5/85GLMXxXBsaxV6AR3dK5H7+r26D0 gksDcioamhaI538K0Jp8XIbjG7a2Mgc1dATaWmiIc9mZMle2FBlUXEDybwB112W/WkFR dJYjXxGk7fotDZQxyZesrXGVTXipzu88Lxo3jYGaypvvreonvZ5OiZl/A+kpv6ikYSPI PeTtu+hLHhYZaiCaF9Yqs4x3n2utjamWpQb6/UbuilXAtvXTRGqAOtAvca9qDQJI1LTV DHSF8U+gYYPrq/6mwEWsthw24nR3dpv50COnACMTrA6c+M1viGi9qA42CRu/TTI8GJL/ HSCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LwjCAnJ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id b66-20020a633445000000b00564b99f128dsi2442851pga.656.2023.09.21.16.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 16:19:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LwjCAnJ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 7F4DC80A1664; Thu, 21 Sep 2023 13:41:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232251AbjIUUlU (ORCPT + 99 others); Thu, 21 Sep 2023 16:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbjIUUlF (ORCPT ); Thu, 21 Sep 2023 16:41:05 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E793199B; Thu, 21 Sep 2023 13:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695327289; x=1726863289; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j8I9xEhVY8G4DBx7Fus59ORWF9OXOGvs193SinT1foI=; b=LwjCAnJ137rH5XRwhcftBz4jCl1S0nkY7prTsUCfMFCTDsRuhLhxu3Ku DJ1uKoTsBixOBKYKhKe3vkT5bWzroUTahGx+95DH/Pw02++eqAdqelvTR 9Uu7uYG7z6O+HQ6UZFYp2pJXPx6Stw8oXaQ+l06W61Fz8uSatYEEkvXcr cgRsuFjxkVpMcL3Iz4k8DU0EkYUbQL18PMOD9i+bN3JemwMyGGUQzEvpt OSZNyHnUMe8Kf3smRMduiqvXdxAutPq9mDzVksCcQFxo9J3stsh/YmDD1 SJmRDTk1rbDExScqTuhP9FrB1t3kTUdjBOoaZG+5QpyZ4FS03MPxV2LZo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="383401598" X-IronPort-AV: E=Sophos;i="6.03,166,1694761200"; d="scan'208";a="383401598" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 13:14:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="696897787" X-IronPort-AV: E=Sophos;i="6.03,166,1694761200"; d="scan'208";a="696897787" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 13:14:46 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Michael Roth , Paolo Bonzini , Sean Christopherson , erdemaktas@google.com, Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, linux-coco@lists.linux.dev, Chao Peng , Ackerley Tng , Vishal Annapurve , Yuan Yao , Jarkko Sakkinen , Xu Yilun , Quentin Perret , wei.w.wang@intel.com, Fuad Tabba Subject: [RFC PATCH v2 2/6] KVM: selftests: Add negative test cases for punch hole for guest_memfd() Date: Thu, 21 Sep 2023 13:14:35 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:41:31 -0700 (PDT) From: Isaku Yamahata Add test cases to check for punch hole of guest_memfd to reject unaligned offset or size. Signed-off-by: Isaku Yamahata --- .../testing/selftests/kvm/guest_memfd_test.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index 75073645aaa1..d5b4bfcdc3fe 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -91,6 +91,37 @@ static void test_fallocate(int fd, size_t page_size, size_t total_size) TEST_ASSERT(!ret, "fallocate to restore punched hole should succeed"); } +/* Negative tests */ +static void test_fallocate_fail(int fd, size_t page_size, size_t total_size) +{ + struct { + off_t offset; + off_t len; + } cases[] = { + {0, 1}, + {0, page_size - 1}, + {0, page_size + 1}, + + {1, 1}, + {1, page_size - 1}, + {1, page_size}, + {1, page_size + 1}, + + {page_size, 1}, + {page_size, page_size - 1}, + {page_size, page_size + 1}, + }; + int ret; + int i; + + for (i = 0; i < ARRAY_SIZE(cases); i++) { + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, + cases[i].offset, cases[i].len); + TEST_ASSERT(ret == -1, + "fallocate(PUNCH_HOLE) with unaligned offset and/or size should fail"); + } +} + static void test_create_guest_memfd_invalid(struct kvm_vm *vm) { uint64_t valid_flags = 0; @@ -160,6 +191,7 @@ int main(int argc, char *argv[]) test_mmap(fd, page_size); test_file_size(fd, page_size, total_size); test_fallocate(fd, page_size, total_size); + test_fallocate_fail(fd, page_size, total_size); close(fd); } -- 2.25.1