Message ID | 20221024113445.1022147-1-wei.w.wang@intel.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp393614wru; Mon, 24 Oct 2022 04:38:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4/nHyWTGP9kDcjN/uCaczLrQOIe8Cc+WxGhOM0PSQOFTl1J8o17DSabU9ofJ2nk0orGfHc X-Received: by 2002:a05:6402:2751:b0:443:d90a:43d4 with SMTP id z17-20020a056402275100b00443d90a43d4mr30884768edd.368.1666611499008; Mon, 24 Oct 2022 04:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666611499; cv=none; d=google.com; s=arc-20160816; b=dcLFulTz0m5cFM7xwJt/X46TAysA/cwa9krtzTg6dcotCdSF6WC4S5rmDs4QHOGoTT hXVp9XcRDGO1Cz42OoOluE/Ggg+0deficiFuMvYKVqVbFfSqXI+zz8sUf+MpwmYVyXLT u9uE10eHWbaZTaTKbapy6MA057ByVrRA/P5hsHotgiA8UP6Jcrf3t9ycbzTZYz11jvPC FNe/i7vKouJONxjwRT0B1a5vRQ7Gh6X50iv9ooc6j8xOii9/3PRivu/KL0jgh4+HUfIL cBWJR402lN0W4LZSWKbvgXN/eJmbXr6dHU968ZAFMo4KnzmDYISco7ixZAKRUTMqkpkQ OjEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=nnjfL20gRRXS94NKqJkerN/Cyi4xxTmguzT+cvGzdLc=; b=wLVTFP77oqQ2z7p8brd+sMAleCZGUp+BvfMoY81AnK8P92WpQ0z2NqOPvF2vntWLM7 smAJRtOl9FZV1EbSQ4hGUV3ClVoWbk1g0VtxKz2A79A35/fVDVIITf/gaibx9vbGXvWu YNw2UZ+BSkvMMzmfMjGKa/MSnaAqGbE35pSw0zhoPOYTiCNzkmVefdKwVye0c73Qma4/ 1mWq/14a8ABIFrGrxNR8jLDT82R/fbQft2O/IZGC+c9ULgnsRunFX7lBkncuYk+gJq7z CJUsJWz06Le/yWtA97rLPH/JXw0e65+pHF2JqCSESISbLyv5z96Ku1jGRRuS+IwjhUlR nlaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gtyqVztj; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd43-20020a17090796ab00b00781599eb7d9si30119244ejc.542.2022.10.24.04.37.55; Mon, 24 Oct 2022 04:38:18 -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=@intel.com header.s=Intel header.b=gtyqVztj; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230337AbiJXLhe (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Mon, 24 Oct 2022 07:37:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230417AbiJXLhV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Oct 2022 07:37:21 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCC831BE95; Mon, 24 Oct 2022 04:37:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666611430; x=1698147430; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Wie0KRK07xUN7/EuZ7ywHo0LLhf937NSiICWnDJkrNM=; b=gtyqVztj/zHIP2P34ZpZ1mdvAT40eMqHm0BZMCsAZ4xlZ9MoKO3zUR5P H55HZft2GCSsbZfbYBExwXWLSBa3Fq5g631p2Ljjt4DNV5jeHJyTEpa1o i1sV0w1eyX7ds7BeAN2WBrgJWeb91WjNjc4NPJ3t+oef0E0D5zTY+SkOj yhfqMUOCwFoO2ameISHGRQm2qH9NW22u3X6Dvusotyxi/ryaH7gRjXL/r SEZkiLfXwXMxWvWytX+KKe+FzZMNH0mNqnw4UbpG6KmU87Rc6dRr07Jz/ M0sNmBfapWwElLqQFNUcb6MrFfqd0s3s/cYkrqHSmIP5RmSLwlZIkInMH Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="371612750" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="371612750" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 04:34:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="773784589" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="773784589" Received: from tdx-lm.sh.intel.com ([10.239.53.27]) by fmsmga001.fm.intel.com with ESMTP; 24 Oct 2022 04:34:48 -0700 From: Wei Wang <wei.w.wang@intel.com> To: seanjc@google.com, pbonzini@redhat.com Cc: dmatlack@google.com, vipinsh@google.com, ajones@ventanamicro.com, eric.auger@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Wang <wei.w.wang@intel.com> Subject: [PATCH v1 00/18] KVM selftests code consolidation and cleanup Date: Mon, 24 Oct 2022 19:34:27 +0800 Message-Id: <20221024113445.1022147-1-wei.w.wang@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747568819078292133?= X-GMAIL-MSGID: =?utf-8?q?1747568819078292133?= |
Series |
KVM selftests code consolidation and cleanup
|
|
Message
Wang, Wei W
Oct. 24, 2022, 11:34 a.m. UTC
This patch series intends to improve kvm selftests with better code consolidation using the helper functions to perform vcpu and thread related operations. In general, several aspects are improved: 1) The current users allocate an array of vcpu pointers to the vcpus that are added to a vm, and an array of vcpu threads. This isn't necessary as kvm_vm already maintains a list of added vcpus. This series changes the list of vcpus in the kvm_vm struct to a vcpu array for users to work with and removes each user's own allocation of such vcpu arrays. Aslo add the vcpu thread to the kvm_vcpu struct, so that users don't need to explicitly allocate a thread array to manage vcpu threads on their own. 2) Change the users to use the helper functions provided by this series with the following enhancements: - Many users working with pthread_create/join forgot to check if error on returning. The helper functions have handled thoses inside, so users don't need to handle them by themselves; - The vcpu threads created via the helper functions are named in "vcpu-##id" format. Naming the threads facilitates debugging, performance tuning, runtime pining etc; - helper functions named with "vm_vcpu_threads_" iterates over all the vcpus that have been added to the vm. Users don't need a explicit loop to go through the added cpus by themselves. 3) kvm_vcpu is used as the interface parameter to the vcpu thread's start routine, and the user specific data is made to be the private data in kvm_vcpu. This can simplify the user specific data structures, as kvm_vcpu has already included the required info for the thread, for example, in patch 13, the cpu_idx field from "struct vcpu_thread" is a duplicate of vcpu->id. The changes have been tested on an SPR server. Patch 15 and 16 haven't been tested due to the lack of an ARM environment currently. Wei Wang (18): KVM: selftests/kvm_util: use array of pointers to maintain vcpus in kvm_vm KVM: selftests/kvm_util: use vm->vcpus[] when create vm with vcpus KVM: selftests/kvm_util: helper functions for vcpus and threads KVM: selftests/kvm_page_table_test: vcpu related code consolidation KVM: selftests/hardware_disable_test: code consolidation and cleanup KVM: selftests/dirty_log_test: vcpu related code consolidation KVM: selftests/max_guest_memory_test: vcpu related code consolidation KVM: selftests/set_memory_region_test: vcpu related code consolidation KVM: selftests/steal_time: vcpu related code consolidation and cleanup KVM: selftests/tsc_scaling_sync: vcpu related code consolidation KVM: selftest/xapic_ipi_test: vcpu related code consolidation KVM: selftests/rseq_test: name the migration thread and some cleanup KVM: selftests/perf_test_util: vcpu related code consolidation KVM: selftest/memslot_perf_test: vcpu related code consolidation KVM: selftests/vgic_init: vcpu related code consolidation KVM: selftest/arch_timer: vcpu related code consolidation KVM: selftests: remove the *vcpu[] input from __vm_create_with_vcpus KVM: selftests/kvm_create_max_vcpus: check KVM_MAX_VCPUS .../selftests/kvm/aarch64/arch_timer.c | 42 ++-- .../testing/selftests/kvm/aarch64/vgic_init.c | 35 ++- .../selftests/kvm/access_tracking_perf_test.c | 18 +- .../selftests/kvm/demand_paging_test.c | 9 +- .../selftests/kvm/dirty_log_perf_test.c | 11 +- tools/testing/selftests/kvm/dirty_log_test.c | 16 +- .../selftests/kvm/hardware_disable_test.c | 56 ++--- .../testing/selftests/kvm/include/kvm_util.h | 24 ++ .../selftests/kvm/include/kvm_util_base.h | 12 +- .../selftests/kvm/include/perf_test_util.h | 9 +- .../selftests/kvm/kvm_create_max_vcpus.c | 7 + .../selftests/kvm/kvm_page_table_test.c | 16 +- tools/testing/selftests/kvm/lib/kvm_util.c | 217 +++++++++++++++--- .../selftests/kvm/lib/perf_test_util.c | 68 ++---- .../selftests/kvm/lib/x86_64/perf_test_util.c | 11 +- tools/testing/selftests/kvm/lib/x86_64/vmx.c | 2 +- .../selftests/kvm/max_guest_memory_test.c | 53 ++--- .../kvm/memslot_modification_stress_test.c | 9 +- .../testing/selftests/kvm/memslot_perf_test.c | 137 +++++------ tools/testing/selftests/kvm/rseq_test.c | 10 +- .../selftests/kvm/set_memory_region_test.c | 16 +- tools/testing/selftests/kvm/steal_time.c | 15 +- .../selftests/kvm/x86_64/tsc_scaling_sync.c | 25 +- .../selftests/kvm/x86_64/xapic_ipi_test.c | 54 ++--- 24 files changed, 476 insertions(+), 396 deletions(-)
Comments
On Mon, Oct 24, 2022 at 07:34:27PM +0800, Wei Wang wrote: > This patch series intends to improve kvm selftests with better code > consolidation using the helper functions to perform vcpu and thread > related operations. > > In general, several aspects are improved: > 1) The current users allocate an array of vcpu pointers to the vcpus that > are added to a vm, and an array of vcpu threads. This isn't necessary > as kvm_vm already maintains a list of added vcpus. This series changes > the list of vcpus in the kvm_vm struct to a vcpu array for users to > work with and removes each user's own allocation of such vcpu arrays. > Aslo add the vcpu thread to the kvm_vcpu struct, so that users don't > need to explicitly allocate a thread array to manage vcpu threads on > their own. > 2) Change the users to use the helper functions provided by this series > with the following enhancements: > - Many users working with pthread_create/join forgot to check if > error on returning. The helper functions have handled thoses inside, > so users don't need to handle them by themselves; > - The vcpu threads created via the helper functions are named in > "vcpu-##id" format. Naming the threads facilitates debugging, > performance tuning, runtime pining etc; > - helper functions named with "vm_vcpu_threads_" iterates over all the > vcpus that have been added to the vm. Users don't need a explicit > loop to go through the added cpus by themselves. > 3) kvm_vcpu is used as the interface parameter to the vcpu thread's > start routine, and the user specific data is made to be the private > data in kvm_vcpu. This can simplify the user specific data structures, > as kvm_vcpu has already included the required info for the thread, for > example, in patch 13, the cpu_idx field from "struct vcpu_thread" > is a duplicate of vcpu->id. I haven't dug too much into the actual code yet, but I have some high level feedback based on a quick look through the series: - Use the format "KVM: selftests: <Decsription>" for the shortlog. - Make the shortlog more specific. "vcpu related code consolidation" is vague. - Do not introduce bugs and then fix them in subsequent commits. This breaks bisection. For example, kvm_page_table_test is broken at "KVM: selftests/kvm_util: use vm->vcpus[] when create vm with vcpus" and then fixed by "KVM: selftests/kvm_page_table_test: vcpu related code consolidation". - Try to limit each patch to one logical change. This is somewhat more art than science, but the basic idea is to avoid changing too much at once so that the code is easier to review and bisect. For example, "KVM: selftests/perf_test_util: vcpu related code consolidation" has a list of 6 different changes being made in the commit description. This is a sure sign this commit should be broken up. The same applies to many of the other patches. This will also make it easier to come up with more specific shortlogs. > > The changes have been tested on an SPR server. Patch 15 and 16 haven't > been tested due to the lack of an ARM environment currently. > > Wei Wang (18): > KVM: selftests/kvm_util: use array of pointers to maintain vcpus in > kvm_vm > KVM: selftests/kvm_util: use vm->vcpus[] when create vm with vcpus > KVM: selftests/kvm_util: helper functions for vcpus and threads > KVM: selftests/kvm_page_table_test: vcpu related code consolidation > KVM: selftests/hardware_disable_test: code consolidation and cleanup > KVM: selftests/dirty_log_test: vcpu related code consolidation > KVM: selftests/max_guest_memory_test: vcpu related code consolidation > KVM: selftests/set_memory_region_test: vcpu related code consolidation > KVM: selftests/steal_time: vcpu related code consolidation and cleanup > KVM: selftests/tsc_scaling_sync: vcpu related code consolidation > KVM: selftest/xapic_ipi_test: vcpu related code consolidation > KVM: selftests/rseq_test: name the migration thread and some cleanup > KVM: selftests/perf_test_util: vcpu related code consolidation > KVM: selftest/memslot_perf_test: vcpu related code consolidation > KVM: selftests/vgic_init: vcpu related code consolidation > KVM: selftest/arch_timer: vcpu related code consolidation > KVM: selftests: remove the *vcpu[] input from __vm_create_with_vcpus > KVM: selftests/kvm_create_max_vcpus: check KVM_MAX_VCPUS > > .../selftests/kvm/aarch64/arch_timer.c | 42 ++-- > .../testing/selftests/kvm/aarch64/vgic_init.c | 35 ++- > .../selftests/kvm/access_tracking_perf_test.c | 18 +- > .../selftests/kvm/demand_paging_test.c | 9 +- > .../selftests/kvm/dirty_log_perf_test.c | 11 +- > tools/testing/selftests/kvm/dirty_log_test.c | 16 +- > .../selftests/kvm/hardware_disable_test.c | 56 ++--- > .../testing/selftests/kvm/include/kvm_util.h | 24 ++ > .../selftests/kvm/include/kvm_util_base.h | 12 +- > .../selftests/kvm/include/perf_test_util.h | 9 +- > .../selftests/kvm/kvm_create_max_vcpus.c | 7 + > .../selftests/kvm/kvm_page_table_test.c | 16 +- > tools/testing/selftests/kvm/lib/kvm_util.c | 217 +++++++++++++++--- > .../selftests/kvm/lib/perf_test_util.c | 68 ++---- > .../selftests/kvm/lib/x86_64/perf_test_util.c | 11 +- > tools/testing/selftests/kvm/lib/x86_64/vmx.c | 2 +- > .../selftests/kvm/max_guest_memory_test.c | 53 ++--- > .../kvm/memslot_modification_stress_test.c | 9 +- > .../testing/selftests/kvm/memslot_perf_test.c | 137 +++++------ > tools/testing/selftests/kvm/rseq_test.c | 10 +- > .../selftests/kvm/set_memory_region_test.c | 16 +- > tools/testing/selftests/kvm/steal_time.c | 15 +- > .../selftests/kvm/x86_64/tsc_scaling_sync.c | 25 +- > .../selftests/kvm/x86_64/xapic_ipi_test.c | 54 ++--- > 24 files changed, 476 insertions(+), 396 deletions(-) > > -- > 2.27.0 >
On Thursday, October 27, 2022 5:23 AM, David Matlack: > On Mon, Oct 24, 2022 at 07:34:27PM +0800, Wei Wang wrote: > > This patch series intends to improve kvm selftests with better code > > consolidation using the helper functions to perform vcpu and thread > > related operations. > > > > In general, several aspects are improved: > > 1) The current users allocate an array of vcpu pointers to the vcpus that > > are added to a vm, and an array of vcpu threads. This isn't necessary > > as kvm_vm already maintains a list of added vcpus. This series changes > > the list of vcpus in the kvm_vm struct to a vcpu array for users to > > work with and removes each user's own allocation of such vcpu arrays. > > Aslo add the vcpu thread to the kvm_vcpu struct, so that users don't > > need to explicitly allocate a thread array to manage vcpu threads on > > their own. > > 2) Change the users to use the helper functions provided by this series > > with the following enhancements: > > - Many users working with pthread_create/join forgot to check if > > error on returning. The helper functions have handled thoses inside, > > so users don't need to handle them by themselves; > > - The vcpu threads created via the helper functions are named in > > "vcpu-##id" format. Naming the threads facilitates debugging, > > performance tuning, runtime pining etc; > > - helper functions named with "vm_vcpu_threads_" iterates over all the > > vcpus that have been added to the vm. Users don't need a explicit > > loop to go through the added cpus by themselves. > > 3) kvm_vcpu is used as the interface parameter to the vcpu thread's > > start routine, and the user specific data is made to be the private > > data in kvm_vcpu. This can simplify the user specific data structures, > > as kvm_vcpu has already included the required info for the thread, for > > example, in patch 13, the cpu_idx field from "struct vcpu_thread" > > is a duplicate of vcpu->id. > > I haven't dug too much into the actual code yet, but I have some high level > feedback based on a quick look through the series: > > - Use the format "KVM: selftests: <Decsription>" for the shortlog. I know it's not common to see so far, but curious is this the required format? I didn't find where it's documented. If it's indeed a requirement, probably we also need to enhance checkpatch.pl to detect this. If it's not required, I think it is more obvious to have /sub_field in the title, e.g. selftests/hardware_disable_test, to outline which specific part of selftests the patch is changing. (the selftests are growing larger with many usages independent of each other). > > - Make the shortlog more specific. "vcpu related code consolidation" is > vague. > > - Do not introduce bugs and then fix them in subsequent commits. This > breaks bisection. For example, kvm_page_table_test is broken at "KVM: > selftests/kvm_util: use vm->vcpus[] when create vm with vcpus" and > then fixed by "KVM: selftests/kvm_page_table_test: vcpu related code > consolidation". > > - Try to limit each patch to one logical change. This is somewhat more > art than science, but the basic idea is to avoid changing too much at > once so that the code is easier to review and bisect. For example, > "KVM: selftests/perf_test_util: vcpu related code consolidation" has > a list of 6 different changes being made in the commit description. > This is a sure sign this commit should be broken up. The same applies > to many of the other patches. This will also make it easier to come > up with more specific shortlogs. OK, will re-organize the patches.
On Thu, Oct 27, 2022, Wang, Wei W wrote: > On Thursday, October 27, 2022 5:23 AM, David Matlack: > > I haven't dug too much into the actual code yet, but I have some high level > > feedback based on a quick look through the series: > > > > - Use the format "KVM: selftests: <Decsription>" for the shortlog. > > I know it's not common to see so far, but curious is this the required format? It's definitely the preferred format. > I didn't find where it's documented. Heh, for all shortlog scopes, the "documentation" is `git log --pretty=oneline` :-) > If it's indeed a requirement, probably we also need to enhance checkpatch.pl > to detect this. I like the idea in theory, but that'd be a daunting task to set up, and quite the maintenance nightmare. There are probably thousands of file => scope mappings throughout the kernel, with any number of exceptions and arbitrary rules. > If it's not required, I think it is more obvious to have /sub_field in the title, > e.g. selftests/hardware_disable_test, to outline which specific part of > selftests the patch is changing. (the selftests are growing larger with many > usages independent of each other). I agree that "KVM: selftests:" is a rather large umbrella, but it's not obvious that "KVM: selfetest/<test>" is unequivocally better, e.g. if someone is making a change to x86_64/vmx_exception_with_invalid_guest_state.c, the scope will be KVM: selftests/x86_64/vmx_exception_with_invalid_guest_state: or KVM: selftests/vmx_exception_with_invalid_guest_state: which doesn't leave a whole lot of room for an actual shortlog. When reviewing selftests patches, I do find myself pausing sometimes to see exactly what file/test is being modified, but in almost all cases a quick glance at the diffstat provides the answer. And on the flip side, having all selftests patches exactly match "KVM: selftests:" makes it super easy to identify selftest changes, i.e. it's mostly a wash overall in terms of efficiency (for me at least).
On Thu, Oct 27, 2022 at 8:44 AM Sean Christopherson <seanjc@google.com> wrote: > > On Thu, Oct 27, 2022, Wang, Wei W wrote: > > On Thursday, October 27, 2022 5:23 AM, David Matlack: > > > I haven't dug too much into the actual code yet, but I have some high level > > > feedback based on a quick look through the series: > > > > > > - Use the format "KVM: selftests: <Decsription>" for the shortlog. > > > > I know it's not common to see so far, but curious is this the required format? > > It's definitely the preferred format. > > > I didn't find where it's documented. > > Heh, for all shortlog scopes, the "documentation" is `git log --pretty=oneline` :-) > > > If it's indeed a requirement, probably we also need to enhance checkpatch.pl > > to detect this. > > I like the idea in theory, but that'd be a daunting task to set up, and quite the > maintenance nightmare. There are probably thousands of file => scope mappings > throughout the kernel, with any number of exceptions and arbitrary rules. I was thinking about proposing this in checkpatch.pl, or in some KVM-specific check script. It seems like the following rule: If a commit only modifies files in tools/testing/selftests/kvm/*, then requires the shortlog match the regex "KVM: selftests: .*". That would handle the vast majority of cases without affecting other subsystems. Sean are you more concerned that if we start validating shortlogs in checkpatch.pl then eventually it will get too out of hand? (i.e. not so concerned with this specific case, but the general problem?) Either way, we should at least document the preferred KVM shortlog styles in Documentation/virtual/kvm/.
On Thu, Oct 27, 2022, David Matlack wrote: > On Thu, Oct 27, 2022 at 8:44 AM Sean Christopherson <seanjc@google.com> wrote: > > I like the idea in theory, but that'd be a daunting task to set up, and quite the > > maintenance nightmare. There are probably thousands of file => scope mappings > > throughout the kernel, with any number of exceptions and arbitrary rules. > > I was thinking about proposing this in checkpatch.pl, or in some > KVM-specific check script. It seems like the following rule: If a > commit only modifies files in tools/testing/selftests/kvm/*, then > requires the shortlog match the regex "KVM: selftests: .*". That would > handle the vast majority of cases without affecting other subsystems. > > Sean are you more concerned that if we start validating shortlogs in > checkpatch.pl then eventually it will get too out of hand? (i.e. not > so concerned with this specific case, but the general problem?) Ya, the general problem. Hardcoding anything KVM specific in checkpatch.pl isn't going to fly. The checkpatch maintainers most definitely don't want to take on the burden of maintaining subsystem rules. Letting one subsystem add custom rules effectively opens the flood gates to all subsystems adding custom rules. And from a KVM perspective, I don't want to have to get an Acked-by from a checkpatch maintiainer just to tweak a KVM rule. The only somewhat feasible approach I can think of would be to provide a generic "language" for shortlog scope rules, and have checkpatch look for a well-known file in relevant directories, e.g. add arch/x86/kvm/SCOPES or whatever. But even that is a non-trivial problem to solve, as it means coming up with a "language" that has a reasonable chance of working for many subsystems without generating too many false positives. It's definitely doable, and likely not actually a maintenance nightmare (I wrote that thinking of modifying a common rules file). But it's still fairly daunting as getting buy-in on something that affects the kernel at large tends to be easier said then done. Then again, I'm probably being pessimistic due to my sub-par regex+scripting skills :-)
On Thu, Oct 27, 2022 at 06:27:39PM +0000, Sean Christopherson wrote: > On Thu, Oct 27, 2022, David Matlack wrote: > > On Thu, Oct 27, 2022 at 8:44 AM Sean Christopherson <seanjc@google.com> wrote: > > > I like the idea in theory, but that'd be a daunting task to set up, and quite the > > > maintenance nightmare. There are probably thousands of file => scope mappings > > > throughout the kernel, with any number of exceptions and arbitrary rules. > > > > I was thinking about proposing this in checkpatch.pl, or in some > > KVM-specific check script. It seems like the following rule: If a > > commit only modifies files in tools/testing/selftests/kvm/*, then > > requires the shortlog match the regex "KVM: selftests: .*". That would > > handle the vast majority of cases without affecting other subsystems. > > > > Sean are you more concerned that if we start validating shortlogs in > > checkpatch.pl then eventually it will get too out of hand? (i.e. not > > so concerned with this specific case, but the general problem?) > > Ya, the general problem. Hardcoding anything KVM specific in checkpatch.pl isn't > going to fly. The checkpatch maintainers most definitely don't want to take on > the burden of maintaining subsystem rules. Letting one subsystem add custom rules > effectively opens the flood gates to all subsystems adding custom rules. And from > a KVM perspective, I don't want to have to get an Acked-by from a checkpatch > maintiainer just to tweak a KVM rule. > > The only somewhat feasible approach I can think of would be to provide a generic > "language" for shortlog scope rules, and have checkpatch look for a well-known > file in relevant directories, e.g. add arch/x86/kvm/SCOPES or whatever. But even > that is a non-trivial problem to solve, as it means coming up with a "language" > that has a reasonable chance of working for many subsystems without generating too > many false positives. > > It's definitely doable, and likely not actually a maintenance nightmare (I wrote > that thinking of modifying a common rules file). But it's still fairly daunting > as getting buy-in on something that affects the kernel at large tends to be easier > said then done. Then again, I'm probably being pessimistic due to my sub-par > regex+scripting skills :-) How about adding support for checkpatch extension plugins? If we could add a plugin script, e.g. tools/testing/selftests/kvm/.checkpatch, and modify checkpatch to run .checkpatch scripts in the patched files' directories (and recursively in the parent directories) when found, then we'd get custom checkpatch behaviors. The scripts wouldn't even have to be written in Perl (but I say that a bit sadly, because I like Perl). Thanks, drew
On Fri, Oct 28, 2022, Andrew Jones wrote: > On Thu, Oct 27, 2022 at 06:27:39PM +0000, Sean Christopherson wrote: > > On Thu, Oct 27, 2022, David Matlack wrote: > > > On Thu, Oct 27, 2022 at 8:44 AM Sean Christopherson <seanjc@google.com> wrote: > > > > I like the idea in theory, but that'd be a daunting task to set up, and quite the > > > > maintenance nightmare. There are probably thousands of file => scope mappings > > > > throughout the kernel, with any number of exceptions and arbitrary rules. > > > > > > I was thinking about proposing this in checkpatch.pl, or in some > > > KVM-specific check script. It seems like the following rule: If a > > > commit only modifies files in tools/testing/selftests/kvm/*, then > > > requires the shortlog match the regex "KVM: selftests: .*". That would > > > handle the vast majority of cases without affecting other subsystems. > > > > > > Sean are you more concerned that if we start validating shortlogs in > > > checkpatch.pl then eventually it will get too out of hand? (i.e. not > > > so concerned with this specific case, but the general problem?) > > > > Ya, the general problem. Hardcoding anything KVM specific in checkpatch.pl isn't > > going to fly. The checkpatch maintainers most definitely don't want to take on > > the burden of maintaining subsystem rules. Letting one subsystem add custom rules > > effectively opens the flood gates to all subsystems adding custom rules. And from > > a KVM perspective, I don't want to have to get an Acked-by from a checkpatch > > maintiainer just to tweak a KVM rule. > > > > The only somewhat feasible approach I can think of would be to provide a generic > > "language" for shortlog scope rules, and have checkpatch look for a well-known > > file in relevant directories, e.g. add arch/x86/kvm/SCOPES or whatever. But even > > that is a non-trivial problem to solve, as it means coming up with a "language" > > that has a reasonable chance of working for many subsystems without generating too > > many false positives. > > > > It's definitely doable, and likely not actually a maintenance nightmare (I wrote > > that thinking of modifying a common rules file). But it's still fairly daunting > > as getting buy-in on something that affects the kernel at large tends to be easier > > said then done. Then again, I'm probably being pessimistic due to my sub-par > > regex+scripting skills :-) > > How about adding support for checkpatch extension plugins? If we could add > a plugin script, e.g. tools/testing/selftests/kvm/.checkpatch, and modify > checkpatch to run .checkpatch scripts in the patched files' directories > (and recursively in the parent directories) when found, then we'd get > custom checkpatch behaviors. The scripts wouldn't even have to be written > in Perl (but I say that a bit sadly, because I like Perl). That will work for simple cases, but patches that touch files in multiple directories will be messy. E.g. a patch that touches virt/kvm/ and arch/x86/kvm/ will have two separate custom rules enforcing two different scopes. Recursively executing plugins will also be problematic, e.g. except for KVM, arch/x86/ is maintained by the tip-tree folks, and the tip-tree is quite opinionated on all sorts of things, whereas KVM tends to be a bit more relaxed. Enforcing scope through plugins would also lead to some amount of duplicate code throught subsystems. Anyways, if someone wants to pursue this, these ideas and the "requirement" should be run by the checkpatch maintainers. They have far more experience and authority in this area, and I suspect we aren't the first people to want checkpatch to get involved in enforcing shortlog scope.
On Fri, Oct 28, 2022 at 8:49 AM Sean Christopherson <seanjc@google.com> wrote: > > On Fri, Oct 28, 2022, Andrew Jones wrote: > > On Thu, Oct 27, 2022 at 06:27:39PM +0000, Sean Christopherson wrote: > > > On Thu, Oct 27, 2022, David Matlack wrote: > > > > On Thu, Oct 27, 2022 at 8:44 AM Sean Christopherson <seanjc@google.com> wrote: > > > > > I like the idea in theory, but that'd be a daunting task to set up, and quite the > > > > > maintenance nightmare. There are probably thousands of file => scope mappings > > > > > throughout the kernel, with any number of exceptions and arbitrary rules. > > > > > > > > I was thinking about proposing this in checkpatch.pl, or in some > > > > KVM-specific check script. It seems like the following rule: If a > > > > commit only modifies files in tools/testing/selftests/kvm/*, then > > > > requires the shortlog match the regex "KVM: selftests: .*". That would > > > > handle the vast majority of cases without affecting other subsystems. > > > > > > > > Sean are you more concerned that if we start validating shortlogs in > > > > checkpatch.pl then eventually it will get too out of hand? (i.e. not > > > > so concerned with this specific case, but the general problem?) > > > > > > Ya, the general problem. Hardcoding anything KVM specific in checkpatch.pl isn't > > > going to fly. The checkpatch maintainers most definitely don't want to take on > > > the burden of maintaining subsystem rules. Letting one subsystem add custom rules > > > effectively opens the flood gates to all subsystems adding custom rules. And from > > > a KVM perspective, I don't want to have to get an Acked-by from a checkpatch > > > maintiainer just to tweak a KVM rule. > > > > > > The only somewhat feasible approach I can think of would be to provide a generic > > > "language" for shortlog scope rules, and have checkpatch look for a well-known > > > file in relevant directories, e.g. add arch/x86/kvm/SCOPES or whatever. But even > > > that is a non-trivial problem to solve, as it means coming up with a "language" > > > that has a reasonable chance of working for many subsystems without generating too > > > many false positives. > > > > > > It's definitely doable, and likely not actually a maintenance nightmare (I wrote > > > that thinking of modifying a common rules file). But it's still fairly daunting > > > as getting buy-in on something that affects the kernel at large tends to be easier > > > said then done. Then again, I'm probably being pessimistic due to my sub-par > > > regex+scripting skills :-) > > > > How about adding support for checkpatch extension plugins? If we could add > > a plugin script, e.g. tools/testing/selftests/kvm/.checkpatch, and modify > > checkpatch to run .checkpatch scripts in the patched files' directories > > (and recursively in the parent directories) when found, then we'd get > > custom checkpatch behaviors. The scripts wouldn't even have to be written > > in Perl (but I say that a bit sadly, because I like Perl). > > That will work for simple cases, but patches that touch files in multiple directories > will be messy. E.g. a patch that touches virt/kvm/ and arch/x86/kvm/ will have > two separate custom rules enforcing two different scopes. > > Recursively executing plugins will also be problematic, e.g. except for KVM, arch/x86/ > is maintained by the tip-tree folks, and the tip-tree is quite opinionated on all > sorts of things, whereas KVM tends to be a bit more relaxed. > > Enforcing scope through plugins would also lead to some amount of duplicate code > throught subsystems. > > Anyways, if someone wants to pursue this, these ideas and the "requirement" should > be run by the checkpatch maintainers. They have far more experience and authority > in this area, and I suspect we aren't the first people to want checkpatch to get > involved in enforcing shortlog scope. Documenting would at least be an improvement over what we have today since it would eliminate the need to re-explain the preferred rules every time. We can just point to the documentation when reviewing patches. `git log --pretty=oneline` is not a great way to document shortlog scopes because it does not explain the rules (e.g. when to use "KVM: x86: " vs "KVM: x86/mmu: "), does not explain why things the way they are, and is inconsistent since we don't always catch every patch that goes by with a non-preferred shortlog scope.
On Mon, Nov 07, 2022, David Matlack wrote: > On Fri, Oct 28, 2022 at 8:49 AM Sean Christopherson <seanjc@google.com> wrote: > > Anyways, if someone wants to pursue this, these ideas and the "requirement" should > > be run by the checkpatch maintainers. They have far more experience and authority > > in this area, and I suspect we aren't the first people to want checkpatch to get > > involved in enforcing shortlog scope. > > Documenting would at least be an improvement over what we have today > since it would eliminate the need to re-explain the preferred rules > every time. We can just point to the documentation when reviewing > patches. Agreed. And there are many other things I want to formalize for KVM x86, e.g. testing expectations, health requirements for the various branches, what each branch is used for etc... If you want to send a patch for the shortlogs thing, maybe create Documentation/process/maintainer-kvm-x86.rst and link it into Documentation/process/maintainer-handbooks.rst? > `git log --pretty=oneline` is not a great way to document shortlog > scopes because it does not explain the rules (e.g. when to use "KVM: > x86: " vs "KVM: x86/mmu: "), does not explain why things the way they > are, and is inconsistent since we don't always catch every patch that > goes by with a non-preferred shortlog scope.
On Mon, Nov 7, 2022 at 10:19 AM Sean Christopherson <seanjc@google.com> wrote: > > On Mon, Nov 07, 2022, David Matlack wrote: > > On Fri, Oct 28, 2022 at 8:49 AM Sean Christopherson <seanjc@google.com> wrote: > > > Anyways, if someone wants to pursue this, these ideas and the "requirement" should > > > be run by the checkpatch maintainers. They have far more experience and authority > > > in this area, and I suspect we aren't the first people to want checkpatch to get > > > involved in enforcing shortlog scope. > > > > Documenting would at least be an improvement over what we have today > > since it would eliminate the need to re-explain the preferred rules > > every time. We can just point to the documentation when reviewing > > patches. > > Agreed. And there are many other things I want to formalize for KVM x86, e.g. > testing expectations, health requirements for the various branches, what each > branch is used for etc... > > If you want to send a patch for the shortlogs thing, maybe create > > Documentation/process/maintainer-kvm-x86.rst > > and link it into Documentation/process/maintainer-handbooks.rst? Can do. I'll try to take a look later this week or next week.