Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp78985pxy; Tue, 4 May 2021 19:04:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoYynCjmoTFkeP2JSlf520PnPDg9KZxdXM+bTJEXjEhVdcQlfeVnp2CDGU0db8GFRzs2yD X-Received: by 2002:a63:a0c:: with SMTP id 12mr25669458pgk.247.1620180249263; Tue, 04 May 2021 19:04:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1620180249; cv=pass; d=google.com; s=arc-20160816; b=cfHksYy2O78IYl3KGXkQiEALR9WNZCmnoRj95XqhSXZGObd3dbJcOyf2NxQ1GWb4tK hBUHkLkQaxo+hmc9LUrcPSjiLGP225MOgA3sWIC2LUnpZz/HOwlprx01sesJSFXl8HmK 1PPecWiKsNv20bHhIZAEG7yGdPvkUabfDjY0TuayGhEn+sesuDxWuQDnbUFH2+Tlkh4s LufZHGPZw4YDvqwudnamaRGSJ3zvYb8PFel6+81R2rB8q9f6PYGvRLFYSVcAdQFTinLm xc19dW++ihx6SSmQSbpYfV8bo0dUsOWBw5Le2IqTPhC7RpPMjGFCqnNWmvpYDakAlCwy 0niA== 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 :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature; bh=6WzY7RSSABUBuuqhLcVFBJRPdiTnc+C0Ilz5NKAeLsA=; b=SlSBVki/++DAB/serKW+9J3q8pOcqq9iP5fFOqHuvyk7T4A4cY+qz0ewuTWBBOapW0 OJ1nj1v4XZylC5obdHzE3EpmXqg3uWR3rUglLWjGQKhmr3FRtRK5klWRL4SHdPW05DI1 mObMYI6cAQsfAcr6zPtcHaILQrPtM64ofNwWPoOj3vBBCVT4O35KJ5NmToQpIyfORnZ6 zpLaFMbZ14bEQLkWOBD67tZ2QjbTjHOk/mLsYnMKJIH16NP30Sei5qj0oQc6SWbE55Ae B+4OHqc6D1u5119iyw7l035eL/uH62ulXTGqfF0eoXkIbmbcHnjRDgR6IXF6HRCFzcbU K0IA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=qeBAJBQn; 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.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o131si19973858pfd.215.2021.05.04.19.03.55; Tue, 04 May 2021 19:04:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=qeBAJBQn; 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.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231703AbhEEBMN (ORCPT + 99 others); Tue, 4 May 2021 21:12:13 -0400 Received: from mail-bn7nam10on2067.outbound.protection.outlook.com ([40.107.92.67]:3146 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231408AbhEEBMM (ORCPT ); Tue, 4 May 2021 21:12:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FkeQsWhE+g3KeWMfvFSSPppoQTTKwIdChsBGuzK11mXkqI89ZjAMt4bFdfWxBbfW7bQ/ABcMRp98457OuNScfPJAcx7bbTtgWYSsFlaSnHhfLmEAGoAslrRi9N9WEaltea8buVnaouLzoxmcM3Szas55QmFNhl/UAnhOJgMo63lOhuQD32kRoZh/R1lhmOvH8wYZLUn7Ph1X60tqeUOsBcKS4qYdohu9aN/QNJdM0OTutkuW6XFvZHfSwyjukfk5V/PdMzfoB2p4Ir0JGDQqiO6JoZ6FXZmrHoywL8c9yH6aKPngswuCCWCUO8okyKrphXqCC31O4NCCHEFZwTghMQ== 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-SenderADCheck; bh=6WzY7RSSABUBuuqhLcVFBJRPdiTnc+C0Ilz5NKAeLsA=; b=F70rK+9Bt0G1MmF9aBJyFnWXvkl6DoVHGXSLtqRIYRPsAD3B4lznwFzNLJhjrZNeEoKNXwjvhUDD50CQDdl3LjT4BPcgnF5czw121qYc5Rc/Hzcw7YLgga9eoPA9KnKVVBRojTYOKRC25Tb0VIBd/8SXorZEMCuCpfVphB9pLaLYhs/PTH6f+H695Eoon7NvviS7LRSBUa/9i0476sBxr5uW+UxASH/MCRxQThA0vYSgh/CDWCwRfq/nAQhc2vOiCjp43zKWnoNiw/vM4eyBnbFrNHvlv5yuhgdE25vml2cVbXuE//JyGr2v12IR45E6A0O4/zLSgQMkjN5Oy27Bqw== 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=6WzY7RSSABUBuuqhLcVFBJRPdiTnc+C0Ilz5NKAeLsA=; b=qeBAJBQnayxsGURezv/GKPmTIwk6sHNyuHPo/a/mja3EJ5UQ87J41THK1e2o/5ckmpNdzPy4wv6jtGkR6CnycOzOqsvAdjcKJAtV4r+LVlEogKGX8fgdmNa802WBv2KjaTtAZajb/UFC95qF9OuFVXbmcZqpSBEnGPZr0h3YoYc= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB3435.namprd12.prod.outlook.com (2603:10b6:5:39::26) by DM6PR12MB3916.namprd12.prod.outlook.com (2603:10b6:5:1ca::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.41; Wed, 5 May 2021 01:11:08 +0000 Received: from DM6PR12MB3435.namprd12.prod.outlook.com ([fe80::69b0:5e8d:c318:3f3b]) by DM6PR12MB3435.namprd12.prod.outlook.com ([fe80::69b0:5e8d:c318:3f3b%7]) with mapi id 15.20.4108.025; Wed, 5 May 2021 01:11:08 +0000 Subject: Re: [PATCH v4 1/1] x86/cpufeatures: Implement Predictive Store Forwarding control. To: Pawan Gupta Cc: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, Jonathan Corbet , bsd@redhat.com References: <20210430131733.192414-1-rsaripal@amd.com> <20210430131733.192414-2-rsaripal@amd.com> <20210505001154.rmibherzitm2yaga@devbox.home> From: "Saripalli, RK" Message-ID: <03c5cd2b-ae83-1d7e-0761-81055d281b78@amd.com> Date: Tue, 4 May 2021 20:11:06 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 In-Reply-To: <20210505001154.rmibherzitm2yaga@devbox.home> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [69.215.231.172] X-ClientProxiedBy: SN6PR16CA0071.namprd16.prod.outlook.com (2603:10b6:805:ca::48) To DM6PR12MB3435.namprd12.prod.outlook.com (2603:10b6:5:39::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [10.0.0.13] (69.215.231.172) by SN6PR16CA0071.namprd16.prod.outlook.com (2603:10b6:805:ca::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Wed, 5 May 2021 01:11:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 250a1d94-c488-4c43-3065-08d90f62a9ae X-MS-TrafficTypeDiagnostic: DM6PR12MB3916: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TIJEih5VU+RKuNedo4s40u55QnQ7xXidCdaWiYiu1yGnfjBmcKYfuWMquRfOGoPs3eOwUomrHxFNXgvGujGk9Skg9/pKqgu21f7jRzc5BMMaZmVts3z0aw+QoIJuBsk74pLWr9g9m9XKIfnyIg/uxQv8rRKQIoNXvuz3WhhwyZg0YwrAnaEVqkj/5lAm6+FjBb90BHdSIqLy+/kbnFRY8mrTb5BGDsM5nE+8SkDXgFDuU5V5tTt/TZxtEI96MiuIcH976bTohyGEv6n8RGm28JqbRCjeh5aVJTgQYtnbRqf0O7XBfX4iS/3UirAkfeKZoV+8F/SNl7nlrEG0jHVHVm84CSI17raHmKhxMpbISbyIAzFvlxRBCmQMLKHJ0hxN8jVtJ9/FtcDLSh9larHD26AhE7pClRdUt0JTo7WXJRngrVVDfZLj6sT9Ifd4Xjzq1f1Gp/uenUhwuPS66SjFEWPXQZQVT3o9tiyVHQVO9zK5MlEfa/bpq6vtW/P7AxW1DB18FUH0gbULgDLbNmZ37su0HKB2kvvsmtY5mU8x/A30C1mqm7hnTFFMuml5iP6M/O7kf8P89w8eGKAa4pt0ALPX7j8eNSs98b84fwNatVakcHTObBRnCDGP32ZVmStENkZG2pFBolckc8xlaXar3Lx+8TKoDNNS3pvXSfoLDN5JmlN8Seeo8wiofdsQUeqs X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3435.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(366004)(346002)(136003)(83380400001)(31696002)(6486002)(6916009)(16576012)(2616005)(8676002)(66946007)(36756003)(956004)(2906002)(38100700002)(478600001)(16526019)(4326008)(5660300002)(53546011)(31686004)(8936002)(26005)(66556008)(66476007)(186003)(316002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?eFZ4ZmNwQW85VENtWGdYdGQrQ2VPUUpVRHYyQkVkT2hyMjQ3VklDenVlQWk0?= =?utf-8?B?bFNpd1BlTWUvUWhsRXczRGZYTGFmY2ZMcTBWSVBBcy9CMXo1Wkpqc0dXQVFQ?= =?utf-8?B?ZkF5KzJZaVI4c3VCTmw1TWc4OVlFZEpRNjNSYnVMVGM5MWljTUh5eVJveEYx?= =?utf-8?B?NXdlclVLbjhpUnRkNklJSFRWR0hON0RyWE5rWFkyUHFtTDlhMnZRZUJMOGlS?= =?utf-8?B?bkRsR0NlMDRRYmprMUxzSWRyaGErSTdZd05ud1NWRVN2bFY1NkhuNXE5S2Nt?= =?utf-8?B?WDdaYXM0dUpFZUphRE5uc1BIMjlacUxONzRRWXhLejZPT3RtYnhRa0RId1lR?= =?utf-8?B?TndSa0tDMFhIaTEvVnVOR21hamZvL3BpakFjMnQydGZ3eS8weHR3c3lQTEMw?= =?utf-8?B?a08rb2JNdlpkWXlaVnVlM2ltRzYvajNnamJ2WCsxalFIclF4MHdDRlQrZTB4?= =?utf-8?B?aStua0p0U0Y1UmVJdTVqeFZNMjFJMEFnNm9laGRobk8wVGNKTEVseEh5MkYw?= =?utf-8?B?UkdtWjVCNFZpOFdKSkJYeGVoU1Q2RUVjOXlUOHFHZzAxU2pyYy9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aHdt?= =?utf-8?B?QkxHWVdOa0NabDJRL2lGWWdUTG0vcDAvMEcxeHptZ3hiMy9UclhnSUV6cmIx?= =?utf-8?B?TmNpZStsQnZUS0JIQkpVMFlZM1c4SWprMmRQWUJMY25GZ1pvL3lHRWlwSnVv?= =?utf-8?B?Q2pCNGtGWENXVG0vUTQvamZGVlFyeitSb1FKdTVKQWNxem1aa2FXVUdHRElM?= =?utf-8?B?R1RhalRSeVpVRzg0M2pGeUc0Q1IybzJtQjNzb2R2eDlkSWswclBLai9lcTdM?= =?utf-8?Q?oiCV1cKyPW0HqZYpOTdMfjMBsE5PJW8ofeKBe/O?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 250a1d94-c488-4c43-3065-08d90f62a9ae X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3435.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 01:11:08.0501 (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: 87QkYn0JZ6PdwuSsNfADzlATcqeRy/9yj7nLOBwzjlXnLKpKWbGrQTpKwjgGRJceQDVb3UGNTnF5Ncas26XPeA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3916 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/4/2021 7:11 PM, Pawan Gupta wrote: > On 30.04.2021 08:17, Ramakrishna Saripalli wrote: >> --- a/arch/x86/kernel/cpu/amd.c >> +++ b/arch/x86/kernel/cpu/amd.c >> @@ -1170,3 +1170,26 @@ void set_dr_addr_mask(unsigned long mask, int dr) >>         break; >>     } >> } >> + >> +static int __init psf_cmdline(char *str) >> +{ >> +    u64 tmp = 0; >> + >> +    if (!boot_cpu_has(X86_FEATURE_PSFD)) >> +        return 0; >> + >> +    if (!str) >> +        return -EINVAL; >> + >> +    if (!strcmp(str, "off")) { >> +        set_cpu_cap(&boot_cpu_data, X86_FEATURE_MSR_SPEC_CTRL); >> +        rdmsrl(MSR_IA32_SPEC_CTRL, tmp); >> +        tmp |= SPEC_CTRL_PSFD; >> +        x86_spec_ctrl_base |= tmp; > > I don't think there is a need to update x86_spec_ctrl_base here. > check_bugs() already reads the MSR_IA32_SPEC_CTRL and updates > x86_spec_ctrl_base. Pawan, you are correct. I added the update to x86_spec_ctrl_base to ensure that the bits in x86_spec_ctrl_base are consistent with the actual bits in the MSR after this change >> +        wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); >> +    } >> + >> +    return 0; >> +} >> + >> +early_param("predict_store_fwd", psf_cmdline); >> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c >> index d41b70fe4918..536136e0daa3 100644 >> --- a/arch/x86/kernel/cpu/bugs.c >> +++ b/arch/x86/kernel/cpu/bugs.c >> @@ -78,6 +78,8 @@ EXPORT_SYMBOL_GPL(mds_idle_clear); >> >> void __init check_bugs(void) >> { >> +    u64 tmp = 0; >> + >>     identify_boot_cpu(); >> >>     /* >> @@ -97,7 +99,9 @@ void __init check_bugs(void) >>      * init code as it is not enumerated and depends on the family. >>      */ >>     if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) >> -        rdmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); >> +        rdmsrl(MSR_IA32_SPEC_CTRL, tmp); >> + >> +    x86_spec_ctrl_base |= tmp; > > This change also doesn't seem to be necessary, psf_cmdline() updates the > MSR( i.e. sets PSFD).  Here read from the MSR will still update > x86_spec_ctrl_base to the correct value. Am I missing something? Yes you are correct because psf_cmdline executes before check_bugs() and does update the MSR. > > Thanks, > Pawan