Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp198lqb; Thu, 23 May 2024 09:06:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVNu4QrxEiYPo1rfZ28deFleLMrO8nHI9jIfbqLqT68MHOU7yydkKnxAFW7NBBev/gGTqXnOW8hmz2j6YyucJcSXP2J9SUwN1PI//jq1g== X-Google-Smtp-Source: AGHT+IGXiLTgVYh5+fqbsFRXTAVANg0peKxQFN9BBG4GK1MdmwqOGe30zZZ4m1hFDeNV+ZCwkKOs X-Received: by 2002:a05:6a20:6f07:b0:1b1:c745:5c66 with SMTP id adf61e73a8af0-1b1f8ae2096mr5843044637.54.1716480419486; Thu, 23 May 2024 09:06:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716480419; cv=pass; d=google.com; s=arc-20160816; b=dYZe+/gsyRysnsiQAF3XPnpsb5isOqq9wcnLt2NvkNEq9bnZRy3kvWplI/8yjbJJoE dET6jUoFXBLD/lwOHlmvMj++IjQBmRWE5j/vg5z0V7zOKLWR9VG27Y4IBzkDNsMCod74 yAN1+dM5HupLM6p30BnpHxeW+47KxVCIOSASK8Gn4J9JoyZo853bAzNA6gKxSxUT+Wye UjS/gZTBrRHlQM/N2r7kyK+sVxonIqgXSy3Bpzj/k+Nc60W7qvrxVWQwKCInaqPYMbDQ xvrD+KgKazNRLaaXtsQ4FI5pZ74aUinuRI06GDQRMzr6E9HNqsx83fo+c2QPQPlq6lzU sBBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=3d3iyJqmM/1eDHi6IVV043bTCqbOnpQe2A0l9FAURNs=; fh=RQrvNSCRMHpTLVMajWvovKgjKU9yd9mGbpIc/8icGsw=; b=KHV4l3hlzQf3CSSiUjpGKfX1ON2GV49yhoFoLp9n02SznBeSfAO0TcvfrrRwZwXerx je6fCdSMRogKjwFXPzkTchLynMpJgC0OfmZ8DiSzsD8yqe+ZyWqtZANywHOxTuHEnX9C YOe43Kzzij6kaOWMMOtzES1NphlHDk36vSfm2M2zSeZhxBF/blw3sa8G3oEoKVYLL83z 3Ht2jw1bWVfphSpV7lpCln/wblqZLTzuwVo6LGfKSPr2xcTRfgVwA3EDYYtUC5yjcWCe 8f6xZ5+ZNcZ70SpCxRrV69j/Hn3+tEb9cEH98Q78ytpLH/cpYwiE4jhnM95omwgjAFr0 IWGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RXxeiBjj; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-187765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6577879fc4esi2121018a12.325.2024.05.23.09.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 09:06:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RXxeiBjj; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-187765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CC587B23139 for ; Thu, 23 May 2024 16:04:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E9821173F; Thu, 23 May 2024 16:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RXxeiBjj" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0259C1D55D for ; Thu, 23 May 2024 16:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716480268; cv=none; b=FOMP0jlq1yyvhzhOqtwVbxd0o4NhbjS2qf7/58bwuz1t5Nvo0dJ10VsGctvQQ+ArynV9Gkv+BU5VaVVHYI91baaZELww1U3Hs0AczWDVKUt04aSKldsbVxcVlQ0r/VrIIqNVt7adnibF3jMAleiVl/cK0HMUNoTEXfiTVLBcygU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716480268; c=relaxed/simple; bh=EhTBCoWEsH6RQeHWfu+3Ppem+Bmf+xIMkgx/LOGt+8s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BgysTmtM9dj6UVqcOK1AYqMe5cNQAL2bAZuUu1/uZ3xU9x4ey+wIGTP6zOArRr2MEzkEEO272hLbslC0AzFG1jnJfraBPCLYRpUU6fr2Ch1UsgNrvrtLWsqpX/QajS4L2Gito2HVei8Whdlk7oUNu8kUcvn9scIqFUJfGS2E+Eo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RXxeiBjj; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61b2ef746c9so254101517b3.1 for ; Thu, 23 May 2024 09:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716480265; x=1717085065; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3d3iyJqmM/1eDHi6IVV043bTCqbOnpQe2A0l9FAURNs=; b=RXxeiBjjFncawXnhuOMFZDJN5S23C+oXf0DEXlPgBqL108Uwku/Z+RmPh9S7gWEPsl N3ndt7oExXpqqgzIITD6ugUGkN8CBJskCX8Hvfz9638+vPGAlWPrpYmR6O6Zpj9mvpAT CuX7RWD8P3SXOSvKBQTb71FwKeFY+c68HEPKzUkDYoYI59yToe4VirrkZ76WP5q0KKTu jGAbtt6CKpjBjRJh3pEUB/95sARYDXm/7eWU3ef8p326OaFQnkkl4fY0XLlUI3EiMmSi fuevxJCBy8hHUGEkHG4jLxtUQAxJ0hKXk2DjXz+uSyKEiV29C0zbFYQbx+HnkRy/P5Te eKEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716480265; x=1717085065; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3d3iyJqmM/1eDHi6IVV043bTCqbOnpQe2A0l9FAURNs=; b=aYFvPuP+einmD1pGjXTxL8XBCKpQIsbIFcUHADUv+XGP8Wz//+eiNUrBqeeUyqwPJ+ TntzP2bYZE03dDjGwL+3Ub7NiGRKUtCcyAlDRnGSWDGXhxYXSYLt3AmprFCaBNOlNNAj araI/GQshczT+r9ioPrhD8rBBCxiQnwrqz4BJ4G/AYmazQIWli6E9aGDWc0PuHiv9gAj Xb0xXqE+0rDlj5MtFeqFGXLyUwz9idAaZnIZJv7Sj9wAloNMZjLoiWirmcowRAniuQVl /NZNFiho6KPyX7Dsdj2jvpaZHqG2QnEjoeAYvfrZ49lZeDzI7yxCNPzneVbrhRwVTXXU UnJA== X-Gm-Message-State: AOJu0YwcGElu6dqG21FbuztzwSFwCmbeEnhmoEXsUPRvngmK6UAcbXmv chqGXs07qAj4+SKP2xAuAlXMCPMsQvRZKOHsS6DrFTaTHvJyvI12wTGsOzVkzSKtGkv3YUXZ6JD TjBeT5ZPOrcx3p2ZXkqQCSsaUmw== X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6902:1207:b0:df4:db4d:5db2 with SMTP id 3f1490d57ef6-df4e0bcd6d0mr1593000276.7.1716480265117; Thu, 23 May 2024 09:04:25 -0700 (PDT) Date: Thu, 23 May 2024 16:04:13 +0000 In-Reply-To: <20240523160413.868830-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240523160413.868830-1-sebastianene@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240523160413.868830-3-sebastianene@google.com> Subject: [PATCH 2/2] misc: Register a PPI for the vcpu stall detection virtual device From: Sebastian Ene To: arnd@arndb.de, gregkh@linuxfoundation.org, will@kernel.org, maz@kernel.org, Rob Herring , Dragan Cvetic , Guenter Roeck Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel-team@android.com, Sebastian Ene Content-Type: text/plain; charset="UTF-8" Request a PPI for each vCPU during probe which will be used by the host to communicate a stall detected event on the vCPU. When the host raises this interrupt from the virtual machine monitor, the guest is expected to handle the interrupt and panic. Signed-off-by: Sebastian Ene --- drivers/misc/vcpu_stall_detector.c | 41 ++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/misc/vcpu_stall_detector.c b/drivers/misc/vcpu_stall_detector.c index e2015c87f03f..c580cd7fd225 100644 --- a/drivers/misc/vcpu_stall_detector.c +++ b/drivers/misc/vcpu_stall_detector.c @@ -32,6 +32,7 @@ struct vcpu_stall_detect_config { u32 clock_freq_hz; u32 stall_timeout_sec; + int ppi_irq; void __iomem *membase; struct platform_device *dev; @@ -77,6 +78,12 @@ vcpu_stall_detect_timer_fn(struct hrtimer *hrtimer) return HRTIMER_RESTART; } +static irqreturn_t vcpu_stall_detector_irq(int irq, void *dev) +{ + panic("vCPU stall detector"); + return IRQ_HANDLED; +} + static int start_stall_detector_cpu(unsigned int cpu) { u32 ticks, ping_timeout_ms; @@ -132,7 +139,7 @@ static int stop_stall_detector_cpu(unsigned int cpu) static int vcpu_stall_detect_probe(struct platform_device *pdev) { - int ret; + int ret, irq, num_irqs; struct resource *r; void __iomem *membase; u32 clock_freq_hz = VCPU_STALL_DEFAULT_CLOCK_HZ; @@ -169,9 +176,32 @@ static int vcpu_stall_detect_probe(struct platform_device *pdev) vcpu_stall_config = (struct vcpu_stall_detect_config) { .membase = membase, .clock_freq_hz = clock_freq_hz, - .stall_timeout_sec = stall_timeout_sec + .stall_timeout_sec = stall_timeout_sec, + .ppi_irq = -1, }; + num_irqs = platform_irq_count(pdev); + if (num_irqs < 0) { + dev_err(&pdev->dev, "Failed to get irqs\n"); + ret = num_irqs; + goto err; + } else if (num_irqs > 1) { + dev_err(&pdev->dev, "Multipple irqs detected\n"); + ret = -EINVAL; + goto err; + } else if (num_irqs == 1) { + irq = platform_get_irq(pdev, 0); + if ((irq > 0) && irq_is_percpu_devid(irq)) { + ret = request_percpu_irq(irq, + vcpu_stall_detector_irq, + "vcpu_stall_detector", + vcpu_stall_detectors); + if (!ret) + vcpu_stall_config.ppi_irq = irq; + + } + } + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "virt/vcpu_stall_detector:online", start_stall_detector_cpu, @@ -184,6 +214,9 @@ static int vcpu_stall_detect_probe(struct platform_device *pdev) vcpu_stall_config.hp_online = ret; return 0; err: + if (vcpu_stall_config.ppi_irq > 0) + free_percpu_irq(vcpu_stall_config.ppi_irq, + vcpu_stall_detectors); return ret; } @@ -193,6 +226,10 @@ static void vcpu_stall_detect_remove(struct platform_device *pdev) cpuhp_remove_state(vcpu_stall_config.hp_online); + if (vcpu_stall_config.ppi_irq > 0) + free_percpu_irq(vcpu_stall_config.ppi_irq, + vcpu_stall_detectors); + for_each_possible_cpu(cpu) stop_stall_detector_cpu(cpu); } -- 2.45.1.288.g0e0cd299f1-goog