Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp130994lqe; Fri, 5 Apr 2024 15:29:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVblyuaZfy0kqoYaq23vhg3qJVf1QqkaEOB1d8vK2UASm2lypgbxUpAbRhm71N+8boLZLZV2V3nxMjFB6rh1zvJHbOsgIrjRBb5ysbAJQ== X-Google-Smtp-Source: AGHT+IFLd8m6jl3oEpxZ6DGZOmBkVBSP3tmxphk+FADXYGdKuFvMwUx89PNrsGMUtrblkqQjAwQp X-Received: by 2002:a05:6512:488e:b0:516:d219:3779 with SMTP id eq14-20020a056512488e00b00516d2193779mr1834310lfb.58.1712356178274; Fri, 05 Apr 2024 15:29:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712356178; cv=pass; d=google.com; s=arc-20160816; b=Fbuwjw8tAkoAyvkaXc+CU3JI7IzgzIX5NbAK0Oyp5I5AX6EXF1d9qLKsNHCHmxaxJ3 ZOBRRFi+Vtm8jHjcn+5Q4e9St5bTQymBu5OgppqXc95STTCo2DepY+9mZ/Pk+0Cr5+3n IM9gyyj3tZhz+Q2dpPvJ+zwysTEkIlOCewgMJ2WzcJAeQMKkyyds1068piu0wInH3nUg ECa5K1u5Y52CwIDXfsDbveTz+GiIEXB41R3v8H9b2YzTUfcCJVHDA9Oitl3eX8flGiG3 kjBFlym1fnFFzZluY5AGr6WDF8+kcg5SoFY+1zf2v6m5RptofHHcGl3Azq3TWtPLtUel /4fA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nkuA428H8SU538A9pVCGPyWi+nmzgqjnZW6ADdcdweQ=; fh=bhqlPbXjHBxQzd6TvgdNdBs+Har8pRoecv6ZHfN2TWo=; b=AKHe/xl2l1jaaGy8jzw5ysfxLAQ7G1mlcZLgExVAoQlLmTI3d6cJhg6rpiEPuuRrVQ f6ZcuqDc24zpaEUXS0+4MybE6qMFp3oJD1uePltlEMhn3I+0NOakFei03fusZN7HKZ0F Ggp6+ELSQpB4IQcF04sgE70Uv7Oh/JC7Q2JnnbHKqGqpJgkC3QFT4i0iLJjT2GMBA6YJ oVozYSBGRP3aeL0dmdHdptuj+xtBAXqRqzUYxupHc8dw3fJtiouE4RSTXojjrlBkmAq6 M97tzTDOgPaLdcLREuB6XgN01O5nConUa7cYzn4w1JV0OYw06HCNmfd830ZUp551im8G 9/mA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="K/ohXARw"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-133679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133679-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a7-20020a170906468700b00a51a7de68fbsi863260ejr.24.2024.04.05.15.29.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 15:29:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="K/ohXARw"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-133679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133679-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 01A2F1F23F7C for ; Fri, 5 Apr 2024 22:29:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6E5D17A92B; Fri, 5 Apr 2024 22:26:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="K/ohXARw" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A97C1791F8; Fri, 5 Apr 2024 22:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712356015; cv=none; b=lxHLL383q+BV/6bVUk+6aq6bJc6P14xqZLjeHQ10PZcZxWaeAajd3UwKwgS6j0yrpwuoYO2SOmupTDjKE4KS6FtUHuLCUaJYRJqyWTxw5YLmbPHEx9buUNdcjZeZO/SHVk3ieGVsYVZFCEJsROvz1vj2GdUC+NCFjQd5uKvvl7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712356015; c=relaxed/simple; bh=LkTbi44XEjcmD+H9V0/r7+1X5xEeMnDv3K3o3ANyhmw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tme879AQ8RGl/z3r3/RT9Nz21uJZ2H0mK/1sGPVwJSlkkFfhtU4SVkLwrF2elGRuW1qZqYtYTQJe1IsKAmPe9TU/G2yVbPJAXusB6IC1PYL11KvMrPXU9IiTonzA9c2ODgAklxTbAQG4sFcdM6b8zm0GvGXM7EacWM7VPGK3piw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=K/ohXARw; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712356013; x=1743892013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LkTbi44XEjcmD+H9V0/r7+1X5xEeMnDv3K3o3ANyhmw=; b=K/ohXARwH+bNb79vSuF48fODgcX+5v5JsD6922Lz+ocp95W13kEJhwuu diqyiPAv+SGfYsmT/hLkzp4RoYgJ3Ap3sLFyhmO+xMRte4crOWqpPp2B7 PajfypQLKzuhwqezg4Tk6wVmBj+AGURh6BHgh2Snn4F3e3dU8vJPoCK7E LZOf6g7smibbZjQ+wnVKyZct3+2q3A7gdTeBPRcmf5ydG1BM1L55wA+KW VseGr7lYSD+rkXwdL5fdyINEyP0fZuQppY8IFwUNh3DtVogzxHPi1YAt8 9mMOoBkJ5Bsr+4KsKUspes+u70p1YLGP30hYvdA4MNC3YDVnGVeJD1Sis Q==; X-CSE-ConnectionGUID: oA5CSr+VQbq9XBlIxV/sww== X-CSE-MsgGUID: 7I0nbuLgSDWKfzrXVEuRnw== X-IronPort-AV: E=McAfee;i="6600,9927,11035"; a="19062791" X-IronPort-AV: E=Sophos;i="6.07,182,1708416000"; d="scan'208";a="19062791" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2024 15:26:51 -0700 X-CSE-ConnectionGUID: cOkIIhzfSXisjOEM48bJGQ== X-CSE-MsgGUID: zH4owt0ZTBS8MP9bwG+JrQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,182,1708416000"; d="scan'208";a="23928332" Received: from jacob-builder.jf.intel.com ([10.54.39.125]) by fmviesa004.fm.intel.com with ESMTP; 05 Apr 2024 15:26:50 -0700 From: Jacob Pan To: LKML , X86 Kernel , Peter Zijlstra , iommu@lists.linux.dev, Thomas Gleixner , "Lu Baolu" , kvm@vger.kernel.org, Dave Hansen , Joerg Roedel , "H. Peter Anvin" , "Borislav Petkov" , "Ingo Molnar" Cc: Paul Luse , Dan Williams , Jens Axboe , Raj Ashok , "Tian, Kevin" , maz@kernel.org, seanjc@google.com, "Robin Murphy" , jim.harris@samsung.com, a.manzanares@samsung.com, "Bjorn Helgaas" , guang.zeng@intel.com, robert.hoo.linux@gmail.com, Jacob Pan Subject: [PATCH v2 09/13] x86/irq: Factor out common code for checking pending interrupts Date: Fri, 5 Apr 2024 15:31:06 -0700 Message-Id: <20240405223110.1609888-10-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240405223110.1609888-1-jacob.jun.pan@linux.intel.com> References: <20240405223110.1609888-1-jacob.jun.pan@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use a common function for checking pending interrupt vector in APIC IRR instead of duplicated open coding them. Additional checks for posted MSI vectors can then be contained in this function. Signed-off-by: Jacob Pan --- arch/x86/include/asm/apic.h | 11 +++++++++++ arch/x86/kernel/apic/vector.c | 5 ++--- arch/x86/kernel/irq.c | 5 ++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 94ce0f7c9d3a..ebf80718912d 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -499,6 +499,17 @@ static inline bool lapic_vector_set_in_irr(unsigned int vector) return !!(irr & (1U << (vector % 32))); } +static inline bool is_vector_pending(unsigned int vector) +{ + unsigned int irr; + + irr = apic_read(APIC_IRR + (vector / 32 * 0x10)); + if (irr & (1 << (vector % 32))) + return true; + + return false; +} + /* * Warm reset vector position: */ diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c index 185738c72766..9eec52925fa3 100644 --- a/arch/x86/kernel/apic/vector.c +++ b/arch/x86/kernel/apic/vector.c @@ -965,7 +965,7 @@ static void __vector_cleanup(struct vector_cleanup *cl, bool check_irr) lockdep_assert_held(&vector_lock); hlist_for_each_entry_safe(apicd, tmp, &cl->head, clist) { - unsigned int irr, vector = apicd->prev_vector; + unsigned int vector = apicd->prev_vector; /* * Paranoia: Check if the vector that needs to be cleaned @@ -979,8 +979,7 @@ static void __vector_cleanup(struct vector_cleanup *cl, bool check_irr) * fixup_irqs() was just called to scan IRR for set bits and * forward them to new destination CPUs via IPIs. */ - irr = check_irr ? apic_read(APIC_IRR + (vector / 32 * 0x10)) : 0; - if (irr & (1U << (vector % 32))) { + if (check_irr && is_vector_pending(vector)) { pr_warn_once("Moved interrupt pending in old target APIC %u\n", apicd->irq); rearm = true; continue; diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c index 8772b0a3abf6..3206d48f380d 100644 --- a/arch/x86/kernel/irq.c +++ b/arch/x86/kernel/irq.c @@ -480,7 +480,7 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_posted_msi_notification) /* A cpu has been removed from cpu_online_mask. Reset irq affinities. */ void fixup_irqs(void) { - unsigned int irr, vector; + unsigned int vector; struct irq_desc *desc; struct irq_data *data; struct irq_chip *chip; @@ -507,8 +507,7 @@ void fixup_irqs(void) if (IS_ERR_OR_NULL(__this_cpu_read(vector_irq[vector]))) continue; - irr = apic_read(APIC_IRR + (vector / 32 * 0x10)); - if (irr & (1 << (vector % 32))) { + if (is_vector_pending(vector)) { desc = __this_cpu_read(vector_irq[vector]); raw_spin_lock(&desc->lock); -- 2.25.1