Received: by 2002:ab2:6816:0:b0:1f8:1780:a4ed with SMTP id t22csp35290lqo; Thu, 9 May 2024 10:27:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWzoId2grMRkRQTSrKzGZoLSys9gP+OXdHWdsztysRTtHGEwBB+LqGN2riG7p9acteJjnRb6C7cS0VFdzKpVdJ7+UudKFeA3nay/rqEFg== X-Google-Smtp-Source: AGHT+IFXV3lE4Buy46voCtjqxQIgA6ZF+RblM02QJldZTbPftBKzediOr/AwzdLZd/GPG2LwpVfG X-Received: by 2002:a2e:742:0:b0:2dc:d2c5:ec8 with SMTP id 38308e7fff4ca-2e52028d7d9mr621001fa.39.1715275646195; Thu, 09 May 2024 10:27:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715275646; cv=pass; d=google.com; s=arc-20160816; b=KOxfFXYgpu8xRKK62PxIomhx42XTKusYbp7lU6tsQNpXZuEIX390qP2Cj8bRhTCMHB PqIzrmMrLSy6uKAKrELyHNOGNW/MIUByGI4mPC78bcQ5DzYXzyRQkYu7gBvx1MMUHS3j PPXJbLP9dy0uqsC8Umiwvwxd7ymk/80+lZxyUKKR4B6+dPX4r0n0HbcqmpI7zKZHxQes Ps8obkLzFPa9/ctQLLzL/liOL+kC415Az4LwvAmp4KN87jw4qduZYcZOXS+1JFE4P8TD KLnRgpqQOsZJ9NTkf1hvuShdcB7GEzOyiHHKUIyqTfEgxwia96uYpl2ljlda1HiaCjRU QkVg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Gk24WOVBQ8v9+/xBnGWVKv0pPEAEDr8oetxf6a2mo9U=; fh=dcBFDQXWFD4njHohMTbdFGzBUfJZTOQlvKFGisgANo4=; b=gScsLnD52Zx7gSLFKClSa+VUtAcnpaZfXMsSrplm58oyuQGARF95Hzul3Rjw43MduJ i5U5yb3lASt0auQUW9ZsC4Aw8E9omvteBcPHE1C5aqmHP5EfI00Rjay34jxulOuxybba QfOo6GdKN86iOX9nZffVe+6yzx+tPrR78IvhckWyfAA4mqJlP9D3dHv7J0d6M+gEpIQQ QHo5b4o5zgML4ESGX+NLNPiWZqmyI7h22ps7QDGodHGR3iyLYOWrZENcJSbtxRlqKdPH Yzom4qtITD8ERNkNR4dmqEHGs6potW2SEPQvUxZNisz0F/s8T1x724s0xY3+nNbEnQ+0 Gn9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JR95zewp; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-174725-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174725-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733beac54csi969948a12.69.2024.05.09.10.27.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:27:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174725-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JR95zewp; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-174725-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174725-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 2C4671F2375D for ; Thu, 9 May 2024 17:22:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85BEC11198; Thu, 9 May 2024 17:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JR95zewp" Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (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 3B25E4C8B for ; Thu, 9 May 2024 17:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715275247; cv=none; b=aen1u3mKjjYvOUE/fikNY6fnQus8bZ6H9rlyswlRs4RWxoGS/DRGYAuVnTPDdbqtu3nLuiouLufdzeot0Ag/ZmaQjCBfSfH6/lGbv6bIVVeHagCfRs1LyfF4nECVenI55Yo8ILsV/usE6QpapdxXvzfJ8yUS9C1h8quCUs9gWeM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715275247; c=relaxed/simple; bh=2VdN5360nE8Rs4Q7QfvHLL88JPhHZUayj90hKIeFeKU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=oJN9j3CqH+mH8HdN1w2F5r4A9C05Z2L2YhQjD5AefrT9fw9FC42L+iKm4wex6yfYpz8r5M4T4dCXKxCcsxVuaLEikPqAGPgSklpAAOckURrZAKxuUFl8VQ5IzmdGWphr3FSmpacFdYvgLmGlgPQII8ayzrLrWrua4XlhyrAB0F4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JR95zewp; arc=none smtp.client-ip=209.85.128.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-62036051972so12080857b3.1 for ; Thu, 09 May 2024 10:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275245; x=1715880045; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Gk24WOVBQ8v9+/xBnGWVKv0pPEAEDr8oetxf6a2mo9U=; b=JR95zewpqMiYUQTLn/tncro0IKycIF9yEsmQ/qLFdbhShVp7ZirIGh7RMRXriwPUos wTQhWLdFRTBlphT/bNh2MWvAo0VDaz2ufTzAMPpgHO77eLnq5rC5YYmuFX/mVKE7F0vX G62+8uD/Q1fGn7LwjznLOiRHUWd/FcacaoPMDffxV1JadPlrObTLysSWAivaje55NQ5B +Hgtw5gCkaWsMjYQrLk81AYdb6Dl5jRYrOVeM7W3uU5oR8fD2EZ6Vw4V+reAof33Onnm +BO3h9fGbfCg6ojLvmEuHT/WAr92O6xpWGyicae79CosKucJEwfoE8KFRNE8xeQ8qn5J uiXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275245; x=1715880045; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gk24WOVBQ8v9+/xBnGWVKv0pPEAEDr8oetxf6a2mo9U=; b=MDnRwKvwq9ZRsAbeFMCqIk0n8sJ/v0Os6RZd1Td5Cquch4Y5b4qSwh+5AUCoD2xhdp FFk666nzR5pI6pjp2TdQOdVBVFpwZy8mS0W45x6oBDKP+peSSY/iz48Wp0tV4TDwWBow kBStho/vFReOpGyeMjeDxvNfu4jqKVhyptxnW5sxcnyHTyWJO8CdHzjPNAszD/zgUtIA POcBlPbn8AVTJrxq12b4sLVLmZQAakAoeuTHb6hn8AAda0wlKgKc3yjZWPWJmSZI+eLR ha1DlLEnXtH3k8Wh9tW44AP/hqb9C8WKjcU2XLK6qVapAdEou0e0q2o7UxAi1Ck5Uz90 kvCw== X-Forwarded-Encrypted: i=1; AJvYcCU/2BYo5cet58sMaDMW9aZlf9KoaSoftHy109Qoe7OFS4aiRKxfbBX8Pm3Bh0VjmVPNZohvRQH0KNLJP+5Odgn6hlo9k/L9EaBqpDNw X-Gm-Message-State: AOJu0YyaRZhOkQB+pthVn/zykPO+ryAHgqYdNrI4mEPgxMKc7GWDj4K/ z4rzs/m/ltpwEEQ/Q/fpWI7YwAvgNkxuFjZC9Zorx/AvTDGACR6jUPfnvkf+Ay4SnVrtCZrjaqk hZT5uUv8GQZ2SXAh+9c8COdJq5yM= X-Received: by 2002:a05:690c:4382:b0:618:79f5:8d32 with SMTP id 00721157ae682-622b0164185mr1225457b3.48.1715275245056; Thu, 09 May 2024 10:20:45 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Muni Sekhar Date: Thu, 9 May 2024 22:50:33 +0530 Message-ID: Subject: Re: Seeking Assistance with Spin Lock Usage and Resolving Hard LOCKUP Error To: "Billie Alsup (balsup)" Cc: kernelnewbies , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 9, 2024 at 8:56=E2=80=AFPM Billie Alsup (balsup) wrote: > > >From: Muni Sekhar > > >Here is a brief overview of how I have implemented spin locks in my modu= le: > > > >spinlock_t my_spinlock; // Declare a spin lock > > > >// In ISR context (interrupt handler): > >spin_lock_irqsave(&my_spinlock, flags); > >// ... Critical section ... > >spin_unlock_irqrestore(&my_spinlock, flags); > > > > > >// In process context: (struct file_operations.read) > >spin_lock(&my_spinlock); > >// ... Critical section ... > >spin_unlock(&my_spinlock); > > from my understanding, you have the usage backwards. It is the irqsave/i= rqrestore versions that should be used within process context to prevent th= e interrupt from being handled on the same cpu while executing in your crit= ical section. > > The use of irqsave/irqrestore within the isr itself is ok, although perha= ps unnecessary. It depends on whether the interrupt can occur again while = you are servicing the interrupt (whether on this cpu or another). Usually = (?) the same interrupt does not nest, unless you have explicitly coded to a= llow it (for example, by acknowledging and re-enabling the interrupt early = in your ISR). Certainly the spinlock is necessary to protect the critical s= ection from running in an isr on one cpu and process space on another cpu. > In the scenario where an interrupt occurs while we are servicing the interrupt, and in the scenario where it doesn't occur while we are servicing the interrupt, when should we use the spin_lock_irqsave/spin_unlock_irqrestore APIs? > From a lockup perspective, not doing the irqsave/irqrestore from process = context could explain your problem. Also look for code (anywhere!) that bli= ndly enables interrupts, rather than doing irqrestore from a prior irqsave. --=20 Thanks, Sekhar