Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4828220iog; Wed, 22 Jun 2022 06:40:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v4r5gpyJvSYmVL/9KkzETPbDfsgLCEwDRFMrTVr84PmRxFXTYJb0xJbaV4tgcdTPVDPKzD X-Received: by 2002:a17:90b:3912:b0:1e8:3cd1:82ca with SMTP id ob18-20020a17090b391200b001e83cd182camr3741626pjb.18.1655905251963; Wed, 22 Jun 2022 06:40:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655905251; cv=none; d=google.com; s=arc-20160816; b=hd9GdFts2FSa9+6SJ4com2NHf8UXo01CjLNoTMG4wcnKViyo8R6IAMDbddRzK+Ji0/ q0CwRgXac4uNip7xVlasgOmjiWxJQdpSAI4kgEoxKQZkhaMrsnIK5WivW3o+HHGqoyGw Jqkt7PYnbzKeR8+1pkLzqtc695Xvq9fgEdze3mLS4Vws1ZFXqPp+9FQvBaLWOTQQZid3 Sx2a1VXuvt5zLNqRBR98QLFwM9Om5tzsahZOOlNEPXF6FIiu/bhRVPz1UjVbqCO4/ui3 SeX4YvA6GykmqaLBfaBciJ6YKfltTJfOyZznAO8cB067t4xvYqQH3ItWAz9S8rET3vZ+ ZV4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Y4kmfcs/X9B5Y6Awz5hwozKMlAr8Qhi0Sic6+65ATHY=; b=CaZQYPgMok9oKLHrTiM/7Jfg6juKKlDzeXlamYT9b9ALzLIRiHT99P38FoL0kC0Zr0 Z/3mhzWn8wZ0GAKvxgPIVCLi5ziTT842guT1BO824+JY6jMblpPeuGbnN1DsQizixcO6 o93u79VlkcuTXbp6ccAHjsrxsnpdCg4obftJur4vJBQIPH35TZH1yFb176ZGPZz2qt37 INBgAU5SdPdMa3cR/Bob9WM/4VCCUmuGovVwuOJ8a1It63EErb942wxbFVhzj3llU2oz m9rRIoS7bXMjHZSMqP2tznFUwOSB7M4wphoB9K5Bb/vyByhGbbWMRHlq2LYlk5skVrQ/ nRbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l3-20020a17090270c300b001639f1759d8si21560390plt.268.2022.06.22.06.40.24; Wed, 22 Jun 2022 06:40:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233816AbiFVNbz (ORCPT + 99 others); Wed, 22 Jun 2022 09:31:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbiFVNbx (ORCPT ); Wed, 22 Jun 2022 09:31:53 -0400 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83D51616F for ; Wed, 22 Jun 2022 06:31:52 -0700 (PDT) Received: from fsav314.sakura.ne.jp (fsav314.sakura.ne.jp [153.120.85.145]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 25MDVTV7072219; Wed, 22 Jun 2022 22:31:29 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav314.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav314.sakura.ne.jp); Wed, 22 Jun 2022 22:31:29 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav314.sakura.ne.jp) Received: from [192.168.1.9] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 25MDVTRu072216 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Wed, 22 Jun 2022 22:31:29 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <1a22993a-00c2-fdec-58e3-8c39159de67a@I-love.SAKURA.ne.jp> Date: Wed, 22 Jun 2022 22:31:28 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] ARM: spectre-v2: fix smp_processor_id() warning Content-Language: en-US To: "Russell King (Oracle)" Cc: Tony Lindgren , LKML , Linux ARM References: <795c9463-452e-bf64-1cc0-c318ccecb1da@I-love.SAKURA.ne.jp> From: Tetsuo Handa In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/06/22 20:21, Russell King (Oracle) wrote: >> static inline void harden_branch_predictor(void) >> { >> - harden_branch_predictor_fn_t fn = per_cpu(harden_branch_predictor_fn, >> - smp_processor_id()); >> + harden_branch_predictor_fn_t fn; >> + >> + preempt_disable_notrace(); >> + fn = per_cpu(harden_branch_predictor_fn, raw_smp_processor_id()); >> + preempt_enable_no_resched_notrace(); >> if (fn) >> fn(); > > The idea is to get the function for the specific CPU, and then to run it > _on_ that CPU, and in theory the CPU that took the fault. However, I > seem to remember there are issues trying to achieve that, and I don't > have a solution for it. Hmm, since some ARM processors support Asymmetric Multiprocessing, whether invalidation is needed depends on which processor was assigned, and that's the reason smp_processor_id() is used? I'm not familiar with hardware, but if a CPU assigned to current thread changes, wouldn't sufficient invalidation take place? In other words, do we need to worry about fn() call if the CPU that took the fault and the CPU which runs the code after harden_branch_predictor() returned differs? If some instructions for CPU-A is not supported by CPU-B, I guess that reading instructions for CPU-A at per_cpu(harden_branch_predictor_fn) and executing instructions on CPU-B at fn() causes problems. Is it guaranteed that all instructions used by fn() are supported by all processors? If it is not guaranteed, we would need to make sure that fn() runs on a CPU which per_cpu(harden_branch_predictor_fn) was done for?