Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp914423rwl; Wed, 29 Mar 2023 10:01:23 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXo4GItt1f0igDJ+POeMg9EUIVy+oXro1XUyY5JmPFGjMj/Orp930NCGRbg/zSCBQMuHeM X-Received: by 2002:a05:6402:4c:b0:4c0:1120:a15d with SMTP id f12-20020a056402004c00b004c01120a15dmr18304572edu.5.1680109283012; Wed, 29 Mar 2023 10:01:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680109282; cv=none; d=google.com; s=arc-20160816; b=Bzo8KXa6TYXtw1D6rrJV0L2630vp4FwG4KIr3Zur/Hd7L7+Pn3kMd36cUFf/+iv3i/ MSCMxnWpYDHasPNaVVNnqLBc3XLAxXAICkYpQQyvNmBIuOxumjaTo8n73R1c19rgI25d qlL20Of5C3nUFPDpOh/pqkHQeFnTsQJVv8K1ebCAStK67LxtVC8uDiMNBJJvunRyUalN i9wzdZietm+r5AY19AH7Ipu9xcPNVkH7NVGsMiNL1R83wMA3ebeLYp2V+Becx4Iu7EPd /v9qJ0CgT56A3e2mXR8hH60GgQvWzP+0uF97jrPfZS4XgXGjlM+Kgn6rrWnJX7/0pi+w hGFg== 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=XhJ2KAFNUebvt6cQMDTLf5QYVLkhRGTjjjB4Lv8Q8Pw=; b=lUYcVcijeTcSWZdbBvmVqRHho7ornSrbWuusyAATxV91V8FbqmCK4Lbg92Lm47K/Ac cMz/+r3bYcaZU9ePtujS33EHK/4PMXnzDXNUodsaO6WZvcahsxOMUtllVjxaFkB5UPT0 t4WrmE4jeIpTO7f09fgWfX6aN/YyA4UdAOnglPoinJB7NKd2bPNWVqV2PHOcMU+LKRtU 5xQHOro27vB9bDOW7MkSdCUkI9lxITJtNdqCz3F0jAhuK3POcWFr5zqQKafk/1nufZFt YywRzRiWw/3jTPjalruYKW1IyefB44zeCxmEqrosUrcB9zbTzdJdYltjSEIu11xqov/J RFbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Nwnor0fu; 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 n20-20020a05640204d400b005021f0d1410si14674796edw.32.2023.03.29.10.00.56; Wed, 29 Mar 2023 10:01:22 -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=Nwnor0fu; 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 S230338AbjC2QrT (ORCPT + 99 others); Wed, 29 Mar 2023 12:47:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbjC2QrS (ORCPT ); Wed, 29 Mar 2023 12:47:18 -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 52A5C525E for ; Wed, 29 Mar 2023 09:47:17 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54574d6204aso160441337b3.15 for ; Wed, 29 Mar 2023 09:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680108436; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XhJ2KAFNUebvt6cQMDTLf5QYVLkhRGTjjjB4Lv8Q8Pw=; b=Nwnor0fuwBFL6HswHVDb9zq4uqB8N0vyANtOGoursE/xCXttz4V6jsoxjL4SKGjtcU vM08UOGTQy3ImsotSEpEn8ev+cnvKUAvL56SaS8B8FBrIaQIcJJDDjylIjDObxUSVj3m /QZ2b+8/qsofV6UllwSgZtticUjx9NgZ0p3PXNaUQQJNdVnoAIr1IyMyMkDLhy+jZkvd 3nt/k1QOxZXpVzmtl9BOim/yPZvH5Vvs4toGP76nX15+oc8clHEikoh1Mn2zLLjO+KnC Nb14v+ooTd2RMCQTcprG20lhhxICTFeqHyl2aaxr+1MLBrctSNDVouYcDHucWdrm7uP3 p9iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680108436; 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=XhJ2KAFNUebvt6cQMDTLf5QYVLkhRGTjjjB4Lv8Q8Pw=; b=doU2l7isxRMCV0207S5MptPNQlvU5/SQJe216KLKjBGiFQz8YVIfKzLCp5PFn269Vh gpRw7nxj7uQwJx0MOrut3BMSeY+JgSSMMsMFpk1fPB/Xh+mWk+98PxE+4uG0FxigyREx HT/55IXH0JzKvFZVmqjyJqg1oPxv/EqIYwqEF4Z1habfz0WHV/7F13dfq9EMa1CdXTIf 9sDGrGr9hxf00p3JcR/eDCIGeccu65gMoxUhkiwJmWeajd9H74gG40bEBy0hSwn6pwPt zlQzUr32VGVpKHwaw/zCtnQIiZmfQJXLpv+RETFnWp4CvvNfn9g1HlnWl5wSyn5elo/a LDXQ== X-Gm-Message-State: AAQBX9eIcCBMQM0UU+kXTV1O8A3Mhlae8mFQiBzDWD5x3bQShn+YqVH9 Y99ajbITL3janGBRJaMci2EUw5jOttE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:b94:b0:541:698b:7bdb with SMTP id ck20-20020a05690c0b9400b00541698b7bdbmr1769126ywb.2.1680108436600; Wed, 29 Mar 2023 09:47:16 -0700 (PDT) Date: Wed, 29 Mar 2023 09:47:15 -0700 In-Reply-To: <38601264-1957-579f-f156-c782bb9826cc@amd.com> Mime-Version: 1.0 References: <20230206060545.628502-1-manali.shukla@amd.com> <20230206060545.628502-3-manali.shukla@amd.com> <38601264-1957-579f-f156-c782bb9826cc@amd.com> Message-ID: Subject: Re: [RFC PATCH kernel 2/2] KVM: SEV: PreventHostIBS enablement for SEV-ES and SNP guest From: Sean Christopherson To: Manali Shukla Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, jolsa@kernel.org, namhyung@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, pbonzini@redhat.com, jpoimboe@kernel.org, pawan.kumar.gupta@linux.intel.com, babu.moger@amd.com, sandipan.das@amd.com, jmattson@google.com, thomas.lendacky@amd.com, nikunj@amd.com, ravi.bangoria@amd.com, eranian@google.com, irogers@google.com, kvm@vger.kernel.org, x86@kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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 On Wed, Mar 29, 2023, Manali Shukla wrote: > On 3/25/2023 1:25 AM, Sean Christopherson wrote: > > On Mon, Feb 06, 2023, Manali Shukla wrote: > >> - if (sev_es_guest(vcpu->kvm)) > >> + if (sev_es_guest(vcpu->kvm)) { > >> + bool ibs_fetch_active, ibs_op_active; > >> + u64 ibs_fetch_ctl, ibs_op_ctl; > >> + > >> + if (svm->prevent_hostibs_enabled) { > >> + /* > >> + * With PreventHostIBS enabled, IBS profiling cannot > >> + * be active when VMRUN is executed. Disable IBS before > >> + * executing VMRUN and, because of a race condition, > >> + * enable the PreventHostIBS window if IBS profiling was > >> + * active. > > > > And the race can't be fixed because...? > > Race can not be fixed because VALID and ENABLE bit for IBS_FETCH_CTL and IBS_OP_CTL > are contained in their same resepective MSRs. Due to this reason following scenario can > be generated: > Read IBS_FETCH_CTL (IbsFetchEn bit is 1 and IBSFetchVal bit is 0) > Write IBS_FETCH_CTL (IbsFetchEn is 0 now) > Imagine in between Read and Write, IBSFetchVal changes to 1. Write to IBS_FETCH_CTL will > clear the IBSFetchVal bit. When STGI is executed after VMEXIT, the NMI is taken and check for > valid mask will fail and generate Dazed and Confused NMI messages. > Please refer to cover letter for more details. I understand the race, I'm asking why this series doesn't fix the race. Effectively suppressing potentially unexpected NMIs because PreventHostIBS was enable is ugly. > >> + */ > >> + ibs_fetch_active = > >> + amd_disable_ibs_fetch(&ibs_fetch_ctl); > >> + ibs_op_active = > >> + amd_disable_ibs_op(&ibs_op_ctl); > >> + > >> + amd_prevent_hostibs_window(ibs_fetch_active || > >> + ibs_op_active); > >> + } > >> + > >> __svm_sev_es_vcpu_run(svm, spec_ctrl_intercepted); > >> - else > >> + > >> + if (svm->prevent_hostibs_enabled) { > >> + if (ibs_fetch_active) > >> + amd_restore_ibs_fetch(ibs_fetch_ctl); > >> + > >> + if (ibs_op_active) > >> + amd_restore_ibs_op(ibs_op_ctl); > > > > IIUC, this adds up to 2 RDMSRs and 4 WRMSRs to the VMRUN path. Blech. There's > > gotta be a better way to implement this. > > I will try to find a better way to implement this. > > > Like PeterZ said, this is basically > > exclude_guest. > > As I mentioned before, exclude_guest lets the profiler decide whether it wants to trace the guest > data or not, whereas PreventHostIBS lets the owner of the guest decide whether host can trace guest's > data or not. PreventHostIBS is purely an enforcement, it does not actually do anything to disable tracing of the guest. What PeterZ and I are complaining about is that instead of integrating this feature with exclude_guest, e.g. finding a way to make guest tracing mutually exclusive with KVM_RUN so that PreventHostIBS can be contexted switched according, this series instead backdoors into perf to forcefully disable tracing. In other words, please try to create a sane contract between userspace, perf, and KVM, e.g. disallow tracing a guest with PreventHostIBS at some level instead of silently toggling tracing around VMRUN.