From patchwork Thu Mar 16 00:30:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176852 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B014DC76195 for ; Thu, 16 Mar 2023 00:31:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3274B6B007D; Wed, 15 Mar 2023 20:31:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D8F66B007E; Wed, 15 Mar 2023 20:31:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C6A76B0080; Wed, 15 Mar 2023 20:31:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0A7026B007D for ; Wed, 15 Mar 2023 20:31:20 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CC1F6A039A for ; Thu, 16 Mar 2023 00:31:19 +0000 (UTC) X-FDA: 80572882278.16.464A273 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf17.hostedemail.com (Postfix) with ESMTP id 1F03F40010 for ; Thu, 16 Mar 2023 00:31:17 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=JJueoK7s; spf=pass (imf17.hostedemail.com: domain of 3VWMSZAsKCIwqs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3VWMSZAsKCIwqs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926678; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rreqZKmQJtCTOHmDtxKTKEfGS9dImrAo0RCl95Sk/EE=; b=b6mNMkcdH8/v5rNwdilWZOoZJFMOQA+xC4fm3GJAC2H46z7zJL+m+QK5R/nlP+3UlU80y/ CZgh/8Gn2lD1MdZoVuO2gMfH5ZNa6FuSUFVI2m6Iok2PoSupA8k2DfFBLNvXL9AkLXWS+e 2AcCUGuAbwbqapuVVlEX4l/AP2/FF7c= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=JJueoK7s; spf=pass (imf17.hostedemail.com: domain of 3VWMSZAsKCIwqs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3VWMSZAsKCIwqs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926678; a=rsa-sha256; cv=none; b=D0Zc2cZoS/mvDB86tymlj8CSWwtoyURrFpNDnpMmbkcxtiauEb+F8AOCAHRQAOlk7iatCD mvvOBYb+sJJyYJtWHXxAmctRenttqdUr88F5EvVUA3kymi+SA8wxvDFmIl6kbAEVehFxqs IeEdf6Pfz5ClJUboCX7h0AnMUnIXcRk= Received: by mail-yb1-f201.google.com with SMTP id e129-20020a251e87000000b00b56598237f5so94484ybe.16 for ; Wed, 15 Mar 2023 17:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926677; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rreqZKmQJtCTOHmDtxKTKEfGS9dImrAo0RCl95Sk/EE=; b=JJueoK7sdFHQHbdAl5nsqaNs4KCHm7sHzvLB42MnoY5lkfM6ZyYxqRBfJSJa8Yj0AO a2uaVznX+a7AGF4HtGGnVlQphXnV9jEi1nR4tPRumBxVDCE+WOnyJKaxZt8wQIJXoXkp loUdl05RrEtBxZJ1mxGOVb+Igf7OXAXS6g5lENKD5GhCbaaHIbFWr/+X13ZJvgEAeOrT ejL8r4WfIiMkFavlKyXDdwKqsnArh0+uyWf18MM3tbJLCmk8NSuRhA6hTr60P2bZx80K jj0hiuo3QlpYfzngCqcd5OQKvr0RQN1Z1ORNuOh1qFkI0/mHIDpESFq+n7v7NaT1lIXl wVMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926677; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rreqZKmQJtCTOHmDtxKTKEfGS9dImrAo0RCl95Sk/EE=; b=nrBkRP12Bi7VlyO9cbSl4NyH/ZIbmRLkrunO6CZqm0lO9tkvzXC3scatremfCWaxnw 6V0j3ZMAdjL/aR2nn10o6+zJqdtPVY95y5O+FVhCUV4cdW6VKDjpCvgKTDBVaMg58ANY JzaTHrLoLe3san4TjkcWT+Gi7waKAK6stw7Ia8hd2+cnCOL2LTL0PW5znkHHsoww7FM1 TUy/h6RoXveackJtAtBL782PXAo32bQHRGWaa+bgdRXF3CGHK0KY4X6pW5ZHUHfDCnqF JX4M9j6mQ4cLynjpKEBLy/HlEqthoetsjSmK9+zMLwi9W8/W4BtU9gk1L9C6qBtR6Ce0 Fyyg== X-Gm-Message-State: AO0yUKUobe4Y1bBgmUJAVaUiifPKd+uk59QxByvYDmftTl2EjRmZ+J6b TEu/P4RyC+hNPS5IKcr/SofFU2zAu1sn6ucYBA== X-Google-Smtp-Source: AK7set+ivCVtWOdQbcZQUI9O6fTh7qxu3KKcJWd7M8I6rNN0cLeTsP1prymLMADMTsLDtTPgMIN1PCmQzWdKXvBTyw== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a25:e201:0:b0:b2e:f387:b428 with SMTP id h1-20020a25e201000000b00b2ef387b428mr12671962ybe.5.1678926677076; Wed, 15 Mar 2023 17:31:17 -0700 (PDT) Date: Thu, 16 Mar 2023 00:30:54 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: <017a3f68ef7007d72f167f937fabd6d64efb9edc.1678926164.git.ackerleytng@google.com> Subject: [RFC PATCH 01/10] KVM: selftests: Test error message fixes for memfd_restricted selftests From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 6kuxkbwm9qrge3ufwhodzx1ikwz6w4nr X-Rspamd-Queue-Id: 1F03F40010 X-HE-Tag: 1678926677-70574 X-HE-Meta: U2FsdGVkX181iscyOha6l0EXPi33o0WKaWSKWnOAbEunFcUEq6zsI18CvI1YiLmka7QJamOCD7+ZZNMRd0tAaENJ9QnTi4bpKyJaCYfRJCNI7syDeP//qu7CpA2koyOeKE8i3TdvYpkkcS39nGgvmeCvk993qQEamb9EQEahL0QDQJalrNJ1rUhBJAYkYpGv8cFyv3QeMR00S0NcLwYmEntQV7xWCypi1+SmU2wcgqGc+xs1jSSpmaYKavPzFsafIl5QRgkZZv4tmUpr//FHNq+UuHRariRWOuquRG6S4+F4gWGHtIiN/LSRbqO7Oq95UaY2r8QMh2JHcQFAwCbQxrvriouxPE3L26MTHfZ3nyuwiIkVT+bnl1cTS6U2nFftYm9qR2hOMvcX1nMSEbJCLU3+FPKxHOrIAfnYyWPMdzF0dS8hZvcq7gW24pWwtHy/Z5zdEx1YS2Sge3l1NlFzEmTL/vJkoAXXuSGgOuOyun/FgsR4bABBhp5th3v4K4GhrqoTetdthMjoCME4b3YMOM90aeLFZh8jNS+z+LOjdCUxsWVgNMuQSgqSE2tUwzlbDvQUEeLziygFJcTueVn22qg8VAfzdFVEHuvJ4SToIlSy76+LSj5IVC4yzOdY2kxVLabdBEm/b9bJBgKin5HdcxknEBm8FFC5vbh8GBdDkjsjQj81GS9fcRAk+NSZ2k5PWXWjlW8Un7HiqlHdxhb+Iz8AJ1GsydCZbHmKAD5f1F9/85sKuUAuc9zRJvJkyZMHOSGjT6fIQA6T16N7NzJTBxnA+3OIbVWFAgdoAp4i7Qd1xIAl/tSqx3G+YC5xqsMWryp5GW0yU3MUBiXGxKLuEX8oS13Jb1OUhMQ8nbI4G7ZPSo8fn1DWYNtDS2NCXVaPSRAnIyenqEfbrEba8YFHTzfwf8/s1b21UaNEdQYO/kBigbI3HoTw1vUat4zMdPvF7zk+2w69iuLCfy/T0yR oh5wt7IV PWd8WMmTfTYXfisLXRtQ5xGApnwfA27nkvqEW0QywG4jrnEdmsbubXoLCk9Vd0d56ljvewpHWwHi3oaJBtmCmPa3FL2dKIaRgpatDDrk45PFBOUhqlSOGTb7o4UuKIvcxlSaSIAin2NDnfzngOfq5XAb3eN/hWlE34G24zICJWRWCU8tx/+yuII6mMdjotfie+bf9QuQ+oCfvHU7SGqEkVF0pMON9QJl+DmjTyGQyJj3JarGzS5kP3A9Hbumu17TH3zW/gNI07yL6Vn1IQmSoba+a41xBHkp8YZUFOsIT4DR3nSZ3OpQbPjz9hRxw50jv47oyy2sMZU3Acbqj8Px6pEdgP1FFgJEAbdghaal4ti8VfvCkVi2afeu9Pc6LukBqoHAvNItjQsVTN8VdVVD3/9GcdA65JP+NYHqqYRc2NC5eNgb317f4sDfzaC0LEJF9Is8aYX68CvbuHZFlxqCKSNDVmml5Yo04ppG1F+jtDY887I4KgICtIxxYRjg68KZFbWrMU8KkLfE2ytUfp5p57SKTsgoFp3DNzpJ7falHCRDqFJxBM1jB93BTGuR+egOPP1bZgteiR0H0NGi9dLP1UrsYf5yvISu90JPDC8cBGEY3cJGtPDHDTS7ulRIITxvwX4t11aJuVuYoBWSBr6nnaCxE13X5KgZyM9hW+bWqQylak19UyiiDB9imGvioCN0G8/E9lugis3uXPDbfghaAUvt6dGAQ+pUIvZXhSTM+oCs79Gw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Signed-off-by: Ackerley Tng --- tools/testing/selftests/vm/memfd_restricted.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/memfd_restricted.c b/tools/testing/selftests/vm/memfd_restricted.c index 3a556b570129..43a512f273f7 100644 --- a/tools/testing/selftests/vm/memfd_restricted.c +++ b/tools/testing/selftests/vm/memfd_restricted.c @@ -49,12 +49,12 @@ static void test_file_size(int fd) } if (sb.st_size != page_size) { - fail("unexpected file size after ftruncate"); + fail("unexpected file size after ftruncate\n"); return; } if (!ftruncate(fd, page_size * 2)) { - fail("unexpected ftruncate\n"); + fail("size of file cannot be changed once set\n"); return; } From patchwork Thu Mar 16 00:30:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78B29C7618B for ; Thu, 16 Mar 2023 00:31:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C8736B007E; Wed, 15 Mar 2023 20:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17A776B0080; Wed, 15 Mar 2023 20:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0401F6B0081; Wed, 15 Mar 2023 20:31:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E7CA46B007E for ; Wed, 15 Mar 2023 20:31:21 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A2DB312110E for ; Thu, 16 Mar 2023 00:31:21 +0000 (UTC) X-FDA: 80572882362.06.1E789CE Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf16.hostedemail.com (Postfix) with ESMTP id C2ECA18000E for ; Thu, 16 Mar 2023 00:31:19 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PAaXwSJq; spf=pass (imf16.hostedemail.com: domain of 3VmMSZAsKCI0rt1v82vFA4xx55x2v.t532z4BE-331Crt1.58x@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3VmMSZAsKCI0rt1v82vFA4xx55x2v.t532z4BE-331Crt1.58x@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926679; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vx2+K6b7VucsfYU5uvwShdem3MP0VCFQdKNh537WPsg=; b=hg1N9yO5lhDQDJVu4EHjp1dR3XnIZbMNJqFqO1XYN8WUVeJ/DXpepfbM4/BhOPoj6igiVu tm+9JLbZRxdWUJUKPujxxqpZNHOQWgn+92eGvnVPgwPEQmjIZzRBwuWl2ne84SZVp8zL7d h1FRQQgqr6oBu7Mmvj/1QeBUfG3AwSo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PAaXwSJq; spf=pass (imf16.hostedemail.com: domain of 3VmMSZAsKCI0rt1v82vFA4xx55x2v.t532z4BE-331Crt1.58x@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3VmMSZAsKCI0rt1v82vFA4xx55x2v.t532z4BE-331Crt1.58x@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926679; a=rsa-sha256; cv=none; b=sl9jE++hpA7u9gRm2LS6aoDcApzUvlo+MZdYJ+7X8iV5/Gfy0DlGKM0i3u5zhZvuHpv0WQ 2NatSqr9pwJ707VXNn/RAe/mcK6BCkOav9VU3T3Xyl/+5k4QfwhyOYfH9n5vGdgQ4jKcWV Dqd93p3jvts80bM97ytf3QXeYyiBgf4= Received: by mail-pj1-f73.google.com with SMTP id q24-20020a17090a2e1800b00237c37964d4so1704963pjd.8 for ; Wed, 15 Mar 2023 17:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926678; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vx2+K6b7VucsfYU5uvwShdem3MP0VCFQdKNh537WPsg=; b=PAaXwSJqPjUc6R/biIaCW2VNIfg9P921yoYdsBglXW7n/3lysnZkeEeswRZxCHBdd2 vae46IBUMuPrhA/m6sIKIzqdGOnQo5Ax7q3XOoZhIMO7H4xC0VbFQ0N3vE+qhGQUMHzu kPA+f6sp7rqp+TQqvoN2RVgjN8fnA/s8vq6Qc0ND26uA1J32QTIzKCh5QE6EZ2HKVyvQ j5NA1EYtTCtaS4iuVqchmK8CE1Gi+C6RcXJmBHwvadsPdAFJPwZbs86of6yw4m2yRstH qut3sHXQ3PqToSUKXfBRc1s9T+WqYiB5itYUbgh+khi4BVYb6F2EdusOJNoVl2aI0MUq SNww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926678; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vx2+K6b7VucsfYU5uvwShdem3MP0VCFQdKNh537WPsg=; b=i7eCQVM2gxVrTlHCyk6a8sLDa/r7tG/IhvmCOBhmwiJDszf/+uTZR/RRV5Du2Xr2Gu wCSUlIX/slEoZ92Yx1Fpq94ae0kH5BZLnKuaQaRcN67xyevoFtD9NqUQ5l25bFgQUO8A T4WGm0TdPLy7EIuqoePG1xZQzeoj/iAXRXGUa1RIa1NNMhGFC9sRReM2hwjQjjiVCeRm zxWPm6IPgDKDX6PcbOCTnoYJd7xxuHTgc/mIXexo/mc2JGY8tD8fnAORWMhFjSCZ/lff iBKwG8rcD8hXhmUEEIpaw9tF/09CNE0tISODDeQAQ2c1AWkRPUG3a6G1Cj17/JSghxmp QY0Q== X-Gm-Message-State: AO0yUKU+liaXvQLs4jRgicnP/oY3/u+703HT5/AjfJqOg+4yRaTLbHqF QuGfEhOJY2+KLb32WdwrGog0xCo8zr2Qg6t14A== X-Google-Smtp-Source: AK7set8pxVyKhYzeYJbLh/hwRd4Uu3vEs7a87hlm2FvbWgBf9tOHOVoa9Y6GzuIXe4LVFtgGHHuaVLgOE52DzxfEww== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a05:6a00:23d6:b0:625:cf6d:b272 with SMTP id g22-20020a056a0023d600b00625cf6db272mr580538pfc.6.1678926678685; Wed, 15 Mar 2023 17:31:18 -0700 (PDT) Date: Thu, 16 Mar 2023 00:30:55 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: <75eba82a2666b0caa96ed0484a713037045ed114.1678926164.git.ackerleytng@google.com> Subject: [RFC PATCH 02/10] KVM: selftests: Test that ftruncate to non-page-aligned size on a restrictedmem fd should fail From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C2ECA18000E X-Rspam-User: X-Stat-Signature: 9bmjwdtg16cri1jzbgbgn84xd8x51u1k X-HE-Tag: 1678926679-898716 X-HE-Meta: U2FsdGVkX1+MDwVW5BKEuZRWbyR6CA1OXe4qackxlknvZigDpSltq/h4EeI8KIy04m97UIPZTVJrNYRv2pVz0MAXH/Du2MZXgUwJTfvvHBMc5QIRuduh6Djb4Q0wX4PZprmjceTYIqQbxkRsuFgKHypqKyLTEKW+M3bbiiDuNQuV9wXwjRFsC7blNT97s6zghchBsFAJAqagb/lXu3TXhSGA4V/9PVHgSDi9YAHYf6dEgLrQyqa8oMb5LSppMoD2eOSvogC4Y6Qj3eNOaurPL12asjEON6AkyJIyR+4HHYY6Pd7gJ6VVGGBfBahxQiz37wEypl7vUqfnOoiaCjHE/XZUS+9/CUKHovFzqLRlXWnHVO3RpxfNKQPFPvrGGnqhbkj5yrHAZjuT79ppmpCFJ9OsAP9F2yie6CheOCgUP3UrU/9qVSrll8tX5sVarqvtYAvfrhssqA4wAgb0ijGJJyLmr9MlGWaPt07HzxbwxeYfq85BsS10FQFf1TFi/4XD5ne8ggLL5cLkhS9XK8ifcg4Dkh0/ZWICedD5QSPBV1gbpnpvRc9wJu0oOk1sSeuI2hBAqVmEjDlqe/F1FmluXK1Mc8HY38kw42+TjuDlPXNuZGmw+GuqG9GDei+xvPRm8EaCo1mvkun/Tj5re1RojYIyW4nYb3GP8g/JOfOfN9cRC1GXy3pT8wU6nK/gYjKQhhRaj0M1oBrAB4KZYVJlaIqz3C4DZ7jkrOH8wp3q61HIAYEcRF178pqjv2uYgwkRCNYnDNlaupftql9HWB7MA/kLPaCaE93nmPpJdApQSveUjwhpRlnIa+9Wd6oTgY7Zo76odklkDPzwjJVmTw8S0thu44MLw3iDXgVNre0SWNtrBCUqBwbPkGq1kBgW4oqdZ87CUiMv6lYSUBR2w/H1/dU5kI8MoPLTkRAjKXFXqwrJNJ/OhzWDcNzgHNS27PR8TC8QX9xZCfhW7YrrgTZ UVJS1aeL M/1hmF7giC1JVnYOBL4GorTy7pMH/9Pk0ajqzJlNfc0ol+Esnp8vosZlRIw3RoG6ykiYHsIZzpC2fGpxeyt9bKiLvIeWETJObS27F9qTfgFcYKAFIsuA/efTDxQzhg4rsaHNiiWwQJIcXM1H5usj06mwMovTCJUu4Ma4xCTwIoulm86JriTVVPJgRKEQnwqu/iWYuJky5lNe+wiamojdDLuljZ6YBsE6P5n0+2JHZxjwyqbOVpqETsJOoFiPKX9AJvyUGgVPUFxOb3mC4YjKQqmsrvV2bJOtrOYOX3dE9w8MzyIdJ+FHxCK5els+GFYbP7iBbxT0/mPEcyaczleUn2dOscOdx4kCvoWP1Oprm8aWOZQFkZ1o5aULd+PiVHB+ZThP0t4SV4dIrBTdTUbyVMIydSfMBQd6q1jxczqjgw1XYSjOz/k/EMGs7fNAzsxycJ3Z2L/L1Ct6jvcvFAKj9u+A7EvcHYn6OEIt0LOyg5f2hfKw449N1b9zgGjqaYUjsr2bJkdPPRPQAg5fP+DPqOadXoNU4hqpAfTBTpEEWgIp3ywMLdnH35Vnjr7bAupMF01ES9G4+f3RQ0LgzCT0iD1of2rK+AcsLhodQWusxErE82bRUM/aQqSUh0UKjVA7RuFbunxjxus6a4VWWKQXmW1XU/9SFf/OY3tX1SHNuG9z+/1a01d5KeIhcoQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Signed-off-by: Ackerley Tng --- tools/testing/selftests/vm/memfd_restricted.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/vm/memfd_restricted.c b/tools/testing/selftests/vm/memfd_restricted.c index 43a512f273f7..9c4e6a0becbc 100644 --- a/tools/testing/selftests/vm/memfd_restricted.c +++ b/tools/testing/selftests/vm/memfd_restricted.c @@ -38,6 +38,11 @@ static void test_file_size(int fd) { struct stat sb; + if (!ftruncate(fd, page_size + 1)) { + fail("ftruncate to non page-aligned sizes should fail\n"); + return; + } + if (ftruncate(fd, page_size)) { fail("ftruncate failed\n"); return; From patchwork Thu Mar 16 00:30:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176854 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 197F2C61DA4 for ; Thu, 16 Mar 2023 00:31:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACA4E6B0080; Wed, 15 Mar 2023 20:31:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A523C6B0081; Wed, 15 Mar 2023 20:31:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A41A6B0082; Wed, 15 Mar 2023 20:31:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7A9786B0080 for ; Wed, 15 Mar 2023 20:31:23 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3BEC2C0A41 for ; Thu, 16 Mar 2023 00:31:23 +0000 (UTC) X-FDA: 80572882446.15.E4A65CB Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf27.hostedemail.com (Postfix) with ESMTP id 66D7F40017 for ; Thu, 16 Mar 2023 00:31:21 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=XWGmJ9JA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3WGMSZAsKCI8tv3xA4xHC6zz77z4x.v75416DG-553Etv3.7Az@flex--ackerleytng.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3WGMSZAsKCI8tv3xA4xHC6zz77z4x.v75416DG-553Etv3.7Az@flex--ackerleytng.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926681; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JjmIOJvjUEG2+4aovgmSBlRBGRP0JRLKbOkhR3o7e/I=; b=kaUMBePRxQGPh9zvMgMtGAQy/HIAckwC8Rdrt2esoQ5pJwq73fmCp/hQdsZgb1G28eoAE2 ESFOpyfgd1Zcvvga1aOalFU+8aqdHD/QaGovWpnqNOqMUo5pqeNW11u/KzyG7Z3xxCma0s rqCKUi0vcVFEdujQZ9J32R578f0FztA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=XWGmJ9JA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3WGMSZAsKCI8tv3xA4xHC6zz77z4x.v75416DG-553Etv3.7Az@flex--ackerleytng.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3WGMSZAsKCI8tv3xA4xHC6zz77z4x.v75416DG-553Etv3.7Az@flex--ackerleytng.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926681; a=rsa-sha256; cv=none; b=x2qd5TgHChtC9+ivr2yaiQZe0O7Ach+jkz0v38VpHDVo2Nb+6dwzG/HyKMsK+eW56+BZui cWJC3joycIcgWW+bTAz0a18t/HmrQuwjJjSREyQ9k266XThDngA9B3Dwf3Bna+C5aRIWwZ W0hMGhIl5OSb4EoHls9rBO7MaT8mVWU= Received: by mail-pf1-f202.google.com with SMTP id p39-20020a056a0026e700b0062315c420d6so161705pfw.21 for ; Wed, 15 Mar 2023 17:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926680; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JjmIOJvjUEG2+4aovgmSBlRBGRP0JRLKbOkhR3o7e/I=; b=XWGmJ9JAs9QizM49LznB/3WeGWT9Pc+PU89wCd8j/FUtVE5mMn/ax/bL088f1qtOz1 RFmCWBaiH29nU9Rm1KEJYwwbJN+AkVaHOxnJG89ZrDJuTFkTNXO5WvuZG2ISNDllw0uo fSjaUkPVuesviWcTzk98UxYatwmpd417x6c+02nHUCPhFRDc3jObfLW3h3zTrxlqgUMt LSd6LeHzPnNB0IV8pPZgCTjW0bYxKCuKc0IBsjiwto4vhAFiBAjpHsDO9Qt092Ms2tAr DgVpYe+MAJleDmnTkKW5CLiYIwwbNbMGX4Gf9ND5AcxA8F5WN4Z2xDh5NS+5PrMXSWp9 XSmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926680; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JjmIOJvjUEG2+4aovgmSBlRBGRP0JRLKbOkhR3o7e/I=; b=w1i/qDQ4l/qqU7kzluZ0lvlHU8QNLZuL0QaIBVuBmqQl1MHdZ39rRePygUuJZrNkwF PKFeW6Oq82ixHEoWu4CtwcK7krRvrIhEncKAMcjnPzUa7nudIXOwSKtHqNtKnehMudbJ wqwYSlUrYvMk7YA29lYW77JGTA7ZOBvr+F4DFR05ZVKEOOlzLS+doCJeVwYh2t2uhqpk 7ohvp2fAqvHP/Js5dCgG2wyoMlS6EHH7TfX3epEdWJCfVcPhGbKmp1sNVNVMifboPp2G UWLr/R5hlq9eigwOYYUN6touZQmdU1y8qWSIwsCCtOOmflfyFQnQ+XPsBndcgDSQpvP3 pblg== X-Gm-Message-State: AO0yUKVfv/teAVoo5NQNckiIz+FP2TqJWbbmkj14Zd43JY2cbco+FZ6W yH3MGw733MYOG4RApiotnEkwXngZ+h6XLI0aCQ== X-Google-Smtp-Source: AK7set+j36PrTQ1uWKwZ/ZTMviUfrC3nfQJHH3bSUBCARqM/YyB/PYWAqeXRAUTM8xOy7rllnybTZtBO0uvKhOtP8A== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a17:902:e5cb:b0:1a0:4346:d43e with SMTP id u11-20020a170902e5cb00b001a04346d43emr595748plf.11.1678926680301; Wed, 15 Mar 2023 17:31:20 -0700 (PDT) Date: Thu, 16 Mar 2023 00:30:56 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: <48490641ce981c31ea58c11ad478ff85cd0dd156.1678926164.git.ackerleytng@google.com> Subject: [RFC PATCH 03/10] KVM: selftests: Test that VM private memory should not be readable from host From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspamd-Queue-Id: 66D7F40017 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: fyeof64icftn9qhqtx3y8mwfb74fedwc X-HE-Tag: 1678926681-995022 X-HE-Meta: U2FsdGVkX18s2eY1Lcqqe3cFKzvJdE0nWiSu8OrlTgBsQK0KrsCSBXvz3rGwtIQBD5dcUTFRKc3CviLDuUP/FYgDlPGXEJKI3imMLa8Dngx+ClthkuwT7dqzAGQ1gowtVG/vcfh1N/CT22sEMO6Z60wytXhIhjmoZI5DdMwJqqEItRRhl9i1MH0xo+I1EVVerfMd+pUOraPvOfHEvt9qCZY7XRVSkcvPRYuvtALsryPsrQxLKjr1VLOkq96Im1UVd6OeI8aiF2KbN+k3nlJze5HMbP5apvdP7uLpbW8R3lg1BAlXX/1oQnzG+NI6wcpcXk/exm5M3sb0b9xKm92PPTiNlk5OEM5GDTupgtZKQoeJKXnMQQL0HslzAzmo8yR528IPo3wd1O0H3/pzPJHbU2vXH4cpo9jFUlNDeccbPCNIccEWZWi1XM4TnwWqlrJhsV5R7PUVxaNlTRicYa0cjbUdFgrPEkVuEiRqp0dysXBn+W2t/k5mG8HtEtnRaCqLGo93mtlFxTjMUdQRywA2QQ1KWTTXRrnqm5zof3p54+uBJyKisf2dalmncZiHgXB1wdfew6Zc1zNV1bVF+T0Xv4AbNtsHWi2HGGsygrejqy8dzYpadi2RD0vkKoR68db7r04qnSjFFiwd3PaRhJUuoqcOa6rTDPrDP7pkB0XXK05J2cvQkBQb3gNo/SMbePIiHIHNOFLjxzQEKKq4FD10WjD9zK1zpa3L32YC84woUG9RnMrWMeVBjXGMKBD/JBKHaFL7PqtnxqnLc7VKW31a4mN17B8pLJfIsvWiCxAIF4chPfJcd//QEbrCRJ8u9Ac7ZiKqS2T0YujU3IW8C+0OelGWQfiQ9s4lxB8AAaCavgHtFrpsKhCHZPYOFBBkmTA8hHrPlS6CRxlJHPN6UBY4Enj670bB6BXGKR0/vYCdcAYlgbqwSammfnBqGi7oDtJHWmFK40USH7PYv1VjPVU /ZYTir2h /CM/RvxrgAzyInu7vZd3GwX7ECQUUEzDacUvrU8nQadRu292p3jVpk3NDi8aSJZCZ7hCjxywM0fEPOfkGFV3H+6wBEfmyBjzXzEdVAOmVZmVbOl19wKOARL22aUOUz3VO9o3QgzTtRrWXhJsD4zoyQix1X2931c4jhj9jqztXGmtSTNIO9xRE5AMcgIlKF1mNg01dbNiKpS4GFwYMPoz7t9rjCiT8HQ9p6eRFa31S15ySCtUFTfY0lAPHyDy1Va1NupnEz84LOrGKJM5xbSIPWpNs1eHtNH6+3Z3sHQyPwQ0SOJg+SIxIFybVIRQDlAESi9lIQOUqZMCJgiEh0iL0YeKYDHZt7y/FJ5mSo8XDHVWYZ1IlnuH1lIcxy7S0dKyoVy/PhLWnmRBej3S7jNlOFD38QWY/GKoWOAOe8TtqALW0vjljbqEhLoHrx0IQofmtkoC7O/BMFaZ+vft7rbmVSgVcgqpJjpYkYi4h4dJwcpi+DboxOtAWfObcXjQ0Hc51HjKlxJgoGeJf8a+HsNwCEwNH7YPEFWb/jb0vktLh+ZVH1LPd+pFogOsp9CUWR302GE/h X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: After VM memory is remapped as private memory and guest has written to private memory, request the host to read the corresponding hva for that private memory. The host should not be able to read the value in private memory. This selftest shows that private memory contents of the guest are not accessible to host userspace via the HVA. Signed-off-by: Ackerley Tng --- .../kvm/x86_64/private_mem_conversions_test.c | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c index ef9894340a2b..f2c1e4450b0e 100644 --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c @@ -47,6 +47,16 @@ static void memcmp_h(uint8_t *mem, uint8_t pattern, size_t size) pattern, i, mem[i]); } +static void memcmp_ne_h(uint8_t *mem, uint8_t pattern, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) + TEST_ASSERT(mem[i] != pattern, + "Expected not to find 0x%x at offset %lu but got 0x%x", + pattern, i, mem[i]); +} + /* * Run memory conversion tests with explicit conversion: * Execute KVM hypercall to map/unmap gpa range which will cause userspace exit @@ -64,8 +74,14 @@ static void memcmp_h(uint8_t *mem, uint8_t pattern, size_t size) #define GUEST_STAGE(o, s) { .offset = o, .size = s } -#define GUEST_SYNC4(gpa, size, current_pattern, new_pattern) \ - ucall(UCALL_SYNC, 4, gpa, size, current_pattern, new_pattern) +#define UCALL_RW_SHARED (0xca11 - 0) +#define UCALL_R_PRIVATE (0xca11 - 1) + +#define REQUEST_HOST_RW_SHARED(gpa, size, current_pattern, new_pattern) \ + ucall(UCALL_RW_SHARED, 4, gpa, size, current_pattern, new_pattern) + +#define REQUEST_HOST_R_PRIVATE(gpa, size, expected_pattern) \ + ucall(UCALL_R_PRIVATE, 3, gpa, size, expected_pattern) static void guest_code(void) { @@ -86,7 +102,7 @@ static void guest_code(void) /* Memory should be shared by default. */ memset((void *)DATA_GPA, ~init_p, DATA_SIZE); - GUEST_SYNC4(DATA_GPA, DATA_SIZE, ~init_p, init_p); + REQUEST_HOST_RW_SHARED(DATA_GPA, DATA_SIZE, ~init_p, init_p); memcmp_g(DATA_GPA, init_p, DATA_SIZE); for (i = 0; i < ARRAY_SIZE(stages); i++) { @@ -113,6 +129,12 @@ static void guest_code(void) kvm_hypercall_map_private(gpa, size); memset((void *)gpa, p2, size); + /* + * Host should not be able to read the values written to private + * memory + */ + REQUEST_HOST_R_PRIVATE(gpa, size, p2); + /* * Verify that the private memory was set to pattern two, and * that shared memory still holds the initial pattern. @@ -133,11 +155,20 @@ static void guest_code(void) continue; kvm_hypercall_map_shared(gpa + j, PAGE_SIZE); - GUEST_SYNC4(gpa + j, PAGE_SIZE, p1, p3); + REQUEST_HOST_RW_SHARED(gpa + j, PAGE_SIZE, p1, p3); memcmp_g(gpa + j, p3, PAGE_SIZE); } + /* + * Even-number pages are still mapped as private, host should + * not be able to read those values. + */ + for (j = 0; j < size; j += PAGE_SIZE) { + if (!((j >> PAGE_SHIFT) & 1)) + REQUEST_HOST_R_PRIVATE(gpa + j, PAGE_SIZE, p2); + } + /* * Convert the entire region back to shared, explicitly write * pattern three to fill in the even-number frames before @@ -145,7 +176,7 @@ static void guest_code(void) */ kvm_hypercall_map_shared(gpa, size); memset((void *)gpa, p3, size); - GUEST_SYNC4(gpa, size, p3, p4); + REQUEST_HOST_RW_SHARED(gpa, size, p3, p4); memcmp_g(gpa, p4, size); /* Reset the shared memory back to the initial pattern. */ @@ -209,7 +240,18 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type) switch (get_ucall(vcpu, &uc)) { case UCALL_ABORT: REPORT_GUEST_ASSERT_4(uc, "%lx %lx %lx %lx"); - case UCALL_SYNC: { + case UCALL_R_PRIVATE: { + uint8_t *hva = addr_gpa2hva(vm, uc.args[0]); + uint64_t size = uc.args[1]; + + /* + * Try to read hva for private gpa from host, should not + * be able to read private data + */ + memcmp_ne_h(hva, uc.args[2], size); + break; + } + case UCALL_RW_SHARED: { uint8_t *hva = addr_gpa2hva(vm, uc.args[0]); uint64_t size = uc.args[1]; From patchwork Thu Mar 16 00:30:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAF56C7618B for ; Thu, 16 Mar 2023 00:31:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D62216B0082; Wed, 15 Mar 2023 20:31:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9B816B0083; Wed, 15 Mar 2023 20:31:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC8526B0085; Wed, 15 Mar 2023 20:31:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9A7736B0082 for ; Wed, 15 Mar 2023 20:31:24 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6E74A120AF2 for ; Thu, 16 Mar 2023 00:31:24 +0000 (UTC) X-FDA: 80572882488.09.A08C062 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf05.hostedemail.com (Postfix) with ESMTP id ABF81100007 for ; Thu, 16 Mar 2023 00:31:22 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DFkZM4Wx; spf=pass (imf05.hostedemail.com: domain of 3WWMSZAsKCJAuw4yB5yID7008805y.w86527EH-664Fuw4.8B0@flex--ackerleytng.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3WWMSZAsKCJAuw4yB5yID7008805y.w86527EH-664Fuw4.8B0@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926682; a=rsa-sha256; cv=none; b=08ViQWfxaLMcE4bnD2SfdIaeBcN0nYWZPTG5ACGGCAVMfKzq6hnDtRZMTTcmzQyuGf4rQ7 PS1QfHivJo1Gwy7v+iZbBpdvfutYATqjnttinawMeRPCEaNOHY9bz2RXSOwSDZZOMx5cqW lg2r3+xMF1ifumudlJuifQ6VxjmDAuw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DFkZM4Wx; spf=pass (imf05.hostedemail.com: domain of 3WWMSZAsKCJAuw4yB5yID7008805y.w86527EH-664Fuw4.8B0@flex--ackerleytng.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3WWMSZAsKCJAuw4yB5yID7008805y.w86527EH-664Fuw4.8B0@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926682; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/WhAZz5TZYbz5eACM2xmX0O35zR+4WA+K6fPnqmTdp0=; b=3Ji0N//Y00NhFWsV+CX6dYOGHhEEtJogQ3/3RKKqk4MV367RT/5oT3lKACtPwOR97+Q5+i qJmNZBpx4hrmNEmDl4iTVJMNTTJi/hh+bFiNjzANNyKTD8t9E2VZXIevCGj6GVQea2ED3/ aj2uEclNo1TOUx1u6ddwn1M6xQLJPgs= Received: by mail-yb1-f202.google.com with SMTP id m6-20020a056902118600b00aeb1e3dbd1bso110753ybu.9 for ; Wed, 15 Mar 2023 17:31:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926682; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/WhAZz5TZYbz5eACM2xmX0O35zR+4WA+K6fPnqmTdp0=; b=DFkZM4WxAkVVNIJBuBzB0nwyIoWMqXfdjlRk3WXV6Jxw5x54jqdNlx617tRGFPhNbf FSFEhLgx9YrnXMD2N9F3ND0dGS2wEQLQ6W2DinnGY36gb1WqdxpuV00Tng2C80Dv85bd GGCXZZnPgvalLdYHdJ5gJafblCxeiqDbyy5BB57SEGPtzpj8zUdhi4l6LoIgVVGg05nZ 6Mo31eLAizgeZ7625k2PZoVDucHfhEkPNcn7OmHS1vFJrTg1pI8T6QFyePo8eh9L2ANf ioVmITbi3yeESUanrzgTRmSVNxGVFuNzX/w7x5gA4sylAMhIN1UM2xnxuIntZGawA78b lh/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926682; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/WhAZz5TZYbz5eACM2xmX0O35zR+4WA+K6fPnqmTdp0=; b=61prnM49cF28ieZ5bFCD70SvaO5LxE6O2EQoOyp6ugVJKwXCX9EuOvvz1MgLyCukGj E04Dgs8/ZG4U+2FEDlGsbcBaqq5VO4q8BEabmq2lZu4Sf9HC6H42dvgtQOVsIPMc8rN6 9uK/AjmyR1HeVelQXwFqvwfgmroDLlkHBc0Mpr7RHLpMfm+YyQntbVQutNa7TTpwoLht PJZAHi7ntzItdAxpO9aNMqo3gG3cPrVR9XATzwla5dMsQr3zJyTMOrlDaOMrvqqQfkZk e08zdH/S6PLt3vmFE476t95nCwJqf18jalQ4JVNwesMY4F0UNL1i1MS9U4az1H9Os4qN KKZA== X-Gm-Message-State: AO0yUKW3/SQcrPupEGOTri6Oy45YndbWZ1Rcn82uLrWBeHuIReSMMZxM iiFNxPOMw070hJXLdgfVyhUlkG9kxpe6A8jb/A== X-Google-Smtp-Source: AK7set9tsl6JIRx5mbMVZPA/DONTxMkHWtMyPLSYdDprwtuWdlOsvzYeVaLj2tQwnFWT9YsS5B+6yQbk5CSUogkZdg== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a25:8b08:0:b0:b14:91e:4d19 with SMTP id i8-20020a258b08000000b00b14091e4d19mr20688255ybl.7.1678926681818; Wed, 15 Mar 2023 17:31:21 -0700 (PDT) Date: Thu, 16 Mar 2023 00:30:57 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: Subject: [RFC PATCH 04/10] KVM: selftests: Exercise restrictedmem allocation and truncation code after KVM invalidation code has been unbound From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspam-User: X-Rspamd-Queue-Id: ABF81100007 X-Rspamd-Server: rspam01 X-Stat-Signature: 3fjbsugbr6pmeqoscro8d34q5thcsytq X-HE-Tag: 1678926682-565459 X-HE-Meta: U2FsdGVkX1+8XAuZJ7x0s/zDNtlMlAWy5ss3yj6kX2VM7a2UkR1D1XAiXySfvkx51oUN8AY87ZNUFvVPg50x6JirylSEB+QVrGY4GJ/PFma2mkgg+gGbv8F2x7V8vIf4MIqetcGGdW+MgRIeJ3WcN1AbrCxe35BGt8hfkF+OlMdHIxx7YKCjeYNI7ZSstEQNOqR1kDuOtu14fChVZLKIn3zXLpWe5CnU5XgYx4kVtD7fGh3IZjae+OFLgJeMAq2U0xJcr28/IN4Crk6VLxyVzpBfo8v04SbgkSkHL3BEYFHInIiPust703KAsCRisRddLEOejMRsXGesLQN9F+OroFHOtBCFesYcGe5LWWZHNiPHbhreXdy4onbl17pNI/TJHu0swGMEiw0H5mvCScZUVwgh46eWhi+brAvKJHAJ5SMZJpI3FZvUmDp0Ccgok8JyCkuBNG7lsXXiDqaW5aDUgLQOeNFOy+Wf0TCIi7Xly1gXuUXfhxP1GUHOsVxmxuCbsOciVkdKQ8l8sMalCtA98QRKkVK0WFlDFya48XwjWnDZS5xH7AnpjSIvf/Xs7CRbs9Hzhg937soI7F14ZSucDvcln3yRyicb6QJc5sUtNHgByNP9W1c+/6MEZqFLIeNmn6eLWPQWOr1+N6DGt8xsPWYWMnA35jyOnV6ADjaIgHghMvGtCygDk1PHfdig5dPoXtlREjx6zYb3lWVwrDFCZo6vp5h2Q4hSPs/Qm0aPTypVCbUU2HsiES6+NRP4d97TY9HItHH21OqKGGmQNkwOubf/6Ssw+/5AABlTgTuW9JZtMYTxNP8AXEJ5f1XWhK+kp68/cKmrCPEKBOXILvSmsTvVpu5r3tB+uCWbzSK0v+bmcB5FU1NofksxoymFtHTQHIInYR13AUWRjoPrVNZ+YLs3J7/UTWOORoXRbXk0F3kCsJWBl9US/fAv8NGXMh9Ymtf+W8oED+NTly6Cd0e Fyee87yT idbEFjVK/Ja7VTMTw5LlrpoJdntA4Hw5nqMmEygE3etIQqlN6xz+qwvVo3AyrOBGSGfrB2cwqTdtg6Re0VhfFAb5y9gvRZYVrvM71dZl0OtJItwXolZcmUPEHTe144wd4H0s+xK/7UmbR0OCiPHLn3BhyxM7Sa2/hRN8QQVGKkIEs1k0YNhStxEUCcNuMZ4Nho7Ngf69e8iOaIeIwtbM2uxmzmeRSpoRbgfLaK8LvW/5IW7yzGsrMVbiVBq7wtvLqS14AObSneLuNbUdlNdHianQqJh6cXtgL7NP/+OjchVh8mST1+Q/p/FfFnJvI5o9DUJmwnhRoIR8DO1aPKKwGp2vxES/bCd0AQORO6NbFF+VhFqexXBZnnjT54o6Lv3AuvJsVhZt7rBvTTCz/hVTLf90zVKCqXHTnJxvmcH5E15u/+PMHSoTrnOckY4ymY6km+ea2r92KkUrz6w0YO9kWx2/fkNTPrJx29a2unv8qK62zUPFf9iRQoZ7Jdfc6XM15mgaxU4uG2cuohGL+kP+8spI4clw2BebOnjHpA0ysLZt93w4Ne0hIGU7slGkkbJpg0fvR7adrTpv46GydS1GQKYIzesPF5WD1Nc1psgYZQVHmokQ+6Rkv+PPAMi6mGHFiNdwwOrJC9N3DPMIjLlfLOYgeJQwl6lNVu9+I X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The kernel interfaces restrictedmem_bind and restrictedmem_unbind are used by KVM to bind/unbind kvm functions to restrictedmem's invalidate_start and invalidate_end callbacks. After the KVM VM is freed, the KVM functions should have been unbound from the restrictedmem_fd's callbacks. In this test, we exercise fallocate to back and unback memory using the restrictedmem fd, and we expect no problems (crashes) after the KVM functions have been unbound. Signed-off-by: Ackerley Tng --- .../kvm/x86_64/private_mem_conversions_test.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c index f2c1e4450b0e..7741916818db 100644 --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c @@ -203,6 +203,30 @@ static void handle_exit_hypercall(struct kvm_vcpu *vcpu) run->hypercall.ret = 0; } +static void test_invalidation_code_unbound(struct kvm_vm *vm) +{ + uint32_t fd; + uint64_t offset; + struct userspace_mem_region *region; + + region = memslot2region(vm, DATA_SLOT); + fd = region->region.restrictedmem_fd; + offset = region->region.restrictedmem_offset; + + kvm_vm_free(vm); + + /* + * At this point the KVM invalidation code should have been unbound from + * the vm. We do allocation and truncation to exercise the restrictedmem + * code. There should be no issues after the unbinding happens. + */ + if (fallocate(fd, 0, offset, DATA_SIZE)) + TEST_FAIL("Unexpected error in fallocate"); + if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + offset, DATA_SIZE)) + TEST_FAIL("Unexpected error in fallocate"); +} + static void test_mem_conversions(enum vm_mem_backing_src_type src_type) { struct kvm_vcpu *vcpu; @@ -270,7 +294,7 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type) } done: - kvm_vm_free(vm); + test_invalidation_code_unbound(vm); } int main(int argc, char *argv[]) From patchwork Thu Mar 16 00:30:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD6A4C6FD1D for ; Thu, 16 Mar 2023 00:31:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7ACE6B0085; Wed, 15 Mar 2023 20:31:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2BC76B0087; Wed, 15 Mar 2023 20:31:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87E676B0088; Wed, 15 Mar 2023 20:31:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7978F6B0085 for ; Wed, 15 Mar 2023 20:31:26 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 48DB181379 for ; Thu, 16 Mar 2023 00:31:26 +0000 (UTC) X-FDA: 80572882572.23.A227298 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 5F58E40005 for ; Thu, 16 Mar 2023 00:31:24 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=auUqsxuf; spf=pass (imf01.hostedemail.com: domain of 3W2MSZAsKCJIwy60D70KF922AA270.yA8749GJ-886Hwy6.AD2@flex--ackerleytng.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3W2MSZAsKCJIwy60D70KF922AA270.yA8749GJ-886Hwy6.AD2@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926684; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QTeAQsqCeHYohT1+z6QROKS290DmjN4VP9f8cpdpaL8=; b=2G2+npCASwo1w84zjF4+w2Q8WkC9bfNB7fAYDiYPb++1cWkRYlhVj7yThJDxXqxd10veZ1 +4ZiAld+Ch0AxnFS2DKk4zTXLWHtlN5plW5PPyPyZL03saP6ry+OqnvIT6U7y7BxL1Ew2E HIUJEgP7UQRysURgMW8kYvRGsPm0vzQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=auUqsxuf; spf=pass (imf01.hostedemail.com: domain of 3W2MSZAsKCJIwy60D70KF922AA270.yA8749GJ-886Hwy6.AD2@flex--ackerleytng.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3W2MSZAsKCJIwy60D70KF922AA270.yA8749GJ-886Hwy6.AD2@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926684; a=rsa-sha256; cv=none; b=qt8NXd/2acmOdNMANuso/2nJYjWgcmHI+Fn1GnWISXkz1L+Gori+bpIN4UK1vFKOmVYEQ0 0Il9IiZo8z0CKvG9G4l5IcGr62A9BHHRZxkOvvLTQWUl97Ud5lFgEzMipQZ4uA6QXgZ5/s 5qOlSkF1PMnBv7doq9srrUvlfeX49aI= Received: by mail-yb1-f202.google.com with SMTP id t25-20020a252d19000000b00b341ad1b626so86351ybt.19 for ; Wed, 15 Mar 2023 17:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926683; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QTeAQsqCeHYohT1+z6QROKS290DmjN4VP9f8cpdpaL8=; b=auUqsxufnhZazK80BuGYrUuT5xQy0nKByTHsDVa5nQ8ggWedTTVRL+DG5jMn5NcxdQ 9zKUsKBxbo+88C8lp499Nf5DzFL8iXzFzdAJ86nKvZqnnh/lTpcH6nmuB0r+XxVUCw1B tWxQxyfQ1qbw8+rrtFLmZAs8p0Ck8ha4gQgZVZNu5KU3Thh3AQojPLOynQtyjzv1FzSr Kq4i+5eQv1x3JKSEQwwxH3yKT9WUMAu3uj+orG9AOM7aiFj0W9PrTlTTkoUWU15/M43G MNpDDQxOGa8+IAVafp0LeD+kSvzDoyTC20PrCP7Ia85PDwUpeCiqEyENM1ZDwu+6T7Px 76MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926683; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QTeAQsqCeHYohT1+z6QROKS290DmjN4VP9f8cpdpaL8=; b=4TGozUEbrhgbbtKJCv2xb2wSdx4n3eAuXBqfMAk6GQo14OahwLFD6nluBX2B1yCaKn rqw3OGMU62aXbDH4iOk0hYiugtBA+A4GnwYTDFBiTRshURJ09Re45kKuzYhJA0tFM+r8 GEuBcLt1yvrbz9QMJ9Bh46j7kxTNgFpMEJvDEvn3IMzWbuaPNjT2SFfu9y6cC/xJBoCv noa+UlmPiGS+NML+N8OTOIOUOLt9P7DlckfBmfpwJnGUX8ewljUHhQR0oE6Mt/LX/fz6 d7ttjONIcMMHCI+FAZv3jTqUUQSBR1RVp1dtQEVbxt58iaWENxMymBuHNvAYofNNH956 gQmw== X-Gm-Message-State: AO0yUKVQ3yinNo/tO5Ti2McHygHdsgXOOCnZQycpoRIWyfoTMbPbzU2U N/rM7vU2leFg6eF/iinUGbampYpXCAjo4DbqSw== X-Google-Smtp-Source: AK7set9qSNzfiSuUSuac6czSQv9JIGaIPRBH/C++HGZYNA2V+6Yj/KtOeknnwR+NdK2YlHb02GTz9vZIhxkpteuF/Q== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a81:e803:0:b0:541:7f49:adac with SMTP id a3-20020a81e803000000b005417f49adacmr1106841ywm.8.1678926683452; Wed, 15 Mar 2023 17:31:23 -0700 (PDT) Date: Thu, 16 Mar 2023 00:30:58 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: <53c62631b481f5811340ef4fcbef511abd2171d7.1678926164.git.ackerleytng@google.com> Subject: [RFC PATCH 05/10] KVM: selftests: Generalize private_mem_conversions_test for parallel execution From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 6j9gxenct8d755tgt8j3icsdbdgmbawd X-Rspamd-Queue-Id: 5F58E40005 X-HE-Tag: 1678926684-271469 X-HE-Meta: U2FsdGVkX19y7d0KLLQxMxg6SRnWykr0KXuXvHPksf+zpUSEXiDF4O4L6AcVqfSosyfAb9lrLR2hJNa6kILzcAKgTkeNFbXdZK+ONFydGkl2xpJu5XbkbpYKSBntAY/JgcCcnBxgzT0SZ2pbN5JGyRc7nhCg6u6WpeAgzk9M3fRzydD3OhZhlcBhNNaZuiTtD00l1xgzpKke0CFyP/fUSjkfWO3MKQk9pmaslDD1NuxmvaLLIC4WIS0VfrnzUz+IISK1/iWqZJyDuX66m/4W1IM2FiLaYSz8zwpUt6j8Y6L6eJROLF6LoO+2iwz3bOYv4ne+eZN6KYVYbnlM4tzm3goRZkHfd9lgCFC1cLN4Km2BZ4wlugvk//kX2vGXbw0PyWpFTPpZ6D9Jv62lKLQmlKYG6WGJcVdm1DXHQCOEN0werhVsPtU8q1ECK64GPN1jQIU4bB8W4HMfEoOq+ww/yge9BlWGrxGOGIJviSl8Kkc2T+kWKZDEKR1QJGFqJA3WFC+uJ3k42lhnGHtvff3cOuMdXkh36Oxe2yViZxEoPUvWeWjZwS5xA1jqTDuclyAl1O9Ei7v7e5ecSSznF/keXHIDVgTZhTVZILlQUP6oNrPt7EmJtzT7l+1masT6JqQjhi6RYZ+QJh9TFzWpF2dx7Re3HGCLLG6xkOXwC03tS4tCOI6g0Yw+YiyQjyE/d4Gt8F0vjH6PYmqMnnVzSCrR3LkDzFlNvWgtuiyTi95Ys1VnkzOzVxqKrDhsVIgOJpICaYYKLSBFPoFbygK7JYCTfBpGWN3/U2QdIJPhtixrD1ug1XjQilrAVvCBMVTZJbGXHN1r9NW8c3cORJGXF5b9VWy7Lh6KUbA05YZTZwFgl4fSa5z9u0JPCeJ5q9WYcXW79KezDZAlhB8MMy5Qnz4iMdwfGDZY7KfVl2EXEX13sje4hHNjYAsiB6AV3m27kyo0buxUdYzc3O0eWgUpUoB ML9waZZZ xLTDZ5Vw+7v8mgxw87XdMJKow6bkq+wHPV4lwPtAkWreasJTSoFHleXjgDOXSVij7mNhLadYgCP7sntOFRwdWKnFaTA1R8rinnU6dlFl2lRadBCIcZrhFN9Y0tE2FFXd3z12L5LjrkRl1VSwFzr6VFzdJtA3uTwBm858g8UC6ZQE0suVK0IOhKnKFS5+KnfFyvsz5CYe1Nrz+l1RcSrZO0b170McPQOPLw42avc8MbmubY5vn41iGEVfjgFRBZOIB34ZExjBfYAkLH9zsB44Ht7xCPfyhfgDiEDF5BsTDGbiq+US9veFlYXQ+ZjAiiREJJntgEBgThYepexg+e1Sj6zF3bycVr66Rg0yQ6IYf639ITsXKUvu2dggokm6Ia3JKY7AzcfL6SBPk0oHKETiFIqRBVvehE5M3cag/CQinIz/kFXw5XyQ+tFUwYK0HHrV91oLKCR9XVWFf7Wlk9aCSkz7a0acitZX+ybqo5GJXg+tdIo3I8iDF6CG7Rfw7GTHE/3TR0qXJPdHZGuQIQQ45HCmxCh9OutWjMKvHkaw41yeYdnCzW4+s/vT59cpYgsNTt9swD6qJVgbPx4OZUxDIUO/gAe0/mTRrLe1+7FixC1gscesL1+BNbSqTJStkB62wZaqe3OD2nGlSz2hCNNAGz9x3r77PdNrBgIFYGtDHZTnSlN6FbJov0kSCNFNnrVDI/GQTDWxIEYNC28kYU6CIP6nTwQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: By running the private/shared memory conversion tests on multiple vCPUs in parallel, we stress-test the restrictedmem subsystem to test conversion of non-overlapping GPA ranges in multiple memslots. Signed-off-by: Ackerley Tng --- .../kvm/x86_64/private_mem_conversions_test.c | 203 +++++++++++++----- 1 file changed, 150 insertions(+), 53 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c index 7741916818db..14aa90e9a89b 100644 --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c @@ -5,6 +5,7 @@ #define _GNU_SOURCE /* for program_invocation_short_name */ #include #include +#include #include #include #include @@ -22,9 +23,10 @@ #include #include -#define DATA_SLOT 10 -#define DATA_GPA ((uint64_t)(1ull << 32)) -#define DATA_SIZE ((uint64_t)(SZ_2M + PAGE_SIZE)) +#define DATA_SLOT_BASE 10 +#define DATA_GPA_BASE ((uint64_t)(1ull << 32)) +#define DATA_SIZE ((uint64_t)(SZ_2M + PAGE_SIZE)) +#define DATA_GPA_SPACING DATA_SIZE /* Horrific macro so that the line info is captured accurately :-( */ #define memcmp_g(gpa, pattern, size) \ @@ -83,7 +85,9 @@ static void memcmp_ne_h(uint8_t *mem, uint8_t pattern, size_t size) #define REQUEST_HOST_R_PRIVATE(gpa, size, expected_pattern) \ ucall(UCALL_R_PRIVATE, 3, gpa, size, expected_pattern) -static void guest_code(void) +const uint8_t init_p = 0xcc; + +static void guest_test_conversions(uint64_t gpa_base) { struct { uint64_t offset; @@ -96,17 +100,11 @@ static void guest_code(void) GUEST_STAGE(PAGE_SIZE, SZ_2M), GUEST_STAGE(SZ_2M, PAGE_SIZE), }; - const uint8_t init_p = 0xcc; uint64_t j; int i; - /* Memory should be shared by default. */ - memset((void *)DATA_GPA, ~init_p, DATA_SIZE); - REQUEST_HOST_RW_SHARED(DATA_GPA, DATA_SIZE, ~init_p, init_p); - memcmp_g(DATA_GPA, init_p, DATA_SIZE); - for (i = 0; i < ARRAY_SIZE(stages); i++) { - uint64_t gpa = DATA_GPA + stages[i].offset; + uint64_t gpa = gpa_base + stages[i].offset; uint64_t size = stages[i].size; uint8_t p1 = 0x11; uint8_t p2 = 0x22; @@ -140,11 +138,11 @@ static void guest_code(void) * that shared memory still holds the initial pattern. */ memcmp_g(gpa, p2, size); - if (gpa > DATA_GPA) - memcmp_g(DATA_GPA, init_p, gpa - DATA_GPA); - if (gpa + size < DATA_GPA + DATA_SIZE) + if (gpa > gpa_base) + memcmp_g(gpa_base, init_p, gpa - gpa_base); + if (gpa + size < gpa_base + DATA_SIZE) memcmp_g(gpa + size, init_p, - (DATA_GPA + DATA_SIZE) - (gpa + size)); + (gpa_base + DATA_SIZE) - (gpa + size)); /* * Convert odd-number page frames back to shared to verify KVM @@ -182,6 +180,19 @@ static void guest_code(void) /* Reset the shared memory back to the initial pattern. */ memset((void *)gpa, init_p, size); } +} + +static void guest_code(uint64_t gpa_base, uint32_t iterations) +{ + int i; + + /* Memory should be shared by default. */ + memset((void *)gpa_base, ~init_p, DATA_SIZE); + REQUEST_HOST_RW_SHARED(gpa_base, DATA_SIZE, ~init_p, init_p); + memcmp_g(gpa_base, init_p, DATA_SIZE); + + for (i = 0; i < iterations; i++) + guest_test_conversions(gpa_base); GUEST_DONE(); } @@ -203,15 +214,27 @@ static void handle_exit_hypercall(struct kvm_vcpu *vcpu) run->hypercall.ret = 0; } -static void test_invalidation_code_unbound(struct kvm_vm *vm) +static uint64_t data_gpa_base_for_vcpu_id(uint8_t n) +{ + return DATA_GPA_BASE + n * DATA_GPA_SPACING; +} + +static void test_invalidation_code_unbound(struct kvm_vm *vm, uint8_t nr_memslots, + off_t data_size) { - uint32_t fd; - uint64_t offset; - struct userspace_mem_region *region; + struct { + uint32_t fd; + uint64_t offset; + } params[KVM_MAX_VCPUS]; + int i; + + for (i = 0; i < nr_memslots; i++) { + struct userspace_mem_region *region; - region = memslot2region(vm, DATA_SLOT); - fd = region->region.restrictedmem_fd; - offset = region->region.restrictedmem_offset; + region = memslot2region(vm, DATA_SLOT_BASE + i); + params[i].fd = region->region.restrictedmem_fd; + params[i].offset = region->region.restrictedmem_offset; + } kvm_vm_free(vm); @@ -220,33 +243,24 @@ static void test_invalidation_code_unbound(struct kvm_vm *vm) * the vm. We do allocation and truncation to exercise the restrictedmem * code. There should be no issues after the unbinding happens. */ - if (fallocate(fd, 0, offset, DATA_SIZE)) - TEST_FAIL("Unexpected error in fallocate"); - if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - offset, DATA_SIZE)) - TEST_FAIL("Unexpected error in fallocate"); + for (i = 0; i < nr_memslots; i++) { + if (fallocate(params[i].fd, 0, params[i].offset, data_size)) + TEST_FAIL("Unexpected error in fallocate"); + if (fallocate(params[i].fd, + FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + params[i].offset, data_size)) + TEST_FAIL("Unexpected error in fallocate"); + } + } -static void test_mem_conversions(enum vm_mem_backing_src_type src_type) +static void test_mem_conversions_for_vcpu(struct kvm_vm *vm, struct kvm_vcpu *vcpu, + uint32_t iterations) { - struct kvm_vcpu *vcpu; struct kvm_run *run; - struct kvm_vm *vm; struct ucall uc; - const struct vm_shape shape = { - .mode = VM_MODE_DEFAULT, - .type = KVM_X86_PROTECTED_VM, - }; - - vm = vm_create_shape_with_one_vcpu(shape, &vcpu, guest_code); - - vm_enable_cap(vm, KVM_CAP_EXIT_HYPERCALL, (1 << KVM_HC_MAP_GPA_RANGE)); - - vm_userspace_mem_region_add(vm, src_type, DATA_GPA, DATA_SLOT, - DATA_SIZE / vm->page_size, KVM_MEM_PRIVATE); - - virt_map(vm, DATA_GPA, DATA_GPA, DATA_SIZE / vm->page_size); + vcpu_args_set(vcpu, 2, data_gpa_base_for_vcpu_id(vcpu->id), iterations); run = vcpu->run; for ( ;; ) { @@ -287,40 +301,123 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type) break; } case UCALL_DONE: - goto done; + return; default: TEST_FAIL("Unknown ucall 0x%lx.", uc.cmd); } } +} + +struct thread_args { + struct kvm_vm *vm; + struct kvm_vcpu *vcpu; + uint32_t iterations; +}; + +void *thread_function(void *input) +{ + struct thread_args *args = (struct thread_args *)input; + + test_mem_conversions_for_vcpu(args->vm, args->vcpu, args->iterations); + + return NULL; +} + +static void add_memslot_for_vcpu( + struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint8_t vcpu_id) +{ + uint64_t gpa = data_gpa_base_for_vcpu_id(vcpu_id); + uint32_t slot = DATA_SLOT_BASE + vcpu_id; + uint64_t npages = DATA_SIZE / vm->page_size; + + vm_userspace_mem_region_add(vm, src_type, gpa, slot, npages, + KVM_MEM_PRIVATE); +} + +static void test_mem_conversions(enum vm_mem_backing_src_type src_type, + uint8_t nr_vcpus, uint32_t iterations) +{ + struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; + pthread_t threads[KVM_MAX_VCPUS]; + struct thread_args args[KVM_MAX_VCPUS]; + struct kvm_vm *vm; + + int i; + int npages_for_all_vcpus; + + const struct vm_shape shape = { + .mode = VM_MODE_DEFAULT, + .type = KVM_X86_PROTECTED_VM, + }; + + vm = __vm_create_with_vcpus(shape, nr_vcpus, 0, guest_code, vcpus); + + vm_enable_cap(vm, KVM_CAP_EXIT_HYPERCALL, (1 << KVM_HC_MAP_GPA_RANGE)); + + npages_for_all_vcpus = DATA_SIZE / vm->page_size * nr_vcpus; + virt_map(vm, DATA_GPA_BASE, DATA_GPA_BASE, npages_for_all_vcpus); + + for (i = 0; i < nr_vcpus; i++) + add_memslot_for_vcpu(vm, src_type, i); + + for (i = 0; i < nr_vcpus; i++) { + args[i].vm = vm; + args[i].vcpu = vcpus[i]; + args[i].iterations = iterations; + + pthread_create(&threads[i], NULL, thread_function, &args[i]); + } + + for (i = 0; i < nr_vcpus; i++) + pthread_join(threads[i], NULL); + + test_invalidation_code_unbound(vm, nr_vcpus, DATA_SIZE); +} -done: - test_invalidation_code_unbound(vm); +static void usage(const char *command) +{ + puts(""); + printf("usage: %s [-h] [-s mem-type] [-n number-of-vcpus] [-i number-of-iterations]\n", + command); + puts(""); + backing_src_help("-s"); + puts(""); + puts(" -n: specify the number of vcpus to run memory conversion"); + puts(" tests in parallel on. (default: 2)"); + puts(""); + puts(" -i: specify the number iterations of memory conversion"); + puts(" tests to run. (default: 10)"); + puts(""); } int main(int argc, char *argv[]) { enum vm_mem_backing_src_type src_type = DEFAULT_VM_MEM_SRC; + uint8_t nr_vcpus = 2; + uint32_t iterations = 10; int opt; TEST_REQUIRE(kvm_has_cap(KVM_CAP_EXIT_HYPERCALL)); TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_PROTECTED_VM)); - while ((opt = getopt(argc, argv, "hs:")) != -1) { + while ((opt = getopt(argc, argv, "hs:n:i:")) != -1) { switch (opt) { + case 'n': + nr_vcpus = atoi_positive("nr_vcpus", optarg); + break; + case 'i': + iterations = atoi_positive("iterations", optarg); + break; case 's': src_type = parse_backing_src_type(optarg); break; case 'h': default: - puts(""); - printf("usage: %s [-h] [-s mem-type]\n", argv[0]); - puts(""); - backing_src_help("-s"); - puts(""); + usage(argv[0]); exit(0); } } - test_mem_conversions(src_type); + test_mem_conversions(src_type, nr_vcpus, iterations); return 0; } From patchwork Thu Mar 16 00:30:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A04E7C7618B for ; Thu, 16 Mar 2023 00:31:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B17F66B0088; Wed, 15 Mar 2023 20:31:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC9026B0089; Wed, 15 Mar 2023 20:31:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91A256B008A; Wed, 15 Mar 2023 20:31:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 808FB6B0088 for ; Wed, 15 Mar 2023 20:31:28 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5330EABA6E for ; Thu, 16 Mar 2023 00:31:28 +0000 (UTC) X-FDA: 80572882656.08.86962CF Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf20.hostedemail.com (Postfix) with ESMTP id 73A031C001A for ; Thu, 16 Mar 2023 00:31:26 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=swpVj1Sm; spf=pass (imf20.hostedemail.com: domain of 3XWMSZAsKCJQy082F92MHB44CC492.0CA96BIL-AA8Jy08.CF4@flex--ackerleytng.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3XWMSZAsKCJQy082F92MHB44CC492.0CA96BIL-AA8Jy08.CF4@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926686; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=36lklAKITNKcvpGi9bBaV0pg92rnpur43Kuea+YFpfM=; b=r4L7V/HDWt0W8VZ39CY79tq07FG6l7CBmN3rDj3vG3r5rE0/CkyrYDOf69oCGt4VWVwyng V+TTpoUVY2FBEfmOTlxFOdsduBY9EecznPiiPKnbLgvZt29C6YJ6ggUOCpQs6uS+lZyXOS 1qtyfLhIpNWhYH4gm9s7h6/zFMXaKWA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=swpVj1Sm; spf=pass (imf20.hostedemail.com: domain of 3XWMSZAsKCJQy082F92MHB44CC492.0CA96BIL-AA8Jy08.CF4@flex--ackerleytng.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3XWMSZAsKCJQy082F92MHB44CC492.0CA96BIL-AA8Jy08.CF4@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926686; a=rsa-sha256; cv=none; b=JL9C3+2I9OidoIr9Ju+LtWrv66q9FByGXfAtIiYg1oFXNWg0uiacRmd750Rx5Sne3Mv+4J UyKb99BKKjWTpG0PR51UG2CH5TDQY/05szIz4zHnervlfUCqf4OTZloSjeLQAMRIW43Mb7 /0bCsXaheC3Ne12iy3vzy19vT0apK08= Received: by mail-pl1-f202.google.com with SMTP id u11-20020a170902e80b00b001a043e84bdfso6192921plg.23 for ; Wed, 15 Mar 2023 17:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926685; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=36lklAKITNKcvpGi9bBaV0pg92rnpur43Kuea+YFpfM=; b=swpVj1SmNmgvWlTTZKcMha4lkIplKfRmILDkyWfcGRLXWLuIlK2d6RzDWw2bYkkCHP soiW4nXc7/hBbAleU8BqoI0AbG96N9laDULGWA+oYmBxb9+GZWi0B0T26gJnbwIFOCwo 5kpRG9JizdS1Y6EbQlta+wo8Fhd+ryKKJGTqSzbsLYaWB10pCI4jhMlJ9DGRJ4DSAtGk 3aahsJCHmb9Uk47t1vgWw/SYjxk2SvIyeXgaVgaNp1TPH4oC+vl3KgGYbWyD1TlOcBi1 gvD1hR4NtBHZOvW4SAlG3B1IpFX0JT8Zq0hcF2742mhE+c1PzdSmxBYs2Pwk5wn4zjuL RaVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926685; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=36lklAKITNKcvpGi9bBaV0pg92rnpur43Kuea+YFpfM=; b=EWpO/HeBQHyzOb8cXSKqbLUynUmglc7qopF/hIfIOYSnRGZD82zWoDyezwNy1BVuNk KEkLV4CTzJcHoNpuJIUBpf8/nYEKrbMxe274xNumeoIAv9ub/0ztTma5w+KFBtUmNHcC OVknANBdnOv8JAYNYLOXB9RZOeMef4rmhp3gHYcotKxCX64M6q4U9z84PItmt1s6kPZ2 A+ndBsBVpvNiL4+2JMx4WcFUl/t2IZhfUB5LGgNCDuvKQpx3HOk0rBqScx4xNp2dYc6s pji/E1622S8oC62Sg5aDthm6F0qodRkmKC/oeVx7OKkuHSU73c5SjpC8bGrCBF7rxi4B sAJQ== X-Gm-Message-State: AO0yUKUfpMOziZW8Em6aPIwve6ety7om50VOWMOMH03L2IjKtHqmzSX6 /NPAt5oDwLHdhjOMgMwLQ4vCWhAxqhGrXZKbwg== X-Google-Smtp-Source: AK7set9HhZ92PQ2OitTC4KZtYEJK0EXqsjjwLnoPjbnEyW7GD+pO7NNEnen5rh0nKaexCpnSy3z8RFk0Cysc1DaScg== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a17:902:d50d:b0:1a0:5402:b17f with SMTP id b13-20020a170902d50d00b001a05402b17fmr634600plg.6.1678926685342; Wed, 15 Mar 2023 17:31:25 -0700 (PDT) Date: Thu, 16 Mar 2023 00:30:59 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: Subject: [RFC PATCH 06/10] KVM: selftests: Default private_mem_conversions_test to use 1 memslot for test data From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 73A031C001A X-Stat-Signature: akgp9ykpsjgypy6hnk6awjqh3qco9i1w X-HE-Tag: 1678926686-999263 X-HE-Meta: U2FsdGVkX1+G1P8sPBt7w0COsuXjYWh0aHAhxXXKBo6VMXJFYwsnCt/xb9n3FOwiBQoeCn+RAv0g3WysD/9Cm0WfBtihI/tDGTkYpOEZa7NynlBSAfPTB4KSfLghXp/KIXVgF/HAbCQ87OqeufWKepUMBhHT0Q/Dp0Ek9NZFnPIulBeydLJTpMpz5T4Bs5+qu45jgJE826O2lY00+3zLp0dpGM1rPXz+8pje2SXLf4PL7bP7WTWAA3twXmaUOfC+uegEC09kn+K+WYubMQQZRjlTVc24xfNAc2yyAWwFJ4CE4lh+95wa07CG6PUmq7iGVYaFnxpEiCEgGgxRgAMkOT4bRzq3ZIRU/SwNA1/0ZRKYIZ5RKWNzXKqGxrJW+mwa8yXMQxjTWaAii/l3zsr0niny1yDE1+KnYjwmWGwXh4cAcg5LmBKW/+eIAsuxRq/veVxOWVbqpPbBeL5rAiV21oyttE1wrNBtgjMc1XgRIrBdQGiEBwRcRiPlC/M2n7eiUk+v1D5P3aCPxDGgCFw7AN0+3C7aOY8pyeaNUpPaC3JLNqPVTcDCV1ursDZDqh0+hjglDJzIkYEV0gac6MJbwGdwYhgsS3yLYK5h/hVdTKNPfzjIE/wMQ8uM/qqsQTZUjlovj+qdzRC3vmk+on9KfX4Q/4tUwAJek93yl+2FFpSUHZAD9JSZf5Y0qO1ZOs8QgJEFxIdDnSDhJTSs181lDS9gNc4MeVNMYGh9ZC2ph4zMylbFJd8p+3XUpaVOSZ2HqF9el4mEPp6hGg2xdMAIyRnZzl0BTBUbGXa1Q4tnENeeD6O3Wtkd5XnXq8Re4o8Rw+XSZ9IIZcHrGL4h+ZwaQUyy+kdi8R7zoBkbSaseSrAUDr+yxN5lusdiqypE008Sfnkn4VXWwPj6HJWgFH/NLXFxi7Wm+qelDwPpjTMXR7KOo28nO0AudttlbtDCu0dR6urYWcGHtPbc/5NJv3c b+wPwtGe eQ+EGU+ZFtMWJ+l2wfZ+9X80EY2zPx/uMeo7gjfpXa6Jxc9h/FbRu2n8jNXhEqGLE5+QTOOwcI/SjhuBXo+pocuHhuXFA39dCLyUTivBd4+/MEg37UyCiJVZ8VeIVyDpS377oTBN7Ex3jKZst3CpFWKV0mJdMUcHsatFcBPMvAVzOSRerFDqRI9Fe4eq9Ghjuo+HBC97v7VYKVefVFcyeLqH/0m3bOPMIysCZEIECp5Gb1w1CLn2f4VvwR5tKI0bpoKo19pmL819p/RpSOkOvF+Q/SlzTZO8uBdDWVDuJ/sq87JsGnABMGOY+idPgC9+tH6zLd6o1Dng0liBtpYu8I4eA7or4z9jvEZlKNVhzJoYX5OGCT6ux7Y8zuzIFyKraQ5o5PCEAfS/EEC2vsYu3pBNRjPT/Px31damPuX6sy6UCyt3s6RwutYlAwwdsZiH97fRQJYmP6OSkUQP2RQV9SwOabdv+stpbVx12+HLZ94IA4az0iO3DRqSKW/PZ2k/Z1K/i2fJ7/DLp0XxrdyDWjaGlYruAoYRp2/S9OL1ZGXr1FYjmRLdgrND95bzem5dBiBDpMh6wqhhGyv2MihGEyR0Io7+EucUoBy2BsW2aRn+0kCavkfk5OeulAjSE6BraMcudXOKcrnDdQMGZ1L46Id2BU8DsW9yHtWmKbOyNNR+6mRJAMyGI49/EUTzUVb69xI8G1vkqW1+8Vyk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Default the private/shared memory conversion tests to use a single memslot, while executing on multiple vCPUs in parallel, to stress-test the restrictedmem subsystem. Also add a flag to allow multiple memslots to be used. Signed-off-by: Ackerley Tng --- .../kvm/x86_64/private_mem_conversions_test.c | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c index 14aa90e9a89b..afaf8d0e52e6 100644 --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c @@ -335,7 +335,8 @@ static void add_memslot_for_vcpu( } static void test_mem_conversions(enum vm_mem_backing_src_type src_type, - uint8_t nr_vcpus, uint32_t iterations) + uint8_t nr_vcpus, uint32_t iterations, + bool use_multiple_memslots) { struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; pthread_t threads[KVM_MAX_VCPUS]; @@ -355,6 +356,16 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, vm_enable_cap(vm, KVM_CAP_EXIT_HYPERCALL, (1 << KVM_HC_MAP_GPA_RANGE)); npages_for_all_vcpus = DATA_SIZE / vm->page_size * nr_vcpus; + + if (use_multiple_memslots) { + for (i = 0; i < nr_vcpus; i++) + add_memslot_for_vcpu(vm, src_type, i); + } else { + vm_userspace_mem_region_add( + vm, src_type, DATA_GPA_BASE, DATA_SLOT_BASE, + npages_for_all_vcpus, KVM_MEM_PRIVATE); + } + virt_map(vm, DATA_GPA_BASE, DATA_GPA_BASE, npages_for_all_vcpus); for (i = 0; i < nr_vcpus; i++) @@ -371,13 +382,16 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, for (i = 0; i < nr_vcpus; i++) pthread_join(threads[i], NULL); - test_invalidation_code_unbound(vm, nr_vcpus, DATA_SIZE); + if (!use_multiple_memslots) + test_invalidation_code_unbound(vm, 1, DATA_SIZE * nr_vcpus); + else + test_invalidation_code_unbound(vm, nr_vcpus, DATA_SIZE); } static void usage(const char *command) { puts(""); - printf("usage: %s [-h] [-s mem-type] [-n number-of-vcpus] [-i number-of-iterations]\n", + printf("usage: %s [-h] [-m] [-s mem-type] [-n number-of-vcpus] [-i number-of-iterations]\n", command); puts(""); backing_src_help("-s"); @@ -388,6 +402,8 @@ static void usage(const char *command) puts(" -i: specify the number iterations of memory conversion"); puts(" tests to run. (default: 10)"); puts(""); + puts(" -m: use multiple memslots (default: use 1 memslot)"); + puts(""); } int main(int argc, char *argv[]) @@ -395,12 +411,13 @@ int main(int argc, char *argv[]) enum vm_mem_backing_src_type src_type = DEFAULT_VM_MEM_SRC; uint8_t nr_vcpus = 2; uint32_t iterations = 10; + bool use_multiple_memslots = false; int opt; TEST_REQUIRE(kvm_has_cap(KVM_CAP_EXIT_HYPERCALL)); TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_PROTECTED_VM)); - while ((opt = getopt(argc, argv, "hs:n:i:")) != -1) { + while ((opt = getopt(argc, argv, "mhs:n:i:")) != -1) { switch (opt) { case 'n': nr_vcpus = atoi_positive("nr_vcpus", optarg); @@ -411,6 +428,9 @@ int main(int argc, char *argv[]) case 's': src_type = parse_backing_src_type(optarg); break; + case 'm': + use_multiple_memslots = true; + break; case 'h': default: usage(argv[0]); @@ -418,6 +438,6 @@ int main(int argc, char *argv[]) } } - test_mem_conversions(src_type, nr_vcpus, iterations); + test_mem_conversions(src_type, nr_vcpus, iterations, use_multiple_memslots); return 0; } From patchwork Thu Mar 16 00:31:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 860D9C76195 for ; Thu, 16 Mar 2023 00:31:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39D886B008A; Wed, 15 Mar 2023 20:31:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3763D6B008C; Wed, 15 Mar 2023 20:31:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EDF06B0092; Wed, 15 Mar 2023 20:31:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 10A616B008A for ; Wed, 15 Mar 2023 20:31:30 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CFA19C125B for ; Thu, 16 Mar 2023 00:31:29 +0000 (UTC) X-FDA: 80572882698.25.39CC28A Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf11.hostedemail.com (Postfix) with ESMTP id 15F424000C for ; Thu, 16 Mar 2023 00:31:27 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I+hk1kHX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3XmMSZAsKCJUz193GA3NIC55DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3XmMSZAsKCJUz193GA3NIC55DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--ackerleytng.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926688; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JBLPG3XthGG9faiSvk5U/ET6qjyhuWi/SwHOth1Ucac=; b=ZhMpTkhN/ZgUPrma7aX1nloLLBpCjHT835HX5zQu2vL2Yt9Lu7HPQUrxIMNf+PgL515Fe0 WUgINdoHppheeOzA0V/apiSsoxQCfMIHViX8yFzhfr26BKHjIz7mDdAn/FkAZg5RCZTphn DLaODvD/vSOsClfLQ/7oSz1+JyYsBVE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I+hk1kHX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3XmMSZAsKCJUz193GA3NIC55DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3XmMSZAsKCJUz193GA3NIC55DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--ackerleytng.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926688; a=rsa-sha256; cv=none; b=5963LAySW9itpaKBTKldUX25HGV7VoiADgpaV1s/bwJNhHKhujV5sj+3goQT5JhUs4XAnS 09PE3bDx2P3mlzQgnysGC/oQZ0xChSfxjJNKTu0sJFtuTzUL9fyJeONbLygFuZn6dThc8V LKrP7uv1P9UxYobPzOf6z1QZZC6k15U= Received: by mail-pj1-f73.google.com with SMTP id n33-20020a17090a5aa400b0023b4f444476so68447pji.3 for ; Wed, 15 Mar 2023 17:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926687; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JBLPG3XthGG9faiSvk5U/ET6qjyhuWi/SwHOth1Ucac=; b=I+hk1kHXyTdyRHWR/E+Fe4D/KjC/hhFWZULnWPbpGXImZDU13NH2r0CvjRWyfCgLxX /nkIHP6zbtD+kRkLZz1i9msvu36P2j1F1ed2x92tbTloVbSMlV2L5X7YmVhhKmZ4DqvM XpXOnOkjDklzkljzqZGV/y4Nh+8aXvLV39ccn20yIQi1+cuwUBgQwtL3GYk3OKYOFzt5 fGTKHpxrFE/fRCl2mKHPSZMCdRAxw4bOce1hR/tDvln+tyvmSAorwJz0NO2G3/AQeBf+ ctLv6vLizdn+6uzwfijXtM/b902mBW+WM3hgf9E7bWyK12V6rTdbKghkmJDtmACEkOkZ v8Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926687; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JBLPG3XthGG9faiSvk5U/ET6qjyhuWi/SwHOth1Ucac=; b=OJ+8HLq37D4S1VGKBlds+pax/Li2+94e9fEs9eZMIIz+JB9cCrJVkM0kgtlCtutFhl 6TX8/H4hm+G2IhhvYEegPrrlCWas2xez8u8yoVbsQQAs5DTuydy5peT8kOG+/gKtrYTs QFGrJOj5SbzDshFHIRQHnLHBZ781tRfCp+rnWEqXHV+qZcNCPSk6Xm5tODDouVYQSRz0 d/3z5mqy+8hk0VsbG8j3mwFAw4h0l7AxUry43TyghPHvONCzhQSkp2bsyMZG533fWwHX rnoA5N5nCCZdGxd5ahRx+RYz14491Ha1lKjruEu/5UtGLBMhM58dXOQLblZFXy0bVxx5 zMIA== X-Gm-Message-State: AO0yUKV+aZkfjlvaRKBojIspFyxmzkLGXzEHulHVlYSSq2ppSz+pEBYB hNYspiOtlx4qC9xGgILKZ/g9Ycx5+JhtcjQjrA== X-Google-Smtp-Source: AK7set8wyHBYS0yNjAY2Bu6NPZk7sDhPcWzuxoadwL3xHiIjGr+DZnA4k/ntT0jv/7rXx9SUD16F0j0DYIAvrg8IcQ== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a17:902:e749:b0:1a0:4aa3:3a9a with SMTP id p9-20020a170902e74900b001a04aa33a9amr581092plf.2.1678926686991; Wed, 15 Mar 2023 17:31:26 -0700 (PDT) Date: Thu, 16 Mar 2023 00:31:00 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: <59ff32ad0aa9e3533a96064d1ae07aba11f55924.1678926164.git.ackerleytng@google.com> Subject: [RFC PATCH 07/10] KVM: selftests: Add vm_userspace_mem_region_add_with_restrictedmem From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspamd-Queue-Id: 15F424000C X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: m48hwdtszmhharcdne15kpkna493nac5 X-HE-Tag: 1678926687-173905 X-HE-Meta: U2FsdGVkX184HvTza9Np2Ftvn8Wf0+4xxtOWax4N2qmNgwXj9CYaR8caJyoEL0nCyJllJjzrAcrwAb8okooTK3FD1TaqyTs6ckgiWWWYB6lz7Feq1LzAaFCC1FWKs9Ucc+3IRC706eshnzdMb6hpgxaUs9RIyV6puANGcmh7JzhwD/DFMakC6DIEl8a80+ll4fiJpDQ4e1xE91mzJHi/3QnmavVWaSKj3nZhqdxXJHWvCjlEpt1omMULMP6kUoyYyy4hJK+bHx4CGh0YJIUTKwXdmYLWEVT9kF5WBASYjNuKfj4C+uTwouuH4Y46qNzpHn1wXSzjmF4rMGNHh5d5Vg5yDVFS/Rpuqs15x+SnuZ8FDJKDo1khzZYfLgRiwYStI0fg+wQ775zxN3DH43nErJIVz1Ae3FvCcFnrWi5IIampBltakwUOEc1gsGOltNTDyUQ63txWEJ+Rr436QRP7NlTaTOYVHnaq6jdT/kiwVrUfw6QLbaqO6512xiqfix8XdJurqOtSpYct5tsEwhhXVPPjWDeYaJiZyIoz0AkKSheJ5ZyXMxZ/dVsmRuU4ICV8UAr51TMgsLzQjMzLIniflbdbEzbyV79h/ldTIXBXhZgOb/1fxbZbl//pZsViKL8T9zIB/fq9FHoxPJKpqFbZG50fpl/yXtJ+L+O8j/ENmKLvbqDNOFK2/T0+GzFsde0TC6wxYJZFFobaj5C2Ch/GAwRgydoGM5ctJZ6RoPv/kOyfMf18Y0duVIRzbfMABAW/mQjI7kxO59LscIxY8iExpg/6iZ3bMrX6qXcMqspxTQnZ5iZADrl8O1o5yWCTF6pEFFQvzmXFhqOJfxrz7dO5NZiqzZgMtDGZjGn4uh8Vxzxm7Zo7+xxWdpWGyJIB6yraDuXdMbXBCJPmCnbKWw+1zjLO16Rs9rTi/JD24dzysFltcxb2BbV2JbcoYLKZLGiKsOhKAi16igniLfgawii ND9Lx3jQ TUVC5DKBTxqKqhQdyBLDMDXtu0iikTZfKx7GDXNqj4v/5NOBaw9I5VFHCKguOr7lG4swmijxNm1pWVTgMd/vD8CDEAOZGHskNU5WQotIEJAxFP5BIUwI/F25gdNHSuzfiJAwts+3135qlyTv9bk51gcSDTl3ilFW3JemO4SwG9zf7V1mbcO3ewVMzRG4diZFwCR8RgjiT7wJl7uXAgvDzvZgDQpSFBGgoq2Q49l40ywgMnZRnQDeW7BBaStz05ETN2GcL6rp1bhFrbMc8NBOLIhI1oRJIuY0MUIT7F9Do2SnNTg1ZUA5pbp+xd7YQhSle9IgGlAS60Qs4C3h42Do3kq9hOsm9yKOZsuseezDjzlsGadTHg5MScvXNO6auT2QgcegSpiexI7fpkN+C/vb8eqcOLj43uxvhYJwFBGTGVPqRuToFla/YcVKMdNa7lj2ukUx9MlcKGNtDHtEBvP67kkxf8wF8mctWkE5CuuqnIyJVF28ZPRJ3xYR0aDyENuRSBnm8pWW0SfajQy1MwINVgGH1E1KTh9L83lKLBSaq4yELHiz7e0GIwAaqyvyNg73c3sMvLimhmHiozQyO47FnIgadC0NLBlx/h0d6CaHQ3VnIuGbfcHrav02p1ZJjape1u4wh0qyo+FYFXHi8qG4jwecaj/RU59/MCp7+H5wM2msnaq+n+Kkk7fs/f644MNYf9hP8IV4ucu3DUnE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Provide new function to allow restrictedmem's fd and offset to be specified in selftests. No functional change intended to vm_userspace_mem_region_add. Signed-off-by: Ackerley Tng --- .../selftests/kvm/include/kvm_util_base.h | 4 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 46 +++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index b6531a4063bb..c1ac82332ca4 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -486,6 +486,10 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint64_t guest_paddr, uint32_t slot, uint64_t npages, uint32_t flags); +void vm_userspace_mem_region_add_with_restrictedmem(struct kvm_vm *vm, + enum vm_mem_backing_src_type src_type, + uint64_t guest_paddr, uint32_t slot, uint64_t npages, + uint32_t flags, int restrictedmem_fd, uint64_t restrictedmem_offset); void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags); void vm_mem_region_move(struct kvm_vm *vm, uint32_t slot, uint64_t new_gpa); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index d0e6b10f140f..d6bfcfc5cdea 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -898,6 +898,43 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint64_t guest_paddr, uint32_t slot, uint64_t npages, uint32_t flags) +{ + int restrictedmem_fd; + + restrictedmem_fd = flags & KVM_MEM_PRIVATE ? memfd_restricted(0) : 0; + vm_userspace_mem_region_add_with_restrictedmem( + vm, src_type, guest_paddr, slot, npages, flags, + restrictedmem_fd, 0); +} + +/* + * VM Userspace Memory Region Add With restrictedmem + * + * Input Args: + * vm - Virtual Machine + * src_type - Storage source for this region. + * NULL to use anonymous memory. + * guest_paddr - Starting guest physical address + * slot - KVM region slot + * npages - Number of physical pages + * flags - KVM memory region flags (e.g. KVM_MEM_LOG_DIRTY_PAGES) + * restrictedmem_fd - restrictedmem_fd for use with restrictedmem + * restrictedmem_offset - offset within restrictedmem_fd to be used + * + * Output Args: None + * + * Return: None + * + * Allocates a memory area of the number of pages specified by npages + * and maps it to the VM specified by vm, at a starting physical address + * given by guest_paddr. The region is created with a KVM region slot + * given by slot, which must be unique and < KVM_MEM_SLOTS_NUM. The + * region is created with the flags given by flags. + */ +void vm_userspace_mem_region_add_with_restrictedmem(struct kvm_vm *vm, + enum vm_mem_backing_src_type src_type, + uint64_t guest_paddr, uint32_t slot, uint64_t npages, + uint32_t flags, int restrictedmem_fd, uint64_t restrictedmem_offset) { int ret; struct userspace_mem_region *region; @@ -1011,8 +1048,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, region->backing_src_type = src_type; if (flags & KVM_MEM_PRIVATE) { - region->region.restrictedmem_fd = memfd_restricted(0); - region->region.restrictedmem_offset = 0; + region->region.restrictedmem_fd = restrictedmem_fd; + region->region.restrictedmem_offset = restrictedmem_offset; TEST_ASSERT(region->region.restrictedmem_fd >= 0, "Failed to create restricted memfd"); @@ -1030,10 +1067,11 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION2 IOCTL failed,\n" " rc: %i errno: %i\n" " slot: %u flags: 0x%x\n" - " guest_phys_addr: 0x%lx size: 0x%lx restricted fd: %d\n", + " guest_phys_addr: 0x%lx size: 0x%lx\n" + " restricted fd: %d restricted_offset: 0x%llx\n", ret, errno, slot, flags, guest_paddr, (uint64_t) region->region.memory_size, - region->region.restrictedmem_fd); + region->region.restrictedmem_fd, region->region.restrictedmem_offset); /* Add to quick lookup data structures */ vm_userspace_mem_region_gpa_insert(&vm->regions.gpa_tree, region); From patchwork Thu Mar 16 00:31:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4970FC7618B for ; Thu, 16 Mar 2023 00:31:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9DFD6B008C; Wed, 15 Mar 2023 20:31:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C501E6B0092; Wed, 15 Mar 2023 20:31:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A04B26B0093; Wed, 15 Mar 2023 20:31:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 90AAC6B008C for ; Wed, 15 Mar 2023 20:31:31 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7069316125F for ; Thu, 16 Mar 2023 00:31:31 +0000 (UTC) X-FDA: 80572882782.14.96F4540 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf01.hostedemail.com (Postfix) with ESMTP id B016740013 for ; Thu, 16 Mar 2023 00:31:29 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=d8uc3IAp; spf=pass (imf01.hostedemail.com: domain of 3YGMSZAsKCJc13B5IC5PKE77FF7C5.3FDC9ELO-DDBM13B.FI7@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3YGMSZAsKCJc13B5IC5PKE77FF7C5.3FDC9ELO-DDBM13B.FI7@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926689; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=K90xoVX+0RlzLAw3SfN8qTyLgxMNh2Rq4fRe4RbG85I=; b=37HJEOVux0TDY5zZDyWd63vPMxMcpq60WWjpyTTqiavYFOKWsJOQ6gsPIbvxF22GbIkrRn 5EyfQGgIW1kwvPePqHBXY/t2C/HTWBNS+6h3q/KgURqHN1GMMRPSw1gUt3O+jYPtzcahHj N1H8eL3fT0RkGrkAeZfcJH+ZNAht7WE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=d8uc3IAp; spf=pass (imf01.hostedemail.com: domain of 3YGMSZAsKCJc13B5IC5PKE77FF7C5.3FDC9ELO-DDBM13B.FI7@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3YGMSZAsKCJc13B5IC5PKE77FF7C5.3FDC9ELO-DDBM13B.FI7@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926689; a=rsa-sha256; cv=none; b=wj0RlCGybbI/04vrU1toxcNlYVvvAtTdwDOihgHtImf2gtUMzSRIg5N5NhucuvA8AX69iE QfQpEcGsW3xiHs3uwwPfPb7hAIckFrHy9DS8XbazDKBZNOWkAivQBjt8HbvXees0XxkFvD JWZ31JNwIbUyotGU4crC0SljBI4WIls= Received: by mail-pj1-f73.google.com with SMTP id nm11-20020a17090b19cb00b0023d0c90d851so71665pjb.1 for ; Wed, 15 Mar 2023 17:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926688; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=K90xoVX+0RlzLAw3SfN8qTyLgxMNh2Rq4fRe4RbG85I=; b=d8uc3IApbYmz26P2pZurWd/mdMnPn+5Qfc7rz6kuRm/Rdx7nODA9CSqEzNbHzvos3x RveM5uzlBa4alqsey/A+ZQ+F9FkBIhKp+vzmydZ7x8yVdpJ1dFg58aZJtFtCTBrdqTeM jtglH5cHaz9xRzfcMN6bC6InRMKXNsMGC/lp63mFpBGrilMy6mUNN3C7pjzFUdepgkuU +cgfLXerxqml3OAS1MvZtFFYDjNKV6KkSDelOKwW/Ftb9Njw0KqVRUjV1fgWAjc/PHx5 vlmTiVMmyjWJKxE37zalK36nTXI7Daq2qNoskHBh/u2Z2VdJEZ3uNpydLhqA1aIDw3qB CSMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926688; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K90xoVX+0RlzLAw3SfN8qTyLgxMNh2Rq4fRe4RbG85I=; b=sdT1SAx6bxN2bno4+Bvkc0UP2MWRsRNEq5YaRlk6e0m1GeMzF0Aey8ZCfE9lKArjvB nLZ3AJLMEILkj/zSzTRUfdMLWEJDhafiWIYnpORasy+6yH4XrY9ndDUTZBGCcXuoIXmM BQDyYGend5VjqrtPwZUd+IhUlwlF9fNT4H/kYqDUJZ1rc/pP+mes3Zm07hBPsywFga8A 3sKtriPst9tXz062pshbD34GK9LvA3Fiv9XCmKnuwRRhtw1Bt7IvSwpVYLAjt/JNEd/c lZAsHbi7/XrlA5BJMcFLfOSrmkSGaTWcnV6Wo4/aZnLjRSprEbe9YOWcnoC6RhAfteuw KvaQ== X-Gm-Message-State: AO0yUKVERXiz1eM2agUgX97D8x6kJHyjuusY8LbuIQZhr/Z9NQ5xeFqe jyKV03ktwzQN+fyFSu8Rv5qVJyzC1qfaX+9DbQ== X-Google-Smtp-Source: AK7set81FNM6aZ2KKc0RpczFG5Lx+WgCWICz/KzlEJw1NjziYveSgQLqdoN474MmozxZF5HPAo3b3AmF9lnSjz983g== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a05:6a00:198d:b0:5a9:9713:1dc with SMTP id d13-20020a056a00198d00b005a9971301dcmr677531pfl.6.1678926688561; Wed, 15 Mar 2023 17:31:28 -0700 (PDT) Date: Thu, 16 Mar 2023 00:31:01 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: <287d6e84dc788d84599392ca5d65864201f9a6a4.1678926164.git.ackerleytng@google.com> Subject: [RFC PATCH 08/10] KVM: selftests: Default private_mem_conversions_test to use 1 restrictedmem file for test data From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 1cxqqmxerm941fnhxf55m9ca4ki1e7m3 X-Rspamd-Queue-Id: B016740013 X-HE-Tag: 1678926689-57432 X-HE-Meta: U2FsdGVkX1/J+FMm4lzB+90p5c0ymeUgYprf3U3idJkkq8lroZ7wBAQt3kS+qj56U3LLbLT4pllVeDuNi+V4T5JsDdvBo6QauDd3vzjq6gAlR084I8FeXr248q6NuaVLKBeZ3pQU92eeRtIQvFTm/U/vS6hkToib6lPZ1HNRaFN4scsSqMXaH/rjTfBIS89FPOFv/0wobpVuXIEmRCFhENSkqspLUlOC0lOl6l2ng8uTeDBUjQNTi144U6WPXWhR5IE8nuJC+br11mjNFk1l2bH6S8y3bCbNPj/fn6do3sPAMeWOzwb7b/uR7MKUN3368hnyuvIC1UX6JAdw7Is7khC4CYXvsGbZunwdTnNxiGzZuIc6y5hBr7IwjxiqxqsIpuxbCyuT4GqhyNFvdyeD5OTFiZsRR8XnYWMUE0cnEwAl0ZynHElWJ2MzcYlCA7VbPpFPgjyUNLkIR4RZC3wTWt7mAR68jQhadzakUk0TB+YCJ6ZEHO6BShVfSxHIZzb7mrcB+R44n0NeJ2JCTnSgheE8mFIPJmXEr51UwLvFUCkVNRjViwCGtlfErC3sZS5dKYCbzX9NlTt1H388dJ0HOjUu23Ap9BTi0LkTMmuF64M4g7FEbuePJiD0p6zYmx8sYIiKrLnqTSs6v40+VSWMLRb3VWqdwogG9XYakeCaBEKsNX3mwCfDtGhGAyESt3PE/RneQ1wFoJVnr+iiQspMENsWRAHT0p7czDOa9yRDd2yoSxeLkOea9snfC+8AC6ly6z3+1jLB8NMO3UHuE0qL+YSzukAWt7Dr82LAaeJ721A9yqhOPtgYcxbeqJMqT9a2WJxu1hcEbY84lxnwQrHF5nH1xgkViSAUWk8UwyqYXuM2ZLHJfuVj+SSx2DDVbE76QDjpSvMiPP7gJhAqm0nFscKXvpqi+hSTmWT8+RYm2/IvSeutZiiWT8q/tnTdQQPcQQdTifRTt/WQ5bL/QPA 2BBv/ohG b8efJh3/fpz5Q3KSiidVCdFNiHZ0UXEB479bxWpoWWbNP/Rcmed0MHZc5FowZhW1V7BNUTsXau3tkx44IFGGXoCqxp/qpyUZq5j7bySk4KEQaJyrCO8Q/uHPWH2tlmKeVv2zTA3iw7GhHY7/L97kZHEZGFW88GPaDE6ojYT9JAJW02lylocsfXOL6jWMQi0p/xTeDiqcJKjfPtJxDpdHdwV9sHzDI+RPmvkE4Kfl2YQIIKmtj98k3EsV+b6J/oEeTngVuSaLShm9RMIE2wFTyhopYcYIWq31eGnrlPi9xStCbxSj7Q3H8yvGT6voyQIX69Oi9yPu8qlHIsoWKaueoocIZdm+C7yzIi4eOlEvg0l7UnHyC5x9CHkU80W1wmOKOVoXm9wtbG96P2vzrTIy/IEmc/0l9gb5ZBY+/DLO0thTA79/GQgR/73lNNVbD252Hl710O3vMvuEAAy2DUYp3HiqdxVHtIONxBRyZlKXUs5o4fDsLVAYoKxoHkZ+buqj+9XNRfA6NwDDhi1Ci+tQ7FSfLfyi45cGrGQgla1zh8m9NeP+evL02M9yTw1gn1BqEKNex+qYCjj79EYQduvqoyD3gys+TDzgHLTL7C2eTf30m0TAWM5gY1uUJlNaiqqhG07e0sKhNj2wI7fUr6cCDuIV8d2nYO7ymqH3h2zlIgMsYj2qliGPWl/MVi5d6wtcHvao+4XkPMg6n980= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Default the private/shared memory conversion tests to use a single file (when multiple memslots are requested), while executing on multiple vCPUs in parallel, to stress-test the restrictedmem subsystem. Also add a flag to allow multiple files to be used. Signed-off-by: Ackerley Tng --- .../kvm/x86_64/private_mem_conversions_test.c | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c index afaf8d0e52e6..ca30f0f05c39 100644 --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c @@ -324,7 +324,8 @@ void *thread_function(void *input) } static void add_memslot_for_vcpu( - struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint8_t vcpu_id) + struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint8_t vcpu_id, + int restrictedmem_fd, uint64_t restrictedmem_offset) { uint64_t gpa = data_gpa_base_for_vcpu_id(vcpu_id); uint32_t slot = DATA_SLOT_BASE + vcpu_id; @@ -336,7 +337,8 @@ static void add_memslot_for_vcpu( static void test_mem_conversions(enum vm_mem_backing_src_type src_type, uint8_t nr_vcpus, uint32_t iterations, - bool use_multiple_memslots) + bool use_multiple_memslots, + bool use_different_restrictedmem_files) { struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; pthread_t threads[KVM_MAX_VCPUS]; @@ -356,21 +358,28 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, vm_enable_cap(vm, KVM_CAP_EXIT_HYPERCALL, (1 << KVM_HC_MAP_GPA_RANGE)); npages_for_all_vcpus = DATA_SIZE / vm->page_size * nr_vcpus; + virt_map(vm, DATA_GPA_BASE, DATA_GPA_BASE, npages_for_all_vcpus); if (use_multiple_memslots) { - for (i = 0; i < nr_vcpus; i++) - add_memslot_for_vcpu(vm, src_type, i); + int fd = memfd_restricted(0); + int offset = 0; + + for (i = 0; i < nr_vcpus; i++) { + if (use_different_restrictedmem_files) { + if (i > 0) + fd = memfd_restricted(0); + } else { + offset = i * DATA_GPA_SPACING; + } + + add_memslot_for_vcpu(vm, src_type, i, fd, offset); + } } else { vm_userspace_mem_region_add( vm, src_type, DATA_GPA_BASE, DATA_SLOT_BASE, npages_for_all_vcpus, KVM_MEM_PRIVATE); } - virt_map(vm, DATA_GPA_BASE, DATA_GPA_BASE, npages_for_all_vcpus); - - for (i = 0; i < nr_vcpus; i++) - add_memslot_for_vcpu(vm, src_type, i); - for (i = 0; i < nr_vcpus; i++) { args[i].vm = vm; args[i].vcpu = vcpus[i]; @@ -382,7 +391,7 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, for (i = 0; i < nr_vcpus; i++) pthread_join(threads[i], NULL); - if (!use_multiple_memslots) + if (!use_multiple_memslots || !use_different_restrictedmem_files) test_invalidation_code_unbound(vm, 1, DATA_SIZE * nr_vcpus); else test_invalidation_code_unbound(vm, nr_vcpus, DATA_SIZE); @@ -391,8 +400,9 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, static void usage(const char *command) { puts(""); - printf("usage: %s [-h] [-m] [-s mem-type] [-n number-of-vcpus] [-i number-of-iterations]\n", - command); + printf("usage: %s\n", command); + printf(" [-h] [-m] [-f] [-s mem-type]\n"); + printf(" [-n number-of-vcpus] [-i number-of-iterations]\n"); puts(""); backing_src_help("-s"); puts(""); @@ -404,6 +414,9 @@ static void usage(const char *command) puts(""); puts(" -m: use multiple memslots (default: use 1 memslot)"); puts(""); + puts(" -f: use different restrictedmem files for each memslot"); + puts(" (default: use 1 restrictedmem file for all memslots)"); + puts(""); } int main(int argc, char *argv[]) @@ -412,12 +425,13 @@ int main(int argc, char *argv[]) uint8_t nr_vcpus = 2; uint32_t iterations = 10; bool use_multiple_memslots = false; + bool use_different_restrictedmem_files = false; int opt; TEST_REQUIRE(kvm_has_cap(KVM_CAP_EXIT_HYPERCALL)); TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_PROTECTED_VM)); - while ((opt = getopt(argc, argv, "mhs:n:i:")) != -1) { + while ((opt = getopt(argc, argv, "fmhs:n:i:")) != -1) { switch (opt) { case 'n': nr_vcpus = atoi_positive("nr_vcpus", optarg); @@ -431,6 +445,9 @@ int main(int argc, char *argv[]) case 'm': use_multiple_memslots = true; break; + case 'f': + use_different_restrictedmem_files = true; + break; case 'h': default: usage(argv[0]); @@ -438,6 +455,13 @@ int main(int argc, char *argv[]) } } - test_mem_conversions(src_type, nr_vcpus, iterations, use_multiple_memslots); + if (!use_multiple_memslots && use_different_restrictedmem_files) { + printf("Overriding -f flag: "); + puts("Using just 1 restrictedmem file since only 1 memslot is to be used."); + use_different_restrictedmem_files = false; + } + + test_mem_conversions(src_type, nr_vcpus, iterations, use_multiple_memslots, + use_different_restrictedmem_files); return 0; } From patchwork Thu Mar 16 00:31:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FE9FC7619A for ; Thu, 16 Mar 2023 00:31:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76EBC6B0093; Wed, 15 Mar 2023 20:31:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71F056B0095; Wed, 15 Mar 2023 20:31:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FB2A6B0096; Wed, 15 Mar 2023 20:31:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 38C1C6B0093 for ; Wed, 15 Mar 2023 20:31:33 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EAAF912110E for ; Thu, 16 Mar 2023 00:31:32 +0000 (UTC) X-FDA: 80572882824.29.E81839B Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf20.hostedemail.com (Postfix) with ESMTP id 2C7221C000D for ; Thu, 16 Mar 2023 00:31:30 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bOjlcixb; spf=pass (imf20.hostedemail.com: domain of 3YmMSZAsKCJk35D7KE7RMG99HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--ackerleytng.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3YmMSZAsKCJk35D7KE7RMG99HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926691; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xKXEz6/mGmWtcTzhu61L6SyW9ch3P6ySrkhZdBbEs24=; b=gHnM4QeyZRNUKS7/gFZ13rLjeQvSTSXAeHkdAovJPN9OaBxa0vTNl6WodWZsqTN0+Qxh3u pF5cVBqh0nvw56kUsfj2nKnBk0O4ZKk2ke6HaQZc7/Rm4mtUJh7s7wg6VtU+QPbWT3fLrf kHafKj0QMI0ZS1mBIEsfEzAnXVRuy8Y= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bOjlcixb; spf=pass (imf20.hostedemail.com: domain of 3YmMSZAsKCJk35D7KE7RMG99HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--ackerleytng.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3YmMSZAsKCJk35D7KE7RMG99HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926691; a=rsa-sha256; cv=none; b=vkdmdeAUdTng4peit/SFNf0SXc/36DKs1te/QSVMYuLeGXjt6COkHXpGPW1YK5g/J2n7jJ v38RTYuVNidSodXHUo2oznF788jsrg30KYkvKIg0MfiFKrHQfKO1HG5ehGXoQIKUtlOtIj sc2/ULLBc6Zlyg00dBeHO434PxVoor0= Received: by mail-pl1-f202.google.com with SMTP id u11-20020a170902e80b00b001a043e84bdfso6193040plg.23 for ; Wed, 15 Mar 2023 17:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926690; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xKXEz6/mGmWtcTzhu61L6SyW9ch3P6ySrkhZdBbEs24=; b=bOjlcixbSYLhJ8wlZFJqykn9M5Vc0cFpb5g7LhT4djxRWIFNy4JccJg4iGmlnPSQyG lJkRIlzLGQZ3CT8tV3X05ZRlfpMlsWsYm10BZk0r/Rv+yvfQdYk0fGtvbClQaHHaYv5l Oj+/kJI0SJy2+jeH1DiW21OupNOPFM9Wh7wNdPPay5eUxl09yuqaKdEkkyKrOhWCrZJX e3EV/eGevF9LE/ooEptOTOPMZBAmj7BKZBkDjiPROvuVe+4bwZbAe4m1RyZsPF9uX6pM WIBv4RjDLE054xRE18NVAkWPZAWP+NMIosMPzwAwGqSXU4pxgbXQRbLdQ2u4zKCbVIO2 DV9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926690; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xKXEz6/mGmWtcTzhu61L6SyW9ch3P6ySrkhZdBbEs24=; b=HM9+eGXpAG4vKTz+60yXdNuLI0u0ozwRGdEcgFUNbILxRw+XkFOqPWPN2xm3ee48wq i8dOKRPDwFZojULOWCcR783kjxSfJIFfy/6pcaK1bd+9O656bv65sp4IkfZC3u1n18UZ 3FgW8w+h1iXAtP12C1rhzG9YyoJZqoNs2nufNF7qBB2QIxicsvssRUHABSydVIzdk+Tm x+2Ga62ItMPbSfCIPtJ4vxMTaumu2BGsQ+Y5IifB5MVxfdEJxeTeKvviOdhaadTxICbb 92V0+KgUV4RuQsy+pEOb8xrEbHjic6oaVviwOJDLsf97aYQNXNW5o33hlz7Sf391WENr 1qFA== X-Gm-Message-State: AO0yUKXMMnskTDIXj862WDmv/Tq/6f7U0upQy6PO944dVe2tjfFk02Z+ 52cVb2RDprLiJS6h+mOWMB5Tx4Wa9IwT0CV8Mg== X-Google-Smtp-Source: AK7set8gW1ruUe+jZfx4vo3AOKGV2qgKk/o0c2WgfJNyT6l/gKi5/qNPPNY0SZ250Rg6tfQ0OBKmkU3mHKKgzrPR/w== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a65:6392:0:b0:50b:cc91:5534 with SMTP id h18-20020a656392000000b0050bcc915534mr320262pgv.2.1678926690322; Wed, 15 Mar 2023 17:31:30 -0700 (PDT) Date: Thu, 16 Mar 2023 00:31:02 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: Subject: [RFC PATCH 09/10] KVM: selftests: Add tests around sharing a restrictedmem fd From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2C7221C000D X-Stat-Signature: x3ohfuxy4h6mizokryyjkr45ojf9i6hb X-HE-Tag: 1678926690-357026 X-HE-Meta: U2FsdGVkX1+QeoMLO7xlBGLvr5KQ5ivXXgaUiBIf96P1at/Gkx4Ryuwg1kRvxfAoqQKJbVYe6B4j7h95VgD5RjYfRUv/qp3Ct1cFgDJNQmnMwyA3RIlc/bB01T9jry5Silgp/3Q34y8cjrBLg1oT6ybvWMrvOkc6i+67AYnx3F5F7aKLM0uBv/OZM98ZJRHXlINeXhe+7Cag9K53JeCjy4Po+AIFMaTYYtLJSK+kNbFkhcBj6BOQv989Nb/qA9yWSzMeAcFOVpfYq2a0ILSot97Ub8OmmClbt9UvtFvuTrHjPklJ1nuXqfdwkCqbfVBKZL/riqEFcgwU3h6gXmpLO1oU1KyZNNa/mh4whWoQn4Zil61R/JQE5fR7iNxN3Mwe+2Y+LUko7HVLrs7MlFP6sXsAtLKDp0GZLqtzvrGLNY8fI2yGHCe7Rwt/Uv4wvFLvREDhjSr+otBzjMfwA5VQTp54+EHvD+6fPjZYGHUProGXKsDnslcWUK+vxAJrv/NX0rUqvr5d/v0FvPv8TN8mupYHBMkvJczKPjr/T4SPvkYwDUkboC4ZVVRR0j3kH5xxvXNBbqwSm0n3LttedVyjqn++SiegMFwZRjTvMf9v+sz0eCH3EpWqk5HbA57tLv2V6oZhe42gJNiWxImjwuDxue6+rwc0DdqQTDPU/+dfUsBpebrr5/Jhk7BwoISqS+VSPkExAw3X8pfJoorpsSDF22wwPdSaWQT5/IOZHMuoy7kfDTsXqq7HIk20dhGXEoDfcqhyPFDgSxTxcJGMCYpWL9LY/TrgN3KmI0nMowvA6K3R0K86F7ML2y1/ujoJLGJuar+DerRRzBhPGqGDHy9YIOekHj/4EB6Sy9Rz53dH5O3USMWhwMj4UBes3PMV6FCFAbFi31pf5VGTC7/CWVnNKVLCEaOuGfehRdgrn761oshtpECiTC4OSDkE+Sy9GOt31jYJ0QJsRZ4Qeig82Wn Al50PjRw jAkgxa4xrLEbC2FG79QwH1YLyKjZ3epM6aR5Q95O14MYU6TDIV51TAcN+/+15PhAwQlkg7uRE9637lpjIsMo7gJ25tR+fPuTL3270u/DxcbYd5u5YL388cnmdRpqCzx1CpD/Y7ywJrjB5l5qUXANrrawKjkmCLzwFH0No5H5EBC8NO9BQYVMh0pWdW2A5EBpfQL8vhbNhnN+lFP7gjtQNZoKpDq1HIodFf7LgE/9BP1+FELm1SZADh2Datu/coEKNGqTd423CZnd8AiScq6RqpWKE5rg0x8qB7awoy+3aMpCczpaIc2OYLXE7Yc4rAIUsI7dEq+KA3ZMGF8ZT6/9H/LNx/VUMz83SQdyrzUQ6dlewwvPfLdCR9RnxneBjBRIKyZcmy20N0T1qFdS8Q3TPFY/9OSfXf4V0qqL/9cKIhR1YQrZJ4yzWfI2IBnJShz6TKm7Lheg7qsbQHNkXbBaFF9eICwKFsLm+fxolDPpnKlok63Phw8A2Z0Zqp2Wxda4Q7ortp5DZC/eWKCnHAYUKsyc/MWyiETgkPeZpwCW+Uqd3pmnEskYpJR+HAH0QrgrJysnEBvxTebTbKTBpHJ4O1R/ZND91Eg1fnKD12HbieN+KxEyIogcIPibVB6CYghc+OcmhSsSf+WkIy/0uRusFx6ZjbBa26r+u3YPK X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Tests that + Different memslots in the same VM should be able to share a restrictedmem_fd + A second VM cannot share the same offsets in a restrictedmem_fd + Different VMs should be able to share the same restrictedmem_fd, as long as the offsets in the restrictedmem_fd are different Signed-off-by: Ackerley Tng --- .../selftests/kvm/set_memory_region_test.c | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index cc727d11569e..789c413e2a67 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -401,7 +401,7 @@ static bool set_private_region_failed(struct kvm_vm *vm, void *hva, static void test_private_regions(void) { int ret; - struct kvm_vm *vm; + struct kvm_vm *vm, *vm2; void *mem; int fd; @@ -416,7 +416,7 @@ static void test_private_regions(void) vm = __vm_create(shape, 1, 0); - mem = mmap(NULL, MEM_REGION_SIZE * 2, PROT_READ | PROT_WRITE, + mem = mmap(NULL, MEM_REGION_SIZE * 3, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); TEST_ASSERT(mem != MAP_FAILED, "Failed to mmap() host"); @@ -448,8 +448,31 @@ static void test_private_regions(void) TEST_ASSERT(ret == -1 && errno == EINVAL, "Set overlapping restrictedmem_offset should fail"); - munmap(mem, MEM_REGION_SIZE * 2); + ret = __vm_set_user_memory_region2(vm, MEM_REGION_SLOT + 1, + KVM_MEM_PRIVATE, + MEM_REGION_GPA + MEM_REGION_SIZE, + MEM_REGION_SIZE, + mem + MEM_REGION_SIZE, + fd, MEM_REGION_SIZE); + TEST_ASSERT(!ret, + "Different memslots should be able to share a restrictedmem_fd"); + + vm2 = __vm_create(shape, 1, 0); + TEST_ASSERT(set_private_region_failed(vm2, mem + 2 * MEM_REGION_SIZE, fd, 0), + "Pages (offsets) of a restrictedmem_fd should be exclusive to a VM"); + + ret = __vm_set_user_memory_region2(vm2, MEM_REGION_SLOT, + KVM_MEM_PRIVATE, + MEM_REGION_GPA + 2 * MEM_REGION_SIZE, + MEM_REGION_SIZE, + mem + 2 * MEM_REGION_SIZE, + fd, 2 * MEM_REGION_SIZE); + TEST_ASSERT(!ret, + "Different VMs should be able to share a restrictedmem_fd"); + + munmap(mem, MEM_REGION_SIZE * 3); kvm_vm_free(vm); + kvm_vm_free(vm2); } int main(int argc, char *argv[]) From patchwork Thu Mar 16 00:31:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAA4AC6FD1D for ; Thu, 16 Mar 2023 00:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39EA46B0095; Wed, 15 Mar 2023 20:31:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FF4E6B0098; Wed, 15 Mar 2023 20:31:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12B546B0099; Wed, 15 Mar 2023 20:31:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0436C6B0095 for ; Wed, 15 Mar 2023 20:31:35 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CE30E81379 for ; Thu, 16 Mar 2023 00:31:34 +0000 (UTC) X-FDA: 80572882908.10.12201C8 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf23.hostedemail.com (Postfix) with ESMTP id 1649414000B for ; Thu, 16 Mar 2023 00:31:32 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=W0G3AmVB; spf=pass (imf23.hostedemail.com: domain of 3Y2MSZAsKCJo46E8LF8SNHAAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--ackerleytng.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3Y2MSZAsKCJo46E8LF8SNHAAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678926693; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YxU1hhaZ4SyfL9lxoIcMNBPPAq0yfPS0xuipesTDclo=; b=t0G81g6n571N+jm1rDy+b5jYvgZpkB4dSj2lFUxpp3rzJyXFko+AnkGfjlJXZ3G8EAtEzX ZnUKipl4LpXxdWL5YhM2aWQNQx29u/BKmrvIq1+cXzMyqk313bhvt9x5InMlbUe4hZX6ON i48d9bfyrAQXrlwA+jgcFX3pWggHwNo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=W0G3AmVB; spf=pass (imf23.hostedemail.com: domain of 3Y2MSZAsKCJo46E8LF8SNHAAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--ackerleytng.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3Y2MSZAsKCJo46E8LF8SNHAAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926693; a=rsa-sha256; cv=none; b=SgafrMq39RNiTrw5//4FOreSN/r8P8z1TYkzYzoK9fS+tOKui5Kv9AfntEKc65zj/9T+h4 ploIh9R/I7x3bBvjdCjKWT/nx9ltkvo5BUQXmhR8N6uKsoMwqwbooQ/xPoJocSecuVD+zX xYFA0/Goy1zKSmWLugUKBzAjDRbFeYI= Received: by mail-pg1-f201.google.com with SMTP id m12-20020a6562cc000000b0050bdfabc8e2so15878pgv.9 for ; Wed, 15 Mar 2023 17:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926692; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YxU1hhaZ4SyfL9lxoIcMNBPPAq0yfPS0xuipesTDclo=; b=W0G3AmVBhmaEPW1mzeOzfktEstHk/ayT4Fca4WpYB+uqnQXqFONecZpHfNEM3EVkI8 dMoU+aBolGRnKrvqkSWbCeJFkilUlbcTqWcVH0y2O7kmHEk9EOK0BEV0KFKuPFrnCkbs QOotzJYDWHJggJes5/KIvM96osSnaCvae3qKB3LUHRBB+uNwEOmmHmd8zvTbRGoEVjUL rVFdyBsTEprlo4ciiWa3+M8yKhD16Tn+oY0bqfI0h7Rz5RgpgT08FQynab2lujb51lp7 x7X7TlFctPEGFqxyshGyufJ1XL1Zen+FPj5jvwOG/5BAnYWpY1i72h9z5SjlNs7jYsNa hwdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926692; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YxU1hhaZ4SyfL9lxoIcMNBPPAq0yfPS0xuipesTDclo=; b=YV9V9aYkTmxzHWlrsruRNaMM0VmWOEvzp2VCES3Awuc4jL5u5k6UW3mp2oS/+F+zCX Ggi4lWFW7i3tlWm0ZicpfgvZ05Q2YNAM41M2PxHtTtK4S0seCgluLQTgA2PODnhofzWM CzbkjfkAlhyVtcMkv5aIglELqOnL/sYgkZZqASh6DDlPRjuTujkLvUuryGIPl6ukR/Lp NU6rGYD4tJ/H/pehvAgnyL+KoYiG+QnQ6uFEfaz88chZzMa32mslJorLEX8caGKk3RAY JvCXG7+uOIAi9GC5MdnSBXDqljOSuxiRDZHt0Lq4/4YsYQQ1qQHe2xA4dI6msHSpQv8v ZXeg== X-Gm-Message-State: AO0yUKX5jHsfVzthOh0HRaISl6sCde/n9pSHSCjrYV33O+U+OYLPHN9z Iw4IWH4ZOvHgr6VhlhaRB+ccADLh1nwcCzwgfQ== X-Google-Smtp-Source: AK7set/r1L80ZGqvN1Jqjj7ZwUbt+f+1AOqGwiuE9AJvattpTxM2ZIa1Wyqx7LP6pavKwLlYqhK3jR4rdgiNHjRokg== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a65:530d:0:b0:502:fd12:83ce with SMTP id m13-20020a65530d000000b00502fd1283cemr347381pgq.5.1678926691968; Wed, 15 Mar 2023 17:31:31 -0700 (PDT) Date: Thu, 16 Mar 2023 00:31:03 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: <90aaa4ab85fa5e3d5641793e2a4873282eb16556.1678926164.git.ackerleytng@google.com> Subject: [RFC PATCH 10/10] KVM: selftests: Test KVM exit behavior for private memory/access From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Stat-Signature: 6jurbcj4iubpf9czxipu71c14wf4z5db X-Rspam-User: X-Rspamd-Queue-Id: 1649414000B X-Rspamd-Server: rspam06 X-HE-Tag: 1678926692-853810 X-HE-Meta: U2FsdGVkX19+xahzLbphql5kCFCLSFiSdXv/WeRYB5gbwGIf5ivARP9OFYMX68jYRZtalMSFijlKMGnmmrjj1BZnYas+Co4LGTe+rme8Cy7iQkNQpvQAhmug811tosxV2he3AsB9VRcojFO08lnHvHgV/tN1eRlvIjWjJKT22hVEDCZBJz7/XOFJRCTEi4wzE+5I6jzCcRWu5tvV0FATMnIYcCAnI6jOm5cMZPwqa8lHNRkXD26t5PBXt68KEsLroku8e+YmmFrVYeweESRN0pW8h/vUHCOx6Uhtj3t5ypZYd/24q1ytGQBHafXRb0RatdadxbvLNK28MJSo1nFL5sXVRzOyR68afAnncSWyrGUdcfVID+jMvDp0x+/T6Y5WLSr7TDW45OROeS07sZBsHl8CNR/b06U3fK784fPb9xKMYWWvED7VsyculxSS5pOVF0AVg01Q+8GoFNMcmj55fQ74dbAQlBjFYR9wXAdihpQD3NH2gBjkYX6H6gtb5QfbkYsoBTguVMONh5jg90TYAO/6g8pAKW1Gi3mMJOcJ76UbcRiiWTTevfzFSXWGf8flPWpfPQucOMnH4CIZ2iqeuRV3Mz8SaUJXfR7qcfjk5iHuG4VC0QjWwgjDFGcsE6oWcPRH+BAH9JpG4YBqMVCYtxHaHQgF8zGMBQs+HRmi7zlk6Z2jf/rSepH2itKZNUhrY8HST72FygjykmeBz9xXJ1jh9LUMI+7gd6+GO5cHO7V0cIauNK5BJmW+G3rS0ER7pYbToMM32TR0/fqfEt4U5bpcPgcQ1u1ULxhCoLSsVOkC22LamfSQoLk7h836ktj489OcgBe9yDyYdk5zEAZltGp1zQ/zrD9rMSay3YNKgNpfqnvt12s5PmgYXzAK8syuajXDJQxsYZnGxe19yCVNjNmgG6uHmW7sBBBBTh37LbZcz9W0nxD+252g3kkKY+nF6AOVbObW+iRtTJgs960 iTdAegOn lQDmeIAsXavvUR2lOLJB6+TWiuqFAf0Aad+zyzURNqiMOhv60SG0Tzn6TwMiKE6ESz8YHDgxUfH2MUbvzIllOIIBXZXMwajDWeN5vqPKEZkvapDX7TnIjdLfMuUYpc1Obn15NXvLwWoy//n3qULhas/dfJezD6q0dAjHZdqXKN7Edj59Ho6UFatfMT9x9jPERqwgws2SmdziVW1kl+jMBf/j2OJnnQzkIHgyVqXoPTpLP2Gi8Ti0QL4FE0Tr+bq/C8FdWBkcMYohTcAWpBXl4sZFCg0GINOM65VIohlrIWSE67xwcU9GPLbsrKen8oNzdRMXsZVsO8HZgkmihwnTN2G82u3J/cteuiI1q7HRi+50zdn6mdWnd+A2gdV0Do4JhzmZm88s5A3pZuWqhuNNrmDsF8vK79CpTIQKmQS9O3rdsoWj73zSUlfm5ZYMt79QO1m/MCOvopVjksB191BgUnzehhaEmZq2YFj1kny+YMfgIAc9+sH47jcxAUFS4KJIPwbxaZ1uy8O99z+WsbXkK5P4uebzLClLfzuqZJtvMj+AFGq4ozePJvBltiHvYtwIdw/T7RGhN8jIYca1CmlPDc6lr1RE8ENfjqva/NSb7yQXbRkAYaGUkp8/K0w3D+4C3gWY7v0dMbsbOhtidrwZKhMr8hKUA40/vxweG X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: "Testing private access when memslot gets deleted" tests the behavior of KVM when a private memslot gets deleted while the VM is using the private memslot. When KVM looks up the deleted (slot = NULL) memslot, KVM should exit to userspace with KVM_EXIT_MEMORY_FAULT. In the second test, upon a private access to non-private memslot, KVM should also exit to userspace with KVM_EXIT_MEMORY_FAULT. Signed-off-by: Ackerley Tng --- tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/private_mem_kvm_exits_test.c | 124 ++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/private_mem_kvm_exits_test.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index bafee3c43b2e..0ad588852a1d 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -80,6 +80,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/nested_exceptions_test TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test TEST_GEN_PROGS_x86_64 += x86_64/pmu_event_filter_test TEST_GEN_PROGS_x86_64 += x86_64/private_mem_conversions_test +TEST_GEN_PROGS_x86_64 += x86_64/private_mem_kvm_exits_test TEST_GEN_PROGS_x86_64 += x86_64/set_boot_cpu_id TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test TEST_GEN_PROGS_x86_64 += x86_64/smaller_maxphyaddr_emulation_test diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_kvm_exits_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_kvm_exits_test.c new file mode 100644 index 000000000000..c8667dfbbf0a --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/private_mem_kvm_exits_test.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2022, Google LLC. + */ +#include "kvm_util_base.h" +#include +#include +#include +#include "kvm_util.h" +#include "processor.h" +#include "test_util.h" + +/* Arbitrarily selected to avoid overlaps with anything else */ +#define EXITS_TEST_GVA 0xc0000000 +#define EXITS_TEST_GPA EXITS_TEST_GVA +#define EXITS_TEST_NPAGES 1 +#define EXITS_TEST_SIZE (EXITS_TEST_NPAGES * PAGE_SIZE) +#define EXITS_TEST_SLOT 10 + +static uint64_t guest_repeatedly_read(void) +{ + volatile uint64_t value; + + while (true) + value = *((uint64_t *) EXITS_TEST_GVA); + + return value; +} + +static uint32_t run_vcpu_get_exit_reason(struct kvm_vcpu *vcpu) +{ + vcpu_run(vcpu); + + return vcpu->run->exit_reason; +} + +const struct vm_shape protected_vm_shape = { + .mode = VM_MODE_DEFAULT, + .type = KVM_X86_PROTECTED_VM, +}; + +static void test_private_access_memslot_deleted(void) +{ + struct kvm_vm *vm; + struct kvm_vcpu *vcpu; + pthread_t vm_thread; + void *thread_return; + uint32_t exit_reason; + + vm = vm_create_shape_with_one_vcpu(protected_vm_shape, &vcpu, + guest_repeatedly_read); + + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, + EXITS_TEST_GPA, EXITS_TEST_SLOT, + EXITS_TEST_NPAGES, + KVM_MEM_PRIVATE); + + virt_map(vm, EXITS_TEST_GVA, EXITS_TEST_GPA, EXITS_TEST_NPAGES); + + /* Request to access page privately */ + vm_mem_map_shared_or_private(vm, EXITS_TEST_GPA, EXITS_TEST_SIZE, false); + + pr_info("Testing private access when memslot gets deleted\n"); + + pthread_create(&vm_thread, NULL, + (void *(*)(void *))run_vcpu_get_exit_reason, + (void *)vcpu); + + vm_mem_region_delete(vm, EXITS_TEST_SLOT); + + pthread_join(vm_thread, &thread_return); + exit_reason = (uint32_t)(uint64_t)thread_return; + + ASSERT_EQ(exit_reason, KVM_EXIT_MEMORY_FAULT); + ASSERT_EQ(vcpu->run->memory.flags, KVM_MEMORY_EXIT_FLAG_PRIVATE); + ASSERT_EQ(vcpu->run->memory.gpa, EXITS_TEST_GPA); + ASSERT_EQ(vcpu->run->memory.size, EXITS_TEST_SIZE); + + pr_info("\t ... PASSED\n"); + + kvm_vm_free(vm); +} + +static void test_private_access_memslot_not_private(void) +{ + struct kvm_vm *vm; + struct kvm_vcpu *vcpu; + uint32_t exit_reason; + + vm = vm_create_shape_with_one_vcpu(protected_vm_shape, &vcpu, + guest_repeatedly_read); + + /* Add a non-private memslot (flags = 0) */ + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, + EXITS_TEST_GPA, EXITS_TEST_SLOT, + EXITS_TEST_NPAGES, 0); + + virt_map(vm, EXITS_TEST_GVA, EXITS_TEST_GPA, EXITS_TEST_NPAGES); + + /* Request to access page privately */ + vm_set_memory_attributes(vm, EXITS_TEST_GPA, EXITS_TEST_SIZE, + KVM_MEMORY_ATTRIBUTE_PRIVATE); + + pr_info("Testing private access to non-private memslot\n"); + + exit_reason = run_vcpu_get_exit_reason(vcpu); + + ASSERT_EQ(exit_reason, KVM_EXIT_MEMORY_FAULT); + ASSERT_EQ(vcpu->run->memory.flags, KVM_MEMORY_EXIT_FLAG_PRIVATE); + ASSERT_EQ(vcpu->run->memory.gpa, EXITS_TEST_GPA); + ASSERT_EQ(vcpu->run->memory.size, EXITS_TEST_SIZE); + + pr_info("\t ... PASSED\n"); + + kvm_vm_free(vm); +} + +int main(int argc, char *argv[]) +{ + TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_PROTECTED_VM)); + + test_private_access_memslot_deleted(); + test_private_access_memslot_not_private(); +}