Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4736734rdb; Fri, 15 Sep 2023 10:39:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSol81mK9KkZFoeHRcqjf5HYW0x5xZgwPi1Bs5H6YFYJ+q+VK9HC/wnqE68Rw63zqi7U4Q X-Received: by 2002:a17:90a:bd8b:b0:263:72fe:3ef7 with SMTP id z11-20020a17090abd8b00b0026372fe3ef7mr2103499pjr.42.1694799570147; Fri, 15 Sep 2023 10:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694799570; cv=none; d=google.com; s=arc-20160816; b=qrVf9viX040dFJ+nKo7UcNuD06+EDUouRygKqixumA49yIK90hZBTHZZV6vGhCGASc C8f2sz2dDPdC99boJABdwcGIC83/ZOY+VTcL2z7x1g9Rq6JCJEyugw7DpWapl/HNA0BJ HyolkWWz3U75z7ULqljj6+wK7abw6cMT5A0sZK5NaXmgA/d0QyXSKtWbEAlCnh1NWNiz 8pOMHRwbufpx0hHIOptXVhP7F1CfG8rSze8feU4VkHSk5w2z8LvXamWE3BXt4X3Pl9Mv VI2EsADT4a2rARxaoaXnxMUbL9mkY6L5uJWvOpcDdlUsu2AHPdyTYrf5dWm9ZrAc5TkD 31iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=CeI0S+/aC/SJQyGJYbQJ8C23w5BWLgPhEwUAg2dI/+Y=; fh=Pj7hn9hSiIBbBUJ0lL1RP4xGgUEUh7gIC6/R4W1gXXs=; b=ONJKvAM3hYmnKYIxljtMyYhZH3fxlmeNvE5SoRnTfR3HMrzlReCAtdFm3DeCfsw4/v XLiBcBD6UFwNM3L6eVhLEKJGcVfUDIOJyOwUNqqFugEVtbkFedHCLd2wgxTJH/MtYesa E4kzdbbC1lRkpb2olx7oERoq7DSt3ApsIHuwOM7BYwWMzocYcmiBI+Z9YHlggIJBNr2s 1PwYBpjs644kL7oyC43E8EqrkCSOOCJlkZjtmq+4eQ8BcO50lj7Weja24M7/FvtitKFD ru/vQq0yqEIyMbzPxE0vcadH+m9dy7zA/xMQLZAEiQCkOwNvJZRn0l/IKPSSIwuC91lL +9EA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id om6-20020a17090b3a8600b00263cdc45e8bsi6290196pjb.87.2023.09.15.10.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:39:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id AB562830153E; Fri, 15 Sep 2023 10:39:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231349AbjIORis (ORCPT + 99 others); Fri, 15 Sep 2023 13:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236283AbjIORi3 (ORCPT ); Fri, 15 Sep 2023 13:38:29 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D746F2134 for ; Fri, 15 Sep 2023 10:37:44 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B90F01FB; Fri, 15 Sep 2023 10:38:21 -0700 (PDT) Received: from [10.1.197.60] (eglon.cambridge.arm.com [10.1.197.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A752D3F5A1; Fri, 15 Sep 2023 10:37:41 -0700 (PDT) Message-ID: Date: Fri, 15 Sep 2023 18:37:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v5 15/24] x86/resctrl: Allow arch to allocate memory needed in resctrl_arch_rmid_read() Content-Language: en-GB To: Reinette Chatre , x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com References: <20230728164254.27562-1-james.morse@arm.com> <20230728164254.27562-16-james.morse@arm.com> <8ba79ccf-a1e0-d486-178c-5dfb6553a400@arm.com> <4f7facea-ffc4-63c3-b960-fa92eb03b04c@intel.com> From: James Morse In-Reply-To: <4f7facea-ffc4-63c3-b960-fa92eb03b04c@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 10:39:22 -0700 (PDT) Hi Reinette, On 25/08/2023 00:04, Reinette Chatre wrote: > On 8/24/2023 9:56 AM, James Morse wrote: >> On 09/08/2023 23:37, Reinette Chatre wrote: >>> On 7/28/2023 9:42 AM, James Morse wrote: >>>> Depending on the number of monitors available, Arm's MPAM may need to >>>> allocate a monitor prior to reading the counter value. Allocating a >>>> contended resource may involve sleeping. >>>> >>>> add_rmid_to_limbo() calls resctrl_arch_rmid_read() for multiple domains, >>>> the allocation should be valid for all domains. >>>> >>>> __check_limbo() and mon_event_count() each make multiple calls to >>>> resctrl_arch_rmid_read(), to avoid extra work on contended systems, >>>> the allocation should be valid for multiple invocations of >>>> resctrl_arch_rmid_read(). >>>> >>>> Add arch hooks for this allocation, which need calling before >>>> resctrl_arch_rmid_read(). The allocated monitor is passed to >>>> resctrl_arch_rmid_read(), then freed again afterwards. The helper >>>> can be called on any CPU, and can sleep. >> >>> Looking at the error paths all the errors are silent failures. >> >> Yeah, I don't really expect this to ever fail. The memory arm64 needs to allocate is >> smaller than a pointer - if that fails, I think there are bigger problems. The hardware >> resource is something the call will wait for. >> >> As you note, it's hard to propagate an unlikely error back from here. >> >> >>> On the >>> failure in mon_event_read() this could potentially be handled by setting >>> the "err" field in struct rmid_read ... at least then the caller can print >>> an error instead of displaying a zero count to the user. >> >> Sure, that covers the one a human being might see. > > Right. > >>> The other failures are harder to handle though. >> >> I don't think the silent failure is such a bad thing. For the limbo handler, no RMID moves >> between the lists until the handler is able to make progress. > > ok, so it needs to ensure that the handler is still rescheduled > when such a failure is encountered. Yup, the silent error occurs in __check_limbo(), and cqm_handle_limbo() will still reschedule the worker. Similarly, for mbm_update(), mbm_handle_overflow() will still reschedule the work. >> For the overflow handler, its possible an overflow will get missed (I still have an >> overflow interrupt I can use here). But I don't think this will be the biggest problem on >> a machine that is struggling to allocate 4 bytes. > > As I now (I think) better understand for MPAM it is 4 bytes of memory as well as > reservation of a hardware resource. Could something go wrong attempting to find an > available hardware resource that as you state later is indeed scarce? I wonder if > it would not be helpful to at least have resctrl log an error from the > places where it is not possible to propagate the error. If it can't allocate a monitor, it should block until one becomes available. Errors should never occur during normal use. I'll add pr_warn_ratelimited() for errors returned on this path. >>> Considering that these contexts are allocated and >>> freed so often, why not allocate them once (perhaps in struct rdt_hw_domain?) >>> on driver load with clear error handling? >> >> Because the resource they represent is scarce. You may have 100 control or monitor groups, >> but only 10 hardware monitors. The hardware monitor has to be allocated and programmed >> before it can be read. > > I think I misunderstood what "context" is when I wrote the above. I > was thinking about memory allocation that can be done early and > neglected to connect the "context" to be an actual hardware resource. Let me know if there is a better name. Obviously I had to avoid 'resource'! Thanks, James