Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3728100pxb; Mon, 24 Jan 2022 16:30:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwg81T017hM/0tnVUYZWWSBohKAZx3mUmi/rKXCGUPjbxxk8NdgPc7I1BicsFeRVlg+2N+c X-Received: by 2002:a05:6a00:21c7:b0:4c6:8696:1578 with SMTP id t7-20020a056a0021c700b004c686961578mr15881786pfj.83.1643070617394; Mon, 24 Jan 2022 16:30:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643070617; cv=none; d=google.com; s=arc-20160816; b=odi6kOs+l6vKfm0eP3XUNK9Ak8WSRcb8lhKx55f0DqH1Jm0tK0My0fh2eEavohEfFG zwjW+EZIVDao2wqWervhghAQJFfNhE59fWOlfj/Nb3FNuhEnt006OBxw3w1K2NnwvulX 1miQa1i4EEvNDsdy7EyQlfOglHI/VH0jQf2IoHOVXp5GiGMj408r8s7Ezqaso783g61v kkgfAoBlGTt5J0P1fCV7LoBsn290t1Cem/6vezqb8z0r3Ic5mW6/7DxaYQ1fsV/4MV2o w1G8ECjzD0B4ex0tP944g8PTM2H58JZOSqq7ykdHj4Pwcutc46Hvg0B3IB1H4kWecy3h 2tGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b4UdjSz5NYtQinQlQ94XoaqaHbQcVUOxbqVn67Al5y4=; b=hgXSeWYFC60swsC3TU1juhzdFOBs3OuUz8eA+hJDAlK56QnRdVEIOkgwLo79MZYUcM qfKi3MuK99XvH9b0YvJAUlDop6wP9JzYuXq77vEViPuYzg32hktteHAAxHkqVqF/u7Wz Vic14TJHpIJroRWj4HXYhpgbHW67xAco5oF7Xwjv9lxdt8qt3e4VFOx/GkFUBgU5oAcG tTI56ILHQ201LBdXYkkhLFMRuAuBl2VeCwxjBAZXwCO9NRBEthUyI7PwjHHxsJwJpH+G pbzFCq2Pnmz9Ftg/X7o6EhNTWDk7N/WGga0ZLZTr8d8ufgleKvXFX+TlbkrPOfnNgZau xNLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yWNekzEQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si14248752plk.619.2022.01.24.16.30.04; Mon, 24 Jan 2022 16:30:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yWNekzEQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2374676AbiAYARk (ORCPT + 99 others); Mon, 24 Jan 2022 19:17:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1851079AbiAXXbx (ORCPT ); Mon, 24 Jan 2022 18:31:53 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B4F3C075D05; Mon, 24 Jan 2022 13:35:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DFAEA614DA; Mon, 24 Jan 2022 21:35:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F398EC340E4; Mon, 24 Jan 2022 21:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060112; bh=Ss+KyW9+v4+zPtZvCbZxmRTFAjt5mNV30rcy4WIJht8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yWNekzEQUQtqfBF5fITcfnD2mTnVfsxE84QV8hBwtkOu3Eb9Ej9/1DpOpzmw+aksj Nbkm6oyD1O4LwgU//ol81hQmwKtqbLk66WgCL/BawK3vTQJjVdg/Ou1qqfNAugcJOx JYE08hIMDtx5J+DcfxD8xO5ltwKE8SXr1AeHrqts= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksandr Andrushchenko , Boris Ostrovsky , Juergen Gross Subject: [PATCH 5.16 0844/1039] xen/gntdev: fix unmap notification order Date: Mon, 24 Jan 2022 19:43:53 +0100 Message-Id: <20220124184153.659861284@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleksandr Andrushchenko commit ce2f46f3531a03781181b7f4bd1ff9f8c5086e7e upstream. While working with Xen's libxenvchan library I have faced an issue with unmap notifications sent in wrong order if both UNMAP_NOTIFY_SEND_EVENT and UNMAP_NOTIFY_CLEAR_BYTE were requested: first we send an event channel notification and then clear the notification byte which renders in the below inconsistency (cli_live is the byte which was requested to be cleared on unmap): [ 444.514243] gntdev_put_map UNMAP_NOTIFY_SEND_EVENT map->notify.event 6 libxenvchan_is_open cli_live 1 [ 444.515239] __unmap_grant_pages UNMAP_NOTIFY_CLEAR_BYTE at 14 Thus it is not possible to reliably implement the checks like - wait for the notification (UNMAP_NOTIFY_SEND_EVENT) - check the variable (UNMAP_NOTIFY_CLEAR_BYTE) because it is possible that the variable gets checked before it is cleared by the kernel. To fix that we need to re-order the notifications, so the variable is first gets cleared and then the event channel notification is sent. With this fix I can see the correct order of execution: [ 54.522611] __unmap_grant_pages UNMAP_NOTIFY_CLEAR_BYTE at 14 [ 54.537966] gntdev_put_map UNMAP_NOTIFY_SEND_EVENT map->notify.event 6 libxenvchan_is_open cli_live 0 Cc: stable@vger.kernel.org Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Boris Ostrovsky Link: https://lore.kernel.org/r/20211210092817.580718-1-andr2000@gmail.com Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- drivers/xen/gntdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -250,13 +250,13 @@ void gntdev_put_map(struct gntdev_priv * if (!refcount_dec_and_test(&map->users)) return; + if (map->pages && !use_ptemod) + unmap_grant_pages(map, 0, map->count); + if (map->notify.flags & UNMAP_NOTIFY_SEND_EVENT) { notify_remote_via_evtchn(map->notify.event); evtchn_put(map->notify.event); } - - if (map->pages && !use_ptemod) - unmap_grant_pages(map, 0, map->count); gntdev_free_map(map); }