Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4995876rwb; Tue, 6 Sep 2022 16:47:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5WDYz2AQpwEjP5e2ybRuqvEBSXv2ZQW8nPfD7hpSL62hfkE8OgmiKre1DjFMLZdimJ9Zpu X-Received: by 2002:a17:907:1c0d:b0:76f:ab7:d0ed with SMTP id nc13-20020a1709071c0d00b0076f0ab7d0edmr538010ejc.608.1662508038358; Tue, 06 Sep 2022 16:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662508038; cv=none; d=google.com; s=arc-20160816; b=Z3Ix6kaGeYKiAwqkQ2YhWdYlcEMjxFOvSsjFHZLca5nOx7NWBaOWq9kwcS5eQB8q0I Y3iIimKmK8ion+2RB+Ga+scc+otl2YYRcDfzUXj5yuoUunFJQm8oM3qv75/pcV9TtLgs ISrOPyOpa0qdHjE6gEQW3qWo+AXGiJdgC5afGizCYbvszFSVXDGchbtQukvky7Zt9cXP SuYuZcOviLugSoT6C5gu6zFJaBJm/dn8SxCH3vrqv3zG++TJ24SHTZO/ZAdNoRZqogeq HrtT7l9y+tgVy1LpfuRDoE4YwhnO/JVQk8cwuRh3bKAUSeckdGYoKrtc/sMeBH+GcylC 0ZhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oaTtXOG0HZ5g5qg4koIa0611t09qPZATkIZPeRybbyE=; b=t/jHLf1zrzttipgfQ6zxRZ39m7Ia4GNwjgVucjMEpw1TDZipvYuslBia/umbhZhOf+ Bi2YfhXD5DJSaoL9U5+TDEL+FymToayKz5MbfCgkDOdzweuKdCKCQHuTQopP0G64p8y5 jWRzrJv6yM8k08Yxb65+TuAOvlZ4TQt23Y4Q+18DWkr6mPa94AWL9nl9IsjsRZyYtjiu u24dsxhHrpansByAb5BlUC0XSt42gxev/YBcEIPa8+hS++0+VWE69WeJTjmI5BD6vHRy NFIwek63M5bksyi9ppu/jhuO5kVbKK9Bljvb+8LU+1U1U0vIOYT7Q8dXabRCJY+9Z1uP 0ODw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F9OuXAaK; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020aa7c1c5000000b0044e69ba81e1si6212157edp.168.2022.09.06.16.46.52; Tue, 06 Sep 2022 16:47: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=@google.com header.s=20210112 header.b=F9OuXAaK; 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 S229953AbiIFWqf (ORCPT + 99 others); Tue, 6 Sep 2022 18:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbiIFWqd (ORCPT ); Tue, 6 Sep 2022 18:46:33 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FBB398A73 for ; Tue, 6 Sep 2022 15:46:31 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id v4so11870364pgi.10 for ; Tue, 06 Sep 2022 15:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=oaTtXOG0HZ5g5qg4koIa0611t09qPZATkIZPeRybbyE=; b=F9OuXAaK9W/u+qhAD+rF7gpCdPMj7kJHKN9t+vgit1gYXr1EkM+WrrruLUx4F3l5ie UsrOz+FuNMl/EFgfiACGIkaE9ifiyu06ogeBMh8iWGI51bjZOkTmurcic6E4XvY8nqzP TSWashKQMI97TUyvJyFBZTiNoYrqjmmbnVrOfevlaMSQweP4Gq5ZohUCYj/N3RSC/bav 71+jlsf7gG0rg221WIDoGpXAkFxLoBWnCzLI1ecyoumbxuLAvIFzvmP8WuAgTQ2rweYw QV0B2dTMPyJE1NZl+ObhHFeqjGZlhGnpQ7Uror3D3se62430ZVQDcpKraWsPk7whuD10 R7mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=oaTtXOG0HZ5g5qg4koIa0611t09qPZATkIZPeRybbyE=; b=lkTQ6ECk8Kakv1Fub8YmFBXM9ELMrr4InYOOXUL2Fjp/muPqb51Hat1rhReQdVkkki z36pFKIQ3en2vYnewgsYN6QUZbqOyDsFvRD4RoDK7e9CgBQTAOm9RyjWf7XkEuaYz7sk M4fCCHah1oFpTKkWS10C7SzZIvrlAP0H2pNp0dbqXH9nUix62Jfy1OXCngCgUgqTkAGj 0flAgPOGadC+YJ/Oj3sdwz8J7QUL6cGbcr9RM0SkDubrQrHOk9mbsA92gjHuNipSsCyT WxACMiTFtV0tvwsaDlINcI+GLZ3FqwJms+hscNc/Obo50MqPwpkr+lTR8Z8Fgmh9wyA2 TbcQ== X-Gm-Message-State: ACgBeo2Qcs4wuHPeh84DfYexoQWOLn1retze+SLV3VsNm86MJUCKnEqA +/jAeLlIh/6xeODQLlkxoyhSQRFsAkowJ616JljQOlakWX4= X-Received: by 2002:a63:4726:0:b0:430:3886:5a2f with SMTP id u38-20020a634726000000b0043038865a2fmr774630pga.99.1662504390764; Tue, 06 Sep 2022 15:46:30 -0700 (PDT) MIME-Version: 1.0 References: <20220903012849.938069-1-vannapurve@google.com> <20220903012849.938069-3-vannapurve@google.com> <20220905074609.ga4tnpuxpcgppx4r@kamzik> In-Reply-To: <20220905074609.ga4tnpuxpcgppx4r@kamzik> From: Vishal Annapurve Date: Tue, 6 Sep 2022 15:46:20 -0700 Message-ID: Subject: Re: [V1 PATCH 2/5] selftests: kvm: Introduce kvm_arch_main and helpers To: Andrew Jones Cc: x86 , kvm list , LKML , linux-kselftest@vger.kernel.org, Paolo Bonzini , shuah , Ben Gardon , Sean Christopherson , oupton@google.com, peterx@redhat.com, Vitaly Kuznetsov , drjones@redhat.com, David Matlack Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Mon, Sep 5, 2022 at 12:46 AM Andrew Jones wrote: > > On Sat, Sep 03, 2022 at 01:28:46AM +0000, Vishal Annapurve wrote: > > Introduce following APIs: > > 1) kvm_arch_main : to be called at the startup of each test. > > With this, AArch64 can move the content of its constructor, > init_guest_modes(), into kvm_arch_main(). Or, instead of the > > main() > { > /* common main stuff */ > kvm_arch_main(); > __main(); > } > > approach we could have each arch provide a constructor > > arch_init() > { > common_pre_main_stuff(); > /* arch specific pre-main stuff */ > } > > I personally prefer the latter. > I agree with your suggestion of using constructors here. This will help avoid changes in all the selftests. Maybe I can add a common constructor that can invoke arch specific init. I will add this change in the next series. Thanks, Vishal > Thanks, > drew > > > 2) kvm_arch_post_vm_load: called after guest elf image is loaded into > > memory to populate any global state in guest memory. > > > > Suggested-by: Sean Christopherson > > Signed-off-by: Vishal Annapurve > > --- > > tools/testing/selftests/kvm/include/kvm_util_base.h | 10 ++++++++++ > > tools/testing/selftests/kvm/lib/aarch64/processor.c | 8 ++++++++ > > tools/testing/selftests/kvm/lib/elf.c | 2 ++ > > tools/testing/selftests/kvm/lib/kvm_util.c | 2 ++ > > tools/testing/selftests/kvm/lib/riscv/processor.c | 8 ++++++++ > > tools/testing/selftests/kvm/lib/s390x/processor.c | 8 ++++++++ > > tools/testing/selftests/kvm/lib/x86_64/processor.c | 8 ++++++++ > > 7 files changed, 46 insertions(+) > > > > diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h > > index 9e521d1c8afe..301bef6376a5 100644 > > --- a/tools/testing/selftests/kvm/include/kvm_util_base.h > > +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h > > @@ -834,6 +834,16 @@ static inline int __vm_disable_nx_huge_pages(struct kvm_vm *vm) > > return __vm_enable_cap(vm, KVM_CAP_VM_DISABLE_NX_HUGE_PAGES, 0); > > } > > > > +/* > > + * API to execute architecture specific setup before executing selftest logic. > > + */ > > +void kvm_arch_main(void); > > + > > +/* > > + * API to execute architecture specific setup after loading VMs. > > + */ > > +void kvm_arch_post_vm_load(struct kvm_vm *vm); > > + > > /* > > * API to be implemented by all the selftests. > > */ > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > index 6f5551368944..a7ca1947d574 100644 > > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c > > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > @@ -528,3 +528,11 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, > > [arg4] "r"(arg4), [arg5] "r"(arg5), [arg6] "r"(arg6) > > : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); > > } > > + > > +void kvm_arch_main(void) > > +{ > > +} > > + > > +void kvm_arch_post_vm_load(struct kvm_vm *vm) > > +{ > > +} > > diff --git a/tools/testing/selftests/kvm/lib/elf.c b/tools/testing/selftests/kvm/lib/elf.c > > index 9f54c098d9d0..f56f9279e703 100644 > > --- a/tools/testing/selftests/kvm/lib/elf.c > > +++ b/tools/testing/selftests/kvm/lib/elf.c > > @@ -189,4 +189,6 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename) > > phdr.p_filesz); > > } > > } > > + > > + kvm_arch_post_vm_load(vm); > > } > > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > > index 2e611a021c6e..b778dc684e30 100644 > > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > > @@ -1985,6 +1985,8 @@ int main(int argc, char *argv[]) > > /* Tell stdout not to buffer its content */ > > setbuf(stdout, NULL); > > > > + kvm_arch_main(); > > + > > __main(argc, argv); > > > > return 0; > > diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c > > index 604478151212..d992ad5b5771 100644 > > --- a/tools/testing/selftests/kvm/lib/riscv/processor.c > > +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c > > @@ -362,3 +362,11 @@ void vcpu_args_set(struct kvm_vcpu *vcpu, unsigned int num, ...) > > void assert_on_unhandled_exception(struct kvm_vcpu *vcpu) > > { > > } > > + > > +void kvm_arch_main(void) > > +{ > > +} > > + > > +void kvm_arch_post_vm_load(struct kvm_vm *vm) > > +{ > > +} > > diff --git a/tools/testing/selftests/kvm/lib/s390x/processor.c b/tools/testing/selftests/kvm/lib/s390x/processor.c > > index 89d7340d9cbd..3a249783b3fe 100644 > > --- a/tools/testing/selftests/kvm/lib/s390x/processor.c > > +++ b/tools/testing/selftests/kvm/lib/s390x/processor.c > > @@ -218,3 +218,11 @@ void vcpu_arch_dump(FILE *stream, struct kvm_vcpu *vcpu, uint8_t indent) > > void assert_on_unhandled_exception(struct kvm_vcpu *vcpu) > > { > > } > > + > > +void kvm_arch_main(void) > > +{ > > +} > > + > > +void kvm_arch_post_vm_load(struct kvm_vm *vm) > > +{ > > +} > > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c > > index 2e6e61bbe81b..e22cfc4bf284 100644 > > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c > > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c > > @@ -1311,3 +1311,11 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) > > > > return val == 'Y'; > > } > > + > > +void kvm_arch_main(void) > > +{ > > +} > > + > > +void kvm_arch_post_vm_load(struct kvm_vm *vm) > > +{ > > +} > > -- > > 2.37.2.789.g6183377224-goog > >