From patchwork Thu Mar 2 05:24:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 63214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4063145wrd; Wed, 1 Mar 2023 21:52:13 -0800 (PST) X-Google-Smtp-Source: AK7set8KycB3BNLrLMTulm30h8Cz4VouyJZUyEnmd+3sy1iAnL1OItrr0PyB8lo+hL1CK9e/BQfj X-Received: by 2002:a17:906:5d16:b0:8af:3fef:52c9 with SMTP id g22-20020a1709065d1600b008af3fef52c9mr13991202ejt.22.1677736333654; Wed, 01 Mar 2023 21:52:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677736333; cv=none; d=google.com; s=arc-20160816; b=unjyQ5k0+cXAk3ve7O12XpM7K9WSGbqWIZ8pw2+/wwmtY2Zt1GuSDc1mI2l0TJ7DGk hK4M7DyY1JItlKzc/99uGc0e6C0DUMHBm8NnFAkqehg9ws/qNaf8pMg3CwAcJVCp7Bkv zFukUd9NXX/9Ik/Ze6eYGSKJb4B62aEckNnRG9KP3WDz70tEFbUei/z46/UQXzT4gHkS snjUqlcWSxo8yaMOqp27tIQLtVk9cjU84pTXshauZmuBPAtRtetjQKF1tMHfpI/rYjFQ t2dSBye0bEK6ke471yrEeiFLTOAnMdM2nMCBzrocTk8S3R14x89VlEur7VPNRGcBxgdL TqCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rIemuu6QZ5e7zz1ZmPXxi8UM/1xuDAEOyCDdvKuC//8=; b=ylavK1NKsmpQQlSePMvIwAYHdA3p75R/kUU5II++gNN7X6jaMoE9J6pUf+T11eF3Py hGCFpkBSZ+Y1v5hNCRpKQS78A+3p9PfGBjNqA3Rsv20J/B3LtL3+YHFP02SqCIYx1fa8 YkXqAUmKDaKRVpMGKDwbCmm0pISLa1uj/6fDDg2yh2sH1zcuhJrUWCvv/5DbvyF8bnWd PnCxIAdX7E/NSl7bG4oB2NHF4cQ1U/jWa0v6YCpHJPlU7QXeRo2q10ZGVGFTUcW5iTSN 4IYePeXdrNHN9WuAiXHPt4kGMk0j6xVaYfloxUtIJ2kkltDhXb3+8VpUhGsJ6lVNiqUw FGvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UwF2KvFf; 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=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js19-20020a17090797d300b008e1a91a7b8csi3340573ejc.968.2023.03.01.21.51.49; Wed, 01 Mar 2023 21:52:13 -0800 (PST) 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=@intel.com header.s=Intel header.b=UwF2KvFf; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229900AbjCBFvE (ORCPT + 99 others); Thu, 2 Mar 2023 00:51:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjCBFut (ORCPT ); Thu, 2 Mar 2023 00:50:49 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF942149A8; Wed, 1 Mar 2023 21:50:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677736248; x=1709272248; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0uFNdDkUqLm94ae1U1jdZV+knFHrk6JmxBSxXFP+9lc=; b=UwF2KvFfHcJTiFByhahOJlnBhnaZCZIwahxEuqlpr5xqKzDPAqkFt4OB abTLQvLSEav16cogCTo7brCSsx9Hh1M71OVGc9JKd2Xbvhxj/vd88mt5/ mtT4KD1ZnmvY8lyL7wL2hFXKikU2sqif0BTGVEccDLs1WSmSVSACl6HMP EJuY5U7bEuECtyagI6SsqLEYM8nmWKXWcylbSHFlQaI0A+iK+J7dKEk4n V6ACxavPYJs9Q+H8yKqgMzGC6odnOnzN/xzMW+w/A2IVVDWrwfjbBSIuD 2+XfeIMqOfeK/OY4EN+SZRk+pUMzsrr6wTo50xgFa/SAs3nTJ1ZM4BCA5 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="420887033" X-IronPort-AV: E=Sophos;i="5.98,226,1673942400"; d="scan'208";a="420887033" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2023 21:50:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="920530877" X-IronPort-AV: E=Sophos;i="5.98,226,1673942400"; d="scan'208";a="920530877" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 01 Mar 2023 21:50:45 -0800 From: Xin Li To: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, andrew.cooper3@citrix.com, seanjc@google.com, pbonzini@redhat.com, ravi.v.shankar@intel.com Subject: [PATCH v4 04/34] x86/traps: add external_interrupt() to dispatch external interrupts Date: Wed, 1 Mar 2023 21:24:41 -0800 Message-Id: <20230302052511.1918-5-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230302052511.1918-1-xin3.li@intel.com> References: <20230302052511.1918-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759234053948746604?= X-GMAIL-MSGID: =?utf-8?q?1759234053948746604?= From: "H. Peter Anvin (Intel)" Add external_interrupt() to dispatch external interrupts to their handlers. If an external interrupt is a system interrupt, dipatch it through system_interrupt_handler_table, otherwise call into dispatch_common_interrupt(). Signed-off-by: H. Peter Anvin (Intel) Co-developed-by: Xin Li Tested-by: Shan Kang Signed-off-by: Xin Li --- arch/x86/kernel/traps.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index c0f7666140da..31ad645be2fb 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -1499,6 +1499,47 @@ void __init install_system_interrupt_handler(unsigned int n, const void *asm_add alloc_intr_gate(n, asm_addr); } +#ifndef CONFIG_X86_LOCAL_APIC +/* + * Used when local APIC is not compiled into the kernel, but + * external_interrupt() needs dispatch_spurious_interrupt(). + */ +DEFINE_IDTENTRY_IRQ(spurious_interrupt) +{ + pr_info("Spurious interrupt (vector 0x%x) on CPU#%d, should never happen.\n", + vector, smp_processor_id()); +} +#endif + +/* + * External interrupt dispatch function. + * + * Until/unless dispatch_common_interrupt() can be taught to deal with the + * special system vectors, split the dispatch. + * + * Note: dispatch_common_interrupt() already deals with IRQ_MOVE_CLEANUP_VECTOR. + */ +int external_interrupt(struct pt_regs *regs, unsigned int vector) +{ + unsigned int sysvec = vector - FIRST_SYSTEM_VECTOR; + + if (vector < FIRST_EXTERNAL_VECTOR) { + pr_err("invalid external interrupt vector %d\n", vector); + return -EINVAL; + } + + if (sysvec < NR_SYSTEM_VECTORS) { + if (system_interrupt_handlers[sysvec]) + system_interrupt_handlers[sysvec](regs); + else + dispatch_spurious_interrupt(regs, vector); + } else { + dispatch_common_interrupt(regs, vector); + } + + return 0; +} + void __init trap_init(void) { /* Init cpu_entry_area before IST entries are set up */