From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 21F8D3858C52 for ; Wed, 22 Nov 2023 13:03:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 21F8D3858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 21F8D3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700658241; cv=none; b=SbUCjpiTX9Vgjbx26lvbiv/sa262qXdYVUcOvVDlMIy3pRDXsLskVPraCcAvhC20MH4wN21xYBwuX+k873riLRfdohovKju33+CGWIXdpvt2DBb0STA9WhZKtNkGeFnGpyG+llg457OXdwQjOFjnatHSE/8WhTN+BDvp9++qqeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700658241; c=relaxed/simple; bh=4+PKlPCMJSrexT/ME7oSDWr/dGLT1gYH0BtQar8xCBQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=PAAhgl8ow2t1k8cd7oRuY2RqgD2UEilMsfSDOQy/z/YcBH0mEz7iCqrjsrvjUtxiT3RyVYvyTuiJFqOKqOb+eIy/VIhiQkKyDxqC86Wzy/TkAXsgkGNoJfTO7m+jMfnjP8pSFZ8p6Eh0Z+knV2zD77hn7F5GbuWn+Y+1xD90ImQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6c39ad730aaso5509128b3a.0 for ; Wed, 22 Nov 2023 05:03:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700658230; x=1701263030; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=HXGJvosli14mJ28jXuuzQ7LL1Gg7GIWP/SDQ2YVxYuk=; b=lWAyCvGc6u30UXESfKHR52yQ3OtQT21FvGF2TjQ89yBFisQmW9U6G4Ezt3MpYwVyqn TTX0b4KxcPbmxH7Qp5gObgwp0RNrwANUrgnSedRs7wXUkhwx/aYd+Vibvq7JbLeZ05PO BWwvQs4PD5ptQxReNNiEUIP37sMS7U1CKO2DVi2qh5e4CRJhV1r7bhvGmDX/8ytyATCq 7GOYg2ARfemf+avBDsaa6a6h5dDKIEd8IZWK1yaiWlE7TEWxc/tHLGWeTu4NCbeS9eNk TBfKFAxhtcFQVzfg872Ykl0lRwZ1U3g+MM4CrqT2uBTWbk9esyzBuQG31pnse3a8dhmF 8MqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700658230; x=1701263030; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HXGJvosli14mJ28jXuuzQ7LL1Gg7GIWP/SDQ2YVxYuk=; b=mYqazdIxbjDuuYiy9qIQzt+5hrvNlxVPzLpCwY1SbH7i5wzVLTu9Eduz9KotrjuXmB 5abyxUPnTbHIivYk4h4kCaslbin3Hnp/Gw2rFd+PUwkuEzw6gN9c5Qm3whl2vlJ81iwh GSLs+d7hzcyN05zcERnkhxfOzyW7XMLzL6RYClreNTdYa7Dk+nhfRVOT8C9QtcgKjUkj e7JVf2ZShRGNc2vMa5LG18ergVT6ukIMtsR9Q2ssPUzWosN66YQAxRm9a26Sbte7+5XR sJbvOZmFAufJkNJT0NmvBYpLc68sypvCiAkdY1yiIaBAszEv4CvHbUP0irw8J5JaBgEs r6lw== X-Gm-Message-State: AOJu0Ywx0hQr1vAoLIRSC/9BPhvErkvHegMSALH3SwGdT+zlCPsP+Nb8 ILitKq24ON1ZxFKBQZ5Bef5PKx1486nRvW/LPgBX0w== X-Google-Smtp-Source: AGHT+IEyhuHZ7HepP2id4ZKTj07dc5qxPuD1iuU4ktrG6ZoiTet9a8QfQYK9/cAsaDc8q5JC/omdXQ== X-Received: by 2002:a05:6a21:1a9:b0:187:bc51:2ea3 with SMTP id le41-20020a056a2101a900b00187bc512ea3mr2849393pzb.57.1700658229889; Wed, 22 Nov 2023 05:03:49 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c2:94e:6d31:2e3e:8d88:83c3? ([2804:1b3:a7c2:94e:6d31:2e3e:8d88:83c3]) by smtp.gmail.com with ESMTPSA id n16-20020a056a0007d000b006cbb40669b1sm4663908pfu.23.2023.11.22.05.03.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Nov 2023 05:03:49 -0800 (PST) Message-ID: <2d25f3e5-6433-4c42-a4e1-eb80b973d21a@linaro.org> Date: Wed, 22 Nov 2023 10:03:47 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 11/19] elf: Do not duplicate the GLIBC_TUNABLES string Content-Language: en-US To: Siddhesh Poyarekar , libc-alpha@sourceware.org References: <20231106202552.3404059-1-adhemerval.zanella@linaro.org> <20231106202552.3404059-12-adhemerval.zanella@linaro.org> <0be5babe-a123-47af-98e1-abab4d1c7fd2@sourceware.org> <7692cb6a-0832-403c-b704-b4f143b21e12@sourceware.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <7692cb6a-0832-403c-b704-b4f143b21e12@sourceware.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 22/11/23 09:23, Siddhesh Poyarekar wrote: > On 2023-11-21 13:12, Adhemerval Zanella Netto wrote: >>>> -tunable_initialize (tunable_t *cur, const char *strval) >>>> +tunable_initialize (tunable_t *cur, const char *strval, size_t len) >>>>    { >>>> -  tunable_val_t val; >>>> +  tunable_val_t val = { 0 }; >>>>        if (cur->type.type_code != TUNABLE_TYPE_STRING) >>>>        val.numval = (tunable_num_t) _dl_strtoul (strval, NULL); >>> >>> There's an implicit assumption that strval is NULL terminated for numeric values.  Is that safe?  Maybe all you need to do here is copy strval into a static buffer of size 21 (basically size of the string representing -1ULL) and pass that to _dl_strtoul. >> >> Afaiu the environment variable will always be NULL terminated (although some >> might overlap).  This is due how the kernel will layout the argv/envp on >> process creation at sys_execve: > > Sure, but the strval here should not be the entire envvar, just the value portion of it.  Granted that _dl_strtoul will bail out on the first non-numeric character, so maybe it's not For the GLIBC_TUNABLES itself, parse_tunables will pass the correct length for each tunable. For the alias case, get_next_env will pass the value length (which I fixed on v4 btw). So I think there is no need to copy the value on a temporary value, parsing can be done in-place since kernel ensures the string will be null-terminated. > >>>> -      if (disable) >>>> +      if (n.disable) >>>>            { >>>>              CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, POPCNT, 6); >>>>              CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SSE4_1, 6); >>>>              CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SSE4_2, 6); >>>> -          if (memcmp (n, "XSAVEC", 6) == 0) >>>> +          if (memcmp (n.str, "XSAVEC", 6) == 0) >>> >>> Why does this use the bare memcmp and not the tunables_strcmp? >> >> If I recall correctly, I did tried it and it resulted in worse codegen.  The >> tunable_str_comma_strcmp also checks the size, which on the x86 code is not >> required and for some reason compiler can not eliminate. > > Why isn't it required? Couldn't n.str be smaller than 6 chars? No because on the start of the loop the switch checks for 'n.len'.