Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3512989rdb; Wed, 13 Sep 2023 14:35:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQN2pYYsx/waXuSEwLdRx3IPbtbQrYONYaiYrLx+BVR2PeBFUTtt3LVWTRD0DiykJVVzlY X-Received: by 2002:a05:6a00:cc2:b0:68b:fb93:5b4e with SMTP id b2-20020a056a000cc200b0068bfb935b4emr3807921pfv.26.1694640913476; Wed, 13 Sep 2023 14:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694640913; cv=none; d=google.com; s=arc-20160816; b=ABO1z2Car6AGiMxpOWrifsafafzmNHaFk0iNG/LTpO1NnMEkXCZThqigkgYWDDIUnE 67HZe02CzFWn4314FZozAUay4T8oJzkV9bsnLtsziKzU8Pca2/J9wVys5un80Lzlt3HZ 6UUMVR+pOfK4amTu+ztgna7ii5CcrDxK0JylMnSP4g2sslmFtEqlyZ1KuUC814xHjQUo 4rB1aXD7x50T2WEZE2COmTAWztT/iRKbhQz74rRgfY8rdnQPcSjOCOCcQnYM8zhMo0R5 4lfxI2hYKSA2M3jpJO4N69Qu752lgJWMted77pQdCPl8Gq193cUNfTHQi0jRU+J2QRoi DafA== 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=TQ1/8LcHST8ZSxahmy6kgZMfLehjT1preFT6O6Z97xc=; fh=ANS6iRpdj3ntKSmwSzT4LEHUH9ZAudCj9zvP8/EeThQ=; b=b7X9RyBQc2KExizLvYM/dQDCU56b5ZDk8anyvWTgCSPJti1LHfk8ET1ZLyytBt4bWf 5OEvNzH8ZiepOUViqwQRH5usp/vzFhaZeYcx/HGW3Dr17icoODIR9N29h3FS30fDPJlM wpdMX8cUOkCFfpLYJGKKjiaFdrJRZJt2YtXka+TvUlOSmW2JZxaftFGRz7yryJt4uF7E HrMZ3fGJKGE5JF42hFp8Ty4pRQbzH7jV1to/RPrdIBpa6W7wFaD9sV86msVU4/nkrzRa JyyeB4g8K13qZs6y7YMGVbwWATTgz3sC5eHgPdcjwEkps77sl68XIiBBbPlnziwARUOk qXnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PRfT0uWn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b26-20020a6567da000000b00573fef93a87si5859513pgs.834.2023.09.13.14.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:35:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PRfT0uWn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 11AE881D80AA; Wed, 13 Sep 2023 03:49:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238068AbjIMKta (ORCPT + 99 others); Wed, 13 Sep 2023 06:49:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239734AbjIMKtR (ORCPT ); Wed, 13 Sep 2023 06:49:17 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E6019AF; Wed, 13 Sep 2023 03:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694602152; x=1726138152; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xwzNgHMxNVvtmveSbOCZiym0KA+uWinftiYSWsEC+Yk=; b=PRfT0uWndEFuxpeVjNZFHfLshIdp4OrlJYwm/d8i5B9k+BKzyzN5h0EZ +5d2VZdgP1zk6mLJ7cAflFJZzWHJTfFqlWIKMJPzihwBl4aJ/a52/G2pg eyKW6Lz3WOIf5Jci9HjnHy+ksbtSusSEgCPtnCB5bNz1fTnskVOm02zHJ UVxA62UC1ZNeijbGdIPGfPuxo66Pm1we6Cz8f8krpE7F6bBiU0nWu7UzF P+nd+CYILi0+imGTCNHSWSJO+XqvfXOeUE9vjY5ACo5FKkY4wZiN/mtTZ fjVkyb3LyeJHqP8CGt3qU4qp+80y72xya2iDP1xk6Q3ZAG+V+oS6SbeEf g==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="377537900" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="377537900" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 03:49:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="809635597" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="809635597" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 03:49:12 -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 5/6] KVM: selftests: Add selftest for guest_memfd() fibmap Date: Wed, 13 Sep 2023 03:48:54 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 03:49:34 -0700 (PDT) From: Isaku Yamahata Signed-off-by: Isaku Yamahata --- .../testing/selftests/kvm/guest_memfd_test.c | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index 4d2b110ab0d6..c20b4a14e9c7 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -10,6 +10,7 @@ #include "kvm_util_base.h" #include #include +#include #include #include #include @@ -91,6 +92,49 @@ 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_fibmap(int fd, size_t page_size, size_t total_size) +{ + int ret; + int b; + int i; + + /* Make while file unallocated as known initial state */ + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, + 0, total_size); + TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) at while file should succeed"); + + for (i = 0; i < total_size / page_size; i++) { + b = i; + ret = ioctl(fd, FIBMAP, &b); + if (ret == -EINVAL) { + print_skip("Set CONFIG_KVM_GENERIC_PRIVATE_MEM_BMAP=y. bmap test. "); + return; + } + TEST_ASSERT(!ret, "ioctl(FIBMAP) should succeed"); + TEST_ASSERT(!b, "ioctl(FIBMAP) should return zero 0x%x", b); + } + + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, page_size, page_size * 2); + TEST_ASSERT(!ret, "fallocate beginning at page_size should succeed"); + + for (i = 0; i < total_size / page_size; i++) { + b = i; + ret = ioctl(fd, FIBMAP, &b); + if (ret == -EINVAL) { + print_skip("Set CONFIG_KVM_GENERIC_PRIVATE_MEM_BMAP=y. bmap test. "); + return; + } + TEST_ASSERT(!ret, "ioctl(FIBMAP) should succeed"); + + if (i == 1 || i == 2) { + TEST_ASSERT(b, "ioctl(FIBMAP) should return non-zero 0x%x", b); + } else { + TEST_ASSERT(!b, "ioctl(FIBMAP) should return non-zero, 0x%x", b); + } + } + +} + static void test_create_guest_memfd_invalid(struct kvm_vm *vm) { uint64_t valid_flags = 0; @@ -158,6 +202,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_fibmap(fd, page_size, total_size); close(fd); } -- 2.25.1