From patchwork Fri Jun 2 16:08:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1139933vqr; Fri, 2 Jun 2023 09:11:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ub1i7WLh7T3p1/5v/HXEVGplcpGiSIfJsBxl0VnzlSQdYc+cmXWBV/svp8F5GmZ7zxPg6 X-Received: by 2002:a92:d084:0:b0:329:bba2:781a with SMTP id h4-20020a92d084000000b00329bba2781amr10243842ilh.0.1685722310619; Fri, 02 Jun 2023 09:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722310; cv=none; d=google.com; s=arc-20160816; b=vwW7W5x4fcTIsq8W2jgcEeILG9S2Zg/KDnTSM6GlIGBWImez8gFIsa3W8fZApMPR1B bmjfdT/o0Bdi/kOjVOtzGQAWA4Yct7doF3Txmn96Q1AWg+MXiSIggR2E1D+4YzNc5+FN GnY4yLam/fRzExXNHiBUre43hdZBwvIET9Cg8XUE0/rhCEzDxjahIEUwiL+laDMkDpO2 6Yc1JhSsf3+xaUGslRsh8mqGGdvdcUHx87/OUkbuDQ5MwbZjErRu4xtfNF7DTWl3/7Qc s22xYqeleqKqlpZXifLGjVa0+y9IhvcuA1wGRhEffqD4W26eLGPU8OyeE5rNY+yE++3R ONZQ== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=DpCi+Z+5IrlXYT4x1uPx6ey3Kh6k4RwU4EEsfyAeFCY=; b=DOiHd6KSJ+AJ5I08jAHvSyTc67xJ+lsLs3UZkd4vDpaT/ymSMcwkWNgFB9gCWfcOdx kT6qchsQR8jDN+CzQmRshQPj5BCptH2oecsyGyJqepWhPDxVrOuyliqtNS58DjEUCm8h PdRoGRGP/MokW1srqii+3n43XYqmYoGRmU0bXpqYMwnSFl13T/o2ltAf1x77IdQaG812 x0JTqhD1jDNmxAr9FBYnTNIDxNhBQNdq+4jK8kCHugo2jukfraUb38R8GMWUwvb+ZMlb M5QZcwczytbKmcnAg3BOZIpHSg6CIcgT+Odk0kRa6JE128GVGFxd8QbSnbMHkCLBT1hZ E3Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=HfcMR6iJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x63-20020a636342000000b005303a7ca052si1199512pgb.491.2023.06.02.09.11.37; Fri, 02 Jun 2023 09:11:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=HfcMR6iJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236500AbjFBQJ1 (ORCPT + 99 others); Fri, 2 Jun 2023 12:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236489AbjFBQJX (ORCPT ); Fri, 2 Jun 2023 12:09:23 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 494FFE40 for ; Fri, 2 Jun 2023 09:09:22 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-651e4007b9cso1531088b3a.3 for ; Fri, 02 Jun 2023 09:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722162; x=1688314162; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DpCi+Z+5IrlXYT4x1uPx6ey3Kh6k4RwU4EEsfyAeFCY=; b=HfcMR6iJ3p+XpoWwwGnuCf8DXEruqodHMrgo0qRUl9XKRxAQVZGiN8TxS7KXZ6liYk IHfRjrAnrHvGlvRXdd0vMGLUxjqvqzDBCEZqkZ+AlgA2D+HqWzekq3osmRA2k0du5O5o kCcbGty+UgEm8rxi/OLq7qgVCFwHH13HTXpftBj1XaM0i7tjBO9lKRJTdTnJF5R/3t6c JrkS5ti9XRCTfaa1D8P3ktMUx2ASyp8GqB5XYe9RG7pBvxny7Wq3BWLQtvGrXB/UToqw xyXoWdXWsB9HM0UfeGzOOvYeGlmazG1w/VKQFNAblPuwmKiFaBvQdPac1I4EbR7ShaXp NDtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722162; x=1688314162; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DpCi+Z+5IrlXYT4x1uPx6ey3Kh6k4RwU4EEsfyAeFCY=; b=c6vuIow/e83ig2dsIWcmPiY9VHdLVm78tO9MMFB79hwkC3H06zogh2AncHQZaq595l fJiq0nII9vdWCt9rWK9p2nMCZnpiP2/sQUrrOcC17VrASIPu3pySPLXSGV7V8U8776+o Uf4PalM3YXhAWpghHKoNAfAGG4NAA4pGbmP4KDJrm6kd2ja/y8x29SHhkf7ylQKlExMc x68pS4BgaA3IrnpfMEWg3DRtpz1Uy9TtxGDo8hTDrzzXXEtgWg1e0y+kXzY7LouffiBf 84tEXlpvISsuJ1OdtwALTjVTcDekZiIEkNtZ2iQgvY828IUXjLYMXSzpOEf14JlJTylw zOaw== X-Gm-Message-State: AC+VfDzUR9VRrflPHZcdkJV6vAbioLabrHpLimDyT5IrMOvD0oYBnof4 5geuj/JHTcFxcnkZ7afDoeifkdWBNt2o X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:2183:b0:643:a542:b311 with SMTP id h3-20020a056a00218300b00643a542b311mr4840248pfi.0.1685722161708; Fri, 02 Jun 2023 09:09:21 -0700 (PDT) Date: Fri, 2 Jun 2023 09:08:59 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-2-vipinsh@google.com> Subject: [PATCH v2 01/16] KVM: selftests: Clear dirty logs in user defined chunks sizes in dirty_log_perf_test From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607957350623978?= X-GMAIL-MSGID: =?utf-8?q?1767607957350623978?= In dirty_log_perf_test, provide a new option 'k' to specify the size of the chunks and clear dirty memory in chunks in each iteration. If option is not provided then fallback to the old way of clearing whole memslot in one call in each iteration. In production environment whole memslot is rarely cleared in a single call, instead clearing operation is split across multiple calls to reduce time between clearing and sending memory to a remote host. This change mimics the production usecases and allows to get performance numbers based on that. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index e9d6d1aecf89..119ddfc7306e 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -134,6 +134,7 @@ struct test_params { uint32_t write_percent; uint32_t random_seed; bool random_access; + uint64_t clear_chunk_size; }; static void toggle_dirty_logging(struct kvm_vm *vm, int slots, bool enable) @@ -169,16 +170,28 @@ static void get_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], int slots } } -static void clear_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], - int slots, uint64_t pages_per_slot) +static void clear_dirty_log_in_chunks(struct kvm_vm *vm, + unsigned long *bitmaps[], int slots, + uint64_t pages_per_slot, + uint64_t pages_per_clear) { - int i; + uint64_t from, clear_pages_count; + int i, slot; for (i = 0; i < slots; i++) { - int slot = MEMSTRESS_MEM_SLOT_INDEX + i; - - kvm_vm_clear_dirty_log(vm, slot, bitmaps[i], 0, pages_per_slot); + slot = MEMSTRESS_MEM_SLOT_INDEX + i; + from = 0; + clear_pages_count = pages_per_clear; + + while (from < pages_per_slot) { + if (from + clear_pages_count > pages_per_slot) + clear_pages_count = pages_per_slot - from; + kvm_vm_clear_dirty_log(vm, slot, bitmaps[i], from, + clear_pages_count); + from += clear_pages_count; + } } + } static unsigned long **alloc_bitmaps(int slots, uint64_t pages_per_slot) @@ -215,6 +228,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) uint64_t guest_num_pages; uint64_t host_num_pages; uint64_t pages_per_slot; + uint64_t pages_per_clear; struct timespec start; struct timespec ts_diff; struct timespec get_dirty_log_total = (struct timespec){0}; @@ -235,6 +249,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages); host_num_pages = vm_num_host_pages(mode, guest_num_pages); pages_per_slot = host_num_pages / p->slots; + pages_per_clear = p->clear_chunk_size / getpagesize(); bitmaps = alloc_bitmaps(p->slots, pages_per_slot); @@ -315,7 +330,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) if (dirty_log_manual_caps) { clock_gettime(CLOCK_MONOTONIC, &start); - clear_dirty_log(vm, bitmaps, p->slots, pages_per_slot); + clear_dirty_log_in_chunks(vm, bitmaps, p->slots, + pages_per_slot, + pages_per_clear); ts_diff = timespec_elapsed(start); clear_dirty_log_total = timespec_add(clear_dirty_log_total, ts_diff); @@ -413,6 +430,11 @@ static void help(char *name) " To leave the application task unpinned, drop the final entry:\n\n" " ./dirty_log_perf_test -v 3 -c 22,23,24\n\n" " (default: no pinning)\n"); + printf(" -k: Specify the chunk size in which dirty memory gets cleared\n" + " in memslots in each iteration. If the size is bigger than\n" + " the memslot size then whole memslot is cleared in one call.\n" + " Size must be aligned to the host page size. e.g. 10M or 3G\n" + " (default: UINT64_MAX, clears whole memslot in one call)\n"); puts(""); exit(0); } @@ -428,6 +450,7 @@ int main(int argc, char *argv[]) .slots = 1, .random_seed = 1, .write_percent = 100, + .clear_chunk_size = UINT64_MAX, }; int opt; @@ -438,7 +461,7 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "ab:c:eghi:m:nop:r:s:v:x:w:")) != -1) { + while ((opt = getopt(argc, argv, "ab:c:eghi:k:m:nop:r:s:v:x:w:")) != -1) { switch (opt) { case 'a': p.random_access = true; @@ -462,6 +485,9 @@ int main(int argc, char *argv[]) case 'i': p.iterations = atoi_positive("Number of iterations", optarg); break; + case 'k': + p.clear_chunk_size = parse_size(optarg); + break; case 'm': guest_modes_cmdline(optarg); break; From patchwork Fri Jun 2 16:09:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102648 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1145745vqr; Fri, 2 Jun 2023 09:20:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6yH019aYERMN4dtCgjCjdLOQhrAmepfpXSRgAZYHVZl+4ytNkzYWlM+p4miee1PB+BGjpY X-Received: by 2002:a05:6358:880b:b0:123:2dcc:afcd with SMTP id hv11-20020a056358880b00b001232dccafcdmr6998618rwb.1.1685722840951; Fri, 02 Jun 2023 09:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722840; cv=none; d=google.com; s=arc-20160816; b=m7hEi1Z64pfWs135PYGUIEO4m2MPCDITYad7sn3iXs6xl1pmBB58pfMZARlBFLeGNF 1dKZGbPnGOXVlPhf0JHXvLiQOcoI1ToV6QWkwmuwzEQEFXAT4h1oGSRvJ++Kp1KoM6aA VB8JkeX1yMVeVE9B0Qb3XGFSeGaHf66mdVAcKIGZT4zoNb6rQAjy3dQ/+866HN7jcQck pTrvjlJBn5HSiM0qGWUiOg4YF8acA0O7fLcajpUdqtatvFivY96DEwVB8pHJxEqGKF4l PkxzB/JsDx3PK8NYiFKy3Swrw+MPvp7OtWhSBAi/75VY8y5C87LPeZoGKINgiInercW6 MrLQ== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=reSpQux61RJZJqDsTFoDFmSOkfig6/G5ur1FFXdW+Iw=; b=cbI7zMOseY0Sv3TwHa9hCZBP/UZO7fVKdqPVEViLAFENrDjqF5LmPaWKRuI9kvDvCs vdadCb4OxVxtVvrCo/23awKoaLVmbQ8HbnA/yUjJkw71ccC7ImIqdCSbQmxQslj1wLMd QRxP5yHxTG3T9ZpVq2mJjgkBuvxuRhrVtZk51CnoyqRHaM8zXMpo2QAj2YWNJ8+ypK/4 6HaqEzfdxMGvoMV7YPchV55WT0GyHiXGe794rVYAsP+k7YLIwbjSxLlRpZd6ZlbjRIm4 J3K9XY+GlWQG8ZSI0uHSE5yv0RdtIKbOWKPMHJ9R6XJcqNKREHsR/vye17OtQg2zzfTl ILKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Nery7N09; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d26-20020a63735a000000b005030925d31asi1186640pgn.203.2023.06.02.09.20.28; Fri, 02 Jun 2023 09:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Nery7N09; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235825AbjFBQJb (ORCPT + 99 others); Fri, 2 Jun 2023 12:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236529AbjFBQJ0 (ORCPT ); Fri, 2 Jun 2023 12:09:26 -0400 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 AD88F1AD for ; Fri, 2 Jun 2023 09:09:24 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bb2202e0108so1016455276.1 for ; Fri, 02 Jun 2023 09:09:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722164; x=1688314164; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=reSpQux61RJZJqDsTFoDFmSOkfig6/G5ur1FFXdW+Iw=; b=Nery7N09ub9ZwszJcaP2RaQeFUpVfIUClULYoJNCv0nmmaSATwziFhFG6U3dYDLKoQ L9drpqC2yL+EBnwjo9iEoiI5SqrPJ4COUeKCUkto6WScJ4k7QxjCwWO+xu6zR2w8Ms7Y g71MEHJild0QfvuE9EvmodRfRpkB6FSwoCyRei/rwamIW8aYnRWnvssNIV+xig+yToqy 7LLYR4U6K3iWH99NzWXy3BA1U6+xbZoa0eqzZ6Q+yGdcRqc3MVym+ONWDEZ2yy/xmSHV b2XWmusMNnhXq3avpcOVHAJU3vLRZTkYx3P/807P0dyObmLHptHPl4+5txiV/ugQdwi2 WupA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722164; x=1688314164; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=reSpQux61RJZJqDsTFoDFmSOkfig6/G5ur1FFXdW+Iw=; b=giF0kvDRm9xfmMqNtZSB9K+V/mzd4FQG/CiWcC2CDAArtMehFfAenjGAP21ESgxtc/ zhAk8RSBFDfyPxzasZSbLJwuOplKx1eu2PwWE+ozaQTyUlbtr24A88ifL2ufUu/Ukb9N TxVBaZ2ygFypSEJXL5cTvCH/vn27odWxF7hEZNF4ddABn0X+JZmffxWn6QBTlBghyJrj O8gNgmBrxRstec9krF0YwZl6bEE96WvMkM+E28Yra17jGlCQmrlgdDRaSZxsjXqYjhmS +9D90MFBpgX62P2IB6YZUlc6ZQ8gWRdSNWsNWV6qIHEsazbB5e1It1lckAONq4ADUzsR 2Aog== X-Gm-Message-State: AC+VfDwbM8+oTjbFg4kjrrO/d6ySD+hGNp+CTwz2ff7YS7AcHq0N9PUT IdQPSLB4gsjkEFGeHDDW+oeh31OxXdHu X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a25:cd0a:0:b0:ba8:918a:ceec with SMTP id d10-20020a25cd0a000000b00ba8918aceecmr470216ybf.4.1685722163747; Fri, 02 Jun 2023 09:09:23 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:00 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-3-vipinsh@google.com> Subject: [PATCH v2 02/16] KVM: selftests: Add optional delay between consecutive clear-dirty-log calls From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767608513694580286?= X-GMAIL-MSGID: =?utf-8?q?1767608513694580286?= In dirty_log_perf_test, add option "-l" to wait between consecutive clear-dirty-log calls. Accept delay from user in milliseconds. If option is not provided then fallback to no wait between clear calls. This allows dirty_log_perf_test to mimic real world use where after clearing dirty memory, some time is spent in transferring memory before making a subsequeunt clear-dirty-log call. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 119ddfc7306e..2e31f13aaba6 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -135,6 +135,7 @@ struct test_params { uint32_t random_seed; bool random_access; uint64_t clear_chunk_size; + int clear_chunk_wait_time_ms; }; static void toggle_dirty_logging(struct kvm_vm *vm, int slots, bool enable) @@ -173,8 +174,14 @@ static void get_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], int slots static void clear_dirty_log_in_chunks(struct kvm_vm *vm, unsigned long *bitmaps[], int slots, uint64_t pages_per_slot, - uint64_t pages_per_clear) + uint64_t pages_per_clear, int wait_ms, + struct timespec *time_taken) { + struct timespec wait = { + .tv_sec = wait_ms / 1000, + .tv_nsec = (wait_ms % 1000) * 1000000ull, + }; + struct timespec start, end; uint64_t from, clear_pages_count; int i, slot; @@ -186,12 +193,17 @@ static void clear_dirty_log_in_chunks(struct kvm_vm *vm, while (from < pages_per_slot) { if (from + clear_pages_count > pages_per_slot) clear_pages_count = pages_per_slot - from; + clock_gettime(CLOCK_MONOTONIC, &start); kvm_vm_clear_dirty_log(vm, slot, bitmaps[i], from, clear_pages_count); + end = timespec_elapsed(start); + *time_taken = timespec_add(*time_taken, end); from += clear_pages_count; + if (wait_ms) + nanosleep(&wait, NULL); + } } - } static unsigned long **alloc_bitmaps(int slots, uint64_t pages_per_slot) @@ -329,11 +341,11 @@ static void run_test(enum vm_guest_mode mode, void *arg) iteration, ts_diff.tv_sec, ts_diff.tv_nsec); if (dirty_log_manual_caps) { - clock_gettime(CLOCK_MONOTONIC, &start); clear_dirty_log_in_chunks(vm, bitmaps, p->slots, pages_per_slot, - pages_per_clear); - ts_diff = timespec_elapsed(start); + pages_per_clear, + p->clear_chunk_wait_time_ms, + &ts_diff); clear_dirty_log_total = timespec_add(clear_dirty_log_total, ts_diff); pr_info("Iteration %d clear dirty log time: %ld.%.9lds\n", @@ -435,6 +447,11 @@ static void help(char *name) " the memslot size then whole memslot is cleared in one call.\n" " Size must be aligned to the host page size. e.g. 10M or 3G\n" " (default: UINT64_MAX, clears whole memslot in one call)\n"); + printf(" -l: Specify time in milliseconds to wait after Clear-Dirty-Log\n" + " call. This allows to mimic use cases where flow is to get\n" + " dirty log followed by multiple clear dirty log calls and\n" + " sending corresponding memory to destination (in this test\n" + " sending will be just idle waiting)\n"); puts(""); exit(0); } @@ -451,6 +468,7 @@ int main(int argc, char *argv[]) .random_seed = 1, .write_percent = 100, .clear_chunk_size = UINT64_MAX, + .clear_chunk_wait_time_ms = 0, }; int opt; @@ -461,7 +479,7 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "ab:c:eghi:k:m:nop:r:s:v:x:w:")) != -1) { + while ((opt = getopt(argc, argv, "ab:c:eghi:k:l:m:nop:r:s:v:x:w:")) != -1) { switch (opt) { case 'a': p.random_access = true; @@ -488,6 +506,11 @@ int main(int argc, char *argv[]) case 'k': p.clear_chunk_size = parse_size(optarg); break; + case 'l': + p.clear_chunk_wait_time_ms = + atoi_non_negative("Clear dirty log chunks wait time", + optarg); + break; case 'm': guest_modes_cmdline(optarg); break; From patchwork Fri Jun 2 16:09:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1139608vqr; Fri, 2 Jun 2023 09:11:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IV5+hqR76rAPkR+VtDm4avY54ledXqYvpMlj6A84iRCK9/CmEigyclPrMWjhHt0WBvPWP X-Received: by 2002:a17:903:26c4:b0:1b1:b50c:e313 with SMTP id jg4-20020a17090326c400b001b1b50ce313mr322533plb.66.1685722283364; Fri, 02 Jun 2023 09:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722283; cv=none; d=google.com; s=arc-20160816; b=rXQvFq6c/7IJ+re+LdiURoTISGGimPAnPUEuByudboiSv5yKESK9zT2kF/Vjh+7kh0 HiV7dSMheMMw7iqukTGt6a+RzeBT2KJ4ZGJIMQbUBP1RXphl4ulv6z2cDsyRBn96Rjph P7xY2B02FgWpSQ/zSdThABkMi0pBC7UGJAHLOkC5uWPQFQC9+zGRQo09KMqCPn8Vg3i5 iizA2h1cMuGMyVhh68dOpkD3Y5cbl4ImZ8eCe2MyqafaXBLR6grJNGcHp9H0h0Xu+Cvg umI5W9TdVY+3d49kBJ1XmSP/7jLXaEPdUn4mheauiLXGCtKJl7pwAl3sRBqxgXb487IO uoJA== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=U16a7SsqQ7yjyv5J8Y2N4u7Ylkl11H9qatwpuhmZUgo=; b=ZVTzTdRbh0Zs75/gsQIQvFcDnNngnzJODrTnFH98LQoA5GcDlB+qSiP1jG/Ft5Srkn LLQrn33zrfElGDlmC75LyiHor4OupyJc4HE2b4/mklJ+E7hpkzqzrTBLZs/uzFOnSiPM jbqAP3xwK7VvuzQCjQuqX1Mnf2mszVz/ASlg8Pg+/Yvpg/xhGXxTbgwgI0CBZB//FfWF 9w4Ek/ofP+uT3NQi1dc9QHxAYXn13trl9iBL0LeZ3hPOKj1B/gc+MjWl6qlUW5wCa/7Y zo/Mjf+lqkgisBE7ikZ7MIwmgr6YTNmrzUVqlOjFqtzNdZugV6yQyFdqjSIVva1pS72t F35A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=636YoGkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a170902d89100b001a8031f3964si1080962plz.437.2023.06.02.09.11.09; Fri, 02 Jun 2023 09:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=636YoGkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236646AbjFBQJd (ORCPT + 99 others); Fri, 2 Jun 2023 12:09:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236561AbjFBQJ2 (ORCPT ); Fri, 2 Jun 2023 12:09:28 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50AAD132 for ; Fri, 2 Jun 2023 09:09:26 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2566b668cc5so1567374a91.0 for ; Fri, 02 Jun 2023 09:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722166; x=1688314166; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=U16a7SsqQ7yjyv5J8Y2N4u7Ylkl11H9qatwpuhmZUgo=; b=636YoGkhL1EaD07rsMfPK9rB926Ht76M8pVZszNcRp8cSFBaHFxW4ESJErvKH1m1wQ b8SVVb+49Lm4c7lpuGUxvabzksatMUh3aHtTfXuucGjqsfAbB7x8jB5X+IIkfWd/B+pM hI1Jypk91JlkfEFB2dbGzi8Bjd9QmphZBvbPzeFfXopwyd64oFIEk7hcFeTi49fzsYb0 jMhjapC0h8n44W4QCQ7q/RI4lKIJPywJjobPFbGliUK4+jwpyLj3v9rdAbRrHTavotzv jSbTLKdo3Rd++6WRrKKX3ZluUSmLDy9wL6sxwwb/x/fXUrLPPNX7BCJ2JivFRXiwGY+V XR9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722166; x=1688314166; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U16a7SsqQ7yjyv5J8Y2N4u7Ylkl11H9qatwpuhmZUgo=; b=j8TsfQiCqClzJoCwWB0J6H0nT2RL3YDiL48roj3ah1+OPLhSgYfArdzeYpbSCGNRAq LsM65gYyRL5mCKSDnaF8k7CcSb1uJBy8wDMOsiuC0Yx/BJ2lIxQ0Chgr97cyQwjG252t Ubyi99NpXpbkCUZkzSvpTSw8eeWDPhMTQBL6k2+nBRM2d61ex0Cl/ABKnk7DaAUFKcet RjMKYMNlAdr3Qf038gPhYwEYojYLb5LcjtRzyy60kFR3d4e4qFr0qivYuZfUQFIyvhWF Md6N+ruPaSrdDRreIRyks0ib2o8Zhe5omtbN//8ygPpAKKp0gVJH562hDASeYZHUNMwa 35ag== X-Gm-Message-State: AC+VfDz5GVzUhSVwpfw2H3L7kR5UsoBBW3pS7AFqGZZ+A4ugNSoB0U6A 20ReweYnPLmFLWXzrqFvHwKr0Rvy6QTc X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:de04:b0:24e:18ff:5bad with SMTP id m4-20020a17090ade0400b0024e18ff5badmr42850pjv.0.1685722165847; Fri, 02 Jun 2023 09:09:25 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:01 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-4-vipinsh@google.com> Subject: [PATCH v2 03/16] KVM: selftests: Pass the count of read and write accesses from guest to host From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607928740836496?= X-GMAIL-MSGID: =?utf-8?q?1767607928740836496?= Pass the number of read and write accesses done in the memstress guest code to userspace. These counts will provide a way to measure vCPUs performance during memstress and dirty logging related tests. For example, in dirty_log_perf_test this can be used to measure how much progress vCPUs are able to do while VMM is getting and clearing dirty logs. In dirty_log_perf_test, each vCPU runs once and then waits until iteration value is incremented by main thread, therefore, these access counts will not provide much useful information except for observing read vs write counts. However, in future commits, dirty_log_perf_test behavior will be changed to allow vCPUs to execute independent of userspace iterations. This will mimic real world workload where guest keeps on executing while VMM is collecting and clearing dirty logs separately. With read and write accesses known for each vCPU, impact of get and clear dirty log APIs can be quantified. Note that access counts will not be 100% reliable in knowing vCPUs performances. Few things which can affect vCPU progress: 1. vCPUs are scheduled less by host 2. Userspace operations run for longer time which end up giving vCPUs more time to execute. Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/lib/memstress.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c index 5f1d3173c238..ac53cc6e36d7 100644 --- a/tools/testing/selftests/kvm/lib/memstress.c +++ b/tools/testing/selftests/kvm/lib/memstress.c @@ -49,6 +49,8 @@ void memstress_guest_code(uint32_t vcpu_idx) struct memstress_args *args = &memstress_args; struct memstress_vcpu_args *vcpu_args = &args->vcpu_args[vcpu_idx]; struct guest_random_state rand_state; + uint64_t write_access; + uint64_t read_access; uint64_t gva; uint64_t pages; uint64_t addr; @@ -64,6 +66,8 @@ void memstress_guest_code(uint32_t vcpu_idx) GUEST_ASSERT(vcpu_args->vcpu_idx == vcpu_idx); while (true) { + write_access = 0; + read_access = 0; for (i = 0; i < pages; i++) { if (args->random_access) page = guest_random_u32(&rand_state) % pages; @@ -72,13 +76,16 @@ void memstress_guest_code(uint32_t vcpu_idx) addr = gva + (page * args->guest_page_size); - if (guest_random_u32(&rand_state) % 100 < args->write_percent) + if (guest_random_u32(&rand_state) % 100 < args->write_percent) { *(uint64_t *)addr = 0x0123456789ABCDEF; - else + write_access++; + } else { READ_ONCE(*(uint64_t *)addr); + read_access++; + } } - GUEST_SYNC(1); + GUEST_SYNC_ARGS(1, read_access, write_access, 0, 0); } } From patchwork Fri Jun 2 16:09:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102650 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1145894vqr; Fri, 2 Jun 2023 09:20:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JVTp0yKAw+YNb2tUUmA092pXknbeXqe7rjVMkC76WCNm254Fh7BvN5uM7oPwqT9v9qTje X-Received: by 2002:a17:902:ce90:b0:1b1:a829:e2b5 with SMTP id f16-20020a170902ce9000b001b1a829e2b5mr443389plg.52.1685722855801; Fri, 02 Jun 2023 09:20:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722855; cv=none; d=google.com; s=arc-20160816; b=ZFxwHGx+SSc4zU9GTk5SJWZT7BtAGKssgmu/fvgtr4IswomtQHimvJUZGXG3iM9q/d MSKFJPiqd33XiY8MtgSHTriJ4IaumAZdRj4bUf6+oqsgdBir8/tG96WfQdRD5qniVUtd YBsnRqpPl/zT011CL9uCa0BV33FruAXXQMxh3JVznIP82ru0IAYQyroKG+r3EMO1ueoe BLXcew3KUI/tye64baDRmAAgT2vOj4Z6NPM56b/6rLz/OaQpM0WKvwmCxposDAfNWwVm PU4YuN7MooSY0SoFHmThwmOLu311fCVVDLeEJcCiUUZQMsIati52H8Cc/28nPkbJukAU IstA== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=vX8ZCjC9l+xt5cqUnwzlqCkk/7EvJIEZcs67EwYM95Y=; b=KDECRC4DRZpvskgC7eZTS2uWi2ugqwys+W2PzyhMkvyFZDuOCDqb2M085vIa00XLff MGVZrHIUUoc6JaqIV/ycxbQEEI4TfXEbkIQokB1Hv3F8k5LhhS8Mrwny+Zv2gQIzl3FB 7fmjcgojSLpI9nA3jUXv6SVVwPVaGZ73vw3cZciORhS/CR3YowzyXM7+haeAjHT1pEMW XPfNIhQWzvhufyvLc7Zdnzy30mtYnhJguHg3ylmGclgixdqJ+StJclzv6YNn8GkzygHJ K78O9UH8h4jVjqfB/ZKlNetfKQ+6WS5wobAQjzW5P28h+a8z/ON3AICAvZ+Mlh+l87zU llKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ZpYUhbbZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020a170902bd8d00b001a97262fe53si1050814pls.552.2023.06.02.09.20.42; Fri, 02 Jun 2023 09:20:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ZpYUhbbZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236730AbjFBQKM (ORCPT + 99 others); Fri, 2 Jun 2023 12:10:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236616AbjFBQJc (ORCPT ); Fri, 2 Jun 2023 12:09:32 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52C30E42 for ; Fri, 2 Jun 2023 09:09:28 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5340957a1f1so975249a12.1 for ; Fri, 02 Jun 2023 09:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722167; x=1688314167; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vX8ZCjC9l+xt5cqUnwzlqCkk/7EvJIEZcs67EwYM95Y=; b=ZpYUhbbZC6uUYrReM+ixNdEUwp22WUU7l8j2aahWsJUYqP381L7DaYeopKye6+Q9sn w6jGO0nX6WnAtH7Q3sGlOdc68vECR5PacYtF8uFrv3gPYqUB1KYLtsQIi3wA+701ktoo VcYLyZENUnFYI88cWmJbgLosheXItBqWsjUj1JOOFK7yQMQ1EVYBrKEM74EAZ9G1JJes +Fy3XP3gLD3JszJ1CTZiXeoILpXFoZBpgnn/vdDYBMvk+Dqwv0kvHMMpaOH7tt3QFj+s ke1ao1kRwftxIusnCaBSonu2zz1KVzCGGfUgW7HZsGqYe4xCh5lCKxmVw7qkF3LGd5ny Gpkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722167; x=1688314167; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vX8ZCjC9l+xt5cqUnwzlqCkk/7EvJIEZcs67EwYM95Y=; b=T5t8ks4w6Pa7UI8Az3p3S7mlR7AhPmb2Xi4Ob+ZcuTp4zIqRUE1P2DNcm89tJN+yyv B/FFCoIGC1WPfLLT38OKilo6SSXbb4Wrdn8SXCGVyxbtIhwtbscoa3qeIFLCQo7sViUo OMnDdDUN1XXqPIclfpISFgqMwZuEzHjpg/tsQef8uDPanUrwm0YZW60saCBgUmOknzJ2 GLnil30X4E5MTsCyas3XI8GlKeRMHdqiYjFLq3TaPIb+I+kV2AmI5NnXGMBWYGxTGk0U U9dS9mnrTvES+Tcx+6vYk9s/W2gMd2e/VsjkxubMt+dk2sH5P4y5Qh2j51b8fGewtFe5 Wesw== X-Gm-Message-State: AC+VfDwFzbvauoPEPeZJROAZepCks2xso8gIpY2UmyYJKGZAh8cquB1L tX20Ze1x+vHX4sBN68LSp0fGt7zp8SWs X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a63:685:0:b0:530:866e:c3c1 with SMTP id 127-20020a630685000000b00530866ec3c1mr2520235pgg.11.1685722167618; Fri, 02 Jun 2023 09:09:27 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:02 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-5-vipinsh@google.com> Subject: [PATCH v2 04/16] KVM: selftests: Print read-write progress by vCPUs in dirty_log_perf_test From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767608529351480821?= X-GMAIL-MSGID: =?utf-8?q?1767608529351480821?= Fetch count of read and write accesses from guest code and print sum of these values across all vCPUs in dirty_log_perf_test. This data provides progress made by vCPUs during dirty logging operations. Since, vCPUs execute in lockstep with userspace dirty log iterations, this metric is not very interesting. However, in future commits when dirty_log_perf_test can execute vCPUs independently from dirty log iterations then this metric can give good measure of vCPUs performance during dirty logging. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 2e31f13aaba6..14b012a0dcb1 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "kvm_util.h" @@ -66,17 +67,22 @@ static u64 dirty_log_manual_caps; static bool host_quit; static int iteration; static int vcpu_last_completed_iteration[KVM_MAX_VCPUS]; +static atomic_ullong total_reads; +static atomic_ullong total_writes; static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) { struct kvm_vcpu *vcpu = vcpu_args->vcpu; int vcpu_idx = vcpu_args->vcpu_idx; uint64_t pages_count = 0; + uint64_t reads = 0; + uint64_t writes = 0; struct kvm_run *run; struct timespec start; struct timespec ts_diff; struct timespec total = (struct timespec){0}; struct timespec avg; + struct ucall uc = {}; int ret; run = vcpu->run; @@ -89,7 +95,7 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) ts_diff = timespec_elapsed(start); TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret); - TEST_ASSERT(get_ucall(vcpu, NULL) == UCALL_SYNC, + TEST_ASSERT(get_ucall(vcpu, &uc) == UCALL_SYNC, "Invalid guest sync status: exit_reason=%s\n", exit_reason_str(run->exit_reason)); @@ -101,6 +107,8 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) if (current_iteration) { pages_count += vcpu_args->pages; total = timespec_add(total, ts_diff); + reads += uc.args[2]; + writes += uc.args[3]; pr_debug("vCPU %d iteration %d dirty memory time: %ld.%.9lds\n", vcpu_idx, current_iteration, ts_diff.tv_sec, ts_diff.tv_nsec); @@ -123,6 +131,8 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) pr_debug("\nvCPU %d dirtied 0x%lx pages over %d iterations in %ld.%.9lds. (Avg %ld.%.9lds/iteration)\n", vcpu_idx, pages_count, vcpu_last_completed_iteration[vcpu_idx], total.tv_sec, total.tv_nsec, avg.tv_sec, avg.tv_nsec); + atomic_fetch_add(&total_reads, reads); + atomic_fetch_add(&total_writes, writes); } struct test_params { @@ -270,6 +280,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) dirty_log_manual_caps); arch_setup_vm(vm, nr_vcpus); + atomic_store(&total_reads, 0); + atomic_store(&total_writes, 0); /* Start the iterations */ iteration = 0; @@ -388,6 +400,10 @@ static void run_test(enum vm_guest_mode mode, void *arg) clear_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec); } + pr_info("Total pages touched: %llu (Reads: %llu, Writes: %llu)\n", + atomic_load(&total_reads) + atomic_load(&total_writes), + atomic_load(&total_reads), atomic_load(&total_writes)); + free_bitmaps(bitmaps, p->slots); arch_cleanup_vm(vm); memstress_destroy_vm(vm); From patchwork Fri Jun 2 16:09:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102637 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1139535vqr; Fri, 2 Jun 2023 09:11:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ671Rhf3hbNjb+2s5Spk3wA/QFp5NK4JU9T/ix/Lb4TW1GyOqf76P/E1OtxH2augxE0erDV X-Received: by 2002:a17:90a:7146:b0:258:9174:20a8 with SMTP id g6-20020a17090a714600b00258917420a8mr286005pjs.35.1685722276576; Fri, 02 Jun 2023 09:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722276; cv=none; d=google.com; s=arc-20160816; b=nPLC3B/4yu3/Vry8jzOw5DeIAKOYCIO5kQcYC40bzQS8u8mKLy52ucmNX3QNpBDIX5 4jWNGxA89XgWl+jmgYfrvpkYlel0cvG8qo7m2ewpo8169OzzfkjUVZwpcJFJJNuQYKzI oiqaMIAygIP1fKS+0+kR7r/Yz5mTzPsNS7f/0vO6gVFiDz5PDlcIaej0tSHJ/XnENOr6 qh/TfyDITEgK08Ccehn9fjD799LJgFvzEl1Yvmg2DjGPWOh1IWGvGzFAXTrWduDtBASO PFyc1xbxAZG58fK2GKfdU7HAsuZGo70PNCnxcMjyPqGz5QabR2w2rXLXx30H0MzLirtZ 3fbQ== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=TCZIk7VgxCOZOGj9BrulapCebBiXjQ5+VJfBT1Ieq9g=; b=0hcp7eHN5lIv/IzKJIVFygP3JPClQhvucPpnJ9Kxvs/PqSduR8vO95gLUNpCfHMrnD lWtZr7325G4mIxRqGjl/WrwQJyS8kNZhZDL1d3WKegxT51Lb9hOK6IlEeu4ElXgMPM1g SDL78/YCAiQi78j3awtYoYau5TJ7T139CAj902mQ87oAdfmg68hhw/VMbEcDQhbAsIgp qjXeLhZnpGMaDZ4VEA2bxKVDvm/fta1mC4Ep1Lo7utvoJn6Ejdlnpy3IWPYQTiAdkLHH Un1Q8OORkRqTT/bu8r5dYoe0D0gc3yr3IDhw/lhsTYW8MVeTSmZK+ofPCzUw50g6oXdX kObQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=48Jv9Ndg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m4-20020a6545c4000000b0053f4a727dacsi1197342pgr.251.2023.06.02.09.11.03; Fri, 02 Jun 2023 09:11:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=48Jv9Ndg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236349AbjFBQKS (ORCPT + 99 others); Fri, 2 Jun 2023 12:10:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236308AbjFBQJn (ORCPT ); Fri, 2 Jun 2023 12:09:43 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5086AE52 for ; Fri, 2 Jun 2023 09:09:30 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-52857fc23b1so2072345a12.2 for ; Fri, 02 Jun 2023 09:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722169; x=1688314169; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TCZIk7VgxCOZOGj9BrulapCebBiXjQ5+VJfBT1Ieq9g=; b=48Jv9Ndg6W2FWtv0TNF+EvHQkuzevnf0de3wNHQhiINnd1y+TJ3ZHZNsYvgiBjl6lh 9WUrwiuBOv0A4GYPSawEV6yVx5LbPQL0U+gQGnFWAFVUnyrF1z1qm1xlbl6HRjy6NNwE 8XB2SVK1dbUaEeLrM/H8JHaqBSIup+A6xNFpzpaufkcVOP+VAaTUukUdmKNrTQcISuZt yTtWhk1kuZr3BXzyN9NP6mKp7IAXkKM1nK9WQaTXO/PtqFm7I9EIaNt4fcwETtWcECAj 9ktEJ+8oLB8jJgpGPXgzImfVTKXWHcOIgbQS6xiesRZonieLTn89FjSta0ZVX6QUoqee mZLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722169; x=1688314169; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TCZIk7VgxCOZOGj9BrulapCebBiXjQ5+VJfBT1Ieq9g=; b=lEwl30rZA0RxS8XXWMGf3OlM7o08zYDaLTl8UHa38AfqykGAca3lwLtizRJngAiP4X SGEmZfrTuu1U1VdgF4+ZO2T9jIGDIrhiek1VcPEg9gwW+8hHr7Qewsyy3jRCk0uY8Pxh cZrSzhDPQ/f3T3kXB3KiaNXuI8Auu91mo2To4ilWvCVqJiKZtIckDukinPQs55pWOsXH xF9sKf7uap9Zn/X/OATZRk5SvN47WANamBWTQktIW255cHFWt1tJ53suxNIyGUutLBIf j4XNo0y8vXe4LImnoPjGvHWXNdwSp1g4b23GL0plTJaDo+zls0wR1+nFX0Spnnkvm12+ O40Q== X-Gm-Message-State: AC+VfDxY6oc6Y8Il8pQd2j/Zpk08uVPf8gNCTm43uA8MuEqYqgdu45a1 ppegSsFi/qd4CoczHgzcaUu0NJVu9TSK X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a63:d044:0:b0:53f:32cf:bcd1 with SMTP id s4-20020a63d044000000b0053f32cfbcd1mr2492124pgi.5.1685722169678; Fri, 02 Jun 2023 09:09:29 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:03 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-6-vipinsh@google.com> Subject: [PATCH v2 05/16] KVM: selftests: Allow independent execution of vCPUs in dirty_log_perf_test From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607922166709415?= X-GMAIL-MSGID: =?utf-8?q?1767607922166709415?= Give users command line option (-j) to execute vCPUs independently of dirty log iterations after initialization is complete. This change makes dirty_log_perf_test behave like real world workflows where guest vCPUs keep on executing while VMM collects and clear dirty logs. Total pages touched during execution of test will give good estimate of how vCPUs are performing while dirty logging is enabled. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 14b012a0dcb1..fbf973d6cc66 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -69,6 +69,7 @@ static int iteration; static int vcpu_last_completed_iteration[KVM_MAX_VCPUS]; static atomic_ullong total_reads; static atomic_ullong total_writes; +static bool lockstep_iterations; static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) { @@ -83,12 +84,16 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) struct timespec total = (struct timespec){0}; struct timespec avg; struct ucall uc = {}; + int current_iteration = -1; int ret; run = vcpu->run; while (!READ_ONCE(host_quit)) { - int current_iteration = READ_ONCE(iteration); + if (lockstep_iterations) + current_iteration = READ_ONCE(iteration); + else + current_iteration++; clock_gettime(CLOCK_MONOTONIC, &start); ret = _vcpu_run(vcpu); @@ -118,13 +123,19 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) ts_diff.tv_nsec); } - /* - * Keep running the guest while dirty logging is being disabled - * (iteration is negative) so that vCPUs are accessing memory - * for the entire duration of zapping collapsible SPTEs. - */ - while (current_iteration == READ_ONCE(iteration) && - READ_ONCE(iteration) >= 0 && !READ_ONCE(host_quit)) {} + if (lockstep_iterations) { + /* + * Keep running the guest while dirty logging is being disabled + * (iteration is negative) so that vCPUs are accessing memory + * for the entire duration of zapping collapsible SPTEs. + */ + while (current_iteration == READ_ONCE(iteration) && + READ_ONCE(iteration) >= 0 && !READ_ONCE(host_quit)) + ; + } else { + while (!READ_ONCE(iteration) && !READ_ONCE(host_quit)) + ; + } } avg = timespec_div(total, vcpu_last_completed_iteration[vcpu_idx]); @@ -332,18 +343,20 @@ static void run_test(enum vm_guest_mode mode, void *arg) clock_gettime(CLOCK_MONOTONIC, &start); iteration++; - pr_debug("Starting iteration %d\n", iteration); - for (i = 0; i < nr_vcpus; i++) { - while (READ_ONCE(vcpu_last_completed_iteration[i]) - != iteration) - ; + if (lockstep_iterations) { + pr_debug("Starting iteration %d\n", iteration); + for (i = 0; i < nr_vcpus; i++) { + while (READ_ONCE(vcpu_last_completed_iteration[i]) + != iteration) + ; + } + + ts_diff = timespec_elapsed(start); + vcpu_dirty_total = timespec_add(vcpu_dirty_total, ts_diff); + pr_info("Iteration %d dirty memory time: %ld.%.9lds\n", + iteration, ts_diff.tv_sec, ts_diff.tv_nsec); } - ts_diff = timespec_elapsed(start); - vcpu_dirty_total = timespec_add(vcpu_dirty_total, ts_diff); - pr_info("Iteration %d dirty memory time: %ld.%.9lds\n", - iteration, ts_diff.tv_sec, ts_diff.tv_nsec); - clock_gettime(CLOCK_MONOTONIC, &start); get_dirty_log(vm, bitmaps, p->slots); ts_diff = timespec_elapsed(start); @@ -365,6 +378,10 @@ static void run_test(enum vm_guest_mode mode, void *arg) } } + /* Block further vCPUs execution */ + if (!lockstep_iterations) + WRITE_ONCE(iteration, 0); + /* * Run vCPUs while dirty logging is being disabled to stress disabling * in terms of both performance and correctness. Opt-in via command @@ -458,6 +475,10 @@ static void help(char *name) " To leave the application task unpinned, drop the final entry:\n\n" " ./dirty_log_perf_test -v 3 -c 22,23,24\n\n" " (default: no pinning)\n"); + printf(" -j: Execute vCPUs independent of dirty log iterations\n" + " Independent vCPUs execution will allow them to continuously\n" + " dirty memory while main thread is collecting and clearing\n" + " dirty logs in each iteration.\n"); printf(" -k: Specify the chunk size in which dirty memory gets cleared\n" " in memslots in each iteration. If the size is bigger than\n" " the memslot size then whole memslot is cleared in one call.\n" @@ -492,10 +513,10 @@ int main(int argc, char *argv[]) kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | KVM_DIRTY_LOG_INITIALLY_SET); - + lockstep_iterations = true; guest_modes_append_default(); - while ((opt = getopt(argc, argv, "ab:c:eghi:k:l:m:nop:r:s:v:x:w:")) != -1) { + while ((opt = getopt(argc, argv, "ab:c:eghi:jk:l:m:nop:r:s:v:x:w:")) != -1) { switch (opt) { case 'a': p.random_access = true; @@ -519,6 +540,9 @@ int main(int argc, char *argv[]) case 'i': p.iterations = atoi_positive("Number of iterations", optarg); break; + case 'j': + lockstep_iterations = false; + break; case 'k': p.clear_chunk_size = parse_size(optarg); break; From patchwork Fri Jun 2 16:09:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1139336vqr; Fri, 2 Jun 2023 09:11:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ANwL8TGJ94u23jhzqIAAjdpTWi+8GSr2uqTVHzdkhojTVUSNOmvvunUeqpS0MRL8H7TR7 X-Received: by 2002:a05:6a20:2583:b0:110:9210:f6ac with SMTP id k3-20020a056a20258300b001109210f6acmr10595547pzd.37.1685722260237; Fri, 02 Jun 2023 09:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722260; cv=none; d=google.com; s=arc-20160816; b=hXtsM6W1pYx59+WKv8BapizaVeP0YUQxxfyHOUh2w7jMN0xETsqKTXuyNyraAi6cvg ulB2UmJr+vZ7fHgrqThi4YfMxTrvP0v46KgsGzQLPX9iAUtXkBKb1wV8lABNB6cvGp/o 1GmPYsxLEAeq5Mre4ivyFqcBnCJ38vbRjaaM6FyeyiE7yQoUYFYPrw6O8jg0/uZstL48 3MnETWP6wID149fVk3sq37PPRk+FXa3k6gNRQwd9AagVT1GAwGF49LM7QlulHcefdvPM XbYjLyX1cIlUYeKZ507WuIGnpKxmdWAsL5pJyrphXySy5GsgEvByMn8OqTfkJLCCIzmn wEMg== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=fngtlIXFBOk5ojPhoCZKxdftJsl/PCjzcivfHulUfxM=; b=WvVdSWYQIq2n0274D/dmip09RbwmuHCTPJ9RVlnylsLkw88p/2mDVIpOIVzdbhECMU W1MH1tGC3dEPOPX6wG11Vgx3Gd3qKvnTd5wWlUXhQZdZjVbpldy333P+IEm/tscqERKk FCDT9Sg4jGUfBY/1gkHdOUk95eQI2RQBMcXgsDbnIuB99rCa3F/G9310ffm00FxWRVul VzxX5Pt17fPfMreVqxR9cXvFbuFJP0s0equC9C3U5nU1o/6RpbHktu+wLp1leAoM6dfa IKEHAyDnQFsgtXrXE/QTTA2IA65vdC3GtDrvIa9TEpTjiFzumv7iZrHxU6ULMCOb80mY Lrjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=KTqFTUl8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v18-20020a637a12000000b0053145cd75besi1186225pgc.41.2023.06.02.09.10.47; Fri, 02 Jun 2023 09:11:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=KTqFTUl8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236592AbjFBQJ7 (ORCPT + 99 others); Fri, 2 Jun 2023 12:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236607AbjFBQJn (ORCPT ); Fri, 2 Jun 2023 12:09:43 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B130E1B9 for ; Fri, 2 Jun 2023 09:09:32 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-564fb1018bcso33918577b3.0 for ; Fri, 02 Jun 2023 09:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722172; x=1688314172; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fngtlIXFBOk5ojPhoCZKxdftJsl/PCjzcivfHulUfxM=; b=KTqFTUl8/O/otunDnIcW8NMT9NoZpURoL+fT5x3jr7xLTtmqLTsOpMHELHqceBBNBQ AmDayYQtgKFH5Z55J+qEEznt7CMzcfBLKa9rXdwkcbaxYdDyFrpWK5tIf+OgM6RdtGyq GQdHIK3QOQ2drYG/ZFFk+kHjBy+s90SO6eGGqGaoiIn9r7XkEBIEo/mXJtp3GumBEOA+ p4STDDMfVtsOTK10O8PNGuXazkAWxMkEfK3iCnrl9MiWc43AYLln6h9/+ty9OxynFFMd DAYdFz0PuZJQnqyg+7O9VnZBBnLY/2RVdSpDM0DZZNDzkFP0BkvcK+wZMlJvwm1mfdaV VyLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722172; x=1688314172; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fngtlIXFBOk5ojPhoCZKxdftJsl/PCjzcivfHulUfxM=; b=H6ZDeBD65n/WjTTUr1a0pKlkNCVRt6BPo32qmtccKq7TljWjD3i4Jxf8eOTPjz5B6w O2ZMlFa/CAsJBMHIPw9kGQya45GyB+q3JlOawYbvveIC7w01+CZybwBr8+MpSwMJKaXn gCKZjCjy78wOGVeyEO6PbyLFFROT5XuMaGNuMzjeSq2VyTnJ/0j11+ZaTSJEeb0VVcoW z9EkT0TsON+Cd5JvXHatgeCsLe0pBbygowSOHbnPZgvX19NzXLYiYnztgZ0GnLztxyLR NN0fPAS5iB52S+7xy4EF7cwnBdBBFErJXRFNWjDef7HtjVMRMcz8H55+aa4fT7i9SwRo GJ1A== X-Gm-Message-State: AC+VfDwoD1kVQQMPhyt8cQLoZRaVtyzLsHL1hZ7Z8Il1ixmtRSYJeg6V D6YNZZURuT0vOZDzsu6WWOLy+4IeaZk7 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a81:c509:0:b0:55a:3133:86fa with SMTP id k9-20020a81c509000000b0055a313386famr182818ywi.3.1685722171727; Fri, 02 Jun 2023 09:09:31 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:04 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-7-vipinsh@google.com> Subject: [PATCH v2 06/16] KVM: arm64: Correct the kvm_pgtable_stage2_flush() documentation From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607904542841328?= X-GMAIL-MSGID: =?utf-8?q?1767607904542841328?= Remove _range suffix from kvm_pgtable_stage2_flush_range which is used in documentation of kvm_pgtable_stage2_flush(). There is no function named kvm_pgtable_stage2_flush_range(). Fixes: 93c66b40d728 ("KVM: arm64: Add support for stage-2 cache flushing in generic page-table") Signed-off-by: Vipin Sharma --- arch/arm64/include/asm/kvm_pgtable.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 850d65f705fa..d542a671c564 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -657,9 +657,8 @@ int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr, bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr); /** - * kvm_pgtable_stage2_flush_range() - Clean and invalidate data cache to Point - * of Coherency for guest stage-2 address - * range. + * kvm_pgtable_stage2_flush() - Clean and invalidate data cache to Point of + * Coherency for guest stage-2 address range. * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). * @addr: Intermediate physical address from which to flush. * @size: Size of the range. From patchwork Fri Jun 2 16:09:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1139475vqr; Fri, 2 Jun 2023 09:11:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5BOpmjWg+mdnWU0HODVt0gLHcOzvlWUnG0TbZruYfwR2SqjQ1XKYA+RImcqYKS89vQpgYT X-Received: by 2002:a17:902:c1c5:b0:1b1:ac87:b47b with SMTP id c5-20020a170902c1c500b001b1ac87b47bmr352320plc.55.1685722270738; Fri, 02 Jun 2023 09:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722270; cv=none; d=google.com; s=arc-20160816; b=glEVnBranmDrcuyfp2aukzVERbajESGdHVWK9swohawSM2EL+1MDFHFjfVG8sLM+2P ZlD619aEdboi677BtN6qChw61Vy0d0HQyGzebPVRH1rsvT7wm5bg98vgNt5Di/oDa4QR FttFkHuvvDWTZb3bJbL/Om8DmXHXZofeP4NtuR4eFvBh4Io14dLKETAW1P5KG3tgEh0Q 5iftGZpiqxD6qAcU2HSOP1xp3xRjqzLrEWPkfRO5xo9JToqg8lM301kK9gw3G/agRdhQ cuetzitxqFbHStOwOAS4kmN+waCxRX/3I19ahJ0CyLsS+xy0RjLGrkpBb/CxBJMMsz1G SdYQ== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=XlXfZDaqwtQ8jb+NBFxxHmMdNa0dhVq7sf+3J9mNCvc=; b=rKCMx68vOs1dYCfKhJZSYvtvEAzfkNzGRvHVK63DlqNpyOUayCDf1OyZLzZTdB5i+v lj+o9EndM3W47DIcKYbnz6aKxnpU+py3izwt3mEJA7k9ItVsTw5u5JUQRDhK4gFvEUGX 6u/wyMigv7tFLMgjUsZ3hADy5R77ehiX8kFJk1hTKROh6aaiwGio9JcqYRLZtbv5UYVl DSMng4fVFYBps2q2ITDHdmrO1MMkAvAjzwEoXJUuQcDeVX7+S1/olY/0Qyk7no+9MrqH 5/W6pymNq2Ad6C1vTNnZfl0xbwUMidxCuZTFSYiE0tpMzAYNbt/nzfAbmok7fk2GBh2m I6yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Cav0E0cC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f12-20020a170902ab8c00b001aad9b73ff2si1078293plr.285.2023.06.02.09.10.55; Fri, 02 Jun 2023 09:11:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Cav0E0cC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235456AbjFBQKC (ORCPT + 99 others); Fri, 2 Jun 2023 12:10:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236728AbjFBQJr (ORCPT ); Fri, 2 Jun 2023 12:09:47 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49240E72 for ; Fri, 2 Jun 2023 09:09:35 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-53f44c2566dso974058a12.2 for ; Fri, 02 Jun 2023 09:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722174; x=1688314174; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XlXfZDaqwtQ8jb+NBFxxHmMdNa0dhVq7sf+3J9mNCvc=; b=Cav0E0cCrA4YixnMBQKMfIUVj88wiap2lnIB8ag1Iz/8mWp6WkXueCvYRCBiVgJMpL yz6b5GmGWPhdoaqfWLr4eMh+mes1ArSi+nNH2aSvBuPWl2X06K+1JFMN+UK2I8zKDZ+Y An4/Ccw/5HBcgWIwlUsNKHK+GBxiwi6UrW0Rt5OfBwhcgGTE2dlnkWyH08h03FWRL/+p PpYax2iQC4+/Q7s8QR0zA1oOFG5toYWxuVQyxHq17uCmAv8sJvsjFT497G95S2n7vNCo An7ffox8QUfjjPO3WBaFb5yO8HO3WOQ44El3H8raJwdkFn/AASepix+It/ssVM4Hws1C WsIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722174; x=1688314174; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XlXfZDaqwtQ8jb+NBFxxHmMdNa0dhVq7sf+3J9mNCvc=; b=iJ7rdYVTeagk8mEMm5D8rNQssSgjqNGjYs+Z9jUPnrdlY8hD2YIjTBDysq+trs6HWX kzhoK0v+ql2z607Per3ahSrofCQLkn+lhkHChcS1IK6vFRR7pf6QRgFvl52CXRpevxPf iu5ZgI8GjyCDnEA0bvZP0rV8mOGIEzhuH/W7VVczv6occEuEy2XZaw2Z3KRY0couHo1S PlfF2s1tOsn7G4sQ8n+KItms1wZAUJRrAUwVMP2MkLDemUQoGaEbLFCL6buziiebC8Ng STu+oozYk6WJVGzgzWXp+QpxG9gCMJXSjMt1GZQTguozHCgnWdnFkbfwa8Sfgnw7BCnU ER6Q== X-Gm-Message-State: AC+VfDyeSW2XfLI9PXANSZEGXguG0S96He1bzdhureJ3lE5XRC2u2Zr8 i7759GBIw6r/4tUEX/fORhoxF1BVSg/7 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a63:385:0:b0:530:70cb:6da9 with SMTP id 127-20020a630385000000b0053070cb6da9mr2521810pgd.10.1685722173764; Fri, 02 Jun 2023 09:09:33 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:05 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-8-vipinsh@google.com> Subject: [PATCH v2 07/16] KVM: mmu: Move mmu lock/unlock to arch code for clear dirty log From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607915870162249?= X-GMAIL-MSGID: =?utf-8?q?1767607915870162249?= Move mmu_lock lock and unlock calls from common code in kvm_clear_dirty_log_protect() to arch specific code in kvm_arch_mmu_enable_log_dirty_pt_masked(). None of the other code inside the for loop of kvm_arch_mmu_enable_log_dirty_pt_masked() needs mmu_lock exclusivity apart from the arch specific API call. Future commits will change clear dirty log operations under mmu read lock instead of write lock for ARM and, potentially, x86 architectures. No functional changes intended. Signed-off-by: Vipin Sharma --- arch/arm64/kvm/mmu.c | 2 ++ arch/mips/kvm/mmu.c | 2 ++ arch/riscv/kvm/mmu.c | 2 ++ arch/x86/kvm/mmu/mmu.c | 3 +++ virt/kvm/dirty_ring.c | 2 -- virt/kvm/kvm_main.c | 4 ---- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 6db9ef288ec3..0c2c2c0846f1 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1125,6 +1125,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, phys_addr_t start = (base_gfn + __ffs(mask)) << PAGE_SHIFT; phys_addr_t end = (base_gfn + __fls(mask) + 1) << PAGE_SHIFT; + write_lock(&kvm->mmu_lock); lockdep_assert_held_write(&kvm->mmu_lock); stage2_wp_range(&kvm->arch.mmu, start, end); @@ -1139,6 +1140,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, */ if (kvm_dirty_log_manual_protect_and_init_set(kvm)) kvm_mmu_split_huge_pages(kvm, start, end); + write_unlock(&kvm->mmu_lock); } static void kvm_send_hwpoison_signal(unsigned long address, short lsb) diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c index e8c08988ed37..33c5af333ff9 100644 --- a/arch/mips/kvm/mmu.c +++ b/arch/mips/kvm/mmu.c @@ -419,7 +419,9 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, gfn_t start = base_gfn + __ffs(mask); gfn_t end = base_gfn + __fls(mask); + spin_lock(&kvm->mmu_lock); kvm_mips_mkclean_gpa_pt(kvm, start, end); + spin_unlock(&kvm->mmu_lock); } /* diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index f2eb47925806..fe026ff5eb65 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -399,7 +399,9 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, phys_addr_t start = (base_gfn + __ffs(mask)) << PAGE_SHIFT; phys_addr_t end = (base_gfn + __fls(mask) + 1) << PAGE_SHIFT; + spin_lock(&kvm->mmu_lock); gstage_wp_range(kvm, start, end); + spin_unlock(&kvm->mmu_lock); } void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index c8961f45e3b1..6fff4228e31c 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1382,6 +1382,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { + write_lock(&kvm->mmu_lock); /* * Huge pages are NOT write protected when we start dirty logging in * initially-all-set mode; must write protect them here so that they @@ -1412,6 +1413,8 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, kvm_mmu_clear_dirty_pt_masked(kvm, slot, gfn_offset, mask); else kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); + + write_unlock(&kvm->mmu_lock); } int kvm_cpu_dirty_log_size(void) diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c index c1cd7dfe4a90..d894c58d2152 100644 --- a/virt/kvm/dirty_ring.c +++ b/virt/kvm/dirty_ring.c @@ -66,9 +66,7 @@ static void kvm_reset_dirty_gfn(struct kvm *kvm, u32 slot, u64 offset, u64 mask) if (!memslot || (offset + __fls(mask)) >= memslot->npages) return; - KVM_MMU_LOCK(kvm); kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset, mask); - KVM_MMU_UNLOCK(kvm); } int kvm_dirty_ring_alloc(struct kvm_dirty_ring *ring, int index, u32 size) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 13aed654111a..747bfa2f1dd3 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2160,7 +2160,6 @@ static int kvm_get_dirty_log_protect(struct kvm *kvm, struct kvm_dirty_log *log) dirty_bitmap_buffer = kvm_second_dirty_bitmap(memslot); memset(dirty_bitmap_buffer, 0, n); - KVM_MMU_LOCK(kvm); for (i = 0; i < n / sizeof(long); i++) { unsigned long mask; gfn_t offset; @@ -2176,7 +2175,6 @@ static int kvm_get_dirty_log_protect(struct kvm *kvm, struct kvm_dirty_log *log) kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset, mask); } - KVM_MMU_UNLOCK(kvm); } if (flush) @@ -2271,7 +2269,6 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm, if (copy_from_user(dirty_bitmap_buffer, log->dirty_bitmap, n)) return -EFAULT; - KVM_MMU_LOCK(kvm); for (offset = log->first_page, i = offset / BITS_PER_LONG, n = DIV_ROUND_UP(log->num_pages, BITS_PER_LONG); n--; i++, offset += BITS_PER_LONG) { @@ -2294,7 +2291,6 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm, offset, mask); } } - KVM_MMU_UNLOCK(kvm); if (flush) kvm_arch_flush_remote_tlbs_memslot(kvm, memslot); From patchwork Fri Jun 2 16:09:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1139474vqr; Fri, 2 Jun 2023 09:11:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ70HGR+rX22MlsNVJjDz1SmdW72IZWTOTOytzyXq2qinqHVppCiVOUQzEp0Y/P4pVSMvhMM X-Received: by 2002:a05:6a20:914e:b0:10e:bcb0:199c with SMTP id x14-20020a056a20914e00b0010ebcb0199cmr8620127pzc.31.1685722270669; Fri, 02 Jun 2023 09:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722270; cv=none; d=google.com; s=arc-20160816; b=UGgY5Fg9frHW2jlSfiYjPdu13cXlRLdBcjXcxUU6m0aUyUSG0B7fzDOtYL68R3YNIj iEgGZRqNFQKn0tHFKaWD+iRP4bN8FSM5vZqbsQvADTvFD+mOwBRTsX4ff4Ow3qdwwYX/ +2PAaYOpQkyjv/+UwW2hFu54r0IoIY/GkbvlAW+0r6Cm6jXk+OzZUUHdpb2gW9ERgl3x Z8yTLg5gu9tI73UkmrCOIJr8W25j/zTy+9QlbKYeS96uwQN60OViRj1BjUlqHiPzdlMU AirGyXkUemdwopg5gDAoz3vnVj2/H+4ppPGLV8O//tCiyu3uMrJTp0F/QMlNO3Z/h8qw WSbA== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=GJx+yypKzd3COmz5TQWkFGxt9Sb1HD5xNFJXRHqVvy0=; b=sPzmbJ/ghUXbqouf5mYHvQucp1AzQfmC/hHmfVx+8VvR8FMyEJ/p0IR3DIcRB4fUcZ dbIfuM25X3kVR5C98mzrLyJVzsjZbgphD3Z1gPrs1SfviweMBrrK4DfeShdqdP96OhUW Tjg8czGi+R0fJG1hLMdiZ7fwtMo/gBKIg9ScnPByTwwGLC+G+wuJ6fhZsue5DOIcXkYx juHHTCxej61WyXQCv6LsSrj1539m3sEe5lCW6rW9+JPHIhCgR/xGH14S4mgxXv0nH5sy bX3cExE/MVo2kDSxCxzZXAKiOhoUkjIUEdqJGA01PKtHWVF22ZIv5XeVRSM3DcSUiHg7 /wNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=szBGu+EQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a70-20020a639049000000b0053439c18c47si1168166pge.240.2023.06.02.09.10.58; Fri, 02 Jun 2023 09:11:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=szBGu+EQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236728AbjFBQKJ (ORCPT + 99 others); Fri, 2 Jun 2023 12:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236757AbjFBQJr (ORCPT ); Fri, 2 Jun 2023 12:09:47 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 795A9E7F for ; Fri, 2 Jun 2023 09:09:36 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-56536dd5f79so33625067b3.3 for ; Fri, 02 Jun 2023 09:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722176; x=1688314176; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GJx+yypKzd3COmz5TQWkFGxt9Sb1HD5xNFJXRHqVvy0=; b=szBGu+EQ2vs8Q3A0ZT1RS79FNLRJxSOVkrDrBBX7rmCKLzKn/b+E4mNymytABzCLif EgUFXaPy7nG7KM6jDjkYBO0vsJLxZ4XBjsoF6X75ZimJDOLxnKGoSfjvnPNLfA9vSHBD s9ihl+kXGelNmLHAJZYRz4+yQ+Fx6J3bT5bOlL9FOfNpgH6MN5wQNIGrZvk2XbL68tHF B/csW1RkKWfzpRPcNxb+4yNUfWvhAhXwGpxjibheJUkN4+CaHLLPZUdUbJv/P8pKuPN/ Cvmf4i9nzVBBvNWz3J0YGn8SEauVZOkYjg+xhiWvEBlTBwkFZHPSrYROctUU+loxAFaS zjKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722176; x=1688314176; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GJx+yypKzd3COmz5TQWkFGxt9Sb1HD5xNFJXRHqVvy0=; b=QsSZhnKQoGHbU2KP2R1Qb4n0GOWFHoYIK2RAW4fT7IGF6XwKQaFN7XUCqO9e905DBL kAKPniRxYBuc9/0rtwQT4zGlFEhY1giIqdoMYWr+JeucZv6p+/mZ8Gz59AiK6R/TMhoO oNw4m3kXbTrxi/k1+ZHr1FgdtPo40N1E3fez30r+oSjrRcS3rJKqRg2KIv3EL5n1ewtx w+OrE/MQxQll9CSd2P+vXxscKL8EX1WQwht8NnKFpm5mJKtM/X0jJ4+Q7+cA/+OIx6Co ZUyYId8ZtbOQLwGJyUeJeEvZJb4BKIupLeSugDz0UBdmKtxLJUGoadl783IfQPi3MYcg puqA== X-Gm-Message-State: AC+VfDz92RVYhwfUx2V6djH0CL7EW63J89TfP6ncVSZCznEyBG1yZYVH 3uH+8ImjT6aYlTQlsRUhz+b2G1xewcYu X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6902:100a:b0:bad:600:1833 with SMTP id w10-20020a056902100a00b00bad06001833mr2072241ybt.0.1685722176005; Fri, 02 Jun 2023 09:09:36 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:06 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-9-vipinsh@google.com> Subject: [PATCH v2 08/16] KMV: arm64: Pass page table walker flags to stage2_apply_range_*() From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607915224781669?= X-GMAIL-MSGID: =?utf-8?q?1767607915224781669?= Allow stage2_apply_range_*() to accept enum kvm_pgtable_walk_flags{} for stage 2 walkers. Pass 0 as the flag value from all of its caller effectively making it a no-op. Page table walker flags will be used in future commits to enable clear-dirty-log operation under MMU read lock. Current users of stage2_apply_range_*() API runs under assumption of holding MMU write lock. Stage2 page table walkers then run under the same assumption. In future commits, when clear-dirty-log is modified to run under MMU read lock then this flag will be used to pass shared page walk intent. No functional changes intended. Signed-off-by: Vipin Sharma --- arch/arm64/include/asm/kvm_pgtable.h | 12 +++++++++--- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 4 ++-- arch/arm64/kvm/hyp/pgtable.c | 16 ++++++++++------ arch/arm64/kvm/mmu.c | 26 ++++++++++++++++---------- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index d542a671c564..8ef7e8f3f054 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -560,6 +560,7 @@ int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size, * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). * @addr: Intermediate physical address from which to remove the mapping. * @size: Size of the mapping. + * @flags: Page-table walker flags. * * The offset of @addr within a page is ignored and @size is rounded-up to * the next page boundary. @@ -572,7 +573,8 @@ int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size, * * Return: 0 on success, negative error code on failure. */ -int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size); +int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags); /** * kvm_pgtable_stage2_wrprotect() - Write-protect guest stage-2 address range @@ -580,6 +582,7 @@ int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size); * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). * @addr: Intermediate physical address from which to write-protect, * @size: Size of the range. + * @flags: Page-table walker flags. * * The offset of @addr within a page is ignored and @size is rounded-up to * the next page boundary. @@ -590,7 +593,8 @@ int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size); * * Return: 0 on success, negative error code on failure. */ -int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size); +int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags); /** * kvm_pgtable_stage2_mkyoung() - Set the access flag in a page-table entry. @@ -662,13 +666,15 @@ bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr); * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). * @addr: Intermediate physical address from which to flush. * @size: Size of the range. + * @flags: Page-table walker flags. * * The offset of @addr within a page is ignored and @size is rounded-up to * the next page boundary. * * Return: 0 on success, negative error code on failure. */ -int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size); +int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags); /** * kvm_pgtable_stage2_split() - Split a range of huge pages into leaf PTEs pointing diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index d35e75b13ffe..13f5cf5f87c3 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -333,11 +333,11 @@ static int host_stage2_unmap_dev_all(void) /* Unmap all non-memory regions to recycle the pages */ for (i = 0; i < hyp_memblock_nr; i++, addr = reg->base + reg->size) { reg = &hyp_memory[i]; - ret = kvm_pgtable_stage2_unmap(pgt, addr, reg->base - addr); + ret = kvm_pgtable_stage2_unmap(pgt, addr, reg->base - addr, 0); if (ret) return ret; } - return kvm_pgtable_stage2_unmap(pgt, addr, BIT(pgt->ia_bits) - addr); + return kvm_pgtable_stage2_unmap(pgt, addr, BIT(pgt->ia_bits) - addr, 0); } struct kvm_mem_range { diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 364b68013038..a3a0812b2301 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1044,12 +1044,14 @@ static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx, return 0; } -int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size) +int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags) { struct kvm_pgtable_walker walker = { .cb = stage2_unmap_walker, .arg = pgt, - .flags = KVM_PGTABLE_WALK_LEAF | KVM_PGTABLE_WALK_TABLE_POST, + .flags = flags | KVM_PGTABLE_WALK_LEAF | + KVM_PGTABLE_WALK_TABLE_POST, }; return kvm_pgtable_walk(pgt, addr, size, &walker); @@ -1128,11 +1130,12 @@ static int stage2_update_leaf_attrs(struct kvm_pgtable *pgt, u64 addr, return 0; } -int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size) +int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags) { return stage2_update_leaf_attrs(pgt, addr, size, 0, KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, - NULL, NULL, 0); + NULL, NULL, flags); } kvm_pte_t kvm_pgtable_stage2_mkyoung(struct kvm_pgtable *pgt, u64 addr) @@ -1213,11 +1216,12 @@ static int stage2_flush_walker(const struct kvm_pgtable_visit_ctx *ctx, return 0; } -int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size) +int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags) { struct kvm_pgtable_walker walker = { .cb = stage2_flush_walker, - .flags = KVM_PGTABLE_WALK_LEAF, + .flags = flags | KVM_PGTABLE_WALK_LEAF, .arg = pgt, }; diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 0c2c2c0846f1..1030921d89f8 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -55,7 +55,9 @@ static phys_addr_t stage2_range_addr_end(phys_addr_t addr, phys_addr_t end) */ static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, phys_addr_t end, - int (*fn)(struct kvm_pgtable *, u64, u64), + enum kvm_pgtable_walk_flags flags, + int (*fn)(struct kvm_pgtable *, u64, u64, + enum kvm_pgtable_walk_flags), bool resched) { struct kvm *kvm = kvm_s2_mmu_to_kvm(mmu); @@ -68,7 +70,7 @@ static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, return -EINVAL; next = stage2_range_addr_end(addr, end); - ret = fn(pgt, addr, next - addr); + ret = fn(pgt, addr, next - addr, flags); if (ret) break; @@ -79,8 +81,8 @@ static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, return ret; } -#define stage2_apply_range_resched(mmu, addr, end, fn) \ - stage2_apply_range(mmu, addr, end, fn, true) +#define stage2_apply_range_resched(mmu, addr, end, flags, fn) \ + stage2_apply_range(mmu, addr, end, flags, fn, true) /* * Get the maximum number of page-tables pages needed to split a range @@ -316,7 +318,7 @@ static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 lockdep_assert_held_write(&kvm->mmu_lock); WARN_ON(size & ~PAGE_MASK); - WARN_ON(stage2_apply_range(mmu, start, end, kvm_pgtable_stage2_unmap, + WARN_ON(stage2_apply_range(mmu, start, end, 0, kvm_pgtable_stage2_unmap, may_block)); } @@ -331,7 +333,8 @@ static void stage2_flush_memslot(struct kvm *kvm, phys_addr_t addr = memslot->base_gfn << PAGE_SHIFT; phys_addr_t end = addr + PAGE_SIZE * memslot->npages; - stage2_apply_range_resched(&kvm->arch.mmu, addr, end, kvm_pgtable_stage2_flush); + stage2_apply_range_resched(&kvm->arch.mmu, addr, end, 0, + kvm_pgtable_stage2_flush); } /** @@ -1041,10 +1044,13 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, * @mmu: The KVM stage-2 MMU pointer * @addr: Start address of range * @end: End address of range + * @flags: Page-table walker flags. */ -static void stage2_wp_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, phys_addr_t end) +static void stage2_wp_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, phys_addr_t end, + enum kvm_pgtable_walk_flags flags) { - stage2_apply_range_resched(mmu, addr, end, kvm_pgtable_stage2_wrprotect); + stage2_apply_range_resched(mmu, addr, end, flags, + kvm_pgtable_stage2_wrprotect); } /** @@ -1073,7 +1079,7 @@ static void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot) end = (memslot->base_gfn + memslot->npages) << PAGE_SHIFT; write_lock(&kvm->mmu_lock); - stage2_wp_range(&kvm->arch.mmu, start, end); + stage2_wp_range(&kvm->arch.mmu, start, end, 0); write_unlock(&kvm->mmu_lock); kvm_flush_remote_tlbs(kvm); } @@ -1128,7 +1134,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, write_lock(&kvm->mmu_lock); lockdep_assert_held_write(&kvm->mmu_lock); - stage2_wp_range(&kvm->arch.mmu, start, end); + stage2_wp_range(&kvm->arch.mmu, start, end, 0); /* * Eager-splitting is done when manual-protect is set. We From patchwork Fri Jun 2 16:09:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1140105vqr; Fri, 2 Jun 2023 09:12:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5nRHIWEKLhtSwCqkhovq6zOTFRK8b5CYpv8AX/r3DJgeYOTw2dgd+lUIWnCTPiaGO0IO2i X-Received: by 2002:a17:903:1cb:b0:1b0:4baa:ba92 with SMTP id e11-20020a17090301cb00b001b04baaba92mr447750plh.1.1685722325059; Fri, 02 Jun 2023 09:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722325; cv=none; d=google.com; s=arc-20160816; b=NLbJYW11sFOK+RChtAxWwONN8u3rs4f4YJlpUA2KJvKwivkWIy2VYAOqArVqlZTB3J 7lUaC+XreOp9VCMVnBsM5EUUfoUySYepxIIovskTaaoob2U0M+GSyHBItdxE+Wk7nR6N 9cbwRQjOKVE7y6XUMliBztXARmwl86GGbiaGBsnIFPX4XuSWUp7gpyVC9OpzW+BxA+6z ugpq1nEi81A/+6NYGZkqhikC7/Nj7bj0B+NZz7WiAYJt5vjZEuiLifPWrEeEkV4kbQcF FZFLCwPvDtqfQDJr1M5ono7Z0EZ5quJ/0mX1f9OywGD6wH3imfw5N8gPNAwgR+wPZYx1 cs2w== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=NyrihgmYesBmBKLp4ITVdJ3LGNh6LVDPlJHbJ3BWmKo=; b=KE7Z5/4xmC0D0DoDcs+TabN6wq2A2UxTwd8V5ApIUsLFxzPnQubuu6btAb4NmS9j+o IUCprQlherbz2E1g44iTDyki4QFVKtjPzII5iRn4Fs0YJmKUopZwBUPXMIfiC8AppD72 +G8vzBAYNxuuvY7qMjePgSXHthGD78Xzc1JIQuusxiCXtDvdvNw1WPpcSrvYPnUc/UxS FwV6fAZn1oU+d1tPMTBYHJ6Eg4C1S37C3KM3tNDZsq1SyrRenPVtJovg6KR8inCHfHC/ Q3lXhqGZZyVsDkCoN+KEjwunj7IUuxHY1l9AfiHKtYuFmmbbn2p531hQ0sCEQzUVy4ye sC7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=6JvB68lu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a170902a38100b001ac2ff9fbf8si1042747pla.403.2023.06.02.09.11.52; Fri, 02 Jun 2023 09:12:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=6JvB68lu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234920AbjFBQKE (ORCPT + 99 others); Fri, 2 Jun 2023 12:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236809AbjFBQJw (ORCPT ); Fri, 2 Jun 2023 12:09:52 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0313A10DD for ; Fri, 2 Jun 2023 09:09:39 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-56561689700so33440807b3.2 for ; Fri, 02 Jun 2023 09:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722178; x=1688314178; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NyrihgmYesBmBKLp4ITVdJ3LGNh6LVDPlJHbJ3BWmKo=; b=6JvB68luEiFeoyKEfjP/g+vMwC/sRddTQaYllS5g+5bpQDmhXIgwwZiHHiYhNY6/hh +N3LQSiNtnyna/XZaiM18ivCXXQ4yuX/15A1AGZwy0Qa/f1hIAf3oKXB2h5AuHkYQgCs xj8Y82H0f8TZvkTqQ0Hx5MWBndbNiI7NCzZ3czEuYGWHs7LAUCirzskxbkVOl+noMZFx tm27fSCTKAwfbeEstcfEbI/nW6D9qAihf0lb2MdszgnmyhfNayDhGNG1boLJ+W+UNY9A PKxN0bCcFoMuNsJAFUnK+mzP9snrdOrZPjuzoVjhjXEuIkdNPWm6zU7rdhcbdNuxMxHK DaOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722178; x=1688314178; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NyrihgmYesBmBKLp4ITVdJ3LGNh6LVDPlJHbJ3BWmKo=; b=akK4lEPsGC7Ig52GvSeML4mb3snB34OqTrtzdhI0kplLc1wwXg82o+2IookjYV+qqK 6SDhGlZFWBHGqCCjZvReDe8K+1p2cSCaTfScJI2OO0uoW49+zo4Sax2Lk4XOjYQKApt/ RmyWhb6VetHZFYNH0dc4mc/m2GaPJnmN6maRCnyYq6mwdLDsTPMiusJmTfYTdyuUVu8Z 125pnHOi1jxt+9911vMiewkfYUVePoeIjXCJ04fpaH7KBQe0bwk/8FT2T3OVy/iyVzG6 mqP6hYBvamcn1teY73kaSBaD7ROIg/Eeq0r8WTlZ/Eag1Ym3ZRHFKDYlXMxZzdUGXJ+2 qVdA== X-Gm-Message-State: AC+VfDyKgCM0mh9QpgJDURPZ0HgxfhaBhFZ5B+j1ea37gsiSinP0zfh0 BlvA5qCwufB/Y2TzSdBQr+Q9qfC1gIck X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a81:b620:0:b0:561:b8d1:743b with SMTP id u32-20020a81b620000000b00561b8d1743bmr170869ywh.10.1685722178126; Fri, 02 Jun 2023 09:09:38 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:07 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-10-vipinsh@google.com> Subject: [PATCH v2 09/16] KVM: arm64: Document the page table walker actions based on the callback's return value From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607973044177707?= X-GMAIL-MSGID: =?utf-8?q?1767607973044177707?= Document what the page table walker do when walker callback function returns a value. Current documentation is not correct as negative error of -EAGAIN on a non-shared page table walker doesn't terminate the walker and continues to the next step. There might be a better place to keep this information, for now this documentation will work as a reference guide until a better way is found. Signed-off-by: Vipin Sharma --- arch/arm64/include/asm/kvm_pgtable.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 8ef7e8f3f054..957bc20dab00 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -711,8 +711,19 @@ int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size, * after invoking the walker callback, allowing the walker to descend into * a newly installed table. * - * Returning a negative error code from the walker callback function will - * terminate the walk immediately with the same error code. + * Depending on the return value from the walker callback function, the page + * table walk will continue or exit the walk. This is also dependent on the + * type of the walker, i.e. shared walker (vCPU fault handlers) or non-shared + * walker. + * + * Walker Type | Callback | Walker action + * -------------|------------------|-------------- + * Non-Shared | 0 | Continue + * Non-Shared | -EAGAIN | Continue + * Non-Shared | Any other | Exit + * -------------|------------------|-------------- + * Shared | 0 | Continue + * Shared | Any other | Exit * * Return: 0 on success, negative error code on failure. */ From patchwork Fri Jun 2 16:09:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102649 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1145753vqr; Fri, 2 Jun 2023 09:20:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ZobKBi50VO4Fbz6+WFt7Zw/vWVQneL25Fghtte0EpjSsxJ4JKIGO/JLs5JRQ0tJZs4Ffj X-Received: by 2002:a05:6a20:914a:b0:ff:ca91:68ee with SMTP id x10-20020a056a20914a00b000ffca9168eemr6284700pzc.9.1685722841139; Fri, 02 Jun 2023 09:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722841; cv=none; d=google.com; s=arc-20160816; b=yfbMTAR28QK6KlErtmarrMNNURK8jqDfRzOZoly9DDkzOV+p66ChHMnwXvqTBwhsy4 2NNGA0IpsLoHFKQLGr/NUtMZ+/dyrQQaP+pk/OvxSLoweASCBHyWB+9Zab6BdsdaMMnw E+gL6ibaoNRe4kl2qZqIHSP2OjMTn2sCvIS4v/dFaBkSb/nMK62frRStZPXGVzZYME/l VwoM35m2CQnEewW4HuFPT6mtpn/FTZW2E3UE7abfUaL81UMeXIoBeK0a5+HqBtOzQhSE CGodU6RYokacZvUlzzbJc7yXT4GKxVlYVA6yYeYBfcJZCg6kVsTrhsbNt58HYC/IyduC GbLQ== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=i16qvWrTxXmM44zqvAfMO+VQ2ZgLrONxQcP35eFduXw=; b=nB/WLuek91sdKqSrmC5ennn1MP7by+0h8EuHLLXYpf30eIRK4RvE7rv49P3ZK8ruMG hUIzVHKwAYOKtZgrZLzOLymEawia9U0qUCvoVBCQ+sbDkZ7I2djCPW8xlVnaIW+vjvhS xr0sAnem/Cup3niATxQK4SMgfHHXsaSb+1xGXt8gNbAce8Dcm/Q764Ccf+WVCIzwFU5o gB2lOmP16TQXL07Ln5f/5FI7v1KDr43UtIkN+c2FNBVbGZQHvEh/KRyKTkcoLpcNFW3v YHWY1+eFflP0yv2e1yFcxE7SJcPDweG5V2a9YmDlNneffQ/i62SnLx6gL5iD5Z4O7S3f h0fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=7epqj+D7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i15-20020a056a00004f00b0064d337029ecsi963271pfk.200.2023.06.02.09.20.29; Fri, 02 Jun 2023 09:20:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=7epqj+D7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236308AbjFBQKZ (ORCPT + 99 others); Fri, 2 Jun 2023 12:10:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236841AbjFBQJ5 (ORCPT ); Fri, 2 Jun 2023 12:09:57 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E54510FA for ; Fri, 2 Jun 2023 09:09:40 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1b03057588cso22051705ad.1 for ; Fri, 02 Jun 2023 09:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722180; x=1688314180; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=i16qvWrTxXmM44zqvAfMO+VQ2ZgLrONxQcP35eFduXw=; b=7epqj+D7b/Vs8MJCaB/Yaig4pdk6Xsa6+PhHha/KiUX7vkzJuwNVRvh/QKSBOYWOoF 9Kl1CGagQi1DXxlGyYvTod7C6g15Jc/lvseccbcVTnZGlpUMuN85YotpNb24SiVNDe/4 jJWg+BewppQ9iRi+5TbG/EFvPtgidVbx51XdS+ZgnSZfKoodj1WI4tk7ctB/2mpU7ujt 5GR5L1lxyi6Yc/dQP61OizppKV4BxJWb97C2tfKTvu6BWLjF7QcXhyPnKGED9xXxbRV0 rkKjEao0Yem9n3mVyvzo3PMl7x2joHF/KT0tNezMLtd5RxYZ9imnBCUvokvJr8Ssuvgw mKhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722180; x=1688314180; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i16qvWrTxXmM44zqvAfMO+VQ2ZgLrONxQcP35eFduXw=; b=cm0gop4oSBxkPkZ/Avwk7RsOilRcdf8Fe8n04LCWgNZy4PeUh5lP6NIGEMMrRl5LEp iiUOBxp05E2ECshl0fgOPhKvHPXBeRxpfU4EBiNrp1pxmbLn0Ffz1JFB/Ehhtl1ABIag u3Owj3CIIHVEeodEsKee4mMreBo+igVExP8vmPKsMUV4KPhroCW9g+IVRISpKsN6RMqF P4MeVDmRfXcjVJkG68/pY3t+P9/zibVdZoMkN+gqfua9MNAyB8EljKzEiVe8drRWGEcd qqDAE3hmvteDvQFGRXXx4USMXyyVrwiZRzNdVndPhrtUc1RoWLqr8IYUktz/q1Gz0b9i U/dg== X-Gm-Message-State: AC+VfDy0A25xQ97tz4g7gLna1kWRtc+qoCI8L+apyNmJDwhcWkIfrmkz x8w95gDcOO9QF73YaE3Nk3u7MnrxecFT X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:903:3251:b0:1b0:6a10:1ba1 with SMTP id ji17-20020a170903325100b001b06a101ba1mr117384plb.13.1685722180001; Fri, 02 Jun 2023 09:09:40 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:08 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-11-vipinsh@google.com> Subject: [PATCH v2 10/16] KVM: arm64: Return -ENOENT if PTE is not valid in stage2_attr_walker From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767608514011909707?= X-GMAIL-MSGID: =?utf-8?q?1767608514011909707?= Return -ENOENT from stage2_attr_walker for invalid PTE. Continue page table walk if walker callback returns -ENOENT outside of the fault handler path else terminate the walk. In fault handler path, similar to -EAGAIN in user_mem_abort, retry guest execution. stage2_attr_walker() is used from multiple places like, write protection, MMU notifier callbacks, and relaxing permission during vCPU faults. This function returns -EAGAIN for different cases: 1. When PTE is not valid. 2. When cmpxchg() fails while setting new SPTE. For non-shared walkers, like write protection and MMU notifier, above 2 cases are just ignored by walker and it moves to the next SPTE. #2 will never happen for non-shared walkers as they don't use cmpxchg() for updating SPTEs. For shared walkers, like vCPU fault handler, above 2 cases results in walk termination. In future commits, clear-dirty-log walker will write protect SPTEs under MMU read lock and use shared page table walker. This will result in two shared page table walkers type, vCPUs fault handler and clear-dirty-log, competing with each other and sometime causing cmpxchg() failure. So, -EAGAIN in clear-dirty-log walker due to cmpxchg() failure must be retried. Whereas, -EAGAIN in the clear-dirty-log due to invalid SPTE must be ignored instead of exiting as per the current logic of shared page table walker. This is not needed for vCPU fault handler which also runs via shared page table walker and terminates walk on getting -EAGAIN due to invalid SPTE. To handle all these scenarios, stage2_attr_walker must return different error codes for invalid SPTEs and cmxchg() failure. -ENOENT for invalid SPTE is chosen because it is not used by any other shared walker. When clear-dirty-log will be changed to use shared page table walker, it will be possible to differentiate cases of retrying, continuing or terminating the walk for shared fault handler and shared clear-dirty-log. Signed-off-by: Vipin Sharma --- arch/arm64/include/asm/kvm_pgtable.h | 1 + arch/arm64/kvm/hyp/pgtable.c | 19 ++++++++++++------- arch/arm64/kvm/mmu.c | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 957bc20dab00..23e7e7851f1d 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -720,6 +720,7 @@ int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size, * -------------|------------------|-------------- * Non-Shared | 0 | Continue * Non-Shared | -EAGAIN | Continue + * Non-Shared | -ENOENT | Continue * Non-Shared | Any other | Exit * -------------|------------------|-------------- * Shared | 0 | Continue diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index a3a0812b2301..bc8c5c4ac1cf 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -186,14 +186,19 @@ static bool kvm_pgtable_walk_continue(const struct kvm_pgtable_walker *walker, /* * Visitor callbacks return EAGAIN when the conditions that led to a * fault are no longer reflected in the page tables due to a race to - * update a PTE. In the context of a fault handler this is interpreted - * as a signal to retry guest execution. + * update a PTE. * - * Ignore the return code altogether for walkers outside a fault handler - * (e.g. write protecting a range of memory) and chug along with the - * page table walk. + * Callbacks can also return ENOENT when PTE which is visited is not + * valid. + * + * In the context of a fault handler interpret these as a signal + * to retry guest execution. + * + * Ignore these return codes altogether for walkers outside a fault + * handler (e.g. write protecting a range of memory) and chug along + * with the page table walk. */ - if (r == -EAGAIN) + if (r == -EAGAIN || r == -ENOENT) return !(walker->flags & KVM_PGTABLE_WALK_HANDLE_FAULT); return !r; @@ -1072,7 +1077,7 @@ static int stage2_attr_walker(const struct kvm_pgtable_visit_ctx *ctx, struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; if (!kvm_pte_valid(ctx->old)) - return -EAGAIN; + return -ENOENT; data->level = ctx->level; data->pte = pte; diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 1030921d89f8..356dc4131023 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1551,7 +1551,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, read_unlock(&kvm->mmu_lock); kvm_set_pfn_accessed(pfn); kvm_release_pfn_clean(pfn); - return ret != -EAGAIN ? ret : 0; + return (ret != -EAGAIN && ret != -ENOENT) ? ret : 0; } /* Resolve the access fault by making the page young again. */ From patchwork Fri Jun 2 16:09:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1139785vqr; Fri, 2 Jun 2023 09:11:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6SbmQcSOWAmSgJoWoJdBYbvNXX9VBqd6ES4VoJM3P3MsM1lslSD/f+2DAdXeuVlrson/Jj X-Received: by 2002:a05:6a20:4284:b0:110:9b0b:71b6 with SMTP id o4-20020a056a20428400b001109b0b71b6mr16007531pzj.37.1685722297854; Fri, 02 Jun 2023 09:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722297; cv=none; d=google.com; s=arc-20160816; b=AWarCVwJOaIbjaIdfOUdrkg1LSsslNQCFyjPYXHTJUkgmg/ILgypRdy2fUNRQrzrPR lDvRKuITtAZqIVTcwdX1TkDLwLHEDiY/Clx6oB7RZwrMklgV2XGpw8DuRlxgUy10DnFU YqifzBgIuI+yY1HnfYhy0Ta1o4qFLGPOCQLt0WaHde7OYTao0sVZVeXkNx+Zh5XGhVva UpwYy/l2F1J2MJl7lJrtVDWN8V/nTL/EnCTZpehSjNnpqDiTRSxHO38TqFEEzFsLyQMK O72X1iVWjK7NH7uMRyaVVdL5F2KetF8DVOOQY2TeqquRf8C2u5Y9XvS6U4q2O5w5lf/+ IWpg== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=rivHDhk0ioxMpP1XynwGaSZFsNZDBBbqgVAGbR7E/X8=; b=cWeUvcbWFGNz16UzNwlBLHypYYvFMXGXEL0CQnuFvwgHvgx9RXgOZibp9Dg18oYcLL nXDrnXZ4TBZNWsISa6FoLlXXZOlWIwoDQRmBNRk4kj319AvpBysNDZDi5uhJenLJzAM6 AMtrFR++JTLNoqDm9TJ3CboSUWbiw5QqC61ciYTPS29Ghw1qUwVVuKtomWaybYi3IR2q tgfUcCGUqnPs3boaYpj4Cx9xqeow6owwBzHnrpwbnSm/g292AwJ5tneF2jsJEkC/Tawm 5PQR6vaUGePkNpXrEDOR1Z8BOucLg90KSowR3aJC2aCfYF0z/cujX4d/gaAy1UkOU8A5 Wv8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=IxpZG4Tk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y192-20020a638ac9000000b0052856ce370asi1219798pgd.426.2023.06.02.09.11.25; Fri, 02 Jun 2023 09:11:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=IxpZG4Tk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236811AbjFBQK7 (ORCPT + 99 others); Fri, 2 Jun 2023 12:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236571AbjFBQKd (ORCPT ); Fri, 2 Jun 2023 12:10:33 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7056FE6B for ; Fri, 2 Jun 2023 09:09:58 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1b02cd4b829so15186575ad.1 for ; Fri, 02 Jun 2023 09:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722181; x=1688314181; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rivHDhk0ioxMpP1XynwGaSZFsNZDBBbqgVAGbR7E/X8=; b=IxpZG4TkYuPd8UtpcDQplKJDDIpAs6lGKWZe95duADLUk5Xly6SRvjrVvCEGB/Fk1a E9X3IJECzkdQ25Bkjejj4IbXek6JqPY58HRA50EOI/YFTzUpFaA/bzGSlAOm+5PEvo+T 6jKSmBS0KSmdPni70wpBlwTPrvyYGZvMtxSC3Fbri9jwwzePk7OY91lpj01vmu9g7PZn a5J+YN0h1Qu/z/w7ubpNpCMDwcQqYWttGGXgoLeySgwUxIZDyVDmv/3Bk/4OJqAcfD0+ gHcpPqAo0vTPvSXpzWrIqDWuTjrALALhGQwaLZCyItTHvmVctEjS/JfpfTvctKcX+1gM QFLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722181; x=1688314181; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rivHDhk0ioxMpP1XynwGaSZFsNZDBBbqgVAGbR7E/X8=; b=j3kPOFsJnFHnC677bOueH6TgXSYQkbtFQLxoDTdA44H/el0zBqPduDvyRHujkXrik3 A36Ns7aqPc+SgnUm8NkNmdqQYPKbwPcdqMlbzNynM8YkoZjW9s7Tme4C980gcg4Ev9aa ZHkG2s5ZOm7qaWl8Po3h4INzm+ComXQMRd68HESa/ZnaeMhUh4Ym2EJMV1n0OFwjvVrK wimT8+y2Qv0VRXWK3KHVE070e1iL8wH9CZetaaUPE4/OOuK1eiw2qyvmZ6ar5G9AF2Xt rmsObzHtAT7MclHILgD+319Q7rTLWYhYRNo2mzVz+wyotMmKv/2+JD0Ym80zTD9b9Wgq Ig4g== X-Gm-Message-State: AC+VfDzHFs/kwL4Jy3BhsYI4O5+kXrNPZ+DSVrLktrRRoP09LZW5rI0p zwiPHm0X5ptgP4TgvN7pquRcZhxfaUf6 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:e3c5:b0:1b1:c90e:b7aa with SMTP id r5-20020a170902e3c500b001b1c90eb7aamr56727ple.4.1685722181662; Fri, 02 Jun 2023 09:09:41 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:09 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-12-vipinsh@google.com> Subject: [PATCH v2 11/16] KVM: arm64: Use KVM_PGTABLE_WALK_SHARED flag instead of KVM_PGTABLE_WALK_HANDLE_FAULT From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607943827752953?= X-GMAIL-MSGID: =?utf-8?q?1767607943827752953?= Check against shared page table walker flag instead of fault handler flag when determining if walk should continue or not. vCPU page fault handlers uses shared page walker and there are no other shared page walkers in Arm. This will change in future commit when clear-dirty-log will use shared page walker and continue, retry or terminate logic for a walk will change between shared page walkers. Signed-off-by: Vipin Sharma --- arch/arm64/kvm/hyp/pgtable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index bc8c5c4ac1cf..7f80e953b502 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -191,7 +191,7 @@ static bool kvm_pgtable_walk_continue(const struct kvm_pgtable_walker *walker, * Callbacks can also return ENOENT when PTE which is visited is not * valid. * - * In the context of a fault handler interpret these as a signal + * In the context of a shared walker interpret these as a signal * to retry guest execution. * * Ignore these return codes altogether for walkers outside a fault @@ -199,7 +199,7 @@ static bool kvm_pgtable_walk_continue(const struct kvm_pgtable_walker *walker, * with the page table walk. */ if (r == -EAGAIN || r == -ENOENT) - return !(walker->flags & KVM_PGTABLE_WALK_HANDLE_FAULT); + return !(walker->flags & KVM_PGTABLE_WALK_SHARED); return !r; } From patchwork Fri Jun 2 16:09:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102645 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1140482vqr; Fri, 2 Jun 2023 09:12:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5bifZP1cxAS0qWHX1cKIhVh1KXzda+UcoRExy37GxltUjrJQXSRnI3HOk9WVCUrvmhYtMf X-Received: by 2002:a05:6a20:6a0b:b0:107:10b6:4c84 with SMTP id p11-20020a056a206a0b00b0010710b64c84mr16178614pzk.21.1685722356835; Fri, 02 Jun 2023 09:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722356; cv=none; d=google.com; s=arc-20160816; b=qE0yI6S9pk24ADoWiS6fcyw4y9Udf7FsGlHR04+zFuj0h31b/HUtjyW6Fg/D0eate7 B7tkV0nmQOC4cUJdD5vU0cW5uRGSjAdY8fVs6h4UngvNdauFvAoO04ZqakyoQTEK8D9V 3Bjl7opy9F8Y6hdp1ehzpG0f/jucz+/IybC2yhoibHSDfhfLCkNpwW5zKpaqplQUw4GP l6KTL+jdV9lTL60rBoRaalWDdlAdIQ2Aaf33Xznjmbh4U6eo9Ngp1PtbAH5sej7d/bv1 p5qlZWSv16qJ0BM5XdFmN3A8/8cNUB6VKrt5bGy8/VBf7Fa9TApJ5GvjZefuzuPwaPmp gbrg== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=dYi36v/YAwaQRjgMVH+8EY8FA7aBBtQ+BKuLP6eDkvQ=; b=BRympbahVyLNQijdNjlafswdvSa4A0gVhNmeqSDcRg065oxh7v0b7YZyyG1AiCuQKN YV991j8hOmXMpmnNeCg5gbkLpQxyxat9L1v6hodOQgfehJEmCnTDWBbZ95Aztt0P2q1E uTjQ/WRAx5hUq5bFuDSqdNvaqvcAgz6QtxiffHST44stG9ysrl405z3KCAkmNzFG2oJC JzYF2U0AQWawPGQsF3W+JVdV+EWqSRsvDfB3nRv0HDJ9SbRPRIZ+IjIZ66DZimPwGusr JX1OtR1bxrRqo3aG+ZFONvueVOxhU4b3zZ4pxUk/x4CU3SeFOn7BMIRRmcSJaCNpCDHl YW8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Dw12ocPS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a631854000000b0053f352478fasi1212317pgy.307.2023.06.02.09.12.24; Fri, 02 Jun 2023 09:12:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Dw12ocPS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236778AbjFBQLD (ORCPT + 99 others); Fri, 2 Jun 2023 12:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236649AbjFBQKm (ORCPT ); Fri, 2 Jun 2023 12:10:42 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 012ACE78 for ; Fri, 2 Jun 2023 09:10:01 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2562fbb193bso845137a91.1 for ; Fri, 02 Jun 2023 09:10:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722184; x=1688314184; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dYi36v/YAwaQRjgMVH+8EY8FA7aBBtQ+BKuLP6eDkvQ=; b=Dw12ocPSe9vJUzYvSsSf9AU3CWoiwTk/XWOJWSQ28tLpoS2cFvmMFQbSf/qpjpxy7v oO7YPmr7slJeCTpuInsqqCsWP0mQqS3ua3oN9mzqlTzskeKCsUc+Eng3akxDWWH0DIw4 jhV0Z/aBx0lDztLRsncoYBKeU0QZUKmq2gyk1zRIGBfBu0xTC7gF0pRwGDV7061++Ztg o5Q/lPpRn/0BOjk3RHl0WBfcrcdb3R1NScbQhD6quOJddTL53tPtBy4zB10NE0mDM/7t Ap9iqqT0iz8St+1DIUrYSZSYDvTKdSKGgplDSGDJzXhKejoEUVmNl+mnTfSIjic7IX8O rhDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722184; x=1688314184; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dYi36v/YAwaQRjgMVH+8EY8FA7aBBtQ+BKuLP6eDkvQ=; b=a648lOrDJ0Gs+kVeu5FjsyQ6uxU9z0itXLvVlhGos/hWHXhydQsf3EDSpwd6poujF5 Ush2MAnvwMMCl/aG0KJDP2ZAWJWFJtH2u4E6nEPxBYbUVTYLcrWk0XZtkHt4DGpBybxg +g4kZMHrMwgr6yuqq4NSH7HnkZ08wYBYtKqVE1cvZqtAkdhGUOjdEYYWeXqwYGOzPp6s gt7X9pApnVXlG0Mzb/Sy+9sXZ7ckDXqREUSfm2oyD8JxLHhakFU2uoLXKADCo9ilaWKo 7R26+M9lyCRBfLI66tvxRpXiKnxsKCgGv0uR+rEgK4IujlRdORs16X4daC5ODS3raRiB gmeQ== X-Gm-Message-State: AC+VfDzXoVTSNqKy0zgdaY7hxctcvWp9Fbj9twVWnIu5EY3xQIPP3svW F7yOrc/rLixTN78IIK5jL++qhbjCRBtO X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:c08e:b0:252:733d:15dc with SMTP id o14-20020a17090ac08e00b00252733d15dcmr97816pjs.2.1685722183850; Fri, 02 Jun 2023 09:09:43 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:10 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-13-vipinsh@google.com> Subject: [PATCH v2 12/16] KVM: arm64: Retry shared page table walks outside of fault handler From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767608006183260673?= X-GMAIL-MSGID: =?utf-8?q?1767608006183260673?= For a shared page walker which is not fault handler, retry the walk if walker callback function returns -EAGAIN, or continue to the next SPTE if callback function return -ENOENT. Update the kvm_pgtable_walk documentation. For fault handler logic remains same, i.e. exit the walk and resume the guest when getting -EAGAIN and -ENOENT errors from walker callback function. Currently, there is no page walker which is shared and not a fault handler, but this will change in future patches when clear-dirty-log walker will use MMU read lock and run via shared walker. Signed-off-by: Vipin Sharma --- arch/arm64/include/asm/kvm_pgtable.h | 23 ++++++++++------- arch/arm64/kvm/hyp/pgtable.c | 38 +++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 23e7e7851f1d..145be12a5fc2 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -716,15 +716,20 @@ int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size, * type of the walker, i.e. shared walker (vCPU fault handlers) or non-shared * walker. * - * Walker Type | Callback | Walker action - * -------------|------------------|-------------- - * Non-Shared | 0 | Continue - * Non-Shared | -EAGAIN | Continue - * Non-Shared | -ENOENT | Continue - * Non-Shared | Any other | Exit - * -------------|------------------|-------------- - * Shared | 0 | Continue - * Shared | Any other | Exit + * Walker Type | Callback | Walker action + * -----------------------|------------------|-------------- + * Non-Shared | 0 | Continue + * Non-Shared | -EAGAIN | Continue + * Non-Shared | -ENOENT | Continue + * Non-Shared | Any other | Exit + * -----------------------|------------------|-------------- + * Shared | 0 | Continue + * Shared | -EAGAIN | Retry + * Shared | -ENOENT | Continue + * Shared | Any other | Exit + * -----------------------|------------------|-------------- + * Shared (Fault Handler) | 0 | Continue + * Shared (Fault Handler) | Any other | Exit * * Return: 0 on success, negative error code on failure. */ diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 7f80e953b502..23cda3de2dd4 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -191,15 +191,21 @@ static bool kvm_pgtable_walk_continue(const struct kvm_pgtable_walker *walker, * Callbacks can also return ENOENT when PTE which is visited is not * valid. * - * In the context of a shared walker interpret these as a signal + * In the context of a fault handler interpret these as a signal * to retry guest execution. * - * Ignore these return codes altogether for walkers outside a fault - * handler (e.g. write protecting a range of memory) and chug along + * In the context of a shared walker which is not fault handler + * interpret: + * 1. EAGAIN - A signal to retry walk again. + * 2. ENOENT - A signal to ignore and move on to next SPTE. + * + * Ignore these return codes altogether for other walkers and chug along * with the page table walk. */ - if (r == -EAGAIN || r == -ENOENT) + if (r == -EAGAIN) return !(walker->flags & KVM_PGTABLE_WALK_SHARED); + if (r == -ENOENT) + return !(walker->flags & KVM_PGTABLE_WALK_HANDLE_FAULT); return !r; } @@ -260,24 +266,44 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, return ret; } +static bool kvm_pgtable_walk_retry(const struct kvm_pgtable_walker *walker, + int r) +{ + /* + * All shared page table walks where visitor callbacks return -EAGAIN + * should be retried with the exception of fault handler. In case of + * fault handler retry is achieved by resuming the guest. + */ + if (r == -EAGAIN) + return (walker->flags & KVM_PGTABLE_WALK_SHARED) && + !(walker->flags & KVM_PGTABLE_WALK_HANDLE_FAULT); + + return !r; +} + static int __kvm_pgtable_walk(struct kvm_pgtable_walk_data *data, struct kvm_pgtable_mm_ops *mm_ops, kvm_pteref_t pgtable, u32 level) { u32 idx; int ret = 0; + kvm_pteref_t pteref; if (WARN_ON_ONCE(level >= KVM_PGTABLE_MAX_LEVELS)) return -EINVAL; for (idx = kvm_pgtable_idx(data, level); idx < PTRS_PER_PTE; ++idx) { - kvm_pteref_t pteref = &pgtable[idx]; +retry: + pteref = &pgtable[idx]; if (data->addr >= data->end) break; ret = __kvm_pgtable_visit(data, mm_ops, pteref, level); - if (ret) + if (ret) { + if (kvm_pgtable_walk_retry(data->walker, ret)) + goto retry; break; + } } return ret; From patchwork Fri Jun 2 16:09:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102647 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1145684vqr; Fri, 2 Jun 2023 09:20:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4FIW5VQF1r9Z3JnvNc0yoTNQOZ/4JffsO2sGhT6VFb9jxABWHdSwkorgfUL2j442HfJm5O X-Received: by 2002:a05:6a20:a120:b0:10f:3d02:863 with SMTP id q32-20020a056a20a12000b0010f3d020863mr11143731pzk.9.1685722834224; Fri, 02 Jun 2023 09:20:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722834; cv=none; d=google.com; s=arc-20160816; b=Oj+6/SjZ4gYy3AEOl8XqYe78MrTC33Ls8Ye5xOjdMrArjmB3zUVA+pTl92lPobfa8D Ux+Ir2xQCinWF0OKKAxxrMxMQdRApn840r09LigYSB+jSfh41YLl+WgN1uoBqfHkbvyU Wdpfien5MSxt2It06dEs/02zw5L6sGEZP1xot7Lbnk4If4+GbtgkFZ7ExkDa5kDbyHUf jWgjTOZmjZ8h5nnJDO+juapTuXXPgaFUV3gMuI40TNUvmCg5JqKCEtQuOZGGo5gvtMds sTa+WDpjJ8qL+nLMGagDiUpFrAheKdz7xNwwbpp5BYJwTPxpMHFDrcTqO3+kpZ88R+ln N/rA== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=iiQKR5r12cEmfxEtqKB501qQ7U5/inaqlNqkSHrg1Dk=; b=wK0vhm9Z27WXblZ6fhq5UCN1ujgC13y5Ex224C440S6MK/Ea7FzK+2iQRJmcjWgoMA hOJv+IhKv3PGFDRhQ9isUUoIYMGInVwPRJaCuU0JJzgwZjmU82PkPvoNBz8SdeD/jeg2 1FL4oVRx47IcQFu116iBdiyB4kFcI/HgT9IY/DiOzLLy8s+t4ahMpDjLWxDQnfUnBlm5 8wdx+uR0ScKx9bxlsdCBt96yt5bDRuLMkx+PfwacFluuKUpvxbLpJOdwFIbIYyltXamV AUxHGH0crpGEYcuMruG8Z5jAFeXeEWbGoWUAkcgoANvTShFhnPtbO4Jg3EgIGRsGRgA1 Yy3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=pa3mVvgl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e26-20020aa7981a000000b0065296ab4747si933872pfl.193.2023.06.02.09.20.20; Fri, 02 Jun 2023 09:20:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=pa3mVvgl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236783AbjFBQLG (ORCPT + 99 others); Fri, 2 Jun 2023 12:11:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236698AbjFBQKq (ORCPT ); Fri, 2 Jun 2023 12:10:46 -0400 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 EA400197 for ; Fri, 2 Jun 2023 09:10:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bb1e332f648so2298623276.0 for ; Fri, 02 Jun 2023 09:10:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722186; x=1688314186; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iiQKR5r12cEmfxEtqKB501qQ7U5/inaqlNqkSHrg1Dk=; b=pa3mVvglr9ldo0oASWJgWygRLd3hw8lG1pjLeB+Qzm3K3zOU5BQU88aja7wxcgPXwA AwayadZx6shxLAXjuJFrDzlMtsvb67kGNUVBIz8jQ9pcx5Jd6BF7pMABQixgPuk47qo/ QPSMIrvsitPTIbIvBs3Unmlez10KGpvyazPz0vuoWxeM0ddu7MUX6bOpsZv5FX/RHsfI ab0UhQ4BKG9ohwFpekgRN7rsQtHAtMFU2PEbvOsbX5+K7m399sRVLlUcmEJAu36XrUm4 MIK72o4Xoc2dnSjS77GyfH7dzmpmSt4gmenJO3sxGLvRMkP8fiKXjBjSppWa9vRlnGfd FwPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722186; x=1688314186; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iiQKR5r12cEmfxEtqKB501qQ7U5/inaqlNqkSHrg1Dk=; b=VV0aZNM0He5OoOzoAi7L9gqfHVrm2RPmCuF3ovNucFNsAnjbmeNaj+fEVbWIIZ1cnx R5V5lRiQrI3dVmOiV9l9ZvzUDw/5jp3ijkYWmMtmlusNr5l1iylntIBXGPwXELeldGzx yokH4QbvqTkaQqnwOdSy+aRFt1nZP12cEJ7ezkqFC5+s9uq2YyHJWVRNZMNofGRPYmDJ Ecz+DCzSkEAC2lhT37yO0vkmO2g7W8b4WK5ayaQPHR+2BpwaQFWNt4l/QdhUBUtv7T/e QOd0sHmDzl+VOBOaxY4jdSYMZkZd++IJxoBc18qH/NrAHacowhMYc5K9S+iJb6YjRhcO GDeg== X-Gm-Message-State: AC+VfDyeqAkH+wZ8vVvkh+Jhw2x3CF2yIF0r7xInaRkfh80t96Nkf477 DYd48Y1ina3pD4rfR9gRhg2l3Txd0GbC X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6902:1545:b0:ba8:181b:2558 with SMTP id r5-20020a056902154500b00ba8181b2558mr2255805ybu.4.1685722186031; Fri, 02 Jun 2023 09:09:46 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:11 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-14-vipinsh@google.com> Subject: [PATCH v2 13/16] KVM: arm64: Run clear-dirty-log under MMU read lock From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767608506378253811?= X-GMAIL-MSGID: =?utf-8?q?1767608506378253811?= Take MMU read lock for clearing dirty logs and use shared page table walker. Dirty logs are currently cleared using MMU write locks. This means vCPUs page faults, which takes MMU read lock, will be blocked while dirty logs are being cleared. This causes guest degradation and especially noticeable on VMs with lot of vCPUs. Taking MMU read lock will allow vCPUs to execute parallelly and reduces the impact on vCPUs performance. Signed-off-by: Vipin Sharma --- arch/arm64/kvm/mmu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 356dc4131023..7c966f6f1a41 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -74,8 +74,12 @@ static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, if (ret) break; - if (resched && next != end) - cond_resched_rwlock_write(&kvm->mmu_lock); + if (resched && next != end) { + if (flags & KVM_PGTABLE_WALK_SHARED) + cond_resched_rwlock_read(&kvm->mmu_lock); + else + cond_resched_rwlock_write(&kvm->mmu_lock); + } } while (addr = next, addr != end); return ret; @@ -1131,11 +1135,11 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, phys_addr_t start = (base_gfn + __ffs(mask)) << PAGE_SHIFT; phys_addr_t end = (base_gfn + __fls(mask) + 1) << PAGE_SHIFT; - write_lock(&kvm->mmu_lock); - lockdep_assert_held_write(&kvm->mmu_lock); - - stage2_wp_range(&kvm->arch.mmu, start, end, 0); + read_lock(&kvm->mmu_lock); + stage2_wp_range(&kvm->arch.mmu, start, end, KVM_PGTABLE_WALK_SHARED); + read_unlock(&kvm->mmu_lock); + write_lock(&kvm->mmu_lock); /* * Eager-splitting is done when manual-protect is set. We * also check for initially-all-set because we can avoid From patchwork Fri Jun 2 16:09:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1139622vqr; Fri, 2 Jun 2023 09:11:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6RQSMAePEYzY/HMFMO1jHJFX2PRH4G4wIn8e3p+6mXiI0CYTOecF9zsyXm/6ua/oOD+5lR X-Received: by 2002:a17:90a:1a1a:b0:258:d445:1d0 with SMTP id 26-20020a17090a1a1a00b00258d44501d0mr288341pjk.37.1685722284610; Fri, 02 Jun 2023 09:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722284; cv=none; d=google.com; s=arc-20160816; b=WLXbts2kuZ8tGgTly+ael0xPLPQ6HQYI8GsDwM41nz2kIODQ0UWiyLWby6QBwBvjc6 vWJ1Sp0/C7FhI0Zultz9oq0EermH+X9BuEFYyiO0gOZQqFvnUeIKHhOd8tamQLhADm7p FPADNQab/5DKrwZXa1b/DxYWUdTih0jNNLJeI01oXIQbyca3ejcMNBR0xgRTDdwew7i4 nXceOL+Thfvf6WlF9yKXqBnYGYvpqT2oqXV3gUVajZMQbjSZUH9kkg66+T3mkS0eyN9Q MwzSF2282Ii12Zdqgm4cL8tSFFAlM46SGHgojHWoMkyxsegXbWp8KIw/t1isA2lrzXHQ hL2g== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=ATfYeV4iZLydVfrv7VkfrrcrF6Iyfqli3wOIB/41cFU=; b=b4Xj2chm8h00rwQd9TKjfOW3QJnj2aLctCbAQgRKAcXWt/cLV4SxiJ0sq7N2hkurav 09CrgvswQE2XG0MpoW39e5dz19692RvvZ4zQRfkz2d24x8FtwG7QICVKuh1eiaxchSgo WuWgVWLy4d33Agjzd8tbXdFF4c/MvHf/2OCNx8JRYKjXQnqS9D9YJTSKpbCacnq891Qi t17kVRuFWFVx0C5LCxIAKVN9s5WjSYdIADxf06RIsqW2I4h2/qxX5Wt/2awCvJ7v4Z79 Z0rvGfQ4fPxr78vywVwkWco0+SS3SJi7h1mWBIlyjBNkDUSUpdCjOEyLkOFl1VWRhag+ vLgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Rqyu16ke; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc14-20020a17090b3b8e00b00250c9a70af9si1308032pjb.63.2023.06.02.09.11.11; Fri, 02 Jun 2023 09:11:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Rqyu16ke; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236611AbjFBQK3 (ORCPT + 99 others); Fri, 2 Jun 2023 12:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236619AbjFBQKF (ORCPT ); Fri, 2 Jun 2023 12:10:05 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AE4AE43 for ; Fri, 2 Jun 2023 09:09:48 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-565d1b86a63so31914217b3.0 for ; Fri, 02 Jun 2023 09:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722188; x=1688314188; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ATfYeV4iZLydVfrv7VkfrrcrF6Iyfqli3wOIB/41cFU=; b=Rqyu16keB0kE0WrdwrfeOOljSmmTEf5ym2HasOLzHF8ArvodVvyp0S6Lr0lp8jhqaO yU7vlRlNbGqDi7zvQpbHT6R5zFRE8DckASYhOzfH9V34Q20hh77zuuNe12GxNtHCZXh5 lnbwZ2Svz+2HB81mY68YPRkYswYr7F2GvqW0LS+zjsO1U81VkyPUwY6eD2Ki1IgFqmLS 03LcT6Q3zPmFBx5Lk1wR2QR7kJ2u+CVAlb7S/W7GXhPrjwIAChkVcnGC08nkCFgLZ6+3 IJyon3TZZUbxyP2iFDZRsS+2chcqzC8RuTMktYv6Efxwhi8TOTgmYLyH3MqqUylTOe6h 6cPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722188; x=1688314188; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ATfYeV4iZLydVfrv7VkfrrcrF6Iyfqli3wOIB/41cFU=; b=gu0d0/TCzfyFcPvNPeUcd/sOl6nUhM8CT/CNN9nItwtw3jKD2bObfK08B+SA8HmxpD V6avQLczs8IRX3h58ZIuZdcflS5JliWnJh+8TTL3qdmdRmJldDuOFhWtoaVU8IhTccDl KlPhHO1IDSdwqiPl1wj4hc9mySAjtV/zX7VlvVPGh2D/PL0H5ZUsSAmSAFtBo0KCOMrx JL+EyS4nCYzmFj0kWOGP+mTPD0pDVqSjxCK8x0yQarRu/0XM3YRIGlUtWCxUv7VJ7dCY AZE/+KVr1Eo3xuUyqwK0Q8SKHe8HDIpdVF9LWtVlbbndX6sZ0qgobFFi9dUU99zmx7J7 1/TQ== X-Gm-Message-State: AC+VfDyY/064Az9LnXSJkGTEH8z9qRyIz0iPvlLENZJ8EZQGFlCyuaxL 9R/yuJNl+30Th6ZGreeTJQC6oTZh+Us+ X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a25:e706:0:b0:bac:5d2c:844b with SMTP id e6-20020a25e706000000b00bac5d2c844bmr1305917ybh.8.1685722187745; Fri, 02 Jun 2023 09:09:47 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:12 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-15-vipinsh@google.com> Subject: [PATCH v2 14/16] KVM: arm64: Pass page walker flags from callers of stage 2 split walker From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607930407569610?= X-GMAIL-MSGID: =?utf-8?q?1767607930407569610?= Pass enum kvm_pgtable_walk_flags{} to kvm_pgtable_stage2_split() walker from its caller. This allows split walker users to specify if they want to run split logic via shared walker or non-shared walker. Signed-off-by: Vipin Sharma --- arch/arm64/include/asm/kvm_pgtable.h | 4 +++- arch/arm64/kvm/hyp/pgtable.c | 5 +++-- arch/arm64/kvm/mmu.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 145be12a5fc2..fbf5c6c509fb 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -684,6 +684,7 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size, * @size: Size of the range. * @mc: Cache of pre-allocated and zeroed memory from which to allocate * page-table pages. + * @flags: Page walker flags * * The function tries to split any level 1 or 2 entry that overlaps * with the input range (given by @addr and @size). @@ -693,7 +694,8 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size, * blocks in the input range as allowed by @mc_capacity. */ int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size, - struct kvm_mmu_memory_cache *mc); + struct kvm_mmu_memory_cache *mc, + enum kvm_pgtable_walk_flags flags); /** * kvm_pgtable_walk() - Walk a page-table. diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 23cda3de2dd4..7e84be13d76d 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1408,11 +1408,12 @@ static int stage2_split_walker(const struct kvm_pgtable_visit_ctx *ctx, } int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size, - struct kvm_mmu_memory_cache *mc) + struct kvm_mmu_memory_cache *mc, + enum kvm_pgtable_walk_flags flags) { struct kvm_pgtable_walker walker = { .cb = stage2_split_walker, - .flags = KVM_PGTABLE_WALK_LEAF, + .flags = flags | KVM_PGTABLE_WALK_LEAF, .arg = mc, }; diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 7c966f6f1a41..34d2bd03cf5f 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -153,7 +153,7 @@ static int kvm_mmu_split_huge_pages(struct kvm *kvm, phys_addr_t addr, return -EINVAL; next = __stage2_range_addr_end(addr, end, chunk_size); - ret = kvm_pgtable_stage2_split(pgt, addr, next - addr, cache); + ret = kvm_pgtable_stage2_split(pgt, addr, next - addr, cache, 0); if (ret) break; } while (addr = next, addr != end); From patchwork Fri Jun 2 16:09:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102642 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1140038vqr; Fri, 2 Jun 2023 09:12:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Pmru85yhRpf6R2JcM/XpTuj+qDzJGHDCBRqTQDUL8bpD3dnpkePmRFYgWd6e5kuEJy6mS X-Received: by 2002:a17:902:e5ce:b0:1ae:7631:7fa9 with SMTP id u14-20020a170902e5ce00b001ae76317fa9mr423208plf.37.1685722320278; Fri, 02 Jun 2023 09:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722320; cv=none; d=google.com; s=arc-20160816; b=uR6KeSXTC9J+JEZnXnaqDvTjOZsoHgrU1XmRgVt4XWa7hWxkSCi1fOScBhntn61Oe5 IGjzCPzb+SDZnARtyZhfn9ESWPACuTUixMYACO84wSsBf+nVwXAziLIxLTGFhP+mpcb9 ikCedZjiPz4ORPKeQcgKEi6L61gbGHKg4TkjOW/BC/yVkdEz7q5wf/Hl/oX+Via2va/G UPO511WGMHjpH2OxHFDmopv0/tQJy8ILqr8+tzuGckdxpD2JjW7dBsVGDeT73MmNidId mD0/RbCkni/XY2+Xx9Lw+BDbYVr7P6vzcA/9IDFvwKUkBvvxeod2rklkmOe4yutZTB7y 2H2A== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Hryh0ZWAFdBP/1ensclnMWOs6DFcoKq9t8dEIwwzMjM=; b=npWIbuuxz4cOfCwxJpfmykrvhr/3M2B5qSxaYVu/LIQbnUr6CmCM8YjlBYtCHHk+Ky 3OIGa+GP9EGhc8LhL6RCkm9Shuj0J+nWdoNDUiar8a9ZP1ddTFMEgmyI9rTz4xaxJYyb vssi3+yV9MfXzZUfiaK1NKoOEJRYoaSduHrjLP3VOiJ0xHoMKReAYCfrjSpsV+Q5YfkZ 6nKldFxAj3T5rx4zq/DqZVWltUU23bDRxsmJjr4NDGivxdrZX++JzTCKE3F0gcvvYD3y Iy6auo3Y3V80DcTpsD+BkXX8kHouHyrwwYZzlcKRkNL59JWzI9Kg4N5TaTC1RbWQ+aq9 /HIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=yFcSJ5sk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a170902da8800b001b00ae4ad40si1126406plx.368.2023.06.02.09.11.48; Fri, 02 Jun 2023 09:12:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=yFcSJ5sk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236760AbjFBQLL (ORCPT + 99 others); Fri, 2 Jun 2023 12:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236790AbjFBQK5 (ORCPT ); Fri, 2 Jun 2023 12:10:57 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 409B610E0 for ; Fri, 2 Jun 2023 09:10:10 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-565de486762so28471877b3.3 for ; Fri, 02 Jun 2023 09:10:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722190; x=1688314190; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Hryh0ZWAFdBP/1ensclnMWOs6DFcoKq9t8dEIwwzMjM=; b=yFcSJ5sk1YiYcQktVHUrIraA4vq3gzBg01wawQ+99X99BcERdv6aw79BJglFIsX38X Jmk2e5UaolCr5t1qAVgv5xhRcuwqz8qsPeKTN4dMinvHjEGhpXtPGawN2ICvlDQZGj8D ZmOScsl1sdyn4gxehMyRauugNpIrQjpu1KxL67VdJydhpwrAe8TXpUojYixIDTXpkYLZ L/KcS63c1WkLy8I19gAWFgXf90HgC8c3L1xN5Hze37jt9RE4scxALJ3lb9KGpgKF7m+y IPNOsGvdWwTPZEtqpxeUuo6lpLAcPxZcX9jQeWMRNApjKkg5jyviIXgCTWMDwLFLuVTH Fsfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722190; x=1688314190; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Hryh0ZWAFdBP/1ensclnMWOs6DFcoKq9t8dEIwwzMjM=; b=YbRopRQ5d4s1RPszjGmOFPaWm/yWA5OdEJzOTA/SwrtUFnFzRzus75ark+vK6dR6ye qJsccATYaRc319kTxhnyf5eSZHA8TzAjC7M8RsUzXp8sFE3b8FcCF8WdKmKBKR7pYXcd DEQ4MVlAuqigBDnuLEWbwtv2Egx6ucLgot/2CsyUz7YVZ+T/9LQ2erJrCSLu1POAHj6E cGk600D18SN+X/yBo/jZ4dAac6NVq9+fkMupMLUAIDnxtPJcJhAFOViIz2xwaHAm5a9B +8MKj2C7zslBNdTGkFpUhxmkfjSsdhz0imJ+ekVM3skijW3DO0l3pxBvRFeZ/juhOpWC 3SJw== X-Gm-Message-State: AC+VfDxhC9da1JnZpQoOi9rjyzmpeev9JyuwOdr4C1dEIfoQMlledidV MxLh7WeUSL55Qg2QS0XN9Bqw41tU3sXo X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a25:bc7:0:b0:ba8:cbd2:61b3 with SMTP id 190-20020a250bc7000000b00ba8cbd261b3mr1223005ybl.5.1685722190144; Fri, 02 Jun 2023 09:09:50 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:13 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-16-vipinsh@google.com> Subject: [PATCH v2 15/16] KVM: arm64: Provide option to pass page walker flag for huge page splits From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607967355775596?= X-GMAIL-MSGID: =?utf-8?q?1767607967355775596?= Pass enum kvm_pgtable_walk_flags{} to kvm_mmu_split_huge_pages(). Use 0 as the flag value to make it no-op. In future commit kvm_mmu_split_huge_pages() will be used under both MMU read lock and MMU write lock. Flag allows to pass intent to use shared or non-shared page walkers to split the huge pages. Signed-off-by: Vipin Sharma --- arch/arm64/kvm/mmu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 34d2bd03cf5f..6dd964e3682c 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -118,7 +118,8 @@ static bool need_split_memcache_topup_or_resched(struct kvm *kvm) } static int kvm_mmu_split_huge_pages(struct kvm *kvm, phys_addr_t addr, - phys_addr_t end) + phys_addr_t end, + enum kvm_pgtable_walk_flags flags) { struct kvm_mmu_memory_cache *cache; struct kvm_pgtable *pgt; @@ -153,7 +154,8 @@ static int kvm_mmu_split_huge_pages(struct kvm *kvm, phys_addr_t addr, return -EINVAL; next = __stage2_range_addr_end(addr, end, chunk_size); - ret = kvm_pgtable_stage2_split(pgt, addr, next - addr, cache, 0); + ret = kvm_pgtable_stage2_split(pgt, addr, next - addr, cache, + flags); if (ret) break; } while (addr = next, addr != end); @@ -1112,7 +1114,7 @@ static void kvm_mmu_split_memory_region(struct kvm *kvm, int slot) end = (memslot->base_gfn + memslot->npages) << PAGE_SHIFT; write_lock(&kvm->mmu_lock); - kvm_mmu_split_huge_pages(kvm, start, end); + kvm_mmu_split_huge_pages(kvm, start, end, 0); write_unlock(&kvm->mmu_lock); } @@ -1149,7 +1151,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, * again. */ if (kvm_dirty_log_manual_protect_and_init_set(kvm)) - kvm_mmu_split_huge_pages(kvm, start, end); + kvm_mmu_split_huge_pages(kvm, start, end, 0); write_unlock(&kvm->mmu_lock); } From patchwork Fri Jun 2 16:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 102644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1140224vqr; Fri, 2 Jun 2023 09:12:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4pTkgwX3fJXA+EWTe8gx0na4YELOQp1lzsG4kHtu0FPMSyjwQukxEwGCerIoiLR8YIgviS X-Received: by 2002:a17:90a:310:b0:255:5a5e:df22 with SMTP id 16-20020a17090a031000b002555a5edf22mr295387pje.43.1685722334541; Fri, 02 Jun 2023 09:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685722334; cv=none; d=google.com; s=arc-20160816; b=Ps64G1EfnjWfcXt2/Sn10O9fhFsKuc5UbudL+w8o+BzV6DSRYES2dVeWmW+407hWki veTGXPR5lBQUH7mgVJf8cMgwCA2i8oRT3vWwm4883wS/8TlWxnq+vpEIyYxIqo1kcCEh oZCneLZi1zvxyn05CSrgTVefcloQv22BYXGKYR/PJaIP22WCuzHpWTK0K8ZWfpfrDE1W np2CwILzAy76fBV8CF0pmN8d2GhpDy+g8B1ZRN1aNubT7HI8jNU/h9BRZn88hvyjLoiQ wNmE8RgN5SX2cDq2oYVwo3cdtMCvLz5LLBLy4tB/64NqETHNilXmpNjOixW2uEg/1N5l ae3A== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=pnaTvciscS5chSJrFdy/XWmGw+v5DL+sKG313yn6vtE=; b=u2YrctInTpMPNeIlkQm0+wVpb9FQ7Po1m1lNYRhUnPnewtOGQmum/6RnabSz/XOBZr QZtOM3jUp3BeX3db6BVssVjeV1bpaDe7HNzuWN5+8O7VBBzY+mFBHjbLI+xqoQbgX0a2 v8W61Oqn8FB/uUKmSiuABObeN39lX+sL+4aHwGSQf1jF1sQ4Y6rBLNXiIxeoXem0F/4J 4U0Vxkxp5Jc+s3cSnCWQtzQg+addcHq9CGmVSCte3NJScK3E+h95zLllI7yM41v+R+om +r4RZLjH+opJno/GCl3ugRPRg/Ql0HQuCeHzH4JtApc6/+xh1GZ/mx9qFELv1eVxkdb6 4s7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=3qM+gPLn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y192-20020a638ac9000000b0052856ce370asi1219798pgd.426.2023.06.02.09.12.00; Fri, 02 Jun 2023 09:12:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=3qM+gPLn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236892AbjFBQLZ (ORCPT + 99 others); Fri, 2 Jun 2023 12:11:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236796AbjFBQK5 (ORCPT ); Fri, 2 Jun 2023 12:10:57 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FB4310E7 for ; Fri, 2 Jun 2023 09:10:11 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-65320a6e904so380504b3a.0 for ; Fri, 02 Jun 2023 09:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685722192; x=1688314192; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pnaTvciscS5chSJrFdy/XWmGw+v5DL+sKG313yn6vtE=; b=3qM+gPLnKOcFkte53nrFJ4yxYHfRvj6VAQ74elJ+qIzLMj97WYlQnMm+LRqHDvoho4 8AW7RUIjuOvTDqJRc6MGpLfknZTHUVt0ac+jf1e4fznmqTNQB1YeAez2Pbf+vu4gX/wo xA9uw3YiFJ59xCiKuG3PqvgkOpwn1kfOyfDGnV3P6/41gfMjzqB9OHhb0wbZKNfck3ux QuubqPWPIMr2dr+usJ/0oHW/nWAg0PkVCfHTFjYBlz4FbohVSt4JZLXej+/lCcVIkw51 dikq26nIlv8414HoG8qlckcW0gk8fed5eU7B/bJPELllDOCa6K4cYwpu/yZBPdgX/sdW NMYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685722192; x=1688314192; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pnaTvciscS5chSJrFdy/XWmGw+v5DL+sKG313yn6vtE=; b=gSJ6ZYybc8c1micmW8iJ+Il/KR25C4qkKFSUYDahVXwn4An6XugYMHkHg8HdytntBY fxfrvQiL9eFzZ8FcttowXs8/QGu5eRqM0E0/T2BiyE/4T2+J55gJIstjGgzFECFBXf71 fNs+jbUWESWykNkeE3c5IQnLNFFhJ/ITBsc63nATygUKoOr9OJc/eAo/9XJD4m2H6V1l y6a5QzEDZ/uEfYQfSf1+ecCK/V1grmb4MvHPEP1MpwfV+FiU4Y1e4Sv2hkcLNrpaPUZy qiL1aifgYPtZ6OXMg6CkuxabT2kgsUsENkjLcB53vdMzmFatNP1PHrblBAKAmMLyh8K6 RitA== X-Gm-Message-State: AC+VfDyKhijQ3sPJHGJHXWh1UWgVzc0N1y/2RBEJgXAXIbaEJwWSV5Mr 107bD2S0s8dvf9X2cWjolQlNT/JZSFDJ X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:2e1a:b0:64f:9e1b:d4a8 with SMTP id fc26-20020a056a002e1a00b0064f9e1bd4a8mr4922796pfb.1.1685722192061; Fri, 02 Jun 2023 09:09:52 -0700 (PDT) Date: Fri, 2 Jun 2023 09:09:14 -0700 In-Reply-To: <20230602160914.4011728-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230602160914.4011728-1-vipinsh@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602160914.4011728-17-vipinsh@google.com> Subject: [PATCH v2 16/16] KVM: arm64: Split huge pages during clear-dirty-log under MMU read lock From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767607982384523838?= X-GMAIL-MSGID: =?utf-8?q?1767607982384523838?= Split huge pages under MMU read lock instead of write when clearing dirty log. Running huge page split under read lock will unblock vCPUs execution and allow whole clear-dirty-log operation run parallelly to vCPUs. Note that splitting huge pages involves two walkers. First walker calls stage2_split_walker() callback on each huge page. This callback will call another walker which creates an unlinked page table. This commit makes first walker as shared page walker which means, -EAGAIN will be retried. Before this patch, -EAGAIN would have been ignored and walker would go to next huge page. In practice this would not happen as the first walker was holding MMU write lock. Inner walker is unchanged as it is working on unlinked page table so no other thread will have access to it. To improve confidence in correctness tested via dirty_log_test. To measure performance improvement tested via dirty_log_perf_test. Set up: ------- Host: ARM Ampere Altra host (64 CPUs, 256 GB memory and single NUMA node) Test VM: 48 vCPU, 192 GB total memory. Ran dirty_log_perf_test for 400 iterations. ./dirty_log_perf_test -k 192G -v 48 -b 4G -m 2 -i 4000 -s anonymous_hugetlb_2mb -j Observation: ------------ +==================+=============================+===================+ | Clear Chunk size | Clear dirty log time change | vCPUs improvement | +==================+=============================+===================+ | 192GB | 56% | 152% | +------------------+-----------------------------+-------------------+ | 1GB | -81% | 72% | +------------------+-----------------------------+-------------------+ When larger chunks are used, clear dirty log time increases due to lots of cmpxchg() but vCPUs are also able to execute parallelly causing better performance of guest. When chunk size is small, read lock is very fast in clearing dirty logs as it is not waiting for MMU write lock and vCPUs are also able to run parallelly. Signed-off-by: Vipin Sharma --- arch/arm64/kvm/mmu.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 6dd964e3682c..aa278f5d27a2 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -126,7 +126,10 @@ static int kvm_mmu_split_huge_pages(struct kvm *kvm, phys_addr_t addr, int ret, cache_capacity; u64 next, chunk_size; - lockdep_assert_held_write(&kvm->mmu_lock); + if (flags & KVM_PGTABLE_WALK_SHARED) + lockdep_assert_held_read(&kvm->mmu_lock); + else + lockdep_assert_held_write(&kvm->mmu_lock); chunk_size = kvm->arch.mmu.split_page_chunk_size; cache_capacity = kvm_mmu_split_nr_page_tables(chunk_size); @@ -138,13 +141,19 @@ static int kvm_mmu_split_huge_pages(struct kvm *kvm, phys_addr_t addr, do { if (need_split_memcache_topup_or_resched(kvm)) { - write_unlock(&kvm->mmu_lock); + if (flags & KVM_PGTABLE_WALK_SHARED) + read_unlock(&kvm->mmu_lock); + else + write_unlock(&kvm->mmu_lock); cond_resched(); /* Eager page splitting is best-effort. */ ret = __kvm_mmu_topup_memory_cache(cache, cache_capacity, cache_capacity); - write_lock(&kvm->mmu_lock); + if (flags & KVM_PGTABLE_WALK_SHARED) + read_lock(&kvm->mmu_lock); + else + write_lock(&kvm->mmu_lock); if (ret) break; } @@ -1139,9 +1148,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, read_lock(&kvm->mmu_lock); stage2_wp_range(&kvm->arch.mmu, start, end, KVM_PGTABLE_WALK_SHARED); - read_unlock(&kvm->mmu_lock); - write_lock(&kvm->mmu_lock); /* * Eager-splitting is done when manual-protect is set. We * also check for initially-all-set because we can avoid @@ -1151,8 +1158,8 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, * again. */ if (kvm_dirty_log_manual_protect_and_init_set(kvm)) - kvm_mmu_split_huge_pages(kvm, start, end, 0); - write_unlock(&kvm->mmu_lock); + kvm_mmu_split_huge_pages(kvm, start, end, KVM_PGTABLE_WALK_SHARED); + read_unlock(&kvm->mmu_lock); } static void kvm_send_hwpoison_signal(unsigned long address, short lsb)