Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2339990rdb; Tue, 3 Oct 2023 19:45:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGodVhN3Fh85nOLu6z4m2g8/TRGSsX5uXa/hLiEaD1IkNa82yKTiDddGZflGy6gPsCiiFwy X-Received: by 2002:a05:6808:4349:b0:3ad:f8a7:1485 with SMTP id dx9-20020a056808434900b003adf8a71485mr1099982oib.18.1696387534117; Tue, 03 Oct 2023 19:45:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696387534; cv=none; d=google.com; s=arc-20160816; b=o5rSzIrRnqCtLejQjj4r8zzK4IYLac5zddq53r1FX3D4/pLugUZ3BLlxNh5/yRyCqR zatxTVlAu+6BR5ruC6OGwqVq62yxq/ZH5ULlWYYJA/wO64ijbX90RyNx1ihS4O/W2HVu Md5ZMRTSeLc0tMuxH8xmqdQe48NAke0AT8XNIt4miJ0ogTaz/euZw0Ru8QsIKLUFOs0D wfoD2DSrURxV4Uvj6XZ845HxVUN4/NzSI4cshljwJ+/ncyOgcnJL2ci12LXsvip9BB+5 cfzAXpUkL5Qc9hEnOX6UeLDHOG3rmnBOvVHBl+kGlIv+hZTJCibmWMziGbOILDvD7PmV nfRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EeV5iV69+//+fPJFnagr3baxBb3XJLwL61SwLH3HuUo=; fh=uPfchtQtwAxsBaJq0H6OQn3OFqA+FzTOodupkROZei8=; b=Yagwax3eN0PsBGv8f/Tuvfb5ILkdB/PHUSA4+KvxJwZZ4c0B1Q2SPZrFwSKjiB/QIX vuzsb4ZRGLYU3g9rtsgM11gg+HX4qfeEmRZB3EDWPzNP4PyC5SVYekH9PVFbR/grmORB 0QCyu6fyORUjics7yOvmLxM8mOVJ5iXq9fZV4NIcSICJ4aPOOKAnzoYicsvyqKKOBH60 2GRCuMph6d+5orcc39dD+fRV0XjOjTmtZhn+htyVTEkRcE02s5p9EOV5qu35Z3inSI99 I71ziVLoQS5LUhkd0rwC7am1F2Rf7/AIPOgefTEKWDb6wvloDH6Dv60wml4VMlEp6IHW aA2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yFOa6ti3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id z2-20020a63e102000000b005854ee6b62asi2869711pgh.543.2023.10.03.19.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 19:45:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yFOa6ti3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 51E548050916; Tue, 3 Oct 2023 19:45:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232579AbjJDCpM (ORCPT + 99 others); Tue, 3 Oct 2023 22:45:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbjJDCpL (ORCPT ); Tue, 3 Oct 2023 22:45:11 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C58AD for ; Tue, 3 Oct 2023 19:45:08 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-405459d9a96so47235e9.0 for ; Tue, 03 Oct 2023 19:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696387506; x=1696992306; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EeV5iV69+//+fPJFnagr3baxBb3XJLwL61SwLH3HuUo=; b=yFOa6ti39dPLEQVxB/3QhAWjBNiOEry04+AkFfNevvBGCWBBP+uPlBY5xP9CLjesdk lozgt4CDrf/SwsQfVd/EHWu3eoO0Dv7qRujv5od2aFW3YNbFXeD/v7691QJFxtBNH13Z fsy3PPMuDg6LgfmZ+B9I5vP40QH/WiELaW/ubxyQCJRxD/gQ3Cp5wZOkVZ67wS2+JBYj YY5cEjgRza7QJ9WYSpMmBnGznDP12gZpmR9cjv8EPQv+3hqYniky2aRhYil6GM817hSh oidbWVGSOWr7YRfVSAxu2zFF5T0JoU0GlMwZTsUm4+44zo3LLe+MNgv6jEMgu54eenjp Vrxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696387506; x=1696992306; 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=EeV5iV69+//+fPJFnagr3baxBb3XJLwL61SwLH3HuUo=; b=Kb7vHXvaRZN7wp9NtMJ1EYg0pcxUqFN4K9aea9jn2enpOhwW3dqo5PhZEmhtL6H18r d+sE/KD1KWSmuPXWu4vrZvGmWa5b9Be3Ll0yqdZRIeASHyc6SO8m1CA9ouAIJ9JGNKQH nQLo6Ewa4UFWq3nzMe1pnkPESmBZxqNgzVkT5j/zlqgH8jNLLriEE81K2GDs9rqMv4AK pjTSlv6MVteVhbpc4rpGPARCwe/yD8NmPP+LaX1shepDf2MqMxix/LvzRbagkmuM6mFx Sm8EVufGQ7tQkNK9wMppyURdchYkPJ7cE41MnxCqEhWdkGr8yl3JhwRoSr+P0TFKj6z7 3Zkw== X-Gm-Message-State: AOJu0YwNt5KyR1BMxU6McY/6ofTeO52aWpdSe9pLbrZ8bU3TEluHU3kZ 0TT+5fVX/+zm0VvMU8LcvRY19x0Oo4jTDr+B3vg5FQ== X-Received: by 2002:a05:600c:1c89:b0:404:74f8:f47c with SMTP id k9-20020a05600c1c8900b0040474f8f47cmr32277wms.5.1696387506513; Tue, 03 Oct 2023 19:45:06 -0700 (PDT) MIME-Version: 1.0 References: <20231004002038.907778-1-jmattson@google.com> <01009a2a-929e-ce16-6f44-1d314e6bcba5@intel.com> In-Reply-To: <01009a2a-929e-ce16-6f44-1d314e6bcba5@intel.com> From: Jim Mattson Date: Tue, 3 Oct 2023 19:44:51 -0700 Message-ID: Subject: Re: [PATCH] x86: KVM: Add feature flag for AMD's FsGsKernelGsBaseNonSerializing To: Dave Hansen Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Pawan Gupta , Jiaxi Chen , Kim Phillips , Paolo Bonzini , Sean Christopherson , "H. Peter Anvin" , x86@kernel.org, Dave Hansen , Borislav Petkov , Ingo Molnar , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 03 Oct 2023 19:45:31 -0700 (PDT) On Tue, Oct 3, 2023 at 5:57=E2=80=AFPM Dave Hansen = wrote: > > On 10/3/23 17:20, Jim Mattson wrote: > > Define an X86_FEATURE_* flag for > > CPUID.80000021H:EAX.FsGsKernelGsBaseNonSerializing[bit 1], and > > advertise the feature to userspace via KVM_GET_SUPPORTED_CPUID. > ... > > +#define X86_FEATURE_BASES_NON_SERIAL (20*32+ 1) /* "" FSBASE, GSBASE, = and KERNELGSBASE are non-serializing */ > > This is failing to differentiate two *VERY* different things. > > FSBASE, GSBASE, and KERNELGSBASE themselves are registers. They have > *NOTHING* to do with serialization. WRFSBASE, for instance is not > serializing. Reading (with RDMSR) or using any of those three registers > is not serializing. > > The *ONLY* thing that relates them to serialization is the WRMSR > instruction which itself is (mostly) architecturally serializing and the > fact that WRMSR has historically been the main way to write those three > registers. > > The AMD docs call this out, which helps. But the changelog, comments > and probably the feature naming need some work. You're right; I was overly terse. I'll elucidate in v2. > Why does this matter, btw? Why do guests need this bit passed through? The business of declaring breaking changes to the architectural specification in a CPUID bit has never made much sense to me. Legacy software that depends on the original architectural specification isn't going to query the CPUID bit, because the CPUID bit didn't exist when it was written. New software probably isn't going to query the CPUID bit, either, because it has to have an implementation that works on newer processors regardless. Why, then, would a developer bother to provide an implementation that only works on older processors *and* the code to select an implementation based on a CPUID bit? Take, for example, CPUID.(EAX=3D7,ECX=3D0):EBX[bit 13], which, IIRC, was the first CPUID bit of the "Ha ha; we're changing the architectural specification" category. When Intel introduced this new behavior in Haswell, they broke WIN87EM.DLL in Windows XP (see https://communities.vmware.com/t5/Legacy-User-Blogs/General-Protection-Faul= t-in-module-WIN87EM-DLL-at-0001-02C6/ta-p/2770422). I know of at least three software packages commonly running in VMs that were broken as a result. The CPUID bit didn't solve any problems, and I doubt that any software queries that bit today. As a hypervisor developer, however, it's not up to me to make value judgments on individual CPUID bits. If a bit indicates an innate characteristic of the hardware, it should be passed through. No one is likely to query CPUID.80000021H.EAX[bit 21] today, but if someone does query the bit in the future, they can reasonably expect that WRMSR({FS,GS,KERNELGS}_BASE) is a serializing operation whenever this bit is clear. Therefore, any hypervisor that doesn't pass the bit through is broken. Sadly, this also means that for a heterogenous migration pool, the hypervisor must set this bit in the guest CPUID if it is set on any host in the pool. Yes, that means that the legacy behavior may sometimes be present in a VM that enumerates the CPUID bit, but that's the best we can do. I'm a little surprised at the pushback, TBH. Are you implying that there is some advantage to *not* passing this bit through?