From patchwork Thu Mar 12 08:28:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 11433557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDD8E1709 for ; Thu, 12 Mar 2020 08:29:49 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D4EF9206F7 for ; Thu, 12 Mar 2020 08:29:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4EF9206F7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCJCo-0004tp-Rw; Thu, 12 Mar 2020 08:28:38 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCJCn-0004te-Uw for xen-devel@lists.xenproject.org; Thu, 12 Mar 2020 08:28:37 +0000 X-Inumbo-ID: 76d89564-643b-11ea-b127-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 76d89564-643b-11ea-b127-12813bfff9fa; Thu, 12 Mar 2020 08:28:36 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BF02EB1E3; Thu, 12 Mar 2020 08:28:34 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Thu, 12 Mar 2020 09:28:29 +0100 Message-Id: <20200312082831.22280-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200312082831.22280-1-jgross@suse.com> References: <20200312082831.22280-1-jgross@suse.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 2/4] xen: don't process rcu callbacks when holding a rcu_read_lock() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Some keyhandlers are calling process_pending_softirqs() while holding a rcu_read_lock(). This is wrong, as process_pending_softirqs() might activate rcu calls which should not happen inside a rcu_read_lock(). For that purpose modify process_pending_softirqs() to not allow rcu callback processing when a rcu_read_lock() is being held. Signed-off-by: Juergen Gross --- V3: - add RCU_SOFTIRQ to ignore in process_pending_softirqs_norcu() (Roger Pau Monné) V5: - block rcu processing depending on rch_read_lock() being held or not (Jan Beulich) --- xen/common/softirq.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xen/common/softirq.c b/xen/common/softirq.c index b83ad96d6c..00d676b62c 100644 --- a/xen/common/softirq.c +++ b/xen/common/softirq.c @@ -29,6 +29,7 @@ static void __do_softirq(unsigned long ignore_mask) { unsigned int i, cpu; unsigned long pending; + bool rcu_allowed = !(ignore_mask & (1ul << RCU_SOFTIRQ)); for ( ; ; ) { @@ -38,7 +39,7 @@ static void __do_softirq(unsigned long ignore_mask) */ cpu = smp_processor_id(); - if ( rcu_pending(cpu) ) + if ( rcu_allowed && rcu_pending(cpu) ) rcu_check_callbacks(cpu); if ( ((pending = (softirq_pending(cpu) & ~ignore_mask)) == 0) @@ -53,9 +54,16 @@ static void __do_softirq(unsigned long ignore_mask) void process_pending_softirqs(void) { + unsigned long ignore_mask = (1ul << SCHEDULE_SOFTIRQ) | + (1ul << SCHED_SLAVE_SOFTIRQ); + + /* Block RCU processing in case of rcu_read_lock() held. */ + if ( preempt_count() ) + ignore_mask |= 1ul << RCU_SOFTIRQ; + ASSERT(!in_irq() && local_irq_is_enabled()); /* Do not enter scheduler as it can preempt the calling context. */ - __do_softirq((1ul << SCHEDULE_SOFTIRQ) | (1ul << SCHED_SLAVE_SOFTIRQ)); + __do_softirq(ignore_mask); } void do_softirq(void)