Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp12282lqi; Wed, 6 Mar 2024 08:45:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVbGpEjEscXVD//R6cZqiIYAvCCqiK+ED04USMSz5abDFJMAUg3Xg3cLSzRmlaxC7/pxVTo/CItlL0UBYd/ziJnL9dMw6OMj1/KMkaVQA== X-Google-Smtp-Source: AGHT+IGmwDN8G6AKyPejN3GBFxSaLrN+UgGf5qHT/jGCz5xwFXJwRtITAvY1FkXHhnqK6GHgARh+ X-Received: by 2002:a17:903:191:b0:1dc:b989:9b96 with SMTP id z17-20020a170903019100b001dcb9899b96mr6703859plg.49.1709743530702; Wed, 06 Mar 2024 08:45:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709743530; cv=pass; d=google.com; s=arc-20160816; b=Nvgqf6iyYPwIW/vHZQryDvsq25QsRE2h0ih/dTXUFeTGCf7baxV6JvNqMrMmJVjomu BxGaF852PJQclGMLCSR7BMM+57HwSrnQswfEDzDrvjELxulNaTMtkz6POF5PmfPynTCz 7iJcR4ZoCUODaV/f8gub1gFRwJzgQxoilsKL/6HFXN172YZ2pELmg5N9vCAJu9MTp/0h Kccnm2HDmWbGrxmgFzcwvjvyxEOc5UnzJTDxnoMtNTFvwSHCGbNOk5NW4coLv/g9AMHN CZ6TFDomy3M2dXsnUTwq2YxA4XIgzg6wzJWAoINkThnZe9iEKMA96YD8laAdFZAbBNKK Sk+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=nIsCFmhpWTW8fxuoFcfHLz0Rx4rMwL+WRCdnBbQqrps=; fh=I5RWciIKGJS2dENgTVM42GnHGGnBBP4jX3JndZeznDA=; b=SlTmxV1wadGy5NT35kCCdu1dJqmfXJoNxjDEXB6XsAKEpu8TsfU2lYGcCdjB6+EQat 4JtGh2JlnR3j90ZQjDHwwwRAurC0BS97H3hSKCuXWcJ7muMXNsDIC7hxc6okzUVVPPcb NQf3CJdXj1i88YQw0xcuDIswbYzzNTlI+46FwwwR3XG/qBhDJCFCkRK3zJb5OXvms8N5 xs1tDvrU/3dJhpfZltKAQopHKskvNoJ6FxwPldNv38amAVHhBpqWfajYBRG2BnrYwsOV MPDh4RN37v0DD1PQxGt0vGTl8Rx9SsI2qiGcSptiLGZvznaHGVcD5VG7/daU07xfvONl M4/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oT3UjOFp; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94287-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94287-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ma7-20020a170903094700b001dd08159d19si6740116plb.50.2024.03.06.08.45.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 08:45:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94287-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oT3UjOFp; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94287-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94287-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5C55C2816D3 for ; Wed, 6 Mar 2024 16:45:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD110137935; Wed, 6 Mar 2024 16:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oT3UjOFp" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E8C81369B7 for ; Wed, 6 Mar 2024 16:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709743521; cv=none; b=Kl7LFafq0O7o4BfcogLnPapofy8TrQ3eV4cj+wZtSem9tyTfesaRMqnCIZLDxUrlFByPNq2KsW6di09rbGi2T+60RfPTMSO+hsHFfo5xZJTlKgIeYZHLFV4OSN5/ArH4amJyuLkqgah7nUlkQ50ED65l7NDcoj2gP97btow/Wjs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709743521; c=relaxed/simple; bh=4h2+ccgnnm7BOvBn+5jjhRD3CpCSaSxs1q/2EbjETd0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=K8xxO2oVcCl4SicAhB6AZ8XTawjzdBPYWwlGtm06rXPtkMcOcL10z8PwXIeOG3JzwV/bJsFDPTTA6epilZUBp0FphjF5z/qABt9YVJpnYtCigMVJMoLkX+5CjOUSpn7KF8IcmBa+eMsb+45Z+otttaHrahWjtAjfFH2vu9i43K0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oT3UjOFp; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-608d6ffc64eso15303127b3.0 for ; Wed, 06 Mar 2024 08:45:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709743519; x=1710348319; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nIsCFmhpWTW8fxuoFcfHLz0Rx4rMwL+WRCdnBbQqrps=; b=oT3UjOFpJPOUZ718+iKA8cKCe106L4rLrqikIiwuKEcJ35Erj9pNoN/puCfWnEnBUq wxSOJfE/5TkCceANj6AqO3W3/A0HbAkV+P4DLPnmfRa1/pBRy3qSoX9kXvznZFwktNZt 5rgkG/pUj7kDG/wRDQZ1n1CdG03YxNzTUXXzYfOvYNREqCMfSVVH3Hos24LWpeUy2mJl XuqEnWM6drDAIIuqPhB4/aWqSRMpxgQqIpVGpof/5GzOzAgFEg7df3MY6yUqkWnJBokh 6AKN8VPtMQz84hEIbBJlx9YJSEFb5MvG441FfmlAHjN8HpDRQ9vsdpiV3dewjnjUo0WY vJWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709743519; x=1710348319; 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=nIsCFmhpWTW8fxuoFcfHLz0Rx4rMwL+WRCdnBbQqrps=; b=USnrGkrC84QVlnnuEj76+iyCvVUT6FbgyPHSci2AUy6hO5GbUy9ZUl1G59rcI4IxPd /OV/QI2j+v8SAPR1vIizR8+kHBRSTaydvD0YBj+KxjnuOi8/Ng/ZeMueaRcxlpvWFPWb ixNt9a8JIg6A/DgolDxlEkBfp4wo+wpvjh01uVFCQYKzJuHSyNeTcQUTGTddOY62tGFU 3adXMuQCmaQ1CtYikRX76gu31ZmdQx6A0M5mN7fKRzSYqcv4rm6Bq8D3kQedpXx8MAtE 24gXNLtmvVWMk98V8ZlA+IEuOcebg3oTACE+YDdIJ7jcDL/sjQdAHntiHBvEGee2+bcA JnYA== X-Forwarded-Encrypted: i=1; AJvYcCXH9cYRs7+3S4lXz3vJLuevIP7ND+/o0oWxyVhk1tN186DbOaAm9SWoC2yiCAXcHFu2EHZFC71vNwJoTO6jLw6cgV4wd59O71+dHOE1 X-Gm-Message-State: AOJu0YwPsCaiCehXMeS6EzveCC49lBzgiazLl+TsV0pr58BwXtacrLkS ulANQVu8JPARwf4SBLqd164tH1bU2O+Zw2yVH+VawiuPsZ7YwWH1+KbtWCFeQupOgrM6CeFOJUT gXA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:d104:0:b0:609:82e7:c0b with SMTP id w4-20020a81d104000000b0060982e70c0bmr1162866ywi.3.1709743519455; Wed, 06 Mar 2024 08:45:19 -0800 (PST) Date: Wed, 6 Mar 2024 08:45:17 -0800 In-Reply-To: <76744e4b-361d-43ae-9a52-6a410ed57303@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <1880816055.4545532.1709260250219.JavaMail.zimbra@sjtu.edu.cn> <76744e4b-361d-43ae-9a52-6a410ed57303@amd.com> Message-ID: Subject: Re: [PATCH] KVM:SVM: Flush cache only on CPUs running SEV guest From: Sean Christopherson To: Tom Lendacky Cc: Zheyun Shen , pbonzini@redhat.com, tglx@linutronix.de, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Wed, Mar 06, 2024, Tom Lendacky wrote: > On 3/5/24 18:19, Sean Christopherson wrote: > > On Tue, Mar 05, 2024, Tom Lendacky wrote: > > > On 3/4/24 11:55, Sean Christopherson wrote: > > > > +Tom > > > > > > > > "KVM: SVM:" for the shortlog scope. > > > > > > > > On Fri, Mar 01, 2024, Zheyun Shen wrote: > > > > > On AMD CPUs without ensuring cache consistency, each memory page reclamation in > > > > > an SEV guest triggers a call to wbinvd_on_all_cpus, thereby affecting the > > > > > performance of other programs on the host. > > > > > > > > > > Typically, an AMD server may have 128 cores or more, while the SEV guest might only > > > > > utilize 8 of these cores. Meanwhile, host can use qemu-affinity to bind these 8 vCPUs > > > > > to specific physical CPUs. > > > > > > > > > > Therefore, keeping a record of the physical core numbers each time a vCPU runs > > > > > can help avoid flushing the cache for all CPUs every time. > > > > > > > > This needs an unequivocal statement from AMD that flushing caches only on CPUs > > > > that do VMRUN is sufficient. That sounds like it should be obviously correct, > > > > as I don't see how else a cache line can be dirtied for the encrypted PA, but > > > > this entire non-coherent caches mess makes me more than a bit paranoid. > > > > > > As long as the wbinvd_on_all_cpus() related to the ASID flushing isn't > > > changed, this should be ok. And the code currently flushes the source pages > > > when doing LAUNCH_UPDATE commands and adding encrypted regions, so should be > > > good there. > > > > Nice, thanks! > > > > > Would it make sense to make this configurable, with the current behavior the > > > default, until testing looks good for a while? > > > > I don't hate the idea, but I'm inclined to hit the "I'm feeling lucky" button. > > I would rather we put in effort to all but guarantee we can do a clean revert in > > the future, at which point a kill switch doesn't add all that much value. E.g. > > it would allow for a non-disruptive fix, and maybe a slightly faster confirmation > > of a bug, but that's about it. > > > > And since the fallout from this would be host data corruption, _not_ rebooting > > hosts that may have been corrupted is probably a bad idea, i.e. the whole > > non-disruptive fix benefit is quite dubious. > > > > The other issue is that it'd be extremely difficult to know when we could/should > > remove the kill switch. It might be months or even years before anyone starts > > running high volume of SEV/SEV-ES VMs with this optimization. > > I can run the next version of the patch through our CI and see if it > uncovers anything. I just worry about corner cases... but then that's just > me. Heh, it's definitely not just you, this scares me more than a bit. Doh, I realize I misread your suggestion (several times). You're suggesting we make this opt-in. Hmm, that's definitely more valuable than a kill switch, though it has the same problem of us having no idea when it's safe to enable by default. And I'm not sure I like the idea of having a knob that basically says, "we think this works, but we're too scared to enable it by default, so _you_ should totally enable it and let us know if we've corrupted your data" :-)