From nobody Thu Mar 28 16:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1602845948; cv=none; d=zohomail.com; s=zohoarc; b=kXWn46CRFXHAf5C4XwqUL4z4JEByT5M92YmSoE4tpxtmfktML/SkZ7r81Q+pl+q7y04aEA3TczdjBHSIZY4IcoDjkcB3Jel0YvP7aQRmG5hyoe8/60+n7IYhjAQBXzEKmelpH211FMbxcJMzLCiyz6HuIf7G/MMGWIBCdyiMz78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602845948; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3PiaK/obgiTv0XRvqmFG9GqAISyxz4e5B/+qnu8lyy8=; b=D8VPjNfuR0pYT2LZN7LRnlhWItLcxDF4mUl10gbYlzq/Vk6RHa1lVQyGW38QpRl5ItNo1F9ZtjKhpHZO8rOKIacKccNHAwXKMHWWSK/aT4yFiOuleZz/R7Kgg8E0Fm+wt5Y+f/32ET76qP5iHMWDRrwlwIXlbsFZOpYUKZMKsbk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602845948549822.1696066110419; Fri, 16 Oct 2020 03:59:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.7889.20822 (Exim 4.92) (envelope-from ) id 1kTNRe-0005sz-3v; Fri, 16 Oct 2020 10:58:46 +0000 Received: by outflank-mailman (output) from mailman id 7889.20822; Fri, 16 Oct 2020 10:58:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kTNRe-0005ss-0v; Fri, 16 Oct 2020 10:58:46 +0000 Received: by outflank-mailman (input) for mailman id 7889; Fri, 16 Oct 2020 10:58:44 +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.92) (envelope-from ) id 1kTNRc-0005rv-Kl for xen-devel@lists.xenproject.org; Fri, 16 Oct 2020 10:58:44 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 075dc980-4a36-40c8-ab3d-39aca8adcbe4; Fri, 16 Oct 2020 10:58:43 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BAA7DAD63; Fri, 16 Oct 2020 10:58:42 +0000 (UTC) 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.92) (envelope-from ) id 1kTNRc-0005rv-Kl for xen-devel@lists.xenproject.org; Fri, 16 Oct 2020 10:58:44 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 075dc980-4a36-40c8-ab3d-39aca8adcbe4; Fri, 16 Oct 2020 10:58:43 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BAA7DAD63; Fri, 16 Oct 2020 10:58:42 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 075dc980-4a36-40c8-ab3d-39aca8adcbe4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1602845922; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3PiaK/obgiTv0XRvqmFG9GqAISyxz4e5B/+qnu8lyy8=; b=ifARsuR09pu3ja6qReJpPDQA/5SsLNTgOlFQf4OCyEhKgdRLziNBAOvipfOzCGygq0ReE0 b1JP2WgcHPtbeBtwpMhNPLKtC+CTcUaVdMiAa3WhzUr8+WpM0nRAVN0ZKHm78Y/cQh5U7L ZjcjIRgljUqeTDxVZAvvn8HNPULiEMU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v3 1/2] xen/events: access last_priority and last_vcpu_id together Date: Fri, 16 Oct 2020 12:58:38 +0200 Message-Id: <20201016105839.14796-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201016105839.14796-1-jgross@suse.com> References: <20201016105839.14796-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" The queue for a fifo event is depending on the vcpu_id and the priority of the event. When sending an event it might happen the event needs to change queues and the old queue needs to be kept for keeping the links between queue elements intact. For this purpose the event channel contains last_priority and last_vcpu_id values elements for being able to identify the old queue. In order to avoid races always access last_priority and last_vcpu_id with a single atomic operation avoiding any inconsistencies. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- xen/common/event_fifo.c | 25 +++++++++++++++++++------ xen/include/xen/sched.h | 3 +-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c index fc189152e1..2f4e8c54fc 100644 --- a/xen/common/event_fifo.c +++ b/xen/common/event_fifo.c @@ -42,6 +42,14 @@ struct evtchn_fifo_domain { unsigned int num_evtchns; }; =20 +union evtchn_fifo_lastq { + uint32_t raw; + struct { + uint8_t last_priority; + uint16_t last_vcpu_id; + }; +}; + static inline event_word_t *evtchn_fifo_word_from_port(const struct domain= *d, unsigned int port) { @@ -86,16 +94,18 @@ static struct evtchn_fifo_queue *lock_old_queue(const s= truct domain *d, struct vcpu *v; struct evtchn_fifo_queue *q, *old_q; unsigned int try; + union evtchn_fifo_lastq lastq; =20 for ( try =3D 0; try < 3; try++ ) { - v =3D d->vcpu[evtchn->last_vcpu_id]; - old_q =3D &v->evtchn_fifo->queue[evtchn->last_priority]; + lastq.raw =3D read_atomic(&evtchn->fifo_lastq); + v =3D d->vcpu[lastq.last_vcpu_id]; + old_q =3D &v->evtchn_fifo->queue[lastq.last_priority]; =20 spin_lock_irqsave(&old_q->lock, *flags); =20 - v =3D d->vcpu[evtchn->last_vcpu_id]; - q =3D &v->evtchn_fifo->queue[evtchn->last_priority]; + v =3D d->vcpu[lastq.last_vcpu_id]; + q =3D &v->evtchn_fifo->queue[lastq.last_priority]; =20 if ( old_q =3D=3D q ) return old_q; @@ -246,8 +256,11 @@ static void evtchn_fifo_set_pending(struct vcpu *v, st= ruct evtchn *evtchn) /* Moved to a different queue? */ if ( old_q !=3D q ) { - evtchn->last_vcpu_id =3D v->vcpu_id; - evtchn->last_priority =3D q->priority; + union evtchn_fifo_lastq lastq =3D { }; + + lastq.last_vcpu_id =3D v->vcpu_id; + lastq.last_priority =3D q->priority; + write_atomic(&evtchn->fifo_lastq, lastq.raw); =20 spin_unlock_irqrestore(&old_q->lock, flags); spin_lock_irqsave(&q->lock, flags); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index d8ed83f869..a298ff4df8 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -114,8 +114,7 @@ struct evtchn u16 virq; /* state =3D=3D ECS_VIRQ */ } u; u8 priority; - u8 last_priority; - u16 last_vcpu_id; + u32 fifo_lastq; /* Data for fifo events identifying last queue. */ #ifdef CONFIG_XSM union { #ifdef XSM_NEED_GENERIC_EVTCHN_SSID --=20 2.26.2