From patchwork Thu Mar 30 13:55:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 77205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1169722vqo; Thu, 30 Mar 2023 07:30:18 -0700 (PDT) X-Google-Smtp-Source: AK7set+Tf+lh40mFBfceA8aV/ouoBut+8VCvXAAR54ALSCDl0qdw08nrM+L1mtxo8QIS8dqvcdbS X-Received: by 2002:a05:6a20:84a2:b0:cc:5f27:d003 with SMTP id u34-20020a056a2084a200b000cc5f27d003mr18506129pzd.56.1680186618284; Thu, 30 Mar 2023 07:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680186618; cv=none; d=google.com; s=arc-20160816; b=tCUn/jx7iKUnpBgH3WL+0l1ajMWmEZuotUgsa9sn24Mo7NmTaMixwcm9nsJIV2A8Yg TetY+zTD5xodwpKKfTpcZRxp4siFX5O858rELu2xcfIRCxUl63FJGaF1p9fb2Lm6QLfh QZl03kYPa1pqQV5JXf83RrNd7DGc8CqMS6oLEHVwzPPMDp7v9sqb3GV5e6koqJi+DQZ5 hTicvFuu8e1lvZezsgLV7dnDjKBnDyLiF1G3bBPaqWvRgMpF26ZW9HEgppsU6WGSwbyH xzVkOiF7yIkCQX1O9eSme7BBml8VRpeXHvekCgpo8NoO+plQLnNZHvcJvw5tou7wlUxd ofNw== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=Db8tOgMamx6SeqgPHUVcNRbWY9TzQjouDMjbLfKO9Bs=; b=YGC36Lgez0ENHevxLA6Jmb9v7ycE/9KLL6UhVwvUyxJGYUPDksUBX1h4VLKgPZvtpR QuGtu2yuFtD2PqfWZjHoBi08EYWmIFrBu/d9TQ+IX9o22Hp/GYvyPz874HufHy6vbsyQ +xGfSj+cHafATecxuKppjX9SKhnmBecJC5r1IjqU7EPeCnh9vqLq0mHUs6BL1LmWS0+e f5KEi330LX7QnHCgAV252viDbi6rIjqwi0Ll7X3nQAnHkdEWGirNNI17Y4oNZdPIz3Rp AnGLDh5vQdeGScqMG0Z4uHFJM6QKvow3W9DcRCHsSqEspOitf1A8ef6PZlPwLgfIJSHi gQGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=smbJl9qF; 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 i23-20020aa796f7000000b00625488ab85esi8064967pfq.4.2023.03.30.07.30.03; Thu, 30 Mar 2023 07:30:18 -0700 (PDT) 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=smbJl9qF; 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 S232222AbjC3N4U (ORCPT + 99 others); Thu, 30 Mar 2023 09:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232090AbjC3N4Q (ORCPT ); Thu, 30 Mar 2023 09:56:16 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3EA67ED3 for ; Thu, 30 Mar 2023 06:56:14 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id p12-20020a25420c000000b00b6eb3c67574so18710889yba.11 for ; Thu, 30 Mar 2023 06:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680184574; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Db8tOgMamx6SeqgPHUVcNRbWY9TzQjouDMjbLfKO9Bs=; b=smbJl9qFP0l+li/hTveSDyoWOwzoPsoLgc8Y/ZUlzb4z79RlsRniVMcWs8fQnlPjSe aZIByw2LkyVG+iujSfkEbBIxijps0U3JAGOLzKQD9VF1QS6DCfGVK5PsbLIIh3MtvbGo T3VY05+yvWDx1cCieWInbheUEtsfNdp1dtZDEiXe5SSdR+eR8joFUtII4AWaimvlXvG/ sfl8ELaGwsoupYMFHqtKEz38EFqsNC1R1YPxJO4rYlNrGruq5MFrZBGFSN37GhwGY3YM EiffeAwYzCqWYR2AfbaJ5EMGJt94EYC2UWzEKmgiyjaM0LGsMIo42eXzY/vwAOpfHseR 5XvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680184574; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Db8tOgMamx6SeqgPHUVcNRbWY9TzQjouDMjbLfKO9Bs=; b=gU9E7ULLyDdmcirBkjTeTWqU4+iGJdrcdwnCLHw7oP7fkqL5krbwnGGb/oOrnYis3f Jx+p2aNKbLcrYy/La0AzK0NIOheOmkO346hXUuI2Y4z881rqzphx07V3Fh0AyBxhjrAE 57WpW+bRcoF7FfJByqZfijavVtvNdlwIjLysTBS68fZUD+nVuvUKF4I2A93ERrJRcmVj 7fOi7n+AJEPS4zYjCqlxwQsv4XX5Fm6IZsl31TFTyUNHoCO8o9biOxCEeXKTJjrBInLj P25jVRmkbTToM/VOVB3/ZdQBMe76u6h8/yzX8R2wXJ0OzGa44SRQyXYEltfxkOZ4qaeY 70oQ== X-Gm-Message-State: AAQBX9eiwQxG2JrDdXoFDNb9fot4l2s91+f2wduds3/LdH6P1KlFiI5n 07YzujE2xLt8AK7bNISKFfeqk1Ud01trBIPKXg== X-Received: from peternewman-vh.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:30cc]) (user=peternewman job=sendgmr) by 2002:a25:d9d6:0:b0:b80:e387:f6af with SMTP id q205-20020a25d9d6000000b00b80e387f6afmr50312ybg.2.1680184574244; Thu, 30 Mar 2023 06:56:14 -0700 (PDT) Date: Thu, 30 Mar 2023 15:55:56 +0200 In-Reply-To: <20230330135558.1019658-1-peternewman@google.com> Mime-Version: 1.0 References: <20230330135558.1019658-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230330135558.1019658-2-peternewman@google.com> Subject: [PATCH v5 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops From: Peter Newman To: reinette.chatre@intel.com, fenghua.yu@intel.com Cc: Babu.Moger@amd.com, bp@alien8.de, dave.hansen@linux.intel.com, eranian@google.com, gupasani@google.com, hpa@zytor.com, james.morse@arm.com, linux-kernel@vger.kernel.org, mingo@redhat.com, skodak@google.com, tglx@linutronix.de, tony.luck@intel.com, x86@kernel.org, Peter Newman X-Spam-Status: No, score=-7.7 required=5.0 tests=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=unavailable 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?1761803363411653155?= X-GMAIL-MSGID: =?utf-8?q?1761803363411653155?= rdtgroup_kn_lock_live() can only release a kernfs reference for a single file before waiting on the rdtgroup_mutex, limiting its usefulness for operations on multiple files, such as rename. Factor the work needed to respectively break and unbreak active protection on an individual file into rdtgroup_kn_{get,put}(). No functional change. Signed-off-by: Peter Newman Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 35 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 6ad33f355861..51b869149e76 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2301,6 +2301,26 @@ static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn) } } +static void rdtgroup_kn_get(struct rdtgroup *rdtgrp, struct kernfs_node *kn) +{ + atomic_inc(&rdtgrp->waitcount); + kernfs_break_active_protection(kn); +} + +static void rdtgroup_kn_put(struct rdtgroup *rdtgrp, struct kernfs_node *kn) +{ + if (atomic_dec_and_test(&rdtgrp->waitcount) && + (rdtgrp->flags & RDT_DELETED)) { + if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP || + rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) + rdtgroup_pseudo_lock_remove(rdtgrp); + kernfs_unbreak_active_protection(kn); + rdtgroup_remove(rdtgrp); + } else { + kernfs_unbreak_active_protection(kn); + } +} + struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn) { struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn); @@ -2308,8 +2328,7 @@ struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn) if (!rdtgrp) return NULL; - atomic_inc(&rdtgrp->waitcount); - kernfs_break_active_protection(kn); + rdtgroup_kn_get(rdtgrp, kn); mutex_lock(&rdtgroup_mutex); @@ -2328,17 +2347,7 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn) return; mutex_unlock(&rdtgroup_mutex); - - if (atomic_dec_and_test(&rdtgrp->waitcount) && - (rdtgrp->flags & RDT_DELETED)) { - if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP || - rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) - rdtgroup_pseudo_lock_remove(rdtgrp); - kernfs_unbreak_active_protection(kn); - rdtgroup_remove(rdtgrp); - } else { - kernfs_unbreak_active_protection(kn); - } + rdtgroup_kn_put(rdtgrp, kn); } static int mkdir_mondata_all(struct kernfs_node *parent_kn,