Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1237784rdb; Fri, 16 Feb 2024 09:11:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRl5Ei01fNdIw2CSO+nYWpVV3dC7amVo2VfRTSFy2Jqh4XVJE+pWo7NTrY5KAKaEB0Z3J3XWILTy/OJ0N4HAIzwF/Ufj8bze35wtcmrQ== X-Google-Smtp-Source: AGHT+IH9kslpd0REpKvAo99lHDL0hLq9kPg84NVp7xgKz7X8llcdTRXRbwCfwd8eyeTa6dXDLKKU X-Received: by 2002:a05:6102:304a:b0:46c:f77e:6f28 with SMTP id w10-20020a056102304a00b0046cf77e6f28mr8299786vsa.0.1708103485408; Fri, 16 Feb 2024 09:11:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708103485; cv=pass; d=google.com; s=arc-20160816; b=cFJ/OAUc3kBiGjs4jyRHpyvKUnSc8H5rdXmqJFRbiDLTUU9xBEoFRgEXM6P9I5MYep L+vuNmigEKIPsLSm/l+BtKyqAJr8iSYdOSoU1Pw6S/DNgFRgVyLa3EUKbeNvzZ2EGToJ +4XE0lCD5wH0B1SW90nYjAqKaChQrX8nN1jaNuno0R7fKuvIKhJ5T6WGOqjJ84z0AbfL bAjzCbjjtnssmC8UI3YYFbhHhrTzEz7Nma9TZcHorRvA6WiELLTW5HC6YtMbgT1fpss+ NejraZV2kA90SPZxGm1UhsK4mOmklG/bSdvl0ruGD1hvYPeHlo5vC9k9KALYfbj3KS4K dBXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=oPLoHMDsqQNJdlKAI9HnWogN2mbo4uQRJ1gPPP9G92g=; fh=GTGQO3EiodyjBpEOcC/wE0S+Itj6BSlRxJrfbXgwsQg=; b=UEmy9+5lWpr8VASxbIREYYjPW4Telp2T3Gh4Kgfvhnk0TUyHmqX0fIAdbLWDgCj9fC 1q1lIWJPDx2Wep0qYGriWTUbp+6ryqUyEJkK2Z9467CwlzmOe9tPoC+uOfXTzEL8yyBy 8Rto7r9Pizw3IfCREmRNi4onSPZQwYKoA8DYZ+Gl4E4nsqMMjPnCqaPX3K/PTPDdPoHm gDOmz3xDoo+9D85uFUc9G8yYkLqiFxVuv3c3anYOG85XHYVDanTiPUX5JQu/pzFG4eBl uOIooCEqEJWJ2qRY+4YsctKCSfi2ynKXEsItXTnySZ2uujWmqkiyhS2he0bzVWfXsocF BtaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=h957QmJD; 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-69037-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69037-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g6-20020a0561020cc600b0046d614e5534si85065vst.447.2024.02.16.09.11.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 09:11:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69037-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=h957QmJD; 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-69037-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69037-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1DE3E1C216DF for ; Fri, 16 Feb 2024 17:11:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A88F133293; Fri, 16 Feb 2024 17:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h957QmJD" Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 18903132C1E for ; Fri, 16 Feb 2024 17:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708103450; cv=none; b=TBJRYnKuSNcdLC65UzEzbP2/0b/VgCIq5c+8wNumr3xL/Yz6QYrZx5Wtu7BKgfNLJPLgDkv1mzLDb5a42kJd5rYfcpAt1dnJlVbqKPL+CG14tX38X7KpX0rvymn0oAylapX9E8kXKJZr2Sk1NTE+arPB52RgBznN70D5Op6PaS4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708103450; c=relaxed/simple; bh=pgTDiq6ve8t51vcCTkPcdbVxXT7PbEdlzjJcC+OUwC8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pEdkEr8KtL9+U7r8NbL71DgBF1S+yAWrJrWrv+pviOKovUO7Gw1b/VSbEnIS9nE4sykbrW6lbUQsJRkMU/4Wys2agYJKels7jaGWkUXqheQ+Tgl50KKMi/9LN5BlvKEPJGQ7HV/xcvgqEY/wdzPdSAhfUnFXXYVA3+KZ1Ofqujc= 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=h957QmJD; arc=none smtp.client-ip=209.85.215.201 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-pg1-f201.google.com with SMTP id 41be03b00d2f7-5c65e666609so1087040a12.1 for ; Fri, 16 Feb 2024 09:10:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708103448; x=1708708248; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=oPLoHMDsqQNJdlKAI9HnWogN2mbo4uQRJ1gPPP9G92g=; b=h957QmJDQTstbymkqM9WcFdkbUdswfszidOrgHRgwnZJzDHt2keBGq59Fi3TSryCu/ ZJWgvnNQlR7OSEybFxMGpaAINEJGf15n0g0BOJkJEkm0ifUVRh09EohfGkvZInTryJrG 0E1Yfr7IOGoXCuCYSghBXSEP9GpUkEd93aRGSbl5zY+hQzHAs9xj1AKR5En5AiFNFPD1 2IXKpde8H0HCatbVGxdyjthDusQDcT+xGx34mHTez5+kxrlqp3R/FVvoOxknfkV9BpLL b0rcyJWqdu/JvIy7SHOK9IzINzMxfegBRga5S82Rrwemvw3Bfy4Ky5B7UaWoTE67imXC zvBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708103448; x=1708708248; h=content-transfer-encoding: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=oPLoHMDsqQNJdlKAI9HnWogN2mbo4uQRJ1gPPP9G92g=; b=j2FlGtommPbXeZ83oRyi52xiorhn3W3DR9QJ6B8NkiJMLhzIOKW6DUgwPX023i4QSA lg/8LVLf9k6uAHPdrph0bANsbb08i3nKe2BScv6A3LGu4ZzleoIZrfgPc6P6U5e8FEsD OV5K6ijA+sFjBgVDIR7WS5z6oWVo3JeHYmVnkL+PVnnJsvTPtNLdclLI7gr387IfwnYg jMWC4c9uy9dTWexQT4IcpiMTzMdg3dtlBNnVrXtNVN0T3m8hiWnUS9q7iWs8JCONyEDd QboHmeAHwCBfjsJqWQF8aAHtGy/LeiZSU3skxgL3jIv6ZaAHxvYe9L7gSo756zSkbJ9B H7CQ== X-Forwarded-Encrypted: i=1; AJvYcCU9B99OVgVheOEr0jD7IXmGP/1HIAeZzh2KAUe2YOZuVNsRqOxcN9raob+SzJ88n2ReGfGc987qYEMQ+M64axKWsT9WpN5IrRD9YxAx X-Gm-Message-State: AOJu0YyVic32KZr0VerjBUBv0MlZQZK7xZPxP9DojZQc92jTFFFnkICB i0b4M0cw1HzWrxgwQOl47qR7AC1+7j9PJ1SOBkzjhVWlPucrlcCvFTk7UzJZpAaDFi+OFDNliCJ ugw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:6d0d:0:b0:5cd:9ea4:c99 with SMTP id bf13-20020a656d0d000000b005cd9ea40c99mr64720pgb.6.1708103448433; Fri, 16 Feb 2024 09:10:48 -0800 (PST) Date: Fri, 16 Feb 2024 09:10:47 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240215010004.1456078-1-seanjc@google.com> <20240215010004.1456078-2-seanjc@google.com> Message-ID: Subject: Re: [PATCH 1/2] KVM: x86: Mark target gfn of emulated atomic instruction as dirty From: Sean Christopherson To: David Matlack Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Pasha Tatashin , Michael Krebs Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 15, 2024, Sean Christopherson wrote: > On Thu, Feb 15, 2024, David Matlack wrote: > > On Wed, Feb 14, 2024 at 5:00=E2=80=AFPM Sean Christopherson wrote: > > > > > > When emulating an atomic access on behalf of the guest, mark the targ= et > > > gfn dirty if the CMPXCHG by KVM is attempted and doesn't fault. This > > > fixes a bug where KVM effectively corrupts guest memory during live > > > migration by writing to guest memory without informing userspace that= the > > > page is dirty. > > > > > > Marking the page dirty got unintentionally dropped when KVM's emulate= d > > > CMPXCHG was converted to do a user access. Before that, KVM explicit= ly > > > mapped the guest page into kernel memory, and marked the page dirty d= uring > > > the unmap phase. > > > > > > Mark the page dirty even if the CMPXCHG fails, as the old data is wri= tten > > > back on failure, i.e. the page is still written. The value written i= s > > > guaranteed to be the same because the operation is atomic, but KVM's = ABI > > > is that all writes are dirty logged regardless of the value written. = And > > > more importantly, that's what KVM did before the buggy commit. > > > > > > Huge kudos to the folks on the Cc list (and many others), who did all= the > > > actual work of triaging and debugging. > > > > > > Fixes: 1c2361f667f3 ("KVM: x86: Use __try_cmpxchg_user() to emulate a= tomic accesses") > >=20 > > I'm only half serious but... Should we just revert this commit? >=20 > No. David, any objection to this patch? I'd like to get this on its way to Pao= lo asap, but also want to make sure we all agree this is the right solution be= fore doing so.