From patchwork Tue Mar 10 07:28:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11428587 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 569771800 for ; Tue, 10 Mar 2020 07:30:05 +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 3AC9B2467C for ; Tue, 10 Mar 2020 07:30:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3AC9B2467C 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 1jBZK1-0001YM-SM; Tue, 10 Mar 2020 07:29:01 +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 1jBZK0-0001YC-R4 for xen-devel@lists.xenproject.org; Tue, 10 Mar 2020 07:29:00 +0000 X-Inumbo-ID: cede43a2-62a0-11ea-ad1e-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id cede43a2-62a0-11ea-ad1e-12813bfff9fa; Tue, 10 Mar 2020 07:28:59 +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 0E245AE2E; Tue, 10 Mar 2020 07:28:59 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Tue, 10 Mar 2020 08:28:51 +0100 Message-Id: <20200310072853.27567-5-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200310072853.27567-1-jgross@suse.com> References: <20200310072853.27567-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v4 4/6] xen/rcu: fix rcu_lock_domain() 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" rcu_lock_domain() misuses the domain structure as rcu lock, which is working only as long as rcu_read_lock() isn't evaluating the lock. Fix that by adding a rcu lock to struct domain and use that for rcu_lock_domain(). Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- xen/common/domain.c | 1 + xen/include/xen/rcupdate.h | 1 + xen/include/xen/sched.h | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 6ad458fa6b..b4eb476a9c 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -398,6 +398,7 @@ struct domain *domain_create(domid_t domid, goto fail; atomic_set(&d->refcnt, 1); + RCU_READ_LOCK_INIT(&d->rcu_lock); spin_lock_init_prof(d, domain_lock); spin_lock_init_prof(d, page_alloc_lock); spin_lock_init(&d->hypercall_deadlock_mutex); diff --git a/xen/include/xen/rcupdate.h b/xen/include/xen/rcupdate.h index 87f35b7704..31c8b86d13 100644 --- a/xen/include/xen/rcupdate.h +++ b/xen/include/xen/rcupdate.h @@ -65,6 +65,7 @@ int rcu_needs_cpu(int cpu); struct _rcu_read_lock {}; typedef struct _rcu_read_lock rcu_read_lock_t; #define DEFINE_RCU_READ_LOCK(x) rcu_read_lock_t x +#define RCU_READ_LOCK_INIT(x) /** * rcu_read_lock - mark the beginning of an RCU read-side critical section. diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 3a4f43098c..647e4d31fb 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -348,6 +348,8 @@ struct domain shared_info_t *shared_info; /* shared data area */ + rcu_read_lock_t rcu_lock; + spinlock_t domain_lock; spinlock_t page_alloc_lock; /* protects all the following fields */ @@ -634,13 +636,13 @@ int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d); static inline void rcu_unlock_domain(struct domain *d) { if ( d != current->domain ) - rcu_read_unlock(d); + rcu_read_unlock(&d->rcu_lock); } static inline struct domain *rcu_lock_domain(struct domain *d) { if ( d != current->domain ) - rcu_read_lock(d); + rcu_read_lock(&d->rcu_lock); return d; }