Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp195002lql; Fri, 12 Apr 2024 07:46:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXwR9G5nsTMy7ViDaaAvbXD9PGBfDnJbT0I8R4eb93RpQxViaL6SSZyzl/5xLVvbXDto6TgESlMu4hevxC4sfdmdehOH+3E86QGLdOVOA== X-Google-Smtp-Source: AGHT+IGe310LwUIPbd519hMuv8d/AL16+FvlCxNURQc5JutuY9NT1KUjqbT69sau7hexkrjY2iqd X-Received: by 2002:a17:902:e841:b0:1e4:c75e:aae2 with SMTP id t1-20020a170902e84100b001e4c75eaae2mr3166216plg.59.1712933208316; Fri, 12 Apr 2024 07:46:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712933208; cv=pass; d=google.com; s=arc-20160816; b=uY3Kp3e09H5gqPt9W6+D9fDQqcrOwmUuStSM/LkgrRJCPZFmADHWVhzTK15dSEEZxc KjHeKq26uGAQuscDVTCjmgWMH7Sam4Cx6zvD101TFeGO91NwrAJV5TY9nhtssFOs1JiW UydtQ2JXF2/j6YwJkDpzbvv2QFC/7IRmuRvPuwudst7A1zvkyAtCCATnFUsvP/LpQcwX 7Z1st9AzDN0iYX/A285HMhCjbfMShq0amk11YsFe29RsiDumrZxr2dFWskvMcj5tOXOX b7fgu687cBPJ10cbacXDusz29oCtfd41NeGc6nF5EspJQj3JNx3oYXvPwulEP2MIpzFg oT+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=k/w83GnUvUHZbz+UTHAih1AffSV0m2Aw7yhXR77HCXU=; fh=1LQ4AYYqRh3b7ekqjesKbHLq6et17oV1SnCTHd61zjw=; b=fm0kMr9bOEQF+BKnMRR5FQWiyrpy5+smyz3JUvoZJwOH6C5frtFVMXx1vwxPmWP7Ua hOZH5IYW7yTg0+7ig/p/0LLnmV1SnXgIUfwG1YwYX7C0B1eFG2mEIQlNMxTaa2FEYgBQ sezF7wMfBQ6zVjzE2mrfCAu3D6ufRSKoqsbn7uhB0h9fGaBFa6eaLfpjIG/s0OVC5rDe 5cjkyEf+TZ1RriJFmyiwRB0KtqUotEqfvhnyNXGjUeGw3dQrvEqqVUnKNm6oMloH+SDm wbIqLK6egqGyS69icrUDVvaTtQ7buBLsl8twxKTfJztl1r8EEWWWEGR0HZsu+F3yOyHE Iw2Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="q9/qT5zn"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-142846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142846-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id lk6-20020a17090308c600b001e59e466568si1631001plb.184.2024.04.12.07.46.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 07:46:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="q9/qT5zn"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-142846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142846-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 03251B248D4 for ; Fri, 12 Apr 2024 14:35:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F029C13D61A; Fri, 12 Apr 2024 14:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q9/qT5zn" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12667205E22; Fri, 12 Apr 2024 14:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712932544; cv=none; b=O8yeeYlryQ6wcGOE/7uJ8t4ES8BGEqrTEXcx9kj8n6zwG4L+dD6X7cRDdssI6x/DpyOBWqYpVb282yK29ayMnbTiyoSIWqMbGMwI17vBsoEYO2OhCYneT7Y6A5rgMYK0ena8BqweVh9QCJWotR3JrEYuFyyzqLRkn/OZN7frUsY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712932544; c=relaxed/simple; bh=O3nJ43+rFmMOBYnN5dpRArxVDL7kzbTHUko/HHy6Vw8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=QjPZDJmd6qzsy1yKIvG5QBZLHwj72EMhSDcft4hg2dRVRkV+ZdNKNIWpG+G0Hqo/5sUTQsfWXulPUDsGyGbaNi0aUJ5MD6FUTyZisVlF2Vyw261KC4Jzx1WLenmNthbgK3u1LmreNp5dmk2rY/rWQC8V1JAYmVkxOoQ6pu9uCnQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q9/qT5zn; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F634C32783; Fri, 12 Apr 2024 14:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712932543; bh=O3nJ43+rFmMOBYnN5dpRArxVDL7kzbTHUko/HHy6Vw8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=q9/qT5znh72zB+98BEW0nAZrnGAzabUQxyfLyLzuZBHGOaWNqjBwu+hRNAHC8fA3M mSTW1F9bbr7RUaVWsQ8tCdR0FBd3iHNcjf2Z5q9AX5SbTmvNhpqX45o7YWBVv8TrOA lHp1V7/oHuiTg3dGUnef89Zgn4R8pVjz/rpizkJdrGywSuYl+URusB45ztW7h2shMT G2h1a2pRsq7ZjmB+nCQ85OqklOryC6fItX1q8Jm2pf+RCYarjzxHg4Q9D3+QGv4gfK J73gxwYjOTAbzPM74qG6DXNKQSLX8ePxRvzFx3iLpRsWzMijQZy0LtPcNq0byNoaiF 4nnqtfhoziH0A== Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-516ef30b16eso1159650e87.3; Fri, 12 Apr 2024 07:35:43 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUGmsd1cwovosHI1Peynv4+R1Qx3PKEFkutcAt0KKqBPvNUe4z0z5IzbXRur7lsVQOhpvnuSu5r6GvsdefXhf+qPMP9LDG4aSq32086ALM5JO6YgQQ3WKnz0fzoC0M5S7oZs2TFdwE1AQ== X-Gm-Message-State: AOJu0YxmggnfStIjFAL7PMytxHUtQ8KdkfWgObp7Caj289DXuiC3u5BB 9wUaSlCyCCulz5La9aRypkkI0vHy3sKlXRa6CWtMJqoU83tMyefGet5Pc0Og7hboQ8aWgaXzwlm l9qPzeYAiD8IyztDRLx7qhvBzUhQ= X-Received: by 2002:a19:910c:0:b0:513:ccda:bc86 with SMTP id t12-20020a19910c000000b00513ccdabc86mr1770884lfd.4.1712932541923; Fri, 12 Apr 2024 07:35:41 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240301130532.3953167-1-chenhuacai@loongson.cn> <20240301130532.3953167-2-chenhuacai@loongson.cn> <20240412133235.GA27868@willie-the-truck> In-Reply-To: <20240412133235.GA27868@willie-the-truck> From: Huacai Chen Date: Fri, 12 Apr 2024 22:35:28 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] mmiowb: Hook up mmiowb helpers to mutexes as well as spinlocks To: Will Deacon Cc: Huacai Chen , Peter Zijlstra , Ingo Molnar , Arnd Bergmann , Waiman Long , Boqun Feng , Guo Ren , Rui Wang , WANG Xuerui , Jiaxun Yang , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, mpe@ellerman.id.au Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Will, On Fri, Apr 12, 2024 at 9:32=E2=80=AFPM Will Deacon wrote= : > > On Fri, Mar 01, 2024 at 09:05:32PM +0800, Huacai Chen wrote: > > Commit fb24ea52f78e0d595852e ("drivers: Remove explicit invocations of > > mmiowb()") remove all mmiowb() in drivers, but it says: > > > > "NOTE: mmiowb() has only ever guaranteed ordering in conjunction with > > spin_unlock(). However, pairing each mmiowb() removal in this patch wit= h > > the corresponding call to spin_unlock() is not at all trivial, so there > > is a small chance that this change may regress any drivers incorrectly > > relying on mmiowb() to order MMIO writes between CPUs using lock-free > > synchronisation." > > > > The mmio in radeon_ring_commit() is protected by a mutex rather than a > > spinlock, but in the mutex fastpath it behaves similar to spinlock. We > > can add mmiowb() calls in the radeon driver but the maintainer says he > > doesn't like such a workaround, and radeon is not the only example of > > mutex protected mmio. > > Oh no! Ostrich programming is real! > > https://lore.kernel.org/lkml/CAHk-=3Dwgbnn7x+i72NqnvXotbxjsk2Ag56Q5YP0OSv= hY9sUk7QA@mail.gmail.com/ Yes, you are probably right, so we solved it in the architectural code like this finally. https://lore.kernel.org/loongarch/20240305143958.1752241-1-chenhuacai@loong= son.cn/T/#u Huacai > > > So we extend the mmiowb tracking system from spinlock to mutex, hook up > > mmiowb helpers to mutexes as well as spinlocks. > > > > Without this, we get such an error when run 'glxgears' on weak ordering > > architectures such as LoongArch: > > > > radeon 0000:04:00.0: ring 0 stalled for more than 10324msec > > radeon 0000:04:00.0: ring 3 stalled for more than 10240msec > > radeon 0000:04:00.0: GPU lockup (current fence id 0x000000000001f412 la= st fence id 0x000000000001f414 on ring 3) > > radeon 0000:04:00.0: GPU lockup (current fence id 0x000000000000f940 la= st fence id 0x000000000000f941 on ring 0) > > radeon 0000:04:00.0: scheduling IB failed (-35). > > [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35) > > radeon 0000:04:00.0: scheduling IB failed (-35). > > [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35) > > radeon 0000:04:00.0: scheduling IB failed (-35). > > [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35) > > radeon 0000:04:00.0: scheduling IB failed (-35). > > [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35) > > radeon 0000:04:00.0: scheduling IB failed (-35). > > [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35) > > radeon 0000:04:00.0: scheduling IB failed (-35). > > [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35) > > radeon 0000:04:00.0: scheduling IB failed (-35). > > [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35) > > > > Link: https://lore.kernel.org/dri-devel/29df7e26-d7a8-4f67-b988-44353c4= 270ac@amd.com/T/#t > > Hmm. It's hard to tell from that thread whether you're really falling > afoul of the problems that mmiowb() tries to solve or whether Loongson > simply doesn't have enough ordering in its MMIO accessors. > > The code you proposed has: > > mmiowb(); /* Make sure wptr is up-to-date for hw */ > > but mmiowb() is really about ensuring order with MMIO accesses from a > different CPU that subsequently takes the lock. > > So please can you explain a bit more about the failing case? I'm worried > that mmiowb() may be the wrong tool for the job here. > > Thanks, > > Will