From patchwork Tue Aug 1 10:47:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2640677vqg; Tue, 1 Aug 2023 05:43:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlHhWNhFJSOKKjID0vALDfi840yQNrbXsN+jKEd3qeIjEL5ydBtCVO9v2heGzndrevwcXvo3 X-Received: by 2002:a17:902:dacf:b0:1bb:c9e3:6d4f with SMTP id q15-20020a170902dacf00b001bbc9e36d4fmr17441175plx.10.1690893815153; Tue, 01 Aug 2023 05:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690893815; cv=none; d=google.com; s=arc-20160816; b=hAe8+TjfOacBfXV0oxYi1U7xnIGePUMyRkIjtIA5hCA1AbiJzckOEIgLszjO3GOENX 6QUf+6/CGJsB5ufyTfgKpvCtYQ2LWLlC+SBZQSojn5r8enHMFum1d0HeXY7CKgRcqJRn Kcoj5QA/oEFOftfgRVqgAbUKfF8R9YlI0jnr2ZL0paQiYr8P43Eiw4ajBOseROVFzmOS SWM/bG9H54ouJOEtDT7vTkAqCgjyXumv3LGUWdv68gSUqRIsWw+OTB8xpwrSJLVrFrPZ 3yTRsifQqzA/yz8a9WV1O/w9fPgVkwuEE8CHRyZdvDLbfZI2owAAXMSfGc71gR+H06PW dm+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=gTGbbDL5HBuwEB2u+LxYM2ki0P05Jj6Bwt/DqClxZRM=; fh=mE3iieUIZLcDfOLIULj9X6/p0bMDPZGFSVRsnyRUnTc=; b=ujUY8wK0ZwBlPAwzsFoqTkogrSNXE+Gz2Fm6ObugbKot4T0Wh6v9uU7pyTADLC6cDm MI1vuhwbUYF+t9K1IxCtmyjALvCBdVYHaR7khSuOP9362gked0XqApgTG4RYxRkU8H0s Yx5qKLcCTz3540K6EsOPeKR3vp42yMDI+FN7KPjUYYbHcEFHwtrhvd2eAFsYxlZitXUw BpEn0IC22RiB+pJu5b/KcFdZ7zHZgyzc1m5slZDVmIDzVg4RkHmoo0+D6kwPArQTt72L iJ0LsY/+4P5mhm5AJLZt48+Wwofk83ktXIDI9BZCI2idONVdFoKYGpsZCM24YWdDaQ8C Ekyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=O4gGV7ZO; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a6-20020a170902ecc600b001bbabd5b14esi2006713plh.608.2023.08.01.05.43.21; Tue, 01 Aug 2023 05:43:35 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=O4gGV7ZO; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233551AbjHAKto (ORCPT + 99 others); Tue, 1 Aug 2023 06:49:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234142AbjHAKtH (ORCPT ); Tue, 1 Aug 2023 06:49:07 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7AF435BB for ; Tue, 1 Aug 2023 03:47:39 -0700 (PDT) Message-ID: <20230801103816.969106021@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690886842; 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: references:references; bh=gTGbbDL5HBuwEB2u+LxYM2ki0P05Jj6Bwt/DqClxZRM=; b=O4gGV7ZOTVqqbE6WSzsywAE5Cpx7g7mSLkc5363gGwi7+ahrylAyXCJPa9zNdfozz+j5UE 17tQSbwgejhr/4IjXgpWuImY0feIHZEcv47fhed5mlH5gT4HZ0ZO+1+H3w5Ifew1duomZK YLph3O3TvX68sg1OPZj8IitHGh9l+7F13b7IbbiinGXsflqEWvwRAC8vfK8i0sqjMtOSi3 lCEXKTb+MNEixXo2UqiWPXIMGqnqG8suKZJvmXhzhgkSGtL+osXBcW+NqBWs+AmWifzl9c lvMmaYe5nEMZhNUkjYl2S6loeHR5DzSiyFCPAz44ss080GeUvWzvGB/UF790Yw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690886842; 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: references:references; bh=gTGbbDL5HBuwEB2u+LxYM2ki0P05Jj6Bwt/DqClxZRM=; b=cM7usDf8nyzMnAL7AVpjBBqvxDJiBHwi0Mya4JKi36rmvsACYGj91OylKsdZEo6ZvfLQ1N P/RYVAgzEdrHLFCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Andrew Cooper , Tom Lendacky , Paolo Bonzini , Wei Liu , Arjan van de Ven , Juergen Gross , Michael Kelley , Peter Keresztes Schmidt , "Peter Zijlstra (Intel)" Subject: [patch V3 33/60] x86/apic/ipi: Tidy up the code and fixup comments References: <20230801103042.936020332@linutronix.de> MIME-Version: 1.0 Date: Tue, 1 Aug 2023 12:47:22 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773030672988289456 X-GMAIL-MSGID: 1773030672988289456 Replace the undecodable comment on top of the function, replace the space consuming zero content comments with useful ones and tidy up the implementation to prevent further eye bleed. Make __default_send_IPI_shortcut() static as it has no other users. Signed-off-by: Thomas Gleixner Acked-by: Peter Zijlstra (Intel) --- arch/x86/kernel/apic/ipi.c | 74 ++++++++++++++++++------------------------- arch/x86/kernel/apic/local.h | 2 - 2 files changed, 32 insertions(+), 44 deletions(-) --- a/arch/x86/kernel/apic/ipi.c +++ b/arch/x86/kernel/apic/ipi.c @@ -108,68 +108,58 @@ static inline void __xapic_wait_icr_idle cpu_relax(); } -void __default_send_IPI_shortcut(unsigned int shortcut, int vector) +/* + * This is safe against interruption because it only writes the lower 32 + * bits of the APIC_ICR register. The destination field is ignored for + * short hand IPIs. + * + * wait_icr_idle() + * write(ICR2, dest) + * NMI + * wait_icr_idle() + * write(ICR) + * wait_icr_idle() + * write(ICR) + * + * This function does not need to disable interrupts as there is no ICR2 + * interaction. The memory write is direct except when the machine is + * affected by the 11AP Pentium erratum, which turns the plain write into + * an XCHG operation. + */ +static void __default_send_IPI_shortcut(unsigned int shortcut, int vector) { /* - * Subtle. In the case of the 'never do double writes' workaround - * we have to lock out interrupts to be safe. As we don't care - * of the value read we use an atomic rmw access to avoid costly - * cli/sti. Otherwise we use an even cheaper single atomic write - * to the APIC. - */ - unsigned int cfg; - - /* - * Wait for idle. + * Wait for the previous ICR command to complete. Use + * safe_apic_wait_icr_idle() for the NMI vector as there have been + * issues where otherwise the system hangs when the panic CPU tries + * to stop the others before launching the kdump kernel. */ if (unlikely(vector == NMI_VECTOR)) safe_apic_wait_icr_idle(); else __xapic_wait_icr_idle(); - /* - * No need to touch the target chip field. Also the destination - * mode is ignored when a shorthand is used. - */ - cfg = __prepare_ICR(shortcut, vector, 0); - - /* - * Send the IPI. The write to APIC_ICR fires this off. - */ - native_apic_mem_write(APIC_ICR, cfg); + /* Destination field (ICR2) and the destination mode are ignored */ + native_apic_mem_write(APIC_ICR, __prepare_ICR(shortcut, vector, 0)); } /* * This is used to send an IPI with no shorthand notation (the destination is * specified in bits 56 to 63 of the ICR). */ -void __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int dest) +void __default_send_IPI_dest_field(unsigned int dest_mask, int vector, + unsigned int dest_mode) { - unsigned long cfg; - - /* - * Wait for idle. - */ + /* See comment in __default_send_IPI_shortcut() */ if (unlikely(vector == NMI_VECTOR)) safe_apic_wait_icr_idle(); else __xapic_wait_icr_idle(); - /* - * prepare target chip field - */ - cfg = __prepare_ICR2(mask); - native_apic_mem_write(APIC_ICR2, cfg); - - /* - * program the ICR - */ - cfg = __prepare_ICR(0, vector, dest); - - /* - * Send the IPI. The write to APIC_ICR fires this off. - */ - native_apic_mem_write(APIC_ICR, cfg); + /* Set the IPI destination field in the ICR */ + native_apic_mem_write(APIC_ICR2, __prepare_ICR2(dest_mask)); + /* Send it with the proper destination mode */ + native_apic_mem_write(APIC_ICR, __prepare_ICR(0, vector, dest_mode)); } void default_send_IPI_single_phys(int cpu, int vector) --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -44,8 +44,6 @@ static inline unsigned int __prepare_ICR void default_init_apic_ldr(void); -void __default_send_IPI_shortcut(unsigned int shortcut, int vector); - /* * This is used to send an IPI with no shorthand notation (the destination is * specified in bits 56 to 63 of the ICR).