Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4842654rdb; Fri, 15 Sep 2023 14:10:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyI3xrRAIfgPuJJgdVr5Mkr8CA4S+8SbqSYhaCPkfbuQcB1Jpeq0EaBgYUDLlKr14GXROl X-Received: by 2002:a17:902:be08:b0:1c3:94a4:34bd with SMTP id r8-20020a170902be0800b001c394a434bdmr2500158pls.40.1694812217839; Fri, 15 Sep 2023 14:10:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694812217; cv=pass; d=google.com; s=arc-20160816; b=iqo4BAykqq1g3U0AXViAdbnN4Q3n0jExmedAVPfoq/37fWIlY0vXXlRNGMwrs/fMV0 Rpyp9Rblq0wrX/JNxMWlQL2LMfpVy2RHC1cMbMDLPHz/FKjTQxfLoItziJTHRhH9F8E7 SONuxgo1sWMaGz/1ZuOain2/pxolcmyNvKzaHn9Zxob69z2bJoE56ncX59QNfUNKyYhQ /X/PoFeXxxqludMIatwVYfeB5sRsJ2DvTNNjnr1ohC18snkvyTaEb+poS5bXRx/0ZLfI yFmusxhtoOaLLLMrVy8pQpNWJCh0pYj8TahGDgOAS48GiBUMlA6BCCKA2j6XRPDg7Hl8 pUhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=/u7Y9N/tJ6VhIiKADc2PcXlWfNVnVpsC/Jd2c+go5iA=; fh=+m+7WRVZTvuO0jiBL2LFLYNr1CKgIDdFdkEi9mliCBE=; b=OpZW8RQ8EcI+tbuPb1VXZUEa4rnVjQLQUIGxS2ZqGcHnhQ97ZakK87E3KqoNmgdcBJ Vp+rpwheU6OMRUqD1sw6au21xa8Qju/6Q8JiLljl0LDYCake2wQJI0gy80YcMc1VQklw hzgNDUP7/nSbQ5TB9aX85oU6VfMkFNDN9tm933npbUO2PUPmFycpWgRbFssP36iXSMZW 3TN7oO3wSn21MKN7cHbksA1nVBWMurQvQcTXxx2lfXZZZmFKKmr4TZJ5hUuHVRNUOOiG Vx/3CEMpTDu7hpf9ELGhKNMLvcfs/+SWLMvs/gOKp9A9Ya3Codj6FjuHNfjzbeeb7OiH w53A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=hHr2Txcu; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id a12-20020a170902eccc00b001b39e50bfdasi4084909plh.638.2023.09.15.14.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 14:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=hHr2Txcu; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id AAED683B361C; Fri, 15 Sep 2023 13:58:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237786AbjIOU6M (ORCPT + 99 others); Fri, 15 Sep 2023 16:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237697AbjIOU5i (ORCPT ); Fri, 15 Sep 2023 16:57:38 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2086.outbound.protection.outlook.com [40.107.92.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21A6430FE; Fri, 15 Sep 2023 13:54:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CycNLcmMX4RoVr2Oyxpf1YkA8uZIZW7tZ0JJYaVm0v4a6izWGLUnkN4PcaVrvgsiQsC5tXEpBbSxoDzIdAelK5ZiTqLjSZS5cXOtyST8Ij6nQelU0P0YvMSDIT6t6GMxXi0VBmZBRzpWoX6IFBkKGA7Pegf/spfY1vs3wqPxcZ4AuZhMm6E1Cvh936uegz8KKVtQ21ko4WVeZLNMdjGX8PgNNbAOpzwEtid3yCpaA5IOAITIoc42+xkmc6PoJjINwSngumiw0VEDj16v5+9Ase4OyMR2uQR+x5KiT8MF+3u4fry8+w5qvk8vLeYOgUB1zdUZbk/+OGoMFLFMTLXVDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/u7Y9N/tJ6VhIiKADc2PcXlWfNVnVpsC/Jd2c+go5iA=; b=lecuBsw2x5tEM8LBVME/HDS31zADhibkS0W8Svb04DTuAkJQ6IVXkuQlLXsaqOrOWJEqe/A057lZBbQemJui0kPrHGlZR+cEU742MLwxuCeCkGaJFWkGVnTcwx4McH/ex6avE77FEnW3kxkttyQ4zbKBAmcaVokd8mLT4+bCsya2fNcwkOCN4a8JwwwGbKWHiXVbwYiA93Dk+iLqW5Z8dwbZjG49sekwywjF3YRTkeLfsKRK2bK6M3f044IwhXCHFaIChnlriGz/SwlUIQTW5qH6poCVJ6RXo8dpfsbUeczx5KAwCOS4QNJHVOjapIFJcbhiiWt+158j5yBwV0ZtNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/u7Y9N/tJ6VhIiKADc2PcXlWfNVnVpsC/Jd2c+go5iA=; b=hHr2Txcu4MfwKyBK3hhpoU9KuvwrIa/qdT4Qv7mHCQU6nW0IRmCDzR+BQxFN24OtiX4uUtvIK9XdsjmbJPBMe4ZpxkTbunJumH2gRAo74u5olQTerjcJfck5a+iebWlnsDTSvdlPtYjRgBHs6fvQm5d2VZ9jQ6q/2SLB6djCrr4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by MW4PR12MB7117.namprd12.prod.outlook.com (2603:10b6:303:221::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20; Fri, 15 Sep 2023 20:54:13 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::d267:7b8b:844f:8bcd]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::d267:7b8b:844f:8bcd%7]) with mapi id 15.20.6792.021; Fri, 15 Sep 2023 20:54:12 +0000 Message-ID: Date: Fri, 15 Sep 2023 15:54:09 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH 1/2] KVM: SVM: Fix TSC_AUX virtualization setup Content-Language: en-US To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , Babu Moger References: <8a5c1d2637475c7fb9657cdd6cb0e86f2bb3bab6.1694721045.git.thomas.lendacky@amd.com> <8b047dad-84ac-69f9-3875-38bca92d7534@amd.com> From: Tom Lendacky In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SN6PR2101CA0009.namprd21.prod.outlook.com (2603:10b6:805:106::19) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|MW4PR12MB7117:EE_ X-MS-Office365-Filtering-Correlation-Id: 53ca3ee6-e0ac-42e9-46e8-08dbb62dea64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rMMT9KrXusDXJrhSpoGLfeEVMTmHQntl5obsnajcyTwaFI9osH2P8kVKfuXdcCiwMUO305JGRw7OSNGWViZebHi1NUWqobniagBfegHj/Si2lTmuNEeEe9bSc4WnU8htU6nJ+BtWklGIQvppvLluzgQXIuez/dPlJw3v2ZwOogbEVHJK6UGlsXBQFQZFGUAh9Ig9zkrkJEcOWGHb1HWauvH0eMetAnwKpqtQZkR6/juGYQfNQ2PXZcKP/2vpPL8uoH+9W5gqK+EmDQZ+SJL9L92jJaBWSNl0sA8VMwwenPmDduXMZtIPD3cl36TWIWtSPCrKzvswp0p4EjpYSnul9MqNk3vQt5lgZf4Jew6jkdNbIIu0J/19+s1D2Vr4JBqUKWu/AzKSl31hom3UtFLX9QImLwuH/7vCc4V7sUIeuBaW+6hdaUm4dwczeoDyR2ZowjAs32mx3mnhUJD2t8ePw0qGPP8tnEO3zsct9xU36LAY89vu1TyCvp1O8aO0NHaGrtyi6jp9/orlwt5HDFlTmErMusppyFk1r3jYO0FuUK7g8BWS4RlVsVUgZLiKUhKZE3sfB47cp24rBEMvBMZbNLfgNieCOGnmraa4PoH1BQVlS9IuYqpUzuMkr/ZG1OeyKrxenEh1hlAeZzZ0fqiU2A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(366004)(136003)(376002)(396003)(39860400002)(186009)(451199024)(1800799009)(2616005)(26005)(478600001)(38100700002)(6512007)(66899024)(6666004)(53546011)(6506007)(6486002)(4326008)(8676002)(8936002)(5660300002)(41300700001)(66476007)(66946007)(66556008)(36756003)(6916009)(86362001)(31696002)(316002)(2906002)(83380400001)(54906003)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MFhkYURiem04dnFTU2IvQzNEc0Y2OXBnRGxxSlpEZWdoRGlwcTE0N2hiSk1x?= =?utf-8?B?T3FPTGJhcXNWc1VuQ3pDTDY3b25ZU09BRlROMHh3Vi9SOFBzS0pIM1pMTXps?= =?utf-8?B?TVArYTdUd1JERkxuYTY5bzhJcXplc0tIell1TnNtZmMvNGI2N3R3M3pUTUVr?= =?utf-8?B?dGZzZXV6VTQzR0RVVmtTbVBQbjJ4K2Z2T1QwcmREMWlCT2tkenJlZzZidlZ3?= =?utf-8?B?RFI2WTM2bGU3eHc0c3JZTThMYWRXNDBvQ1NJS09ZMitpNWVoRVBLNTBHNVFv?= =?utf-8?B?emdUTmZ6M3dtM2FETEFPbHUyMHJvYUlLcURnYlZZdG0zTjZNajJV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JHwlLLF1p?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53ca3ee6-e0ac-42e9-46e8-08dbb62dea64 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 20:54:12.7061 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xmoOET4q5ruGyt1FYNUWYgFTLinU1eCe37LL/FDkNjXc7MoFFvrWGlr1qULGq/EZ7flWQGoS63YNBH/P/CWmcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7117 X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 15 Sep 2023 13:58:37 -0700 (PDT) On 9/15/23 12:32, Sean Christopherson wrote: > On Fri, Sep 15, 2023, Tom Lendacky wrote: >> On 9/14/23 15:48, Tom Lendacky wrote: >>> On 9/14/23 15:28, Sean Christopherson wrote: >>>> On Thu, Sep 14, 2023, Tom Lendacky wrote: >> >>> >>>> >>>>> +        if (guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) >>>>> +            svm_clr_intercept(svm, INTERCEPT_RDTSCP); >>>> >>>> Same thing here. >>> >>> Will do. >> >> For RDTSCP, svm_recalc_instruction_intercepts() will set/clear the RDTSCP >> intercept as part of the svm_vcpu_set_after_cpuid() path, but it will only >> do it based on kvm_cpu_cap_has(X86_FEATURE_RDTSCP) being true, which is very >> likely. >> >> Do you think that is good enough and we can drop the setting and clearing of >> the RDTSCP intercept in the sev_es_vcpu_set_after_cpuid() function and only >> deal with the TSC_AUX MSR intercept? > > The common handling should be good enough. > >> On a side note, it looks like RDTSCP would not be intercepted if the KVM cap >> X86_FEATURE_RDTSCP feature is cleared, however unlikely, in >> kvm_set_cpu_caps() and RDTSCP is not advertised to the guest (assuming the >> guest is ignoring the RDTSCP CPUID bit). > > Hmm, yes, though the only scenario in which KVM clears RDTSCP on AMD comes with > a WARN (it's a guard against KVM bugs). If the guest ignores CPUID and uses > RDTSCP anyways, the guest deserves its death, and leaking the host pCPU doesn't > seem like a major issue. > > That said, if hardware behavior is to ignore unknown intercepts, e.g. if KVM can > safely set INTERCEPT_RDTSCP even when hardware doesn't support said intercept, > then I wouldn't be opposed to doing: > > /* > * Intercept INVPCID if shadow paging is enabled to sync/free shadow > * roots, or if INVPCID is disabled in the guest to inject #UD. > */ > if (!kvm_cpu_cap_has(X86_FEATURE_INVPCID) || > !npt_enabled || !guest_cpuid_has(&svm->vcpu, X86_FEATURE_INVPCID)) > svm_set_intercept(svm, INTERCEPT_INVPCID); > else > svm_clr_intercept(svm, INTERCEPT_INVPCID); > > if (kvm_cpu_cap_has(X86_FEATURE_RDTSCP) && > guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) > svm_clr_intercept(svm, INTERCEPT_RDTSCP); > else > svm_set_intercept(svm, INTERCEPT_RDTSCP); > > Alternatively, KVM could check boot_cpu_has() instead or kvm_cpu_cap_has(), but > that's not foolproof either, e.g. see Intel's of hiding PCID to workaround the > TLB flushing bug on Alderlake. So my vote would either be to keep things as-is, > or do the above (if that's safe). Keep things as-is works for me :) Thanks, Tom