From patchwork Wed Dec 28 19:24:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 13083158 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8C5AC4167B for ; Wed, 28 Dec 2022 19:24:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233168AbiL1TYs (ORCPT ); Wed, 28 Dec 2022 14:24:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231701AbiL1TYo (ORCPT ); Wed, 28 Dec 2022 14:24:44 -0500 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 628811402A for ; Wed, 28 Dec 2022 11:24:43 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id y2-20020a17090a784200b00225c0839b80so5794208pjl.5 for ; Wed, 28 Dec 2022 11:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=bCqKzNO/sV1xA0tw8G4wlXIPUU+2YxbZOWSs6DXXIHU=; b=AyzeTyN2Jl9A+vgxF5pIBGLPh1T0qKh2Yl02a8PYsQJwpVgZMhKKulr2k2ivswTPcF KN4PFwjw1InW7UVfkB8fYtgvWObRTmfT5PHmlZ7U/lbB+AtSq7fgtjwVEs3s17+ixP2q /70AQjNqjhMFgIjsfb7wv8XKPRf4b+bi+//zJ9I/15wv52uspPxtwQhqsG5RfcRn6bZR uUh66NmH0EBsVB0SEfAif5TNEzSz2EusU/+q04Lx731PrULE46E0gskMNkpw8x/zEsUf /qc0mLaGHrE617ecyqsALZx/28rl7y38x4Hof7URzPEQS5FZA89NKHuNxb+tSuto8hL/ zkMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bCqKzNO/sV1xA0tw8G4wlXIPUU+2YxbZOWSs6DXXIHU=; b=XOLrVs+Ic+pOeoovP8ZgdYOnmTbKqimZqqF2O4roNvFqZDb//+vWYY0jzpA0u3wtDJ BHBEMcpqz/ZBNghTk48EeaTDuRIe9JauecTOauYTLo2sAmNRqEzoVq8txB5ac5fnmAP7 oRlcsZYMJrBfHerFaylZKU1ETcb2muTbte24R5oO9ylzqDV+wMZYR9hFKwVULfQKX3+Z JNMntt9Obvk53ONHsoX0YkAiLiV7xRQPf5rRhwvPzspJ5gRRlOVsnVHNwrsQHgXQYCWK UBgBjhFn7dnihYaHkQ8h+iQwUyX1p7oH2BwS5bGRC9J+JmJTClJZ/WNhwDvrNPAzRhqy jCGw== X-Gm-Message-State: AFqh2kqm26zwsjAP+Ab9RisOfryQ2lx1L4ewbfELpZ4j953ywLN77R8O NvqaJSzjBp1A5F/qtgKJBx0Pfoq/1wQro6OY X-Google-Smtp-Source: AMrXdXtczBbC4gOkuY8fyj8GLvFBw8u5fcJQAsmg8+Zk5BRzu9WEfhCZBLEomwBgIFoDCOwFTtz8lKRDNBukVY2M X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:aa7:9d11:0:b0:56b:676e:1815 with SMTP id k17-20020aa79d11000000b0056b676e1815mr1678776pfp.66.1672255482753; Wed, 28 Dec 2022 11:24:42 -0800 (PST) Date: Wed, 28 Dec 2022 19:24:34 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221228192438.2835203-1-vannapurve@google.com> Subject: [V4 PATCH 0/4] Execute hypercalls according to host cpu From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Confidential VMs(CVMs) need to execute hypercall instruction as per the CPU type. Normally KVM emulates the vmcall/vmmcall instruction by patching the guest code at runtime. Such a guest memory manipulation by KVM is not allowed with CVMs and is also undesirable in general. This series adds support of executing hypercall as per the host cpu type queried using cpuid instruction. CPU vendor type is stored early during selftest setup and guest setup to be reused later. Changes in v4: 1) Incoporated suggestions from Sean - * Added APIs to query host cpu type * Shared the host cpu type with guests to avoid querying the cpu type again * Modified kvm_hypercall to execute vmcall/vmmcall according to host cpu type. 2) Dropped the separate API for kvm_hypercall. v3: https://lore.kernel.org/lkml/20221222230458.3828342-1-vannapurve@google.com/ Vishal Annapurve (4): KVM: selftests: x86: use this_cpu_* helpers KVM: selftests: x86: Add variables to store cpu type KVM: sefltests: x86: Replace is_*cpu with is_host_*cpu KVM: selftests: x86: Invoke kvm hypercall as per host cpu .../selftests/kvm/include/x86_64/processor.h | 26 ++++++++++- .../selftests/kvm/lib/x86_64/processor.c | 44 ++++++++++--------- .../selftests/kvm/x86_64/fix_hypercall_test.c | 4 +- .../selftests/kvm/x86_64/mmio_warning_test.c | 2 +- .../kvm/x86_64/pmu_event_filter_test.c | 4 +- .../vmx_exception_with_invalid_guest_state.c | 2 +- 6 files changed, 54 insertions(+), 28 deletions(-) Reviewed-by: David Matlack