Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp171828rwb; Mon, 26 Sep 2022 16:45:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6B8x+kPQYdWB1kcAk33ApEe10y+AFPp6QCv9XTj2tvKf+YqoeJjZ7KPvtrAMW3ZT8pgvzK X-Received: by 2002:a17:90b:3843:b0:202:df54:4c10 with SMTP id nl3-20020a17090b384300b00202df544c10mr1275835pjb.100.1664235911726; Mon, 26 Sep 2022 16:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664235911; cv=none; d=google.com; s=arc-20160816; b=J52jQfBHK42guLciy3tK9AQiWzXnb52Kv9QtJ0BjiDiwqvUUFdzazbFkJKJiCNjrAd IeccglvePJgoAQjHz4SmWbQfizxW8j/VYTfWoxCPAQrpP5sZn1ILK49tBPSYcFtTdWta CWP7yVGQ7gxX4Rg6GH7gKMvps+DuLddoqMYZP6YTyGIgbgAIDqHsMJH65hSmCTEWGpsO wOVnE3sznLU6qa6HGhoVx8aetJctpNjwJkKw45KhYAGWqLTPaCU7UtUpKnU78wftaoMm hLkF9Y5yDBG7VAIhGL7saPJztWtpyAF8QBBlNfL7vV55/CQiUndBfbgp9qicu+GuEWFF txNw== 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=R4uQtEJE5e59CjrqKVswdXws/gcA7psIs8btH21+MPI=; b=urTDWi7pPqHEqFOJsWalYRTB/xWb1zZ39+AvZM/40lXnNmIi+Lhq88iIxyc3OABdJ/ 5QcjEFty7bwSNTNrgUbBREUP/RejIIxqFusBUl5I9rrzmv4SEor7/FQIR7hVKKzFiW+A JGBZa/MeJ7oEFNBSQC7dABvKHwPnczUC88immq14rwVrInaEn25R2oe+eA7anwpJHhte FG/AIdHu5CzkEh9JRXlU3G9gsiJW8+iqIaZFhBrABZCYgX+oFlp4ycUC5/Wwoc6kPPmy fYqr1RB+6bqQESUwwJbev5WZ5oYgLLLrBSE4QeOmhAO2/8IFP235IAj8fFiNVoBbZHaP A+KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GgFgwZi+; 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 z11-20020a63330b000000b00439c1e186c8si59717pgz.281.2022.09.26.16.44.59; Mon, 26 Sep 2022 16:45:11 -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=GgFgwZi+; 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 S230473AbiIZX1r (ORCPT + 99 others); Mon, 26 Sep 2022 19:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbiIZX1o (ORCPT ); Mon, 26 Sep 2022 19:27:44 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B16666EF2B for ; Mon, 26 Sep 2022 16:27:42 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id 3so7921178pga.1 for ; Mon, 26 Sep 2022 16:27:42 -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=R4uQtEJE5e59CjrqKVswdXws/gcA7psIs8btH21+MPI=; b=GgFgwZi+ddAl59t5WyglkquklNhracaGBrF6jU0NtDfgG0IgyUN+puhncM4Se+w3hN 3ew+w2WAJPxrfTMHOqMoH5NrrG6IkW5+egKVHdTceHhmZygy1KIcyJjeClsgKVlkj5ex oneWUpdx17BO4/PyBE6g+cJ8tE6d/72orSPDJT/z2Dn5cNhJcTxeiz73K/6cipRmQmPg 5WSDE+Crbf2mdPFXkZYYQykqzOJxfF2M7gXPNUdqAk6rST36q6aTR2pVw3SdsdUcI5Zd 7j5360faOwyI019TWu9zwCPdBHpnL9pJ3m2PtS+Z9jLoDEfpk2kTstRnVY5XOIb1KKxO K6qA== 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=R4uQtEJE5e59CjrqKVswdXws/gcA7psIs8btH21+MPI=; b=xIny8FlRuuD+sAhdSZFqnXukuynp975T9PSuxoPt2S6il2flOWNluh67w6tMg98/TY WmlHJR8R1QkswWGoDr1LCPciHvVcCjddsi40nwqGLmMqwe9VzNLo8Yk5drmN6mBIHzRm fmUg6NPkwKXYpMjuuoX0ld9ZiVbZ8gIRdnW/mVvhQgHfCUB+R06hxHAfOQGI8qG34xtd sh46NamzsKZVT21iiB+5pv7/JeP4PROdbyph1wuROaaBdmpfI5hGg4eaQBUDj06uNkvS H7xkxLm8N78sYSED7zxNgnt+SCVmpy7QzG9jO4ip5MOTxAK4zp5f/Rz5Ar767NfpejWK z7tg== X-Gm-Message-State: ACrzQf1vyvEJoks74S8jpQLFtAiCv9tIUs1bh7hr/xvsG0zkGzjCrUOJ /1ArmQlL9v9lZjeDOAnhaVyq/ELOyYWixyiRWB8tKQ== X-Received: by 2002:a63:1a51:0:b0:43b:e496:f2f4 with SMTP id a17-20020a631a51000000b0043be496f2f4mr22517497pgm.99.1664234861996; Mon, 26 Sep 2022 16:27:41 -0700 (PDT) MIME-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> <20220915000448.1674802-5-vannapurve@google.com> In-Reply-To: From: Vishal Annapurve Date: Mon, 26 Sep 2022 16:27:31 -0700 Message-ID: Subject: Re: [V2 PATCH 4/8] KVM: selftests: x86: Precompute the result for is_{intel,amd}_cpu() To: David Matlack Cc: x86 , kvm list , LKML , linux-kselftest@vger.kernel.org, Paolo Bonzini , shuah , Ben Gardon , Sean Christopherson , Oliver Upton , peterx@redhat.com, Vitaly Kuznetsov 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, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Wed, Sep 21, 2022 at 2:19 PM David Matlack wrote: > > On Thu, Sep 15, 2022 at 12:04:44AM +0000, Vishal Annapurve wrote: > > Cache the vendor CPU type in a global variable so that multiple calls > > to is_intel_cpu() do not need to re-execute CPUID. > > > > Add cpu vendor check in kvm_hypercall() so that it executes correct > > vmcall/vmmcall instruction when running on Intel/AMD hosts. This avoids > > exit to KVM which anyway tries to patch the instruction according to > > the cpu type. > > The commit shortlog makes no mention (nor even implies) that this commit > adds AMD support to kvm_hypercall(). Please break this commit up into 2. > One to precompute the result of is_{intel,amd}_cpu() and one to add AMD > support to kvm_hypercall(). > > If you really want to keep this as one commit (I don't know what the > benefit would be), please change the shortlog and commit message to > focus on the kvm_hypercall() change, as that is the real goal of this > commit. The precomputation is arguably and implementation detail. e.g. > is_amd_cpu is used by guest code within fix_hypercall_test.c, just caching the result will break the guest code execution. I have clubbed these two changes together in order to ensure that is_amd_cpu works fine for both host userspace and guest vm logic. > KVM: selftest: Add support for AMD to kvm_hypercall() > > Make it possible to use kvm_hypercall() on AMD by checking if running > on an AMD CPU and, if so, using vmmcall instead of vmcall. In order to > avoid executing CPUID in the guest on every call t kvm_hypercall() > (which would be slow), pre-compute the result of is_{intel,amd}_cpu() > as part of kvm_selftest_arch_init() and sync it into the guest > after loading the ELF image. > > But again, it'd be cleaner just to split it up. Caching the result of > is_{intel,amd}_cpu() is useful in its own right, independent of the > kvm_hypercall() change. > > > > > ... > > > > @@ -1314,8 +1321,10 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) > > > > void kvm_selftest_arch_init(void) > > { > > + is_cpu_amd = cpu_vendor_string_is("AuthenticAMD"); > > } > > > > void kvm_arch_post_vm_elf_load(struct kvm_vm *vm) > > { > > + sync_global_to_guest(vm, is_cpu_amd); > > } > > -- > > 2.37.2.789.g6183377224-goog > >