From patchwork Mon Dec 5 20:32:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 29928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2467829wrr; Mon, 5 Dec 2022 12:54:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf7S5pojvyw1PV/NeRc87TyvYbTEdHxSX6wH+0NtTUbov+rG/Fycj3JYgCy9DlKznzc2szB+ X-Received: by 2002:a05:6402:4312:b0:46c:a461:d016 with SMTP id m18-20020a056402431200b0046ca461d016mr6681213edc.383.1670273652211; Mon, 05 Dec 2022 12:54:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670273652; cv=none; d=google.com; s=arc-20160816; b=uVx3yseRaTwEb3E2ftXYxKX9YL9ay1s/vBVBsmbJtNt19lk6cTEyamIznAGGOT5sP2 YYAwH/LOkXc4gdHmwgAfd10UTkBYgwX6SZ2cjbvR+Xb3br9NIbQ22iy/himidBSJ1r59 WJb6U0V44sg08gTNNxpwx9P4+eLjEHX+b/HWxh/i6oqJUt+09asyMTDMqDWs1sk3HGPP PAuD3IQelTwvZlE9Hl89HE9HEW+d4cLLK24c2fHebLFcWqvkrSxbZahDfdNEG9jOXVrp x+XQXPvg+T99LkiMmyQQp2TAFhIehp/3JZqMwcVjLgj3T9/q3KrmE6cfRHEEgc0yhtqh 5AxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=antRRD0vokgKx0N3J+PXb46vFk8dibXmcnSX4dVIdQw=; b=uTZJL6h21apsify+vCnmxJHX8Syid/MTevfLf1hNO9FEjGO353EniXuQr+fdgV+Ez7 GPwCUuMuP/fWDJocbQycVyEz+t+1v+mhBB0HltpR80nmwmI3sW7OTE6DM6I6p8o/nIoW 9KVMIjlKoCmrSbQHgqWKSuxxS4LGCOt5vHCP9heLI+yYQwnuRvEyJt+qrhf1xxYpIcE7 C14Xlhc7aVPCLiMgG8LAaTlKxHgCCoVc8azzSsxckOFpv3c9AfJuDpTJk61LYvzcmEBI YBW1tXm4cDYvuwHzs3d7+12mgUH4Uhh+Mem3vj/JAo2hwmM9+GNzKV2pDYhKy48H0DBw kfDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ShcU1Hu7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f26-20020a50a6da000000b0046bd3251ed9si365566edc.110.2022.12.05.12.53.49; Mon, 05 Dec 2022 12:54:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ShcU1Hu7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232801AbiLEUdG (ORCPT + 99 others); Mon, 5 Dec 2022 15:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233467AbiLEUc7 (ORCPT ); Mon, 5 Dec 2022 15:32:59 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42F1465E4 for ; Mon, 5 Dec 2022 12:32:58 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id m2-20020a17090a730200b0021020cce6adso17472468pjk.3 for ; Mon, 05 Dec 2022 12:32:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=antRRD0vokgKx0N3J+PXb46vFk8dibXmcnSX4dVIdQw=; b=ShcU1Hu7FjHVxESQXX7VbG15++IpyzlkpBWKvZ0Pj2ZiCG5CXf3V3tl8VyjMYAab3Q p71i5QpQ91HzcA9nBbabEkuvkuYlcsQwtD8P5XN74eYDbN4H2+ka6J9GXH//H6abyVzO IqwYtMPh6LL8xCO1tcC6JuOqIchwcmD2dIrB3yuxJaGFIQItgqNgKx3hP6Rl+ZVwuwbp 8FH8Ao6Fw7Uy05o9e4h8c3TaQuAsFDoSsQCKEWjHHLEDrVQh3pV9p5o0T+2zZKPgCLpc 7q0vnxpyWUi4U6G02COuubsAt1EgtlxuXtW64+IXzxarw1yM53pNlP9VzCyXh1yrhUai xX6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=antRRD0vokgKx0N3J+PXb46vFk8dibXmcnSX4dVIdQw=; b=wKPEEhU7KaboN1DWRRbG7/Q1yBhoV5ywuYcBSqIa8UVDznKR1DBgO82RbIIPuCuNPX 8T0qXor+ZKCZEFGn6Radw2ynqC7yhViA7hpWbUBEJ/hfRomoD7razbOM7d9lFrQ0W59D Y13PUxnlMF0bfbbh4DF4Vslo8oXI1x7WphnILDz3+FSto6aAcPrwZBOelSPqmorUb8s5 bKe8k7knHCBmuBHrZqGZ2Y1YCDqEIie2AcAn872M7RSikYHP1oUfprXb6xWnAngekDkX 1sis7C/EoMBZmtln+0+ISHn5WSpii90kqeueKcNDwWqjZ6TypKamTP9L+ivPSDOKztAK fyIw== X-Gm-Message-State: ANoB5pnFX8pH+dwbFWtFCrftiRBOk0Q7oq1xLz5B7iDZzQDtzQX+A3HY WWfrxSkBceP31LUT5lHwlM/NluOctsqtUSQMc3V48AD5lbqQvmfDT6Tt5WwVXTKx8cZgj3GOVAA ZSjGJ9FsLqtj6YwrvtONVzdT1qu36w6hZbBGvlQMZlwXE4AyHrktBYHGtKCUE3sOijr1NkDs= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:90a:43a4:b0:219:1d0a:34a6 with SMTP id r33-20020a17090a43a400b002191d0a34a6mr4744517pjg.1.1670272377261; Mon, 05 Dec 2022 12:32:57 -0800 (PST) Date: Mon, 5 Dec 2022 20:32:53 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221205203253.3923812-1-jstultz@google.com> Subject: [RFC PATCH] pstore: Switch pmsg_lock to an rt_mutex to avoid priority inversion From: John Stultz To: LKML Cc: John Stultz , Wei Wang , Midas Chien , "Connor O'Brien" , Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , kernel-team@android.com X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751408865039246818?= X-GMAIL-MSGID: =?utf-8?q?1751408865039246818?= Wei Wang reported seeing priority inversion caused latencies caused by contention on pmsg_lock, and suggested it be switched to a rt_mutex. I was initially hesitant this would help, as the tasks in that trace all seemed to be SCHED_NORMAL, so the benefit would be limited to only nice boosting. However, another similar issue was raised where the priority inversion was seen did involve a blocked RT task so it is clear this would be helpful in that case. Feedback would be appreciate! Cc: Wei Wang Cc: Midas Chien Cc: Connor O'Brien Cc: Kees Cook Cc: Anton Vorontsov Cc: Colin Cross Cc: Tony Luck Cc: kernel-team@android.com Reported-by: Wei Wang Signed-off-by: John Stultz --- fs/pstore/pmsg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/pstore/pmsg.c b/fs/pstore/pmsg.c index d8542ec2f38c..18cf94b597e0 100644 --- a/fs/pstore/pmsg.c +++ b/fs/pstore/pmsg.c @@ -7,9 +7,10 @@ #include #include #include +#include #include "internal.h" -static DEFINE_MUTEX(pmsg_lock); +static DEFINE_RT_MUTEX(pmsg_lock); static ssize_t write_pmsg(struct file *file, const char __user *buf, size_t count, loff_t *ppos) @@ -28,9 +29,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf, if (!access_ok(buf, count)) return -EFAULT; - mutex_lock(&pmsg_lock); + rt_mutex_lock(&pmsg_lock); ret = psinfo->write_user(&record, buf); - mutex_unlock(&pmsg_lock); + rt_mutex_unlock(&pmsg_lock); return ret ? ret : count; }