From patchwork Tue Sep 29 04:00:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1373002 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=GvflBQuV; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C0m0S1PDtz9sSJ for ; Tue, 29 Sep 2020 14:01:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FE71386F822; Tue, 29 Sep 2020 04:01:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FE71386F822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1601352080; bh=5AjpkGm5awQIFBluctu0HZCztrS2fq7h7XVp39zK8m8=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GvflBQuVS5KPmEGQbPHHOnDj3CB2KSYcSMUucTSa1gDIJt6qfOWTyrZ1+DqDug+MP kZBbTmD76nyDDOq5hVvIeWgy7NX+kkRNampaEyi3gUwHPdkn80OgkiN8fC+lTmzW9R zoTxoJoSO09vZrsSIpMJqDadQQbD7RWTFo5vcMQE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by sourceware.org (Postfix) with ESMTPS id BA2EC386F822; Tue, 29 Sep 2020 04:01:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BA2EC386F822 Received: by mail-io1-xd41.google.com with SMTP id z25so3399909iol.10; Mon, 28 Sep 2020 21:01:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5AjpkGm5awQIFBluctu0HZCztrS2fq7h7XVp39zK8m8=; b=YGphRFDRTlTQvlaqNsnTaw2yc7GzteadGybPEsiK7IXyOHMqv4hzg5fIYB7p7YMfwM 2H7PwdfFJaakjIGuxWxvZynQEEI6EGh5FzVQkadPDsl2dth+8oOUkue6QblEnJzBhrTD nowuadtpLqDOxJxebzGnwNRYQXXjSZQXTlSW632AxtnyrYezGYpZWUUywpdVjzyFDKMI N49dmRnx/NyUyCR18+knkUmj1rMEV4mV6e5sfEr14YF8njPEzoSW+yNQg1/LmsH8O/PL 7X+2UL7TcX4FH8S7cpIjsxZmy6RaxUutbgAjkzQJ9kZ2Ku1SVGmUU34LcN8r79w6Pqwk PKYw== X-Gm-Message-State: AOAM533TWi1dFkM9+/LnxU3JWpnGRlbSFU90msjmT/K52wJcz+Q0bDQT kllZQPjO2Z4Nol+2FSL17+If6+OVeCHOJjw4Vh9GSPe0HSg= X-Google-Smtp-Source: ABdhPJxL5e8/LV8LVLoBZNAARyf2dtnVSePb9vPRaz9deJJ+KD6zCnvzTKNsVfrJqWHKpkdHfUbKLPwUgxXlCAFPH+Y= X-Received: by 2002:a6b:b787:: with SMTP id h129mr1097968iof.202.1601352076001; Mon, 28 Sep 2020 21:01:16 -0700 (PDT) MIME-Version: 1.0 References: <20200918160709.949608-1-hjl.tools@gmail.com> <20200918160709.949608-3-hjl.tools@gmail.com> <87eemm6n37.fsf@oldenburg2.str.redhat.com> In-Reply-To: Date: Mon, 28 Sep 2020 21:00:40 -0700 Message-ID: Subject: V3 [PATCH] Set tunable value as well as min/max values To: Siddhesh Poyarekar X-Spam-Status: No, score=-3036.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer , "H.J. Lu via Libc-alpha" Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On Mon, Sep 28, 2020 at 10:31 AM Siddhesh Poyarekar via Libc-alpha wrote: > > On 28/09/20 19:05, Florian Weimer via Libc-alpha wrote: > > I'm not sure if this change is philosophically correct as far as the > > tunables framework is concerned. I had thought the limits should be > > something static, so that they are consistent across systems. > > It seems like a good idea to support dynamic limits if they will always > be more restrictive than the most restrictive static limit one could > come up with for the tunable. I didn't exclude dynamic limits from a > design perspective; it's just that the tunables implemented at that time > didn't need them. > > There is a case to always have static bounds (at the minimum to ensure > that values don't overflow the underlying types) but that shouldn't > preclude more restrictive dynamic limits IMO. > > Bikeshed: maybe the macro should be called TUNABLE_SET_WITH_BOUNDS() > instead of TUNABLE_SET_ALL. > Here is the updated patch with TUNABLE_SET_WITH_BOUNDS. OK for master? Thanks. From 34c463f37f46abcb2279196def9925e9797e9ede Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 1 Jun 2020 14:11:32 -0700 Subject: [PATCH] Set tunable value as well as min/max values Some tunable values and their minimum/maximum values must be determinted at run-time. Add TUNABLE_SET_WITH_BOUNDS and TUNABLE_SET_WITH_BOUNDS_FULL to update tunable value together with minimum and maximum values. __tunable_set_val is updated to set tunable value as well as min/max values. --- elf/dl-tunables.c | 17 ++++++++++++----- elf/dl-tunables.h | 21 +++++++++++++++++++-- manual/README.tunables | 24 ++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index 26e6e26612..b44174fe71 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -101,12 +101,19 @@ get_next_env (char **envp, char **name, size_t *namelen, char **val, }) static void -do_tunable_update_val (tunable_t *cur, const void *valp) +do_tunable_update_val (tunable_t *cur, const void *valp, + const void *minp, const void *maxp) { uint64_t val; if (cur->type.type_code != TUNABLE_TYPE_STRING) - val = *((int64_t *) valp); + { + val = *((int64_t *) valp); + if (minp) + cur->type.min = *((int64_t *) minp); + if (maxp) + cur->type.max = *((int64_t *) maxp); + } switch (cur->type.type_code) { @@ -153,15 +160,15 @@ tunable_initialize (tunable_t *cur, const char *strval) cur->initialized = true; valp = strval; } - do_tunable_update_val (cur, valp); + do_tunable_update_val (cur, valp, NULL, NULL); } void -__tunable_set_val (tunable_id_t id, void *valp) +__tunable_set_val (tunable_id_t id, void *valp, void *minp, void *maxp) { tunable_t *cur = &tunable_list[id]; - do_tunable_update_val (cur, valp); + do_tunable_update_val (cur, valp, minp, maxp); } #if TUNABLES_FRONTEND == TUNABLES_FRONTEND_valstring diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h index f05eb50c2f..550b0cc7f4 100644 --- a/elf/dl-tunables.h +++ b/elf/dl-tunables.h @@ -70,9 +70,10 @@ typedef struct _tunable tunable_t; extern void __tunables_init (char **); extern void __tunable_get_val (tunable_id_t, void *, tunable_callback_t); -extern void __tunable_set_val (tunable_id_t, void *); +extern void __tunable_set_val (tunable_id_t, void *, void *, void *); rtld_hidden_proto (__tunables_init) rtld_hidden_proto (__tunable_get_val) +rtld_hidden_proto (__tunable_set_val) /* Define TUNABLE_GET and TUNABLE_SET in short form if TOP_NAMESPACE and TUNABLE_NAMESPACE are defined. This is useful shorthand to get and set @@ -82,11 +83,18 @@ rtld_hidden_proto (__tunable_get_val) TUNABLE_GET_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, __type, __cb) # define TUNABLE_SET(__id, __type, __val) \ TUNABLE_SET_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, __type, __val) +# define TUNABLE_SET_WITH_BOUNDS(__id, __type, __val, __min, __max) \ + TUNABLE_SET_WITH_BOUNDS_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, \ + __type, __val, __min, __max) #else # define TUNABLE_GET(__top, __ns, __id, __type, __cb) \ TUNABLE_GET_FULL (__top, __ns, __id, __type, __cb) # define TUNABLE_SET(__top, __ns, __id, __type, __val) \ TUNABLE_SET_FULL (__top, __ns, __id, __type, __val) +# define TUNABLE_SET_WITH_BOUNDS(__top, __ns, __id, __type, __val, \ + __min, __max) \ + TUNABLE_SET_WITH_BOUNDS_FULL (__top, __ns, __id, __type, __val, \ + __min, __max) #endif /* Get and return a tunable value. If the tunable was set externally and __CB @@ -103,7 +111,16 @@ rtld_hidden_proto (__tunable_get_val) # define TUNABLE_SET_FULL(__top, __ns, __id, __type, __val) \ ({ \ __tunable_set_val (TUNABLE_ENUM_NAME (__top, __ns, __id), \ - & (__type) {__val}); \ + & (__type) {__val}, NULL, NULL); \ +}) + +/* Set a tunable value together with min/max values. */ +# define TUNABLE_SET_WITH_BOUNDS_FULL(__top, __ns, __id, __type, __val, \ + __min, __max) \ +({ \ + __tunable_set_val (TUNABLE_ENUM_NAME (__top, __ns, __id), \ + & (__type) {__val}, & (__type) {__min}, \ + & (__type) {__max}); \ }) /* Namespace sanity for callback functions. Use this macro to keep the diff --git a/manual/README.tunables b/manual/README.tunables index f87a31a65e..fff6c2a87e 100644 --- a/manual/README.tunables +++ b/manual/README.tunables @@ -67,7 +67,7 @@ The list of allowed attributes are: non-AT_SECURE subprocesses. NONE: Read all the time. -2. Use TUNABLE_GET/TUNABLE_SET to get and set tunables. +2. Use TUNABLE_GET/TUNABLE_SET/TUNABLE_SET_WITH_BOUNDS to get and set tunables. 3. OPTIONAL: If tunables in a namespace are being used multiple times within a specific module, set the TUNABLE_NAMESPACE macro to reduce the amount of @@ -112,9 +112,29 @@ form of the macros as follows: where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the remaining arguments are the same as the short form macros. +The minimum and maximum values can updated together with the tunable value +using: + + TUNABLE_SET_WITH_BOUNDS (check, int32_t, val, min, max) + +where 'check' is the tunable name, 'int32_t' is the C type of the tunable, +'val' is a value of same type, 'min' and 'max' are the minimum and maximum +values of the tunable. + +To set the minimum and maximum values of tunables in a different namespace +from that module, use the full form of the macros as follows: + + val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL) + + TUNABLE_SET_WITH_BOUNDS_FULL (glibc, cpu, hwcap_mask, uint64_t, val, min, max) + +where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the +remaining arguments are the same as the short form macros. + When TUNABLE_NAMESPACE is not defined in a module, TUNABLE_GET is equivalent to TUNABLE_GET_FULL, so you will need to provide full namespace information for -both macros. Likewise for TUNABLE_SET and TUNABLE_SET_FULL. +both macros. Likewise for TUNABLE_SET, TUNABLE_SET_FULL, +TUNABLE_SET_WITH_BOUNDS and TUNABLE_SET_WITH_BOUNDS_FULL. ** IMPORTANT NOTE ** -- 2.26.2