Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1890592imm; Thu, 11 Oct 2018 01:17:05 -0700 (PDT) X-Google-Smtp-Source: ACcGV61qs3LcpewOwAlv5JtPykMpbgbAhEhPSpuNUOfvi/FvA2XLsDre7qmKGMeculUV9W1vlypx X-Received: by 2002:a63:646:: with SMTP id 67-v6mr505413pgg.230.1539245825785; Thu, 11 Oct 2018 01:17:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539245825; cv=none; d=google.com; s=arc-20160816; b=XpkMY+UwCOd3Prsh5/qwvV/0ITNjKKsGmCh3jjtszhDc9D8sD1IpKnRveCXXXn53mL G0SFAG78FA+9q17sFq+0I3KpA6QDyXuNMN3KlcaTnSCKiQnPOw5Pg+9t9LOvzB99pkDQ crN9UI5IKSUvaoc5hIeVZHiO0Mi3yD7cXLBtn4RQP2DqPLuMhqXP/jukf9oQVge1G/Lq whwbGKORH0ncUxwe7wkQSK9f9UeCzY2uluv2je0iQ72KW1GNu0U0aJMVwDglRdbxqSCB mCP0OGQQpNPnzRGhUifamRWQ0h/qdRkc5eUwoOK6cV+8vhPiHT+QHKoFeHDPopiz3jYF +iiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=d12y+ockzhXJH0TpWpp6L28F6LM4TlHubeWxTlxeIeI=; b=KtPEgyzxqNNjuk9FXTcpN/fcLD+twyJ4PgDwWIGUjENGFe71/xktBZzcnDbfbLBNfu LHSEbLP7rqOOWd9FGB4+xzr6sUN+UUgT9LhjLYRL2xvmE84FWl4/GxvfPLHajdJGWlYs +wKHIi9na9o2rvOC5up4Qz/rlvyAZHvrajENO6LAQYPAQXYoBd8EtwGl5oz1W2DPBiXH WFD9tkC1j2KDCkXFww4LVOG36Du4J8/fFrv2b+/UDSlppwyPRi09PaI86qBmpR8zD1+r 54zR9qomQD+Nqoyk4fFJ0h7m7HZmSt8exKaiNTubTYl7X0HvcBZOSmQh06Y8ogLhpG/e LQAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZWcCubWi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j3-v6si27960184pld.380.2018.10.11.01.16.51; Thu, 11 Oct 2018 01:17:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZWcCubWi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728071AbeJKP3f (ORCPT + 99 others); Thu, 11 Oct 2018 11:29:35 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:34000 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727983AbeJKP3f (ORCPT ); Thu, 11 Oct 2018 11:29:35 -0400 Received: by mail-it1-f194.google.com with SMTP id l127-v6so18146206ith.1 for ; Thu, 11 Oct 2018 01:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=d12y+ockzhXJH0TpWpp6L28F6LM4TlHubeWxTlxeIeI=; b=ZWcCubWiQHimSR7/kAE6RojrQuAyq0c7geLi/zHhALNHDdOJzL71cR7oAxDlHg1c6b hk+BfkF7cbrsswcJM4y5XenoBcwjKZ9aJgFo6JXUStwSZoCQNEesB8AXSeNwbu5/VOHD nT+PX9zEPX41xQnIaM3BO/vL5lbXvPCI8GO3XF2uJXJ/SOGivTOeDhRRuLJfSkTeSoNs AwFu+V7tRCuBNFXQLp2DrEJJ1SFG10+cJdOl8uNjywKep6Q4/qUSLoSwaFaQ1v8/jUqc ijsyBPxA9N3xL3wqdCLpcRMxktvJ4sLUwg6jWBAjzFP5fHXysEAOsYROzjkfGKaEaocg A85A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=d12y+ockzhXJH0TpWpp6L28F6LM4TlHubeWxTlxeIeI=; b=k7y/fBKsaoEx11GuLDrfBWtasDNDbSeVPGiOAUfvtP+dq4S0RaMlk6mz/6/tP6D5LV djMWxC0Qe5+9hr7SA9iouVSlk5zqSMjvmgYTlBDdl+rSDTIfiqN8x9djhi3tes66I/ZL xlUMzBq9wwy//zPjAtRaxbPCCLBwXqKd7EvchFHE1uWDmPNyHCeD4J0w2zwy32qayv82 PuH+YYv0Uy+3hJYITggapxOPmddk6nWibHyLOI/o40C+uPvX/Xom6NVkxVKyas32Zdlc jSVKwQ9tQMytnjl30QZLEXhgJDVh7/+k0GenODAVtonFxF0xv1G/ZVkswkKk3d2ROgZu fBag== X-Gm-Message-State: ABuFfoigBnUk/++8mCNDnPj/ZUumaJYcZfvlzGs/gnVI6B7PvsKML16u TNjaMzFM4WPJE9OwlX+si+8p6tH4YlgKr4t5u4L/rQ== X-Received: by 2002:a02:97c5:: with SMTP id v5-v6mr388808jaj.72.1539245006985; Thu, 11 Oct 2018 01:03:26 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:1003:0:0:0:0:0 with HTTP; Thu, 11 Oct 2018 01:03:06 -0700 (PDT) In-Reply-To: <20181010214945.5owshc3mlrh74z4b@linutronix.de> References: <20180918152931.17322-1-williams@redhat.com> <20181005163018.icbknlzymwjhdehi@linutronix.de> <20181005163320.zkacovxvlih6blpp@linutronix.de> <20181009142742.ikh7xv2dn5skjjbe@linutronix.de> <20181010092929.a5gd3fkkw6swco4c@linutronix.de> <20181010095343.6qxved3owi6yokoa@linutronix.de> <20181010214945.5owshc3mlrh74z4b@linutronix.de> From: Dmitry Vyukov Date: Thu, 11 Oct 2018 10:03:06 +0200 Message-ID: Subject: Re: [PATCH] mm/kasan: make quarantine_lock a raw_spinlock_t To: Sebastian Andrzej Siewior Cc: Clark Williams , Alexander Potapenko , kasan-dev , Linux-MM , LKML , linux-rt-users@vger.kernel.org, Peter Zijlstra , Thomas Gleixner , Andrew Morton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 10, 2018 at 11:49 PM, Sebastian Andrzej Siewior wrote: > From: Clark Williams > Date: Tue, 18 Sep 2018 10:29:31 -0500 > > The static lock quarantine_lock is used in quarantine.c to protect the > quarantine queue datastructures. It is taken inside quarantine queue > manipulation routines (quarantine_put(), quarantine_reduce() and > quarantine_remove_cache()), with IRQs disabled. > This is not a problem on a stock kernel but is problematic on an RT > kernel where spin locks are sleeping spinlocks, which can sleep and can > not be acquired with disabled interrupts. > > Convert the quarantine_lock to a raw spinlock_t. The usage of > quarantine_lock is confined to quarantine.c and the work performed while > the lock is held is used for debug purpose. > > Signed-off-by: Clark Williams > Acked-by: Sebastian Andrzej Siewior > [bigeasy: slightly altered the commit message] > Signed-off-by: Sebastian Andrzej Siewior Acked-by: Dmitry Vyukov > --- > On 2018-10-10 11:57:41 [+0200], Dmitry Vyukov wrote: >> Yes. Clark's patch looks good to me. Probably would be useful to add a >> comment as to why raw spinlock is used (otherwise somebody may >> refactor it back later). > > If you really insist, I could add something but this didn't happen so > far. git's changelog should provide enough information why to why it was > changed. > > mm/kasan/quarantine.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > --- a/mm/kasan/quarantine.c > +++ b/mm/kasan/quarantine.c > @@ -103,7 +103,7 @@ static int quarantine_head; > static int quarantine_tail; > /* Total size of all objects in global_quarantine across all batches. */ > static unsigned long quarantine_size; > -static DEFINE_SPINLOCK(quarantine_lock); > +static DEFINE_RAW_SPINLOCK(quarantine_lock); > DEFINE_STATIC_SRCU(remove_cache_srcu); > > /* Maximum size of the global queue. */ > @@ -190,7 +190,7 @@ void quarantine_put(struct kasan_free_me > if (unlikely(q->bytes > QUARANTINE_PERCPU_SIZE)) { > qlist_move_all(q, &temp); > > - spin_lock(&quarantine_lock); > + raw_spin_lock(&quarantine_lock); > WRITE_ONCE(quarantine_size, quarantine_size + temp.bytes); > qlist_move_all(&temp, &global_quarantine[quarantine_tail]); > if (global_quarantine[quarantine_tail].bytes >= > @@ -203,7 +203,7 @@ void quarantine_put(struct kasan_free_me > if (new_tail != quarantine_head) > quarantine_tail = new_tail; > } > - spin_unlock(&quarantine_lock); > + raw_spin_unlock(&quarantine_lock); > } > > local_irq_restore(flags); > @@ -230,7 +230,7 @@ void quarantine_reduce(void) > * expected case). > */ > srcu_idx = srcu_read_lock(&remove_cache_srcu); > - spin_lock_irqsave(&quarantine_lock, flags); > + raw_spin_lock_irqsave(&quarantine_lock, flags); > > /* > * Update quarantine size in case of hotplug. Allocate a fraction of > @@ -254,7 +254,7 @@ void quarantine_reduce(void) > quarantine_head = 0; > } > > - spin_unlock_irqrestore(&quarantine_lock, flags); > + raw_spin_unlock_irqrestore(&quarantine_lock, flags); > > qlist_free_all(&to_free, NULL); > srcu_read_unlock(&remove_cache_srcu, srcu_idx); > @@ -310,17 +310,17 @@ void quarantine_remove_cache(struct kmem > */ > on_each_cpu(per_cpu_remove_cache, cache, 1); > > - spin_lock_irqsave(&quarantine_lock, flags); > + raw_spin_lock_irqsave(&quarantine_lock, flags); > for (i = 0; i < QUARANTINE_BATCHES; i++) { > if (qlist_empty(&global_quarantine[i])) > continue; > qlist_move_cache(&global_quarantine[i], &to_free, cache); > /* Scanning whole quarantine can take a while. */ > - spin_unlock_irqrestore(&quarantine_lock, flags); > + raw_spin_unlock_irqrestore(&quarantine_lock, flags); > cond_resched(); > - spin_lock_irqsave(&quarantine_lock, flags); > + raw_spin_lock_irqsave(&quarantine_lock, flags); > } > - spin_unlock_irqrestore(&quarantine_lock, flags); > + raw_spin_unlock_irqrestore(&quarantine_lock, flags); > > qlist_free_all(&to_free, cache); >