From patchwork Wed Feb 10 23:06:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EB0DC433E6 for ; Wed, 10 Feb 2021 23:07:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E20164EE0 for ; Wed, 10 Feb 2021 23:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233746AbhBJXHS (ORCPT ); Wed, 10 Feb 2021 18:07:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233201AbhBJXHP (ORCPT ); Wed, 10 Feb 2021 18:07:15 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B9E1C061756 for ; Wed, 10 Feb 2021 15:06:35 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id i2so4266935ybl.16 for ; Wed, 10 Feb 2021 15:06:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=9BlnMuser/5aLl05HhZkUCOrJicW6mziHT+6ZDrlT3k=; b=uD1oQi/XgHbJocPshzs4uxf+8sEIkro4p5Pt6vXNMqYLjlqe7BKcGvmCkZmmxD9Q4T wXBY79Rz46BuMW3PGaUq8FwjrtCi1c/qtKrzgyDyLcqiIq0emOGRzByh+8xIpA30AyO1 UqAqut7h1XH1rAxFoS1xiNPsCEY/ehI2LbXTJsp0h/WscqbgmrvJdn8ZTQsZ8Q32sSLP fgRPATFHbio9RIPXxyyTS7V1Amf9fWGKySQhYk3dERXY4eqiRLIsVowri/OR/Rjo8nM7 1AFetEyynXOUZRMLhbm6oWjwgBURqLMxlQWlAGGWXy2Uk7VNnjh66h1TAdLSMg54Tuj7 R1NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=9BlnMuser/5aLl05HhZkUCOrJicW6mziHT+6ZDrlT3k=; b=LkpyYE2SPO4zqB6JltzYm6/QmyUFUpNMujWNn0bsb9oUpnLD+TLCodigelOUK24+uM giWFcARdVWDPQ+8pTUwvpispDHN/Vbf2TS+ctMCGEjxz0OoIms4LRF2o9Csr24ovbt29 X2tuh0LzQ++XhHYWJ6l4Jj7F/W0wbS56ZJTW11O08FDG0ePSVW9oIPGETsgM5tk/ayv1 HX7WjiHI0wH6GZXaEb8u/x773cFuF45QpDO48fSHiv3YGZ+3u0qnPn6zIvNKNEabVt5y XV/7fMNTMAK0W2uTMfG02V/ABTszwCJ12SkwVi9YzFm8XKHeuZc4EMe6dTkuaLY1uT7r DCug== X-Gm-Message-State: AOAM530kp43vGaGe0FnDjvdTnk92bs67YmQASblwkerDjuUwVr5uCDod QVMQ3b9QHPASZCDLQ27YoK740L4uGVc= X-Google-Smtp-Source: ABdhPJxQOWTkw0mcemLh5AcZugeeMfQsDqf22jm4kKkdIWXdcBz97VorZWgpRmsZhYmDZnv2WNF+2VGsBzU= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a25:4fc3:: with SMTP id d186mr6925674ybb.343.1612998394331; Wed, 10 Feb 2021 15:06:34 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:11 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-2-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 01/15] KVM: selftests: Explicitly state indicies for vm_guest_mode_params array From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Explicitly state the indices when populating vm_guest_mode_params to make it marginally easier to visualize what's going on. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/lib/kvm_util.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index d787cb802b4a..960f4c5129ff 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -154,13 +154,13 @@ _Static_assert(sizeof(vm_guest_mode_string)/sizeof(char *) == NUM_VM_MODES, "Missing new mode strings?"); const struct vm_guest_mode_params vm_guest_mode_params[] = { - { 52, 48, 0x1000, 12 }, - { 52, 48, 0x10000, 16 }, - { 48, 48, 0x1000, 12 }, - { 48, 48, 0x10000, 16 }, - { 40, 48, 0x1000, 12 }, - { 40, 48, 0x10000, 16 }, - { 0, 0, 0x1000, 12 }, + [VM_MODE_P52V48_4K] = { 52, 48, 0x1000, 12 }, + [VM_MODE_P52V48_64K] = { 52, 48, 0x10000, 16 }, + [VM_MODE_P48V48_4K] = { 48, 48, 0x1000, 12 }, + [VM_MODE_P48V48_64K] = { 48, 48, 0x10000, 16 }, + [VM_MODE_P40V48_4K] = { 40, 48, 0x1000, 12 }, + [VM_MODE_P40V48_64K] = { 40, 48, 0x10000, 16 }, + [VM_MODE_PXXV48_4K] = { 0, 0, 0x1000, 12 }, }; _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES, "Missing new mode params?"); From patchwork Wed Feb 10 23:06:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 861DCC433E9 for ; Wed, 10 Feb 2021 23:07:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4144564ED0 for ; Wed, 10 Feb 2021 23:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233765AbhBJXHW (ORCPT ); Wed, 10 Feb 2021 18:07:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233648AbhBJXHR (ORCPT ); Wed, 10 Feb 2021 18:07:17 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 898F0C061786 for ; Wed, 10 Feb 2021 15:06:37 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id s7so4283402ybj.0 for ; Wed, 10 Feb 2021 15:06:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=u5agusI6ac1ZBmmg02mLrOPHFue6wiHDevsOWTqiwyY=; b=nCnbGdPG+yNhWiOeR88w0ANcwJCfkjyTH8YtC/jZD3yLRLYE4mUjg3Om7/5pXTNNnb 10RSr5D4T7S2RIgqBi4drrXNVKkmOZEknL3snDlEjObJjo3GWdeOmTQ8xl/7CW8g3F6N swsgRPUqr8v10PldITx8F8LQA8EM9rr1jpkkuPJodYa8+O2B9m7zW3d5HvAdehqVPzOo 8Nxaao2qyyeE6/NRgHD5VqyMapsqnqRVMqY8p8uTlF6CLYzD71RXXzYtn7VryQ5Ks00T Onw4pBLrfNn68kjnZpr2YQPTlK3KQ7vf10WP/QsIYk6OG4d1hkb/zwUVc9dKQkStGiE0 Ousw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=u5agusI6ac1ZBmmg02mLrOPHFue6wiHDevsOWTqiwyY=; b=i+Lr3qFe4FTYiLHrucK01IwXq8VzwSgaELmwrgonNYPR6WTZoWAfoZlAJvsUY6e9Th uUttm7OX+No+CdHXu6UTgIuoRsd+OhKxkdHUmG1ZybCk6sb2hn6iBKEV2UNowPl8aGgR Euoou32rTNqJvdeuSGybQ/qmbFUaT3cmSuNDD1yT7J2YtNT4kRrzJ6hmFM+Fjc/f6kxC Xa/p1qa+TLzsHx9gVNaPdsfZrDT/hU/YkNfPb4++IQ1XW5HuUG9vXuCc1ADFa5UepJbc 9W8JeOpbfqqQTTrCM8OGvnvDtcKSb9F0v0PMH31NNQWeujLHOAiCy1Ax9pVqRCB68Qeo yLLg== X-Gm-Message-State: AOAM530YTbLomh1LB7mHXdaGzFasA+bDQsSqqyq8f1Ns6AZm09r8cZXT aebeKRVFoETEur80dEINH05EHfPhDMc= X-Google-Smtp-Source: ABdhPJycTcvRtJ64GeUWyqK0vyZbklWTM01vrk+CfDQE1TBRfeJwQdaWqSFrRvNthsNIZERKrXkxLwkqKbA= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a25:2ac3:: with SMTP id q186mr6830175ybq.213.1612998396762; Wed, 10 Feb 2021 15:06:36 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:12 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-3-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 02/15] KVM: selftests: Expose align() helpers to tests From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Refactor align() to work with non-pointers, add align_ptr() for use with pointers, and expose both helpers so that they can be used by tests and/or other utilities. The align() helper in particular will be used to ensure gpa alignment for hugepages. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/include/kvm_util.h | 15 +++++++++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 11 +---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 2d7eb6989e83..4b5d2362a68a 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -79,6 +79,21 @@ struct vm_guest_mode_params { }; extern const struct vm_guest_mode_params vm_guest_mode_params[]; +/* Aligns x up to the next multiple of size. Size must be a power of 2. */ +static inline uint64_t align(uint64_t x, uint64_t size) +{ + uint64_t mask = size - 1; + + TEST_ASSERT(size != 0 && !(size & (size - 1)), + "size not a power of 2: %lu", size); + return ((x + mask) & ~mask); +} + +static inline void *align_ptr(void *x, size_t size) +{ + return (void *)align((unsigned long)x, size); +} + int kvm_check_cap(long cap); int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap); int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id, diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 960f4c5129ff..584167c6dbc7 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -21,15 +21,6 @@ #define KVM_UTIL_PGS_PER_HUGEPG 512 #define KVM_UTIL_MIN_PFN 2 -/* Aligns x up to the next multiple of size. Size must be a power of 2. */ -static void *align(void *x, size_t size) -{ - size_t mask = size - 1; - TEST_ASSERT(size != 0 && !(size & (size - 1)), - "size not a power of 2: %lu", size); - return (void *) (((size_t) x + mask) & ~mask); -} - /* * Capability * @@ -757,7 +748,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, region->mmap_start, errno); /* Align host address */ - region->host_mem = align(region->mmap_start, alignment); + region->host_mem = align_ptr(region->mmap_start, alignment); /* As needed perform madvise */ if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) { From patchwork Wed Feb 10 23:06:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 503D4C433DB for ; Wed, 10 Feb 2021 23:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23EA864DE9 for ; Wed, 10 Feb 2021 23:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233840AbhBJXIC (ORCPT ); Wed, 10 Feb 2021 18:08:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233412AbhBJXHy (ORCPT ); Wed, 10 Feb 2021 18:07:54 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2E4AC06178A for ; Wed, 10 Feb 2021 15:06:39 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id c12so4250069ybf.1 for ; Wed, 10 Feb 2021 15:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=GEZo8w0hgK50yVJrGIa5NClbFF0q/1wZWPqztqSAI8U=; b=rn5yL60zWHOSQ+4padKHXvkuITHPNRNSNM+Cf+9acwDztaCvEP/GBVQ46b4K61tWUh 0rBN1xLJTmrJEjlUWrvyxWAHzpYRU+matvsXKhc05IbcvNWPj8T75zjBFATONuPPrZxP omSVOmXteiC47KavBtmbXLlzcOdxpao3dOCmu9aeF4UKwlt2bQGEahNFJY4aBRP2PtFc rlr6BsK92Pffqxz8x+FWpJtjLmil2U1AXIjWuvO10GvEQ8DFttN4VfIiO+5fHXVjSRjP NwL5raeTygbl0rz7OCb3GgcHwErhtvIBEGR9Qc3TDbNsP7D8Sj/4OdNyyeNmRr5kUGvI yULg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=GEZo8w0hgK50yVJrGIa5NClbFF0q/1wZWPqztqSAI8U=; b=V17eR4FBZyCHU64SxAS9qb3iOCK5C1sgD2AJPxGEIn6uRAmnIijP1LPBwfH+RUOrbj 7YRO7My4bIuEov1HpIOrQ3f8/i6cm2CDiFupexrhANVbFaRtWywPGJaGk+MEfreamG9x 2+H+yc4g4pqyZMhqrkookCHT9D2257waI0g4WN/B2hU0Ir2jViwG/IjZDgVe095C1R9l lFk0uhznG1Mly0X7vLwUxfR6saWBygaiHZ5X5L0coxVUXUaY402jhwuexyPv4LrmvsP+ 4LDzEqYl+8G79Ft8DjMAfGM5/45Ir6KUrkzFWIBLPL49/wZx9hGDY9CP5Ju0KK0ZkPrE RwaQ== X-Gm-Message-State: AOAM531wTeiD2VCA20u7Re1wJB/H7ykXxpdZXZwG+JHih5HUH2Fxaie+ M99wpOtg6ooqxD4m8Sbc/FzWNhU+Xrs= X-Google-Smtp-Source: ABdhPJyKAtmGiuCuTcqrHgv9sAQanTocQ/PtnpyWOrlk2ZIw5XLV1hGfoeCCdeS0VxjghnW0oJbtesz/eSA= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a25:a241:: with SMTP id b59mr7767318ybi.289.1612998399020; Wed, 10 Feb 2021 15:06:39 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:13 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-4-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 03/15] KVM: selftests: Align HVA for HugeTLB-backed memslots From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Align the HVA for HugeTLB memslots, not just THP memslots. Add an assert so any future backing types are forced to assess whether or not they need to be aligned. Cc: Ben Gardon Cc: Yanan Wang Cc: Andrew Jones Cc: Peter Xu Cc: Aaron Lewis Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/lib/kvm_util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 584167c6dbc7..deaeb47b5a6d 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -731,8 +731,11 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, alignment = 1; #endif - if (src_type == VM_MEM_SRC_ANONYMOUS_THP) + if (src_type == VM_MEM_SRC_ANONYMOUS_THP || + src_type == VM_MEM_SRC_ANONYMOUS_HUGETLB) alignment = max(huge_page_size, alignment); + else + ASSERT_EQ(src_type, VM_MEM_SRC_ANONYMOUS); /* Add enough memory to align up if necessary */ if (alignment > 1) From patchwork Wed Feb 10 23:06:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FD58C433E0 for ; Wed, 10 Feb 2021 23:08:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E000364DFF for ; Wed, 10 Feb 2021 23:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233894AbhBJXIG (ORCPT ); Wed, 10 Feb 2021 18:08:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233831AbhBJXHy (ORCPT ); Wed, 10 Feb 2021 18:07:54 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C2F2C06178C for ; Wed, 10 Feb 2021 15:06:42 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id d194so2976447qke.3 for ; Wed, 10 Feb 2021 15:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=c19kP48HP44DYzRTxNvBkL6r5zKqdROTV6wmdYv7tSc=; b=OwrLzE0kO7weELha4Kp1fyhG7sdykoXrp0hwGwAAbyFvISToZvRacz1aipJVy1fkZU cgbCsaaFfNJ4JdQyKwFr3WMrkI0jYq6noOQD/foIe32KUAa8VdjEK3G+UW54t6hRADdb wycUuoQd7td8LXJMQczRU7OyLqKoh1f0bKv74CLxndstbBo+kocEypj5wHubHb/3e4vF yzuxhUF6i2pk2NHghivBINolGwgbwsRV713qAKG1LQHT3UhYQmx6OlHo3RlRaixnZKhV 9DAQwZ632SXkezIFRW9EEmwd1lKTW8wAt54/RSkjvrzinOCN0/I5/DHLslWvPCgOojxx gQZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=c19kP48HP44DYzRTxNvBkL6r5zKqdROTV6wmdYv7tSc=; b=aacVbCoxrUsgeGXPkVi9U2xEpM2cHThNB3+tu0I4OmfNavG7IJ+cgAkl3YEGahO0CM bA/UDgZLeuk9Ap9qnfnQ9X16bYJxiRafHSf1wWAG2DtsQPW/eDq8qqbLJz2qLxkB0BeI HbCV51+qvQamL8RhWFMTNibhFaJX7SgTVHGz4v0SrwGtcBKeSiaphRuQ9RcPVWhIjwcy zR+P29HW8ERteH4lVVbxuyS/JqMVuTkvrisU6igQIdkV9eYWd+/HVXSPuLKliUbHrmwF SkJSeytGY1B4V9+sX2OS8i5N4y0wmDEinFXnowlsgZwYYvTayRPi+d161VHB012j1aBx YcUA== X-Gm-Message-State: AOAM530X5QEIjPigVIfP/7vwrdP3VXxmZpPDATggOkijao2rZHVOHsYF 676M456usAXs/fRQBc75TptV9Cs8uMA= X-Google-Smtp-Source: ABdhPJwFT6XTMSr0mgp0F4wxa8DFbIUWyWCBFcDFVsnJMDNy8e1Pgi+q+46odnLgegTgvbm111Zk9SL5Sa4= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a05:6214:1144:: with SMTP id b4mr5496535qvt.12.1612998401429; Wed, 10 Feb 2021 15:06:41 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:14 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-5-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 04/15] KVM: selftests: Force stronger HVA alignment (1gb) for hugepages From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Align the HVA for hugepage memslots to 1gb, as opposed to incorrectly assuming all architectures' hugepages are 512*page_size. For x86, multiplying by 512 is correct, but only for 2mb pages, e.g. systems that support 1gb pages will never be able to use them for mapping guest memory, and thus those flows will not be exercised. For arm64, powerpc, and s390 (and mips?), hardcoding the multiplier to 512 is either flat out wrong, or at best correct only in certain configurations. Hardcoding the _alignment_ to 1gb is a compromise between correctness and simplicity. Due to the myriad flavors of hugepages across architectures, attempting to enumerate the exact hugepage size is difficult, and likely requires probing the kernel. But, there is no need for precision since a stronger alignment will not prevent creating a smaller hugepage. For all but the most extreme cases, e.g. arm64's 16gb contiguous PMDs, aligning to 1gb is sufficient to allow KVM to back the guest with hugepages. Add the new alignment in kvm_util.h so that it can be used by callers of vm_userspace_mem_region_add(), e.g. to also ensure GPAs are aligned. Cc: Ben Gardon Cc: Yanan Wang Cc: Andrew Jones Cc: Peter Xu Cc: Aaron Lewis Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/kvm_util.h | 13 +++++++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 4 +--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 4b5d2362a68a..a7dbdf46aa51 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -68,6 +68,19 @@ enum vm_guest_mode { #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT) #define PTES_PER_MIN_PAGE ptes_per_page(MIN_PAGE_SIZE) +/* + * KVM_UTIL_HUGEPAGE_ALIGNMENT is selftest's required alignment for both host + * and guest addresses when backing guest memory with hugepages. This is not + * the exact size of hugepages, rather it's a size that should allow backing + * the guest with hugepages on all architectures. Precisely tracking the exact + * sizes across all architectures is more pain than gain, e.g. x86 supports 2mb + * and 1gb hugepages, arm64 supports 2mb and 1gb hugepages when using 4kb pages + * and 512mb hugepages when using 64kb pages (ignoring contiguous TLB entries), + * powerpc radix supports 1gb hugepages when using 64kb pages, s390 supports 1mb + * hugepages, and so on and so forth. + */ +#define KVM_UTIL_HUGEPAGE_ALIGNMENT (1ULL << 30) + #define vm_guest_mode_string(m) vm_guest_mode_string[m] extern const char * const vm_guest_mode_string[]; diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index deaeb47b5a6d..2e497fbab6ae 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -18,7 +18,6 @@ #include #include -#define KVM_UTIL_PGS_PER_HUGEPG 512 #define KVM_UTIL_MIN_PFN 2 /* @@ -670,7 +669,6 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, { int ret; struct userspace_mem_region *region; - size_t huge_page_size = KVM_UTIL_PGS_PER_HUGEPG * vm->page_size; size_t alignment; TEST_ASSERT(vm_adjust_num_guest_pages(vm->mode, npages) == npages, @@ -733,7 +731,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, if (src_type == VM_MEM_SRC_ANONYMOUS_THP || src_type == VM_MEM_SRC_ANONYMOUS_HUGETLB) - alignment = max(huge_page_size, alignment); + alignment = max((size_t)KVM_UTIL_HUGEPAGE_ALIGNMENT, alignment); else ASSERT_EQ(src_type, VM_MEM_SRC_ANONYMOUS); From patchwork Wed Feb 10 23:06:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7C4AC433E0 for ; Wed, 10 Feb 2021 23:08:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D93964D99 for ; Wed, 10 Feb 2021 23:08:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233225AbhBJXIJ (ORCPT ); Wed, 10 Feb 2021 18:08:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233849AbhBJXH6 (ORCPT ); Wed, 10 Feb 2021 18:07:58 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67BD8C061797 for ; Wed, 10 Feb 2021 15:06:44 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id j128so4258654ybc.5 for ; Wed, 10 Feb 2021 15:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=/D10CsPyV0SuKQhqygo5NqkKV98of4qDPh0B02671yY=; b=p6eFbB4lV84/po/qFsuqgktneKBFo/rdWPBnWdHij7zzm6K8PMOFLAPqOCJv36wE/4 l7WuOWfAhWI1QejNw5yQ43OLcuej3BIfd5lPcxNE3OgTCnUOoF6WjcOLnKNty6n+Ap0f lj5gSFkg7iIFNFW5Q/hNNPBxlY+YcgFKS09YmueZQc2F2EL6uKBb2Kn7txvRVFK0pIQP mMW0869Q9IizM29Pm509hXPM4JFymamPqEnzmvcLCHxwn5k+7uGfpOCnHT5tCq2wLA7K IBqA1IVe0V4NMIEJtaBxHpQTSMafxvECoJ2CGME+Y+yocFlTTvwb09xLNPiDNGduuhhG bXOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=/D10CsPyV0SuKQhqygo5NqkKV98of4qDPh0B02671yY=; b=uBhKCAQ3T2dI6i/PIO5uYDhzZ+OLx9VNBz16FRmxMVwgHxHON/LQAnuoj1lY5J3EiR +MX55gdMKARIawmn4cveBvURyGbCksT/QE1bm71JpcZJe5FFk0An7hjKuGALDDtDErIk iuXkKN0I3k6nO3tTp3PhHLmVBS8C5io1GHvqgtF+APZS+VmT9p/UoswRxoHOErEjRiWE X0oHxijpYJu67aho78K39B9U+SZ1SlPwMpfsRytfleRulrITwHWHqQ54hx2ZjePyFcZE BBw2ooQyT5IM9hsTdFA1WlnCxoxZ3H+7+ROYVxrR5G9TfcV5S1SYpWDxYfhIa+VbEcuO kFDQ== X-Gm-Message-State: AOAM531mPF1g38ib2DBabsSXgx+4/3fpeeS2noDOFHz69Culzd0gjpN1 uJ/IAZJS/m2FcjmTUrEsrnyxwkBSptg= X-Google-Smtp-Source: ABdhPJziAmKySI1rzYdb9feq0O5Fk7tmeqsze9N/hr8LgrlFki/ADyfd+JFTGXW5t1oLWJiizAKMxq7CDA8= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a25:68cf:: with SMTP id d198mr3045894ybc.258.1612998403659; Wed, 10 Feb 2021 15:06:43 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:15 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-6-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 05/15] KVM: selftests: Require GPA to be aligned when backed by hugepages From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Assert that the GPA for a memslot backed by a hugepage is 1gb aligned, and fix perf_test_util accordingly. Lack of GPA alignment prevents KVM from backing the guest with hugepages, e.g. x86's write-protection of hugepages when dirty logging is activated is otherwise not exercised. Add a comment explaining that guest_page_size is for non-huge pages to try and avoid confusion about what it actually tracks. Cc: Ben Gardon Cc: Yanan Wang Cc: Andrew Jones Cc: Peter Xu Cc: Aaron Lewis Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/kvm_util.c | 2 ++ tools/testing/selftests/kvm/lib/perf_test_util.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 2e497fbab6ae..855d20784ba7 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -735,6 +735,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, else ASSERT_EQ(src_type, VM_MEM_SRC_ANONYMOUS); + ASSERT_EQ(guest_paddr, align(guest_paddr, alignment)); + /* Add enough memory to align up if necessary */ if (alignment > 1) region->mmap_size += alignment; diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index 81490b9b4e32..f187b86f2e14 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -58,6 +58,11 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode)); perf_test_args.host_page_size = getpagesize(); + + /* + * Snapshot the non-huge page size. This is used by the guest code to + * access/dirty pages at the logging granularity. + */ perf_test_args.guest_page_size = vm_guest_mode_params[mode].page_size; guest_num_pages = vm_adjust_num_guest_pages(mode, @@ -87,6 +92,10 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) * perf_test_args.guest_page_size; guest_test_phys_mem &= ~(perf_test_args.host_page_size - 1); + if (backing_src == VM_MEM_SRC_ANONYMOUS_THP || + backing_src == VM_MEM_SRC_ANONYMOUS_HUGETLB) + guest_test_phys_mem &= ~(KVM_UTIL_HUGEPAGE_ALIGNMENT - 1); + #ifdef __s390x__ /* Align to 1M (segment size) */ guest_test_phys_mem &= ~((1 << 20) - 1); From patchwork Wed Feb 10 23:06:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E9ABC433E0 for ; Wed, 10 Feb 2021 23:08:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5952764DE9 for ; Wed, 10 Feb 2021 23:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233907AbhBJXIY (ORCPT ); Wed, 10 Feb 2021 18:08:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232692AbhBJXH6 (ORCPT ); Wed, 10 Feb 2021 18:07:58 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACBC4C0617A9 for ; Wed, 10 Feb 2021 15:06:46 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id n62so2963515qkn.7 for ; Wed, 10 Feb 2021 15:06:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=zexaMXro/uaxLhK2Ywnxpp0MxR9oLew721YTh9TC4c0=; b=m+ofpum45E0qQzUCK9BqF/eJF8IGA80dCP1QfNiACUXUp+xm2K/dUceYkdjHQUWUp/ rvu2UecmRFWufyqARJu6NPqBuXWXKrb+yyK3P9awLxiLd5zz5xRPa4B9kon5Sv8640+L Nacd9BMcN2NJOck1+bVJJdZ4FroMm2Eb/Jvc3RBFRrH934AaNCziP62PTOBfEaSwJgE0 LCoKOV67Ja+Vv0SThQnTclLLoCyNLzm3a65DNBeOwZJVFkLwGY/5n9R7n+qbJCX/uWvO t0DWMeaha2V5Up5a0+uLCQICoRhwyQAWpbcvM3OAVOLbx6bsacTkv7oViI/oMC3HIBLO nbDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=zexaMXro/uaxLhK2Ywnxpp0MxR9oLew721YTh9TC4c0=; b=Iqw/A4I4RXWIkxiwCBWSOyxed+jW6K4mQCCyMqfT5xujUP4wR9GJgycXpBejVATQsv Xdji0bORjvmp3jRXqOrZ3voEd+SEVhV8gQUAfLme1RnQ1y6z03Dug2i3QCRgCxvdWNmB kFFybjA3W2Y+s0qgU//Ls2Nqp+lrP2IBdnnZ9QnCLqu9QYBmSuxLAogq53AxGE5n+av4 lBllFZnDd6ldti79QIgIKYdscDyXOi5YrZ/WyPLj4HaTC8GLmpma+9tqEYl5LKGHP0ID e3UKipD+ztiAhf2SEsR1MDyZxy/jbnCFodd0T4tb9kcKPzBTgvfyRukpuOBlWjzbvVcd yQ7w== X-Gm-Message-State: AOAM532Xioto+0TszjxgJ0YQiOH3pV9d4sVxxJeT7Fl4TqQ40MX5UqzH qn7BvX7KY8Lrdc6qjU3xL7K5TtdngA0= X-Google-Smtp-Source: ABdhPJz3HTY7ugKb2RbrHdSjZDB1e7lJMI/wQt32y7nzbR5PZ7MDBvBgIEJ6/0b33NnfIvxHLcZav9vEJD4= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a05:6214:125:: with SMTP id w5mr5212953qvs.20.1612998405853; Wed, 10 Feb 2021 15:06:45 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:16 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-7-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 06/15] KVM: selftests: Use shorthand local var to access struct perf_tests_args From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use 'pta' as a local pointer to the global perf_tests_args in order to shorten line lengths and make the code borderline readable. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- .../selftests/kvm/lib/perf_test_util.c | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index f187b86f2e14..73b0fccc28b9 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -23,7 +23,8 @@ static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM; */ static void guest_code(uint32_t vcpu_id) { - struct perf_test_vcpu_args *vcpu_args = &perf_test_args.vcpu_args[vcpu_id]; + struct perf_test_args *pta = &perf_test_args; + struct perf_test_vcpu_args *vcpu_args = &pta->vcpu_args[vcpu_id]; uint64_t gva; uint64_t pages; int i; @@ -36,9 +37,9 @@ static void guest_code(uint32_t vcpu_id) while (true) { for (i = 0; i < pages; i++) { - uint64_t addr = gva + (i * perf_test_args.guest_page_size); + uint64_t addr = gva + (i * pta->guest_page_size); - if (i % perf_test_args.wr_fract == 0) + if (i % pta->wr_fract == 0) *(uint64_t *)addr = 0x0123456789ABCDEF; else READ_ONCE(*(uint64_t *)addr); @@ -52,32 +53,32 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, uint64_t vcpu_memory_bytes, enum vm_mem_backing_src_type backing_src) { + struct perf_test_args *pta = &perf_test_args; struct kvm_vm *vm; uint64_t guest_num_pages; pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode)); - perf_test_args.host_page_size = getpagesize(); + pta->host_page_size = getpagesize(); /* * Snapshot the non-huge page size. This is used by the guest code to * access/dirty pages at the logging granularity. */ - perf_test_args.guest_page_size = vm_guest_mode_params[mode].page_size; + pta->guest_page_size = vm_guest_mode_params[mode].page_size; guest_num_pages = vm_adjust_num_guest_pages(mode, - (vcpus * vcpu_memory_bytes) / perf_test_args.guest_page_size); + (vcpus * vcpu_memory_bytes) / pta->guest_page_size); - TEST_ASSERT(vcpu_memory_bytes % perf_test_args.host_page_size == 0, + TEST_ASSERT(vcpu_memory_bytes % pta->host_page_size == 0, "Guest memory size is not host page size aligned."); - TEST_ASSERT(vcpu_memory_bytes % perf_test_args.guest_page_size == 0, + TEST_ASSERT(vcpu_memory_bytes % pta->guest_page_size == 0, "Guest memory size is not guest page size aligned."); vm = vm_create_with_vcpus(mode, vcpus, - (vcpus * vcpu_memory_bytes) / perf_test_args.guest_page_size, + (vcpus * vcpu_memory_bytes) / pta->guest_page_size, 0, guest_code, NULL); - - perf_test_args.vm = vm; + pta->vm = vm; /* * If there should be more memory in the guest test region than there @@ -90,8 +91,8 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, vcpu_memory_bytes); guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) * - perf_test_args.guest_page_size; - guest_test_phys_mem &= ~(perf_test_args.host_page_size - 1); + pta->guest_page_size; + guest_test_phys_mem &= ~(pta->host_page_size - 1); if (backing_src == VM_MEM_SRC_ANONYMOUS_THP || backing_src == VM_MEM_SRC_ANONYMOUS_HUGETLB) guest_test_phys_mem &= ~(KVM_UTIL_HUGEPAGE_ALIGNMENT - 1); @@ -125,30 +126,31 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, uint64_t vcpu_memory_bytes, bool partition_vcpu_memory_access) { + struct perf_test_args *pta = &perf_test_args; vm_paddr_t vcpu_gpa; struct perf_test_vcpu_args *vcpu_args; int vcpu_id; for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) { - vcpu_args = &perf_test_args.vcpu_args[vcpu_id]; + vcpu_args = &pta->vcpu_args[vcpu_id]; vcpu_args->vcpu_id = vcpu_id; if (partition_vcpu_memory_access) { vcpu_args->gva = guest_test_virt_mem + (vcpu_id * vcpu_memory_bytes); vcpu_args->pages = vcpu_memory_bytes / - perf_test_args.guest_page_size; + pta->guest_page_size; vcpu_gpa = guest_test_phys_mem + (vcpu_id * vcpu_memory_bytes); } else { vcpu_args->gva = guest_test_virt_mem; vcpu_args->pages = (vcpus * vcpu_memory_bytes) / - perf_test_args.guest_page_size; + pta->guest_page_size; vcpu_gpa = guest_test_phys_mem; } pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n", vcpu_id, vcpu_gpa, vcpu_gpa + - (vcpu_args->pages * perf_test_args.guest_page_size)); + (vcpu_args->pages * pta->guest_page_size)); } } From patchwork Wed Feb 10 23:06:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75FCEC433E9 for ; Wed, 10 Feb 2021 23:09:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 532E864EBB for ; Wed, 10 Feb 2021 23:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233927AbhBJXJA (ORCPT ); Wed, 10 Feb 2021 18:09:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232957AbhBJXIL (ORCPT ); Wed, 10 Feb 2021 18:08:11 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07E7DC0617AB for ; Wed, 10 Feb 2021 15:06:49 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id p27so2336967qkp.8 for ; Wed, 10 Feb 2021 15:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=bqMGTJ5vOw+semy7dsWveGKT1K6fm5k0VBXJ6jv82pA=; b=DDPfRlAN3/unXQuVAovsk/1lAj+LjkZkhNvYdbKLUODsxhaiN4I8Oe+oDNQDktWy03 ar7L13rV4vJTXc2WMNN353xkhag1VI84Fq8McGnYrSqH0/29qG06s4od94m7wsDVAAmc asS/uLUCm25RZQHKVBwLbCmqFkZv2UvKEHrrPhV7zUBtgR7WW4RnHvdbCZUleGIuvueY WKCs+49ZHXiHfJ1FUA0nwMQS091YhF9fXmlsM98rcDAFBU6J7VEqD6CvgyI2l7xnchJI 7xkPcSdZHR9Ka+0fHfTe2al7fCT0puVGB1FMkoc5qWPJgSYF5PcBZQUvK/bv/fUeRmiL BKGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=bqMGTJ5vOw+semy7dsWveGKT1K6fm5k0VBXJ6jv82pA=; b=aImRl+p7aJ7ABOPyKR+py0Z8oYh1QqvqSZsjTuA9TfvyZ9KvUFhzKv2qs33oXSSAK4 cYjXUPnwdQ72cVKz1AVhLh3ASePmEcA/qqhJL37PVMpnQULVzPOXLsNxB1TqNeye33n+ Hgz8J/qR6UGgKE2/DiSjU0Yk0pBvXzogGrtJ4QDpOZI5hSN0OeXMZQIxt9t1GUakRjUW N63CnupPswQtn+yfL5YWAyNyWIHNDm96/1fB6YkAtZMCyhi0HsG5fGQU0jP2iUtINDcr vtpURWPT+G3mPZBcvbHiwwpHqTWbAmiOugRhlhzA32yO4nh13NSci1MOxjwBy3P6X/7d kFcg== X-Gm-Message-State: AOAM530iZKZwfiEvpwWF2P1WoTjWSoDW8As6FWpGpcXqQO1TmiXW6/KV JnoEo9sON/tZADy4S2ttyjzpnRPyO84= X-Google-Smtp-Source: ABdhPJyhA7a+URvhu7VOSpiVDgQ2m//y0GtJoyAE28YOf/D8VPHCX01hw7Ld0JOA7f5dn65bckYASMzIgnM= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a0c:e5c9:: with SMTP id u9mr5391387qvm.55.1612998408158; Wed, 10 Feb 2021 15:06:48 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:17 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-8-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 07/15] KVM: selftests: Capture per-vCPU GPA in perf_test_vcpu_args From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Capture the per-vCPU GPA in perf_test_vcpu_args so that tests can get the GPA without having to calculate the GPA on their own. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/include/perf_test_util.h | 1 + tools/testing/selftests/kvm/lib/perf_test_util.c | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h index 005f2143adeb..4d53238b139f 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -18,6 +18,7 @@ #define PERF_TEST_MEM_SLOT_INDEX 1 struct perf_test_vcpu_args { + uint64_t gpa; uint64_t gva; uint64_t pages; diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index 73b0fccc28b9..f22ce1836547 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -127,7 +127,6 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, bool partition_vcpu_memory_access) { struct perf_test_args *pta = &perf_test_args; - vm_paddr_t vcpu_gpa; struct perf_test_vcpu_args *vcpu_args; int vcpu_id; @@ -140,17 +139,17 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, (vcpu_id * vcpu_memory_bytes); vcpu_args->pages = vcpu_memory_bytes / pta->guest_page_size; - vcpu_gpa = guest_test_phys_mem + - (vcpu_id * vcpu_memory_bytes); + vcpu_args->gpa = guest_test_phys_mem + + (vcpu_id * vcpu_memory_bytes); } else { vcpu_args->gva = guest_test_virt_mem; vcpu_args->pages = (vcpus * vcpu_memory_bytes) / pta->guest_page_size; - vcpu_gpa = guest_test_phys_mem; + vcpu_args->gpa = guest_test_phys_mem; } pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n", - vcpu_id, vcpu_gpa, vcpu_gpa + + vcpu_id, vcpu_args->gpa, vcpu_args->gpa + (vcpu_args->pages * pta->guest_page_size)); } } From patchwork Wed Feb 10 23:06:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93003C433DB for ; Wed, 10 Feb 2021 23:10:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68D0364DFF for ; Wed, 10 Feb 2021 23:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234136AbhBJXK1 (ORCPT ); Wed, 10 Feb 2021 18:10:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233954AbhBJXJ0 (ORCPT ); Wed, 10 Feb 2021 18:09:26 -0500 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 588C6C061356 for ; Wed, 10 Feb 2021 15:06:51 -0800 (PST) Received: by mail-qv1-xf4a.google.com with SMTP id d26so2653007qve.7 for ; Wed, 10 Feb 2021 15:06:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=e5jFMrrVTL3Dr57yHyEm8DbSRLvZbC2fcWOYRcpawLw=; b=jmUj7q3UldLs6UfNTjcZFYwOWuWOU5AEIh73Rn0L0A4OwvAp8hNiKjx6UrN32ZTfku /nZd+Kgbvgkc0F6kH1bSD++xWkguFd94O0gFCt6TykBWVfbWzeAQ6LdaxebM8ETCGS7O SmTIPmQaG61cJ0C7o7eXm6KBXgLBPjiNh01C5ZzGui+hIkQQhAt4fjRPG0tUWp9+jb5W xuv2C9sTiPtfXKySs/3K6ghx+Ctt6DHCu6PKCXX7ccSqj4jm9KrVd1RV1olES8jpWaKw rNXCnWLvC2VtbRlGO1SEgALBj4rF+zS5hp34r+tQcho0v3jWBPKVpJ025q0D31pXCVGz tRJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=e5jFMrrVTL3Dr57yHyEm8DbSRLvZbC2fcWOYRcpawLw=; b=p7J8gp5Ldr0xHvq273OgtmulREPmVqVGpYn9KtY1sM7kLOKS+dGRgBJP0cg8yfHe9S MQSnxjCYWEs8zUEU9TMw4TgTnDtIMDlk97XMp/y8/90ZGNTBFoMvdVGvj6xe8qCYoG4K 4nzyy55v4PiLW0Vv5On8SUAtgDwg3TmNCbiqvdnvffaifak8/+AvzEj4DcXj9Pz7u0ou 4kkqsi15DBPM+NaSuNJ6CzNkNYk1WVf9fDExdaMuRBURSO0pfMWNSBEGheZ82WYPqk3H D84Dmpj/V9XYMD4407NpVkAUga8ja73u1J+Zz6HH5kbbk06gAxQEqJWbxxUdtxXc3NU8 u1MQ== X-Gm-Message-State: AOAM533W9b8BirJTKhbOWNseLW7OQY2Xd3nQi75tsEYPjqjAERVJoj7l 9X4RRj1e4UWkOI2g4gKFJEI5c1JQ9zw= X-Google-Smtp-Source: ABdhPJxc4qHNBFHbYRDNxf4FuEMWtACgfpMEd2VqY/lSClmBZhLHicmuP6qrtwxeJam5kLy3ONb23opabhQ= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a0c:bd93:: with SMTP id n19mr5163222qvg.5.1612998410537; Wed, 10 Feb 2021 15:06:50 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:18 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-9-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 08/15] KVM: selftests: Use perf util's per-vCPU GPA/pages in demand paging test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Grab the per-vCPU GPA and number of pages from perf_util in the demand paging test instead of duplicating perf_util's calculations. Note, this may or may not result in a functional change. It's not clear that the test's calculations are guaranteed to yield the same value as perf_util, e.g. if guest_percpu_mem_size != vcpu_args->pages. Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- .../selftests/kvm/demand_paging_test.c | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index 5f7a229c3af1..0cbf111e6c21 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -294,24 +294,13 @@ static void run_test(enum vm_guest_mode mode, void *arg) TEST_ASSERT(pipefds, "Unable to allocate memory for pipefd"); for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) { - vm_paddr_t vcpu_gpa; + struct perf_test_vcpu_args *vcpu_args; void *vcpu_hva; - uint64_t vcpu_mem_size; - - if (p->partition_vcpu_memory_access) { - vcpu_gpa = guest_test_phys_mem + - (vcpu_id * guest_percpu_mem_size); - vcpu_mem_size = guest_percpu_mem_size; - } else { - vcpu_gpa = guest_test_phys_mem; - vcpu_mem_size = guest_percpu_mem_size * nr_vcpus; - } - PER_VCPU_DEBUG("Added VCPU %d with test mem gpa [%lx, %lx)\n", - vcpu_id, vcpu_gpa, vcpu_gpa + vcpu_mem_size); + vcpu_args = &perf_test_args.vcpu_args[vcpu_id]; /* Cache the HVA pointer of the region */ - vcpu_hva = addr_gpa2hva(vm, vcpu_gpa); + vcpu_hva = addr_gpa2hva(vm, vcpu_args->gpa); /* * Set up user fault fd to handle demand paging @@ -325,7 +314,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) &uffd_handler_threads[vcpu_id], pipefds[vcpu_id * 2], p->uffd_delay, &uffd_args[vcpu_id], - vcpu_hva, vcpu_mem_size); + vcpu_hva, + vcpu_args->pages * perf_test_args.guest_page_size); if (r < 0) exit(-r); } From patchwork Wed Feb 10 23:06:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 122DAC433DB for ; Wed, 10 Feb 2021 23:10:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B761C64ED0 for ; Wed, 10 Feb 2021 23:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233970AbhBJXKO (ORCPT ); Wed, 10 Feb 2021 18:10:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbhBJXJ0 (ORCPT ); Wed, 10 Feb 2021 18:09:26 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71B30C06121D for ; Wed, 10 Feb 2021 15:06:53 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id y79so2937391qka.23 for ; Wed, 10 Feb 2021 15:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=EX0PcjeGA1FsVa28u0L0T+UtxADEQ+txdahAw79zYWo=; b=UKm1BEI9jXw+I1BnyzPMzQCujLZ4ITkUyafcuFrAoF4+L1abIJyW+DlGvBY401OdJo F0+KmFI++onCL0GKu95/izIEetzp0XAPkv1X1B01zCddyy9n3ViZtYmPPw7PEQtuASAz K2xCdsCegHHlS40eyHejY87TFOdRip9sSoBwyewJxmWyPhXFGA1CIMuIx0KXhDuw5J2C O3SSUzIZuu+gGO2rkv7LpEPINYxBsAWMthPmY1g/UbjgwZVrQoUlmF8mLSa7J77EySwg RcuiuLqdh0CIGaJ6DpmyptV/Xw7tILsg3MrV5NSb5sApXMxejW9HDf9HVZO+71hrrrX2 KR0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=EX0PcjeGA1FsVa28u0L0T+UtxADEQ+txdahAw79zYWo=; b=hZa+M8Cuar41H10vSFlYJFtFxoHgBLbAt0ixPFGmN3V5QYD5F/afOJM0iJvicr1lv1 mBQZ4PsH/Ou8O/n9UdYa2yJWRcirjwy2+CG9s0dY1HUXKBrBfknFtlKZbD8SoPr2WE6C MNQQr0IMeGPAzA75nQxndLV8+D9DW/vBXRCykmPO39PIB3Pw5DCfieqauTWemJhIHWkB hzEoMCyBSUo/zni0xGHlByyF7/hRTVcWDaH/Z2Ddr0WJSXcoplz2G0MAxYDj+1QrwSCK naZyvEzFpFs7Lex9Aec+1ZHIHTHoztdNpQhWanMnyu5awuyfJ8oXLgGD0+S9mQqR0JIA 3Crw== X-Gm-Message-State: AOAM533JpuTf5CUUd5DZAfiUkanJ8bjtQqybM3dNHEyZF+J3dH3vDZDU Dkrhfj8lXXhn9ak0gxyiLm18HX5+qN0= X-Google-Smtp-Source: ABdhPJyfpzEFpqLZmwAHBb2LIFQ+yN2kQnTf/TVIyr11JUeAkX01P+1NbnI93ejk1X9/peXZirQ6S7e5psY= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:ad4:5be9:: with SMTP id k9mr5291729qvc.18.1612998412556; Wed, 10 Feb 2021 15:06:52 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:19 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-10-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 09/15] KVM: selftests: Move per-VM GPA into perf_test_args From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Move the per-VM GPA into perf_test_args instead of storing it as a separate global variable. It's not obvious that guest_test_phys_mem holds a GPA, nor that it's connected/coupled with per_vcpu->gpa. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- .../selftests/kvm/include/perf_test_util.h | 8 +----- .../selftests/kvm/lib/perf_test_util.c | 28 ++++++++----------- .../kvm/memslot_modification_stress_test.c | 2 +- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h index 4d53238b139f..cccf1c44bddb 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -29,6 +29,7 @@ struct perf_test_vcpu_args { struct perf_test_args { struct kvm_vm *vm; uint64_t host_page_size; + uint64_t gpa; uint64_t guest_page_size; int wr_fract; @@ -37,13 +38,6 @@ struct perf_test_args { extern struct perf_test_args perf_test_args; -/* - * Guest physical memory offset of the testing memory slot. - * This will be set to the topmost valid physical address minus - * the test memory size. - */ -extern uint64_t guest_test_phys_mem; - struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, uint64_t vcpu_memory_bytes, enum vm_mem_backing_src_type backing_src); diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index f22ce1836547..03f125236021 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -9,8 +9,6 @@ struct perf_test_args perf_test_args; -uint64_t guest_test_phys_mem; - /* * Guest virtual memory offset of the testing memory slot. * Must not conflict with identity mapped test code. @@ -87,29 +85,25 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm), "Requested more guest memory than address space allows.\n" " guest pages: %lx max gfn: %x vcpus: %d wss: %lx]\n", - guest_num_pages, vm_get_max_gfn(vm), vcpus, - vcpu_memory_bytes); + guest_num_pages, vm_get_max_gfn(vm), vcpus, vcpu_memory_bytes); - guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) * - pta->guest_page_size; - guest_test_phys_mem &= ~(pta->host_page_size - 1); + pta->gpa = (vm_get_max_gfn(vm) - guest_num_pages) * pta->guest_page_size; + pta->gpa &= ~(pta->host_page_size - 1); if (backing_src == VM_MEM_SRC_ANONYMOUS_THP || backing_src == VM_MEM_SRC_ANONYMOUS_HUGETLB) - guest_test_phys_mem &= ~(KVM_UTIL_HUGEPAGE_ALIGNMENT - 1); - + pta->gpa &= ~(KVM_UTIL_HUGEPAGE_ALIGNMENT - 1); #ifdef __s390x__ /* Align to 1M (segment size) */ - guest_test_phys_mem &= ~((1 << 20) - 1); + pta->gpa &= ~((1 << 20) - 1); #endif - pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem); + pr_info("guest physical test memory offset: 0x%lx\n", pta->gpa); /* Add an extra memory slot for testing */ - vm_userspace_mem_region_add(vm, backing_src, guest_test_phys_mem, - PERF_TEST_MEM_SLOT_INDEX, - guest_num_pages, 0); + vm_userspace_mem_region_add(vm, backing_src, pta->gpa, + PERF_TEST_MEM_SLOT_INDEX, guest_num_pages, 0); /* Do mapping for the demand paging memory slot */ - virt_map(vm, guest_test_virt_mem, guest_test_phys_mem, guest_num_pages, 0); + virt_map(vm, guest_test_virt_mem, pta->gpa, guest_num_pages, 0); ucall_init(vm, NULL); @@ -139,13 +133,13 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, (vcpu_id * vcpu_memory_bytes); vcpu_args->pages = vcpu_memory_bytes / pta->guest_page_size; - vcpu_args->gpa = guest_test_phys_mem + + vcpu_args->gpa = pta->gpa + (vcpu_id * vcpu_memory_bytes); } else { vcpu_args->gva = guest_test_virt_mem; vcpu_args->pages = (vcpus * vcpu_memory_bytes) / pta->guest_page_size; - vcpu_args->gpa = guest_test_phys_mem; + vcpu_args->gpa = pta->gpa; } pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n", diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index 6096bf0a5b34..569bb1f55bdf 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -121,7 +121,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) add_remove_memslot(vm, p->memslot_modification_delay, p->nr_memslot_modifications, - guest_test_phys_mem + + perf_test_args.gpa + (guest_percpu_mem_size * nr_vcpus) + perf_test_args.host_page_size + perf_test_args.guest_page_size); From patchwork Wed Feb 10 23:06:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 994BFC433DB for ; Wed, 10 Feb 2021 23:08:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7330064DFF for ; Wed, 10 Feb 2021 23:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233937AbhBJXIb (ORCPT ); Wed, 10 Feb 2021 18:08:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233599AbhBJXIO (ORCPT ); Wed, 10 Feb 2021 18:08:14 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1D8AC061221 for ; Wed, 10 Feb 2021 15:06:55 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 78so4242196ybn.14 for ; Wed, 10 Feb 2021 15:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=5DjAXbitjeHVG5TxDqK2++eKHJ0ymPCTq8V7Nw57/kA=; b=fvsehImJ5cIZtskxusx76DIQTu+/oeiLuohwNIAHFHruRJtT2KOpg3mfPWe6/TQL9r bE9LipnBOc72xAM9foaUC5cuIZAOvSdzJ63ZgH161iBpIIwoEL3gJBncmfAJXkBg6epG 470Ts1JG8Wwcaw93ge3QsGJ88zerMsO5670sRkJOr1JNwj1oIi6ouR02QfHA1apbOUpH kfqAs+abDLDKJShazwsX7TWbqh+VzyLq1i2TdWlJ24ZNIqaEwjE3kv1nLJHfKq/LISoG kkB5p13/WsKOkMbTYQA4O/yDliUOFIppZ3n9A+6wN20PuEGioHv857YxdZ9a0iEey6Ng 8nHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=5DjAXbitjeHVG5TxDqK2++eKHJ0ymPCTq8V7Nw57/kA=; b=JG1uEVT5hTwMiLvjRHvXSuiKnMzmvdHoW9pN6hHirRcNs5UuTHfgka+HWuo5kXHqkg 3m33G1SJkUOGUzZBzX1X91cMnQMcRnZrhnMJipWLKDu0FB47eW1HnLsM3QvO3Mhwimhe SsudFp0n7uqXy7ohuFmY0Ri5sZH208GZxn+xM1zhwowxMWloHnOHsjFfUGchDE6AVz6E SvrBPHHviAh0w0jSzL7rDWHpo+vLtdzmZsuwCci4W3/V85EHPWo9mwWhQWA88Bcx8lUC eOEG0uBXU+OBhnHHyvASXazAbPgBq1IbHlfBEjwGlBHTVjGsDgTsmmhwpXZsBJs5loju Mp1g== X-Gm-Message-State: AOAM531xU1P5qwPsOrqlCSglZSuU1VZp/acDQ+1GRiJMOnjeeCJlqCOh 8T5fIrWmqoHaN4drqfzrQnrMvnU5Fm0= X-Google-Smtp-Source: ABdhPJwk20GDwVrtR0WXMBUyTtlj2OgLHbBnBAGq3lcFyLdY1X8407i7E1b2oYwpsWfClEp9vTerSvUn7Og= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a25:1643:: with SMTP id 64mr6808196ybw.169.1612998415062; Wed, 10 Feb 2021 15:06:55 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:20 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-11-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 10/15] KVM: selftests: Remove perf_test_args.host_page_size From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Remove perf_test_args.host_page_size and instead use getpagesize() so that it's somewhat obvious that, for tests that care about the host page size, they care about the system page size, not the hardware page size, e.g. that the logic is unchanged if hugepages are in play. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/demand_paging_test.c | 8 ++++---- tools/testing/selftests/kvm/include/perf_test_util.h | 1 - tools/testing/selftests/kvm/lib/perf_test_util.c | 6 ++---- .../selftests/kvm/memslot_modification_stress_test.c | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index 0cbf111e6c21..b937a65b0e6d 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -83,7 +83,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr) copy.src = (uint64_t)guest_data_prototype; copy.dst = addr; - copy.len = perf_test_args.host_page_size; + copy.len = getpagesize(); copy.mode = 0; clock_gettime(CLOCK_MONOTONIC, &start); @@ -100,7 +100,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr) PER_PAGE_DEBUG("UFFDIO_COPY %d \t%ld ns\n", tid, timespec_to_ns(ts_diff)); PER_PAGE_DEBUG("Paged in %ld bytes at 0x%lx from thread %d\n", - perf_test_args.host_page_size, addr, tid); + getpagesize(), addr, tid); return 0; } @@ -271,10 +271,10 @@ static void run_test(enum vm_guest_mode mode, void *arg) perf_test_args.wr_fract = 1; - guest_data_prototype = malloc(perf_test_args.host_page_size); + guest_data_prototype = malloc(getpagesize()); TEST_ASSERT(guest_data_prototype, "Failed to allocate buffer for guest data pattern"); - memset(guest_data_prototype, 0xAB, perf_test_args.host_page_size); + memset(guest_data_prototype, 0xAB, getpagesize()); vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads)); TEST_ASSERT(vcpu_threads, "Memory allocation failed"); diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h index cccf1c44bddb..223fe6b79a04 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -28,7 +28,6 @@ struct perf_test_vcpu_args { struct perf_test_args { struct kvm_vm *vm; - uint64_t host_page_size; uint64_t gpa; uint64_t guest_page_size; int wr_fract; diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index 03f125236021..982a86c8eeaa 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -57,8 +57,6 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode)); - pta->host_page_size = getpagesize(); - /* * Snapshot the non-huge page size. This is used by the guest code to * access/dirty pages at the logging granularity. @@ -68,7 +66,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, guest_num_pages = vm_adjust_num_guest_pages(mode, (vcpus * vcpu_memory_bytes) / pta->guest_page_size); - TEST_ASSERT(vcpu_memory_bytes % pta->host_page_size == 0, + TEST_ASSERT(vcpu_memory_bytes % getpagesize() == 0, "Guest memory size is not host page size aligned."); TEST_ASSERT(vcpu_memory_bytes % pta->guest_page_size == 0, "Guest memory size is not guest page size aligned."); @@ -88,7 +86,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, guest_num_pages, vm_get_max_gfn(vm), vcpus, vcpu_memory_bytes); pta->gpa = (vm_get_max_gfn(vm) - guest_num_pages) * pta->guest_page_size; - pta->gpa &= ~(pta->host_page_size - 1); + pta->gpa &= ~(getpagesize() - 1); if (backing_src == VM_MEM_SRC_ANONYMOUS_THP || backing_src == VM_MEM_SRC_ANONYMOUS_HUGETLB) pta->gpa &= ~(KVM_UTIL_HUGEPAGE_ALIGNMENT - 1); diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index 569bb1f55bdf..b3b8f08e91ad 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -123,7 +123,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) p->nr_memslot_modifications, perf_test_args.gpa + (guest_percpu_mem_size * nr_vcpus) + - perf_test_args.host_page_size + + getpagesize() + perf_test_args.guest_page_size); run_vcpus = false; From patchwork Wed Feb 10 23:06:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F026C433E0 for ; Wed, 10 Feb 2021 23:09:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 245F864DE9 for ; Wed, 10 Feb 2021 23:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233885AbhBJXIu (ORCPT ); Wed, 10 Feb 2021 18:08:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233794AbhBJXIP (ORCPT ); Wed, 10 Feb 2021 18:08:15 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27C4EC061223 for ; Wed, 10 Feb 2021 15:06:58 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 127so4194283ybc.19 for ; Wed, 10 Feb 2021 15:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=5PnXDF9tiDkGPbh/VAWaDwby96Avt0+QuG4w822UbjY=; b=Ta/BJY4l1df5MvQ8o8wCs579FL0qBg6e+Ev+44fO/sCFPAmHqrzszh1h1b1aidhjgy sA3TU6A6ir+0rKWWoK8QsIiw9+1u1PqhcDkh7V11tiARPiHCVZuNLrgyOvcxbMLWC2MI O/M5epUclP33pX0tTZNA3hVu91cJZBVI2nt8mqMfBRqdxnCDXu6O5hINNLTg2Qvd05ib UqIYB2q7oHinhOVSdWe4lovNE7wHuWKEgLZgDlfQ9chtRBn1ZFSF8+kFxuXwSDFcedlN NHN2rKgG+xttQynNlbxKZUjWtu0GfJ5iPDC8MqCCGhq8GKT62i4n/eS/iR0NFb2nSyYO cSBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=5PnXDF9tiDkGPbh/VAWaDwby96Avt0+QuG4w822UbjY=; b=eJIbu7Gtgw4Iz4sqsnGk+5G35uYV3WSre/dWspqKmTGR40ostbRbaLyzm3ax74iZh6 E9ZP8dVDb/R7y03tUyrfZgKGMw/Bu3ryjK6kh1Fp6DH6RI9mG5Ujuba/WVDjKUS3XN6g MTJSfOgpRRde845xkTfQ1DPzPBymla3fbA+oVFtNZNT+bBZLHRBZ2ipORRzES4r+fYd3 yrj6dMtAwM9WQXIWWWoC9JVvbTE271Qmj/IRrhCSwxCDjup9BLQUtYIEJkB3DgHOAle8 XtkudakykSwSspQAmVOk4SoNz8fY4N8BruLwZtA1YetSDShqd7ZqFlPDWlPpIXmHKb5+ mO+A== X-Gm-Message-State: AOAM53125vCbvcmNTzj5dyPLPHabt1UaYooeH47sRpSsCenHJgbmPEcN By0hTmLotgwaaa7SMmbkjJXdYro+oaA= X-Google-Smtp-Source: ABdhPJyR9/fdNiRPhxrZzkdXH7T1uATs09X8c4/hJiN89SB3JEmCg1rr6cfyZFCkcMjrZMghlHfrJlRlaEc= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a25:67d6:: with SMTP id b205mr1035523ybc.394.1612998417404; Wed, 10 Feb 2021 15:06:57 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:21 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-12-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 11/15] KVM: selftests: Create VM with adjusted number of guest pages for perf tests From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use the already computed guest_num_pages when creating the so called extra VM pages for a perf test, and add a comment explaining why the pages are allocated as extra pages. Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/lib/perf_test_util.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index 982a86c8eeaa..9b0cfdf10772 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -71,9 +71,12 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, TEST_ASSERT(vcpu_memory_bytes % pta->guest_page_size == 0, "Guest memory size is not guest page size aligned."); - vm = vm_create_with_vcpus(mode, vcpus, - (vcpus * vcpu_memory_bytes) / pta->guest_page_size, - 0, guest_code, NULL); + /* + * Pass guest_num_pages to populate the page tables for test memory. + * The memory is also added to memslot 0, but that's a benign side + * effect as KVM allows aliasing HVAs in memslots. + */ + vm = vm_create_with_vcpus(mode, vcpus, 0, guest_num_pages, guest_code, NULL); pta->vm = vm; /* From patchwork Wed Feb 10 23:06:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43450C433E0 for ; Wed, 10 Feb 2021 23:08:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 156D664D99 for ; Wed, 10 Feb 2021 23:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233892AbhBJXIl (ORCPT ); Wed, 10 Feb 2021 18:08:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233797AbhBJXIQ (ORCPT ); Wed, 10 Feb 2021 18:08:16 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82FDCC061225 for ; Wed, 10 Feb 2021 15:07:00 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id 124so2971462qkg.6 for ; Wed, 10 Feb 2021 15:07:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=UoVmn7fpCyRNxRM+3Np7r+DECkmDjVu43eW5UiZ+MBE=; b=FmQct8ROvMDTZ6Y9dfDGAyrs59mWfzPnEMPFaCQJ+BnmImH5W1jpeKxobWA1cA/0kU AlAzbAFrOQI1aqAOwvrTZjGtJ0zijXl6cEGPAbg4R7nlGZL0j+qFo4pjsg27ApQO7p3a EeNI0NzVUBiG7NvGMY4WM1XcMj3cA+KcRuzBjZPXucti/yYOtwQ0zQZlvS3GGMh6cqM2 JLKGnSyetoyykmQEy4YaJViYKGIlahl4oq/nqGm+tDDhSAEKWgy1neObMsxRqQND1h12 3YPZBCCbGRraccOSTLn4wt4wdmCzzDwzCbTx38Bt1Cw4bWoBYswq5Nf7H3HbNp/4Cx+P lKRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=UoVmn7fpCyRNxRM+3Np7r+DECkmDjVu43eW5UiZ+MBE=; b=jVewghtjtd5Oqs4C21Fo0GlYuN5ZXqh9rGzY9qjkI4WjjuytG4tXLDDD30Ry8JkHjt ne08StBOp8DbLjc4aHR8tj50ZAHeS14JH39E68Q4yP+C1Wh0CqV61Dj6rjTidTTKdmcu P3kH7MdyakwGEZrrUS7gZ0y+rU3ScN/Nk9UxwIDO/RgMpsYU3v3HvD14SK/uXaYc3Ain DbSnQfJubGJ2olF1AOWsJNB4tPZNUfdHfeRQ6GhFczER9Ewg7gGQk9A/HEdLcLzns8F3 4gejDGj7mFt1auX8jSgn2cZeBQxAnj1iJw5VfwzTzBDeiKR8AXlbd/cN2BaTL/ogo5tW n2iQ== X-Gm-Message-State: AOAM531JB3hawpzPFxHn5EQk2wZgRwDAX/uyenxhMe7rwujihHloBu43 7Zgp8dAWwlJjvzQSiWWXkO/3jm++TKg= X-Google-Smtp-Source: ABdhPJw8V99g3m/NCGuvuwfBfxYgkAu9OQmH56KymDF8KZ6QMsat8EilVDY4q33kx0ZLagDbfo6zjY28p/U= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:ad4:55aa:: with SMTP id f10mr5441086qvx.46.1612998419716; Wed, 10 Feb 2021 15:06:59 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:22 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-13-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 12/15] KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Fill the per-vCPU args when creating the perf_test VM instead of having the caller do so. This helps ensure that any adjustments to the number of pages (and thus vcpu_memory_bytes) are reflected in the per-VM args. Automatically filling the per-vCPU args will also allow a future patch to do the sync to the guest during creation. Signed-off-by: Sean Christopherson --- .../selftests/kvm/demand_paging_test.c | 6 +- .../selftests/kvm/dirty_log_perf_test.c | 6 +- .../selftests/kvm/include/perf_test_util.h | 6 +- .../selftests/kvm/lib/perf_test_util.c | 74 ++++++++++--------- .../kvm/memslot_modification_stress_test.c | 6 +- 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index b937a65b0e6d..00f2c795b68d 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -267,7 +267,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) int r; vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, - VM_MEM_SRC_ANONYMOUS); + VM_MEM_SRC_ANONYMOUS, + p->partition_vcpu_memory_access); perf_test_args.wr_fract = 1; @@ -279,9 +280,6 @@ static void run_test(enum vm_guest_mode mode, void *arg) vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads)); TEST_ASSERT(vcpu_threads, "Memory allocation failed"); - perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size, - p->partition_vcpu_memory_access); - if (p->use_uffd) { uffd_handler_threads = malloc(nr_vcpus * sizeof(*uffd_handler_threads)); diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 04a2641261be..2c809452eac1 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -114,7 +114,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) struct timespec clear_dirty_log_total = (struct timespec){0}; vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, - p->backing_src); + p->backing_src, + p->partition_vcpu_memory_access); perf_test_args.wr_fract = p->wr_fract; @@ -132,9 +133,6 @@ static void run_test(enum vm_guest_mode mode, void *arg) vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads)); TEST_ASSERT(vcpu_threads, "Memory allocation failed"); - perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size, - p->partition_vcpu_memory_access); - sync_global_to_guest(vm, perf_test_args); /* Start the iterations */ diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h index 223fe6b79a04..3a21e82a0173 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -39,10 +39,8 @@ extern struct perf_test_args perf_test_args; struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, uint64_t vcpu_memory_bytes, - enum vm_mem_backing_src_type backing_src); + enum vm_mem_backing_src_type backing_src, + bool partition_vcpu_memory_access); void perf_test_destroy_vm(struct kvm_vm *vm); -void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, - uint64_t vcpu_memory_bytes, - bool partition_vcpu_memory_access); #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index 9b0cfdf10772..3aa99365726b 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -47,9 +47,45 @@ static void guest_code(uint32_t vcpu_id) } } + +static void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, + uint64_t vcpu_memory_bytes, + bool partition_vcpu_memory_access) +{ + struct perf_test_args *pta = &perf_test_args; + struct perf_test_vcpu_args *vcpu_args; + int vcpu_id; + + for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) { + vcpu_args = &pta->vcpu_args[vcpu_id]; + + vcpu_args->vcpu_id = vcpu_id; + if (partition_vcpu_memory_access) { + vcpu_args->gva = guest_test_virt_mem + + (vcpu_id * vcpu_memory_bytes); + vcpu_args->pages = vcpu_memory_bytes / + pta->guest_page_size; + vcpu_args->gpa = pta->gpa + + (vcpu_id * vcpu_memory_bytes); + } else { + vcpu_args->gva = guest_test_virt_mem; + vcpu_args->pages = (vcpus * vcpu_memory_bytes) / + pta->guest_page_size; + vcpu_args->gpa = pta->gpa; + } + + pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n", + vcpu_id, vcpu_args->gpa, vcpu_args->gpa + + (vcpu_args->pages * pta->guest_page_size)); + } +} + + + struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, uint64_t vcpu_memory_bytes, - enum vm_mem_backing_src_type backing_src) + enum vm_mem_backing_src_type backing_src, + bool partition_vcpu_memory_access) { struct perf_test_args *pta = &perf_test_args; struct kvm_vm *vm; @@ -65,6 +101,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, guest_num_pages = vm_adjust_num_guest_pages(mode, (vcpus * vcpu_memory_bytes) / pta->guest_page_size); + vcpu_memory_bytes = (guest_num_pages * pta->guest_page_size) / vcpus; TEST_ASSERT(vcpu_memory_bytes % getpagesize() == 0, "Guest memory size is not host page size aligned."); @@ -106,6 +143,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, /* Do mapping for the demand paging memory slot */ virt_map(vm, guest_test_virt_mem, pta->gpa, guest_num_pages, 0); + perf_test_setup_vcpus(vm, vcpus, vcpu_memory_bytes, + partition_vcpu_memory_access); + ucall_init(vm, NULL); return vm; @@ -116,35 +156,3 @@ void perf_test_destroy_vm(struct kvm_vm *vm) ucall_uninit(vm); kvm_vm_free(vm); } - -void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, - uint64_t vcpu_memory_bytes, - bool partition_vcpu_memory_access) -{ - struct perf_test_args *pta = &perf_test_args; - struct perf_test_vcpu_args *vcpu_args; - int vcpu_id; - - for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) { - vcpu_args = &pta->vcpu_args[vcpu_id]; - - vcpu_args->vcpu_id = vcpu_id; - if (partition_vcpu_memory_access) { - vcpu_args->gva = guest_test_virt_mem + - (vcpu_id * vcpu_memory_bytes); - vcpu_args->pages = vcpu_memory_bytes / - pta->guest_page_size; - vcpu_args->gpa = pta->gpa + - (vcpu_id * vcpu_memory_bytes); - } else { - vcpu_args->gva = guest_test_virt_mem; - vcpu_args->pages = (vcpus * vcpu_memory_bytes) / - pta->guest_page_size; - vcpu_args->gpa = pta->gpa; - } - - pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n", - vcpu_id, vcpu_args->gpa, vcpu_args->gpa + - (vcpu_args->pages * pta->guest_page_size)); - } -} diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index b3b8f08e91ad..949822833b6b 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -98,16 +98,14 @@ static void run_test(enum vm_guest_mode mode, void *arg) int vcpu_id; vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, - VM_MEM_SRC_ANONYMOUS); + VM_MEM_SRC_ANONYMOUS, + p->partition_vcpu_memory_access); perf_test_args.wr_fract = 1; vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads)); TEST_ASSERT(vcpu_threads, "Memory allocation failed"); - perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size, - p->partition_vcpu_memory_access); - /* Export the shared variables to the guest */ sync_global_to_guest(vm, perf_test_args); From patchwork Wed Feb 10 23:06:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D1C9C433E0 for ; Wed, 10 Feb 2021 23:11:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46A9164DFF for ; Wed, 10 Feb 2021 23:11:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234082AbhBJXKp (ORCPT ); Wed, 10 Feb 2021 18:10:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233881AbhBJXJb (ORCPT ); Wed, 10 Feb 2021 18:09:31 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFDB8C061226 for ; Wed, 10 Feb 2021 15:07:02 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id x4so4237339ybj.22 for ; Wed, 10 Feb 2021 15:07:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=xzPdpv8MHYE/+y1yIo/W7K5+bKtlPzwP+COJMIds9zc=; b=N88xDPdcfGLluTxiRIyEqoDZAZTdnaa6C+IfZ8QM1WX43gcTRsxhXpufBm23LJ5uqZ UNxN8q68FDCnBma5UdZj6Ej1bArWTjXehrQK93rXQ8RqdEHYyUN5j2aPTULweB2vCh+O J4WXqkrDaKi6oyflVYSq75rvSiAKIHivDzoL5/ZsZRd3B9dCZ1T0PuCQsVRtqOB2uD47 +hcSsllQzcG3yLpvgWKeHGc97waiYYMQmklO68Frdy81t7Tuhg1k4eQnPShW/9RoVqhs Y1NOGWysDDTl4UKi0ZbClT75vRRbD94MYhujrprfokxlmZIVceZeexF9RkS4LzeEBGgI hZyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=xzPdpv8MHYE/+y1yIo/W7K5+bKtlPzwP+COJMIds9zc=; b=UltgWYjvsHPRHqWyZ+kPzv5LUipCLo7O0wIvb0qXmDxRXKs7HzjhEpQY6iZgKGyph5 6gAStbOqxpI2wBCbDq+d7WQlETmYgrumQWNpdHu6dQwkOAt1ttdx4CXhS55Ze0e2jtiY QETylT9Wow2LfSdPxnT/L0prDQWQF47+F8pVCnGy/vx4tBMbltrxEKIveb6oHl0n8mlf kOBcSMcoy6dkCUcA0LqtrH0Epj3liTmkSVk9+TKr/NVu7lYeGpl62klgITXRI9xvzNtX OtS3ikmTNAwkH8KigrFaKcwNpQb90MKoCIdsbVbl1rjMi4d8sP0EXsM5J7/scgAY10w7 GyYQ== X-Gm-Message-State: AOAM533dIf3maXWGr4g3lXkLYxYyrka65Hu8Y1k+qrL0ITkZFh+ByTgc hC8yeiUW8/4hOLVntBkrnhhuH/jCXTY= X-Google-Smtp-Source: ABdhPJxGaPCMuU/hHBMxf+330j4xifGRLCQx84eoj9h3tH7LS+XLp9nHuWZkoaEQovrnhM4RpW2zP8OSr7Y= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a25:ce51:: with SMTP id x78mr7620057ybe.198.1612998422267; Wed, 10 Feb 2021 15:07:02 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:23 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-14-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 13/15] KVM: selftests: Sync perf_test_args to guest during VM creation From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Copy perf_test_args to the guest during VM creation instead of relying on the caller to do so at their leisure. Ideally, tests wouldn't even be able to modify perf_test_args, i.e. they would have no motivation to do the sync, but enforcing that is arguably a net negative for readability. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/demand_paging_test.c | 7 +------ tools/testing/selftests/kvm/dirty_log_perf_test.c | 6 +----- tools/testing/selftests/kvm/include/perf_test_util.h | 1 + tools/testing/selftests/kvm/lib/perf_test_util.c | 6 ++++++ .../selftests/kvm/memslot_modification_stress_test.c | 7 +------ 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index 00f2c795b68d..d06ff8f37c53 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -267,11 +267,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) int r; vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, - VM_MEM_SRC_ANONYMOUS, + VM_MEM_SRC_ANONYMOUS, 1, p->partition_vcpu_memory_access); - perf_test_args.wr_fract = 1; - guest_data_prototype = malloc(getpagesize()); TEST_ASSERT(guest_data_prototype, "Failed to allocate buffer for guest data pattern"); @@ -319,9 +317,6 @@ static void run_test(enum vm_guest_mode mode, void *arg) } } - /* Export the shared variables to the guest */ - sync_global_to_guest(vm, perf_test_args); - pr_info("Finished creating vCPUs and starting uffd threads\n"); clock_gettime(CLOCK_MONOTONIC, &start); diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 2c809452eac1..9ab24bf50c60 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -114,11 +114,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) struct timespec clear_dirty_log_total = (struct timespec){0}; vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, - p->backing_src, + p->backing_src, p->wr_fract, p->partition_vcpu_memory_access); - perf_test_args.wr_fract = p->wr_fract; - guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm_get_page_shift(vm); guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages); host_num_pages = vm_num_host_pages(mode, guest_num_pages); @@ -133,8 +131,6 @@ static void run_test(enum vm_guest_mode mode, void *arg) vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads)); TEST_ASSERT(vcpu_threads, "Memory allocation failed"); - sync_global_to_guest(vm, perf_test_args); - /* Start the iterations */ iteration = 0; host_quit = false; diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h index 3a21e82a0173..330e528f206f 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -40,6 +40,7 @@ extern struct perf_test_args perf_test_args; struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, uint64_t vcpu_memory_bytes, enum vm_mem_backing_src_type backing_src, + int wr_fract, bool partition_vcpu_memory_access); void perf_test_destroy_vm(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index 3aa99365726b..6f41fe2685cb 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -85,6 +85,7 @@ static void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, uint64_t vcpu_memory_bytes, enum vm_mem_backing_src_type backing_src, + int wr_fract, bool partition_vcpu_memory_access) { struct perf_test_args *pta = &perf_test_args; @@ -93,6 +94,8 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode)); + pta->wr_fract = wr_fract; + /* * Snapshot the non-huge page size. This is used by the guest code to * access/dirty pages at the logging granularity. @@ -148,6 +151,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, ucall_init(vm, NULL); + /* Export the shared variables to the guest */ + sync_global_to_guest(vm, perf_test_args); + return vm; } diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index 949822833b6b..5ea9d7ef248e 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -98,17 +98,12 @@ static void run_test(enum vm_guest_mode mode, void *arg) int vcpu_id; vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, - VM_MEM_SRC_ANONYMOUS, + VM_MEM_SRC_ANONYMOUS, 1, p->partition_vcpu_memory_access); - perf_test_args.wr_fract = 1; - vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads)); TEST_ASSERT(vcpu_threads, "Memory allocation failed"); - /* Export the shared variables to the guest */ - sync_global_to_guest(vm, perf_test_args); - pr_info("Finished creating vCPUs\n"); for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) From patchwork Wed Feb 10 23:06:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEDE7C433E0 for ; Wed, 10 Feb 2021 23:10:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8189164DE9 for ; Wed, 10 Feb 2021 23:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234155AbhBJXKe (ORCPT ); Wed, 10 Feb 2021 18:10:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233797AbhBJXJb (ORCPT ); Wed, 10 Feb 2021 18:09:31 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DE5DC0611BE for ; Wed, 10 Feb 2021 15:07:05 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id l197so4234116ybf.17 for ; Wed, 10 Feb 2021 15:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=0O47gXh514nfPDoLIe0tEYtVLi+SLooBrwujOdhUj5c=; b=R53vF2RPZ+cJSdkvPJG7YJQe/6soGIV3FT/czqFkJub5LyyaDo/gy9/ZXpebn9oFFK 3XT5gzQt2AnBDDlwJyGjPe+oppvCWF/EFPX7qsqH6lEr/4Mb6RMIR7hZwAPqlOVdrKjL 0i07ym41KhfeJXlA3iPdoyhIDLsDRCwdP2rj9vbTGoAnomVO8RJGmOqTrBZNRdZZvWPG mLnN6Pws3AoVyXzqkxLrImeKvW5512ZJhiJZAx9wWocq24JSrxwX7iOdugwVr8H7uDos vjUKdbpvKsJ5JxX1caTX6cVCkrfooReEGbT2Ho2DT3zS7sb6P+Q+Aj6asZ+YqEmDcbiZ yfdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=0O47gXh514nfPDoLIe0tEYtVLi+SLooBrwujOdhUj5c=; b=sOn6lYXS+bycfcstgktNiZsmCLz8awpKTWEh+9qL9Weq4qVLS8bn8Y209GhHsZmvKV KVe1mpbLInNpokfKWoSLuic78/3Rzowi8CiggttLCqDmBodng4mZuRzkOClzyRINJlds u1qRFoJrb+EcpRSRyESF7IUl5VywE6QUDLF9PZYcijHB9kPcVGFoGE5TYl9kjLrUJL5U 2zXXxnYbYG1424N4eHzpGg284ts2HteYBJgXjW750oC3DPUNjxFmMkVwvOwE2zvuig1k TgziBXP6vCs+ofr+f+m6nmgy0cvBVN73lrkIDd0kkEaZxLTtaYx6KJ64iwWOu4O2P7Nw PSHQ== X-Gm-Message-State: AOAM533oyJcaAEqNcBEKWA9a/5pIAsC7pEg2uN2qTxNXQchddNI86AlK twiNxwTWA6d0gBFzI0Qmut+1jyeZqYE= X-Google-Smtp-Source: ABdhPJzqySYZiZAN5x2B4E4ONnbmA2MSSJV6p8sSGxQeVOJ+OQQVG8MFENrToeIODXJ0kRahIpfSBqMpxSw= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a25:7693:: with SMTP id r141mr2748225ybc.49.1612998424575; Wed, 10 Feb 2021 15:07:04 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:24 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-15-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 14/15] KVM: selftests: Track size of per-VM memslot in perf_test_args From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Capture the final size of the dedicated memslot created by perf_test_args so that tests don't have to try and guesstimate the final result. This will be used by the memslots modification test to remove some truly mind-boggling code. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/perf_test_util.h | 1 + tools/testing/selftests/kvm/lib/perf_test_util.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h index 330e528f206f..4da2d2dbf4c2 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -30,6 +30,7 @@ struct perf_test_args { struct kvm_vm *vm; uint64_t gpa; uint64_t guest_page_size; + uint64_t nr_bytes; int wr_fract; struct perf_test_vcpu_args vcpu_args[KVM_MAX_VCPUS]; diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index 6f41fe2685cb..00953d15388f 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -80,8 +80,6 @@ static void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, } } - - struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, uint64_t vcpu_memory_bytes, enum vm_mem_backing_src_type backing_src, @@ -104,7 +102,11 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, guest_num_pages = vm_adjust_num_guest_pages(mode, (vcpus * vcpu_memory_bytes) / pta->guest_page_size); - vcpu_memory_bytes = (guest_num_pages * pta->guest_page_size) / vcpus; + pta->nr_bytes = guest_num_pages * pta->guest_page_size; + + TEST_ASSERT(pta->nr_bytes % vcpus == 0, + "Guest pages adjustment yielded a weird number of pages."); + vcpu_memory_bytes = pta->nr_bytes / vcpus; TEST_ASSERT(vcpu_memory_bytes % getpagesize() == 0, "Guest memory size is not host page size aligned."); From patchwork Wed Feb 10 23:06:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12081985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AB67C433E0 for ; Wed, 10 Feb 2021 23:09:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60E9C64D99 for ; Wed, 10 Feb 2021 23:09:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234061AbhBJXJP (ORCPT ); Wed, 10 Feb 2021 18:09:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233897AbhBJXIy (ORCPT ); Wed, 10 Feb 2021 18:08:54 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF3FDC061A28 for ; Wed, 10 Feb 2021 15:07:07 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id p185so2969836qkc.9 for ; Wed, 10 Feb 2021 15:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=i/onZ3KiqIHBpv3eMUYx1zyRXltUgIE1V0UnnfUHTlU=; b=cduvZoyAs6pKakf+DUM0JAes2PTO8Xs8SjSx1xNAQRHLUo21knOelo8gzCqGwDHQqB KpP8TQfaQ9yfySQnM6cjOuNQvYt32rnyADYp42LMjK6RdTFJ2l+huXmQKxBDCHeAxkbE v0snVtPybCrxaPnQfXhkc+FzGqFk7EmHzgwtTNC0D8r6b7cYlVA1KXdsG9t7nqC0gTAn tyC1xAVjrMUsD8INIhne/bi2tsAdfhFmmtnDGoIuln/MNT1aqZBwDVdOtXO9p8LZCpX3 PBRUIlbJ3OQ4K1YsvOrElg48KybP6ODa07Qo7GJY2WoaJ1U2YMBiJH6U/QM4CWcHclqd i8HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=i/onZ3KiqIHBpv3eMUYx1zyRXltUgIE1V0UnnfUHTlU=; b=tWkTfAux8EQ7QJ9oniH/BK/vnaHCYGe1R6E50Dtk/f+oNy+sc7oqAOzJrGy5uR4J5H qoz+kVhA4XmEF74X9wWUG/wFKlNwemYRIktgbLDSAFPOwX1lNnEubpbFsv7wEvPhTyBH LUa8eW6/ObFRW+31rUO+WUthHKUmxiPtJ8NYfrPwlA+St1dlAGEx+ftsNZpB1n/LzTCm +HQy13xA+EO8u/3lFESBDckAD0G5joOV19GXoJ3atnCzknZZMB+0luvTjknDYIpaUx9H 2UCxpOD1XcUJyVjZCTQNS2EtQzZ0/Tldm6wCESDEfVY2A5vwP+3WRjv6MWISxBKTbdh3 wXmg== X-Gm-Message-State: AOAM533MjOsKk4SAhfIj+DkXjrD2rNfEFcLlVsAeoqOXDaIxFahqfWST WFai40DNDyWfKw58WT4+GQrHtZxYiD0= X-Google-Smtp-Source: ABdhPJzGJXgDaZRgmcj37pw6FCoVQ458rPN2FxbCfzyyF0dPrmlaITMAuJKlttUJ5rXiMxCAJaeo4VbIPeY= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:11fc:33d:bf1:4cb8]) (user=seanjc job=sendgmr) by 2002:a05:6214:10e7:: with SMTP id q7mr5120746qvt.16.1612998426830; Wed, 10 Feb 2021 15:07:06 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Feb 2021 15:06:25 -0800 In-Reply-To: <20210210230625.550939-1-seanjc@google.com> Message-Id: <20210210230625.550939-16-seanjc@google.com> Mime-Version: 1.0 References: <20210210230625.550939-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 15/15] KVM: selftests: Get rid of gorilla math in memslots modification test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Ben Gardon , Yanan Wang , Andrew Jones , Peter Xu , Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use the recently added perf_test_args.nr_bytes to define the location of the dummy memslot created/removed by the memslot modification test. Presumably, the goal of the existing code is simply to ensure the GPA of the dummy memslot doesn't overlap with perf_test's memslot. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/memslot_modification_stress_test.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index 5ea9d7ef248e..cfc2b75619ba 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -114,10 +114,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) add_remove_memslot(vm, p->memslot_modification_delay, p->nr_memslot_modifications, - perf_test_args.gpa + - (guest_percpu_mem_size * nr_vcpus) + - getpagesize() + - perf_test_args.guest_page_size); + perf_test_args.gpa + perf_test_args.nr_bytes); run_vcpus = false;