Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1714631pxb; Wed, 10 Feb 2021 15:12:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxz/9Xfk9w/YPG8IjvF7InvyoG7lNM9QnAi972E2uU1ojuisNX/hiOOsInLfMWTeOhJf12H X-Received: by 2002:a50:d307:: with SMTP id g7mr5515838edh.204.1612998738049; Wed, 10 Feb 2021 15:12:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612998738; cv=none; d=google.com; s=arc-20160816; b=dvQtLjK3GmwYH1wV+2A+RPAVLIxDB0ghpSTk3U2q7XTUzlG0/MEm1QFCAc3x7HOAET 2hSHxhYwAJrjT2UKp99vKekmMDSu4fX1U3/7JYwBw+4vFBCBT/neBj8LTbeqGvuRuo92 B4en81u373SYW9ZuE3FOvTp8+hKZwyiA++WbGmeRmrDmfOJAdBQoH5kCQNLQCDo+UxYE qnM4ObNs7z1QPIX4d1tIY6RF2y6ZepVIAFGUVCf6o/ka16VTNH1/PsOEJrvJVcXSmGUT BRszFyiL3PkVZdOkqdRFOkWkZHyhT7u0Lr7xPe9xD8AVXdFI0ozUkwylzNrqAroSWHfY 829w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:sender:dkim-signature; bh=/D10CsPyV0SuKQhqygo5NqkKV98of4qDPh0B02671yY=; b=ggKbyWNsXy0aWAwzwZiWXvuJ8A5VKfgidXdA2jrUl0DJ/t7dKhqp4kEHOUGee8u+0S 91Sq4G1X/y2fNHDyF57PgXz2o/bY7ZkagOEw3sW59CL4RNgFwJTzq6W3ZW0OFUzRY4Gf 25HbfrqDOB63ViUFlE7/D1Yq5+CuCizfuYtK/U2i+iOIclpYt7j4JKTJLiOOuJC/Ivt5 j/OuDeApRuR91oaakD0KuheRTj1HkA9VnGlH+t7QSRBCdCk2qSFcH0G3k6+lwJ/RIv1u AJMWqU2kCI/Li+af1XMaDv/qYOQ2yPIZiA8ZK2uNBbjX4Cs007AX5dEPHTyVL29YqrNZ 2kbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=p6eFbB4l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si3020644edz.361.2021.02.10.15.11.49; Wed, 10 Feb 2021 15:12:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=p6eFbB4l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233930AbhBJXIn (ORCPT + 99 others); Wed, 10 Feb 2021 18:08:43 -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 S233848AbhBJXH6 (ORCPT ); Wed, 10 Feb 2021 18:07:58 -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 66E07C061794 for ; Wed, 10 Feb 2021 15:06:44 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 6so4257579ybq.7 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=i9lD2ZN663oxBaQP/T+IZ0oJ9UHKD6wHzA94EWfvaFR3cCNpgY+ikZmC218TjXhmhv 5dTijt4z9+MHJWy67Waw5GyUn6nlp2Dk6eFM91bgnwYsRgcdgZdAy80dbYu9ndbN6NHA iX/k0PBZ7hRQNh/sA9i2uhyGBuEhntSuHEI7mwHbAibeXYd5e5JoBcl7YeLCbDHT0tci aSttNUqVKK6Q8+HQOV4Obea1WHOiToNiiZ9GKXgXqAimB6oDG3QTjbCfkMc4x8QkLuzp XGS84C6V71u7WSOBNaAMsMp5tdfxE8V4/tLn4qLHN6FmdGHcUtYzo3mb8GXDchNQk0tx KLBQ== X-Gm-Message-State: AOAM532MdeFV0jawct4ZwhfRg7bmbVQW4Tn3XdenPMqhNfBeG0QawQiy u0ZiXabjQMmGvOeA7ptxX0BPA2rGayU= 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); -- 2.30.0.478.g8a0d178c01-goog