Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp495792rdb; Thu, 1 Feb 2024 15:09:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2WooJc6vYbAShv9AozTVLdLR9Y6G8+8pTwbn/YsMNihqBzsM3Wc1QTfiTINpNDN/ieD+M X-Received: by 2002:a05:6358:88d:b0:178:c7a1:141a with SMTP id m13-20020a056358088d00b00178c7a1141amr2541947rwj.17.1706828973935; Thu, 01 Feb 2024 15:09:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706828973; cv=pass; d=google.com; s=arc-20160816; b=zGFxBuhHTH08UFta4NiZEzpsE2/8qVDjqE9qpg474rdgEJc3C60GC44hzRtDag1pkt vVgZZiXUT8Zn6C5jQTukJybtGXosoWecxFpUPIi06lwsTVt9FeEAevfFBqXBXEaJoGXZ gtKuVdCi0zRfWaa6lxvVyHH0st84lWTY+UWmTp4kBizWX0LZmfhqXYhLACSnYPBT/Od5 boktSlxUFqWwqZuGcU6VaMPMuQk3oBBMMQuNS0b9t3GboWa8xmhp1nnDTCNE340Sbg8v tI8k8FZuEDYtqMPLxr+8xYpzjXmFznXa6GZPdS8oNAlTAiMdCSv221R4XZZ5NlqsmCvb 4A9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=lIys8ywl8dUROimT8NQnX8daI13tCkTHScBncJRrjoE=; fh=a9uj6mayrbQ8EzTyioxQqLBaqdHmYtT18yAsnafY0iA=; b=kc+i1ebita7lnyxcJUulRGqfjDsUwZcL61J8maQ6Vde1PkIcintT1PMq/fZ9DQ/ByQ JTDU/xOr0OWeOBLqcAym13EJUFrD15m4/Bfleyt8/alax0Q9vxtG8mkyhC5gx86SpRmb CcXERd9XIgmNODSSC0eTuM8BmQxZtBJmt3i2evP+ALjLj6mydMFoATNgnca6fBmDX+Td Ds1lsvVUPRkavcUhhCXxQHgQVU2vgB5bGZJiegrQUi8YyqT0y7f/oKiozc7XKk4FSGoS hmEePe43WfMmVda97HHt0PMcEm+WI2qtyYcM77hklsTDvI+iFDsf+vVRKaDsxxaNHQGQ AgUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EF5SNwHX; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-48978-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48978-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCU8/QBfXQr6ZjCBQeC3xmVxcFwyyiJqDG3X2EuHeOfhiSRsX7Te7SuAwuI5NDw5HP5BUQHMuc+ShN7zRwb7u7j+1GmvUNwPryNgfFuffw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a127-20020a636685000000b005d8e1b8084dsi450782pgc.439.2024.02.01.15.09.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 15:09:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48978-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EF5SNwHX; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-48978-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48978-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 5DC8528A440 for ; Thu, 1 Feb 2024 23:09:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6027947F4D; Thu, 1 Feb 2024 23:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EF5SNwHX" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D384847A70 for ; Thu, 1 Feb 2024 23:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706828935; cv=none; b=pAX0IdVo0qXWPv8XFHYQRio6lndknCy1YfExRCMtBFW4R/nOp/nFE6BXD/ZXuT5TfE6GrBHv5ZVbm3kj6/kPX2/c7gsSFdIfKfBjfmIutBQW66U9AsO67BNDIi5thTAmE53k4bklxM2B77ls6TBV9JxBy8qCDrCpBBTKQ/10THE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706828935; c=relaxed/simple; bh=M9Rbd1TTFJHpw9s+5sNyKj1m810A0YRxxUYpqz9R2Yc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rY9M/AOMCuwakceisFuNUYdxl/JWnbmfRATUecWWkhDGyMHo/ayAJ4vW1OXwhdnyvTmLtpVqKPn4TOHOmxBTMd9WKrHfKC97ARGWlQvvNKSxDZDuSJveEBew77xyyYy4sBLG9zAM07aEI7DJfN6LDhJ33jrJsIGB0fKYm4mqt/c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EF5SNwHX; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706828932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lIys8ywl8dUROimT8NQnX8daI13tCkTHScBncJRrjoE=; b=EF5SNwHXsHyj8w1cUWJQfvQTEp+TAlszAGiastjRKxzAl/dozX6Tueab6QmH3w6f28kHLF ldnXXshx83lKZsAvuvkba2D6QgfZKR6sxZnYm5KCYIYMvR6aOAZ7z0MPtitQMOXjbmMeWt ZlhemX5A1/qP23gcYwLgi+cAQi4eTkQ= Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-PwPtt3Y3Mk6CdUwNrprPGA-1; Thu, 01 Feb 2024 18:08:49 -0500 X-MC-Unique: PwPtt3Y3Mk6CdUwNrprPGA-1 Received: by mail-ua1-f69.google.com with SMTP id a1e0cc1a2514c-7cef6c44e40so852687241.0 for ; Thu, 01 Feb 2024 15:08:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706828929; x=1707433729; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lIys8ywl8dUROimT8NQnX8daI13tCkTHScBncJRrjoE=; b=aBOC2jLlyPeMxe5lSf3TVMGLyAGQn+Bty9nVVWOhTcyH4Jk3wWUEOuh++3//PftTQ3 JgjF3PHZo00jTV6SKgt/0aOhV8NfIULNLaxGIC1HIz6EYK8F44qkyEetofi/TgK5FPrF /0bhX20d3HNbiQ5b92anRrx6+iVOfXymlqU02zJmS5mqdEgCEMccUfvdALK0ZM/cuSo8 /6pO2OR/IlKtZuBJUriYoETbug5BG7RV8U/0PNTHhSY4tyst/130UHUGnUHYqICO4j2r X10gS34ryBvGyS3VPk+xuD9N+10ZLZvOpAOVXaZn332mURlT8r7jI5Gz4FrAEHvlpxtj TKgA== X-Gm-Message-State: AOJu0Yx3hkx/RtjrCwcj9QBUQLdwt1ghfuhVkzBFq7y25qEsCHPO4hRb fALbFPkU1L1lJzYq4dBOg8VX5jM18ZrssD4q71eFxvWIUT6PpZBoSwzsbDZYyMGUPDrMYqiQiaH EI3qh2uXNdnBFkYzBjvutypiE1CGGTmUKGAf1qf/4TVKYf4bZI7GrqN3AEpJl5qVF7l5s1ijZet yPjCf5I4jHUfeObEgPxx7V+ytvuhPU2QmRxf29 X-Received: by 2002:a05:6102:3bc7:b0:46b:2aa2:a979 with SMTP id a7-20020a0561023bc700b0046b2aa2a979mr5287965vsv.20.1706828929145; Thu, 01 Feb 2024 15:08:49 -0800 (PST) X-Received: by 2002:a05:6102:3bc7:b0:46b:2aa2:a979 with SMTP id a7-20020a0561023bc700b0046b2aa2a979mr5287948vsv.20.1706828928875; Thu, 01 Feb 2024 15:08:48 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240131230902.1867092-1-pbonzini@redhat.com> <2b5e6d68-007e-48bd-be61-9a354be2ccbf@intel.com> In-Reply-To: <2b5e6d68-007e-48bd-be61-9a354be2ccbf@intel.com> From: Paolo Bonzini Date: Fri, 2 Feb 2024 00:08:36 +0100 Message-ID: Subject: Re: [PATCH v2 0/2] x86/cpu: fix invalid MTRR mask values for SEV or TME To: Dave Hansen Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Zixi Chen , Adam Dunlap , "Kirill A . Shutemov" , Xiaoyao Li , Kai Huang , Dave Hansen , Thomas Gleixner , Ingo Molnar , x86@kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 1, 2024 at 7:29=E2=80=AFPM Dave Hansen = wrote: > I really wanted get_cpu_address_sizes() to be the one and only spot > where c->x86_phys_bits is established. That way, we don't get a bunch > of code all of the place tweaking it and fighting for who "wins". > We're not there yet, but the approach in this patch moves it back in the > wrong direction because it permits the random tweaking of c->x86_phys_bit= s. I see your point; one of my earlier attempts added a ->c_detect_mem_encrypt() callback that basically amounted to either amd_detect_mem_encrypt() or detect_tme(). I bailed out of it mostly because these functions do more than adjusting phys_bits, and it seemed arbitrary to call them from get_cpu_address_sizes(). The two approaches share the idea of centralizing the computation of x86_phys_bits in get_cpu_address_sizes(). There is unfortunately an important hurdle for your patch, in that currently the BSP and AP flows are completely different. For the BSP the flow is ->c_early_init(), then get_cpu_address_sizes(), then again ->c_early_init() called by ->c_init(), then ->c_init(). For APs it is get_cpu_address_sizes(), then ->c_early_init() called by ->c_init(), then the rest of ->c_init(). And let's not even look at ->c_identify(). This difference is bad for your patch, because get_cpu_address_sizes() is called too early to see enc_phys_bits on APs. But it was also something that fbf6449f84bf didn't take into account, because it left behind the tentative initialization of x86_*_bits in identify_cpu(), while removing it from early_identify_cpu(). And TBH my first reaction after Kirill pointed me to fbf6449f84bf was to revert it. It's not like the code before was much less of a dumpster fire, but that commit made the BSP vs. AP mess even worse. But it fixed a real-world bug and it did remove most of the "first set then adjust" logic, at least for the BSP, so a revert wasn't on the table and patch 1 was what came out of it. I know that in general in Linux we prefer to fix things for good. Dancing one step behind and two ahead comes with the the risk that you only do the step behind. But in the end something like this patch 1 would have to be posted for stable branches (and Greg doesn't like one-off patches), and I am not even sure it's a step behind because it removes _some_ of the BSP vs. AP differences introduced by fbf6449f84bf. In a nutshell: I don't dislike the idea behind your patch, but the code is just not ready for it. I can look into cleaning up cpu/common.c though. I'm a natural procrastinator, it's my kind of thing to embark on a series of 30 patches to clean up 20 years old code... Paolo > Could we instead do something more like the (completely untested) > attached patch? > > BTW, I'm pretty sure the WARN_ON() in the patch won't actually work, but > it'd be nice to work toward a point when it does. >